Convert optimizations to use the Pass infrastructure

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@871 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2001-10-18 01:31:58 +00:00
parent 6db0f4795c
commit 475369e255
6 changed files with 108 additions and 43 deletions

View File

@ -9,6 +9,7 @@
#ifndef LLVM_OPT_LEVELCHANGE_H #ifndef LLVM_OPT_LEVELCHANGE_H
#define LLVM_OPT_LEVELCHANGE_H #define LLVM_OPT_LEVELCHANGE_H
#include "llvm/Transforms/Pass.h"
#include "llvm/Module.h" #include "llvm/Module.h"
#include "llvm/Method.h" #include "llvm/Method.h"
@ -50,6 +51,13 @@ namespace opt {
return DoRaiseRepresentation(M, Level::Highest); 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 // DoEliminateAuxillaryInductionVariables - Eliminate all aux indvars. This
// is one of the transformations performed by DoRaiseRepresentation, that // is one of the transformations performed by DoRaiseRepresentation, that
// converts all induction variables to reference a cannonical induction // converts all induction variables to reference a cannonical induction

View File

@ -7,20 +7,22 @@
#ifndef LLVM_OPT_METHOD_INLINING_H #ifndef LLVM_OPT_METHOD_INLINING_H
#define LLVM_OPT_METHOD_INLINING_H #define LLVM_OPT_METHOD_INLINING_H
#include "llvm/Module.h" #include "llvm/Transforms/Pass.h"
#include "llvm/BasicBlock.h" #include "llvm/BasicBlock.h"
class CallInst; class CallInst;
namespace opt { namespace opt {
// DoMethodInlining - Use a heuristic based approach to inline methods that seem struct MethodInlining : public StatelessPass<MethodInlining> {
// to look good. // DoMethodInlining - Use a heuristic based approach to inline methods that
// // seem to look good.
bool DoMethodInlining(Method *M); //
static bool doMethodInlining(Method *M);
static inline bool DoMethodInlining(Module *M) { inline static bool doPerMethodWork(Method *M) {
return M->reduceApply(DoMethodInlining); return doMethodInlining(M);
} }
};
// InlineMethod - This function forcibly inlines the called method into the // 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 // basic block of the caller. This returns true if it is not possible to inline

View File

@ -7,19 +7,21 @@
#ifndef LLVM_OPT_CONSTANT_PROPOGATION_H #ifndef LLVM_OPT_CONSTANT_PROPOGATION_H
#define LLVM_OPT_CONSTANT_PROPOGATION_H #define LLVM_OPT_CONSTANT_PROPOGATION_H
#include "llvm/Module.h" #include "llvm/Transforms/Pass.h"
class Method;
class TerminatorInst; class TerminatorInst;
namespace opt { namespace opt {
// DoConstantPropogation - Do trivial constant propogation and expression struct ConstantPropogation : public StatelessPass<ConstantPropogation> {
// folding // doConstantPropogation - Do trivial constant propogation and expression
bool DoConstantPropogation(Method *M); // 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 // ConstantFoldTerminator - If a terminator instruction is predicated on a
@ -33,10 +35,13 @@ bool ConstantFoldTerminator(TerminatorInst *T);
// Sparse Conditional Constant Propogation Pass // Sparse Conditional Constant Propogation Pass
// //
bool DoSCCP(Method *M); struct SCCPPass : public StatelessPass<SCCPPass> {
static inline bool DoSCCP(Module *M) { static bool doSCCP(Method *M);
return M->reduceApply(DoSCCP);
} inline static bool doPerMethodWork(Method *M) {
return doSCCP(M);
}
};
} // End Namespace opt } // End Namespace opt

View File

@ -8,21 +8,52 @@
#ifndef LLVM_OPT_DCE_H #ifndef LLVM_OPT_DCE_H
#define LLVM_OPT_DCE_H #define LLVM_OPT_DCE_H
#include "llvm/Module.h" #include "llvm/Transforms/Pass.h"
#include "llvm/Method.h"
namespace opt { namespace opt {
bool DoDeadCodeElimination(Method *M); // DCE a method struct DeadCodeElimination : public StatelessPass<DeadCodeElimination> {
bool DoDeadCodeElimination(Module *C); // DCE & RUC a whole module // 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 // SimplifyCFG - This function is used to do simplification of a CFG. For
// example, it adjusts branches to branches to eliminate the extra hop, it // example, it adjusts branches to branches to eliminate the extra hop, it

View File

@ -8,6 +8,7 @@
#ifndef LLVM_OPT_INDUCTION_VARS_H #ifndef LLVM_OPT_INDUCTION_VARS_H
#define LLVM_OPT_INDUCTION_VARS_H #define LLVM_OPT_INDUCTION_VARS_H
#include "llvm/Transforms/Pass.h"
#include "llvm/Module.h" #include "llvm/Module.h"
namespace opt { namespace opt {
@ -19,6 +20,13 @@ static inline bool DoInductionVariableCannonicalize(Module *M) {
return M->reduceApply(DoInductionVariableCannonicalize); return M->reduceApply(DoInductionVariableCannonicalize);
} }
struct InductionVariableCannonicalize :
public StatelessPass<InductionVariableCannonicalize> {
inline static bool doPerMethodWork(Method *M) {
return DoInductionVariableCannonicalize(M);
}
};
} // end namespace opt } // end namespace opt
#endif #endif

View File

@ -10,24 +10,35 @@
class Method; class Method;
class Module; class Module;
#include "llvm/Transforms/Pass.h"
namespace opt { namespace opt {
// DoSymbolStripping - Remove all symbolic information from a method struct SymbolStripping : public StatelessPass<SymbolStripping> {
// // doSymbolStripping - Remove all symbolic information from a method
bool DoSymbolStripping(Method *M); //
static bool doSymbolStripping(Method *M);
// DoSymbolStripping - Remove all symbolic information from all methods in a inline static bool doPerMethodWork(Method *M) {
// module return doSymbolStripping(M);
// }
static inline bool DoSymbolStripping(Module *M) { };
return M->reduceApply(DoSymbolStripping);
}
// DoFullSymbolStripping - Remove all symbolic information from all methods struct FullSymbolStripping : public StatelessPass<FullSymbolStripping> {
// in a module, and all module level symbols. (method names, etc...)
// // doStripGlobalSymbols - Remove all symbolic information from all methods
bool DoFullSymbolStripping(Module *M); // 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 } // End namespace opt
#endif #endif