Re-install patch to enable use of PassID.

I am preparing another patch to address the failure that prompted
Chris to revert this patch earlier.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36649 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Devang Patel 2007-05-02 20:38:25 +00:00
parent c718288f49
commit eae540a037
3 changed files with 34 additions and 35 deletions

View File

@ -34,8 +34,8 @@
#include <deque> #include <deque>
#include <map> #include <map>
#include <iosfwd> #include <iosfwd>
#include <typeinfo>
#include <cassert> #include <cassert>
#include <stdint.h>
namespace llvm { namespace llvm {
@ -77,7 +77,7 @@ typedef enum PassManagerType PassManagerType;
/// ///
class Pass { class Pass {
AnalysisResolver *Resolver; // Used to resolve analysis AnalysisResolver *Resolver; // Used to resolve analysis
const PassInfo *PassInfoCache; intptr_t PassID;
// AnalysisImpls - This keeps track of which passes implement the interfaces // AnalysisImpls - This keeps track of which passes implement the interfaces
// that are required by the current pass (to implement getAnalysis()). // that are required by the current pass (to implement getAnalysis()).
@ -87,7 +87,7 @@ class Pass {
void operator=(const Pass&); // DO NOT IMPLEMENT void operator=(const Pass&); // DO NOT IMPLEMENT
Pass(const Pass &); // DO NOT IMPLEMENT Pass(const Pass &); // DO NOT IMPLEMENT
public: public:
Pass(intptr_t pid = 0) : Resolver(0), PassInfoCache(0) {} Pass(intptr_t pid) : Resolver(0), PassID(pid) {}
virtual ~Pass(); virtual ~Pass();
/// getPassName - Return a nice clean name for a pass. This usually /// getPassName - Return a nice clean name for a pass. This usually
@ -163,12 +163,12 @@ public:
template<typename AnalysisClass> template<typename AnalysisClass>
static const PassInfo *getClassPassInfo() { static const PassInfo *getClassPassInfo() {
return lookupPassInfo(typeid(AnalysisClass)); return lookupPassInfo((intptr_t)&AnalysisClass::ID);
} }
// lookupPassInfo - Return the pass info object for the specified pass class, // lookupPassInfo - Return the pass info object for the specified pass class,
// or null if it is not known. // or null if it is not known.
static const PassInfo *lookupPassInfo(const std::type_info &TI); static const PassInfo *lookupPassInfo(intptr_t TI);
/// getAnalysisToUpdate<AnalysisType>() - This function is used by subclasses /// getAnalysisToUpdate<AnalysisType>() - This function is used by subclasses
/// to get to the analysis information that might be around that needs to be /// to get to the analysis information that might be around that needs to be
@ -274,7 +274,7 @@ public:
class FunctionPass : public Pass { class FunctionPass : public Pass {
public: public:
FunctionPass(intptr_t pid) : Pass(pid) {} FunctionPass(intptr_t pid) : Pass(pid) {}
/// doInitialization - Virtual method overridden by subclasses to do /// doInitialization - Virtual method overridden by subclasses to do
/// any necessary per-module initialization. /// any necessary per-module initialization.
/// ///
@ -325,7 +325,7 @@ public:
class BasicBlockPass : public Pass { class BasicBlockPass : public Pass {
public: public:
BasicBlockPass(intptr_t pid) : Pass(pid) {} BasicBlockPass(intptr_t pid) : Pass(pid) {}
/// doInitialization - Virtual method overridden by subclasses to do /// doInitialization - Virtual method overridden by subclasses to do
/// any necessary per-module initialization. /// any necessary per-module initialization.
/// ///

View File

@ -37,19 +37,19 @@ class TargetMachine;
class PassInfo { class PassInfo {
const char *PassName; // Nice name for Pass const char *PassName; // Nice name for Pass
const char *PassArgument; // Command Line argument to run this pass const char *PassArgument; // Command Line argument to run this pass
const std::type_info &TypeInfo; // type_info object for this Pass class intptr_t PassID;
bool IsCFGOnlyPass; // Pass only looks at the CFG. bool IsCFGOnlyPass; // Pass only looks at the CFG.
bool IsAnalysisGroup; // True if an analysis group. bool IsAnalysisGroup; // True if an analysis group.
std::vector<const PassInfo*> ItfImpl;// Interfaces implemented by this pass std::vector<const PassInfo*> ItfImpl;// Interfaces implemented by this pass
Pass *(*NormalCtor)(); // No argument ctor Pass *(*NormalCtor)();
public: public:
/// PassInfo ctor - Do not call this directly, this should only be invoked /// PassInfo ctor - Do not call this directly, this should only be invoked
/// through RegisterPass. /// through RegisterPass.
PassInfo(const char *name, const char *arg, const std::type_info &ti, PassInfo(const char *name, const char *arg, intptr_t pi,
Pass *(*normal)() = 0, bool isCFGOnly = false) Pass *(*normal)() = 0, bool isCFGOnly = false)
: PassName(name), PassArgument(arg), TypeInfo(ti), : PassName(name), PassArgument(arg), PassID(pi),
IsCFGOnlyPass(isCFGOnly), IsAnalysisGroup(false), NormalCtor(normal) { IsCFGOnlyPass(isCFGOnly), IsAnalysisGroup(false), NormalCtor(normal) {
} }
@ -65,8 +65,8 @@ public:
const char *getPassArgument() const { return PassArgument; } const char *getPassArgument() const { return PassArgument; }
/// getTypeInfo - Return the type_info object for the pass... /// getTypeInfo - Return the type_info object for the pass...
/// /// TODO : Rename
const std::type_info &getTypeInfo() const { return TypeInfo; } intptr_t getTypeInfo() const { return PassID; }
/// isAnalysisGroup - Return true if this is an analysis group, not a normal /// isAnalysisGroup - Return true if this is an analysis group, not a normal
/// pass. /// pass.
@ -139,12 +139,12 @@ struct RegisterPassBase {
typedef Pass* (*NormalCtor_t)(); typedef Pass* (*NormalCtor_t)();
RegisterPassBase(const char *Name, const char *Arg, const std::type_info &TI, RegisterPassBase(const char *Name, const char *Arg, intptr_t TI,
NormalCtor_t NormalCtor = 0, bool CFGOnly = false) NormalCtor_t NormalCtor = 0, bool CFGOnly = false)
: PIObj(Name, Arg, TI, NormalCtor, CFGOnly) { : PIObj(Name, Arg, TI, NormalCtor, CFGOnly) {
registerPass(); registerPass();
} }
RegisterPassBase(const std::type_info &TI) RegisterPassBase(intptr_t TI)
: PIObj("", "", TI) { : PIObj("", "", TI) {
// This ctor may only be used for analysis groups: it does not auto-register // This ctor may only be used for analysis groups: it does not auto-register
// the pass. // the pass.
@ -165,7 +165,7 @@ struct RegisterPass : public RegisterPassBase {
// Register Pass using default constructor... // Register Pass using default constructor...
RegisterPass(const char *PassArg, const char *Name, bool CFGOnly = false) RegisterPass(const char *PassArg, const char *Name, bool CFGOnly = false)
: RegisterPassBase(Name, PassArg, typeid(PassName), : RegisterPassBase(Name, PassArg, (intptr_t)&PassName::ID,
(RegisterPassBase::NormalCtor_t)callDefaultCtor<PassName>, CFGOnly) { (RegisterPassBase::NormalCtor_t)callDefaultCtor<PassName>, CFGOnly) {
} }
}; };
@ -195,8 +195,8 @@ class RegisterAGBase : public RegisterPassBase {
const PassInfo *ImplementationInfo; const PassInfo *ImplementationInfo;
bool isDefaultImplementation; bool isDefaultImplementation;
protected: protected:
explicit RegisterAGBase(const std::type_info &Interface, explicit RegisterAGBase(intptr_t InterfaceID,
const std::type_info *Pass = 0, intptr_t PassID = 0,
bool isDefault = false); bool isDefault = false);
void setGroupName(const char *Name); void setGroupName(const char *Name);
}; };
@ -204,12 +204,12 @@ protected:
template<typename Interface, bool Default = false> template<typename Interface, bool Default = false>
struct RegisterAnalysisGroup : public RegisterAGBase { struct RegisterAnalysisGroup : public RegisterAGBase {
explicit RegisterAnalysisGroup(RegisterPassBase &RPB) explicit RegisterAnalysisGroup(RegisterPassBase &RPB)
: RegisterAGBase(typeid(Interface), &RPB.getPassInfo()->getTypeInfo(), : RegisterAGBase((intptr_t) &Interface::ID, RPB.getPassInfo()->getTypeInfo(),
Default) { Default) {
} }
explicit RegisterAnalysisGroup(const char *Name) explicit RegisterAnalysisGroup(const char *Name)
: RegisterAGBase(typeid(Interface)) { : RegisterAGBase((intptr_t) &Interface::ID) {
setGroupName(Name); setGroupName(Name);
} }
}; };

View File

@ -133,7 +133,7 @@ namespace {
class PassRegistrar { class PassRegistrar {
/// PassInfoMap - Keep track of the passinfo object for each registered llvm /// PassInfoMap - Keep track of the passinfo object for each registered llvm
/// pass. /// pass.
std::map<TypeInfo, PassInfo*> PassInfoMap; std::map<intptr_t, PassInfo*> PassInfoMap;
/// AnalysisGroupInfo - Keep track of information for each analysis group. /// AnalysisGroupInfo - Keep track of information for each analysis group.
struct AnalysisGroupInfo { struct AnalysisGroupInfo {
@ -147,19 +147,19 @@ class PassRegistrar {
public: public:
const PassInfo *GetPassInfo(const std::type_info &TI) const { const PassInfo *GetPassInfo(intptr_t TI) const {
std::map<TypeInfo, PassInfo*>::const_iterator I = PassInfoMap.find(TI); std::map<intptr_t, PassInfo*>::const_iterator I = PassInfoMap.find(TI);
return I != PassInfoMap.end() ? I->second : 0; return I != PassInfoMap.end() ? I->second : 0;
} }
void RegisterPass(PassInfo &PI) { void RegisterPass(PassInfo &PI) {
bool Inserted = 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!"); assert(Inserted && "Pass registered multiple times!");
} }
void UnregisterPass(PassInfo &PI) { void UnregisterPass(PassInfo &PI) {
std::map<TypeInfo, PassInfo*>::iterator I = std::map<intptr_t, PassInfo*>::iterator I =
PassInfoMap.find(PI.getTypeInfo()); PassInfoMap.find(PI.getTypeInfo());
assert(I != PassInfoMap.end() && "Pass registered but not in map!"); assert(I != PassInfoMap.end() && "Pass registered but not in map!");
@ -168,7 +168,7 @@ public:
} }
void EnumerateWith(PassRegistrationListener *L) { void EnumerateWith(PassRegistrationListener *L) {
for (std::map<TypeInfo, PassInfo*>::const_iterator I = PassInfoMap.begin(), for (std::map<intptr_t, PassInfo*>::const_iterator I = PassInfoMap.begin(),
E = PassInfoMap.end(); I != E; ++I) E = PassInfoMap.end(); I != E; ++I)
L->passEnumerate(I->second); L->passEnumerate(I->second);
} }
@ -210,11 +210,10 @@ static PassRegistrar *getPassRegistrar() {
// getPassInfo - Return the PassInfo data structure that corresponds to this // getPassInfo - Return the PassInfo data structure that corresponds to this
// pass... // pass...
const PassInfo *Pass::getPassInfo() const { const PassInfo *Pass::getPassInfo() const {
if (PassInfoCache) return PassInfoCache; return lookupPassInfo(PassID);
return lookupPassInfo(typeid(*this));
} }
const PassInfo *Pass::lookupPassInfo(const std::type_info &TI) { const PassInfo *Pass::lookupPassInfo(intptr_t TI) {
return getPassRegistrar()->GetPassInfo(TI); return getPassRegistrar()->GetPassInfo(TI);
} }
@ -238,12 +237,12 @@ void RegisterPassBase::unregisterPass() {
// RegisterAGBase implementation // RegisterAGBase implementation
// //
RegisterAGBase::RegisterAGBase(const std::type_info &Interface, RegisterAGBase::RegisterAGBase(intptr_t InterfaceID,
const std::type_info *Pass, bool isDefault) intptr_t PassID, bool isDefault)
: RegisterPassBase(Interface), : RegisterPassBase(InterfaceID),
ImplementationInfo(0), isDefaultImplementation(isDefault) { ImplementationInfo(0), isDefaultImplementation(isDefault) {
InterfaceInfo = const_cast<PassInfo*>(Pass::lookupPassInfo(Interface)); InterfaceInfo = const_cast<PassInfo*>(Pass::lookupPassInfo(InterfaceID));
if (InterfaceInfo == 0) { if (InterfaceInfo == 0) {
// First reference to Interface, register it now. // First reference to Interface, register it now.
registerPass(); registerPass();
@ -252,8 +251,8 @@ RegisterAGBase::RegisterAGBase(const std::type_info &Interface,
assert(PIObj.isAnalysisGroup() && assert(PIObj.isAnalysisGroup() &&
"Trying to join an analysis group that is a normal pass!"); "Trying to join an analysis group that is a normal pass!");
if (Pass) { if (PassID) {
ImplementationInfo = Pass::lookupPassInfo(*Pass); ImplementationInfo = Pass::lookupPassInfo(PassID);
assert(ImplementationInfo && assert(ImplementationInfo &&
"Must register pass before adding to AnalysisGroup!"); "Must register pass before adding to AnalysisGroup!");