diff options
author | Chris Lattner <sabre@nondot.org> | 2002-08-18 00:40:04 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2002-08-18 00:40:04 +0000 |
commit | 41661fdb2e963610b399c8ebe51a507847ef997d (patch) | |
tree | d8a229641bb70cd6467beb3b7ee640ad542f247a /lib/VMCore/Module.cpp | |
parent | e0fbb497ee44f86ec108e4ff8787a848c6ee8655 (diff) |
- ConstantPointerRefs are now automatically removed from the module table
when they are destroyed, which makes Constant::destroyConstant an actually
useful external interface. Expose these methods publicly.
- Implement destroyConstant on ConstPointerNull so that destroyConstant can
be used on any derived type constant safely.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3379 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Module.cpp')
-rw-r--r-- | lib/VMCore/Module.cpp | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/lib/VMCore/Module.cpp b/lib/VMCore/Module.cpp index 990774ab95..a895929280 100644 --- a/lib/VMCore/Module.cpp +++ b/lib/VMCore/Module.cpp @@ -168,17 +168,13 @@ void Module::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->Map.begin(), - E = GVRefMap->Map.end(); I != E; ++I) { - // Delete the ConstantPointerRef node... - I->second->destroyConstant(); - } - - // Since the table is empty, we can now delete it... - delete GVRefMap; - } + // them still. Note that destroying all of the constant pointer refs will + // eventually cause the GVRefMap field to be set to null (by + // destroyConstantPointerRef, below). + // + while (GVRefMap) + // Delete the ConstantPointerRef node... + GVRefMap->Map.begin()->second->destroyConstant(); } // Accessor for the underlying GlobalValRefMap... @@ -190,11 +186,21 @@ ConstantPointerRef *Module::getConstantPointerRef(GlobalValue *V){ if (I != GVRefMap->Map.end()) return I->second; ConstantPointerRef *Ref = new ConstantPointerRef(V); - GVRefMap->Map.insert(std::make_pair(V, Ref)); - + GVRefMap->Map[V] = Ref; return Ref; } +void Module::destroyConstantPointerRef(ConstantPointerRef *CPR) { + assert(GVRefMap && "No map allocated, but we have a CPR?"); + if (!GVRefMap->Map.erase(CPR->getValue())) // Remove it from the map... + assert(0 && "ConstantPointerRef not found in module CPR map!"); + + if (GVRefMap->Map.empty()) { // If the map is empty, delete it. + delete GVRefMap; + GVRefMap = 0; + } +} + void Module::mutateConstantPointerRef(GlobalValue *OldGV, GlobalValue *NewGV) { GlobalValueRefMap::iterator I = GVRefMap->Map.find(OldGV); assert(I != GVRefMap->Map.end() && |