Skip to content

Commit 1e1c9b4

Browse files
committed
Added Pass Statistics
1 parent 8613212 commit 1e1c9b4

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

mlir/mhlo-pass-example/Pow2/main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ int main(int argc, char *argv[]) {
9494
if (mlir::failed(mlir::applyPassManagerCLOptions(pm)))
9595
return 4;
9696

97+
// Enable the statistics (only works on debug mode)
98+
// pm.enableStatistics();
99+
97100
// Add a run of the canonicalizer to optimize the mlir module.
98101
// pm.addNestedPass<mlir::func::FuncOp>(mlir::createCanonicalizerPass());
99102
pm.addNestedPass<mlir::func::FuncOp>(

mlir/mhlo-pass-example/Pow2/mlir/Pow2.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ namespace {
8989
struct SubstitutePow2Pass
9090
: public PassWrapper<SubstitutePow2Pass, OperationPass<func::FuncOp>> {
9191
MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(SubstitutePow2Pass)
92+
// Here we can add the statistic (the statistic is only works on debug mode)
93+
// Since the statistic has the atomic value, we can't use the default copy
94+
// constructor and assignment operator.
95+
// SubstitutePow2Pass() = default;
96+
// SubstitutePow2Pass(const SubstitutePow2Pass &other) {
97+
// this->statistic = other.statistic.getValue();
98+
// };
99+
// mlir::Pass::Statistic statistic{this, "example-statistic", "An example
100+
// statistic"};
92101

93102
void runOnOperation() final;
94103
};
@@ -100,6 +109,8 @@ void SubstitutePow2Pass::runOnOperation() {
100109
patterns.add<Pow2OptPattern>(&getContext());
101110
if (failed(applyPatternsAndFoldGreedily(op, std::move(patterns))))
102111
signalPassFailure();
112+
// Here we can add the statistic (the statistic is only works on debug mode)
113+
// statistic++;
103114
}
104115

105116
namespace {

mlir/mhlo-pass-example/Pow2/mlir/transform/pass.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def Pow2Pass : Pass<"pow-2", "func::FuncOp"> {
2020

2121
// Specify any statistics.
2222
let statistics = [
23-
// Statistic</*C++ variable name=*/"statistic",
24-
// /*display name*/"example-statistic",
25-
// /*description*/"An example statistic">
23+
Statistic</*C++ variable name=*/"statistic",
24+
/*display name*/"example-statistic",
25+
/*description*/"An example statistic">
2626
];
2727
}

0 commit comments

Comments
 (0)