[llvm-branch-commits] [llvm] [llvm-profgen] Extend llvm-profgen to generate vtable profiles with data access events. (PR #148013)

Mingming Liu via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Jul 18 14:51:45 PDT 2025


================
@@ -540,6 +540,22 @@ void ProfileGenerator::generateLineNumBasedProfile() {
   // Fill in boundary sample counts as well as call site samples for calls
   populateBoundarySamplesForAllFunctions(SC.BranchCounter);
 
+  // For each instruction with vtable accesses, get its symbolized inline
+  // stack, and add the vtable counters to the function samples.
+  for (const auto &[IpData, Count] : SC.DataAccessCounter) {
+    uint64_t InstAddr = IpData.first;
+    const SampleContextFrameVector &FrameVec =
+        Binary->getCachedFrameLocationStack(InstAddr, false);
+    if (!FrameVec.empty()) {
+      FunctionSamples &FunctionProfile =
+          getLeafProfileAndAddTotalSamples(FrameVec, 0);
+      LineLocation Loc(
+          FrameVec.back().Location.LineOffset,
+          getBaseDiscriminator(FrameVec.back().Location.Discriminator));
+      FunctionProfile.getTypeSamplesAt(Loc)[FunctionId(IpData.second)] += Count;
----------------
mingmingl-llvm wrote:

done with a slight modification, by adding a helper function `FunctionSamples::addTypeSamplesAt` and calling that function.

https://github.com/llvm/llvm-project/pull/148013


More information about the llvm-branch-commits mailing list