diff --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td --- a/mlir/include/mlir/IR/OpBase.td +++ b/mlir/include/mlir/IR/OpBase.td @@ -845,6 +845,16 @@ 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 --- a/mlir/test/IR/attribute.mlir +++ b/mlir/test/IR/attribute.mlir @@ -8,6 +8,8 @@ "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 diff --git a/mlir/test/lib/Dialect/Test/TestOps.td b/mlir/test/lib/Dialect/Test/TestOps.td --- a/mlir/test/lib/Dialect/Test/TestOps.td +++ b/mlir/test/lib/Dialect/Test/TestOps.td @@ -199,6 +199,7 @@ def IntAttrOp : TEST_Op<"int_attrs"> { let arguments = (ins AnyI32Attr:$any_i32_attr, + IndexAttr:$index_attr, UI32Attr:$ui32_attr, SI32Attr:$si32_attr );