Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIRRTL] Reconsider use of inferReturnType in FIRRTLExprs #6705

Open
mikeurbach opened this issue Feb 15, 2024 · 0 comments
Open

[FIRRTL] Reconsider use of inferReturnType in FIRRTLExprs #6705

mikeurbach opened this issue Feb 15, 2024 · 0 comments
Labels
FIRRTL Involving the `firrtl` dialect

Comments

@mikeurbach
Copy link
Contributor

We require FIRRTLExprs to define inferReturnType, which is used, for example, here:

auto resultTy = CLASS::inferReturnType(operands, attrs, {}); \

There is some ODS machinery to allow subclasses to customize this using inferTypeDecl and inferType:

// Give concrete operations a chance to set a type inference callback. If left
// empty, a declaration for `inferBinaryReturnType` will be emitted that the
// operation is expected to implement.
code inferType = "";
let inferTypeDecl = !if(!empty(inferType), [{
/// Infer the return type of this binary operation.
static FIRRTLType inferBinaryReturnType(FIRRTLType lhs, FIRRTLType rhs,
std::optional<Location> loc);
}], "") # !subst("$_infer", !if(!empty(inferType), "inferBinaryReturnType",
inferType), [{
/// Infer the return type of this operation.
static FIRRTLType inferReturnType(ValueRange operands,
ArrayRef<NamedAttribute> attrs,
std::optional<Location> loc) {
return $_infer(firrtl::type_cast<FIRRTLType>(operands[0].getType()),
firrtl::type_cast<FIRRTLType>(operands[1].getType()),
loc);
}
}]);

@uenoku pointed out on #6701 that we can probably just use methods from InferTypeOpInterface. All of this machinery seems to predate that existing, but we might be able to simplify it now.

@mikeurbach mikeurbach added the FIRRTL Involving the `firrtl` dialect label Feb 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FIRRTL Involving the `firrtl` dialect
Projects
None yet
Development

No branches or pull requests

1 participant