diff options
author | Matthias Springer <springerm@google.com> | 2024-02-28 13:52:22 +0000 |
---|---|---|
committer | Matthias Springer <springerm@google.com> | 2024-02-28 13:56:04 +0000 |
commit | 7e074504bc9e29acdd96c4ba5023cea5d7dc34c2 (patch) | |
tree | fde548a379fb9871e39ebed5e07a0fec497c6861 | |
parent | bb0ff1541092b54f81296350ce0e8a397673a105 (diff) | |
download | llvm-users/matthias-springer/inline_block_simplify.zip llvm-users/matthias-springer/inline_block_simplify.tar.gz llvm-users/matthias-springer/inline_block_simplify.tar.bz2 |
[mlir][Transforms][NFC] Remove InlineBlockRewriteusers/matthias-springer/inline_block_simplify
-rw-r--r-- | mlir/lib/Transforms/Utils/DialectConversion.cpp | 63 |
1 files changed, 10 insertions, 53 deletions
diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp index 2689930..b81495a 100644 --- a/mlir/lib/Transforms/Utils/DialectConversion.cpp +++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp @@ -190,7 +190,6 @@ public: // Block rewrites CreateBlock, EraseBlock, - InlineBlock, MoveBlock, BlockTypeConversion, ReplaceBlockArg, @@ -330,47 +329,6 @@ private: Block *insertBeforeBlock; }; -/// Inlining of a block. This rewrite is immediately reflected in the IR. -/// Note: This rewrite represents only the inlining of the operations. The -/// erasure of the inlined block is a separate rewrite. -class InlineBlockRewrite : public BlockRewrite { -public: - InlineBlockRewrite(ConversionPatternRewriterImpl &rewriterImpl, Block *block, - Block *sourceBlock, Block::iterator before) - : BlockRewrite(Kind::InlineBlock, rewriterImpl, block), - sourceBlock(sourceBlock), - firstInlinedInst(sourceBlock->empty() ? nullptr - : &sourceBlock->front()), - lastInlinedInst(sourceBlock->empty() ? nullptr : &sourceBlock->back()) { - } - - static bool classof(const IRRewrite *rewrite) { - return rewrite->getKind() == Kind::InlineBlock; - } - - void rollback() override { - // Put the operations from the destination block (owned by the rewrite) - // back into the source block. - if (firstInlinedInst) { - assert(lastInlinedInst && "expected operation"); - sourceBlock->getOperations().splice(sourceBlock->begin(), - block->getOperations(), - Block::iterator(firstInlinedInst), - ++Block::iterator(lastInlinedInst)); - } - } - -private: - // The block that originally contained the operations. - Block *sourceBlock; - - // The first inlined operation. - Operation *firstInlinedInst; - - // The last inlined operation. - Operation *lastInlinedInst; -}; - /// Moving of a block. This rewrite is immediately reflected in the IR. class MoveBlockRewrite : public BlockRewrite { public: @@ -858,10 +816,6 @@ struct ConversionPatternRewriterImpl : public RewriterBase::Listener { void notifyBlockInserted(Block *block, Region *previous, Region::iterator previousIt) override; - /// Notifies that a block is being inlined into another block. - void notifyBlockBeingInlined(Block *block, Block *srcBlock, - Block::iterator before); - /// Notifies that a pattern match failed for the given reason. void notifyMatchFailure(Location loc, @@ -1494,11 +1448,6 @@ void ConversionPatternRewriterImpl::notifyBlockInserted( appendRewrite<MoveBlockRewrite>(block, previous, prevBlock); } -void ConversionPatternRewriterImpl::notifyBlockBeingInlined( - Block *block, Block *srcBlock, Block::iterator before) { - appendRewrite<InlineBlockRewrite>(block, srcBlock, before); -} - void ConversionPatternRewriterImpl::notifyMatchFailure( Location loc, function_ref<void(Diagnostic &)> reasonCallback) { LLVM_DEBUG({ @@ -1649,10 +1598,18 @@ void ConversionPatternRewriter::inlineBlockBefore(Block *source, Block *dest, "expected 'source' to have no predecessors"); #endif // NDEBUG - impl->notifyBlockBeingInlined(dest, source, before); + // Replace all uses of block arguments. + // TODO: Support `replaceAllUsesWith` in the dialect conversion. Then this + // function no longer has to be overridden and can be turned into a + // non-virtual function. for (auto it : llvm::zip(source->getArguments(), argValues)) replaceUsesOfBlockArgument(std::get<0>(it), std::get<1>(it)); - dest->getOperations().splice(before, source->getOperations()); + + // Move op by op. + while (!source->empty()) + moveOpBefore(&source->front(), dest, before); + + // Erase the source block. eraseBlock(source); } |