X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FVMCore%2FPass.cpp;h=fc92a95a929ba764801545589999562ceb53a3f9;hb=e6be34a53ecbe8c2ff9f0793b13d847e94c0de91;hp=3f3dbdfd033ba7eb40374cbb9261f7e82269f826;hpb=cde53d3c1e9d6a2add5de847b44818fbb1d69c20;p=oota-llvm.git diff --git a/lib/VMCore/Pass.cpp b/lib/VMCore/Pass.cpp index 3f3dbdfd033..fc92a95a929 100644 --- a/lib/VMCore/Pass.cpp +++ b/lib/VMCore/Pass.cpp @@ -2,8 +2,8 @@ // // The LLVM Compiler Infrastructure // -// This file was developed by the LLVM research group and is distributed under -// the University of Illinois Open Source License. See LICENSE.TXT for details. +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // @@ -18,7 +18,7 @@ #include "llvm/ModuleProvider.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Support/ManagedStatic.h" -#include "llvm/Support/TypeInfo.h" +#include #include using namespace llvm; @@ -26,6 +26,11 @@ using namespace llvm; // Pass Implementation // +// Force out-of-line virtual method. +Pass::~Pass() { + delete Resolver; +} + // Force out-of-line virtual method. ModulePass::~ModulePass() { } @@ -43,7 +48,7 @@ void Pass::dumpPassStructure(unsigned Offset) { const char *Pass::getPassName() const { if (const PassInfo *PI = getPassInfo()) return PI->getPassName(); - return typeid(*this).name(); + return "Unnamed pass: implement Pass::getPassName()"; } // print - Print out the internal state of the pass. This is called by Analyze @@ -76,7 +81,7 @@ bool FunctionPass::runOnModule(Module &M) { bool Changed = doInitialization(M); for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) - if (!I->isExternal()) // Passes are not run on external functions! + if (!I->isDeclaration()) // Passes are not run on external functions! Changed |= runOnFunction(*I); return Changed | doFinalization(M); @@ -85,7 +90,8 @@ bool FunctionPass::runOnModule(Module &M) { // run - On a function, we simply initialize, run the function, then finalize. // bool FunctionPass::run(Function &F) { - if (F.isExternal()) return false;// Passes are not run on external functions! + // Passes are not run on external functions! + if (F.isDeclaration()) return false; bool Changed = doInitialization(*F.getParent()); Changed |= runOnFunction(F); @@ -127,7 +133,7 @@ namespace { class PassRegistrar { /// PassInfoMap - Keep track of the passinfo object for each registered llvm /// pass. - std::map PassInfoMap; + std::map PassInfoMap; /// AnalysisGroupInfo - Keep track of information for each analysis group. struct AnalysisGroupInfo { @@ -141,19 +147,19 @@ class PassRegistrar { public: - const PassInfo *GetPassInfo(const std::type_info &TI) const { - std::map::const_iterator I = PassInfoMap.find(TI); + const PassInfo *GetPassInfo(intptr_t TI) const { + std::map::const_iterator I = PassInfoMap.find(TI); return I != PassInfoMap.end() ? I->second : 0; } void RegisterPass(PassInfo &PI) { bool Inserted = - PassInfoMap.insert(std::make_pair(TypeInfo(PI.getTypeInfo()),&PI)).second; + PassInfoMap.insert(std::make_pair(PI.getTypeInfo(),&PI)).second; assert(Inserted && "Pass registered multiple times!"); } void UnregisterPass(PassInfo &PI) { - std::map::iterator I = + std::map::iterator I = PassInfoMap.find(PI.getTypeInfo()); assert(I != PassInfoMap.end() && "Pass registered but not in map!"); @@ -162,7 +168,7 @@ public: } void EnumerateWith(PassRegistrationListener *L) { - for (std::map::const_iterator I = PassInfoMap.begin(), + for (std::map::const_iterator I = PassInfoMap.begin(), E = PassInfoMap.end(); I != E; ++I) L->passEnumerate(I->second); } @@ -188,22 +194,31 @@ public: }; } -static ManagedStatic PassRegistrarObj; static std::vector *Listeners = 0; +// FIXME: This should use ManagedStatic to manage the pass registrar. +// Unfortunately, we can't do this, because passes are registered with static +// ctors, and having llvm_shutdown clear this map prevents successful +// ressurection after llvm_shutdown is run. +static PassRegistrar *getPassRegistrar() { + static PassRegistrar *PassRegistrarObj = 0; + if (!PassRegistrarObj) + PassRegistrarObj = new PassRegistrar(); + return PassRegistrarObj; +} + // getPassInfo - Return the PassInfo data structure that corresponds to this // pass... const PassInfo *Pass::getPassInfo() const { - if (PassInfoCache) return PassInfoCache; - return lookupPassInfo(typeid(*this)); + return lookupPassInfo(PassID); } -const PassInfo *Pass::lookupPassInfo(const std::type_info &TI) { - return PassRegistrarObj->GetPassInfo(TI); +const PassInfo *Pass::lookupPassInfo(intptr_t TI) { + return getPassRegistrar()->GetPassInfo(TI); } void RegisterPassBase::registerPass() { - PassRegistrarObj->RegisterPass(PIObj); + getPassRegistrar()->RegisterPass(PIObj); // Notify any listeners. if (Listeners) @@ -213,7 +228,7 @@ void RegisterPassBase::registerPass() { } void RegisterPassBase::unregisterPass() { - PassRegistrarObj->UnregisterPass(PIObj); + getPassRegistrar()->UnregisterPass(PIObj); } //===----------------------------------------------------------------------===// @@ -222,12 +237,12 @@ void RegisterPassBase::unregisterPass() { // RegisterAGBase implementation // -RegisterAGBase::RegisterAGBase(const std::type_info &Interface, - const std::type_info *Pass, bool isDefault) - : RegisterPassBase(Interface), +RegisterAGBase::RegisterAGBase(intptr_t InterfaceID, + intptr_t PassID, bool isDefault) + : RegisterPassBase(InterfaceID), ImplementationInfo(0), isDefaultImplementation(isDefault) { - InterfaceInfo = const_cast(Pass::lookupPassInfo(Interface)); + InterfaceInfo = const_cast(Pass::lookupPassInfo(InterfaceID)); if (InterfaceInfo == 0) { // First reference to Interface, register it now. registerPass(); @@ -236,8 +251,8 @@ RegisterAGBase::RegisterAGBase(const std::type_info &Interface, assert(PIObj.isAnalysisGroup() && "Trying to join an analysis group that is a normal pass!"); - if (Pass) { - ImplementationInfo = Pass::lookupPassInfo(*Pass); + if (PassID) { + ImplementationInfo = Pass::lookupPassInfo(PassID); assert(ImplementationInfo && "Must register pass before adding to AnalysisGroup!"); @@ -246,7 +261,7 @@ RegisterAGBase::RegisterAGBase(const std::type_info &Interface, PassInfo *IIPI = const_cast(ImplementationInfo); IIPI->addInterfaceImplemented(InterfaceInfo); - PassRegistrarObj->RegisterAnalysisGroup(InterfaceInfo, IIPI, isDefault); + getPassRegistrar()->RegisterAnalysisGroup(InterfaceInfo, IIPI, isDefault); } } @@ -285,7 +300,7 @@ PassRegistrationListener::~PassRegistrationListener() { // passEnumerate callback on each PassInfo object. // void PassRegistrationListener::enumeratePasses() { - PassRegistrarObj->EnumerateWith(this); + getPassRegistrar()->EnumerateWith(this); } //===----------------------------------------------------------------------===//