[Mlir-commits] [mlir] [MLIR] Fix walk() after PostOrderTraversal change (PR #191357)
Alexis Engelke
llvmlistbot at llvm.org
Fri Apr 10 01:01:02 PDT 2026
https://github.com/aengelke created https://github.com/llvm/llvm-project/pull/191357
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.
>From f0c3a7a1281ab673080898c85ebf601c234e2bdd Mon Sep 17 00:00:00 2001
From: Alexis Engelke <engelke at in.tum.de>
Date: Fri, 10 Apr 2026 08:00:23 +0000
Subject: [PATCH] [spr] initial version
Created using spr 1.3.8-wip
---
mlir/include/mlir/IR/Visitors.h | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
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())
More information about the Mlir-commits
mailing list