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"
84 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
85 #include "dwarf2out.h"
88 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
92 #ifdef SDB_DEBUGGING_INFO
96 #ifdef XCOFF_DEBUGGING_INFO
97 #include "xcoffout.h" /* Needed for external data
98 declarations for e.g. AIX 4.x. */
101 #ifndef HAVE_conditional_execution
102 #define HAVE_conditional_execution 0
105 /* Format to use to print dumpfile index value */
106 #ifndef DUMPFILE_FORMAT
107 #define DUMPFILE_FORMAT ".%02d."
110 /* Describes a dump file. */
112 struct dump_file_info
114 /* The unique extension to apply, e.g. ".jump". */
115 const char *const extension
;
117 /* The -d<c> character that enables this dump file. */
118 char const debug_switch
;
120 /* True if there is a corresponding graph dump file. */
121 char const graph_dump_p
;
123 /* True if the user selected this dump. */
126 /* True if the files have been initialized (ie truncated). */
130 /* Enumerate the extant dump files. */
167 DFI_branch_target_load
,
176 /* Describes all the dump files. Should be kept in order of the
177 pass and in sync with dump_file_index above.
179 Remaining -d letters:
185 static struct dump_file_info dump_file_tbl
[DFI_MAX
] =
187 { "cgraph", 'U', 0, 0, 0 },
188 { "rtl", 'r', 0, 0, 0 },
189 { "sibling", 'i', 0, 0, 0 },
190 { "eh", 'h', 0, 0, 0 },
191 { "jump", 'j', 0, 0, 0 },
192 { "null", 'u', 0, 0, 0 },
193 { "cse", 's', 0, 0, 0 },
194 { "addressof", 'F', 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 { "sched", 'S', 1, 0, 0 },
211 { "lreg", 'l', 1, 0, 0 },
212 { "greg", 'g', 1, 0, 0 },
213 { "postreload", 'o', 1, 0, 0 },
214 { "gcse2", 'J', 0, 0, 0 },
215 { "flow2", 'w', 1, 0, 0 },
216 { "peephole2", 'z', 1, 0, 0 },
217 { "ce3", 'E', 1, 0, 0 },
218 { "rnreg", 'n', 1, 0, 0 },
219 { "bbro", 'B', 1, 0, 0 },
220 { "btl", 'd', 1, 0, 0 }, /* Yes, duplicate enable switch. */
221 { "sched2", 'R', 1, 0, 0 },
222 { "stack", 'k', 1, 0, 0 },
223 { "vartrack", 'V', 1, 0, 0 }, /* Yes, duplicate enable switch. */
224 { "mach", 'M', 1, 0, 0 },
225 { "dbr", 'd', 0, 0, 0 },
228 /* Routine to open a dump file. Return true if the dump file is enabled. */
231 open_dump_file (enum dump_file_index index
, tree decl
)
234 const char *open_arg
;
237 if (! dump_file_tbl
[index
].enabled
)
240 timevar_push (TV_DUMP
);
241 if (dump_file
!= NULL
)
244 sprintf (seq
, DUMPFILE_FORMAT
, index
);
246 if (! dump_file_tbl
[index
].initialized
)
248 /* If we've not initialized the files, do so now. */
249 if (graph_dump_format
!= no_graph
250 && dump_file_tbl
[index
].graph_dump_p
)
252 dump_name
= concat (seq
, dump_file_tbl
[index
].extension
, NULL
);
253 clean_graph_dump_file (dump_base_name
, dump_name
);
256 dump_file_tbl
[index
].initialized
= 1;
262 dump_name
= concat (dump_base_name
, seq
,
263 dump_file_tbl
[index
].extension
, NULL
);
265 dump_file
= fopen (dump_name
, open_arg
);
266 if (dump_file
== NULL
)
267 fatal_error ("can't open %s: %m", dump_name
);
272 fprintf (dump_file
, "\n;; Function %s%s\n\n",
273 lang_hooks
.decl_printable_name (decl
, 2),
274 cfun
->function_frequency
== FUNCTION_FREQUENCY_HOT
276 : cfun
->function_frequency
== FUNCTION_FREQUENCY_UNLIKELY_EXECUTED
277 ? " (unlikely executed)"
280 timevar_pop (TV_DUMP
);
284 /* Routine to close a dump file. */
287 close_dump_file (enum dump_file_index index
,
288 void (*func
) (FILE *, rtx
),
294 timevar_push (TV_DUMP
);
296 && graph_dump_format
!= no_graph
297 && dump_file_tbl
[index
].graph_dump_p
)
302 sprintf (seq
, DUMPFILE_FORMAT
, index
);
303 suffix
= concat (seq
, dump_file_tbl
[index
].extension
, NULL
);
304 print_rtl_graph_with_bb (dump_base_name
, suffix
, insns
);
309 func (dump_file
, insns
);
315 timevar_pop (TV_DUMP
);
318 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
321 This does nothing for local (non-static) variables, unless the
322 variable is a register variable with an ASMSPEC. In that case, or
323 if the variable is not an automatic, it sets up the RTL and
324 outputs any assembler code (label definition, storage allocation
327 DECL is the declaration. If ASMSPEC is nonzero, it specifies
328 the assembler symbol name to be used. TOP_LEVEL is nonzero
329 if this declaration is not within a function. */
332 rest_of_decl_compilation (tree decl
,
337 /* We deferred calling assemble_alias so that we could collect
338 other attributes such as visibility. Emit the alias now. */
341 alias
= lookup_attribute ("alias", DECL_ATTRIBUTES (decl
));
344 alias
= TREE_VALUE (TREE_VALUE (alias
));
345 alias
= get_identifier (TREE_STRING_POINTER (alias
));
346 assemble_alias (decl
, alias
);
350 /* Forward declarations for nested functions are not "external",
351 but we need to treat them as if they were. */
352 if (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)
353 || TREE_CODE (decl
) == FUNCTION_DECL
)
355 timevar_push (TV_VARCONST
);
358 make_decl_rtl (decl
, asmspec
);
360 /* Don't output anything when a tentative file-scope definition
361 is seen. But at end of compilation, do output code for them.
363 We do output all variables when unit-at-a-time is active and rely on
364 callgraph code to defer them except for forward declarations
365 (see gcc.c-torture/compile/920624-1.c) */
367 || !DECL_DEFER_OUTPUT (decl
)
368 || (flag_unit_at_a_time
&& DECL_INITIAL (decl
)))
369 && !DECL_EXTERNAL (decl
))
371 if (flag_unit_at_a_time
&& !cgraph_global_info_ready
372 && TREE_CODE (decl
) != FUNCTION_DECL
&& top_level
)
373 cgraph_varpool_finalize_decl (decl
);
375 assemble_variable (decl
, top_level
, at_end
, 0);
378 #ifdef ASM_FINISH_DECLARE_OBJECT
379 if (decl
== last_assemble_variable_decl
)
381 ASM_FINISH_DECLARE_OBJECT (asm_out_file
, decl
,
386 timevar_pop (TV_VARCONST
);
388 else if (DECL_REGISTER (decl
) && asmspec
!= 0)
390 if (decode_reg_name (asmspec
) >= 0)
392 SET_DECL_RTL (decl
, NULL_RTX
);
393 make_decl_rtl (decl
, asmspec
);
397 error ("%Hinvalid register name `%s' for register variable",
398 &DECL_SOURCE_LOCATION (decl
), asmspec
);
399 DECL_REGISTER (decl
) = 0;
404 else if (TREE_CODE (decl
) == TYPE_DECL
)
406 timevar_push (TV_SYMOUT
);
407 debug_hooks
->type_decl (decl
, !top_level
);
408 timevar_pop (TV_SYMOUT
);
412 /* Called after finishing a record, union or enumeral type. */
415 rest_of_type_compilation (tree type
, int toplev
)
417 /* Avoid confusing the debug information machinery when there are
419 if (errorcount
!= 0 || sorrycount
!= 0)
422 timevar_push (TV_SYMOUT
);
423 debug_hooks
->type_decl (TYPE_STUB_DECL (type
), !toplev
);
424 timevar_pop (TV_SYMOUT
);
427 /* Turn the RTL into assembly. */
429 rest_of_handle_final (tree decl
, rtx insns
)
431 timevar_push (TV_FINAL
);
436 /* Get the function's name, as described by its RTL. This may be
437 different from the DECL_NAME name used in the source file. */
440 if (GET_CODE (x
) != MEM
)
443 if (GET_CODE (x
) != SYMBOL_REF
)
445 fnname
= XSTR (x
, 0);
447 assemble_start_function (decl
, fnname
);
448 final_start_function (insns
, asm_out_file
, optimize
);
449 final (insns
, asm_out_file
, optimize
, 0);
450 final_end_function ();
452 #ifdef IA64_UNWIND_INFO
453 /* ??? The IA-64 ".handlerdata" directive must be issued before
454 the ".endp" directive that closes the procedure descriptor. */
455 output_function_exception_table ();
458 assemble_end_function (decl
, fnname
);
460 #ifndef IA64_UNWIND_INFO
461 /* Otherwise, it feels unclean to switch sections in the middle. */
462 output_function_exception_table ();
466 fflush (asm_out_file
);
468 /* Release all memory allocated by flow. */
469 free_basic_block_vars ();
471 /* Release all memory held by regsets now. */
472 regset_release_memory ();
474 timevar_pop (TV_FINAL
);
480 /* Run delay slot optimization. */
482 rest_of_handle_delay_slots (tree decl
, rtx insns
)
484 timevar_push (TV_DBR_SCHED
);
485 open_dump_file (DFI_dbr
, decl
);
487 dbr_schedule (insns
, dump_file
);
489 close_dump_file (DFI_dbr
, print_rtl
, insns
);
490 timevar_pop (TV_DBR_SCHED
);
497 /* Convert register usage from flat register file usage to a stack
500 rest_of_handle_stack_regs (tree decl
, rtx insns
)
502 #if defined (HAVE_ATTR_length)
503 /* If flow2 creates new instructions which need splitting
504 and scheduling after reload is not done, they might not be
505 split until final which doesn't allow splitting
506 if HAVE_ATTR_length. */
507 #ifdef INSN_SCHEDULING
508 if (optimize
&& !flag_schedule_insns_after_reload
)
513 timevar_push (TV_SHORTEN_BRANCH
);
515 timevar_pop (TV_SHORTEN_BRANCH
);
519 timevar_push (TV_REG_STACK
);
520 open_dump_file (DFI_stack
, decl
);
522 if (reg_to_stack (insns
, dump_file
) && optimize
)
524 if (cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_POST_REGSTACK
525 | (flag_crossjumping
? CLEANUP_CROSSJUMP
: 0))
526 && (flag_reorder_blocks
|| flag_reorder_blocks_and_partition
))
528 reorder_basic_blocks ();
529 cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_POST_REGSTACK
);
533 close_dump_file (DFI_stack
, print_rtl_with_bb
, insns
);
534 timevar_pop (TV_REG_STACK
);
540 /* Track the variables, ie. compute where the variable is stored at each position in function. */
542 rest_of_handle_variable_tracking (tree decl
, rtx insns
)
544 timevar_push (TV_VAR_TRACKING
);
545 open_dump_file (DFI_vartrack
, decl
);
547 variable_tracking_main ();
549 close_dump_file (DFI_vartrack
, print_rtl_with_bb
, insns
);
550 timevar_pop (TV_VAR_TRACKING
);
553 /* Machine independent reorg pass. */
555 rest_of_handle_machine_reorg (tree decl
, rtx insns
)
557 timevar_push (TV_MACH_DEP
);
558 open_dump_file (DFI_mach
, decl
);
560 targetm
.machine_dependent_reorg ();
562 close_dump_file (DFI_mach
, print_rtl
, insns
);
563 timevar_pop (TV_MACH_DEP
);
569 /* Run new register allocator. Return TRUE if we must exit
570 rest_of_compilation upon return. */
572 rest_of_handle_new_regalloc (tree decl
, rtx insns
)
576 delete_trivially_dead_insns (insns
, max_reg_num ());
579 timevar_pop (TV_LOCAL_ALLOC
);
580 if (dump_file_tbl
[DFI_lreg
].enabled
)
582 timevar_push (TV_DUMP
);
584 close_dump_file (DFI_lreg
, NULL
, NULL
);
585 timevar_pop (TV_DUMP
);
588 /* XXX clean up the whole mess to bring live info in shape again. */
589 timevar_push (TV_GLOBAL_ALLOC
);
590 open_dump_file (DFI_greg
, decl
);
592 build_insn_chain (insns
);
593 failure
= reload (insns
, 0);
595 timevar_pop (TV_GLOBAL_ALLOC
);
597 if (dump_file_tbl
[DFI_greg
].enabled
)
599 timevar_push (TV_DUMP
);
601 dump_global_regs (dump_file
);
603 close_dump_file (DFI_greg
, print_rtl_with_bb
, insns
);
604 timevar_pop (TV_DUMP
);
610 reload_completed
= 1;
615 /* Run old register allocator. Return TRUE if we must exit
616 rest_of_compilation upon return. */
618 rest_of_handle_old_regalloc (tree decl
, rtx insns
)
623 /* Allocate the reg_renumber array. */
624 allocate_reg_info (max_regno
, FALSE
, TRUE
);
626 /* And the reg_equiv_memory_loc array. */
627 reg_equiv_memory_loc
= xcalloc (max_regno
, sizeof (rtx
));
629 allocate_initial_values (reg_equiv_memory_loc
);
631 regclass (insns
, max_reg_num (), dump_file
);
632 rebuild_notes
= local_alloc ();
634 timevar_pop (TV_LOCAL_ALLOC
);
636 /* Local allocation may have turned an indirect jump into a direct
637 jump. If so, we must rebuild the JUMP_LABEL fields of jumping
641 timevar_push (TV_JUMP
);
643 rebuild_jump_labels (insns
);
644 purge_all_dead_edges (0);
646 timevar_pop (TV_JUMP
);
649 if (dump_file_tbl
[DFI_lreg
].enabled
)
651 timevar_push (TV_DUMP
);
653 dump_flow_info (dump_file
);
654 dump_local_alloc (dump_file
);
656 close_dump_file (DFI_lreg
, print_rtl_with_bb
, insns
);
657 timevar_pop (TV_DUMP
);
662 timevar_push (TV_GLOBAL_ALLOC
);
663 open_dump_file (DFI_greg
, decl
);
665 /* If optimizing, allocate remaining pseudo-regs. Do the reload
666 pass fixing up any insns that are invalid. */
669 failure
= global_alloc (dump_file
);
672 build_insn_chain (insns
);
673 failure
= reload (insns
, 0);
676 timevar_pop (TV_GLOBAL_ALLOC
);
678 if (dump_file_tbl
[DFI_greg
].enabled
)
680 timevar_push (TV_DUMP
);
682 dump_global_regs (dump_file
);
684 close_dump_file (DFI_greg
, print_rtl_with_bb
, insns
);
685 timevar_pop (TV_DUMP
);
691 /* Run the regrename and cprop passes. */
693 rest_of_handle_regrename (tree decl
, rtx insns
)
695 timevar_push (TV_RENAME_REGISTERS
);
696 open_dump_file (DFI_rnreg
, decl
);
698 if (flag_rename_registers
)
699 regrename_optimize ();
700 if (flag_cprop_registers
)
701 copyprop_hardreg_forward ();
703 close_dump_file (DFI_rnreg
, print_rtl_with_bb
, insns
);
704 timevar_pop (TV_RENAME_REGISTERS
);
707 /* Reorder basic blocks. */
709 rest_of_handle_reorder_blocks (tree decl
, rtx insns
)
712 open_dump_file (DFI_bbro
, decl
);
714 /* Last attempt to optimize CFG, as scheduling, peepholing and insn
715 splitting possibly introduced more crossjumping opportunities. */
716 changed
= cleanup_cfg (CLEANUP_EXPENSIVE
717 | (!HAVE_conditional_execution
718 ? CLEANUP_UPDATE_LIFE
: 0));
720 if (flag_sched2_use_traces
&& flag_schedule_insns_after_reload
)
722 if (flag_reorder_blocks
|| flag_reorder_blocks_and_partition
)
723 reorder_basic_blocks ();
724 if (flag_reorder_blocks
|| flag_reorder_blocks_and_partition
725 || (flag_sched2_use_traces
&& flag_schedule_insns_after_reload
))
726 changed
|= cleanup_cfg (CLEANUP_EXPENSIVE
727 | (!HAVE_conditional_execution
728 ? CLEANUP_UPDATE_LIFE
: 0));
730 /* On conditional execution targets we can not update the life cheaply, so
731 we deffer the updating to after both cleanups. This may lose some cases
732 but should not be terribly bad. */
733 if (changed
&& HAVE_conditional_execution
)
734 update_life_info (NULL
, UPDATE_LIFE_GLOBAL_RM_NOTES
,
736 close_dump_file (DFI_bbro
, print_rtl_with_bb
, insns
);
739 #ifdef INSN_SCHEDULING
740 /* Run instruction scheduler. */
742 rest_of_handle_sched (tree decl
, rtx insns
)
744 timevar_push (TV_SCHED
);
746 /* Print function header into sched dump now
747 because doing the sched analysis makes some of the dump. */
748 if (optimize
> 0 && flag_schedule_insns
)
750 open_dump_file (DFI_sched
, decl
);
752 /* Do control and data sched analysis,
753 and write some of the results to dump file. */
755 schedule_insns (dump_file
);
757 close_dump_file (DFI_sched
, print_rtl_with_bb
, insns
);
759 timevar_pop (TV_SCHED
);
764 /* Run second scheduling pass after reload. */
766 rest_of_handle_sched2 (tree decl
, rtx insns
)
768 timevar_push (TV_SCHED2
);
769 open_dump_file (DFI_sched2
, decl
);
771 /* Do control and data sched analysis again,
772 and write some more of the results to dump file. */
776 if (flag_sched2_use_superblocks
|| flag_sched2_use_traces
)
778 schedule_ebbs (dump_file
);
779 /* No liveness updating code yet, but it should be easy to do.
780 reg-stack recomputes the liveness when needed for now. */
781 count_or_remove_death_notes (NULL
, 1);
782 cleanup_cfg (CLEANUP_EXPENSIVE
);
785 schedule_insns (dump_file
);
787 close_dump_file (DFI_sched2
, print_rtl_with_bb
, insns
);
788 timevar_pop (TV_SCHED2
);
795 rest_of_handle_gcse2 (tree decl
, rtx insns
)
797 open_dump_file (DFI_gcse2
, decl
);
799 gcse_after_reload_main (insns
, dump_file
);
800 rebuild_jump_labels (insns
);
801 delete_trivially_dead_insns (insns
, max_reg_num ());
802 close_dump_file (DFI_gcse2
, print_rtl_with_bb
, insns
);
806 #ifdef ENABLE_CHECKING
811 /* Register allocation pre-pass, to reduce number of moves necessary
812 for two-address machines. */
814 rest_of_handle_regmove (tree decl
, rtx insns
)
816 timevar_push (TV_REGMOVE
);
817 open_dump_file (DFI_regmove
, decl
);
819 regmove_optimize (insns
, max_reg_num (), dump_file
);
821 cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_UPDATE_LIFE
);
822 close_dump_file (DFI_regmove
, print_rtl_with_bb
, insns
);
823 timevar_pop (TV_REGMOVE
);
830 rest_of_handle_tracer (tree decl
, rtx insns
)
832 open_dump_file (DFI_tracer
, decl
);
834 dump_flow_info (dump_file
);
836 cleanup_cfg (CLEANUP_EXPENSIVE
);
837 reg_scan (insns
, max_reg_num (), 0);
838 close_dump_file (DFI_tracer
, print_rtl_with_bb
, get_insns ());
841 /* If-conversion and CFG cleanup. */
843 rest_of_handle_if_conversion (tree decl
, rtx insns
)
845 open_dump_file (DFI_ce1
, decl
);
846 if (flag_if_conversion
)
848 timevar_push (TV_IFCVT
);
850 dump_flow_info (dump_file
);
851 cleanup_cfg (CLEANUP_EXPENSIVE
);
852 reg_scan (insns
, max_reg_num (), 0);
854 timevar_pop (TV_IFCVT
);
856 timevar_push (TV_JUMP
);
857 cleanup_cfg (CLEANUP_EXPENSIVE
);
858 reg_scan (insns
, max_reg_num (), 0);
859 timevar_pop (TV_JUMP
);
860 close_dump_file (DFI_ce1
, print_rtl_with_bb
, get_insns ());
863 /* Rerun if-conversion, as combine may have simplified things enough
864 to now meet sequence length restrictions. */
866 rest_of_handle_if_after_combine (tree decl
, rtx insns
)
868 timevar_push (TV_IFCVT
);
869 open_dump_file (DFI_ce2
, decl
);
875 close_dump_file (DFI_ce2
, print_rtl_with_bb
, insns
);
876 timevar_pop (TV_IFCVT
);
880 rest_of_handle_web (tree decl
, rtx insns
)
882 open_dump_file (DFI_web
, decl
);
883 timevar_push (TV_WEB
);
885 delete_trivially_dead_insns (insns
, max_reg_num ());
886 cleanup_cfg (CLEANUP_EXPENSIVE
);
888 timevar_pop (TV_WEB
);
889 close_dump_file (DFI_web
, print_rtl_with_bb
, insns
);
890 reg_scan (get_insns (), max_reg_num (), 0);
893 /* Do branch profiling and static profile estimation passes. */
895 rest_of_handle_branch_prob (tree decl
, rtx insns
)
899 timevar_push (TV_BRANCH_PROB
);
900 open_dump_file (DFI_bp
, decl
);
902 if (profile_arc_flag
|| flag_test_coverage
|| flag_branch_probabilities
)
905 /* Discover and record the loop depth at the head of each basic
906 block. The loop infrastructure does the real job for us. */
907 flow_loops_find (&loops
, LOOP_TREE
);
910 flow_loops_dump (&loops
, dump_file
, NULL
, 0);
912 /* Estimate using heuristics if no profiling info is available. */
913 if (flag_guess_branch_prob
)
914 estimate_probability (&loops
);
916 flow_loops_free (&loops
);
917 free_dominance_info (CDI_DOMINATORS
);
918 close_dump_file (DFI_bp
, print_rtl_with_bb
, insns
);
919 timevar_pop (TV_BRANCH_PROB
);
922 /* Do optimizations based on expression value profiles. */
924 rest_of_handle_value_profile_transformations (tree decl
, rtx insns
)
926 open_dump_file (DFI_vpt
, decl
);
927 timevar_push (TV_VPT
);
929 if (value_profile_transformations ())
930 cleanup_cfg (CLEANUP_EXPENSIVE
);
932 timevar_pop (TV_VPT
);
933 close_dump_file (DFI_vpt
, print_rtl_with_bb
, insns
);
936 /* Do control and data flow analysis; write some of the results to the
939 rest_of_handle_cfg (tree decl
, rtx insns
)
941 open_dump_file (DFI_cfg
, decl
);
943 dump_flow_info (dump_file
);
945 cleanup_cfg (CLEANUP_EXPENSIVE
946 | (flag_thread_jumps
? CLEANUP_THREADING
: 0));
948 /* It may make more sense to mark constant functions after dead code is
949 eliminated by life_analysis, but we need to do it early, as -fprofile-arcs
950 may insert code making function non-constant, but we still must consider
951 it as constant, otherwise -fbranch-probabilities will not read data back.
953 life_analysis rarely eliminates modification of external memory.
957 /* Alias analysis depends on this information and mark_constant_function
958 depends on alias analysis. */
959 reg_scan (insns
, max_reg_num (), 1);
960 mark_constant_function ();
963 close_dump_file (DFI_cfg
, print_rtl_with_bb
, insns
);
966 /* Purge addressofs. */
968 rest_of_handle_addressof (tree decl
, rtx insns
)
970 open_dump_file (DFI_addressof
, decl
);
972 purge_addressof (insns
);
973 if (optimize
&& purge_all_dead_edges (0))
974 delete_unreachable_blocks ();
975 reg_scan (insns
, max_reg_num (), 1);
977 close_dump_file (DFI_addressof
, print_rtl
, insns
);
980 /* Perform jump bypassing and control flow optimizations. */
982 rest_of_handle_jump_bypass (tree decl
, rtx insns
)
984 timevar_push (TV_BYPASS
);
985 open_dump_file (DFI_bypass
, decl
);
987 cleanup_cfg (CLEANUP_EXPENSIVE
);
988 reg_scan (insns
, max_reg_num (), 1);
990 if (bypass_jumps (dump_file
))
992 rebuild_jump_labels (insns
);
993 cleanup_cfg (CLEANUP_EXPENSIVE
);
994 delete_trivially_dead_insns (insns
, max_reg_num ());
997 close_dump_file (DFI_bypass
, print_rtl_with_bb
, insns
);
998 timevar_pop (TV_BYPASS
);
1002 #ifdef ENABLE_CHECKING
1003 verify_flow_info ();
1007 /* Try to identify useless null pointer tests and delete them. */
1009 rest_of_handle_null_pointer (tree decl
, rtx insns
)
1011 open_dump_file (DFI_null
, decl
);
1013 dump_flow_info (dump_file
);
1015 if (delete_null_pointer_checks (insns
))
1016 cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_PRE_LOOP
);
1018 close_dump_file (DFI_null
, print_rtl_with_bb
, insns
);
1021 /* Try combining insns through substitution. */
1023 rest_of_handle_combine (tree decl
, rtx insns
)
1025 int rebuild_jump_labels_after_combine
= 0;
1027 timevar_push (TV_COMBINE
);
1028 open_dump_file (DFI_combine
, decl
);
1030 rebuild_jump_labels_after_combine
1031 = combine_instructions (insns
, max_reg_num ());
1033 /* Combining insns may have turned an indirect jump into a
1034 direct jump. Rebuild the JUMP_LABEL fields of jumping
1036 if (rebuild_jump_labels_after_combine
)
1038 timevar_push (TV_JUMP
);
1039 rebuild_jump_labels (insns
);
1040 timevar_pop (TV_JUMP
);
1042 cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_UPDATE_LIFE
);
1045 close_dump_file (DFI_combine
, print_rtl_with_bb
, insns
);
1046 timevar_pop (TV_COMBINE
);
1051 /* Perform life analysis. */
1053 rest_of_handle_life (tree decl
, rtx insns
)
1055 open_dump_file (DFI_life
, decl
);
1058 #ifdef ENABLE_CHECKING
1059 verify_flow_info ();
1061 life_analysis (insns
, dump_file
, PROP_FINAL
);
1063 cleanup_cfg ((optimize
? CLEANUP_EXPENSIVE
: 0) | CLEANUP_UPDATE_LIFE
1065 | (flag_thread_jumps
? CLEANUP_THREADING
: 0));
1066 timevar_pop (TV_FLOW
);
1070 setjmp_vars_warning (DECL_INITIAL (decl
));
1071 setjmp_args_warning ();
1076 if (!flag_new_regalloc
&& initialize_uninitialized_subregs ())
1078 /* Insns were inserted, and possibly pseudos created, so
1079 things might look a bit different. */
1080 insns
= get_insns ();
1081 allocate_reg_life_data ();
1082 update_life_info (NULL
, UPDATE_LIFE_GLOBAL_RM_NOTES
,
1083 PROP_LOG_LINKS
| PROP_REG_INFO
| PROP_DEATH_NOTES
);
1089 close_dump_file (DFI_life
, print_rtl_with_bb
, insns
);
1094 /* Perform common subexpression elimination. Nonzero value from
1095 `cse_main' means that jumps were simplified and some code may now
1096 be unreachable, so do jump optimization again. */
1098 rest_of_handle_cse (tree decl
, rtx insns
)
1102 open_dump_file (DFI_cse
, decl
);
1104 dump_flow_info (dump_file
);
1105 timevar_push (TV_CSE
);
1107 reg_scan (insns
, max_reg_num (), 1);
1109 tem
= cse_main (insns
, max_reg_num (), 0, dump_file
);
1111 rebuild_jump_labels (insns
);
1112 if (purge_all_dead_edges (0))
1113 delete_unreachable_blocks ();
1115 delete_trivially_dead_insns (insns
, max_reg_num ());
1117 /* If we are not running more CSE passes, then we are no longer
1118 expecting CSE to be run. But always rerun it in a cheap mode. */
1119 cse_not_expected
= !flag_rerun_cse_after_loop
&& !flag_gcse
;
1121 if (tem
|| optimize
> 1)
1122 cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_PRE_LOOP
);
1123 /* Try to identify useless null pointer tests and delete them. */
1124 if (flag_delete_null_pointer_checks
)
1126 timevar_push (TV_JUMP
);
1128 if (delete_null_pointer_checks (insns
))
1129 cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_PRE_LOOP
);
1130 timevar_pop (TV_JUMP
);
1133 /* The second pass of jump optimization is likely to have
1134 removed a bunch more instructions. */
1135 renumber_insns (dump_file
);
1137 timevar_pop (TV_CSE
);
1138 close_dump_file (DFI_cse
, print_rtl_with_bb
, insns
);
1141 /* Run second CSE pass after loop optimizations. */
1143 rest_of_handle_cse2 (tree decl
, rtx insns
)
1147 timevar_push (TV_CSE2
);
1148 open_dump_file (DFI_cse2
, decl
);
1150 dump_flow_info (dump_file
);
1151 /* CFG is no longer maintained up-to-date. */
1152 tem
= cse_main (insns
, max_reg_num (), 1, dump_file
);
1154 /* Run a pass to eliminate duplicated assignments to condition code
1155 registers. We have to run this after bypass_jumps, because it
1156 makes it harder for that pass to determine whether a jump can be
1158 cse_condition_code_reg ();
1160 purge_all_dead_edges (0);
1161 delete_trivially_dead_insns (insns
, max_reg_num ());
1165 timevar_push (TV_JUMP
);
1166 rebuild_jump_labels (insns
);
1167 cleanup_cfg (CLEANUP_EXPENSIVE
);
1168 timevar_pop (TV_JUMP
);
1170 reg_scan (insns
, max_reg_num (), 0);
1171 close_dump_file (DFI_cse2
, print_rtl_with_bb
, insns
);
1173 timevar_pop (TV_CSE2
);
1176 /* Perform global cse. */
1178 rest_of_handle_gcse (tree decl
, rtx insns
)
1180 int save_csb
, save_cfj
;
1183 timevar_push (TV_GCSE
);
1184 open_dump_file (DFI_gcse
, decl
);
1186 tem
= gcse_main (insns
, dump_file
);
1187 rebuild_jump_labels (insns
);
1188 delete_trivially_dead_insns (insns
, max_reg_num ());
1190 save_csb
= flag_cse_skip_blocks
;
1191 save_cfj
= flag_cse_follow_jumps
;
1192 flag_cse_skip_blocks
= flag_cse_follow_jumps
= 0;
1194 /* If -fexpensive-optimizations, re-run CSE to clean up things done
1196 if (flag_expensive_optimizations
)
1198 timevar_push (TV_CSE
);
1199 reg_scan (insns
, max_reg_num (), 1);
1200 tem2
= cse_main (insns
, max_reg_num (), 0, dump_file
);
1201 purge_all_dead_edges (0);
1202 delete_trivially_dead_insns (insns
, max_reg_num ());
1203 timevar_pop (TV_CSE
);
1204 cse_not_expected
= !flag_rerun_cse_after_loop
;
1207 /* If gcse or cse altered any jumps, rerun jump optimizations to clean
1208 things up. Then possibly re-run CSE again. */
1212 timevar_push (TV_JUMP
);
1213 rebuild_jump_labels (insns
);
1214 cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_PRE_LOOP
);
1215 timevar_pop (TV_JUMP
);
1217 if (flag_expensive_optimizations
)
1219 timevar_push (TV_CSE
);
1220 reg_scan (insns
, max_reg_num (), 1);
1221 tem2
= cse_main (insns
, max_reg_num (), 0, dump_file
);
1222 purge_all_dead_edges (0);
1223 delete_trivially_dead_insns (insns
, max_reg_num ());
1224 timevar_pop (TV_CSE
);
1228 close_dump_file (DFI_gcse
, print_rtl_with_bb
, insns
);
1229 timevar_pop (TV_GCSE
);
1232 flag_cse_skip_blocks
= save_csb
;
1233 flag_cse_follow_jumps
= save_cfj
;
1234 #ifdef ENABLE_CHECKING
1235 verify_flow_info ();
1239 /* Move constant computations out of loops. */
1241 rest_of_handle_loop_optimize (tree decl
, rtx insns
)
1243 int do_unroll
, do_prefetch
;
1245 timevar_push (TV_LOOP
);
1246 delete_dead_jumptables ();
1247 cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_PRE_LOOP
);
1248 open_dump_file (DFI_loop
, decl
);
1250 /* CFG is no longer maintained up-to-date. */
1251 free_bb_for_insn ();
1253 if (flag_unroll_loops
)
1254 do_unroll
= LOOP_AUTO_UNROLL
; /* Having two unrollers is useless. */
1256 do_unroll
= flag_old_unroll_loops
? LOOP_UNROLL
: LOOP_AUTO_UNROLL
;
1257 do_prefetch
= flag_prefetch_loop_arrays
? LOOP_PREFETCH
: 0;
1259 if (flag_rerun_loop_opt
)
1261 cleanup_barriers ();
1263 /* We only want to perform unrolling once. */
1264 loop_optimize (insns
, dump_file
, do_unroll
);
1267 /* The first call to loop_optimize makes some instructions
1268 trivially dead. We delete those instructions now in the
1269 hope that doing so will make the heuristics in loop work
1270 better and possibly speed up compilation. */
1271 delete_trivially_dead_insns (insns
, max_reg_num ());
1273 /* The regscan pass is currently necessary as the alias
1274 analysis code depends on this information. */
1275 reg_scan (insns
, max_reg_num (), 1);
1277 cleanup_barriers ();
1278 loop_optimize (insns
, dump_file
, do_unroll
| do_prefetch
);
1280 /* Loop can create trivially dead instructions. */
1281 delete_trivially_dead_insns (insns
, max_reg_num ());
1282 close_dump_file (DFI_loop
, print_rtl
, insns
);
1283 timevar_pop (TV_LOOP
);
1284 find_basic_blocks (insns
, max_reg_num (), dump_file
);
1289 /* Perform loop optimizations. It might be better to do them a bit
1290 sooner, but we want the profile feedback to work more
1293 rest_of_handle_loop2 (tree decl
, rtx insns
)
1295 struct loops
*loops
;
1298 if (!flag_unswitch_loops
1300 && !flag_unroll_loops
1301 && !flag_branch_on_count_reg
)
1304 timevar_push (TV_LOOP
);
1305 open_dump_file (DFI_loop2
, decl
);
1307 dump_flow_info (dump_file
);
1309 /* Initialize structures for layout changes. */
1310 cfg_layout_initialize ();
1312 loops
= loop_optimizer_init (dump_file
);
1316 /* The optimizations: */
1317 if (flag_unswitch_loops
)
1318 unswitch_loops (loops
);
1320 if (flag_peel_loops
|| flag_unroll_loops
)
1321 unroll_and_peel_loops (loops
,
1322 (flag_peel_loops
? UAP_PEEL
: 0) |
1323 (flag_unroll_loops
? UAP_UNROLL
: 0) |
1324 (flag_unroll_all_loops
? UAP_UNROLL_ALL
: 0));
1326 #ifdef HAVE_doloop_end
1327 if (flag_branch_on_count_reg
&& HAVE_doloop_end
)
1328 doloop_optimize_loops (loops
);
1329 #endif /* HAVE_doloop_end */
1331 loop_optimizer_finalize (loops
, dump_file
);
1334 /* Finalize layout changes. */
1336 if (bb
->next_bb
!= EXIT_BLOCK_PTR
)
1337 bb
->rbi
->next
= bb
->next_bb
;
1338 cfg_layout_finalize ();
1340 cleanup_cfg (CLEANUP_EXPENSIVE
);
1341 delete_trivially_dead_insns (insns
, max_reg_num ());
1342 reg_scan (insns
, max_reg_num (), 0);
1344 dump_flow_info (dump_file
);
1345 close_dump_file (DFI_loop2
, print_rtl_with_bb
, get_insns ());
1346 timevar_pop (TV_LOOP
);
1350 /* This is called from finish_function (within langhooks.parse_file)
1351 after each top-level definition is parsed.
1352 It is supposed to compile that function or variable
1353 and output the assembler code for it.
1354 After we return, the tree storage is freed. */
1357 rest_of_compilation (tree decl
)
1361 timevar_push (TV_REST_OF_COMPILATION
);
1363 /* Register rtl specific functions for cfg. */
1364 rtl_register_cfg_hooks ();
1366 /* Now that we're out of the frontend, we shouldn't have any more
1367 CONCATs anywhere. */
1368 generating_concat_p
= 0;
1370 /* When processing delayed functions, prepare_function_start() won't
1371 have been run to re-initialize it. */
1372 cse_not_expected
= ! optimize
;
1374 if (!cfun
->dont_emit_block_notes
)
1376 /* First, make sure that NOTE_BLOCK is set correctly for each
1377 NOTE_INSN_BLOCK_BEG/NOTE_INSN_BLOCK_END note. */
1378 if (!cfun
->x_whole_function_mode_p
)
1381 /* In function-at-a-time mode, we do not attempt to keep the BLOCK
1382 tree in sensible shape. So, we just recalculate it here. */
1383 if (cfun
->x_whole_function_mode_p
)
1387 finalize_block_changes ();
1391 /* Dump the rtl code if we are dumping rtl. */
1392 if (open_dump_file (DFI_rtl
, decl
))
1393 close_dump_file (DFI_rtl
, print_rtl
, get_insns ());
1395 /* Convert from NOTE_INSN_EH_REGION style notes, and do other
1396 sorts of eh initialization. Delay this until after the
1397 initial rtl dump so that we can see the original nesting. */
1398 convert_from_eh_region_ranges ();
1400 /* If we're emitting a nested function, make sure its parent gets
1401 emitted as well. Doing otherwise confuses debug info. */
1404 for (parent
= DECL_CONTEXT (current_function_decl
);
1405 parent
!= NULL_TREE
;
1406 parent
= get_containing_scope (parent
))
1407 if (TREE_CODE (parent
) == FUNCTION_DECL
)
1408 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (parent
)) = 1;
1411 /* We are now committed to emitting code for this function. Do any
1412 preparation, such as emitting abstract debug info for the inline
1413 before it gets mangled by optimization. */
1414 if (cgraph_function_possibly_inlined_p (decl
))
1415 (*debug_hooks
->outlining_inline_function
) (decl
);
1417 /* Remove any notes we don't need. That will make iterating
1418 over the instruction sequence faster, and allow the garbage
1419 collector to reclaim the memory used by the notes. */
1420 remove_unnecessary_notes ();
1421 if (!cfun
->dont_emit_block_notes
)
1426 /* Initialize some variables used by the optimizers. */
1427 init_function_for_compilation ();
1429 if (! DECL_DEFER_OUTPUT (decl
))
1430 TREE_ASM_WRITTEN (decl
) = 1;
1432 /* Now that integrate will no longer see our rtl, we need not
1433 distinguish between the return value of this function and the
1434 return value of called functions. Also, we can remove all SETs
1435 of subregs of hard registers; they are only here because of
1436 integrate. Also, we can now initialize pseudos intended to
1437 carry magic hard reg data throughout the function. */
1438 rtx_equal_function_value_matters
= 0;
1439 purge_hard_subreg_sets (get_insns ());
1441 /* Early return if there were errors. We can run afoul of our
1442 consistency checks, and there's not really much point in fixing them.
1443 Don't return yet if -Wreturn-type; we need to do cleanup_cfg. */
1444 if (((rtl_dump_and_exit
|| flag_syntax_only
) && !warn_return_type
)
1445 || errorcount
|| sorrycount
)
1446 goto exit_rest_of_compilation
;
1448 timevar_push (TV_JUMP
);
1449 open_dump_file (DFI_sibling
, decl
);
1450 insns
= get_insns ();
1451 rebuild_jump_labels (insns
);
1452 find_exception_handler_labels ();
1453 find_basic_blocks (insns
, max_reg_num (), dump_file
);
1455 delete_unreachable_blocks ();
1457 /* Turn NOTE_INSN_PREDICTIONs into branch predictions. */
1458 if (flag_guess_branch_prob
)
1460 timevar_push (TV_BRANCH_PROB
);
1461 note_prediction_to_br_prob ();
1462 timevar_pop (TV_BRANCH_PROB
);
1465 timevar_pop (TV_JUMP
);
1467 if (cfun
->tail_call_emit
)
1468 fixup_tail_calls ();
1470 insn_locators_initialize ();
1471 /* Complete generation of exception handling code. */
1474 timevar_push (TV_JUMP
);
1475 open_dump_file (DFI_eh
, decl
);
1477 finish_eh_generation ();
1479 close_dump_file (DFI_eh
, print_rtl
, get_insns ());
1480 timevar_pop (TV_JUMP
);
1483 /* Delay emitting hard_reg_initial_value sets until after EH landing pad
1484 generation, which might create new sets. */
1485 emit_initial_value_sets ();
1488 /* If we are doing position-independent code generation, now
1489 is the time to output special prologues and epilogues.
1490 We do not want to do this earlier, because it just clutters
1491 up inline functions with meaningless insns. */
1496 insns
= get_insns ();
1498 /* Copy any shared structure that should not be shared. */
1499 unshare_all_rtl (current_function_decl
, insns
);
1501 #ifdef SETJMP_VIA_SAVE_AREA
1502 /* This must be performed before virtual register instantiation.
1503 Please be aware that everything in the compiler that can look
1504 at the RTL up to this point must understand that REG_SAVE_AREA
1505 is just like a use of the REG contained inside. */
1506 if (current_function_calls_alloca
)
1507 optimize_save_area_alloca (insns
);
1510 /* Instantiate all virtual registers. */
1511 instantiate_virtual_regs (current_function_decl
, insns
);
1513 open_dump_file (DFI_jump
, decl
);
1515 /* Always do one jump optimization pass to ensure that JUMP_LABEL fields
1516 are initialized and to compute whether control can drop off the end
1519 timevar_push (TV_JUMP
);
1520 /* Turn NOTE_INSN_EXPECTED_VALUE into REG_BR_PROB. Do this
1521 before jump optimization switches branch directions. */
1522 if (flag_guess_branch_prob
)
1523 expected_value_to_br_prob ();
1525 reg_scan (insns
, max_reg_num (), 0);
1526 rebuild_jump_labels (insns
);
1527 find_basic_blocks (insns
, max_reg_num (), dump_file
);
1528 delete_trivially_dead_insns (insns
, max_reg_num ());
1530 dump_flow_info (dump_file
);
1531 cleanup_cfg ((optimize
? CLEANUP_EXPENSIVE
: 0) | CLEANUP_PRE_LOOP
1532 | (flag_thread_jumps
? CLEANUP_THREADING
: 0));
1534 create_loop_notes ();
1536 purge_line_number_notes (insns
);
1538 timevar_pop (TV_JUMP
);
1539 close_dump_file (DFI_jump
, print_rtl
, insns
);
1541 /* Now is when we stop if -fsyntax-only and -Wreturn-type. */
1542 if (rtl_dump_and_exit
|| flag_syntax_only
|| DECL_DEFER_OUTPUT (decl
))
1543 goto exit_rest_of_compilation
;
1545 timevar_push (TV_JUMP
);
1548 cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_PRE_LOOP
);
1550 if (flag_delete_null_pointer_checks
)
1551 rest_of_handle_null_pointer (decl
, insns
);
1553 /* Jump optimization, and the removal of NULL pointer checks, may
1554 have reduced the number of instructions substantially. CSE, and
1555 future passes, allocate arrays whose dimensions involve the
1556 maximum instruction UID, so if we can reduce the maximum UID
1557 we'll save big on memory. */
1558 renumber_insns (dump_file
);
1559 timevar_pop (TV_JUMP
);
1561 close_dump_file (DFI_jump
, print_rtl_with_bb
, insns
);
1566 rest_of_handle_cse (decl
, insns
);
1568 rest_of_handle_addressof (decl
, insns
);
1575 rest_of_handle_gcse (decl
, insns
);
1577 if (flag_loop_optimize
)
1578 rest_of_handle_loop_optimize (decl
, insns
);
1581 rest_of_handle_jump_bypass (decl
, insns
);
1584 timevar_push (TV_FLOW
);
1586 rest_of_handle_cfg (decl
, insns
);
1588 if (!flag_tree_based_profiling
1589 && (optimize
> 0 || profile_arc_flag
1590 || flag_test_coverage
|| flag_branch_probabilities
))
1592 rtl_register_profile_hooks ();
1593 rtl_register_value_prof_hooks ();
1594 rest_of_handle_branch_prob (decl
, insns
);
1596 if (flag_branch_probabilities
1597 && flag_profile_values
1598 && flag_value_profile_transformations
)
1599 rest_of_handle_value_profile_transformations (decl
, insns
);
1601 /* Remove the death notes created for vpt. */
1602 if (flag_profile_values
)
1603 count_or_remove_death_notes (NULL
, 1);
1607 rest_of_handle_if_conversion (decl
, insns
);
1610 rest_of_handle_tracer (decl
, insns
);
1613 rest_of_handle_loop2 (decl
, insns
);
1616 rest_of_handle_web (decl
, insns
);
1618 if (flag_rerun_cse_after_loop
)
1619 rest_of_handle_cse2 (decl
, insns
);
1621 cse_not_expected
= 1;
1623 rest_of_handle_life (decl
, insns
);
1626 rest_of_handle_combine (decl
, insns
);
1628 if (flag_if_conversion
)
1629 rest_of_handle_if_after_combine (decl
, insns
);
1631 /* The optimization to partition hot/cold basic blocks into separate
1632 sections of the .o file does not work well with exception handling.
1633 Don't call it if there are exceptions. */
1635 if (flag_reorder_blocks_and_partition
&& !flag_exceptions
)
1638 partition_hot_cold_basic_blocks ();
1639 allocate_reg_life_data ();
1640 update_life_info (NULL
, UPDATE_LIFE_GLOBAL_RM_NOTES
,
1641 PROP_LOG_LINKS
| PROP_REG_INFO
| PROP_DEATH_NOTES
);
1645 if (optimize
> 0 && (flag_regmove
|| flag_expensive_optimizations
))
1646 rest_of_handle_regmove (decl
, insns
);
1648 /* Do unconditional splitting before register allocation to allow machine
1649 description to add extra information not needed previously. */
1650 split_all_insns (1);
1652 #ifdef OPTIMIZE_MODE_SWITCHING
1653 timevar_push (TV_MODE_SWITCH
);
1656 optimize_mode_switching (NULL
);
1659 timevar_pop (TV_MODE_SWITCH
);
1662 /* Any of the several passes since flow1 will have munged register
1663 lifetime data a bit. We need it to be up to date for scheduling
1664 (see handling of reg_known_equiv in init_alias_analysis). */
1665 recompute_reg_usage (insns
, !optimize_size
);
1667 #ifdef INSN_SCHEDULING
1668 rest_of_handle_sched (decl
, insns
);
1671 /* Determine if the current function is a leaf before running reload
1672 since this can impact optimizations done by the prologue and
1673 epilogue thus changing register elimination offsets. */
1674 current_function_is_leaf
= leaf_function_p ();
1676 timevar_push (TV_LOCAL_ALLOC
);
1677 open_dump_file (DFI_lreg
, decl
);
1679 if (flag_new_regalloc
)
1681 if (rest_of_handle_new_regalloc (decl
, insns
))
1682 goto exit_rest_of_compilation
;
1686 if (rest_of_handle_old_regalloc (decl
, insns
))
1687 goto exit_rest_of_compilation
;
1692 open_dump_file (DFI_postreload
, decl
);
1694 /* Do a very simple CSE pass over just the hard registers. */
1697 timevar_push (TV_RELOAD_CSE_REGS
);
1698 reload_cse_regs (insns
);
1699 /* reload_cse_regs can eliminate potentially-trapping MEMs.
1700 Remove any EH edges associated with them. */
1701 if (flag_non_call_exceptions
)
1702 purge_all_dead_edges (0);
1703 timevar_pop (TV_RELOAD_CSE_REGS
);
1706 close_dump_file (DFI_postreload
, print_rtl_with_bb
, insns
);
1708 if (optimize
> 0 && flag_gcse_after_reload
)
1709 rest_of_handle_gcse2 (decl
, insns
);
1711 /* Re-create the death notes which were deleted during reload. */
1712 timevar_push (TV_FLOW2
);
1713 open_dump_file (DFI_flow2
, decl
);
1715 #ifdef ENABLE_CHECKING
1716 verify_flow_info ();
1719 /* If optimizing, then go ahead and split insns now. */
1723 split_all_insns (0);
1725 if (flag_branch_target_load_optimize
)
1727 open_dump_file (DFI_branch_target_load
, decl
);
1729 branch_target_load_optimize (insns
, false);
1731 close_dump_file (DFI_branch_target_load
, print_rtl_with_bb
, insns
);
1737 cleanup_cfg (CLEANUP_EXPENSIVE
);
1739 /* On some machines, the prologue and epilogue code, or parts thereof,
1740 can be represented as RTL. Doing so lets us schedule insns between
1741 it and the rest of the code and also allows delayed branch
1742 scheduling to operate in the epilogue. */
1743 thread_prologue_and_epilogue_insns (insns
);
1744 epilogue_completed
= 1;
1748 life_analysis (insns
, dump_file
, PROP_POSTRELOAD
);
1749 cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_UPDATE_LIFE
1750 | (flag_crossjumping
? CLEANUP_CROSSJUMP
: 0));
1752 /* This is kind of a heuristic. We need to run combine_stack_adjustments
1753 even for machines with possibly nonzero RETURN_POPS_ARGS
1754 and ACCUMULATE_OUTGOING_ARGS. We expect that only ports having
1755 push instructions will have popping returns. */
1756 #ifndef PUSH_ROUNDING
1757 if (!ACCUMULATE_OUTGOING_ARGS
)
1759 combine_stack_adjustments ();
1764 flow2_completed
= 1;
1766 close_dump_file (DFI_flow2
, print_rtl_with_bb
, insns
);
1767 timevar_pop (TV_FLOW2
);
1769 #ifdef HAVE_peephole2
1770 if (optimize
> 0 && flag_peephole2
)
1772 timevar_push (TV_PEEPHOLE2
);
1773 open_dump_file (DFI_peephole2
, decl
);
1775 peephole2_optimize (dump_file
);
1777 close_dump_file (DFI_peephole2
, print_rtl_with_bb
, insns
);
1778 timevar_pop (TV_PEEPHOLE2
);
1782 open_dump_file (DFI_ce3
, decl
);
1784 /* Last attempt to optimize CFG, as scheduling, peepholing and insn
1785 splitting possibly introduced more crossjumping opportunities. */
1786 cleanup_cfg (CLEANUP_EXPENSIVE
1787 | CLEANUP_UPDATE_LIFE
1788 | (flag_crossjumping
? CLEANUP_CROSSJUMP
: 0));
1789 if (flag_if_conversion2
)
1791 timevar_push (TV_IFCVT2
);
1795 timevar_pop (TV_IFCVT2
);
1797 close_dump_file (DFI_ce3
, print_rtl_with_bb
, insns
);
1801 if (flag_rename_registers
|| flag_cprop_registers
)
1802 rest_of_handle_regrename (decl
, insns
);
1804 rest_of_handle_reorder_blocks (decl
, insns
);
1807 if (flag_branch_target_load_optimize2
)
1809 /* Leave this a warning for now so that it is possible to experiment
1810 with running this pass twice. In 3.6, we should either make this
1811 an error, or use separate dump files. */
1812 if (flag_branch_target_load_optimize
)
1813 warning ("branch target register load optimization is not intended "
1816 open_dump_file (DFI_branch_target_load
, decl
);
1818 branch_target_load_optimize (insns
, true);
1820 close_dump_file (DFI_branch_target_load
, print_rtl_with_bb
, insns
);
1825 #ifdef INSN_SCHEDULING
1826 if (optimize
> 0 && flag_schedule_insns_after_reload
)
1827 rest_of_handle_sched2 (decl
, insns
);
1830 #ifdef LEAF_REGISTERS
1831 current_function_uses_only_leaf_regs
1832 = optimize
> 0 && only_leaf_regs_used () && leaf_function_p ();
1836 rest_of_handle_stack_regs (decl
, insns
);
1839 compute_alignments ();
1841 if (flag_var_tracking
)
1842 rest_of_handle_variable_tracking (decl
, insns
);
1844 /* CFG is no longer maintained up-to-date. */
1845 free_bb_for_insn ();
1847 if (targetm
.machine_dependent_reorg
!= 0)
1848 rest_of_handle_machine_reorg (decl
, insns
);
1850 purge_line_number_notes (insns
);
1851 cleanup_barriers ();
1854 if (optimize
> 0 && flag_delayed_branch
)
1855 rest_of_handle_delay_slots (decl
, insns
);
1858 #if defined (HAVE_ATTR_length) && !defined (STACK_REGS)
1859 timevar_push (TV_SHORTEN_BRANCH
);
1860 split_all_insns_noflow ();
1861 timevar_pop (TV_SHORTEN_BRANCH
);
1864 convert_to_eh_region_ranges ();
1866 /* Shorten branches. */
1867 timevar_push (TV_SHORTEN_BRANCH
);
1868 shorten_branches (get_insns ());
1869 timevar_pop (TV_SHORTEN_BRANCH
);
1871 set_nothrow_function_flags ();
1872 if (current_function_nothrow
)
1873 /* Now we know that this can't throw; set the flag for the benefit
1874 of other functions later in this translation unit. */
1875 TREE_NOTHROW (current_function_decl
) = 1;
1877 rest_of_handle_final (decl
, insns
);
1879 /* Write DBX symbols if requested. */
1881 /* Note that for those inline functions where we don't initially
1882 know for certain that we will be generating an out-of-line copy,
1883 the first invocation of this routine (rest_of_compilation) will
1884 skip over this code by doing a `goto exit_rest_of_compilation;'.
1885 Later on, wrapup_global_declarations will (indirectly) call
1886 rest_of_compilation again for those inline functions that need
1887 to have out-of-line copies generated. During that call, we
1888 *will* be routed past here. */
1890 timevar_push (TV_SYMOUT
);
1891 (*debug_hooks
->function_decl
) (decl
);
1892 timevar_pop (TV_SYMOUT
);
1894 exit_rest_of_compilation
:
1896 coverage_end_function ();
1898 /* In case the function was not output,
1899 don't leave any temporary anonymous types
1900 queued up for sdb output. */
1901 #ifdef SDB_DEBUGGING_INFO
1902 if (write_symbols
== SDB_DEBUG
)
1903 sdbout_types (NULL_TREE
);
1906 reload_completed
= 0;
1907 epilogue_completed
= 0;
1908 flow2_completed
= 0;
1911 timevar_push (TV_FINAL
);
1913 /* Clear out the insn_length contents now that they are no
1915 init_insn_lengths ();
1917 /* Show no temporary slots allocated. */
1920 free_basic_block_vars ();
1921 free_bb_for_insn ();
1923 timevar_pop (TV_FINAL
);
1925 if (targetm
.binds_local_p (current_function_decl
))
1927 int pref
= cfun
->preferred_stack_boundary
;
1928 if (cfun
->recursive_call_emit
1929 && cfun
->stack_alignment_needed
> cfun
->preferred_stack_boundary
)
1930 pref
= cfun
->stack_alignment_needed
;
1931 cgraph_rtl_info (current_function_decl
)->preferred_incoming_stack_boundary
1935 /* Make sure volatile mem refs aren't considered valid operands for
1936 arithmetic insns. We must call this here if this is a nested inline
1937 function, since the above code leaves us in the init_recog state
1938 (from final.c), and the function context push/pop code does not
1939 save/restore volatile_ok.
1941 ??? Maybe it isn't necessary for expand_start_function to call this
1942 anymore if we do it here? */
1944 init_recog_no_volatile ();
1946 /* We're done with this function. Free up memory if we can. */
1947 free_after_parsing (cfun
);
1951 timevar_pop (TV_REST_OF_COMPILATION
);
1955 init_optimization_passes (void)
1957 open_dump_file (DFI_cgraph
, NULL
);
1958 cgraph_dump_file
= dump_file
;
1963 finish_optimization_passes (void)
1965 if (profile_arc_flag
|| flag_test_coverage
|| flag_branch_probabilities
)
1967 timevar_push (TV_DUMP
);
1968 open_dump_file (DFI_bp
, NULL
);
1972 close_dump_file (DFI_bp
, NULL
, NULL_RTX
);
1973 timevar_pop (TV_DUMP
);
1976 if (optimize
> 0 && open_dump_file (DFI_combine
, NULL
))
1978 timevar_push (TV_DUMP
);
1979 dump_combine_total_stats (dump_file
);
1980 close_dump_file (DFI_combine
, NULL
, NULL_RTX
);
1981 timevar_pop (TV_DUMP
);
1984 dump_file
= cgraph_dump_file
;
1985 cgraph_dump_file
= NULL
;
1986 close_dump_file (DFI_cgraph
, NULL
, NULL_RTX
);
1988 /* Do whatever is necessary to finish printing the graphs. */
1989 if (graph_dump_format
!= no_graph
)
1993 for (i
= 0; i
< (int) DFI_MAX
; ++i
)
1994 if (dump_file_tbl
[i
].initialized
&& dump_file_tbl
[i
].graph_dump_p
)
1999 sprintf (seq
, DUMPFILE_FORMAT
, i
);
2000 suffix
= concat (seq
, dump_file_tbl
[i
].extension
, NULL
);
2001 finish_graph_dump_file (dump_base_name
, suffix
);
2009 enable_rtl_dump_file (int letter
)
2011 bool matched
= false;
2016 for (i
= 0; i
< (int) DFI_MAX
; ++i
)
2017 dump_file_tbl
[i
].enabled
= 1;
2022 for (i
= 0; i
< (int) DFI_MAX
; ++i
)
2023 if (letter
== dump_file_tbl
[i
].debug_switch
)
2025 dump_file_tbl
[i
].enabled
= 1;