[FIRRTL] TagExtract: make type inference parser friendly

This also changes TagExtract to use the simpler type inference
signatures used by other operations, which will be used when parsing
this operation from fir files.
This commit is contained in:
Andrew Young 2025-07-17 10:48:02 -07:00
parent e5c0e6f20f
commit 0b3976c12e
2 changed files with 17 additions and 6 deletions

View File

@ -540,6 +540,21 @@ def TagExtractOp : FIRRTLExprOp<"tagextract", [InferTypeOpInterface]> {
let arguments = (ins FEnumType:$input);
let results = (outs UIntType:$result);
let assemblyFormat = "$input attr-dict `:` qualified(type($input))";
let inferTypeDecl = [{
static FIRRTLType inferReturnType(FIRRTLType input,
std::optional<Location> loc);
static FIRRTLType inferReturnType(ValueRange operands,
DictionaryAttr attrs,
OpaqueProperties properties,
mlir::RegionRange regions,
std::optional<Location> loc) {
Adaptor adaptor(operands, attrs, properties, regions);
auto input = firrtl::type_cast<FIRRTLType>(adaptor.getInput().getType());
return inferReturnType(input, loc);
}
}];
}
def MultibitMuxOp : FIRRTLExprOp<"multibit_mux"> {

View File

@ -4860,13 +4860,9 @@ FIRRTLType SubaccessOp::inferReturnType(Type inType, Type indexType,
inType);
}
FIRRTLType TagExtractOp::inferReturnType(ValueRange operands,
DictionaryAttr attrs,
OpaqueProperties properties,
mlir::RegionRange regions,
FIRRTLType TagExtractOp::inferReturnType(FIRRTLType input,
std::optional<Location> loc) {
Adaptor adaptor(operands, attrs, properties, regions);
auto inType = type_cast<FEnumType>(adaptor.getInput().getType());
auto inType = type_cast<FEnumType>(input);
auto i = llvm::Log2_32_Ceil(inType.getNumElements());
return UIntType::get(inType.getContext(), i);
}