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. */
169 DFI_branch_target_load
,
178 /* Describes all the dump files. Should be kept in order of the
179 pass and in sync with dump_file_index above.
181 Remaining -d letters:
187 static struct dump_file_info dump_file_tbl
[DFI_MAX
] =
189 { "cgraph", 'U', 0, 0, 0 },
190 { "rtl", 'r', 0, 0, 0 },
191 { "sibling", 'i', 0, 0, 0 },
192 { "eh", 'h', 0, 0, 0 },
193 { "jump", 'j', 0, 0, 0 },
194 { "null", 'u', 0, 0, 0 },
195 { "cse", 's', 0, 0, 0 },
196 { "addressof", 'F', 0, 0, 0 },
197 { "gcse", 'G', 1, 0, 0 },
198 { "loop", 'L', 1, 0, 0 },
199 { "bypass", 'G', 1, 0, 0 }, /* Yes, duplicate enable switch. */
200 { "cfg", 'f', 1, 0, 0 },
201 { "bp", 'b', 1, 0, 0 },
202 { "vpt", 'V', 1, 0, 0 },
203 { "ce1", 'C', 1, 0, 0 },
204 { "tracer", 'T', 1, 0, 0 },
205 { "loop2", 'L', 1, 0, 0 },
206 { "web", 'Z', 0, 0, 0 },
207 { "cse2", 't', 1, 0, 0 },
208 { "life", 'f', 1, 0, 0 }, /* Yes, duplicate enable switch. */
209 { "combine", 'c', 1, 0, 0 },
210 { "ce2", 'C', 1, 0, 0 },
211 { "regmove", 'N', 1, 0, 0 },
212 { "sms", 'm', 0, 0, 0 },
213 { "sched", 'S', 1, 0, 0 },
214 { "lreg", 'l', 1, 0, 0 },
215 { "greg", 'g', 1, 0, 0 },
216 { "postreload", 'o', 1, 0, 0 },
217 { "gcse2", 'J', 0, 0, 0 },
218 { "flow2", 'w', 1, 0, 0 },
219 { "peephole2", 'z', 1, 0, 0 },
220 { "ce3", 'E', 1, 0, 0 },
221 { "rnreg", 'n', 1, 0, 0 },
222 { "bbro", 'B', 1, 0, 0 },
223 { "btl", 'd', 1, 0, 0 }, /* Yes, duplicate enable switch. */
224 { "sched2", 'R', 1, 0, 0 },
225 { "stack", 'k', 1, 0, 0 },
226 { "vartrack", 'V', 1, 0, 0 }, /* Yes, duplicate enable switch. */
227 { "mach", 'M', 1, 0, 0 },
228 { "dbr", 'd', 0, 0, 0 },
231 /* Routine to open a dump file. Return true if the dump file is enabled. */
234 open_dump_file (enum dump_file_index index
, tree decl
)
237 const char *open_arg
;
240 if (! dump_file_tbl
[index
].enabled
)
243 timevar_push (TV_DUMP
);
244 if (dump_file
!= NULL
)
247 sprintf (seq
, DUMPFILE_FORMAT
, index
);
249 if (! dump_file_tbl
[index
].initialized
)
251 /* If we've not initialized the files, do so now. */
252 if (graph_dump_format
!= no_graph
253 && dump_file_tbl
[index
].graph_dump_p
)
255 dump_name
= concat (seq
, dump_file_tbl
[index
].extension
, NULL
);
256 clean_graph_dump_file (dump_base_name
, dump_name
);
259 dump_file_tbl
[index
].initialized
= 1;
265 dump_name
= concat (dump_base_name
, seq
,
266 dump_file_tbl
[index
].extension
, NULL
);
268 dump_file
= fopen (dump_name
, open_arg
);
269 if (dump_file
== NULL
)
270 fatal_error ("can't open %s: %m", dump_name
);
275 fprintf (dump_file
, "\n;; Function %s%s\n\n",
276 lang_hooks
.decl_printable_name (decl
, 2),
277 cfun
->function_frequency
== FUNCTION_FREQUENCY_HOT
279 : cfun
->function_frequency
== FUNCTION_FREQUENCY_UNLIKELY_EXECUTED
280 ? " (unlikely executed)"
283 timevar_pop (TV_DUMP
);
287 /* Routine to close a dump file. */
290 close_dump_file (enum dump_file_index index
,
291 void (*func
) (FILE *, rtx
),
297 timevar_push (TV_DUMP
);
299 && graph_dump_format
!= no_graph
300 && dump_file_tbl
[index
].graph_dump_p
)
305 sprintf (seq
, DUMPFILE_FORMAT
, index
);
306 suffix
= concat (seq
, dump_file_tbl
[index
].extension
, NULL
);
307 print_rtl_graph_with_bb (dump_base_name
, suffix
, insns
);
312 func (dump_file
, insns
);
318 timevar_pop (TV_DUMP
);
321 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
324 This does nothing for local (non-static) variables, unless the
325 variable is a register variable with an ASMSPEC. In that case, or
326 if the variable is not an automatic, it sets up the RTL and
327 outputs any assembler code (label definition, storage allocation
330 DECL is the declaration. If ASMSPEC is nonzero, it specifies
331 the assembler symbol name to be used. TOP_LEVEL is nonzero
332 if this declaration is not within a function. */
335 rest_of_decl_compilation (tree decl
,
340 /* We deferred calling assemble_alias so that we could collect
341 other attributes such as visibility. Emit the alias now. */
344 alias
= lookup_attribute ("alias", DECL_ATTRIBUTES (decl
));
347 alias
= TREE_VALUE (TREE_VALUE (alias
));
348 alias
= get_identifier (TREE_STRING_POINTER (alias
));
349 assemble_alias (decl
, alias
);
353 /* Forward declarations for nested functions are not "external",
354 but we need to treat them as if they were. */
355 if (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)
356 || TREE_CODE (decl
) == FUNCTION_DECL
)
358 timevar_push (TV_VARCONST
);
361 make_decl_rtl (decl
, asmspec
);
363 /* Don't output anything when a tentative file-scope definition
364 is seen. But at end of compilation, do output code for them.
366 We do output all variables when unit-at-a-time is active and rely on
367 callgraph code to defer them except for forward declarations
368 (see gcc.c-torture/compile/920624-1.c) */
370 || !DECL_DEFER_OUTPUT (decl
)
371 || (flag_unit_at_a_time
&& DECL_INITIAL (decl
)))
372 && !DECL_EXTERNAL (decl
))
374 if (flag_unit_at_a_time
&& !cgraph_global_info_ready
375 && TREE_CODE (decl
) != FUNCTION_DECL
&& top_level
)
376 cgraph_varpool_finalize_decl (decl
);
378 assemble_variable (decl
, top_level
, at_end
, 0);
381 #ifdef ASM_FINISH_DECLARE_OBJECT
382 if (decl
== last_assemble_variable_decl
)
384 ASM_FINISH_DECLARE_OBJECT (asm_out_file
, decl
,
389 timevar_pop (TV_VARCONST
);
391 else if (DECL_REGISTER (decl
) && asmspec
!= 0)
393 if (decode_reg_name (asmspec
) >= 0)
395 SET_DECL_RTL (decl
, NULL_RTX
);
396 make_decl_rtl (decl
, asmspec
);
400 error ("%Hinvalid register name `%s' for register variable",
401 &DECL_SOURCE_LOCATION (decl
), asmspec
);
402 DECL_REGISTER (decl
) = 0;
407 else if (TREE_CODE (decl
) == TYPE_DECL
)
409 timevar_push (TV_SYMOUT
);
410 debug_hooks
->type_decl (decl
, !top_level
);
411 timevar_pop (TV_SYMOUT
);
415 /* Called after finishing a record, union or enumeral type. */
418 rest_of_type_compilation (tree type
, int toplev
)
420 /* Avoid confusing the debug information machinery when there are
422 if (errorcount
!= 0 || sorrycount
!= 0)
425 timevar_push (TV_SYMOUT
);
426 debug_hooks
->type_decl (TYPE_STUB_DECL (type
), !toplev
);
427 timevar_pop (TV_SYMOUT
);
430 /* Turn the RTL into assembly. */
432 rest_of_handle_final (tree decl
, rtx insns
)
434 if (decl
!= current_function_decl
|| insns
!= get_insns ())
437 timevar_push (TV_FINAL
);
442 /* Get the function's name, as described by its RTL. This may be
443 different from the DECL_NAME name used in the source file. */
446 if (GET_CODE (x
) != MEM
)
449 if (GET_CODE (x
) != SYMBOL_REF
)
451 fnname
= XSTR (x
, 0);
453 assemble_start_function (decl
, fnname
);
454 final_start_function (insns
, asm_out_file
, optimize
);
455 final (insns
, asm_out_file
, optimize
, 0);
456 final_end_function ();
458 #ifdef IA64_UNWIND_INFO
459 /* ??? The IA-64 ".handlerdata" directive must be issued before
460 the ".endp" directive that closes the procedure descriptor. */
461 output_function_exception_table ();
464 assemble_end_function (decl
, fnname
);
466 #ifndef IA64_UNWIND_INFO
467 /* Otherwise, it feels unclean to switch sections in the middle. */
468 output_function_exception_table ();
472 fflush (asm_out_file
);
474 /* Release all memory allocated by flow. */
475 free_basic_block_vars ();
477 /* Release all memory held by regsets now. */
478 regset_release_memory ();
480 timevar_pop (TV_FINAL
);
486 /* Run delay slot optimization. */
488 rest_of_handle_delay_slots (tree decl
, rtx insns
)
490 if (decl
!= current_function_decl
|| insns
!= get_insns ())
493 timevar_push (TV_DBR_SCHED
);
494 open_dump_file (DFI_dbr
, decl
);
496 dbr_schedule (insns
, dump_file
);
498 close_dump_file (DFI_dbr
, print_rtl
, insns
);
499 timevar_pop (TV_DBR_SCHED
);
506 /* Convert register usage from flat register file usage to a stack
509 rest_of_handle_stack_regs (tree decl
, rtx insns
)
511 if (decl
!= current_function_decl
|| insns
!= get_insns ())
514 #if defined (HAVE_ATTR_length)
515 /* If flow2 creates new instructions which need splitting
516 and scheduling after reload is not done, they might not be
517 split until final which doesn't allow splitting
518 if HAVE_ATTR_length. */
519 #ifdef INSN_SCHEDULING
520 if (optimize
&& !flag_schedule_insns_after_reload
)
525 timevar_push (TV_SHORTEN_BRANCH
);
527 timevar_pop (TV_SHORTEN_BRANCH
);
531 timevar_push (TV_REG_STACK
);
532 open_dump_file (DFI_stack
, decl
);
534 if (reg_to_stack (dump_file
) && optimize
)
536 if (cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_POST_REGSTACK
537 | (flag_crossjumping
? CLEANUP_CROSSJUMP
: 0))
538 && (flag_reorder_blocks
|| flag_reorder_blocks_and_partition
))
540 reorder_basic_blocks ();
541 cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_POST_REGSTACK
);
545 close_dump_file (DFI_stack
, print_rtl_with_bb
, insns
);
546 timevar_pop (TV_REG_STACK
);
552 /* Track the variables, ie. compute where the variable is stored at each position in function. */
554 rest_of_handle_variable_tracking (tree decl
, rtx insns
)
556 if (decl
!= current_function_decl
|| insns
!= get_insns ())
559 timevar_push (TV_VAR_TRACKING
);
560 open_dump_file (DFI_vartrack
, decl
);
562 variable_tracking_main ();
564 close_dump_file (DFI_vartrack
, print_rtl_with_bb
, insns
);
565 timevar_pop (TV_VAR_TRACKING
);
568 /* Machine independent reorg pass. */
570 rest_of_handle_machine_reorg (tree decl
, rtx insns
)
572 if (decl
!= current_function_decl
|| insns
!= get_insns ())
575 timevar_push (TV_MACH_DEP
);
576 open_dump_file (DFI_mach
, decl
);
578 targetm
.machine_dependent_reorg ();
580 close_dump_file (DFI_mach
, print_rtl
, insns
);
581 timevar_pop (TV_MACH_DEP
);
587 /* Run new register allocator. Return TRUE if we must exit
588 rest_of_compilation upon return. */
590 rest_of_handle_new_regalloc (tree decl
, rtx insns
)
594 if (decl
!= current_function_decl
|| insns
!= get_insns ())
597 delete_trivially_dead_insns (insns
, max_reg_num ());
600 timevar_pop (TV_LOCAL_ALLOC
);
601 if (dump_file_tbl
[DFI_lreg
].enabled
)
603 timevar_push (TV_DUMP
);
605 close_dump_file (DFI_lreg
, NULL
, NULL
);
606 timevar_pop (TV_DUMP
);
609 /* XXX clean up the whole mess to bring live info in shape again. */
610 timevar_push (TV_GLOBAL_ALLOC
);
611 open_dump_file (DFI_greg
, decl
);
613 build_insn_chain (insns
);
614 failure
= reload (insns
, 0);
616 timevar_pop (TV_GLOBAL_ALLOC
);
618 if (dump_file_tbl
[DFI_greg
].enabled
)
620 timevar_push (TV_DUMP
);
622 dump_global_regs (dump_file
);
624 close_dump_file (DFI_greg
, print_rtl_with_bb
, insns
);
625 timevar_pop (TV_DUMP
);
631 reload_completed
= 1;
636 /* Run old register allocator. Return TRUE if we must exit
637 rest_of_compilation upon return. */
639 rest_of_handle_old_regalloc (tree decl
, rtx insns
)
644 if (decl
!= current_function_decl
|| insns
!= get_insns ())
647 /* Allocate the reg_renumber array. */
648 allocate_reg_info (max_regno
, FALSE
, TRUE
);
650 /* And the reg_equiv_memory_loc array. */
651 VARRAY_GROW (reg_equiv_memory_loc_varray
, max_regno
);
652 reg_equiv_memory_loc
= &VARRAY_RTX (reg_equiv_memory_loc_varray
, 0);
654 allocate_initial_values (reg_equiv_memory_loc
);
656 regclass (insns
, max_reg_num (), dump_file
);
657 rebuild_notes
= local_alloc ();
659 timevar_pop (TV_LOCAL_ALLOC
);
661 /* Local allocation may have turned an indirect jump into a direct
662 jump. If so, we must rebuild the JUMP_LABEL fields of jumping
666 timevar_push (TV_JUMP
);
668 rebuild_jump_labels (insns
);
669 purge_all_dead_edges (0);
671 timevar_pop (TV_JUMP
);
674 if (dump_file_tbl
[DFI_lreg
].enabled
)
676 timevar_push (TV_DUMP
);
678 dump_flow_info (dump_file
);
679 dump_local_alloc (dump_file
);
681 close_dump_file (DFI_lreg
, print_rtl_with_bb
, insns
);
682 timevar_pop (TV_DUMP
);
687 timevar_push (TV_GLOBAL_ALLOC
);
688 open_dump_file (DFI_greg
, decl
);
690 /* If optimizing, allocate remaining pseudo-regs. Do the reload
691 pass fixing up any insns that are invalid. */
694 failure
= global_alloc (dump_file
);
697 build_insn_chain (insns
);
698 failure
= reload (insns
, 0);
701 timevar_pop (TV_GLOBAL_ALLOC
);
703 if (dump_file_tbl
[DFI_greg
].enabled
)
705 timevar_push (TV_DUMP
);
707 dump_global_regs (dump_file
);
709 close_dump_file (DFI_greg
, print_rtl_with_bb
, insns
);
710 timevar_pop (TV_DUMP
);
716 /* Run the regrename and cprop passes. */
718 rest_of_handle_regrename (tree decl
, rtx insns
)
720 if (decl
!= current_function_decl
|| insns
!= get_insns ())
723 timevar_push (TV_RENAME_REGISTERS
);
724 open_dump_file (DFI_rnreg
, decl
);
726 if (flag_rename_registers
)
727 regrename_optimize ();
728 if (flag_cprop_registers
)
729 copyprop_hardreg_forward ();
731 close_dump_file (DFI_rnreg
, print_rtl_with_bb
, insns
);
732 timevar_pop (TV_RENAME_REGISTERS
);
735 /* Reorder basic blocks. */
737 rest_of_handle_reorder_blocks (tree decl
, rtx insns
)
740 open_dump_file (DFI_bbro
, decl
);
742 if (decl
!= current_function_decl
|| insns
!= get_insns ())
745 /* Last attempt to optimize CFG, as scheduling, peepholing and insn
746 splitting possibly introduced more crossjumping opportunities. */
747 changed
= cleanup_cfg (CLEANUP_EXPENSIVE
748 | (!HAVE_conditional_execution
749 ? CLEANUP_UPDATE_LIFE
: 0));
751 if (flag_sched2_use_traces
&& flag_schedule_insns_after_reload
)
753 if (flag_reorder_blocks
|| flag_reorder_blocks_and_partition
)
754 reorder_basic_blocks ();
755 if (flag_reorder_blocks
|| flag_reorder_blocks_and_partition
756 || (flag_sched2_use_traces
&& flag_schedule_insns_after_reload
))
757 changed
|= cleanup_cfg (CLEANUP_EXPENSIVE
758 | (!HAVE_conditional_execution
759 ? CLEANUP_UPDATE_LIFE
: 0));
761 /* On conditional execution targets we can not update the life cheaply, so
762 we deffer the updating to after both cleanups. This may lose some cases
763 but should not be terribly bad. */
764 if (changed
&& HAVE_conditional_execution
)
765 update_life_info (NULL
, UPDATE_LIFE_GLOBAL_RM_NOTES
,
767 close_dump_file (DFI_bbro
, print_rtl_with_bb
, insns
);
770 #ifdef INSN_SCHEDULING
771 /* Run instruction scheduler. */
773 rest_of_handle_sched (tree decl
, rtx insns
)
775 if (decl
!= current_function_decl
|| insns
!= get_insns ())
778 timevar_push (TV_SMS
);
779 if (optimize
> 0 && flag_modulo_sched
)
782 /* Perform SMS module scheduling. */
783 open_dump_file (DFI_sms
, decl
);
785 /* We want to be able to create new pseudos. */
787 sms_schedule (dump_file
);
788 close_dump_file (DFI_sms
, print_rtl
, get_insns ());
791 /* Update the life information, becuase we add pseudos. */
792 max_regno
= max_reg_num ();
793 allocate_reg_info (max_regno
, FALSE
, FALSE
);
794 update_life_info_in_dirty_blocks (UPDATE_LIFE_GLOBAL_RM_NOTES
,
796 | PROP_KILL_DEAD_CODE
797 | PROP_SCAN_DEAD_CODE
));
800 timevar_pop (TV_SMS
);
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 if (optimize
> 0 && flag_schedule_insns
)
807 open_dump_file (DFI_sched
, decl
);
809 /* Do control and data sched analysis,
810 and write some of the results to dump file. */
812 schedule_insns (dump_file
);
814 close_dump_file (DFI_sched
, print_rtl_with_bb
, insns
);
816 timevar_pop (TV_SCHED
);
821 /* Run second scheduling pass after reload. */
823 rest_of_handle_sched2 (tree decl
, rtx insns
)
825 if (decl
!= current_function_decl
|| insns
!= get_insns ())
828 timevar_push (TV_SCHED2
);
829 open_dump_file (DFI_sched2
, decl
);
831 /* Do control and data sched analysis again,
832 and write some more of the results to dump file. */
836 if (flag_sched2_use_superblocks
|| flag_sched2_use_traces
)
838 schedule_ebbs (dump_file
);
839 /* No liveness updating code yet, but it should be easy to do.
840 reg-stack recomputes the liveness when needed for now. */
841 count_or_remove_death_notes (NULL
, 1);
842 cleanup_cfg (CLEANUP_EXPENSIVE
);
845 schedule_insns (dump_file
);
847 close_dump_file (DFI_sched2
, print_rtl_with_bb
, insns
);
848 timevar_pop (TV_SCHED2
);
855 rest_of_handle_gcse2 (tree decl
, rtx insns
)
857 if (decl
!= current_function_decl
|| insns
!= get_insns ())
860 open_dump_file (DFI_gcse2
, decl
);
862 gcse_after_reload_main (insns
, dump_file
);
863 rebuild_jump_labels (insns
);
864 delete_trivially_dead_insns (insns
, max_reg_num ());
865 close_dump_file (DFI_gcse2
, print_rtl_with_bb
, insns
);
869 #ifdef ENABLE_CHECKING
874 /* Register allocation pre-pass, to reduce number of moves necessary
875 for two-address machines. */
877 rest_of_handle_regmove (tree decl
, rtx insns
)
879 if (decl
!= current_function_decl
|| insns
!= get_insns ())
882 timevar_push (TV_REGMOVE
);
883 open_dump_file (DFI_regmove
, decl
);
885 regmove_optimize (insns
, max_reg_num (), dump_file
);
887 cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_UPDATE_LIFE
);
888 close_dump_file (DFI_regmove
, print_rtl_with_bb
, insns
);
889 timevar_pop (TV_REGMOVE
);
896 rest_of_handle_tracer (tree decl
, rtx insns
)
898 if (decl
!= current_function_decl
|| insns
!= get_insns ())
901 open_dump_file (DFI_tracer
, decl
);
903 dump_flow_info (dump_file
);
905 cleanup_cfg (CLEANUP_EXPENSIVE
);
906 reg_scan (insns
, max_reg_num (), 0);
907 close_dump_file (DFI_tracer
, print_rtl_with_bb
, get_insns ());
910 /* If-conversion and CFG cleanup. */
912 rest_of_handle_if_conversion (tree decl
, rtx insns
)
914 if (decl
!= current_function_decl
|| insns
!= get_insns ())
917 open_dump_file (DFI_ce1
, decl
);
918 if (flag_if_conversion
)
920 timevar_push (TV_IFCVT
);
922 dump_flow_info (dump_file
);
923 cleanup_cfg (CLEANUP_EXPENSIVE
);
924 reg_scan (insns
, max_reg_num (), 0);
926 timevar_pop (TV_IFCVT
);
928 timevar_push (TV_JUMP
);
929 cleanup_cfg (CLEANUP_EXPENSIVE
);
930 reg_scan (insns
, max_reg_num (), 0);
931 timevar_pop (TV_JUMP
);
932 close_dump_file (DFI_ce1
, print_rtl_with_bb
, get_insns ());
935 /* Rerun if-conversion, as combine may have simplified things enough
936 to now meet sequence length restrictions. */
938 rest_of_handle_if_after_combine (tree decl
, rtx insns
)
940 if (decl
!= current_function_decl
|| insns
!= get_insns ())
943 timevar_push (TV_IFCVT
);
944 open_dump_file (DFI_ce2
, decl
);
950 close_dump_file (DFI_ce2
, print_rtl_with_bb
, insns
);
951 timevar_pop (TV_IFCVT
);
955 rest_of_handle_web (tree decl
, rtx insns
)
957 if (decl
!= current_function_decl
|| insns
!= get_insns ())
960 open_dump_file (DFI_web
, decl
);
961 timevar_push (TV_WEB
);
963 delete_trivially_dead_insns (insns
, max_reg_num ());
964 cleanup_cfg (CLEANUP_EXPENSIVE
);
966 timevar_pop (TV_WEB
);
967 close_dump_file (DFI_web
, print_rtl_with_bb
, 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 (tree decl
, rtx insns
)
976 if (decl
!= current_function_decl
|| insns
!= get_insns ())
979 timevar_push (TV_BRANCH_PROB
);
980 open_dump_file (DFI_bp
, decl
);
982 if (profile_arc_flag
|| flag_test_coverage
|| flag_branch_probabilities
)
985 /* Discover and record the loop depth at the head of each basic
986 block. The loop infrastructure does the real job for us. */
987 flow_loops_find (&loops
, LOOP_TREE
);
990 flow_loops_dump (&loops
, dump_file
, NULL
, 0);
992 /* Estimate using heuristics if no profiling info is available. */
993 if (flag_guess_branch_prob
)
994 estimate_probability (&loops
);
996 flow_loops_free (&loops
);
997 free_dominance_info (CDI_DOMINATORS
);
998 close_dump_file (DFI_bp
, print_rtl_with_bb
, insns
);
999 timevar_pop (TV_BRANCH_PROB
);
1002 /* Do optimizations based on expression value profiles. */
1004 rest_of_handle_value_profile_transformations (tree decl
, rtx insns
)
1006 if (decl
!= current_function_decl
|| insns
!= get_insns ())
1009 open_dump_file (DFI_vpt
, decl
);
1010 timevar_push (TV_VPT
);
1012 if (value_profile_transformations ())
1013 cleanup_cfg (CLEANUP_EXPENSIVE
);
1015 timevar_pop (TV_VPT
);
1016 close_dump_file (DFI_vpt
, print_rtl_with_bb
, insns
);
1019 /* Do control and data flow analysis; write some of the results to the
1022 rest_of_handle_cfg (tree decl
, rtx insns
)
1024 if (decl
!= current_function_decl
|| insns
!= get_insns ())
1027 open_dump_file (DFI_cfg
, decl
);
1029 dump_flow_info (dump_file
);
1031 cleanup_cfg (CLEANUP_EXPENSIVE
1032 | (flag_thread_jumps
? CLEANUP_THREADING
: 0));
1034 /* It may make more sense to mark constant functions after dead code is
1035 eliminated by life_analysis, but we need to do it early, as -fprofile-arcs
1036 may insert code making function non-constant, but we still must consider
1037 it as constant, otherwise -fbranch-probabilities will not read data back.
1039 life_analysis rarely eliminates modification of external memory.
1043 /* Alias analysis depends on this information and mark_constant_function
1044 depends on alias analysis. */
1045 reg_scan (insns
, max_reg_num (), 1);
1046 mark_constant_function ();
1049 close_dump_file (DFI_cfg
, print_rtl_with_bb
, insns
);
1052 /* Purge addressofs. */
1054 rest_of_handle_addressof (tree decl
, rtx insns
)
1056 if (decl
!= current_function_decl
|| insns
!= get_insns ())
1059 open_dump_file (DFI_addressof
, decl
);
1061 purge_addressof (insns
);
1062 if (optimize
&& purge_all_dead_edges (0))
1063 delete_unreachable_blocks ();
1064 reg_scan (insns
, max_reg_num (), 1);
1066 close_dump_file (DFI_addressof
, print_rtl
, insns
);
1069 /* Perform jump bypassing and control flow optimizations. */
1071 rest_of_handle_jump_bypass (tree decl
, rtx insns
)
1073 if (decl
!= current_function_decl
|| insns
!= get_insns ())
1076 timevar_push (TV_BYPASS
);
1077 open_dump_file (DFI_bypass
, decl
);
1079 cleanup_cfg (CLEANUP_EXPENSIVE
);
1080 reg_scan (insns
, max_reg_num (), 1);
1082 if (bypass_jumps (dump_file
))
1084 rebuild_jump_labels (insns
);
1085 cleanup_cfg (CLEANUP_EXPENSIVE
);
1086 delete_trivially_dead_insns (insns
, max_reg_num ());
1089 close_dump_file (DFI_bypass
, print_rtl_with_bb
, insns
);
1090 timevar_pop (TV_BYPASS
);
1094 #ifdef ENABLE_CHECKING
1095 verify_flow_info ();
1099 /* Try combining insns through substitution. */
1101 rest_of_handle_combine (tree decl
, rtx insns
)
1103 int rebuild_jump_labels_after_combine
= 0;
1105 if (decl
!= current_function_decl
|| insns
!= get_insns ())
1108 timevar_push (TV_COMBINE
);
1109 open_dump_file (DFI_combine
, decl
);
1111 rebuild_jump_labels_after_combine
1112 = combine_instructions (insns
, max_reg_num ());
1114 /* Combining insns may have turned an indirect jump into a
1115 direct jump. Rebuild the JUMP_LABEL fields of jumping
1117 if (rebuild_jump_labels_after_combine
)
1119 timevar_push (TV_JUMP
);
1120 rebuild_jump_labels (insns
);
1121 timevar_pop (TV_JUMP
);
1123 cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_UPDATE_LIFE
);
1126 close_dump_file (DFI_combine
, print_rtl_with_bb
, insns
);
1127 timevar_pop (TV_COMBINE
);
1132 /* Perform life analysis. */
1134 rest_of_handle_life (tree decl
, rtx insns
)
1136 if (decl
!= current_function_decl
|| insns
!= get_insns ())
1139 open_dump_file (DFI_life
, decl
);
1142 #ifdef ENABLE_CHECKING
1143 verify_flow_info ();
1145 life_analysis (dump_file
, PROP_FINAL
);
1147 cleanup_cfg ((optimize
? CLEANUP_EXPENSIVE
: 0) | CLEANUP_UPDATE_LIFE
1149 | (flag_thread_jumps
? CLEANUP_THREADING
: 0));
1150 timevar_pop (TV_FLOW
);
1154 setjmp_vars_warning (DECL_INITIAL (decl
));
1155 setjmp_args_warning ();
1160 if (!flag_new_regalloc
&& initialize_uninitialized_subregs ())
1162 /* Insns were inserted, and possibly pseudos created, so
1163 things might look a bit different. */
1164 insns
= get_insns ();
1165 allocate_reg_life_data ();
1166 update_life_info (NULL
, UPDATE_LIFE_GLOBAL_RM_NOTES
,
1167 PROP_LOG_LINKS
| PROP_REG_INFO
| PROP_DEATH_NOTES
);
1173 close_dump_file (DFI_life
, print_rtl_with_bb
, insns
);
1178 /* Perform common subexpression elimination. Nonzero value from
1179 `cse_main' means that jumps were simplified and some code may now
1180 be unreachable, so do jump optimization again. */
1182 rest_of_handle_cse (tree decl
, rtx insns
)
1185 if (decl
!= current_function_decl
|| insns
!= get_insns ())
1188 open_dump_file (DFI_cse
, decl
);
1190 dump_flow_info (dump_file
);
1191 timevar_push (TV_CSE
);
1193 reg_scan (insns
, max_reg_num (), 1);
1195 tem
= cse_main (insns
, max_reg_num (), 0, dump_file
);
1197 rebuild_jump_labels (insns
);
1198 if (purge_all_dead_edges (0))
1199 delete_unreachable_blocks ();
1201 delete_trivially_dead_insns (insns
, max_reg_num ());
1203 /* If we are not running more CSE passes, then we are no longer
1204 expecting CSE to be run. But always rerun it in a cheap mode. */
1205 cse_not_expected
= !flag_rerun_cse_after_loop
&& !flag_gcse
;
1207 if (tem
|| optimize
> 1)
1208 cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_PRE_LOOP
);
1210 timevar_pop (TV_CSE
);
1211 close_dump_file (DFI_cse
, print_rtl_with_bb
, insns
);
1214 /* Run second CSE pass after loop optimizations. */
1216 rest_of_handle_cse2 (tree decl
, rtx insns
)
1219 if (decl
!= current_function_decl
|| insns
!= get_insns ())
1222 timevar_push (TV_CSE2
);
1223 open_dump_file (DFI_cse2
, decl
);
1225 dump_flow_info (dump_file
);
1226 /* CFG is no longer maintained up-to-date. */
1227 tem
= cse_main (insns
, max_reg_num (), 1, dump_file
);
1229 /* Run a pass to eliminate duplicated assignments to condition code
1230 registers. We have to run this after bypass_jumps, because it
1231 makes it harder for that pass to determine whether a jump can be
1233 cse_condition_code_reg ();
1235 purge_all_dead_edges (0);
1236 delete_trivially_dead_insns (insns
, max_reg_num ());
1240 timevar_push (TV_JUMP
);
1241 rebuild_jump_labels (insns
);
1242 cleanup_cfg (CLEANUP_EXPENSIVE
);
1243 timevar_pop (TV_JUMP
);
1245 reg_scan (insns
, max_reg_num (), 0);
1246 close_dump_file (DFI_cse2
, print_rtl_with_bb
, insns
);
1248 timevar_pop (TV_CSE2
);
1251 /* Perform global cse. */
1253 rest_of_handle_gcse (tree decl
, rtx insns
)
1255 int save_csb
, save_cfj
;
1257 if (decl
!= current_function_decl
|| insns
!= get_insns ())
1260 timevar_push (TV_GCSE
);
1261 open_dump_file (DFI_gcse
, decl
);
1263 tem
= gcse_main (insns
, dump_file
);
1264 rebuild_jump_labels (insns
);
1265 delete_trivially_dead_insns (insns
, max_reg_num ());
1267 save_csb
= flag_cse_skip_blocks
;
1268 save_cfj
= flag_cse_follow_jumps
;
1269 flag_cse_skip_blocks
= flag_cse_follow_jumps
= 0;
1271 /* If -fexpensive-optimizations, re-run CSE to clean up things done
1273 if (flag_expensive_optimizations
)
1275 timevar_push (TV_CSE
);
1276 reg_scan (insns
, max_reg_num (), 1);
1277 tem2
= cse_main (insns
, max_reg_num (), 0, dump_file
);
1278 purge_all_dead_edges (0);
1279 delete_trivially_dead_insns (insns
, max_reg_num ());
1280 timevar_pop (TV_CSE
);
1281 cse_not_expected
= !flag_rerun_cse_after_loop
;
1284 /* If gcse or cse altered any jumps, rerun jump optimizations to clean
1285 things up. Then possibly re-run CSE again. */
1289 timevar_push (TV_JUMP
);
1290 rebuild_jump_labels (insns
);
1291 cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_PRE_LOOP
);
1292 timevar_pop (TV_JUMP
);
1294 if (flag_expensive_optimizations
)
1296 timevar_push (TV_CSE
);
1297 reg_scan (insns
, max_reg_num (), 1);
1298 tem2
= cse_main (insns
, max_reg_num (), 0, dump_file
);
1299 purge_all_dead_edges (0);
1300 delete_trivially_dead_insns (insns
, max_reg_num ());
1301 timevar_pop (TV_CSE
);
1305 close_dump_file (DFI_gcse
, print_rtl_with_bb
, insns
);
1306 timevar_pop (TV_GCSE
);
1309 flag_cse_skip_blocks
= save_csb
;
1310 flag_cse_follow_jumps
= save_cfj
;
1311 #ifdef ENABLE_CHECKING
1312 verify_flow_info ();
1316 /* Move constant computations out of loops. */
1318 rest_of_handle_loop_optimize (tree decl
, rtx insns
)
1320 int do_unroll
, do_prefetch
;
1322 if (decl
!= current_function_decl
|| insns
!= get_insns ())
1325 timevar_push (TV_LOOP
);
1326 delete_dead_jumptables ();
1327 cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_PRE_LOOP
);
1328 open_dump_file (DFI_loop
, decl
);
1330 /* CFG is no longer maintained up-to-date. */
1331 free_bb_for_insn ();
1333 if (flag_unroll_loops
)
1334 do_unroll
= LOOP_AUTO_UNROLL
; /* Having two unrollers is useless. */
1336 do_unroll
= flag_old_unroll_loops
? LOOP_UNROLL
: LOOP_AUTO_UNROLL
;
1337 do_prefetch
= flag_prefetch_loop_arrays
? LOOP_PREFETCH
: 0;
1339 if (flag_rerun_loop_opt
)
1341 cleanup_barriers ();
1343 /* We only want to perform unrolling once. */
1344 loop_optimize (insns
, dump_file
, do_unroll
);
1347 /* The first call to loop_optimize makes some instructions
1348 trivially dead. We delete those instructions now in the
1349 hope that doing so will make the heuristics in loop work
1350 better and possibly speed up compilation. */
1351 delete_trivially_dead_insns (insns
, max_reg_num ());
1353 /* The regscan pass is currently necessary as the alias
1354 analysis code depends on this information. */
1355 reg_scan (insns
, max_reg_num (), 1);
1357 cleanup_barriers ();
1358 loop_optimize (insns
, dump_file
, do_unroll
| do_prefetch
);
1360 /* Loop can create trivially dead instructions. */
1361 delete_trivially_dead_insns (insns
, max_reg_num ());
1362 close_dump_file (DFI_loop
, print_rtl
, insns
);
1363 timevar_pop (TV_LOOP
);
1364 find_basic_blocks (insns
, max_reg_num (), dump_file
);
1369 /* Perform loop optimizations. It might be better to do them a bit
1370 sooner, but we want the profile feedback to work more
1373 rest_of_handle_loop2 (tree decl
, rtx insns
)
1375 struct loops
*loops
;
1378 if (decl
!= current_function_decl
|| insns
!= get_insns ())
1381 if (!flag_unswitch_loops
1383 && !flag_unroll_loops
1384 && !flag_branch_on_count_reg
)
1387 timevar_push (TV_LOOP
);
1388 open_dump_file (DFI_loop2
, decl
);
1390 dump_flow_info (dump_file
);
1392 /* Initialize structures for layout changes. */
1393 cfg_layout_initialize ();
1395 loops
= loop_optimizer_init (dump_file
);
1399 /* The optimizations: */
1400 if (flag_unswitch_loops
)
1401 unswitch_loops (loops
);
1403 if (flag_peel_loops
|| flag_unroll_loops
)
1404 unroll_and_peel_loops (loops
,
1405 (flag_peel_loops
? UAP_PEEL
: 0) |
1406 (flag_unroll_loops
? UAP_UNROLL
: 0) |
1407 (flag_unroll_all_loops
? UAP_UNROLL_ALL
: 0));
1409 #ifdef HAVE_doloop_end
1410 if (flag_branch_on_count_reg
&& HAVE_doloop_end
)
1411 doloop_optimize_loops (loops
);
1412 #endif /* HAVE_doloop_end */
1414 loop_optimizer_finalize (loops
, dump_file
);
1417 /* Finalize layout changes. */
1419 if (bb
->next_bb
!= EXIT_BLOCK_PTR
)
1420 bb
->rbi
->next
= bb
->next_bb
;
1421 cfg_layout_finalize ();
1423 cleanup_cfg (CLEANUP_EXPENSIVE
);
1424 delete_trivially_dead_insns (insns
, max_reg_num ());
1425 reg_scan (insns
, max_reg_num (), 0);
1427 dump_flow_info (dump_file
);
1428 close_dump_file (DFI_loop2
, print_rtl_with_bb
, get_insns ());
1429 timevar_pop (TV_LOOP
);
1433 /* This is called from finish_function (within langhooks.parse_file)
1434 after each top-level definition is parsed.
1435 It is supposed to compile that function or variable
1436 and output the assembler code for it.
1437 After we return, the tree storage is freed. */
1440 rest_of_compilation (void)
1442 tree decl
= current_function_decl
;
1446 /* There's no need to defer outputting this function any more; we
1447 know we want to output it. */
1448 DECL_DEFER_OUTPUT (current_function_decl
) = 0;
1450 /* There's no need to defer outputting this function any more; we
1451 know we want to output it. */
1452 DECL_DEFER_OUTPUT (current_function_decl
) = 0;
1454 /* Register rtl specific functions for cfg. */
1455 rtl_register_cfg_hooks ();
1457 /* Now that we're out of the frontend, we shouldn't have any more
1458 CONCATs anywhere. */
1459 generating_concat_p
= 0;
1461 /* When processing delayed functions, prepare_function_start() won't
1462 have been run to re-initialize it. */
1463 cse_not_expected
= ! optimize
;
1465 if (!cfun
->dont_emit_block_notes
)
1467 /* First, make sure that NOTE_BLOCK is set correctly for each
1468 NOTE_INSN_BLOCK_BEG/NOTE_INSN_BLOCK_END note. */
1469 if (!cfun
->x_whole_function_mode_p
)
1472 /* In function-at-a-time mode, we do not attempt to keep the BLOCK
1473 tree in sensible shape. So, we just recalculate it here. */
1474 if (cfun
->x_whole_function_mode_p
)
1478 finalize_block_changes ();
1482 /* Dump the rtl code if we are dumping rtl. */
1483 if (open_dump_file (DFI_rtl
, decl
))
1484 close_dump_file (DFI_rtl
, print_rtl
, get_insns ());
1486 /* Convert from NOTE_INSN_EH_REGION style notes, and do other
1487 sorts of eh initialization. Delay this until after the
1488 initial rtl dump so that we can see the original nesting. */
1489 convert_from_eh_region_ranges ();
1491 /* If we're emitting a nested function, make sure its parent gets
1492 emitted as well. Doing otherwise confuses debug info. */
1495 for (parent
= DECL_CONTEXT (current_function_decl
);
1496 parent
!= NULL_TREE
;
1497 parent
= get_containing_scope (parent
))
1498 if (TREE_CODE (parent
) == FUNCTION_DECL
)
1499 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (parent
)) = 1;
1502 /* We are now committed to emitting code for this function. Do any
1503 preparation, such as emitting abstract debug info for the inline
1504 before it gets mangled by optimization. */
1505 if (cgraph_function_possibly_inlined_p (decl
))
1506 (*debug_hooks
->outlining_inline_function
) (decl
);
1508 /* Remove any notes we don't need. That will make iterating
1509 over the instruction sequence faster, and allow the garbage
1510 collector to reclaim the memory used by the notes. */
1511 remove_unnecessary_notes ();
1512 if (!cfun
->dont_emit_block_notes
)
1517 /* Initialize some variables used by the optimizers. */
1518 init_function_for_compilation ();
1520 TREE_ASM_WRITTEN (decl
) = 1;
1522 /* Now that integrate will no longer see our rtl, we need not
1523 distinguish between the return value of this function and the
1524 return value of called functions. Also, we can remove all SETs
1525 of subregs of hard registers; they are only here because of
1526 integrate. Also, we can now initialize pseudos intended to
1527 carry magic hard reg data throughout the function. */
1528 rtx_equal_function_value_matters
= 0;
1529 purge_hard_subreg_sets (get_insns ());
1531 /* Early return if there were errors. We can run afoul of our
1532 consistency checks, and there's not really much point in fixing them. */
1533 if (rtl_dump_and_exit
|| flag_syntax_only
|| errorcount
|| sorrycount
)
1534 goto exit_rest_of_compilation
;
1536 timevar_push (TV_JUMP
);
1537 open_dump_file (DFI_sibling
, decl
);
1538 insns
= get_insns ();
1539 rebuild_jump_labels (insns
);
1540 find_exception_handler_labels ();
1541 find_basic_blocks (insns
, max_reg_num (), dump_file
);
1543 delete_unreachable_blocks ();
1545 /* Turn NOTE_INSN_PREDICTIONs into branch predictions. */
1546 if (flag_guess_branch_prob
)
1548 timevar_push (TV_BRANCH_PROB
);
1549 note_prediction_to_br_prob ();
1550 timevar_pop (TV_BRANCH_PROB
);
1553 timevar_pop (TV_JUMP
);
1555 if (cfun
->tail_call_emit
)
1556 fixup_tail_calls ();
1558 insn_locators_initialize ();
1559 /* Complete generation of exception handling code. */
1562 timevar_push (TV_JUMP
);
1563 open_dump_file (DFI_eh
, decl
);
1565 finish_eh_generation ();
1567 close_dump_file (DFI_eh
, print_rtl
, get_insns ());
1568 timevar_pop (TV_JUMP
);
1571 /* Delay emitting hard_reg_initial_value sets until after EH landing pad
1572 generation, which might create new sets. */
1573 emit_initial_value_sets ();
1576 /* If we are doing position-independent code generation, now
1577 is the time to output special prologues and epilogues.
1578 We do not want to do this earlier, because it just clutters
1579 up inline functions with meaningless insns. */
1584 insns
= get_insns ();
1586 /* Copy any shared structure that should not be shared. */
1587 unshare_all_rtl (current_function_decl
, insns
);
1589 #ifdef SETJMP_VIA_SAVE_AREA
1590 /* This must be performed before virtual register instantiation.
1591 Please be aware that everything in the compiler that can look
1592 at the RTL up to this point must understand that REG_SAVE_AREA
1593 is just like a use of the REG contained inside. */
1594 if (current_function_calls_alloca
)
1595 optimize_save_area_alloca (insns
);
1598 /* Instantiate all virtual registers. */
1599 instantiate_virtual_regs (current_function_decl
, insns
);
1601 open_dump_file (DFI_jump
, decl
);
1603 /* Always do one jump optimization pass to ensure that JUMP_LABEL fields
1604 are initialized and to compute whether control can drop off the end
1607 timevar_push (TV_JUMP
);
1608 /* Turn NOTE_INSN_EXPECTED_VALUE into REG_BR_PROB. Do this
1609 before jump optimization switches branch directions. */
1610 if (flag_guess_branch_prob
)
1611 expected_value_to_br_prob ();
1613 reg_scan (insns
, max_reg_num (), 0);
1614 rebuild_jump_labels (insns
);
1615 find_basic_blocks (insns
, max_reg_num (), dump_file
);
1616 delete_trivially_dead_insns (insns
, max_reg_num ());
1618 dump_flow_info (dump_file
);
1619 cleanup_cfg ((optimize
? CLEANUP_EXPENSIVE
: 0) | CLEANUP_PRE_LOOP
1620 | (flag_thread_jumps
? CLEANUP_THREADING
: 0));
1622 create_loop_notes ();
1624 purge_line_number_notes (insns
);
1626 close_dump_file (DFI_jump
, print_rtl
, insns
);
1629 cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_PRE_LOOP
);
1631 /* Jump optimization, and the removal of NULL pointer checks, may
1632 have reduced the number of instructions substantially. CSE, and
1633 future passes, allocate arrays whose dimensions involve the
1634 maximum instruction UID, so if we can reduce the maximum UID
1635 we'll save big on memory. */
1636 renumber_insns (dump_file
);
1637 timevar_pop (TV_JUMP
);
1639 close_dump_file (DFI_jump
, print_rtl_with_bb
, insns
);
1644 rest_of_handle_cse (decl
, insns
);
1646 rest_of_handle_addressof (decl
, insns
);
1653 rest_of_handle_gcse (decl
, insns
);
1655 if (flag_loop_optimize
)
1656 rest_of_handle_loop_optimize (decl
, insns
);
1659 rest_of_handle_jump_bypass (decl
, insns
);
1662 timevar_push (TV_FLOW
);
1664 rest_of_handle_cfg (decl
, insns
);
1666 if (!flag_tree_based_profiling
1667 && (optimize
> 0 || profile_arc_flag
1668 || flag_test_coverage
|| flag_branch_probabilities
))
1670 rtl_register_profile_hooks ();
1671 rtl_register_value_prof_hooks ();
1672 rest_of_handle_branch_prob (decl
, insns
);
1674 if (flag_branch_probabilities
1675 && flag_profile_values
1676 && flag_value_profile_transformations
)
1677 rest_of_handle_value_profile_transformations (decl
, insns
);
1679 /* Remove the death notes created for vpt. */
1680 if (flag_profile_values
)
1681 count_or_remove_death_notes (NULL
, 1);
1685 rest_of_handle_if_conversion (decl
, insns
);
1688 rest_of_handle_tracer (decl
, insns
);
1691 rest_of_handle_loop2 (decl
, insns
);
1694 rest_of_handle_web (decl
, insns
);
1696 if (flag_rerun_cse_after_loop
)
1697 rest_of_handle_cse2 (decl
, insns
);
1699 cse_not_expected
= 1;
1701 rest_of_handle_life (decl
, insns
);
1704 rest_of_handle_combine (decl
, insns
);
1706 if (flag_if_conversion
)
1707 rest_of_handle_if_after_combine (decl
, insns
);
1709 /* The optimization to partition hot/cold basic blocks into separate
1710 sections of the .o file does not work well with exception handling.
1711 Don't call it if there are exceptions. */
1713 if (flag_reorder_blocks_and_partition
&& !flag_exceptions
)
1716 partition_hot_cold_basic_blocks ();
1717 allocate_reg_life_data ();
1718 update_life_info (NULL
, UPDATE_LIFE_GLOBAL_RM_NOTES
,
1719 PROP_LOG_LINKS
| PROP_REG_INFO
| PROP_DEATH_NOTES
);
1723 if (optimize
> 0 && (flag_regmove
|| flag_expensive_optimizations
))
1724 rest_of_handle_regmove (decl
, insns
);
1726 /* Do unconditional splitting before register allocation to allow machine
1727 description to add extra information not needed previously. */
1728 split_all_insns (1);
1730 #ifdef OPTIMIZE_MODE_SWITCHING
1731 timevar_push (TV_MODE_SWITCH
);
1734 optimize_mode_switching (NULL
);
1737 timevar_pop (TV_MODE_SWITCH
);
1740 /* Any of the several passes since flow1 will have munged register
1741 lifetime data a bit. We need it to be up to date for scheduling
1742 (see handling of reg_known_equiv in init_alias_analysis). */
1743 recompute_reg_usage (insns
, !optimize_size
);
1745 #ifdef INSN_SCHEDULING
1746 rest_of_handle_sched (decl
, insns
);
1749 /* Determine if the current function is a leaf before running reload
1750 since this can impact optimizations done by the prologue and
1751 epilogue thus changing register elimination offsets. */
1752 current_function_is_leaf
= leaf_function_p ();
1754 timevar_push (TV_LOCAL_ALLOC
);
1755 open_dump_file (DFI_lreg
, decl
);
1757 if (flag_new_regalloc
)
1759 if (rest_of_handle_new_regalloc (decl
, insns
))
1760 goto exit_rest_of_compilation
;
1764 if (rest_of_handle_old_regalloc (decl
, insns
))
1765 goto exit_rest_of_compilation
;
1770 open_dump_file (DFI_postreload
, decl
);
1772 /* Do a very simple CSE pass over just the hard registers. */
1775 timevar_push (TV_RELOAD_CSE_REGS
);
1776 reload_cse_regs (insns
);
1777 /* reload_cse_regs can eliminate potentially-trapping MEMs.
1778 Remove any EH edges associated with them. */
1779 if (flag_non_call_exceptions
)
1780 purge_all_dead_edges (0);
1781 timevar_pop (TV_RELOAD_CSE_REGS
);
1784 close_dump_file (DFI_postreload
, print_rtl_with_bb
, insns
);
1786 if (optimize
> 0 && flag_gcse_after_reload
)
1787 rest_of_handle_gcse2 (decl
, insns
);
1789 /* Re-create the death notes which were deleted during reload. */
1790 timevar_push (TV_FLOW2
);
1791 open_dump_file (DFI_flow2
, decl
);
1793 #ifdef ENABLE_CHECKING
1794 verify_flow_info ();
1797 /* If optimizing, then go ahead and split insns now. */
1801 split_all_insns (0);
1803 if (flag_branch_target_load_optimize
)
1805 open_dump_file (DFI_branch_target_load
, decl
);
1807 branch_target_load_optimize (/*after_prologue_epilogue_gen=*/false);
1809 close_dump_file (DFI_branch_target_load
, print_rtl_with_bb
, insns
);
1815 cleanup_cfg (CLEANUP_EXPENSIVE
);
1817 /* On some machines, the prologue and epilogue code, or parts thereof,
1818 can be represented as RTL. Doing so lets us schedule insns between
1819 it and the rest of the code and also allows delayed branch
1820 scheduling to operate in the epilogue. */
1821 thread_prologue_and_epilogue_insns (insns
);
1822 epilogue_completed
= 1;
1826 life_analysis (dump_file
, PROP_POSTRELOAD
);
1827 cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_UPDATE_LIFE
1828 | (flag_crossjumping
? CLEANUP_CROSSJUMP
: 0));
1830 /* This is kind of a heuristic. We need to run combine_stack_adjustments
1831 even for machines with possibly nonzero RETURN_POPS_ARGS
1832 and ACCUMULATE_OUTGOING_ARGS. We expect that only ports having
1833 push instructions will have popping returns. */
1834 #ifndef PUSH_ROUNDING
1835 if (!ACCUMULATE_OUTGOING_ARGS
)
1837 combine_stack_adjustments ();
1842 flow2_completed
= 1;
1844 close_dump_file (DFI_flow2
, print_rtl_with_bb
, insns
);
1845 timevar_pop (TV_FLOW2
);
1847 #ifdef HAVE_peephole2
1848 if (optimize
> 0 && flag_peephole2
)
1850 timevar_push (TV_PEEPHOLE2
);
1851 open_dump_file (DFI_peephole2
, decl
);
1853 peephole2_optimize (dump_file
);
1855 close_dump_file (DFI_peephole2
, print_rtl_with_bb
, insns
);
1856 timevar_pop (TV_PEEPHOLE2
);
1860 open_dump_file (DFI_ce3
, decl
);
1862 /* Last attempt to optimize CFG, as scheduling, peepholing and insn
1863 splitting possibly introduced more crossjumping opportunities. */
1864 cleanup_cfg (CLEANUP_EXPENSIVE
1865 | CLEANUP_UPDATE_LIFE
1866 | (flag_crossjumping
? CLEANUP_CROSSJUMP
: 0));
1867 if (flag_if_conversion2
)
1869 timevar_push (TV_IFCVT2
);
1873 timevar_pop (TV_IFCVT2
);
1875 close_dump_file (DFI_ce3
, print_rtl_with_bb
, insns
);
1879 if (flag_rename_registers
|| flag_cprop_registers
)
1880 rest_of_handle_regrename (decl
, insns
);
1882 rest_of_handle_reorder_blocks (decl
, insns
);
1885 if (flag_branch_target_load_optimize2
)
1887 /* Leave this a warning for now so that it is possible to experiment
1888 with running this pass twice. In 3.6, we should either make this
1889 an error, or use separate dump files. */
1890 if (flag_branch_target_load_optimize
)
1891 warning ("branch target register load optimization is not intended "
1894 open_dump_file (DFI_branch_target_load
, decl
);
1896 branch_target_load_optimize (/*after_prologue_epilogue_gen=*/true);
1898 close_dump_file (DFI_branch_target_load
, print_rtl_with_bb
, insns
);
1903 #ifdef INSN_SCHEDULING
1904 if (optimize
> 0 && flag_schedule_insns_after_reload
)
1905 rest_of_handle_sched2 (decl
, insns
);
1908 #ifdef LEAF_REGISTERS
1909 current_function_uses_only_leaf_regs
1910 = optimize
> 0 && only_leaf_regs_used () && leaf_function_p ();
1914 rest_of_handle_stack_regs (decl
, insns
);
1917 compute_alignments ();
1919 if (flag_var_tracking
)
1920 rest_of_handle_variable_tracking (decl
, insns
);
1922 /* CFG is no longer maintained up-to-date. */
1923 free_bb_for_insn ();
1925 if (targetm
.machine_dependent_reorg
!= 0)
1926 rest_of_handle_machine_reorg (decl
, insns
);
1928 purge_line_number_notes (insns
);
1929 cleanup_barriers ();
1932 if (optimize
> 0 && flag_delayed_branch
)
1933 rest_of_handle_delay_slots (decl
, insns
);
1936 #if defined (HAVE_ATTR_length) && !defined (STACK_REGS)
1937 timevar_push (TV_SHORTEN_BRANCH
);
1938 split_all_insns_noflow ();
1939 timevar_pop (TV_SHORTEN_BRANCH
);
1942 convert_to_eh_region_ranges ();
1944 /* Shorten branches. */
1945 timevar_push (TV_SHORTEN_BRANCH
);
1946 shorten_branches (get_insns ());
1947 timevar_pop (TV_SHORTEN_BRANCH
);
1949 set_nothrow_function_flags ();
1950 if (current_function_nothrow
)
1951 /* Now we know that this can't throw; set the flag for the benefit
1952 of other functions later in this translation unit. */
1953 TREE_NOTHROW (current_function_decl
) = 1;
1955 rest_of_handle_final (decl
, insns
);
1957 /* Write DBX symbols if requested. */
1959 /* Note that for those inline functions where we don't initially
1960 know for certain that we will be generating an out-of-line copy,
1961 the first invocation of this routine (rest_of_compilation) will
1962 skip over this code by doing a `goto exit_rest_of_compilation;'.
1963 Later on, wrapup_global_declarations will (indirectly) call
1964 rest_of_compilation again for those inline functions that need
1965 to have out-of-line copies generated. During that call, we
1966 *will* be routed past here. */
1968 timevar_push (TV_SYMOUT
);
1969 (*debug_hooks
->function_decl
) (decl
);
1970 timevar_pop (TV_SYMOUT
);
1972 exit_rest_of_compilation
:
1974 coverage_end_function ();
1976 /* In case the function was not output,
1977 don't leave any temporary anonymous types
1978 queued up for sdb output. */
1979 #ifdef SDB_DEBUGGING_INFO
1980 if (write_symbols
== SDB_DEBUG
)
1981 sdbout_types (NULL_TREE
);
1984 reload_completed
= 0;
1985 epilogue_completed
= 0;
1986 flow2_completed
= 0;
1989 timevar_push (TV_FINAL
);
1991 /* Clear out the insn_length contents now that they are no
1993 init_insn_lengths ();
1995 /* Show no temporary slots allocated. */
1998 free_basic_block_vars ();
1999 free_bb_for_insn ();
2001 timevar_pop (TV_FINAL
);
2003 if (targetm
.binds_local_p (current_function_decl
))
2005 int pref
= cfun
->preferred_stack_boundary
;
2006 if (cfun
->recursive_call_emit
2007 && cfun
->stack_alignment_needed
> cfun
->preferred_stack_boundary
)
2008 pref
= cfun
->stack_alignment_needed
;
2009 cgraph_rtl_info (current_function_decl
)->preferred_incoming_stack_boundary
2013 /* Make sure volatile mem refs aren't considered valid operands for
2014 arithmetic insns. We must call this here if this is a nested inline
2015 function, since the above code leaves us in the init_recog state
2016 (from final.c), and the function context push/pop code does not
2017 save/restore volatile_ok.
2019 ??? Maybe it isn't necessary for expand_start_function to call this
2020 anymore if we do it here? */
2022 init_recog_no_volatile ();
2024 /* We're done with this function. Free up memory if we can. */
2025 free_after_parsing (cfun
);
2029 init_optimization_passes (void)
2031 open_dump_file (DFI_cgraph
, NULL
);
2032 cgraph_dump_file
= dump_file
;
2037 finish_optimization_passes (void)
2039 if (profile_arc_flag
|| flag_test_coverage
|| flag_branch_probabilities
)
2041 timevar_push (TV_DUMP
);
2042 open_dump_file (DFI_bp
, NULL
);
2046 close_dump_file (DFI_bp
, NULL
, NULL_RTX
);
2047 timevar_pop (TV_DUMP
);
2050 if (optimize
> 0 && open_dump_file (DFI_combine
, NULL
))
2052 timevar_push (TV_DUMP
);
2053 dump_combine_total_stats (dump_file
);
2054 close_dump_file (DFI_combine
, NULL
, NULL_RTX
);
2055 timevar_pop (TV_DUMP
);
2058 dump_file
= cgraph_dump_file
;
2059 cgraph_dump_file
= NULL
;
2060 close_dump_file (DFI_cgraph
, NULL
, NULL_RTX
);
2062 /* Do whatever is necessary to finish printing the graphs. */
2063 if (graph_dump_format
!= no_graph
)
2067 for (i
= 0; i
< (int) DFI_MAX
; ++i
)
2068 if (dump_file_tbl
[i
].initialized
&& dump_file_tbl
[i
].graph_dump_p
)
2073 sprintf (seq
, DUMPFILE_FORMAT
, i
);
2074 suffix
= concat (seq
, dump_file_tbl
[i
].extension
, NULL
);
2075 finish_graph_dump_file (dump_base_name
, suffix
);
2083 enable_rtl_dump_file (int letter
)
2085 bool matched
= false;
2090 for (i
= 0; i
< (int) DFI_MAX
; ++i
)
2091 dump_file_tbl
[i
].enabled
= 1;
2096 for (i
= 0; i
< (int) DFI_MAX
; ++i
)
2097 if (letter
== dump_file_tbl
[i
].debug_switch
)
2099 dump_file_tbl
[i
].enabled
= 1;
2107 struct tree_opt_pass pass_rest_of_compilation
=
2109 "rest of compilation", /* name */
2111 rest_of_compilation
, /* execute */
2114 0, /* static_pass_number */
2115 TV_REST_OF_COMPILATION
, /* tv_id */
2116 PROP_rtl
, /* properties_required */
2117 0, /* properties_provided */
2118 PROP_rtl
, /* properties_destroyed */
2119 0, /* todo_flags_start */
2120 TODO_ggc_collect
/* todo_flags_finish */