diff --git a/mlir/docs/Dialects/Transform.md b/mlir/docs/Dialects/Transform.md --- a/mlir/docs/Dialects/Transform.md +++ b/mlir/docs/Dialects/Transform.md @@ -64,6 +64,24 @@ 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 +%1 = transform.param.constant 3 : i32 -> !transform.param +transform.execute_if_cmpi eq %0, %1 : !transform.param, !transform.param +// 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 --- a/mlir/include/mlir/Dialect/Transform/IR/TransformTypes.td +++ b/mlir/include/mlir/Dialect/Transform/IR/TransformTypes.td @@ -55,6 +55,16 @@ let assemblyFormat = "`<` $operation_name `>`"; } +def Transform_AnyParamType : TypeDef]> { + 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]> { let description = [{ diff --git a/mlir/lib/Dialect/Transform/IR/TransformTypes.cpp b/mlir/lib/Dialect/Transform/IR/TransformTypes.cpp --- a/mlir/lib/Dialect/Transform/IR/TransformTypes.cpp +++ b/mlir/lib/Dialect/Transform/IR/TransformTypes.cpp @@ -96,6 +96,16 @@ return DiagnosedSilenceableFailure::success(); } +//===----------------------------------------------------------------------===// +// transform::AnyParamType +//===----------------------------------------------------------------------===// + +DiagnosedSilenceableFailure +transform::AnyParamType::checkPayload(Location loc, + ArrayRef payload) const { + return DiagnosedSilenceableFailure::success(); +} + //===----------------------------------------------------------------------===// // transform::ParamType //===----------------------------------------------------------------------===// diff --git a/mlir/test/Dialect/Transform/ops.mlir b/mlir/test/Dialect/Transform/ops.mlir --- a/mlir/test/Dialect/Transform/ops.mlir +++ b/mlir/test/Dialect/Transform/ops.mlir @@ -113,3 +113,10 @@ %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 --- a/mlir/test/Dialect/Transform/test-interpreter.mlir +++ b/mlir/test/Dialect/Transform/test-interpreter.mlir @@ -1684,15 +1684,18 @@ // 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 @@ %2 = transform.param.constant 2 -> !transform.param transform.annotate %0 "broadcast_attr" = %2 : !transform.any_op, !transform.param 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 } // -----