Skip to content

Commit 1a4f0d6

Browse files
[mlir][doc] Fix transform dialect tutorial ch3 (#150456)
Fixed some bugs in documentation. Add CallOpInterfaceHandle to the arguments of ChangeCallTargetOp, after doing so the section described in the documentation works correctly, Otherwise the following code reports an error. ``` // Cast to our new type. %casted = transform.cast %call : !transform.any_op to !transform.my.call_op_interface // Using our new operation. transform.my.change_call_target %casted, "microkernel" : !transform.my.call_op_interface ```
1 parent e76780b commit 1a4f0d6

File tree

4 files changed

+45
-9
lines changed

4 files changed

+45
-9
lines changed

mlir/docs/Tutorials/transform/Ch3.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,21 @@ void MyExtension::init() {
139139
```
140140

141141
This type is now directly available in the Transform dialect and can be used in operations.
142+
In the previous tablegen definition, the type of `$call` must be `Transform_ConcreteOp<“func.call”>`,
143+
By adding `CallOpInterfaceHandle` as an allowed type for `$call`, the corresponding handle
144+
is allowed to be to any op implementing the interface.
142145

146+
```tablegen
147+
def ChangeCallTargetOp : ... {
148+
let arguments = (ins
149+
// Allow the handle to be to concrete `func.call` ops as well as any op implementing
150+
// the `CallOpInterface`.
151+
AnyTypeOf<[Transform_ConcreteOpType<"func.call">, CallOpInterfaceHandle]>:$call,
152+
StrAttr:$new_target);
153+
}
154+
```
155+
156+
We can then add the following code to `sequence.mlir` and run it with the interpreter.
143157

144158
```mlir
145159
// Cast to our new type.
@@ -172,7 +186,7 @@ def CallToOp : Op<Transform_Dialect, "my.call_to_op",
172186
let results = (outs TransformHandleTypeInterface:$transformed);
173187
174188
// Provide nice syntax.
175-
let assemblyFormat = "$call attr-dict `:` functional-type(inputs, outputs)";
189+
let assemblyFormat = "$call attr-dict `:` functional-type(operands, results)";
176190
177191
// Declare the function implementing the interface for a single payload operation.
178192
let extraClassDeclaration = [{

mlir/examples/transform/Ch3/include/MyExtension.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ def ChangeCallTargetOp : Op<Transform_Dialect, "my.change_call_target",
4646
// We use a string attribute as the symbol may not exist in the transform IR so the
4747
// verification may fail.
4848
let arguments = (ins
49-
// Specify the type constraint on the input accepting only `func.call` payload
50-
// operations.
51-
Transform_ConcreteOpType<"func.call">:$call,
49+
// Allow the handle to be to concrete func.call ops as well as any op implementing
50+
// the CallOpInterface.
51+
AnyTypeOf<[Transform_ConcreteOpType<"func.call">, CallOpInterfaceHandle]>:$call,
5252
StrAttr:$new_target);
5353

5454
// The results are empty as the transformation does not produce any new payload.

mlir/test/Examples/transform/Ch3/ops.mlir

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,30 @@ module attributes {transform.with_named_sequence} {
3030
// -----
3131

3232
func.func private @orig()
33+
func.func private @updated()
3334

3435
// CHECK-LABEL: func @test2
3536
func.func @test2() {
37+
// CHECK: call @updated
38+
call @orig() : () -> ()
39+
return
40+
}
41+
42+
module attributes {transform.with_named_sequence} {
43+
transform.named_sequence @__transform_main(%arg0: !transform.any_op) {
44+
%call = transform.structured.match ops{["func.call"]} in %arg0 : (!transform.any_op) -> !transform.my.call_op_interface
45+
// CHECK: transform.my.change_call_target %{{.*}}, "updated" : !transform.my.call_op_interface
46+
transform.my.change_call_target %call, "updated" : !transform.my.call_op_interface
47+
transform.yield
48+
}
49+
}
50+
51+
// -----
52+
53+
func.func private @orig()
54+
55+
// CHECK-LABEL: func @test3
56+
func.func @test3() {
3657
// CHECK: "my.mm4"
3758
call @orig() : () -> ()
3859
return

mlir/test/Examples/transform/Ch3/sequence.mlir

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,12 @@ module attributes {transform.with_named_sequence} {
101101
%_1, %outline_target = transform.structured.fuse_into_containing_op %matmul_fused_2 into %loop_third
102102
: (!transform.any_op, !transform.any_op) -> (!transform.any_op, !transform.any_op)
103103
%func, %call = transform.loop.outline %outline_target {func_name = "outlined"}
104-
: (!transform.any_op) -> (!transform.any_op, !transform.op<"func.call">)
105-
106-
// Rewrite the call target.
107-
transform.my.change_call_target %call, "microkernel" : !transform.op<"func.call">
108-
104+
: (!transform.any_op) -> (!transform.any_op, !transform.any_op)
105+
// Cast to our new type.
106+
%casted = transform.cast %call : !transform.any_op to !transform.my.call_op_interface
107+
// Using our new operation.
108+
transform.my.change_call_target %casted, "microkernel" : !transform.my.call_op_interface
109+
109110
transform.yield
110111
}
111112
}

0 commit comments

Comments
 (0)