- // 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), 0, 0));
+template<typename PassName>
+Pass *callDefaultCtor() { return new PassName(); }
+
+//===---------------------------------------------------------------------------
+/// RegisterPass<t> template - This template class is used to notify the system
+/// that a Pass is available for use, and registers it into the internal
+/// database maintained by the PassManager. Unless this template is used, opt,
+/// for example will not be able to see the pass and attempts to create the pass
+/// will fail. This template is used in the follow manner (at global scope, in
+/// your .cpp file):
+///
+/// static RegisterPass<YourPassClassName> tmp("passopt", "My Pass Name");
+///
+/// This statement will cause your pass to be created by calling the default
+/// constructor exposed by the pass. If you have a different constructor that
+/// must be called, create a global constructor function (which takes the
+/// arguments you need and returns a Pass*) and register your pass like this:
+///
+/// static RegisterPass<PassClassName> tmp("passopt", "My Name");
+///
+template<typename passName>
+struct RegisterPass : public PassInfo {
+
+ // Register Pass using default constructor...
+ RegisterPass(const char *PassArg, const char *Name, bool CFGOnly = false,
+ bool is_analysis = false)
+ : PassInfo(Name, PassArg, &passName::ID,
+ PassInfo::NormalCtor_t(callDefaultCtor<passName>),
+ CFGOnly, is_analysis) {
+ PassRegistry::getPassRegistry()->registerPass(*this);