Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / gcc / passes.c
blob956885ab7171fe8e67009509c379bbb2387dd605
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);
256 /* Called after finishing a record, union or enumeral type. */
258 void
259 rest_of_type_compilation (tree type, int toplev)
261 /* Avoid confusing the debug information machinery when there are
262 errors. */
263 if (errorcount != 0 || sorrycount != 0)
264 return;
266 timevar_push (TV_SYMOUT);
267 debug_hooks->type_decl (TYPE_STUB_DECL (type), !toplev);
268 timevar_pop (TV_SYMOUT);
271 /* Turn the RTL into assembly. */
272 static void
273 rest_of_handle_final (void)
275 timevar_push (TV_FINAL);
277 rtx x;
278 const char *fnname;
280 /* Get the function's name, as described by its RTL. This may be
281 different from the DECL_NAME name used in the source file. */
283 x = DECL_RTL (current_function_decl);
284 if (!MEM_P (x))
285 abort ();
286 x = XEXP (x, 0);
287 if (GET_CODE (x) != SYMBOL_REF)
288 abort ();
289 fnname = XSTR (x, 0);
291 assemble_start_function (current_function_decl, fnname);
292 final_start_function (get_insns (), asm_out_file, optimize);
293 final (get_insns (), asm_out_file, optimize, 0);
294 final_end_function ();
296 #ifdef TARGET_UNWIND_INFO
297 /* ??? The IA-64 ".handlerdata" directive must be issued before
298 the ".endp" directive that closes the procedure descriptor. */
299 output_function_exception_table ();
300 #endif
302 assemble_end_function (current_function_decl, fnname);
304 #ifndef TARGET_UNWIND_INFO
305 /* Otherwise, it feels unclean to switch sections in the middle. */
306 output_function_exception_table ();
307 #endif
309 user_defined_section_attribute = false;
311 if (! quiet_flag)
312 fflush (asm_out_file);
314 /* Release all memory allocated by flow. */
315 free_basic_block_vars ();
318 /* Write DBX symbols if requested. */
320 /* Note that for those inline functions where we don't initially
321 know for certain that we will be generating an out-of-line copy,
322 the first invocation of this routine (rest_of_compilation) will
323 skip over this code by doing a `goto exit_rest_of_compilation;'.
324 Later on, wrapup_global_declarations will (indirectly) call
325 rest_of_compilation again for those inline functions that need
326 to have out-of-line copies generated. During that call, we
327 *will* be routed past here. */
329 timevar_push (TV_SYMOUT);
330 (*debug_hooks->function_decl) (current_function_decl);
331 timevar_pop (TV_SYMOUT);
333 ggc_collect ();
334 timevar_pop (TV_FINAL);
337 #ifdef DELAY_SLOTS
338 /* Run delay slot optimization. */
339 static void
340 rest_of_handle_delay_slots (void)
342 timevar_push (TV_DBR_SCHED);
343 open_dump_file (DFI_dbr, current_function_decl);
345 dbr_schedule (get_insns (), dump_file);
347 close_dump_file (DFI_dbr, print_rtl, get_insns ());
349 ggc_collect ();
351 timevar_pop (TV_DBR_SCHED);
353 #endif
355 #ifdef STACK_REGS
356 /* Convert register usage from flat register file usage to a stack
357 register file. */
358 static void
359 rest_of_handle_stack_regs (void)
361 #if defined (HAVE_ATTR_length)
362 /* If flow2 creates new instructions which need splitting
363 and scheduling after reload is not done, they might not be
364 split until final which doesn't allow splitting
365 if HAVE_ATTR_length. */
366 #ifdef INSN_SCHEDULING
367 if (optimize && !flag_schedule_insns_after_reload)
368 #else
369 if (optimize)
370 #endif
372 timevar_push (TV_SHORTEN_BRANCH);
373 split_all_insns (1);
374 timevar_pop (TV_SHORTEN_BRANCH);
376 #endif
378 timevar_push (TV_REG_STACK);
379 open_dump_file (DFI_stack, current_function_decl);
381 if (reg_to_stack (dump_file) && optimize)
383 if (cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK
384 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0))
385 && (flag_reorder_blocks || flag_reorder_blocks_and_partition))
387 reorder_basic_blocks (0);
388 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK);
392 close_dump_file (DFI_stack, print_rtl_with_bb, get_insns ());
394 ggc_collect ();
395 timevar_pop (TV_REG_STACK);
397 #endif
399 /* Track the variables, i.e. compute where the variable is stored at each position in function. */
400 static void
401 rest_of_handle_variable_tracking (void)
403 timevar_push (TV_VAR_TRACKING);
404 open_dump_file (DFI_vartrack, current_function_decl);
406 variable_tracking_main ();
408 close_dump_file (DFI_vartrack, print_rtl_with_bb, get_insns ());
409 timevar_pop (TV_VAR_TRACKING);
412 /* Machine dependent reorg pass. */
413 static void
414 rest_of_handle_machine_reorg (void)
416 timevar_push (TV_MACH_DEP);
417 open_dump_file (DFI_mach, current_function_decl);
419 targetm.machine_dependent_reorg ();
421 close_dump_file (DFI_mach, print_rtl, get_insns ());
423 ggc_collect ();
424 timevar_pop (TV_MACH_DEP);
428 /* Run old register allocator. Return TRUE if we must exit
429 rest_of_compilation upon return. */
430 static bool
431 rest_of_handle_old_regalloc (void)
433 int failure;
434 int rebuild_notes;
436 timevar_push (TV_LOCAL_ALLOC);
437 open_dump_file (DFI_lreg, current_function_decl);
439 /* Allocate the reg_renumber array. */
440 allocate_reg_info (max_regno, FALSE, TRUE);
442 /* And the reg_equiv_memory_loc array. */
443 VARRAY_GROW (reg_equiv_memory_loc_varray, max_regno);
444 reg_equiv_memory_loc = &VARRAY_RTX (reg_equiv_memory_loc_varray, 0);
446 allocate_initial_values (reg_equiv_memory_loc);
448 regclass (get_insns (), max_reg_num (), dump_file);
449 rebuild_notes = local_alloc ();
451 timevar_pop (TV_LOCAL_ALLOC);
453 /* Local allocation may have turned an indirect jump into a direct
454 jump. If so, we must rebuild the JUMP_LABEL fields of jumping
455 instructions. */
456 if (rebuild_notes)
458 timevar_push (TV_JUMP);
460 rebuild_jump_labels (get_insns ());
461 purge_all_dead_edges (0);
462 delete_unreachable_blocks ();
464 timevar_pop (TV_JUMP);
467 if (dump_enabled_p (DFI_lreg))
469 timevar_push (TV_DUMP);
470 dump_flow_info (dump_file);
471 dump_local_alloc (dump_file);
472 timevar_pop (TV_DUMP);
475 close_dump_file (DFI_lreg, print_rtl_with_bb, get_insns ());
477 ggc_collect ();
479 timevar_push (TV_GLOBAL_ALLOC);
480 open_dump_file (DFI_greg, current_function_decl);
482 /* If optimizing, allocate remaining pseudo-regs. Do the reload
483 pass fixing up any insns that are invalid. */
485 if (optimize)
486 failure = global_alloc (dump_file);
487 else
489 build_insn_chain (get_insns ());
490 failure = reload (get_insns (), 0);
493 if (dump_enabled_p (DFI_greg))
495 timevar_push (TV_DUMP);
496 dump_global_regs (dump_file);
497 timevar_pop (TV_DUMP);
499 close_dump_file (DFI_greg, print_rtl_with_bb, get_insns ());
502 ggc_collect ();
504 timevar_pop (TV_GLOBAL_ALLOC);
506 return failure;
509 /* Run the regrename and cprop passes. */
510 static void
511 rest_of_handle_regrename (void)
513 timevar_push (TV_RENAME_REGISTERS);
514 open_dump_file (DFI_rnreg, current_function_decl);
516 if (flag_rename_registers)
517 regrename_optimize ();
518 if (flag_cprop_registers)
519 copyprop_hardreg_forward ();
521 close_dump_file (DFI_rnreg, print_rtl_with_bb, get_insns ());
522 timevar_pop (TV_RENAME_REGISTERS);
525 /* Reorder basic blocks. */
526 static void
527 rest_of_handle_reorder_blocks (void)
529 bool changed;
530 unsigned int liveness_flags;
532 open_dump_file (DFI_bbro, current_function_decl);
534 /* Last attempt to optimize CFG, as scheduling, peepholing and insn
535 splitting possibly introduced more crossjumping opportunities. */
536 liveness_flags = (!HAVE_conditional_execution ? CLEANUP_UPDATE_LIFE : 0);
537 changed = cleanup_cfg (CLEANUP_EXPENSIVE | liveness_flags);
539 if (flag_sched2_use_traces && flag_schedule_insns_after_reload)
540 tracer (liveness_flags);
541 if (flag_reorder_blocks || flag_reorder_blocks_and_partition)
542 reorder_basic_blocks (liveness_flags);
543 if (flag_reorder_blocks || flag_reorder_blocks_and_partition
544 || (flag_sched2_use_traces && flag_schedule_insns_after_reload))
545 changed |= cleanup_cfg (CLEANUP_EXPENSIVE | liveness_flags);
547 /* On conditional execution targets we can not update the life cheaply, so
548 we deffer the updating to after both cleanups. This may lose some cases
549 but should not be terribly bad. */
550 if (changed && HAVE_conditional_execution)
551 update_life_info (NULL, UPDATE_LIFE_GLOBAL_RM_NOTES,
552 PROP_DEATH_NOTES);
553 close_dump_file (DFI_bbro, print_rtl_with_bb, get_insns ());
556 /* Partition hot and cold basic blocks. */
557 static void
558 rest_of_handle_partition_blocks (void)
560 no_new_pseudos = 0;
561 partition_hot_cold_basic_blocks ();
562 allocate_reg_life_data ();
563 update_life_info (NULL, UPDATE_LIFE_GLOBAL_RM_NOTES,
564 PROP_LOG_LINKS | PROP_REG_INFO | PROP_DEATH_NOTES);
565 no_new_pseudos = 1;
568 #ifdef INSN_SCHEDULING
569 /* Run instruction scheduler. */
570 /* Perform SMS module scheduling. */
571 static void
572 rest_of_handle_sms (void)
574 timevar_push (TV_SMS);
575 open_dump_file (DFI_sms, current_function_decl);
577 /* We want to be able to create new pseudos. */
578 no_new_pseudos = 0;
579 sms_schedule (dump_file);
580 close_dump_file (DFI_sms, print_rtl, get_insns ());
583 /* Update the life information, because we add pseudos. */
584 max_regno = max_reg_num ();
585 allocate_reg_info (max_regno, FALSE, FALSE);
586 update_life_info_in_dirty_blocks (UPDATE_LIFE_GLOBAL_RM_NOTES,
587 (PROP_DEATH_NOTES
588 | PROP_KILL_DEAD_CODE
589 | PROP_SCAN_DEAD_CODE));
590 no_new_pseudos = 1;
592 ggc_collect ();
593 timevar_pop (TV_SMS);
596 /* Run instruction scheduler. */
597 static void
598 rest_of_handle_sched (void)
600 timevar_push (TV_SCHED);
602 /* Print function header into sched dump now
603 because doing the sched analysis makes some of the dump. */
604 open_dump_file (DFI_sched, current_function_decl);
606 /* Do control and data sched analysis,
607 and write some of the results to dump file. */
609 schedule_insns (dump_file);
611 close_dump_file (DFI_sched, print_rtl_with_bb, get_insns ());
613 ggc_collect ();
614 timevar_pop (TV_SCHED);
617 /* Run second scheduling pass after reload. */
618 static void
619 rest_of_handle_sched2 (void)
621 timevar_push (TV_SCHED2);
622 open_dump_file (DFI_sched2, current_function_decl);
624 /* Do control and data sched analysis again,
625 and write some more of the results to dump file. */
627 split_all_insns (1);
629 if (flag_sched2_use_superblocks || flag_sched2_use_traces)
631 schedule_ebbs (dump_file);
632 /* No liveness updating code yet, but it should be easy to do.
633 reg-stack recomputes the liveness when needed for now. */
634 count_or_remove_death_notes (NULL, 1);
635 cleanup_cfg (CLEANUP_EXPENSIVE);
637 else
638 schedule_insns (dump_file);
640 close_dump_file (DFI_sched2, print_rtl_with_bb, get_insns ());
642 ggc_collect ();
644 timevar_pop (TV_SCHED2);
646 #endif
648 static void
649 rest_of_handle_gcse2 (void)
651 timevar_push (TV_GCSE_AFTER_RELOAD);
652 open_dump_file (DFI_gcse2, current_function_decl);
654 gcse_after_reload_main (get_insns ());
655 rebuild_jump_labels (get_insns ());
656 delete_trivially_dead_insns (get_insns (), max_reg_num ());
657 close_dump_file (DFI_gcse2, print_rtl_with_bb, get_insns ());
659 ggc_collect ();
661 #ifdef ENABLE_CHECKING
662 verify_flow_info ();
663 #endif
665 timevar_pop (TV_GCSE_AFTER_RELOAD);
668 /* Register allocation pre-pass, to reduce number of moves necessary
669 for two-address machines. */
670 static void
671 rest_of_handle_regmove (void)
673 timevar_push (TV_REGMOVE);
674 open_dump_file (DFI_regmove, current_function_decl);
676 regmove_optimize (get_insns (), max_reg_num (), dump_file);
678 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
679 close_dump_file (DFI_regmove, print_rtl_with_bb, get_insns ());
681 ggc_collect ();
682 timevar_pop (TV_REGMOVE);
685 /* Run tracer. */
686 static void
687 rest_of_handle_tracer (void)
689 open_dump_file (DFI_tracer, current_function_decl);
690 if (dump_file)
691 dump_flow_info (dump_file);
692 tracer (0);
693 cleanup_cfg (CLEANUP_EXPENSIVE);
694 reg_scan (get_insns (), max_reg_num ());
695 close_dump_file (DFI_tracer, print_rtl_with_bb, get_insns ());
698 /* If-conversion and CFG cleanup. */
699 static void
700 rest_of_handle_if_conversion (void)
702 timevar_push (TV_IFCVT);
703 open_dump_file (DFI_ce1, current_function_decl);
705 if (flag_if_conversion)
707 if (dump_file)
708 dump_flow_info (dump_file);
709 cleanup_cfg (CLEANUP_EXPENSIVE);
710 reg_scan (get_insns (), max_reg_num ());
711 if_convert (0);
714 timevar_push (TV_JUMP);
715 cleanup_cfg (CLEANUP_EXPENSIVE);
716 reg_scan (get_insns (), max_reg_num ());
717 timevar_pop (TV_JUMP);
719 close_dump_file (DFI_ce1, print_rtl_with_bb, get_insns ());
720 timevar_pop (TV_IFCVT);
723 /* Rerun if-conversion, as combine may have simplified things enough
724 to now meet sequence length restrictions. */
725 static void
726 rest_of_handle_if_after_combine (void)
728 timevar_push (TV_IFCVT);
729 open_dump_file (DFI_ce2, current_function_decl);
731 no_new_pseudos = 0;
732 if_convert (1);
733 no_new_pseudos = 1;
735 close_dump_file (DFI_ce2, print_rtl_with_bb, get_insns ());
736 timevar_pop (TV_IFCVT);
739 static void
740 rest_of_handle_if_after_reload (void)
742 timevar_push (TV_IFCVT2);
743 open_dump_file (DFI_ce3, current_function_decl);
745 /* Last attempt to optimize CFG, as scheduling, peepholing and insn
746 splitting possibly introduced more crossjumping opportunities. */
747 cleanup_cfg (CLEANUP_EXPENSIVE
748 | CLEANUP_UPDATE_LIFE
749 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0));
750 if (flag_if_conversion2)
751 if_convert (1);
752 close_dump_file (DFI_ce3, print_rtl_with_bb, get_insns ());
753 timevar_pop (TV_IFCVT2);
756 static void
757 rest_of_handle_web (void)
759 open_dump_file (DFI_web, current_function_decl);
760 timevar_push (TV_WEB);
761 web_main ();
762 delete_trivially_dead_insns (get_insns (), max_reg_num ());
763 cleanup_cfg (CLEANUP_EXPENSIVE);
765 timevar_pop (TV_WEB);
766 close_dump_file (DFI_web, print_rtl_with_bb, get_insns ());
767 reg_scan (get_insns (), max_reg_num ());
770 /* Do branch profiling and static profile estimation passes. */
771 static void
772 rest_of_handle_branch_prob (void)
774 struct loops loops;
776 timevar_push (TV_BRANCH_PROB);
777 open_dump_file (DFI_bp, current_function_decl);
779 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
780 branch_prob ();
782 /* Discover and record the loop depth at the head of each basic
783 block. The loop infrastructure does the real job for us. */
784 flow_loops_find (&loops, LOOP_TREE);
786 if (dump_file)
787 flow_loops_dump (&loops, dump_file, NULL, 0);
789 /* Estimate using heuristics if no profiling info is available. */
790 if (flag_guess_branch_prob)
791 estimate_probability (&loops);
793 flow_loops_free (&loops);
794 free_dominance_info (CDI_DOMINATORS);
795 close_dump_file (DFI_bp, print_rtl_with_bb, get_insns ());
796 timevar_pop (TV_BRANCH_PROB);
799 /* Do optimizations based on expression value profiles. */
800 static void
801 rest_of_handle_value_profile_transformations (void)
803 open_dump_file (DFI_vpt, current_function_decl);
804 timevar_push (TV_VPT);
806 if (value_profile_transformations ())
807 cleanup_cfg (CLEANUP_EXPENSIVE);
809 timevar_pop (TV_VPT);
810 close_dump_file (DFI_vpt, print_rtl_with_bb, get_insns ());
813 /* Do control and data flow analysis; write some of the results to the
814 dump file. */
815 static void
816 rest_of_handle_cfg (void)
818 open_dump_file (DFI_cfg, current_function_decl);
819 if (dump_file)
820 dump_flow_info (dump_file);
821 if (optimize)
822 cleanup_cfg (CLEANUP_EXPENSIVE
823 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
825 /* It may make more sense to mark constant functions after dead code is
826 eliminated by life_analysis, but we need to do it early, as -fprofile-arcs
827 may insert code making function non-constant, but we still must consider
828 it as constant, otherwise -fbranch-probabilities will not read data back.
830 life_analysis rarely eliminates modification of external memory.
832 FIXME: now with tree based profiling we are in the trap described above
833 again. It seems to be easiest to disable the optimization for time
834 being before the problem is either solved by moving the transformation
835 to the IPA level (we need the CFG for this) or the very early optimization
836 passes are made to ignore the const/pure flags so code does not change. */
837 if (optimize
838 && (!flag_tree_based_profiling
839 || (!profile_arc_flag && !flag_branch_probabilities)))
841 /* Alias analysis depends on this information and mark_constant_function
842 depends on alias analysis. */
843 reg_scan (get_insns (), max_reg_num ());
844 mark_constant_function ();
847 close_dump_file (DFI_cfg, print_rtl_with_bb, get_insns ());
850 /* Perform jump bypassing and control flow optimizations. */
851 static void
852 rest_of_handle_jump_bypass (void)
854 timevar_push (TV_BYPASS);
855 open_dump_file (DFI_bypass, current_function_decl);
857 cleanup_cfg (CLEANUP_EXPENSIVE);
858 reg_scan (get_insns (), max_reg_num ());
860 if (bypass_jumps (dump_file))
862 rebuild_jump_labels (get_insns ());
863 cleanup_cfg (CLEANUP_EXPENSIVE);
864 delete_trivially_dead_insns (get_insns (), max_reg_num ());
867 close_dump_file (DFI_bypass, print_rtl_with_bb, get_insns ());
868 timevar_pop (TV_BYPASS);
870 ggc_collect ();
872 #ifdef ENABLE_CHECKING
873 verify_flow_info ();
874 #endif
877 /* Try combining insns through substitution. */
878 static void
879 rest_of_handle_combine (void)
881 int rebuild_jump_labels_after_combine = 0;
883 timevar_push (TV_COMBINE);
884 open_dump_file (DFI_combine, current_function_decl);
886 rebuild_jump_labels_after_combine
887 = combine_instructions (get_insns (), max_reg_num ());
889 /* Combining insns may have turned an indirect jump into a
890 direct jump. Rebuild the JUMP_LABEL fields of jumping
891 instructions. */
892 if (rebuild_jump_labels_after_combine)
894 timevar_push (TV_JUMP);
895 rebuild_jump_labels (get_insns ());
896 timevar_pop (TV_JUMP);
898 delete_dead_jumptables ();
899 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
902 close_dump_file (DFI_combine, print_rtl_with_bb, get_insns ());
903 timevar_pop (TV_COMBINE);
905 ggc_collect ();
908 /* Perform life analysis. */
909 static void
910 rest_of_handle_life (void)
912 open_dump_file (DFI_life, current_function_decl);
913 regclass_init ();
915 #ifdef ENABLE_CHECKING
916 verify_flow_info ();
917 #endif
918 life_analysis (dump_file, PROP_FINAL);
919 if (optimize)
920 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE | CLEANUP_LOG_LINKS
921 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
923 if (extra_warnings)
925 setjmp_vars_warning (DECL_INITIAL (current_function_decl));
926 setjmp_args_warning ();
929 if (optimize)
931 if (initialize_uninitialized_subregs ())
933 /* Insns were inserted, and possibly pseudos created, so
934 things might look a bit different. */
935 allocate_reg_life_data ();
936 update_life_info (NULL, UPDATE_LIFE_GLOBAL_RM_NOTES,
937 PROP_LOG_LINKS | PROP_REG_INFO | PROP_DEATH_NOTES);
941 no_new_pseudos = 1;
943 close_dump_file (DFI_life, print_rtl_with_bb, get_insns ());
945 ggc_collect ();
948 /* Perform common subexpression elimination. Nonzero value from
949 `cse_main' means that jumps were simplified and some code may now
950 be unreachable, so do jump optimization again. */
951 static void
952 rest_of_handle_cse (void)
954 int tem;
956 open_dump_file (DFI_cse, current_function_decl);
957 if (dump_file)
958 dump_flow_info (dump_file);
959 timevar_push (TV_CSE);
961 reg_scan (get_insns (), max_reg_num ());
963 tem = cse_main (get_insns (), max_reg_num (), dump_file);
964 if (tem)
965 rebuild_jump_labels (get_insns ());
966 if (purge_all_dead_edges (0))
967 delete_unreachable_blocks ();
969 delete_trivially_dead_insns (get_insns (), max_reg_num ());
971 /* If we are not running more CSE passes, then we are no longer
972 expecting CSE to be run. But always rerun it in a cheap mode. */
973 cse_not_expected = !flag_rerun_cse_after_loop && !flag_gcse;
975 if (tem)
976 delete_dead_jumptables ();
978 if (tem || optimize > 1)
979 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
981 timevar_pop (TV_CSE);
982 close_dump_file (DFI_cse, print_rtl_with_bb, get_insns ());
984 ggc_collect ();
987 /* Run second CSE pass after loop optimizations. */
988 static void
989 rest_of_handle_cse2 (void)
991 int tem;
993 timevar_push (TV_CSE2);
994 open_dump_file (DFI_cse2, current_function_decl);
995 if (dump_file)
996 dump_flow_info (dump_file);
997 /* CFG is no longer maintained up-to-date. */
998 tem = cse_main (get_insns (), max_reg_num (), dump_file);
1000 /* Run a pass to eliminate duplicated assignments to condition code
1001 registers. We have to run this after bypass_jumps, because it
1002 makes it harder for that pass to determine whether a jump can be
1003 bypassed safely. */
1004 cse_condition_code_reg ();
1006 purge_all_dead_edges (0);
1007 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1009 if (tem)
1011 timevar_push (TV_JUMP);
1012 rebuild_jump_labels (get_insns ());
1013 delete_dead_jumptables ();
1014 cleanup_cfg (CLEANUP_EXPENSIVE);
1015 timevar_pop (TV_JUMP);
1017 reg_scan (get_insns (), max_reg_num ());
1018 close_dump_file (DFI_cse2, print_rtl_with_bb, get_insns ());
1019 timevar_pop (TV_CSE2);
1021 ggc_collect ();
1024 /* Perform global cse. */
1025 static void
1026 rest_of_handle_gcse (void)
1028 int save_csb, save_cfj;
1029 int tem2 = 0, tem;
1031 timevar_push (TV_GCSE);
1032 open_dump_file (DFI_gcse, current_function_decl);
1034 tem = gcse_main (get_insns (), dump_file);
1035 rebuild_jump_labels (get_insns ());
1036 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1038 save_csb = flag_cse_skip_blocks;
1039 save_cfj = flag_cse_follow_jumps;
1040 flag_cse_skip_blocks = flag_cse_follow_jumps = 0;
1042 /* If -fexpensive-optimizations, re-run CSE to clean up things done
1043 by gcse. */
1044 if (flag_expensive_optimizations)
1046 timevar_push (TV_CSE);
1047 reg_scan (get_insns (), max_reg_num ());
1048 tem2 = cse_main (get_insns (), max_reg_num (), dump_file);
1049 purge_all_dead_edges (0);
1050 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1051 timevar_pop (TV_CSE);
1052 cse_not_expected = !flag_rerun_cse_after_loop;
1055 /* If gcse or cse altered any jumps, rerun jump optimizations to clean
1056 things up. */
1057 if (tem || tem2)
1059 timevar_push (TV_JUMP);
1060 rebuild_jump_labels (get_insns ());
1061 delete_dead_jumptables ();
1062 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
1063 timevar_pop (TV_JUMP);
1066 close_dump_file (DFI_gcse, print_rtl_with_bb, get_insns ());
1067 timevar_pop (TV_GCSE);
1069 ggc_collect ();
1070 flag_cse_skip_blocks = save_csb;
1071 flag_cse_follow_jumps = save_cfj;
1072 #ifdef ENABLE_CHECKING
1073 verify_flow_info ();
1074 #endif
1077 /* Move constant computations out of loops. */
1078 static void
1079 rest_of_handle_loop_optimize (void)
1081 int do_prefetch;
1083 timevar_push (TV_LOOP);
1084 open_dump_file (DFI_loop, current_function_decl);
1086 /* CFG is no longer maintained up-to-date. */
1087 free_bb_for_insn ();
1088 profile_status = PROFILE_ABSENT;
1090 do_prefetch = flag_prefetch_loop_arrays ? LOOP_PREFETCH : 0;
1092 if (flag_rerun_loop_opt)
1094 cleanup_barriers ();
1096 /* We only want to perform unrolling once. */
1097 loop_optimize (get_insns (), dump_file, 0);
1099 /* The first call to loop_optimize makes some instructions
1100 trivially dead. We delete those instructions now in the
1101 hope that doing so will make the heuristics in loop work
1102 better and possibly speed up compilation. */
1103 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1105 /* The regscan pass is currently necessary as the alias
1106 analysis code depends on this information. */
1107 reg_scan (get_insns (), max_reg_num ());
1109 cleanup_barriers ();
1110 loop_optimize (get_insns (), dump_file, do_prefetch);
1112 /* Loop can create trivially dead instructions. */
1113 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1114 find_basic_blocks (get_insns ());
1115 close_dump_file (DFI_loop, print_rtl, get_insns ());
1116 timevar_pop (TV_LOOP);
1118 ggc_collect ();
1121 /* Perform loop optimizations. It might be better to do them a bit
1122 sooner, but we want the profile feedback to work more
1123 efficiently. */
1124 static void
1125 rest_of_handle_loop2 (void)
1127 struct loops *loops;
1128 basic_block bb;
1130 if (!flag_move_loop_invariants
1131 && !flag_unswitch_loops
1132 && !flag_peel_loops
1133 && !flag_unroll_loops
1134 && !flag_branch_on_count_reg)
1135 return;
1137 timevar_push (TV_LOOP);
1138 open_dump_file (DFI_loop2, current_function_decl);
1139 if (dump_file)
1140 dump_flow_info (dump_file);
1142 /* Initialize structures for layout changes. */
1143 cfg_layout_initialize (0);
1145 loops = loop_optimizer_init (dump_file);
1147 if (loops)
1149 /* The optimizations: */
1150 if (flag_move_loop_invariants)
1151 move_loop_invariants (loops);
1153 if (flag_unswitch_loops)
1154 unswitch_loops (loops);
1156 if (flag_peel_loops || flag_unroll_loops)
1157 unroll_and_peel_loops (loops,
1158 (flag_peel_loops ? UAP_PEEL : 0) |
1159 (flag_unroll_loops ? UAP_UNROLL : 0) |
1160 (flag_unroll_all_loops ? UAP_UNROLL_ALL : 0));
1162 #ifdef HAVE_doloop_end
1163 if (flag_branch_on_count_reg && HAVE_doloop_end)
1164 doloop_optimize_loops (loops);
1165 #endif /* HAVE_doloop_end */
1167 loop_optimizer_finalize (loops, dump_file);
1170 free_dominance_info (CDI_DOMINATORS);
1172 /* Finalize layout changes. */
1173 FOR_EACH_BB (bb)
1174 if (bb->next_bb != EXIT_BLOCK_PTR)
1175 bb->rbi->next = bb->next_bb;
1176 cfg_layout_finalize ();
1178 cleanup_cfg (CLEANUP_EXPENSIVE);
1179 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1180 reg_scan (get_insns (), max_reg_num ());
1181 if (dump_file)
1182 dump_flow_info (dump_file);
1183 close_dump_file (DFI_loop2, print_rtl_with_bb, get_insns ());
1184 timevar_pop (TV_LOOP);
1185 ggc_collect ();
1188 static void
1189 rest_of_handle_branch_target_load_optimize (void)
1191 static int warned = 0;
1193 /* Leave this a warning for now so that it is possible to experiment
1194 with running this pass twice. In 3.6, we should either make this
1195 an error, or use separate dump files. */
1196 if (flag_branch_target_load_optimize
1197 && flag_branch_target_load_optimize2
1198 && !warned)
1200 warning ("branch target register load optimization is not intended "
1201 "to be run twice");
1203 warned = 1;
1206 open_dump_file (DFI_branch_target_load, current_function_decl);
1207 branch_target_load_optimize (epilogue_completed);
1208 close_dump_file (DFI_branch_target_load, print_rtl_with_bb, get_insns ());
1209 ggc_collect ();
1212 #ifdef OPTIMIZE_MODE_SWITCHING
1213 static void
1214 rest_of_handle_mode_switching (void)
1216 timevar_push (TV_MODE_SWITCH);
1218 no_new_pseudos = 0;
1219 optimize_mode_switching (NULL);
1220 no_new_pseudos = 1;
1222 timevar_pop (TV_MODE_SWITCH);
1224 #endif
1226 static void
1227 rest_of_handle_jump (void)
1229 ggc_collect ();
1231 timevar_push (TV_JUMP);
1232 open_dump_file (DFI_sibling, current_function_decl);
1234 delete_unreachable_blocks ();
1235 #ifdef ENABLE_CHECKING
1236 verify_flow_info ();
1237 #endif
1239 if (cfun->tail_call_emit)
1240 fixup_tail_calls ();
1242 close_dump_file (DFI_sibling, print_rtl, get_insns ());
1243 timevar_pop (TV_JUMP);
1246 static void
1247 rest_of_handle_eh (void)
1249 insn_locators_initialize ();
1250 /* Complete generation of exception handling code. */
1251 if (doing_eh (0))
1253 timevar_push (TV_JUMP);
1254 open_dump_file (DFI_eh, current_function_decl);
1256 cleanup_cfg (CLEANUP_PRE_LOOP | CLEANUP_NO_INSN_DEL);
1258 finish_eh_generation ();
1260 cleanup_cfg (CLEANUP_PRE_LOOP | CLEANUP_NO_INSN_DEL);
1262 close_dump_file (DFI_eh, print_rtl, get_insns ());
1263 timevar_pop (TV_JUMP);
1267 static void
1268 rest_of_handle_stack_adjustments (void)
1270 life_analysis (dump_file, PROP_POSTRELOAD);
1271 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE
1272 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0));
1274 /* This is kind of a heuristic. We need to run combine_stack_adjustments
1275 even for machines with possibly nonzero RETURN_POPS_ARGS
1276 and ACCUMULATE_OUTGOING_ARGS. We expect that only ports having
1277 push instructions will have popping returns. */
1278 #ifndef PUSH_ROUNDING
1279 if (!ACCUMULATE_OUTGOING_ARGS)
1280 #endif
1281 combine_stack_adjustments ();
1284 static void
1285 rest_of_handle_flow2 (void)
1287 timevar_push (TV_FLOW2);
1288 open_dump_file (DFI_flow2, current_function_decl);
1290 /* Re-create the death notes which were deleted during reload. */
1291 #ifdef ENABLE_CHECKING
1292 verify_flow_info ();
1293 #endif
1295 /* If optimizing, then go ahead and split insns now. */
1296 #ifndef STACK_REGS
1297 if (optimize > 0)
1298 #endif
1299 split_all_insns (0);
1301 if (flag_branch_target_load_optimize)
1303 close_dump_file (DFI_flow2, print_rtl_with_bb, get_insns ());
1304 rest_of_handle_branch_target_load_optimize ();
1305 open_dump_file (DFI_flow2, current_function_decl);
1308 if (optimize)
1309 cleanup_cfg (CLEANUP_EXPENSIVE);
1311 /* On some machines, the prologue and epilogue code, or parts thereof,
1312 can be represented as RTL. Doing so lets us schedule insns between
1313 it and the rest of the code and also allows delayed branch
1314 scheduling to operate in the epilogue. */
1315 thread_prologue_and_epilogue_insns (get_insns ());
1316 epilogue_completed = 1;
1318 if (optimize)
1319 rest_of_handle_stack_adjustments ();
1321 flow2_completed = 1;
1323 close_dump_file (DFI_flow2, print_rtl_with_bb, get_insns ());
1324 timevar_pop (TV_FLOW2);
1326 ggc_collect ();
1330 static void
1331 rest_of_handle_jump2 (void)
1333 open_dump_file (DFI_jump, current_function_decl);
1335 /* Always do one jump optimization pass to ensure that JUMP_LABEL fields
1336 are initialized and to compute whether control can drop off the end
1337 of the function. */
1339 timevar_push (TV_JUMP);
1340 /* Turn NOTE_INSN_EXPECTED_VALUE into REG_BR_PROB. Do this
1341 before jump optimization switches branch directions. */
1342 if (flag_guess_branch_prob)
1343 expected_value_to_br_prob ();
1345 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1346 reg_scan (get_insns (), max_reg_num ());
1347 if (dump_file)
1348 dump_flow_info (dump_file);
1349 cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_PRE_LOOP
1350 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
1352 create_loop_notes ();
1354 purge_line_number_notes (get_insns ());
1356 if (optimize)
1357 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
1359 /* Jump optimization, and the removal of NULL pointer checks, may
1360 have reduced the number of instructions substantially. CSE, and
1361 future passes, allocate arrays whose dimensions involve the
1362 maximum instruction UID, so if we can reduce the maximum UID
1363 we'll save big on memory. */
1364 renumber_insns (dump_file);
1366 close_dump_file (DFI_jump, print_rtl_with_bb, get_insns ());
1367 timevar_pop (TV_JUMP);
1369 ggc_collect ();
1372 #ifdef HAVE_peephole2
1373 static void
1374 rest_of_handle_peephole2 (void)
1376 timevar_push (TV_PEEPHOLE2);
1377 open_dump_file (DFI_peephole2, current_function_decl);
1379 peephole2_optimize (dump_file);
1381 close_dump_file (DFI_peephole2, print_rtl_with_bb, get_insns ());
1382 timevar_pop (TV_PEEPHOLE2);
1384 #endif
1386 static void
1387 rest_of_handle_postreload (void)
1389 timevar_push (TV_RELOAD_CSE_REGS);
1390 open_dump_file (DFI_postreload, current_function_decl);
1392 /* Do a very simple CSE pass over just the hard registers. */
1393 reload_cse_regs (get_insns ());
1394 /* reload_cse_regs can eliminate potentially-trapping MEMs.
1395 Remove any EH edges associated with them. */
1396 if (flag_non_call_exceptions)
1397 purge_all_dead_edges (0);
1399 close_dump_file (DFI_postreload, print_rtl_with_bb, get_insns ());
1400 timevar_pop (TV_RELOAD_CSE_REGS);
1403 static void
1404 rest_of_handle_shorten_branches (void)
1406 /* Shorten branches. */
1407 timevar_push (TV_SHORTEN_BRANCH);
1408 shorten_branches (get_insns ());
1409 timevar_pop (TV_SHORTEN_BRANCH);
1412 static void
1413 rest_of_clean_state (void)
1415 rtx insn, next;
1416 coverage_end_function ();
1418 /* It is very important to decompose the RTL instruction chain here:
1419 debug information keeps pointing into CODE_LABEL insns inside the function
1420 body. If these remain pointing to the other insns, we end up preserving
1421 whole RTL chain and attached detailed debug info in memory. */
1422 for (insn = get_insns (); insn; insn = next)
1424 next = NEXT_INSN (insn);
1425 NEXT_INSN (insn) = NULL;
1426 PREV_INSN (insn) = NULL;
1429 /* In case the function was not output,
1430 don't leave any temporary anonymous types
1431 queued up for sdb output. */
1432 #ifdef SDB_DEBUGGING_INFO
1433 if (write_symbols == SDB_DEBUG)
1434 sdbout_types (NULL_TREE);
1435 #endif
1437 reload_completed = 0;
1438 epilogue_completed = 0;
1439 flow2_completed = 0;
1440 no_new_pseudos = 0;
1442 timevar_push (TV_FINAL);
1444 /* Clear out the insn_length contents now that they are no
1445 longer valid. */
1446 init_insn_lengths ();
1448 /* Show no temporary slots allocated. */
1449 init_temp_slots ();
1451 free_basic_block_vars ();
1452 free_bb_for_insn ();
1454 timevar_pop (TV_FINAL);
1456 if (targetm.binds_local_p (current_function_decl))
1458 int pref = cfun->preferred_stack_boundary;
1459 if (cfun->stack_alignment_needed > cfun->preferred_stack_boundary)
1460 pref = cfun->stack_alignment_needed;
1461 cgraph_rtl_info (current_function_decl)->preferred_incoming_stack_boundary
1462 = pref;
1465 /* Make sure volatile mem refs aren't considered valid operands for
1466 arithmetic insns. We must call this here if this is a nested inline
1467 function, since the above code leaves us in the init_recog state
1468 (from final.c), and the function context push/pop code does not
1469 save/restore volatile_ok.
1471 ??? Maybe it isn't necessary for expand_start_function to call this
1472 anymore if we do it here? */
1474 init_recog_no_volatile ();
1476 /* We're done with this function. Free up memory if we can. */
1477 free_after_parsing (cfun);
1478 free_after_compilation (cfun);
1482 /* This function is called from the pass manager in tree-optimize.c
1483 after all tree passes have finished for a single function, and we
1484 have expanded the function body from trees to RTL.
1485 Once we are here, we have decided that we're supposed to output
1486 that function, i.e. that we should write assembler code for it.
1488 We run a series of low-level passes here on the function's RTL
1489 representation. Each pass is called via a rest_of_* function. */
1491 static void
1492 rest_of_compilation (void)
1494 /* If we're emitting a nested function, make sure its parent gets
1495 emitted as well. Doing otherwise confuses debug info. */
1497 tree parent;
1498 for (parent = DECL_CONTEXT (current_function_decl);
1499 parent != NULL_TREE;
1500 parent = get_containing_scope (parent))
1501 if (TREE_CODE (parent) == FUNCTION_DECL)
1502 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (parent)) = 1;
1505 /* We are now committed to emitting code for this function. Do any
1506 preparation, such as emitting abstract debug info for the inline
1507 before it gets mangled by optimization. */
1508 if (cgraph_function_possibly_inlined_p (current_function_decl))
1509 (*debug_hooks->outlining_inline_function) (current_function_decl);
1511 /* Remove any notes we don't need. That will make iterating
1512 over the instruction sequence faster, and allow the garbage
1513 collector to reclaim the memory used by the notes. */
1514 remove_unnecessary_notes ();
1516 /* Initialize some variables used by the optimizers. */
1517 init_function_for_compilation ();
1519 TREE_ASM_WRITTEN (current_function_decl) = 1;
1521 /* Early return if there were errors. We can run afoul of our
1522 consistency checks, and there's not really much point in fixing them. */
1523 if (rtl_dump_and_exit || flag_syntax_only || errorcount || sorrycount)
1524 goto exit_rest_of_compilation;
1526 rest_of_handle_jump ();
1528 rest_of_handle_eh ();
1530 /* Delay emitting hard_reg_initial_value sets until after EH landing pad
1531 generation, which might create new sets. */
1532 emit_initial_value_sets ();
1534 #ifdef FINALIZE_PIC
1535 /* If we are doing position-independent code generation, now
1536 is the time to output special prologues and epilogues.
1537 We do not want to do this earlier, because it just clutters
1538 up inline functions with meaningless insns. */
1539 if (flag_pic)
1540 FINALIZE_PIC;
1541 #endif
1543 /* Copy any shared structure that should not be shared. */
1544 unshare_all_rtl ();
1546 #ifdef SETJMP_VIA_SAVE_AREA
1547 /* This must be performed before virtual register instantiation.
1548 Please be aware that everything in the compiler that can look
1549 at the RTL up to this point must understand that REG_SAVE_AREA
1550 is just like a use of the REG contained inside. */
1551 if (current_function_calls_alloca)
1552 optimize_save_area_alloca ();
1553 #endif
1555 /* Instantiate all virtual registers. */
1556 instantiate_virtual_regs ();
1558 rest_of_handle_jump2 ();
1560 if (optimize > 0)
1561 rest_of_handle_cse ();
1563 if (optimize > 0)
1565 if (flag_gcse)
1566 rest_of_handle_gcse ();
1568 if (flag_loop_optimize)
1569 rest_of_handle_loop_optimize ();
1571 if (flag_gcse)
1572 rest_of_handle_jump_bypass ();
1575 timevar_push (TV_FLOW);
1576 rest_of_handle_cfg ();
1578 if (!flag_tree_based_profiling
1579 && (optimize > 0 || profile_arc_flag
1580 || flag_test_coverage || flag_branch_probabilities))
1582 rtl_register_profile_hooks ();
1583 rtl_register_value_prof_hooks ();
1584 rest_of_handle_branch_prob ();
1586 if (flag_branch_probabilities
1587 && flag_profile_values
1588 && (flag_value_profile_transformations
1589 || flag_speculative_prefetching))
1590 rest_of_handle_value_profile_transformations ();
1592 /* Remove the death notes created for vpt. */
1593 if (flag_profile_values)
1594 count_or_remove_death_notes (NULL, 1);
1597 if (optimize > 0)
1598 rest_of_handle_if_conversion ();
1600 if (optimize > 0 && flag_tracer)
1601 rest_of_handle_tracer ();
1603 if (optimize > 0
1604 && flag_loop_optimize2)
1605 rest_of_handle_loop2 ();
1607 if (optimize > 0 && flag_web)
1608 rest_of_handle_web ();
1610 if (optimize > 0 && flag_rerun_cse_after_loop)
1611 rest_of_handle_cse2 ();
1613 cse_not_expected = 1;
1615 rest_of_handle_life ();
1616 timevar_pop (TV_FLOW);
1618 if (optimize > 0)
1619 rest_of_handle_combine ();
1621 if (optimize > 0 && flag_if_conversion)
1622 rest_of_handle_if_after_combine ();
1624 /* The optimization to partition hot/cold basic blocks into separate
1625 sections of the .o file does not work well with linkonce or with
1626 user defined section attributes. Don't call it if either case
1627 arises. */
1629 if (flag_reorder_blocks_and_partition
1630 && !DECL_ONE_ONLY (current_function_decl)
1631 && !user_defined_section_attribute)
1632 rest_of_handle_partition_blocks ();
1634 if (optimize > 0 && flag_regmove)
1635 rest_of_handle_regmove ();
1637 /* Do unconditional splitting before register allocation to allow machine
1638 description to add extra information not needed previously. */
1639 split_all_insns (1);
1641 #ifdef OPTIMIZE_MODE_SWITCHING
1642 rest_of_handle_mode_switching ();
1643 #endif
1645 /* Any of the several passes since flow1 will have munged register
1646 lifetime data a bit. We need it to be up to date for scheduling
1647 (see handling of reg_known_equiv in init_alias_analysis). */
1648 recompute_reg_usage ();
1650 #ifdef INSN_SCHEDULING
1651 if (optimize > 0 && flag_modulo_sched)
1652 rest_of_handle_sms ();
1654 if (flag_schedule_insns)
1655 rest_of_handle_sched ();
1656 #endif
1658 /* Determine if the current function is a leaf before running reload
1659 since this can impact optimizations done by the prologue and
1660 epilogue thus changing register elimination offsets. */
1661 current_function_is_leaf = leaf_function_p ();
1663 if (rest_of_handle_old_regalloc ())
1664 goto exit_rest_of_compilation;
1666 if (optimize > 0)
1667 rest_of_handle_postreload ();
1669 if (optimize > 0 && flag_gcse_after_reload)
1670 rest_of_handle_gcse2 ();
1672 rest_of_handle_flow2 ();
1674 #ifdef HAVE_peephole2
1675 if (optimize > 0 && flag_peephole2)
1676 rest_of_handle_peephole2 ();
1677 #endif
1679 if (optimize > 0)
1680 rest_of_handle_if_after_reload ();
1682 if (optimize > 0)
1684 if (flag_rename_registers || flag_cprop_registers)
1685 rest_of_handle_regrename ();
1687 rest_of_handle_reorder_blocks ();
1690 if (flag_branch_target_load_optimize2)
1691 rest_of_handle_branch_target_load_optimize ();
1693 #ifdef LEAF_REGISTERS
1694 current_function_uses_only_leaf_regs
1695 = optimize > 0 && only_leaf_regs_used () && leaf_function_p ();
1696 #endif
1698 #ifdef INSN_SCHEDULING
1699 if (optimize > 0 && flag_schedule_insns_after_reload)
1700 rest_of_handle_sched2 ();
1701 #endif
1703 #ifdef STACK_REGS
1704 rest_of_handle_stack_regs ();
1705 #endif
1707 compute_alignments ();
1709 /* Aggressively duplicate basic blocks ending in computed gotos to the
1710 tails of their predecessors, unless we are optimizing for size. */
1711 if (flag_expensive_optimizations && !optimize_size)
1712 duplicate_computed_gotos ();
1714 if (flag_var_tracking)
1715 rest_of_handle_variable_tracking ();
1717 /* CFG is no longer maintained up-to-date. */
1718 free_bb_for_insn ();
1720 if (targetm.machine_dependent_reorg != 0)
1721 rest_of_handle_machine_reorg ();
1723 purge_line_number_notes (get_insns ());
1724 cleanup_barriers ();
1726 #ifdef DELAY_SLOTS
1727 if (flag_delayed_branch)
1728 rest_of_handle_delay_slots ();
1729 #endif
1731 #if defined (HAVE_ATTR_length) && !defined (STACK_REGS)
1732 timevar_push (TV_SHORTEN_BRANCH);
1733 split_all_insns_noflow ();
1734 timevar_pop (TV_SHORTEN_BRANCH);
1735 #endif
1737 convert_to_eh_region_ranges ();
1739 rest_of_handle_shorten_branches ();
1741 set_nothrow_function_flags ();
1743 rest_of_handle_final ();
1745 exit_rest_of_compilation:
1747 rest_of_clean_state ();
1750 void
1751 finish_optimization_passes (void)
1753 enum tree_dump_index i;
1754 struct dump_file_info *dfi;
1755 char *name;
1757 timevar_push (TV_DUMP);
1758 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
1760 open_dump_file (DFI_bp, NULL);
1761 end_branch_prob ();
1762 close_dump_file (DFI_bp, NULL, NULL_RTX);
1765 if (optimize > 0 && open_dump_file (DFI_combine, NULL))
1767 dump_combine_total_stats (dump_file);
1768 close_dump_file (DFI_combine, NULL, NULL_RTX);
1771 /* Do whatever is necessary to finish printing the graphs. */
1772 if (graph_dump_format != no_graph)
1773 for (i = DFI_MIN; (dfi = get_dump_file_info (i)) != NULL; ++i)
1774 if (dump_initialized_p (i)
1775 && (dfi->flags & TDF_RTL) != 0
1776 && (name = get_dump_file_name (i)) != NULL)
1778 finish_graph_dump_file (name);
1779 free (name);
1782 timevar_pop (TV_DUMP);
1785 struct tree_opt_pass pass_rest_of_compilation =
1787 NULL, /* name */
1788 NULL, /* gate */
1789 rest_of_compilation, /* execute */
1790 NULL, /* sub */
1791 NULL, /* next */
1792 0, /* static_pass_number */
1793 TV_REST_OF_COMPILATION, /* tv_id */
1794 PROP_rtl, /* properties_required */
1795 0, /* properties_provided */
1796 PROP_rtl, /* properties_destroyed */
1797 0, /* todo_flags_start */
1798 TODO_ggc_collect, /* todo_flags_finish */
1799 0 /* letter */