/* Branch prediction routines for the GNU compiler.
- Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
This file is part of GCC.
#include "recog.h"
#include "expr.h"
#include "predict.h"
-#include "profile.h"
+#include "coverage.h"
#include "sreal.h"
#include "params.h"
#include "target.h"
maybe_hot_bb_p (bb)
basic_block bb;
{
- if (profile_info.count_profiles_merged
- && flag_branch_probabilities
+ if (profile_info && flag_branch_probabilities
&& (bb->count
- < profile_info.max_counter_in_program
- / PARAM_VALUE (HOT_BB_COUNT_FRACTION)))
+ < profile_info->sum_max / PARAM_VALUE (HOT_BB_COUNT_FRACTION)))
return false;
if (bb->frequency < BB_FREQ_MAX / PARAM_VALUE (HOT_BB_FREQUENCY_FRACTION))
return false;
probably_cold_bb_p (bb)
basic_block bb;
{
- if (profile_info.count_profiles_merged
- && flag_branch_probabilities
+ if (profile_info && flag_branch_probabilities
&& (bb->count
- < profile_info.max_counter_in_program
- / PARAM_VALUE (HOT_BB_COUNT_FRACTION)))
+ < profile_info->sum_max / PARAM_VALUE (HOT_BB_COUNT_FRACTION)))
return true;
if (bb->frequency < BB_FREQ_MAX / PARAM_VALUE (HOT_BB_FREQUENCY_FRACTION))
return true;
probably_never_executed_bb_p (bb)
basic_block bb;
{
- if (profile_info.count_profiles_merged
- && flag_branch_probabilities)
- return ((bb->count + profile_info.count_profiles_merged / 2)
- / profile_info.count_profiles_merged) == 0;
+ if (profile_info && flag_branch_probabilities)
+ return ((bb->count + profile_info->runs / 2) / profile_info->runs) == 0;
return false;
}
{
if (!any_condjump_p (insn))
abort ();
+ if (!flag_guess_branch_prob)
+ return;
REG_NOTES (insn)
= gen_rtx_EXPR_LIST (REG_BR_PRED,
if (simple_loop_p (loops_info, loop, &desc)
&& desc.const_iter)
{
+ int prob;
niter = desc.niter + 1;
if (niter == 0) /* We might overflow here. */
niter = desc.niter;
+ prob = (REG_BR_PROB_BASE
+ - (REG_BR_PROB_BASE + niter /2) / niter);
+ /* Branch prediction algorithm gives 0 frequency for everything
+ after the end of loop for loop having 0 probability to finish. */
+ if (prob == REG_BR_PROB_BASE)
+ prob = REG_BR_PROB_BASE - 1;
predict_edge (desc.in_edge, PRED_LOOP_ITERATIONS,
- REG_BR_PROB_BASE
- - (REG_BR_PROB_BASE + niter /2)
- / niter);
+ prob);
}
bbs = get_loop_body (loop);
counts_to_freqs ();
else
{
- sreal_init (&real_zero, 0, 0);
- sreal_init (&real_one, 1, 0);
- sreal_init (&real_br_prob_base, REG_BR_PROB_BASE, 0);
- sreal_init (&real_bb_freq_max, BB_FREQ_MAX, 0);
- sreal_init (&real_one_half, 1, -1);
- sreal_div (&real_inv_br_prob_base, &real_one, &real_br_prob_base);
- sreal_sub (&real_almost_one, &real_one, &real_inv_br_prob_base);
+ static int real_values_initialized = 0;
+
+ if (!real_values_initialized)
+ {
+ real_values_initialized = 1;
+ sreal_init (&real_zero, 0, 0);
+ sreal_init (&real_one, 1, 0);
+ sreal_init (&real_br_prob_base, REG_BR_PROB_BASE, 0);
+ sreal_init (&real_bb_freq_max, BB_FREQ_MAX, 0);
+ sreal_init (&real_one_half, 1, -1);
+ sreal_div (&real_inv_br_prob_base, &real_one, &real_br_prob_base);
+ sreal_sub (&real_almost_one, &real_one, &real_inv_br_prob_base);
+ }
mark_dfs_back_edges ();
/* Fill in the probability values in flowgraph based on the REG_BR_PROB
{
basic_block bb;
- if (!profile_info.count_profiles_merged
- || !flag_branch_probabilities)
+ if (!profile_info || !flag_branch_probabilities)
return;
cfun->function_frequency = FUNCTION_FREQUENCY_UNLIKELY_EXECUTED;
FOR_EACH_BB (bb)