|
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> |
20 | 21 | #include <mlir/Interfaces/SideEffectInterfaces.h> |
21 | 22 | #include <mlir/Support/LLVM.h> |
22 | 23 |
|
@@ -309,15 +310,29 @@ RunLivenessAnalysis::RunLivenessAnalysis(Operation *op) { |
309 | 310 | << " has no liveness info (unreachable), mark dead"; |
310 | 311 | solver.getOrCreateState<Liveness>(result.value()); |
311 | 312 | } |
| 313 | + SmallVector<Value> mustLiveValues; |
| 314 | + if (auto loopOp = dyn_cast<LoopLikeOpInterface>(op)) { |
| 315 | + std::optional<SmallVector<Value>> ivs = loopOp.getLoopInductionVars(); |
| 316 | + if (ivs.has_value()) |
| 317 | + mustLiveValues.append(*ivs); |
| 318 | + } |
312 | 319 | for (auto ®ion : op->getRegions()) { |
313 | 320 | for (auto &block : region) { |
314 | 321 | for (auto blockArg : llvm::enumerate(block.getArguments())) { |
315 | 322 | if (getLiveness(blockArg.value())) |
316 | 323 | continue; |
317 | | - LDBG() << "Block argument: " << blockArg.index() << " of " |
318 | | - << OpWithFlags(op, OpPrintingFlags().skipRegions()) |
319 | | - << " has no liveness info, mark dead"; |
320 | | - solver.getOrCreateState<Liveness>(blockArg.value()); |
| 324 | + if (llvm::find(mustLiveValues, blockArg.value())) { |
| 325 | + LDBG() << "Block argument: " << blockArg.index() << " of " |
| 326 | + << OpWithFlags(op, OpPrintingFlags().skipRegions()) |
| 327 | + << " is must value, mark live"; |
| 328 | + (void)solver.getOrCreateState<Liveness>(blockArg.value()) |
| 329 | + ->markLive(); |
| 330 | + } else { |
| 331 | + LDBG() << "Block argument: " << blockArg.index() << " of " |
| 332 | + << OpWithFlags(op, OpPrintingFlags().skipRegions()) |
| 333 | + << " has no liveness info, mark dead"; |
| 334 | + solver.getOrCreateState<Liveness>(blockArg.value()); |
| 335 | + } |
321 | 336 | } |
322 | 337 | } |
323 | 338 | } |
|
0 commit comments