Skip to content

Commit a792cb6

Browse files
[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.
1 parent 237a799 commit a792cb6

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

mlir/include/mlir/IR/Builders.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ class OpBuilder : public Builder {
530530
// Fold the operation. If successful erase it, otherwise notify.
531531
if (succeeded(tryFold(op, results)))
532532
op->erase();
533-
else if (listener)
533+
else if (block && listener)
534534
listener->notifyOperationInserted(op, /*previous=*/{});
535535
}
536536

mlir/lib/IR/Builders.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,11 +408,11 @@ AffineMap Builder::getShiftedAffineMap(AffineMap map, int64_t shift) {
408408

409409
/// Insert the given operation at the current insertion point and return it.
410410
Operation *OpBuilder::insert(Operation *op) {
411-
if (block)
411+
if (block) {
412412
block->getOperations().insert(insertPoint, op);
413-
414-
if (listener)
415-
listener->notifyOperationInserted(op, /*previous=*/{});
413+
if (listener)
414+
listener->notifyOperationInserted(op, /*previous=*/{});
415+
}
416416
return op;
417417
}
418418

0 commit comments

Comments
 (0)