mlir-tblgen has enough information to automatically generate the verify()
function for some attributes and types. (The canonical example might be checking
whether or not an integer value is one of the specified enum values for enum
attributes.)
Previously, the genVerifyDecl field was used to instruct mlir-tblgen to
generate a declaration for the verify() function, and users would be required
to provide the implementation. This diff adds the capability to specify a
verify() function directly in the mlir-tblgen input (ODS) file.
This is accomplished by duplicating the existing mlir-tblgen logic for code
generation of get() methods via the builders field, and modifying it
slightly to generate verify() methods. As such:
- the TablgGen Builder class was renamed to MethodSpec (for "method specification") to reflect a more general usage
- a verifiers field was added to the AttrOrTypeDef base class
- the EnumAttr class was modified to provide a custom verify() implementation for integer and bit enum attributes
- tests were added for integer and bit enums to verify that getChecked() will return a null attribute for invalid enum values
The existing genVerifyDecl behavior is maintained, and attributes/types will
only behave differently if a non-empty verifiers field is present.
This functionality is expected to be used by a subsequent diff that adds Python
bindings for enums, and will also be used for fastmath support in the
Arithmetic dialect.