[Mlir-commits] [mlir] f0a8c5c - [mlir][irdl] Add `irdl.c_pred`
Mathieu Fehr
llvmlistbot at llvm.org
Thu Jun 8 03:38:16 PDT 2023
Author: Mathieu Fehr
Date: 2023-06-08T11:40:48+01:00
New Revision: f0a8c5c5cbed8d2afb76da8f2406cd056f170206
URL: https://github.com/llvm/llvm-project/commit/f0a8c5c5cbed8d2afb76da8f2406cd056f170206
DIFF: https://github.com/llvm/llvm-project/commit/f0a8c5c5cbed8d2afb76da8f2406cd056f170206.diff
LOG: [mlir][irdl] Add `irdl.c_pred`
`irdl.c_pred` is an attribute constraint defined by a C++ predicate.
Contrary to the other constraints, this operation cannot be used in
dialects that are registered at runtime. Its principal use is to
share dialect definitions that are defined in C++ or ODS.
Reviewed By: Mogball
Differential Revision: https://reviews.llvm.org/D152301
Added:
mlir/test/Dialect/IRDL/cpred.irdl.mlir
Modified:
mlir/include/mlir/Dialect/IRDL/IR/IRDLOps.td
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/IRDL/IR/IRDLOps.td b/mlir/include/mlir/Dialect/IRDL/IR/IRDLOps.td
index f5b4600062ea7..f451db3215846 100644
--- a/mlir/include/mlir/Dialect/IRDL/IR/IRDLOps.td
+++ b/mlir/include/mlir/Dialect/IRDL/IR/IRDLOps.td
@@ -426,4 +426,39 @@ def IRDL_AllOf : IRDL_ConstraintOp<"all_of",
let assemblyFormat = [{ `(` $args `)` ` ` attr-dict }];
}
+def IRDL_CPredOp : IRDL_Op<"c_pred"> {
+ let summary = "Constraints an attribute using a C++ predicate";
+ let description = [{
+ `irdl.c_pred` defines a constraint that is written in C++.
+
+ Dialects using this operation cannot be registered at runtime, as it relies
+ on C++ code.
+
+ Special placeholders can be used to refer to entities in the context where
+ this predicate is used. They serve as "hooks" to the enclosing environment.
+ The following special placeholders are supported in constraints for an op:
+
+ * `$_builder` will be replaced by a mlir::Builder instance.
+ * `$_op` will be replaced by the current operation.
+ * `$_self` will be replaced with the entity this predicate is attached to.
+ Compared to ODS, `$_self` is always of type `mlir::Attribute`, and types
+ are manipulated as `TypeAttr` attributes.
+
+ Example:
+ ```mlir
+ irdl.type @op_with_attr {
+ %0 = irdl.c_pred "::llvm::isa<::mlir::IntegerAttr>($_self)"
+ irdl.parameters(%0)
+ }
+ ```
+
+ In this example, @op_with_attr is defined as a type with a single
+ parameter, which is an `IntegerAttr`, as constrained by the C++ predicate.
+ }];
+
+ let arguments = (ins StrAttr:$pred);
+ let results = (outs IRDL_AttributeType:$output);
+ let assemblyFormat = "$pred ` ` attr-dict";
+}
+
#endif // MLIR_DIALECT_IRDL_IR_IRDLOPS
diff --git a/mlir/test/Dialect/IRDL/cpred.irdl.mlir b/mlir/test/Dialect/IRDL/cpred.irdl.mlir
new file mode 100644
index 0000000000000..129793e565d27
--- /dev/null
+++ b/mlir/test/Dialect/IRDL/cpred.irdl.mlir
@@ -0,0 +1,14 @@
+// RUN: mlir-opt %s | mlir-opt | FileCheck %s
+
+module {
+ // CHECK-LABEL: irdl.dialect @dialect {
+ irdl.dialect @dialect {
+ // CHECK-LABEL: irdl.type @type {
+ irdl.type @type {
+ %0 = irdl.c_pred "::llvm::isa<::mlir::IntegerAttr>($_self)"
+ // CHECK: %{{.*}} = irdl.c_pred "::llvm::isa<::mlir::IntegerAttr>($_self)"
+ irdl.parameters(%0)
+ // CHECK: irdl.parameters(%{{.*}})
+ }
+ }
+}
More information about the Mlir-commits
mailing list