+ bool X;
+ for (; I != E; ++I) {
+ AliasSet &NewAS = addPointer(I.getPointer(), I.getSize(),
+ (AliasSet::AccessType)AS.AccessTy, X);
+ if (AS.isVolatile()) NewAS.setVolatile();
+ }
+ }
+}
+
+/// 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;
+}
+
+
+// deleteValue 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::deleteValue(Value *PtrVal) {
+ // Notify the alias analysis implementation that this value is gone.
+ AA.deleteValue(PtrVal);
+
+ // If this is a call instruction, remove the callsite from the appropriate
+ // AliasSet.
+ CallSite CS = CallSite::get(PtrVal);
+ if (CS.getInstruction()) {
+ Function *F = CS.getCalledFunction();
+ if (!F || !AA.doesNotAccessMemory(F)) {
+ if (AliasSet *AS = findAliasSetForCallSite(CS))
+ AS->removeCallSite(CS);