diff options
author | Chris Lattner <sabre@nondot.org> | 2001-10-13 06:58:40 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2001-10-13 06:58:40 +0000 |
commit | dd6dfbc8cc008faca03b6ac9b904f263205a418a (patch) | |
tree | d2e0e64dd6789168260c3b08c42dba87f5d6cac4 /lib/VMCore/Module.cpp | |
parent | b1726accb24ad13419dcbc88beae11dec4733c5a (diff) |
* Add support for Module specific constants
* Add proper support for ConstPoolPointerReference's
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@771 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Module.cpp')
-rw-r--r-- | lib/VMCore/Module.cpp | 59 |
1 files changed, 55 insertions, 4 deletions
diff --git a/lib/VMCore/Module.cpp b/lib/VMCore/Module.cpp index 5fc11d1b10..fbe8586714 100644 --- a/lib/VMCore/Module.cpp +++ b/lib/VMCore/Module.cpp @@ -12,6 +12,7 @@ #include "llvm/ValueHolderImpl.h" #include "llvm/Support/STLExtras.h" #include "llvm/Type.h" +#include <map> // Instantiate Templates - This ugliness is the price we have to pay // for having a DefHolderImpl.h file seperate from DefHolder.h! :( @@ -19,9 +20,16 @@ template class ValueHolder<GlobalVariable, Module, Module>; template class ValueHolder<Method, Module, Module>; +// Define the GlobalValueRefMap as a struct that wraps a map so that we don't +// have Module.h depend on <map> +// +struct GlobalValueRefMap : public map<GlobalValue*, ConstPoolPointerReference*>{ +}; + + Module::Module() : Value(Type::VoidTy, Value::ModuleVal, ""), SymTabValue(this), - GlobalList(this, this), MethodList(this, this) { + GlobalList(this, this), MethodList(this, this), GVRefMap(0) { } Module::~Module() { @@ -42,9 +50,25 @@ Module::~Module() { // delete. // void Module::dropAllReferences() { - MethodListType::iterator MI = MethodList.begin(); - for (; MI != MethodList.end(); ++MI) - (*MI)->dropAllReferences(); + for_each(MethodList.begin(), MethodList.end(), + std::mem_fun(&Method::dropAllReferences)); + + for_each(GlobalList.begin(), GlobalList.end(), + std::mem_fun(&GlobalVariable::dropAllReferences)); + + // If there are any GlobalVariable references still out there, nuke them now. + // Since all references are hereby dropped, nothing could possibly reference + // them still. + if (GVRefMap) { + for (GlobalValueRefMap::iterator I = GVRefMap->begin(), E = GVRefMap->end(); + I != E; ++I) { + // Delete the ConstPoolPointerReference node... + I->second->destroyConstant(); + } + + // Since the table is empty, we can now delete it... + delete GVRefMap; + } } // reduceApply - Apply the specified function to all of the methods in this @@ -63,3 +87,30 @@ bool Module::reduceApply(bool (*Func)(const Method*)) const { return reduce_apply_bool(begin(), end(), Func); } +// Accessor for the underlying GlobalValRefMap... +ConstPoolPointerReference *Module::getConstPoolPointerReference(GlobalValue *V){ + // Create ref map lazily on demand... + if (GVRefMap == 0) GVRefMap = new GlobalValueRefMap(); + + GlobalValueRefMap::iterator I = GVRefMap->find(V); + if (I != GVRefMap->end()) return I->second; + + ConstPoolPointerReference *Ref = new ConstPoolPointerReference(V); + GVRefMap->insert(make_pair(V, Ref)); + + return Ref; +} + +void Module::mutateConstPoolPointerReference(GlobalValue *OldGV, + GlobalValue *NewGV) { + GlobalValueRefMap::iterator I = GVRefMap->find(OldGV); + assert(I != GVRefMap->end() && + "mutateConstPoolPointerReference; OldGV not in table!"); + ConstPoolPointerReference *Ref = I->second; + + // Remove the old entry... + GVRefMap->erase(I); + + // Insert the new entry... + GVRefMap->insert(make_pair(NewGV, Ref)); +} |