mirror of
https://github.com/RPCS3/llvm.git
synced 2025-03-04 08:37:45 +00:00
- 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
This commit is contained in:
parent
e0fbb497ee
commit
41661fdb2e
@ -441,6 +441,7 @@ void ConstantStruct::destroyConstant() {
|
|||||||
destroyConstantImpl();
|
destroyConstantImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//---- ConstantPointerNull::get() implementation...
|
//---- ConstantPointerNull::get() implementation...
|
||||||
//
|
//
|
||||||
static ValueMap<char, ConstantPointerNull> NullPtrConstants;
|
static ValueMap<char, ConstantPointerNull> NullPtrConstants;
|
||||||
@ -452,6 +453,14 @@ ConstantPointerNull *ConstantPointerNull::get(const PointerType *Ty) {
|
|||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// destroyConstant - Remove the constant from the constant table...
|
||||||
|
//
|
||||||
|
void ConstantPointerNull::destroyConstant() {
|
||||||
|
NullPtrConstants.remove(this);
|
||||||
|
destroyConstantImpl();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//---- ConstantPointerRef::get() implementation...
|
//---- ConstantPointerRef::get() implementation...
|
||||||
//
|
//
|
||||||
ConstantPointerRef *ConstantPointerRef::get(GlobalValue *GV) {
|
ConstantPointerRef *ConstantPointerRef::get(GlobalValue *GV) {
|
||||||
@ -461,6 +470,14 @@ ConstantPointerRef *ConstantPointerRef::get(GlobalValue *GV) {
|
|||||||
return GV->getParent()->getConstantPointerRef(GV);
|
return GV->getParent()->getConstantPointerRef(GV);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// destroyConstant - Remove the constant from the constant table...
|
||||||
|
//
|
||||||
|
void ConstantPointerRef::destroyConstant() {
|
||||||
|
getValue()->getParent()->destroyConstantPointerRef(this);
|
||||||
|
destroyConstantImpl();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//---- ConstantExpr::get() implementations...
|
//---- ConstantExpr::get() implementations...
|
||||||
//
|
//
|
||||||
typedef pair<unsigned, vector<Constant*> > ExprMapKeyType;
|
typedef pair<unsigned, vector<Constant*> > ExprMapKeyType;
|
||||||
|
@ -168,17 +168,13 @@ void Module::dropAllReferences() {
|
|||||||
|
|
||||||
// If there are any GlobalVariable references still out there, nuke them now.
|
// If there are any GlobalVariable references still out there, nuke them now.
|
||||||
// Since all references are hereby dropped, nothing could possibly reference
|
// Since all references are hereby dropped, nothing could possibly reference
|
||||||
// them still.
|
// them still. Note that destroying all of the constant pointer refs will
|
||||||
if (GVRefMap) {
|
// eventually cause the GVRefMap field to be set to null (by
|
||||||
for (GlobalValueRefMap::iterator I = GVRefMap->Map.begin(),
|
// destroyConstantPointerRef, below).
|
||||||
E = GVRefMap->Map.end(); I != E; ++I) {
|
//
|
||||||
|
while (GVRefMap)
|
||||||
// Delete the ConstantPointerRef node...
|
// Delete the ConstantPointerRef node...
|
||||||
I->second->destroyConstant();
|
GVRefMap->Map.begin()->second->destroyConstant();
|
||||||
}
|
|
||||||
|
|
||||||
// Since the table is empty, we can now delete it...
|
|
||||||
delete GVRefMap;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Accessor for the underlying GlobalValRefMap...
|
// Accessor for the underlying GlobalValRefMap...
|
||||||
@ -190,11 +186,21 @@ ConstantPointerRef *Module::getConstantPointerRef(GlobalValue *V){
|
|||||||
if (I != GVRefMap->Map.end()) return I->second;
|
if (I != GVRefMap->Map.end()) return I->second;
|
||||||
|
|
||||||
ConstantPointerRef *Ref = new ConstantPointerRef(V);
|
ConstantPointerRef *Ref = new ConstantPointerRef(V);
|
||||||
GVRefMap->Map.insert(std::make_pair(V, Ref));
|
GVRefMap->Map[V] = Ref;
|
||||||
|
|
||||||
return 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) {
|
void Module::mutateConstantPointerRef(GlobalValue *OldGV, GlobalValue *NewGV) {
|
||||||
GlobalValueRefMap::iterator I = GVRefMap->Map.find(OldGV);
|
GlobalValueRefMap::iterator I = GVRefMap->Map.find(OldGV);
|
||||||
assert(I != GVRefMap->Map.end() &&
|
assert(I != GVRefMap->Map.end() &&
|
||||||
|
Loading…
x
Reference in New Issue
Block a user