[ODS] Add definition for TypeAttr
authorLei Zhang <antiagainst@google.com>
Tue, 14 May 2019 16:08:41 +0000 (09:08 -0700)
committerMehdi Amini <joker.eph@gmail.com>
Mon, 20 May 2019 20:41:38 +0000 (13:41 -0700)
--

PiperOrigin-RevId: 248147938

mlir/include/mlir/IR/OpBase.td
mlir/test/mlir-tblgen/op-attribute.td

index 58e6867..21bce37 100644 (file)
@@ -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.
index 0272d0e..a72869d 100644 (file)
@@ -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
 // ---