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"
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 /* Describes a dump file. */
113 struct dump_file_info
115 /* The unique extension to apply, e.g. ".jump". */
116 const char *const extension;
118 /* The -d<c> character that enables this dump file. */
119 char const debug_switch;
121 /* True if there is a corresponding graph dump file. */
122 char const graph_dump_p;
124 /* True if the user selected this dump. */
127 /* True if the files have been initialized (ie truncated). */
131 /* Enumerate the extant dump files. */
168 DFI_branch_target_load,
177 /* Describes all the dump files. Should be kept in order of the
178 pass and in sync with dump_file_index above.
180 Remaining -d letters:
186 static struct dump_file_info dump_file_tbl[DFI_MAX] =
188 { "cgraph", 'U', 0, 0, 0 },
189 { "rtl", 'r', 0, 0, 0 },
190 { "sibling", 'i', 0, 0, 0 },
191 { "eh", 'h', 0, 0, 0 },
192 { "jump", 'j', 0, 0, 0 },
193 { "null", 'u', 0, 0, 0 },
194 { "cse", 's', 0, 0, 0 },
195 { "gcse", 'G', 1, 0, 0 },
196 { "loop", 'L', 1, 0, 0 },
197 { "bypass", 'G', 1, 0, 0 }, /* Yes, duplicate enable switch. */
198 { "cfg", 'f', 1, 0, 0 },
199 { "bp", 'b', 1, 0, 0 },
200 { "vpt", 'V', 1, 0, 0 },
201 { "ce1", 'C', 1, 0, 0 },
202 { "tracer", 'T', 1, 0, 0 },
203 { "loop2", 'L', 1, 0, 0 },
204 { "web", 'Z', 0, 0, 0 },
205 { "cse2", 't', 1, 0, 0 },
206 { "life", 'f', 1, 0, 0 }, /* Yes, duplicate enable switch. */
207 { "combine", 'c', 1, 0, 0 },
208 { "ce2", 'C', 1, 0, 0 },
209 { "regmove", 'N', 1, 0, 0 },
210 { "sms", 'm', 0, 0, 0 },
211 { "sched", 'S', 1, 0, 0 },
212 { "lreg", 'l', 1, 0, 0 },
213 { "greg", 'g', 1, 0, 0 },
214 { "postreload", 'o', 1, 0, 0 },
215 { "gcse2", 'J', 0, 0, 0 },
216 { "flow2", 'w', 1, 0, 0 },
217 { "peephole2", 'z', 1, 0, 0 },
218 { "ce3", 'E', 1, 0, 0 },
219 { "rnreg", 'n', 1, 0, 0 },
220 { "bbro", 'B', 1, 0, 0 },
221 { "btl", 'd', 1, 0, 0 }, /* Yes, duplicate enable switch. */
222 { "sched2", 'R', 1, 0, 0 },
223 { "stack", 'k', 1, 0, 0 },
224 { "vartrack", 'V', 1, 0, 0 }, /* Yes, duplicate enable switch. */
225 { "mach", 'M', 1, 0, 0 },
226 { "dbr", 'd', 0, 0, 0 },
229 /* Routine to open a dump file. Return true if the dump file is enabled. */
232 open_dump_file (enum dump_file_index index, tree decl)
235 const char *open_arg;
238 if (! dump_file_tbl[index].enabled)
241 timevar_push (TV_DUMP);
242 if (dump_file != NULL)
245 sprintf (seq, DUMPFILE_FORMAT, index);
247 if (! dump_file_tbl[index].initialized)
249 /* If we've not initialized the files, do so now. */
250 if (graph_dump_format != no_graph
251 && dump_file_tbl[index].graph_dump_p)
253 dump_name = concat (seq, dump_file_tbl[index].extension, NULL);
254 clean_graph_dump_file (dump_base_name, dump_name);
257 dump_file_tbl[index].initialized = 1;
263 dump_name = concat (dump_base_name, seq,
264 dump_file_tbl[index].extension, NULL);
266 dump_file = fopen (dump_name, open_arg);
267 if (dump_file == NULL)
268 fatal_error ("can't open %s: %m", dump_name);
273 fprintf (dump_file, "\n;; Function %s%s\n\n",
274 lang_hooks.decl_printable_name (decl, 2),
275 cfun->function_frequency == FUNCTION_FREQUENCY_HOT
277 : cfun->function_frequency == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED
278 ? " (unlikely executed)"
281 timevar_pop (TV_DUMP);
285 /* Routine to close a dump file. */
288 close_dump_file (enum dump_file_index index,
289 void (*func) (FILE *, rtx),
295 timevar_push (TV_DUMP);
297 && graph_dump_format != no_graph
298 && dump_file_tbl[index].graph_dump_p)
303 sprintf (seq, DUMPFILE_FORMAT, index);
304 suffix = concat (seq, dump_file_tbl[index].extension, NULL);
305 print_rtl_graph_with_bb (dump_base_name, suffix, insns);
310 func (dump_file, insns);
316 timevar_pop (TV_DUMP);
319 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
322 This does nothing for local (non-static) variables, unless the
323 variable is a register variable with an ASMSPEC. In that case, or
324 if the variable is not an automatic, it sets up the RTL and
325 outputs any assembler code (label definition, storage allocation
328 DECL is the declaration. If ASMSPEC is nonzero, it specifies
329 the assembler symbol name to be used. TOP_LEVEL is nonzero
330 if this declaration is not within a function. */
333 rest_of_decl_compilation (tree decl,
338 /* We deferred calling assemble_alias so that we could collect
339 other attributes such as visibility. Emit the alias now. */
342 alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
345 alias = TREE_VALUE (TREE_VALUE (alias));
346 alias = get_identifier (TREE_STRING_POINTER (alias));
347 assemble_alias (decl, alias);
351 /* Forward declarations for nested functions are not "external",
352 but we need to treat them as if they were. */
353 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
354 || TREE_CODE (decl) == FUNCTION_DECL)
356 timevar_push (TV_VARCONST);
359 make_decl_rtl (decl, asmspec);
361 /* Don't output anything when a tentative file-scope definition
362 is seen. But at end of compilation, do output code for them.
364 We do output all variables when unit-at-a-time is active and rely on
365 callgraph code to defer them except for forward declarations
366 (see gcc.c-torture/compile/920624-1.c) */
368 || !DECL_DEFER_OUTPUT (decl)
369 || (flag_unit_at_a_time && DECL_INITIAL (decl)))
370 && !DECL_EXTERNAL (decl))
372 if (flag_unit_at_a_time && !cgraph_global_info_ready
373 && TREE_CODE (decl) != FUNCTION_DECL && top_level)
374 cgraph_varpool_finalize_decl (decl);
376 assemble_variable (decl, top_level, at_end, 0);
379 #ifdef ASM_FINISH_DECLARE_OBJECT
380 if (decl == last_assemble_variable_decl)
382 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
387 timevar_pop (TV_VARCONST);
389 else if (DECL_REGISTER (decl) && asmspec != 0)
391 if (decode_reg_name (asmspec) >= 0)
393 SET_DECL_RTL (decl, NULL_RTX);
394 make_decl_rtl (decl, asmspec);
398 error ("%Hinvalid register name `%s' for register variable",
399 &DECL_SOURCE_LOCATION (decl), asmspec);
400 DECL_REGISTER (decl) = 0;
405 else if (TREE_CODE (decl) == TYPE_DECL)
407 timevar_push (TV_SYMOUT);
408 debug_hooks->type_decl (decl, !top_level);
409 timevar_pop (TV_SYMOUT);
413 /* Called after finishing a record, union or enumeral type. */
416 rest_of_type_compilation (tree type, int toplev)
418 /* Avoid confusing the debug information machinery when there are
420 if (errorcount != 0 || sorrycount != 0)
423 timevar_push (TV_SYMOUT);
424 debug_hooks->type_decl (TYPE_STUB_DECL (type), !toplev);
425 timevar_pop (TV_SYMOUT);
428 /* Turn the RTL into assembly. */
430 rest_of_handle_final (void)
432 timevar_push (TV_FINAL);
437 /* Get the function's name, as described by its RTL. This may be
438 different from the DECL_NAME name used in the source file. */
440 x = DECL_RTL (current_function_decl);
444 if (GET_CODE (x) != SYMBOL_REF)
446 fnname = XSTR (x, 0);
448 assemble_start_function (current_function_decl, fnname);
449 final_start_function (get_insns (), asm_out_file, optimize);
450 final (get_insns (), asm_out_file, optimize, 0);
451 final_end_function ();
453 #ifdef IA64_UNWIND_INFO
454 /* ??? The IA-64 ".handlerdata" directive must be issued before
455 the ".endp" directive that closes the procedure descriptor. */
456 output_function_exception_table ();
459 assemble_end_function (current_function_decl, fnname);
461 #ifndef IA64_UNWIND_INFO
462 /* Otherwise, it feels unclean to switch sections in the middle. */
463 output_function_exception_table ();
467 fflush (asm_out_file);
469 /* Release all memory allocated by flow. */
470 free_basic_block_vars ();
472 /* Release all memory held by regsets now. */
473 regset_release_memory ();
476 /* Write DBX symbols if requested. */
478 /* Note that for those inline functions where we don't initially
479 know for certain that we will be generating an out-of-line copy,
480 the first invocation of this routine (rest_of_compilation) will
481 skip over this code by doing a `goto exit_rest_of_compilation;'.
482 Later on, wrapup_global_declarations will (indirectly) call
483 rest_of_compilation again for those inline functions that need
484 to have out-of-line copies generated. During that call, we
485 *will* be routed past here. */
487 timevar_push (TV_SYMOUT);
488 (*debug_hooks->function_decl) (current_function_decl);
489 timevar_pop (TV_SYMOUT);
492 timevar_pop (TV_FINAL);
496 /* Run delay slot optimization. */
498 rest_of_handle_delay_slots (void)
500 timevar_push (TV_DBR_SCHED);
501 open_dump_file (DFI_dbr, current_function_decl);
503 dbr_schedule (get_insns (), dump_file);
505 close_dump_file (DFI_dbr, print_rtl, get_insns ());
509 timevar_pop (TV_DBR_SCHED);
514 /* Convert register usage from flat register file usage to a stack
517 rest_of_handle_stack_regs (void)
519 #if defined (HAVE_ATTR_length)
520 /* If flow2 creates new instructions which need splitting
521 and scheduling after reload is not done, they might not be
522 split until final which doesn't allow splitting
523 if HAVE_ATTR_length. */
524 #ifdef INSN_SCHEDULING
525 if (optimize && !flag_schedule_insns_after_reload)
530 timevar_push (TV_SHORTEN_BRANCH);
532 timevar_pop (TV_SHORTEN_BRANCH);
536 timevar_push (TV_REG_STACK);
537 open_dump_file (DFI_stack, current_function_decl);
539 if (reg_to_stack (dump_file) && optimize)
541 if (cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK
542 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0))
543 && (flag_reorder_blocks || flag_reorder_blocks_and_partition))
545 reorder_basic_blocks ();
546 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK);
550 close_dump_file (DFI_stack, print_rtl_with_bb, get_insns ());
553 timevar_pop (TV_REG_STACK);
557 /* Track the variables, ie. compute where the variable is stored at each position in function. */
559 rest_of_handle_variable_tracking (void)
561 timevar_push (TV_VAR_TRACKING);
562 open_dump_file (DFI_vartrack, current_function_decl);
564 variable_tracking_main ();
566 close_dump_file (DFI_vartrack, print_rtl_with_bb, get_insns ());
567 timevar_pop (TV_VAR_TRACKING);
570 /* Machine dependent reorg pass. */
572 rest_of_handle_machine_reorg (void)
574 timevar_push (TV_MACH_DEP);
575 open_dump_file (DFI_mach, current_function_decl);
577 targetm.machine_dependent_reorg ();
579 close_dump_file (DFI_mach, print_rtl, get_insns ());
582 timevar_pop (TV_MACH_DEP);
586 /* Run new register allocator. Return TRUE if we must exit
587 rest_of_compilation upon return. */
589 rest_of_handle_new_regalloc (void)
593 timevar_push (TV_LOCAL_ALLOC);
594 open_dump_file (DFI_lreg, current_function_decl);
596 delete_trivially_dead_insns (get_insns (), max_reg_num ());
599 timevar_pop (TV_LOCAL_ALLOC);
600 close_dump_file (DFI_lreg, NULL, NULL);
602 /* XXX clean up the whole mess to bring live info in shape again. */
603 timevar_push (TV_GLOBAL_ALLOC);
604 open_dump_file (DFI_greg, current_function_decl);
606 build_insn_chain (get_insns ());
607 failure = reload (get_insns (), 0);
609 timevar_pop (TV_GLOBAL_ALLOC);
613 if (dump_file_tbl[DFI_greg].enabled)
615 timevar_push (TV_DUMP);
616 dump_global_regs (dump_file);
617 timevar_pop (TV_DUMP);
618 close_dump_file (DFI_greg, print_rtl_with_bb, get_insns ());
624 reload_completed = 1;
629 /* Run old register allocator. Return TRUE if we must exit
630 rest_of_compilation upon return. */
632 rest_of_handle_old_regalloc (void)
637 timevar_push (TV_LOCAL_ALLOC);
638 open_dump_file (DFI_lreg, current_function_decl);
640 /* Allocate the reg_renumber array. */
641 allocate_reg_info (max_regno, FALSE, TRUE);
643 /* And the reg_equiv_memory_loc array. */
644 VARRAY_GROW (reg_equiv_memory_loc_varray, max_regno);
645 reg_equiv_memory_loc = &VARRAY_RTX (reg_equiv_memory_loc_varray, 0);
647 allocate_initial_values (reg_equiv_memory_loc);
649 regclass (get_insns (), max_reg_num (), dump_file);
650 rebuild_notes = local_alloc ();
652 timevar_pop (TV_LOCAL_ALLOC);
654 /* Local allocation may have turned an indirect jump into a direct
655 jump. If so, we must rebuild the JUMP_LABEL fields of jumping
659 timevar_push (TV_JUMP);
661 rebuild_jump_labels (get_insns ());
662 purge_all_dead_edges (0);
664 timevar_pop (TV_JUMP);
667 if (dump_file_tbl[DFI_lreg].enabled)
669 timevar_push (TV_DUMP);
670 dump_flow_info (dump_file);
671 dump_local_alloc (dump_file);
672 timevar_pop (TV_DUMP);
675 close_dump_file (DFI_lreg, print_rtl_with_bb, get_insns ());
679 timevar_push (TV_GLOBAL_ALLOC);
680 open_dump_file (DFI_greg, current_function_decl);
682 /* If optimizing, allocate remaining pseudo-regs. Do the reload
683 pass fixing up any insns that are invalid. */
686 failure = global_alloc (dump_file);
689 build_insn_chain (get_insns ());
690 failure = reload (get_insns (), 0);
693 if (dump_file_tbl[DFI_greg].enabled)
695 timevar_push (TV_DUMP);
696 dump_global_regs (dump_file);
697 timevar_pop (TV_DUMP);
699 close_dump_file (DFI_greg, print_rtl_with_bb, get_insns ());
704 timevar_pop (TV_GLOBAL_ALLOC);
709 /* Run the regrename and cprop passes. */
711 rest_of_handle_regrename (void)
713 timevar_push (TV_RENAME_REGISTERS);
714 open_dump_file (DFI_rnreg, current_function_decl);
716 if (flag_rename_registers)
717 regrename_optimize ();
718 if (flag_cprop_registers)
719 copyprop_hardreg_forward ();
721 close_dump_file (DFI_rnreg, print_rtl_with_bb, get_insns ());
722 timevar_pop (TV_RENAME_REGISTERS);
725 /* Reorder basic blocks. */
727 rest_of_handle_reorder_blocks (void)
730 open_dump_file (DFI_bbro, current_function_decl);
732 /* Last attempt to optimize CFG, as scheduling, peepholing and insn
733 splitting possibly introduced more crossjumping opportunities. */
734 changed = cleanup_cfg (CLEANUP_EXPENSIVE
735 | (!HAVE_conditional_execution
736 ? CLEANUP_UPDATE_LIFE : 0));
738 if (flag_sched2_use_traces && flag_schedule_insns_after_reload)
740 if (flag_reorder_blocks || flag_reorder_blocks_and_partition)
741 reorder_basic_blocks ();
742 if (flag_reorder_blocks || flag_reorder_blocks_and_partition
743 || (flag_sched2_use_traces && flag_schedule_insns_after_reload))
744 changed |= cleanup_cfg (CLEANUP_EXPENSIVE
745 | (!HAVE_conditional_execution
746 ? CLEANUP_UPDATE_LIFE : 0));
748 /* On conditional execution targets we can not update the life cheaply, so
749 we deffer the updating to after both cleanups. This may lose some cases
750 but should not be terribly bad. */
751 if (changed && HAVE_conditional_execution)
752 update_life_info (NULL, UPDATE_LIFE_GLOBAL_RM_NOTES,
754 close_dump_file (DFI_bbro, print_rtl_with_bb, get_insns ());
757 /* Partition hot and cold basic blocks. */
759 rest_of_handle_partition_blocks (void)
762 partition_hot_cold_basic_blocks ();
763 allocate_reg_life_data ();
764 update_life_info (NULL, UPDATE_LIFE_GLOBAL_RM_NOTES,
765 PROP_LOG_LINKS | PROP_REG_INFO | PROP_DEATH_NOTES);
769 #ifdef INSN_SCHEDULING
770 /* Run instruction scheduler. */
771 /* Perform SMS module scheduling. */
773 rest_of_handle_sms (void)
775 timevar_push (TV_SMS);
776 open_dump_file (DFI_sms, current_function_decl);
778 /* We want to be able to create new pseudos. */
780 sms_schedule (dump_file);
781 close_dump_file (DFI_sms, print_rtl, get_insns ());
784 /* Update the life information, because we add pseudos. */
785 max_regno = max_reg_num ();
786 allocate_reg_info (max_regno, FALSE, FALSE);
787 update_life_info_in_dirty_blocks (UPDATE_LIFE_GLOBAL_RM_NOTES,
789 | PROP_KILL_DEAD_CODE
790 | PROP_SCAN_DEAD_CODE));
794 timevar_pop (TV_SMS);
797 /* Run instruction scheduler. */
799 rest_of_handle_sched (void)
801 timevar_push (TV_SCHED);
803 /* Print function header into sched dump now
804 because doing the sched analysis makes some of the dump. */
805 open_dump_file (DFI_sched, current_function_decl);
807 /* Do control and data sched analysis,
808 and write some of the results to dump file. */
810 schedule_insns (dump_file);
812 close_dump_file (DFI_sched, print_rtl_with_bb, get_insns ());
815 timevar_pop (TV_SCHED);
818 /* Run second scheduling pass after reload. */
820 rest_of_handle_sched2 (void)
822 timevar_push (TV_SCHED2);
823 open_dump_file (DFI_sched2, current_function_decl);
825 /* Do control and data sched analysis again,
826 and write some more of the results to dump file. */
830 if (flag_sched2_use_superblocks || flag_sched2_use_traces)
832 schedule_ebbs (dump_file);
833 /* No liveness updating code yet, but it should be easy to do.
834 reg-stack recomputes the liveness when needed for now. */
835 count_or_remove_death_notes (NULL, 1);
836 cleanup_cfg (CLEANUP_EXPENSIVE);
839 schedule_insns (dump_file);
841 close_dump_file (DFI_sched2, print_rtl_with_bb, get_insns ());
845 timevar_pop (TV_SCHED2);
850 rest_of_handle_gcse2 (void)
852 timevar_push (TV_RELOAD_CSE_REGS);
853 open_dump_file (DFI_gcse2, current_function_decl);
855 gcse_after_reload_main (get_insns (), dump_file);
856 rebuild_jump_labels (get_insns ());
857 delete_trivially_dead_insns (get_insns (), max_reg_num ());
858 close_dump_file (DFI_gcse2, print_rtl_with_bb, get_insns ());
862 #ifdef ENABLE_CHECKING
866 timevar_pop (TV_RELOAD_CSE_REGS);
869 /* Register allocation pre-pass, to reduce number of moves necessary
870 for two-address machines. */
872 rest_of_handle_regmove (void)
874 timevar_push (TV_REGMOVE);
875 open_dump_file (DFI_regmove, current_function_decl);
877 regmove_optimize (get_insns (), max_reg_num (), dump_file);
879 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
880 close_dump_file (DFI_regmove, print_rtl_with_bb, get_insns ());
883 timevar_pop (TV_REGMOVE);
888 rest_of_handle_tracer (void)
890 open_dump_file (DFI_tracer, current_function_decl);
892 dump_flow_info (dump_file);
894 cleanup_cfg (CLEANUP_EXPENSIVE);
895 reg_scan (get_insns (), max_reg_num (), 0);
896 close_dump_file (DFI_tracer, print_rtl_with_bb, get_insns ());
899 /* If-conversion and CFG cleanup. */
901 rest_of_handle_if_conversion (void)
903 timevar_push (TV_IFCVT);
904 open_dump_file (DFI_ce1, current_function_decl);
906 if (flag_if_conversion)
909 dump_flow_info (dump_file);
910 cleanup_cfg (CLEANUP_EXPENSIVE);
911 reg_scan (get_insns (), max_reg_num (), 0);
915 timevar_push (TV_JUMP);
916 cleanup_cfg (CLEANUP_EXPENSIVE);
917 reg_scan (get_insns (), max_reg_num (), 0);
918 timevar_pop (TV_JUMP);
920 close_dump_file (DFI_ce1, print_rtl_with_bb, get_insns ());
921 timevar_pop (TV_IFCVT);
924 /* Rerun if-conversion, as combine may have simplified things enough
925 to now meet sequence length restrictions. */
927 rest_of_handle_if_after_combine (void)
929 timevar_push (TV_IFCVT);
930 open_dump_file (DFI_ce2, current_function_decl);
936 close_dump_file (DFI_ce2, print_rtl_with_bb, get_insns ());
937 timevar_pop (TV_IFCVT);
941 rest_of_handle_if_after_reload (void)
943 timevar_push (TV_IFCVT2);
944 open_dump_file (DFI_ce3, current_function_decl);
946 /* Last attempt to optimize CFG, as scheduling, peepholing and insn
947 splitting possibly introduced more crossjumping opportunities. */
948 cleanup_cfg (CLEANUP_EXPENSIVE
949 | CLEANUP_UPDATE_LIFE
950 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0));
951 if (flag_if_conversion2)
953 close_dump_file (DFI_ce3, print_rtl_with_bb, get_insns ());
954 timevar_pop (TV_IFCVT2);
958 rest_of_handle_web (void)
960 open_dump_file (DFI_web, current_function_decl);
961 timevar_push (TV_WEB);
963 delete_trivially_dead_insns (get_insns (), max_reg_num ());
964 cleanup_cfg (CLEANUP_EXPENSIVE);
966 timevar_pop (TV_WEB);
967 close_dump_file (DFI_web, print_rtl_with_bb, get_insns ());
968 reg_scan (get_insns (), max_reg_num (), 0);
971 /* Do branch profiling and static profile estimation passes. */
973 rest_of_handle_branch_prob (void)
977 timevar_push (TV_BRANCH_PROB);
978 open_dump_file (DFI_bp, current_function_decl);
980 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
983 /* Discover and record the loop depth at the head of each basic
984 block. The loop infrastructure does the real job for us. */
985 flow_loops_find (&loops, LOOP_TREE);
988 flow_loops_dump (&loops, dump_file, NULL, 0);
990 /* Estimate using heuristics if no profiling info is available. */
991 if (flag_guess_branch_prob)
992 estimate_probability (&loops);
994 flow_loops_free (&loops);
995 free_dominance_info (CDI_DOMINATORS);
996 close_dump_file (DFI_bp, print_rtl_with_bb, get_insns ());
997 timevar_pop (TV_BRANCH_PROB);
1000 /* Do optimizations based on expression value profiles. */
1002 rest_of_handle_value_profile_transformations (void)
1004 open_dump_file (DFI_vpt, current_function_decl);
1005 timevar_push (TV_VPT);
1007 if (value_profile_transformations ())
1008 cleanup_cfg (CLEANUP_EXPENSIVE);
1010 timevar_pop (TV_VPT);
1011 close_dump_file (DFI_vpt, print_rtl_with_bb, get_insns ());
1014 /* Do control and data flow analysis; write some of the results to the
1017 rest_of_handle_cfg (void)
1019 open_dump_file (DFI_cfg, current_function_decl);
1021 dump_flow_info (dump_file);
1023 cleanup_cfg (CLEANUP_EXPENSIVE
1024 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
1026 /* It may make more sense to mark constant functions after dead code is
1027 eliminated by life_analysis, but we need to do it early, as -fprofile-arcs
1028 may insert code making function non-constant, but we still must consider
1029 it as constant, otherwise -fbranch-probabilities will not read data back.
1031 life_analysis rarely eliminates modification of external memory.
1035 /* Alias analysis depends on this information and mark_constant_function
1036 depends on alias analysis. */
1037 reg_scan (get_insns (), max_reg_num (), 1);
1038 mark_constant_function ();
1041 close_dump_file (DFI_cfg, print_rtl_with_bb, get_insns ());
1044 /* Perform jump bypassing and control flow optimizations. */
1046 rest_of_handle_jump_bypass (void)
1048 timevar_push (TV_BYPASS);
1049 open_dump_file (DFI_bypass, current_function_decl);
1051 cleanup_cfg (CLEANUP_EXPENSIVE);
1052 reg_scan (get_insns (), max_reg_num (), 1);
1054 if (bypass_jumps (dump_file))
1056 rebuild_jump_labels (get_insns ());
1057 cleanup_cfg (CLEANUP_EXPENSIVE);
1058 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1061 close_dump_file (DFI_bypass, print_rtl_with_bb, get_insns ());
1062 timevar_pop (TV_BYPASS);
1066 #ifdef ENABLE_CHECKING
1067 verify_flow_info ();
1071 /* Try combining insns through substitution. */
1073 rest_of_handle_combine (void)
1075 int rebuild_jump_labels_after_combine = 0;
1077 timevar_push (TV_COMBINE);
1078 open_dump_file (DFI_combine, current_function_decl);
1080 rebuild_jump_labels_after_combine
1081 = combine_instructions (get_insns (), max_reg_num ());
1083 /* Combining insns may have turned an indirect jump into a
1084 direct jump. Rebuild the JUMP_LABEL fields of jumping
1086 if (rebuild_jump_labels_after_combine)
1088 timevar_push (TV_JUMP);
1089 rebuild_jump_labels (get_insns ());
1090 timevar_pop (TV_JUMP);
1092 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
1095 close_dump_file (DFI_combine, print_rtl_with_bb, get_insns ());
1096 timevar_pop (TV_COMBINE);
1101 /* Perform life analysis. */
1103 rest_of_handle_life (void)
1105 open_dump_file (DFI_life, current_function_decl);
1108 #ifdef ENABLE_CHECKING
1109 verify_flow_info ();
1111 life_analysis (dump_file, PROP_FINAL);
1113 cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_UPDATE_LIFE
1115 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
1119 setjmp_vars_warning (DECL_INITIAL (current_function_decl));
1120 setjmp_args_warning ();
1125 if (!flag_new_regalloc && initialize_uninitialized_subregs ())
1127 /* Insns were inserted, and possibly pseudos created, so
1128 things might look a bit different. */
1129 allocate_reg_life_data ();
1130 update_life_info (NULL, UPDATE_LIFE_GLOBAL_RM_NOTES,
1131 PROP_LOG_LINKS | PROP_REG_INFO | PROP_DEATH_NOTES);
1137 close_dump_file (DFI_life, print_rtl_with_bb, get_insns ());
1142 /* Perform common subexpression elimination. Nonzero value from
1143 `cse_main' means that jumps were simplified and some code may now
1144 be unreachable, so do jump optimization again. */
1146 rest_of_handle_cse (void)
1150 open_dump_file (DFI_cse, current_function_decl);
1152 dump_flow_info (dump_file);
1153 timevar_push (TV_CSE);
1155 reg_scan (get_insns (), max_reg_num (), 1);
1157 tem = cse_main (get_insns (), max_reg_num (), 0, dump_file);
1159 rebuild_jump_labels (get_insns ());
1160 if (purge_all_dead_edges (0))
1161 delete_unreachable_blocks ();
1163 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1165 /* If we are not running more CSE passes, then we are no longer
1166 expecting CSE to be run. But always rerun it in a cheap mode. */
1167 cse_not_expected = !flag_rerun_cse_after_loop && !flag_gcse;
1169 if (tem || optimize > 1)
1170 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
1172 timevar_pop (TV_CSE);
1173 close_dump_file (DFI_cse, print_rtl_with_bb, get_insns ());
1178 /* Run second CSE pass after loop optimizations. */
1180 rest_of_handle_cse2 (void)
1184 timevar_push (TV_CSE2);
1185 open_dump_file (DFI_cse2, current_function_decl);
1187 dump_flow_info (dump_file);
1188 /* CFG is no longer maintained up-to-date. */
1189 tem = cse_main (get_insns (), max_reg_num (), 1, dump_file);
1191 /* Run a pass to eliminate duplicated assignments to condition code
1192 registers. We have to run this after bypass_jumps, because it
1193 makes it harder for that pass to determine whether a jump can be
1195 cse_condition_code_reg ();
1197 purge_all_dead_edges (0);
1198 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1202 timevar_push (TV_JUMP);
1203 rebuild_jump_labels (get_insns ());
1204 cleanup_cfg (CLEANUP_EXPENSIVE);
1205 timevar_pop (TV_JUMP);
1207 reg_scan (get_insns (), max_reg_num (), 0);
1208 close_dump_file (DFI_cse2, print_rtl_with_bb, get_insns ());
1209 timevar_pop (TV_CSE2);
1214 /* Perform global cse. */
1216 rest_of_handle_gcse (void)
1218 int save_csb, save_cfj;
1221 timevar_push (TV_GCSE);
1222 open_dump_file (DFI_gcse, current_function_decl);
1224 tem = gcse_main (get_insns (), dump_file);
1225 rebuild_jump_labels (get_insns ());
1226 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1228 save_csb = flag_cse_skip_blocks;
1229 save_cfj = flag_cse_follow_jumps;
1230 flag_cse_skip_blocks = flag_cse_follow_jumps = 0;
1232 /* If -fexpensive-optimizations, re-run CSE to clean up things done
1234 if (flag_expensive_optimizations)
1236 timevar_push (TV_CSE);
1237 reg_scan (get_insns (), max_reg_num (), 1);
1238 tem2 = cse_main (get_insns (), max_reg_num (), 0, dump_file);
1239 purge_all_dead_edges (0);
1240 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1241 timevar_pop (TV_CSE);
1242 cse_not_expected = !flag_rerun_cse_after_loop;
1245 /* If gcse or cse altered any jumps, rerun jump optimizations to clean
1246 things up. Then possibly re-run CSE again. */
1250 timevar_push (TV_JUMP);
1251 rebuild_jump_labels (get_insns ());
1252 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
1253 timevar_pop (TV_JUMP);
1255 if (flag_expensive_optimizations)
1257 timevar_push (TV_CSE);
1258 reg_scan (get_insns (), max_reg_num (), 1);
1259 tem2 = cse_main (get_insns (), max_reg_num (), 0, dump_file);
1260 purge_all_dead_edges (0);
1261 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1262 timevar_pop (TV_CSE);
1266 close_dump_file (DFI_gcse, print_rtl_with_bb, get_insns ());
1267 timevar_pop (TV_GCSE);
1270 flag_cse_skip_blocks = save_csb;
1271 flag_cse_follow_jumps = save_cfj;
1272 #ifdef ENABLE_CHECKING
1273 verify_flow_info ();
1277 /* Move constant computations out of loops. */
1279 rest_of_handle_loop_optimize (void)
1281 int do_unroll, do_prefetch;
1283 timevar_push (TV_LOOP);
1284 delete_dead_jumptables ();
1285 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
1286 open_dump_file (DFI_loop, current_function_decl);
1288 /* CFG is no longer maintained up-to-date. */
1289 free_bb_for_insn ();
1291 if (flag_unroll_loops)
1292 do_unroll = LOOP_AUTO_UNROLL; /* Having two unrollers is useless. */
1294 do_unroll = flag_old_unroll_loops ? LOOP_UNROLL : LOOP_AUTO_UNROLL;
1295 do_prefetch = flag_prefetch_loop_arrays ? LOOP_PREFETCH : 0;
1297 if (flag_rerun_loop_opt)
1299 cleanup_barriers ();
1301 /* We only want to perform unrolling once. */
1302 loop_optimize (get_insns (), dump_file, do_unroll);
1305 /* The first call to loop_optimize makes some instructions
1306 trivially dead. We delete those instructions now in the
1307 hope that doing so will make the heuristics in loop work
1308 better and possibly speed up compilation. */
1309 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1311 /* The regscan pass is currently necessary as the alias
1312 analysis code depends on this information. */
1313 reg_scan (get_insns (), max_reg_num (), 1);
1315 cleanup_barriers ();
1316 loop_optimize (get_insns (), dump_file, do_unroll | do_prefetch);
1318 /* Loop can create trivially dead instructions. */
1319 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1320 find_basic_blocks (get_insns (), max_reg_num (), dump_file);
1321 close_dump_file (DFI_loop, print_rtl, get_insns ());
1322 timevar_pop (TV_LOOP);
1327 /* Perform loop optimizations. It might be better to do them a bit
1328 sooner, but we want the profile feedback to work more
1331 rest_of_handle_loop2 (void)
1333 struct loops *loops;
1336 if (!flag_move_loop_invariants
1337 && !flag_unswitch_loops
1339 && !flag_unroll_loops
1340 && !flag_branch_on_count_reg)
1343 timevar_push (TV_LOOP);
1344 open_dump_file (DFI_loop2, current_function_decl);
1346 dump_flow_info (dump_file);
1348 /* Initialize structures for layout changes. */
1349 cfg_layout_initialize ();
1351 loops = loop_optimizer_init (dump_file);
1355 /* The optimizations: */
1356 if (flag_move_loop_invariants)
1357 move_loop_invariants (loops);
1359 if (flag_unswitch_loops)
1360 unswitch_loops (loops);
1362 if (flag_peel_loops || flag_unroll_loops)
1363 unroll_and_peel_loops (loops,
1364 (flag_peel_loops ? UAP_PEEL : 0) |
1365 (flag_unroll_loops ? UAP_UNROLL : 0) |
1366 (flag_unroll_all_loops ? UAP_UNROLL_ALL : 0));
1368 #ifdef HAVE_doloop_end
1369 if (flag_branch_on_count_reg && HAVE_doloop_end)
1370 doloop_optimize_loops (loops);
1371 #endif /* HAVE_doloop_end */
1373 loop_optimizer_finalize (loops, dump_file);
1376 /* Finalize layout changes. */
1378 if (bb->next_bb != EXIT_BLOCK_PTR)
1379 bb->rbi->next = bb->next_bb;
1380 cfg_layout_finalize ();
1382 cleanup_cfg (CLEANUP_EXPENSIVE);
1383 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1384 reg_scan (get_insns (), max_reg_num (), 0);
1386 dump_flow_info (dump_file);
1387 close_dump_file (DFI_loop2, print_rtl_with_bb, get_insns ());
1388 timevar_pop (TV_LOOP);
1393 rest_of_handle_branch_target_load_optimize (void)
1395 static int warned = 0;
1397 /* Leave this a warning for now so that it is possible to experiment
1398 with running this pass twice. In 3.6, we should either make this
1399 an error, or use separate dump files. */
1400 if (flag_branch_target_load_optimize
1401 && flag_branch_target_load_optimize2
1404 warning ("branch target register load optimization is not intended "
1410 open_dump_file (DFI_branch_target_load, current_function_decl);
1411 branch_target_load_optimize (epilogue_completed);
1412 close_dump_file (DFI_branch_target_load, print_rtl_with_bb, get_insns ());
1416 #ifdef OPTIMIZE_MODE_SWITCHING
1418 rest_of_handle_mode_switching (void)
1420 timevar_push (TV_MODE_SWITCH);
1423 optimize_mode_switching (NULL);
1426 timevar_pop (TV_MODE_SWITCH);
1431 rest_of_handle_jump (void)
1435 timevar_push (TV_JUMP);
1436 open_dump_file (DFI_sibling, current_function_decl);
1438 /* ??? We may get caled either via tree_rest_of_compilation when the CFG
1439 is already built or directly (for instance from coverage code).
1440 The direct callers shall be updated. */
1441 if (!basic_block_info)
1444 rebuild_jump_labels (get_insns ());
1445 find_exception_handler_labels ();
1446 find_basic_blocks (get_insns (), max_reg_num (), dump_file);
1449 /* ??? We may get called either via tree_rest_of_compilation when the CFG
1450 is already built or directly (for instance from coverage code).
1451 The direct callers shall be updated. */
1452 if (!basic_block_info)
1455 rebuild_jump_labels (get_insns ());
1456 find_exception_handler_labels ();
1457 find_basic_blocks (get_insns (), max_reg_num (), dump_file);
1459 delete_unreachable_blocks ();
1460 #ifdef ENABLE_CHECKING
1461 verify_flow_info ();
1463 timevar_pop (TV_JUMP);
1467 rest_of_handle_guess_branch_prob (void)
1469 /* Turn NOTE_INSN_PREDICTIONs into branch predictions. */
1470 if (flag_guess_branch_prob)
1472 timevar_push (TV_BRANCH_PROB);
1473 note_prediction_to_br_prob ();
1474 timevar_pop (TV_BRANCH_PROB);
1479 rest_of_handle_eh (void)
1481 insn_locators_initialize ();
1482 /* Complete generation of exception handling code. */
1485 timevar_push (TV_JUMP);
1486 open_dump_file (DFI_eh, current_function_decl);
1488 finish_eh_generation ();
1490 close_dump_file (DFI_eh, print_rtl, get_insns ());
1491 timevar_pop (TV_JUMP);
1497 rest_of_handle_prologue_epilogue (void)
1499 if (optimize && !flow2_completed)
1500 cleanup_cfg (CLEANUP_EXPENSIVE);
1502 /* On some machines, the prologue and epilogue code, or parts thereof,
1503 can be represented as RTL. Doing so lets us schedule insns between
1504 it and the rest of the code and also allows delayed branch
1505 scheduling to operate in the epilogue. */
1506 thread_prologue_and_epilogue_insns (get_insns ());
1507 epilogue_completed = 1;
1509 if (optimize && flow2_completed)
1510 life_analysis (dump_file, PROP_POSTRELOAD);
1514 rest_of_handle_stack_adjustments (void)
1516 life_analysis (dump_file, PROP_POSTRELOAD);
1517 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE
1518 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0));
1520 /* This is kind of a heuristic. We need to run combine_stack_adjustments
1521 even for machines with possibly nonzero RETURN_POPS_ARGS
1522 and ACCUMULATE_OUTGOING_ARGS. We expect that only ports having
1523 push instructions will have popping returns. */
1524 #ifndef PUSH_ROUNDING
1525 if (!ACCUMULATE_OUTGOING_ARGS)
1527 combine_stack_adjustments ();
1531 rest_of_handle_flow2 (void)
1533 timevar_push (TV_FLOW2);
1534 open_dump_file (DFI_flow2, current_function_decl);
1536 /* Re-create the death notes which were deleted during reload. */
1537 #ifdef ENABLE_CHECKING
1538 verify_flow_info ();
1541 /* If optimizing, then go ahead and split insns now. */
1545 split_all_insns (0);
1547 if (flag_branch_target_load_optimize)
1548 rest_of_handle_branch_target_load_optimize ();
1550 if (!targetm.late_rtl_prologue_epilogue)
1551 rest_of_handle_prologue_epilogue ();
1554 rest_of_handle_stack_adjustments ();
1556 flow2_completed = 1;
1558 close_dump_file (DFI_flow2, print_rtl_with_bb, get_insns ());
1559 timevar_pop (TV_FLOW2);
1566 rest_of_handle_jump2 (void)
1568 open_dump_file (DFI_jump, current_function_decl);
1570 /* Always do one jump optimization pass to ensure that JUMP_LABEL fields
1571 are initialized and to compute whether control can drop off the end
1574 timevar_push (TV_JUMP);
1575 /* Turn NOTE_INSN_EXPECTED_VALUE into REG_BR_PROB. Do this
1576 before jump optimization switches branch directions. */
1577 if (flag_guess_branch_prob)
1578 expected_value_to_br_prob ();
1580 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1581 reg_scan (get_insns (), max_reg_num (), 0);
1583 dump_flow_info (dump_file);
1584 cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_PRE_LOOP
1585 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
1587 create_loop_notes ();
1589 purge_line_number_notes (get_insns ());
1592 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
1594 /* Jump optimization, and the removal of NULL pointer checks, may
1595 have reduced the number of instructions substantially. CSE, and
1596 future passes, allocate arrays whose dimensions involve the
1597 maximum instruction UID, so if we can reduce the maximum UID
1598 we'll save big on memory. */
1599 renumber_insns (dump_file);
1601 close_dump_file (DFI_jump, print_rtl_with_bb, get_insns ());
1602 timevar_pop (TV_JUMP);
1607 #ifdef HAVE_peephole2
1609 rest_of_handle_peephole2 (void)
1611 timevar_push (TV_PEEPHOLE2);
1612 open_dump_file (DFI_peephole2, current_function_decl);
1614 peephole2_optimize (dump_file);
1616 close_dump_file (DFI_peephole2, print_rtl_with_bb, get_insns ());
1617 timevar_pop (TV_PEEPHOLE2);
1622 rest_of_handle_postreload (void)
1624 timevar_push (TV_RELOAD_CSE_REGS);
1625 open_dump_file (DFI_postreload, current_function_decl);
1627 /* Do a very simple CSE pass over just the hard registers. */
1628 reload_cse_regs (get_insns ());
1629 /* reload_cse_regs can eliminate potentially-trapping MEMs.
1630 Remove any EH edges associated with them. */
1631 if (flag_non_call_exceptions)
1632 purge_all_dead_edges (0);
1634 close_dump_file (DFI_postreload, print_rtl_with_bb, get_insns ());
1635 timevar_pop (TV_RELOAD_CSE_REGS);
1639 rest_of_handle_shorten_branches (void)
1641 /* Shorten branches. */
1642 timevar_push (TV_SHORTEN_BRANCH);
1643 shorten_branches (get_insns ());
1644 timevar_pop (TV_SHORTEN_BRANCH);
1648 rest_of_clean_state (void)
1650 coverage_end_function ();
1652 /* In case the function was not output,
1653 don't leave any temporary anonymous types
1654 queued up for sdb output. */
1655 #ifdef SDB_DEBUGGING_INFO
1656 if (write_symbols == SDB_DEBUG)
1657 sdbout_types (NULL_TREE);
1660 reload_completed = 0;
1661 epilogue_completed = 0;
1662 flow2_completed = 0;
1665 timevar_push (TV_FINAL);
1667 /* Clear out the insn_length contents now that they are no
1669 init_insn_lengths ();
1671 /* Show no temporary slots allocated. */
1674 free_basic_block_vars ();
1675 free_bb_for_insn ();
1677 timevar_pop (TV_FINAL);
1679 if (targetm.binds_local_p (current_function_decl))
1681 int pref = cfun->preferred_stack_boundary;
1682 if (cfun->recursive_call_emit
1683 && cfun->stack_alignment_needed > cfun->preferred_stack_boundary)
1684 pref = cfun->stack_alignment_needed;
1685 cgraph_rtl_info (current_function_decl)->preferred_incoming_stack_boundary
1689 /* Make sure volatile mem refs aren't considered valid operands for
1690 arithmetic insns. We must call this here if this is a nested inline
1691 function, since the above code leaves us in the init_recog state
1692 (from final.c), and the function context push/pop code does not
1693 save/restore volatile_ok.
1695 ??? Maybe it isn't necessary for expand_start_function to call this
1696 anymore if we do it here? */
1698 init_recog_no_volatile ();
1700 /* We're done with this function. Free up memory if we can. */
1701 free_after_parsing (cfun);
1705 /* This is called from finish_function (within langhooks.parse_file)
1706 after each top-level definition is parsed.
1707 It is supposed to compile that function or variable
1708 and output the assembler code for it.
1709 After we return, the tree storage is freed. */
1712 rest_of_compilation (void)
1714 /* There's no need to defer outputting this function any more; we
1715 know we want to output it. */
1716 DECL_DEFER_OUTPUT (current_function_decl) = 0;
1718 /* Register rtl specific functions for cfg. */
1719 rtl_register_cfg_hooks ();
1721 /* Now that we're out of the frontend, we shouldn't have any more
1722 CONCATs anywhere. */
1723 generating_concat_p = 0;
1725 /* When processing delayed functions, prepare_function_start () won't
1726 have been run to re-initialize it. */
1727 cse_not_expected = ! optimize;
1729 finalize_block_changes ();
1731 /* Dump the rtl code if we are dumping rtl. */
1732 if (open_dump_file (DFI_rtl, current_function_decl))
1733 close_dump_file (DFI_rtl, print_rtl, get_insns ());
1735 /* Convert from NOTE_INSN_EH_REGION style notes, and do other
1736 sorts of eh initialization. Delay this until after the
1737 initial rtl dump so that we can see the original nesting. */
1738 convert_from_eh_region_ranges ();
1740 /* If we're emitting a nested function, make sure its parent gets
1741 emitted as well. Doing otherwise confuses debug info. */
1744 for (parent = DECL_CONTEXT (current_function_decl);
1745 parent != NULL_TREE;
1746 parent = get_containing_scope (parent))
1747 if (TREE_CODE (parent) == FUNCTION_DECL)
1748 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (parent)) = 1;
1751 /* We are now committed to emitting code for this function. Do any
1752 preparation, such as emitting abstract debug info for the inline
1753 before it gets mangled by optimization. */
1754 if (cgraph_function_possibly_inlined_p (current_function_decl))
1755 (*debug_hooks->outlining_inline_function) (current_function_decl);
1757 /* Remove any notes we don't need. That will make iterating
1758 over the instruction sequence faster, and allow the garbage
1759 collector to reclaim the memory used by the notes. */
1760 remove_unnecessary_notes ();
1762 /* Initialize some variables used by the optimizers. */
1763 init_function_for_compilation ();
1765 TREE_ASM_WRITTEN (current_function_decl) = 1;
1767 /* Now that integrate will no longer see our rtl, we need not
1768 distinguish between the return value of this function and the
1769 return value of called functions. Also, we can remove all SETs
1770 of subregs of hard registers; they are only here because of
1771 integrate. Also, we can now initialize pseudos intended to
1772 carry magic hard reg data throughout the function.
1774 FIXME: All this looks thoroughly obsolete... maybe we can
1775 get rid of both these lines unconditionally? */
1776 rtx_equal_function_value_matters = 0;
1777 purge_hard_subreg_sets (get_insns ());
1779 /* Early return if there were errors. We can run afoul of our
1780 consistency checks, and there's not really much point in fixing them. */
1781 if (rtl_dump_and_exit || flag_syntax_only || errorcount || sorrycount)
1782 goto exit_rest_of_compilation;
1784 rest_of_handle_jump ();
1785 rest_of_handle_guess_branch_prob ();
1787 if (cfun->tail_call_emit)
1788 fixup_tail_calls ();
1790 rest_of_handle_eh ();
1792 /* Delay emitting hard_reg_initial_value sets until after EH landing pad
1793 generation, which might create new sets. */
1794 emit_initial_value_sets ();
1797 /* If we are doing position-independent code generation, now
1798 is the time to output special prologues and epilogues.
1799 We do not want to do this earlier, because it just clutters
1800 up inline functions with meaningless insns. */
1805 /* Copy any shared structure that should not be shared. */
1808 #ifdef SETJMP_VIA_SAVE_AREA
1809 /* This must be performed before virtual register instantiation.
1810 Please be aware that everything in the compiler that can look
1811 at the RTL up to this point must understand that REG_SAVE_AREA
1812 is just like a use of the REG contained inside. */
1813 if (current_function_calls_alloca)
1814 optimize_save_area_alloca ();
1817 /* Instantiate all virtual registers. */
1818 instantiate_virtual_regs ();
1820 rest_of_handle_jump2 ();
1823 rest_of_handle_cse ();
1828 rest_of_handle_gcse ();
1830 if (flag_loop_optimize)
1831 rest_of_handle_loop_optimize ();
1834 rest_of_handle_jump_bypass ();
1837 timevar_push (TV_FLOW);
1838 rest_of_handle_cfg ();
1840 if (!flag_tree_based_profiling
1841 && (optimize > 0 || profile_arc_flag
1842 || flag_test_coverage || flag_branch_probabilities))
1844 rtl_register_profile_hooks ();
1845 rtl_register_value_prof_hooks ();
1846 rest_of_handle_branch_prob ();
1848 if (flag_branch_probabilities
1849 && flag_profile_values
1850 && flag_value_profile_transformations)
1851 rest_of_handle_value_profile_transformations ();
1853 /* Remove the death notes created for vpt. */
1854 if (flag_profile_values)
1855 count_or_remove_death_notes (NULL, 1);
1859 rest_of_handle_if_conversion ();
1861 if (optimize > 0 && flag_tracer)
1862 rest_of_handle_tracer ();
1865 && flag_loop_optimize2)
1866 rest_of_handle_loop2 ();
1868 if (optimize > 0 && flag_web)
1869 rest_of_handle_web ();
1871 if (optimize > 0 && flag_rerun_cse_after_loop)
1872 rest_of_handle_cse2 ();
1874 cse_not_expected = 1;
1876 rest_of_handle_life ();
1877 timevar_pop (TV_FLOW);
1880 rest_of_handle_combine ();
1882 if (optimize > 0 && flag_if_conversion)
1883 rest_of_handle_if_after_combine ();
1885 /* The optimization to partition hot/cold basic blocks into separate
1886 sections of the .o file does not work well with exception handling.
1887 Don't call it if there are exceptions. */
1889 if (optimize > 0 && flag_reorder_blocks_and_partition && !flag_exceptions)
1890 rest_of_handle_partition_blocks ();
1892 if (optimize > 0 && (flag_regmove || flag_expensive_optimizations))
1893 rest_of_handle_regmove ();
1895 /* Do unconditional splitting before register allocation to allow machine
1896 description to add extra information not needed previously. */
1897 split_all_insns (1);
1899 #ifdef OPTIMIZE_MODE_SWITCHING
1900 rest_of_handle_mode_switching ();
1903 /* Any of the several passes since flow1 will have munged register
1904 lifetime data a bit. We need it to be up to date for scheduling
1905 (see handling of reg_known_equiv in init_alias_analysis). */
1906 recompute_reg_usage (get_insns (), !optimize_size);
1908 #ifdef INSN_SCHEDULING
1909 if (optimize > 0 && flag_modulo_sched)
1910 rest_of_handle_sms ();
1912 if (flag_schedule_insns)
1913 rest_of_handle_sched ();
1916 /* Determine if the current function is a leaf before running reload
1917 since this can impact optimizations done by the prologue and
1918 epilogue thus changing register elimination offsets. */
1919 current_function_is_leaf = leaf_function_p ();
1921 if (flag_new_regalloc)
1923 if (rest_of_handle_new_regalloc ())
1924 goto exit_rest_of_compilation;
1928 if (rest_of_handle_old_regalloc ())
1929 goto exit_rest_of_compilation;
1933 rest_of_handle_postreload ();
1935 if (optimize > 0 && flag_gcse_after_reload)
1936 rest_of_handle_gcse2 ();
1938 rest_of_handle_flow2 ();
1940 #ifdef HAVE_peephole2
1941 if (optimize > 0 && flag_peephole2)
1942 rest_of_handle_peephole2 ();
1946 rest_of_handle_if_after_reload ();
1950 if (flag_rename_registers || flag_cprop_registers)
1951 rest_of_handle_regrename ();
1953 rest_of_handle_reorder_blocks ();
1956 if (flag_branch_target_load_optimize2)
1957 rest_of_handle_branch_target_load_optimize ();
1959 #ifdef LEAF_REGISTERS
1960 current_function_uses_only_leaf_regs
1961 = optimize > 0 && only_leaf_regs_used () && leaf_function_p ();
1964 if (targetm.late_rtl_prologue_epilogue)
1965 rest_of_handle_prologue_epilogue ();
1967 #ifdef INSN_SCHEDULING
1968 if (optimize > 0 && flag_schedule_insns_after_reload)
1969 rest_of_handle_sched2 ();
1973 rest_of_handle_stack_regs ();
1976 compute_alignments ();
1978 if (flag_var_tracking)
1979 rest_of_handle_variable_tracking ();
1981 /* CFG is no longer maintained up-to-date. */
1982 free_bb_for_insn ();
1984 if (targetm.machine_dependent_reorg != 0)
1985 rest_of_handle_machine_reorg ();
1987 purge_line_number_notes (get_insns ());
1988 cleanup_barriers ();
1991 if (flag_delayed_branch)
1992 rest_of_handle_delay_slots ();
1995 #if defined (HAVE_ATTR_length) && !defined (STACK_REGS)
1996 timevar_push (TV_SHORTEN_BRANCH);
1997 split_all_insns_noflow ();
1998 timevar_pop (TV_SHORTEN_BRANCH);
2001 convert_to_eh_region_ranges ();
2003 rest_of_handle_shorten_branches ();
2005 set_nothrow_function_flags ();
2007 rest_of_handle_final ();
2009 exit_rest_of_compilation:
2011 rest_of_clean_state ();
2015 init_optimization_passes (void)
2017 open_dump_file (DFI_cgraph, NULL);
2018 cgraph_dump_file = dump_file;
2023 finish_optimization_passes (void)
2025 timevar_push (TV_DUMP);
2026 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
2028 open_dump_file (DFI_bp, NULL);
2030 close_dump_file (DFI_bp, NULL, NULL_RTX);
2033 if (optimize > 0 && open_dump_file (DFI_combine, NULL))
2035 dump_combine_total_stats (dump_file);
2036 close_dump_file (DFI_combine, NULL, NULL_RTX);
2039 dump_file = cgraph_dump_file;
2040 cgraph_dump_file = NULL;
2041 close_dump_file (DFI_cgraph, NULL, NULL_RTX);
2043 /* Do whatever is necessary to finish printing the graphs. */
2044 if (graph_dump_format != no_graph)
2048 for (i = 0; i < (int) DFI_MAX; ++i)
2049 if (dump_file_tbl[i].initialized && dump_file_tbl[i].graph_dump_p)
2054 sprintf (seq, DUMPFILE_FORMAT, i);
2055 suffix = concat (seq, dump_file_tbl[i].extension, NULL);
2056 finish_graph_dump_file (dump_base_name, suffix);
2061 timevar_pop (TV_DUMP);
2065 enable_rtl_dump_file (int letter)
2067 bool matched = false;
2072 for (i = 0; i < (int) DFI_MAX; ++i)
2073 dump_file_tbl[i].enabled = 1;
2078 for (i = 0; i < (int) DFI_MAX; ++i)
2079 if (letter == dump_file_tbl[i].debug_switch)
2081 dump_file_tbl[i].enabled = 1;
2089 struct tree_opt_pass pass_rest_of_compilation =
2091 "rest of compilation", /* name */
2093 rest_of_compilation, /* execute */
2096 0, /* static_pass_number */
2097 TV_REST_OF_COMPILATION, /* tv_id */
2098 PROP_rtl, /* properties_required */
2099 0, /* properties_provided */
2100 PROP_rtl, /* properties_destroyed */
2101 0, /* todo_flags_start */
2102 TODO_ggc_collect /* todo_flags_finish */