Add a new AliassetTracker::remove method. Because we need to be able to remove

a pointer from an AliasSet, maintain the pointer values on a doubly linked
list instead of a singly linked list, to permit efficient removal from the
middle of the list.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10506 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2003-12-18 08:11:56 +00:00
parent 45ab10cb6e
commit 2cffeec014
2 changed files with 69 additions and 17 deletions

View File

@ -47,9 +47,14 @@ void AliasSet::mergeSetIn(AliasSet &AS) {
RefCount++; // AS is now pointing to us...
// Merge the list of constituent pointers...
PtrListTail->second.setTail(AS.PtrListHead);
PtrListTail = AS.PtrListTail;
AS.PtrListHead = AS.PtrListTail = 0;
if (AS.PtrList) {
*PtrListEnd = AS.PtrList;
AS.PtrList->second.setPrevInList(PtrListEnd);
PtrListEnd = AS.PtrListEnd;
AS.PtrList = 0;
AS.PtrListEnd = &AS.PtrList;
}
}
void AliasSetTracker::removeAliasSet(AliasSet *AS) {
@ -82,11 +87,9 @@ void AliasSet::addPointer(AliasSetTracker &AST, HashNodePair &Entry,
Entry.second.updateSize(Size);
// Add it to the end of the list...
if (PtrListTail)
PtrListTail->second.setTail(&Entry);
else
PtrListHead = &Entry;
PtrListTail = &Entry;
assert(*PtrListEnd == 0 && "End of list is not null?");
*PtrListEnd = &Entry;
PtrListEnd = Entry.second.setPrevInList(PtrListEnd);
RefCount++; // Entry points to alias set...
}
@ -253,6 +256,31 @@ void AliasSetTracker::add(const AliasSetTracker &AST) {
}
}
// remove method - This method is used to remove a pointer value from the
// AliasSetTracker entirely. It should be used when an instruction is deleted
// from the program to update the AST. If you don't use this, you would have
// dangling pointers to deleted instructions.
//
void AliasSetTracker::remove(Value *PtrVal) {
// First, look up the PointerRec for this pointer...
hash_map<Value*, AliasSet::PointerRec>::iterator I = PointerMap.find(PtrVal);
if (I == PointerMap.end()) return; // Noop
// If we found one, remove the pointer from the alias set it is in.
AliasSet::HashNodePair &PtrValEnt = *I;
AliasSet *AS = PtrValEnt.second.getAliasSet(*this);
// Unlink from the list of values...
PtrValEnt.second.removeFromList();
// Stop using the alias set
if (--AS->RefCount == 0)
AS->removeFromTracker(*this);
PointerMap.erase(I);
}
//===----------------------------------------------------------------------===//
// AliasSet/AliasSetTracker Printing Support
//===----------------------------------------------------------------------===//