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 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"
66 #include "diagnostic.h"
69 #include "dwarf2asm.h"
70 #include "integrate.h"
74 #include "langhooks.h"
75 #include "cfglayout.h"
77 #include "hosthooks.h"
81 #include "value-prof.h"
82 #include "alloc-pool.h"
83 #include "tree-pass.h"
84 #include "tree-dump.h"
86 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
87 #include "dwarf2out.h"
90 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
94 #ifdef SDB_DEBUGGING_INFO
98 #ifdef XCOFF_DEBUGGING_INFO
99 #include "xcoffout.h" /* Needed for external data
100 declarations for e.g. AIX 4.x. */
103 #ifndef HAVE_conditional_execution
104 #define HAVE_conditional_execution 0
107 /* Format to use to print dumpfile index value */
108 #ifndef DUMPFILE_FORMAT
109 #define DUMPFILE_FORMAT ".%02d."
112 static int initializing_dump = 0;
114 /* Routine to open a dump file. Return true if the dump file is enabled. */
117 open_dump_file (enum tree_dump_index index, tree decl)
119 if (! dump_enabled_p (index))
122 timevar_push (TV_DUMP);
124 gcc_assert (!dump_file);
125 gcc_assert (!dump_file_name);
127 dump_file_name = get_dump_file_name (index);
128 initializing_dump = !dump_initialized_p (index);
129 dump_file = dump_begin (index, NULL);
131 if (dump_file == NULL)
132 fatal_error ("can't open %s: %m", dump_file_name);
135 fprintf (dump_file, "\n;; Function %s%s\n\n",
136 lang_hooks.decl_printable_name (decl, 2),
137 cfun->function_frequency == FUNCTION_FREQUENCY_HOT
139 : cfun->function_frequency == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED
140 ? " (unlikely executed)"
143 timevar_pop (TV_DUMP);
147 /* Routine to close a dump file. */
150 close_dump_file (enum tree_dump_index index,
151 void (*func) (FILE *, rtx),
157 timevar_push (TV_DUMP);
159 && graph_dump_format != no_graph)
161 /* If we've not initialized the files, do so now. */
162 if (initializing_dump)
163 clean_graph_dump_file (dump_file_name);
165 print_rtl_graph_with_bb (dump_file_name, insns);
169 func (dump_file, insns);
171 dump_end (index, dump_file);
172 free ((char *) dump_file_name);
175 dump_file_name = NULL;
176 timevar_pop (TV_DUMP);
179 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
182 This does nothing for local (non-static) variables, unless the
183 variable is a register variable with DECL_ASSEMBLER_NAME set. In
184 that case, or if the variable is not an automatic, it sets up the
185 RTL and outputs any assembler code (label definition, storage
186 allocation and initialization).
188 DECL is the declaration. TOP_LEVEL is nonzero
189 if this declaration is not within a function. */
192 rest_of_decl_compilation (tree decl,
196 /* We deferred calling assemble_alias so that we could collect
197 other attributes such as visibility. Emit the alias now. */
200 alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
203 alias = TREE_VALUE (TREE_VALUE (alias));
204 alias = get_identifier (TREE_STRING_POINTER (alias));
205 assemble_alias (decl, alias);
209 /* Can't defer this, because it needs to happen before any
210 later function definitions are processed. */
211 if (DECL_REGISTER (decl) && DECL_ASSEMBLER_NAME_SET_P (decl))
212 make_decl_rtl (decl);
214 /* Forward declarations for nested functions are not "external",
215 but we need to treat them as if they were. */
216 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
217 || TREE_CODE (decl) == FUNCTION_DECL)
219 timevar_push (TV_VARCONST);
221 /* Don't output anything when a tentative file-scope definition
222 is seen. But at end of compilation, do output code for them.
224 We do output all variables when unit-at-a-time is active and rely on
225 callgraph code to defer them except for forward declarations
226 (see gcc.c-torture/compile/920624-1.c) */
228 || !DECL_DEFER_OUTPUT (decl)
229 || (flag_unit_at_a_time && DECL_INITIAL (decl)))
230 && !DECL_EXTERNAL (decl))
232 if (flag_unit_at_a_time && !cgraph_global_info_ready
233 && TREE_CODE (decl) != FUNCTION_DECL && top_level
234 /* If we defer processing of decls that have had their
235 DECL_RTL set above (say, in make_decl_rtl),
236 check_global_declarations() will clear it before
237 assemble_variable has a chance to act on it. This
238 would remove all traces of the register name in a
239 global register variable, for example. */
240 && !DECL_RTL_SET_P (decl))
241 cgraph_varpool_finalize_decl (decl);
243 assemble_variable (decl, top_level, at_end, 0);
246 #ifdef ASM_FINISH_DECLARE_OBJECT
247 if (decl == last_assemble_variable_decl)
249 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
254 timevar_pop (TV_VARCONST);
256 else if (TREE_CODE (decl) == TYPE_DECL)
258 timevar_push (TV_SYMOUT);
259 debug_hooks->type_decl (decl, !top_level);
260 timevar_pop (TV_SYMOUT);
264 /* Called after finishing a record, union or enumeral type. */
267 rest_of_type_compilation (tree type, int toplev)
269 /* Avoid confusing the debug information machinery when there are
271 if (errorcount != 0 || sorrycount != 0)
274 timevar_push (TV_SYMOUT);
275 debug_hooks->type_decl (TYPE_STUB_DECL (type), !toplev);
276 timevar_pop (TV_SYMOUT);
279 /* Turn the RTL into assembly. */
281 rest_of_handle_final (void)
283 timevar_push (TV_FINAL);
288 /* Get the function's name, as described by its RTL. This may be
289 different from the DECL_NAME name used in the source file. */
291 x = DECL_RTL (current_function_decl);
292 gcc_assert (MEM_P (x));
294 gcc_assert (GET_CODE (x) == SYMBOL_REF);
295 fnname = XSTR (x, 0);
297 assemble_start_function (current_function_decl, fnname);
298 final_start_function (get_insns (), asm_out_file, optimize);
299 final (get_insns (), asm_out_file, optimize, 0);
300 final_end_function ();
302 #ifdef TARGET_UNWIND_INFO
303 /* ??? The IA-64 ".handlerdata" directive must be issued before
304 the ".endp" directive that closes the procedure descriptor. */
305 output_function_exception_table ();
308 assemble_end_function (current_function_decl, fnname);
310 #ifndef TARGET_UNWIND_INFO
311 /* Otherwise, it feels unclean to switch sections in the middle. */
312 output_function_exception_table ();
315 user_defined_section_attribute = false;
318 fflush (asm_out_file);
320 /* Release all memory allocated by flow. */
321 free_basic_block_vars ();
323 /* Release all memory held by regsets now. */
324 regset_release_memory ();
327 /* Write DBX symbols if requested. */
329 /* Note that for those inline functions where we don't initially
330 know for certain that we will be generating an out-of-line copy,
331 the first invocation of this routine (rest_of_compilation) will
332 skip over this code by doing a `goto exit_rest_of_compilation;'.
333 Later on, wrapup_global_declarations will (indirectly) call
334 rest_of_compilation again for those inline functions that need
335 to have out-of-line copies generated. During that call, we
336 *will* be routed past here. */
338 timevar_push (TV_SYMOUT);
339 (*debug_hooks->function_decl) (current_function_decl);
340 timevar_pop (TV_SYMOUT);
343 timevar_pop (TV_FINAL);
347 /* Run delay slot optimization. */
349 rest_of_handle_delay_slots (void)
351 timevar_push (TV_DBR_SCHED);
352 open_dump_file (DFI_dbr, current_function_decl);
354 dbr_schedule (get_insns (), dump_file);
356 close_dump_file (DFI_dbr, print_rtl, get_insns ());
360 timevar_pop (TV_DBR_SCHED);
365 /* Convert register usage from flat register file usage to a stack
368 rest_of_handle_stack_regs (void)
370 #if defined (HAVE_ATTR_length)
371 /* If flow2 creates new instructions which need splitting
372 and scheduling after reload is not done, they might not be
373 split until final which doesn't allow splitting
374 if HAVE_ATTR_length. */
375 #ifdef INSN_SCHEDULING
376 if (optimize && !flag_schedule_insns_after_reload)
381 timevar_push (TV_SHORTEN_BRANCH);
383 timevar_pop (TV_SHORTEN_BRANCH);
387 timevar_push (TV_REG_STACK);
388 open_dump_file (DFI_stack, current_function_decl);
390 if (reg_to_stack (dump_file) && optimize)
392 if (cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK
393 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0))
394 && (flag_reorder_blocks || flag_reorder_blocks_and_partition))
396 reorder_basic_blocks (0);
397 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK);
401 close_dump_file (DFI_stack, print_rtl_with_bb, get_insns ());
404 timevar_pop (TV_REG_STACK);
408 /* Track the variables, ie. compute where the variable is stored at each position in function. */
410 rest_of_handle_variable_tracking (void)
412 timevar_push (TV_VAR_TRACKING);
413 open_dump_file (DFI_vartrack, current_function_decl);
415 variable_tracking_main ();
417 close_dump_file (DFI_vartrack, print_rtl_with_bb, get_insns ());
418 timevar_pop (TV_VAR_TRACKING);
421 /* Machine dependent reorg pass. */
423 rest_of_handle_machine_reorg (void)
425 timevar_push (TV_MACH_DEP);
426 open_dump_file (DFI_mach, current_function_decl);
428 targetm.machine_dependent_reorg ();
430 close_dump_file (DFI_mach, print_rtl, get_insns ());
433 timevar_pop (TV_MACH_DEP);
437 /* Run new register allocator. Return TRUE if we must exit
438 rest_of_compilation upon return. */
440 rest_of_handle_new_regalloc (void)
444 timevar_push (TV_LOCAL_ALLOC);
445 open_dump_file (DFI_lreg, current_function_decl);
447 delete_trivially_dead_insns (get_insns (), max_reg_num ());
450 timevar_pop (TV_LOCAL_ALLOC);
451 close_dump_file (DFI_lreg, NULL, NULL);
453 /* XXX clean up the whole mess to bring live info in shape again. */
454 timevar_push (TV_GLOBAL_ALLOC);
455 open_dump_file (DFI_greg, current_function_decl);
457 build_insn_chain (get_insns ());
458 failure = reload (get_insns (), 0);
460 timevar_pop (TV_GLOBAL_ALLOC);
464 if (dump_enabled_p (DFI_greg))
466 timevar_push (TV_DUMP);
467 dump_global_regs (dump_file);
468 timevar_pop (TV_DUMP);
469 close_dump_file (DFI_greg, print_rtl_with_bb, get_insns ());
475 reload_completed = 1;
480 /* Run old register allocator. Return TRUE if we must exit
481 rest_of_compilation upon return. */
483 rest_of_handle_old_regalloc (void)
488 timevar_push (TV_LOCAL_ALLOC);
489 open_dump_file (DFI_lreg, current_function_decl);
491 /* Allocate the reg_renumber array. */
492 allocate_reg_info (max_regno, FALSE, TRUE);
494 /* And the reg_equiv_memory_loc array. */
495 VARRAY_GROW (reg_equiv_memory_loc_varray, max_regno);
496 reg_equiv_memory_loc = &VARRAY_RTX (reg_equiv_memory_loc_varray, 0);
498 allocate_initial_values (reg_equiv_memory_loc);
500 regclass (get_insns (), max_reg_num (), dump_file);
501 rebuild_notes = local_alloc ();
503 timevar_pop (TV_LOCAL_ALLOC);
505 /* Local allocation may have turned an indirect jump into a direct
506 jump. If so, we must rebuild the JUMP_LABEL fields of jumping
510 timevar_push (TV_JUMP);
512 rebuild_jump_labels (get_insns ());
513 purge_all_dead_edges (0);
515 timevar_pop (TV_JUMP);
518 if (dump_enabled_p (DFI_lreg))
520 timevar_push (TV_DUMP);
521 dump_flow_info (dump_file);
522 dump_local_alloc (dump_file);
523 timevar_pop (TV_DUMP);
526 close_dump_file (DFI_lreg, print_rtl_with_bb, get_insns ());
530 timevar_push (TV_GLOBAL_ALLOC);
531 open_dump_file (DFI_greg, current_function_decl);
533 /* If optimizing, allocate remaining pseudo-regs. Do the reload
534 pass fixing up any insns that are invalid. */
537 failure = global_alloc (dump_file);
540 build_insn_chain (get_insns ());
541 failure = reload (get_insns (), 0);
544 if (dump_enabled_p (DFI_greg))
546 timevar_push (TV_DUMP);
547 dump_global_regs (dump_file);
548 timevar_pop (TV_DUMP);
550 close_dump_file (DFI_greg, print_rtl_with_bb, get_insns ());
555 timevar_pop (TV_GLOBAL_ALLOC);
560 /* Run the regrename and cprop passes. */
562 rest_of_handle_regrename (void)
564 timevar_push (TV_RENAME_REGISTERS);
565 open_dump_file (DFI_rnreg, current_function_decl);
567 if (flag_rename_registers)
568 regrename_optimize ();
569 if (flag_cprop_registers)
570 copyprop_hardreg_forward ();
572 close_dump_file (DFI_rnreg, print_rtl_with_bb, get_insns ());
573 timevar_pop (TV_RENAME_REGISTERS);
576 /* Reorder basic blocks. */
578 rest_of_handle_reorder_blocks (void)
581 unsigned int liveness_flags;
583 open_dump_file (DFI_bbro, current_function_decl);
585 /* Last attempt to optimize CFG, as scheduling, peepholing and insn
586 splitting possibly introduced more crossjumping opportunities. */
587 liveness_flags = (!HAVE_conditional_execution ? CLEANUP_UPDATE_LIFE : 0);
588 changed = cleanup_cfg (CLEANUP_EXPENSIVE | liveness_flags);
590 if (flag_sched2_use_traces && flag_schedule_insns_after_reload)
591 tracer (liveness_flags);
592 if (flag_reorder_blocks || flag_reorder_blocks_and_partition)
593 reorder_basic_blocks (liveness_flags);
594 if (flag_reorder_blocks || flag_reorder_blocks_and_partition
595 || (flag_sched2_use_traces && flag_schedule_insns_after_reload))
596 changed |= cleanup_cfg (CLEANUP_EXPENSIVE | liveness_flags);
598 /* On conditional execution targets we can not update the life cheaply, so
599 we deffer the updating to after both cleanups. This may lose some cases
600 but should not be terribly bad. */
601 if (changed && HAVE_conditional_execution)
602 update_life_info (NULL, UPDATE_LIFE_GLOBAL_RM_NOTES,
604 close_dump_file (DFI_bbro, print_rtl_with_bb, get_insns ());
607 /* Partition hot and cold basic blocks. */
609 rest_of_handle_partition_blocks (void)
612 partition_hot_cold_basic_blocks ();
613 allocate_reg_life_data ();
614 update_life_info (NULL, UPDATE_LIFE_GLOBAL_RM_NOTES,
615 PROP_LOG_LINKS | PROP_REG_INFO | PROP_DEATH_NOTES);
619 #ifdef INSN_SCHEDULING
620 /* Run instruction scheduler. */
621 /* Perform SMS module scheduling. */
623 rest_of_handle_sms (void)
625 timevar_push (TV_SMS);
626 open_dump_file (DFI_sms, current_function_decl);
628 /* We want to be able to create new pseudos. */
630 sms_schedule (dump_file);
631 close_dump_file (DFI_sms, print_rtl, get_insns ());
634 /* Update the life information, because we add pseudos. */
635 max_regno = max_reg_num ();
636 allocate_reg_info (max_regno, FALSE, FALSE);
637 update_life_info_in_dirty_blocks (UPDATE_LIFE_GLOBAL_RM_NOTES,
639 | PROP_KILL_DEAD_CODE
640 | PROP_SCAN_DEAD_CODE));
644 timevar_pop (TV_SMS);
647 /* Run instruction scheduler. */
649 rest_of_handle_sched (void)
651 timevar_push (TV_SCHED);
653 /* Print function header into sched dump now
654 because doing the sched analysis makes some of the dump. */
655 open_dump_file (DFI_sched, current_function_decl);
657 /* Do control and data sched analysis,
658 and write some of the results to dump file. */
660 schedule_insns (dump_file);
662 close_dump_file (DFI_sched, print_rtl_with_bb, get_insns ());
665 timevar_pop (TV_SCHED);
668 /* Run second scheduling pass after reload. */
670 rest_of_handle_sched2 (void)
672 timevar_push (TV_SCHED2);
673 open_dump_file (DFI_sched2, current_function_decl);
675 /* Do control and data sched analysis again,
676 and write some more of the results to dump file. */
680 if (flag_sched2_use_superblocks || flag_sched2_use_traces)
682 schedule_ebbs (dump_file);
683 /* No liveness updating code yet, but it should be easy to do.
684 reg-stack recomputes the liveness when needed for now. */
685 count_or_remove_death_notes (NULL, 1);
686 cleanup_cfg (CLEANUP_EXPENSIVE);
689 schedule_insns (dump_file);
691 close_dump_file (DFI_sched2, print_rtl_with_bb, get_insns ());
695 timevar_pop (TV_SCHED2);
700 rest_of_handle_gcse2 (void)
702 timevar_push (TV_GCSE_AFTER_RELOAD);
703 open_dump_file (DFI_gcse2, current_function_decl);
705 gcse_after_reload_main (get_insns ());
706 rebuild_jump_labels (get_insns ());
707 delete_trivially_dead_insns (get_insns (), max_reg_num ());
708 close_dump_file (DFI_gcse2, print_rtl_with_bb, get_insns ());
712 #ifdef ENABLE_CHECKING
716 timevar_pop (TV_GCSE_AFTER_RELOAD);
719 /* Register allocation pre-pass, to reduce number of moves necessary
720 for two-address machines. */
722 rest_of_handle_regmove (void)
724 timevar_push (TV_REGMOVE);
725 open_dump_file (DFI_regmove, current_function_decl);
727 regmove_optimize (get_insns (), max_reg_num (), dump_file);
729 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
730 close_dump_file (DFI_regmove, print_rtl_with_bb, get_insns ());
733 timevar_pop (TV_REGMOVE);
738 rest_of_handle_tracer (void)
740 open_dump_file (DFI_tracer, current_function_decl);
742 dump_flow_info (dump_file);
744 cleanup_cfg (CLEANUP_EXPENSIVE);
745 reg_scan (get_insns (), max_reg_num (), 0);
746 close_dump_file (DFI_tracer, print_rtl_with_bb, get_insns ());
749 /* If-conversion and CFG cleanup. */
751 rest_of_handle_if_conversion (void)
753 timevar_push (TV_IFCVT);
754 open_dump_file (DFI_ce1, current_function_decl);
756 if (flag_if_conversion)
759 dump_flow_info (dump_file);
760 cleanup_cfg (CLEANUP_EXPENSIVE);
761 reg_scan (get_insns (), max_reg_num (), 0);
765 timevar_push (TV_JUMP);
766 cleanup_cfg (CLEANUP_EXPENSIVE);
767 reg_scan (get_insns (), max_reg_num (), 0);
768 timevar_pop (TV_JUMP);
770 close_dump_file (DFI_ce1, print_rtl_with_bb, get_insns ());
771 timevar_pop (TV_IFCVT);
774 /* Rerun if-conversion, as combine may have simplified things enough
775 to now meet sequence length restrictions. */
777 rest_of_handle_if_after_combine (void)
779 timevar_push (TV_IFCVT);
780 open_dump_file (DFI_ce2, current_function_decl);
786 close_dump_file (DFI_ce2, print_rtl_with_bb, get_insns ());
787 timevar_pop (TV_IFCVT);
791 rest_of_handle_if_after_reload (void)
793 timevar_push (TV_IFCVT2);
794 open_dump_file (DFI_ce3, current_function_decl);
796 /* Last attempt to optimize CFG, as scheduling, peepholing and insn
797 splitting possibly introduced more crossjumping opportunities. */
798 cleanup_cfg (CLEANUP_EXPENSIVE
799 | CLEANUP_UPDATE_LIFE
800 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0));
801 if (flag_if_conversion2)
803 close_dump_file (DFI_ce3, print_rtl_with_bb, get_insns ());
804 timevar_pop (TV_IFCVT2);
808 rest_of_handle_web (void)
810 open_dump_file (DFI_web, current_function_decl);
811 timevar_push (TV_WEB);
813 delete_trivially_dead_insns (get_insns (), max_reg_num ());
814 cleanup_cfg (CLEANUP_EXPENSIVE);
816 timevar_pop (TV_WEB);
817 close_dump_file (DFI_web, print_rtl_with_bb, get_insns ());
818 reg_scan (get_insns (), max_reg_num (), 0);
821 /* Do branch profiling and static profile estimation passes. */
823 rest_of_handle_branch_prob (void)
827 timevar_push (TV_BRANCH_PROB);
828 open_dump_file (DFI_bp, current_function_decl);
830 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
833 /* Discover and record the loop depth at the head of each basic
834 block. The loop infrastructure does the real job for us. */
835 flow_loops_find (&loops, LOOP_TREE);
838 flow_loops_dump (&loops, dump_file, NULL, 0);
840 /* Estimate using heuristics if no profiling info is available. */
841 if (flag_guess_branch_prob)
842 estimate_probability (&loops);
844 flow_loops_free (&loops);
845 free_dominance_info (CDI_DOMINATORS);
846 close_dump_file (DFI_bp, print_rtl_with_bb, get_insns ());
847 timevar_pop (TV_BRANCH_PROB);
850 /* Do optimizations based on expression value profiles. */
852 rest_of_handle_value_profile_transformations (void)
854 open_dump_file (DFI_vpt, current_function_decl);
855 timevar_push (TV_VPT);
857 if (value_profile_transformations ())
858 cleanup_cfg (CLEANUP_EXPENSIVE);
860 timevar_pop (TV_VPT);
861 close_dump_file (DFI_vpt, print_rtl_with_bb, get_insns ());
864 /* Do control and data flow analysis; write some of the results to the
867 rest_of_handle_cfg (void)
869 open_dump_file (DFI_cfg, current_function_decl);
871 dump_flow_info (dump_file);
873 cleanup_cfg (CLEANUP_EXPENSIVE
874 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
876 /* It may make more sense to mark constant functions after dead code is
877 eliminated by life_analysis, but we need to do it early, as -fprofile-arcs
878 may insert code making function non-constant, but we still must consider
879 it as constant, otherwise -fbranch-probabilities will not read data back.
881 life_analysis rarely eliminates modification of external memory.
885 /* Alias analysis depends on this information and mark_constant_function
886 depends on alias analysis. */
887 reg_scan (get_insns (), max_reg_num (), 1);
888 mark_constant_function ();
891 close_dump_file (DFI_cfg, print_rtl_with_bb, get_insns ());
894 /* Perform jump bypassing and control flow optimizations. */
896 rest_of_handle_jump_bypass (void)
898 timevar_push (TV_BYPASS);
899 open_dump_file (DFI_bypass, current_function_decl);
901 cleanup_cfg (CLEANUP_EXPENSIVE);
902 reg_scan (get_insns (), max_reg_num (), 1);
904 if (bypass_jumps (dump_file))
906 rebuild_jump_labels (get_insns ());
907 cleanup_cfg (CLEANUP_EXPENSIVE);
908 delete_trivially_dead_insns (get_insns (), max_reg_num ());
911 close_dump_file (DFI_bypass, print_rtl_with_bb, get_insns ());
912 timevar_pop (TV_BYPASS);
916 #ifdef ENABLE_CHECKING
921 /* Try combining insns through substitution. */
923 rest_of_handle_combine (void)
925 int rebuild_jump_labels_after_combine = 0;
927 timevar_push (TV_COMBINE);
928 open_dump_file (DFI_combine, current_function_decl);
930 rebuild_jump_labels_after_combine
931 = combine_instructions (get_insns (), max_reg_num ());
933 /* Combining insns may have turned an indirect jump into a
934 direct jump. Rebuild the JUMP_LABEL fields of jumping
936 if (rebuild_jump_labels_after_combine)
938 timevar_push (TV_JUMP);
939 rebuild_jump_labels (get_insns ());
940 timevar_pop (TV_JUMP);
942 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
945 close_dump_file (DFI_combine, print_rtl_with_bb, get_insns ());
946 timevar_pop (TV_COMBINE);
951 /* Perform life analysis. */
953 rest_of_handle_life (void)
955 open_dump_file (DFI_life, current_function_decl);
958 #ifdef ENABLE_CHECKING
961 life_analysis (dump_file, PROP_FINAL);
963 cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_UPDATE_LIFE
965 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
969 setjmp_vars_warning (DECL_INITIAL (current_function_decl));
970 setjmp_args_warning ();
975 if (!flag_new_regalloc && initialize_uninitialized_subregs ())
977 /* Insns were inserted, and possibly pseudos created, so
978 things might look a bit different. */
979 allocate_reg_life_data ();
980 update_life_info (NULL, UPDATE_LIFE_GLOBAL_RM_NOTES,
981 PROP_LOG_LINKS | PROP_REG_INFO | PROP_DEATH_NOTES);
987 close_dump_file (DFI_life, print_rtl_with_bb, get_insns ());
992 /* Perform common subexpression elimination. Nonzero value from
993 `cse_main' means that jumps were simplified and some code may now
994 be unreachable, so do jump optimization again. */
996 rest_of_handle_cse (void)
1000 open_dump_file (DFI_cse, current_function_decl);
1002 dump_flow_info (dump_file);
1003 timevar_push (TV_CSE);
1005 reg_scan (get_insns (), max_reg_num (), 1);
1007 tem = cse_main (get_insns (), max_reg_num (), dump_file);
1009 rebuild_jump_labels (get_insns ());
1010 if (purge_all_dead_edges (0))
1011 delete_unreachable_blocks ();
1013 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1015 /* If we are not running more CSE passes, then we are no longer
1016 expecting CSE to be run. But always rerun it in a cheap mode. */
1017 cse_not_expected = !flag_rerun_cse_after_loop && !flag_gcse;
1019 if (tem || optimize > 1)
1020 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
1022 timevar_pop (TV_CSE);
1023 close_dump_file (DFI_cse, print_rtl_with_bb, get_insns ());
1028 /* Run second CSE pass after loop optimizations. */
1030 rest_of_handle_cse2 (void)
1034 timevar_push (TV_CSE2);
1035 open_dump_file (DFI_cse2, current_function_decl);
1037 dump_flow_info (dump_file);
1038 /* CFG is no longer maintained up-to-date. */
1039 tem = cse_main (get_insns (), max_reg_num (), dump_file);
1041 /* Run a pass to eliminate duplicated assignments to condition code
1042 registers. We have to run this after bypass_jumps, because it
1043 makes it harder for that pass to determine whether a jump can be
1045 cse_condition_code_reg ();
1047 purge_all_dead_edges (0);
1048 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1052 timevar_push (TV_JUMP);
1053 rebuild_jump_labels (get_insns ());
1054 cleanup_cfg (CLEANUP_EXPENSIVE);
1055 timevar_pop (TV_JUMP);
1057 reg_scan (get_insns (), max_reg_num (), 0);
1058 close_dump_file (DFI_cse2, print_rtl_with_bb, get_insns ());
1059 timevar_pop (TV_CSE2);
1064 /* Perform global cse. */
1066 rest_of_handle_gcse (void)
1068 int save_csb, save_cfj;
1071 timevar_push (TV_GCSE);
1072 open_dump_file (DFI_gcse, current_function_decl);
1074 tem = gcse_main (get_insns (), dump_file);
1075 rebuild_jump_labels (get_insns ());
1076 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1078 save_csb = flag_cse_skip_blocks;
1079 save_cfj = flag_cse_follow_jumps;
1080 flag_cse_skip_blocks = flag_cse_follow_jumps = 0;
1082 /* If -fexpensive-optimizations, re-run CSE to clean up things done
1084 if (flag_expensive_optimizations)
1086 timevar_push (TV_CSE);
1087 reg_scan (get_insns (), max_reg_num (), 1);
1088 tem2 = cse_main (get_insns (), max_reg_num (), dump_file);
1089 purge_all_dead_edges (0);
1090 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1091 timevar_pop (TV_CSE);
1092 cse_not_expected = !flag_rerun_cse_after_loop;
1095 /* If gcse or cse altered any jumps, rerun jump optimizations to clean
1096 things up. Then possibly re-run CSE again. */
1100 timevar_push (TV_JUMP);
1101 rebuild_jump_labels (get_insns ());
1102 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
1103 timevar_pop (TV_JUMP);
1105 if (flag_expensive_optimizations)
1107 timevar_push (TV_CSE);
1108 reg_scan (get_insns (), max_reg_num (), 1);
1109 tem2 = cse_main (get_insns (), max_reg_num (), dump_file);
1110 purge_all_dead_edges (0);
1111 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1112 timevar_pop (TV_CSE);
1116 close_dump_file (DFI_gcse, print_rtl_with_bb, get_insns ());
1117 timevar_pop (TV_GCSE);
1120 flag_cse_skip_blocks = save_csb;
1121 flag_cse_follow_jumps = save_cfj;
1122 #ifdef ENABLE_CHECKING
1123 verify_flow_info ();
1127 /* Move constant computations out of loops. */
1129 rest_of_handle_loop_optimize (void)
1131 int do_unroll, do_prefetch;
1133 timevar_push (TV_LOOP);
1134 delete_dead_jumptables ();
1135 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
1136 open_dump_file (DFI_loop, current_function_decl);
1138 /* CFG is no longer maintained up-to-date. */
1139 free_bb_for_insn ();
1141 if (flag_unroll_loops)
1142 do_unroll = LOOP_AUTO_UNROLL; /* Having two unrollers is useless. */
1144 do_unroll = flag_old_unroll_loops ? LOOP_UNROLL : LOOP_AUTO_UNROLL;
1145 do_prefetch = flag_prefetch_loop_arrays ? LOOP_PREFETCH : 0;
1147 if (flag_rerun_loop_opt)
1149 cleanup_barriers ();
1151 /* We only want to perform unrolling once. */
1152 loop_optimize (get_insns (), dump_file, do_unroll);
1155 /* The first call to loop_optimize makes some instructions
1156 trivially dead. We delete those instructions now in the
1157 hope that doing so will make the heuristics in loop work
1158 better and possibly speed up compilation. */
1159 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1161 /* The regscan pass is currently necessary as the alias
1162 analysis code depends on this information. */
1163 reg_scan (get_insns (), max_reg_num (), 1);
1165 cleanup_barriers ();
1166 loop_optimize (get_insns (), dump_file, do_unroll | do_prefetch);
1168 /* Loop can create trivially dead instructions. */
1169 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1170 find_basic_blocks (get_insns (), max_reg_num (), dump_file);
1171 close_dump_file (DFI_loop, print_rtl, get_insns ());
1172 timevar_pop (TV_LOOP);
1177 /* Perform loop optimizations. It might be better to do them a bit
1178 sooner, but we want the profile feedback to work more
1181 rest_of_handle_loop2 (void)
1183 struct loops *loops;
1186 if (!flag_move_loop_invariants
1187 && !flag_unswitch_loops
1189 && !flag_unroll_loops
1190 && !flag_branch_on_count_reg)
1193 timevar_push (TV_LOOP);
1194 open_dump_file (DFI_loop2, current_function_decl);
1196 dump_flow_info (dump_file);
1198 /* Initialize structures for layout changes. */
1199 cfg_layout_initialize (0);
1201 loops = loop_optimizer_init (dump_file);
1205 /* The optimizations: */
1206 if (flag_move_loop_invariants)
1207 move_loop_invariants (loops);
1209 if (flag_unswitch_loops)
1210 unswitch_loops (loops);
1212 if (flag_peel_loops || flag_unroll_loops)
1213 unroll_and_peel_loops (loops,
1214 (flag_peel_loops ? UAP_PEEL : 0) |
1215 (flag_unroll_loops ? UAP_UNROLL : 0) |
1216 (flag_unroll_all_loops ? UAP_UNROLL_ALL : 0));
1218 #ifdef HAVE_doloop_end
1219 if (flag_branch_on_count_reg && HAVE_doloop_end)
1220 doloop_optimize_loops (loops);
1221 #endif /* HAVE_doloop_end */
1223 loop_optimizer_finalize (loops, dump_file);
1226 free_dominance_info (CDI_DOMINATORS);
1228 /* Finalize layout changes. */
1230 if (bb->next_bb != EXIT_BLOCK_PTR)
1231 bb->rbi->next = bb->next_bb;
1232 cfg_layout_finalize ();
1234 cleanup_cfg (CLEANUP_EXPENSIVE);
1235 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1236 reg_scan (get_insns (), max_reg_num (), 0);
1238 dump_flow_info (dump_file);
1239 close_dump_file (DFI_loop2, print_rtl_with_bb, get_insns ());
1240 timevar_pop (TV_LOOP);
1245 rest_of_handle_branch_target_load_optimize (void)
1247 static int warned = 0;
1249 /* Leave this a warning for now so that it is possible to experiment
1250 with running this pass twice. In 3.6, we should either make this
1251 an error, or use separate dump files. */
1252 if (flag_branch_target_load_optimize
1253 && flag_branch_target_load_optimize2
1256 warning ("branch target register load optimization is not intended "
1262 open_dump_file (DFI_branch_target_load, current_function_decl);
1263 branch_target_load_optimize (epilogue_completed);
1264 close_dump_file (DFI_branch_target_load, print_rtl_with_bb, get_insns ());
1268 #ifdef OPTIMIZE_MODE_SWITCHING
1270 rest_of_handle_mode_switching (void)
1272 timevar_push (TV_MODE_SWITCH);
1275 optimize_mode_switching (NULL);
1278 timevar_pop (TV_MODE_SWITCH);
1283 rest_of_handle_jump (void)
1287 timevar_push (TV_JUMP);
1288 open_dump_file (DFI_sibling, current_function_decl);
1290 /* ??? We may get caled either via tree_rest_of_compilation when the CFG
1291 is already built or directly (for instance from coverage code).
1292 The direct callers shall be updated. */
1293 if (!basic_block_info)
1296 rebuild_jump_labels (get_insns ());
1297 find_exception_handler_labels ();
1298 find_basic_blocks (get_insns (), max_reg_num (), dump_file);
1301 /* ??? We may get called either via tree_rest_of_compilation when the CFG
1302 is already built or directly (for instance from coverage code).
1303 The direct callers shall be updated. */
1304 if (!basic_block_info)
1307 rebuild_jump_labels (get_insns ());
1308 find_exception_handler_labels ();
1309 find_basic_blocks (get_insns (), max_reg_num (), dump_file);
1311 delete_unreachable_blocks ();
1312 #ifdef ENABLE_CHECKING
1313 verify_flow_info ();
1316 if (cfun->tail_call_emit)
1317 fixup_tail_calls ();
1319 close_dump_file (DFI_sibling, print_rtl, get_insns ());
1320 timevar_pop (TV_JUMP);
1324 rest_of_handle_eh (void)
1326 insn_locators_initialize ();
1327 /* Complete generation of exception handling code. */
1330 timevar_push (TV_JUMP);
1331 open_dump_file (DFI_eh, current_function_decl);
1333 cleanup_cfg (CLEANUP_PRE_LOOP | CLEANUP_NO_INSN_DEL);
1335 finish_eh_generation ();
1337 cleanup_cfg (CLEANUP_PRE_LOOP | CLEANUP_NO_INSN_DEL);
1339 close_dump_file (DFI_eh, print_rtl, get_insns ());
1340 timevar_pop (TV_JUMP);
1346 rest_of_handle_prologue_epilogue (void)
1348 if (optimize && !flow2_completed)
1349 cleanup_cfg (CLEANUP_EXPENSIVE);
1351 /* On some machines, the prologue and epilogue code, or parts thereof,
1352 can be represented as RTL. Doing so lets us schedule insns between
1353 it and the rest of the code and also allows delayed branch
1354 scheduling to operate in the epilogue. */
1355 thread_prologue_and_epilogue_insns (get_insns ());
1356 epilogue_completed = 1;
1358 if (optimize && flow2_completed)
1359 life_analysis (dump_file, PROP_POSTRELOAD);
1363 rest_of_handle_stack_adjustments (void)
1365 life_analysis (dump_file, PROP_POSTRELOAD);
1366 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE
1367 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0));
1369 /* This is kind of a heuristic. We need to run combine_stack_adjustments
1370 even for machines with possibly nonzero RETURN_POPS_ARGS
1371 and ACCUMULATE_OUTGOING_ARGS. We expect that only ports having
1372 push instructions will have popping returns. */
1373 #ifndef PUSH_ROUNDING
1374 if (!ACCUMULATE_OUTGOING_ARGS)
1376 combine_stack_adjustments ();
1380 rest_of_handle_flow2 (void)
1382 timevar_push (TV_FLOW2);
1383 open_dump_file (DFI_flow2, current_function_decl);
1385 /* Re-create the death notes which were deleted during reload. */
1386 #ifdef ENABLE_CHECKING
1387 verify_flow_info ();
1390 /* If optimizing, then go ahead and split insns now. */
1394 split_all_insns (0);
1396 if (flag_branch_target_load_optimize)
1397 rest_of_handle_branch_target_load_optimize ();
1399 if (!targetm.late_rtl_prologue_epilogue)
1400 rest_of_handle_prologue_epilogue ();
1403 rest_of_handle_stack_adjustments ();
1405 flow2_completed = 1;
1407 close_dump_file (DFI_flow2, print_rtl_with_bb, get_insns ());
1408 timevar_pop (TV_FLOW2);
1415 rest_of_handle_jump2 (void)
1417 open_dump_file (DFI_jump, current_function_decl);
1419 /* Always do one jump optimization pass to ensure that JUMP_LABEL fields
1420 are initialized and to compute whether control can drop off the end
1423 timevar_push (TV_JUMP);
1424 /* Turn NOTE_INSN_EXPECTED_VALUE into REG_BR_PROB. Do this
1425 before jump optimization switches branch directions. */
1426 if (flag_guess_branch_prob)
1427 expected_value_to_br_prob ();
1429 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1430 reg_scan (get_insns (), max_reg_num (), 0);
1432 dump_flow_info (dump_file);
1433 cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_PRE_LOOP
1434 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
1436 create_loop_notes ();
1438 purge_line_number_notes (get_insns ());
1441 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
1443 /* Jump optimization, and the removal of NULL pointer checks, may
1444 have reduced the number of instructions substantially. CSE, and
1445 future passes, allocate arrays whose dimensions involve the
1446 maximum instruction UID, so if we can reduce the maximum UID
1447 we'll save big on memory. */
1448 renumber_insns (dump_file);
1450 close_dump_file (DFI_jump, print_rtl_with_bb, get_insns ());
1451 timevar_pop (TV_JUMP);
1456 #ifdef HAVE_peephole2
1458 rest_of_handle_peephole2 (void)
1460 timevar_push (TV_PEEPHOLE2);
1461 open_dump_file (DFI_peephole2, current_function_decl);
1463 peephole2_optimize (dump_file);
1465 close_dump_file (DFI_peephole2, print_rtl_with_bb, get_insns ());
1466 timevar_pop (TV_PEEPHOLE2);
1471 rest_of_handle_postreload (void)
1473 timevar_push (TV_RELOAD_CSE_REGS);
1474 open_dump_file (DFI_postreload, current_function_decl);
1476 /* Do a very simple CSE pass over just the hard registers. */
1477 reload_cse_regs (get_insns ());
1478 /* reload_cse_regs can eliminate potentially-trapping MEMs.
1479 Remove any EH edges associated with them. */
1480 if (flag_non_call_exceptions)
1481 purge_all_dead_edges (0);
1483 close_dump_file (DFI_postreload, print_rtl_with_bb, get_insns ());
1484 timevar_pop (TV_RELOAD_CSE_REGS);
1488 rest_of_handle_shorten_branches (void)
1490 /* Shorten branches. */
1491 timevar_push (TV_SHORTEN_BRANCH);
1492 shorten_branches (get_insns ());
1493 timevar_pop (TV_SHORTEN_BRANCH);
1497 rest_of_clean_state (void)
1500 coverage_end_function ();
1502 /* It is very important to decompose the RTL instruction chain here:
1503 debug information keeps pointing into CODE_LABEL insns inside the function
1504 body. If these remain pointing to the other insns, we end up preserving
1505 whole RTL chain and attached detailed debug info in memory. */
1506 for (insn = get_insns (); insn; insn = next)
1508 next = NEXT_INSN (insn);
1509 NEXT_INSN (insn) = NULL;
1510 PREV_INSN (insn) = NULL;
1513 /* In case the function was not output,
1514 don't leave any temporary anonymous types
1515 queued up for sdb output. */
1516 #ifdef SDB_DEBUGGING_INFO
1517 if (write_symbols == SDB_DEBUG)
1518 sdbout_types (NULL_TREE);
1521 reload_completed = 0;
1522 epilogue_completed = 0;
1523 flow2_completed = 0;
1526 timevar_push (TV_FINAL);
1528 /* Clear out the insn_length contents now that they are no
1530 init_insn_lengths ();
1532 /* Show no temporary slots allocated. */
1535 free_basic_block_vars ();
1536 free_bb_for_insn ();
1538 timevar_pop (TV_FINAL);
1540 if (targetm.binds_local_p (current_function_decl))
1542 int pref = cfun->preferred_stack_boundary;
1543 if (cfun->recursive_call_emit
1544 && cfun->stack_alignment_needed > cfun->preferred_stack_boundary)
1545 pref = cfun->stack_alignment_needed;
1546 cgraph_rtl_info (current_function_decl)->preferred_incoming_stack_boundary
1550 /* Make sure volatile mem refs aren't considered valid operands for
1551 arithmetic insns. We must call this here if this is a nested inline
1552 function, since the above code leaves us in the init_recog state
1553 (from final.c), and the function context push/pop code does not
1554 save/restore volatile_ok.
1556 ??? Maybe it isn't necessary for expand_start_function to call this
1557 anymore if we do it here? */
1559 init_recog_no_volatile ();
1561 /* We're done with this function. Free up memory if we can. */
1562 free_after_parsing (cfun);
1563 free_after_compilation (cfun);
1567 /* This function is called from the pass manager in tree-optimize.c
1568 after all tree passes have finished for a single function, and we
1569 have expanded the function body from trees to RTL.
1570 Once we are here, we have decided that we're supposed to output
1571 that function, ie. that we should write assembler code for it.
1573 We run a series of low-level passes here on the function's RTL
1574 representation. Each pass is called via a rest_of_* function. */
1577 rest_of_compilation (void)
1579 /* Convert from NOTE_INSN_EH_REGION style notes, and do other
1580 sorts of eh initialization. */
1581 convert_from_eh_region_ranges ();
1583 /* If we're emitting a nested function, make sure its parent gets
1584 emitted as well. Doing otherwise confuses debug info. */
1587 for (parent = DECL_CONTEXT (current_function_decl);
1588 parent != NULL_TREE;
1589 parent = get_containing_scope (parent))
1590 if (TREE_CODE (parent) == FUNCTION_DECL)
1591 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (parent)) = 1;
1594 /* We are now committed to emitting code for this function. Do any
1595 preparation, such as emitting abstract debug info for the inline
1596 before it gets mangled by optimization. */
1597 if (cgraph_function_possibly_inlined_p (current_function_decl))
1598 (*debug_hooks->outlining_inline_function) (current_function_decl);
1600 /* Remove any notes we don't need. That will make iterating
1601 over the instruction sequence faster, and allow the garbage
1602 collector to reclaim the memory used by the notes. */
1603 remove_unnecessary_notes ();
1605 /* Initialize some variables used by the optimizers. */
1606 init_function_for_compilation ();
1608 TREE_ASM_WRITTEN (current_function_decl) = 1;
1610 /* Early return if there were errors. We can run afoul of our
1611 consistency checks, and there's not really much point in fixing them. */
1612 if (rtl_dump_and_exit || flag_syntax_only || errorcount || sorrycount)
1613 goto exit_rest_of_compilation;
1615 rest_of_handle_jump ();
1617 rest_of_handle_eh ();
1619 /* Delay emitting hard_reg_initial_value sets until after EH landing pad
1620 generation, which might create new sets. */
1621 emit_initial_value_sets ();
1624 /* If we are doing position-independent code generation, now
1625 is the time to output special prologues and epilogues.
1626 We do not want to do this earlier, because it just clutters
1627 up inline functions with meaningless insns. */
1632 /* Copy any shared structure that should not be shared. */
1635 #ifdef SETJMP_VIA_SAVE_AREA
1636 /* This must be performed before virtual register instantiation.
1637 Please be aware that everything in the compiler that can look
1638 at the RTL up to this point must understand that REG_SAVE_AREA
1639 is just like a use of the REG contained inside. */
1640 if (current_function_calls_alloca)
1641 optimize_save_area_alloca ();
1644 /* Instantiate all virtual registers. */
1645 instantiate_virtual_regs ();
1647 rest_of_handle_jump2 ();
1650 rest_of_handle_cse ();
1655 rest_of_handle_gcse ();
1657 if (flag_loop_optimize)
1658 rest_of_handle_loop_optimize ();
1661 rest_of_handle_jump_bypass ();
1664 timevar_push (TV_FLOW);
1665 rest_of_handle_cfg ();
1667 if (!flag_tree_based_profiling
1668 && (optimize > 0 || profile_arc_flag
1669 || flag_test_coverage || flag_branch_probabilities))
1671 rtl_register_profile_hooks ();
1672 rtl_register_value_prof_hooks ();
1673 rest_of_handle_branch_prob ();
1675 if (flag_branch_probabilities
1676 && flag_profile_values
1677 && (flag_value_profile_transformations
1678 || flag_speculative_prefetching))
1679 rest_of_handle_value_profile_transformations ();
1681 /* Remove the death notes created for vpt. */
1682 if (flag_profile_values)
1683 count_or_remove_death_notes (NULL, 1);
1687 rest_of_handle_if_conversion ();
1689 if (optimize > 0 && flag_tracer)
1690 rest_of_handle_tracer ();
1693 && flag_loop_optimize2)
1694 rest_of_handle_loop2 ();
1696 if (optimize > 0 && flag_web)
1697 rest_of_handle_web ();
1699 if (optimize > 0 && flag_rerun_cse_after_loop)
1700 rest_of_handle_cse2 ();
1702 cse_not_expected = 1;
1704 rest_of_handle_life ();
1705 timevar_pop (TV_FLOW);
1708 rest_of_handle_combine ();
1710 if (optimize > 0 && flag_if_conversion)
1711 rest_of_handle_if_after_combine ();
1713 /* The optimization to partition hot/cold basic blocks into separate
1714 sections of the .o file does not work well with linkonce or with
1715 user defined section attributes. Don't call it if either case
1718 if (flag_reorder_blocks_and_partition
1719 && !DECL_ONE_ONLY (current_function_decl)
1720 && !user_defined_section_attribute)
1721 rest_of_handle_partition_blocks ();
1723 if (optimize > 0 && (flag_regmove || flag_expensive_optimizations))
1724 rest_of_handle_regmove ();
1726 /* Do unconditional splitting before register allocation to allow machine
1727 description to add extra information not needed previously. */
1728 split_all_insns (1);
1730 #ifdef OPTIMIZE_MODE_SWITCHING
1731 rest_of_handle_mode_switching ();
1734 /* Any of the several passes since flow1 will have munged register
1735 lifetime data a bit. We need it to be up to date for scheduling
1736 (see handling of reg_known_equiv in init_alias_analysis). */
1737 recompute_reg_usage (get_insns (), !optimize_size);
1739 #ifdef INSN_SCHEDULING
1740 if (optimize > 0 && flag_modulo_sched)
1741 rest_of_handle_sms ();
1743 if (flag_schedule_insns)
1744 rest_of_handle_sched ();
1747 /* Determine if the current function is a leaf before running reload
1748 since this can impact optimizations done by the prologue and
1749 epilogue thus changing register elimination offsets. */
1750 current_function_is_leaf = leaf_function_p ();
1752 if (flag_new_regalloc)
1754 if (rest_of_handle_new_regalloc ())
1755 goto exit_rest_of_compilation;
1759 if (rest_of_handle_old_regalloc ())
1760 goto exit_rest_of_compilation;
1764 rest_of_handle_postreload ();
1766 if (optimize > 0 && flag_gcse_after_reload)
1767 rest_of_handle_gcse2 ();
1769 rest_of_handle_flow2 ();
1771 #ifdef HAVE_peephole2
1772 if (optimize > 0 && flag_peephole2)
1773 rest_of_handle_peephole2 ();
1777 rest_of_handle_if_after_reload ();
1781 if (flag_rename_registers || flag_cprop_registers)
1782 rest_of_handle_regrename ();
1784 rest_of_handle_reorder_blocks ();
1787 if (flag_branch_target_load_optimize2)
1788 rest_of_handle_branch_target_load_optimize ();
1790 #ifdef LEAF_REGISTERS
1791 current_function_uses_only_leaf_regs
1792 = optimize > 0 && only_leaf_regs_used () && leaf_function_p ();
1795 if (targetm.late_rtl_prologue_epilogue)
1796 rest_of_handle_prologue_epilogue ();
1798 #ifdef INSN_SCHEDULING
1799 if (optimize > 0 && flag_schedule_insns_after_reload)
1800 rest_of_handle_sched2 ();
1804 rest_of_handle_stack_regs ();
1807 compute_alignments ();
1809 if (flag_var_tracking)
1810 rest_of_handle_variable_tracking ();
1812 /* CFG is no longer maintained up-to-date. */
1813 free_bb_for_insn ();
1815 if (targetm.machine_dependent_reorg != 0)
1816 rest_of_handle_machine_reorg ();
1818 purge_line_number_notes (get_insns ());
1819 cleanup_barriers ();
1822 if (flag_delayed_branch)
1823 rest_of_handle_delay_slots ();
1826 #if defined (HAVE_ATTR_length) && !defined (STACK_REGS)
1827 timevar_push (TV_SHORTEN_BRANCH);
1828 split_all_insns_noflow ();
1829 timevar_pop (TV_SHORTEN_BRANCH);
1832 convert_to_eh_region_ranges ();
1834 rest_of_handle_shorten_branches ();
1836 set_nothrow_function_flags ();
1838 rest_of_handle_final ();
1840 exit_rest_of_compilation:
1842 rest_of_clean_state ();
1846 finish_optimization_passes (void)
1848 enum tree_dump_index i;
1849 struct dump_file_info *dfi;
1852 timevar_push (TV_DUMP);
1853 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
1855 open_dump_file (DFI_bp, NULL);
1857 close_dump_file (DFI_bp, NULL, NULL_RTX);
1860 if (optimize > 0 && open_dump_file (DFI_combine, NULL))
1862 dump_combine_total_stats (dump_file);
1863 close_dump_file (DFI_combine, NULL, NULL_RTX);
1866 /* Do whatever is necessary to finish printing the graphs. */
1867 if (graph_dump_format != no_graph)
1868 for (i = DFI_MIN; (dfi = get_dump_file_info (i)) != NULL; ++i)
1869 if (dump_initialized_p (i)
1870 && (dfi->flags & TDF_RTL) != 0
1871 && (name = get_dump_file_name (i)) != NULL)
1873 finish_graph_dump_file (name);
1877 timevar_pop (TV_DUMP);
1880 struct tree_opt_pass pass_rest_of_compilation =
1884 rest_of_compilation, /* execute */
1887 0, /* static_pass_number */
1888 TV_REST_OF_COMPILATION, /* tv_id */
1889 PROP_rtl, /* properties_required */
1890 0, /* properties_provided */
1891 PROP_rtl, /* properties_destroyed */
1892 0, /* todo_flags_start */
1893 TODO_ggc_collect, /* todo_flags_finish */