From: Chris Lattner Date: Fri, 1 Dec 2006 23:46:50 +0000 (+0000) Subject: Switch analysis groups to be unregistered when llvm_shutdown is called. X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=ee740834ab56671de0a6ce44263d94ed72b69851;p=oota-llvm.git Switch analysis groups to be unregistered when llvm_shutdown is called. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32110 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/PassSupport.h b/include/llvm/PassSupport.h index 30e49aa8293..e4144f7e422 100644 --- a/include/llvm/PassSupport.h +++ b/include/llvm/PassSupport.h @@ -197,8 +197,6 @@ protected: const std::type_info *Pass = 0, bool isDefault = false); void setGroupName(const char *Name); -public: - ~RegisterAGBase(); }; template diff --git a/lib/VMCore/Pass.cpp b/lib/VMCore/Pass.cpp index 0097fbdd311..44675bed3eb 100644 --- a/lib/VMCore/Pass.cpp +++ b/lib/VMCore/Pass.cpp @@ -286,8 +286,22 @@ void BasicBlockPass::addToPassManager(BasicBlockPassManager *PM, //===----------------------------------------------------------------------===// // Pass Registration mechanism // +namespace { class PassRegistrar { + /// PassInfoMap - Keep track of the passinfo object for each registered llvm + /// pass. std::map PassInfoMap; + + /// AnalysisGroupInfo - Keep track of information for each analysis group. + struct AnalysisGroupInfo { + const PassInfo *DefaultImpl; + std::set Implementations; + AnalysisGroupInfo() : DefaultImpl(0) {} + }; + + /// AnalysisGroupInfoMap - Information for each analysis group. + std::map AnalysisGroupInfoMap; + public: const PassInfo *GetPassInfo(const std::type_info &TI) const { @@ -315,8 +329,27 @@ public: E = PassInfoMap.end(); I != E; ++I) L->passEnumerate(I->second); } + + + /// Analysis Group Mechanisms. + void RegisterAnalysisGroup(PassInfo *InterfaceInfo, + const PassInfo *ImplementationInfo, + bool isDefault) { + AnalysisGroupInfo &AGI = AnalysisGroupInfoMap[InterfaceInfo]; + assert(AGI.Implementations.count(ImplementationInfo) == 0 && + "Cannot add a pass to the same analysis group more than once!"); + AGI.Implementations.insert(ImplementationInfo); + if (isDefault) { + assert(AGI.DefaultImpl == 0 && InterfaceInfo->getNormalCtor() == 0 && + "Default implementation for analysis group already specified!"); + assert(ImplementationInfo->getNormalCtor() && + "Cannot specify pass as default if it does not have a default ctor"); + AGI.DefaultImpl = ImplementationInfo; + InterfaceInfo->setNormalCtor(ImplementationInfo->getNormalCtor()); + } + } }; - +} static ManagedStatic PassRegistrarObj; static std::vector *Listeners = 0; @@ -350,14 +383,6 @@ void RegisterPassBase::unregisterPass() { // Analysis Group Implementation Code //===----------------------------------------------------------------------===// -struct AnalysisGroupInfo { - const PassInfo *DefaultImpl; - std::set Implementations; - AnalysisGroupInfo() : DefaultImpl(0) {} -}; - -static std::map *AnalysisGroupInfoMap = 0; - // RegisterAGBase implementation // RegisterAGBase::RegisterAGBase(const std::type_info &Interface, @@ -383,23 +408,8 @@ RegisterAGBase::RegisterAGBase(const std::type_info &Interface, // the interface. PassInfo *IIPI = const_cast(ImplementationInfo); IIPI->addInterfaceImplemented(InterfaceInfo); - - // Lazily allocate to avoid nasty initialization order dependencies - if (AnalysisGroupInfoMap == 0) - AnalysisGroupInfoMap = new std::map(); - - AnalysisGroupInfo &AGI = (*AnalysisGroupInfoMap)[InterfaceInfo]; - assert(AGI.Implementations.count(ImplementationInfo) == 0 && - "Cannot add a pass to the same analysis group more than once!"); - AGI.Implementations.insert(ImplementationInfo); - if (isDefault) { - assert(AGI.DefaultImpl == 0 && InterfaceInfo->getNormalCtor() == 0 && - "Default implementation for analysis group already specified!"); - assert(ImplementationInfo->getNormalCtor() && - "Cannot specify pass as default if it does not have a default ctor"); - AGI.DefaultImpl = ImplementationInfo; - InterfaceInfo->setNormalCtor(ImplementationInfo->getNormalCtor()); - } + + PassRegistrarObj->RegisterAnalysisGroup(InterfaceInfo, IIPI, isDefault); } } @@ -408,35 +418,6 @@ void RegisterAGBase::setGroupName(const char *Name) { InterfaceInfo->setPassName(Name); } -RegisterAGBase::~RegisterAGBase() { - if (ImplementationInfo) { - assert(AnalysisGroupInfoMap && "Inserted into map, but map doesn't exist?"); - AnalysisGroupInfo &AGI = (*AnalysisGroupInfoMap)[InterfaceInfo]; - - assert(AGI.Implementations.count(ImplementationInfo) && - "Pass not a member of analysis group?"); - - if (AGI.DefaultImpl == ImplementationInfo) - AGI.DefaultImpl = 0; - - AGI.Implementations.erase(ImplementationInfo); - - // Last member of this analysis group? Unregister PassInfo, delete map entry - if (AGI.Implementations.empty()) { - assert(AGI.DefaultImpl == 0 && - "Default implementation didn't unregister?"); - AnalysisGroupInfoMap->erase(InterfaceInfo); - if (AnalysisGroupInfoMap->empty()) { // Delete map if empty - delete AnalysisGroupInfoMap; - AnalysisGroupInfoMap = 0; - } - } - } - - if (InterfaceInfo == &PIObj) - unregisterPass(); -} - //===----------------------------------------------------------------------===// // PassRegistrationListener implementation