diff options
-rw-r--r-- | mlir/include/mlir/IR/OpBase.td | 2 | ||||
-rw-r--r-- | mlir/test/mlir-tblgen/op-attribute.td | 27 |
2 files changed, 25 insertions, 4 deletions
diff --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td index 58e6867f547..21bce37a25f 100644 --- a/mlir/include/mlir/IR/OpBase.td +++ b/mlir/include/mlir/IR/OpBase.td @@ -680,6 +680,8 @@ class TypeAttrBase<string retType, string description> : let convertFromStorage = "$_self.getValue().cast<" # retType # ">()"; } +def TypeAttr : TypeAttrBase<"Type", "any type attribute">; + // DerivedAttr are attributes whose value is computed from properties // of the operation. They do not require additional storage and are // materialized as needed. diff --git a/mlir/test/mlir-tblgen/op-attribute.td b/mlir/test/mlir-tblgen/op-attribute.td index 0272d0e2991..a72869de308 100644 --- a/mlir/test/mlir-tblgen/op-attribute.td +++ b/mlir/test/mlir-tblgen/op-attribute.td @@ -75,9 +75,6 @@ def AOp : NS_Op<"a_op", []> { def SomeTypeAttr : TypeAttrBase<"SomeType", "some type attribute">; -// Test common attribute kinds' constraints -// --- - def BOp : NS_Op<"b_op", []> { let arguments = (ins AnyAttr:$any_attr, @@ -91,10 +88,31 @@ def BOp : NS_Op<"b_op", []> { FunctionAttr:$function_attr, SomeTypeAttr:$type_attr, ArrayAttr:$array_attr, - TypedArrayAttrBase<SomeAttr, "SomeAttr array">:$some_attr_array + TypedArrayAttrBase<SomeAttr, "SomeAttr array">:$some_attr_array, + TypeAttr:$type_attr ); } +// Test common attribute kind getters' return types +// --- + +// CHECK: Attribute BOp::any_attr() +// CHECK: bool BOp::bool_attr() +// CHECK: APInt BOp::i32_attr() +// CHECK: APInt BOp::i64_attr() +// CHECK: APFloat BOp::f32_attr() +// CHECK: APFloat BOp::f64_attr() +// CHECK: StringRef BOp::str_attr() +// CHECK: ElementsAttr BOp::elements_attr() +// CHECK: Function *BOp::function_attr() +// CHECK: SomeType BOp::type_attr() +// CHECK: ArrayAttr BOp::array_attr() +// CHECK: ArrayAttr BOp::some_attr_array() +// CHECK: Type BOp::type_attr() + +// Test common attribute kinds' constraints +// --- + // CHECK-LABEL: BOp::verify // CHECK: if (!((true))) // CHECK: if (!((tblgen_bool_attr.isa<BoolAttr>()))) @@ -108,6 +126,7 @@ def BOp : NS_Op<"b_op", []> { // CHECK: if (!(((tblgen_type_attr.isa<TypeAttr>())) && ((tblgen_type_attr.cast<TypeAttr>().getValue().isa<SomeType>())))) // CHECK: if (!((tblgen_array_attr.isa<ArrayAttr>()))) // CHECK: if (!(((tblgen_some_attr_array.isa<ArrayAttr>())) && (llvm::all_of(tblgen_some_attr_array.cast<ArrayAttr>(), [](Attribute attr) { return (some-condition); })))) +// CHECK: if (!(((tblgen_type_attr.isa<TypeAttr>())) && ((tblgen_type_attr.cast<TypeAttr>().getValue().isa<Type>())))) // Test building constant values for array attribute kinds // --- |