@@ -207,13 +207,13 @@ class IRRewrite {
207
207
// / Roll back the rewrite. Operations may be erased during rollback.
208
208
virtual void rollback () = 0;
209
209
210
- // / Commit the rewrite. Operations may be unlinked from their blocks during
211
- // / the commit phase, but they must not be erased yet. This is because
212
- // / internal dialect conversion state (such as `mapping`) may still be using
213
- // / them. Operations must be erased during cleanup.
210
+ // / Commit the rewrite. Operations/blocks may be unlinked during the commit
211
+ // / phase, but they must not be erased yet. This is because internal dialect
212
+ // / conversion state (such as `mapping`) may still be using them. Operations/
213
+ // / blocks must be erased during cleanup.
214
214
virtual void commit () {}
215
215
216
- // / Cleanup operations. Cleanup is called after commit.
216
+ // / Cleanup operations/blocks . Cleanup is called after commit.
217
217
virtual void cleanup () {}
218
218
219
219
Kind getKind () const { return kind; }
@@ -280,9 +280,9 @@ class CreateBlockRewrite : public BlockRewrite {
280
280
};
281
281
282
282
// / Erasure of a block. Block erasures are partially reflected in the IR. Erased
283
- // / blocks are immediately unlinked, but only erased when the rewrite is
284
- // / committed. This makes it easier to rollback a block erasure: the block is
285
- // / simply inserted into its original location.
283
+ // / blocks are immediately unlinked, but only erased during cleanup. This makes
284
+ // / it easier to rollback a block erasure: the block is simply inserted into its
285
+ // / original location.
286
286
class EraseBlockRewrite : public BlockRewrite {
287
287
public:
288
288
EraseBlockRewrite (ConversionPatternRewriterImpl &rewriterImpl, Block *block,
@@ -295,7 +295,8 @@ class EraseBlockRewrite : public BlockRewrite {
295
295
}
296
296
297
297
~EraseBlockRewrite () override {
298
- assert (!block && " rewrite was neither rolled back nor committed" );
298
+ assert (!block &&
299
+ " rewrite was neither rolled back nor committed/cleaned up" );
299
300
}
300
301
301
302
void rollback () override {
@@ -310,7 +311,7 @@ class EraseBlockRewrite : public BlockRewrite {
310
311
block = nullptr ;
311
312
}
312
313
313
- void commit () override {
314
+ void cleanup () override {
314
315
// Erase the block.
315
316
assert (block && " expected block" );
316
317
assert (block->empty () && " expected empty block" );
@@ -438,6 +439,8 @@ class BlockTypeConversionRewrite : public BlockRewrite {
438
439
439
440
void commit () override ;
440
441
442
+ void cleanup () override ;
443
+
441
444
void rollback () override ;
442
445
443
446
private:
@@ -985,7 +988,9 @@ void BlockTypeConversionRewrite::commit() {
985
988
rewriterImpl.mapping .lookupOrDefault (castValue, origArg.getType ()));
986
989
}
987
990
}
991
+ }
988
992
993
+ void BlockTypeConversionRewrite::cleanup () {
989
994
assert (origBlock->empty () && " expected empty block" );
990
995
origBlock->dropAllDefinedValueUses ();
991
996
delete origBlock;
@@ -1483,6 +1488,11 @@ void ConversionPatternRewriterImpl::notifyBlockInserted(
1483
1488
Block *block, Region *previous, Region::iterator previousIt) {
1484
1489
assert (!wasOpReplaced (block->getParentOp ()) &&
1485
1490
" attempting to insert into a region within a replaced/erased op" );
1491
+ LLVM_DEBUG ({
1492
+ logger.startLine () << " ** Insert Block into : '"
1493
+ << block->getParentOp ()->getName () << " '("
1494
+ << block->getParentOp () << " )\n " ;
1495
+ });
1486
1496
1487
1497
if (!previous) {
1488
1498
// This is a newly created block.
0 commit comments