Fix PR139: \
[oota-llvm.git] / include / llvm / PassSupport.h
index 16115cf5f3518b2a60d7fb7d8892f59b264b6d76..f20e40743f36b5f7b2a7c6b975e01e8d41dd5705 100644 (file)
@@ -1,4 +1,11 @@
 //===- llvm/PassSupport.h - Pass Support code -------------------*- C++ -*-===//
+// 
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// 
+//===----------------------------------------------------------------------===//
 //
 // This file defines stuff that is used to define and "use" Passes.  This file
 // is automatically #included by Pass.h, so:
@@ -16,6 +23,8 @@
 
 // No need to include Pass.h, we are being included by it!
 
+namespace llvm {
+
 class TargetMachine;
 
 //===---------------------------------------------------------------------------
@@ -47,7 +56,7 @@ public:
   /// PassInfo ctor - Do not call this directly, this should only be invoked
   /// through RegisterPass.
   PassInfo(const char *name, const char *arg, const std::type_info &ti, 
-           unsigned pt, Pass *(*normal)() = 0,
+           unsigned char pt, Pass *(*normal)() = 0,
            Pass *(*targetctor)(TargetMachine &) = 0)
     : PassName(name), PassArgument(arg), TypeInfo(ti), PassType(pt),
       NormalCtor(normal), TargetCtor(targetctor)  {
@@ -152,10 +161,10 @@ protected:
   void registerPass(PassInfo *);
   void unregisterPass(PassInfo *);
 
-  /// setPreservesCFG - Notice that this pass only depends on the CFG, so
+  /// setOnlyUsesCFG - Notice that this pass only depends on the CFG, so
   /// transformations that do not modify the CFG do not invalidate this pass.
   ///
-  void setPreservesCFG();
+  void setOnlyUsesCFG();
 };
 
 template<typename PassName>
@@ -165,19 +174,19 @@ template<typename PassName>
 struct RegisterPass : public RegisterPassBase {
   
   // Register Pass using default constructor...
-  RegisterPass(const char *PassArg, const char *Name, unsigned PassTy = 0) {
+  RegisterPass(const char *PassArg, const char *Name, unsigned char 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,
+  RegisterPass(const char *PassArg, const char *Name, unsigned char 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,
+  RegisterPass(const char *PassArg, const char *Name, unsigned char PassTy,
                Pass *(*targetctor)(TargetMachine &)) {
     registerPass(new PassInfo(Name, PassArg, typeid(PassName), PassTy,
                               0, targetctor));
@@ -185,7 +194,7 @@ struct RegisterPass : public RegisterPassBase {
 
   // Generic constructor version that has an unknown ctor type...
   template<typename CtorType>
-  RegisterPass(const char *PassArg, const char *Name, unsigned PassTy,
+  RegisterPass(const char *PassArg, const char *Name, unsigned char PassTy,
                CtorType *Fn) {
     registerPass(new PassInfo(Name, PassArg, typeid(PassName), PassTy, 0));
   }
@@ -196,25 +205,50 @@ struct RegisterPass : public RegisterPassBase {
 ///
 template<typename PassName>
 struct RegisterOpt : public RegisterPassBase {
-  RegisterOpt(const char *PassArg, const char *Name) {
+  RegisterOpt(const char *PassArg, const char *Name, bool CFGOnly = false) {
     registerPass(new PassInfo(Name, PassArg, typeid(PassName),
                               PassInfo::Optimization,
                               callDefaultCtor<PassName>));
+    if (CFGOnly) setOnlyUsesCFG();
   }
 
   /// Register Pass using default constructor explicitly...
   ///
-  RegisterOpt(const char *PassArg, const char *Name, Pass *(*ctor)()) {
+  RegisterOpt(const char *PassArg, const char *Name, Pass *(*ctor)(),
+              bool CFGOnly = false) {
     registerPass(new PassInfo(Name, PassArg, typeid(PassName),
                               PassInfo::Optimization, ctor));
+    if (CFGOnly) setOnlyUsesCFG();
+  }
+
+  /// Register FunctionPass using default constructor explicitly...
+  ///
+  RegisterOpt(const char *PassArg, const char *Name, FunctionPass *(*ctor)(),
+              bool CFGOnly = false) {
+    registerPass(new PassInfo(Name, PassArg, typeid(PassName),
+                              PassInfo::Optimization, 
+                              static_cast<Pass*(*)()>(ctor)));
+    if (CFGOnly) setOnlyUsesCFG();
   }
 
   /// Register Pass using TargetMachine constructor...
   ///
   RegisterOpt(const char *PassArg, const char *Name,
-               Pass *(*targetctor)(TargetMachine &)) {
+               Pass *(*targetctor)(TargetMachine &), bool CFGOnly = false) {
     registerPass(new PassInfo(Name, PassArg, typeid(PassName),
                               PassInfo::Optimization, 0, targetctor));
+    if (CFGOnly) setOnlyUsesCFG();
+  }
+
+  /// Register FunctionPass using TargetMachine constructor...
+  ///
+  RegisterOpt(const char *PassArg, const char *Name,
+              FunctionPass *(*targetctor)(TargetMachine &),
+              bool CFGOnly = false) {
+    registerPass(new PassInfo(Name, PassArg, typeid(PassName),
+                              PassInfo::Optimization, 0,
+                            static_cast<Pass*(*)(TargetMachine&)>(targetctor)));
+    if (CFGOnly) setOnlyUsesCFG();
   }
 };
 
@@ -231,8 +265,7 @@ struct RegisterAnalysis : public RegisterPassBase {
     registerPass(new PassInfo(Name, PassArg, typeid(PassName),
                               PassInfo::Analysis,
                               callDefaultCtor<PassName>));
-    if (CFGOnly)
-      setPreservesCFG();
+    if (CFGOnly) setOnlyUsesCFG();
   }
 };
 
@@ -365,4 +398,7 @@ struct PassRegistrationListener {
 struct IncludeFile {
   IncludeFile(void *);
 };
+
+} // End llvm namespace
+
 #endif