[Mlir-commits] [mlir] [mlir][IR] Add rewriter API for moving operations (PR #78988)
Matthias Springer
llvmlistbot at llvm.org
Mon Jan 22 07:47:37 PST 2024
================
@@ -285,12 +286,17 @@ class OpBuilder : public Builder {
virtual ~Listener() = default;
- /// Notification handler for when an operation is inserted into the builder.
- /// `op` is the operation that was inserted.
- virtual void notifyOperationInserted(Operation *op) {}
-
- /// Notification handler for when a block is created using the builder.
- /// `block` is the block that was created.
+ /// Notify the listener that the specified operation was inserted.
+ ///
+ /// * If the operation was moved, then `previous` is the previous location
+ /// of the op.
+ /// * If the operation was unlinked before it was inserted, then `previous`
+ /// is empty.
+ ///
+ /// Note: Creating an (unlinked) op does not trigger this notification.
+ virtual void notifyOperationInserted(Operation *op, InsertPoint previous) {}
----------------
matthias-springer wrote:
Note: This is similar to what was proposed [here (IR listeners)](https://discourse.llvm.org/t/rfc-introduce-the-concept-of-ir-listeners-in-mlir/67854), but the callback is fired *after* the IR was modified.
```c++
// This method is called when an operation is inserted into a block. The oldBlock is nullptr is the operation wasn't previously in a block.
virtual void notifyOpInserted(Operation *op, Block *oldBlock,
Block *newBlock) {}
```
https://github.com/llvm/llvm-project/pull/78988
More information about the Mlir-commits
mailing list