[Mlir-commits] [mlir] [MLIR][Python] Add optional arguments to PassManager IR printing (PR #89301)

Oleksandr Alex Zinenko llvmlistbot at llvm.org
Fri Jun 7 02:58:24 PDT 2024


================
@@ -44,8 +44,23 @@ MlirLogicalResult mlirPassManagerRunOnOp(MlirPassManager passManager,
   return wrap(unwrap(passManager)->run(unwrap(op)));
 }
 
-void mlirPassManagerEnableIRPrinting(MlirPassManager passManager) {
-  return unwrap(passManager)->enableIRPrinting();
+void mlirPassManagerEnableIRPrinting(MlirPassManager passManager,
+                                     bool shouldPrintBeforePass,
+                                     bool shouldPrintAfterPass,
+                                     bool printModuleScope,
+                                     bool printAfterOnlyOnChange,
+                                     bool printAfterOnlyOnFailure) {
+  auto shouldPrintBeforeFn = [shouldPrintBeforePass](Pass *, Operation *) {return shouldPrintBeforePass;};
+  auto shouldPrintAfterFn = [shouldPrintAfterPass](Pass *, Operation *) {return shouldPrintAfterPass;};
----------------
ftynse wrote:

Wrappers are already available. This can take a `bool (*shouldPrintAfterPass)(MlirPass, MlirOperation, void *userData)`. Python binding side can define two overloads: one that takes a bool and another that takes a `std::function<bool (MlirPass, MlirOperation)>`, both using lambdas to delegate further. I believe we have type casters in place for this to work pretty much out of the box.

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


More information about the Mlir-commits mailing list