[llvm] [llvm-profgen] Improve sample profile density (PR #92144)
via llvm-commits
llvm-commits at lists.llvm.org
Thu May 23 09:57:15 PDT 2024
================
@@ -768,9 +747,88 @@ void ProfileGenerator::populateBoundarySamplesForAllFunctions(
}
}
+// Note that ideally the size should be the number of function instruction.
+// However, for probe-based profile, we don't have the accurate instruction
+// count for each probe, instead, the probe sample is the samples count for the
+// block, which is equivelant to total_instruction_samples/num_of_instruction in
+// one block. Hence, we use the number of probe as a proxy for the function's
+// size.
+void ProfileGeneratorBase::calculateBodySamplesAndSize(
+ const FunctionSamples &FSamples, uint64_t &TotalBodySamples,
+ uint64_t &FuncBodySize) {
+ FuncBodySize +=
+ FSamples.getBodySamples().size() + FSamples.getCallsiteSamples().size();
+
+ for (const auto &I : FSamples.getBodySamples())
+ TotalBodySamples += I.second.getSamples();
+
+ // The whole function could be inlined and optimized out, use the callsite
+ // head samples instead to estimate the body count.
+ for (const auto &CallsiteSamples : FSamples.getCallsiteSamples())
+ for (const auto &Callee : CallsiteSamples.second) {
+ // This is used for caluculating the binary-level density, so the
+ // inlinees' samples and size should be included in the calculation.
+ calculateBodySamplesAndSize(Callee.second, TotalBodySamples,
+ FuncBodySize);
+ TotalBodySamples += Callee.second.getHeadSamplesEstimate();
----------------
WenleiHe wrote:
Is this needed? It seems to duplicate the inlinee's body samples. Can we remove?
https://github.com/llvm/llvm-project/pull/92144
More information about the llvm-commits
mailing list