[llvm] 0125db9 - [TimePasses] Small fix in "-time-passes" flag that makes it more stable

Kirill Naumov via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 8 09:01:31 PDT 2020


Author: Kirill Naumov
Date: 2020-04-08T15:59:45Z
New Revision: 0125db9ab21de29191e04fe021bb675b146f2645

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

LOG: [TimePasses] Small fix in "-time-passes" flag that makes it more stable

Adds StringMap for TimingData.

Differential Revision: https://reviews.llvm.org/D76946
Reviewed By: fedor.sergeev

Added: 
    

Modified: 
    llvm/include/llvm/IR/PassTimingInfo.h
    llvm/lib/IR/PassTimingInfo.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/IR/PassTimingInfo.h b/llvm/include/llvm/IR/PassTimingInfo.h
index b8d8f117f73d..b70850fd64d7 100644
--- a/llvm/include/llvm/IR/PassTimingInfo.h
+++ b/llvm/include/llvm/IR/PassTimingInfo.h
@@ -55,11 +55,9 @@ class TimePassesHandler {
   /// A group of all pass-timing timers.
   TimerGroup TG;
 
+  using TimerVector = llvm::SmallVector<std::unique_ptr<Timer>, 4>;
   /// Map of timers for pass invocations
-  DenseMap<PassInvocationID, std::unique_ptr<Timer>> TimingData;
-
-  /// Map that counts invocations of passes, for use in UniqPassID construction.
-  StringMap<unsigned> PassIDCountMap;
+  StringMap<TimerVector> TimingData;
 
   /// Stack of currently active timers.
   SmallVector<Timer *, 8> TimerStack;
@@ -96,9 +94,6 @@ class TimePassesHandler {
   /// Returns the new timer for each new run of the pass.
   Timer &getPassTimer(StringRef PassID);
 
-  /// Returns the incremented counter for the next invocation of \p PassID.
-  unsigned nextPassID(StringRef PassID) { return ++PassIDCountMap[PassID]; }
-
   void startTimer(StringRef PassID);
   void stopTimer(StringRef PassID);
 

diff  --git a/llvm/lib/IR/PassTimingInfo.cpp b/llvm/lib/IR/PassTimingInfo.cpp
index 9cc44ea05fee..25275e5733ac 100644
--- a/llvm/lib/IR/PassTimingInfo.cpp
+++ b/llvm/lib/IR/PassTimingInfo.cpp
@@ -168,17 +168,18 @@ void reportAndResetTimings(raw_ostream *OutStream) {
 /// Returns the timer for the specified pass invocation of \p PassID.
 /// Each time it creates a new timer.
 Timer &TimePassesHandler::getPassTimer(StringRef PassID) {
-  // Bump counts for each request of the timer.
-  unsigned Count = nextPassID(PassID);
+  // Take a vector of Timers created for this \p PassID and append
+  // one more timer to it.
+  TimerVector &Timers = TimingData[PassID];
+  unsigned Count = Timers.size() + 1;
 
-  // Unconditionally appending description with a pass-invocation number.
   std::string FullDesc = formatv("{0} #{1}", PassID, Count).str();
 
-  PassInvocationID UID{PassID, Count};
   Timer *T = new Timer(PassID, FullDesc, TG);
-  auto Pair = TimingData.try_emplace(UID, T);
-  assert(Pair.second && "should always create a new timer");
-  return *(Pair.first->second.get());
+  Timers.emplace_back(T);
+  assert(Count == Timers.size() && "sanity check");
+
+  return *T;
 }
 
 TimePassesHandler::TimePassesHandler(bool Enabled)
@@ -198,17 +199,23 @@ LLVM_DUMP_METHOD void TimePassesHandler::dump() const {
   dbgs() << "Dumping timers for " << getTypeName<TimePassesHandler>()
          << ":\n\tRunning:\n";
   for (auto &I : TimingData) {
-    const Timer *MyTimer = I.second.get();
-    if (!MyTimer || MyTimer->isRunning())
-      dbgs() << "\tTimer " << MyTimer << " for pass " << I.first.first << "("
-             << I.first.second << ")\n";
+    StringRef PassID = I.getKey();
+    const TimerVector& MyTimers = I.getValue();
+    for (unsigned idx = 0; idx < MyTimers.size(); idx++) {
+      const Timer* MyTimer = MyTimers[idx].get();
+      if (MyTimer && MyTimer->isRunning())
+        dbgs() << "\tTimer " << MyTimer << " for pass " << PassID << "(" << idx << ")\n";
+    }
   }
   dbgs() << "\tTriggered:\n";
   for (auto &I : TimingData) {
-    const Timer *MyTimer = I.second.get();
-    if (!MyTimer || (MyTimer->hasTriggered() && !MyTimer->isRunning()))
-      dbgs() << "\tTimer " << MyTimer << " for pass " << I.first.first << "("
-             << I.first.second << ")\n";
+    StringRef PassID = I.getKey();
+    const TimerVector& MyTimers = I.getValue();
+    for (unsigned idx = 0; idx < MyTimers.size(); idx++) {
+      const Timer* MyTimer = MyTimers[idx].get();
+      if (MyTimer && MyTimer->hasTriggered() && !MyTimer->isRunning())
+        dbgs() << "\tTimer " << MyTimer << " for pass " << PassID << "(" << idx << ")\n";
+    }
   }
 }
 


        


More information about the llvm-commits mailing list