-
- no_new_pseudos = 1;
-
- close_dump_file (DFI_life, print_rtl_with_bb, get_insns ());
-
- ggc_collect ();
-}
-
-/* Perform common subexpression elimination. Nonzero value from
- `cse_main' means that jumps were simplified and some code may now
- be unreachable, so do jump optimization again. */
-static void
-rest_of_handle_cse (void)
-{
- int tem;
-
- open_dump_file (DFI_cse, current_function_decl);
- if (dump_file)
- dump_flow_info (dump_file);
- timevar_push (TV_CSE);
-
- reg_scan (get_insns (), max_reg_num ());
-
- tem = cse_main (get_insns (), max_reg_num (), dump_file);
- if (tem)
- rebuild_jump_labels (get_insns ());
- if (purge_all_dead_edges (0))
- delete_unreachable_blocks ();
-
- delete_trivially_dead_insns (get_insns (), max_reg_num ());
-
- /* If we are not running more CSE passes, then we are no longer
- expecting CSE to be run. But always rerun it in a cheap mode. */
- cse_not_expected = !flag_rerun_cse_after_loop && !flag_gcse;
-
- if (tem)
- delete_dead_jumptables ();
-
- if (tem || optimize > 1)
- cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
-
- timevar_pop (TV_CSE);
- close_dump_file (DFI_cse, print_rtl_with_bb, get_insns ());
-
- ggc_collect ();
-}
-
-/* Run second CSE pass after loop optimizations. */
-static void
-rest_of_handle_cse2 (void)
-{
- int tem;
-
- timevar_push (TV_CSE2);
- open_dump_file (DFI_cse2, current_function_decl);
- if (dump_file)
- dump_flow_info (dump_file);
- /* CFG is no longer maintained up-to-date. */
- tem = cse_main (get_insns (), max_reg_num (), dump_file);
-
- /* Run a pass to eliminate duplicated assignments to condition code
- registers. We have to run this after bypass_jumps, because it
- makes it harder for that pass to determine whether a jump can be
- bypassed safely. */
- cse_condition_code_reg ();
-
- purge_all_dead_edges (0);
- delete_trivially_dead_insns (get_insns (), max_reg_num ());
-
- if (tem)
- {
- timevar_push (TV_JUMP);
- rebuild_jump_labels (get_insns ());
- delete_dead_jumptables ();
- cleanup_cfg (CLEANUP_EXPENSIVE);
- timevar_pop (TV_JUMP);
- }
- reg_scan (get_insns (), max_reg_num ());
- close_dump_file (DFI_cse2, print_rtl_with_bb, get_insns ());
- timevar_pop (TV_CSE2);
-
- ggc_collect ();
-}
-
-/* Perform global cse. */
-static void
-rest_of_handle_gcse (void)
-{
- int save_csb, save_cfj;
- int tem2 = 0, tem;
-
- timevar_push (TV_GCSE);
- open_dump_file (DFI_gcse, current_function_decl);
-
- tem = gcse_main (get_insns (), dump_file);
- rebuild_jump_labels (get_insns ());
- delete_trivially_dead_insns (get_insns (), max_reg_num ());
-
- save_csb = flag_cse_skip_blocks;
- save_cfj = flag_cse_follow_jumps;
- flag_cse_skip_blocks = flag_cse_follow_jumps = 0;
-
- /* If -fexpensive-optimizations, re-run CSE to clean up things done
- by gcse. */
- if (flag_expensive_optimizations)
- {
- timevar_push (TV_CSE);
- reg_scan (get_insns (), max_reg_num ());
- tem2 = cse_main (get_insns (), max_reg_num (), dump_file);
- purge_all_dead_edges (0);
- delete_trivially_dead_insns (get_insns (), max_reg_num ());
- timevar_pop (TV_CSE);
- cse_not_expected = !flag_rerun_cse_after_loop;
- }
-
- /* If gcse or cse altered any jumps, rerun jump optimizations to clean
- things up. */
- if (tem || tem2)
- {
- timevar_push (TV_JUMP);
- rebuild_jump_labels (get_insns ());
- delete_dead_jumptables ();
- cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
- timevar_pop (TV_JUMP);
- }
-
- close_dump_file (DFI_gcse, print_rtl_with_bb, get_insns ());
- timevar_pop (TV_GCSE);
-
- ggc_collect ();
- flag_cse_skip_blocks = save_csb;
- flag_cse_follow_jumps = save_cfj;
-#ifdef ENABLE_CHECKING
- verify_flow_info ();
-#endif
-}
-
-/* Move constant computations out of loops. */
-static void
-rest_of_handle_loop_optimize (void)
-{
- int do_prefetch;
-
- timevar_push (TV_LOOP);
- open_dump_file (DFI_loop, current_function_decl);
-
- /* CFG is no longer maintained up-to-date. */
- free_bb_for_insn ();
- profile_status = PROFILE_ABSENT;
-
- do_prefetch = flag_prefetch_loop_arrays ? LOOP_PREFETCH : 0;
-
- if (flag_rerun_loop_opt)
- {
- cleanup_barriers ();
-
- /* We only want to perform unrolling once. */
- loop_optimize (get_insns (), dump_file, 0);
-
- /* The first call to loop_optimize makes some instructions
- trivially dead. We delete those instructions now in the
- hope that doing so will make the heuristics in loop work
- better and possibly speed up compilation. */
- delete_trivially_dead_insns (get_insns (), max_reg_num ());
-
- /* The regscan pass is currently necessary as the alias
- analysis code depends on this information. */
- reg_scan (get_insns (), max_reg_num ());
- }
- cleanup_barriers ();
- loop_optimize (get_insns (), dump_file, do_prefetch);
-
- /* Loop can create trivially dead instructions. */
- delete_trivially_dead_insns (get_insns (), max_reg_num ());
- find_basic_blocks (get_insns ());
- close_dump_file (DFI_loop, print_rtl, get_insns ());
- timevar_pop (TV_LOOP);
-
- ggc_collect ();
-}
-
-/* Perform loop optimizations. It might be better to do them a bit
- sooner, but we want the profile feedback to work more
- efficiently. */
-static void
-rest_of_handle_loop2 (void)
-{
- struct loops *loops;
- basic_block bb;
-
- if (!flag_move_loop_invariants
- && !flag_unswitch_loops
- && !flag_peel_loops
- && !flag_unroll_loops
- && !flag_branch_on_count_reg)
- return;
-
- timevar_push (TV_LOOP);
- open_dump_file (DFI_loop2, current_function_decl);
- if (dump_file)
- dump_flow_info (dump_file);
-
- /* Initialize structures for layout changes. */
- cfg_layout_initialize (0);
-
- loops = loop_optimizer_init (dump_file);
-
- if (loops)
- {
- /* The optimizations: */
- if (flag_move_loop_invariants)
- move_loop_invariants (loops);
-
- if (flag_unswitch_loops)
- unswitch_loops (loops);
-
- if (flag_peel_loops || flag_unroll_loops)
- unroll_and_peel_loops (loops,
- (flag_peel_loops ? UAP_PEEL : 0) |
- (flag_unroll_loops ? UAP_UNROLL : 0) |
- (flag_unroll_all_loops ? UAP_UNROLL_ALL : 0));
-
-#ifdef HAVE_doloop_end
- if (flag_branch_on_count_reg && HAVE_doloop_end)
- doloop_optimize_loops (loops);
-#endif /* HAVE_doloop_end */
-
- loop_optimizer_finalize (loops, dump_file);
- }
-
- free_dominance_info (CDI_DOMINATORS);
-
- /* Finalize layout changes. */
- FOR_EACH_BB (bb)
- if (bb->next_bb != EXIT_BLOCK_PTR)
- bb->rbi->next = bb->next_bb;
- cfg_layout_finalize ();
-
- cleanup_cfg (CLEANUP_EXPENSIVE);
- delete_trivially_dead_insns (get_insns (), max_reg_num ());
- reg_scan (get_insns (), max_reg_num ());
- if (dump_file)
- dump_flow_info (dump_file);
- close_dump_file (DFI_loop2, print_rtl_with_bb, get_insns ());
- timevar_pop (TV_LOOP);
- ggc_collect ();
-}
-
-static void
-rest_of_handle_branch_target_load_optimize (void)
-{
- static int warned = 0;
-
- /* Leave this a warning for now so that it is possible to experiment
- with running this pass twice. In 3.6, we should either make this
- an error, or use separate dump files. */
- if (flag_branch_target_load_optimize
- && flag_branch_target_load_optimize2
- && !warned)
- {
- warning ("branch target register load optimization is not intended "
- "to be run twice");
-
- warned = 1;
- }
-
- open_dump_file (DFI_branch_target_load, current_function_decl);
- branch_target_load_optimize (epilogue_completed);
- close_dump_file (DFI_branch_target_load, print_rtl_with_bb, get_insns ());
- ggc_collect ();
-}
-
-#ifdef OPTIMIZE_MODE_SWITCHING
-static void
-rest_of_handle_mode_switching (void)
-{
- timevar_push (TV_MODE_SWITCH);
-
- no_new_pseudos = 0;
- optimize_mode_switching (NULL);
- no_new_pseudos = 1;
-
- timevar_pop (TV_MODE_SWITCH);
-}
-#endif
-
-static void
-rest_of_handle_jump (void)
-{
- ggc_collect ();
-
- timevar_push (TV_JUMP);
- open_dump_file (DFI_sibling, current_function_decl);
-
- delete_unreachable_blocks ();
-#ifdef ENABLE_CHECKING
- verify_flow_info ();
-#endif
-
- if (cfun->tail_call_emit)
- fixup_tail_calls ();
-
- close_dump_file (DFI_sibling, print_rtl, get_insns ());
- timevar_pop (TV_JUMP);
-}
-
-static void
-rest_of_handle_eh (void)
-{
- insn_locators_initialize ();
- /* Complete generation of exception handling code. */
- if (doing_eh (0))
- {
- timevar_push (TV_JUMP);
- open_dump_file (DFI_eh, current_function_decl);
-
- cleanup_cfg (CLEANUP_PRE_LOOP | CLEANUP_NO_INSN_DEL);
-
- finish_eh_generation ();
-
- cleanup_cfg (CLEANUP_PRE_LOOP | CLEANUP_NO_INSN_DEL);
-
- close_dump_file (DFI_eh, print_rtl, get_insns ());
- timevar_pop (TV_JUMP);
- }
-}
-
-static void
-rest_of_handle_stack_adjustments (void)
-{
- life_analysis (dump_file, PROP_POSTRELOAD);
- cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE
- | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0));
-
- /* This is kind of a heuristic. We need to run combine_stack_adjustments
- even for machines with possibly nonzero RETURN_POPS_ARGS
- and ACCUMULATE_OUTGOING_ARGS. We expect that only ports having
- push instructions will have popping returns. */
-#ifndef PUSH_ROUNDING
- if (!ACCUMULATE_OUTGOING_ARGS)
-#endif
- combine_stack_adjustments ();
-}
-
-static void
-rest_of_handle_flow2 (void)
-{
- timevar_push (TV_FLOW2);
- open_dump_file (DFI_flow2, current_function_decl);
-
- /* Re-create the death notes which were deleted during reload. */
-#ifdef ENABLE_CHECKING
- verify_flow_info ();
-#endif
-
- /* If optimizing, then go ahead and split insns now. */
-#ifndef STACK_REGS
- if (optimize > 0)
-#endif
- split_all_insns (0);
-
- if (flag_branch_target_load_optimize)
- {
- close_dump_file (DFI_flow2, print_rtl_with_bb, get_insns ());
- rest_of_handle_branch_target_load_optimize ();
- open_dump_file (DFI_flow2, current_function_decl);
- }
-
- if (optimize)
- cleanup_cfg (CLEANUP_EXPENSIVE);
-
- /* On some machines, the prologue and epilogue code, or parts thereof,
- can be represented as RTL. Doing so lets us schedule insns between
- it and the rest of the code and also allows delayed branch
- scheduling to operate in the epilogue. */
- thread_prologue_and_epilogue_insns (get_insns ());
- epilogue_completed = 1;
-
- if (optimize)
- rest_of_handle_stack_adjustments ();
-
- flow2_completed = 1;
-
- close_dump_file (DFI_flow2, print_rtl_with_bb, get_insns ());
- timevar_pop (TV_FLOW2);
-
- ggc_collect ();
-}
-
-
-static void
-rest_of_handle_jump2 (void)
-{
- open_dump_file (DFI_jump, current_function_decl);
-
- /* Always do one jump optimization pass to ensure that JUMP_LABEL fields
- are initialized and to compute whether control can drop off the end
- of the function. */
-
- timevar_push (TV_JUMP);
- /* Turn NOTE_INSN_EXPECTED_VALUE into REG_BR_PROB. Do this
- before jump optimization switches branch directions. */
- if (flag_guess_branch_prob)
- expected_value_to_br_prob ();
-
- delete_trivially_dead_insns (get_insns (), max_reg_num ());
- reg_scan (get_insns (), max_reg_num ());
- if (dump_file)
- dump_flow_info (dump_file);
- cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_PRE_LOOP
- | (flag_thread_jumps ? CLEANUP_THREADING : 0));
-
- create_loop_notes ();
-
- purge_line_number_notes (get_insns ());
-
- if (optimize)
- cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
-
- /* Jump optimization, and the removal of NULL pointer checks, may
- have reduced the number of instructions substantially. CSE, and
- future passes, allocate arrays whose dimensions involve the
- maximum instruction UID, so if we can reduce the maximum UID
- we'll save big on memory. */
- renumber_insns (dump_file);
-
- close_dump_file (DFI_jump, print_rtl_with_bb, get_insns ());
- timevar_pop (TV_JUMP);
-
- ggc_collect ();
-}
-
-#ifdef HAVE_peephole2
-static void
-rest_of_handle_peephole2 (void)
-{
- timevar_push (TV_PEEPHOLE2);
- open_dump_file (DFI_peephole2, current_function_decl);
-
- peephole2_optimize (dump_file);
-
- close_dump_file (DFI_peephole2, print_rtl_with_bb, get_insns ());
- timevar_pop (TV_PEEPHOLE2);
-}
-#endif
-
-static void
-rest_of_handle_postreload (void)
-{
- timevar_push (TV_RELOAD_CSE_REGS);
- open_dump_file (DFI_postreload, current_function_decl);
-
- /* Do a very simple CSE pass over just the hard registers. */
- reload_cse_regs (get_insns ());
- /* reload_cse_regs can eliminate potentially-trapping MEMs.
- Remove any EH edges associated with them. */
- if (flag_non_call_exceptions)
- purge_all_dead_edges (0);
-
- close_dump_file (DFI_postreload, print_rtl_with_bb, get_insns ());
- timevar_pop (TV_RELOAD_CSE_REGS);