[PATCH] D158689: Fix dangling reference after D147740

William Junda Huang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 23 18:48:06 PDT 2023


huangjd updated this revision to Diff 552948.
huangjd added a comment.

Update incorrect use of reference


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158689

Files:
  llvm/include/llvm/ProfileData/SampleProf.h


Index: llvm/include/llvm/ProfileData/SampleProf.h
===================================================================
--- llvm/include/llvm/ProfileData/SampleProf.h
+++ llvm/include/llvm/ProfileData/SampleProf.h
@@ -1603,13 +1603,25 @@
                            ? TotalSamples - CalleeProfile.getTotalSamples()
                            : 0;
         TotalSamples += CalleeProfile.getHeadSamplesEstimate();
+
+      }
+    }
+
+    // FlattenNestedProfile adds new FunctionSamples to the output, which may
+    // invalidate the reference Profile, so it needs to be reset after all
+    // flattening.
+    for (const auto &I : FS.getCallsiteSamples()) {
+      for (const auto &Callee : I.second) {
+        const auto &CalleeProfile = Callee.second;
         // Recursively convert callee profile.
         flattenNestedProfile(OutputProfiles, CalleeProfile);
       }
     }
-    Profile.addTotalSamples(TotalSamples);
+    FunctionSamples &NewProfile = OutputProfiles[Context];
 
-    Profile.setHeadSamples(Profile.getHeadSamplesEstimate());
+    NewProfile.addTotalSamples(TotalSamples);
+
+    NewProfile.setHeadSamples(NewProfile.getHeadSamplesEstimate());
   }
 
   // Nest all children profiles into the profile of Node.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158689.552948.patch
Type: text/x-patch
Size: 1235 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230824/97eaaaeb/attachment.bin>


More information about the llvm-commits mailing list