forked from OSchip/llvm-project
Add attr constraint support to constrain IntegerArray attribute values at a specified index.
-- PiperOrigin-RevId: 242209394
This commit is contained in:
parent
a1b4cae30a
commit
fe1211edf2
|
@ -645,6 +645,22 @@ class ArrayMinCount<int n> : AttrConstraint<
|
|||
CPred<"{0}.cast<ArrayAttr>().size() >= " # n>,
|
||||
"with at least " # n # " elements">;
|
||||
|
||||
class IntArrayNthElemEq<int index, int value> : AttrConstraint<
|
||||
AllOf<[
|
||||
CPred<"{0}.cast<ArrayAttr>().size() > " # index>,
|
||||
CPred<"{0}.cast<ArrayAttr>().getValue()[" # index # "]"
|
||||
".cast<IntegerAttr>().getInt() == " # value>
|
||||
]>,
|
||||
"whose " # index # "-th element must be " # value>;
|
||||
|
||||
class IntArrayNthElemMinValue<int index, int min> : AttrConstraint<
|
||||
AllOf<[
|
||||
CPred<"{0}.cast<ArrayAttr>().size() > " # index>,
|
||||
CPred<"{0}.cast<ArrayAttr>().getValue()[" # index # "]"
|
||||
".cast<IntegerAttr>().getInt() >= " # min>
|
||||
]>,
|
||||
"whose " # index # "-th element must be at least " # min>;
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// OpTrait definitions
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
|
|
@ -70,3 +70,19 @@ def OpG : Op<"op_for_arr_min_count", []> {
|
|||
// CHECK-LABEL: OpG::verify()
|
||||
// CHECK: (tblgen_attr.cast<ArrayAttr>().size() >= 8)
|
||||
// CHECK-SAME: return emitOpError("attribute 'attr' failed to satisfy constraint: array attribute with at least 8 elements");
|
||||
|
||||
def OpH : Op<"op_for_arr_value_at_index", []> {
|
||||
let arguments = (ins Confined<ArrayAttr, [IntArrayNthElemEq<0, 8>]>:$attr);
|
||||
}
|
||||
|
||||
// CHECK-LABEL: OpH::verify()
|
||||
// CHECK: (((tblgen_attr.cast<ArrayAttr>().size() > 0)) && ((tblgen_attr.cast<ArrayAttr>().getValue()[0].cast<IntegerAttr>().getInt() == 8)))))
|
||||
// CHECK-SAME: return emitOpError("attribute 'attr' failed to satisfy constraint: array attribute whose 0-th element must be 8");
|
||||
|
||||
def OpI: Op<"op_for_arr_min_value_at_index", []> {
|
||||
let arguments = (ins Confined<ArrayAttr, [IntArrayNthElemMinValue<0, 8>]>:$attr);
|
||||
}
|
||||
|
||||
// CHECK-LABEL: OpI::verify()
|
||||
// CHECK: (((tblgen_attr.cast<ArrayAttr>().size() > 0)) && ((tblgen_attr.cast<ArrayAttr>().getValue()[0].cast<IntegerAttr>().getInt() >= 8)))))
|
||||
// CHECK-SAME: return emitOpError("attribute 'attr' failed to satisfy constraint: array attribute whose 0-th element must be at least 8");
|
||||
|
|
Loading…
Reference in New Issue