[Mlir-commits] [mlir] 34f124b - [mlir][toy] Use `make_early_inc_range` when erasing ops during iteration (#146892)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Jul 3 07:37:02 PDT 2025
Author: Matthias Springer
Date: 2025-07-03T16:36:59+02:00
New Revision: 34f124b06ffd3a4e5befafe3cf5daf7753f415ff
URL: https://github.com/llvm/llvm-project/commit/34f124b06ffd3a4e5befafe3cf5daf7753f415ff
DIFF: https://github.com/llvm/llvm-project/commit/34f124b06ffd3a4e5befafe3cf5daf7753f415ff.diff
LOG: [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.
Added:
Modified:
mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp
mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp
Removed:
################################################################################
diff --git a/mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp b/mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp
index de1eafc4d8678..22f75e042fe08 100644
--- a/mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp
+++ b/mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp
@@ -92,7 +92,7 @@ class PrintOpLowering : public ConversionPattern {
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());
diff --git a/mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp b/mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp
index a20a2c888a175..54eeb275ae85e 100644
--- a/mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp
+++ b/mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp
@@ -92,7 +92,7 @@ class PrintOpLowering : public ConversionPattern {
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());
More information about the Mlir-commits
mailing list