1 /* Top level of GCC compilers (cc1, cc1plus, etc.)
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 /* This is the top level of cc1/c++.
23 It parses command args, opens files, invokes the various passes
24 in the proper order, and counts the time used by each.
25 Error messages and low-level interface to malloc also handled here. */
28 #undef FLOAT /* This is for hpux. They should change hpux. */
29 #undef FFS /* Some systems define this in param.h. */
31 #include "coretypes.h"
35 #ifdef HAVE_SYS_RESOURCE_H
36 # include <sys/resource.h>
39 #ifdef HAVE_SYS_TIMES_H
40 # include <sys/times.h>
49 #include "insn-attr.h"
50 #include "insn-config.h"
51 #include "insn-flags.h"
52 #include "hard-reg-set.h"
59 #include "basic-block.h"
65 #include "diagnostic.h"
68 #include "dwarf2asm.h"
69 #include "integrate.h"
73 #include "langhooks.h"
74 #include "cfglayout.h"
76 #include "hosthooks.h"
80 #include "value-prof.h"
81 #include "alloc-pool.h"
82 #include "tree-pass.h"
83 #include "tree-dump.h"
85 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
86 #include "dwarf2out.h"
89 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
93 #ifdef SDB_DEBUGGING_INFO
97 #ifdef XCOFF_DEBUGGING_INFO
98 #include "xcoffout.h" /* Needed for external data
99 declarations for e.g. AIX 4.x. */
102 #ifndef HAVE_conditional_execution
103 #define HAVE_conditional_execution 0
106 /* Format to use to print dumpfile index value */
107 #ifndef DUMPFILE_FORMAT
108 #define DUMPFILE_FORMAT ".%02d."
111 static int initializing_dump = 0;
113 /* Routine to open a dump file. Return true if the dump file is enabled. */
116 open_dump_file (enum tree_dump_index index, tree decl)
118 if (! dump_enabled_p (index))
121 timevar_push (TV_DUMP);
123 gcc_assert (!dump_file && !dump_file_name);
125 dump_file_name = get_dump_file_name (index);
126 initializing_dump = !dump_initialized_p (index);
127 dump_file = dump_begin (index, NULL);
129 if (dump_file == NULL)
130 fatal_error ("can't open %s: %m", dump_file_name);
133 fprintf (dump_file, "\n;; Function %s%s\n\n",
134 lang_hooks.decl_printable_name (decl, 2),
135 cfun->function_frequency == FUNCTION_FREQUENCY_HOT
137 : cfun->function_frequency == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED
138 ? " (unlikely executed)"
141 timevar_pop (TV_DUMP);
145 /* Routine to close a dump file. */
148 close_dump_file (enum tree_dump_index index,
149 void (*func) (FILE *, rtx),
155 timevar_push (TV_DUMP);
157 && graph_dump_format != no_graph)
159 /* If we've not initialized the files, do so now. */
160 if (initializing_dump)
161 clean_graph_dump_file (dump_file_name);
163 print_rtl_graph_with_bb (dump_file_name, insns);
167 func (dump_file, insns);
169 dump_end (index, dump_file);
170 free ((char *) dump_file_name);
173 dump_file_name = NULL;
174 timevar_pop (TV_DUMP);
177 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
180 This does nothing for local (non-static) variables, unless the
181 variable is a register variable with DECL_ASSEMBLER_NAME set. In
182 that case, or if the variable is not an automatic, it sets up the
183 RTL and outputs any assembler code (label definition, storage
184 allocation and initialization).
186 DECL is the declaration. TOP_LEVEL is nonzero
187 if this declaration is not within a function. */
190 rest_of_decl_compilation (tree decl,
194 /* We deferred calling assemble_alias so that we could collect
195 other attributes such as visibility. Emit the alias now. */
198 alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
201 alias = TREE_VALUE (TREE_VALUE (alias));
202 alias = get_identifier (TREE_STRING_POINTER (alias));
203 assemble_alias (decl, alias);
207 /* Can't defer this, because it needs to happen before any
208 later function definitions are processed. */
209 if (DECL_REGISTER (decl) && DECL_ASSEMBLER_NAME_SET_P (decl))
210 make_decl_rtl (decl);
212 /* Forward declarations for nested functions are not "external",
213 but we need to treat them as if they were. */
214 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
215 || TREE_CODE (decl) == FUNCTION_DECL)
217 timevar_push (TV_VARCONST);
219 /* Don't output anything when a tentative file-scope definition
220 is seen. But at end of compilation, do output code for them.
222 We do output all variables when unit-at-a-time is active and rely on
223 callgraph code to defer them except for forward declarations
224 (see gcc.c-torture/compile/920624-1.c) */
226 || !DECL_DEFER_OUTPUT (decl)
227 || DECL_INITIAL (decl))
228 && !DECL_EXTERNAL (decl))
230 if (flag_unit_at_a_time && !cgraph_global_info_ready
231 && TREE_CODE (decl) != FUNCTION_DECL && top_level)
232 cgraph_varpool_finalize_decl (decl);
234 assemble_variable (decl, top_level, at_end, 0);
237 #ifdef ASM_FINISH_DECLARE_OBJECT
238 if (decl == last_assemble_variable_decl)
240 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
245 timevar_pop (TV_VARCONST);
247 else if (TREE_CODE (decl) == TYPE_DECL)
249 timevar_push (TV_SYMOUT);
250 debug_hooks->type_decl (decl, !top_level);
251 timevar_pop (TV_SYMOUT);
254 /* Let cgraph know about the existence of variables. */
255 if (TREE_CODE (decl) == VAR_DECL && !DECL_EXTERNAL (decl))
256 cgraph_varpool_node (decl);
259 /* Called after finishing a record, union or enumeral type. */
262 rest_of_type_compilation (tree type, int toplev)
264 /* Avoid confusing the debug information machinery when there are
266 if (errorcount != 0 || sorrycount != 0)
269 timevar_push (TV_SYMOUT);
270 debug_hooks->type_decl (TYPE_STUB_DECL (type), !toplev);
271 timevar_pop (TV_SYMOUT);
274 /* Turn the RTL into assembly. */
276 rest_of_handle_final (void)
278 timevar_push (TV_FINAL);
283 /* Get the function's name, as described by its RTL. This may be
284 different from the DECL_NAME name used in the source file. */
286 x = DECL_RTL (current_function_decl);
287 gcc_assert (MEM_P (x));
289 gcc_assert (GET_CODE (x) == SYMBOL_REF);
290 fnname = XSTR (x, 0);
292 assemble_start_function (current_function_decl, fnname);
293 final_start_function (get_insns (), asm_out_file, optimize);
294 final (get_insns (), asm_out_file, optimize);
295 final_end_function ();
297 #ifdef TARGET_UNWIND_INFO
298 /* ??? The IA-64 ".handlerdata" directive must be issued before
299 the ".endp" directive that closes the procedure descriptor. */
300 output_function_exception_table ();
303 assemble_end_function (current_function_decl, fnname);
305 #ifndef TARGET_UNWIND_INFO
306 /* Otherwise, it feels unclean to switch sections in the middle. */
307 output_function_exception_table ();
310 user_defined_section_attribute = false;
313 fflush (asm_out_file);
315 /* Release all memory allocated by flow. */
316 free_basic_block_vars ();
319 /* Write DBX symbols if requested. */
321 /* Note that for those inline functions where we don't initially
322 know for certain that we will be generating an out-of-line copy,
323 the first invocation of this routine (rest_of_compilation) will
324 skip over this code by doing a `goto exit_rest_of_compilation;'.
325 Later on, wrapup_global_declarations will (indirectly) call
326 rest_of_compilation again for those inline functions that need
327 to have out-of-line copies generated. During that call, we
328 *will* be routed past here. */
330 timevar_push (TV_SYMOUT);
331 (*debug_hooks->function_decl) (current_function_decl);
332 if (unlikely_text_section_name)
333 free (unlikely_text_section_name);
334 timevar_pop (TV_SYMOUT);
337 timevar_pop (TV_FINAL);
341 /* Run delay slot optimization. */
343 rest_of_handle_delay_slots (void)
345 timevar_push (TV_DBR_SCHED);
346 open_dump_file (DFI_dbr, current_function_decl);
348 dbr_schedule (get_insns (), dump_file);
350 close_dump_file (DFI_dbr, print_rtl, get_insns ());
354 timevar_pop (TV_DBR_SCHED);
359 /* Convert register usage from flat register file usage to a stack
362 rest_of_handle_stack_regs (void)
364 #if defined (HAVE_ATTR_length)
365 /* If flow2 creates new instructions which need splitting
366 and scheduling after reload is not done, they might not be
367 split until final which doesn't allow splitting
368 if HAVE_ATTR_length. */
369 #ifdef INSN_SCHEDULING
370 if (optimize && !flag_schedule_insns_after_reload)
375 timevar_push (TV_SHORTEN_BRANCH);
377 timevar_pop (TV_SHORTEN_BRANCH);
381 timevar_push (TV_REG_STACK);
382 open_dump_file (DFI_stack, current_function_decl);
384 if (reg_to_stack (dump_file) && optimize)
386 if (cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK
387 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0))
388 && (flag_reorder_blocks || flag_reorder_blocks_and_partition))
390 reorder_basic_blocks (0);
391 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK);
395 close_dump_file (DFI_stack, print_rtl_with_bb, get_insns ());
398 timevar_pop (TV_REG_STACK);
402 /* Track the variables, i.e. compute where the variable is stored at each position in function. */
404 rest_of_handle_variable_tracking (void)
406 timevar_push (TV_VAR_TRACKING);
407 open_dump_file (DFI_vartrack, current_function_decl);
409 variable_tracking_main ();
411 close_dump_file (DFI_vartrack, print_rtl_with_bb, get_insns ());
412 timevar_pop (TV_VAR_TRACKING);
415 /* Machine dependent reorg pass. */
417 rest_of_handle_machine_reorg (void)
419 timevar_push (TV_MACH_DEP);
420 open_dump_file (DFI_mach, current_function_decl);
422 targetm.machine_dependent_reorg ();
424 close_dump_file (DFI_mach, print_rtl, get_insns ());
427 timevar_pop (TV_MACH_DEP);
431 /* Run old register allocator. Return TRUE if we must exit
432 rest_of_compilation upon return. */
434 rest_of_handle_old_regalloc (void)
439 timevar_push (TV_LOCAL_ALLOC);
440 open_dump_file (DFI_lreg, current_function_decl);
442 /* Allocate the reg_renumber array. */
443 allocate_reg_info (max_regno, FALSE, TRUE);
445 /* And the reg_equiv_memory_loc array. */
446 VARRAY_GROW (reg_equiv_memory_loc_varray, max_regno);
447 reg_equiv_memory_loc = &VARRAY_RTX (reg_equiv_memory_loc_varray, 0);
449 allocate_initial_values (reg_equiv_memory_loc);
451 regclass (get_insns (), max_reg_num (), dump_file);
452 rebuild_notes = local_alloc ();
454 timevar_pop (TV_LOCAL_ALLOC);
456 /* Local allocation may have turned an indirect jump into a direct
457 jump. If so, we must rebuild the JUMP_LABEL fields of jumping
461 timevar_push (TV_JUMP);
463 rebuild_jump_labels (get_insns ());
464 purge_all_dead_edges (0);
465 delete_unreachable_blocks ();
467 timevar_pop (TV_JUMP);
470 if (dump_enabled_p (DFI_lreg))
472 timevar_push (TV_DUMP);
473 dump_flow_info (dump_file);
474 dump_local_alloc (dump_file);
475 timevar_pop (TV_DUMP);
478 close_dump_file (DFI_lreg, print_rtl_with_bb, get_insns ());
482 timevar_push (TV_GLOBAL_ALLOC);
483 open_dump_file (DFI_greg, current_function_decl);
485 /* If optimizing, allocate remaining pseudo-regs. Do the reload
486 pass fixing up any insns that are invalid. */
489 failure = global_alloc (dump_file);
492 build_insn_chain (get_insns ());
493 failure = reload (get_insns (), 0);
496 if (dump_enabled_p (DFI_greg))
498 timevar_push (TV_DUMP);
499 dump_global_regs (dump_file);
500 timevar_pop (TV_DUMP);
502 close_dump_file (DFI_greg, print_rtl_with_bb, get_insns ());
507 timevar_pop (TV_GLOBAL_ALLOC);
512 /* Run the regrename and cprop passes. */
514 rest_of_handle_regrename (void)
516 timevar_push (TV_RENAME_REGISTERS);
517 open_dump_file (DFI_rnreg, current_function_decl);
519 if (flag_rename_registers)
520 regrename_optimize ();
521 if (flag_cprop_registers)
522 copyprop_hardreg_forward ();
524 close_dump_file (DFI_rnreg, print_rtl_with_bb, get_insns ());
525 timevar_pop (TV_RENAME_REGISTERS);
528 /* Reorder basic blocks. */
530 rest_of_handle_reorder_blocks (void)
533 unsigned int liveness_flags;
535 open_dump_file (DFI_bbro, current_function_decl);
537 /* Last attempt to optimize CFG, as scheduling, peepholing and insn
538 splitting possibly introduced more crossjumping opportunities. */
539 liveness_flags = (!HAVE_conditional_execution ? CLEANUP_UPDATE_LIFE : 0);
540 changed = cleanup_cfg (CLEANUP_EXPENSIVE | liveness_flags);
542 if (flag_sched2_use_traces && flag_schedule_insns_after_reload)
543 tracer (liveness_flags);
544 if (flag_reorder_blocks || flag_reorder_blocks_and_partition)
545 reorder_basic_blocks (liveness_flags);
546 if (flag_reorder_blocks || flag_reorder_blocks_and_partition
547 || (flag_sched2_use_traces && flag_schedule_insns_after_reload))
548 changed |= cleanup_cfg (CLEANUP_EXPENSIVE | liveness_flags);
550 /* On conditional execution targets we can not update the life cheaply, so
551 we deffer the updating to after both cleanups. This may lose some cases
552 but should not be terribly bad. */
553 if (changed && HAVE_conditional_execution)
554 update_life_info (NULL, UPDATE_LIFE_GLOBAL_RM_NOTES,
556 close_dump_file (DFI_bbro, print_rtl_with_bb, get_insns ());
559 /* Partition hot and cold basic blocks. */
561 rest_of_handle_partition_blocks (void)
564 partition_hot_cold_basic_blocks ();
565 allocate_reg_life_data ();
566 update_life_info (NULL, UPDATE_LIFE_GLOBAL_RM_NOTES,
567 PROP_LOG_LINKS | PROP_REG_INFO | PROP_DEATH_NOTES);
571 #ifdef INSN_SCHEDULING
572 /* Run instruction scheduler. */
573 /* Perform SMS module scheduling. */
575 rest_of_handle_sms (void)
580 timevar_push (TV_SMS);
581 open_dump_file (DFI_sms, current_function_decl);
583 /* We want to be able to create new pseudos. */
585 /* Collect loop information to be used in SMS. */
586 cfg_layout_initialize (CLEANUP_UPDATE_LIFE);
587 sms_schedule (dump_file);
588 close_dump_file (DFI_sms, print_rtl, get_insns ());
590 /* Update the life information, because we add pseudos. */
591 max_regno = max_reg_num ();
592 allocate_reg_info (max_regno, FALSE, FALSE);
593 blocks = sbitmap_alloc (last_basic_block);
594 sbitmap_ones (blocks);
595 update_life_info (blocks, UPDATE_LIFE_GLOBAL_RM_NOTES,
598 | PROP_KILL_DEAD_CODE
599 | PROP_SCAN_DEAD_CODE));
603 /* Finalize layout changes. */
605 if (bb->next_bb != EXIT_BLOCK_PTR)
606 bb->rbi->next = bb->next_bb;
607 cfg_layout_finalize ();
608 free_dominance_info (CDI_DOMINATORS);
610 timevar_pop (TV_SMS);
613 /* Run instruction scheduler. */
615 rest_of_handle_sched (void)
617 timevar_push (TV_SCHED);
619 /* Print function header into sched dump now
620 because doing the sched analysis makes some of the dump. */
621 open_dump_file (DFI_sched, current_function_decl);
623 /* Do control and data sched analysis,
624 and write some of the results to dump file. */
626 schedule_insns (dump_file);
628 close_dump_file (DFI_sched, print_rtl_with_bb, get_insns ());
631 timevar_pop (TV_SCHED);
634 /* Run second scheduling pass after reload. */
636 rest_of_handle_sched2 (void)
638 timevar_push (TV_SCHED2);
639 open_dump_file (DFI_sched2, current_function_decl);
641 /* Do control and data sched analysis again,
642 and write some more of the results to dump file. */
646 if (flag_sched2_use_superblocks || flag_sched2_use_traces)
648 schedule_ebbs (dump_file);
649 /* No liveness updating code yet, but it should be easy to do.
650 reg-stack recomputes the liveness when needed for now. */
651 count_or_remove_death_notes (NULL, 1);
652 cleanup_cfg (CLEANUP_EXPENSIVE);
655 schedule_insns (dump_file);
657 close_dump_file (DFI_sched2, print_rtl_with_bb, get_insns ());
661 timevar_pop (TV_SCHED2);
666 rest_of_handle_gcse2 (void)
668 timevar_push (TV_GCSE_AFTER_RELOAD);
669 open_dump_file (DFI_gcse2, current_function_decl);
671 gcse_after_reload_main (get_insns ());
672 rebuild_jump_labels (get_insns ());
673 delete_trivially_dead_insns (get_insns (), max_reg_num ());
674 close_dump_file (DFI_gcse2, print_rtl_with_bb, get_insns ());
678 #ifdef ENABLE_CHECKING
682 timevar_pop (TV_GCSE_AFTER_RELOAD);
685 /* Register allocation pre-pass, to reduce number of moves necessary
686 for two-address machines. */
688 rest_of_handle_regmove (void)
690 timevar_push (TV_REGMOVE);
691 open_dump_file (DFI_regmove, current_function_decl);
693 regmove_optimize (get_insns (), max_reg_num (), dump_file);
695 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
696 close_dump_file (DFI_regmove, print_rtl_with_bb, get_insns ());
699 timevar_pop (TV_REGMOVE);
704 rest_of_handle_tracer (void)
706 open_dump_file (DFI_tracer, current_function_decl);
708 dump_flow_info (dump_file);
710 cleanup_cfg (CLEANUP_EXPENSIVE);
711 reg_scan (get_insns (), max_reg_num ());
712 close_dump_file (DFI_tracer, print_rtl_with_bb, get_insns ());
715 /* If-conversion and CFG cleanup. */
717 rest_of_handle_if_conversion (void)
719 timevar_push (TV_IFCVT);
720 open_dump_file (DFI_ce1, current_function_decl);
722 if (flag_if_conversion)
725 dump_flow_info (dump_file);
726 cleanup_cfg (CLEANUP_EXPENSIVE);
727 reg_scan (get_insns (), max_reg_num ());
731 timevar_push (TV_JUMP);
732 cleanup_cfg (CLEANUP_EXPENSIVE);
733 reg_scan (get_insns (), max_reg_num ());
734 timevar_pop (TV_JUMP);
736 close_dump_file (DFI_ce1, print_rtl_with_bb, get_insns ());
737 timevar_pop (TV_IFCVT);
740 /* Rerun if-conversion, as combine may have simplified things enough
741 to now meet sequence length restrictions. */
743 rest_of_handle_if_after_combine (void)
745 timevar_push (TV_IFCVT);
746 open_dump_file (DFI_ce2, current_function_decl);
752 close_dump_file (DFI_ce2, print_rtl_with_bb, get_insns ());
753 timevar_pop (TV_IFCVT);
757 rest_of_handle_if_after_reload (void)
759 timevar_push (TV_IFCVT2);
760 open_dump_file (DFI_ce3, current_function_decl);
762 /* Last attempt to optimize CFG, as scheduling, peepholing and insn
763 splitting possibly introduced more crossjumping opportunities. */
764 cleanup_cfg (CLEANUP_EXPENSIVE
765 | CLEANUP_UPDATE_LIFE
766 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0));
767 if (flag_if_conversion2)
769 close_dump_file (DFI_ce3, print_rtl_with_bb, get_insns ());
770 timevar_pop (TV_IFCVT2);
774 rest_of_handle_web (void)
776 open_dump_file (DFI_web, current_function_decl);
777 timevar_push (TV_WEB);
779 delete_trivially_dead_insns (get_insns (), max_reg_num ());
780 cleanup_cfg (CLEANUP_EXPENSIVE);
782 timevar_pop (TV_WEB);
783 close_dump_file (DFI_web, print_rtl_with_bb, get_insns ());
784 reg_scan (get_insns (), max_reg_num ());
787 /* Do branch profiling and static profile estimation passes. */
789 rest_of_handle_branch_prob (void)
793 timevar_push (TV_BRANCH_PROB);
794 open_dump_file (DFI_bp, current_function_decl);
796 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
799 /* Discover and record the loop depth at the head of each basic
800 block. The loop infrastructure does the real job for us. */
801 flow_loops_find (&loops);
804 flow_loops_dump (&loops, dump_file, NULL, 0);
806 /* Estimate using heuristics if no profiling info is available. */
807 if (flag_guess_branch_prob)
808 estimate_probability (&loops);
810 flow_loops_free (&loops);
811 free_dominance_info (CDI_DOMINATORS);
812 close_dump_file (DFI_bp, print_rtl_with_bb, get_insns ());
813 timevar_pop (TV_BRANCH_PROB);
816 /* Do optimizations based on expression value profiles. */
818 rest_of_handle_value_profile_transformations (void)
820 open_dump_file (DFI_vpt, current_function_decl);
821 timevar_push (TV_VPT);
823 if (value_profile_transformations ())
824 cleanup_cfg (CLEANUP_EXPENSIVE);
826 timevar_pop (TV_VPT);
827 close_dump_file (DFI_vpt, print_rtl_with_bb, get_insns ());
830 /* Do control and data flow analysis; write some of the results to the
833 rest_of_handle_cfg (void)
835 open_dump_file (DFI_cfg, current_function_decl);
837 dump_flow_info (dump_file);
839 cleanup_cfg (CLEANUP_EXPENSIVE
840 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
842 /* It may make more sense to mark constant functions after dead code is
843 eliminated by life_analysis, but we need to do it early, as -fprofile-arcs
844 may insert code making function non-constant, but we still must consider
845 it as constant, otherwise -fbranch-probabilities will not read data back.
847 life_analysis rarely eliminates modification of external memory.
849 FIXME: now with tree based profiling we are in the trap described above
850 again. It seems to be easiest to disable the optimization for time
851 being before the problem is either solved by moving the transformation
852 to the IPA level (we need the CFG for this) or the very early optimization
853 passes are made to ignore the const/pure flags so code does not change. */
855 && (!flag_tree_based_profiling
856 || (!profile_arc_flag && !flag_branch_probabilities)))
858 /* Alias analysis depends on this information and mark_constant_function
859 depends on alias analysis. */
860 reg_scan (get_insns (), max_reg_num ());
861 mark_constant_function ();
864 close_dump_file (DFI_cfg, print_rtl_with_bb, get_insns ());
867 /* Perform jump bypassing and control flow optimizations. */
869 rest_of_handle_jump_bypass (void)
871 timevar_push (TV_BYPASS);
872 open_dump_file (DFI_bypass, current_function_decl);
874 cleanup_cfg (CLEANUP_EXPENSIVE);
875 reg_scan (get_insns (), max_reg_num ());
877 if (bypass_jumps (dump_file))
879 rebuild_jump_labels (get_insns ());
880 cleanup_cfg (CLEANUP_EXPENSIVE);
881 delete_trivially_dead_insns (get_insns (), max_reg_num ());
884 close_dump_file (DFI_bypass, print_rtl_with_bb, get_insns ());
885 timevar_pop (TV_BYPASS);
889 #ifdef ENABLE_CHECKING
894 /* Try combining insns through substitution. */
896 rest_of_handle_combine (void)
898 int rebuild_jump_labels_after_combine = 0;
900 timevar_push (TV_COMBINE);
901 open_dump_file (DFI_combine, current_function_decl);
903 rebuild_jump_labels_after_combine
904 = combine_instructions (get_insns (), max_reg_num ());
906 /* Combining insns may have turned an indirect jump into a
907 direct jump. Rebuild the JUMP_LABEL fields of jumping
909 if (rebuild_jump_labels_after_combine)
911 timevar_push (TV_JUMP);
912 rebuild_jump_labels (get_insns ());
913 timevar_pop (TV_JUMP);
915 delete_dead_jumptables ();
916 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
919 close_dump_file (DFI_combine, print_rtl_with_bb, get_insns ());
920 timevar_pop (TV_COMBINE);
925 /* Perform life analysis. */
927 rest_of_handle_life (void)
929 open_dump_file (DFI_life, current_function_decl);
932 #ifdef ENABLE_CHECKING
935 life_analysis (dump_file, PROP_FINAL);
937 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE | CLEANUP_LOG_LINKS
938 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
942 setjmp_vars_warning (DECL_INITIAL (current_function_decl));
943 setjmp_args_warning ();
948 if (initialize_uninitialized_subregs ())
950 /* Insns were inserted, and possibly pseudos created, so
951 things might look a bit different. */
952 allocate_reg_life_data ();
953 update_life_info (NULL, UPDATE_LIFE_GLOBAL_RM_NOTES,
954 PROP_LOG_LINKS | PROP_REG_INFO | PROP_DEATH_NOTES);
960 close_dump_file (DFI_life, print_rtl_with_bb, get_insns ());
965 /* Perform common subexpression elimination. Nonzero value from
966 `cse_main' means that jumps were simplified and some code may now
967 be unreachable, so do jump optimization again. */
969 rest_of_handle_cse (void)
973 open_dump_file (DFI_cse, current_function_decl);
975 dump_flow_info (dump_file);
976 timevar_push (TV_CSE);
978 reg_scan (get_insns (), max_reg_num ());
980 tem = cse_main (get_insns (), max_reg_num (), dump_file);
982 rebuild_jump_labels (get_insns ());
983 if (purge_all_dead_edges (0))
984 delete_unreachable_blocks ();
986 delete_trivially_dead_insns (get_insns (), max_reg_num ());
988 /* If we are not running more CSE passes, then we are no longer
989 expecting CSE to be run. But always rerun it in a cheap mode. */
990 cse_not_expected = !flag_rerun_cse_after_loop && !flag_gcse;
993 delete_dead_jumptables ();
995 if (tem || optimize > 1)
996 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
998 timevar_pop (TV_CSE);
999 close_dump_file (DFI_cse, print_rtl_with_bb, get_insns ());
1004 /* Run second CSE pass after loop optimizations. */
1006 rest_of_handle_cse2 (void)
1010 timevar_push (TV_CSE2);
1011 open_dump_file (DFI_cse2, current_function_decl);
1013 dump_flow_info (dump_file);
1014 /* CFG is no longer maintained up-to-date. */
1015 tem = cse_main (get_insns (), max_reg_num (), dump_file);
1017 /* Run a pass to eliminate duplicated assignments to condition code
1018 registers. We have to run this after bypass_jumps, because it
1019 makes it harder for that pass to determine whether a jump can be
1021 cse_condition_code_reg ();
1023 purge_all_dead_edges (0);
1024 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1028 timevar_push (TV_JUMP);
1029 rebuild_jump_labels (get_insns ());
1030 delete_dead_jumptables ();
1031 cleanup_cfg (CLEANUP_EXPENSIVE);
1032 timevar_pop (TV_JUMP);
1034 reg_scan (get_insns (), max_reg_num ());
1035 close_dump_file (DFI_cse2, print_rtl_with_bb, get_insns ());
1036 timevar_pop (TV_CSE2);
1041 /* Perform global cse. */
1043 rest_of_handle_gcse (void)
1045 int save_csb, save_cfj;
1048 timevar_push (TV_GCSE);
1049 open_dump_file (DFI_gcse, current_function_decl);
1051 tem = gcse_main (get_insns (), dump_file);
1052 rebuild_jump_labels (get_insns ());
1053 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1055 save_csb = flag_cse_skip_blocks;
1056 save_cfj = flag_cse_follow_jumps;
1057 flag_cse_skip_blocks = flag_cse_follow_jumps = 0;
1059 /* If -fexpensive-optimizations, re-run CSE to clean up things done
1061 if (flag_expensive_optimizations)
1063 timevar_push (TV_CSE);
1064 reg_scan (get_insns (), max_reg_num ());
1065 tem2 = cse_main (get_insns (), max_reg_num (), dump_file);
1066 purge_all_dead_edges (0);
1067 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1068 timevar_pop (TV_CSE);
1069 cse_not_expected = !flag_rerun_cse_after_loop;
1072 /* If gcse or cse altered any jumps, rerun jump optimizations to clean
1076 timevar_push (TV_JUMP);
1077 rebuild_jump_labels (get_insns ());
1078 delete_dead_jumptables ();
1079 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
1080 timevar_pop (TV_JUMP);
1083 close_dump_file (DFI_gcse, print_rtl_with_bb, get_insns ());
1084 timevar_pop (TV_GCSE);
1087 flag_cse_skip_blocks = save_csb;
1088 flag_cse_follow_jumps = save_cfj;
1089 #ifdef ENABLE_CHECKING
1090 verify_flow_info ();
1094 /* Move constant computations out of loops. */
1096 rest_of_handle_loop_optimize (void)
1100 timevar_push (TV_LOOP);
1101 open_dump_file (DFI_loop, current_function_decl);
1103 /* CFG is no longer maintained up-to-date. */
1104 free_bb_for_insn ();
1105 profile_status = PROFILE_ABSENT;
1107 do_prefetch = flag_prefetch_loop_arrays ? LOOP_PREFETCH : 0;
1109 if (flag_rerun_loop_opt)
1111 cleanup_barriers ();
1113 /* We only want to perform unrolling once. */
1114 loop_optimize (get_insns (), dump_file, 0);
1116 /* The first call to loop_optimize makes some instructions
1117 trivially dead. We delete those instructions now in the
1118 hope that doing so will make the heuristics in loop work
1119 better and possibly speed up compilation. */
1120 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1122 /* The regscan pass is currently necessary as the alias
1123 analysis code depends on this information. */
1124 reg_scan (get_insns (), max_reg_num ());
1126 cleanup_barriers ();
1127 loop_optimize (get_insns (), dump_file, do_prefetch);
1129 /* Loop can create trivially dead instructions. */
1130 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1131 find_basic_blocks (get_insns ());
1132 close_dump_file (DFI_loop, print_rtl, get_insns ());
1133 timevar_pop (TV_LOOP);
1138 /* Perform loop optimizations. It might be better to do them a bit
1139 sooner, but we want the profile feedback to work more
1142 rest_of_handle_loop2 (void)
1144 struct loops *loops;
1147 if (!flag_move_loop_invariants
1148 && !flag_unswitch_loops
1150 && !flag_unroll_loops
1151 && !flag_branch_on_count_reg)
1154 timevar_push (TV_LOOP);
1155 open_dump_file (DFI_loop2, current_function_decl);
1157 dump_flow_info (dump_file);
1159 /* Initialize structures for layout changes. */
1160 cfg_layout_initialize (0);
1162 loops = loop_optimizer_init (dump_file);
1166 /* The optimizations: */
1167 if (flag_move_loop_invariants)
1168 move_loop_invariants (loops);
1170 if (flag_unswitch_loops)
1171 unswitch_loops (loops);
1173 if (flag_peel_loops || flag_unroll_loops)
1174 unroll_and_peel_loops (loops,
1175 (flag_peel_loops ? UAP_PEEL : 0) |
1176 (flag_unroll_loops ? UAP_UNROLL : 0) |
1177 (flag_unroll_all_loops ? UAP_UNROLL_ALL : 0));
1179 #ifdef HAVE_doloop_end
1180 if (flag_branch_on_count_reg && HAVE_doloop_end)
1181 doloop_optimize_loops (loops);
1182 #endif /* HAVE_doloop_end */
1184 loop_optimizer_finalize (loops, dump_file);
1187 free_dominance_info (CDI_DOMINATORS);
1189 /* Finalize layout changes. */
1191 if (bb->next_bb != EXIT_BLOCK_PTR)
1192 bb->rbi->next = bb->next_bb;
1193 cfg_layout_finalize ();
1195 cleanup_cfg (CLEANUP_EXPENSIVE);
1196 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1197 reg_scan (get_insns (), max_reg_num ());
1199 dump_flow_info (dump_file);
1200 close_dump_file (DFI_loop2, print_rtl_with_bb, get_insns ());
1201 timevar_pop (TV_LOOP);
1206 rest_of_handle_branch_target_load_optimize (void)
1208 static int warned = 0;
1210 /* Leave this a warning for now so that it is possible to experiment
1211 with running this pass twice. In 3.6, we should either make this
1212 an error, or use separate dump files. */
1213 if (flag_branch_target_load_optimize
1214 && flag_branch_target_load_optimize2
1217 warning ("branch target register load optimization is not intended "
1223 open_dump_file (DFI_branch_target_load, current_function_decl);
1224 branch_target_load_optimize (epilogue_completed);
1225 close_dump_file (DFI_branch_target_load, print_rtl_with_bb, get_insns ());
1229 #ifdef OPTIMIZE_MODE_SWITCHING
1231 rest_of_handle_mode_switching (void)
1233 timevar_push (TV_MODE_SWITCH);
1236 optimize_mode_switching (NULL);
1239 timevar_pop (TV_MODE_SWITCH);
1244 rest_of_handle_jump (void)
1248 timevar_push (TV_JUMP);
1249 open_dump_file (DFI_sibling, current_function_decl);
1251 delete_unreachable_blocks ();
1252 #ifdef ENABLE_CHECKING
1253 verify_flow_info ();
1256 if (cfun->tail_call_emit)
1257 fixup_tail_calls ();
1259 close_dump_file (DFI_sibling, print_rtl, get_insns ());
1260 timevar_pop (TV_JUMP);
1264 rest_of_handle_eh (void)
1266 insn_locators_initialize ();
1267 /* Complete generation of exception handling code. */
1270 timevar_push (TV_JUMP);
1271 open_dump_file (DFI_eh, current_function_decl);
1273 cleanup_cfg (CLEANUP_PRE_LOOP | CLEANUP_NO_INSN_DEL);
1275 finish_eh_generation ();
1277 cleanup_cfg (CLEANUP_PRE_LOOP | CLEANUP_NO_INSN_DEL);
1279 close_dump_file (DFI_eh, print_rtl, get_insns ());
1280 timevar_pop (TV_JUMP);
1285 rest_of_handle_stack_adjustments (void)
1287 life_analysis (dump_file, PROP_POSTRELOAD);
1288 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE
1289 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0));
1291 /* This is kind of a heuristic. We need to run combine_stack_adjustments
1292 even for machines with possibly nonzero RETURN_POPS_ARGS
1293 and ACCUMULATE_OUTGOING_ARGS. We expect that only ports having
1294 push instructions will have popping returns. */
1295 #ifndef PUSH_ROUNDING
1296 if (!ACCUMULATE_OUTGOING_ARGS)
1298 combine_stack_adjustments ();
1302 rest_of_handle_flow2 (void)
1304 timevar_push (TV_FLOW2);
1305 open_dump_file (DFI_flow2, current_function_decl);
1307 /* Re-create the death notes which were deleted during reload. */
1308 #ifdef ENABLE_CHECKING
1309 verify_flow_info ();
1312 /* If optimizing, then go ahead and split insns now. */
1316 split_all_insns (0);
1318 if (flag_branch_target_load_optimize)
1320 close_dump_file (DFI_flow2, print_rtl_with_bb, get_insns ());
1321 rest_of_handle_branch_target_load_optimize ();
1322 open_dump_file (DFI_flow2, current_function_decl);
1326 cleanup_cfg (CLEANUP_EXPENSIVE);
1328 /* On some machines, the prologue and epilogue code, or parts thereof,
1329 can be represented as RTL. Doing so lets us schedule insns between
1330 it and the rest of the code and also allows delayed branch
1331 scheduling to operate in the epilogue. */
1332 thread_prologue_and_epilogue_insns (get_insns ());
1333 epilogue_completed = 1;
1336 rest_of_handle_stack_adjustments ();
1338 flow2_completed = 1;
1340 close_dump_file (DFI_flow2, print_rtl_with_bb, get_insns ());
1341 timevar_pop (TV_FLOW2);
1348 rest_of_handle_jump2 (void)
1350 open_dump_file (DFI_jump, current_function_decl);
1352 /* Always do one jump optimization pass to ensure that JUMP_LABEL fields
1353 are initialized and to compute whether control can drop off the end
1356 timevar_push (TV_JUMP);
1357 /* Turn NOTE_INSN_EXPECTED_VALUE into REG_BR_PROB. Do this
1358 before jump optimization switches branch directions. */
1359 if (flag_guess_branch_prob)
1360 expected_value_to_br_prob ();
1362 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1363 reg_scan (get_insns (), max_reg_num ());
1365 dump_flow_info (dump_file);
1366 cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_PRE_LOOP
1367 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
1369 create_loop_notes ();
1371 purge_line_number_notes (get_insns ());
1374 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
1376 /* Jump optimization, and the removal of NULL pointer checks, may
1377 have reduced the number of instructions substantially. CSE, and
1378 future passes, allocate arrays whose dimensions involve the
1379 maximum instruction UID, so if we can reduce the maximum UID
1380 we'll save big on memory. */
1381 renumber_insns (dump_file);
1383 close_dump_file (DFI_jump, print_rtl_with_bb, get_insns ());
1384 timevar_pop (TV_JUMP);
1389 #ifdef HAVE_peephole2
1391 rest_of_handle_peephole2 (void)
1393 timevar_push (TV_PEEPHOLE2);
1394 open_dump_file (DFI_peephole2, current_function_decl);
1396 peephole2_optimize (dump_file);
1398 close_dump_file (DFI_peephole2, print_rtl_with_bb, get_insns ());
1399 timevar_pop (TV_PEEPHOLE2);
1404 rest_of_handle_postreload (void)
1406 timevar_push (TV_RELOAD_CSE_REGS);
1407 open_dump_file (DFI_postreload, current_function_decl);
1409 /* Do a very simple CSE pass over just the hard registers. */
1410 reload_cse_regs (get_insns ());
1411 /* reload_cse_regs can eliminate potentially-trapping MEMs.
1412 Remove any EH edges associated with them. */
1413 if (flag_non_call_exceptions)
1414 purge_all_dead_edges (0);
1416 close_dump_file (DFI_postreload, print_rtl_with_bb, get_insns ());
1417 timevar_pop (TV_RELOAD_CSE_REGS);
1421 rest_of_handle_shorten_branches (void)
1423 /* Shorten branches. */
1424 timevar_push (TV_SHORTEN_BRANCH);
1425 shorten_branches (get_insns ());
1426 timevar_pop (TV_SHORTEN_BRANCH);
1430 rest_of_clean_state (void)
1433 coverage_end_function ();
1435 /* It is very important to decompose the RTL instruction chain here:
1436 debug information keeps pointing into CODE_LABEL insns inside the function
1437 body. If these remain pointing to the other insns, we end up preserving
1438 whole RTL chain and attached detailed debug info in memory. */
1439 for (insn = get_insns (); insn; insn = next)
1441 next = NEXT_INSN (insn);
1442 NEXT_INSN (insn) = NULL;
1443 PREV_INSN (insn) = NULL;
1446 /* In case the function was not output,
1447 don't leave any temporary anonymous types
1448 queued up for sdb output. */
1449 #ifdef SDB_DEBUGGING_INFO
1450 if (write_symbols == SDB_DEBUG)
1451 sdbout_types (NULL_TREE);
1454 reload_completed = 0;
1455 epilogue_completed = 0;
1456 flow2_completed = 0;
1459 timevar_push (TV_FINAL);
1461 /* Clear out the insn_length contents now that they are no
1463 init_insn_lengths ();
1465 /* Show no temporary slots allocated. */
1468 free_basic_block_vars ();
1469 free_bb_for_insn ();
1471 timevar_pop (TV_FINAL);
1473 if (targetm.binds_local_p (current_function_decl))
1475 int pref = cfun->preferred_stack_boundary;
1476 if (cfun->stack_alignment_needed > cfun->preferred_stack_boundary)
1477 pref = cfun->stack_alignment_needed;
1478 cgraph_rtl_info (current_function_decl)->preferred_incoming_stack_boundary
1482 /* Make sure volatile mem refs aren't considered valid operands for
1483 arithmetic insns. We must call this here if this is a nested inline
1484 function, since the above code leaves us in the init_recog state
1485 (from final.c), and the function context push/pop code does not
1486 save/restore volatile_ok.
1488 ??? Maybe it isn't necessary for expand_start_function to call this
1489 anymore if we do it here? */
1491 init_recog_no_volatile ();
1493 /* We're done with this function. Free up memory if we can. */
1494 free_after_parsing (cfun);
1495 free_after_compilation (cfun);
1499 /* This function is called from the pass manager in tree-optimize.c
1500 after all tree passes have finished for a single function, and we
1501 have expanded the function body from trees to RTL.
1502 Once we are here, we have decided that we're supposed to output
1503 that function, i.e. that we should write assembler code for it.
1505 We run a series of low-level passes here on the function's RTL
1506 representation. Each pass is called via a rest_of_* function. */
1509 rest_of_compilation (void)
1511 /* If we're emitting a nested function, make sure its parent gets
1512 emitted as well. Doing otherwise confuses debug info. */
1515 for (parent = DECL_CONTEXT (current_function_decl);
1516 parent != NULL_TREE;
1517 parent = get_containing_scope (parent))
1518 if (TREE_CODE (parent) == FUNCTION_DECL)
1519 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (parent)) = 1;
1522 /* We are now committed to emitting code for this function. Do any
1523 preparation, such as emitting abstract debug info for the inline
1524 before it gets mangled by optimization. */
1525 if (cgraph_function_possibly_inlined_p (current_function_decl))
1526 (*debug_hooks->outlining_inline_function) (current_function_decl);
1528 /* Remove any notes we don't need. That will make iterating
1529 over the instruction sequence faster, and allow the garbage
1530 collector to reclaim the memory used by the notes. */
1531 remove_unnecessary_notes ();
1533 /* Initialize some variables used by the optimizers. */
1534 init_function_for_compilation ();
1536 TREE_ASM_WRITTEN (current_function_decl) = 1;
1538 /* Early return if there were errors. We can run afoul of our
1539 consistency checks, and there's not really much point in fixing them. */
1540 if (rtl_dump_and_exit || flag_syntax_only || errorcount || sorrycount)
1541 goto exit_rest_of_compilation;
1543 rest_of_handle_jump ();
1545 rest_of_handle_eh ();
1547 /* Delay emitting hard_reg_initial_value sets until after EH landing pad
1548 generation, which might create new sets. */
1549 emit_initial_value_sets ();
1552 /* If we are doing position-independent code generation, now
1553 is the time to output special prologues and epilogues.
1554 We do not want to do this earlier, because it just clutters
1555 up inline functions with meaningless insns. */
1560 /* Copy any shared structure that should not be shared. */
1563 #ifdef SETJMP_VIA_SAVE_AREA
1564 /* This must be performed before virtual register instantiation.
1565 Please be aware that everything in the compiler that can look
1566 at the RTL up to this point must understand that REG_SAVE_AREA
1567 is just like a use of the REG contained inside. */
1568 if (current_function_calls_alloca)
1569 optimize_save_area_alloca ();
1572 /* Instantiate all virtual registers. */
1573 instantiate_virtual_regs ();
1575 rest_of_handle_jump2 ();
1578 rest_of_handle_cse ();
1583 rest_of_handle_gcse ();
1585 if (flag_loop_optimize)
1586 rest_of_handle_loop_optimize ();
1589 rest_of_handle_jump_bypass ();
1592 timevar_push (TV_FLOW);
1593 rest_of_handle_cfg ();
1595 if (!flag_tree_based_profiling
1596 && (optimize > 0 || profile_arc_flag
1597 || flag_test_coverage || flag_branch_probabilities))
1599 rtl_register_profile_hooks ();
1600 rtl_register_value_prof_hooks ();
1601 rest_of_handle_branch_prob ();
1603 if (flag_branch_probabilities
1604 && flag_profile_values
1605 && (flag_value_profile_transformations
1606 || flag_speculative_prefetching))
1607 rest_of_handle_value_profile_transformations ();
1609 /* Remove the death notes created for vpt. */
1610 if (flag_profile_values)
1611 count_or_remove_death_notes (NULL, 1);
1615 rest_of_handle_if_conversion ();
1617 if (optimize > 0 && flag_tracer)
1618 rest_of_handle_tracer ();
1621 && flag_loop_optimize2)
1622 rest_of_handle_loop2 ();
1624 if (optimize > 0 && flag_web)
1625 rest_of_handle_web ();
1627 if (optimize > 0 && flag_rerun_cse_after_loop)
1628 rest_of_handle_cse2 ();
1630 cse_not_expected = 1;
1632 rest_of_handle_life ();
1633 timevar_pop (TV_FLOW);
1636 rest_of_handle_combine ();
1638 if (optimize > 0 && flag_if_conversion)
1639 rest_of_handle_if_after_combine ();
1641 /* The optimization to partition hot/cold basic blocks into separate
1642 sections of the .o file does not work well with linkonce or with
1643 user defined section attributes. Don't call it if either case
1646 if (flag_reorder_blocks_and_partition
1647 && !DECL_ONE_ONLY (current_function_decl)
1648 && !user_defined_section_attribute)
1649 rest_of_handle_partition_blocks ();
1651 if (optimize > 0 && flag_regmove)
1652 rest_of_handle_regmove ();
1654 /* Do unconditional splitting before register allocation to allow machine
1655 description to add extra information not needed previously. */
1656 split_all_insns (1);
1658 #ifdef OPTIMIZE_MODE_SWITCHING
1659 rest_of_handle_mode_switching ();
1662 /* Any of the several passes since flow1 will have munged register
1663 lifetime data a bit. We need it to be up to date for scheduling
1664 (see handling of reg_known_equiv in init_alias_analysis). */
1665 recompute_reg_usage ();
1667 #ifdef INSN_SCHEDULING
1668 if (optimize > 0 && flag_modulo_sched)
1669 rest_of_handle_sms ();
1671 if (flag_schedule_insns)
1672 rest_of_handle_sched ();
1675 /* Determine if the current function is a leaf before running reload
1676 since this can impact optimizations done by the prologue and
1677 epilogue thus changing register elimination offsets. */
1678 current_function_is_leaf = leaf_function_p ();
1680 if (rest_of_handle_old_regalloc ())
1681 goto exit_rest_of_compilation;
1684 rest_of_handle_postreload ();
1686 if (optimize > 0 && flag_gcse_after_reload)
1687 rest_of_handle_gcse2 ();
1689 rest_of_handle_flow2 ();
1691 #ifdef HAVE_peephole2
1692 if (optimize > 0 && flag_peephole2)
1693 rest_of_handle_peephole2 ();
1697 rest_of_handle_if_after_reload ();
1701 if (flag_rename_registers || flag_cprop_registers)
1702 rest_of_handle_regrename ();
1704 rest_of_handle_reorder_blocks ();
1707 if (flag_branch_target_load_optimize2)
1708 rest_of_handle_branch_target_load_optimize ();
1710 #ifdef LEAF_REGISTERS
1711 current_function_uses_only_leaf_regs
1712 = optimize > 0 && only_leaf_regs_used () && leaf_function_p ();
1715 #ifdef INSN_SCHEDULING
1716 if (optimize > 0 && flag_schedule_insns_after_reload)
1717 rest_of_handle_sched2 ();
1721 rest_of_handle_stack_regs ();
1724 compute_alignments ();
1726 /* Aggressively duplicate basic blocks ending in computed gotos to the
1727 tails of their predecessors, unless we are optimizing for size. */
1728 if (flag_expensive_optimizations && !optimize_size)
1729 duplicate_computed_gotos ();
1731 if (flag_var_tracking)
1732 rest_of_handle_variable_tracking ();
1734 /* CFG is no longer maintained up-to-date. */
1735 free_bb_for_insn ();
1737 if (targetm.machine_dependent_reorg != 0)
1738 rest_of_handle_machine_reorg ();
1740 purge_line_number_notes (get_insns ());
1741 cleanup_barriers ();
1744 if (flag_delayed_branch)
1745 rest_of_handle_delay_slots ();
1748 #if defined (HAVE_ATTR_length) && !defined (STACK_REGS)
1749 timevar_push (TV_SHORTEN_BRANCH);
1750 split_all_insns_noflow ();
1751 timevar_pop (TV_SHORTEN_BRANCH);
1754 convert_to_eh_region_ranges ();
1756 rest_of_handle_shorten_branches ();
1758 set_nothrow_function_flags ();
1760 rest_of_handle_final ();
1762 exit_rest_of_compilation:
1764 rest_of_clean_state ();
1768 finish_optimization_passes (void)
1770 enum tree_dump_index i;
1771 struct dump_file_info *dfi;
1774 timevar_push (TV_DUMP);
1775 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
1777 open_dump_file (DFI_bp, NULL);
1779 close_dump_file (DFI_bp, NULL, NULL_RTX);
1782 if (optimize > 0 && open_dump_file (DFI_combine, NULL))
1784 dump_combine_total_stats (dump_file);
1785 close_dump_file (DFI_combine, NULL, NULL_RTX);
1788 /* Do whatever is necessary to finish printing the graphs. */
1789 if (graph_dump_format != no_graph)
1790 for (i = DFI_MIN; (dfi = get_dump_file_info (i)) != NULL; ++i)
1791 if (dump_initialized_p (i)
1792 && (dfi->flags & TDF_RTL) != 0
1793 && (name = get_dump_file_name (i)) != NULL)
1795 finish_graph_dump_file (name);
1799 timevar_pop (TV_DUMP);
1802 struct tree_opt_pass pass_rest_of_compilation =
1806 rest_of_compilation, /* execute */
1809 0, /* static_pass_number */
1810 TV_REST_OF_COMPILATION, /* tv_id */
1811 PROP_rtl, /* properties_required */
1812 0, /* properties_provided */
1813 PROP_rtl, /* properties_destroyed */
1814 0, /* todo_flags_start */
1815 TODO_ggc_collect, /* todo_flags_finish */