[Mlir-commits] [mlir] a792cb6 - [mlir][IR] Do not trigger `notifyOperationInserted` for unlinked ops (#80278)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Feb 2 00:50:01 PST 2024


Author: Matthias Springer
Date: 2024-02-02T09:49:58+01:00
New Revision: a792cb6e3e03aff22dabb6cc94db68d15d953a55

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

LOG: [mlir][IR] Do not trigger `notifyOperationInserted` for unlinked ops (#80278)

This commit changes `OpBuilder::create` and `OpBuilder::createOrFold`
such that `notifyOperationInserted` is no longer triggered if no
insertion point is set. In such a case, an unlinked operation is created
but not inserted, so `notifyOperationInserted` should not be triggered.

Note: Inserting another op into a block that belongs to an unlinked op
(e.g., by the builder of the unlinked op) will trigger a notification.

Added: 
    

Modified: 
    mlir/include/mlir/IR/Builders.h
    mlir/lib/IR/Builders.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/IR/Builders.h b/mlir/include/mlir/IR/Builders.h
index 8c25a1aa2fad1..4fc29c65f2e68 100644
--- a/mlir/include/mlir/IR/Builders.h
+++ b/mlir/include/mlir/IR/Builders.h
@@ -530,7 +530,7 @@ class OpBuilder : public Builder {
     // Fold the operation. If successful erase it, otherwise notify.
     if (succeeded(tryFold(op, results)))
       op->erase();
-    else if (listener)
+    else if (block && listener)
       listener->notifyOperationInserted(op, /*previous=*/{});
   }
 

diff  --git a/mlir/lib/IR/Builders.cpp b/mlir/lib/IR/Builders.cpp
index 589d41de9b8bc..e7725a1d9fd2a 100644
--- a/mlir/lib/IR/Builders.cpp
+++ b/mlir/lib/IR/Builders.cpp
@@ -408,11 +408,11 @@ AffineMap Builder::getShiftedAffineMap(AffineMap map, int64_t shift) {
 
 /// Insert the given operation at the current insertion point and return it.
 Operation *OpBuilder::insert(Operation *op) {
-  if (block)
+  if (block) {
     block->getOperations().insert(insertPoint, op);
-
-  if (listener)
-    listener->notifyOperationInserted(op, /*previous=*/{});
+    if (listener)
+      listener->notifyOperationInserted(op, /*previous=*/{});
+  }
   return op;
 }
 


        


More information about the Mlir-commits mailing list