Skip to content

Commit d81f19e

Browse files
update code.
1 parent e1cfe4d commit d81f19e

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

mlir/lib/Analysis/DataFlow/LivenessAnalysis.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ void LivenessAnalysis::visitBranchOperand(OpOperand &operand) {
137137
// Populating such blocks in `blocks`.
138138
bool mayLive = false;
139139
SmallVector<Block *, 4> blocks;
140-
if (isa<RegionBranchOpInterface>(op)) {
140+
SmallVector<BlockArgument> argumentNotOperand;
141+
if (auto regionBranchOp = dyn_cast<RegionBranchOpInterface>(op)) {
141142
if (op->getNumResults() != 0) {
142143
// This mark value of type 1.c liveness as may live, because the region
143144
// branch operation has a return value, and the non-forwarded operand can
@@ -169,20 +170,17 @@ void LivenessAnalysis::visitBranchOperand(OpOperand &operand) {
169170
// In the block of the successor block argument of RegionBranchOpInterface,
170171
// there may be arguments of RegionBranchOpInterface, such as the IV of
171172
// 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) {
173+
for (Region &region : op->getRegions()) {
174174
SmallVector<RegionSuccessor> successors;
175-
regionBranchOp.getSuccessorRegions(op->getRegion(i), successors);
175+
regionBranchOp.getSuccessorRegions(region, successors);
176176
for (RegionSuccessor successor : successors) {
177177
if (successor.isParent())
178178
continue;
179179
auto arguments = successor.getSuccessor()->getArguments();
180180
ValueRange regionInputs = successor.getSuccessorInputs();
181181
for (auto argument : arguments) {
182182
if (llvm::find(regionInputs, argument) == regionInputs.end()) {
183-
(void)getLatticeElement(argument)->markLive();
184-
LDBG() << "Marking RegionBranchOp's success argument live: "
185-
<< argument;
183+
argumentNotOperand.push_back(argument);
186184
}
187185
}
188186
}
@@ -246,13 +244,20 @@ void LivenessAnalysis::visitBranchOperand(OpOperand &operand) {
246244
Liveness *operandLiveness = getLatticeElement(operand.get());
247245
LDBG() << "Marking branch operand live: " << operand.get();
248246
propagateIfChanged(operandLiveness, operandLiveness->markLive());
247+
for (BlockArgument argument : argumentNotOperand) {
248+
Liveness *argumentLiveness = getLatticeElement(argument);
249+
LDBG() << "Marking RegionBranchOp's argument live: " << argument;
250+
propagateIfChanged(argumentLiveness, argumentLiveness->markLive());
251+
}
249252
}
250253

251254
// Now that we have checked for memory-effecting ops in the blocks of concern,
252255
// we will simply visit the op with this non-forwarded operand to potentially
253256
// mark it "live" due to type (1.a/3) liveness.
254257
SmallVector<Liveness *, 4> operandLiveness;
255258
operandLiveness.push_back(getLatticeElement(operand.get()));
259+
for (BlockArgument argument : argumentNotOperand)
260+
operandLiveness.push_back(getLatticeElement(argument));
256261
SmallVector<const Liveness *, 4> resultsLiveness;
257262
for (const Value result : op->getResults())
258263
resultsLiveness.push_back(getLatticeElement(result));

0 commit comments

Comments
 (0)