|
17 | 17 | #include <mlir/IR/Operation.h> |
18 | 18 | #include <mlir/IR/Value.h> |
19 | 19 | #include <mlir/Interfaces/CallInterfaces.h> |
20 | | -#include <mlir/Interfaces/LoopLikeInterface.h> |
21 | 20 | #include <mlir/Interfaces/SideEffectInterfaces.h> |
22 | 21 | #include <mlir/Support/LLVM.h> |
23 | 22 |
|
@@ -166,6 +165,28 @@ void LivenessAnalysis::visitBranchOperand(OpOperand &operand) { |
166 | 165 | blocks.push_back(&block); |
167 | 166 | } |
168 | 167 | } |
| 168 | + |
| 169 | + // In the block of the successor block argument of RegionBranchOpInterface, |
| 170 | + // there may be arguments of RegionBranchOpInterface, such as the IV of |
| 171 | + // scf.forOp. Explicitly set this argument to live. |
| 172 | + auto regionBranchOp = cast<RegionBranchOpInterface>(op); |
| 173 | + for (size_t i = 0, e = op->getNumRegions(); i < e; ++i) { |
| 174 | + SmallVector<RegionSuccessor> successors; |
| 175 | + regionBranchOp.getSuccessorRegions(op->getRegion(i), successors); |
| 176 | + for (RegionSuccessor successor : successors) { |
| 177 | + if (successor.isParent()) |
| 178 | + continue; |
| 179 | + auto arguments = successor.getSuccessor()->getArguments(); |
| 180 | + ValueRange regionInputs = successor.getSuccessorInputs(); |
| 181 | + for (auto argument : arguments) { |
| 182 | + if (llvm::find(regionInputs, argument) == regionInputs.end()) { |
| 183 | + (void)getLatticeElement(argument)->markLive(); |
| 184 | + LDBG() << "Marking RegionBranchOp's success argument live: " |
| 185 | + << argument; |
| 186 | + } |
| 187 | + } |
| 188 | + } |
| 189 | + } |
169 | 190 | } else if (isa<BranchOpInterface>(op)) { |
170 | 191 | // We cannot track all successor blocks of the branch operation(More |
171 | 192 | // specifically, it's the successor's successor). Additionally, different |
@@ -196,18 +217,6 @@ void LivenessAnalysis::visitBranchOperand(OpOperand &operand) { |
196 | 217 | break; |
197 | 218 | } |
198 | 219 | } |
199 | | - |
200 | | - // If the parentOp is live and it implements the LoopLiveOpInterface, then |
201 | | - // set its IV as live. |
202 | | - if (mayLive && isa<LoopLikeOpInterface>(parentOp)) { |
203 | | - auto loopOp = cast<LoopLikeOpInterface>(parentOp); |
204 | | - std::optional<SmallVector<Value>> ivs = loopOp.getLoopInductionVars(); |
205 | | - if (ivs.has_value()) { |
206 | | - for (auto iv : *ivs) { |
207 | | - getLatticeElement(iv)->markLive(); |
208 | | - } |
209 | | - } |
210 | | - } |
211 | 220 | } else { |
212 | 221 | // When the op is a `RegionBranchTerminatorOpInterface`, like an |
213 | 222 | // `scf.condition` op or return-like, like an `scf.yield` op, its branch |
|
0 commit comments