[PATCH] D128859: [llvm-profgen] Do not cache the frame location stack during computing inlined context size

Lei Wang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 25 21:11:03 PDT 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG91cc53d5a455: [llvm-profgen] Do not cache the frame location stack during computing inlined… (authored by wlei).

Changed prior to commit:
  https://reviews.llvm.org/D128859?vs=443793&id=470693#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128859

Files:
  llvm/tools/llvm-profgen/ProfileGenerator.cpp
  llvm/tools/llvm-profgen/ProfiledBinary.cpp
  llvm/tools/llvm-profgen/ProfiledBinary.h


Index: llvm/tools/llvm-profgen/ProfiledBinary.h
===================================================================
--- llvm/tools/llvm-profgen/ProfiledBinary.h
+++ llvm/tools/llvm-profgen/ProfiledBinary.h
@@ -477,18 +477,24 @@
   // Load the symbols from debug table and populate into symbol list.
   void populateSymbolListFromDWARF(ProfileSymbolList &SymbolList);
 
-  const SampleContextFrameVector &
+  SampleContextFrameVector
   getFrameLocationStack(uint64_t Address, bool UseProbeDiscriminator = false) {
+    InstructionPointer IP(this, Address);
+    return symbolize(IP, true, UseProbeDiscriminator);
+  }
+
+  const SampleContextFrameVector &
+  getCachedFrameLocationStack(uint64_t Address,
+                              bool UseProbeDiscriminator = false) {
     auto I = AddressToLocStackMap.emplace(Address, SampleContextFrameVector());
     if (I.second) {
-      InstructionPointer IP(this, Address);
-      I.first->second = symbolize(IP, true, UseProbeDiscriminator);
+      I.first->second = getFrameLocationStack(Address, UseProbeDiscriminator);
     }
     return I.first->second;
   }
 
-  Optional<SampleContextFrame> getInlineLeafFrameLoc(uint64_t Address) {
-    const auto &Stack = getFrameLocationStack(Address);
+  Optional<SampleContextFrame> getInlineLeafFrameLoc(uint64_t Offset) {
+    const auto &Stack = getCachedFrameLocationStack(Offset);
     if (Stack.empty())
       return {};
     return Stack.back();
Index: llvm/tools/llvm-profgen/ProfiledBinary.cpp
===================================================================
--- llvm/tools/llvm-profgen/ProfiledBinary.cpp
+++ llvm/tools/llvm-profgen/ProfiledBinary.cpp
@@ -233,8 +233,10 @@
 }
 
 bool ProfiledBinary::inlineContextEqual(uint64_t Address1, uint64_t Address2) {
-  const SampleContextFrameVector &Context1 = getFrameLocationStack(Address1);
-  const SampleContextFrameVector &Context2 = getFrameLocationStack(Address2);
+  const SampleContextFrameVector &Context1 =
+      getCachedFrameLocationStack(Address1);
+  const SampleContextFrameVector &Context2 =
+      getCachedFrameLocationStack(Address2);
   if (Context1.size() != Context2.size())
     return false;
   if (Context1.empty())
@@ -254,7 +256,7 @@
   // Process from frame root to leaf
   for (auto Address : Stack) {
     const SampleContextFrameVector &ExpandedContext =
-        getFrameLocationStack(Address);
+        getCachedFrameLocationStack(Address);
     // An instruction without a valid debug line will be ignored by sample
     // processing
     if (ExpandedContext.empty())
@@ -806,10 +808,9 @@
     return;
 
   do {
-    const SampleContextFrameVector &SymbolizedCallStack =
+    const SampleContextFrameVector SymbolizedCallStack =
         getFrameLocationStack(IP.Address, UsePseudoProbes);
     uint64_t Size = AddressToInstSizeMap[IP.Address];
-
     // Record instruction size for the corresponding context
     FuncSizeTracker.addInstructionForContext(SymbolizedCallStack, Size);
 
Index: llvm/tools/llvm-profgen/ProfileGenerator.cpp
===================================================================
--- llvm/tools/llvm-profgen/ProfileGenerator.cpp
+++ llvm/tools/llvm-profgen/ProfileGenerator.cpp
@@ -667,7 +667,7 @@
       continue;
 
     do {
-      const SampleContextFrameVector &FrameVec =
+      const SampleContextFrameVector FrameVec =
           Binary->getFrameLocationStack(IP.Address);
       if (!FrameVec.empty()) {
         // FIXME: As accumulating total count per instruction caused some
@@ -709,7 +709,7 @@
       continue;
     // Record called target sample and its count.
     const SampleContextFrameVector &FrameVec =
-        Binary->getFrameLocationStack(SourceAddress);
+        Binary->getCachedFrameLocationStack(SourceAddress);
     if (!FrameVec.empty()) {
       FunctionSamples &FunctionProfile =
           getLeafProfileAndAddTotalSamples(FrameVec, 0);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128859.470693.patch
Type: text/x-patch
Size: 3883 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221026/7232f139/attachment-0001.bin>


More information about the llvm-commits mailing list