[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
Mon Jul 11 17:30:05 PDT 2022


wlei updated this revision to Diff 443793.
wlei added a comment.

Updating D128859 <https://reviews.llvm.org/D128859>: [llvm-profgen] Do not cache the frame location stack during computing inlined context size


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
@@ -492,18 +492,23 @@
   // Load the symbols from debug table and populate into symbol list.
   void populateSymbolListFromDWARF(ProfileSymbolList &SymbolList);
 
-  const SampleContextFrameVector &
+  SampleContextFrameVector
   getFrameLocationStack(uint64_t Offset, bool UseProbeDiscriminator = false) {
+    InstructionPointer IP(this, Offset);
+    return symbolize(IP, true, UseProbeDiscriminator);
+  }
+
+  const SampleContextFrameVector &
+  getCachedFrameLocationStack(uint64_t Offset,
+                              bool UseProbeDiscriminator = false) {
     auto I = Offset2LocStackMap.emplace(Offset, SampleContextFrameVector());
-    if (I.second) {
-      InstructionPointer IP(this, Offset);
-      I.first->second = symbolize(IP, true, UseProbeDiscriminator);
-    }
+    if (I.second)
+      I.first->second = getFrameLocationStack(Offset, UseProbeDiscriminator);
     return I.first->second;
   }
 
   Optional<SampleContextFrame> getInlineLeafFrameLoc(uint64_t Offset) {
-    const auto &Stack = getFrameLocationStack(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
@@ -235,8 +235,10 @@
 bool ProfiledBinary::inlineContextEqual(uint64_t Address1, uint64_t Address2) {
   uint64_t Offset1 = virtualAddrToOffset(Address1);
   uint64_t Offset2 = virtualAddrToOffset(Address2);
-  const SampleContextFrameVector &Context1 = getFrameLocationStack(Offset1);
-  const SampleContextFrameVector &Context2 = getFrameLocationStack(Offset2);
+  const SampleContextFrameVector &Context1 =
+      getCachedFrameLocationStack(Offset1);
+  const SampleContextFrameVector &Context2 =
+      getCachedFrameLocationStack(Offset2);
   if (Context1.size() != Context2.size())
     return false;
   if (Context1.empty())
@@ -257,7 +259,7 @@
   for (auto Address : Stack) {
     uint64_t Offset = virtualAddrToOffset(Address);
     const SampleContextFrameVector &ExpandedContext =
-        getFrameLocationStack(Offset);
+        getCachedFrameLocationStack(Offset);
     // An instruction without a valid debug line will be ignored by sample
     // processing
     if (ExpandedContext.empty())
@@ -817,7 +819,7 @@
 
   do {
     uint64_t Offset = virtualAddrToOffset(IP.Address);
-    const SampleContextFrameVector &SymbolizedCallStack =
+    const SampleContextFrameVector SymbolizedCallStack =
         getFrameLocationStack(Offset, UsePseudoProbes);
     uint64_t Size = Offset2InstSizeMap[Offset];
 
Index: llvm/tools/llvm-profgen/ProfileGenerator.cpp
===================================================================
--- llvm/tools/llvm-profgen/ProfileGenerator.cpp
+++ llvm/tools/llvm-profgen/ProfileGenerator.cpp
@@ -670,7 +670,7 @@
 
     do {
       uint64_t Offset = Binary->virtualAddrToOffset(IP.Address);
-      const SampleContextFrameVector &FrameVec =
+      const SampleContextFrameVector FrameVec =
           Binary->getFrameLocationStack(Offset);
       if (!FrameVec.empty()) {
         // FIXME: As accumulating total count per instruction caused some
@@ -711,7 +711,7 @@
       continue;
     // Record called target sample and its count.
     const SampleContextFrameVector &FrameVec =
-        Binary->getFrameLocationStack(SourceOffset);
+        Binary->getCachedFrameLocationStack(SourceOffset);
     if (!FrameVec.empty()) {
       FunctionSamples &FunctionProfile =
           getLeafProfileAndAddTotalSamples(FrameVec, 0);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128859.443793.patch
Type: text/x-patch
Size: 3866 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220712/696eec9e/attachment.bin>


More information about the llvm-commits mailing list