From 11f093fab4a38a652563cde52fcfa65ebcdc65e4 Mon Sep 17 00:00:00 2001 From: Ulysse Beaugnon Date: Thu, 16 Apr 2020 10:28:02 +0200 Subject: [PATCH] [MLIR] Add IndexAttr to primitive attributes kinds in tablegen. OpBase.td defined attributes kind for all integer types expect index. This commit fixes that by adding an IndexAttr attribute kind. Update the respective tests. Differential Revision: https://reviews.llvm.org/D78195 --- mlir/include/mlir/IR/OpBase.td | 10 ++++++++++ mlir/test/IR/attribute.mlir | 6 ++++++ mlir/test/lib/Dialect/Test/TestOps.td | 1 + 3 files changed, 17 insertions(+) diff --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td index e552279..14ef45e 100644 --- a/mlir/include/mlir/IR/OpBase.td +++ b/mlir/include/mlir/IR/OpBase.td @@ -845,6 +845,16 @@ def BoolAttr : Attr()">, "bool attribute"> { let constBuilderCall = "$_builder.getBoolAttr($0)"; } +// Index attribute. +def IndexAttr : + TypedAttrBase< + Index, "IntegerAttr", + And<[CPred<"$_self.isa()">, + CPred<"$_self.cast().getType().isa()">]>, + "index attribute"> { + let returnType = [{ APInt }]; +} + // Base class for any integer (regardless of signedness semantics) attributes // of fixed width. class AnyIntegerAttrBase : diff --git a/mlir/test/IR/attribute.mlir b/mlir/test/IR/attribute.mlir index 31804b2..81edebd 100644 --- a/mlir/test/IR/attribute.mlir +++ b/mlir/test/IR/attribute.mlir @@ -8,6 +8,8 @@ func @int_attrs_pass() { "test.int_attrs"() { // CHECK: any_i32_attr = 5 : ui32 any_i32_attr = 5 : ui32, + // CHECK-SAME: index_attr = 8 : index + index_attr = 8 : index, // CHECK-SAME: si32_attr = 7 : si32 si32_attr = 7 : si32, // CHECK-SAME: ui32_attr = 6 : ui32 @@ -17,6 +19,7 @@ func @int_attrs_pass() { "test.int_attrs"() { // CHECK: any_i32_attr = 5 : si32 any_i32_attr = 5 : si32, + index_attr = 8 : index, si32_attr = 7 : si32, ui32_attr = 6 : ui32 } : () -> () @@ -24,6 +27,7 @@ func @int_attrs_pass() { "test.int_attrs"() { // CHECK: any_i32_attr = 5 : i32 any_i32_attr = 5 : i32, + index_attr = 8 : index, si32_attr = 7 : si32, ui32_attr = 6 : ui32 } : () -> () @@ -122,6 +126,7 @@ func @wrong_int_attrs_signedness_fail() { // expected-error @+1 {{'si32_attr' failed to satisfy constraint: 32-bit signed integer attribute}} "test.int_attrs"() { any_i32_attr = 5 : i32, + index_attr = 8 : index, si32_attr = 7 : ui32, ui32_attr = 6 : ui32 } : () -> () @@ -134,6 +139,7 @@ func @wrong_int_attrs_signedness_fail() { // expected-error @+1 {{'ui32_attr' failed to satisfy constraint: 32-bit unsigned integer attribute}} "test.int_attrs"() { any_i32_attr = 5 : i32, + index_attr = 8 : index, si32_attr = 7 : si32, ui32_attr = 6 : si32 } : () -> () diff --git a/mlir/test/lib/Dialect/Test/TestOps.td b/mlir/test/lib/Dialect/Test/TestOps.td index 6f1ef4a..524780b 100644 --- a/mlir/test/lib/Dialect/Test/TestOps.td +++ b/mlir/test/lib/Dialect/Test/TestOps.td @@ -199,6 +199,7 @@ def I64EnumAttrOp : TEST_Op<"i64_enum_attr"> { def IntAttrOp : TEST_Op<"int_attrs"> { let arguments = (ins AnyI32Attr:$any_i32_attr, + IndexAttr:$index_attr, UI32Attr:$ui32_attr, SI32Attr:$si32_attr ); -- 2.7.4