[ODS] Add new definitions for non-negative integer attributes

This CL added a new NonNegativeIntAttrBase class and two instantiations,
one for I32 and the other for I64.

PiperOrigin-RevId: 261513292
This commit is contained in:
Lei Zhang 2019-08-03 16:58:26 -07:00 committed by TensorFlower Gardener
parent 17d55101cc
commit 201b59fb55
2 changed files with 27 additions and 5 deletions
third_party/mlir
include/mlir/IR
test/lib/TestDialect

View File

@ -585,11 +585,12 @@ def BoolAttr : Attr<CPred<"$_self.isa<BoolAttr>()">, "bool attribute"> {
// Base class for integer attributes of fixed width.
class IntegerAttrBase<I attrValType, string descr> :
TypedAttrBase<attrValType, "IntegerAttr",
And<[CPred<"$_self.isa<IntegerAttr>()">,
CPred<"$_self.cast<IntegerAttr>().getType()."
"isInteger(" # attrValType.bitwidth # ")">]>,
descr> {
TypedAttrBase<
attrValType, "IntegerAttr",
And<[CPred<"$_self.isa<IntegerAttr>()">,
CPred<"$_self.cast<IntegerAttr>().getType()."
"isInteger(" # attrValType.bitwidth # ")">]>,
descr> {
let returnType = [{ APInt }];
}
@ -602,6 +603,20 @@ def APIntAttr : Attr<CPred<"$_self.isa<IntegerAttr>()">,
def I32Attr : IntegerAttrBase<I32, "32-bit integer attribute">;
def I64Attr : IntegerAttrBase<I64, "64-bit integer attribute">;
class NonNegativeIntAttrBase<I attrValType, string descr> :
TypedAttrBase<
attrValType, "IntegerAttr",
And<[IntegerAttrBase<attrValType, "">.predicate,
CPred<"!$_self.cast<IntegerAttr>().getValue().isNegative()">]>,
descr> {
let returnType = [{ APInt }];
}
def NonNegativeI32Attr : NonNegativeIntAttrBase<
I32, "non-negative 32-bit integer attribute">;
def NonNegativeI64Attr : NonNegativeIntAttrBase<
I64, "non-negative 64-bit integer attribute">;
// Base class for float attributes of fixed width.
class FloatAttrBase<F attrValType, string descr> :
TypedAttrBase<attrValType, "FloatAttr",

View File

@ -76,6 +76,13 @@ def MixedNormalVariadicResults : TEST_Op<
// Test Attributes
//===----------------------------------------------------------------------===//
def NonNegIntAttrOp : TEST_Op<"non_negative_int_attr"> {
let arguments = (ins
NonNegativeI32Attr:$i32attr,
NonNegativeI64Attr:$i64attr
);
}
def TypeArrayAttrOp : TEST_Op<"type_array_attr"> {
let arguments = (ins TypeArrayAttr:$attr);
}