mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-28 04:33:05 +00:00
Clean up reference counting to stop "leaking" alias sets
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15099 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
199edde707
commit
b8a31ace2c
@ -62,9 +62,8 @@ class AliasSet {
|
|||||||
if (AS->Forward) {
|
if (AS->Forward) {
|
||||||
AliasSet *OldAS = AS;
|
AliasSet *OldAS = AS;
|
||||||
AS = OldAS->getForwardedTarget(AST);
|
AS = OldAS->getForwardedTarget(AST);
|
||||||
if (--OldAS->RefCount == 0)
|
AS->addRef();
|
||||||
OldAS->removeFromTracker(AST);
|
OldAS->dropRef(AST);
|
||||||
AS->RefCount++;
|
|
||||||
}
|
}
|
||||||
return AS;
|
return AS;
|
||||||
}
|
}
|
||||||
@ -118,6 +117,13 @@ class AliasSet {
|
|||||||
void setPrev(AliasSet *P) { Prev = P; }
|
void setPrev(AliasSet *P) { Prev = P; }
|
||||||
void setNext(AliasSet *N) { Next = N; }
|
void setNext(AliasSet *N) { Next = N; }
|
||||||
|
|
||||||
|
void addRef() { ++RefCount; }
|
||||||
|
void dropRef(AliasSetTracker &AST) {
|
||||||
|
assert(RefCount >= 1 && "Invalid reference count detected!");
|
||||||
|
if (--RefCount == 0)
|
||||||
|
removeFromTracker(AST);
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// Accessors...
|
/// Accessors...
|
||||||
bool isRef() const { return AccessTy & Refs; }
|
bool isRef() const { return AccessTy & Refs; }
|
||||||
@ -187,15 +193,10 @@ private:
|
|||||||
AliasSet() : PtrList(0), PtrListEnd(&PtrList), Forward(0), RefCount(0),
|
AliasSet() : PtrList(0), PtrListEnd(&PtrList), Forward(0), RefCount(0),
|
||||||
AccessTy(NoModRef), AliasTy(MustAlias), Volatile(false) {
|
AccessTy(NoModRef), AliasTy(MustAlias), Volatile(false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
AliasSet(const AliasSet &AS) {
|
AliasSet(const AliasSet &AS) {
|
||||||
// AliasSet's only get copy constructed in simple circumstances. In
|
assert(0 && "Copy ctor called!?!?!");
|
||||||
// particular, they cannot have any pointers in their list. Despite this,
|
abort();
|
||||||
// we have to be sure to update the PtrListEnd to not point to the source
|
|
||||||
// AliasSet's list.
|
|
||||||
assert(AS.PtrList == 0 && "AliasSet has pointers in it!");
|
|
||||||
PtrList = 0; PtrListEnd = &PtrList;
|
|
||||||
Forward = AS.Forward; RefCount = AS.RefCount;
|
|
||||||
AccessTy = AS.AccessTy; AliasTy = AS.AliasTy; Volatile = AS.Volatile;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HashNodePair *getSomePointer() const {
|
HashNodePair *getSomePointer() const {
|
||||||
@ -210,9 +211,8 @@ private:
|
|||||||
|
|
||||||
AliasSet *Dest = Forward->getForwardedTarget(AST);
|
AliasSet *Dest = Forward->getForwardedTarget(AST);
|
||||||
if (Dest != Forward) {
|
if (Dest != Forward) {
|
||||||
Dest->RefCount++;
|
Dest->addRef();
|
||||||
if (--Forward->RefCount == 0)
|
Forward->dropRef(AST);
|
||||||
Forward->removeFromTracker(AST);
|
|
||||||
Forward = Dest;
|
Forward = Dest;
|
||||||
}
|
}
|
||||||
return Dest;
|
return Dest;
|
||||||
|
@ -45,7 +45,7 @@ void AliasSet::mergeSetIn(AliasSet &AS) {
|
|||||||
assert(RefCount != 0);
|
assert(RefCount != 0);
|
||||||
|
|
||||||
AS.Forward = this; // Forward across AS now...
|
AS.Forward = this; // Forward across AS now...
|
||||||
RefCount++; // AS is now pointing to us...
|
addRef(); // AS is now pointing to us...
|
||||||
|
|
||||||
// Merge the list of constituent pointers...
|
// Merge the list of constituent pointers...
|
||||||
if (AS.PtrList) {
|
if (AS.PtrList) {
|
||||||
@ -59,6 +59,10 @@ void AliasSet::mergeSetIn(AliasSet &AS) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AliasSetTracker::removeAliasSet(AliasSet *AS) {
|
void AliasSetTracker::removeAliasSet(AliasSet *AS) {
|
||||||
|
if (AliasSet *Fwd = AS->Forward) {
|
||||||
|
Fwd->dropRef(*this);
|
||||||
|
AS->Forward = 0;
|
||||||
|
}
|
||||||
AliasSets.erase(AS);
|
AliasSets.erase(AS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +95,7 @@ void AliasSet::addPointer(AliasSetTracker &AST, HashNodePair &Entry,
|
|||||||
assert(*PtrListEnd == 0 && "End of list is not null?");
|
assert(*PtrListEnd == 0 && "End of list is not null?");
|
||||||
*PtrListEnd = &Entry;
|
*PtrListEnd = &Entry;
|
||||||
PtrListEnd = Entry.second.setPrevInList(PtrListEnd);
|
PtrListEnd = Entry.second.setPrevInList(PtrListEnd);
|
||||||
RefCount++; // Entry points to alias set...
|
addRef(); // Entry points to alias set...
|
||||||
}
|
}
|
||||||
|
|
||||||
void AliasSet::addCallSite(CallSite CS, AliasAnalysis &AA) {
|
void AliasSet::addCallSite(CallSite CS, AliasAnalysis &AA) {
|
||||||
@ -130,7 +134,7 @@ bool AliasSet::aliasesPointer(const Value *Ptr, unsigned Size,
|
|||||||
// If this is a may-alias set, we have to check all of the pointers in the set
|
// If this is a may-alias set, we have to check all of the pointers in the set
|
||||||
// to be sure it doesn't alias the set...
|
// to be sure it doesn't alias the set...
|
||||||
for (iterator I = begin(), E = end(); I != E; ++I)
|
for (iterator I = begin(), E = end(); I != E; ++I)
|
||||||
if (AA.alias(Ptr, Size, I->first, I->second.getSize()))
|
if (AA.alias(Ptr, Size, I.getPointer(), I.getSize()))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Check the call sites list and invoke list...
|
// Check the call sites list and invoke list...
|
||||||
@ -204,7 +208,7 @@ AliasSet &AliasSetTracker::getAliasSetForPointer(Value *Pointer, unsigned Size,
|
|||||||
} else {
|
} else {
|
||||||
if (New) *New = true;
|
if (New) *New = true;
|
||||||
// Otherwise create a new alias set to hold the loaded pointer...
|
// Otherwise create a new alias set to hold the loaded pointer...
|
||||||
AliasSets.push_back(AliasSet());
|
AliasSets.push_back(new AliasSet());
|
||||||
AliasSets.back().addPointer(*this, Entry, Size);
|
AliasSets.back().addPointer(*this, Entry, Size);
|
||||||
return AliasSets.back();
|
return AliasSets.back();
|
||||||
}
|
}
|
||||||
@ -238,7 +242,7 @@ bool AliasSetTracker::add(CallSite CS) {
|
|||||||
|
|
||||||
AliasSet *AS = findAliasSetForCallSite(CS);
|
AliasSet *AS = findAliasSetForCallSite(CS);
|
||||||
if (!AS) {
|
if (!AS) {
|
||||||
AliasSets.push_back(AliasSet());
|
AliasSets.push_back(new AliasSet());
|
||||||
AS = &AliasSets.back();
|
AS = &AliasSets.back();
|
||||||
AS->addCallSite(CS, AA);
|
AS->addCallSite(CS, AA);
|
||||||
return true;
|
return true;
|
||||||
@ -285,7 +289,7 @@ void AliasSetTracker::add(const AliasSetTracker &AST) {
|
|||||||
AliasSet::iterator I = AS.begin(), E = AS.end();
|
AliasSet::iterator I = AS.begin(), E = AS.end();
|
||||||
bool X;
|
bool X;
|
||||||
for (; I != E; ++I)
|
for (; I != E; ++I)
|
||||||
addPointer(I->first, I->second.getSize(),
|
addPointer(I.getPointer(), I.getSize(),
|
||||||
(AliasSet::AccessType)AS.AccessTy, X);
|
(AliasSet::AccessType)AS.AccessTy, X);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -364,9 +368,7 @@ void AliasSetTracker::deleteValue(Value *PtrVal) {
|
|||||||
// Unlink from the list of values...
|
// Unlink from the list of values...
|
||||||
PtrValEnt.second.removeFromList();
|
PtrValEnt.second.removeFromList();
|
||||||
// Stop using the alias set
|
// Stop using the alias set
|
||||||
if (--AS->RefCount == 0)
|
AS->dropRef(*this);
|
||||||
AS->removeFromTracker(*this);
|
|
||||||
|
|
||||||
PointerMap.erase(I);
|
PointerMap.erase(I);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -394,8 +396,8 @@ void AliasSet::print(std::ostream &OS) const {
|
|||||||
OS << "Pointers: ";
|
OS << "Pointers: ";
|
||||||
for (iterator I = begin(), E = end(); I != E; ++I) {
|
for (iterator I = begin(), E = end(); I != E; ++I) {
|
||||||
if (I != begin()) OS << ", ";
|
if (I != begin()) OS << ", ";
|
||||||
WriteAsOperand(OS << "(", I->first);
|
WriteAsOperand(OS << "(", I.getPointer());
|
||||||
OS << ", " << I->second.getSize() << ")";
|
OS << ", " << I.getSize() << ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!CallSites.empty()) {
|
if (!CallSites.empty()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user