Skip to content

Commit 9b2eb37

Browse files
[mlir][Transforms][NFC] Remove SplitBlockRewrite
When splitting a block during a dialect conversion, a `SplitBlockRewrite` object is stored in the dialect conversion state. This commit removes `SplitBlockRewrite`. Instead, a combination of `CreateBlockRewrite` and multiple `MoveOperationRewrite` is used. This change simplifies the internal state of the dialect conversion and is also needed to properly support listeners. `RewriteBase::splitBlock` is now no longer virtual. All necessary information for committing/rolling back a split block rewrite can be deduced from `Listener::notifyBlockInserted` and `Listener::notifyOperationInserted` (which is also called when moving an operation).
1 parent 3b232f0 commit 9b2eb37

File tree

3 files changed

+1
-44
lines changed

3 files changed

+1
-44
lines changed

mlir/include/mlir/IR/PatternMatch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ class RewriterBase : public OpBuilder {
579579

580580
/// Split the operations starting at "before" (inclusive) out of the given
581581
/// block into a new block, and return it.
582-
virtual Block *splitBlock(Block *block, Block::iterator before);
582+
Block *splitBlock(Block *block, Block::iterator before);
583583

584584
/// Unlink this operation from its current block and insert it right before
585585
/// `existingOp` which may be in the same or another block in the same

mlir/include/mlir/Transforms/DialectConversion.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -741,9 +741,6 @@ class ConversionPatternRewriter final : public PatternRewriter {
741741
/// implemented for dialect conversion.
742742
void eraseBlock(Block *block) override;
743743

744-
/// PatternRewriter hook for splitting a block into two parts.
745-
Block *splitBlock(Block *block, Block::iterator before) override;
746-
747744
/// PatternRewriter hook for inlining the ops of a block into another block.
748745
void inlineBlockBefore(Block *source, Block *dest, Block::iterator before,
749746
ValueRange argValues = std::nullopt) override;

mlir/lib/Transforms/Utils/DialectConversion.cpp

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ class IRRewrite {
189189
EraseBlock,
190190
InlineBlock,
191191
MoveBlock,
192-
SplitBlock,
193192
BlockTypeConversion,
194193
ReplaceBlockArg,
195194
// Operation rewrites
@@ -397,30 +396,6 @@ class MoveBlockRewrite : public BlockRewrite {
397396
Block *insertBeforeBlock;
398397
};
399398

400-
/// Splitting of a block. This rewrite is immediately reflected in the IR.
401-
class SplitBlockRewrite : public BlockRewrite {
402-
public:
403-
SplitBlockRewrite(ConversionPatternRewriterImpl &rewriterImpl, Block *block,
404-
Block *originalBlock)
405-
: BlockRewrite(Kind::SplitBlock, rewriterImpl, block),
406-
originalBlock(originalBlock) {}
407-
408-
static bool classof(const IRRewrite *rewrite) {
409-
return rewrite->getKind() == Kind::SplitBlock;
410-
}
411-
412-
void rollback() override {
413-
// Merge back the block that was split out.
414-
originalBlock->getOperations().splice(originalBlock->end(),
415-
block->getOperations());
416-
eraseBlock(block);
417-
}
418-
419-
private:
420-
// The original block from which this block was split.
421-
Block *originalBlock;
422-
};
423-
424399
/// This structure contains the information pertaining to an argument that has
425400
/// been converted.
426401
struct ConvertedArgInfo {
@@ -881,9 +856,6 @@ struct ConversionPatternRewriterImpl : public RewriterBase::Listener {
881856
void notifyBlockInserted(Block *block, Region *previous,
882857
Region::iterator previousIt) override;
883858

884-
/// Notifies that a block was split.
885-
void notifySplitBlock(Block *block, Block *continuation);
886-
887859
/// Notifies that a block is being inlined into another block.
888860
void notifyBlockBeingInlined(Block *block, Block *srcBlock,
889861
Block::iterator before);
@@ -1526,11 +1498,6 @@ void ConversionPatternRewriterImpl::notifyBlockInserted(
15261498
appendRewrite<MoveBlockRewrite>(block, previous, prevBlock);
15271499
}
15281500

1529-
void ConversionPatternRewriterImpl::notifySplitBlock(Block *block,
1530-
Block *continuation) {
1531-
appendRewrite<SplitBlockRewrite>(continuation, block);
1532-
}
1533-
15341501
void ConversionPatternRewriterImpl::notifyBlockBeingInlined(
15351502
Block *block, Block *srcBlock, Block::iterator before) {
15361503
appendRewrite<InlineBlockRewrite>(block, srcBlock, before);
@@ -1657,13 +1624,6 @@ ConversionPatternRewriter::getRemappedValues(ValueRange keys,
16571624
results);
16581625
}
16591626

1660-
Block *ConversionPatternRewriter::splitBlock(Block *block,
1661-
Block::iterator before) {
1662-
auto *continuation = block->splitBlock(before);
1663-
impl->notifySplitBlock(block, continuation);
1664-
return continuation;
1665-
}
1666-
16671627
void ConversionPatternRewriter::inlineBlockBefore(Block *source, Block *dest,
16681628
Block::iterator before,
16691629
ValueRange argValues) {

0 commit comments

Comments
 (0)