Skip to content

Commit

Permalink
[FIRRTL] Fix missing folding of sizeof for aggregates.
Browse files Browse the repository at this point in the history
  • Loading branch information
darthscsi committed May 1, 2024
1 parent acbee5d commit bdc8503
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/Dialect/FIRRTL/FIRRTLFolds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -958,9 +958,9 @@ OpFoldResult IntegerShrOp::fold(FoldAdaptor adaptor) {

OpFoldResult SizeOfIntrinsicOp::fold(FoldAdaptor) {
auto base = getInput().getType();
auto w = base.getBitWidthOrSentinel();
if (w >= 0)
return getIntAttr(getType(), APInt(32, w));
auto w = getBitWidth(base);
if (w)
return getIntAttr(getType(), APInt(32, *w));
return {};
}

Expand Down
20 changes: 20 additions & 0 deletions test/Dialect/FIRRTL/canonicalization.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -3463,6 +3463,7 @@ firrtl.module @Whens(in %clock: !firrtl.clock, in %a: !firrtl.uint<1>, in %reset
}
}

// CHECK-LABEL: Probes
firrtl.module @Probes(in %clock: !firrtl.clock) {
// CHECK-NOT: firrtl.int.fpga_probe %clock, %zero_width : !firrtl.uint<0>
%zero_width = firrtl.wire : !firrtl.uint<0>
Expand All @@ -3472,4 +3473,23 @@ firrtl.module @Probes(in %clock: !firrtl.clock) {
firrtl.int.fpga_probe %clock, %empty_bundle : !firrtl.bundle<a: uint<0>>
}

// CHECK-LABEL: sizeof
firrtl.module @sizeof(in %clock: !firrtl.clock,
in %vec: !firrtl.vector<uint<3>,3>,
in %bundle: !firrtl.bundle<a: uint<2>, b: uint<2>>) {
// CHECK: %c4_ui32 = firrtl.constant 4 : !firrtl.uint<32>
// CHECK: %c9_ui32 = firrtl.constant 9 : !firrtl.uint<32>
// CHECK: %c1_ui32 = firrtl.constant 1 : !firrtl.uint<32>
// CHECK: %n_c = firrtl.node interesting_name %c1_ui32
// CHECK: %n_vec = firrtl.node interesting_name %c9_ui32
// CHECK: %n_bundle = firrtl.node interesting_name %c4_ui32
%s_c = firrtl.int.sizeof %clock : (!firrtl.clock) -> !firrtl.uint<32>
%n_c = firrtl.node interesting_name %s_c : !firrtl.uint<32>
%s_vec = firrtl.int.sizeof %vec : (!firrtl.vector<uint<3>,3>) -> !firrtl.uint<32>
%n_vec = firrtl.node interesting_name %s_vec : !firrtl.uint<32>
%s_bundle = firrtl.int.sizeof %bundle : (!firrtl.bundle<a: uint<2>, b: uint<2>>) -> !firrtl.uint<32>
%n_bundle = firrtl.node interesting_name %s_bundle : !firrtl.uint<32>
}


}

0 comments on commit bdc8503

Please sign in to comment.