[Mlir-commits] [mlir] [MLIR][Python] Add bindings for PDL native function registering (PR #159926)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sat Sep 20 06:43:10 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-20 12:56:58.000000 +0000
+++ pdl.py	2025-09-20 13:42:46.874305 +0000
@@ -93,10 +93,11 @@
 # implicitly in the greedy pattern rewrite driver to
 # make our Python-defined folding useless,
 # so here we define a new dialect to workaround this.
 def load_myint_dialect():
     from mlir.dialects import irdl
+
     m = Module.create()
     with InsertionPoint(m.body):
         myint = irdl.dialect("myint")
         with InsertionPoint(myint.body):
             constant = irdl.operation_("constant")
@@ -106,36 +107,48 @@
                 irdl.attributes_([iattr], ["value"])
                 irdl.results_([i32], ["cst"], [irdl.Variadicity.single])
             add = irdl.operation_("add")
             with InsertionPoint(add.body):
                 i32 = irdl.is_(TypeAttr.get(IntegerType.get_signless(32)))
-                irdl.operands_([i32, i32], ["lhs", "rhs"], [irdl.Variadicity.single, irdl.Variadicity.single])
+                irdl.operands_(
+                    [i32, i32],
+                    ["lhs", "rhs"],
+                    [irdl.Variadicity.single, irdl.Variadicity.single],
+                )
                 irdl.results_([i32], ["res"], [irdl.Variadicity.single])
 
     m.operation.verify()
     irdl.load_dialects(m)
+
 
 # This PDL pattern is to fold constant additions,
 # i.e. add(constant0, constant1) -> constant2
 # where constant2 = constant0 + constant1.
 def get_pdl_pattern_fold():
     m = Module.create()
     with InsertionPoint(m.body):
+
         @pdl.pattern(benefit=1, sym_name="myint_add_fold")
         def pat():
             t = pdl.TypeOp(IntegerType.get_signless(32))
             a0 = pdl.AttributeOp()
             a1 = pdl.AttributeOp()
-            c0 = pdl.OperationOp(name="myint.constant", attributes={"value": a0}, types=[t])
-            c1 = pdl.OperationOp(name="myint.constant", attributes={"value": a1}, types=[t])
+            c0 = pdl.OperationOp(
+                name="myint.constant", attributes={"value": a0}, types=[t]
+            )
+            c1 = pdl.OperationOp(
+                name="myint.constant", attributes={"value": a1}, types=[t]
+            )
             v0 = pdl.ResultOp(c0, 0)
             v1 = pdl.ResultOp(c1, 0)
             op0 = pdl.OperationOp(name="myint.add", args=[v0, v1], types=[t])
 
             @pdl.rewrite()
             def rew():
-                sum = pdl.apply_native_rewrite([pdl.AttributeType.get()], "add_fold", [a0, a1])
+                sum = pdl.apply_native_rewrite(
+                    [pdl.AttributeType.get()], "add_fold", [a0, a1]
+                )
                 newOp = pdl.OperationOp(
                     name="myint.constant", attributes={"value": sum}, types=[t]
                 )
                 pdl.ReplaceOp(op0, with_op=newOp)
 

``````````

</details>


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


More information about the Mlir-commits mailing list