[Mlir-commits] [mlir] [MLIR][Python] Expose the insertion point of pattern rewriter (PR #161001)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sat Sep 27 03:58:50 PDT 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {darker}-->


:warning: Python code formatter, darker found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
darker --check --diff -r origin/main...HEAD mlir/test/python/integration/dialects/pdl.py
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from darker here.
</summary>

``````````diff
--- pdl.py	2025-09-27 10:37:35.000000 +0000
+++ pdl.py	2025-09-27 10:58:25.302926 +0000
@@ -252,29 +252,43 @@
         @pdl.pattern(benefit=1, sym_name="myint_constant_expand")
         def pat():
             t = pdl.TypeOp(i32)
             cst = pdl.AttributeOp()
             pdl.apply_native_constraint([], "is_one", [cst])
-            op0 = pdl.OperationOp(name="myint.constant", attributes={"value": cst}, types=[t])
+            op0 = pdl.OperationOp(
+                name="myint.constant", attributes={"value": cst}, types=[t]
+            )
 
             @pdl.rewrite()
             def rew():
-                expanded = pdl.apply_native_rewrite([pdl.OperationType.get()], "expand", [cst])
+                expanded = pdl.apply_native_rewrite(
+                    [pdl.OperationType.get()], "expand", [cst]
+                )
                 pdl.ReplaceOp(op0, with_op=expanded)
 
     def is_one(rewriter, results, values):
         cst = values[0].value
         return cst <= 1
-    
+
     def expand(rewriter, results, values):
         cst = values[0].value
         c1 = cst // 2
         c2 = cst - c1
         with rewriter.ip():
-            op1 = Operation.create("myint.constant", results=[i32], attributes={"value": IntegerAttr.get(i32, c1)})
-            op2 = Operation.create("myint.constant", results=[i32], attributes={"value": IntegerAttr.get(i32, c2)})
-            res = Operation.create("myint.add", results=[i32], operands=[op1.result, op2.result])
+            op1 = Operation.create(
+                "myint.constant",
+                results=[i32],
+                attributes={"value": IntegerAttr.get(i32, c1)},
+            )
+            op2 = Operation.create(
+                "myint.constant",
+                results=[i32],
+                attributes={"value": IntegerAttr.get(i32, c2)},
+            )
+            res = Operation.create(
+                "myint.add", results=[i32], operands=[op1.result, op2.result]
+            )
         results.append(res)
 
     pdl_module = PDLModule(m)
     pdl_module.register_constraint_function("is_one", is_one)
     pdl_module.register_rewrite_function("expand", expand)

``````````

</details>


https://github.com/llvm/llvm-project/pull/161001


More information about the Mlir-commits mailing list