[FIRRTL] Enums: Add user-defined constructor encodings #8724
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.
This adds the ability to specify the constants used to encode enumeration variants in the tag. For example,
The values can be unspecified, in which case it defaults to one higher than the previous value, or zero if it is the first value. For example, these two enumerations are the same:
{| A = 0, B = 1 |} == {| A, B |}In FIRRTL, Two enumeration types are considered equal if they have the same variants with the same values and data, without regard to variant order. Internally in FIRRTL dialect IR, enumerations types must have the variants sorted from low to high. For example the following two enumeration types are equivalent:
{| B = 1, A = 0 |} == {| A, B |}The mlir syntax has been updated to ellide the the tag values and data types if they are implicit. For example, the first type would be roundtripped to the second type:
Enumerations are no longer lowered to SystemVerilog enumerations, but to regular integer types. This is for a variety of reasons, but mainly because enumerations in SV are nominal and it was not a good fit for our structural enumerations.
In LowerToHW, the
firrtl.istagoperation lowers to a comparison to a constant value created with a localparam, which can show up in the output depending on how the module is optimized. The FIRRTL code below,produces: