aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2001-10-18 01:31:58 +0000
committerChris Lattner <sabre@nondot.org>2001-10-18 01:31:58 +0000
commit475369e255bbdd70de3fb870bbd9fae3d6b1038f (patch)
treecd718cac568ffe8b871a8645a21252b28da005e0
parent6db0f4795cbd9b58add13c2b2f0c7124112ab9b7 (diff)
Convert optimizations to use the Pass infrastructure
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@871 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Optimizations/LevelChange.h8
-rw-r--r--include/llvm/Transforms/FunctionInlining.h18
-rw-r--r--include/llvm/Transforms/Scalar/ConstantProp.h29
-rw-r--r--include/llvm/Transforms/Scalar/DCE.h51
-rw-r--r--include/llvm/Transforms/Scalar/InductionVars.h8
-rw-r--r--include/llvm/Transforms/Scalar/SymbolStripping.h37
6 files changed, 108 insertions, 43 deletions
diff --git a/include/llvm/Optimizations/LevelChange.h b/include/llvm/Optimizations/LevelChange.h
index 745b893d84..2afbb390dc 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<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
diff --git a/include/llvm/Transforms/FunctionInlining.h b/include/llvm/Transforms/FunctionInlining.h
index b314b97bed..5a87c1b8e5 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<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
diff --git a/include/llvm/Transforms/Scalar/ConstantProp.h b/include/llvm/Transforms/Scalar/ConstantProp.h
index 7d86ac3250..3cf6d94c4f 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<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
diff --git a/include/llvm/Transforms/Scalar/DCE.h b/include/llvm/Transforms/Scalar/DCE.h
index 7ddef5e912..287a2a8086 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<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
diff --git a/include/llvm/Transforms/Scalar/InductionVars.h b/include/llvm/Transforms/Scalar/InductionVars.h
index 4e8d4a68ce..48b267c61a 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<InductionVariableCannonicalize> {
+ 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 1b26685d1e..83724eb739 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<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