[Mlir-commits] [mlir] [MLIR] [Python] align python ir printing with mlir-print-ir-after-all (PR #107522)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Sep 5 22:36:18 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Bimo (xurui1995)

<details>
<summary>Changes</summary>

When using the `enable_ir_printing` API from Python, it invokes IR printing with default args, printing the IR before each pass and printing IR after pass only if there have been changes. This PR attempts to align the `enable_ir_printing` API with the documentation

* default arg of `enableIRPrinting`
https://github.com/llvm/llvm-project/blob/093b8bfe6b64c916647ae64af8066df22bb6ea65/mlir/include/mlir/Pass/PassManager.h#L380-L387

* PyPassManager
https://github.com/llvm/llvm-project/blob/77f1b481b884621c12cde5f2ce6f080f11dbbbcc/mlir/lib/Bindings/Python/Pass.cpp#L75-L80

---
Full diff: https://github.com/llvm/llvm-project/pull/107522.diff


2 Files Affected:

- (modified) mlir/lib/CAPI/IR/Pass.cpp (+6-1) 
- (modified) mlir/test/python/pass_manager.py (-7) 


``````````diff
diff --git a/mlir/lib/CAPI/IR/Pass.cpp b/mlir/lib/CAPI/IR/Pass.cpp
index d242baae99c086..4d49e2ad949756 100644
--- a/mlir/lib/CAPI/IR/Pass.cpp
+++ b/mlir/lib/CAPI/IR/Pass.cpp
@@ -45,7 +45,12 @@ MlirLogicalResult mlirPassManagerRunOnOp(MlirPassManager passManager,
 }
 
 void mlirPassManagerEnableIRPrinting(MlirPassManager passManager) {
-  return unwrap(passManager)->enableIRPrinting();
+  auto shouldPrintBeforePass = [](Pass *, Operation *) { return false; };
+  auto shouldPrintAfterPass = [](Pass *, Operation *) { return true; };
+  bool printModuleScope = true, printAfterOnlyOnChange = false;
+  return unwrap(passManager)
+      ->enableIRPrinting(shouldPrintBeforePass, shouldPrintAfterPass,
+                         printModuleScope, printAfterOnlyOnChange);
 }
 
 void mlirPassManagerEnableVerifier(MlirPassManager passManager, bool enable) {
diff --git a/mlir/test/python/pass_manager.py b/mlir/test/python/pass_manager.py
index 43af80b53166cc..fc7225f920f730 100644
--- a/mlir/test/python/pass_manager.py
+++ b/mlir/test/python/pass_manager.py
@@ -300,13 +300,6 @@ def testPrintIrAfterAll():
         pm = PassManager.parse("builtin.module(canonicalize)")
         ctx.enable_multithreading(False)
         pm.enable_ir_printing()
-        # CHECK: // -----// IR Dump Before Canonicalizer (canonicalize) ('builtin.module' operation) //----- //
-        # CHECK: module {
-        # CHECK:   func.func @main() {
-        # CHECK:     %[[C10:.*]] = arith.constant 10 : i64
-        # CHECK:     return
-        # CHECK:   }
-        # CHECK: }
         # CHECK: // -----// IR Dump After Canonicalizer (canonicalize) ('builtin.module' operation) //----- //
         # CHECK: module {
         # CHECK:   func.func @main() {

``````````

</details>


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


More information about the Mlir-commits mailing list