@@ -291,8 +291,27 @@ Right now, the following primitive constraints are supported:
291
291
equal to ` N `
292
292
* ` IntMaxValue<N> ` : Specifying an integer attribute to be less than or equal
293
293
to ` N `
294
+ * ` IntNEQValue<N> ` : Specifying an integer attribute to be not equal
295
+ to ` N `
296
+ * ` IntPositive ` : Specifying an integer attribute whose value is positive
297
+ * ` IntNonNegative ` : Specifying an integer attribute whose value is
298
+ non-negative
294
299
* ` ArrayMinCount<N> ` : Specifying an array attribute to have at least ` N `
295
300
elements
301
+ * ` ArrayMaxCount<N> ` : Specifying an array attribute to have at most ` N `
302
+ elements
303
+ * ` ArrayCount<N> ` : Specifying an array attribute to have exactly ` N `
304
+ elements
305
+ * ` DenseArrayCount<N> ` : Specifying a dense array attribute to have
306
+ exactly ` N ` elements
307
+ * ` DenseArrayStrictlyPositive<arrayType> ` : Specifying a dense array attribute
308
+ of type ` arrayType ` to have all positive elements
309
+ * ` DenseArrayStrictlyNonNegative<arrayType> ` : Specifying a dense array attribute
310
+ of type ` arrayType ` to have all non-negative elements
311
+ * ` DenseArraySorted<arrayType> ` : Specifying a dense array attribute
312
+ of type ` arrayType ` to have elements in non-decreasing order
313
+ * ` DenseArrayStrictlySorted<arrayType> ` : Specifying a dense array attribute
314
+ of type ` arrayType ` to have elements in increasing order
296
315
* ` IntArrayNthElemEq<I, N> ` : Specifying an integer array attribute's ` I ` -th
297
316
element to be equal to ` N `
298
317
* ` IntArrayNthElemMinValue<I, N> ` : Specifying an integer array attribute's
@@ -301,9 +320,36 @@ Right now, the following primitive constraints are supported:
301
320
` I ` -th element to be less than or equal to ` N `
302
321
* ` IntArrayNthElemInRange<I, M, N> ` : Specifying an integer array attribute's
303
322
` I ` -th element to be greater than or equal to ` M ` and less than or equal to ` N `
323
+ * ` IsNullAttr ` : Specifying an optional attribute which must be empty
304
324
305
325
TODO: Design and implement more primitive constraints
306
326
327
+ #### Combining constraints
328
+
329
+ ` AllAttrOf ` is provided to allow combination of multiple constraints which
330
+ must all hold.
331
+
332
+ For example:
333
+ ``` tablegen
334
+ def OpAllAttrConstraint1 : TEST_Op<"all_attr_constraint_of1"> {
335
+ let arguments = (ins I64ArrayAttr:$attr);
336
+ let results = (outs I32);
337
+ }
338
+ def OpAllAttrConstraint2 : TEST_Op<"all_attr_constraint_of2"> {
339
+ let arguments = (ins I64ArrayAttr:$attr);
340
+ let results = (outs I32);
341
+ }
342
+ def Constraint0 : AttrConstraint<
343
+ CPred<"::llvm::cast<::mlir::IntegerAttr>(::llvm::cast<ArrayAttr>($_self)[0]).getInt() == 0">,
344
+ "[0] == 0">;
345
+ def Constraint1 : AttrConstraint<
346
+ CPred<"::llvm::cast<::mlir::IntegerAttr>(::llvm::cast<ArrayAttr>($_self)[1]).getInt() == 1">,
347
+ "[1] == 1">;
348
+ def : Pat<(OpAllAttrConstraint1
349
+ AllAttrOf<[Constraint0, Constraint1]>:$attr),
350
+ (OpAllAttrConstraint2 $attr)>;
351
+ ```
352
+
307
353
### Operation regions
308
354
309
355
The regions of an operation are specified inside of the ` dag ` -typed ` regions ` ,
@@ -1398,6 +1444,8 @@ optionality, default values, etc.:
1398
1444
* ` OptionalAttr ` : specifies an attribute as [ optional] ( #optional-attributes ) .
1399
1445
* ` ConfinedAttr ` : adapts an attribute with
1400
1446
[ further constraints] ( #confining-attributes ) .
1447
+ * ` AllAttrOf ` : adapts an attribute with
1448
+ [ multiple constraints] ( #combining-constraints ) .
1401
1449
1402
1450
### Enum attributes
1403
1451
0 commit comments