- 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
This commit is contained in:
Chris Lattner 2002-08-21 17:08:37 +00:00
parent 7742799a80
commit fb30fda1de
3 changed files with 27 additions and 8 deletions

View File

@ -25,6 +25,7 @@
#include <vector>
#include <map>
#include <iosfwd>
#include <typeinfo>
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<typename AnalysisClass>
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<AnalysisType>() - This function is used by subclasses to get to
// the analysis information that they claim to use by overriding the
// getAnalysisUsage function.
//
template<typename AnalysisType>
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<AnalysisType>();
assert(PI && "getAnalysis for unregistered pass!");
return *(AnalysisType*)Resolver->getAnalysis(PI);
}
template<typename AnalysisType>
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<typename AnalysisType>
AnalysisType *getAnalysisToUpdate() {
assert(Resolver && "Pass not resident in a PassManager object!");
return (AnalysisType*)Resolver->getAnalysisToUpdate(AnalysisType::ID);
const PassInfo *PI = getClassPassInfo<AnalysisType>();
if (PI == 0) return 0;
return (AnalysisType*)Resolver->getAnalysisToUpdate(PI);
}

View File

@ -39,7 +39,7 @@ public:
}
template<class PassClass>
AnalysisUsage &addRequired() {
Required.push_back(PassClass::ID);
Required.push_back(Pass::getClassPassInfo<PassClass>());
return *this;
}
@ -53,7 +53,7 @@ public:
template<class PassClass>
AnalysisUsage &addPreserved() {
Preserved.push_back(PassClass::ID);
Preserved.push_back(Pass::getClassPassInfo<PassClass>());
return *this;
}

View File

@ -11,7 +11,6 @@
#include "llvm/Module.h"
#include "Support/STLExtras.h"
#include "Support/TypeInfo.h"
#include <typeinfo>
#include <stdio.h>
#include <sys/resource.h>
#include <sys/unistd.h>
@ -371,8 +370,12 @@ static std::vector<PassRegistrationListener*> *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<TypeInfo, PassInfo*>::iterator I = PassInfoMap->find(typeid(*this));
std::map<TypeInfo, PassInfo*>::iterator I = PassInfoMap->find(TI);
return (I != PassInfoMap->end()) ? I->second : 0;
}