* be.po, ca.po, da.po, de.po, el.po, es.po, fr.po, ja.po, nl.po,
[official-gcc.git] / gcc / passes.c
blob93126b020ea5d84ef18be188e045ca041cc7818b
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 "tree-pass.h"
82 #include "tree-dump.h"
84 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
85 #include "dwarf2out.h"
86 #endif
88 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
89 #include "dbxout.h"
90 #endif
92 #ifdef SDB_DEBUGGING_INFO
93 #include "sdbout.h"
94 #endif
96 #ifdef XCOFF_DEBUGGING_INFO
97 #include "xcoffout.h" /* Needed for external data
98 declarations for e.g. AIX 4.x. */
99 #endif
101 #ifndef HAVE_conditional_execution
102 #define HAVE_conditional_execution 0
103 #endif
105 /* Format to use to print dumpfile index value */
106 #ifndef DUMPFILE_FORMAT
107 #define DUMPFILE_FORMAT ".%02d."
108 #endif
110 static int initializing_dump = 0;
112 /* Routine to open a dump file. Return true if the dump file is enabled. */
114 static int
115 open_dump_file (enum tree_dump_index index, tree decl)
117 if (! dump_enabled_p (index))
118 return 0;
120 timevar_push (TV_DUMP);
122 gcc_assert (!dump_file && !dump_file_name);
124 dump_file_name = get_dump_file_name (index);
125 initializing_dump = !dump_initialized_p (index);
126 dump_file = dump_begin (index, NULL);
128 if (dump_file == NULL)
129 fatal_error ("can't open %s: %m", dump_file_name);
131 if (decl)
132 fprintf (dump_file, "\n;; Function %s%s\n\n",
133 lang_hooks.decl_printable_name (decl, 2),
134 cfun->function_frequency == FUNCTION_FREQUENCY_HOT
135 ? " (hot)"
136 : cfun->function_frequency == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED
137 ? " (unlikely executed)"
138 : "");
140 timevar_pop (TV_DUMP);
141 return 1;
144 /* Routine to close a dump file. */
146 static void
147 close_dump_file (enum tree_dump_index index,
148 void (*func) (FILE *, rtx),
149 rtx insns)
151 if (! dump_file)
152 return;
154 timevar_push (TV_DUMP);
155 if (insns
156 && graph_dump_format != no_graph)
158 /* If we've not initialized the files, do so now. */
159 if (initializing_dump)
160 clean_graph_dump_file (dump_file_name);
162 print_rtl_graph_with_bb (dump_file_name, insns);
165 if (func && insns)
166 func (dump_file, insns);
168 dump_end (index, dump_file);
169 free ((char *) dump_file_name);
171 dump_file = NULL;
172 dump_file_name = NULL;
173 timevar_pop (TV_DUMP);
176 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
177 and TYPE_DECL nodes.
179 This does nothing for local (non-static) variables, unless the
180 variable is a register variable with DECL_ASSEMBLER_NAME set. In
181 that case, or if the variable is not an automatic, it sets up the
182 RTL and outputs any assembler code (label definition, storage
183 allocation and initialization).
185 DECL is the declaration. TOP_LEVEL is nonzero
186 if this declaration is not within a function. */
188 void
189 rest_of_decl_compilation (tree decl,
190 int top_level,
191 int at_end)
193 /* We deferred calling assemble_alias so that we could collect
194 other attributes such as visibility. Emit the alias now. */
196 tree alias;
197 alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
198 if (alias)
200 alias = TREE_VALUE (TREE_VALUE (alias));
201 alias = get_identifier (TREE_STRING_POINTER (alias));
202 assemble_alias (decl, alias);
206 /* Can't defer this, because it needs to happen before any
207 later function definitions are processed. */
208 if (DECL_REGISTER (decl) && DECL_ASSEMBLER_NAME_SET_P (decl))
209 make_decl_rtl (decl);
211 /* Forward declarations for nested functions are not "external",
212 but we need to treat them as if they were. */
213 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
214 || TREE_CODE (decl) == FUNCTION_DECL)
216 timevar_push (TV_VARCONST);
218 /* Don't output anything when a tentative file-scope definition
219 is seen. But at end of compilation, do output code for them.
221 We do output all variables when unit-at-a-time is active and rely on
222 callgraph code to defer them except for forward declarations
223 (see gcc.c-torture/compile/920624-1.c) */
224 if ((at_end
225 || !DECL_DEFER_OUTPUT (decl)
226 || DECL_INITIAL (decl))
227 && !DECL_EXTERNAL (decl))
229 if (flag_unit_at_a_time && !cgraph_global_info_ready
230 && TREE_CODE (decl) != FUNCTION_DECL)
231 cgraph_varpool_finalize_decl (decl);
232 else
233 assemble_variable (decl, top_level, at_end, 0);
236 #ifdef ASM_FINISH_DECLARE_OBJECT
237 if (decl == last_assemble_variable_decl)
239 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
240 top_level, at_end);
242 #endif
244 timevar_pop (TV_VARCONST);
246 else if (TREE_CODE (decl) == TYPE_DECL)
248 timevar_push (TV_SYMOUT);
249 debug_hooks->type_decl (decl, !top_level);
250 timevar_pop (TV_SYMOUT);
253 /* Let cgraph know about the existence of variables. */
254 if (TREE_CODE (decl) == VAR_DECL && !DECL_EXTERNAL (decl))
255 cgraph_varpool_node (decl);
258 /* Called after finishing a record, union or enumeral type. */
260 void
261 rest_of_type_compilation (tree type, int toplev)
263 /* Avoid confusing the debug information machinery when there are
264 errors. */
265 if (errorcount != 0 || sorrycount != 0)
266 return;
268 timevar_push (TV_SYMOUT);
269 debug_hooks->type_decl (TYPE_STUB_DECL (type), !toplev);
270 timevar_pop (TV_SYMOUT);
273 /* Turn the RTL into assembly. */
274 static void
275 rest_of_handle_final (void)
277 timevar_push (TV_FINAL);
279 rtx x;
280 const char *fnname;
282 /* Get the function's name, as described by its RTL. This may be
283 different from the DECL_NAME name used in the source file. */
285 x = DECL_RTL (current_function_decl);
286 gcc_assert (MEM_P (x));
287 x = XEXP (x, 0);
288 gcc_assert (GET_CODE (x) == SYMBOL_REF);
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);
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 ();
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 basic_block bb;
575 sbitmap blocks;
577 timevar_push (TV_SMS);
578 open_dump_file (DFI_sms, current_function_decl);
580 /* We want to be able to create new pseudos. */
581 no_new_pseudos = 0;
582 /* Collect loop information to be used in SMS. */
583 cfg_layout_initialize (CLEANUP_UPDATE_LIFE);
584 sms_schedule (dump_file);
585 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 blocks = sbitmap_alloc (last_basic_block);
591 sbitmap_ones (blocks);
592 update_life_info (blocks, UPDATE_LIFE_GLOBAL_RM_NOTES,
593 (PROP_DEATH_NOTES
594 | PROP_REG_INFO
595 | PROP_KILL_DEAD_CODE
596 | PROP_SCAN_DEAD_CODE));
598 no_new_pseudos = 1;
600 /* Finalize layout changes. */
601 FOR_EACH_BB (bb)
602 if (bb->next_bb != EXIT_BLOCK_PTR)
603 bb->rbi->next = bb->next_bb;
604 cfg_layout_finalize ();
605 free_dominance_info (CDI_DOMINATORS);
606 ggc_collect ();
607 timevar_pop (TV_SMS);
610 /* Run instruction scheduler. */
611 static void
612 rest_of_handle_sched (void)
614 timevar_push (TV_SCHED);
616 /* Print function header into sched dump now
617 because doing the sched analysis makes some of the dump. */
618 open_dump_file (DFI_sched, current_function_decl);
620 /* Do control and data sched analysis,
621 and write some of the results to dump file. */
623 schedule_insns (dump_file);
625 close_dump_file (DFI_sched, print_rtl_with_bb, get_insns ());
627 ggc_collect ();
628 timevar_pop (TV_SCHED);
631 /* Run second scheduling pass after reload. */
632 static void
633 rest_of_handle_sched2 (void)
635 timevar_push (TV_SCHED2);
636 open_dump_file (DFI_sched2, current_function_decl);
638 /* Do control and data sched analysis again,
639 and write some more of the results to dump file. */
641 split_all_insns (1);
643 if (flag_sched2_use_superblocks || flag_sched2_use_traces)
645 schedule_ebbs (dump_file);
646 /* No liveness updating code yet, but it should be easy to do.
647 reg-stack recomputes the liveness when needed for now. */
648 count_or_remove_death_notes (NULL, 1);
649 cleanup_cfg (CLEANUP_EXPENSIVE);
651 else
652 schedule_insns (dump_file);
654 close_dump_file (DFI_sched2, print_rtl_with_bb, get_insns ());
656 ggc_collect ();
658 timevar_pop (TV_SCHED2);
660 #endif
662 static void
663 rest_of_handle_gcse2 (void)
665 timevar_push (TV_GCSE_AFTER_RELOAD);
666 open_dump_file (DFI_gcse2, current_function_decl);
668 gcse_after_reload_main (get_insns ());
669 rebuild_jump_labels (get_insns ());
670 delete_trivially_dead_insns (get_insns (), max_reg_num ());
671 close_dump_file (DFI_gcse2, print_rtl_with_bb, get_insns ());
673 ggc_collect ();
675 #ifdef ENABLE_CHECKING
676 verify_flow_info ();
677 #endif
679 timevar_pop (TV_GCSE_AFTER_RELOAD);
682 /* Register allocation pre-pass, to reduce number of moves necessary
683 for two-address machines. */
684 static void
685 rest_of_handle_regmove (void)
687 timevar_push (TV_REGMOVE);
688 open_dump_file (DFI_regmove, current_function_decl);
690 regmove_optimize (get_insns (), max_reg_num (), dump_file);
692 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
693 close_dump_file (DFI_regmove, print_rtl_with_bb, get_insns ());
695 ggc_collect ();
696 timevar_pop (TV_REGMOVE);
699 /* Run tracer. */
700 static void
701 rest_of_handle_tracer (void)
703 open_dump_file (DFI_tracer, current_function_decl);
704 if (dump_file)
705 dump_flow_info (dump_file);
706 tracer (0);
707 cleanup_cfg (CLEANUP_EXPENSIVE);
708 reg_scan (get_insns (), max_reg_num ());
709 close_dump_file (DFI_tracer, print_rtl_with_bb, get_insns ());
712 /* If-conversion and CFG cleanup. */
713 static void
714 rest_of_handle_if_conversion (void)
716 timevar_push (TV_IFCVT);
717 open_dump_file (DFI_ce1, current_function_decl);
719 if (flag_if_conversion)
721 if (dump_file)
722 dump_flow_info (dump_file);
723 cleanup_cfg (CLEANUP_EXPENSIVE);
724 reg_scan (get_insns (), max_reg_num ());
725 if_convert (0);
728 timevar_push (TV_JUMP);
729 cleanup_cfg (CLEANUP_EXPENSIVE);
730 reg_scan (get_insns (), max_reg_num ());
731 timevar_pop (TV_JUMP);
733 close_dump_file (DFI_ce1, print_rtl_with_bb, get_insns ());
734 timevar_pop (TV_IFCVT);
737 /* Rerun if-conversion, as combine may have simplified things enough
738 to now meet sequence length restrictions. */
739 static void
740 rest_of_handle_if_after_combine (void)
742 timevar_push (TV_IFCVT);
743 open_dump_file (DFI_ce2, current_function_decl);
745 no_new_pseudos = 0;
746 if_convert (1);
747 no_new_pseudos = 1;
749 close_dump_file (DFI_ce2, print_rtl_with_bb, get_insns ());
750 timevar_pop (TV_IFCVT);
753 static void
754 rest_of_handle_if_after_reload (void)
756 timevar_push (TV_IFCVT2);
757 open_dump_file (DFI_ce3, current_function_decl);
759 /* Last attempt to optimize CFG, as scheduling, peepholing and insn
760 splitting possibly introduced more crossjumping opportunities. */
761 cleanup_cfg (CLEANUP_EXPENSIVE
762 | CLEANUP_UPDATE_LIFE
763 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0));
764 if (flag_if_conversion2)
765 if_convert (1);
766 close_dump_file (DFI_ce3, print_rtl_with_bb, get_insns ());
767 timevar_pop (TV_IFCVT2);
770 static void
771 rest_of_handle_web (void)
773 open_dump_file (DFI_web, current_function_decl);
774 timevar_push (TV_WEB);
775 web_main ();
776 delete_trivially_dead_insns (get_insns (), max_reg_num ());
777 cleanup_cfg (CLEANUP_EXPENSIVE);
779 timevar_pop (TV_WEB);
780 close_dump_file (DFI_web, print_rtl_with_bb, get_insns ());
781 reg_scan (get_insns (), max_reg_num ());
784 /* Do branch profiling and static profile estimation passes. */
785 static void
786 rest_of_handle_branch_prob (void)
788 struct loops loops;
790 timevar_push (TV_BRANCH_PROB);
791 open_dump_file (DFI_bp, current_function_decl);
793 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
794 branch_prob ();
796 /* Discover and record the loop depth at the head of each basic
797 block. The loop infrastructure does the real job for us. */
798 flow_loops_find (&loops);
800 if (dump_file)
801 flow_loops_dump (&loops, dump_file, NULL, 0);
803 /* Estimate using heuristics if no profiling info is available. */
804 if (flag_guess_branch_prob)
805 estimate_probability (&loops);
807 flow_loops_free (&loops);
808 free_dominance_info (CDI_DOMINATORS);
809 close_dump_file (DFI_bp, print_rtl_with_bb, get_insns ());
810 timevar_pop (TV_BRANCH_PROB);
813 /* Do optimizations based on expression value profiles. */
814 static void
815 rest_of_handle_value_profile_transformations (void)
817 open_dump_file (DFI_vpt, current_function_decl);
818 timevar_push (TV_VPT);
820 if (value_profile_transformations ())
821 cleanup_cfg (CLEANUP_EXPENSIVE);
823 timevar_pop (TV_VPT);
824 close_dump_file (DFI_vpt, print_rtl_with_bb, get_insns ());
827 /* Do control and data flow analysis; write some of the results to the
828 dump file. */
829 static void
830 rest_of_handle_cfg (void)
832 open_dump_file (DFI_cfg, current_function_decl);
833 if (dump_file)
834 dump_flow_info (dump_file);
835 if (optimize)
836 cleanup_cfg (CLEANUP_EXPENSIVE
837 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
839 /* It may make more sense to mark constant functions after dead code is
840 eliminated by life_analysis, but we need to do it early, as -fprofile-arcs
841 may insert code making function non-constant, but we still must consider
842 it as constant, otherwise -fbranch-probabilities will not read data back.
844 life_analysis rarely eliminates modification of external memory.
846 FIXME: now with tree based profiling we are in the trap described above
847 again. It seems to be easiest to disable the optimization for time
848 being before the problem is either solved by moving the transformation
849 to the IPA level (we need the CFG for this) or the very early optimization
850 passes are made to ignore the const/pure flags so code does not change. */
851 if (optimize
852 && (!flag_tree_based_profiling
853 || (!profile_arc_flag && !flag_branch_probabilities)))
855 /* Alias analysis depends on this information and mark_constant_function
856 depends on alias analysis. */
857 reg_scan (get_insns (), max_reg_num ());
858 mark_constant_function ();
861 close_dump_file (DFI_cfg, print_rtl_with_bb, get_insns ());
864 /* Perform jump bypassing and control flow optimizations. */
865 static void
866 rest_of_handle_jump_bypass (void)
868 timevar_push (TV_BYPASS);
869 open_dump_file (DFI_bypass, current_function_decl);
871 cleanup_cfg (CLEANUP_EXPENSIVE);
872 reg_scan (get_insns (), max_reg_num ());
874 if (bypass_jumps (dump_file))
876 rebuild_jump_labels (get_insns ());
877 cleanup_cfg (CLEANUP_EXPENSIVE);
878 delete_trivially_dead_insns (get_insns (), max_reg_num ());
881 close_dump_file (DFI_bypass, print_rtl_with_bb, get_insns ());
882 timevar_pop (TV_BYPASS);
884 ggc_collect ();
886 #ifdef ENABLE_CHECKING
887 verify_flow_info ();
888 #endif
891 /* Try combining insns through substitution. */
892 static void
893 rest_of_handle_combine (void)
895 int rebuild_jump_labels_after_combine = 0;
897 timevar_push (TV_COMBINE);
898 open_dump_file (DFI_combine, current_function_decl);
900 rebuild_jump_labels_after_combine
901 = combine_instructions (get_insns (), max_reg_num ());
903 /* Combining insns may have turned an indirect jump into a
904 direct jump. Rebuild the JUMP_LABEL fields of jumping
905 instructions. */
906 if (rebuild_jump_labels_after_combine)
908 timevar_push (TV_JUMP);
909 rebuild_jump_labels (get_insns ());
910 timevar_pop (TV_JUMP);
912 delete_dead_jumptables ();
913 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
916 close_dump_file (DFI_combine, print_rtl_with_bb, get_insns ());
917 timevar_pop (TV_COMBINE);
919 ggc_collect ();
922 /* Perform life analysis. */
923 static void
924 rest_of_handle_life (void)
926 open_dump_file (DFI_life, current_function_decl);
927 regclass_init ();
929 #ifdef ENABLE_CHECKING
930 verify_flow_info ();
931 #endif
932 life_analysis (dump_file, PROP_FINAL);
933 if (optimize)
934 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE | CLEANUP_LOG_LINKS
935 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
937 if (extra_warnings)
939 setjmp_vars_warning (DECL_INITIAL (current_function_decl));
940 setjmp_args_warning ();
943 if (optimize)
945 if (initialize_uninitialized_subregs ())
947 /* Insns were inserted, and possibly pseudos created, so
948 things might look a bit different. */
949 allocate_reg_life_data ();
950 update_life_info (NULL, UPDATE_LIFE_GLOBAL_RM_NOTES,
951 PROP_LOG_LINKS | PROP_REG_INFO | PROP_DEATH_NOTES);
955 no_new_pseudos = 1;
957 close_dump_file (DFI_life, print_rtl_with_bb, get_insns ());
959 ggc_collect ();
962 /* Perform common subexpression elimination. Nonzero value from
963 `cse_main' means that jumps were simplified and some code may now
964 be unreachable, so do jump optimization again. */
965 static void
966 rest_of_handle_cse (void)
968 int tem;
970 open_dump_file (DFI_cse, current_function_decl);
971 if (dump_file)
972 dump_flow_info (dump_file);
973 timevar_push (TV_CSE);
975 reg_scan (get_insns (), max_reg_num ());
977 tem = cse_main (get_insns (), max_reg_num (), dump_file);
978 if (tem)
979 rebuild_jump_labels (get_insns ());
980 if (purge_all_dead_edges ())
981 delete_unreachable_blocks ();
983 delete_trivially_dead_insns (get_insns (), max_reg_num ());
985 /* If we are not running more CSE passes, then we are no longer
986 expecting CSE to be run. But always rerun it in a cheap mode. */
987 cse_not_expected = !flag_rerun_cse_after_loop && !flag_gcse;
989 if (tem)
990 delete_dead_jumptables ();
992 if (tem || optimize > 1)
993 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
995 timevar_pop (TV_CSE);
996 close_dump_file (DFI_cse, print_rtl_with_bb, get_insns ());
998 ggc_collect ();
1001 /* Run second CSE pass after loop optimizations. */
1002 static void
1003 rest_of_handle_cse2 (void)
1005 int tem;
1007 timevar_push (TV_CSE2);
1008 open_dump_file (DFI_cse2, current_function_decl);
1009 if (dump_file)
1010 dump_flow_info (dump_file);
1011 /* CFG is no longer maintained up-to-date. */
1012 tem = cse_main (get_insns (), max_reg_num (), dump_file);
1014 /* Run a pass to eliminate duplicated assignments to condition code
1015 registers. We have to run this after bypass_jumps, because it
1016 makes it harder for that pass to determine whether a jump can be
1017 bypassed safely. */
1018 cse_condition_code_reg ();
1020 purge_all_dead_edges ();
1021 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1023 if (tem)
1025 timevar_push (TV_JUMP);
1026 rebuild_jump_labels (get_insns ());
1027 delete_dead_jumptables ();
1028 cleanup_cfg (CLEANUP_EXPENSIVE);
1029 timevar_pop (TV_JUMP);
1031 reg_scan (get_insns (), max_reg_num ());
1032 close_dump_file (DFI_cse2, print_rtl_with_bb, get_insns ());
1033 timevar_pop (TV_CSE2);
1035 ggc_collect ();
1038 /* Perform global cse. */
1039 static void
1040 rest_of_handle_gcse (void)
1042 int save_csb, save_cfj;
1043 int tem2 = 0, tem;
1045 timevar_push (TV_GCSE);
1046 open_dump_file (DFI_gcse, current_function_decl);
1048 tem = gcse_main (get_insns (), dump_file);
1049 rebuild_jump_labels (get_insns ());
1050 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1052 save_csb = flag_cse_skip_blocks;
1053 save_cfj = flag_cse_follow_jumps;
1054 flag_cse_skip_blocks = flag_cse_follow_jumps = 0;
1056 /* If -fexpensive-optimizations, re-run CSE to clean up things done
1057 by gcse. */
1058 if (flag_expensive_optimizations)
1060 timevar_push (TV_CSE);
1061 reg_scan (get_insns (), max_reg_num ());
1062 tem2 = cse_main (get_insns (), max_reg_num (), dump_file);
1063 purge_all_dead_edges ();
1064 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1065 timevar_pop (TV_CSE);
1066 cse_not_expected = !flag_rerun_cse_after_loop;
1069 /* If gcse or cse altered any jumps, rerun jump optimizations to clean
1070 things up. */
1071 if (tem || tem2)
1073 timevar_push (TV_JUMP);
1074 rebuild_jump_labels (get_insns ());
1075 delete_dead_jumptables ();
1076 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
1077 timevar_pop (TV_JUMP);
1080 close_dump_file (DFI_gcse, print_rtl_with_bb, get_insns ());
1081 timevar_pop (TV_GCSE);
1083 ggc_collect ();
1084 flag_cse_skip_blocks = save_csb;
1085 flag_cse_follow_jumps = save_cfj;
1086 #ifdef ENABLE_CHECKING
1087 verify_flow_info ();
1088 #endif
1091 /* Move constant computations out of loops. */
1092 static void
1093 rest_of_handle_loop_optimize (void)
1095 int do_prefetch;
1097 timevar_push (TV_LOOP);
1098 open_dump_file (DFI_loop, current_function_decl);
1100 /* CFG is no longer maintained up-to-date. */
1101 free_bb_for_insn ();
1102 profile_status = PROFILE_ABSENT;
1104 do_prefetch = flag_prefetch_loop_arrays ? LOOP_PREFETCH : 0;
1106 if (flag_rerun_loop_opt)
1108 cleanup_barriers ();
1110 /* We only want to perform unrolling once. */
1111 loop_optimize (get_insns (), dump_file, 0);
1113 /* The first call to loop_optimize makes some instructions
1114 trivially dead. We delete those instructions now in the
1115 hope that doing so will make the heuristics in loop work
1116 better and possibly speed up compilation. */
1117 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1119 /* The regscan pass is currently necessary as the alias
1120 analysis code depends on this information. */
1121 reg_scan (get_insns (), max_reg_num ());
1123 cleanup_barriers ();
1124 loop_optimize (get_insns (), dump_file, do_prefetch);
1126 /* Loop can create trivially dead instructions. */
1127 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1128 find_basic_blocks (get_insns ());
1129 close_dump_file (DFI_loop, print_rtl, get_insns ());
1130 timevar_pop (TV_LOOP);
1132 ggc_collect ();
1135 /* Perform loop optimizations. It might be better to do them a bit
1136 sooner, but we want the profile feedback to work more
1137 efficiently. */
1138 static void
1139 rest_of_handle_loop2 (void)
1141 struct loops *loops;
1142 basic_block bb;
1144 if (!flag_move_loop_invariants
1145 && !flag_unswitch_loops
1146 && !flag_peel_loops
1147 && !flag_unroll_loops
1148 && !flag_branch_on_count_reg)
1149 return;
1151 timevar_push (TV_LOOP);
1152 open_dump_file (DFI_loop2, current_function_decl);
1153 if (dump_file)
1154 dump_flow_info (dump_file);
1156 /* Initialize structures for layout changes. */
1157 cfg_layout_initialize (0);
1159 loops = loop_optimizer_init (dump_file);
1161 if (loops)
1163 /* The optimizations: */
1164 if (flag_move_loop_invariants)
1165 move_loop_invariants (loops);
1167 if (flag_unswitch_loops)
1168 unswitch_loops (loops);
1170 if (flag_peel_loops || flag_unroll_loops)
1171 unroll_and_peel_loops (loops,
1172 (flag_peel_loops ? UAP_PEEL : 0) |
1173 (flag_unroll_loops ? UAP_UNROLL : 0) |
1174 (flag_unroll_all_loops ? UAP_UNROLL_ALL : 0));
1176 #ifdef HAVE_doloop_end
1177 if (flag_branch_on_count_reg && HAVE_doloop_end)
1178 doloop_optimize_loops (loops);
1179 #endif /* HAVE_doloop_end */
1181 loop_optimizer_finalize (loops, dump_file);
1184 free_dominance_info (CDI_DOMINATORS);
1186 /* Finalize layout changes. */
1187 FOR_EACH_BB (bb)
1188 if (bb->next_bb != EXIT_BLOCK_PTR)
1189 bb->rbi->next = bb->next_bb;
1190 cfg_layout_finalize ();
1192 cleanup_cfg (CLEANUP_EXPENSIVE);
1193 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1194 reg_scan (get_insns (), max_reg_num ());
1195 if (dump_file)
1196 dump_flow_info (dump_file);
1197 close_dump_file (DFI_loop2, print_rtl_with_bb, get_insns ());
1198 timevar_pop (TV_LOOP);
1199 ggc_collect ();
1202 static void
1203 rest_of_handle_branch_target_load_optimize (void)
1205 static int warned = 0;
1207 /* Leave this a warning for now so that it is possible to experiment
1208 with running this pass twice. In 3.6, we should either make this
1209 an error, or use separate dump files. */
1210 if (flag_branch_target_load_optimize
1211 && flag_branch_target_load_optimize2
1212 && !warned)
1214 warning (0, "branch target register load optimization is not intended "
1215 "to be run twice");
1217 warned = 1;
1220 open_dump_file (DFI_branch_target_load, current_function_decl);
1221 branch_target_load_optimize (epilogue_completed);
1222 close_dump_file (DFI_branch_target_load, print_rtl_with_bb, get_insns ());
1223 ggc_collect ();
1226 #ifdef OPTIMIZE_MODE_SWITCHING
1227 static void
1228 rest_of_handle_mode_switching (void)
1230 timevar_push (TV_MODE_SWITCH);
1232 no_new_pseudos = 0;
1233 optimize_mode_switching (NULL);
1234 no_new_pseudos = 1;
1236 timevar_pop (TV_MODE_SWITCH);
1238 #endif
1240 static void
1241 rest_of_handle_jump (void)
1243 ggc_collect ();
1245 timevar_push (TV_JUMP);
1246 open_dump_file (DFI_sibling, current_function_decl);
1248 delete_unreachable_blocks ();
1249 #ifdef ENABLE_CHECKING
1250 verify_flow_info ();
1251 #endif
1253 if (cfun->tail_call_emit)
1254 fixup_tail_calls ();
1256 close_dump_file (DFI_sibling, print_rtl, get_insns ());
1257 timevar_pop (TV_JUMP);
1260 static void
1261 rest_of_handle_eh (void)
1263 insn_locators_initialize ();
1264 /* Complete generation of exception handling code. */
1265 if (doing_eh (0))
1267 timevar_push (TV_JUMP);
1268 open_dump_file (DFI_eh, current_function_decl);
1270 cleanup_cfg (CLEANUP_PRE_LOOP | CLEANUP_NO_INSN_DEL);
1272 finish_eh_generation ();
1274 cleanup_cfg (CLEANUP_PRE_LOOP | CLEANUP_NO_INSN_DEL);
1276 close_dump_file (DFI_eh, print_rtl, get_insns ());
1277 timevar_pop (TV_JUMP);
1281 static void
1282 rest_of_handle_stack_adjustments (void)
1284 life_analysis (dump_file, PROP_POSTRELOAD);
1285 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE
1286 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0));
1288 /* This is kind of a heuristic. We need to run combine_stack_adjustments
1289 even for machines with possibly nonzero RETURN_POPS_ARGS
1290 and ACCUMULATE_OUTGOING_ARGS. We expect that only ports having
1291 push instructions will have popping returns. */
1292 #ifndef PUSH_ROUNDING
1293 if (!ACCUMULATE_OUTGOING_ARGS)
1294 #endif
1295 combine_stack_adjustments ();
1298 static void
1299 rest_of_handle_flow2 (void)
1301 timevar_push (TV_FLOW2);
1302 open_dump_file (DFI_flow2, current_function_decl);
1304 /* Re-create the death notes which were deleted during reload. */
1305 #ifdef ENABLE_CHECKING
1306 verify_flow_info ();
1307 #endif
1309 /* If optimizing, then go ahead and split insns now. */
1310 #ifndef STACK_REGS
1311 if (optimize > 0)
1312 #endif
1313 split_all_insns (0);
1315 if (flag_branch_target_load_optimize)
1317 close_dump_file (DFI_flow2, print_rtl_with_bb, get_insns ());
1318 rest_of_handle_branch_target_load_optimize ();
1319 open_dump_file (DFI_flow2, current_function_decl);
1322 if (optimize)
1323 cleanup_cfg (CLEANUP_EXPENSIVE);
1325 /* On some machines, the prologue and epilogue code, or parts thereof,
1326 can be represented as RTL. Doing so lets us schedule insns between
1327 it and the rest of the code and also allows delayed branch
1328 scheduling to operate in the epilogue. */
1329 thread_prologue_and_epilogue_insns (get_insns ());
1330 epilogue_completed = 1;
1332 if (optimize)
1333 rest_of_handle_stack_adjustments ();
1335 flow2_completed = 1;
1337 close_dump_file (DFI_flow2, print_rtl_with_bb, get_insns ());
1338 timevar_pop (TV_FLOW2);
1340 ggc_collect ();
1344 static void
1345 rest_of_handle_jump2 (void)
1347 open_dump_file (DFI_jump, current_function_decl);
1349 /* Always do one jump optimization pass to ensure that JUMP_LABEL fields
1350 are initialized and to compute whether control can drop off the end
1351 of the function. */
1353 timevar_push (TV_JUMP);
1354 /* Turn NOTE_INSN_EXPECTED_VALUE into REG_BR_PROB. Do this
1355 before jump optimization switches branch directions. */
1356 if (flag_guess_branch_prob)
1357 expected_value_to_br_prob ();
1359 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1360 reg_scan (get_insns (), max_reg_num ());
1361 if (dump_file)
1362 dump_flow_info (dump_file);
1363 cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_PRE_LOOP
1364 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
1366 create_loop_notes ();
1368 purge_line_number_notes (get_insns ());
1370 if (optimize)
1371 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
1373 /* Jump optimization, and the removal of NULL pointer checks, may
1374 have reduced the number of instructions substantially. CSE, and
1375 future passes, allocate arrays whose dimensions involve the
1376 maximum instruction UID, so if we can reduce the maximum UID
1377 we'll save big on memory. */
1378 renumber_insns (dump_file);
1380 close_dump_file (DFI_jump, print_rtl_with_bb, get_insns ());
1381 timevar_pop (TV_JUMP);
1383 ggc_collect ();
1386 #ifdef HAVE_peephole2
1387 static void
1388 rest_of_handle_peephole2 (void)
1390 timevar_push (TV_PEEPHOLE2);
1391 open_dump_file (DFI_peephole2, current_function_decl);
1393 peephole2_optimize (dump_file);
1395 close_dump_file (DFI_peephole2, print_rtl_with_bb, get_insns ());
1396 timevar_pop (TV_PEEPHOLE2);
1398 #endif
1400 static void
1401 rest_of_handle_postreload (void)
1403 timevar_push (TV_RELOAD_CSE_REGS);
1404 open_dump_file (DFI_postreload, current_function_decl);
1406 /* Do a very simple CSE pass over just the hard registers. */
1407 reload_cse_regs (get_insns ());
1408 /* reload_cse_regs can eliminate potentially-trapping MEMs.
1409 Remove any EH edges associated with them. */
1410 if (flag_non_call_exceptions)
1411 purge_all_dead_edges ();
1413 close_dump_file (DFI_postreload, print_rtl_with_bb, get_insns ());
1414 timevar_pop (TV_RELOAD_CSE_REGS);
1417 static void
1418 rest_of_handle_shorten_branches (void)
1420 /* Shorten branches. */
1421 timevar_push (TV_SHORTEN_BRANCH);
1422 shorten_branches (get_insns ());
1423 timevar_pop (TV_SHORTEN_BRANCH);
1426 static void
1427 rest_of_clean_state (void)
1429 rtx insn, next;
1431 /* It is very important to decompose the RTL instruction chain here:
1432 debug information keeps pointing into CODE_LABEL insns inside the function
1433 body. If these remain pointing to the other insns, we end up preserving
1434 whole RTL chain and attached detailed debug info in memory. */
1435 for (insn = get_insns (); insn; insn = next)
1437 next = NEXT_INSN (insn);
1438 NEXT_INSN (insn) = NULL;
1439 PREV_INSN (insn) = NULL;
1442 /* In case the function was not output,
1443 don't leave any temporary anonymous types
1444 queued up for sdb output. */
1445 #ifdef SDB_DEBUGGING_INFO
1446 if (write_symbols == SDB_DEBUG)
1447 sdbout_types (NULL_TREE);
1448 #endif
1450 reload_completed = 0;
1451 epilogue_completed = 0;
1452 flow2_completed = 0;
1453 no_new_pseudos = 0;
1455 timevar_push (TV_FINAL);
1457 /* Clear out the insn_length contents now that they are no
1458 longer valid. */
1459 init_insn_lengths ();
1461 /* Show no temporary slots allocated. */
1462 init_temp_slots ();
1464 free_basic_block_vars ();
1465 free_bb_for_insn ();
1467 timevar_pop (TV_FINAL);
1469 if (targetm.binds_local_p (current_function_decl))
1471 int pref = cfun->preferred_stack_boundary;
1472 if (cfun->stack_alignment_needed > cfun->preferred_stack_boundary)
1473 pref = cfun->stack_alignment_needed;
1474 cgraph_rtl_info (current_function_decl)->preferred_incoming_stack_boundary
1475 = pref;
1478 /* Make sure volatile mem refs aren't considered valid operands for
1479 arithmetic insns. We must call this here if this is a nested inline
1480 function, since the above code leaves us in the init_recog state
1481 (from final.c), and the function context push/pop code does not
1482 save/restore volatile_ok.
1484 ??? Maybe it isn't necessary for expand_start_function to call this
1485 anymore if we do it here? */
1487 init_recog_no_volatile ();
1489 /* We're done with this function. Free up memory if we can. */
1490 free_after_parsing (cfun);
1491 free_after_compilation (cfun);
1495 /* This function is called from the pass manager in tree-optimize.c
1496 after all tree passes have finished for a single function, and we
1497 have expanded the function body from trees to RTL.
1498 Once we are here, we have decided that we're supposed to output
1499 that function, i.e. that we should write assembler code for it.
1501 We run a series of low-level passes here on the function's RTL
1502 representation. Each pass is called via a rest_of_* function. */
1504 static void
1505 rest_of_compilation (void)
1507 /* If we're emitting a nested function, make sure its parent gets
1508 emitted as well. Doing otherwise confuses debug info. */
1510 tree parent;
1511 for (parent = DECL_CONTEXT (current_function_decl);
1512 parent != NULL_TREE;
1513 parent = get_containing_scope (parent))
1514 if (TREE_CODE (parent) == FUNCTION_DECL)
1515 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (parent)) = 1;
1518 /* We are now committed to emitting code for this function. Do any
1519 preparation, such as emitting abstract debug info for the inline
1520 before it gets mangled by optimization. */
1521 if (cgraph_function_possibly_inlined_p (current_function_decl))
1522 (*debug_hooks->outlining_inline_function) (current_function_decl);
1524 /* Remove any notes we don't need. That will make iterating
1525 over the instruction sequence faster, and allow the garbage
1526 collector to reclaim the memory used by the notes. */
1527 remove_unnecessary_notes ();
1529 /* Initialize some variables used by the optimizers. */
1530 init_function_for_compilation ();
1532 TREE_ASM_WRITTEN (current_function_decl) = 1;
1534 /* Early return if there were errors. We can run afoul of our
1535 consistency checks, and there's not really much point in fixing them. */
1536 if (rtl_dump_and_exit || flag_syntax_only || errorcount || sorrycount)
1537 goto exit_rest_of_compilation;
1539 rest_of_handle_jump ();
1541 rest_of_handle_eh ();
1543 /* Delay emitting hard_reg_initial_value sets until after EH landing pad
1544 generation, which might create new sets. */
1545 emit_initial_value_sets ();
1547 #ifdef FINALIZE_PIC
1548 /* If we are doing position-independent code generation, now
1549 is the time to output special prologues and epilogues.
1550 We do not want to do this earlier, because it just clutters
1551 up inline functions with meaningless insns. */
1552 if (flag_pic)
1553 FINALIZE_PIC;
1554 #endif
1556 /* Copy any shared structure that should not be shared. */
1557 unshare_all_rtl ();
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 */