Skip to content

Commit 34f124b

Browse files
[mlir][toy] Use make_early_inc_range when erasing ops during iteration (#146892)
Use `make_early_inc_range` when erasing operations from a block to make sure that the iterator is not invalidated. The previous implementation happened to work on a "normal" dialect conversion because some IR modifications are delayed. It no longer works with a One-Shot Dialect Conversion. The new One-Shot Dialect Conversion API is more similar to the normal rewriter API.
1 parent 522d743 commit 34f124b

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class PrintOpLowering : public ConversionPattern {
9292
auto step = rewriter.create<arith::ConstantIndexOp>(loc, 1);
9393
auto loop =
9494
rewriter.create<scf::ForOp>(loc, lowerBound, upperBound, step);
95-
for (Operation &nested : *loop.getBody())
95+
for (Operation &nested : make_early_inc_range(*loop.getBody()))
9696
rewriter.eraseOp(&nested);
9797
loopIvs.push_back(loop.getInductionVar());
9898

mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class PrintOpLowering : public ConversionPattern {
9292
auto step = rewriter.create<arith::ConstantIndexOp>(loc, 1);
9393
auto loop =
9494
rewriter.create<scf::ForOp>(loc, lowerBound, upperBound, step);
95-
for (Operation &nested : *loop.getBody())
95+
for (Operation &nested : make_early_inc_range(*loop.getBody()))
9696
rewriter.eraseOp(&nested);
9797
loopIvs.push_back(loop.getInductionVar());
9898

0 commit comments

Comments
 (0)