diff --git a/include/llvm/Optimizations/LevelChange.h b/include/llvm/Optimizations/LevelChange.h index 745b893d84a..2afbb390dc7 100644 --- a/include/llvm/Optimizations/LevelChange.h +++ b/include/llvm/Optimizations/LevelChange.h @@ -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 { + 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 diff --git a/include/llvm/Transforms/FunctionInlining.h b/include/llvm/Transforms/FunctionInlining.h index b314b97bed4..5a87c1b8e5c 100644 --- a/include/llvm/Transforms/FunctionInlining.h +++ b/include/llvm/Transforms/FunctionInlining.h @@ -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 { + // 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 diff --git a/include/llvm/Transforms/Scalar/ConstantProp.h b/include/llvm/Transforms/Scalar/ConstantProp.h index 7d86ac3250a..3cf6d94c4fb 100644 --- a/include/llvm/Transforms/Scalar/ConstantProp.h +++ b/include/llvm/Transforms/Scalar/ConstantProp.h @@ -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 { + // 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 { + static bool doSCCP(Method *M); + + inline static bool doPerMethodWork(Method *M) { + return doSCCP(M); + } +}; } // End Namespace opt diff --git a/include/llvm/Transforms/Scalar/DCE.h b/include/llvm/Transforms/Scalar/DCE.h index 7ddef5e9129..287a2a8086b 100644 --- a/include/llvm/Transforms/Scalar/DCE.h +++ b/include/llvm/Transforms/Scalar/DCE.h @@ -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 { + // 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 { + // 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 diff --git a/include/llvm/Transforms/Scalar/InductionVars.h b/include/llvm/Transforms/Scalar/InductionVars.h index 4e8d4a68cea..48b267c61ac 100644 --- a/include/llvm/Transforms/Scalar/InductionVars.h +++ b/include/llvm/Transforms/Scalar/InductionVars.h @@ -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 { + inline static bool doPerMethodWork(Method *M) { + return DoInductionVariableCannonicalize(M); + } +}; + } // end namespace opt #endif diff --git a/include/llvm/Transforms/Scalar/SymbolStripping.h b/include/llvm/Transforms/Scalar/SymbolStripping.h index 1b26685d1e8..83724eb7394 100644 --- a/include/llvm/Transforms/Scalar/SymbolStripping.h +++ b/include/llvm/Transforms/Scalar/SymbolStripping.h @@ -10,24 +10,35 @@ 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 { + // 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 { + + // 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