From 95a60a5c8c5620da65d588b6b8c71f8145a31993 Mon Sep 17 00:00:00 2001 From: Jan Hubicka Date: Wed, 19 Jul 2017 20:08:53 +0200 Subject: [PATCH] predict.c (propagate_unlikely_bbs_forward): Break out from ... * predict.c (propagate_unlikely_bbs_forward): Break out from ... (determine_unlikely_bbs): ... here. * predict.h (propagate_unlikely_bbs_forward): Declare. * cfgexpand.c (pass_expand::execute): Use it. * bb-reorder.c (sanitize_hot_paths): Do not consider known to be unlikely edges. (find_rarely_executed_basic_blocks_and_crossing_edges): Use propagate_unlikely_bbs_forward. From-SVN: r250359 --- gcc/ChangeLog | 11 +++++++ gcc/predict.c | 86 +++++++++++++++++++++++++++++---------------------- 2 files changed, 60 insertions(+), 37 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 44b3ba9a54b..746b08ecb2d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,14 @@ +2017-07-19 Jan Hubicka + + * predict.c (propagate_unlikely_bbs_forward): Break out from ... + (determine_unlikely_bbs): ... here. + * predict.h (propagate_unlikely_bbs_forward): Declare. + * cfgexpand.c (pass_expand::execute): Use it. + * bb-reorder.c (sanitize_hot_paths): Do not consider known to be + unlikely edges. + (find_rarely_executed_basic_blocks_and_crossing_edges): Use + propagate_unlikely_bbs_forward. + 2017-07-19 Jan Hubicka PR middle-end/81331 diff --git a/gcc/predict.c b/gcc/predict.c index 1e2e11d71f0..609c099d7b5 100644 --- a/gcc/predict.c +++ b/gcc/predict.c @@ -3374,6 +3374,55 @@ expensive_function_p (int threshold) return false; } +/* All basic blocks that are reachable only from unlikely basic blocks are + unlikely. */ + +void +propagate_unlikely_bbs_forward (void) +{ + auto_vec worklist; + basic_block bb; + edge_iterator ei; + edge e; + + if (!(ENTRY_BLOCK_PTR_FOR_FN (cfun)->count == profile_count::zero ())) + { + ENTRY_BLOCK_PTR_FOR_FN (cfun)->aux = (void *)(size_t) 1; + worklist.safe_push (ENTRY_BLOCK_PTR_FOR_FN (cfun)); + + while (worklist.length () > 0) + { + bb = worklist.pop (); + FOR_EACH_EDGE (e, ei, bb->succs) + if (!(e->count == profile_count::zero ()) + && !(e->dest->count == profile_count::zero ()) + && !e->dest->aux) + { + e->dest->aux = (void *)(size_t) 1; + worklist.safe_push (e->dest); + } + } + } + + FOR_ALL_BB_FN (bb, cfun) + { + if (!bb->aux) + { + if (!(bb->count == profile_count::zero ()) + && (dump_file && (dump_flags & TDF_DETAILS))) + fprintf (dump_file, + "Basic block %i is marked unlikely by forward prop\n", + bb->index); + bb->count = profile_count::zero (); + bb->frequency = 0; + FOR_EACH_EDGE (e, ei, bb->succs) + e->count = profile_count::zero (); + } + else + bb->aux = NULL; + } +} + /* Determine basic blocks/edges that are known to be unlikely executed and set their counters to zero. This is done with first identifying obviously unlikely BBs/edges and then @@ -3418,43 +3467,6 @@ determine_unlikely_bbs () gcc_checking_assert (!bb->aux); } - if (!(ENTRY_BLOCK_PTR_FOR_FN (cfun)->count == profile_count::zero ())) - { - ENTRY_BLOCK_PTR_FOR_FN (cfun)->aux = (void *)(size_t) 1; - worklist.safe_push (ENTRY_BLOCK_PTR_FOR_FN (cfun)); - - while (worklist.length () > 0) - { - bb = worklist.pop (); - FOR_EACH_EDGE (e, ei, bb->succs) - if (!(e->count == profile_count::zero ()) - && !(e->dest->count == profile_count::zero ()) - && !e->dest->aux) - { - e->dest->aux = (void *)(size_t) 1; - worklist.safe_push (e->dest); - } - } - } - - FOR_ALL_BB_FN (bb, cfun) - { - if (!bb->aux) - { - if (!(bb->count == profile_count::zero ()) - && (dump_file && (dump_flags & TDF_DETAILS))) - fprintf (dump_file, - "Basic block %i is marked unlikely by forward prop\n", - bb->index); - bb->count = profile_count::zero (); - bb->frequency = 0; - FOR_EACH_EDGE (e, ei, bb->succs) - e->count = profile_count::zero (); - } - else - bb->aux = NULL; - } - auto_vec nsuccs; nsuccs.safe_grow_cleared (last_basic_block_for_fn (cfun)); FOR_ALL_BB_FN (bb, cfun) -- 2.30.2