[llvm-commits] CVS: llvm/lib/Analysis/AliasSetTracker.cpp

Chris Lattner lattner at cs.uiuc.edu
Thu Dec 18 02:13:01 PST 2003


Changes in directory llvm/lib/Analysis:

AliasSetTracker.cpp updated: 1.9 -> 1.10

---
Log message:

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.


---
Diffs of the changes:  (+36 -8)

Index: llvm/lib/Analysis/AliasSetTracker.cpp
diff -u llvm/lib/Analysis/AliasSetTracker.cpp:1.9 llvm/lib/Analysis/AliasSetTracker.cpp:1.10
--- llvm/lib/Analysis/AliasSetTracker.cpp:1.9	Sat Dec 13 22:52:11 2003
+++ llvm/lib/Analysis/AliasSetTracker.cpp	Thu Dec 18 02:11:56 2003
@@ -47,9 +47,14 @@
   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 @@
   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...
 }
 
@@ -252,6 +255,31 @@
                    (AliasSet::AccessType)AS.AccessTy);
     }
 }
+
+
+// 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





More information about the llvm-commits mailing list