[llvm] [llvm-profgen] Improve sample profile density (PR #92144)

via llvm-commits llvm-commits at lists.llvm.org
Fri May 17 18:40:22 PDT 2024


================
@@ -768,9 +745,79 @@ void ProfileGenerator::populateBoundarySamplesForAllFunctions(
   }
 }
 
+void ProfileGeneratorBase::calculateDensity(
+    const FunctionSamples &FSamples,
+    std::vector<std::pair<double, uint64_t>> &DensityList,
+    uint64_t &TotalProfileSamples) {
+  uint64_t TotalBodySamples = 0;
+  uint64_t FuncBodySize = 0;
+  for (const auto &I : FSamples.getBodySamples()) {
+    TotalBodySamples += I.second.getSamples();
+    FuncBodySize++;
+  }
+
+  // The whole function could be inlined and optimized out, use the callsite
+  // head samples instead to estimate the body count.
+  if (FuncBodySize == 0) {
+    for (const auto &CallsiteSamples : FSamples.getCallsiteSamples()) {
+      FuncBodySize++;
+      for (const auto &Callee : CallsiteSamples.second) {
+        calculateDensity(Callee.second, DensityList, TotalProfileSamples);
----------------
WenleiHe wrote:

I was thinking about density as a binary level metric as opposed to source level, in which case it maps better with inlinee included. Just like when we dump hot function list, it's binary level function, instead of source level function. 

Any particular reason to do this on source level with inlining excluded? 

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


More information about the llvm-commits mailing list