diff options
Diffstat (limited to 'lib/Transforms/IPO')
-rw-r--r-- | lib/Transforms/IPO/ConstantMerge.cpp | 61 | ||||
-rw-r--r-- | lib/Transforms/IPO/DeadTypeElimination.cpp | 44 | ||||
-rw-r--r-- | lib/Transforms/IPO/GlobalDCE.cpp | 36 | ||||
-rw-r--r-- | lib/Transforms/IPO/InlineSimple.cpp | 16 | ||||
-rw-r--r-- | lib/Transforms/IPO/SimpleStructMutation.cpp | 47 |
5 files changed, 150 insertions, 54 deletions
diff --git a/lib/Transforms/IPO/ConstantMerge.cpp b/lib/Transforms/IPO/ConstantMerge.cpp index 0951c731e1..d78d185e8a 100644 --- a/lib/Transforms/IPO/ConstantMerge.cpp +++ b/lib/Transforms/IPO/ConstantMerge.cpp @@ -18,6 +18,7 @@ #include "llvm/GlobalVariable.h" #include "llvm/Module.h" #include "llvm/Method.h" +#include "llvm/Pass.h" // mergeDuplicateConstants - Workhorse for the pass. This eliminates duplicate // constants, starting at global ConstantNo, and adds vars to the map if they @@ -56,27 +57,43 @@ bool mergeDuplicateConstants(Module *M, unsigned &ConstantNo, return MadeChanges; } - -// mergeDuplicateConstants - Static accessor for clients that don't want to -// deal with passes. -// -bool ConstantMerge::mergeDuplicateConstants(Module *M) { - std::map<Constant*, GlobalVariable*> Constants; - unsigned LastConstantSeen = 0; - return ::mergeDuplicateConstants(M, LastConstantSeen, Constants); -} - - -// doInitialization - For this pass, process all of the globals in the -// module, eliminating duplicate constants. -// -bool ConstantMerge::doInitialization(Module *M) { - return ::mergeDuplicateConstants(M, LastConstantSeen, Constants); +namespace { + // FIXME: ConstantMerge should not be a methodPass!!! + class ConstantMerge : public MethodPass { + protected: + std::map<Constant*, GlobalVariable*> Constants; + unsigned LastConstantSeen; + public: + inline ConstantMerge() : LastConstantSeen(0) {} + + // doInitialization - For this pass, process all of the globals in the + // module, eliminating duplicate constants. + // + bool doInitialization(Module *M) { + return ::mergeDuplicateConstants(M, LastConstantSeen, Constants); + } + + bool runOnMethod(Method*) { return false; } + + // doFinalization - Clean up internal state for this module + // + bool doFinalization(Module *M) { + LastConstantSeen = 0; + Constants.clear(); + return false; + } + }; + + 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 runOnMethod(Method *M) { + return ::mergeDuplicateConstants(M->getParent(), LastConstantSeen, + Constants); + } + }; } -// doPerMethodWork - Check to see if any globals have been added to the -// global list for the module. If so, eliminate them. -// -bool DynamicConstantMerge::runOnMethod(Method *M) { - return ::mergeDuplicateConstants(M->getParent(), LastConstantSeen, Constants); -} +Pass *createConstantMergePass() { return new ConstantMerge(); } +Pass *createDynamicConstantMergePass() { return new DynamicConstantMerge(); } diff --git a/lib/Transforms/IPO/DeadTypeElimination.cpp b/lib/Transforms/IPO/DeadTypeElimination.cpp index 09d8db4eb8..801cdffb7e 100644 --- a/lib/Transforms/IPO/DeadTypeElimination.cpp +++ b/lib/Transforms/IPO/DeadTypeElimination.cpp @@ -23,6 +23,7 @@ #include "llvm/iTerminators.h" #include "llvm/iOther.h" #include "llvm/Support/CFG.h" +#include "llvm/Pass.h" #include <algorithm> #include <iostream> using std::vector; @@ -31,6 +32,36 @@ using std::cerr; static const Type *PtrSByte = 0; // 'sbyte*' type +namespace { + struct CleanupGCCOutput : public MethodPass { + // doPassInitialization - For this pass, it removes global symbol table + // entries for primitive types. These are never used for linking in GCC and + // they make the output uglier to look at, so we nuke them. + // + // Also, initialize instance variables. + // + bool doInitialization(Module *M); + + // doPerMethodWork - This method simplifies the specified method hopefully. + // + bool runOnMethod(Method *M); + + // doPassFinalization - Strip out type names that are unused by the program + bool doFinalization(Module *M); + + // getAnalysisUsageInfo - This function needs FindUsedTypes to do its job... + // + virtual void getAnalysisUsageInfo(Pass::AnalysisSet &Required, + Pass::AnalysisSet &Destroyed, + Pass::AnalysisSet &Provided) { + // FIXME: Invalidates the CFG + Required.push_back(FindUsedTypes::ID); + } + }; +} + + + // ConvertCallTo - Convert a call to a varargs function with no arg types // specified to a concrete nonvarargs method. // @@ -79,7 +110,7 @@ static void ConvertCallTo(CallInst *CI, Method *Dest) { // because of the way things are declared in C. If this is the case, patch // things up. // -bool CleanupGCCOutput::PatchUpMethodReferences(Module *M) { +static bool PatchUpMethodReferences(Module *M) { SymbolTable *ST = M->getSymbolTable(); if (!ST) return false; @@ -545,12 +576,7 @@ bool CleanupGCCOutput::doFinalization(Module *M) { return Changed; } -// getAnalysisUsageInfo - This function needs the results of the -// FindUsedTypes and FindUnsafePointerTypes analysis passes... -// -void CleanupGCCOutput::getAnalysisUsageInfo(Pass::AnalysisSet &Required, - Pass::AnalysisSet &Destroyed, - Pass::AnalysisSet &Provided) { - // FIXME: Invalidates the CFG - Required.push_back(FindUsedTypes::ID); +Pass *createCleanupGCCOutputPass() { + return new CleanupGCCOutput(); } + diff --git a/lib/Transforms/IPO/GlobalDCE.cpp b/lib/Transforms/IPO/GlobalDCE.cpp index 1b64a0b369..454f6014e6 100644 --- a/lib/Transforms/IPO/GlobalDCE.cpp +++ b/lib/Transforms/IPO/GlobalDCE.cpp @@ -8,6 +8,7 @@ #include "llvm/Analysis/CallGraph.h" #include "llvm/Module.h" #include "llvm/Method.h" +#include "llvm/Pass.h" #include "Support/DepthFirstIterator.h" #include <set> @@ -45,18 +46,27 @@ static bool RemoveUnreachableMethods(Module *M, cfg::CallGraph &CallGraph) { return true; } -bool GlobalDCE::run(Module *M) { - return RemoveUnreachableMethods(M, getAnalysis<cfg::CallGraph>()); -} +namespace { + 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) { + return RemoveUnreachableMethods(M, getAnalysis<cfg::CallGraph>()); + } -// getAnalysisUsageInfo - This function works on the call graph of a module. -// It is capable of updating the call graph to reflect the new state of the -// module. -// -void GlobalDCE::getAnalysisUsageInfo(Pass::AnalysisSet &Required, - Pass::AnalysisSet &Destroyed, - Pass::AnalysisSet &Provided) { - Required.push_back(cfg::CallGraph::ID); - // FIXME: This should update the callgraph, not destroy it! - Destroyed.push_back(cfg::CallGraph::ID); + // getAnalysisUsageInfo - This function works on the call graph of a module. + // It is capable of updating the call graph to reflect the new state of the + // module. + // + virtual void getAnalysisUsageInfo(Pass::AnalysisSet &Required, + Pass::AnalysisSet &Destroyed, + Pass::AnalysisSet &Provided) { + Required.push_back(cfg::CallGraph::ID); + // FIXME: This should update the callgraph, not destroy it! + Destroyed.push_back(cfg::CallGraph::ID); + } + }; } + +Pass *createGlobalDCEPass() { return new GlobalDCE(); } diff --git a/lib/Transforms/IPO/InlineSimple.cpp b/lib/Transforms/IPO/InlineSimple.cpp index d4c23a9208..9ca23f7448 100644 --- a/lib/Transforms/IPO/InlineSimple.cpp +++ b/lib/Transforms/IPO/InlineSimple.cpp @@ -21,6 +21,7 @@ #include "llvm/Transforms/MethodInlining.h" #include "llvm/Module.h" #include "llvm/Method.h" +#include "llvm/Pass.h" #include "llvm/iTerminators.h" #include "llvm/iPHINode.h" #include "llvm/iOther.h" @@ -249,7 +250,10 @@ static inline bool DoMethodInlining(BasicBlock *BB) { return false; } -bool MethodInlining::doMethodInlining(Method *M) { +// doMethodInlining - Use a heuristic based approach to inline methods that +// seem to look good. +// +static bool doMethodInlining(Method *M) { bool Changed = false; // Loop through now and inline instructions a basic block at a time... @@ -264,3 +268,13 @@ bool MethodInlining::doMethodInlining(Method *M) { return Changed; } + +namespace { + struct MethodInlining : public MethodPass { + virtual bool runOnMethod(Method *M) { + return doMethodInlining(M); + } + }; +} + +Pass *createMethodInliningPass() { return new MethodInlining(); } diff --git a/lib/Transforms/IPO/SimpleStructMutation.cpp b/lib/Transforms/IPO/SimpleStructMutation.cpp index 8583e3e850..168f839736 100644 --- a/lib/Transforms/IPO/SimpleStructMutation.cpp +++ b/lib/Transforms/IPO/SimpleStructMutation.cpp @@ -19,6 +19,37 @@ using std::pair; #include "llvm/Assembly/Writer.h" +namespace { + class SimpleStructMutation : public MutateStructTypes { + public: + enum Transform { SwapElements, SortElements } CurrentXForm; + + SimpleStructMutation(enum Transform XForm) : CurrentXForm(XForm) {} + + virtual bool run(Module *M) { + setTransforms(getTransforms(M, CurrentXForm)); + bool Changed = MutateStructTypes::run(M); + clearTransforms(); + return Changed; + } + + // getAnalysisUsageInfo - This function needs the results of the + // FindUsedTypes and FindUnsafePointerTypes analysis passes... + // + virtual void getAnalysisUsageInfo(Pass::AnalysisSet &Required, + Pass::AnalysisSet &Destroyed, + Pass::AnalysisSet &Provided) { + Required.push_back(FindUsedTypes::ID); + Required.push_back(FindUnsafePointerTypes::ID); + MutateStructTypes::getAnalysisUsageInfo(Required, Destroyed, Provided); + } + + private: + TransformsType getTransforms(Module *M, enum Transform); + }; +} // end anonymous namespace + + // PruneTypes - Given a type Ty, make sure that neither it, or one of its // subtypes, occur in TypesToModify. @@ -87,6 +118,7 @@ static inline void GetTransformation(const StructType *ST, } } + SimpleStructMutation::TransformsType SimpleStructMutation::getTransforms(Module *M, enum Transform XForm) { // We need to know which types to modify, and which types we CAN'T modify @@ -137,13 +169,10 @@ SimpleStructMutation::TransformsType } -// getAnalysisUsageInfo - This function needs the results of the -// FindUsedTypes and FindUnsafePointerTypes analysis passes... -// -void SimpleStructMutation::getAnalysisUsageInfo(Pass::AnalysisSet &Required, - Pass::AnalysisSet &Destroyed, - Pass::AnalysisSet &Provided){ - Required.push_back(FindUsedTypes::ID); - Required.push_back(FindUnsafePointerTypes::ID); - MutateStructTypes::getAnalysisUsageInfo(Required, Destroyed, Provided); +Pass *createSwapElementsPass() { + return new SimpleStructMutation(SimpleStructMutation::SwapElements); +} +Pass *createSortElementsPass() { + return new SimpleStructMutation(SimpleStructMutation::SortElements); } + |