Skip to content

Commit 1bf4f12

Browse files
add LoopLikeOpInterface visit logic in the visit function.
1 parent 55321b8 commit 1bf4f12

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

mlir/lib/Analysis/DataFlow/LivenessAnalysis.cpp

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,18 @@ void LivenessAnalysis::visitBranchOperand(OpOperand &operand) {
196196
break;
197197
}
198198
}
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+
}
199211
} else {
200212
// When the op is a `RegionBranchTerminatorOpInterface`, like an
201213
// `scf.condition` op or return-like, like an `scf.yield` op, its branch
@@ -310,29 +322,16 @@ RunLivenessAnalysis::RunLivenessAnalysis(Operation *op) {
310322
<< " has no liveness info (unreachable), mark dead";
311323
solver.getOrCreateState<Liveness>(result.value());
312324
}
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-
}
325+
319326
for (auto &region : op->getRegions()) {
320327
for (auto &block : region) {
321328
for (auto blockArg : llvm::enumerate(block.getArguments())) {
322329
if (getLiveness(blockArg.value()))
323330
continue;
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-
}
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());
336335
}
337336
}
338337
}

0 commit comments

Comments
 (0)