]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
profile.c (compute_branch_probabilities): Compute and dump the overlap between the...
authorDehao Chen <dehao@google.com>
Thu, 20 Oct 2011 00:39:12 +0000 (00:39 +0000)
committerDehao Chen <dehao@gcc.gnu.org>
Thu, 20 Oct 2011 00:39:12 +0000 (00:39 +0000)
2011-10-20  Dehao Chen  <dehao@google.com>

* profile.c (compute_branch_probabilities): Compute and dump the
overlap between the static estimation and the instrumentation profile.
(OVERLAP_BASE): New macro.
(compute_frequency_overlap): New function

From-SVN: r180233

gcc/ChangeLog
gcc/profile.c

index 394634bc3dd7f19a8da4f92026ffc582b338dbb4..34e94e403fe68e6acf79f4a622e7d1eba570845b 100644 (file)
@@ -1,3 +1,10 @@
+2011-10-20  Dehao Chen  <dehao@google.com>
+
+       * profile.c (compute_branch_probabilities): Compute and dump the
+       overlap between the static estimation and the instrumentation profile.
+       (OVERLAP_BASE): New macro.
+       (compute_frequency_overlap): New function
+
 2011-10-19  Jakub Jelinek  <jakub@redhat.com>
 
        * config/i386/i386.c (expand_vec_perm_vpshufb2_vpermq_even_odd): Use
index 893e2cd17c774fd1e97af0ab3ed767cdc824eeac..41108394e98a68eefc2605edf8af5299146d2410 100644 (file)
@@ -437,6 +437,39 @@ read_profile_edge_counts (gcov_type *exec_counts)
     return num_edges;
 }
 
+#define OVERLAP_BASE 10000
+
+/* Compare the static estimated profile to the actual profile, and
+   return the "degree of overlap" measure between them.
+
+   Degree of overlap is a number between 0 and OVERLAP_BASE. It is
+   the sum of each basic block's minimum relative weights between
+   two profiles. And overlap of OVERLAP_BASE means two profiles are
+   identical.  */
+
+static int
+compute_frequency_overlap (void)
+{
+  gcov_type count_total = 0, freq_total = 0;
+  int overlap = 0;
+  basic_block bb;
+
+  FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, NULL, next_bb)
+    {
+      count_total += bb->count;
+      freq_total += bb->frequency;
+    }
+
+  if (count_total == 0 || freq_total == 0)
+    return 0;
+
+  FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, NULL, next_bb)
+    overlap += MIN (bb->count * OVERLAP_BASE / count_total,
+                   bb->frequency * OVERLAP_BASE / freq_total);
+
+  return overlap;
+}
+
 /* Compute the branch probabilities for the various branches.
    Annotate them accordingly.  
 
@@ -607,7 +640,13 @@ compute_branch_probabilities (unsigned cfg_checksum, unsigned lineno_checksum)
        }
     }
   if (dump_file)
-    dump_flow_info (dump_file, dump_flags);
+    {
+      int overlap = compute_frequency_overlap ();
+      dump_flow_info (dump_file, dump_flags);
+      fprintf (dump_file, "Static profile overlap: %d.%d%%\n",
+              overlap / (OVERLAP_BASE / 100),
+              overlap % (OVERLAP_BASE / 100));
+    }
 
   total_num_passes += passes;
   if (dump_file)