
2006-03-02 Daniel Berlin <dberlin@dberlin.org> * gcc/tree-vrp.c (execute_vrp): Return value. * gcc/regrename.c (rest_of_handle_regrename): Ditto. * gcc/tree-into-ssa.c (rewrite_into_ssa): Ditto. * gcc/tree-complex.c (tree_lower_complex): Ditto. (tree_lower_complex_O0): Ditto. * gcc/tracer.c (rest_of_handle_tracer): Ditto. * gcc/postreload-gcse.c (rest_of_handle_gcse2): Ditto. * gcc/postreload.c (rest_of_handle_postreload): Ditto. * gcc/tree-tailcall.c (execute_tail_recursion): Ditto. (execute_tail_calls): Ditto. * gcc/tree-ssa-loop-ch.c (copy_loop_headers): Ditto. * gcc/tree.h (init_function_for_compilation): Ditto. * gcc/ipa-cp.c (ipcp_driver): Ditto. * gcc/tree-scalar-evolution.c (scev_const_prop): Ditto. * gcc/tree-scalar-evolution.h (scev_const_prop): Ditto. * gcc/final.c (compute_alignments): Ditto. (rest_of_handle_final): Ditto. (rest_of_handle_shorten_branches): Ditto. (rest_of_clean_state): Ditto. * gcc/omp-low.c (execute_expand_omp): Ditto. (execute_lower_omp): Ditto. * gcc/tree-ssa-dse.c (tree_ssa_dse): Ditto. * gcc/ipa-reference.c (static_execute): Ditto. * gcc/tree-ssa-uncprop.c (tree_ssa_uncprop): Ditto. * gcc/reorg.c (rest_of_handle_delay_slots): Ditto. (rest_of_handle_machine_reorg): Ditto. * gcc/cgraphunit.c (rebuild_cgraph_edges): Ditto. * gcc/flow.c (recompute_reg_usage): Ditto. (rest_of_handle_remove_death_notes): Ditto. (rest_of_handle_life): Ditto. (rest_of_handle_flow2): Ditto. * gcc/tree-ssa-copyrename.c (rename_ssa_copies): Ditto. * gcc/tree-ssa-ccp.c (do_ssa_ccp): Ditto. (do_ssa_store_ccp): Ditto. (execute_fold_all_builtins): Ditto. * gcc/mode-switching.c (rest_of_handle_mode_switching): Ditto. * gcc/modulo-sched.c (rest_of_handle_sms): Ditto. * gcc/ipa-pure-const.c (static_execute): Ditto. * gcc/cse.c (rest_of_handle_cse): Ditto. (rest_of_handle_cse2): Ditto. * gcc/web.c (rest_of_handle_web): Ditto. * gcc/tree-stdarg.c (execute_optimize_stdarg): Ditto. * gcc/tree-ssa-math-opts.c (execute_cse_reciprocals): Ditto. * gcc/tree-ssa-dom.c (tree_ssa_dominator_optimize): Ditto. * gcc/tree-nrv.c (tree_nrv): Ditto. (execute_return_slot_opt): Ditto. * gcc/tree-ssa-alias.c (compute_may_aliases): Ditto. (create_structure_vars): Ditto. * gcc/loop-init.c (rtl_loop_init): Ditto. (rtl_loop_done): Ditto. (rtl_move_loop_invariants): Ditto. (rtl_unswitch): Ditto. (rtl_unroll_and_peel_loops): Ditto. (rtl_doloop): Ditto. * gcc/gimple-low.c (lower_function_body): Ditto. (mark_used_blocks): Ditto. * gcc/tree-ssa-sink.c (execute_sink_code): Ditto. * gcc/ipa-inline.c (cgraph_decide_inlining): Ditto. (cgraph_early_inlining): Ditto. * gcc/global.c (rest_of_handle_global_alloc): Ditto. * gcc/jump.c (cleanup_barriers): Ditto. (purge_line_number_notes): Ditto. * gcc/ifcvt.c (rest_of_handle_if_conversion): Ditto. (rest_of_handle_if_after_reload): Ditto. * gcc/tree-ssa-loop.c (tree_ssa_loop_init): Ditto. (tree_ssa_loop_im): Ditto. (tree_ssa_loop_unswitch): Ditto. (tree_vectorize): Ditto. (tree_linear_transform): Ditto. (tree_ssa_loop_ivcanon): Ditto. (tree_ssa_empty_loop): Ditto. (tree_ssa_loop_bounds): Ditto. (tree_complete_unroll): Ditto. (tree_ssa_loop_prefetch): Ditto. (tree_ssa_loop_ivopts): Ditto. (tree_ssa_loop_done): Ditto. * gcc/predict.c (tree_estimate_probability): Ditto. * gcc/recog.c (split_all_insns_noflow): Ditto. (rest_of_handle_peephole2): Ditto. (rest_of_handle_split_all_insns): Ditto. * gcc/tree-eh.c (lower_eh_constructs): Ditto. * gcc/regmove.c (rest_of_handle_regmove): Ditto. (rest_of_handle_stack_adjustments): Ditto. * gcc/local-alloc.c (rest_of_handle_local_alloc): Ditto. * gcc/function.c (instantiate_virtual_regs): Ditto. (init_function_for_compilation): Ditto. (rest_of_handle_check_leaf_regs): Ditto. * gcc/gcse.c (rest_of_handle_jump_bypass): Ditto. (rest_of_handle_gcse): Ditto. * gcc/ipa-type-escape.c (type_escape_execute): Ditto. * gcc/alias.c (rest_of_handle_cfg): Ditto. * gcc/tree-if-conv.c (main_tree_if_conversion): Ditto. * gcc/profile.c (rest_of_handle_branch_prob): Ditto. * gcc/tree-ssa-phiopt.c (tree_ssa_phiopt): Ditto. * gcc/rtl-factoring.c (rest_of_rtl_seqabstr): Ditto. * gcc/bt-load.c (rest_of_handle_branch_target_load_optimize): Ditto * gcc/tree-dfa.c (find_referenced_vars): Ditto. * gcc/except.c (set_nothrow_function_flags): Ditto. (convert_to_eh_region_ranges): Ditto. (rest_of_handle_eh): Ditto. * gcc/emit-rtl.c (unshare_all_rtl): Ditto. (remove_unnecessary_notes): Ditto. * gcc/except.h (set_nothrow_function_flags): Ditto. (convert_to_eh_region_ranges): Ditto. * gcc/cfgexpand.c (tree_expand_cfg): Ditto. * gcc/tree-cfgcleanup.c (merge_phi_nodes): Ditto. * gcc/tree-ssa-pre.c (do_pre): Ditto. (execute_fre): Ditto. * gcc/cfgcleanup.c (rest_of_handle_jump): Ditto. (rest_of_handle_jump2): Ditto. * gcc/tree-sra.c (tree_sra): Ditto. * gcc/tree-mudflap.c (execute_mudflap_function_ops): Ditto. (execute_mudflap_function_decls): Ditto. * gcc/tree-ssa-copy.c (do_copy_prop): Ditto. (do_store_copy_prop): Ditto. * gcc/ipa-prop.h (ipcp_driver): Ditto. * gcc/cfglayout.c (insn_locators_initialize): Ditto. * gcc/tree-ssa-forwprop.c (tree_ssa_forward_propagate_single_use_vars): Ditto. * gcc/cfglayout.h (insn_locators_initialize): Ditto. * gcc/tree-ssa-dce.c (tree_ssa_dce): Ditto. * gcc/tree-ssa.c (execute_early_warn_uninitialized): Ditto. (execute_late_warn_uninitialized): Ditto. * gcc/rtl.h (cleanup_barriers): Ditto. (split_all_insns_noflow): Ditto. (purge_line_number_notes): Ditto. (unshare_all_rtl): Ditto. (remove_unnecessary_notes): Ditto. (recompute_reg_usage): Ditto. (variable_tracking_main): Ditto. * gcc/integrate.c (emit_initial_value_sets): Ditto. * gcc/integrate.h (emit_initial_value_sets): Ditto. * gcc/tree-optimize.c (execute_free_datastructures): Ditto (execute_free_cfg_annotations): Ditto. (execute_fixup_cfg): Ditto. (execute_cleanup_cfg_pre_ipa): Ditto. (execute_cleanup_cfg_post_optimizing): Ditto. (execute_init_datastructures): Ditto. * gcc/tree-object-size.c (compute_object_sizes): Ditto. * gcc/combine.c (rest_of_handle_combine): Ditto. * gcc/tree-outof-ssa.c (rewrite_out_of_ssa): Ditto. * gcc/bb-reorder.c (duplicate_computed_gotos): Ditto. (rest_of_handle_reorder_blocks): Ditto. (rest_of_handle_partition_blocks): Ditto. * gcc/var-tracking.c (variable_tracking_main): Ditto. * gcc/tree-profile.c (tree_profiling): Ditto. * gcc/tree-vect-generic.c (expand_vector_operations): Ditto. * gcc/reg-stack.c (rest_of_handle_stack_regs): Ditto. * gcc/sched-rgn.c (rest_of_handle_sched): Ditto. (rest_of_handle_sched2): Ditto. * gcc/basic-block.h (free_bb_insn): Ditto. * gcc/tree-ssa-structalias.c (ipa_pta_execute): Ditto. * gcc/tree-cfg.c (execute_build_cfg): Ditto. (remove_useless_stmts): Ditto. (split_critical_edges): Ditto. (execute_warn_function_return): Ditto. (execute_warn_function_noreturn): Ditto. * gcc/tree-ssa-reassoc.c (execute_reassoc): Ditto. * gcc/cfgrtl.c (free_bb_for_insn): Ditto. * gcc/passes.c (execute_one_pass): Run additional todos returned by execute function. * gcc/tree-pass.h (struct tree_opt_pass): Make execute return a value. From-SVN: r111643
242 lines
6.7 KiB
C
242 lines
6.7 KiB
C
/* Loop header copying on trees.
|
|
Copyright (C) 2004, 2005 Free Software Foundation, Inc.
|
|
|
|
This file is part of GCC.
|
|
|
|
GCC is free software; you can redistribute it and/or modify it
|
|
under the terms of the GNU General Public License as published by the
|
|
Free Software Foundation; either version 2, or (at your option) any
|
|
later version.
|
|
|
|
GCC is distributed in the hope that it will be useful, but WITHOUT
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with GCC; see the file COPYING. If not, write to the Free
|
|
Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
|
|
02110-1301, USA. */
|
|
|
|
#include "config.h"
|
|
#include "system.h"
|
|
#include "coretypes.h"
|
|
#include "tm.h"
|
|
#include "tree.h"
|
|
#include "rtl.h"
|
|
#include "tm_p.h"
|
|
#include "hard-reg-set.h"
|
|
#include "basic-block.h"
|
|
#include "output.h"
|
|
#include "diagnostic.h"
|
|
#include "tree-flow.h"
|
|
#include "tree-dump.h"
|
|
#include "tree-pass.h"
|
|
#include "timevar.h"
|
|
#include "cfgloop.h"
|
|
#include "tree-inline.h"
|
|
#include "flags.h"
|
|
#include "tree-inline.h"
|
|
|
|
/* Duplicates headers of loops if they are small enough, so that the statements
|
|
in the loop body are always executed when the loop is entered. This
|
|
increases effectiveness of code motion optimizations, and reduces the need
|
|
for loop preconditioning. */
|
|
|
|
/* Check whether we should duplicate HEADER of LOOP. At most *LIMIT
|
|
instructions should be duplicated, limit is decreased by the actual
|
|
amount. */
|
|
|
|
static bool
|
|
should_duplicate_loop_header_p (basic_block header, struct loop *loop,
|
|
int *limit)
|
|
{
|
|
block_stmt_iterator bsi;
|
|
tree last;
|
|
|
|
/* Do not copy one block more than once (we do not really want to do
|
|
loop peeling here). */
|
|
if (header->aux)
|
|
return false;
|
|
|
|
gcc_assert (EDGE_COUNT (header->succs) > 0);
|
|
if (single_succ_p (header))
|
|
return false;
|
|
if (flow_bb_inside_loop_p (loop, EDGE_SUCC (header, 0)->dest)
|
|
&& flow_bb_inside_loop_p (loop, EDGE_SUCC (header, 1)->dest))
|
|
return false;
|
|
|
|
/* If this is not the original loop header, we want it to have just
|
|
one predecessor in order to match the && pattern. */
|
|
if (header != loop->header && !single_pred_p (header))
|
|
return false;
|
|
|
|
last = last_stmt (header);
|
|
if (TREE_CODE (last) != COND_EXPR)
|
|
return false;
|
|
|
|
/* Approximately copy the conditions that used to be used in jump.c --
|
|
at most 20 insns and no calls. */
|
|
for (bsi = bsi_start (header); !bsi_end_p (bsi); bsi_next (&bsi))
|
|
{
|
|
last = bsi_stmt (bsi);
|
|
|
|
if (TREE_CODE (last) == LABEL_EXPR)
|
|
continue;
|
|
|
|
if (get_call_expr_in (last))
|
|
return false;
|
|
|
|
*limit -= estimate_num_insns (last);
|
|
if (*limit < 0)
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/* Checks whether LOOP is a do-while style loop. */
|
|
|
|
static bool
|
|
do_while_loop_p (struct loop *loop)
|
|
{
|
|
tree stmt = last_stmt (loop->latch);
|
|
|
|
/* If the latch of the loop is not empty, it is not a do-while loop. */
|
|
if (stmt
|
|
&& TREE_CODE (stmt) != LABEL_EXPR)
|
|
return false;
|
|
|
|
/* If the header contains just a condition, it is not a do-while loop. */
|
|
stmt = last_and_only_stmt (loop->header);
|
|
if (stmt
|
|
&& TREE_CODE (stmt) == COND_EXPR)
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
/* For all loops, copy the condition at the end of the loop body in front
|
|
of the loop. This is beneficial since it increases efficiency of
|
|
code motion optimizations. It also saves one jump on entry to the loop. */
|
|
|
|
static unsigned int
|
|
copy_loop_headers (void)
|
|
{
|
|
struct loops *loops;
|
|
unsigned i;
|
|
struct loop *loop;
|
|
basic_block header;
|
|
edge exit, entry;
|
|
basic_block *bbs, *copied_bbs;
|
|
unsigned n_bbs;
|
|
unsigned bbs_size;
|
|
|
|
loops = loop_optimizer_init (LOOPS_HAVE_PREHEADERS
|
|
| LOOPS_HAVE_SIMPLE_LATCHES);
|
|
if (!loops)
|
|
return 0;
|
|
|
|
#ifdef ENABLE_CHECKING
|
|
verify_loop_structure (loops);
|
|
#endif
|
|
|
|
bbs = XNEWVEC (basic_block, n_basic_blocks);
|
|
copied_bbs = XNEWVEC (basic_block, n_basic_blocks);
|
|
bbs_size = n_basic_blocks;
|
|
|
|
for (i = 1; i < loops->num; i++)
|
|
{
|
|
/* Copy at most 20 insns. */
|
|
int limit = 20;
|
|
|
|
loop = loops->parray[i];
|
|
if (!loop)
|
|
continue;
|
|
header = loop->header;
|
|
|
|
/* If the loop is already a do-while style one (either because it was
|
|
written as such, or because jump threading transformed it into one),
|
|
we might be in fact peeling the first iteration of the loop. This
|
|
in general is not a good idea. */
|
|
if (do_while_loop_p (loop))
|
|
continue;
|
|
|
|
/* Iterate the header copying up to limit; this takes care of the cases
|
|
like while (a && b) {...}, where we want to have both of the conditions
|
|
copied. TODO -- handle while (a || b) - like cases, by not requiring
|
|
the header to have just a single successor and copying up to
|
|
postdominator. */
|
|
|
|
exit = NULL;
|
|
n_bbs = 0;
|
|
while (should_duplicate_loop_header_p (header, loop, &limit))
|
|
{
|
|
/* Find a successor of header that is inside a loop; i.e. the new
|
|
header after the condition is copied. */
|
|
if (flow_bb_inside_loop_p (loop, EDGE_SUCC (header, 0)->dest))
|
|
exit = EDGE_SUCC (header, 0);
|
|
else
|
|
exit = EDGE_SUCC (header, 1);
|
|
bbs[n_bbs++] = header;
|
|
gcc_assert (bbs_size > n_bbs);
|
|
header = exit->dest;
|
|
}
|
|
|
|
if (!exit)
|
|
continue;
|
|
|
|
if (dump_file && (dump_flags & TDF_DETAILS))
|
|
fprintf (dump_file,
|
|
"Duplicating header of the loop %d up to edge %d->%d.\n",
|
|
loop->num, exit->src->index, exit->dest->index);
|
|
|
|
/* Ensure that the header will have just the latch as a predecessor
|
|
inside the loop. */
|
|
if (!single_pred_p (exit->dest))
|
|
exit = single_pred_edge (loop_split_edge_with (exit, NULL));
|
|
|
|
entry = loop_preheader_edge (loop);
|
|
|
|
if (!tree_duplicate_sese_region (entry, exit, bbs, n_bbs, copied_bbs))
|
|
{
|
|
fprintf (dump_file, "Duplication failed.\n");
|
|
continue;
|
|
}
|
|
|
|
/* Ensure that the latch and the preheader is simple (we know that they
|
|
are not now, since there was the loop exit condition. */
|
|
loop_split_edge_with (loop_preheader_edge (loop), NULL);
|
|
loop_split_edge_with (loop_latch_edge (loop), NULL);
|
|
}
|
|
|
|
free (bbs);
|
|
free (copied_bbs);
|
|
|
|
loop_optimizer_finalize (loops);
|
|
return 0;
|
|
}
|
|
|
|
static bool
|
|
gate_ch (void)
|
|
{
|
|
return flag_tree_ch != 0;
|
|
}
|
|
|
|
struct tree_opt_pass pass_ch =
|
|
{
|
|
"ch", /* name */
|
|
gate_ch, /* gate */
|
|
copy_loop_headers, /* execute */
|
|
NULL, /* sub */
|
|
NULL, /* next */
|
|
0, /* static_pass_number */
|
|
TV_TREE_CH, /* tv_id */
|
|
PROP_cfg | PROP_ssa, /* properties_required */
|
|
0, /* properties_provided */
|
|
0, /* properties_destroyed */
|
|
0, /* todo_flags_start */
|
|
TODO_cleanup_cfg | TODO_dump_func
|
|
| TODO_verify_ssa, /* todo_flags_finish */
|
|
0 /* letter */
|
|
};
|