[mlir] Fixed ordering of pass statistics.

The change makes sure the plain C string statistics names
are properly ordered.

Differential Revision: https://reviews.llvm.org/D130122
This commit is contained in:
Slava Zakharin
2022-07-19 13:26:35 -07:00
parent 41f6a21025
commit 04644a9e55
3 changed files with 14 additions and 5 deletions

View File

@@ -33,11 +33,10 @@ static void printPassEntry(raw_ostream &os, unsigned indent, StringRef pass,
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<const char *>(
&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;

View File

@@ -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

View File

@@ -172,10 +172,17 @@ struct TestStatisticPass
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