[Mlir-commits] [mlir] [MLIR] Fix walk() after PostOrderTraversal change (PR #191357)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Apr 10 01:01:35 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-core
Author: Alexis Engelke (aengelke)
<details>
<summary>Changes</summary>
make_early_inc_range doesn't keep the range alive, only the iterators.
This breaks with the recent PostOrderTraversal change, which no longer
stores the state in the iterators. Store the range in a variable to keep
it alive for the entire loop.
Fixup of #<!-- -->191047 / 691a130e0f14459d9358a71ffd52a01295e6200a.
---
Full diff: https://github.com/llvm/llvm-project/pull/191357.diff
1 Files Affected:
- (modified) mlir/include/mlir/IR/Visitors.h (+6-4)
``````````diff
diff --git a/mlir/include/mlir/IR/Visitors.h b/mlir/include/mlir/IR/Visitors.h
index 893f66ae33deb..907f470c0d248 100644
--- a/mlir/include/mlir/IR/Visitors.h
+++ b/mlir/include/mlir/IR/Visitors.h
@@ -120,8 +120,9 @@ void walk(Operation *op, function_ref<void(Block *)> callback,
WalkOrder order) {
for (auto ®ion : Iterator::makeIterable(*op)) {
// Early increment here in the case where the block is erased.
- for (auto &block :
- llvm::make_early_inc_range(Iterator::makeIterable(region))) {
+ // PostOrderTraversal keeps state outside of iterators, so store it here.
+ auto &&It = Iterator::makeIterable(region);
+ for (auto &block : llvm::make_early_inc_range(It)) {
if (order == WalkOrder::PreOrder)
callback(&block);
for (auto &nestedOp : Iterator::makeIterable(block))
@@ -195,8 +196,9 @@ WalkResult walk(Operation *op, function_ref<WalkResult(Block *)> callback,
WalkOrder order) {
for (auto ®ion : Iterator::makeIterable(*op)) {
// Early increment here in the case where the block is erased.
- for (auto &block :
- llvm::make_early_inc_range(Iterator::makeIterable(region))) {
+ // PostOrderTraversal keeps state outside of iterators, so store it here.
+ auto &&It = Iterator::makeIterable(region);
+ for (auto &block : llvm::make_early_inc_range(It)) {
if (order == WalkOrder::PreOrder) {
WalkResult result = callback(&block);
if (result.wasSkipped())
``````````
</details>
https://github.com/llvm/llvm-project/pull/191357
More information about the Mlir-commits
mailing list