+/// remove - Remove the specified (potentially non-empty) alias set from the
+/// tracker.
+void AliasSetTracker::remove(AliasSet &AS) {
+ // Drop all call sites.
+ AS.CallSites.clear();
+
+ // Clear the alias set.
+ unsigned NumRefs = 0;
+ while (!AS.empty()) {
+ AliasSet::HashNodePair *P = AS.PtrList;
+
+ // Unlink from the list of values.
+ P->second.removeFromList();
+
+ // Remember how many references need to be dropped.
+ ++NumRefs;
+
+ // Finally, remove the entry.
+ Value *Remove = P->first; // Take a copy because it is invalid to pass
+ PointerMap.erase(Remove); // a reference to the data being erased.
+ }
+
+ // Stop using the alias set, removing it.
+ AS.RefCount -= NumRefs;
+ if (AS.RefCount == 0)
+ AS.removeFromTracker(*this);
+}
+
+bool AliasSetTracker::remove(Value *Ptr, unsigned Size) {
+ AliasSet *AS = findAliasSetForPointer(Ptr, Size);
+ if (!AS) return false;
+ remove(*AS);
+ return true;
+}
+
+bool AliasSetTracker::remove(LoadInst *LI) {
+ unsigned Size = AA.getTargetData().getTypeSize(LI->getType());
+ AliasSet *AS = findAliasSetForPointer(LI->getOperand(0), Size);
+ if (!AS) return false;
+ remove(*AS);
+ return true;
+}
+
+bool AliasSetTracker::remove(StoreInst *SI) {
+ unsigned Size = AA.getTargetData().getTypeSize(SI->getOperand(0)->getType());
+ AliasSet *AS = findAliasSetForPointer(SI->getOperand(1), Size);
+ if (!AS) return false;
+ remove(*AS);
+ return true;
+}
+
+bool AliasSetTracker::remove(FreeInst *FI) {
+ AliasSet *AS = findAliasSetForPointer(FI->getOperand(0), ~0);
+ if (!AS) return false;
+ remove(*AS);
+ return true;
+}
+
+bool AliasSetTracker::remove(CallSite CS) {
+ if (Function *F = CS.getCalledFunction())
+ if (AA.doesNotAccessMemory(F))
+ return false; // doesn't alias anything
+
+ AliasSet *AS = findAliasSetForCallSite(CS);
+ if (!AS) return false;
+ remove(*AS);
+ return true;
+}
+
+bool AliasSetTracker::remove(Instruction *I) {
+ // Dispatch to one of the other remove methods...
+ if (LoadInst *LI = dyn_cast<LoadInst>(I))
+ return remove(LI);
+ else if (StoreInst *SI = dyn_cast<StoreInst>(I))
+ return remove(SI);
+ else if (CallInst *CI = dyn_cast<CallInst>(I))
+ return remove(CI);
+ else if (FreeInst *FI = dyn_cast<FreeInst>(I))
+ return remove(FI);
+ return true;
+}