-/// Pass *createMyPass(foo &opt) { return new MyPass(opt); }
-/// static RegisterPass<PassClassName> tmp("passopt", "My Name", createMyPass);
-///
-struct RegisterPassBase {
- /// getPassInfo - Get the pass info for the registered class...
- ///
- const PassInfo *getPassInfo() const { return PIObj; }
-
- RegisterPassBase() : PIObj(0) {}
- ~RegisterPassBase() { // Intentionally non-virtual...
- if (PIObj) unregisterPass(PIObj);
- }
-
-protected:
- PassInfo *PIObj; // The PassInfo object for this pass
- void registerPass(PassInfo *);
- void unregisterPass(PassInfo *);
-
- /// setPreservesCFG - Notice that this pass only depends on the CFG, so
- /// transformations that do not modify the CFG do not invalidate this pass.
- ///
- void setPreservesCFG();
-};
-
-template<typename PassName>
-Pass *callDefaultCtor() { return new PassName(); }
-
-template<typename PassName>
-struct RegisterPass : public RegisterPassBase {
-
- // Register Pass using default constructor...
- RegisterPass(const char *PassArg, const char *Name, unsigned PassTy = 0) {
- registerPass(new PassInfo(Name, PassArg, typeid(PassName), PassTy,
- callDefaultCtor<PassName>, 0));
- }
-
- // Register Pass using default constructor explicitly...
- RegisterPass(const char *PassArg, const char *Name, unsigned PassTy,
- Pass *(*ctor)()) {
- registerPass(new PassInfo(Name, PassArg, typeid(PassName), PassTy, ctor,0));
- }
-
- // Register Pass using TargetData constructor...
- RegisterPass(const char *PassArg, const char *Name, unsigned PassTy,
- Pass *(*datactor)(const TargetData &)) {
- registerPass(new PassInfo(Name, PassArg, typeid(PassName), PassTy,
- 0, datactor));
- }
-
- // Generic constructor version that has an unknown ctor type...
- template<typename CtorType>
- RegisterPass(const char *PassArg, const char *Name, unsigned PassTy,
- CtorType *Fn) {
- registerPass(new PassInfo(Name, PassArg, typeid(PassName), PassTy, 0, 0));
- }
-};
-
-/// RegisterOpt - Register something that is to show up in Opt, this is just a
-/// shortcut for specifying RegisterPass...
-///
-template<typename PassName>
-struct RegisterOpt : public RegisterPassBase {
- RegisterOpt(const char *PassArg, const char *Name) {
- registerPass(new PassInfo(Name, PassArg, typeid(PassName),
- PassInfo::Optimization,
- callDefaultCtor<PassName>, 0));
- }
-
- /// Register Pass using default constructor explicitly...
- ///
- RegisterOpt(const char *PassArg, const char *Name, Pass *(*ctor)()) {
- registerPass(new PassInfo(Name, PassArg, typeid(PassName),
- PassInfo::Optimization, ctor, 0));
- }
-
- /// Register Pass using TargetData constructor...
- ///
- RegisterOpt(const char *PassArg, const char *Name,
- Pass *(*datactor)(const TargetData &)) {
- registerPass(new PassInfo(Name, PassArg, typeid(PassName),
- PassInfo::Optimization, 0, datactor));
- }
-};
-
-/// RegisterAnalysis - Register something that is to show up in Analysis, this
-/// is just a shortcut for specifying RegisterPass... Analyses take a special
-/// argument that, when set to true, tells the system that the analysis ONLY
-/// depends on the shape of the CFG, so if a transformation preserves the CFG
-/// that the analysis is not invalidated.
-///
-template<typename PassName>
-struct RegisterAnalysis : public RegisterPassBase {
- RegisterAnalysis(const char *PassArg, const char *Name,
- bool CFGOnly = false) {
- registerPass(new PassInfo(Name, PassArg, typeid(PassName),
- PassInfo::Analysis,
- callDefaultCtor<PassName>, 0));
- if (CFGOnly)
- setPreservesCFG();
- }
-};
-
-/// RegisterLLC - Register something that is to show up in LLC, this is just a
-/// shortcut for specifying RegisterPass...