@@ -190,7 +190,6 @@ class IRRewrite {
190
190
// Block rewrites
191
191
CreateBlock,
192
192
EraseBlock,
193
- InlineBlock,
194
193
MoveBlock,
195
194
BlockTypeConversion,
196
195
ReplaceBlockArg,
@@ -330,47 +329,6 @@ class EraseBlockRewrite : public BlockRewrite {
330
329
Block *insertBeforeBlock;
331
330
};
332
331
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
-
374
332
// / Moving of a block. This rewrite is immediately reflected in the IR.
375
333
class MoveBlockRewrite : public BlockRewrite {
376
334
public:
@@ -858,10 +816,6 @@ struct ConversionPatternRewriterImpl : public RewriterBase::Listener {
858
816
void notifyBlockInserted (Block *block, Region *previous,
859
817
Region::iterator previousIt) override ;
860
818
861
- // / Notifies that a block is being inlined into another block.
862
- void notifyBlockBeingInlined (Block *block, Block *srcBlock,
863
- Block::iterator before);
864
-
865
819
// / Notifies that a pattern match failed for the given reason.
866
820
void
867
821
notifyMatchFailure (Location loc,
@@ -1494,11 +1448,6 @@ void ConversionPatternRewriterImpl::notifyBlockInserted(
1494
1448
appendRewrite<MoveBlockRewrite>(block, previous, prevBlock);
1495
1449
}
1496
1450
1497
- void ConversionPatternRewriterImpl::notifyBlockBeingInlined (
1498
- Block *block, Block *srcBlock, Block::iterator before) {
1499
- appendRewrite<InlineBlockRewrite>(block, srcBlock, before);
1500
- }
1501
-
1502
1451
void ConversionPatternRewriterImpl::notifyMatchFailure (
1503
1452
Location loc, function_ref<void (Diagnostic &)> reasonCallback) {
1504
1453
LLVM_DEBUG ({
@@ -1649,10 +1598,18 @@ void ConversionPatternRewriter::inlineBlockBefore(Block *source, Block *dest,
1649
1598
" expected 'source' to have no predecessors" );
1650
1599
#endif // NDEBUG
1651
1600
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.
1653
1605
for (auto it : llvm::zip (source->getArguments (), argValues))
1654
1606
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.
1656
1613
eraseBlock (source);
1657
1614
}
1658
1615
0 commit comments