[PATCH] D128824: [SCCP] Add API for AdditionalUsers to the Instruction Visitor.

Alexandros Lamprineas via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 29 07:34:05 PDT 2022


labrinea created this revision.
labrinea added a reviewer: llvm-commits.
Herald added a subscriber: hiraditya.
Herald added a project: All.
labrinea requested review of this revision.
Herald added a project: LLVM.

- Make it possible to remove an Additional User.
- Accumulate the Additional Users in a list.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128824

Files:
  llvm/lib/Transforms/Utils/SCCPSolver.cpp


Index: llvm/lib/Transforms/Utils/SCCPSolver.cpp
===================================================================
--- llvm/lib/Transforms/Utils/SCCPSolver.cpp
+++ llvm/lib/Transforms/Utils/SCCPSolver.cpp
@@ -122,7 +122,8 @@
   DenseSet<Edge> KnownFeasibleEdges;
 
   DenseMap<Function *, AnalysisResultsForFn> AnalysisResults;
-  DenseMap<Value *, SmallPtrSet<User *, 2>> AdditionalUsers;
+  DenseMap<Value *, SmallPtrSet<User *, 8>> AdditionalUsers;
+  DenseMap<User *, SmallPtrSet<Value *, 8>> AdditionalUserOf;
 
   LLVMContext &Ctx;
 
@@ -236,8 +237,8 @@
 
   // Add U as additional user of V.
   void addAdditionalUser(Value *V, User *U) {
-    auto Iter = AdditionalUsers.insert({V, {}});
-    Iter.first->second.insert(U);
+    AdditionalUsers[V].insert(U);
+    AdditionalUserOf[U].insert(V);
   }
 
   // Mark I's users as changed, including AdditionalUsers.
@@ -257,17 +258,10 @@
           operandChangedState(UI);
     }
 
-    auto Iter = AdditionalUsers.find(I);
-    if (Iter != AdditionalUsers.end()) {
-      // Copy additional users before notifying them of changes, because new
-      // users may be added, potentially invalidating the iterator.
-      SmallVector<Instruction *, 2> ToNotify;
-      for (User *U : Iter->second)
-        if (auto *UI = dyn_cast<Instruction>(U))
-          ToNotify.push_back(UI);
-      for (Instruction *UI : ToNotify)
-        operandChangedState(UI);
-    }
+    SmallVector<Instruction *, 8> ToNotify;
+    findAdditionalUsersFor(I, ToNotify);
+    for (Instruction *UI : ToNotify)
+      operandChangedState(UI);
   }
   void handleCallOverdefined(CallBase &CB);
   void handleCallResult(CallBase &CB);
@@ -348,6 +342,36 @@
     return A->second.PredInfo->removePredicateInfoFor(I);
   }
 
+  void removeFromAdditionalUsers(User *U) {
+    auto AUO = AdditionalUserOf.find(U);
+    if (AUO != AdditionalUserOf.end()) {
+      for (Value *V : AUO->second) {
+        auto AU = AdditionalUsers.find(V);
+        if (AU != AdditionalUsers.end())
+          AU->second.erase(U);
+      }
+    }
+  }
+
+  void removeFromAdditionalUserOf(Value *V) {
+    auto AU = AdditionalUsers.find(V);
+    if (AU != AdditionalUsers.end()) {
+      for (User *U : AU->second) {
+        auto AUO = AdditionalUserOf.find(U);
+        if (AUO != AdditionalUserOf.end())
+          AUO->second.erase(V);
+      }
+    }
+  }
+
+  void findAdditionalUsersFor(Value *V, SmallVectorImpl<Instruction *> &Users) {
+    auto Iter = AdditionalUsers.find(V);
+    if (Iter != AdditionalUsers.end())
+      for (User *U : Iter->second)
+        if (auto *I = dyn_cast<Instruction>(U))
+          Users.push_back(I);
+  }
+
   DomTreeUpdater getDTU(Function &F) {
     auto A = AnalysisResults.find(&F);
     assert(A != AnalysisResults.end() && "Need analysis results for function.");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128824.441004.patch
Type: text/x-patch
Size: 2817 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220629/fa2b4093/attachment.bin>


More information about the llvm-commits mailing list