diff options
author | Chris Lattner <sabre@nondot.org> | 2006-12-01 23:46:50 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2006-12-01 23:46:50 +0000 |
commit | ee740834ab56671de0a6ce44263d94ed72b69851 (patch) | |
tree | 9a253e7b4ad7e4a35b4c9feef6c8b12d56b24c44 /lib/VMCore/Pass.cpp | |
parent | 280d801839ff2c427d53e2f0e20232a723ecc36a (diff) | |
download | external_llvm-ee740834ab56671de0a6ce44263d94ed72b69851.zip external_llvm-ee740834ab56671de0a6ce44263d94ed72b69851.tar.gz external_llvm-ee740834ab56671de0a6ce44263d94ed72b69851.tar.bz2 |
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
Diffstat (limited to 'lib/VMCore/Pass.cpp')
-rw-r--r-- | lib/VMCore/Pass.cpp | 91 |
1 files changed, 36 insertions, 55 deletions
diff --git a/lib/VMCore/Pass.cpp b/lib/VMCore/Pass.cpp index 0097fbd..44675be 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<TypeInfo, PassInfo*> PassInfoMap; + + /// AnalysisGroupInfo - Keep track of information for each analysis group. + struct AnalysisGroupInfo { + const PassInfo *DefaultImpl; + std::set<const PassInfo *> Implementations; + AnalysisGroupInfo() : DefaultImpl(0) {} + }; + + /// AnalysisGroupInfoMap - Information for each analysis group. + std::map<const PassInfo *, AnalysisGroupInfo> 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<PassRegistrar> PassRegistrarObj; static std::vector<PassRegistrationListener*> *Listeners = 0; @@ -350,14 +383,6 @@ void RegisterPassBase::unregisterPass() { // Analysis Group Implementation Code //===----------------------------------------------------------------------===// -struct AnalysisGroupInfo { - const PassInfo *DefaultImpl; - std::set<const PassInfo *> Implementations; - AnalysisGroupInfo() : DefaultImpl(0) {} -}; - -static std::map<const PassInfo *, AnalysisGroupInfo> *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<PassInfo*>(ImplementationInfo); IIPI->addInterfaceImplemented(InterfaceInfo); - - // Lazily allocate to avoid nasty initialization order dependencies - if (AnalysisGroupInfoMap == 0) - AnalysisGroupInfoMap = new std::map<const PassInfo *,AnalysisGroupInfo>(); - - 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 |