[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.
This commit is contained in:
Matthias Springer
2025-07-03 16:36:59 +02:00
committed by GitHub
parent 522d743545
commit 34f124b06f
2 changed files with 2 additions and 2 deletions

View File

@@ -92,7 +92,7 @@ public:
auto step = rewriter.create<arith::ConstantIndexOp>(loc, 1);
auto loop =
rewriter.create<scf::ForOp>(loc, lowerBound, upperBound, step);
for (Operation &nested : *loop.getBody())
for (Operation &nested : make_early_inc_range(*loop.getBody()))
rewriter.eraseOp(&nested);
loopIvs.push_back(loop.getInductionVar());

View File

@@ -92,7 +92,7 @@ public:
auto step = rewriter.create<arith::ConstantIndexOp>(loc, 1);
auto loop =
rewriter.create<scf::ForOp>(loc, lowerBound, upperBound, step);
for (Operation &nested : *loop.getBody())
for (Operation &nested : make_early_inc_range(*loop.getBody()))
rewriter.eraseOp(&nested);
loopIvs.push_back(loop.getInductionVar());