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
#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

View 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

View 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

View 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

View 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

View File

@ -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