[llvm-branch-commits] [llvm] [BOLT] Add profile density computation (PR #101094)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Aug 5 10:17:47 PDT 2024


================
@@ -1441,6 +1458,18 @@ Error PrintProgramStats::runOnFunctions(BinaryContext &BC) {
       StaleSampleCount += SampleCount;
       ++NumAllStaleFunctions;
     }
+
+    if (opts::ShowDensity) {
+      uint64_t Instructions = Function.getInputInstructionCount();
+      // In case of BOLT split functions registered in BAT, samples are
+      // automatically attributed to the main fragment. Add instructions from
+      // all fragments.
+      if (IsHotParentOfBOLTSplitFunction)
+        for (const BinaryFunction *Fragment : Function.getFragments())
+          Instructions += Fragment->getInputInstructionCount();
+      double Density = (double)1.0 * SampleCount / Instructions;
----------------
WenleiHe wrote:

If sample count is from branch count, size represented in instructions count may not be a good denominator? 

For compiler CSSPGO, we use sum of block execution count (sum of counts on probes) divided by number of probes (proxy for number of blocks) as density. If we use instructions count as the denominator, then the numerator should probably be total dynamic instructions count, which is different from raw branch count but can be derived from branches.

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


More information about the llvm-branch-commits mailing list