[HW] Enable parametric polymorphism for module parameters #8040
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The current implementation of parametric polymorphism in modules, as described in the CIRCT documentation, supports input and output types but does not extend to parameters.
For example, given a parameter
<DATA_WIDTH: i32>
, it is possible to define an argument likein %input : !hw.int<#hw.param.decl.ref<"DATA_WIDTH">>
, but it is not possible to define a parameter such as<RESET_VALUE: !hw.int<#hw.param.decl.ref<"DATA_WIDTH">>>
Consider the following code snippet:
In this example, with the parameter
DATA_WIDTH: i32 = 96
, the argumentin %input
of typehw.int<#hw.param.decl.ref<"DATA_WIDTH">>
is correctly matched withinput: %input: i96
through a simple substitution. However,circt-opt
fails to recognize thatRESET_VALUE: i96
is the equivalent toRESET_VALUE: !hw.int<#hw.param.decl.ref<"DATA_WIDTH">>
. Instead it emits the following error message:This issue can be reproduced using the following demo: Godbolt Link.
My proposed PR addresses this limitation and enables parametric polymorphism for module parameters, ensuring that types like
!hw.int<#hw.param.decl.ref<"DATA_WIDTH">>
are correctly recognized and validated.