diff --git a/llvm/include/llvm/Analysis/AliasSetTracker.h b/llvm/include/llvm/Analysis/AliasSetTracker.h --- a/llvm/include/llvm/Analysis/AliasSetTracker.h +++ b/llvm/include/llvm/Analysis/AliasSetTracker.h @@ -11,6 +11,8 @@ // of disjoint sets. Each AliasSet object constructed by the AliasSetTracker // object refers to memory disjoint from the other sets. // +// An AliasSetTracker can only be used on immutable IR. +// //===----------------------------------------------------------------------===// #ifndef LLVM_ANALYSIS_ALIASSETTRACKER_H @@ -321,28 +323,10 @@ } class AliasSetTracker { - /// A CallbackVH to arrange for AliasSetTracker to be notified whenever a - /// Value is deleted. - class ASTCallbackVH final : public CallbackVH { - AliasSetTracker *AST; - - void deleted() override; - void allUsesReplacedWith(Value *) override; - - public: - ASTCallbackVH(Value *V, AliasSetTracker *AST = nullptr); - - ASTCallbackVH &operator=(Value *V); - }; - /// Traits to tell DenseMap that tell us how to compare and hash the value - /// handle. - struct ASTCallbackVHDenseMapInfo : public DenseMapInfo {}; - AAResults &AA; ilist AliasSets; - using PointerMapType = DenseMap; + using PointerMapType = DenseMap, AliasSet::PointerRec *>; // Map from pointers to their node PointerMapType PointerMap; @@ -390,18 +374,6 @@ /// Return the underlying alias analysis object used by this tracker. AAResults &getAliasAnalysis() const { return AA; } - /// 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 deleteValue(Value *PtrVal); - - /// This method should be used whenever a preexisting value in the program is - /// copied or cloned, introducing a new value. Note that it is ok for clients - /// that use this method to introduce the same value multiple times: if the - /// tracker already knows about a value, it will ignore the request. - void copyValue(Value *From, Value *To); - using iterator = ilist::iterator; using const_iterator = ilist::const_iterator; @@ -429,7 +401,7 @@ /// Just like operator[] on the map, except that it creates an entry for the /// pointer if it doesn't already exist. AliasSet::PointerRec &getEntryFor(Value *V) { - AliasSet::PointerRec *&Entry = PointerMap[ASTCallbackVH(V, this)]; + AliasSet::PointerRec *&Entry = PointerMap[V]; if (!Entry) Entry = new AliasSet::PointerRec(V); return *Entry; diff --git a/llvm/lib/Analysis/AliasSetTracker.cpp b/llvm/lib/Analysis/AliasSetTracker.cpp --- a/llvm/lib/Analysis/AliasSetTracker.cpp +++ b/llvm/lib/Analysis/AliasSetTracker.cpp @@ -509,57 +509,6 @@ } } -// 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) { - // First, look up the PointerRec for this pointer. - PointerMapType::iterator I = PointerMap.find_as(PtrVal); - if (I == PointerMap.end()) return; // Noop - - // If we found one, remove the pointer from the alias set it is in. - AliasSet::PointerRec *PtrValEnt = I->second; - AliasSet *AS = PtrValEnt->getAliasSet(*this); - - // Unlink and delete from the list of values. - PtrValEnt->eraseFromList(); - - if (AS->Alias == AliasSet::SetMayAlias) { - AS->SetSize--; - TotalMayAliasSetSize--; - } - - // Stop using the alias set. - AS->dropRef(*this); - - PointerMap.erase(I); -} - -// copyValue - This method should be used whenever a preexisting value in the -// program is copied or cloned, introducing a new value. Note that it is ok for -// clients that use this method to introduce the same value multiple times: if -// the tracker already knows about a value, it will ignore the request. -// -void AliasSetTracker::copyValue(Value *From, Value *To) { - // First, look up the PointerRec for this pointer. - PointerMapType::iterator I = PointerMap.find_as(From); - if (I == PointerMap.end()) - return; // Noop - assert(I->second->hasAliasSet() && "Dead entry?"); - - AliasSet::PointerRec &Entry = getEntryFor(To); - if (Entry.hasAliasSet()) return; // Already in the tracker! - - // getEntryFor above may invalidate iterator \c I, so reinitialize it. - I = PointerMap.find_as(From); - // Add it to the alias set it aliases... - AliasSet *AS = I->second->getAliasSet(*this); - AS->addPointer(*this, Entry, I->second->getSize(), I->second->getAAInfo(), - true, true); -} - AliasSet &AliasSetTracker::mergeAllAliasSets() { assert(!AliasAnyAS && (TotalMayAliasSetSize > SaturationThreshold) && "Full merge should happen once, when the saturation threshold is " @@ -672,28 +621,6 @@ LLVM_DUMP_METHOD void AliasSetTracker::dump() const { print(dbgs()); } #endif -//===----------------------------------------------------------------------===// -// ASTCallbackVH Class Implementation -//===----------------------------------------------------------------------===// - -void AliasSetTracker::ASTCallbackVH::deleted() { - assert(AST && "ASTCallbackVH called with a null AliasSetTracker!"); - AST->deleteValue(getValPtr()); - // this now dangles! -} - -void AliasSetTracker::ASTCallbackVH::allUsesReplacedWith(Value *V) { - AST->copyValue(getValPtr(), V); -} - -AliasSetTracker::ASTCallbackVH::ASTCallbackVH(Value *V, AliasSetTracker *ast) - : CallbackVH(V), AST(ast) {} - -AliasSetTracker::ASTCallbackVH & -AliasSetTracker::ASTCallbackVH::operator=(Value *V) { - return *this = ASTCallbackVH(V, AST); -} - //===----------------------------------------------------------------------===// // AliasSetPrinter Pass //===----------------------------------------------------------------------===//