From 617b465c7f1fa399d376f89a1b255fbb39e4e738 Mon Sep 17 00:00:00 2001 From: Zdenek Dvorak Date: Sat, 8 Feb 2003 15:29:00 +0100 Subject: cfgloop.h (fix_loop_placement, [...]): Declare. * cfgloop.h (fix_loop_placement, can_duplicate_loop_p, duplicate_loop_to_header_edge, loopify, remove_path, split_loop_bb): Declare. (DLTHE_FLAG_UPDATE_FREQ): New. * cfgloopmanip.c (duplicate_loop, duplicate_subloops, copy_loops_to, loop_redirect_edge, loop_delete_branch_edge, copy_bbs, remove_bbs, rpe_enum_p, find_branch, alp_enum_p, add_loop, fix_loop_placements, fix_bb_placement, fix_bb_placements, place_new_loop, scale_loop_frequencies, scale_bbs_frequencies, record_exit_edges): New static functions. (fix_loop_placement, can_duplicate_loop_p, duplicate_loop_to_header_edge, loopify, remove_path, split_loop_bb): New functions. * cfgloop.h (loop_optimizer_init, loop_optimizer_finalize, unswitch_loops): Declare. * loop-init.c: New file. * loop-unswitch.c: New file. * Makefile.in (loop-init.o, loop-unswitch.o): New. * params.def (PARAM_MAX_UNSWITCH_INSNS, PARAM_MAX_UNSWITCH_LEVEL): New. * toplev.c (DFI_loop2): New dump. (flag_unswitch_loops): New. (lang_independent_options): Add it. (rest_of_compilation): Call new loop optimizer. (parse_options_and_default_flags): Turn flag_unswitch_loops on with -O3. From-SVN: r62578 --- gcc/toplev.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'gcc/toplev.c') diff --git a/gcc/toplev.c b/gcc/toplev.c index 7b49110..840632a 100644 --- a/gcc/toplev.c +++ b/gcc/toplev.c @@ -239,6 +239,7 @@ enum dump_file_index DFI_bp, DFI_ce1, DFI_tracer, + DFI_loop2, DFI_cse2, DFI_life, DFI_combine, @@ -289,6 +290,7 @@ static struct dump_file_info dump_file[DFI_MAX] = { "bp", 'b', 1, 0, 0 }, { "ce1", 'C', 1, 0, 0 }, { "tracer", 'T', 1, 0, 0 }, + { "loop2", 'L', 1, 0, 0 }, { "cse2", 't', 1, 0, 0 }, { "life", 'f', 1, 0, 0 }, /* Yes, duplicate enable switch. */ { "combine", 'c', 1, 0, 0 }, @@ -519,6 +521,9 @@ int flag_unroll_loops; int flag_unroll_all_loops; +/* Nonzero enables loop unswitching. */ +int flag_unswitch_loops; + /* Nonzero enables prefetch optimizations for arrays in loops. */ int flag_prefetch_loop_arrays; @@ -997,6 +1002,8 @@ static const lang_independent_options f_options[] = N_("Perform loop unrolling when iteration count is known") }, {"unroll-all-loops", &flag_unroll_all_loops, 1, N_("Perform loop unrolling for all loops") }, + {"unswitch-loops", &flag_unswitch_loops, 1, + N_("Perform loop unswitching") }, {"prefetch-loop-arrays", &flag_prefetch_loop_arrays, 1, N_("Generate prefetch instructions, if available, for arrays in loops") }, {"move-all-movables", &flag_move_all_movables, 1, @@ -3057,6 +3064,38 @@ rest_of_compilation (decl) timevar_pop (TV_TRACER); } + /* Perform loop optimalizations. It might be better to do them a bit + sooner, but we want the profile feedback to work more efficiently. */ + if (optimize > 0 + && flag_unswitch_loops) + { + struct loops *loops; + timevar_push (TV_LOOP); + open_dump_file (DFI_loop2, decl); + if (rtl_dump_file) + dump_flow_info (rtl_dump_file); + + loops = loop_optimizer_init (rtl_dump_file); + + if (loops) + { + /* The optimalizations: */ + if (flag_unswitch_loops) + unswitch_loops (loops); + + loop_optimizer_finalize (loops, rtl_dump_file); + } + + cleanup_cfg (CLEANUP_EXPENSIVE); + delete_trivially_dead_insns (insns, max_reg_num ()); + reg_scan (insns, max_reg_num (), 0); + if (rtl_dump_file) + dump_flow_info (rtl_dump_file); + close_dump_file (DFI_loop2, print_rtl_with_bb, get_insns ()); + timevar_pop (TV_LOOP); + ggc_collect (); + } + if (flag_rerun_cse_after_loop) { timevar_push (TV_CSE2); @@ -4884,6 +4923,7 @@ parse_options_and_default_flags (argc, argv) { flag_inline_functions = 1; flag_rename_registers = 1; + flag_unswitch_loops = 1; } if (optimize < 2 || optimize_size) -- cgit v1.1