#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"),
/// BBPassManager manages BasicBlockPass. It batches all the
/// pass together and sequence them to process one basic block before
/// processing next basic block.
-class VISIBILITY_HIDDEN BBPassManager : public PMDataManager,
- public FunctionPass {
+class BBPassManager : public PMDataManager, public FunctionPass {
public:
static char ID;
static ManagedStatic<sys::SmartMutex<true> > TimingInfoMutex;
-class VISIBILITY_HIDDEN TimingInfo {
+class TimingInfo {
std::map<Pass*, Timer> TimingData;
TimerGroup TG;
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();
- }
-}
+ if (Pass *AP = findAnalysisPass(AID, true)) {
-/// 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");
- }
-
- 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();
+ }
}
}
std::map<AnalysisID, Pass *>::iterator Info = I++;
if (!dynamic_cast<ImmutablePass*>(Info->second) &&
std::find(PreservedSet.begin(), PreservedSet.end(), Info->first) ==
- PreservedSet.end())
+ PreservedSet.end()) {
// Remove this analysis
+ if (PassDebugging >= Details) {
+ Pass *S = Info->second;
+ errs() << " -- '" << P->getPassName() << "' is not preserving '";
+ errs() << S->getPassName() << "'\n";
+ }
InheritedAnalysis[Index]->erase(Info);
+ }
}
}
}
/// Remove analysis passes that are not used any longer
-void PMDataManager::removeDeadPasses(Pass *P, const StringRef &Msg,
+void PMDataManager::removeDeadPasses(Pass *P, StringRef Msg,
enum PassDebuggingString DBG_STR) {
SmallVector<Pass *, 12> DeadPasses;
freePass(*I, Msg, DBG_STR);
}
-void PMDataManager::freePass(Pass *P, const StringRef &Msg,
+void PMDataManager::freePass(Pass *P, StringRef Msg,
enum PassDebuggingString DBG_STR) {
dumpPassInfo(P, FREEING_MSG, DBG_STR, Msg);
void PMDataManager::dumpPassInfo(Pass *P, enum PassDebuggingString S1,
enum PassDebuggingString S2,
- const StringRef &Msg) {
+ StringRef Msg) {
if (PassDebugging < Executions)
return;
errs() << (void*)this << std::string(getDepth()*2+1, ' ');
dumpAnalysisUsage("Preserved", P, analysisUsage.getPreservedSet());
}
-void PMDataManager::dumpAnalysisUsage(const StringRef &Msg, const Pass *P,
+void PMDataManager::dumpAnalysisUsage(StringRef Msg, const Pass *P,
const AnalysisUsage::VectorType &Set) const {
assert(PassDebugging >= Details);
if (Set.empty())
bool FunctionPassManagerImpl::doInitialization(Module &M) {
bool Changed = false;
+ dumpArguments();
+ dumpPasses();
+
for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index)
Changed |= getContainedManager(Index)->doInitialization(M);
bool Changed = false;
TimingInfo::createTheTimeInfo();
- dumpArguments();
- dumpPasses();
-
initializeAllAnalysisInfo();
for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index)
Changed |= getContainedManager(Index)->runOnFunction(F);
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;
}
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
ModulePass *MP = getContainedPass(Index);
- dumpPassInfo(MP, EXECUTION_MSG, ON_MODULE_MSG,
- M.getModuleIdentifier().c_str());
+ dumpPassInfo(MP, EXECUTION_MSG, ON_MODULE_MSG, M.getModuleIdentifier());
dumpRequiredSet(MP);
initializeAnalysisImpl(MP);
if (Changed)
dumpPassInfo(MP, MODIFICATION_MSG, ON_MODULE_MSG,
- M.getModuleIdentifier().c_str());
+ M.getModuleIdentifier());
dumpPreservedSet(MP);
verifyPreservedAnalysis(MP);
removeNotPreservedAnalysis(MP);
recordAvailableAnalysis(MP);
- removeDeadPasses(MP, M.getModuleIdentifier().c_str(), ON_MODULE_MSG);
+ removeDeadPasses(MP, M.getModuleIdentifier(), ON_MODULE_MSG);
}
// Finalize on-the-fly passes