#include "llvm/ModuleProvider.h"
#include "llvm/Support/Streams.h"
#include "llvm/Support/ManagedStatic.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/Threading.h"
+#include "llvm/System/Mutex.h"
#include "llvm/Analysis/Dominators.h"
#include "llvm-c/Core.h"
#include <algorithm>
-#include <vector>
+#include <cstdio>
#include <map>
using namespace llvm;
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)"));
clEnumValEnd));
} // End of llvm namespace
+void PassManagerPrettyStackEntry::print(raw_ostream &OS) const {
+ if (V == 0 && M == 0)
+ OS << "Releasing pass '";
+ else
+ OS << "Running pass '";
+
+ OS << P->getPassName() << "'";
+
+ if (M) {
+ OS << " on module '" << M->getModuleIdentifier() << "'.\n";
+ return;
+ }
+ if (V == 0) {
+ OS << '\n';
+ return;
+ }
+
+ OS << " on ";
+ if (isa<Function>(V))
+ OS << "function";
+ else if (isa<BasicBlock>(V))
+ OS << "basic block";
+ else
+ OS << "value";
+
+ OS << " '";
+ WriteAsOperand(OS, V, /*PrintTy=*/false, M);
+ OS << "'\n";
+}
+
+
namespace {
//===----------------------------------------------------------------------===//
public:
static char ID;
explicit BBPassManager(int Depth)
- : PMDataManager(Depth), FunctionPass((intptr_t)&ID) {}
+ : PMDataManager(Depth), FunctionPass(&ID) {}
/// Execute all of the passes scheduled for execution. Keep track of
/// whether any of the passes modifies the function, and if so, return true.
}
BasicBlockPass *getContainedPass(unsigned N) {
- assert ( N < PassVector.size() && "Pass number out of range!");
+ assert(N < PassVector.size() && "Pass number out of range!");
BasicBlockPass *BP = static_cast<BasicBlockPass *>(PassVector[N]);
return BP;
}
public:
static char ID;
explicit FunctionPassManagerImpl(int Depth) :
- Pass((intptr_t)&ID), PMDataManager(Depth),
+ Pass(&ID), PMDataManager(Depth),
PMTopLevelManager(TLM_Function) { }
/// add - Add a pass to the queue of passes to run. This passes ownership of
}
FPPassManager *getContainedManager(unsigned N) {
- assert ( N < PassManagers.size() && "Pass number out of range!");
+ assert(N < PassManagers.size() && "Pass number out of range!");
FPPassManager *FP = static_cast<FPPassManager *>(PassManagers[N]);
return FP;
}
/// It batches all Module passes and function pass managers together and
/// sequences them to process one module.
class MPPassManager : public Pass, public PMDataManager {
-
public:
static char ID;
explicit MPPassManager(int Depth) :
- Pass((intptr_t)&ID), PMDataManager(Depth) { }
+ Pass(&ID), PMDataManager(Depth) { }
// Delete on the fly managers.
virtual ~MPPassManager() {
}
ModulePass *getContainedPass(unsigned N) {
- assert ( N < PassVector.size() && "Pass number out of range!");
- ModulePass *MP = static_cast<ModulePass *>(PassVector[N]);
- return MP;
+ assert(N < PassVector.size() && "Pass number out of range!");
+ return static_cast<ModulePass *>(PassVector[N]);
}
virtual PassManagerType getPassManagerType() const {
public:
static char ID;
explicit PassManagerImpl(int Depth) :
- Pass((intptr_t)&ID), PMDataManager(Depth),
- PMTopLevelManager(TLM_Pass) { }
+ Pass(&ID), PMDataManager(Depth), PMTopLevelManager(TLM_Pass) { }
/// add - Add a pass to the queue of passes to run. This passes ownership of
/// the Pass to the PassManager. When the PassManager is destroyed, the pass
}
inline void addTopLevelPass(Pass *P) {
-
if (ImmutablePass *IP = dynamic_cast<ImmutablePass *> (P)) {
// P is a immutable pass and it will be managed by this
} else {
P->assignPassManager(activeStack);
}
-
}
MPPassManager *getContainedManager(unsigned N) {
- assert ( N < PassManagers.size() && "Pass number out of range!");
+ assert(N < PassManagers.size() && "Pass number out of range!");
MPPassManager *MP = static_cast<MPPassManager *>(PassManagers[N]);
return MP;
}
-
};
char PassManagerImpl::ID = 0;
namespace {
//===----------------------------------------------------------------------===//
-// TimingInfo Class - This class is used to calculate information about the
-// amount of time each pass takes to execute. This only happens when
-// -time-passes is enabled on the command line.
-//
+/// TimingInfo Class - This class is used to calculate information about the
+/// amount of time each pass takes to execute. This only happens when
+/// -time-passes is enabled on the command line.
+///
+
+static ManagedStatic<sys::Mutex> TimingInfoMutex;
class VISIBILITY_HIDDEN TimingInfo {
std::map<Pass*, Timer> TimingData;
static void createTheTimeInfo();
void passStarted(Pass *P) {
-
if (dynamic_cast<PMDataManager *>(P))
return;
+ if (llvm_is_multithreaded()) TimingInfoMutex->acquire();
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();
+ if (llvm_is_multithreaded()) TimingInfoMutex->release();
}
void passEnded(Pass *P) {
-
if (dynamic_cast<PMDataManager *>(P))
return;
+ if (llvm_is_multithreaded()) TimingInfoMutex->acquire();
std::map<Pass*, Timer>::iterator I = TimingData.find(P);
- assert (I != TimingData.end() && "passStarted/passEnded not nested right!");
+ assert(I != TimingData.end() && "passStarted/passEnded not nested right!");
I->second.stopTimer();
+ if (llvm_is_multithreaded()) TimingInfoMutex->release();
}
};
// PMTopLevelManager implementation
/// Initialize top level manager. Create first pass manager.
-PMTopLevelManager::PMTopLevelManager (enum TopLevelManagerType t) {
-
+PMTopLevelManager::PMTopLevelManager(enum TopLevelManagerType t) {
if (t == TLM_Pass) {
MPPassManager *MPP = new MPPassManager(1);
MPP->setTopLevelManager(this);
addPassManager(MPP);
activeStack.push(MPP);
- }
- else if (t == TLM_Function) {
+ } else if (t == TLM_Function) {
FPPassManager *FPP = new FPPassManager(1);
FPP->setTopLevelManager(this);
addPassManager(FPP);
/// Set pass P as the last user of the given analysis passes.
void PMTopLevelManager::setLastUser(SmallVector<Pass *, 12> &AnalysisPasses,
Pass *P) {
-
for (SmallVector<Pass *, 12>::iterator I = AnalysisPasses.begin(),
E = AnalysisPasses.end(); I != E; ++I) {
Pass *AP = *I;
// generate the analysis again. Stale analysis info should not be
// available at this point.
if (P->getPassInfo() &&
- P->getPassInfo()->isAnalysis() && findAnalysisPass(P->getPassInfo()))
+ P->getPassInfo()->isAnalysis() && findAnalysisPass(P->getPassInfo())) {
+ delete P;
return;
+ }
AnalysisUsage *AnUsage = findAnalysisUsage(P);
- const AnalysisUsage::VectorType &RequiredSet = AnUsage->getRequiredSet();
- for (AnalysisUsage::VectorType::const_iterator I = RequiredSet.begin(),
- E = RequiredSet.end(); I != E; ++I) {
-
- Pass *AnalysisPass = findAnalysisPass(*I);
- if (!AnalysisPass) {
- AnalysisPass = (*I)->createPass();
- // Schedule this analysis run first only if it is not a lower level
- // analysis pass. Lower level analsyis passes are run on the fly.
- if (P->getPotentialPassManagerType () >=
- AnalysisPass->getPotentialPassManagerType())
- schedulePass(AnalysisPass);
- else
- delete AnalysisPass;
+ bool checkAnalysis = true;
+ while (checkAnalysis) {
+ checkAnalysis = false;
+
+ const AnalysisUsage::VectorType &RequiredSet = AnUsage->getRequiredSet();
+ for (AnalysisUsage::VectorType::const_iterator I = RequiredSet.begin(),
+ E = RequiredSet.end(); I != E; ++I) {
+
+ Pass *AnalysisPass = findAnalysisPass(*I);
+ if (!AnalysisPass) {
+ AnalysisPass = (*I)->createPass();
+ if (P->getPotentialPassManagerType () ==
+ AnalysisPass->getPotentialPassManagerType())
+ // Schedule analysis pass that is managed by the same pass manager.
+ schedulePass(AnalysisPass);
+ else if (P->getPotentialPassManagerType () >
+ AnalysisPass->getPotentialPassManagerType()) {
+ // Schedule analysis pass that is managed by a new manager.
+ schedulePass(AnalysisPass);
+ // Recheck analysis passes to ensure that required analysises that
+ // are already checked are still available.
+ checkAnalysis = true;
+ }
+ else
+ // Do not schedule this analysis. Lower level analsyis
+ // passes are run on the fly.
+ delete AnalysisPass;
+ }
}
}
Pass *P = NULL;
// Check pass managers
- for (std::vector<PMDataManager *>::iterator I = PassManagers.begin(),
+ for (SmallVector<PMDataManager *, 8>::iterator I = PassManagers.begin(),
E = PassManagers.end(); P == NULL && I != E; ++I) {
PMDataManager *PMD = *I;
P = PMD->findAnalysisPass(AID, false);
}
// Check other pass managers
- for (std::vector<PMDataManager *>::iterator I = IndirectPassManagers.begin(),
+ for (SmallVector<PMDataManager *, 8>::iterator
+ I = IndirectPassManagers.begin(),
E = IndirectPassManagers.end(); P == NULL && I != E; ++I)
P = (*I)->findAnalysisPass(AID, false);
- for (std::vector<ImmutablePass *>::iterator I = ImmutablePasses.begin(),
+ for (SmallVector<ImmutablePass *, 8>::iterator I = ImmutablePasses.begin(),
E = ImmutablePasses.end(); P == NULL && I != E; ++I) {
const PassInfo *PI = (*I)->getPassInfo();
if (PI == AID)
// (sometimes indirectly), but there's no inheritance relationship
// between PMDataManager and Pass, so we have to dynamic_cast to get
// from a PMDataManager* to a Pass*.
- for (std::vector<PMDataManager *>::const_iterator I = PassManagers.begin(),
+ for (SmallVector<PMDataManager *, 8>::const_iterator I = PassManagers.begin(),
E = PassManagers.end(); I != E; ++I)
dynamic_cast<Pass *>(*I)->dumpPassStructure(1);
}
return;
cerr << "Pass Arguments: ";
- for (std::vector<PMDataManager *>::const_iterator I = PassManagers.begin(),
- E = PassManagers.end(); I != E; ++I) {
- PMDataManager *PMD = *I;
- PMD->dumpPassArguments();
- }
+ for (SmallVector<PMDataManager *, 8>::const_iterator I = PassManagers.begin(),
+ E = PassManagers.end(); I != E; ++I)
+ (*I)->dumpPassArguments();
cerr << "\n";
}
void PMTopLevelManager::initializeAllAnalysisInfo() {
-
- for (std::vector<PMDataManager *>::iterator I = PassManagers.begin(),
- E = PassManagers.end(); I != E; ++I) {
- PMDataManager *PMD = *I;
- PMD->initializeAnalysisInfo();
- }
+ for (SmallVector<PMDataManager *, 8>::iterator I = PassManagers.begin(),
+ E = PassManagers.end(); I != E; ++I)
+ (*I)->initializeAnalysisInfo();
// Initailize other pass managers
- for (std::vector<PMDataManager *>::iterator I = IndirectPassManagers.begin(),
+ for (SmallVector<PMDataManager *, 8>::iterator I = IndirectPassManagers.begin(),
E = IndirectPassManagers.end(); I != E; ++I)
(*I)->initializeAnalysisInfo();
- for(DenseMap<Pass *, Pass *>::iterator DMI = LastUser.begin(),
+ for (DenseMap<Pass *, Pass *>::iterator DMI = LastUser.begin(),
DME = LastUser.end(); DMI != DME; ++DMI) {
DenseMap<Pass *, SmallPtrSet<Pass *, 8> >::iterator InvDMI =
InversedLastUser.find(DMI->second);
/// Destructor
PMTopLevelManager::~PMTopLevelManager() {
- for (std::vector<PMDataManager *>::iterator I = PassManagers.begin(),
+ for (SmallVector<PMDataManager *, 8>::iterator I = PassManagers.begin(),
E = PassManagers.end(); I != E; ++I)
delete *I;
- for (std::vector<ImmutablePass *>::iterator
+ for (SmallVector<ImmutablePass *, 8>::iterator
I = ImmutablePasses.begin(), E = ImmutablePasses.end(); I != E; ++I)
delete *I;
for (DenseMap<Pass *, AnalysisUsage *>::iterator DMI = AnUsageMap.begin(),
- DME = AnUsageMap.end(); DMI != DME; ++DMI) {
- AnalysisUsage *AU = DMI->second;
- delete AU;
- }
-
+ DME = AnUsageMap.end(); DMI != DME; ++DMI)
+ delete DMI->second;
}
//===----------------------------------------------------------------------===//
/// Augement AvailableAnalysis by adding analysis made available by pass P.
void PMDataManager::recordAvailableAnalysis(Pass *P) {
-
- if (const PassInfo *PI = P->getPassInfo()) {
- AvailableAnalysis[PI] = P;
+ const PassInfo *PI = P->getPassInfo();
+ if (PI == 0) return;
+
+ AvailableAnalysis[PI] = P;
- //This pass is the current implementation of all of the interfaces it
- //implements as well.
- const std::vector<const PassInfo*> &II = PI->getInterfacesImplemented();
- for (unsigned i = 0, e = II.size(); i != e; ++i)
- AvailableAnalysis[II[i]] = P;
- }
+ //This pass is the current implementation of all of the interfaces it
+ //implements as well.
+ const std::vector<const PassInfo*> &II = PI->getInterfacesImplemented();
+ for (unsigned i = 0, e = II.size(); i != e; ++i)
+ AvailableAnalysis[II[i]] = P;
}
// Return true if P preserves high level analysis used by other
// passes managed by this manager
bool PMDataManager::preserveHigherLevelAnalysis(Pass *P) {
-
AnalysisUsage *AnUsage = TPM->findAnalysisUsage(P);
-
if (AnUsage->getPreservesAll())
return true;
const AnalysisUsage::VectorType &PreservedSet = AnUsage->getPreservedSet();
- for (std::vector<Pass *>::iterator I = HigherLevelAnalysis.begin(),
+ for (SmallVector<Pass *, 8>::iterator I = HigherLevelAnalysis.begin(),
E = HigherLevelAnalysis.end(); I != E; ++I) {
Pass *P1 = *I;
if (!dynamic_cast<ImmutablePass*>(P1) &&
/// verifyDomInfo - Verify dominator information if it is available.
void PMDataManager::verifyDomInfo(Pass &P, Function &F) {
-
if (!VerifyDomInfo || !P.getResolver())
return;
- DominatorTree *DT = P.getAnalysisToUpdate<DominatorTree>();
+ DominatorTree *DT = P.getAnalysisIfAvailable<DominatorTree>();
if (!DT)
return;
OtherDT.dump();
cerr << "----- Invalid -----\n";
DT->dump();
- assert (0 && "Invalid dominator info");
+ assert(0 && "Invalid dominator info");
}
- DominanceFrontier *DF = P.getAnalysisToUpdate<DominanceFrontier>();
+ DominanceFrontier *DF = P.getAnalysisIfAvailable<DominanceFrontier>();
if (!DF)
return;
OtherDF.dump();
cerr << "----- Invalid -----\n";
DF->dump();
- assert (0 && "Invalid dominator info");
+ assert(0 && "Invalid dominator info");
}
}
&& std::find(PreservedSet.begin(), PreservedSet.end(), Info->first) ==
PreservedSet.end()) {
// Remove this analysis
- AvailableAnalysis.erase(Info);
if (PassDebugging >= Details) {
Pass *S = Info->second;
cerr << " -- '" << P->getPassName() << "' is not preserving '";
cerr << S->getPassName() << "'\n";
}
+ AvailableAnalysis.erase(Info);
}
}
dumpPassInfo(*I, FREEING_MSG, DBG_STR, Msg);
- if (TheTimeInfo) TheTimeInfo->passStarted(*I);
- (*I)->releaseMemory();
- if (TheTimeInfo) TheTimeInfo->passEnded(*I);
-
- std::map<AnalysisID, Pass*>::iterator Pos =
- AvailableAnalysis.find((*I)->getPassInfo());
-
- // It is possible that pass is already removed from the AvailableAnalysis
- if (Pos != AvailableAnalysis.end())
- AvailableAnalysis.erase(Pos);
+ {
+ // 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);
+
+ // It is possible that pass is already removed from the AvailableAnalysis
+ if (Pos != AvailableAnalysis.end())
+ 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) {
+ Pos = AvailableAnalysis.find(II[i]);
+ if (Pos != AvailableAnalysis.end() && Pos->second == *I)
+ AvailableAnalysis.erase(Pos);
+ }
+ }
}
}
/// Add pass P into the PassVector. Update
/// AvailableAnalysis appropriately if ProcessAnalysis is true.
-void PMDataManager::add(Pass *P,
- bool ProcessAnalysis) {
-
+void PMDataManager::add(Pass *P, bool ProcessAnalysis) {
// This manager is going to manage pass P. Set up analysis resolver
// to connect them.
AnalysisResolver *AR = new AnalysisResolver(*this);
// then the F's manager, not F, records itself as a last user of M.
SmallVector<Pass *, 12> TransferLastUses;
- if (ProcessAnalysis) {
-
- // At the moment, this pass is the last user of all required passes.
- SmallVector<Pass *, 12> LastUses;
- SmallVector<Pass *, 8> RequiredPasses;
- SmallVector<AnalysisID, 8> ReqAnalysisNotAvailable;
-
- unsigned PDepth = this->getDepth();
-
- collectRequiredAnalysis(RequiredPasses,
- ReqAnalysisNotAvailable, P);
- for (SmallVector<Pass *, 8>::iterator I = RequiredPasses.begin(),
- E = RequiredPasses.end(); I != E; ++I) {
- Pass *PRequired = *I;
- unsigned RDepth = 0;
-
- assert (PRequired->getResolver() && "Analysis Resolver is not set");
- PMDataManager &DM = PRequired->getResolver()->getPMDataManager();
- RDepth = DM.getDepth();
-
- if (PDepth == RDepth)
- LastUses.push_back(PRequired);
- else if (PDepth > RDepth) {
- // Let the parent claim responsibility of last use
- TransferLastUses.push_back(PRequired);
- // Keep track of higher level analysis used by this manager.
- HigherLevelAnalysis.push_back(PRequired);
- } else
- assert (0 && "Unable to accomodate Required Pass");
- }
+ if (!ProcessAnalysis) {
+ // Add pass
+ PassVector.push_back(P);
+ return;
+ }
- // Set P as P's last user until someone starts using P.
- // However, if P is a Pass Manager then it does not need
- // to record its last user.
- if (!dynamic_cast<PMDataManager *>(P))
- LastUses.push_back(P);
- TPM->setLastUser(LastUses, P);
-
- if (!TransferLastUses.empty()) {
- Pass *My_PM = dynamic_cast<Pass *>(this);
- TPM->setLastUser(TransferLastUses, My_PM);
- TransferLastUses.clear();
- }
+ // At the moment, this pass is the last user of all required passes.
+ SmallVector<Pass *, 12> LastUses;
+ SmallVector<Pass *, 8> RequiredPasses;
+ SmallVector<AnalysisID, 8> ReqAnalysisNotAvailable;
- // Now, take care of required analysises that are not available.
- for (SmallVector<AnalysisID, 8>::iterator
- I = ReqAnalysisNotAvailable.begin(),
- E = ReqAnalysisNotAvailable.end() ;I != E; ++I) {
- Pass *AnalysisPass = (*I)->createPass();
- this->addLowerLevelRequiredPass(P, AnalysisPass);
- }
+ unsigned PDepth = this->getDepth();
+
+ collectRequiredAnalysis(RequiredPasses,
+ ReqAnalysisNotAvailable, P);
+ for (SmallVector<Pass *, 8>::iterator I = RequiredPasses.begin(),
+ E = RequiredPasses.end(); I != E; ++I) {
+ Pass *PRequired = *I;
+ unsigned RDepth = 0;
+
+ assert(PRequired->getResolver() && "Analysis Resolver is not set");
+ PMDataManager &DM = PRequired->getResolver()->getPMDataManager();
+ RDepth = DM.getDepth();
- // Take a note of analysis required and made available by this pass.
- // Remove the analysis not preserved by this pass
- removeNotPreservedAnalysis(P);
- recordAvailableAnalysis(P);
+ if (PDepth == RDepth)
+ LastUses.push_back(PRequired);
+ else if (PDepth > RDepth) {
+ // Let the parent claim responsibility of last use
+ TransferLastUses.push_back(PRequired);
+ // Keep track of higher level analysis used by this manager.
+ HigherLevelAnalysis.push_back(PRequired);
+ } else
+ assert(0 && "Unable to accomodate Required Pass");
}
+ // Set P as P's last user until someone starts using P.
+ // However, if P is a Pass Manager then it does not need
+ // to record its last user.
+ if (!dynamic_cast<PMDataManager *>(P))
+ LastUses.push_back(P);
+ TPM->setLastUser(LastUses, P);
+
+ if (!TransferLastUses.empty()) {
+ Pass *My_PM = dynamic_cast<Pass *>(this);
+ TPM->setLastUser(TransferLastUses, My_PM);
+ TransferLastUses.clear();
+ }
+
+ // Now, take care of required analysises that are not available.
+ for (SmallVector<AnalysisID, 8>::iterator
+ I = ReqAnalysisNotAvailable.begin(),
+ E = ReqAnalysisNotAvailable.end() ;I != E; ++I) {
+ Pass *AnalysisPass = (*I)->createPass();
+ this->addLowerLevelRequiredPass(P, AnalysisPass);
+ }
+
+ // Take a note of analysis required and made available by this pass.
+ // Remove the analysis not preserved by this pass
+ removeNotPreservedAnalysis(P);
+ recordAvailableAnalysis(P);
+
// Add pass
PassVector.push_back(P);
}
AnalysisUsage *AnUsage = TPM->findAnalysisUsage(P);
const AnalysisUsage::VectorType &RequiredSet = AnUsage->getRequiredSet();
for (AnalysisUsage::VectorType::const_iterator
- I = RequiredSet.begin(), E = RequiredSet.end();
- I != E; ++I) {
- AnalysisID AID = *I;
+ I = RequiredSet.begin(), E = RequiredSet.end(); I != E; ++I) {
if (Pass *AnalysisPass = findAnalysisPass(*I, true))
RP.push_back(AnalysisPass);
else
- RP_NotAvail.push_back(AID);
+ RP_NotAvail.push_back(*I);
}
const AnalysisUsage::VectorType &IDs = AnUsage->getRequiredTransitiveSet();
for (AnalysisUsage::VectorType::const_iterator I = IDs.begin(),
E = IDs.end(); I != E; ++I) {
- AnalysisID AID = *I;
if (Pass *AnalysisPass = findAnalysisPass(*I, true))
RP.push_back(AnalysisPass);
else
- RP_NotAvail.push_back(AID);
+ RP_NotAvail.push_back(*I);
}
}
// If that is not the case then it will raise an assert when it is used.
continue;
AnalysisResolver *AR = P->getResolver();
- assert (AR && "Analysis Resolver is not set");
+ assert(AR && "Analysis Resolver is not set");
AR->addAnalysisImplsPair(*I, Impl);
}
}
}
void PMDataManager::dumpPassArguments() const {
- for(std::vector<Pass *>::const_iterator I = PassVector.begin(),
+ for (SmallVector<Pass *, 8>::const_iterator I = PassVector.begin(),
E = PassVector.end(); I != E; ++I) {
if (PMDataManager *PMD = dynamic_cast<PMDataManager *>(*I))
PMD->dumpPassArguments();
}
}
-void PMDataManager::dumpRequiredSet(const Pass *P)
- const {
+void PMDataManager::dumpRequiredSet(const Pass *P) const {
if (PassDebugging < Details)
return;
dumpAnalysisUsage("Required", P, analysisUsage.getRequiredSet());
}
-void PMDataManager::dumpPreservedSet(const Pass *P)
- const {
+void PMDataManager::dumpPreservedSet(const Pass *P) const {
if (PassDebugging < Details)
return;
}
void PMDataManager::dumpAnalysisUsage(const char *Msg, const Pass *P,
- const AnalysisUsage::VectorType &Set)
- const {
+ const AnalysisUsage::VectorType &Set) const {
assert(PassDebugging >= Details);
if (Set.empty())
return;
cerr << (void*)P << std::string(getDepth()*2+3, ' ') << Msg << " Analyses:";
- for (unsigned i = 0; i != Set.size(); ++i) {
- if (i) cerr << ",";
- cerr << " " << Set[i]->getPassName();
- }
- cerr << "\n";
+ for (unsigned i = 0; i != Set.size(); ++i) {
+ if (i) cerr << ",";
+ cerr << " " << Set[i]->getPassName();
+ }
+ cerr << "\n";
}
/// Add RequiredPass into list of lower level passes required by pass P.
cerr << "Unable to schedule '" << RequiredPass->getPassName();
cerr << "' required by '" << P->getPassName() << "'\n";
#endif
- assert (0 && "Unable to schedule pass");
+ assert(0 && "Unable to schedule pass");
}
// Destructor
PMDataManager::~PMDataManager() {
-
- for (std::vector<Pass *>::iterator I = PassVector.begin(),
+ for (SmallVector<Pass *, 8>::iterator I = PassVector.begin(),
E = PassVector.end(); I != E; ++I)
delete *I;
-
}
//===----------------------------------------------------------------------===//
// NOTE: Is this the right place to define this method ?
-// getAnalysisToUpdate - Return an analysis result or null if it doesn't exist
-Pass *AnalysisResolver::getAnalysisToUpdate(AnalysisID ID, bool dir) const {
+// getAnalysisIfAvailable - Return analysis result or null if it doesn't exist.
+Pass *AnalysisResolver::getAnalysisIfAvailable(AnalysisID ID, bool dir) const {
return PM.findAnalysisPass(ID, dir);
}
/// Execute all of the passes scheduled for execution by invoking
/// runOnBasicBlock method. Keep track of whether any of the passes modifies
/// the function, and if so, return true.
-bool
-BBPassManager::runOnFunction(Function &F) {
-
+bool BBPassManager::runOnFunction(Function &F) {
if (F.isDeclaration())
return false;
initializeAnalysisImpl(BP);
- if (TheTimeInfo) TheTimeInfo->passStarted(BP);
- Changed |= BP->runOnBasicBlock(*I);
- if (TheTimeInfo) TheTimeInfo->passEnded(BP);
+ {
+ // If the pass crashes, remember this.
+ PassManagerPrettyStackEntry X(BP, *I);
+
+ if (TheTimeInfo) TheTimeInfo->passStarted(BP);
+ Changed |= BP->runOnBasicBlock(*I);
+ if (TheTimeInfo) TheTimeInfo->passEnded(BP);
+ }
if (Changed)
dumpPassInfo(BP, MODIFICATION_MSG, ON_BASICBLOCK_MSG,
}
// Implement doInitialization and doFinalization
-inline bool BBPassManager::doInitialization(Module &M) {
+bool BBPassManager::doInitialization(Module &M) {
bool Changed = false;
- for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
- BasicBlockPass *BP = getContainedPass(Index);
- Changed |= BP->doInitialization(M);
- }
+ for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index)
+ Changed |= getContainedPass(Index)->doInitialization(M);
return Changed;
}
-inline bool BBPassManager::doFinalization(Module &M) {
+bool BBPassManager::doFinalization(Module &M) {
bool Changed = false;
- for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
- BasicBlockPass *BP = getContainedPass(Index);
- Changed |= BP->doFinalization(M);
- }
+ for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index)
+ Changed |= getContainedPass(Index)->doFinalization(M);
return Changed;
}
-inline bool BBPassManager::doInitialization(Function &F) {
+bool BBPassManager::doInitialization(Function &F) {
bool Changed = false;
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
return Changed;
}
-inline bool BBPassManager::doFinalization(Function &F) {
+bool BBPassManager::doFinalization(Function &F) {
bool Changed = false;
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
//===----------------------------------------------------------------------===//
// FunctionPassManagerImpl implementation
//
-inline bool FunctionPassManagerImpl::doInitialization(Module &M) {
+bool FunctionPassManagerImpl::doInitialization(Module &M) {
bool Changed = false;
- for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
- FPPassManager *FP = getContainedManager(Index);
- Changed |= FP->doInitialization(M);
- }
+ for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index)
+ Changed |= getContainedManager(Index)->doInitialization(M);
return Changed;
}
-inline bool FunctionPassManagerImpl::doFinalization(Module &M) {
+bool FunctionPassManagerImpl::doFinalization(Module &M) {
bool Changed = false;
- for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
- FPPassManager *FP = getContainedManager(Index);
- Changed |= FP->doFinalization(M);
- }
+ for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index)
+ Changed |= getContainedManager(Index)->doFinalization(M);
return Changed;
}
+/// cleanup - After running all passes, clean up pass manager cache.
+void FPPassManager::cleanup() {
+ for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
+ FunctionPass *FP = getContainedPass(Index);
+ AnalysisResolver *AR = FP->getResolver();
+ assert(AR && "Analysis Resolver is not set");
+ AR->clearAnalysisImpls();
+ }
+}
+
// Execute all the passes managed by this top level manager.
// Return true if any function is modified by a pass.
bool FunctionPassManagerImpl::run(Function &F) {
-
bool Changed = false;
-
TimingInfo::createTheTimeInfo();
dumpArguments();
dumpPasses();
initializeAllAnalysisInfo();
- for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
- FPPassManager *FP = getContainedManager(Index);
- Changed |= FP->runOnFunction(F);
- }
+ for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index)
+ Changed |= getContainedManager(Index)->runOnFunction(F);
+
+ for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index)
+ getContainedManager(Index)->cleanup();
+
return Changed;
}
/// runOnFunction method. Keep track of whether any of the passes modifies
/// the function, and if so, return true.
bool FPPassManager::runOnFunction(Function &F) {
+ if (F.isDeclaration())
+ return false;
bool Changed = false;
- if (F.isDeclaration())
- return false;
-
// Collect inherited analysis from Module level pass manager.
populateInheritedAnalysis(TPM->activeStack);
initializeAnalysisImpl(FP);
- if (TheTimeInfo) TheTimeInfo->passStarted(FP);
- Changed |= FP->runOnFunction(F);
- if (TheTimeInfo) TheTimeInfo->passEnded(FP);
+ {
+ PassManagerPrettyStackEntry X(FP, F);
+
+ if (TheTimeInfo) TheTimeInfo->passStarted(FP);
+ Changed |= FP->runOnFunction(F);
+ if (TheTimeInfo) TheTimeInfo->passEnded(FP);
+ }
if (Changed)
dumpPassInfo(FP, MODIFICATION_MSG, ON_FUNCTION_MSG, F.getNameStart());
}
bool FPPassManager::runOnModule(Module &M) {
-
bool Changed = doInitialization(M);
- for(Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
- this->runOnFunction(*I);
+ for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
+ runOnFunction(*I);
return Changed |= doFinalization(M);
}
-inline bool FPPassManager::doInitialization(Module &M) {
+bool FPPassManager::doInitialization(Module &M) {
bool Changed = false;
- for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
- FunctionPass *FP = getContainedPass(Index);
- Changed |= FP->doInitialization(M);
- }
+ for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index)
+ Changed |= getContainedPass(Index)->doInitialization(M);
return Changed;
}
-inline bool FPPassManager::doFinalization(Module &M) {
+bool FPPassManager::doFinalization(Module &M) {
bool Changed = false;
- for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
- FunctionPass *FP = getContainedPass(Index);
- Changed |= FP->doFinalization(M);
- }
+ for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index)
+ Changed |= getContainedPass(Index)->doFinalization(M);
return Changed;
}
initializeAnalysisImpl(MP);
- if (TheTimeInfo) TheTimeInfo->passStarted(MP);
- Changed |= MP->runOnModule(M);
- if (TheTimeInfo) TheTimeInfo->passEnded(MP);
+ {
+ PassManagerPrettyStackEntry X(MP, M);
+ if (TheTimeInfo) TheTimeInfo->passStarted(MP);
+ Changed |= MP->runOnModule(M);
+ if (TheTimeInfo) TheTimeInfo->passEnded(MP);
+ }
if (Changed)
dumpPassInfo(MP, MODIFICATION_MSG, ON_MODULE_MSG,
/// RequiredPass is run on the fly by Pass Manager when P requests it
/// through getAnalysis interface.
void MPPassManager::addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) {
-
- assert (P->getPotentialPassManagerType() == PMT_ModulePassManager
- && "Unable to handle Pass that requires lower level Analysis pass");
- assert ((P->getPotentialPassManagerType() <
- RequiredPass->getPotentialPassManagerType())
- && "Unable to handle Pass that requires lower level Analysis pass");
+ assert(P->getPotentialPassManagerType() == PMT_ModulePassManager &&
+ "Unable to handle Pass that requires lower level Analysis pass");
+ assert((P->getPotentialPassManagerType() <
+ RequiredPass->getPotentialPassManagerType()) &&
+ "Unable to handle Pass that requires lower level Analysis pass");
FunctionPassManagerImpl *FPP = OnTheFlyManagers[P];
if (!FPP) {
/// Return function pass corresponding to PassInfo PI, that is
/// required by module pass MP. Instantiate analysis pass, by using
/// its runOnFunction() for function F.
-Pass* MPPassManager::getOnTheFlyPass(Pass *MP, const PassInfo *PI,
- Function &F) {
- AnalysisID AID = PI;
+Pass* MPPassManager::getOnTheFlyPass(Pass *MP, const PassInfo *PI, Function &F){
FunctionPassManagerImpl *FPP = OnTheFlyManagers[MP];
- assert (FPP && "Unable to find on the fly pass");
+ assert(FPP && "Unable to find on the fly pass");
FPP->run(F);
- return (dynamic_cast<PMTopLevelManager *>(FPP))->findAnalysisPass(AID);
+ return (dynamic_cast<PMTopLevelManager *>(FPP))->findAnalysisPass(PI);
}
/// run - Execute all of the passes scheduled for execution. Keep track of
/// whether any of the passes modifies the module, and if so, return true.
bool PassManagerImpl::run(Module &M) {
-
bool Changed = false;
-
TimingInfo::createTheTimeInfo();
dumpArguments();
dumpPasses();
initializeAllAnalysisInfo();
- for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
- MPPassManager *MP = getContainedManager(Index);
- Changed |= MP->runOnModule(M);
- }
+ for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index)
+ Changed |= getContainedManager(Index)->runOnModule(M);
return Changed;
}
/// the Pass to the PassManager. When the PassManager is destroyed, the pass
/// will be destroyed as well, so there is no need to delete the pass. This
/// implies that all passes MUST be allocated with 'new'.
-void
-PassManager::add(Pass *P) {
+void PassManager::add(Pass *P) {
PM->add(P);
}
/// run - Execute all of the passes scheduled for execution. Keep track of
/// whether any of the passes modifies the module, and if so, return true.
-bool
-PassManager::run(Module &M) {
+bool PassManager::run(Module &M) {
return PM->run(M);
}
// Push PM on the stack and set its top level manager.
void PMStack::push(PMDataManager *PM) {
+ assert(PM && "Unable to push. Pass Manager expected");
- PMDataManager *Top = NULL;
- assert (PM && "Unable to push. Pass Manager expected");
+ if (!this->empty()) {
+ PMTopLevelManager *TPM = this->top()->getTopLevelManager();
- if (this->empty()) {
- Top = PM;
- }
- else {
- Top = this->top();
- PMTopLevelManager *TPM = Top->getTopLevelManager();
-
- assert (TPM && "Unable to find top level manager");
+ assert(TPM && "Unable to find top level manager");
TPM->addIndirectPassManager(PM);
PM->setTopLevelManager(TPM);
}
// Dump content of the pass manager stack.
void PMStack::dump() {
- for(std::deque<PMDataManager *>::iterator I = S.begin(),
- E = S.end(); I != E; ++I) {
- Pass *P = dynamic_cast<Pass *>(*I);
- printf("%s ", P->getPassName());
- }
+ for (std::deque<PMDataManager *>::iterator I = S.begin(),
+ E = S.end(); I != E; ++I)
+ printf("%s ", dynamic_cast<Pass *>(*I)->getPassName());
+
if (!S.empty())
printf("\n");
}
/// add self into that manager.
void ModulePass::assignPassManager(PMStack &PMS,
PassManagerType PreferredType) {
-
// Find Module Pass Manager
while(!PMS.empty()) {
PassManagerType TopPMType = PMS.top()->getPassManagerType();
else
break;
}
-
+ assert(!PMS.empty() && "Unable to find appropriate Pass Manager");
PMS.top()->add(this);
}
void FunctionPass::assignPassManager(PMStack &PMS,
PassManagerType PreferredType) {
- // Find Module Pass Manager (TODO : Or Call Graph Pass Manager)
+ // Find Module Pass Manager
while(!PMS.empty()) {
if (PMS.top()->getPassManagerType() > PMT_FunctionPassManager)
PMS.pop();
// [3] Assign manager to manage this new manager. This may create
// and push new managers into PMS
-
- // If Call Graph Pass Manager is active then use it to manage
- // this new Function Pass manager.
- if (PMD->getPassManagerType() == PMT_CallGraphPassManager)
- FPP->assignPassManager(PMS, PMT_CallGraphPassManager);
- else
- FPP->assignPassManager(PMS);
+ FPP->assignPassManager(PMS, PMD->getPassManagerType());
// [4] Push new manager into PMS
PMS.push(FPP);
/// in the PM Stack and add self into that manager.
void BasicBlockPass::assignPassManager(PMStack &PMS,
PassManagerType PreferredType) {
-
BBPassManager *BBP = NULL;
// Basic Pass Manager is a leaf pass manager. It does not handle