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 DECL_ASSEMBLER_NAME set. In
324 that case, or if the variable is not an automatic, it sets up the
325 RTL and outputs any assembler code (label definition, storage
326 allocation and initialization).
328 DECL is the declaration. TOP_LEVEL is nonzero
329 if this declaration is not within a function. */
332 rest_of_decl_compilation (tree decl
,
336 /* We deferred calling assemble_alias so that we could collect
337 other attributes such as visibility. Emit the alias now. */
340 alias
= lookup_attribute ("alias", DECL_ATTRIBUTES (decl
));
343 alias
= TREE_VALUE (TREE_VALUE (alias
));
344 alias
= get_identifier (TREE_STRING_POINTER (alias
));
345 assemble_alias (decl
, alias
);
349 /* Can't defer this, because it needs to happen before any
350 later function definitions are processed. */
351 if (DECL_REGISTER (decl
) && DECL_ASSEMBLER_NAME_SET_P (decl
))
352 make_decl_rtl (decl
);
354 /* Forward declarations for nested functions are not "external",
355 but we need to treat them as if they were. */
356 if (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)
357 || TREE_CODE (decl
) == FUNCTION_DECL
)
359 timevar_push (TV_VARCONST
);
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 /* If we defer processing of decls that have had their
375 DECL_RTL set above (say, in make_decl_rtl),
376 check_global_declarations() will clear it before
377 assemble_variable has a chance to act on it. This
378 would remove all traces of the register name in a
379 global register variable, for example. */
380 && !DECL_RTL_SET_P (decl
))
381 cgraph_varpool_finalize_decl (decl
);
383 assemble_variable (decl
, top_level
, at_end
, 0);
386 #ifdef ASM_FINISH_DECLARE_OBJECT
387 if (decl
== last_assemble_variable_decl
)
389 ASM_FINISH_DECLARE_OBJECT (asm_out_file
, decl
,
394 timevar_pop (TV_VARCONST
);
396 else if (TREE_CODE (decl
) == TYPE_DECL
)
398 timevar_push (TV_SYMOUT
);
399 debug_hooks
->type_decl (decl
, !top_level
);
400 timevar_pop (TV_SYMOUT
);
404 /* Called after finishing a record, union or enumeral type. */
407 rest_of_type_compilation (tree type
, int toplev
)
409 /* Avoid confusing the debug information machinery when there are
411 if (errorcount
!= 0 || sorrycount
!= 0)
414 timevar_push (TV_SYMOUT
);
415 debug_hooks
->type_decl (TYPE_STUB_DECL (type
), !toplev
);
416 timevar_pop (TV_SYMOUT
);
419 /* Turn the RTL into assembly. */
421 rest_of_handle_final (void)
423 timevar_push (TV_FINAL
);
428 /* Get the function's name, as described by its RTL. This may be
429 different from the DECL_NAME name used in the source file. */
431 x
= DECL_RTL (current_function_decl
);
435 if (GET_CODE (x
) != SYMBOL_REF
)
437 fnname
= XSTR (x
, 0);
439 assemble_start_function (current_function_decl
, fnname
);
440 final_start_function (get_insns (), asm_out_file
, optimize
);
441 final (get_insns (), asm_out_file
, optimize
, 0);
442 final_end_function ();
444 #ifdef TARGET_UNWIND_INFO
445 /* ??? The IA-64 ".handlerdata" directive must be issued before
446 the ".endp" directive that closes the procedure descriptor. */
447 output_function_exception_table ();
450 assemble_end_function (current_function_decl
, fnname
);
452 #ifndef TARGET_UNWIND_INFO
453 /* Otherwise, it feels unclean to switch sections in the middle. */
454 output_function_exception_table ();
457 user_defined_section_attribute
= false;
460 fflush (asm_out_file
);
462 /* Release all memory allocated by flow. */
463 free_basic_block_vars ();
465 /* Release all memory held by regsets now. */
466 regset_release_memory ();
469 /* Write DBX symbols if requested. */
471 /* Note that for those inline functions where we don't initially
472 know for certain that we will be generating an out-of-line copy,
473 the first invocation of this routine (rest_of_compilation) will
474 skip over this code by doing a `goto exit_rest_of_compilation;'.
475 Later on, wrapup_global_declarations will (indirectly) call
476 rest_of_compilation again for those inline functions that need
477 to have out-of-line copies generated. During that call, we
478 *will* be routed past here. */
480 timevar_push (TV_SYMOUT
);
481 (*debug_hooks
->function_decl
) (current_function_decl
);
482 timevar_pop (TV_SYMOUT
);
485 timevar_pop (TV_FINAL
);
489 /* Run delay slot optimization. */
491 rest_of_handle_delay_slots (void)
493 timevar_push (TV_DBR_SCHED
);
494 open_dump_file (DFI_dbr
, current_function_decl
);
496 dbr_schedule (get_insns (), dump_file
);
498 close_dump_file (DFI_dbr
, print_rtl
, get_insns ());
502 timevar_pop (TV_DBR_SCHED
);
507 /* Convert register usage from flat register file usage to a stack
510 rest_of_handle_stack_regs (void)
512 #if defined (HAVE_ATTR_length)
513 /* If flow2 creates new instructions which need splitting
514 and scheduling after reload is not done, they might not be
515 split until final which doesn't allow splitting
516 if HAVE_ATTR_length. */
517 #ifdef INSN_SCHEDULING
518 if (optimize
&& !flag_schedule_insns_after_reload
)
523 timevar_push (TV_SHORTEN_BRANCH
);
525 timevar_pop (TV_SHORTEN_BRANCH
);
529 timevar_push (TV_REG_STACK
);
530 open_dump_file (DFI_stack
, current_function_decl
);
532 if (reg_to_stack (dump_file
) && optimize
)
534 if (cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_POST_REGSTACK
535 | (flag_crossjumping
? CLEANUP_CROSSJUMP
: 0))
536 && (flag_reorder_blocks
|| flag_reorder_blocks_and_partition
))
538 reorder_basic_blocks (0);
539 cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_POST_REGSTACK
);
543 close_dump_file (DFI_stack
, print_rtl_with_bb
, get_insns ());
546 timevar_pop (TV_REG_STACK
);
550 /* Track the variables, ie. compute where the variable is stored at each position in function. */
552 rest_of_handle_variable_tracking (void)
554 timevar_push (TV_VAR_TRACKING
);
555 open_dump_file (DFI_vartrack
, current_function_decl
);
557 variable_tracking_main ();
559 close_dump_file (DFI_vartrack
, print_rtl_with_bb
, get_insns ());
560 timevar_pop (TV_VAR_TRACKING
);
563 /* Machine dependent reorg pass. */
565 rest_of_handle_machine_reorg (void)
567 timevar_push (TV_MACH_DEP
);
568 open_dump_file (DFI_mach
, current_function_decl
);
570 targetm
.machine_dependent_reorg ();
572 close_dump_file (DFI_mach
, print_rtl
, get_insns ());
575 timevar_pop (TV_MACH_DEP
);
579 /* Run new register allocator. Return TRUE if we must exit
580 rest_of_compilation upon return. */
582 rest_of_handle_new_regalloc (void)
586 timevar_push (TV_LOCAL_ALLOC
);
587 open_dump_file (DFI_lreg
, current_function_decl
);
589 delete_trivially_dead_insns (get_insns (), max_reg_num ());
592 timevar_pop (TV_LOCAL_ALLOC
);
593 close_dump_file (DFI_lreg
, NULL
, NULL
);
595 /* XXX clean up the whole mess to bring live info in shape again. */
596 timevar_push (TV_GLOBAL_ALLOC
);
597 open_dump_file (DFI_greg
, current_function_decl
);
599 build_insn_chain (get_insns ());
600 failure
= reload (get_insns (), 0);
602 timevar_pop (TV_GLOBAL_ALLOC
);
606 if (dump_file_tbl
[DFI_greg
].enabled
)
608 timevar_push (TV_DUMP
);
609 dump_global_regs (dump_file
);
610 timevar_pop (TV_DUMP
);
611 close_dump_file (DFI_greg
, print_rtl_with_bb
, get_insns ());
617 reload_completed
= 1;
622 /* Run old register allocator. Return TRUE if we must exit
623 rest_of_compilation upon return. */
625 rest_of_handle_old_regalloc (void)
630 timevar_push (TV_LOCAL_ALLOC
);
631 open_dump_file (DFI_lreg
, current_function_decl
);
633 /* Allocate the reg_renumber array. */
634 allocate_reg_info (max_regno
, FALSE
, TRUE
);
636 /* And the reg_equiv_memory_loc array. */
637 VARRAY_GROW (reg_equiv_memory_loc_varray
, max_regno
);
638 reg_equiv_memory_loc
= &VARRAY_RTX (reg_equiv_memory_loc_varray
, 0);
640 allocate_initial_values (reg_equiv_memory_loc
);
642 regclass (get_insns (), max_reg_num (), dump_file
);
643 rebuild_notes
= local_alloc ();
645 timevar_pop (TV_LOCAL_ALLOC
);
647 /* Local allocation may have turned an indirect jump into a direct
648 jump. If so, we must rebuild the JUMP_LABEL fields of jumping
652 timevar_push (TV_JUMP
);
654 rebuild_jump_labels (get_insns ());
655 purge_all_dead_edges (0);
657 timevar_pop (TV_JUMP
);
660 if (dump_file_tbl
[DFI_lreg
].enabled
)
662 timevar_push (TV_DUMP
);
663 dump_flow_info (dump_file
);
664 dump_local_alloc (dump_file
);
665 timevar_pop (TV_DUMP
);
668 close_dump_file (DFI_lreg
, print_rtl_with_bb
, get_insns ());
672 timevar_push (TV_GLOBAL_ALLOC
);
673 open_dump_file (DFI_greg
, current_function_decl
);
675 /* If optimizing, allocate remaining pseudo-regs. Do the reload
676 pass fixing up any insns that are invalid. */
679 failure
= global_alloc (dump_file
);
682 build_insn_chain (get_insns ());
683 failure
= reload (get_insns (), 0);
686 if (dump_file_tbl
[DFI_greg
].enabled
)
688 timevar_push (TV_DUMP
);
689 dump_global_regs (dump_file
);
690 timevar_pop (TV_DUMP
);
692 close_dump_file (DFI_greg
, print_rtl_with_bb
, get_insns ());
697 timevar_pop (TV_GLOBAL_ALLOC
);
702 /* Run the regrename and cprop passes. */
704 rest_of_handle_regrename (void)
706 timevar_push (TV_RENAME_REGISTERS
);
707 open_dump_file (DFI_rnreg
, current_function_decl
);
709 if (flag_rename_registers
)
710 regrename_optimize ();
711 if (flag_cprop_registers
)
712 copyprop_hardreg_forward ();
714 close_dump_file (DFI_rnreg
, print_rtl_with_bb
, get_insns ());
715 timevar_pop (TV_RENAME_REGISTERS
);
718 /* Reorder basic blocks. */
720 rest_of_handle_reorder_blocks (void)
723 unsigned int liveness_flags
;
725 open_dump_file (DFI_bbro
, current_function_decl
);
727 /* Last attempt to optimize CFG, as scheduling, peepholing and insn
728 splitting possibly introduced more crossjumping opportunities. */
729 liveness_flags
= (!HAVE_conditional_execution
? CLEANUP_UPDATE_LIFE
: 0);
730 changed
= cleanup_cfg (CLEANUP_EXPENSIVE
| liveness_flags
);
732 if (flag_sched2_use_traces
&& flag_schedule_insns_after_reload
)
733 tracer (liveness_flags
);
734 if (flag_reorder_blocks
|| flag_reorder_blocks_and_partition
)
735 reorder_basic_blocks (liveness_flags
);
736 if (flag_reorder_blocks
|| flag_reorder_blocks_and_partition
737 || (flag_sched2_use_traces
&& flag_schedule_insns_after_reload
))
738 changed
|= cleanup_cfg (CLEANUP_EXPENSIVE
| liveness_flags
);
740 /* On conditional execution targets we can not update the life cheaply, so
741 we deffer the updating to after both cleanups. This may lose some cases
742 but should not be terribly bad. */
743 if (changed
&& HAVE_conditional_execution
)
744 update_life_info (NULL
, UPDATE_LIFE_GLOBAL_RM_NOTES
,
746 close_dump_file (DFI_bbro
, print_rtl_with_bb
, get_insns ());
749 /* Partition hot and cold basic blocks. */
751 rest_of_handle_partition_blocks (void)
754 partition_hot_cold_basic_blocks ();
755 allocate_reg_life_data ();
756 update_life_info (NULL
, UPDATE_LIFE_GLOBAL_RM_NOTES
,
757 PROP_LOG_LINKS
| PROP_REG_INFO
| PROP_DEATH_NOTES
);
761 #ifdef INSN_SCHEDULING
762 /* Run instruction scheduler. */
763 /* Perform SMS module scheduling. */
765 rest_of_handle_sms (void)
767 timevar_push (TV_SMS
);
768 open_dump_file (DFI_sms
, current_function_decl
);
770 /* We want to be able to create new pseudos. */
772 sms_schedule (dump_file
);
773 close_dump_file (DFI_sms
, print_rtl
, get_insns ());
776 /* Update the life information, because we add pseudos. */
777 max_regno
= max_reg_num ();
778 allocate_reg_info (max_regno
, FALSE
, FALSE
);
779 update_life_info_in_dirty_blocks (UPDATE_LIFE_GLOBAL_RM_NOTES
,
781 | PROP_KILL_DEAD_CODE
782 | PROP_SCAN_DEAD_CODE
));
786 timevar_pop (TV_SMS
);
789 /* Run instruction scheduler. */
791 rest_of_handle_sched (void)
793 timevar_push (TV_SCHED
);
795 /* Print function header into sched dump now
796 because doing the sched analysis makes some of the dump. */
797 open_dump_file (DFI_sched
, current_function_decl
);
799 /* Do control and data sched analysis,
800 and write some of the results to dump file. */
802 schedule_insns (dump_file
);
804 close_dump_file (DFI_sched
, print_rtl_with_bb
, get_insns ());
807 timevar_pop (TV_SCHED
);
810 /* Run second scheduling pass after reload. */
812 rest_of_handle_sched2 (void)
814 timevar_push (TV_SCHED2
);
815 open_dump_file (DFI_sched2
, current_function_decl
);
817 /* Do control and data sched analysis again,
818 and write some more of the results to dump file. */
822 if (flag_sched2_use_superblocks
|| flag_sched2_use_traces
)
824 schedule_ebbs (dump_file
);
825 /* No liveness updating code yet, but it should be easy to do.
826 reg-stack recomputes the liveness when needed for now. */
827 count_or_remove_death_notes (NULL
, 1);
828 cleanup_cfg (CLEANUP_EXPENSIVE
);
831 schedule_insns (dump_file
);
833 close_dump_file (DFI_sched2
, print_rtl_with_bb
, get_insns ());
837 timevar_pop (TV_SCHED2
);
842 rest_of_handle_gcse2 (void)
844 timevar_push (TV_GCSE_AFTER_RELOAD
);
845 open_dump_file (DFI_gcse2
, current_function_decl
);
847 gcse_after_reload_main (get_insns ());
848 rebuild_jump_labels (get_insns ());
849 delete_trivially_dead_insns (get_insns (), max_reg_num ());
850 close_dump_file (DFI_gcse2
, print_rtl_with_bb
, get_insns ());
854 #ifdef ENABLE_CHECKING
858 timevar_pop (TV_GCSE_AFTER_RELOAD
);
861 /* Register allocation pre-pass, to reduce number of moves necessary
862 for two-address machines. */
864 rest_of_handle_regmove (void)
866 timevar_push (TV_REGMOVE
);
867 open_dump_file (DFI_regmove
, current_function_decl
);
869 regmove_optimize (get_insns (), max_reg_num (), dump_file
);
871 cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_UPDATE_LIFE
);
872 close_dump_file (DFI_regmove
, print_rtl_with_bb
, get_insns ());
875 timevar_pop (TV_REGMOVE
);
880 rest_of_handle_tracer (void)
882 open_dump_file (DFI_tracer
, current_function_decl
);
884 dump_flow_info (dump_file
);
886 cleanup_cfg (CLEANUP_EXPENSIVE
);
887 reg_scan (get_insns (), max_reg_num (), 0);
888 close_dump_file (DFI_tracer
, print_rtl_with_bb
, get_insns ());
891 /* If-conversion and CFG cleanup. */
893 rest_of_handle_if_conversion (void)
895 timevar_push (TV_IFCVT
);
896 open_dump_file (DFI_ce1
, current_function_decl
);
898 if (flag_if_conversion
)
901 dump_flow_info (dump_file
);
902 cleanup_cfg (CLEANUP_EXPENSIVE
);
903 reg_scan (get_insns (), max_reg_num (), 0);
907 timevar_push (TV_JUMP
);
908 cleanup_cfg (CLEANUP_EXPENSIVE
);
909 reg_scan (get_insns (), max_reg_num (), 0);
910 timevar_pop (TV_JUMP
);
912 close_dump_file (DFI_ce1
, print_rtl_with_bb
, get_insns ());
913 timevar_pop (TV_IFCVT
);
916 /* Rerun if-conversion, as combine may have simplified things enough
917 to now meet sequence length restrictions. */
919 rest_of_handle_if_after_combine (void)
921 timevar_push (TV_IFCVT
);
922 open_dump_file (DFI_ce2
, current_function_decl
);
928 close_dump_file (DFI_ce2
, print_rtl_with_bb
, get_insns ());
929 timevar_pop (TV_IFCVT
);
933 rest_of_handle_if_after_reload (void)
935 timevar_push (TV_IFCVT2
);
936 open_dump_file (DFI_ce3
, current_function_decl
);
938 /* Last attempt to optimize CFG, as scheduling, peepholing and insn
939 splitting possibly introduced more crossjumping opportunities. */
940 cleanup_cfg (CLEANUP_EXPENSIVE
941 | CLEANUP_UPDATE_LIFE
942 | (flag_crossjumping
? CLEANUP_CROSSJUMP
: 0));
943 if (flag_if_conversion2
)
945 close_dump_file (DFI_ce3
, print_rtl_with_bb
, get_insns ());
946 timevar_pop (TV_IFCVT2
);
950 rest_of_handle_web (void)
952 open_dump_file (DFI_web
, current_function_decl
);
953 timevar_push (TV_WEB
);
955 delete_trivially_dead_insns (get_insns (), max_reg_num ());
956 cleanup_cfg (CLEANUP_EXPENSIVE
);
958 timevar_pop (TV_WEB
);
959 close_dump_file (DFI_web
, print_rtl_with_bb
, get_insns ());
960 reg_scan (get_insns (), max_reg_num (), 0);
963 /* Do branch profiling and static profile estimation passes. */
965 rest_of_handle_branch_prob (void)
969 timevar_push (TV_BRANCH_PROB
);
970 open_dump_file (DFI_bp
, current_function_decl
);
972 if (profile_arc_flag
|| flag_test_coverage
|| flag_branch_probabilities
)
975 /* Discover and record the loop depth at the head of each basic
976 block. The loop infrastructure does the real job for us. */
977 flow_loops_find (&loops
, LOOP_TREE
);
980 flow_loops_dump (&loops
, dump_file
, NULL
, 0);
982 /* Estimate using heuristics if no profiling info is available. */
983 if (flag_guess_branch_prob
)
984 estimate_probability (&loops
);
986 flow_loops_free (&loops
);
987 free_dominance_info (CDI_DOMINATORS
);
988 close_dump_file (DFI_bp
, print_rtl_with_bb
, get_insns ());
989 timevar_pop (TV_BRANCH_PROB
);
992 /* Do optimizations based on expression value profiles. */
994 rest_of_handle_value_profile_transformations (void)
996 open_dump_file (DFI_vpt
, current_function_decl
);
997 timevar_push (TV_VPT
);
999 if (value_profile_transformations ())
1000 cleanup_cfg (CLEANUP_EXPENSIVE
);
1002 timevar_pop (TV_VPT
);
1003 close_dump_file (DFI_vpt
, print_rtl_with_bb
, get_insns ());
1006 /* Do control and data flow analysis; write some of the results to the
1009 rest_of_handle_cfg (void)
1011 open_dump_file (DFI_cfg
, current_function_decl
);
1013 dump_flow_info (dump_file
);
1015 cleanup_cfg (CLEANUP_EXPENSIVE
1016 | (flag_thread_jumps
? CLEANUP_THREADING
: 0));
1018 /* It may make more sense to mark constant functions after dead code is
1019 eliminated by life_analysis, but we need to do it early, as -fprofile-arcs
1020 may insert code making function non-constant, but we still must consider
1021 it as constant, otherwise -fbranch-probabilities will not read data back.
1023 life_analysis rarely eliminates modification of external memory.
1027 /* Alias analysis depends on this information and mark_constant_function
1028 depends on alias analysis. */
1029 reg_scan (get_insns (), max_reg_num (), 1);
1030 mark_constant_function ();
1033 close_dump_file (DFI_cfg
, print_rtl_with_bb
, get_insns ());
1036 /* Perform jump bypassing and control flow optimizations. */
1038 rest_of_handle_jump_bypass (void)
1040 timevar_push (TV_BYPASS
);
1041 open_dump_file (DFI_bypass
, current_function_decl
);
1043 cleanup_cfg (CLEANUP_EXPENSIVE
);
1044 reg_scan (get_insns (), max_reg_num (), 1);
1046 if (bypass_jumps (dump_file
))
1048 rebuild_jump_labels (get_insns ());
1049 cleanup_cfg (CLEANUP_EXPENSIVE
);
1050 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1053 close_dump_file (DFI_bypass
, print_rtl_with_bb
, get_insns ());
1054 timevar_pop (TV_BYPASS
);
1058 #ifdef ENABLE_CHECKING
1059 verify_flow_info ();
1063 /* Try combining insns through substitution. */
1065 rest_of_handle_combine (void)
1067 int rebuild_jump_labels_after_combine
= 0;
1069 timevar_push (TV_COMBINE
);
1070 open_dump_file (DFI_combine
, current_function_decl
);
1072 rebuild_jump_labels_after_combine
1073 = combine_instructions (get_insns (), max_reg_num ());
1075 /* Combining insns may have turned an indirect jump into a
1076 direct jump. Rebuild the JUMP_LABEL fields of jumping
1078 if (rebuild_jump_labels_after_combine
)
1080 timevar_push (TV_JUMP
);
1081 rebuild_jump_labels (get_insns ());
1082 timevar_pop (TV_JUMP
);
1084 cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_UPDATE_LIFE
);
1087 close_dump_file (DFI_combine
, print_rtl_with_bb
, get_insns ());
1088 timevar_pop (TV_COMBINE
);
1093 /* Perform life analysis. */
1095 rest_of_handle_life (void)
1097 open_dump_file (DFI_life
, current_function_decl
);
1100 #ifdef ENABLE_CHECKING
1101 verify_flow_info ();
1103 life_analysis (dump_file
, PROP_FINAL
);
1105 cleanup_cfg ((optimize
? CLEANUP_EXPENSIVE
: 0) | CLEANUP_UPDATE_LIFE
1107 | (flag_thread_jumps
? CLEANUP_THREADING
: 0));
1111 setjmp_vars_warning (DECL_INITIAL (current_function_decl
));
1112 setjmp_args_warning ();
1117 if (!flag_new_regalloc
&& initialize_uninitialized_subregs ())
1119 /* Insns were inserted, and possibly pseudos created, so
1120 things might look a bit different. */
1121 allocate_reg_life_data ();
1122 update_life_info (NULL
, UPDATE_LIFE_GLOBAL_RM_NOTES
,
1123 PROP_LOG_LINKS
| PROP_REG_INFO
| PROP_DEATH_NOTES
);
1129 close_dump_file (DFI_life
, print_rtl_with_bb
, get_insns ());
1134 /* Perform common subexpression elimination. Nonzero value from
1135 `cse_main' means that jumps were simplified and some code may now
1136 be unreachable, so do jump optimization again. */
1138 rest_of_handle_cse (void)
1142 open_dump_file (DFI_cse
, current_function_decl
);
1144 dump_flow_info (dump_file
);
1145 timevar_push (TV_CSE
);
1147 reg_scan (get_insns (), max_reg_num (), 1);
1149 tem
= cse_main (get_insns (), max_reg_num (), dump_file
);
1151 rebuild_jump_labels (get_insns ());
1152 if (purge_all_dead_edges (0))
1153 delete_unreachable_blocks ();
1155 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1157 /* If we are not running more CSE passes, then we are no longer
1158 expecting CSE to be run. But always rerun it in a cheap mode. */
1159 cse_not_expected
= !flag_rerun_cse_after_loop
&& !flag_gcse
;
1161 if (tem
|| optimize
> 1)
1162 cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_PRE_LOOP
);
1164 timevar_pop (TV_CSE
);
1165 close_dump_file (DFI_cse
, print_rtl_with_bb
, get_insns ());
1170 /* Run second CSE pass after loop optimizations. */
1172 rest_of_handle_cse2 (void)
1176 timevar_push (TV_CSE2
);
1177 open_dump_file (DFI_cse2
, current_function_decl
);
1179 dump_flow_info (dump_file
);
1180 /* CFG is no longer maintained up-to-date. */
1181 tem
= cse_main (get_insns (), max_reg_num (), dump_file
);
1183 /* Run a pass to eliminate duplicated assignments to condition code
1184 registers. We have to run this after bypass_jumps, because it
1185 makes it harder for that pass to determine whether a jump can be
1187 cse_condition_code_reg ();
1189 purge_all_dead_edges (0);
1190 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1194 timevar_push (TV_JUMP
);
1195 rebuild_jump_labels (get_insns ());
1196 cleanup_cfg (CLEANUP_EXPENSIVE
);
1197 timevar_pop (TV_JUMP
);
1199 reg_scan (get_insns (), max_reg_num (), 0);
1200 close_dump_file (DFI_cse2
, print_rtl_with_bb
, get_insns ());
1201 timevar_pop (TV_CSE2
);
1206 /* Perform global cse. */
1208 rest_of_handle_gcse (void)
1210 int save_csb
, save_cfj
;
1213 timevar_push (TV_GCSE
);
1214 open_dump_file (DFI_gcse
, current_function_decl
);
1216 tem
= gcse_main (get_insns (), dump_file
);
1217 rebuild_jump_labels (get_insns ());
1218 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1220 save_csb
= flag_cse_skip_blocks
;
1221 save_cfj
= flag_cse_follow_jumps
;
1222 flag_cse_skip_blocks
= flag_cse_follow_jumps
= 0;
1224 /* If -fexpensive-optimizations, re-run CSE to clean up things done
1226 if (flag_expensive_optimizations
)
1228 timevar_push (TV_CSE
);
1229 reg_scan (get_insns (), max_reg_num (), 1);
1230 tem2
= cse_main (get_insns (), max_reg_num (), dump_file
);
1231 purge_all_dead_edges (0);
1232 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1233 timevar_pop (TV_CSE
);
1234 cse_not_expected
= !flag_rerun_cse_after_loop
;
1237 /* If gcse or cse altered any jumps, rerun jump optimizations to clean
1238 things up. Then possibly re-run CSE again. */
1242 timevar_push (TV_JUMP
);
1243 rebuild_jump_labels (get_insns ());
1244 cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_PRE_LOOP
);
1245 timevar_pop (TV_JUMP
);
1247 if (flag_expensive_optimizations
)
1249 timevar_push (TV_CSE
);
1250 reg_scan (get_insns (), max_reg_num (), 1);
1251 tem2
= cse_main (get_insns (), max_reg_num (), dump_file
);
1252 purge_all_dead_edges (0);
1253 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1254 timevar_pop (TV_CSE
);
1258 close_dump_file (DFI_gcse
, print_rtl_with_bb
, get_insns ());
1259 timevar_pop (TV_GCSE
);
1262 flag_cse_skip_blocks
= save_csb
;
1263 flag_cse_follow_jumps
= save_cfj
;
1264 #ifdef ENABLE_CHECKING
1265 verify_flow_info ();
1269 /* Move constant computations out of loops. */
1271 rest_of_handle_loop_optimize (void)
1273 int do_unroll
, do_prefetch
;
1275 timevar_push (TV_LOOP
);
1276 delete_dead_jumptables ();
1277 cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_PRE_LOOP
);
1278 open_dump_file (DFI_loop
, current_function_decl
);
1280 /* CFG is no longer maintained up-to-date. */
1281 free_bb_for_insn ();
1283 if (flag_unroll_loops
)
1284 do_unroll
= LOOP_AUTO_UNROLL
; /* Having two unrollers is useless. */
1286 do_unroll
= flag_old_unroll_loops
? LOOP_UNROLL
: LOOP_AUTO_UNROLL
;
1287 do_prefetch
= flag_prefetch_loop_arrays
? LOOP_PREFETCH
: 0;
1289 if (flag_rerun_loop_opt
)
1291 cleanup_barriers ();
1293 /* We only want to perform unrolling once. */
1294 loop_optimize (get_insns (), dump_file
, do_unroll
);
1297 /* The first call to loop_optimize makes some instructions
1298 trivially dead. We delete those instructions now in the
1299 hope that doing so will make the heuristics in loop work
1300 better and possibly speed up compilation. */
1301 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1303 /* The regscan pass is currently necessary as the alias
1304 analysis code depends on this information. */
1305 reg_scan (get_insns (), max_reg_num (), 1);
1307 cleanup_barriers ();
1308 loop_optimize (get_insns (), dump_file
, do_unroll
| do_prefetch
);
1310 /* Loop can create trivially dead instructions. */
1311 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1312 find_basic_blocks (get_insns (), max_reg_num (), dump_file
);
1313 close_dump_file (DFI_loop
, print_rtl
, get_insns ());
1314 timevar_pop (TV_LOOP
);
1319 /* Perform loop optimizations. It might be better to do them a bit
1320 sooner, but we want the profile feedback to work more
1323 rest_of_handle_loop2 (void)
1325 struct loops
*loops
;
1328 if (!flag_move_loop_invariants
1329 && !flag_unswitch_loops
1331 && !flag_unroll_loops
1332 && !flag_branch_on_count_reg
)
1335 timevar_push (TV_LOOP
);
1336 open_dump_file (DFI_loop2
, current_function_decl
);
1338 dump_flow_info (dump_file
);
1340 /* Initialize structures for layout changes. */
1341 cfg_layout_initialize (0);
1343 loops
= loop_optimizer_init (dump_file
);
1347 /* The optimizations: */
1348 if (flag_move_loop_invariants
)
1349 move_loop_invariants (loops
);
1351 if (flag_unswitch_loops
)
1352 unswitch_loops (loops
);
1354 if (flag_peel_loops
|| flag_unroll_loops
)
1355 unroll_and_peel_loops (loops
,
1356 (flag_peel_loops
? UAP_PEEL
: 0) |
1357 (flag_unroll_loops
? UAP_UNROLL
: 0) |
1358 (flag_unroll_all_loops
? UAP_UNROLL_ALL
: 0));
1360 #ifdef HAVE_doloop_end
1361 if (flag_branch_on_count_reg
&& HAVE_doloop_end
)
1362 doloop_optimize_loops (loops
);
1363 #endif /* HAVE_doloop_end */
1365 loop_optimizer_finalize (loops
, dump_file
);
1368 free_dominance_info (CDI_DOMINATORS
);
1370 /* Finalize layout changes. */
1372 if (bb
->next_bb
!= EXIT_BLOCK_PTR
)
1373 bb
->rbi
->next
= bb
->next_bb
;
1374 cfg_layout_finalize ();
1376 cleanup_cfg (CLEANUP_EXPENSIVE
);
1377 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1378 reg_scan (get_insns (), max_reg_num (), 0);
1380 dump_flow_info (dump_file
);
1381 close_dump_file (DFI_loop2
, print_rtl_with_bb
, get_insns ());
1382 timevar_pop (TV_LOOP
);
1387 rest_of_handle_branch_target_load_optimize (void)
1389 static int warned
= 0;
1391 /* Leave this a warning for now so that it is possible to experiment
1392 with running this pass twice. In 3.6, we should either make this
1393 an error, or use separate dump files. */
1394 if (flag_branch_target_load_optimize
1395 && flag_branch_target_load_optimize2
1398 warning ("branch target register load optimization is not intended "
1404 open_dump_file (DFI_branch_target_load
, current_function_decl
);
1405 branch_target_load_optimize (epilogue_completed
);
1406 close_dump_file (DFI_branch_target_load
, print_rtl_with_bb
, get_insns ());
1410 #ifdef OPTIMIZE_MODE_SWITCHING
1412 rest_of_handle_mode_switching (void)
1414 timevar_push (TV_MODE_SWITCH
);
1417 optimize_mode_switching (NULL
);
1420 timevar_pop (TV_MODE_SWITCH
);
1425 rest_of_handle_jump (void)
1429 timevar_push (TV_JUMP
);
1430 open_dump_file (DFI_sibling
, current_function_decl
);
1432 /* ??? We may get caled either via tree_rest_of_compilation when the CFG
1433 is already built or directly (for instance from coverage code).
1434 The direct callers shall be updated. */
1435 if (!basic_block_info
)
1438 rebuild_jump_labels (get_insns ());
1439 find_exception_handler_labels ();
1440 find_basic_blocks (get_insns (), max_reg_num (), dump_file
);
1443 /* ??? We may get called either via tree_rest_of_compilation when the CFG
1444 is already built or directly (for instance from coverage code).
1445 The direct callers shall be updated. */
1446 if (!basic_block_info
)
1449 rebuild_jump_labels (get_insns ());
1450 find_exception_handler_labels ();
1451 find_basic_blocks (get_insns (), max_reg_num (), dump_file
);
1453 delete_unreachable_blocks ();
1454 #ifdef ENABLE_CHECKING
1455 verify_flow_info ();
1457 timevar_pop (TV_JUMP
);
1461 rest_of_handle_eh (void)
1463 insn_locators_initialize ();
1464 /* Complete generation of exception handling code. */
1467 timevar_push (TV_JUMP
);
1468 open_dump_file (DFI_eh
, current_function_decl
);
1470 cleanup_cfg (CLEANUP_PRE_LOOP
| CLEANUP_NO_INSN_DEL
);
1472 finish_eh_generation ();
1474 cleanup_cfg (CLEANUP_PRE_LOOP
| CLEANUP_NO_INSN_DEL
);
1476 close_dump_file (DFI_eh
, print_rtl
, get_insns ());
1477 timevar_pop (TV_JUMP
);
1483 rest_of_handle_prologue_epilogue (void)
1485 if (optimize
&& !flow2_completed
)
1486 cleanup_cfg (CLEANUP_EXPENSIVE
);
1488 /* On some machines, the prologue and epilogue code, or parts thereof,
1489 can be represented as RTL. Doing so lets us schedule insns between
1490 it and the rest of the code and also allows delayed branch
1491 scheduling to operate in the epilogue. */
1492 thread_prologue_and_epilogue_insns (get_insns ());
1493 epilogue_completed
= 1;
1495 if (optimize
&& flow2_completed
)
1496 life_analysis (dump_file
, PROP_POSTRELOAD
);
1500 rest_of_handle_stack_adjustments (void)
1502 life_analysis (dump_file
, PROP_POSTRELOAD
);
1503 cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_UPDATE_LIFE
1504 | (flag_crossjumping
? CLEANUP_CROSSJUMP
: 0));
1506 /* This is kind of a heuristic. We need to run combine_stack_adjustments
1507 even for machines with possibly nonzero RETURN_POPS_ARGS
1508 and ACCUMULATE_OUTGOING_ARGS. We expect that only ports having
1509 push instructions will have popping returns. */
1510 #ifndef PUSH_ROUNDING
1511 if (!ACCUMULATE_OUTGOING_ARGS
)
1513 combine_stack_adjustments ();
1517 rest_of_handle_flow2 (void)
1519 timevar_push (TV_FLOW2
);
1520 open_dump_file (DFI_flow2
, current_function_decl
);
1522 /* Re-create the death notes which were deleted during reload. */
1523 #ifdef ENABLE_CHECKING
1524 verify_flow_info ();
1527 /* If optimizing, then go ahead and split insns now. */
1531 split_all_insns (0);
1533 if (flag_branch_target_load_optimize
)
1534 rest_of_handle_branch_target_load_optimize ();
1536 if (!targetm
.late_rtl_prologue_epilogue
)
1537 rest_of_handle_prologue_epilogue ();
1540 rest_of_handle_stack_adjustments ();
1542 flow2_completed
= 1;
1544 close_dump_file (DFI_flow2
, print_rtl_with_bb
, get_insns ());
1545 timevar_pop (TV_FLOW2
);
1552 rest_of_handle_jump2 (void)
1554 open_dump_file (DFI_jump
, current_function_decl
);
1556 /* Always do one jump optimization pass to ensure that JUMP_LABEL fields
1557 are initialized and to compute whether control can drop off the end
1560 timevar_push (TV_JUMP
);
1561 /* Turn NOTE_INSN_EXPECTED_VALUE into REG_BR_PROB. Do this
1562 before jump optimization switches branch directions. */
1563 if (flag_guess_branch_prob
)
1564 expected_value_to_br_prob ();
1566 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1567 reg_scan (get_insns (), max_reg_num (), 0);
1569 dump_flow_info (dump_file
);
1570 cleanup_cfg ((optimize
? CLEANUP_EXPENSIVE
: 0) | CLEANUP_PRE_LOOP
1571 | (flag_thread_jumps
? CLEANUP_THREADING
: 0));
1573 create_loop_notes ();
1575 purge_line_number_notes (get_insns ());
1578 cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_PRE_LOOP
);
1580 /* Jump optimization, and the removal of NULL pointer checks, may
1581 have reduced the number of instructions substantially. CSE, and
1582 future passes, allocate arrays whose dimensions involve the
1583 maximum instruction UID, so if we can reduce the maximum UID
1584 we'll save big on memory. */
1585 renumber_insns (dump_file
);
1587 close_dump_file (DFI_jump
, print_rtl_with_bb
, get_insns ());
1588 timevar_pop (TV_JUMP
);
1593 #ifdef HAVE_peephole2
1595 rest_of_handle_peephole2 (void)
1597 timevar_push (TV_PEEPHOLE2
);
1598 open_dump_file (DFI_peephole2
, current_function_decl
);
1600 peephole2_optimize (dump_file
);
1602 close_dump_file (DFI_peephole2
, print_rtl_with_bb
, get_insns ());
1603 timevar_pop (TV_PEEPHOLE2
);
1608 rest_of_handle_postreload (void)
1610 timevar_push (TV_RELOAD_CSE_REGS
);
1611 open_dump_file (DFI_postreload
, current_function_decl
);
1613 /* Do a very simple CSE pass over just the hard registers. */
1614 reload_cse_regs (get_insns ());
1615 /* reload_cse_regs can eliminate potentially-trapping MEMs.
1616 Remove any EH edges associated with them. */
1617 if (flag_non_call_exceptions
)
1618 purge_all_dead_edges (0);
1620 close_dump_file (DFI_postreload
, print_rtl_with_bb
, get_insns ());
1621 timevar_pop (TV_RELOAD_CSE_REGS
);
1625 rest_of_handle_shorten_branches (void)
1627 /* Shorten branches. */
1628 timevar_push (TV_SHORTEN_BRANCH
);
1629 shorten_branches (get_insns ());
1630 timevar_pop (TV_SHORTEN_BRANCH
);
1634 rest_of_clean_state (void)
1636 coverage_end_function ();
1638 /* In case the function was not output,
1639 don't leave any temporary anonymous types
1640 queued up for sdb output. */
1641 #ifdef SDB_DEBUGGING_INFO
1642 if (write_symbols
== SDB_DEBUG
)
1643 sdbout_types (NULL_TREE
);
1646 reload_completed
= 0;
1647 epilogue_completed
= 0;
1648 flow2_completed
= 0;
1651 timevar_push (TV_FINAL
);
1653 /* Clear out the insn_length contents now that they are no
1655 init_insn_lengths ();
1657 /* Show no temporary slots allocated. */
1660 free_basic_block_vars ();
1661 free_bb_for_insn ();
1663 timevar_pop (TV_FINAL
);
1665 if (targetm
.binds_local_p (current_function_decl
))
1667 int pref
= cfun
->preferred_stack_boundary
;
1668 if (cfun
->recursive_call_emit
1669 && cfun
->stack_alignment_needed
> cfun
->preferred_stack_boundary
)
1670 pref
= cfun
->stack_alignment_needed
;
1671 cgraph_rtl_info (current_function_decl
)->preferred_incoming_stack_boundary
1675 /* Make sure volatile mem refs aren't considered valid operands for
1676 arithmetic insns. We must call this here if this is a nested inline
1677 function, since the above code leaves us in the init_recog state
1678 (from final.c), and the function context push/pop code does not
1679 save/restore volatile_ok.
1681 ??? Maybe it isn't necessary for expand_start_function to call this
1682 anymore if we do it here? */
1684 init_recog_no_volatile ();
1686 /* We're done with this function. Free up memory if we can. */
1687 free_after_parsing (cfun
);
1691 /* This function is called from the pass manager in tree-optimize.c
1692 after all tree passes have finished for a single function, and we
1693 have expanded the function body from trees to RTL.
1694 Once we are here, we have decided that we're supposed to output
1695 that function, ie. that we should write assembler code for it.
1697 We run a series of low-level passes here on the function's RTL
1698 representation. Each pass is called via a rest_of_* function. */
1701 rest_of_compilation (void)
1703 /* There's no need to defer outputting this function any more; we
1704 know we want to output it. */
1705 DECL_DEFER_OUTPUT (current_function_decl
) = 0;
1707 /* Now that we're done expanding trees to RTL, we shouldn't have any
1708 more CONCATs anywhere. */
1709 generating_concat_p
= 0;
1711 /* When processing delayed functions, prepare_function_start () won't
1712 have been run to re-initialize it. */
1713 cse_not_expected
= ! optimize
;
1715 finalize_block_changes ();
1717 /* Dump the rtl code if we are dumping rtl. */
1718 if (open_dump_file (DFI_rtl
, current_function_decl
))
1719 close_dump_file (DFI_rtl
, print_rtl
, get_insns ());
1721 /* Convert from NOTE_INSN_EH_REGION style notes, and do other
1722 sorts of eh initialization. Delay this until after the
1723 initial rtl dump so that we can see the original nesting. */
1724 convert_from_eh_region_ranges ();
1726 /* If we're emitting a nested function, make sure its parent gets
1727 emitted as well. Doing otherwise confuses debug info. */
1730 for (parent
= DECL_CONTEXT (current_function_decl
);
1731 parent
!= NULL_TREE
;
1732 parent
= get_containing_scope (parent
))
1733 if (TREE_CODE (parent
) == FUNCTION_DECL
)
1734 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (parent
)) = 1;
1737 /* We are now committed to emitting code for this function. Do any
1738 preparation, such as emitting abstract debug info for the inline
1739 before it gets mangled by optimization. */
1740 if (cgraph_function_possibly_inlined_p (current_function_decl
))
1741 (*debug_hooks
->outlining_inline_function
) (current_function_decl
);
1743 /* Remove any notes we don't need. That will make iterating
1744 over the instruction sequence faster, and allow the garbage
1745 collector to reclaim the memory used by the notes. */
1746 remove_unnecessary_notes ();
1748 /* Initialize some variables used by the optimizers. */
1749 init_function_for_compilation ();
1751 TREE_ASM_WRITTEN (current_function_decl
) = 1;
1753 /* Early return if there were errors. We can run afoul of our
1754 consistency checks, and there's not really much point in fixing them. */
1755 if (rtl_dump_and_exit
|| flag_syntax_only
|| errorcount
|| sorrycount
)
1756 goto exit_rest_of_compilation
;
1758 rest_of_handle_jump ();
1760 if (cfun
->tail_call_emit
)
1761 fixup_tail_calls ();
1763 rest_of_handle_eh ();
1765 /* Delay emitting hard_reg_initial_value sets until after EH landing pad
1766 generation, which might create new sets. */
1767 emit_initial_value_sets ();
1770 /* If we are doing position-independent code generation, now
1771 is the time to output special prologues and epilogues.
1772 We do not want to do this earlier, because it just clutters
1773 up inline functions with meaningless insns. */
1778 /* Copy any shared structure that should not be shared. */
1781 #ifdef SETJMP_VIA_SAVE_AREA
1782 /* This must be performed before virtual register instantiation.
1783 Please be aware that everything in the compiler that can look
1784 at the RTL up to this point must understand that REG_SAVE_AREA
1785 is just like a use of the REG contained inside. */
1786 if (current_function_calls_alloca
)
1787 optimize_save_area_alloca ();
1790 /* Instantiate all virtual registers. */
1791 instantiate_virtual_regs ();
1793 rest_of_handle_jump2 ();
1796 rest_of_handle_cse ();
1801 rest_of_handle_gcse ();
1803 if (flag_loop_optimize
)
1804 rest_of_handle_loop_optimize ();
1807 rest_of_handle_jump_bypass ();
1810 timevar_push (TV_FLOW
);
1811 rest_of_handle_cfg ();
1813 if (!flag_tree_based_profiling
1814 && (optimize
> 0 || profile_arc_flag
1815 || flag_test_coverage
|| flag_branch_probabilities
))
1817 rtl_register_profile_hooks ();
1818 rtl_register_value_prof_hooks ();
1819 rest_of_handle_branch_prob ();
1821 if (flag_branch_probabilities
1822 && flag_profile_values
1823 && (flag_value_profile_transformations
1824 || flag_speculative_prefetching
))
1825 rest_of_handle_value_profile_transformations ();
1827 /* Remove the death notes created for vpt. */
1828 if (flag_profile_values
)
1829 count_or_remove_death_notes (NULL
, 1);
1833 rest_of_handle_if_conversion ();
1835 if (optimize
> 0 && flag_tracer
)
1836 rest_of_handle_tracer ();
1839 && flag_loop_optimize2
)
1840 rest_of_handle_loop2 ();
1842 if (optimize
> 0 && flag_web
)
1843 rest_of_handle_web ();
1845 if (optimize
> 0 && flag_rerun_cse_after_loop
)
1846 rest_of_handle_cse2 ();
1848 cse_not_expected
= 1;
1850 rest_of_handle_life ();
1851 timevar_pop (TV_FLOW
);
1854 rest_of_handle_combine ();
1856 if (optimize
> 0 && flag_if_conversion
)
1857 rest_of_handle_if_after_combine ();
1859 /* The optimization to partition hot/cold basic blocks into separate
1860 sections of the .o file does not work well with linkonce or with
1861 user defined section attributes. Don't call it if either case
1864 if (flag_reorder_blocks_and_partition
1865 && !DECL_ONE_ONLY (current_function_decl
)
1866 && !user_defined_section_attribute
)
1867 rest_of_handle_partition_blocks ();
1869 if (optimize
> 0 && (flag_regmove
|| flag_expensive_optimizations
))
1870 rest_of_handle_regmove ();
1872 /* Do unconditional splitting before register allocation to allow machine
1873 description to add extra information not needed previously. */
1874 split_all_insns (1);
1876 #ifdef OPTIMIZE_MODE_SWITCHING
1877 rest_of_handle_mode_switching ();
1880 /* Any of the several passes since flow1 will have munged register
1881 lifetime data a bit. We need it to be up to date for scheduling
1882 (see handling of reg_known_equiv in init_alias_analysis). */
1883 recompute_reg_usage (get_insns (), !optimize_size
);
1885 #ifdef INSN_SCHEDULING
1886 if (optimize
> 0 && flag_modulo_sched
)
1887 rest_of_handle_sms ();
1889 if (flag_schedule_insns
)
1890 rest_of_handle_sched ();
1893 /* Determine if the current function is a leaf before running reload
1894 since this can impact optimizations done by the prologue and
1895 epilogue thus changing register elimination offsets. */
1896 current_function_is_leaf
= leaf_function_p ();
1898 if (flag_new_regalloc
)
1900 if (rest_of_handle_new_regalloc ())
1901 goto exit_rest_of_compilation
;
1905 if (rest_of_handle_old_regalloc ())
1906 goto exit_rest_of_compilation
;
1910 rest_of_handle_postreload ();
1912 if (optimize
> 0 && flag_gcse_after_reload
)
1913 rest_of_handle_gcse2 ();
1915 rest_of_handle_flow2 ();
1917 #ifdef HAVE_peephole2
1918 if (optimize
> 0 && flag_peephole2
)
1919 rest_of_handle_peephole2 ();
1923 rest_of_handle_if_after_reload ();
1927 if (flag_rename_registers
|| flag_cprop_registers
)
1928 rest_of_handle_regrename ();
1930 rest_of_handle_reorder_blocks ();
1933 if (flag_branch_target_load_optimize2
)
1934 rest_of_handle_branch_target_load_optimize ();
1936 #ifdef LEAF_REGISTERS
1937 current_function_uses_only_leaf_regs
1938 = optimize
> 0 && only_leaf_regs_used () && leaf_function_p ();
1941 if (targetm
.late_rtl_prologue_epilogue
)
1942 rest_of_handle_prologue_epilogue ();
1944 #ifdef INSN_SCHEDULING
1945 if (optimize
> 0 && flag_schedule_insns_after_reload
)
1946 rest_of_handle_sched2 ();
1950 rest_of_handle_stack_regs ();
1953 compute_alignments ();
1955 if (flag_var_tracking
)
1956 rest_of_handle_variable_tracking ();
1958 /* CFG is no longer maintained up-to-date. */
1959 free_bb_for_insn ();
1961 if (targetm
.machine_dependent_reorg
!= 0)
1962 rest_of_handle_machine_reorg ();
1964 purge_line_number_notes (get_insns ());
1965 cleanup_barriers ();
1968 if (flag_delayed_branch
)
1969 rest_of_handle_delay_slots ();
1972 #if defined (HAVE_ATTR_length) && !defined (STACK_REGS)
1973 timevar_push (TV_SHORTEN_BRANCH
);
1974 split_all_insns_noflow ();
1975 timevar_pop (TV_SHORTEN_BRANCH
);
1978 convert_to_eh_region_ranges ();
1980 rest_of_handle_shorten_branches ();
1982 set_nothrow_function_flags ();
1984 rest_of_handle_final ();
1986 exit_rest_of_compilation
:
1988 rest_of_clean_state ();
1992 init_optimization_passes (void)
1994 open_dump_file (DFI_cgraph
, NULL
);
1995 cgraph_dump_file
= dump_file
;
2000 finish_optimization_passes (void)
2002 timevar_push (TV_DUMP
);
2003 if (profile_arc_flag
|| flag_test_coverage
|| flag_branch_probabilities
)
2005 open_dump_file (DFI_bp
, NULL
);
2007 close_dump_file (DFI_bp
, NULL
, NULL_RTX
);
2010 if (optimize
> 0 && open_dump_file (DFI_combine
, NULL
))
2012 dump_combine_total_stats (dump_file
);
2013 close_dump_file (DFI_combine
, NULL
, NULL_RTX
);
2016 dump_file
= cgraph_dump_file
;
2017 cgraph_dump_file
= NULL
;
2018 close_dump_file (DFI_cgraph
, NULL
, NULL_RTX
);
2020 /* Do whatever is necessary to finish printing the graphs. */
2021 if (graph_dump_format
!= no_graph
)
2025 for (i
= 0; i
< (int) DFI_MAX
; ++i
)
2026 if (dump_file_tbl
[i
].initialized
&& dump_file_tbl
[i
].graph_dump_p
)
2031 sprintf (seq
, DUMPFILE_FORMAT
, i
);
2032 suffix
= concat (seq
, dump_file_tbl
[i
].extension
, NULL
);
2033 finish_graph_dump_file (dump_base_name
, suffix
);
2038 timevar_pop (TV_DUMP
);
2042 enable_rtl_dump_file (int letter
)
2044 bool matched
= false;
2049 for (i
= 0; i
< (int) DFI_MAX
; ++i
)
2050 dump_file_tbl
[i
].enabled
= 1;
2055 for (i
= 0; i
< (int) DFI_MAX
; ++i
)
2056 if (letter
== dump_file_tbl
[i
].debug_switch
)
2058 dump_file_tbl
[i
].enabled
= 1;
2066 struct tree_opt_pass pass_rest_of_compilation
=
2068 "rest of compilation", /* name */
2070 rest_of_compilation
, /* execute */
2073 0, /* static_pass_number */
2074 TV_REST_OF_COMPILATION
, /* tv_id */
2075 PROP_rtl
, /* properties_required */
2076 0, /* properties_provided */
2077 PROP_rtl
, /* properties_destroyed */
2078 0, /* todo_flags_start */
2079 TODO_ggc_collect
/* todo_flags_finish */