Convert optimizations to use the Pass infrastructure
authorChris Lattner <sabre@nondot.org>
Thu, 18 Oct 2001 01:31:58 +0000 (01:31 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 18 Oct 2001 01:31:58 +0000 (01:31 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@871 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Optimizations/LevelChange.h
include/llvm/Transforms/FunctionInlining.h
include/llvm/Transforms/Scalar/ConstantProp.h
include/llvm/Transforms/Scalar/DCE.h
include/llvm/Transforms/Scalar/InductionVars.h
include/llvm/Transforms/Scalar/SymbolStripping.h

index 745b893d84a14c02d5f059b8648df9ccf5ec9cf4..2afbb390dc7d6df77dd65834090342913c24bee5 100644 (file)
@@ -9,6 +9,7 @@
 #ifndef LLVM_OPT_LEVELCHANGE_H
 #define LLVM_OPT_LEVELCHANGE_H
 
+#include "llvm/Transforms/Pass.h"
 #include "llvm/Module.h"
 #include "llvm/Method.h"
 
@@ -50,6 +51,13 @@ namespace opt {
     return DoRaiseRepresentation(M, Level::Highest);
   }
 
+  struct RaiseRepresentation : public StatelessPass<RaiseRepresentation> {
+    inline static bool doPerMethodWork(Method *M) {
+      return DoRaiseRepresentation(M);
+    }
+  };
+
+
   // DoEliminateAuxillaryInductionVariables - Eliminate all aux indvars.  This
   // is one of the transformations performed by DoRaiseRepresentation, that
   // converts all induction variables to reference a cannonical induction
index b314b97bed46eaf5c4964276ec5c5c904553d759..5a87c1b8e5cbeb2127a5001495f691ce7566033d 100644 (file)
@@ -7,20 +7,22 @@
 #ifndef LLVM_OPT_METHOD_INLINING_H
 #define LLVM_OPT_METHOD_INLINING_H
 
-#include "llvm/Module.h"
+#include "llvm/Transforms/Pass.h"
 #include "llvm/BasicBlock.h"
 class CallInst;
 
 namespace opt {
 
-// DoMethodInlining - Use a heuristic based approach to inline methods that seem
-// to look good.
-//
-bool DoMethodInlining(Method *M);
+struct MethodInlining : public StatelessPass<MethodInlining> {
+  // DoMethodInlining - Use a heuristic based approach to inline methods that
+  // seem to look good.
+  //
+  static bool doMethodInlining(Method *M);
 
-static inline bool DoMethodInlining(Module *M) { 
-  return M->reduceApply(DoMethodInlining); 
-}
+  inline static bool doPerMethodWork(Method *M) {
+    return doMethodInlining(M);
+  }
+};
 
 // InlineMethod - This function forcibly inlines the called method into the
 // basic block of the caller.  This returns true if it is not possible to inline
index 7d86ac3250a92e4adbdc4d7093113eb5ccc0edec..3cf6d94c4fbb510b0d52cd8ee299d54f2fdeb309 100644 (file)
@@ -7,19 +7,21 @@
 #ifndef LLVM_OPT_CONSTANT_PROPOGATION_H
 #define LLVM_OPT_CONSTANT_PROPOGATION_H
 
-#include "llvm/Module.h"
-class Method;
+#include "llvm/Transforms/Pass.h"
 class TerminatorInst;
 
 namespace opt {
 
-// DoConstantPropogation - Do trivial constant propogation and expression
-// folding
-bool DoConstantPropogation(Method *M);
+struct ConstantPropogation : public StatelessPass<ConstantPropogation> {
+  // doConstantPropogation - Do trivial constant propogation and expression
+  // folding
+  static bool doConstantPropogation(Method *M);
+
+  inline static bool doPerMethodWork(Method *M) {
+    return doConstantPropogation(M);
+  }
+};
 
-static inline bool DoConstantPropogation(Module *M) { 
-  return M->reduceApply(DoConstantPropogation); 
-}
 
 
 // ConstantFoldTerminator - If a terminator instruction is predicated on a
@@ -33,10 +35,13 @@ bool ConstantFoldTerminator(TerminatorInst *T);
 // Sparse Conditional Constant Propogation Pass
 //
 
-bool DoSCCP(Method *M);
-static inline bool DoSCCP(Module *M) {
-  return M->reduceApply(DoSCCP);
-}
+struct SCCPPass : public StatelessPass<SCCPPass> {
+  static bool doSCCP(Method *M);
+
+  inline static bool doPerMethodWork(Method *M) {
+    return doSCCP(M);
+  }
+};
 
 }  // End Namespace opt
 
index 7ddef5e91292a2217f5819bfda2287a1f1d0c165..287a2a8086ba935736ef7c20e7ec9ed7fc5766f5 100644 (file)
@@ -8,21 +8,52 @@
 #ifndef LLVM_OPT_DCE_H
 #define LLVM_OPT_DCE_H
 
-#include "llvm/Module.h"
-#include "llvm/Method.h"
+#include "llvm/Transforms/Pass.h"
 
 namespace opt {
 
-bool DoDeadCodeElimination(Method *M);         // DCE a method
-bool DoDeadCodeElimination(Module *C);         // DCE & RUC a whole module
+struct DeadCodeElimination : public StatelessPass<DeadCodeElimination> {
+  // External Interface:
+  //
+  static bool doDCE(Method *M);
+
+  // Remove unused global values - This removes unused global values of no
+  // possible value.  This currently includes unused method prototypes and
+  // unitialized global variables.
+  //
+  static bool RemoveUnusedGlobalValues(Module *M);
+
+  // RemoveUnusedGlobalValuesAfterLink - This function is only to be used after
+  // linking the application.  It removes global variables with initializers and
+  // unreachable methods.  This should only be used after an application is
+  // linked, when it is not possible for an external entity to make a global
+  // value live again.
+  //
+  // static bool RemoveUnusedGlobalValuesAfterLink(Module *M); // TODO
+
+  // Pass Interface...
+  inline static bool doPassInitialization(Module *M) {
+    return RemoveUnusedGlobalValues(M);
+  }
+  inline static bool doPerMethodWork(Method *M) { return doDCE(M); }
+  inline static bool doPassFinalization(Module *M) {
+    return RemoveUnusedGlobalValues(M);
+  }
+};
+
+
+
+struct AgressiveDCE : public StatelessPass<AgressiveDCE> {
+  // DoADCE - Execute the Agressive Dead Code Elimination Algorithm
+  //
+  static bool doADCE(Method *M);                        // Defined in ADCE.cpp
+
+  inline static bool doPerMethodWork(Method *M) {
+    return doADCE(M);
+  }
+};
 
 
-// DoADCE - Execute the Agressive Dead Code Elimination Algorithm
-//
-bool DoADCE(Method *M);                        // Defined in ADCE.cpp
-static inline bool DoADCE(Module *M) {
-  return M->reduceApply(DoADCE);
-}
 
 // SimplifyCFG - This function is used to do simplification of a CFG.  For
 // example, it adjusts branches to branches to eliminate the extra hop, it
index 4e8d4a68cea1a1300c7f7df9656ce138927e0559..48b267c61ac09d78b8ece050904a21558471c845 100644 (file)
@@ -8,6 +8,7 @@
 #ifndef LLVM_OPT_INDUCTION_VARS_H
 #define LLVM_OPT_INDUCTION_VARS_H
 
+#include "llvm/Transforms/Pass.h"
 #include "llvm/Module.h"
 
 namespace opt {
@@ -19,6 +20,13 @@ static inline bool DoInductionVariableCannonicalize(Module *M) {
   return M->reduceApply(DoInductionVariableCannonicalize); 
 }
 
+struct InductionVariableCannonicalize : 
+    public StatelessPass<InductionVariableCannonicalize> {
+  inline static bool doPerMethodWork(Method *M) {
+    return DoInductionVariableCannonicalize(M);
+  }
+};
+
 }  // end namespace opt
 
 #endif
index 1b26685d1e805f5f6e2c1fcf1df2a86e51fe135c..83724eb739443dbc084d8b3bfd47a9ab1735f4d2 100644 (file)
 
 class Method;
 class Module;
+#include "llvm/Transforms/Pass.h"
 
 namespace opt {
 
-// DoSymbolStripping - Remove all symbolic information from a method
-//
-bool DoSymbolStripping(Method *M);
+struct SymbolStripping : public StatelessPass<SymbolStripping> {
+  // doSymbolStripping - Remove all symbolic information from a method
+  //
+  static bool doSymbolStripping(Method *M);
 
-// DoSymbolStripping - Remove all symbolic information from all methods in a 
-// module
-//
-static inline bool DoSymbolStripping(Module *M) { 
-  return M->reduceApply(DoSymbolStripping); 
-}
+  inline static bool doPerMethodWork(Method *M) {
+    return doSymbolStripping(M);
+  }
+};
 
-// DoFullSymbolStripping - Remove all symbolic information from all methods 
-// in a module, and all module level symbols. (method names, etc...)
-//
-bool DoFullSymbolStripping(Module *M);
+struct FullSymbolStripping : public StatelessPass<FullSymbolStripping> {
+  
+  // doStripGlobalSymbols - Remove all symbolic information from all methods 
+  // in a module, and all module level symbols. (method names, etc...)
+  //
+  static bool doStripGlobalSymbols(Module *M);
+
+  inline static bool doPassInitialization(Module *M) {
+    return doStripGlobalSymbols(M);
+  }
+
+  inline static bool doPerMethodWork(Method *M) {
+    return SymbolStripping::doSymbolStripping(M);
+  }
+};
 
 } // End namespace opt 
 #endif