[llvm] db5855d - [AST] Restrict AliasSetTracker to immutable IR

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 15 07:28:55 PST 2022


Author: Nikita Popov
Date: 2022-11-15T16:27:28+01:00
New Revision: db5855d0e49c1a220bb7ba1cd61e6101a4a8626f

URL: https://github.com/llvm/llvm-project/commit/db5855d0e49c1a220bb7ba1cd61e6101a4a8626f
DIFF: https://github.com/llvm/llvm-project/commit/db5855d0e49c1a220bb7ba1cd61e6101a4a8626f.diff

LOG: [AST] Restrict AliasSetTracker to immutable IR

This restricts usage of AliasSetTracker to IR that does not change.
We used to use it during LICM where the underlying IR could change,
but remaining uses all use AST as part of a separate analysis phase.

This is split out from D137955, which makes use of the new guarantee
to switch to BatchAA.

Differential Revision: https://reviews.llvm.org/D138014

Added: 
    

Modified: 
    llvm/include/llvm/Analysis/AliasSetTracker.h
    llvm/lib/Analysis/AliasSetTracker.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Analysis/AliasSetTracker.h b/llvm/include/llvm/Analysis/AliasSetTracker.h
index d36807082cfe..15f00a2341a6 100644
--- 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 @@ inline raw_ostream& operator<<(raw_ostream &OS, const AliasSet &AS) {
 }
 
 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<Value *> {};
-
   AAResults &AA;
   ilist<AliasSet> AliasSets;
 
-  using PointerMapType = DenseMap<ASTCallbackVH, AliasSet::PointerRec *,
-                                  ASTCallbackVHDenseMapInfo>;
+  using PointerMapType = DenseMap<AssertingVH<Value>, AliasSet::PointerRec *>;
 
   // Map from pointers to their node
   PointerMapType PointerMap;
@@ -390,18 +374,6 @@ class AliasSetTracker {
   /// 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<AliasSet>::iterator;
   using const_iterator = ilist<AliasSet>::const_iterator;
 
@@ -429,7 +401,7 @@ class AliasSetTracker {
   /// 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
index 24bcb8a2ba02..6523d6a9cde9 100644
--- a/llvm/lib/Analysis/AliasSetTracker.cpp
+++ b/llvm/lib/Analysis/AliasSetTracker.cpp
@@ -509,57 +509,6 @@ void AliasSetTracker::add(const AliasSetTracker &AST) {
   }
 }
 
-// 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 AliasSet::dump() const { print(dbgs()); }
 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
 //===----------------------------------------------------------------------===//


        


More information about the llvm-commits mailing list