[Mlir-commits] [mlir] 66645a0 - [mlir][python] Include anchor op in PassManager.parse

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Nov 3 08:49:52 PDT 2022


Author: rkayaith
Date: 2022-11-03T11:49:48-04:00
New Revision: 66645a03fc8a36b5052113f1466e8baf01137623

URL: https://github.com/llvm/llvm-project/commit/66645a03fc8a36b5052113f1466e8baf01137623
DIFF: https://github.com/llvm/llvm-project/commit/66645a03fc8a36b5052113f1466e8baf01137623.diff

LOG: [mlir][python] Include anchor op in PassManager.parse

The pipeline string must now include the pass manager's anchor op. This
makes the parse API properly roundtrip the printed form of a pass
manager.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D136405

Added: 
    

Modified: 
    mlir/lib/Bindings/Python/Pass.cpp
    mlir/test/Integration/Dialect/SparseTensor/python/tools/sparse_compiler.py
    mlir/test/Integration/Dialect/SparseTensor/taco/tools/mlir_sparse_compiler.py
    mlir/test/python/dialects/async_dialect.py
    mlir/test/python/dialects/gpu.py
    mlir/test/python/dialects/sparse_tensor/passes.py
    mlir/test/python/execution_engine.py
    mlir/test/python/integration/dialects/linalg/opsrun.py
    mlir/test/python/pass_manager.py

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Bindings/Python/Pass.cpp b/mlir/lib/Bindings/Python/Pass.cpp
index 99d67582d1780..f08a4bd2daa7d 100644
--- a/mlir/lib/Bindings/Python/Pass.cpp
+++ b/mlir/lib/Bindings/Python/Pass.cpp
@@ -85,7 +85,7 @@ void mlir::python::populatePassManagerSubmodule(py::module &m) {
           [](const std::string &pipeline, DefaultingPyMlirContext context) {
             MlirPassManager passManager = mlirPassManagerCreate(context->get());
             PyPrintAccumulator errorMsg;
-            MlirLogicalResult status = mlirOpPassManagerAddPipeline(
+            MlirLogicalResult status = mlirParsePassPipeline(
                 mlirPassManagerGetAsOpPassManager(passManager),
                 mlirStringRefCreate(pipeline.data(), pipeline.size()),
                 errorMsg.getCallback(), errorMsg.getUserData());

diff  --git a/mlir/test/Integration/Dialect/SparseTensor/python/tools/sparse_compiler.py b/mlir/test/Integration/Dialect/SparseTensor/python/tools/sparse_compiler.py
index 174e847f72c23..abdab9738def7 100644
--- a/mlir/test/Integration/Dialect/SparseTensor/python/tools/sparse_compiler.py
+++ b/mlir/test/Integration/Dialect/SparseTensor/python/tools/sparse_compiler.py
@@ -13,7 +13,7 @@ class SparseCompiler:
   """Sparse compiler class for compiling and building MLIR modules."""
 
   def __init__(self, options: str, opt_level: int, shared_libs: Sequence[str]):
-    pipeline = f'sparse-compiler{{{options} reassociate-fp-reductions=1 enable-index-optimizations=1}}'
+    pipeline = f'builtin.module(sparse-compiler{{{options} reassociate-fp-reductions=1 enable-index-optimizations=1}})'
     self.pipeline = pipeline
     self.opt_level = opt_level
     self.shared_libs = shared_libs

diff  --git a/mlir/test/Integration/Dialect/SparseTensor/taco/tools/mlir_sparse_compiler.py b/mlir/test/Integration/Dialect/SparseTensor/taco/tools/mlir_sparse_compiler.py
index 6f117f386f531..1ba0d393894b9 100644
--- a/mlir/test/Integration/Dialect/SparseTensor/taco/tools/mlir_sparse_compiler.py
+++ b/mlir/test/Integration/Dialect/SparseTensor/taco/tools/mlir_sparse_compiler.py
@@ -16,7 +16,7 @@ class SparseCompiler:
   """Sparse compiler class for compiling and building MLIR modules."""
 
   def __init__(self, options: str, opt_level: int, shared_libs: Sequence[str]):
-    pipeline = f'sparse-compiler{{{options} reassociate-fp-reductions=1 enable-index-optimizations=1}}'
+    pipeline = f'builtin.module(sparse-compiler{{{options} reassociate-fp-reductions=1 enable-index-optimizations=1}})'
     self.pipeline = pipeline
     self.opt_level = opt_level
     self.shared_libs = shared_libs

diff  --git a/mlir/test/python/dialects/async_dialect.py b/mlir/test/python/dialects/async_dialect.py
index 6a33bd6b6d030..da3103cecddf2 100644
--- a/mlir/test/python/dialects/async_dialect.py
+++ b/mlir/test/python/dialects/async_dialect.py
@@ -11,7 +11,7 @@ def run(f):
 
 def testAsyncPass():
   with Context() as context:
-    PassManager.parse('async-to-async-runtime')
+    PassManager.parse('any(async-to-async-runtime)')
   print('SUCCESS')
 
 # CHECK-LABEL: testAsyncPass

diff  --git a/mlir/test/python/dialects/gpu.py b/mlir/test/python/dialects/gpu.py
index edf59dfc9c8fb..38bf038a5eeed 100644
--- a/mlir/test/python/dialects/gpu.py
+++ b/mlir/test/python/dialects/gpu.py
@@ -11,7 +11,7 @@ def run(f):
 
 def testGPUPass():
   with Context() as context:
-    PassManager.parse('gpu-kernel-outlining')
+    PassManager.parse('any(gpu-kernel-outlining)')
   print('SUCCESS')
 
 # CHECK-LABEL: testGPUPass

diff  --git a/mlir/test/python/dialects/sparse_tensor/passes.py b/mlir/test/python/dialects/sparse_tensor/passes.py
index f3510c5ce8169..9319e16e054de 100644
--- a/mlir/test/python/dialects/sparse_tensor/passes.py
+++ b/mlir/test/python/dialects/sparse_tensor/passes.py
@@ -16,7 +16,7 @@ def run(f):
 @run
 def testSparseTensorPass():
   with Context() as context:
-    PassManager.parse('sparsification')
-    PassManager.parse('sparse-tensor-conversion')
+    PassManager.parse('any(sparsification)')
+    PassManager.parse('any(sparse-tensor-conversion)')
   # CHECK: SUCCESS
   print('SUCCESS')

diff  --git a/mlir/test/python/execution_engine.py b/mlir/test/python/execution_engine.py
index c518803789637..7b7ee953ea193 100644
--- a/mlir/test/python/execution_engine.py
+++ b/mlir/test/python/execution_engine.py
@@ -63,7 +63,7 @@ def testInvalidModule():
 
 def lowerToLLVM(module):
   pm = PassManager.parse(
-      "convert-complex-to-llvm,convert-memref-to-llvm,convert-func-to-llvm,reconcile-unrealized-casts")
+      "builtin.module(convert-complex-to-llvm,convert-memref-to-llvm,convert-func-to-llvm,reconcile-unrealized-casts)")
   pm.run(module)
   return module
 

diff  --git a/mlir/test/python/integration/dialects/linalg/opsrun.py b/mlir/test/python/integration/dialects/linalg/opsrun.py
index e22f5a0ea3d87..2075ecfc21d01 100644
--- a/mlir/test/python/integration/dialects/linalg/opsrun.py
+++ b/mlir/test/python/integration/dialects/linalg/opsrun.py
@@ -192,10 +192,10 @@ def transform(module, boilerplate):
   mod = Module.parse("\n".join([str(op) for op in ops]) + boilerplate)
 
   pm = PassManager.parse(
-      "func.func(convert-linalg-to-loops, lower-affine, " +
+      "builtin.module(func.func(convert-linalg-to-loops, lower-affine, " +
       "convert-math-to-llvm, convert-scf-to-cf, arith-expand, memref-expand), "
       + "convert-vector-to-llvm, convert-memref-to-llvm, convert-func-to-llvm," +
-      "reconcile-unrealized-casts")
+      "reconcile-unrealized-casts)")
   pm.run(mod)
   return mod
 

diff  --git a/mlir/test/python/pass_manager.py b/mlir/test/python/pass_manager.py
index a2d56a1f6e031..99170cd042b67 100644
--- a/mlir/test/python/pass_manager.py
+++ b/mlir/test/python/pass_manager.py
@@ -44,7 +44,7 @@ def testParseSuccess():
 
     # A registered pass should parse successfully.
     pm = PassManager.parse("builtin.module(func.func(print-op-stats{json=false}))")
-    # CHECK: Roundtrip: builtin.module(builtin.module(func.func(print-op-stats{json=false})))
+    # CHECK: Roundtrip: builtin.module(func.func(print-op-stats{json=false}))
     log("Roundtrip: ", pm)
 run(testParseSuccess)
 
@@ -53,7 +53,7 @@ def testParseSuccess():
 def testParseFail():
   with Context():
     try:
-      pm = PassManager.parse("unknown-pass")
+      pm = PassManager.parse("any(unknown-pass)")
     except ValueError as e:
       #      CHECK: ValueError exception: MLIR Textual PassPipeline Parser:1:1: error:
       # CHECK-SAME: 'unknown-pass' does not refer to a registered pass or pass pipeline
@@ -83,7 +83,7 @@ def testInvalidNesting():
 # CHECK-LABEL: TEST: testRun
 def testRunPipeline():
   with Context():
-    pm = PassManager.parse("print-op-stats{json=false}")
+    pm = PassManager.parse("builtin.module(print-op-stats{json=false})")
     module = Module.parse(r"""func.func @successfulParse() { return }""")
     pm.run(module)
 # CHECK: Operations encountered:


        


More information about the Mlir-commits mailing list