Skip to content

Commit 5515247

Browse files
committed
[FIRRTL] Fix TagExtractOp's type inference
TagExtractOp's type inference predates adding user-defined encodings for enums in FIRRTL. This fixes the issue by using the bitwidth helpers defined on the enumeration type.
1 parent 959e0f1 commit 5515247

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

lib/Dialect/FIRRTL/FIRRTLOps.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4863,8 +4863,7 @@ FIRRTLType SubaccessOp::inferReturnType(Type inType, Type indexType,
48634863
FIRRTLType TagExtractOp::inferReturnType(FIRRTLType input,
48644864
std::optional<Location> loc) {
48654865
auto inType = type_cast<FEnumType>(input);
4866-
auto i = llvm::Log2_32_Ceil(inType.getNumElements());
4867-
return UIntType::get(inType.getContext(), i);
4866+
return UIntType::get(inType.getContext(), inType.getTagWidth());
48684867
}
48694868

48704869
ParseResult MultibitMuxOp::parse(OpAsmParser &parser, OperationState &result) {

test/Dialect/FIRRTL/parse-basic.fir

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -961,10 +961,10 @@ circuit MyModule : ; CHECK: firrtl.circuit "MyModule"
961961

962962
; CHECK-LABEL: firrtl.module private @TagExtract
963963
module TagExtract:
964-
input i : {|A, B, C|}
965-
output o : UInt<2>
966-
; CHECK: %0 = firrtl.tagextract %i : !firrtl.enum<A, B, C>
967-
; CHECK: firrtl.matchingconnect %o, %0 : !firrtl.uint<2>
964+
input i : {|A, B, C = 8|}
965+
output o : UInt<4>
966+
; CHECK: %0 = firrtl.tagextract %i : !firrtl.enum<A, B, C = 8>
967+
; CHECK: firrtl.matchingconnect %o, %0 : !firrtl.uint<4>
968968
connect o, tagExtract(i)
969969

970970
; CHECK-LABEL: module private @RefsChild(

0 commit comments

Comments
 (0)