def StrAttr : StringBasedAttr<CPred<"$_self.isa<StringAttr>()">,
"string attribute">;
+// Base class for attributes containing types. Example:
+// def IntTypeAttr : TypeAttrBase<"IntegerType", "integer type attribute">
+// defines a type attribute containing an integer type.
+class TypeAttrBase<string retType, string description> :
+ Attr<And<[
+ CPred<"$_self.isa<TypeAttr>()">,
+ CPred<"$_self.cast<TypeAttr>().getValue().isa<" # retType # ">()">]>,
+ description> {
+ let storageType = [{ TypeAttr }];
+ let returnType = retType;
+ let convertFromStorage = "$_self.getValue().cast<" # retType # ">()";
+}
+
+def TypeAttr : TypeAttrBase<"Type", "any type attribute">;
+
// An enum attribute case.
class EnumAttrCase<string sym> : StringBasedAttr<
CPred<"$_self.cast<StringAttr>().getValue() == \"" # sym # "\"">,
def StrArrayAttr : TypedArrayAttrBase<StrAttr, "string array attribute"> {
let constBuilderCall = "$_builder.getStrArrayAttr($0)";
}
+def TypeArrayAttr : TypedArrayAttrBase<TypeAttr, "type array attribute"> {
+ let constBuilderCall = ?;
+}
// Attributes containing functions.
def FunctionAttr : Attr<CPred<"$_self.isa<FunctionAttr>()">,
let constBuilderCall = "$_builder.getFunctionAttr($0)";
}
-// Base class for attributes containing types. Example:
-// def IntTypeAttr : TypeAttrBase<"IntegerType", "integer type attribute">
-// defines a type attribute containing an integer type.
-class TypeAttrBase<string retType, string description> :
- Attr<And<[
- CPred<"$_self.isa<TypeAttr>()">,
- CPred<"$_self.cast<TypeAttr>().getValue().isa<" # retType # ">()">]>,
- description> {
- let storageType = [{ TypeAttr }];
- let returnType = retType;
- 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.
--- /dev/null
+// RUN: mlir-test-opt %s -split-input-file -verify | FileCheck %s
+
+//===----------------------------------------------------------------------===//
+// Test TypeArrayAttr
+//===----------------------------------------------------------------------===//
+
+func @correct_type_array_attr_pass() {
+ // CHECK: test.type_array_attr
+ "test.type_array_attr"() {attr: [i32, f32]} : () -> ()
+ return
+}
+
+// -----
+
+func @non_type_in_type_array_attr_fail() {
+ // expected-error @+1 {{'attr' failed to satisfy constraint: type array attribute}}
+ "test.type_array_attr"() {attr: [i32, 5: i64]} : () -> ()
+ return
+}