File tree Expand file tree Collapse file tree 4 files changed +65
-0
lines changed
Expand file tree Collapse file tree 4 files changed +65
-0
lines changed Original file line number Diff line number Diff line change @@ -92,6 +92,18 @@ mlirPassManagerEnableVerifier(MlirPassManager passManager, bool enable);
9292MLIR_CAPI_EXPORTED void
9393mlirPassManagerEnableTiming (MlirPassManager passManager );
9494
95+ /// Enumerated type of pass display modes.
96+ /// Mainly used in mlirPassManagerEnableStatistics.
97+ typedef enum {
98+ MLIR_PASS_DISPLAY_MODE_LIST ,
99+ MLIR_PASS_DISPLAY_MODE_PIPELINE ,
100+ } MlirPassDisplayMode ;
101+
102+ /// Enable pass statistics.
103+ MLIR_CAPI_EXPORTED void
104+ mlirPassManagerEnableStatistics (MlirPassManager passManager ,
105+ MlirPassDisplayMode displayMode );
106+
95107/// Nest an OpPassManager under the top-level PassManager, the nested
96108/// passmanager will only run on operations matching the provided name.
97109/// The returned OpPassManager will be destroyed when the parent is destroyed.
Original file line number Diff line number Diff line change @@ -56,6 +56,13 @@ class PyPassManager {
5656
5757// / Create the `mlir.passmanager` here.
5858void mlir::python::populatePassManagerSubmodule (nb::module_ &m) {
59+ // ----------------------------------------------------------------------------
60+ // Mapping of enumerated types
61+ // ----------------------------------------------------------------------------
62+ nb::enum_<MlirPassDisplayMode>(m, " PassDisplayMode" )
63+ .value (" LIST" , MLIR_PASS_DISPLAY_MODE_LIST)
64+ .value (" PIPELINE" , MLIR_PASS_DISPLAY_MODE_PIPELINE);
65+
5966 // ----------------------------------------------------------------------------
6067 // Mapping of MlirExternalPass
6168 // ----------------------------------------------------------------------------
@@ -138,6 +145,14 @@ void mlir::python::populatePassManagerSubmodule(nb::module_ &m) {
138145 mlirPassManagerEnableTiming (passManager.get ());
139146 },
140147 " Enable pass timing." )
148+ .def (
149+ " enable_statistics" ,
150+ [](PyPassManager &passManager, MlirPassDisplayMode displayMode) {
151+ mlirPassManagerEnableStatistics (passManager.get (), displayMode);
152+ },
153+ " displayMode" _a =
154+ MlirPassDisplayMode::MLIR_PASS_DISPLAY_MODE_PIPELINE,
155+ " Enable pass statistics." )
141156 .def_static (
142157 " parse" ,
143158 [](const std::string &pipeline, DefaultingPyMlirContext context) {
Original file line number Diff line number Diff line change 1313#include " mlir/CAPI/Support.h"
1414#include " mlir/CAPI/Utils.h"
1515#include " mlir/Pass/PassManager.h"
16+ #include " llvm/Support/ErrorHandling.h"
1617#include < optional>
1718
1819using namespace mlir ;
@@ -79,6 +80,22 @@ void mlirPassManagerEnableTiming(MlirPassManager passManager) {
7980 unwrap (passManager)->enableTiming ();
8081}
8182
83+ void mlirPassManagerEnableStatistics (MlirPassManager passManager,
84+ MlirPassDisplayMode displayMode) {
85+ PassDisplayMode mode;
86+ switch (displayMode) {
87+ case MLIR_PASS_DISPLAY_MODE_LIST:
88+ mode = PassDisplayMode::List;
89+ break ;
90+ case MLIR_PASS_DISPLAY_MODE_PIPELINE:
91+ mode = PassDisplayMode::Pipeline;
92+ break ;
93+ default :
94+ llvm_unreachable (" unknown pass display mode" );
95+ }
96+ unwrap (passManager)->enableStatistics (mode);
97+ }
98+
8299MlirOpPassManager mlirPassManagerGetNestedUnder (MlirPassManager passManager,
83100 MlirStringRef operationName) {
84101 return wrap (&unwrap (passManager)->nest (unwrap (operationName)));
Original file line number Diff line number Diff line change @@ -435,3 +435,24 @@ def print_file_tree(directory, prefix=""):
435435
436436 print_file_tree (temp_dir )
437437 log ("// Tree printing end" )
438+
439+
440+ # CHECK-LABEL: TEST: testEnableStatistics
441+ @run
442+ def testEnableStatistics ():
443+ with Context () as ctx :
444+ module = ModuleOp .parse (
445+ """
446+ module {
447+ func.func @main() {
448+ %0 = arith.constant 10
449+ return
450+ }
451+ }
452+ """
453+ )
454+ pm = PassManager .parse ("builtin.module(canonicalize)" )
455+ pm .enable_statistics ()
456+ # CHECK: Pass statistics report
457+ pm .run (module )
458+
You can’t perform that action at this time.
0 commit comments