-/// 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>));
- }
-
- // 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));
- }
-
- // Register Pass using TargetMachine constructor...
- RegisterPass(const char *PassArg, const char *Name, unsigned PassTy,
- Pass *(*targetctor)(TargetMachine &)) {
- registerPass(new PassInfo(Name, PassArg, typeid(PassName), PassTy,
- 0, targetctor));
- }
-
- // 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));
- }
-};
-
-/// 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>));
- }
-
- /// 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));
- }
-
- /// Register Pass using TargetMachine constructor...
- ///
- RegisterOpt(const char *PassArg, const char *Name,
- Pass *(*targetctor)(TargetMachine &)) {
- registerPass(new PassInfo(Name, PassArg, typeid(PassName),
- PassInfo::Optimization, 0, targetctor));
- }
-};
-
-/// 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.