[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
Mon Aug 25 22:53:57 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.addTypeSamplesAt(Loc, FunctionId(IpData.second), Count);
+    }
+  }
+
----------------
mingmingl-llvm wrote:

I moved this to a helper function `ProfileGenerator::populateTypeSamplesForAllFunctions`. 

If I understand correctly,  `llvm-profgen` supports 4 settings -- {LBR w/o callgraph, LBR w call graph} x {binary using line + discriminator, binary enabling pseudo-probe based mapping}. `ProfileGenerator::populateTypeSamplesForAllFunctions` only supports LBR w/o callgraph + binary using line + discriminator.

In the updated patch
* `llvm-profgen.cpp`  will report errors on the 3 other cases
* `afdo-with-vtable.test` and `afdo-with-vtable-pie.test` are updated to test that `llvm-profgen` will report error and exit with `-use-dwarf-correlation=false`.

Unfortunately the environment where I can conveniently collect LBR is temporarily not available due to a very recent  tech issue so I cannot collect context-sensitive perf traces or provide it. I'll deal with the tech issue and hopefully be able to collect LBR conveniently in the new few days to update this patch.

 I'll file a Github issue to track the other three combinations of settings. Meanwhile may I know which setting is preferred the most out of the other 3 settings? 

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


More information about the llvm-branch-commits mailing list