[Mlir-commits] [mlir] [mlir][doc] Fix transform dialect tutorial ch3 (PR #150456)

lonely eagle llvmlistbot at llvm.org
Thu Jul 24 09:38:54 PDT 2025


https://github.com/linuxlonelyeagle created https://github.com/llvm/llvm-project/pull/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
```

>From 61002e561fe0a34b2d8b05d9adeef667294c1f6b Mon Sep 17 00:00:00 2001
From: linuxlonelyeagle <2020382038 at qq.com>
Date: Thu, 24 Jul 2025 16:30:53 +0000
Subject: [PATCH] fixes errors in documentation.

---
 mlir/docs/Tutorials/transform/Ch3.md          | 15 ++++++++++++-
 .../transform/Ch3/include/MyExtension.td      |  2 +-
 mlir/test/Examples/transform/Ch3/ops.mlir     | 21 +++++++++++++++++++
 .../test/Examples/transform/Ch3/sequence.mlir | 11 +++++-----
 4 files changed, 42 insertions(+), 7 deletions(-)

diff --git a/mlir/docs/Tutorials/transform/Ch3.md b/mlir/docs/Tutorials/transform/Ch3.md
index fa788d13e2055..919f1e6a19b8f 100644
--- a/mlir/docs/Tutorials/transform/Ch3.md
+++ b/mlir/docs/Tutorials/transform/Ch3.md
@@ -139,7 +139,20 @@ void MyExtension::init() {
 ```
 
 This type is now directly available in the Transform dialect and can be used in operations.
+We modify `$call` type must be `Transform_ConcreteOp<“func.call”>`, let it use the 
+`CallOpInterfaceHandle`.
 
+```tablegen
+def ChangeCallTargetOp : ... {
+    let arguments = (ins
+    // Specify the type constraint on the input accepting only `func.call` payload
+    // operations.
+    AnyTypeOf<[Transform_ConcreteOpType<"func.call">, CallOpInterfaceHandle]>:$call,
+    StrAttr:$new_target); 
+}
+```
+
+We can then add the following to `sequence.mlir` and run it with the interpreter.
 
 ```mlir
   // Cast to our new type.
@@ -172,7 +185,7 @@ def CallToOp : Op<Transform_Dialect, "my.call_to_op",
   let results = (outs TransformHandleTypeInterface:$transformed);
 
   // Provide nice syntax.
-  let assemblyFormat = "$call attr-dict `:` functional-type(inputs, outputs)";
+  let assemblyFormat = "$call attr-dict `:` functional-type(operands, results)";
 
   // Declare the function implementing the interface for a single payload operation.
   let extraClassDeclaration = [{
diff --git a/mlir/examples/transform/Ch3/include/MyExtension.td b/mlir/examples/transform/Ch3/include/MyExtension.td
index 5a78186d75c7b..5aab9808a5cd5 100644
--- a/mlir/examples/transform/Ch3/include/MyExtension.td
+++ b/mlir/examples/transform/Ch3/include/MyExtension.td
@@ -48,7 +48,7 @@ def ChangeCallTargetOp : Op<Transform_Dialect, "my.change_call_target",
   let arguments = (ins
     // Specify the type constraint on the input accepting only `func.call` payload
     // operations.
-    Transform_ConcreteOpType<"func.call">:$call,
+    AnyTypeOf<[Transform_ConcreteOpType<"func.call">, CallOpInterfaceHandle]>:$call,
     StrAttr:$new_target);
 
   // The results are empty as the transformation does not produce any new payload.
diff --git a/mlir/test/Examples/transform/Ch3/ops.mlir b/mlir/test/Examples/transform/Ch3/ops.mlir
index b2d47cc369a58..707a09fe251ef 100644
--- a/mlir/test/Examples/transform/Ch3/ops.mlir
+++ b/mlir/test/Examples/transform/Ch3/ops.mlir
@@ -30,9 +30,30 @@ module attributes {transform.with_named_sequence} {
 // -----
 
 func.func private @orig()
+func.func private @updated()
 
 // CHECK-LABEL: func @test2
 func.func @test2() {
+  // CHECK: call @updated
+  call @orig() : () -> ()
+  return
+}
+
+module attributes {transform.with_named_sequence} {
+  transform.named_sequence @__transform_main(%arg0: !transform.any_op) {
+    %call = transform.structured.match ops{["func.call"]} in %arg0 : (!transform.any_op) -> !transform.my.call_op_interface
+    // CHECK: transform.my.change_call_target %{{.*}}, "updated" : !transform.my.call_op_interface
+    transform.my.change_call_target %call, "updated" : !transform.my.call_op_interface
+    transform.yield
+  }
+}
+
+// -----
+
+func.func private @orig()
+
+// CHECK-LABEL: func @test3
+func.func @test3() {
   // CHECK: "my.mm4"
   call @orig() : () -> ()
   return
diff --git a/mlir/test/Examples/transform/Ch3/sequence.mlir b/mlir/test/Examples/transform/Ch3/sequence.mlir
index 4d28518ca3d9e..877b0064647d3 100644
--- a/mlir/test/Examples/transform/Ch3/sequence.mlir
+++ b/mlir/test/Examples/transform/Ch3/sequence.mlir
@@ -101,11 +101,12 @@ module attributes {transform.with_named_sequence} {
     %_1, %outline_target = transform.structured.fuse_into_containing_op %matmul_fused_2 into %loop_third
         : (!transform.any_op, !transform.any_op) -> (!transform.any_op, !transform.any_op)
     %func, %call = transform.loop.outline %outline_target {func_name = "outlined"}
-        : (!transform.any_op) -> (!transform.any_op, !transform.op<"func.call">)
-  
-    // Rewrite the call target.
-    transform.my.change_call_target %call, "microkernel" : !transform.op<"func.call">
-  
+        : (!transform.any_op) -> (!transform.any_op, !transform.any_op)
+    // 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
+
     transform.yield
   }
 }



More information about the Mlir-commits mailing list