diff options
author | Matthias Springer <me@m-sp.org> | 2024-01-25 11:01:28 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-25 11:01:28 +0100 |
commit | 5cc0f76d34c7d00fa3e4ff01efe24d5de592e82c (patch) | |
tree | 04291163fb3678c3cd546d04045efe8d69591c7b /mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp | |
parent | 45fec0c110cccd5e0c9b60d51bc2ffc1645c9a40 (diff) | |
download | llvm-5cc0f76d34c7d00fa3e4ff01efe24d5de592e82c.zip llvm-5cc0f76d34c7d00fa3e4ff01efe24d5de592e82c.tar.gz llvm-5cc0f76d34c7d00fa3e4ff01efe24d5de592e82c.tar.bz2 |
[mlir][IR] Add rewriter API for moving operations (#78988)
The pattern rewriter documentation states that "*all* IR mutations [...]
are required to be performed via the `PatternRewriter`." This commit
adds two functions that were missing from the rewriter API:
`moveOpBefore` and `moveOpAfter`.
After an operation was moved, the `notifyOperationInserted` callback is
triggered. This allows listeners such as the greedy pattern rewrite
driver to react to IR changes.
This commit narrows the discrepancy between the kind of IR modification
that can be performed and the kind of IR modifications that can be
listened to.
Diffstat (limited to 'mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp')
-rw-r--r-- | mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp b/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp index ac73e82b..c27fee7 100644 --- a/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp +++ b/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp @@ -133,9 +133,16 @@ protected: } } - void notifyOperationInserted(Operation *op) override { - RewriterBase::ForwardingListener::notifyOperationInserted(op); + void notifyOperationInserted(Operation *op, InsertPoint previous) override { + RewriterBase::ForwardingListener::notifyOperationInserted(op, previous); + // Invalidate the finger print of the op that owns the block into which the + // op was inserted into. invalidateFingerPrint(op->getParentOp()); + + // Also invalidate the finger print of the op that owns the block from which + // the op was moved from. (Only applicable if the op was moved.) + if (previous.isSet()) + invalidateFingerPrint(previous.getBlock()->getParentOp()); } void notifyOperationModified(Operation *op) override { @@ -331,7 +338,7 @@ protected: /// Notify the driver that the specified operation was inserted. Update the /// worklist as needed: The operation is enqueued depending on scope and /// strict mode. - void notifyOperationInserted(Operation *op) override; + void notifyOperationInserted(Operation *op, InsertPoint previous) override; /// Notify the driver that the specified operation was removed. Update the /// worklist as needed: The operation and its children are removed from the @@ -641,13 +648,14 @@ void GreedyPatternRewriteDriver::notifyBlockRemoved(Block *block) { config.listener->notifyBlockRemoved(block); } -void GreedyPatternRewriteDriver::notifyOperationInserted(Operation *op) { +void GreedyPatternRewriteDriver::notifyOperationInserted(Operation *op, + InsertPoint previous) { LLVM_DEBUG({ logger.startLine() << "** Insert : '" << op->getName() << "'(" << op << ")\n"; }); if (config.listener) - config.listener->notifyOperationInserted(op); + config.listener->notifyOperationInserted(op, previous); if (config.strictMode == GreedyRewriteStrictness::ExistingAndNewOps) strictModeFilteredOps.insert(op); addToWorklist(op); |