diff --git a/mlir/lib/Pass/PassStatistics.cpp b/mlir/lib/Pass/PassStatistics.cpp --- a/mlir/lib/Pass/PassStatistics.cpp +++ b/mlir/lib/Pass/PassStatistics.cpp @@ -33,11 +33,10 @@ return; // Make sure to sort the statistics by name. - llvm::array_pod_sort(stats.begin(), stats.end(), - [](const auto *lhs, const auto *rhs) { - return llvm::array_pod_sort_comparator( - &lhs->name, &rhs->name); - }); + llvm::array_pod_sort( + stats.begin(), stats.end(), [](const auto *lhs, const auto *rhs) { + return StringRef{lhs->name}.compare(StringRef{rhs->name}); + }); // Collect the largest name and value length from each of the statistics. size_t largestName = 0, largestValue = 0; diff --git a/mlir/test/Pass/pipeline-stats.mlir b/mlir/test/Pass/pipeline-stats.mlir --- a/mlir/test/Pass/pipeline-stats.mlir +++ b/mlir/test/Pass/pipeline-stats.mlir @@ -5,14 +5,17 @@ // LIST: Pass statistics report // LIST: TestStatisticPass // LIST-NEXT: (S) {{0|8}} num-ops - Number of operations counted +// LIST-NEXT: (S) {{0|8}} num-ops2 - Number of operations counted one more time // LIST-NOT: Verifier // PIPELINE: Pass statistics report // PIPELINE: 'func.func' Pipeline // PIPELINE-NEXT: TestStatisticPass // PIPELINE-NEXT: (S) {{0|4}} num-ops - Number of operations counted +// PIPELINE-NEXT: (S) {{0|4}} num-ops2 - Number of operations counted one more time // PIPELINE-NEXT: TestStatisticPass // PIPELINE-NEXT: (S) {{0|4}} num-ops - Number of operations counted +// PIPELINE-NEXT: (S) {{0|4}} num-ops2 - Number of operations counted one more time func.func @foo() { return diff --git a/mlir/test/lib/Pass/TestPassManager.cpp b/mlir/test/lib/Pass/TestPassManager.cpp --- a/mlir/test/lib/Pass/TestPassManager.cpp +++ b/mlir/test/lib/Pass/TestPassManager.cpp @@ -172,10 +172,17 @@ StringRef getArgument() const final { return "test-stats-pass"; } StringRef getDescription() const final { return "Test pass statistics"; } + // Use a couple of statistics to verify their ordering + // in the print out. The statistics are registered in the order + // of construction, so put "num-ops2" before "num-ops" and + // make sure that the order is reversed. + Statistic opCountDuplicate{this, "num-ops2", + "Number of operations counted one more time"}; Statistic opCount{this, "num-ops", "Number of operations counted"}; void runOnOperation() final { getOperation()->walk([&](Operation *) { ++opCount; }); + getOperation()->walk([&](Operation *) { ++opCountDuplicate; }); } }; } // namespace