predict.c (combine_predictions_for_bb): Add dry_run parmaeter.
authorJan Hubicka <jh@suse.cz>
Sun, 17 Apr 2016 16:08:27 +0000 (18:08 +0200)
committerJan Hubicka <hubicka@gcc.gnu.org>
Sun, 17 Apr 2016 16:08:27 +0000 (16:08 +0000)
* predict.c (combine_predictions_for_bb): Add dry_run parmaeter.
(tree_estimate_probability): Likewise.
(pass_profile::execute): Update.
(report_predictor_hitrates): New function.
* profile.c (compute_branch_probabilities): Use it.
* predict.h (report_predictor_hitrates): Declare.

From-SVN: r235082

gcc/ChangeLog
gcc/predict.c
gcc/predict.h
gcc/profile.c

index 1e9ef9b93c67d7c6803ed300e1007e2edd4fde0f..f6d8870f1dc18190d119b83ce6fc34b6555ece7f 100644 (file)
@@ -1,3 +1,12 @@
+2016-04-17  Jan Hubicka  <jh@suse.cz>
+
+       * predict.c (combine_predictions_for_bb): Add dry_run parmaeter.
+       (tree_estimate_probability): Likewise.
+       (pass_profile::execute): Update.
+       (report_predictor_hitrates): New function.
+       * profile.c (compute_branch_probabilities): Use it.
+       * predict.h (report_predictor_hitrates): Declare.
+
 2016-04-17  Jan Hubicka  <jh@suse.cz>
 
        PR ipa/70018
index 150d8d008e7c3d730cfb867258fb69ba2b725c8d..f1e22aef5f41f394d0ea439c0d3f130d9b81aa1f 100644 (file)
@@ -842,10 +842,11 @@ combine_predictions_for_insn (rtx_insn *insn, basic_block bb)
 }
 
 /* Combine predictions into single probability and store them into CFG.
-   Remove now useless prediction entries.  */
+   Remove now useless prediction entries.
+   If DRY_RUN is set, only produce dumps and do not modify profile.  */
 
 static void
-combine_predictions_for_bb (basic_block bb)
+combine_predictions_for_bb (basic_block bb, bool dry_run)
 {
   int best_probability = PROB_EVEN;
   enum br_predictor best_predictor = END_PREDICTORS;
@@ -876,7 +877,7 @@ combine_predictions_for_bb (basic_block bb)
      this later.  */
   if (nedges != 2)
     {
-      if (!bb->count)
+      if (!bb->count && !dry_run)
        set_even_probabilities (bb);
       clear_bb_predictions (bb);
       if (dump_file)
@@ -982,7 +983,7 @@ combine_predictions_for_bb (basic_block bb)
     }
   clear_bb_predictions (bb);
 
-  if (!bb->count)
+  if (!bb->count && !dry_run)
     {
       first->probability = combined_probability;
       second->probability = REG_BR_PROB_BASE - combined_probability;
@@ -2327,10 +2328,11 @@ tree_estimate_probability_bb (basic_block bb)
 
 /* Predict branch probabilities and estimate profile of the tree CFG.
    This function can be called from the loop optimizers to recompute
-   the profile information.  */
+   the profile information.
+   If DRY_RUN is set, do not modify CFG and only produce dump files.  */
 
 void
-tree_estimate_probability (void)
+tree_estimate_probability (bool dry_run)
 {
   basic_block bb;
 
@@ -2352,7 +2354,7 @@ tree_estimate_probability (void)
     tree_estimate_probability_bb (bb);
 
   FOR_EACH_BB_FN (bb, cfun)
-    combine_predictions_for_bb (bb);
+    combine_predictions_for_bb (bb, dry_run);
 
   if (flag_checking)
     bb_predictions->traverse<void *, assert_is_empty> (NULL);
@@ -2360,7 +2362,8 @@ tree_estimate_probability (void)
   delete bb_predictions;
   bb_predictions = NULL;
 
-  estimate_bb_frequencies (false);
+  if (!dry_run)
+    estimate_bb_frequencies (false);
   free_dominance_info (CDI_POST_DOMINATORS);
   remove_fake_exit_edges ();
 }
@@ -3040,7 +3043,7 @@ pass_profile::execute (function *fun)
   if (nb_loops > 1)
     scev_initialize ();
 
-  tree_estimate_probability ();
+  tree_estimate_probability (false);
 
   if (nb_loops > 1)
     scev_finalize ();
@@ -3191,3 +3194,30 @@ rebuild_frequencies (void)
     gcc_unreachable ();
   timevar_pop (TV_REBUILD_FREQUENCIES);
 }
+
+/* Perform a dry run of the branch prediction pass and report comparsion of
+   the predicted and real profile into the dump file.  */
+
+void
+report_predictor_hitrates (void)
+{
+  unsigned nb_loops;
+
+  loop_optimizer_init (LOOPS_NORMAL);
+  if (dump_file && (dump_flags & TDF_DETAILS))
+    flow_loops_dump (dump_file, NULL, 0);
+
+  mark_irreducible_loops ();
+
+  nb_loops = number_of_loops (cfun);
+  if (nb_loops > 1)
+    scev_initialize ();
+
+  tree_estimate_probability (true);
+
+  if (nb_loops > 1)
+    scev_finalize ();
+
+  loop_optimizer_finalize ();
+}
+
index 84dcf4a0414aec2af34f6db22691f79cb5147a35..a725596e8123abaf0de42f1a2f36ee4302a93f21 100644 (file)
@@ -90,5 +90,6 @@ extern void compute_function_frequency (void);
 extern tree build_predict_expr (enum br_predictor, enum prediction);
 extern const char *predictor_name (enum br_predictor);
 extern void rebuild_frequencies (void);
+extern void report_predictor_hitrates (void);
 
 #endif  /* GCC_PREDICT_H */
index bdc89c245ab2592da9833a31d33606edbb5e1e5e..39c81d4fbafeb8bd9e6cc1144a1a992bb5fd3ce4 100644 (file)
@@ -845,6 +845,8 @@ compute_branch_probabilities (unsigned cfg_checksum, unsigned lineno_checksum)
       fputc ('\n', dump_file);
       fputc ('\n', dump_file);
     }
+  if (dump_file && (dump_flags & TDF_DETAILS))
+    report_predictor_hitrates ();
 
   free_aux_for_blocks ();
 }