diff options
author | Chris Lattner <sabre@nondot.org> | 2003-12-18 08:11:56 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2003-12-18 08:11:56 +0000 |
commit | 2cffeec014537a5f4d2313a5c21c3aa6fcf33288 (patch) | |
tree | 7ea833c04e386c31b822e7ae698ac94a635f5ada /lib/Analysis/AliasSetTracker.cpp | |
parent | 45ab10cb6ebe1e4b7efc5ee6aecc3ebe24829d70 (diff) |
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
Diffstat (limited to 'lib/Analysis/AliasSetTracker.cpp')
-rw-r--r-- | lib/Analysis/AliasSetTracker.cpp | 44 |
1 files changed, 36 insertions, 8 deletions
diff --git a/lib/Analysis/AliasSetTracker.cpp b/lib/Analysis/AliasSetTracker.cpp index a3d58d90e9..67cef76d57 100644 --- a/lib/Analysis/AliasSetTracker.cpp +++ b/lib/Analysis/AliasSetTracker.cpp @@ -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 //===----------------------------------------------------------------------===// |