aboutsummaryrefslogtreecommitdiff
path: root/include/llvm/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-01-21 07:31:50 +0000
committerChris Lattner <sabre@nondot.org>2002-01-21 07:31:50 +0000
commitf4de63f65fa995e68e3cd268117ab065068be413 (patch)
tree2fd8cd44af0f23dafd94102c1c0152b1cd82fe4d /include/llvm/Transforms
parentaff5bcebb7fb9880e0a3518a8e7c999e738d531c (diff)
Implement a more powerful, simpler, pass system. This pass system can figure
out how to run a collection of passes optimially given their behaviors and charactaristics. Convert code to use it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1507 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Transforms')
-rw-r--r--include/llvm/Transforms/ChangeAllocations.h6
-rw-r--r--include/llvm/Transforms/FunctionInlining.h4
-rw-r--r--include/llvm/Transforms/HoistPHIConstants.h4
-rw-r--r--include/llvm/Transforms/IPO.h8
-rw-r--r--include/llvm/Transforms/IPO/ConstantMerge.h15
-rw-r--r--include/llvm/Transforms/IPO/GlobalDCE.h6
-rw-r--r--include/llvm/Transforms/IPO/SimpleStructMutation.h25
-rw-r--r--include/llvm/Transforms/Instrumentation/TraceValues.h8
-rw-r--r--include/llvm/Transforms/MutateStructTypes.h29
-rw-r--r--include/llvm/Transforms/RaisePointerReferences.h8
-rw-r--r--include/llvm/Transforms/Scalar/ConstantProp.h8
-rw-r--r--include/llvm/Transforms/Scalar/DCE.h12
-rw-r--r--include/llvm/Transforms/Scalar/IndVarSimplify.h4
-rw-r--r--include/llvm/Transforms/Scalar/InductionVars.h4
-rw-r--r--include/llvm/Transforms/Scalar/InstructionCombining.h4
-rw-r--r--include/llvm/Transforms/Scalar/SymbolStripping.h10
16 files changed, 90 insertions, 65 deletions
diff --git a/include/llvm/Transforms/ChangeAllocations.h b/include/llvm/Transforms/ChangeAllocations.h
index 8f53051da3..05fb133410 100644
--- a/include/llvm/Transforms/ChangeAllocations.h
+++ b/include/llvm/Transforms/ChangeAllocations.h
@@ -13,7 +13,7 @@
#include "llvm/Pass.h"
class TargetData;
-class LowerAllocations : public Pass {
+class LowerAllocations : public MethodPass {
Method *MallocMeth; // Methods in the module we are processing
Method *FreeMeth; // Initialized by doPassInitializationVirt
@@ -28,12 +28,12 @@ public:
//
// This function is always successful.
//
- bool doPassInitialization(Module *M);
+ bool doInitialization(Module *M);
// doPerMethodWork - This method does the actual work of converting
// instructions over, assuming that the pass has already been initialized.
//
- bool doPerMethodWork(Method *M);
+ bool runOnMethod(Method *M);
};
#endif
diff --git a/include/llvm/Transforms/FunctionInlining.h b/include/llvm/Transforms/FunctionInlining.h
index 520cc7fe6c..abc08fdbad 100644
--- a/include/llvm/Transforms/FunctionInlining.h
+++ b/include/llvm/Transforms/FunctionInlining.h
@@ -13,13 +13,13 @@ class CallInst;
namespace opt {
-struct MethodInlining : public Pass {
+struct MethodInlining : public MethodPass {
// DoMethodInlining - Use a heuristic based approach to inline methods that
// seem to look good.
//
static bool doMethodInlining(Method *M);
- virtual bool doPerMethodWork(Method *M) {
+ virtual bool runOnMethod(Method *M) {
return doMethodInlining(M);
}
};
diff --git a/include/llvm/Transforms/HoistPHIConstants.h b/include/llvm/Transforms/HoistPHIConstants.h
index 65bae751a8..27bf7ab021 100644
--- a/include/llvm/Transforms/HoistPHIConstants.h
+++ b/include/llvm/Transforms/HoistPHIConstants.h
@@ -11,12 +11,12 @@
#include "llvm/Pass.h"
-struct HoistPHIConstants : public Pass {
+struct HoistPHIConstants : public MethodPass {
// doHoistPHIConstants - Hoist constants out of PHI instructions
//
static bool doHoistPHIConstants(Method *M);
- virtual bool doPerMethodWork(Method *M) { return doHoistPHIConstants(M); }
+ virtual bool runOnMethod(Method *M) { return doHoistPHIConstants(M); }
};
#endif
diff --git a/include/llvm/Transforms/IPO.h b/include/llvm/Transforms/IPO.h
index 99ff169a1a..6bdba2241d 100644
--- a/include/llvm/Transforms/IPO.h
+++ b/include/llvm/Transforms/IPO.h
@@ -8,7 +8,7 @@
#include "llvm/Analysis/FindUsedTypes.h"
-class CleanupGCCOutput : public Pass {
+class CleanupGCCOutput : public MethodPass {
Method *Malloc, *Free; // Pointers to external declarations, or null if none
FindUsedTypes FUT; // Use FUT to eliminate type names that are never used
public:
@@ -27,14 +27,14 @@ public:
//
// Also, initialize instance variables.
//
- bool doPassInitialization(Module *M);
+ bool doInitialization(Module *M);
// doPerMethodWork - This method simplifies the specified method hopefully.
//
- bool doPerMethodWork(Method *M);
+ bool runOnMethod(Method *M);
// doPassFinalization - Strip out type names that are unused by the program
- bool doPassFinalization(Module *M);
+ bool doFinalization(Module *M);
private:
bool doOneCleanupPass(Method *M);
};
diff --git a/include/llvm/Transforms/IPO/ConstantMerge.h b/include/llvm/Transforms/IPO/ConstantMerge.h
index 37d830ccf8..54f699a811 100644
--- a/include/llvm/Transforms/IPO/ConstantMerge.h
+++ b/include/llvm/Transforms/IPO/ConstantMerge.h
@@ -22,7 +22,8 @@
class Constant;
class GlobalVariable;
-class ConstantMerge : public Pass {
+// FIXME: ConstantMerge should not be a methodPass!!!
+class ConstantMerge : public MethodPass {
protected:
std::map<Constant*, GlobalVariable*> Constants;
unsigned LastConstantSeen;
@@ -34,14 +35,16 @@ public:
//
static bool mergeDuplicateConstants(Module *M);
- // doPassInitialization - For this pass, process all of the globals in the
+ // doInitialization - For this pass, process all of the globals in the
// module, eliminating duplicate constants.
//
- bool doPassInitialization(Module *M);
+ bool doInitialization(Module *M);
- // doPassFinalization - Clean up internal state for this module
+ bool runOnMethod(Method*) { return false; }
+
+ // doFinalization - Clean up internal state for this module
//
- bool doPassFinalization(Module *M) {
+ bool doFinalization(Module *M) {
LastConstantSeen = 0;
Constants.clear();
return false;
@@ -52,7 +55,7 @@ struct DynamicConstantMerge : public ConstantMerge {
// doPerMethodWork - Check to see if any globals have been added to the
// global list for the module. If so, eliminate them.
//
- bool doPerMethodWork(Method *M);
+ bool runOnMethod(Method *M);
};
#endif
diff --git a/include/llvm/Transforms/IPO/GlobalDCE.h b/include/llvm/Transforms/IPO/GlobalDCE.h
index 5491751b54..c4c74470de 100644
--- a/include/llvm/Transforms/IPO/GlobalDCE.h
+++ b/include/llvm/Transforms/IPO/GlobalDCE.h
@@ -7,15 +7,17 @@
#ifndef LLVM_TRANSFORM_IPO_GLOBALDCE_H
#define LLVM_TRANSFORM_IPO_GLOBALDCE_H
+#include "llvm/Pass.h"
+
namespace cfg { class CallGraph; }
class Module;
-struct GlobalDCE {
+struct GlobalDCE : public Pass {
// run - Do the GlobalDCE pass on the specified module, optionally updating
// the specified callgraph to reflect the changes.
//
- bool run(Module *M, cfg::CallGraph *CG = 0);
+ bool run(Module *M);
};
#endif
diff --git a/include/llvm/Transforms/IPO/SimpleStructMutation.h b/include/llvm/Transforms/IPO/SimpleStructMutation.h
index 77b962b107..181996d45b 100644
--- a/include/llvm/Transforms/IPO/SimpleStructMutation.h
+++ b/include/llvm/Transforms/IPO/SimpleStructMutation.h
@@ -1,22 +1,27 @@
-//===- llvm/Transforms/SwapStructContents.h - Permute Structs ----*- C++ -*--=//
+//===- llvm/Transforms/SimpleStructMutation.h - Permute Structs --*- C++ -*--=//
//
-// This pass does a simple transformation that swaps all of the elements of the
-// struct types in the program around.
+// This pass does is a wrapper that can do a few simple structure mutation
+// transformations.
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_TRANSFORMS_SWAPSTRUCTCONTENTS_H
-#define LLVM_TRANSFORMS_SWAPSTRUCTCONTENTS_H
+#ifndef LLVM_TRANSFORMS_SIMPLESTRUCTMUTATION_H
+#define LLVM_TRANSFORMS_SIMPLESTRUCTMUTATION_H
#include "llvm/Transforms/MutateStructTypes.h"
-// FIXME: Move to correct location!
-class PrebuiltStructMutation : public MutateStructTypes {
+class SimpleStructMutation : public MutateStructTypes {
public:
- enum Transform { SwapElements, SortElements };
+ enum Transform { SwapElements, SortElements } CurrentXForm;
- PrebuiltStructMutation(Module *M, enum Transform XForm)
- : MutateStructTypes(getTransforms(M, XForm)) {}
+ SimpleStructMutation(enum Transform XForm) : CurrentXForm(XForm) {}
+
+ virtual bool run(Module *M) {
+ setTransforms(getTransforms(M, CurrentXForm));
+ bool Changed = MutateStructTypes::run(M);
+ clearTransforms();
+ return Changed;
+ }
private:
static TransformsType getTransforms(Module *M, enum Transform);
diff --git a/include/llvm/Transforms/Instrumentation/TraceValues.h b/include/llvm/Transforms/Instrumentation/TraceValues.h
index 13847161f1..996db1747e 100644
--- a/include/llvm/Transforms/Instrumentation/TraceValues.h
+++ b/include/llvm/Transforms/Instrumentation/TraceValues.h
@@ -11,7 +11,7 @@
#include "llvm/Pass.h"
class Method;
-class InsertTraceCode : public Pass {
+class InsertTraceCode : public MethodPass {
bool TraceBasicBlockExits, TraceMethodExits;
Method *PrintfMeth;
public:
@@ -21,7 +21,7 @@ public:
// Add a prototype for printf if it is not already in the program.
//
- bool doPassInitialization(Module *M);
+ bool doInitialization(Module *M);
//--------------------------------------------------------------------------
// Function InsertCodeToTraceValues
@@ -32,9 +32,9 @@ public:
static bool doit(Method *M, bool traceBasicBlockExits,
bool traceMethodExits, Method *Printf);
- // doPerMethodWork - This method does the work. Always successful.
+ // runOnMethod - This method does the work. Always successful.
//
- bool doPerMethodWork(Method *M) {
+ bool runOnMethod(Method *M) {
return doit(M, TraceBasicBlockExits, TraceMethodExits, PrintfMeth);
}
};
diff --git a/include/llvm/Transforms/MutateStructTypes.h b/include/llvm/Transforms/MutateStructTypes.h
index 23bf71c3b1..390168f645 100644
--- a/include/llvm/Transforms/MutateStructTypes.h
+++ b/include/llvm/Transforms/MutateStructTypes.h
@@ -51,25 +51,40 @@ public:
//
typedef std::map<const StructType*, std::vector<int> > TransformsType;
- MutateStructTypes(const TransformsType &Transforms);
+ MutateStructTypes(const TransformsType &Transforms) {
+ setTransforms(Transforms);
+ }
+ // run - do the transformation
+ virtual bool run(Module *M);
- // doPassInitialization - This loops over global constants defined in the
+protected:
+
+ // Alternatively, it is valid to subclass this class and provide transforms
+ // this way. See SimpleStructMutation for an example.
+ //
+ MutateStructTypes() {}
+ void setTransforms(const TransformsType &Transforms);
+ void clearTransforms();
+
+private:
+
+ // processGlobals - This loops over global constants defined in the
// module, converting them to their new type. Also this creates placeholder
// methods for methods than need to be copied because they have a new
// signature type.
//
- bool doPassInitialization(Module *M);
+ void processGlobals(Module *M);
- // doPerMethodWork - This transforms the instructions of the method to use the
+ // transformMethod - This transforms the instructions of the method to use the
// new types.
//
- bool doPerMethodWork(Method *M);
+ void transformMethod(Method *M);
- // doPassFinalization - This removes the old versions of methods that are no
+ // removeDeadGlobals - This removes the old versions of methods that are no
// longer needed.
//
- virtual bool doPassFinalization(Module *M);
+ void removeDeadGlobals(Module *M);
private:
// ConvertType - Convert from the old type system to the new one...
diff --git a/include/llvm/Transforms/RaisePointerReferences.h b/include/llvm/Transforms/RaisePointerReferences.h
index 593ccf2496..b652f33712 100644
--- a/include/llvm/Transforms/RaisePointerReferences.h
+++ b/include/llvm/Transforms/RaisePointerReferences.h
@@ -15,10 +15,10 @@
// expressions as possible, by converting expressions to use getelementptr and
// friends.
//
-struct RaisePointerReferences : public Pass {
+struct RaisePointerReferences : public MethodPass {
static bool doit(Method *M);
- virtual bool doPerMethodWork(Method *M) { return doit(M); }
+ virtual bool runOnMethod(Method *M) { return doit(M); }
};
@@ -26,10 +26,10 @@ struct RaisePointerReferences : public Pass {
// converts all induction variables to reference a cannonical induction
// variable (which starts at 0 and counts by 1).
//
-struct EliminateAuxillaryInductionVariables : public Pass {
+struct EliminateAuxillaryInductionVariables : public MethodPass {
static bool doit(Method *M) { return false; } // TODO!
- virtual bool doPerMethodWork(Method *M) { return doit(M); }
+ virtual bool runOnMethod(Method *M) { return doit(M); }
};
#endif
diff --git a/include/llvm/Transforms/Scalar/ConstantProp.h b/include/llvm/Transforms/Scalar/ConstantProp.h
index e77a9c0600..f4418665f9 100644
--- a/include/llvm/Transforms/Scalar/ConstantProp.h
+++ b/include/llvm/Transforms/Scalar/ConstantProp.h
@@ -12,7 +12,7 @@ class TerminatorInst;
namespace opt {
-struct ConstantPropogation : public Pass {
+struct ConstantPropogation : public MethodPass {
// doConstantPropogation - Do trivial constant propogation and expression
// folding
static bool doConstantPropogation(Method *M);
@@ -22,7 +22,7 @@ struct ConstantPropogation : public Pass {
//
static bool doConstantPropogation(BasicBlock *BB, BasicBlock::iterator &I);
- inline bool doPerMethodWork(Method *M) {
+ inline bool runOnMethod(Method *M) {
return doConstantPropogation(M);
}
};
@@ -39,10 +39,10 @@ bool ConstantFoldTerminator(TerminatorInst *T);
//===----------------------------------------------------------------------===//
// Sparse Conditional Constant Propogation Pass
//
-struct SCCPPass : public Pass {
+struct SCCPPass : public MethodPass {
static bool doSCCP(Method *M);
- inline bool doPerMethodWork(Method *M) {
+ inline bool runOnMethod(Method *M) {
return doSCCP(M);
}
};
diff --git a/include/llvm/Transforms/Scalar/DCE.h b/include/llvm/Transforms/Scalar/DCE.h
index 86943ebd85..0e9c620548 100644
--- a/include/llvm/Transforms/Scalar/DCE.h
+++ b/include/llvm/Transforms/Scalar/DCE.h
@@ -13,7 +13,7 @@
namespace opt {
-struct DeadCodeElimination : public Pass {
+struct DeadCodeElimination : public MethodPass {
// External Interface:
//
static bool doDCE(Method *M);
@@ -33,23 +33,23 @@ struct DeadCodeElimination : public Pass {
static bool RemoveUnusedGlobalValues(Module *M);
// Pass Interface...
- virtual bool doPassInitialization(Module *M) {
+ virtual bool doInitialization(Module *M) {
return RemoveUnusedGlobalValues(M);
}
- virtual bool doPerMethodWork(Method *M) { return doDCE(M); }
- virtual bool doPassFinalization(Module *M) {
+ virtual bool runOnMethod(Method *M) { return doDCE(M); }
+ virtual bool doFinalization(Module *M) {
return RemoveUnusedGlobalValues(M);
}
};
-struct AgressiveDCE : public Pass {
+struct AgressiveDCE : public MethodPass {
// DoADCE - Execute the Agressive Dead Code Elimination Algorithm
//
static bool doADCE(Method *M); // Defined in ADCE.cpp
- virtual bool doPerMethodWork(Method *M) {
+ virtual bool runOnMethod(Method *M) {
return doADCE(M);
}
};
diff --git a/include/llvm/Transforms/Scalar/IndVarSimplify.h b/include/llvm/Transforms/Scalar/IndVarSimplify.h
index 00a43b5ab8..13f811994b 100644
--- a/include/llvm/Transforms/Scalar/IndVarSimplify.h
+++ b/include/llvm/Transforms/Scalar/IndVarSimplify.h
@@ -10,10 +10,10 @@
#include "llvm/Pass.h"
-struct InductionVariableSimplify : public Pass {
+struct InductionVariableSimplify : public MethodPass {
static bool doit(Method *M);
- virtual bool doPerMethodWork(Method *M) { return doit(M); }
+ virtual bool runOnMethod(Method *M) { return doit(M); }
};
#endif
diff --git a/include/llvm/Transforms/Scalar/InductionVars.h b/include/llvm/Transforms/Scalar/InductionVars.h
index 82ec9fcc75..146239d82b 100644
--- a/include/llvm/Transforms/Scalar/InductionVars.h
+++ b/include/llvm/Transforms/Scalar/InductionVars.h
@@ -12,12 +12,12 @@
namespace opt {
-struct InductionVariableCannonicalize : public Pass {
+struct InductionVariableCannonicalize : public MethodPass {
// doInductionVariableCannonicalize - Simplify induction variables in loops
//
static bool doIt(Method *M);
- virtual bool doPerMethodWork(Method *M) {
+ virtual bool runOnMethod(Method *M) {
return doIt(M);
}
};
diff --git a/include/llvm/Transforms/Scalar/InstructionCombining.h b/include/llvm/Transforms/Scalar/InstructionCombining.h
index 09762d1552..c79a1caf4b 100644
--- a/include/llvm/Transforms/Scalar/InstructionCombining.h
+++ b/include/llvm/Transforms/Scalar/InstructionCombining.h
@@ -17,11 +17,11 @@
#include "llvm/Pass.h"
-struct InstructionCombining : public Pass {
+struct InstructionCombining : public MethodPass {
static bool doit(Method *M);
static bool CombineInstruction(Instruction *I);
- virtual bool doPerMethodWork(Method *M) { return doit(M); }
+ virtual bool runOnMethod(Method *M) { return doit(M); }
};
#endif
diff --git a/include/llvm/Transforms/Scalar/SymbolStripping.h b/include/llvm/Transforms/Scalar/SymbolStripping.h
index 1feb4381e9..ff31a4b532 100644
--- a/include/llvm/Transforms/Scalar/SymbolStripping.h
+++ b/include/llvm/Transforms/Scalar/SymbolStripping.h
@@ -12,28 +12,28 @@
namespace opt {
-struct SymbolStripping : public Pass {
+struct SymbolStripping : public MethodPass {
// doSymbolStripping - Remove all symbolic information from a method
//
static bool doSymbolStripping(Method *M);
- virtual bool doPerMethodWork(Method *M) {
+ virtual bool runOnMethod(Method *M) {
return doSymbolStripping(M);
}
};
-struct FullSymbolStripping : public Pass {
+struct FullSymbolStripping : public MethodPass {
// doStripGlobalSymbols - Remove all symbolic information from all methods
// in a module, and all module level symbols. (method names, etc...)
//
static bool doStripGlobalSymbols(Module *M);
- virtual bool doPassInitialization(Module *M) {
+ virtual bool doInitialization(Module *M) {
return doStripGlobalSymbols(M);
}
- virtual bool doPerMethodWork(Method *M) {
+ virtual bool runOnMethod(Method *M) {
return SymbolStripping::doSymbolStripping(M);
}
};