* tree-vrp.c (execute_vrp): Do not pass dump argument to. loop_optimizer_init and loop_optimizer_finalize * tree-ssa-sink.c (execute_sink_code): Ditto. * tree-ssa-loop-ch.c (copy_loop_headers): Ditto. * tree-ssa-loop.c (tree_loop_optimizer_init, tree_ssa_loop_init, tree_ssa_loop_done): Ditto. * tree-ssa-pre.c (init_pre, fini_pre): Ditto. * sched-ebb.c: Include output.h. (schedule_ebbs): Do not use dump argument. * value-prof.h (struct profile_hooks): Remove profile_dump_file. * loop.c (loop_dump_stream): Removed. (loop_optimize, rest_of_handle_loop_optimize): Do not use dump argument. (scan_loop, move_movables, find_and_verify_loops, mark_loop_jump, emit_prefetch_instructions, loop_bivs_find, loop_bivs_check, final_biv_value, loop_biv_eliminable_p, loop_givs_rescan, loop_iterations, strength_reduce, record_biv, record_giv, final_giv_value, check_final_value, check_ext_dependent_givs, combine_givs, check_dbra_loop, maybe_eliminate_biv, load_mems, try_copy_prop, loop_delete_insns, try_swap_copy_prop): Use dump_file instead of loop_dump_stream. * ddg.c (print_ddg_edge, print_ddg, vcg_print_ddg): Do not call argument dump_file. * reorg.c (dbr_schedule, rest_of_handle_delay_slots): Do not use dump argument. * flow.c (life_analysis, rest_of_handle_life): Ditto. * haifa-sched.c: Include output.h (schedule_insns, sched_init): Do not use dump argument. * mode-switching.c (optimize_mode_switching): Ditto. * modulo-sched.c (stats_file): Removed. (print_node_sched_params): Do not call argument dump_file. (sms_schedule_by_order, loop_canon_p, sms_schedule, rest_of_handle_sms): Do not use dump argument. Use dump_file instead of stats_file. * cse.c (cse_main, rest_of_handle_cse, rest_of_handle_cse2): Do not use dump argument. * loop-init.c (loop_optimizer_init, loop_optimizer_finalize, rtl_loop_init, rtl_loop_done): Ditto. * global.c (global_alloc, rest_of_handle_global_alloc): Ditto. * predict.c (combine_predictions_for_bb, tree_estimate_probability): Ditto. * recog.c (peephole2_optimize, rest_of_handle_peephole2): Ditto. * lcm.c (pre_edge_lcm, pre_edge_rev_lcm): Ditto. * regmove.c (fixup_match_1, fixup_match_2, regmove_optimize, rest_of_handle_regmove, rest_of_handle_stack_adjustments): Ditto. * emit-rtl.c (renumber_insns): Ditto. * cfgexpand.c (add_reg_br_prob_note, expand_gimple_cond_expr, expand_gimple_basic_block, tree_expand_cfg): Ditto. * regclass.c (regclass): Ditto. * tree-outof-ssa.c (analyze_edges_for_bb, perform_edge_inserts, remove_ssa_form, rewrite_out_of_ssa): Ditto. * reg-stack.c (compensate_edge, compensate_edges, convert_regs_1, convert_regs_2, convert_regs, reg_to_stack, rest_of_handle_stack_regs): Ditto. * sched-rgn.c (schedule_insns, rest_of_handle_sched): Ditto. * local-alloc.c (rest_of_handle_local_alloc): Do not pass dump_file to regclass. * gcse.c (gcse_file, debug_stderr): Removed. (gcse_main, bypass_jumps, rest_of_handle_jump_bypass, rest_of_handle_gcse): Do not use dump argument. (cprop_jump, cprop_insn, do_local_cprop, cprop, find_implicit_sets, one_cprop_pass, bypass_block, compute_pre_data, insert_insn_end_bb, pre_edge_insert, pre_insert_copy_insn, pre_delete, one_pre_gcse_pass, compute_code_hoist_vbeinout, compute_code_hoist_data, one_code_hoisting_pass, trim_ld_motion_mems, update_ld_motion_stores, compute_store_table, build_store_vectors, insert_insn_start_bb, insert_store, remove_reachable_equiv_notes, replace_store_insn, store_motion): Use dump_file instead of gcse_file. * ipa-type-escape.c (type_escape_execute): Remove debugging comments. * profile.c (profile_dump_file): Removed. (branch_prob): Use dump_file instead of profile_dump_file. * ipa.c (cgraph_remove_unreachable_nodes): Do not call argument dump_file. * tree-ssa-copy.c (dump_copy_of): Ditto. * rtl-factoring.c (rtl_seqabstr, rest_of_rtl_seqabstr): Do not pass dump file to life_analysis. * bt-load.c (branch_target_load_optimize): Ditto. * cfgcleanup.c (rest_of_handle_jump2): Do not pass dump_file to renumber_insns. * rtl.h (cse_main, renumber_insns, schedule_insns, schedule_ebbs, regclass, dbr_schedule): Declaration changed. * sched-int.h (sched_init): Declaration changed. * tree-profile.c (tree_profile_dump_file): Removed. (tree_profile_hooks): Removed profile_dump_file hook. * rtl-profile (rtl_profile_dump_file): Removed. (rtl_profile_hooks): emoved profile_dump_file hook. * cfgloop.h (loop_optimizer_init, loop_optimizer_finalize): Declaration changed. * c-gimplify.c (c_genericize): Do not call local variable dump_file. * tree-cfg.c (build_tree_cfg): Ditto. * Makefile.in (haifa-sched.o, sched-ebb.o): Add output.h dependency. * basic-block.h (life_analysis, pre_edge_lcm, pre_edge_rev_lcm): Declaration changed. * config/sh/sh.c (sh_output_mi_thunk): Do not pass dump_file to life_analysis and schedule_insns. * config/m68hc11/m68hc11.c (m68hc11_reorg): Do not pass dump_file to life_analysis. * config/mt/mt.c (mt_machine_reorg): Do not pass dump_file to dbr_schedule. * config/mips/mips.c (mips_reorg): Ditto. * config/ia64/ia64.c (ia64_reorg): Do not pass dump_file to schedule_ebbs. From-SVN: r110656
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 void
|
|
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;
|
|
|
|
#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);
|
|
}
|
|
|
|
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 */
|
|
};
|