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
This commit is contained in:
Chris Lattner
2002-02-26 21:46:54 +00:00
parent 3b2541424f
commit bd0ef77cde
32 changed files with 528 additions and 512 deletions

View File

@@ -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);
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);
}
};
}
// 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);
}
// 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(); }