X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FVMCore%2FPass.cpp;h=6db5d7e24c5ef2f4eec9eb5cc0680261411ba4a6;hb=9036d80d7b696daec0eb4738848b18a2a6e4fe1f;hp=fc92a95a929ba764801545589999562ceb53a3f9;hpb=97cf759b822818414f9604c74d3bcfe75a91520b;p=oota-llvm.git diff --git a/lib/VMCore/Pass.cpp b/lib/VMCore/Pass.cpp index fc92a95a929..6db5d7e24c5 100644 --- a/lib/VMCore/Pass.cpp +++ b/lib/VMCore/Pass.cpp @@ -13,12 +13,14 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Pass.h" #include "llvm/PassManager.h" #include "llvm/Module.h" #include "llvm/ModuleProvider.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Support/ManagedStatic.h" #include +#include #include using namespace llvm; @@ -35,7 +37,7 @@ Pass::~Pass() { ModulePass::~ModulePass() { } bool Pass::mustPreserveAnalysisID(const PassInfo *AnalysisID) const { - return Resolver->getAnalysisToUpdate(AnalysisID, true) != 0; + return Resolver->getAnalysisIfAvailable(AnalysisID, true) != 0; } // dumpPassStructure - Implement the -debug-passes=Structure option @@ -43,8 +45,10 @@ void Pass::dumpPassStructure(unsigned Offset) { cerr << std::string(Offset*2, ' ') << getPassName() << "\n"; } -// getPassName - Use C++ RTTI to get a SOMEWHAT intelligible name for the pass. -// +/// getPassName - Return a nice clean name for a pass. This usually +/// implemented in terms of the name that is registered by one of the +/// Registration templates, but can be overloaded directly. +/// const char *Pass::getPassName() const { if (const PassInfo *PI = getPassInfo()) return PI->getPassName(); @@ -112,20 +116,6 @@ bool BasicBlockPass::runOnFunction(Function &F) { return Changed | doFinalization(F); } -// To run directly on the basic block, we initialize, runOnBasicBlock, then -// finalize. -// -bool BasicBlockPass::runPass(BasicBlock &BB) { - Function &F = *BB.getParent(); - Module &M = *F.getParent(); - bool Changed = doInitialization(M); - Changed |= doInitialization(F); - Changed |= runOnBasicBlock(BB); - Changed |= doFinalization(F); - Changed |= doFinalization(M); - return Changed; -} - //===----------------------------------------------------------------------===// // Pass Registration mechanism // @@ -133,7 +123,8 @@ namespace { class PassRegistrar { /// PassInfoMap - Keep track of the passinfo object for each registered llvm /// pass. - std::map PassInfoMap; + typedef std::map MapType; + MapType PassInfoMap; /// AnalysisGroupInfo - Keep track of information for each analysis group. struct AnalysisGroupInfo { @@ -148,19 +139,18 @@ class PassRegistrar { public: const PassInfo *GetPassInfo(intptr_t TI) const { - std::map::const_iterator I = PassInfoMap.find(TI); + MapType::const_iterator I = PassInfoMap.find(TI); return I != PassInfoMap.end() ? I->second : 0; } - void RegisterPass(PassInfo &PI) { + void RegisterPass(const PassInfo &PI) { bool Inserted = PassInfoMap.insert(std::make_pair(PI.getTypeInfo(),&PI)).second; - assert(Inserted && "Pass registered multiple times!"); + assert(Inserted && "Pass registered multiple times!"); Inserted=Inserted; } - void UnregisterPass(PassInfo &PI) { - std::map::iterator I = - PassInfoMap.find(PI.getTypeInfo()); + void UnregisterPass(const PassInfo &PI) { + MapType::iterator I = PassInfoMap.find(PI.getTypeInfo()); assert(I != PassInfoMap.end() && "Pass registered but not in map!"); // Remove pass from the map. @@ -168,7 +158,7 @@ public: } void EnumerateWith(PassRegistrationListener *L) { - for (std::map::const_iterator I = PassInfoMap.begin(), + for (MapType::const_iterator I = PassInfoMap.begin(), E = PassInfoMap.end(); I != E; ++I) L->passEnumerate(I->second); } @@ -217,18 +207,18 @@ const PassInfo *Pass::lookupPassInfo(intptr_t TI) { return getPassRegistrar()->GetPassInfo(TI); } -void RegisterPassBase::registerPass() { - getPassRegistrar()->RegisterPass(PIObj); +void PassInfo::registerPass() { + getPassRegistrar()->RegisterPass(*this); // Notify any listeners. if (Listeners) for (std::vector::iterator I = Listeners->begin(), E = Listeners->end(); I != E; ++I) - (*I)->passRegistered(&PIObj); + (*I)->passRegistered(this); } -void RegisterPassBase::unregisterPass() { - getPassRegistrar()->UnregisterPass(PIObj); +void PassInfo::unregisterPass() { + getPassRegistrar()->UnregisterPass(*this); } //===----------------------------------------------------------------------===// @@ -237,18 +227,18 @@ void RegisterPassBase::unregisterPass() { // RegisterAGBase implementation // -RegisterAGBase::RegisterAGBase(intptr_t InterfaceID, +RegisterAGBase::RegisterAGBase(const char *Name, intptr_t InterfaceID, intptr_t PassID, bool isDefault) - : RegisterPassBase(InterfaceID), + : PassInfo(Name, InterfaceID), ImplementationInfo(0), isDefaultImplementation(isDefault) { InterfaceInfo = const_cast(Pass::lookupPassInfo(InterfaceID)); if (InterfaceInfo == 0) { // First reference to Interface, register it now. registerPass(); - InterfaceInfo = &PIObj; + InterfaceInfo = this; } - assert(PIObj.isAnalysisGroup() && + assert(isAnalysisGroup() && "Trying to join an analysis group that is a normal pass!"); if (PassID) { @@ -265,11 +255,6 @@ RegisterAGBase::RegisterAGBase(intptr_t InterfaceID, } } -void RegisterAGBase::setGroupName(const char *Name) { - assert(InterfaceInfo->getPassName()[0] == 0 && "Interface Name already set!"); - InterfaceInfo->setPassName(Name); -} - //===----------------------------------------------------------------------===// // PassRegistrationListener implementation @@ -309,8 +294,9 @@ void PassRegistrationListener::enumeratePasses() { namespace { struct GetCFGOnlyPasses : public PassRegistrationListener { - std::vector &CFGOnlyList; - GetCFGOnlyPasses(std::vector &L) : CFGOnlyList(L) {} + typedef AnalysisUsage::VectorType VectorType; + VectorType &CFGOnlyList; + GetCFGOnlyPasses(VectorType &L) : CFGOnlyList(L) {} void passEnumerate(const PassInfo *P) { if (P->isCFGOnlyPass())