[Mlir-commits] [mlir] d9b021d - [MLIR][Transform] Safely erase transform ops by collecting first (#172016)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Dec 22 02:51:26 PST 2025


Author: Miloš Poletanović
Date: 2025-12-22T11:51:22+01:00
New Revision: d9b021d33a3197aecbcf070b182abc9dbcddf204

URL: https://github.com/llvm/llvm-project/commit/d9b021d33a3197aecbcf070b182abc9dbcddf204
DIFF: https://github.com/llvm/llvm-project/commit/d9b021d33a3197aecbcf070b182abc9dbcddf204.diff

LOG: [MLIR][Transform] Safely erase transform ops by collecting first (#172016)

Avoids runtime crashes caused by deleting operations inside a walk.
Operations are gathered during the walk and then erased in the correct
dependency order after the walk finishes.

Issue: [#130023](https://github.com/llvm/llvm-project/issues/130023)

---------

Co-authored-by: Milos Poletanovic <mpoletanovic at syrmia.com>
Co-authored-by: Milos Poletanovic <milos.poletanovic at htecgroup.com>

Added: 
    

Modified: 
    mlir/test/lib/Dialect/Transform/TestTransformDialectInterpreter.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/test/lib/Dialect/Transform/TestTransformDialectInterpreter.cpp b/mlir/test/lib/Dialect/Transform/TestTransformDialectInterpreter.cpp
index 1273414cd4dfc..bd2de68fb276d 100644
--- a/mlir/test/lib/Dialect/Transform/TestTransformDialectInterpreter.cpp
+++ b/mlir/test/lib/Dialect/Transform/TestTransformDialectInterpreter.cpp
@@ -36,13 +36,18 @@ struct TestTransformDialectEraseSchedulePass
   }
 
   void runOnOperation() override {
+    SmallVector<Operation *> opsToDelete;
     getOperation()->walk<WalkOrder::PreOrder>([&](Operation *nestedOp) {
       if (isa<transform::TransformOpInterface>(nestedOp)) {
-        nestedOp->erase();
+        opsToDelete.push_back(nestedOp);
         return WalkResult::skip();
       }
       return WalkResult::advance();
     });
+    for (Operation *op : llvm::reverse(opsToDelete)) {
+      // erase the operation
+      op->erase();
+    }
   }
 };
 } // namespace


        


More information about the Mlir-commits mailing list