#include "llvm/Pass.h"
#include "Support/CommandLine.h"
#include "Support/LeakDetector.h"
+#include "Support/Timer.h"
#include <algorithm>
#include <iostream>
class Annotable;
// 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.
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();
+ }
};
//===----------------------------------------------------------------------===//
// 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; )
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.
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.
//
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; ) {