[Mlir-commits] [mlir] 024ae73 - [mlir][Transform] Add transform.any_param type
Quinn Dawkins
llvmlistbot at llvm.org
Thu Jul 27 11:21:56 PDT 2023
Author: Quinn Dawkins
Date: 2023-07-27T14:10:29-04:00
New Revision: 024ae73fa196adf41bb55cc2481ef28bde0e0a2c
URL: https://github.com/llvm/llvm-project/commit/024ae73fa196adf41bb55cc2481ef28bde0e0a2c
DIFF: https://github.com/llvm/llvm-project/commit/024ae73fa196adf41bb55cc2481ef28bde0e0a2c.diff
LOG: [mlir][Transform] Add transform.any_param type
Introduces a generic parameter type intended for transform dialect use
cases that uses/manipulates the underlying attribute (e.g. op
annotation). Includes a disclaimer that mixing parameter based and
attribute based control is discouraged.
Differential Revision: https://reviews.llvm.org/D155980
Added:
Modified:
mlir/docs/Dialects/Transform.md
mlir/include/mlir/Dialect/Transform/IR/TransformTypes.td
mlir/lib/Dialect/Transform/IR/TransformTypes.cpp
mlir/test/Dialect/Transform/ops.mlir
mlir/test/Dialect/Transform/test-interpreter.mlir
Removed:
################################################################################
diff --git a/mlir/docs/Dialects/Transform.md b/mlir/docs/Dialects/Transform.md
index cf4c6f9b5b4359..0a59d4b32c7eb6 100644
--- a/mlir/docs/Dialects/Transform.md
+++ b/mlir/docs/Dialects/Transform.md
@@ -64,6 +64,24 @@ objects. They usually apply the respective transformation for every mapped
object ("batched execution"). Deviations from this convention are described in
the documentation of Transform IR ops.
+Parameters, such as `%1` in the above example, have two logical roles in
+transform IR. In parameter based control, they carry the values needed to
+execute the explicit control defined by the transforms, for example:
+
+```mlir
+%0 = transform.match.structured.rank %linalg_op_handle : !transform.param<index>
+%1 = transform.param.constant 3 : i32 -> !transform.param<index>
+transform.execute_if_cmpi eq %0, %1 : !transform.param<index>, !transform.param<index>
+// Some nested body of transform ops
+```
+
+Alternatively, parameters can associate with the payload IR where the specific
+value at execution time has no bearing on the execution of the transform IR. In
+other words, parameters can either associate with the transform IR or the
+payload IR. Note that it is generally discouraged to use parameters containing
+arbitrary attributes within transform control. Parameter based control should
+try to be explicitly typed when possible.
+
The transform IR values have transform IR types, which should implement exactly one of:
* [TransformHandleTypeInterface](Transform.md#transformhandletypeinterface-transformhandletypeinterface),
diff --git a/mlir/include/mlir/Dialect/Transform/IR/TransformTypes.td b/mlir/include/mlir/Dialect/Transform/IR/TransformTypes.td
index 1d88e2b5880a39..44dfce913d15a2 100644
--- a/mlir/include/mlir/Dialect/Transform/IR/TransformTypes.td
+++ b/mlir/include/mlir/Dialect/Transform/IR/TransformTypes.td
@@ -55,6 +55,16 @@ def Transform_OperationType : TypeDef<Transform_Dialect, "Operation",
let assemblyFormat = "`<` $operation_name `>`";
}
+def Transform_AnyParamType : TypeDef<Transform_Dialect, "AnyParam",
+ [DeclareTypeInterfaceMethods<TransformParamTypeInterface>]> {
+ let description = [{
+ Transform IR value that can be associated with a list of parameters
+ of any type.
+ }];
+ let mnemonic = "any_param";
+ let assemblyFormat = "";
+}
+
def Transform_ParamType : TypeDef<Transform_Dialect, "Param",
[DeclareTypeInterfaceMethods<TransformParamTypeInterface>]> {
let description = [{
diff --git a/mlir/lib/Dialect/Transform/IR/TransformTypes.cpp b/mlir/lib/Dialect/Transform/IR/TransformTypes.cpp
index 1360f23c5018fd..5f70235c2352af 100644
--- a/mlir/lib/Dialect/Transform/IR/TransformTypes.cpp
+++ b/mlir/lib/Dialect/Transform/IR/TransformTypes.cpp
@@ -96,6 +96,16 @@ transform::OperationType::checkPayload(Location loc,
return DiagnosedSilenceableFailure::success();
}
+//===----------------------------------------------------------------------===//
+// transform::AnyParamType
+//===----------------------------------------------------------------------===//
+
+DiagnosedSilenceableFailure
+transform::AnyParamType::checkPayload(Location loc,
+ ArrayRef<Attribute> payload) const {
+ return DiagnosedSilenceableFailure::success();
+}
+
//===----------------------------------------------------------------------===//
// transform::ParamType
//===----------------------------------------------------------------------===//
diff --git a/mlir/test/Dialect/Transform/ops.mlir b/mlir/test/Dialect/Transform/ops.mlir
index dc35a9a6c9032d..a0a2f6fb6fcdaa 100644
--- a/mlir/test/Dialect/Transform/ops.mlir
+++ b/mlir/test/Dialect/Transform/ops.mlir
@@ -113,3 +113,10 @@ transform.sequence failures(propagate) {
%0 = transform.structured.match ops{["linalg.matmul"]} in %arg1 : (!transform.any_op) -> !transform.any_op
transform.structured.tile %0 [[2], 4, 8] : (!transform.any_op) -> (!transform.any_op, !transform.any_op, !transform.any_op, !transform.any_op)
}
+
+// CHECK: transform.sequence
+// CHECK: transform.param.constant "example_string
+transform.sequence failures(propagate) {
+^bb0(%arg1: !transform.any_op):
+ transform.param.constant "example_string" -> !transform.any_param
+}
diff --git a/mlir/test/Dialect/Transform/test-interpreter.mlir b/mlir/test/Dialect/Transform/test-interpreter.mlir
index 4ebecd8c933925..db97d0a0887576 100644
--- a/mlir/test/Dialect/Transform/test-interpreter.mlir
+++ b/mlir/test/Dialect/Transform/test-interpreter.mlir
@@ -1684,15 +1684,18 @@ transform.sequence failures(propagate) {
// CHECK-LABEL: func @test_annotation()
// CHECK-NEXT: "test.annotate_me"()
+// CHECK-SAME: any_attr = "example"
// CHECK-SAME: broadcast_attr = 2 : i64
// CHECK-SAME: new_attr = 1 : i32
// CHECK-SAME: unit_attr
// CHECK-NEXT: "test.annotate_me"()
+// CHECK-SAME: any_attr = "example"
// CHECK-SAME: broadcast_attr = 2 : i64
// CHECK-SAME: existing_attr = "test"
// CHECK-SAME: new_attr = 1 : i32
// CHECK-SAME: unit_attr
// CHECK-NEXT: "test.annotate_me"()
+// CHECK-SAME: any_attr = "example"
// CHECK-SAME: broadcast_attr = 2 : i64
// CHECK-SAME: new_attr = 1 : i32
// CHECK-SAME: unit_attr
@@ -1711,6 +1714,9 @@ transform.sequence failures(propagate) {
%2 = transform.param.constant 2 -> !transform.param<i64>
transform.annotate %0 "broadcast_attr" = %2 : !transform.any_op, !transform.param<i64>
transform.annotate %0 "unit_attr" : !transform.any_op
+
+ %3 = transform.param.constant "example" -> !transform.any_param
+ transform.annotate %0 "any_attr" = %3 : !transform.any_op, !transform.any_param
}
// -----
More information about the Mlir-commits
mailing list