Mercurial > hg > CbC > CbC_gcc
diff gcc/shrink-wrap.c @ 131:84e7813d76e9
gcc-8.2
author | mir3636 |
---|---|
date | Thu, 25 Oct 2018 07:37:49 +0900 |
parents | 04ced10e8804 |
children | 1830386684a0 |
line wrap: on
line diff
--- a/gcc/shrink-wrap.c Fri Oct 27 22:46:09 2017 +0900 +++ b/gcc/shrink-wrap.c Thu Oct 25 07:37:49 2018 +0900 @@ -1,5 +1,5 @@ /* Shrink-wrapping related optimizations. - Copyright (C) 1987-2017 Free Software Foundation, Inc. + Copyright (C) 1987-2018 Free Software Foundation, Inc. This file is part of GCC. @@ -157,7 +157,7 @@ struct dead_debug_local *debug) { rtx set, src, dest; - bitmap live_out, live_in, bb_uses, bb_defs; + bitmap live_out, live_in, bb_uses = NULL, bb_defs = NULL; unsigned int i, dregno, end_dregno; unsigned int sregno = FIRST_PSEUDO_REGISTER; unsigned int end_sregno = FIRST_PSEUDO_REGISTER; @@ -309,10 +309,10 @@ move it as far as we can. */ do { - if (MAY_HAVE_DEBUG_INSNS) + if (MAY_HAVE_DEBUG_BIND_INSNS) { FOR_BB_INSNS_REVERSE (bb, dinsn) - if (DEBUG_INSN_P (dinsn)) + if (DEBUG_BIND_INSN_P (dinsn)) { df_ref use; FOR_EACH_INSN_USE (use, dinsn) @@ -330,8 +330,11 @@ /* Check whether BB uses DEST or clobbers DEST. We need to add INSN to BB if so. Either way, DEST is no longer live on entry, except for any part that overlaps SRC (next loop). */ - bb_uses = &DF_LR_BB_INFO (bb)->use; - bb_defs = &DF_LR_BB_INFO (bb)->def; + if (!*split_p) + { + bb_uses = &DF_LR_BB_INFO (bb)->use; + bb_defs = &DF_LR_BB_INFO (bb)->def; + } if (df_live) { for (i = dregno; i < end_dregno; i++) @@ -561,7 +564,7 @@ BB_END (old_bb) = end; redirect_edge_succ (e, new_bb); - new_bb->frequency = EDGE_FREQUENCY (e); + new_bb->count = e->count (); e->flags |= EDGE_FALLTHRU; e = make_single_succ_edge (new_bb, EXIT_BLOCK_PTR_FOR_FN (cfun), 0); @@ -880,19 +883,18 @@ the correct answer for reducible flow graphs; for irreducible flow graphs our profile is messed up beyond repair anyway. */ - gcov_type num = 0; - gcov_type den = 0; + profile_count num = profile_count::zero (); + profile_count den = profile_count::zero (); FOR_EACH_EDGE (e, ei, pro->preds) if (!dominated_by_p (CDI_DOMINATORS, e->src, pro)) { - num += EDGE_FREQUENCY (e); - den += e->src->frequency; + if (e->count ().initialized_p ()) + num += e->count (); + if (e->src->count.initialized_p ()) + den += e->src->count; } - if (den == 0) - den = 1; - /* All is okay, so do it. */ crtl->shrink_wrapped = true; @@ -919,10 +921,9 @@ if (dump_file) fprintf (dump_file, "Duplicated %d to %d\n", bb->index, dup->index); - - bb->frequency = RDIV (num * bb->frequency, den); - dup->frequency -= bb->frequency; - bb->count = bb->count.apply_scale (num, den); + + if (num == profile_count::zero () || den.nonzero_p ()) + bb->count = bb->count.apply_scale (num, den); dup->count -= bb->count; } @@ -995,8 +996,7 @@ continue; } - new_bb->count += e->src->count.apply_probability (e->probability); - new_bb->frequency += EDGE_FREQUENCY (e); + new_bb->count += e->count (); redirect_edge_and_branch_force (e, new_bb); if (dump_file) @@ -1181,7 +1181,7 @@ work: this does not always add up to the block frequency at all, and even if it does, rounding error makes for bad decisions. */ - SW (bb)->own_cost = bb->frequency; + SW (bb)->own_cost = bb->count.to_frequency (cfun); edge e; edge_iterator ei; @@ -1253,8 +1253,9 @@ /* Set HAS_COMPONENTS in every block to the maximum it can be set to without setting it on any path from entry to exit where it was not already set somewhere (or, for blocks that have no path to the exit, consider only - paths from the entry to the block itself). */ -static void + paths from the entry to the block itself). Return whether any changes + were made to some HAS_COMPONENTS. */ +static bool spread_components (sbitmap components) { basic_block entry_block = ENTRY_BLOCK_PTR_FOR_FN (cfun); @@ -1373,14 +1374,23 @@ bitmap_clear_bit (seen, bb->index); } + todo.release (); + /* Finally, mark everything not not needed both forwards and backwards. */ + bool did_changes = false; + FOR_EACH_BB_FN (bb, cfun) { + bitmap_copy (old, SW (bb)->has_components); + bitmap_and (SW (bb)->head_components, SW (bb)->head_components, SW (bb)->tail_components); bitmap_and_compl (SW (bb)->has_components, components, SW (bb)->head_components); + + if (!did_changes && !bitmap_equal_p (old, SW (bb)->has_components)) + did_changes = true; } FOR_ALL_BB_FN (bb, cfun) @@ -1392,6 +1402,8 @@ fprintf (dump_file, "\n"); } } + + return did_changes; } /* If we cannot handle placing some component's prologues or epilogues where @@ -1795,7 +1807,16 @@ EXECUTE_IF_SET_IN_BITMAP (components, 0, j, sbi) place_prologue_for_one_component (j, first_bb); - spread_components (components); + /* Try to minimize the number of saves and restores. Do this as long as + it changes anything. This does not iterate more than a few times. */ + int spread_times = 0; + while (spread_components (components)) + { + spread_times++; + + if (dump_file) + fprintf (dump_file, "Now spread %d times.\n", spread_times); + } disqualify_problematic_components (components);