[Mlir-commits] [mlir] [MLIR][Python] Support Python-defined passes in MLIR (PR #156000)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Aug 29 09:25:45 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/pass.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
--- pass.py	2025-08-29 16:20:59.000000 +0000
+++ pass.py	2025-08-29 16:25:10.371111 +0000
@@ -4,10 +4,11 @@
 from mlir.ir import *
 from mlir.passmanager import *
 from mlir.dialects.builtin import ModuleOp
 from mlir.dialects import pdl
 from mlir.rewrite import *
+
 
 def log(*args):
     print(*args, file=sys.stderr)
     sys.stderr.flush()
 
@@ -15,10 +16,11 @@
 def run(f):
     log("\nTEST:", f.__name__)
     f()
     gc.collect()
     assert Context._get_live_count() == 0
+
 
 def make_pdl_module():
     with Location.unknown():
         pdl_module = Module.create()
         with InsertionPoint(pdl_module.body):
@@ -41,33 +43,37 @@
                     )
                     pdl.ReplaceOp(op0, with_op=newOp)
 
         return pdl_module
 
+
 # CHECK-LABEL: TEST: testCustomPass
 @run
 def testCustomPass():
     with Context():
         pdl_module = make_pdl_module()
 
         class CustomPass(Pass):
             def __init__(self):
                 super().__init__("CustomPass", op_name="builtin.module")
+
             def run(self, m):
                 frozen = PDLModule(pdl_module).freeze()
                 apply_patterns_and_fold_greedily_for_op(m, frozen)
 
-        module = ModuleOp.parse(r"""
+        module = ModuleOp.parse(
+            r"""
             module {
               func.func @add(%a: index, %b: index) -> index {
                 %sum = arith.addi %a, %b : index
                 return %sum : index
               }
             }
-        """)
+        """
+        )
 
         # CHECK-LABEL: Dump After CustomPass
         # CHECK: arith.muli
-        pm = PassManager('any')
+        pm = PassManager("any")
         pm.enable_ir_printing()
         pm.add(CustomPass())
         pm.run(module)

``````````

</details>


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


More information about the Mlir-commits mailing list