From 5a5f50e974c1dd781281725c537a42bea8d6139c Mon Sep 17 00:00:00 2001 From: hubicka Date: Sun, 17 Apr 2016 16:08:27 +0000 Subject: [PATCH] * 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@235082 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 9 +++++++++ gcc/predict.c | 48 +++++++++++++++++++++++++++++++++++++++--------- gcc/predict.h | 1 + gcc/profile.c | 2 ++ 4 files changed, 51 insertions(+), 9 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 1e9ef9b93c6..f6d8870f1dc 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,14 @@ 2016-04-17 Jan Hubicka + * 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 + PR ipa/70018 * cgraph.h (cgraph_node::set_const_flag, cgraph_node::set_pure_flag): Update prototype to return bool; diff --git a/gcc/predict.c b/gcc/predict.c index 150d8d008e7..f1e22aef5f4 100644 --- a/gcc/predict.c +++ b/gcc/predict.c @@ -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 (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 (); +} + diff --git a/gcc/predict.h b/gcc/predict.h index 84dcf4a0414..a725596e812 100644 --- a/gcc/predict.h +++ b/gcc/predict.h @@ -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 */ diff --git a/gcc/profile.c b/gcc/profile.c index bdc89c245ab..39c81d4fbaf 100644 --- a/gcc/profile.c +++ b/gcc/profile.c @@ -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 (); } -- 2.11.4.GIT