summaryrefslogtreecommitdiff
path: root/gcc/cfgloopmanip.c
diff options
context:
space:
mode:
authorhubicka <hubicka@138bc75d-0d04-0410-961f-82ee72b054a4>2017-07-01 20:46:40 +0000
committerhubicka <hubicka@138bc75d-0d04-0410-961f-82ee72b054a4>2017-07-01 20:46:40 +0000
commitca69b0696432d6230a0cac12b1f9fc939ec1eae1 (patch)
tree7af6a2ca2adedc6bef10ea8e3c46425031abf858 /gcc/cfgloopmanip.c
parenteaa16535715d4925ef016ccd8723f3f9caaeff92 (diff)
downloadgcc-ca69b0696432d6230a0cac12b1f9fc939ec1eae1.tar.gz
* cfg.c (scale_bbs_frequencies): New function.
* cfg.h (scale_bbs_frequencies): Declare it. * cfgloopanal.c (single_likely_exit): Cleanup. * cfgloopmanip.c (scale_loop_frequencies): Take profile_probability as parameter. (scale_loop_profile): Likewise. (loop_version): Likewise. (create_empty_loop_on_edge): Update. * cfgloopmanip.h (scale_loop_frequencies, scale_loop_profile, scale_loop_frequencies, scale_loop_profile, loopify, loop_version): Update prototypes. * modulo-sched.c (sms_schedule): Update. * predict.c (unlikely_executed_edge_p): Also check probability. (probably_never_executed_edge_p): Fix typo. * tree-if-conv.c (version_loop_for_if_conversion): Update. * tree-parloops.c (gen_parallel_loop): Update. * tree-ssa-loop-ivcanon.c (try_peel_loop): Update. * tree-ssa-loop-manip.c (tree_transform_and_unroll_loop): Update. * tree-ssa-loop-split.c (split_loop): Update. * tree-ssa-loop-unswitch.c (tree_unswitch_loop): Update. * tree-vect-loop-manip.c (vect_do_peeling): Update. (vect_loop_versioning): Update. * tree-vect-loop.c (scale_profile_for_vect_loop): Update. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@249872 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cfgloopmanip.c')
-rw-r--r--gcc/cfgloopmanip.c58
1 files changed, 30 insertions, 28 deletions
diff --git a/gcc/cfgloopmanip.c b/gcc/cfgloopmanip.c
index f319026ae16..a7d0e612eb2 100644
--- a/gcc/cfgloopmanip.c
+++ b/gcc/cfgloopmanip.c
@@ -488,38 +488,42 @@ add_loop (struct loop *loop, struct loop *outer)
free (bbs);
}
-/* Multiply all frequencies in LOOP by NUM/DEN. */
+/* Scale profile of loop by P. */
void
-scale_loop_frequencies (struct loop *loop, int num, int den)
+scale_loop_frequencies (struct loop *loop, profile_probability p)
{
basic_block *bbs;
bbs = get_loop_body (loop);
- scale_bbs_frequencies_int (bbs, loop->num_nodes, num, den);
+ scale_bbs_frequencies (bbs, loop->num_nodes, p);
free (bbs);
}
-/* Multiply all frequencies in LOOP by SCALE/REG_BR_PROB_BASE.
+/* Scale profile in LOOP by P.
If ITERATION_BOUND is non-zero, scale even further if loop is predicted
to iterate too many times. */
void
-scale_loop_profile (struct loop *loop, int scale, gcov_type iteration_bound)
+scale_loop_profile (struct loop *loop, profile_probability p,
+ gcov_type iteration_bound)
{
gcov_type iterations = expected_loop_iterations_unbounded (loop);
edge e;
edge_iterator ei;
if (dump_file && (dump_flags & TDF_DETAILS))
- fprintf (dump_file, ";; Scaling loop %i with scale %f, "
- "bounding iterations to %i from guessed %i\n",
- loop->num, (double)scale / REG_BR_PROB_BASE,
- (int)iteration_bound, (int)iterations);
+ {
+ fprintf (dump_file, ";; Scaling loop %i with scale ",
+ loop->num);
+ p.dump (dump_file);
+ fprintf (dump_file, " bounding iterations to %i from guessed %i\n",
+ (int)iteration_bound, (int)iterations);
+ }
/* See if loop is predicted to iterate too many times. */
if (iteration_bound && iterations > 0
- && apply_probability (iterations, scale) > iteration_bound)
+ && p.apply (iterations) > iteration_bound)
{
/* Fixing loop profile for different trip count is not trivial; the exit
probabilities has to be updated to match and frequencies propagated down
@@ -569,7 +573,7 @@ scale_loop_profile (struct loop *loop, int scale, gcov_type iteration_bound)
/* Roughly speaking we want to reduce the loop body profile by the
difference of loop iterations. We however can do better if
we look at the actual profile, if it is available. */
- scale = RDIV (iteration_bound * scale, iterations);
+ p = p.apply_scale (iteration_bound, iterations);
bool determined = false;
if (loop->header->count.initialized_p ())
@@ -582,9 +586,8 @@ scale_loop_profile (struct loop *loop, int scale, gcov_type iteration_bound)
if (count_in > profile_count::zero () )
{
- scale = GCOV_COMPUTE_SCALE (count_in.to_gcov_type ()
- * iteration_bound,
- loop->header->count.to_gcov_type ());
+ p = count_in.probability_in (loop->header->count.apply_scale
+ (iteration_bound, 1));
determined = true;
}
}
@@ -597,18 +600,19 @@ scale_loop_profile (struct loop *loop, int scale, gcov_type iteration_bound)
freq_in += EDGE_FREQUENCY (e);
if (freq_in != 0)
- scale = GCOV_COMPUTE_SCALE (freq_in * iteration_bound,
- loop->header->frequency);
+ p = profile_probability::probability_in_gcov_type
+ (freq_in * iteration_bound, loop->header->frequency);
}
- if (!scale)
- scale = 1;
+ if (!(p > profile_probability::never ()))
+ p = profile_probability::very_unlikely ();
}
- if (scale == REG_BR_PROB_BASE)
+ if (p >= profile_probability::always ()
+ || !p.initialized_p ())
return;
/* Scale the actual probabilities. */
- scale_loop_frequencies (loop, scale, REG_BR_PROB_BASE);
+ scale_loop_frequencies (loop, p);
if (dump_file && (dump_flags & TDF_DETAILS))
fprintf (dump_file, ";; guessed iterations are now %i\n",
(int)expected_loop_iterations_unbounded (loop));
@@ -778,7 +782,6 @@ create_empty_loop_on_edge (edge entry_edge,
gcond *cond_expr;
tree exit_test;
edge exit_e;
- int prob;
gcc_assert (entry_edge && initial_value && stride && upper_bound && iv);
@@ -802,9 +805,7 @@ create_empty_loop_on_edge (edge entry_edge,
add_loop (loop, outer);
/* TODO: Fix frequencies and counts. */
- prob = REG_BR_PROB_BASE / 2;
-
- scale_loop_frequencies (loop, REG_BR_PROB_BASE - prob, REG_BR_PROB_BASE);
+ scale_loop_frequencies (loop, profile_probability::even ());
/* Update dominators. */
update_dominators_in_loop (loop);
@@ -862,7 +863,8 @@ create_empty_loop_on_edge (edge entry_edge,
struct loop *
loopify (edge latch_edge, edge header_edge,
basic_block switch_bb, edge true_edge, edge false_edge,
- bool redirect_all_edges, unsigned true_scale, unsigned false_scale)
+ bool redirect_all_edges, profile_probability true_scale,
+ profile_probability false_scale)
{
basic_block succ_bb = latch_edge->dest;
basic_block pred_bb = header_edge->src;
@@ -915,8 +917,8 @@ loopify (edge latch_edge, edge header_edge,
e->count = switch_bb->count.apply_probability (e->probability);
}
}
- scale_loop_frequencies (loop, false_scale, REG_BR_PROB_BASE);
- scale_loop_frequencies (succ_bb->loop_father, true_scale, REG_BR_PROB_BASE);
+ scale_loop_frequencies (loop, false_scale);
+ scale_loop_frequencies (succ_bb->loop_father, true_scale);
update_dominators_in_loop (loop);
return loop;
@@ -1683,7 +1685,7 @@ struct loop *
loop_version (struct loop *loop,
void *cond_expr, basic_block *condition_bb,
profile_probability then_prob, profile_probability else_prob,
- unsigned then_scale, unsigned else_scale,
+ profile_probability then_scale, profile_probability else_scale,
bool place_after)
{
basic_block first_head, second_head;