[mlir][ODS] Add `ConstantEnumCase` (#78992)
Specifying an enum case of an enum attr currently requires the use of either `NativeCodeCall` or a `ConstantAttr` specifying the full C++ name of the enum case. The disadvantages of both are less readable code due to including C++ expressions and very few checks of any kind, creating C++ code that does not compile instead. This PR adds `ConstantEnumCase`, a kind of `ConstantAttr` which automatically derives the correct value representation from a given enum and the string representation of an enum case. It supports both `EnumAttrInfo`s (enums wrapping `IntegerAttr`) and `EnumAttr` (proper dialect attributes). It even supports bit-enums, allowing one to list multiple enum cases and have them be combined. If an enum case is not found, an assertion is triggered with a proper error message. Besides the tests, it was also used to simplify DRR patterns in the arith dialect.
Loading
Please sign in to comment