summaryrefslogtreecommitdiff
path: root/mlir/include/mlir/Dialect/IRDL/IR/IRDLOps.td
diff options
context:
space:
mode:
authorMathieu Fehr <mathieu.fehr@gmail.com>2023-03-08 21:21:54 +0100
committerMathieu Fehr <mathieu.fehr@gmail.com>2023-05-17 21:57:16 +0100
commit42987dfa3a85e0cec987b9f07a8ffe61073ddc52 (patch)
treeb560ec140543acdd22a79a7f8ff1e46436d2a4e7 /mlir/include/mlir/Dialect/IRDL/IR/IRDLOps.td
parent6dcad42acbd5d047ac276ca73f1dc0012a39e99e (diff)
downloadllvm-42987dfa3a85e0cec987b9f07a8ffe61073ddc52.tar.gz
[mlir][irdl] Add `irdl.any_of` operation
The `irdl.any_of` operation represent a constraint that is satisfied if any of its subconstraint is satisfied. For instance, in the following example: ``` %0 = irdl.is f32 %1 = irdl.is f64 %2 = irdl.any_of(f32, f64) ``` `%2` can only be satisfied by `f32` or `f64`. Note that the verification algorithm required by `irdl.any_of` is non-trivial, since we want that the order of arguments of `irdl.any_of` to not matter. For this reason, our registration algorithm fails if two constraints used by `any_of` might be satisfied by the same `Attribute`. This is approximated by checking the possible `Attribute` bases of each constraints. Depends on D145734 Reviewed By: Mogball Differential Revision: https://reviews.llvm.org/D145735
Diffstat (limited to 'mlir/include/mlir/Dialect/IRDL/IR/IRDLOps.td')
-rw-r--r--mlir/include/mlir/Dialect/IRDL/IR/IRDLOps.td69
1 files changed, 69 insertions, 0 deletions
diff --git a/mlir/include/mlir/Dialect/IRDL/IR/IRDLOps.td b/mlir/include/mlir/Dialect/IRDL/IR/IRDLOps.td
index 5cce6858be2c..f5b4600062ea 100644
--- a/mlir/include/mlir/Dialect/IRDL/IR/IRDLOps.td
+++ b/mlir/include/mlir/Dialect/IRDL/IR/IRDLOps.td
@@ -356,5 +356,74 @@ def IRDL_Any : IRDL_ConstraintOp<"any",
let assemblyFormat = " attr-dict ";
}
+def IRDL_AnyOf : IRDL_ConstraintOp<"any_of",
+ [ParentOneOf<["TypeOp", "AttributeOp", "OperationOp"]>,
+ SameOperandsAndResultType]> {
+ let summary = "Constraints to the union of the provided constraints";
+ let description = [{
+ `irdl.any_of` defines a constraint that accepts any type or attribute that
+ satisfies at least one of its provided type constraints.
+
+ Example:
+
+ ```mlir
+ irdl.dialect cmath {
+ irdl.type complex {
+ %0 = irdl.is i32
+ %1 = irdl.is i64
+ %2 = irdl.is f32
+ %3 = irdl.is f64
+ %4 = irdl.any_of(%0, %1, %2, %3)
+ irdl.parameters(%4)
+ }
+ }
+ ```
+
+ The above program defines a type `complex` inside the dialect `cmath` that
+ can have a single type parameter that can be either `i32`, `i64`, `f32` or
+ `f32`.
+ }];
+
+ let arguments = (ins Variadic<IRDL_AttributeType>:$args);
+ let results = (outs IRDL_AttributeType:$output);
+ let assemblyFormat = [{ `(` $args `)` ` ` attr-dict }];
+}
+
+def IRDL_AllOf : IRDL_ConstraintOp<"all_of",
+ [ParentOneOf<["TypeOp", "AttributeOp", "OperationOp"]>,
+ SameOperandsAndResultType]> {
+ let summary = "Constraints to the intersection of the provided constraints";
+ let description = [{
+ `irdl.all_of` defines a constraint that accepts any type or attribute that
+ satisfies all of its provided constraints.
+
+ Example:
+
+ ```mlir
+ irdl.dialect cmath {
+ irdl.type complex_f32 {
+ %0 = irdl.is i32
+ %1 = irdl.is f32
+ %2 = irdl.any_of(%0, %1) // is 32-bit
+
+ %3 = irdl.is f32
+ %4 = irdl.is f64
+ %5 = irdl.any_of(%3, %4) // is a float
+
+ %6 = irdl.all_of(%2, %5) // is a 32-bit float
+ irdl.parameters(%6)
+ }
+ }
+ ```
+
+ The above program defines a type `complex` inside the dialect `cmath` that
+ can has one parameter that must be 32-bit long and a float (in other
+ words, that must be `f32`).
+ }];
+
+ let arguments = (ins Variadic<IRDL_AttributeType>:$args);
+ let results = (outs IRDL_AttributeType:$output);
+ let assemblyFormat = [{ `(` $args `)` ` ` attr-dict }];
+}
#endif // MLIR_DIALECT_IRDL_IR_IRDLOPS