From fb30fda1de96251017ae092f469de4b290b6b61b Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 21 Aug 2002 17:08:37 +0000 Subject: [PATCH] - Eliminate the need for analyses to expose an ::ID member. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3414 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Pass.h | 24 ++++++++++++++++++++---- include/llvm/PassAnalysisSupport.h | 4 ++-- lib/VMCore/Pass.cpp | 7 +++++-- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/include/llvm/Pass.h b/include/llvm/Pass.h index edd7e738c8d..5b55e0dba12 100644 --- a/include/llvm/Pass.h +++ b/include/llvm/Pass.h @@ -25,6 +25,7 @@ #include #include #include +#include class Value; class BasicBlock; class Function; @@ -108,20 +109,33 @@ public: // dumpPassStructure - Implement the -debug-passes=PassStructure option virtual void dumpPassStructure(unsigned Offset = 0); + // getPassInfo - Static method to get the pass information from a class name. + template + static const PassInfo *getClassPassInfo() { + return lookupPassInfo(typeid(AnalysisClass)); + } + protected: + // lookupPassInfo - Return the pass info object for the specified pass class, + // or null if it is not known. + static const PassInfo *lookupPassInfo(const std::type_info &TI); + // getAnalysis() - This function is used by subclasses to get to // the analysis information that they claim to use by overriding the // getAnalysisUsage function. // template AnalysisType &getAnalysis() { - assert(Resolver && "Pass not resident in a PassManager object!"); - return *(AnalysisType*)Resolver->getAnalysis(AnalysisType::ID); + assert(Resolver && "Pass has not been inserted into a PassManager object!"); + const PassInfo *PI = getClassPassInfo(); + assert(PI && "getAnalysis for unregistered pass!"); + return *(AnalysisType*)Resolver->getAnalysis(PI); } template AnalysisType &getAnalysisID(const PassInfo *PI) { - assert(Resolver && "Pass not resident in a PassManager object!"); + assert(Resolver && "Pass has not been inserted into a PassManager object!"); + assert(PI && "getAnalysis for unregistered pass!"); return *(AnalysisType*)Resolver->getAnalysis(PI); } @@ -134,7 +148,9 @@ protected: template AnalysisType *getAnalysisToUpdate() { assert(Resolver && "Pass not resident in a PassManager object!"); - return (AnalysisType*)Resolver->getAnalysisToUpdate(AnalysisType::ID); + const PassInfo *PI = getClassPassInfo(); + if (PI == 0) return 0; + return (AnalysisType*)Resolver->getAnalysisToUpdate(PI); } diff --git a/include/llvm/PassAnalysisSupport.h b/include/llvm/PassAnalysisSupport.h index f04b4a6b468..43c353d4d9e 100644 --- a/include/llvm/PassAnalysisSupport.h +++ b/include/llvm/PassAnalysisSupport.h @@ -39,7 +39,7 @@ public: } template AnalysisUsage &addRequired() { - Required.push_back(PassClass::ID); + Required.push_back(Pass::getClassPassInfo()); return *this; } @@ -53,7 +53,7 @@ public: template AnalysisUsage &addPreserved() { - Preserved.push_back(PassClass::ID); + Preserved.push_back(Pass::getClassPassInfo()); return *this; } diff --git a/lib/VMCore/Pass.cpp b/lib/VMCore/Pass.cpp index 1c54a1b2d19..b6f855d017e 100644 --- a/lib/VMCore/Pass.cpp +++ b/lib/VMCore/Pass.cpp @@ -11,7 +11,6 @@ #include "llvm/Module.h" #include "Support/STLExtras.h" #include "Support/TypeInfo.h" -#include #include #include #include @@ -371,8 +370,12 @@ static std::vector *Listeners = 0; // pass... const PassInfo *Pass::getPassInfo() const { if (PassInfoCache) return PassInfoCache; + return lookupPassInfo(typeid(*this)); +} + +const PassInfo *Pass::lookupPassInfo(const std::type_info &TI) { if (PassInfoMap == 0) return 0; - std::map::iterator I = PassInfoMap->find(typeid(*this)); + std::map::iterator I = PassInfoMap->find(TI); return (I != PassInfoMap->end()) ? I->second : 0; }