diff options
author | Chris Lattner <sabre@nondot.org> | 2002-02-26 21:46:54 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2002-02-26 21:46:54 +0000 |
commit | bd0ef77cde9c9e82f2b4ad33e4982c46274d6540 (patch) | |
tree | 0903b61112c9e6d336c8b623e235ede2f937f13c /lib/Transforms/IPO/ConstantMerge.cpp | |
parent | 3b2541424f771ae11c30675ce06da7b380780028 (diff) |
Change over to use new style pass mechanism, now passes only expose small
creation functions in their public header file, unless they can help it.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1816 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/IPO/ConstantMerge.cpp')
-rw-r--r-- | lib/Transforms/IPO/ConstantMerge.cpp | 61 |
1 files changed, 39 insertions, 22 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(); } |