[mlir][ODS] Verify type constraint in `TypeAttrOf`
authorMarkus Böck <markus.boeck02@gmail.com>
Fri, 7 Apr 2023 10:29:55 +0000 (12:29 +0200)
committerMarkus Böck <markus.boeck02@gmail.com>
Fri, 7 Apr 2023 10:30:15 +0000 (12:30 +0200)
commitaa9ae76cac0443b7d70b27ae2c0bf9cf92f344d3
treed09fbab881655d892224adcf323a04913189cc1c
parentb2e98c18cc8abf2c1cc6a7f85c8708550cc8fd28
[mlir][ODS] Verify type constraint in `TypeAttrOf`

The current implementation does not verify the type constraint, meaning that any type that happens to be of the same C++ type would pass the verifier.
E.g. a `TypeAttrOf<I64>` would happily accept a `i32` since both satisfy `isa<IntegerType>()`.

This patch fixes that by adding an optional type predicate parameter to `TypeAttrBase` that the type within `TypeAttr` has to satisfy. `TypeAttrOf` then simply passes the predicate of its type parameter as argument.

Differential Revision: https://reviews.llvm.org/D147778
mlir/include/mlir/IR/OpBase.td
mlir/test/IR/attribute.mlir
mlir/test/lib/Dialect/Test/TestOps.td
mlir/test/mlir-tblgen/op-attribute.td