Skip to content

Commit 94a562c

Browse files
committed
[FIRRTL] Erase empty layerblocks
Add a canonicalizer that will erase empty `firrtl.layerblock` ops. Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
1 parent dcd7c47 commit 94a562c

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

include/circt/Dialect/FIRRTL/FIRRTLStatements.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ def LayerBlockOp : FIRRTLOp<
403403
$layerName $region attr-dict
404404
}];
405405
let hasVerifier = 1;
406+
let hasCanonicalizeMethod = 1;
406407
}
407408

408409
#endif // CIRCT_DIALECT_FIRRTL_FIRRTLSTATEMENTS_TD

lib/Dialect/FIRRTL/FIRRTLFolds.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3410,3 +3410,19 @@ LogicalResult FPGAProbeIntrinsicOp::canonicalize(FPGAProbeIntrinsicOp op,
34103410
rewriter.eraseOp(op);
34113411
return success();
34123412
}
3413+
3414+
//===----------------------------------------------------------------------===//
3415+
// Layer Block Op
3416+
//===----------------------------------------------------------------------===//
3417+
3418+
LogicalResult LayerBlockOp::canonicalize(LayerBlockOp op,
3419+
PatternRewriter &rewriter) {
3420+
3421+
// If the layerblock is empty, erase it.
3422+
if (op.getBody()->empty()) {
3423+
rewriter.eraseOp(op);
3424+
return success();
3425+
}
3426+
3427+
return failure();
3428+
}

test/Dialect/FIRRTL/canonicalization.mlir

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
firrtl.circuit "Casts" {
44

5+
firrtl.layer @A bind {}
6+
57
// CHECK-LABEL: firrtl.module @Casts
68
firrtl.module @Casts(in %ui1 : !firrtl.uint<1>, in %si1 : !firrtl.sint<1>,
79
in %clock : !firrtl.clock, in %asyncreset : !firrtl.asyncreset,
@@ -3588,4 +3590,10 @@ firrtl.class @PropertyArithmetic(in %in: !firrtl.integer, out %out0: !firrtl.int
35883590
firrtl.propassign %out0, %3 : !firrtl.integer
35893591
firrtl.propassign %out1, %4 : !firrtl.integer
35903592
}
3593+
3594+
// CHECK-LABEL: firrtl.module private @LayerBlocks
3595+
firrtl.module private @LayerBlocks() {
3596+
// CHECK-NOT: firrtl.layerblock @A
3597+
firrtl.layerblock @A {}
3598+
}
35913599
}

0 commit comments

Comments
 (0)