From 7e074504bc9e29acdd96c4ba5023cea5d7dc34c2 Mon Sep 17 00:00:00 2001 From: Matthias Springer Date: Wed, 28 Feb 2024 13:52:22 +0000 Subject: [mlir][Transforms][NFC] Remove InlineBlockRewrite --- mlir/lib/Transforms/Utils/DialectConversion.cpp | 63 ++++--------------------- 1 file 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(block, previous, prevBlock); } -void ConversionPatternRewriterImpl::notifyBlockBeingInlined( - Block *block, Block *srcBlock, Block::iterator before) { - appendRewrite(block, srcBlock, before); -} - void ConversionPatternRewriterImpl::notifyMatchFailure( Location loc, function_ref 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); } -- cgit v1.1