Skip to content

Commit 7e07450

Browse files
[mlir][Transforms][NFC] Remove InlineBlockRewrite
1 parent bb0ff15 commit 7e07450

File tree

1 file changed

+10
-53
lines changed

1 file changed

+10
-53
lines changed

mlir/lib/Transforms/Utils/DialectConversion.cpp

Lines changed: 10 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ class IRRewrite {
190190
// Block rewrites
191191
CreateBlock,
192192
EraseBlock,
193-
InlineBlock,
194193
MoveBlock,
195194
BlockTypeConversion,
196195
ReplaceBlockArg,
@@ -330,47 +329,6 @@ class EraseBlockRewrite : public BlockRewrite {
330329
Block *insertBeforeBlock;
331330
};
332331

333-
/// Inlining of a block. This rewrite is immediately reflected in the IR.
334-
/// Note: This rewrite represents only the inlining of the operations. The
335-
/// erasure of the inlined block is a separate rewrite.
336-
class InlineBlockRewrite : public BlockRewrite {
337-
public:
338-
InlineBlockRewrite(ConversionPatternRewriterImpl &rewriterImpl, Block *block,
339-
Block *sourceBlock, Block::iterator before)
340-
: BlockRewrite(Kind::InlineBlock, rewriterImpl, block),
341-
sourceBlock(sourceBlock),
342-
firstInlinedInst(sourceBlock->empty() ? nullptr
343-
: &sourceBlock->front()),
344-
lastInlinedInst(sourceBlock->empty() ? nullptr : &sourceBlock->back()) {
345-
}
346-
347-
static bool classof(const IRRewrite *rewrite) {
348-
return rewrite->getKind() == Kind::InlineBlock;
349-
}
350-
351-
void rollback() override {
352-
// Put the operations from the destination block (owned by the rewrite)
353-
// back into the source block.
354-
if (firstInlinedInst) {
355-
assert(lastInlinedInst && "expected operation");
356-
sourceBlock->getOperations().splice(sourceBlock->begin(),
357-
block->getOperations(),
358-
Block::iterator(firstInlinedInst),
359-
++Block::iterator(lastInlinedInst));
360-
}
361-
}
362-
363-
private:
364-
// The block that originally contained the operations.
365-
Block *sourceBlock;
366-
367-
// The first inlined operation.
368-
Operation *firstInlinedInst;
369-
370-
// The last inlined operation.
371-
Operation *lastInlinedInst;
372-
};
373-
374332
/// Moving of a block. This rewrite is immediately reflected in the IR.
375333
class MoveBlockRewrite : public BlockRewrite {
376334
public:
@@ -858,10 +816,6 @@ struct ConversionPatternRewriterImpl : public RewriterBase::Listener {
858816
void notifyBlockInserted(Block *block, Region *previous,
859817
Region::iterator previousIt) override;
860818

861-
/// Notifies that a block is being inlined into another block.
862-
void notifyBlockBeingInlined(Block *block, Block *srcBlock,
863-
Block::iterator before);
864-
865819
/// Notifies that a pattern match failed for the given reason.
866820
void
867821
notifyMatchFailure(Location loc,
@@ -1494,11 +1448,6 @@ void ConversionPatternRewriterImpl::notifyBlockInserted(
14941448
appendRewrite<MoveBlockRewrite>(block, previous, prevBlock);
14951449
}
14961450

1497-
void ConversionPatternRewriterImpl::notifyBlockBeingInlined(
1498-
Block *block, Block *srcBlock, Block::iterator before) {
1499-
appendRewrite<InlineBlockRewrite>(block, srcBlock, before);
1500-
}
1501-
15021451
void ConversionPatternRewriterImpl::notifyMatchFailure(
15031452
Location loc, function_ref<void(Diagnostic &)> reasonCallback) {
15041453
LLVM_DEBUG({
@@ -1649,10 +1598,18 @@ void ConversionPatternRewriter::inlineBlockBefore(Block *source, Block *dest,
16491598
"expected 'source' to have no predecessors");
16501599
#endif // NDEBUG
16511600

1652-
impl->notifyBlockBeingInlined(dest, source, before);
1601+
// Replace all uses of block arguments.
1602+
// TODO: Support `replaceAllUsesWith` in the dialect conversion. Then this
1603+
// function no longer has to be overridden and can be turned into a
1604+
// non-virtual function.
16531605
for (auto it : llvm::zip(source->getArguments(), argValues))
16541606
replaceUsesOfBlockArgument(std::get<0>(it), std::get<1>(it));
1655-
dest->getOperations().splice(before, source->getOperations());
1607+
1608+
// Move op by op.
1609+
while (!source->empty())
1610+
moveOpBefore(&source->front(), dest, before);
1611+
1612+
// Erase the source block.
16561613
eraseBlock(source);
16571614
}
16581615

0 commit comments

Comments
 (0)