#include "llvm/PassManagers.h"
+#include "llvm/Assembly/Writer.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Timer.h"
#include "llvm/Module.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/System/Mutex.h"
#include "llvm/System/Threading.h"
-#include "llvm/Analysis/Dominators.h"
#include "llvm-c/Core.h"
#include <algorithm>
#include <cstdio>
None, Arguments, Structure, Executions, Details
};
-// Always verify dominfo if expensive checking is enabled.
-#ifdef XDEBUG
-bool VerifyDomInfo = true;
-#else
-bool VerifyDomInfo = false;
-#endif
-static cl::opt<bool,true>
-VerifyDomInfoX("verify-dom-info", cl::location(VerifyDomInfo),
- cl::desc("Verify dominator info (time consuming)"));
-
static cl::opt<enum PassDebugLevel>
PassDebugging("debug-pass", cl::Hidden,
cl::desc("Print PassManager debugging information"),
// null. It may be called multiple times.
static void createTheTimeInfo();
- void passStarted(Pass *P) {
+ /// passStarted - This method creates a timer for the given pass if it doesn't
+ /// already have one, and starts the timer.
+ Timer *passStarted(Pass *P) {
if (dynamic_cast<PMDataManager *>(P))
- return;
+ return 0;
sys::SmartScopedLock<true> Lock(*TimingInfoMutex);
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<PMDataManager *>(P))
- return;
-
- sys::SmartScopedLock<true> Lock(*TimingInfoMutex);
- std::map<Pass*, Timer>::iterator I = TimingData.find(P);
- assert(I != TimingData.end() && "passStarted/passEnded not nested right!");
- I->second.stopTimer();
+ Timer *T = &I->second;
+ T->startTimer();
+ return T;
}
};
for (AnalysisUsage::VectorType::const_iterator I = PreservedSet.begin(),
E = PreservedSet.end(); I != E; ++I) {
AnalysisID AID = *I;
- if (Pass *AP = findAnalysisPass(AID, true))
- AP->verifyAnalysis();
- }
-}
-
-/// verifyDomInfo - Verify dominator information if it is available.
-void PMDataManager::verifyDomInfo(Pass &P, Function &F) {
- if (!VerifyDomInfo || !P.getResolver())
- return;
-
- DominatorTree *DT = P.getAnalysisIfAvailable<DominatorTree>();
- if (!DT)
- return;
-
- DominatorTree OtherDT;
- OtherDT.getBase().recalculate(F);
- if (DT->compare(OtherDT)) {
- errs() << "Dominator Information for " << F.getName() << "\n";
- errs() << "Pass '" << P.getPassName() << "'\n";
- errs() << "----- Valid -----\n";
- OtherDT.dump();
- errs() << "----- Invalid -----\n";
- DT->dump();
- llvm_unreachable("Invalid dominator info");
- }
+ if (Pass *AP = findAnalysisPass(AID, true)) {
- DominanceFrontier *DF = P.getAnalysisIfAvailable<DominanceFrontier>();
- if (!DF)
- return;
-
- DominanceFrontier OtherDF;
- std::vector<BasicBlock*> DTRoots = DT->getRoots();
- OtherDF.calculate(*DT, DT->getNode(DTRoots[0]));
- if (DF->compare(OtherDF)) {
- errs() << "Dominator Information for " << F.getName() << "\n";
- errs() << "Pass '" << P.getPassName() << "'\n";
- errs() << "----- Valid -----\n";
- OtherDF.dump();
- errs() << "----- Invalid -----\n";
- DF->dump();
- llvm_unreachable("Invalid dominator info");
+ Timer *T = 0;
+ if (TheTimeInfo) T = TheTimeInfo->passStarted(AP);
+ AP->verifyAnalysis();
+ if (T) T->stopTimer();
+ }
}
}
}
for (SmallVector<Pass *, 12>::iterator I = DeadPasses.begin(),
- E = DeadPasses.end(); I != E; ++I) {
+ E = DeadPasses.end(); I != E; ++I)
+ freePass(*I, Msg, DBG_STR);
+}
- dumpPassInfo(*I, FREEING_MSG, DBG_STR, Msg);
+void PMDataManager::freePass(Pass *P, const StringRef &Msg,
+ enum PassDebuggingString DBG_STR) {
+ dumpPassInfo(P, FREEING_MSG, DBG_STR, Msg);
- {
- // If the pass crashes releasing memory, remember this.
- PassManagerPrettyStackEntry X(*I);
-
- if (TheTimeInfo) TheTimeInfo->passStarted(*I);
- (*I)->releaseMemory();
- if (TheTimeInfo) TheTimeInfo->passEnded(*I);
- }
- if (const PassInfo *PI = (*I)->getPassInfo()) {
- std::map<AnalysisID, Pass*>::iterator Pos =
- AvailableAnalysis.find(PI);
+ {
+ // If the pass crashes releasing memory, remember this.
+ PassManagerPrettyStackEntry X(P);
+
+ Timer *T = StartPassTimer(P);
+ P->releaseMemory();
+ StopPassTimer(P, T);
+ }
- // It is possible that pass is already removed from the AvailableAnalysis
- if (Pos != AvailableAnalysis.end())
- AvailableAnalysis.erase(Pos);
+ if (const PassInfo *PI = P->getPassInfo()) {
+ // Remove the pass itself (if it is not already removed).
+ AvailableAnalysis.erase(PI);
- // Remove all interfaces this pass implements, for which it is also
- // listed as the available implementation.
- const std::vector<const PassInfo*> &II = PI->getInterfacesImplemented();
- for (unsigned i = 0, e = II.size(); i != e; ++i) {
- Pos = AvailableAnalysis.find(II[i]);
- if (Pos != AvailableAnalysis.end() && Pos->second == *I)
- AvailableAnalysis.erase(Pos);
- }
+ // Remove all interfaces this pass implements, for which it is also
+ // listed as the available implementation.
+ const std::vector<const PassInfo*> &II = PI->getInterfacesImplemented();
+ for (unsigned i = 0, e = II.size(); i != e; ++i) {
+ std::map<AnalysisID, Pass*>::iterator Pos =
+ AvailableAnalysis.find(II[i]);
+ if (Pos != AvailableAnalysis.end() && Pos->second == P)
+ AvailableAnalysis.erase(Pos);
}
}
}
// If the pass crashes, remember this.
PassManagerPrettyStackEntry X(BP, *I);
- if (TheTimeInfo) TheTimeInfo->passStarted(BP);
+ Timer *T = StartPassTimer(BP);
Changed |= BP->runOnBasicBlock(*I);
- if (TheTimeInfo) TheTimeInfo->passEnded(BP);
+ StopPassTimer(BP, T);
}
if (Changed)
{
PassManagerPrettyStackEntry X(FP, F);
- if (TheTimeInfo) TheTimeInfo->passStarted(FP);
+ Timer *T = StartPassTimer(FP);
Changed |= FP->runOnFunction(F);
- if (TheTimeInfo) TheTimeInfo->passEnded(FP);
+ StopPassTimer(FP, T);
}
if (Changed)
removeNotPreservedAnalysis(FP);
recordAvailableAnalysis(FP);
removeDeadPasses(FP, F.getName(), ON_FUNCTION_MSG);
-
- // If dominator information is available then verify the info if requested.
- verifyDomInfo(*FP, F);
}
return Changed;
}
{
PassManagerPrettyStackEntry X(MP, M);
- if (TheTimeInfo) TheTimeInfo->passStarted(MP);
+ Timer *T = StartPassTimer(MP);
Changed |= MP->runOnModule(M);
- if (TheTimeInfo) TheTimeInfo->passEnded(MP);
+ StopPassTimer(MP, T);
}
if (Changed)
}
/// If TimingInfo is enabled then start pass timer.
-void llvm::StartPassTimer(Pass *P) {
+Timer *llvm::StartPassTimer(Pass *P) {
if (TheTimeInfo)
- TheTimeInfo->passStarted(P);
+ return TheTimeInfo->passStarted(P);
+ return 0;
}
/// If TimingInfo is enabled then stop pass timer.
-void llvm::StopPassTimer(Pass *P) {
- if (TheTimeInfo)
- TheTimeInfo->passEnded(P);
+void llvm::StopPassTimer(Pass *P, Timer *T) {
+ if (T) T->stopTimer();
}
//===----------------------------------------------------------------------===//