* config/xtensa/lib1funcs.asm (__mulsi3): Use symbolic name for ACCLO.
[official-gcc.git] / gcc / passes.c
blob7bb661d0d0ebadc06be0402063938b5f561e2c4d
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, 2005 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
10 version.
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
15 for more details.
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
20 02111-1307, USA. */
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. */
27 #include "config.h"
28 #undef FLOAT /* This is for hpux. They should change hpux. */
29 #undef FFS /* Some systems define this in param.h. */
30 #include "system.h"
31 #include "coretypes.h"
32 #include "tm.h"
33 #include <signal.h>
35 #ifdef HAVE_SYS_RESOURCE_H
36 # include <sys/resource.h>
37 #endif
39 #ifdef HAVE_SYS_TIMES_H
40 # include <sys/times.h>
41 #endif
43 #include "line-map.h"
44 #include "input.h"
45 #include "tree.h"
46 #include "rtl.h"
47 #include "tm_p.h"
48 #include "flags.h"
49 #include "insn-attr.h"
50 #include "insn-config.h"
51 #include "insn-flags.h"
52 #include "hard-reg-set.h"
53 #include "recog.h"
54 #include "output.h"
55 #include "except.h"
56 #include "function.h"
57 #include "toplev.h"
58 #include "expr.h"
59 #include "basic-block.h"
60 #include "intl.h"
61 #include "ggc.h"
62 #include "graph.h"
63 #include "regs.h"
64 #include "timevar.h"
65 #include "diagnostic.h"
66 #include "params.h"
67 #include "reload.h"
68 #include "dwarf2asm.h"
69 #include "integrate.h"
70 #include "real.h"
71 #include "debug.h"
72 #include "target.h"
73 #include "langhooks.h"
74 #include "cfglayout.h"
75 #include "cfgloop.h"
76 #include "hosthooks.h"
77 #include "cgraph.h"
78 #include "opts.h"
79 #include "coverage.h"
80 #include "value-prof.h"
81 #include "alloc-pool.h"
82 #include "tree-pass.h"
83 #include "tree-dump.h"
85 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
86 #include "dwarf2out.h"
87 #endif
89 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
90 #include "dbxout.h"
91 #endif
93 #ifdef SDB_DEBUGGING_INFO
94 #include "sdbout.h"
95 #endif
97 #ifdef XCOFF_DEBUGGING_INFO
98 #include "xcoffout.h" /* Needed for external data
99 declarations for e.g. AIX 4.x. */
100 #endif
102 #ifndef HAVE_conditional_execution
103 #define HAVE_conditional_execution 0
104 #endif
106 /* Format to use to print dumpfile index value */
107 #ifndef DUMPFILE_FORMAT
108 #define DUMPFILE_FORMAT ".%02d."
109 #endif
111 static int initializing_dump = 0;
113 /* Routine to open a dump file. Return true if the dump file is enabled. */
115 static int
116 open_dump_file (enum tree_dump_index index, tree decl)
118 if (! dump_enabled_p (index))
119 return 0;
121 timevar_push (TV_DUMP);
123 if (dump_file != NULL || dump_file_name != NULL)
124 abort ();
126 dump_file_name = get_dump_file_name (index);
127 initializing_dump = !dump_initialized_p (index);
128 dump_file = dump_begin (index, NULL);
130 if (dump_file == NULL)
131 fatal_error ("can't open %s: %m", dump_file_name);
133 if (decl)
134 fprintf (dump_file, "\n;; Function %s%s\n\n",
135 lang_hooks.decl_printable_name (decl, 2),
136 cfun->function_frequency == FUNCTION_FREQUENCY_HOT
137 ? " (hot)"
138 : cfun->function_frequency == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED
139 ? " (unlikely executed)"
140 : "");
142 timevar_pop (TV_DUMP);
143 return 1;
146 /* Routine to close a dump file. */
148 static void
149 close_dump_file (enum tree_dump_index index,
150 void (*func) (FILE *, rtx),
151 rtx insns)
153 if (! dump_file)
154 return;
156 timevar_push (TV_DUMP);
157 if (insns
158 && graph_dump_format != no_graph)
160 /* If we've not initialized the files, do so now. */
161 if (initializing_dump)
162 clean_graph_dump_file (dump_file_name);
164 print_rtl_graph_with_bb (dump_file_name, insns);
167 if (func && insns)
168 func (dump_file, insns);
170 dump_end (index, dump_file);
171 free ((char *) dump_file_name);
173 dump_file = NULL;
174 dump_file_name = NULL;
175 timevar_pop (TV_DUMP);
178 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
179 and TYPE_DECL nodes.
181 This does nothing for local (non-static) variables, unless the
182 variable is a register variable with DECL_ASSEMBLER_NAME set. In
183 that case, or if the variable is not an automatic, it sets up the
184 RTL and outputs any assembler code (label definition, storage
185 allocation and initialization).
187 DECL is the declaration. TOP_LEVEL is nonzero
188 if this declaration is not within a function. */
190 void
191 rest_of_decl_compilation (tree decl,
192 int top_level,
193 int at_end)
195 /* We deferred calling assemble_alias so that we could collect
196 other attributes such as visibility. Emit the alias now. */
198 tree alias;
199 alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
200 if (alias)
202 alias = TREE_VALUE (TREE_VALUE (alias));
203 alias = get_identifier (TREE_STRING_POINTER (alias));
204 assemble_alias (decl, alias);
208 /* Can't defer this, because it needs to happen before any
209 later function definitions are processed. */
210 if (DECL_REGISTER (decl) && DECL_ASSEMBLER_NAME_SET_P (decl))
211 make_decl_rtl (decl);
213 /* Forward declarations for nested functions are not "external",
214 but we need to treat them as if they were. */
215 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
216 || TREE_CODE (decl) == FUNCTION_DECL)
218 timevar_push (TV_VARCONST);
220 /* Don't output anything when a tentative file-scope definition
221 is seen. But at end of compilation, do output code for them.
223 We do output all variables when unit-at-a-time is active and rely on
224 callgraph code to defer them except for forward declarations
225 (see gcc.c-torture/compile/920624-1.c) */
226 if ((at_end
227 || !DECL_DEFER_OUTPUT (decl)
228 || (flag_unit_at_a_time && DECL_INITIAL (decl)))
229 && !DECL_EXTERNAL (decl))
231 if (flag_unit_at_a_time && !cgraph_global_info_ready
232 && TREE_CODE (decl) != FUNCTION_DECL && top_level)
233 cgraph_varpool_finalize_decl (decl);
234 else
235 assemble_variable (decl, top_level, at_end, 0);
238 #ifdef ASM_FINISH_DECLARE_OBJECT
239 if (decl == last_assemble_variable_decl)
241 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
242 top_level, at_end);
244 #endif
246 timevar_pop (TV_VARCONST);
248 else if (TREE_CODE (decl) == TYPE_DECL)
250 timevar_push (TV_SYMOUT);
251 debug_hooks->type_decl (decl, !top_level);
252 timevar_pop (TV_SYMOUT);
255 /* Let cgraph know about the existance of variables. */
256 if (TREE_CODE (decl) == VAR_DECL && !DECL_EXTERNAL (decl))
257 cgraph_varpool_node (decl);
260 /* Called after finishing a record, union or enumeral type. */
262 void
263 rest_of_type_compilation (tree type, int toplev)
265 /* Avoid confusing the debug information machinery when there are
266 errors. */
267 if (errorcount != 0 || sorrycount != 0)
268 return;
270 timevar_push (TV_SYMOUT);
271 debug_hooks->type_decl (TYPE_STUB_DECL (type), !toplev);
272 timevar_pop (TV_SYMOUT);
275 /* Turn the RTL into assembly. */
276 static void
277 rest_of_handle_final (void)
279 timevar_push (TV_FINAL);
281 rtx x;
282 const char *fnname;
284 /* Get the function's name, as described by its RTL. This may be
285 different from the DECL_NAME name used in the source file. */
287 x = DECL_RTL (current_function_decl);
288 if (!MEM_P (x))
289 abort ();
290 x = XEXP (x, 0);
291 if (GET_CODE (x) != SYMBOL_REF)
292 abort ();
293 fnname = XSTR (x, 0);
295 assemble_start_function (current_function_decl, fnname);
296 final_start_function (get_insns (), asm_out_file, optimize);
297 final (get_insns (), asm_out_file, optimize, 0);
298 final_end_function ();
300 #ifdef TARGET_UNWIND_INFO
301 /* ??? The IA-64 ".handlerdata" directive must be issued before
302 the ".endp" directive that closes the procedure descriptor. */
303 output_function_exception_table ();
304 #endif
306 assemble_end_function (current_function_decl, fnname);
308 #ifndef TARGET_UNWIND_INFO
309 /* Otherwise, it feels unclean to switch sections in the middle. */
310 output_function_exception_table ();
311 #endif
313 user_defined_section_attribute = false;
315 if (! quiet_flag)
316 fflush (asm_out_file);
318 /* Release all memory allocated by flow. */
319 free_basic_block_vars ();
322 /* Write DBX symbols if requested. */
324 /* Note that for those inline functions where we don't initially
325 know for certain that we will be generating an out-of-line copy,
326 the first invocation of this routine (rest_of_compilation) will
327 skip over this code by doing a `goto exit_rest_of_compilation;'.
328 Later on, wrapup_global_declarations will (indirectly) call
329 rest_of_compilation again for those inline functions that need
330 to have out-of-line copies generated. During that call, we
331 *will* be routed past here. */
333 timevar_push (TV_SYMOUT);
334 (*debug_hooks->function_decl) (current_function_decl);
335 timevar_pop (TV_SYMOUT);
337 ggc_collect ();
338 timevar_pop (TV_FINAL);
341 #ifdef DELAY_SLOTS
342 /* Run delay slot optimization. */
343 static void
344 rest_of_handle_delay_slots (void)
346 timevar_push (TV_DBR_SCHED);
347 open_dump_file (DFI_dbr, current_function_decl);
349 dbr_schedule (get_insns (), dump_file);
351 close_dump_file (DFI_dbr, print_rtl, get_insns ());
353 ggc_collect ();
355 timevar_pop (TV_DBR_SCHED);
357 #endif
359 #ifdef STACK_REGS
360 /* Convert register usage from flat register file usage to a stack
361 register file. */
362 static void
363 rest_of_handle_stack_regs (void)
365 #if defined (HAVE_ATTR_length)
366 /* If flow2 creates new instructions which need splitting
367 and scheduling after reload is not done, they might not be
368 split until final which doesn't allow splitting
369 if HAVE_ATTR_length. */
370 #ifdef INSN_SCHEDULING
371 if (optimize && !flag_schedule_insns_after_reload)
372 #else
373 if (optimize)
374 #endif
376 timevar_push (TV_SHORTEN_BRANCH);
377 split_all_insns (1);
378 timevar_pop (TV_SHORTEN_BRANCH);
380 #endif
382 timevar_push (TV_REG_STACK);
383 open_dump_file (DFI_stack, current_function_decl);
385 if (reg_to_stack (dump_file) && optimize)
387 if (cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK
388 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0))
389 && (flag_reorder_blocks || flag_reorder_blocks_and_partition))
391 reorder_basic_blocks (0);
392 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK);
396 close_dump_file (DFI_stack, print_rtl_with_bb, get_insns ());
398 ggc_collect ();
399 timevar_pop (TV_REG_STACK);
401 #endif
403 /* Track the variables, i.e. compute where the variable is stored at each position in function. */
404 static void
405 rest_of_handle_variable_tracking (void)
407 timevar_push (TV_VAR_TRACKING);
408 open_dump_file (DFI_vartrack, current_function_decl);
410 variable_tracking_main ();
412 close_dump_file (DFI_vartrack, print_rtl_with_bb, get_insns ());
413 timevar_pop (TV_VAR_TRACKING);
416 /* Machine dependent reorg pass. */
417 static void
418 rest_of_handle_machine_reorg (void)
420 timevar_push (TV_MACH_DEP);
421 open_dump_file (DFI_mach, current_function_decl);
423 targetm.machine_dependent_reorg ();
425 close_dump_file (DFI_mach, print_rtl, get_insns ());
427 ggc_collect ();
428 timevar_pop (TV_MACH_DEP);
432 /* Run old register allocator. Return TRUE if we must exit
433 rest_of_compilation upon return. */
434 static bool
435 rest_of_handle_old_regalloc (void)
437 int failure;
438 int rebuild_notes;
440 timevar_push (TV_LOCAL_ALLOC);
441 open_dump_file (DFI_lreg, current_function_decl);
443 /* Allocate the reg_renumber array. */
444 allocate_reg_info (max_regno, FALSE, TRUE);
446 /* And the reg_equiv_memory_loc array. */
447 VARRAY_GROW (reg_equiv_memory_loc_varray, max_regno);
448 reg_equiv_memory_loc = &VARRAY_RTX (reg_equiv_memory_loc_varray, 0);
450 allocate_initial_values (reg_equiv_memory_loc);
452 regclass (get_insns (), max_reg_num (), dump_file);
453 rebuild_notes = local_alloc ();
455 timevar_pop (TV_LOCAL_ALLOC);
457 /* Local allocation may have turned an indirect jump into a direct
458 jump. If so, we must rebuild the JUMP_LABEL fields of jumping
459 instructions. */
460 if (rebuild_notes)
462 timevar_push (TV_JUMP);
464 rebuild_jump_labels (get_insns ());
465 purge_all_dead_edges (0);
466 delete_unreachable_blocks ();
468 timevar_pop (TV_JUMP);
471 if (dump_enabled_p (DFI_lreg))
473 timevar_push (TV_DUMP);
474 dump_flow_info (dump_file);
475 dump_local_alloc (dump_file);
476 timevar_pop (TV_DUMP);
479 close_dump_file (DFI_lreg, print_rtl_with_bb, get_insns ());
481 ggc_collect ();
483 timevar_push (TV_GLOBAL_ALLOC);
484 open_dump_file (DFI_greg, current_function_decl);
486 /* If optimizing, allocate remaining pseudo-regs. Do the reload
487 pass fixing up any insns that are invalid. */
489 if (optimize)
490 failure = global_alloc (dump_file);
491 else
493 build_insn_chain (get_insns ());
494 failure = reload (get_insns (), 0);
497 if (dump_enabled_p (DFI_greg))
499 timevar_push (TV_DUMP);
500 dump_global_regs (dump_file);
501 timevar_pop (TV_DUMP);
503 close_dump_file (DFI_greg, print_rtl_with_bb, get_insns ());
506 ggc_collect ();
508 timevar_pop (TV_GLOBAL_ALLOC);
510 return failure;
513 /* Run the regrename and cprop passes. */
514 static void
515 rest_of_handle_regrename (void)
517 timevar_push (TV_RENAME_REGISTERS);
518 open_dump_file (DFI_rnreg, current_function_decl);
520 if (flag_rename_registers)
521 regrename_optimize ();
522 if (flag_cprop_registers)
523 copyprop_hardreg_forward ();
525 close_dump_file (DFI_rnreg, print_rtl_with_bb, get_insns ());
526 timevar_pop (TV_RENAME_REGISTERS);
529 /* Reorder basic blocks. */
530 static void
531 rest_of_handle_reorder_blocks (void)
533 bool changed;
534 unsigned int liveness_flags;
536 open_dump_file (DFI_bbro, current_function_decl);
538 /* Last attempt to optimize CFG, as scheduling, peepholing and insn
539 splitting possibly introduced more crossjumping opportunities. */
540 liveness_flags = (!HAVE_conditional_execution ? CLEANUP_UPDATE_LIFE : 0);
541 changed = cleanup_cfg (CLEANUP_EXPENSIVE | liveness_flags);
543 if (flag_sched2_use_traces && flag_schedule_insns_after_reload)
544 tracer (liveness_flags);
545 if (flag_reorder_blocks || flag_reorder_blocks_and_partition)
546 reorder_basic_blocks (liveness_flags);
547 if (flag_reorder_blocks || flag_reorder_blocks_and_partition
548 || (flag_sched2_use_traces && flag_schedule_insns_after_reload))
549 changed |= cleanup_cfg (CLEANUP_EXPENSIVE | liveness_flags);
551 /* On conditional execution targets we can not update the life cheaply, so
552 we deffer the updating to after both cleanups. This may lose some cases
553 but should not be terribly bad. */
554 if (changed && HAVE_conditional_execution)
555 update_life_info (NULL, UPDATE_LIFE_GLOBAL_RM_NOTES,
556 PROP_DEATH_NOTES);
557 close_dump_file (DFI_bbro, print_rtl_with_bb, get_insns ());
560 /* Partition hot and cold basic blocks. */
561 static void
562 rest_of_handle_partition_blocks (void)
564 no_new_pseudos = 0;
565 partition_hot_cold_basic_blocks ();
566 allocate_reg_life_data ();
567 update_life_info (NULL, UPDATE_LIFE_GLOBAL_RM_NOTES,
568 PROP_LOG_LINKS | PROP_REG_INFO | PROP_DEATH_NOTES);
569 no_new_pseudos = 1;
572 #ifdef INSN_SCHEDULING
573 /* Run instruction scheduler. */
574 /* Perform SMS module scheduling. */
575 static void
576 rest_of_handle_sms (void)
578 timevar_push (TV_SMS);
579 open_dump_file (DFI_sms, current_function_decl);
581 /* We want to be able to create new pseudos. */
582 no_new_pseudos = 0;
583 sms_schedule (dump_file);
584 close_dump_file (DFI_sms, print_rtl, get_insns ());
587 /* Update the life information, because we add pseudos. */
588 max_regno = max_reg_num ();
589 allocate_reg_info (max_regno, FALSE, FALSE);
590 update_life_info_in_dirty_blocks (UPDATE_LIFE_GLOBAL_RM_NOTES,
591 (PROP_DEATH_NOTES
592 | PROP_KILL_DEAD_CODE
593 | PROP_SCAN_DEAD_CODE));
594 no_new_pseudos = 1;
596 ggc_collect ();
597 timevar_pop (TV_SMS);
600 /* Run instruction scheduler. */
601 static void
602 rest_of_handle_sched (void)
604 timevar_push (TV_SCHED);
606 /* Print function header into sched dump now
607 because doing the sched analysis makes some of the dump. */
608 open_dump_file (DFI_sched, current_function_decl);
610 /* Do control and data sched analysis,
611 and write some of the results to dump file. */
613 schedule_insns (dump_file);
615 close_dump_file (DFI_sched, print_rtl_with_bb, get_insns ());
617 ggc_collect ();
618 timevar_pop (TV_SCHED);
621 /* Run second scheduling pass after reload. */
622 static void
623 rest_of_handle_sched2 (void)
625 timevar_push (TV_SCHED2);
626 open_dump_file (DFI_sched2, current_function_decl);
628 /* Do control and data sched analysis again,
629 and write some more of the results to dump file. */
631 split_all_insns (1);
633 if (flag_sched2_use_superblocks || flag_sched2_use_traces)
635 schedule_ebbs (dump_file);
636 /* No liveness updating code yet, but it should be easy to do.
637 reg-stack recomputes the liveness when needed for now. */
638 count_or_remove_death_notes (NULL, 1);
639 cleanup_cfg (CLEANUP_EXPENSIVE);
641 else
642 schedule_insns (dump_file);
644 close_dump_file (DFI_sched2, print_rtl_with_bb, get_insns ());
646 ggc_collect ();
648 timevar_pop (TV_SCHED2);
650 #endif
652 static void
653 rest_of_handle_gcse2 (void)
655 timevar_push (TV_GCSE_AFTER_RELOAD);
656 open_dump_file (DFI_gcse2, current_function_decl);
658 gcse_after_reload_main (get_insns ());
659 rebuild_jump_labels (get_insns ());
660 delete_trivially_dead_insns (get_insns (), max_reg_num ());
661 close_dump_file (DFI_gcse2, print_rtl_with_bb, get_insns ());
663 ggc_collect ();
665 #ifdef ENABLE_CHECKING
666 verify_flow_info ();
667 #endif
669 timevar_pop (TV_GCSE_AFTER_RELOAD);
672 /* Register allocation pre-pass, to reduce number of moves necessary
673 for two-address machines. */
674 static void
675 rest_of_handle_regmove (void)
677 timevar_push (TV_REGMOVE);
678 open_dump_file (DFI_regmove, current_function_decl);
680 regmove_optimize (get_insns (), max_reg_num (), dump_file);
682 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
683 close_dump_file (DFI_regmove, print_rtl_with_bb, get_insns ());
685 ggc_collect ();
686 timevar_pop (TV_REGMOVE);
689 /* Run tracer. */
690 static void
691 rest_of_handle_tracer (void)
693 open_dump_file (DFI_tracer, current_function_decl);
694 if (dump_file)
695 dump_flow_info (dump_file);
696 tracer (0);
697 cleanup_cfg (CLEANUP_EXPENSIVE);
698 reg_scan (get_insns (), max_reg_num ());
699 close_dump_file (DFI_tracer, print_rtl_with_bb, get_insns ());
702 /* If-conversion and CFG cleanup. */
703 static void
704 rest_of_handle_if_conversion (void)
706 timevar_push (TV_IFCVT);
707 open_dump_file (DFI_ce1, current_function_decl);
709 if (flag_if_conversion)
711 if (dump_file)
712 dump_flow_info (dump_file);
713 cleanup_cfg (CLEANUP_EXPENSIVE);
714 reg_scan (get_insns (), max_reg_num ());
715 if_convert (0);
718 timevar_push (TV_JUMP);
719 cleanup_cfg (CLEANUP_EXPENSIVE);
720 reg_scan (get_insns (), max_reg_num ());
721 timevar_pop (TV_JUMP);
723 close_dump_file (DFI_ce1, print_rtl_with_bb, get_insns ());
724 timevar_pop (TV_IFCVT);
727 /* Rerun if-conversion, as combine may have simplified things enough
728 to now meet sequence length restrictions. */
729 static void
730 rest_of_handle_if_after_combine (void)
732 timevar_push (TV_IFCVT);
733 open_dump_file (DFI_ce2, current_function_decl);
735 no_new_pseudos = 0;
736 if_convert (1);
737 no_new_pseudos = 1;
739 close_dump_file (DFI_ce2, print_rtl_with_bb, get_insns ());
740 timevar_pop (TV_IFCVT);
743 static void
744 rest_of_handle_if_after_reload (void)
746 timevar_push (TV_IFCVT2);
747 open_dump_file (DFI_ce3, current_function_decl);
749 /* Last attempt to optimize CFG, as scheduling, peepholing and insn
750 splitting possibly introduced more crossjumping opportunities. */
751 cleanup_cfg (CLEANUP_EXPENSIVE
752 | CLEANUP_UPDATE_LIFE
753 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0));
754 if (flag_if_conversion2)
755 if_convert (1);
756 close_dump_file (DFI_ce3, print_rtl_with_bb, get_insns ());
757 timevar_pop (TV_IFCVT2);
760 static void
761 rest_of_handle_web (void)
763 open_dump_file (DFI_web, current_function_decl);
764 timevar_push (TV_WEB);
765 web_main ();
766 delete_trivially_dead_insns (get_insns (), max_reg_num ());
767 cleanup_cfg (CLEANUP_EXPENSIVE);
769 timevar_pop (TV_WEB);
770 close_dump_file (DFI_web, print_rtl_with_bb, get_insns ());
771 reg_scan (get_insns (), max_reg_num ());
774 /* Do branch profiling and static profile estimation passes. */
775 static void
776 rest_of_handle_branch_prob (void)
778 struct loops loops;
780 timevar_push (TV_BRANCH_PROB);
781 open_dump_file (DFI_bp, current_function_decl);
783 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
784 branch_prob ();
786 /* Discover and record the loop depth at the head of each basic
787 block. The loop infrastructure does the real job for us. */
788 flow_loops_find (&loops);
790 if (dump_file)
791 flow_loops_dump (&loops, dump_file, NULL, 0);
793 /* Estimate using heuristics if no profiling info is available. */
794 if (flag_guess_branch_prob)
795 estimate_probability (&loops);
797 flow_loops_free (&loops);
798 free_dominance_info (CDI_DOMINATORS);
799 close_dump_file (DFI_bp, print_rtl_with_bb, get_insns ());
800 timevar_pop (TV_BRANCH_PROB);
803 /* Do optimizations based on expression value profiles. */
804 static void
805 rest_of_handle_value_profile_transformations (void)
807 open_dump_file (DFI_vpt, current_function_decl);
808 timevar_push (TV_VPT);
810 if (value_profile_transformations ())
811 cleanup_cfg (CLEANUP_EXPENSIVE);
813 timevar_pop (TV_VPT);
814 close_dump_file (DFI_vpt, print_rtl_with_bb, get_insns ());
817 /* Do control and data flow analysis; write some of the results to the
818 dump file. */
819 static void
820 rest_of_handle_cfg (void)
822 open_dump_file (DFI_cfg, current_function_decl);
823 if (dump_file)
824 dump_flow_info (dump_file);
825 if (optimize)
826 cleanup_cfg (CLEANUP_EXPENSIVE
827 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
829 /* It may make more sense to mark constant functions after dead code is
830 eliminated by life_analysis, but we need to do it early, as -fprofile-arcs
831 may insert code making function non-constant, but we still must consider
832 it as constant, otherwise -fbranch-probabilities will not read data back.
834 life_analysis rarely eliminates modification of external memory.
836 FIXME: now with tree based profiling we are in the trap described above
837 again. It seems to be easiest to disable the optimization for time
838 being before the problem is either solved by moving the transformation
839 to the IPA level (we need the CFG for this) or the very early optimization
840 passes are made to ignore the const/pure flags so code does not change. */
841 if (optimize
842 && (!flag_tree_based_profiling
843 || (!profile_arc_flag && !flag_branch_probabilities)))
845 /* Alias analysis depends on this information and mark_constant_function
846 depends on alias analysis. */
847 reg_scan (get_insns (), max_reg_num ());
848 mark_constant_function ();
851 close_dump_file (DFI_cfg, print_rtl_with_bb, get_insns ());
854 /* Perform jump bypassing and control flow optimizations. */
855 static void
856 rest_of_handle_jump_bypass (void)
858 timevar_push (TV_BYPASS);
859 open_dump_file (DFI_bypass, current_function_decl);
861 cleanup_cfg (CLEANUP_EXPENSIVE);
862 reg_scan (get_insns (), max_reg_num ());
864 if (bypass_jumps (dump_file))
866 rebuild_jump_labels (get_insns ());
867 cleanup_cfg (CLEANUP_EXPENSIVE);
868 delete_trivially_dead_insns (get_insns (), max_reg_num ());
871 close_dump_file (DFI_bypass, print_rtl_with_bb, get_insns ());
872 timevar_pop (TV_BYPASS);
874 ggc_collect ();
876 #ifdef ENABLE_CHECKING
877 verify_flow_info ();
878 #endif
881 /* Try combining insns through substitution. */
882 static void
883 rest_of_handle_combine (void)
885 int rebuild_jump_labels_after_combine = 0;
887 timevar_push (TV_COMBINE);
888 open_dump_file (DFI_combine, current_function_decl);
890 rebuild_jump_labels_after_combine
891 = combine_instructions (get_insns (), max_reg_num ());
893 /* Combining insns may have turned an indirect jump into a
894 direct jump. Rebuild the JUMP_LABEL fields of jumping
895 instructions. */
896 if (rebuild_jump_labels_after_combine)
898 timevar_push (TV_JUMP);
899 rebuild_jump_labels (get_insns ());
900 timevar_pop (TV_JUMP);
902 delete_dead_jumptables ();
903 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
906 close_dump_file (DFI_combine, print_rtl_with_bb, get_insns ());
907 timevar_pop (TV_COMBINE);
909 ggc_collect ();
912 /* Perform life analysis. */
913 static void
914 rest_of_handle_life (void)
916 open_dump_file (DFI_life, current_function_decl);
917 regclass_init ();
919 #ifdef ENABLE_CHECKING
920 verify_flow_info ();
921 #endif
922 life_analysis (dump_file, PROP_FINAL);
923 if (optimize)
924 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE | CLEANUP_LOG_LINKS
925 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
927 if (extra_warnings)
929 setjmp_vars_warning (DECL_INITIAL (current_function_decl));
930 setjmp_args_warning ();
933 if (optimize)
935 if (initialize_uninitialized_subregs ())
937 /* Insns were inserted, and possibly pseudos created, so
938 things might look a bit different. */
939 allocate_reg_life_data ();
940 update_life_info (NULL, UPDATE_LIFE_GLOBAL_RM_NOTES,
941 PROP_LOG_LINKS | PROP_REG_INFO | PROP_DEATH_NOTES);
945 no_new_pseudos = 1;
947 close_dump_file (DFI_life, print_rtl_with_bb, get_insns ());
949 ggc_collect ();
952 /* Perform common subexpression elimination. Nonzero value from
953 `cse_main' means that jumps were simplified and some code may now
954 be unreachable, so do jump optimization again. */
955 static void
956 rest_of_handle_cse (void)
958 int tem;
960 open_dump_file (DFI_cse, current_function_decl);
961 if (dump_file)
962 dump_flow_info (dump_file);
963 timevar_push (TV_CSE);
965 reg_scan (get_insns (), max_reg_num ());
967 tem = cse_main (get_insns (), max_reg_num (), dump_file);
968 if (tem)
969 rebuild_jump_labels (get_insns ());
970 if (purge_all_dead_edges (0))
971 delete_unreachable_blocks ();
973 delete_trivially_dead_insns (get_insns (), max_reg_num ());
975 /* If we are not running more CSE passes, then we are no longer
976 expecting CSE to be run. But always rerun it in a cheap mode. */
977 cse_not_expected = !flag_rerun_cse_after_loop && !flag_gcse;
979 if (tem)
980 delete_dead_jumptables ();
982 if (tem || optimize > 1)
983 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
985 timevar_pop (TV_CSE);
986 close_dump_file (DFI_cse, print_rtl_with_bb, get_insns ());
988 ggc_collect ();
991 /* Run second CSE pass after loop optimizations. */
992 static void
993 rest_of_handle_cse2 (void)
995 int tem;
997 timevar_push (TV_CSE2);
998 open_dump_file (DFI_cse2, current_function_decl);
999 if (dump_file)
1000 dump_flow_info (dump_file);
1001 /* CFG is no longer maintained up-to-date. */
1002 tem = cse_main (get_insns (), max_reg_num (), dump_file);
1004 /* Run a pass to eliminate duplicated assignments to condition code
1005 registers. We have to run this after bypass_jumps, because it
1006 makes it harder for that pass to determine whether a jump can be
1007 bypassed safely. */
1008 cse_condition_code_reg ();
1010 purge_all_dead_edges (0);
1011 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1013 if (tem)
1015 timevar_push (TV_JUMP);
1016 rebuild_jump_labels (get_insns ());
1017 delete_dead_jumptables ();
1018 cleanup_cfg (CLEANUP_EXPENSIVE);
1019 timevar_pop (TV_JUMP);
1021 reg_scan (get_insns (), max_reg_num ());
1022 close_dump_file (DFI_cse2, print_rtl_with_bb, get_insns ());
1023 timevar_pop (TV_CSE2);
1025 ggc_collect ();
1028 /* Perform global cse. */
1029 static void
1030 rest_of_handle_gcse (void)
1032 int save_csb, save_cfj;
1033 int tem2 = 0, tem;
1035 timevar_push (TV_GCSE);
1036 open_dump_file (DFI_gcse, current_function_decl);
1038 tem = gcse_main (get_insns (), dump_file);
1039 rebuild_jump_labels (get_insns ());
1040 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1042 save_csb = flag_cse_skip_blocks;
1043 save_cfj = flag_cse_follow_jumps;
1044 flag_cse_skip_blocks = flag_cse_follow_jumps = 0;
1046 /* If -fexpensive-optimizations, re-run CSE to clean up things done
1047 by gcse. */
1048 if (flag_expensive_optimizations)
1050 timevar_push (TV_CSE);
1051 reg_scan (get_insns (), max_reg_num ());
1052 tem2 = cse_main (get_insns (), max_reg_num (), dump_file);
1053 purge_all_dead_edges (0);
1054 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1055 timevar_pop (TV_CSE);
1056 cse_not_expected = !flag_rerun_cse_after_loop;
1059 /* If gcse or cse altered any jumps, rerun jump optimizations to clean
1060 things up. */
1061 if (tem || tem2)
1063 timevar_push (TV_JUMP);
1064 rebuild_jump_labels (get_insns ());
1065 delete_dead_jumptables ();
1066 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
1067 timevar_pop (TV_JUMP);
1070 close_dump_file (DFI_gcse, print_rtl_with_bb, get_insns ());
1071 timevar_pop (TV_GCSE);
1073 ggc_collect ();
1074 flag_cse_skip_blocks = save_csb;
1075 flag_cse_follow_jumps = save_cfj;
1076 #ifdef ENABLE_CHECKING
1077 verify_flow_info ();
1078 #endif
1081 /* Move constant computations out of loops. */
1082 static void
1083 rest_of_handle_loop_optimize (void)
1085 int do_prefetch;
1087 timevar_push (TV_LOOP);
1088 open_dump_file (DFI_loop, current_function_decl);
1090 /* CFG is no longer maintained up-to-date. */
1091 free_bb_for_insn ();
1092 profile_status = PROFILE_ABSENT;
1094 do_prefetch = flag_prefetch_loop_arrays ? LOOP_PREFETCH : 0;
1096 if (flag_rerun_loop_opt)
1098 cleanup_barriers ();
1100 /* We only want to perform unrolling once. */
1101 loop_optimize (get_insns (), dump_file, 0);
1103 /* The first call to loop_optimize makes some instructions
1104 trivially dead. We delete those instructions now in the
1105 hope that doing so will make the heuristics in loop work
1106 better and possibly speed up compilation. */
1107 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1109 /* The regscan pass is currently necessary as the alias
1110 analysis code depends on this information. */
1111 reg_scan (get_insns (), max_reg_num ());
1113 cleanup_barriers ();
1114 loop_optimize (get_insns (), dump_file, do_prefetch);
1116 /* Loop can create trivially dead instructions. */
1117 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1118 find_basic_blocks (get_insns ());
1119 close_dump_file (DFI_loop, print_rtl, get_insns ());
1120 timevar_pop (TV_LOOP);
1122 ggc_collect ();
1125 /* Perform loop optimizations. It might be better to do them a bit
1126 sooner, but we want the profile feedback to work more
1127 efficiently. */
1128 static void
1129 rest_of_handle_loop2 (void)
1131 struct loops *loops;
1132 basic_block bb;
1134 if (!flag_move_loop_invariants
1135 && !flag_unswitch_loops
1136 && !flag_peel_loops
1137 && !flag_unroll_loops
1138 && !flag_branch_on_count_reg)
1139 return;
1141 timevar_push (TV_LOOP);
1142 open_dump_file (DFI_loop2, current_function_decl);
1143 if (dump_file)
1144 dump_flow_info (dump_file);
1146 /* Initialize structures for layout changes. */
1147 cfg_layout_initialize (0);
1149 loops = loop_optimizer_init (dump_file);
1151 if (loops)
1153 /* The optimizations: */
1154 if (flag_move_loop_invariants)
1155 move_loop_invariants (loops);
1157 if (flag_unswitch_loops)
1158 unswitch_loops (loops);
1160 if (flag_peel_loops || flag_unroll_loops)
1161 unroll_and_peel_loops (loops,
1162 (flag_peel_loops ? UAP_PEEL : 0) |
1163 (flag_unroll_loops ? UAP_UNROLL : 0) |
1164 (flag_unroll_all_loops ? UAP_UNROLL_ALL : 0));
1166 #ifdef HAVE_doloop_end
1167 if (flag_branch_on_count_reg && HAVE_doloop_end)
1168 doloop_optimize_loops (loops);
1169 #endif /* HAVE_doloop_end */
1171 loop_optimizer_finalize (loops, dump_file);
1174 free_dominance_info (CDI_DOMINATORS);
1176 /* Finalize layout changes. */
1177 FOR_EACH_BB (bb)
1178 if (bb->next_bb != EXIT_BLOCK_PTR)
1179 bb->rbi->next = bb->next_bb;
1180 cfg_layout_finalize ();
1182 cleanup_cfg (CLEANUP_EXPENSIVE);
1183 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1184 reg_scan (get_insns (), max_reg_num ());
1185 if (dump_file)
1186 dump_flow_info (dump_file);
1187 close_dump_file (DFI_loop2, print_rtl_with_bb, get_insns ());
1188 timevar_pop (TV_LOOP);
1189 ggc_collect ();
1192 static void
1193 rest_of_handle_branch_target_load_optimize (void)
1195 static int warned = 0;
1197 /* Leave this a warning for now so that it is possible to experiment
1198 with running this pass twice. In 3.6, we should either make this
1199 an error, or use separate dump files. */
1200 if (flag_branch_target_load_optimize
1201 && flag_branch_target_load_optimize2
1202 && !warned)
1204 warning ("branch target register load optimization is not intended "
1205 "to be run twice");
1207 warned = 1;
1210 open_dump_file (DFI_branch_target_load, current_function_decl);
1211 branch_target_load_optimize (epilogue_completed);
1212 close_dump_file (DFI_branch_target_load, print_rtl_with_bb, get_insns ());
1213 ggc_collect ();
1216 #ifdef OPTIMIZE_MODE_SWITCHING
1217 static void
1218 rest_of_handle_mode_switching (void)
1220 timevar_push (TV_MODE_SWITCH);
1222 no_new_pseudos = 0;
1223 optimize_mode_switching (NULL);
1224 no_new_pseudos = 1;
1226 timevar_pop (TV_MODE_SWITCH);
1228 #endif
1230 static void
1231 rest_of_handle_jump (void)
1233 ggc_collect ();
1235 timevar_push (TV_JUMP);
1236 open_dump_file (DFI_sibling, current_function_decl);
1238 delete_unreachable_blocks ();
1239 #ifdef ENABLE_CHECKING
1240 verify_flow_info ();
1241 #endif
1243 if (cfun->tail_call_emit)
1244 fixup_tail_calls ();
1246 close_dump_file (DFI_sibling, print_rtl, get_insns ());
1247 timevar_pop (TV_JUMP);
1250 static void
1251 rest_of_handle_eh (void)
1253 insn_locators_initialize ();
1254 /* Complete generation of exception handling code. */
1255 if (doing_eh (0))
1257 timevar_push (TV_JUMP);
1258 open_dump_file (DFI_eh, current_function_decl);
1260 cleanup_cfg (CLEANUP_PRE_LOOP | CLEANUP_NO_INSN_DEL);
1262 finish_eh_generation ();
1264 cleanup_cfg (CLEANUP_PRE_LOOP | CLEANUP_NO_INSN_DEL);
1266 close_dump_file (DFI_eh, print_rtl, get_insns ());
1267 timevar_pop (TV_JUMP);
1271 static void
1272 rest_of_handle_stack_adjustments (void)
1274 life_analysis (dump_file, PROP_POSTRELOAD);
1275 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE
1276 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0));
1278 /* This is kind of a heuristic. We need to run combine_stack_adjustments
1279 even for machines with possibly nonzero RETURN_POPS_ARGS
1280 and ACCUMULATE_OUTGOING_ARGS. We expect that only ports having
1281 push instructions will have popping returns. */
1282 #ifndef PUSH_ROUNDING
1283 if (!ACCUMULATE_OUTGOING_ARGS)
1284 #endif
1285 combine_stack_adjustments ();
1288 static void
1289 rest_of_handle_flow2 (void)
1291 timevar_push (TV_FLOW2);
1292 open_dump_file (DFI_flow2, current_function_decl);
1294 /* Re-create the death notes which were deleted during reload. */
1295 #ifdef ENABLE_CHECKING
1296 verify_flow_info ();
1297 #endif
1299 /* If optimizing, then go ahead and split insns now. */
1300 #ifndef STACK_REGS
1301 if (optimize > 0)
1302 #endif
1303 split_all_insns (0);
1305 if (flag_branch_target_load_optimize)
1307 close_dump_file (DFI_flow2, print_rtl_with_bb, get_insns ());
1308 rest_of_handle_branch_target_load_optimize ();
1309 open_dump_file (DFI_flow2, current_function_decl);
1312 if (optimize)
1313 cleanup_cfg (CLEANUP_EXPENSIVE);
1315 /* On some machines, the prologue and epilogue code, or parts thereof,
1316 can be represented as RTL. Doing so lets us schedule insns between
1317 it and the rest of the code and also allows delayed branch
1318 scheduling to operate in the epilogue. */
1319 thread_prologue_and_epilogue_insns (get_insns ());
1320 epilogue_completed = 1;
1322 if (optimize)
1323 rest_of_handle_stack_adjustments ();
1325 flow2_completed = 1;
1327 close_dump_file (DFI_flow2, print_rtl_with_bb, get_insns ());
1328 timevar_pop (TV_FLOW2);
1330 ggc_collect ();
1334 static void
1335 rest_of_handle_jump2 (void)
1337 open_dump_file (DFI_jump, current_function_decl);
1339 /* Always do one jump optimization pass to ensure that JUMP_LABEL fields
1340 are initialized and to compute whether control can drop off the end
1341 of the function. */
1343 timevar_push (TV_JUMP);
1344 /* Turn NOTE_INSN_EXPECTED_VALUE into REG_BR_PROB. Do this
1345 before jump optimization switches branch directions. */
1346 if (flag_guess_branch_prob)
1347 expected_value_to_br_prob ();
1349 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1350 reg_scan (get_insns (), max_reg_num ());
1351 if (dump_file)
1352 dump_flow_info (dump_file);
1353 cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_PRE_LOOP
1354 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
1356 create_loop_notes ();
1358 purge_line_number_notes (get_insns ());
1360 if (optimize)
1361 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
1363 /* Jump optimization, and the removal of NULL pointer checks, may
1364 have reduced the number of instructions substantially. CSE, and
1365 future passes, allocate arrays whose dimensions involve the
1366 maximum instruction UID, so if we can reduce the maximum UID
1367 we'll save big on memory. */
1368 renumber_insns (dump_file);
1370 close_dump_file (DFI_jump, print_rtl_with_bb, get_insns ());
1371 timevar_pop (TV_JUMP);
1373 ggc_collect ();
1376 #ifdef HAVE_peephole2
1377 static void
1378 rest_of_handle_peephole2 (void)
1380 timevar_push (TV_PEEPHOLE2);
1381 open_dump_file (DFI_peephole2, current_function_decl);
1383 peephole2_optimize (dump_file);
1385 close_dump_file (DFI_peephole2, print_rtl_with_bb, get_insns ());
1386 timevar_pop (TV_PEEPHOLE2);
1388 #endif
1390 static void
1391 rest_of_handle_postreload (void)
1393 timevar_push (TV_RELOAD_CSE_REGS);
1394 open_dump_file (DFI_postreload, current_function_decl);
1396 /* Do a very simple CSE pass over just the hard registers. */
1397 reload_cse_regs (get_insns ());
1398 /* reload_cse_regs can eliminate potentially-trapping MEMs.
1399 Remove any EH edges associated with them. */
1400 if (flag_non_call_exceptions)
1401 purge_all_dead_edges (0);
1403 close_dump_file (DFI_postreload, print_rtl_with_bb, get_insns ());
1404 timevar_pop (TV_RELOAD_CSE_REGS);
1407 static void
1408 rest_of_handle_shorten_branches (void)
1410 /* Shorten branches. */
1411 timevar_push (TV_SHORTEN_BRANCH);
1412 shorten_branches (get_insns ());
1413 timevar_pop (TV_SHORTEN_BRANCH);
1416 static void
1417 rest_of_clean_state (void)
1419 rtx insn, next;
1420 coverage_end_function ();
1422 /* It is very important to decompose the RTL instruction chain here:
1423 debug information keeps pointing into CODE_LABEL insns inside the function
1424 body. If these remain pointing to the other insns, we end up preserving
1425 whole RTL chain and attached detailed debug info in memory. */
1426 for (insn = get_insns (); insn; insn = next)
1428 next = NEXT_INSN (insn);
1429 NEXT_INSN (insn) = NULL;
1430 PREV_INSN (insn) = NULL;
1433 /* In case the function was not output,
1434 don't leave any temporary anonymous types
1435 queued up for sdb output. */
1436 #ifdef SDB_DEBUGGING_INFO
1437 if (write_symbols == SDB_DEBUG)
1438 sdbout_types (NULL_TREE);
1439 #endif
1441 reload_completed = 0;
1442 epilogue_completed = 0;
1443 flow2_completed = 0;
1444 no_new_pseudos = 0;
1446 timevar_push (TV_FINAL);
1448 /* Clear out the insn_length contents now that they are no
1449 longer valid. */
1450 init_insn_lengths ();
1452 /* Show no temporary slots allocated. */
1453 init_temp_slots ();
1455 free_basic_block_vars ();
1456 free_bb_for_insn ();
1458 timevar_pop (TV_FINAL);
1460 if (targetm.binds_local_p (current_function_decl))
1462 int pref = cfun->preferred_stack_boundary;
1463 if (cfun->stack_alignment_needed > cfun->preferred_stack_boundary)
1464 pref = cfun->stack_alignment_needed;
1465 cgraph_rtl_info (current_function_decl)->preferred_incoming_stack_boundary
1466 = pref;
1469 /* Make sure volatile mem refs aren't considered valid operands for
1470 arithmetic insns. We must call this here if this is a nested inline
1471 function, since the above code leaves us in the init_recog state
1472 (from final.c), and the function context push/pop code does not
1473 save/restore volatile_ok.
1475 ??? Maybe it isn't necessary for expand_start_function to call this
1476 anymore if we do it here? */
1478 init_recog_no_volatile ();
1480 /* We're done with this function. Free up memory if we can. */
1481 free_after_parsing (cfun);
1482 free_after_compilation (cfun);
1486 /* This function is called from the pass manager in tree-optimize.c
1487 after all tree passes have finished for a single function, and we
1488 have expanded the function body from trees to RTL.
1489 Once we are here, we have decided that we're supposed to output
1490 that function, i.e. that we should write assembler code for it.
1492 We run a series of low-level passes here on the function's RTL
1493 representation. Each pass is called via a rest_of_* function. */
1495 static void
1496 rest_of_compilation (void)
1498 /* If we're emitting a nested function, make sure its parent gets
1499 emitted as well. Doing otherwise confuses debug info. */
1501 tree parent;
1502 for (parent = DECL_CONTEXT (current_function_decl);
1503 parent != NULL_TREE;
1504 parent = get_containing_scope (parent))
1505 if (TREE_CODE (parent) == FUNCTION_DECL)
1506 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (parent)) = 1;
1509 /* We are now committed to emitting code for this function. Do any
1510 preparation, such as emitting abstract debug info for the inline
1511 before it gets mangled by optimization. */
1512 if (cgraph_function_possibly_inlined_p (current_function_decl))
1513 (*debug_hooks->outlining_inline_function) (current_function_decl);
1515 /* Remove any notes we don't need. That will make iterating
1516 over the instruction sequence faster, and allow the garbage
1517 collector to reclaim the memory used by the notes. */
1518 remove_unnecessary_notes ();
1520 /* Initialize some variables used by the optimizers. */
1521 init_function_for_compilation ();
1523 TREE_ASM_WRITTEN (current_function_decl) = 1;
1525 /* Early return if there were errors. We can run afoul of our
1526 consistency checks, and there's not really much point in fixing them. */
1527 if (rtl_dump_and_exit || flag_syntax_only || errorcount || sorrycount)
1528 goto exit_rest_of_compilation;
1530 rest_of_handle_jump ();
1532 rest_of_handle_eh ();
1534 /* Delay emitting hard_reg_initial_value sets until after EH landing pad
1535 generation, which might create new sets. */
1536 emit_initial_value_sets ();
1538 #ifdef FINALIZE_PIC
1539 /* If we are doing position-independent code generation, now
1540 is the time to output special prologues and epilogues.
1541 We do not want to do this earlier, because it just clutters
1542 up inline functions with meaningless insns. */
1543 if (flag_pic)
1544 FINALIZE_PIC;
1545 #endif
1547 /* Copy any shared structure that should not be shared. */
1548 unshare_all_rtl ();
1550 #ifdef SETJMP_VIA_SAVE_AREA
1551 /* This must be performed before virtual register instantiation.
1552 Please be aware that everything in the compiler that can look
1553 at the RTL up to this point must understand that REG_SAVE_AREA
1554 is just like a use of the REG contained inside. */
1555 if (current_function_calls_alloca)
1556 optimize_save_area_alloca ();
1557 #endif
1559 /* Instantiate all virtual registers. */
1560 instantiate_virtual_regs ();
1562 rest_of_handle_jump2 ();
1564 if (optimize > 0)
1565 rest_of_handle_cse ();
1567 if (optimize > 0)
1569 if (flag_gcse)
1570 rest_of_handle_gcse ();
1572 if (flag_loop_optimize)
1573 rest_of_handle_loop_optimize ();
1575 if (flag_gcse)
1576 rest_of_handle_jump_bypass ();
1579 timevar_push (TV_FLOW);
1580 rest_of_handle_cfg ();
1582 if (!flag_tree_based_profiling
1583 && (optimize > 0 || profile_arc_flag
1584 || flag_test_coverage || flag_branch_probabilities))
1586 rtl_register_profile_hooks ();
1587 rtl_register_value_prof_hooks ();
1588 rest_of_handle_branch_prob ();
1590 if (flag_branch_probabilities
1591 && flag_profile_values
1592 && (flag_value_profile_transformations
1593 || flag_speculative_prefetching))
1594 rest_of_handle_value_profile_transformations ();
1596 /* Remove the death notes created for vpt. */
1597 if (flag_profile_values)
1598 count_or_remove_death_notes (NULL, 1);
1601 if (optimize > 0)
1602 rest_of_handle_if_conversion ();
1604 if (optimize > 0 && flag_tracer)
1605 rest_of_handle_tracer ();
1607 if (optimize > 0
1608 && flag_loop_optimize2)
1609 rest_of_handle_loop2 ();
1611 if (optimize > 0 && flag_web)
1612 rest_of_handle_web ();
1614 if (optimize > 0 && flag_rerun_cse_after_loop)
1615 rest_of_handle_cse2 ();
1617 cse_not_expected = 1;
1619 rest_of_handle_life ();
1620 timevar_pop (TV_FLOW);
1622 if (optimize > 0)
1623 rest_of_handle_combine ();
1625 if (optimize > 0 && flag_if_conversion)
1626 rest_of_handle_if_after_combine ();
1628 /* The optimization to partition hot/cold basic blocks into separate
1629 sections of the .o file does not work well with linkonce or with
1630 user defined section attributes. Don't call it if either case
1631 arises. */
1633 if (flag_reorder_blocks_and_partition
1634 && !DECL_ONE_ONLY (current_function_decl)
1635 && !user_defined_section_attribute)
1636 rest_of_handle_partition_blocks ();
1638 if (optimize > 0 && flag_regmove)
1639 rest_of_handle_regmove ();
1641 /* Do unconditional splitting before register allocation to allow machine
1642 description to add extra information not needed previously. */
1643 split_all_insns (1);
1645 #ifdef OPTIMIZE_MODE_SWITCHING
1646 rest_of_handle_mode_switching ();
1647 #endif
1649 /* Any of the several passes since flow1 will have munged register
1650 lifetime data a bit. We need it to be up to date for scheduling
1651 (see handling of reg_known_equiv in init_alias_analysis). */
1652 recompute_reg_usage ();
1654 #ifdef INSN_SCHEDULING
1655 if (optimize > 0 && flag_modulo_sched)
1656 rest_of_handle_sms ();
1658 if (flag_schedule_insns)
1659 rest_of_handle_sched ();
1660 #endif
1662 /* Determine if the current function is a leaf before running reload
1663 since this can impact optimizations done by the prologue and
1664 epilogue thus changing register elimination offsets. */
1665 current_function_is_leaf = leaf_function_p ();
1667 if (rest_of_handle_old_regalloc ())
1668 goto exit_rest_of_compilation;
1670 if (optimize > 0)
1671 rest_of_handle_postreload ();
1673 if (optimize > 0 && flag_gcse_after_reload)
1674 rest_of_handle_gcse2 ();
1676 rest_of_handle_flow2 ();
1678 #ifdef HAVE_peephole2
1679 if (optimize > 0 && flag_peephole2)
1680 rest_of_handle_peephole2 ();
1681 #endif
1683 if (optimize > 0)
1684 rest_of_handle_if_after_reload ();
1686 if (optimize > 0)
1688 if (flag_rename_registers || flag_cprop_registers)
1689 rest_of_handle_regrename ();
1691 rest_of_handle_reorder_blocks ();
1694 if (flag_branch_target_load_optimize2)
1695 rest_of_handle_branch_target_load_optimize ();
1697 #ifdef LEAF_REGISTERS
1698 current_function_uses_only_leaf_regs
1699 = optimize > 0 && only_leaf_regs_used () && leaf_function_p ();
1700 #endif
1702 #ifdef INSN_SCHEDULING
1703 if (optimize > 0 && flag_schedule_insns_after_reload)
1704 rest_of_handle_sched2 ();
1705 #endif
1707 #ifdef STACK_REGS
1708 rest_of_handle_stack_regs ();
1709 #endif
1711 compute_alignments ();
1713 /* Aggressively duplicate basic blocks ending in computed gotos to the
1714 tails of their predecessors, unless we are optimizing for size. */
1715 if (flag_expensive_optimizations && !optimize_size)
1716 duplicate_computed_gotos ();
1718 if (flag_var_tracking)
1719 rest_of_handle_variable_tracking ();
1721 /* CFG is no longer maintained up-to-date. */
1722 free_bb_for_insn ();
1724 if (targetm.machine_dependent_reorg != 0)
1725 rest_of_handle_machine_reorg ();
1727 purge_line_number_notes (get_insns ());
1728 cleanup_barriers ();
1730 #ifdef DELAY_SLOTS
1731 if (flag_delayed_branch)
1732 rest_of_handle_delay_slots ();
1733 #endif
1735 #if defined (HAVE_ATTR_length) && !defined (STACK_REGS)
1736 timevar_push (TV_SHORTEN_BRANCH);
1737 split_all_insns_noflow ();
1738 timevar_pop (TV_SHORTEN_BRANCH);
1739 #endif
1741 convert_to_eh_region_ranges ();
1743 rest_of_handle_shorten_branches ();
1745 set_nothrow_function_flags ();
1747 rest_of_handle_final ();
1749 exit_rest_of_compilation:
1751 rest_of_clean_state ();
1754 void
1755 finish_optimization_passes (void)
1757 enum tree_dump_index i;
1758 struct dump_file_info *dfi;
1759 char *name;
1761 timevar_push (TV_DUMP);
1762 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
1764 open_dump_file (DFI_bp, NULL);
1765 end_branch_prob ();
1766 close_dump_file (DFI_bp, NULL, NULL_RTX);
1769 if (optimize > 0 && open_dump_file (DFI_combine, NULL))
1771 dump_combine_total_stats (dump_file);
1772 close_dump_file (DFI_combine, NULL, NULL_RTX);
1775 /* Do whatever is necessary to finish printing the graphs. */
1776 if (graph_dump_format != no_graph)
1777 for (i = DFI_MIN; (dfi = get_dump_file_info (i)) != NULL; ++i)
1778 if (dump_initialized_p (i)
1779 && (dfi->flags & TDF_RTL) != 0
1780 && (name = get_dump_file_name (i)) != NULL)
1782 finish_graph_dump_file (name);
1783 free (name);
1786 timevar_pop (TV_DUMP);
1789 struct tree_opt_pass pass_rest_of_compilation =
1791 NULL, /* name */
1792 NULL, /* gate */
1793 rest_of_compilation, /* execute */
1794 NULL, /* sub */
1795 NULL, /* next */
1796 0, /* static_pass_number */
1797 TV_REST_OF_COMPILATION, /* tv_id */
1798 PROP_rtl, /* properties_required */
1799 0, /* properties_provided */
1800 PROP_rtl, /* properties_destroyed */
1801 0, /* todo_flags_start */
1802 TODO_ggc_collect, /* todo_flags_finish */
1803 0 /* letter */