File tree Expand file tree Collapse file tree 4 files changed +62
-0
lines changed Expand file tree Collapse file tree 4 files changed +62
-0
lines changed Original file line number Diff line number Diff line change @@ -92,6 +92,18 @@ mlirPassManagerEnableVerifier(MlirPassManager passManager, bool enable);
92
92
MLIR_CAPI_EXPORTED void
93
93
mlirPassManagerEnableTiming (MlirPassManager passManager );
94
94
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
+
95
107
/// Nest an OpPassManager under the top-level PassManager, the nested
96
108
/// passmanager will only run on operations matching the provided name.
97
109
/// The returned OpPassManager will be destroyed when the parent is destroyed.
Original file line number Diff line number Diff line change @@ -57,6 +57,13 @@ class PyPassManager {
57
57
58
58
// / Create the `mlir.passmanager` here.
59
59
void mlir::python::populatePassManagerSubmodule (nb::module_ &m) {
60
+ // ----------------------------------------------------------------------------
61
+ // Mapping of enumerated types
62
+ // ----------------------------------------------------------------------------
63
+ nb::enum_<MlirPassDisplayMode>(m, " PassDisplayMode" )
64
+ .value (" LIST" , MLIR_PASS_DISPLAY_MODE_LIST)
65
+ .value (" PIPELINE" , MLIR_PASS_DISPLAY_MODE_PIPELINE);
66
+
60
67
// ----------------------------------------------------------------------------
61
68
// Mapping of MlirExternalPass
62
69
// ----------------------------------------------------------------------------
@@ -139,6 +146,14 @@ void mlir::python::populatePassManagerSubmodule(nb::module_ &m) {
139
146
mlirPassManagerEnableTiming (passManager.get ());
140
147
},
141
148
" Enable pass timing." )
149
+ .def (
150
+ " enable_statistics" ,
151
+ [](PyPassManager &passManager, MlirPassDisplayMode displayMode) {
152
+ mlirPassManagerEnableStatistics (passManager.get (), displayMode);
153
+ },
154
+ " displayMode" _a =
155
+ MlirPassDisplayMode::MLIR_PASS_DISPLAY_MODE_PIPELINE,
156
+ " Enable pass statistics." )
142
157
.def_static (
143
158
" parse" ,
144
159
[](const std::string &pipeline, DefaultingPyMlirContext context) {
Original file line number Diff line number Diff line change 13
13
#include " mlir/CAPI/Support.h"
14
14
#include " mlir/CAPI/Utils.h"
15
15
#include " mlir/Pass/PassManager.h"
16
+ #include " llvm/Support/ErrorHandling.h"
16
17
#include < optional>
17
18
18
19
using namespace mlir ;
@@ -79,6 +80,20 @@ void mlirPassManagerEnableTiming(MlirPassManager passManager) {
79
80
unwrap (passManager)->enableTiming ();
80
81
}
81
82
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
+ }
94
+ unwrap (passManager)->enableStatistics (mode);
95
+ }
96
+
82
97
MlirOpPassManager mlirPassManagerGetNestedUnder (MlirPassManager passManager,
83
98
MlirStringRef operationName) {
84
99
return wrap (&unwrap (passManager)->nest (unwrap (operationName)));
Original file line number Diff line number Diff line change @@ -435,3 +435,23 @@ def print_file_tree(directory, prefix=""):
435
435
436
436
print_file_tree (temp_dir )
437
437
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 )
You can’t perform that action at this time.
0 commit comments