Another step towards getting rid of static ctors for pass registration: have INITIALIZE_PASS AND INITIALIZE_AG_PASS

expand to an initializeMyPass() function (in additional to the extant static ctors).  Eventually, these will be called
from a big InitializeAllPasses() function, and the PassInfo's they create (which would be leaked if this code were used
at the moment) will be handed off to a PassRegistry for ownership.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@115703 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Owen Anderson 2010-10-05 22:58:16 +00:00
parent df72eaef3d
commit e2a268fd03
2 changed files with 19 additions and 8 deletions

View File

@ -55,17 +55,14 @@ public:
NormalCtor_t normal, bool isCFGOnly, bool is_analysis) NormalCtor_t normal, bool isCFGOnly, bool is_analysis)
: PassName(name), PassArgument(arg), PassID(pi), : PassName(name), PassArgument(arg), PassID(pi),
IsCFGOnlyPass(isCFGOnly), IsCFGOnlyPass(isCFGOnly),
IsAnalysis(is_analysis), IsAnalysisGroup(false), NormalCtor(normal) { IsAnalysis(is_analysis), IsAnalysisGroup(false), NormalCtor(normal) { }
PassRegistry::getPassRegistry()->registerPass(*this);
}
/// 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. This version is for use by analysis groups; it /// through RegisterPass. This version is for use by analysis groups; it
/// does not auto-register the pass. /// does not auto-register the pass.
PassInfo(const char *name, const void *pi) PassInfo(const char *name, const void *pi)
: PassName(name), PassArgument(""), PassID(pi), : PassName(name), PassArgument(""), PassID(pi),
IsCFGOnlyPass(false), IsCFGOnlyPass(false),
IsAnalysis(false), IsAnalysisGroup(true), NormalCtor(0) { IsAnalysis(false), IsAnalysisGroup(true), NormalCtor(0) { }
}
/// getPassName - Return the friendly name for the pass, never returns null /// getPassName - Return the friendly name for the pass, never returns null
/// ///
@ -131,8 +128,14 @@ private:
}; };
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis) \ #define INITIALIZE_PASS(passName, arg, name, cfg, analysis) \
void initialize##passName##Pass() { \
PassInfo *PI = new PassInfo(name, arg, & passName ::ID, \
PassInfo::NormalCtor_t(callDefaultCtor< passName >), cfg, analysis); \
PassRegistry::getPassRegistry()->registerPass(*PI); \
} \
static RegisterPass<passName> passName ## _info(arg, name, cfg, analysis) static RegisterPass<passName> passName ## _info(arg, name, cfg, analysis)
template<typename PassName> template<typename PassName>
Pass *callDefaultCtor() { return new PassName(); } Pass *callDefaultCtor() { return new PassName(); }
@ -162,7 +165,7 @@ struct RegisterPass : public PassInfo {
: PassInfo(Name, PassArg, &passName::ID, : PassInfo(Name, PassArg, &passName::ID,
PassInfo::NormalCtor_t(callDefaultCtor<passName>), PassInfo::NormalCtor_t(callDefaultCtor<passName>),
CFGOnly, is_analysis) { CFGOnly, is_analysis) {
PassRegistry::getPassRegistry()->registerPass(*this);
} }
}; };
@ -187,7 +190,7 @@ struct RegisterPass : public PassInfo {
/// a nice name with the interface. /// a nice name with the interface.
/// ///
class RegisterAGBase : public PassInfo { class RegisterAGBase : public PassInfo {
protected: public:
RegisterAGBase(const char *Name, RegisterAGBase(const char *Name,
const void *InterfaceID, const void *InterfaceID,
const void *PassID = 0, const void *PassID = 0,
@ -208,6 +211,15 @@ struct RegisterAnalysisGroup : public RegisterAGBase {
}; };
#define INITIALIZE_AG_PASS(passName, agName, arg, name, cfg, analysis, def) \ #define INITIALIZE_AG_PASS(passName, agName, arg, name, cfg, analysis, def) \
void initialize##passName##Pass() { \
PassInfo *PI = new PassInfo(name, arg, & passName ::ID, \
PassInfo::NormalCtor_t(callDefaultCtor< passName >), cfg, analysis); \
PassRegistry::getPassRegistry()->registerPass(*PI); \
\
PassInfo *AI = new PassInfo(name, & agName :: ID); \
PassRegistry::getPassRegistry()->registerAnalysisGroup( \
& agName ::ID, & passName ::ID, *AI, def); \
} \
static RegisterPass<passName> passName ## _info(arg, name, cfg, analysis); \ static RegisterPass<passName> passName ## _info(arg, name, cfg, analysis); \
static RegisterAnalysisGroup<agName, def> passName ## _ag(passName ## _info) static RegisterAnalysisGroup<agName, def> passName ## _ag(passName ## _info)

View File

@ -213,7 +213,6 @@ RegisterAGBase::RegisterAGBase(const char *Name, const void *InterfaceID,
*this, isDefault); *this, isDefault);
} }
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// PassRegistrationListener implementation // PassRegistrationListener implementation
// //