================
@@ -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
_______________________________________________
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to