Start using the new function cloning header
[oota-llvm.git] / lib / VMCore / PassManagerT.h
index cf8624105da987fb323e3c2707ab3a69eb09656c..53ce19f2e1f1fd15e402b68e6c29b7805a9617c2 100644 (file)
@@ -18,6 +18,7 @@
 #include "llvm/Pass.h"
 #include "Support/CommandLine.h"
 #include "Support/LeakDetector.h"
+#include "Support/Timer.h"
 #include <algorithm>
 #include <iostream>
 class Annotable;
@@ -75,25 +76,13 @@ struct PMDebug {
 // amount of time each pass takes to execute.  This only happens when
 // -time-passes is enabled on the command line.
 //
-struct TimeRecord {      // TimeRecord - Data we collect and print for each pass
-  double Elapsed;        // Wall clock time elapsed in seconds
-  double UserTime;       // User time elapsed
-  double SystemTime;     // System time elapsed
-  unsigned long MaxRSS;  // Maximum resident set size (in bytes)
-  unsigned long RSSTemp; // Temp for calculating maxrss
-
-  TimeRecord() : Elapsed(0), UserTime(0), SystemTime(0), MaxRSS(0) {}
-  void passStart(const TimeRecord &T);
-  void passEnd(const TimeRecord &T);
-  void sum(const TimeRecord &TR);
-  bool operator<(const TimeRecord &TR) const;
-
-  void print(const char *PassName, const TimeRecord &TotalTime) const;
-};
 
 class TimingInfo {
-  std::map<Pass*, TimeRecord> TimingData;
-  TimingInfo() {}   // Private ctor, must use create member
+  std::map<Pass*, Timer> TimingData;
+  TimerGroup TG;
+
+  // Private ctor, must use 'create' member
+  TimingInfo() : TG("... Pass execution timing report ...") {}
 public:
   // Create method.  If Timing is enabled, this creates and returns a new timing
   // object, otherwise it returns null.
@@ -101,10 +90,25 @@ public:
   static TimingInfo *create();
 
   // TimingDtor - Print out information about timing information
-  ~TimingInfo();
+  ~TimingInfo() {
+    // Delete all of the timers...
+    TimingData.clear();
+    // TimerGroup is deleted next, printing the report.
+  }
 
-  void passStarted(Pass *P);
-  void passEnded(Pass *P);
+  void passStarted(Pass *P) {
+    if (dynamic_cast<AnalysisResolver*>(P)) return;
+    std::map<Pass*, Timer>::iterator I = TimingData.find(P);
+    if (I == TimingData.end())
+      I=TimingData.insert(std::make_pair(P, Timer(P->getPassName(), TG))).first;
+    I->second.startTimer();
+  }
+  void passEnded(Pass *P) {
+    if (dynamic_cast<AnalysisResolver*>(P)) return;
+    std::map<Pass*, Timer>::iterator I = TimingData.find(P);
+    assert (I != TimingData.end() && "passStarted/passEnded not nested right!");
+    I->second.stopTimer();
+  }
 };
 
 //===----------------------------------------------------------------------===//
@@ -248,7 +252,7 @@ public:
 
 
       // Erase all analyses not in the preserved set...
-      if (!AnUsage.preservesAll()) {
+      if (!AnUsage.getPreservesAll()) {
         const std::vector<AnalysisID> &PreservedSet = AnUsage.getPreservedSet();
         for (std::map<AnalysisID, Pass*>::iterator I = CurrentAnalyses.begin(),
                E = CurrentAnalyses.end(); I != E; )
@@ -354,7 +358,7 @@ public:
     return 0;
   }
 
-  // {start/end}Pass - Called when a pass is started, it just propogates
+  // {start/end}Pass - Called when a pass is started, it just propagates
   // information up to the top level PassManagerT object to tell it that a pass
   // has started or ended.  This is used to gather timing information about
   // passes.
@@ -380,7 +384,7 @@ public:
       LastUseOf[I->second] = User;    // Local pass, extend the lifetime
     } else {
       // Pass not in current available set, must be a higher level pass
-      // available to us, propogate to parent pass manager...  We tell the
+      // available to us, propagate to parent pass manager...  We tell the
       // parent that we (the passmanager) are using the analysis so that it
       // frees the analysis AFTER this pass manager runs.
       //
@@ -468,7 +472,7 @@ private:
       markPassUsed(*I, P);     // Mark *I as used by P
 
     // Erase all analyses not in the preserved set...
-    if (!AnUsage.preservesAll()) {
+    if (!AnUsage.getPreservesAll()) {
       const std::vector<AnalysisID> &PreservedSet = AnUsage.getPreservedSet();
       for (std::map<AnalysisID, Pass*>::iterator I = CurrentAnalyses.begin(),
              E = CurrentAnalyses.end(); I != E; ) {