[PATCH] D84295: [CallGraph] Preserve call records vector when replacing call edge

Sergey Dmitriev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 22 02:02:39 PDT 2020


sdmitriev updated this revision to Diff 279728.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84295/new/

https://reviews.llvm.org/D84295

Files:
  llvm/lib/Analysis/CallGraph.cpp


Index: llvm/lib/Analysis/CallGraph.cpp
===================================================================
--- llvm/lib/Analysis/CallGraph.cpp
+++ llvm/lib/Analysis/CallGraph.cpp
@@ -281,13 +281,37 @@
       I->second = NewNode;
       NewNode->AddRef();
 
-      // Refresh callback references.
-      forEachCallbackFunction(Call, [=](Function *CB) {
-        removeOneAbstractEdgeTo(CG->getOrInsertFunction(CB));
+      // Refresh callback references. Do not resize CalledFunctions if the
+      // number of callbacks is the same for new and old call sites.
+      SmallVector<CallGraphNode *, 4u> OldCBs;
+      SmallVector<CallGraphNode *, 4u> NewCBs;
+      forEachCallbackFunction(Call, [this, &OldCBs](Function *CB) {
+        OldCBs.push_back(CG->getOrInsertFunction(CB));
       });
-      forEachCallbackFunction(NewCall, [=](Function *CB) {
-        addCalledFunction(nullptr, CG->getOrInsertFunction(CB));
+      forEachCallbackFunction(NewCall, [this, &NewCBs](Function *CB) {
+        NewCBs.push_back(CG->getOrInsertFunction(CB));
       });
+      if (OldCBs.size() == NewCBs.size()) {
+        for (unsigned N = 0; N < OldCBs.size(); ++N) {
+          CallGraphNode *OldNode = OldCBs[N];
+          CallGraphNode *NewNode = NewCBs[N];
+          for (auto J = CalledFunctions.begin();; ++J) {
+            assert(J != CalledFunctions.end() &&
+                   "Cannot find callsite to update!");
+            if (!J->first && J->second == OldNode) {
+              J->second = NewNode;
+              OldNode->DropRef();
+              NewNode->AddRef();
+              break;
+            }
+          }
+        }
+      } else {
+        for (auto *CGN : OldCBs)
+          removeOneAbstractEdgeTo(CGN);
+        for (auto *CGN : NewCBs)
+          addCalledFunction(nullptr, CGN);
+      }
       return;
     }
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84295.279728.patch
Type: text/x-patch
Size: 1843 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200722/dd97a992/attachment.bin>


More information about the llvm-commits mailing list