[Mlir-commits] [mlir] ba8e336 - [mlir] Use array_pod_sort for sorting stats/counters.

Benjamin Kramer llvmlistbot at llvm.org
Thu Mar 17 12:28:05 PDT 2022


Author: Benjamin Kramer
Date: 2022-03-17T20:14:24+01:00
New Revision: ba8e336a238723474ff9aa62021ffefbfb2bfa73

URL: https://github.com/llvm/llvm-project/commit/ba8e336a238723474ff9aa62021ffefbfb2bfa73
DIFF: https://github.com/llvm/llvm-project/commit/ba8e336a238723474ff9aa62021ffefbfb2bfa73.diff

LOG: [mlir] Use array_pod_sort for sorting stats/counters.

This isn't performance sensitive and array_pod_sort is a lot smaller.
NFCI.

Added: 
    

Modified: 
    mlir/lib/Pass/PassStatistics.cpp
    mlir/lib/Support/DebugCounter.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Pass/PassStatistics.cpp b/mlir/lib/Pass/PassStatistics.cpp
index aa46adaf76e9c..660c5100b2134 100644
--- a/mlir/lib/Pass/PassStatistics.cpp
+++ b/mlir/lib/Pass/PassStatistics.cpp
@@ -90,16 +90,17 @@ static void printResultsAsList(raw_ostream &os, OpPassManager &pm) {
     addStats(&pass);
 
   // Sort the statistics by pass name and then by record name.
-  std::vector<std::pair<StringRef, std::vector<Statistic>>> passAndStatistics;
-  for (auto &passIt : mergedStats)
-    passAndStatistics.emplace_back(passIt.first(), std::move(passIt.second));
-  llvm::sort(passAndStatistics, [](const auto &lhs, const auto &rhs) {
-    return lhs.first.compare(rhs.first) < 0;
-  });
+  auto passAndStatistics =
+      llvm::to_vector<16>(llvm::make_pointer_range(mergedStats));
+  llvm::array_pod_sort(passAndStatistics.begin(), passAndStatistics.end(),
+                       [](const decltype(passAndStatistics)::value_type *lhs,
+                          const decltype(passAndStatistics)::value_type *rhs) {
+                         return (*lhs)->getKey().compare((*rhs)->getKey());
+                       });
 
   // Print the timing information sequentially.
   for (auto &statData : passAndStatistics)
-    printPassEntry(os, /*indent=*/2, statData.first, statData.second);
+    printPassEntry(os, /*indent=*/2, statData->first(), statData->second);
 }
 
 /// Print the results in pipeline mode that mirrors the internal pass manager

diff  --git a/mlir/lib/Support/DebugCounter.cpp b/mlir/lib/Support/DebugCounter.cpp
index 930d5d393f774..e0fabb3fa1e29 100644
--- a/mlir/lib/Support/DebugCounter.cpp
+++ b/mlir/lib/Support/DebugCounter.cpp
@@ -87,10 +87,11 @@ void DebugCounter::print(raw_ostream &os) const {
   // Order the registered counters by name.
   SmallVector<const llvm::StringMapEntry<Counter> *, 16> sortedCounters(
       llvm::make_pointer_range(counters));
-  llvm::sort(sortedCounters, [](const llvm::StringMapEntry<Counter> *lhs,
-                                const llvm::StringMapEntry<Counter> *rhs) {
-    return lhs->getKey() < rhs->getKey();
-  });
+  llvm::array_pod_sort(sortedCounters.begin(), sortedCounters.end(),
+                       [](const decltype(sortedCounters)::value_type *lhs,
+                          const decltype(sortedCounters)::value_type *rhs) {
+                         return (*lhs)->getKey().compare((*rhs)->getKey());
+                       });
 
   os << "DebugCounter counters:\n";
   for (const llvm::StringMapEntry<Counter> *counter : sortedCounters) {


        


More information about the Mlir-commits mailing list