Skip to content

Conversation

@milos1397
Copy link

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

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.
@github-actions
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added the mlir label Dec 12, 2025
@llvmbot
Copy link
Member

llvmbot commented Dec 12, 2025

@llvm/pr-subscribers-mlir

Author: Miloš Poletanović (milos1397)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/172016.diff

2 Files Affected:

  • (added) mlir/test/Dialect/Transform/transform-dialect-erase-schedule.mlir (+15)
  • (modified) mlir/test/lib/Dialect/Transform/TestTransformDialectInterpreter.cpp (+6-1)
diff --git a/mlir/test/Dialect/Transform/transform-dialect-erase-schedule.mlir b/mlir/test/Dialect/Transform/transform-dialect-erase-schedule.mlir
new file mode 100644
index 0000000000000..a258568d8679b
--- /dev/null
+++ b/mlir/test/Dialect/Transform/transform-dialect-erase-schedule.mlir
@@ -0,0 +1,15 @@
+// RUN: mlir-opt %s -test-transform-dialect-erase-schedule | FileCheck %s
+
+module attributes {transform.with_named_sequence} {
+    func.func @transform_example(%arg0: !transform.any_op) {
+        %transform_copy = transform.structured.match ops{["linalg.copy"]} in %arg0 : (!transform.any_op) -> !transform.any_op
+        transform.nvgpu.rewrite_copy_as_tma %transform_copy : (!transform.any_op) -> ()
+        transform.yield
+    }
+}
+
+// CHECK-LABEL: module attributes {transform.with_named_sequence} {
+// CHECK-NEXT: func.func @transform_example(%arg0: !transform.any_op) {
+// CHECK-NEXT: transform.yield
+// CHECK-NEXT: }
+// CHECK-NEXT: }
\ No newline at end of file
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants