]> gcc.gnu.org Git - gcc.git/blame - gcc/passes.c
re PR libgcj/17623 (URL does not retain userInfo across context constructor.)
[gcc.git] / gcc / passes.c
CommitLineData
f6db1481
RH
1/* Top level of GCC compilers (cc1, cc1plus, etc.)
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9Software Foundation; either version 2, or (at your option) any later
10version.
11
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
16
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING. If not, write to the Free
19Software Foundation, 59 Temple Place - Suite 330, Boston, MA
2002111-1307, USA. */
21
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. */
26
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>
34
35#ifdef HAVE_SYS_RESOURCE_H
36# include <sys/resource.h>
37#endif
38
39#ifdef HAVE_SYS_TIMES_H
40# include <sys/times.h>
41#endif
42
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"
f6db1481
RH
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"
2f8e398b 82#include "tree-pass.h"
9f8628ba 83#include "tree-dump.h"
f6db1481
RH
84
85#if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
86#include "dwarf2out.h"
87#endif
88
97b0ade3 89#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
f6db1481
RH
90#include "dbxout.h"
91#endif
92
93#ifdef SDB_DEBUGGING_INFO
94#include "sdbout.h"
95#endif
96
97#ifdef XCOFF_DEBUGGING_INFO
98#include "xcoffout.h" /* Needed for external data
99 declarations for e.g. AIX 4.x. */
100#endif
101
102#ifndef HAVE_conditional_execution
103#define HAVE_conditional_execution 0
104#endif
105
106/* Format to use to print dumpfile index value */
107#ifndef DUMPFILE_FORMAT
108#define DUMPFILE_FORMAT ".%02d."
109#endif
110
9f8628ba 111static int initializing_dump = 0;
f6db1481
RH
112
113/* Routine to open a dump file. Return true if the dump file is enabled. */
114
115static int
9f8628ba 116open_dump_file (enum tree_dump_index index, tree decl)
f6db1481 117{
9f8628ba 118 if (! dump_enabled_p (index))
f6db1481
RH
119 return 0;
120
121 timevar_push (TV_DUMP);
f6db1481 122
8127d0e0
NS
123 if (dump_file != NULL || dump_file_name != NULL)
124 abort ();
f6db1481 125
9f8628ba
PB
126 dump_file_name = get_dump_file_name (index);
127 initializing_dump = !dump_initialized_p (index);
128 dump_file = dump_begin (index, NULL);
f6db1481 129
f6db1481 130 if (dump_file == NULL)
9f8628ba 131 fatal_error ("can't open %s: %m", dump_file_name);
f6db1481
RH
132
133 if (decl)
134 fprintf (dump_file, "\n;; Function %s%s\n\n",
ae2bcd98 135 lang_hooks.decl_printable_name (decl, 2),
f6db1481
RH
136 cfun->function_frequency == FUNCTION_FREQUENCY_HOT
137 ? " (hot)"
138 : cfun->function_frequency == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED
139 ? " (unlikely executed)"
140 : "");
141
142 timevar_pop (TV_DUMP);
143 return 1;
144}
145
146/* Routine to close a dump file. */
147
148static void
9f8628ba 149close_dump_file (enum tree_dump_index index,
f6db1481
RH
150 void (*func) (FILE *, rtx),
151 rtx insns)
152{
153 if (! dump_file)
154 return;
155
156 timevar_push (TV_DUMP);
157 if (insns
9f8628ba 158 && graph_dump_format != no_graph)
f6db1481 159 {
9f8628ba
PB
160 /* If we've not initialized the files, do so now. */
161 if (initializing_dump)
162 clean_graph_dump_file (dump_file_name);
f6db1481 163
9f8628ba 164 print_rtl_graph_with_bb (dump_file_name, insns);
f6db1481
RH
165 }
166
167 if (func && insns)
168 func (dump_file, insns);
169
9f8628ba
PB
170 dump_end (index, dump_file);
171 free ((char *) dump_file_name);
f6db1481
RH
172
173 dump_file = NULL;
9f8628ba 174 dump_file_name = NULL;
f6db1481
RH
175 timevar_pop (TV_DUMP);
176}
177
178/* This is called from various places for FUNCTION_DECL, VAR_DECL,
179 and TYPE_DECL nodes.
180
181 This does nothing for local (non-static) variables, unless the
0e6df31e
GK
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).
f6db1481 186
0e6df31e 187 DECL is the declaration. TOP_LEVEL is nonzero
f6db1481
RH
188 if this declaration is not within a function. */
189
190void
191rest_of_decl_compilation (tree decl,
f6db1481
RH
192 int top_level,
193 int at_end)
194{
195 /* We deferred calling assemble_alias so that we could collect
196 other attributes such as visibility. Emit the alias now. */
197 {
198 tree alias;
199 alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
200 if (alias)
201 {
202 alias = TREE_VALUE (TREE_VALUE (alias));
203 alias = get_identifier (TREE_STRING_POINTER (alias));
204 assemble_alias (decl, alias);
205 }
206 }
207
0e6df31e
GK
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);
212
f6db1481
RH
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)
217 {
218 timevar_push (TV_VARCONST);
219
f6db1481
RH
220 /* Don't output anything when a tentative file-scope definition
221 is seen. But at end of compilation, do output code for them.
222
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))
230 {
231 if (flag_unit_at_a_time && !cgraph_global_info_ready
a0c71497
AO
232 && TREE_CODE (decl) != FUNCTION_DECL && top_level
233 /* If we defer processing of decls that have had their
234 DECL_RTL set above (say, in make_decl_rtl),
235 check_global_declarations() will clear it before
236 assemble_variable has a chance to act on it. This
237 would remove all traces of the register name in a
238 global register variable, for example. */
239 && !DECL_RTL_SET_P (decl))
f6db1481
RH
240 cgraph_varpool_finalize_decl (decl);
241 else
242 assemble_variable (decl, top_level, at_end, 0);
243 }
244
245#ifdef ASM_FINISH_DECLARE_OBJECT
246 if (decl == last_assemble_variable_decl)
247 {
248 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
249 top_level, at_end);
250 }
251#endif
252
253 timevar_pop (TV_VARCONST);
254 }
f6db1481
RH
255 else if (TREE_CODE (decl) == TYPE_DECL)
256 {
257 timevar_push (TV_SYMOUT);
258 debug_hooks->type_decl (decl, !top_level);
259 timevar_pop (TV_SYMOUT);
260 }
261}
262
263/* Called after finishing a record, union or enumeral type. */
264
265void
266rest_of_type_compilation (tree type, int toplev)
267{
268 /* Avoid confusing the debug information machinery when there are
269 errors. */
270 if (errorcount != 0 || sorrycount != 0)
271 return;
272
273 timevar_push (TV_SYMOUT);
274 debug_hooks->type_decl (TYPE_STUB_DECL (type), !toplev);
275 timevar_pop (TV_SYMOUT);
276}
277
278/* Turn the RTL into assembly. */
279static void
fd743bc1 280rest_of_handle_final (void)
f6db1481
RH
281{
282 timevar_push (TV_FINAL);
283 {
284 rtx x;
285 const char *fnname;
286
287 /* Get the function's name, as described by its RTL. This may be
288 different from the DECL_NAME name used in the source file. */
289
fd743bc1 290 x = DECL_RTL (current_function_decl);
8127d0e0
NS
291 if (!MEM_P (x))
292 abort ();
f6db1481 293 x = XEXP (x, 0);
8127d0e0
NS
294 if (GET_CODE (x) != SYMBOL_REF)
295 abort ();
f6db1481
RH
296 fnname = XSTR (x, 0);
297
fd743bc1
PB
298 assemble_start_function (current_function_decl, fnname);
299 final_start_function (get_insns (), asm_out_file, optimize);
300 final (get_insns (), asm_out_file, optimize, 0);
f6db1481
RH
301 final_end_function ();
302
951120ea 303#ifdef TARGET_UNWIND_INFO
f6db1481
RH
304 /* ??? The IA-64 ".handlerdata" directive must be issued before
305 the ".endp" directive that closes the procedure descriptor. */
306 output_function_exception_table ();
307#endif
308
fd743bc1 309 assemble_end_function (current_function_decl, fnname);
f6db1481 310
951120ea 311#ifndef TARGET_UNWIND_INFO
f6db1481
RH
312 /* Otherwise, it feels unclean to switch sections in the middle. */
313 output_function_exception_table ();
314#endif
315
9fb32434
CT
316 user_defined_section_attribute = false;
317
f6db1481
RH
318 if (! quiet_flag)
319 fflush (asm_out_file);
320
321 /* Release all memory allocated by flow. */
bb8a619e 322 free_basic_block_vars ();
f6db1481
RH
323
324 /* Release all memory held by regsets now. */
325 regset_release_memory ();
326 }
97b0ade3
PB
327
328 /* Write DBX symbols if requested. */
329
330 /* Note that for those inline functions where we don't initially
331 know for certain that we will be generating an out-of-line copy,
332 the first invocation of this routine (rest_of_compilation) will
333 skip over this code by doing a `goto exit_rest_of_compilation;'.
334 Later on, wrapup_global_declarations will (indirectly) call
335 rest_of_compilation again for those inline functions that need
336 to have out-of-line copies generated. During that call, we
337 *will* be routed past here. */
338
339 timevar_push (TV_SYMOUT);
340 (*debug_hooks->function_decl) (current_function_decl);
341 timevar_pop (TV_SYMOUT);
f6db1481
RH
342
343 ggc_collect ();
97b0ade3 344 timevar_pop (TV_FINAL);
f6db1481
RH
345}
346
347#ifdef DELAY_SLOTS
348/* Run delay slot optimization. */
349static void
fd743bc1 350rest_of_handle_delay_slots (void)
f6db1481
RH
351{
352 timevar_push (TV_DBR_SCHED);
fd743bc1 353 open_dump_file (DFI_dbr, current_function_decl);
f6db1481 354
fd743bc1 355 dbr_schedule (get_insns (), dump_file);
f6db1481 356
fd743bc1 357 close_dump_file (DFI_dbr, print_rtl, get_insns ());
f6db1481
RH
358
359 ggc_collect ();
97b0ade3
PB
360
361 timevar_pop (TV_DBR_SCHED);
f6db1481
RH
362}
363#endif
364
365#ifdef STACK_REGS
366/* Convert register usage from flat register file usage to a stack
367 register file. */
368static void
fd743bc1 369rest_of_handle_stack_regs (void)
f6db1481
RH
370{
371#if defined (HAVE_ATTR_length)
372 /* If flow2 creates new instructions which need splitting
373 and scheduling after reload is not done, they might not be
374 split until final which doesn't allow splitting
375 if HAVE_ATTR_length. */
376#ifdef INSN_SCHEDULING
377 if (optimize && !flag_schedule_insns_after_reload)
378#else
379 if (optimize)
380#endif
381 {
382 timevar_push (TV_SHORTEN_BRANCH);
383 split_all_insns (1);
384 timevar_pop (TV_SHORTEN_BRANCH);
385 }
386#endif
387
388 timevar_push (TV_REG_STACK);
fd743bc1 389 open_dump_file (DFI_stack, current_function_decl);
f6db1481 390
827c06b6 391 if (reg_to_stack (dump_file) && optimize)
f6db1481
RH
392 {
393 if (cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK
394 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0))
750054a2 395 && (flag_reorder_blocks || flag_reorder_blocks_and_partition))
f6db1481 396 {
35b6b437 397 reorder_basic_blocks (0);
f6db1481
RH
398 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK);
399 }
400 }
401
fd743bc1 402 close_dump_file (DFI_stack, print_rtl_with_bb, get_insns ());
f6db1481
RH
403
404 ggc_collect ();
97b0ade3 405 timevar_pop (TV_REG_STACK);
f6db1481
RH
406}
407#endif
408
89dbed81 409/* Track the variables, i.e. compute where the variable is stored at each position in function. */
f6db1481 410static void
fd743bc1 411rest_of_handle_variable_tracking (void)
f6db1481
RH
412{
413 timevar_push (TV_VAR_TRACKING);
fd743bc1 414 open_dump_file (DFI_vartrack, current_function_decl);
f6db1481
RH
415
416 variable_tracking_main ();
417
fd743bc1 418 close_dump_file (DFI_vartrack, print_rtl_with_bb, get_insns ());
f6db1481
RH
419 timevar_pop (TV_VAR_TRACKING);
420}
421
97b0ade3 422/* Machine dependent reorg pass. */
f6db1481 423static void
fd743bc1 424rest_of_handle_machine_reorg (void)
f6db1481
RH
425{
426 timevar_push (TV_MACH_DEP);
fd743bc1 427 open_dump_file (DFI_mach, current_function_decl);
f6db1481 428
5fd9b178 429 targetm.machine_dependent_reorg ();
f6db1481 430
fd743bc1 431 close_dump_file (DFI_mach, print_rtl, get_insns ());
f6db1481
RH
432
433 ggc_collect ();
97b0ade3 434 timevar_pop (TV_MACH_DEP);
f6db1481
RH
435}
436
437
438/* Run new register allocator. Return TRUE if we must exit
439 rest_of_compilation upon return. */
440static bool
fd743bc1 441rest_of_handle_new_regalloc (void)
f6db1481
RH
442{
443 int failure;
444
97b0ade3
PB
445 timevar_push (TV_LOCAL_ALLOC);
446 open_dump_file (DFI_lreg, current_function_decl);
447
fd743bc1 448 delete_trivially_dead_insns (get_insns (), max_reg_num ());
f6db1481
RH
449 reg_alloc ();
450
451 timevar_pop (TV_LOCAL_ALLOC);
97b0ade3 452 close_dump_file (DFI_lreg, NULL, NULL);
f6db1481
RH
453
454 /* XXX clean up the whole mess to bring live info in shape again. */
455 timevar_push (TV_GLOBAL_ALLOC);
fd743bc1 456 open_dump_file (DFI_greg, current_function_decl);
f6db1481 457
fd743bc1
PB
458 build_insn_chain (get_insns ());
459 failure = reload (get_insns (), 0);
f6db1481
RH
460
461 timevar_pop (TV_GLOBAL_ALLOC);
462
97b0ade3
PB
463 ggc_collect ();
464
9f8628ba 465 if (dump_enabled_p (DFI_greg))
f6db1481
RH
466 {
467 timevar_push (TV_DUMP);
f6db1481 468 dump_global_regs (dump_file);
f6db1481 469 timevar_pop (TV_DUMP);
97b0ade3 470 close_dump_file (DFI_greg, print_rtl_with_bb, get_insns ());
f6db1481
RH
471 }
472
473 if (failure)
474 return true;
475
476 reload_completed = 1;
477
478 return false;
479}
480
481/* Run old register allocator. Return TRUE if we must exit
482 rest_of_compilation upon return. */
483static bool
fd743bc1 484rest_of_handle_old_regalloc (void)
f6db1481
RH
485{
486 int failure;
487 int rebuild_notes;
488
97b0ade3
PB
489 timevar_push (TV_LOCAL_ALLOC);
490 open_dump_file (DFI_lreg, current_function_decl);
491
f6db1481
RH
492 /* Allocate the reg_renumber array. */
493 allocate_reg_info (max_regno, FALSE, TRUE);
494
495 /* And the reg_equiv_memory_loc array. */
965ccc5a
R
496 VARRAY_GROW (reg_equiv_memory_loc_varray, max_regno);
497 reg_equiv_memory_loc = &VARRAY_RTX (reg_equiv_memory_loc_varray, 0);
f6db1481
RH
498
499 allocate_initial_values (reg_equiv_memory_loc);
500
fd743bc1 501 regclass (get_insns (), max_reg_num (), dump_file);
f6db1481
RH
502 rebuild_notes = local_alloc ();
503
504 timevar_pop (TV_LOCAL_ALLOC);
505
506 /* Local allocation may have turned an indirect jump into a direct
507 jump. If so, we must rebuild the JUMP_LABEL fields of jumping
508 instructions. */
509 if (rebuild_notes)
510 {
511 timevar_push (TV_JUMP);
512
fd743bc1 513 rebuild_jump_labels (get_insns ());
f6db1481
RH
514 purge_all_dead_edges (0);
515
516 timevar_pop (TV_JUMP);
517 }
518
9f8628ba 519 if (dump_enabled_p (DFI_lreg))
f6db1481
RH
520 {
521 timevar_push (TV_DUMP);
f6db1481
RH
522 dump_flow_info (dump_file);
523 dump_local_alloc (dump_file);
f6db1481
RH
524 timevar_pop (TV_DUMP);
525 }
526
97b0ade3
PB
527 close_dump_file (DFI_lreg, print_rtl_with_bb, get_insns ());
528
f6db1481
RH
529 ggc_collect ();
530
531 timevar_push (TV_GLOBAL_ALLOC);
fd743bc1 532 open_dump_file (DFI_greg, current_function_decl);
f6db1481
RH
533
534 /* If optimizing, allocate remaining pseudo-regs. Do the reload
535 pass fixing up any insns that are invalid. */
536
537 if (optimize)
538 failure = global_alloc (dump_file);
539 else
540 {
fd743bc1
PB
541 build_insn_chain (get_insns ());
542 failure = reload (get_insns (), 0);
f6db1481
RH
543 }
544
9f8628ba 545 if (dump_enabled_p (DFI_greg))
f6db1481
RH
546 {
547 timevar_push (TV_DUMP);
f6db1481 548 dump_global_regs (dump_file);
97b0ade3 549 timevar_pop (TV_DUMP);
f6db1481 550
fd743bc1 551 close_dump_file (DFI_greg, print_rtl_with_bb, get_insns ());
f6db1481
RH
552 }
553
97b0ade3
PB
554 ggc_collect ();
555
556 timevar_pop (TV_GLOBAL_ALLOC);
557
f6db1481
RH
558 return failure;
559}
560
561/* Run the regrename and cprop passes. */
562static void
fd743bc1 563rest_of_handle_regrename (void)
f6db1481
RH
564{
565 timevar_push (TV_RENAME_REGISTERS);
fd743bc1 566 open_dump_file (DFI_rnreg, current_function_decl);
f6db1481
RH
567
568 if (flag_rename_registers)
569 regrename_optimize ();
570 if (flag_cprop_registers)
571 copyprop_hardreg_forward ();
572
fd743bc1 573 close_dump_file (DFI_rnreg, print_rtl_with_bb, get_insns ());
f6db1481
RH
574 timevar_pop (TV_RENAME_REGISTERS);
575}
576
577/* Reorder basic blocks. */
578static void
fd743bc1 579rest_of_handle_reorder_blocks (void)
f6db1481
RH
580{
581 bool changed;
35b6b437
RS
582 unsigned int liveness_flags;
583
fd743bc1 584 open_dump_file (DFI_bbro, current_function_decl);
2f8e398b 585
f6db1481
RH
586 /* Last attempt to optimize CFG, as scheduling, peepholing and insn
587 splitting possibly introduced more crossjumping opportunities. */
35b6b437
RS
588 liveness_flags = (!HAVE_conditional_execution ? CLEANUP_UPDATE_LIFE : 0);
589 changed = cleanup_cfg (CLEANUP_EXPENSIVE | liveness_flags);
f6db1481
RH
590
591 if (flag_sched2_use_traces && flag_schedule_insns_after_reload)
35b6b437 592 tracer (liveness_flags);
750054a2 593 if (flag_reorder_blocks || flag_reorder_blocks_and_partition)
35b6b437 594 reorder_basic_blocks (liveness_flags);
750054a2 595 if (flag_reorder_blocks || flag_reorder_blocks_and_partition
f6db1481 596 || (flag_sched2_use_traces && flag_schedule_insns_after_reload))
35b6b437 597 changed |= cleanup_cfg (CLEANUP_EXPENSIVE | liveness_flags);
f6db1481
RH
598
599 /* On conditional execution targets we can not update the life cheaply, so
600 we deffer the updating to after both cleanups. This may lose some cases
601 but should not be terribly bad. */
602 if (changed && HAVE_conditional_execution)
603 update_life_info (NULL, UPDATE_LIFE_GLOBAL_RM_NOTES,
604 PROP_DEATH_NOTES);
fd743bc1 605 close_dump_file (DFI_bbro, print_rtl_with_bb, get_insns ());
f6db1481
RH
606}
607
97b0ade3
PB
608/* Partition hot and cold basic blocks. */
609static void
610rest_of_handle_partition_blocks (void)
611{
612 no_new_pseudos = 0;
613 partition_hot_cold_basic_blocks ();
614 allocate_reg_life_data ();
615 update_life_info (NULL, UPDATE_LIFE_GLOBAL_RM_NOTES,
616 PROP_LOG_LINKS | PROP_REG_INFO | PROP_DEATH_NOTES);
617 no_new_pseudos = 1;
618}
619
f6db1481
RH
620#ifdef INSN_SCHEDULING
621/* Run instruction scheduler. */
97b0ade3 622/* Perform SMS module scheduling. */
f6db1481 623static void
97b0ade3 624rest_of_handle_sms (void)
f6db1481 625{
e5626198 626 timevar_push (TV_SMS);
97b0ade3 627 open_dump_file (DFI_sms, current_function_decl);
e5626198 628
97b0ade3
PB
629 /* We want to be able to create new pseudos. */
630 no_new_pseudos = 0;
631 sms_schedule (dump_file);
632 close_dump_file (DFI_sms, print_rtl, get_insns ());
e5626198 633
e5626198 634
97b0ade3
PB
635 /* Update the life information, because we add pseudos. */
636 max_regno = max_reg_num ();
637 allocate_reg_info (max_regno, FALSE, FALSE);
638 update_life_info_in_dirty_blocks (UPDATE_LIFE_GLOBAL_RM_NOTES,
639 (PROP_DEATH_NOTES
640 | PROP_KILL_DEAD_CODE
641 | PROP_SCAN_DEAD_CODE));
642 no_new_pseudos = 1;
e5626198 643
97b0ade3 644 ggc_collect ();
e5626198 645 timevar_pop (TV_SMS);
97b0ade3
PB
646}
647
648/* Run instruction scheduler. */
649static void
650rest_of_handle_sched (void)
651{
f6db1481
RH
652 timevar_push (TV_SCHED);
653
654 /* Print function header into sched dump now
655 because doing the sched analysis makes some of the dump. */
97b0ade3 656 open_dump_file (DFI_sched, current_function_decl);
f6db1481 657
97b0ade3
PB
658 /* Do control and data sched analysis,
659 and write some of the results to dump file. */
f6db1481 660
97b0ade3 661 schedule_insns (dump_file);
f6db1481 662
97b0ade3 663 close_dump_file (DFI_sched, print_rtl_with_bb, get_insns ());
f6db1481
RH
664
665 ggc_collect ();
97b0ade3 666 timevar_pop (TV_SCHED);
f6db1481
RH
667}
668
669/* Run second scheduling pass after reload. */
670static void
fd743bc1 671rest_of_handle_sched2 (void)
f6db1481
RH
672{
673 timevar_push (TV_SCHED2);
fd743bc1 674 open_dump_file (DFI_sched2, current_function_decl);
f6db1481
RH
675
676 /* Do control and data sched analysis again,
677 and write some more of the results to dump file. */
678
679 split_all_insns (1);
680
681 if (flag_sched2_use_superblocks || flag_sched2_use_traces)
682 {
683 schedule_ebbs (dump_file);
684 /* No liveness updating code yet, but it should be easy to do.
4ee31f1e 685 reg-stack recomputes the liveness when needed for now. */
f6db1481
RH
686 count_or_remove_death_notes (NULL, 1);
687 cleanup_cfg (CLEANUP_EXPENSIVE);
688 }
689 else
690 schedule_insns (dump_file);
691
fd743bc1 692 close_dump_file (DFI_sched2, print_rtl_with_bb, get_insns ());
f6db1481
RH
693
694 ggc_collect ();
97b0ade3
PB
695
696 timevar_pop (TV_SCHED2);
f6db1481
RH
697}
698#endif
699
f9957958 700static void
fd743bc1 701rest_of_handle_gcse2 (void)
f9957958 702{
0516f6fe 703 timevar_push (TV_GCSE_AFTER_RELOAD);
fd743bc1 704 open_dump_file (DFI_gcse2, current_function_decl);
f9957958 705
0516f6fe 706 gcse_after_reload_main (get_insns ());
fd743bc1
PB
707 rebuild_jump_labels (get_insns ());
708 delete_trivially_dead_insns (get_insns (), max_reg_num ());
709 close_dump_file (DFI_gcse2, print_rtl_with_bb, get_insns ());
f9957958
MH
710
711 ggc_collect ();
712
713#ifdef ENABLE_CHECKING
714 verify_flow_info ();
715#endif
97b0ade3 716
0516f6fe 717 timevar_pop (TV_GCSE_AFTER_RELOAD);
f9957958
MH
718}
719
f6db1481
RH
720/* Register allocation pre-pass, to reduce number of moves necessary
721 for two-address machines. */
722static void
fd743bc1 723rest_of_handle_regmove (void)
f6db1481
RH
724{
725 timevar_push (TV_REGMOVE);
fd743bc1 726 open_dump_file (DFI_regmove, current_function_decl);
f6db1481 727
fd743bc1 728 regmove_optimize (get_insns (), max_reg_num (), dump_file);
f6db1481
RH
729
730 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
fd743bc1 731 close_dump_file (DFI_regmove, print_rtl_with_bb, get_insns ());
f6db1481
RH
732
733 ggc_collect ();
97b0ade3 734 timevar_pop (TV_REGMOVE);
f6db1481
RH
735}
736
737/* Run tracer. */
738static void
fd743bc1 739rest_of_handle_tracer (void)
f6db1481 740{
fd743bc1 741 open_dump_file (DFI_tracer, current_function_decl);
f6db1481
RH
742 if (dump_file)
743 dump_flow_info (dump_file);
35b6b437 744 tracer (0);
f6db1481 745 cleanup_cfg (CLEANUP_EXPENSIVE);
fd743bc1 746 reg_scan (get_insns (), max_reg_num (), 0);
f6db1481
RH
747 close_dump_file (DFI_tracer, print_rtl_with_bb, get_insns ());
748}
749
750/* If-conversion and CFG cleanup. */
751static void
fd743bc1 752rest_of_handle_if_conversion (void)
f6db1481 753{
97b0ade3 754 timevar_push (TV_IFCVT);
fd743bc1 755 open_dump_file (DFI_ce1, current_function_decl);
97b0ade3 756
f6db1481
RH
757 if (flag_if_conversion)
758 {
f6db1481
RH
759 if (dump_file)
760 dump_flow_info (dump_file);
761 cleanup_cfg (CLEANUP_EXPENSIVE);
fd743bc1 762 reg_scan (get_insns (), max_reg_num (), 0);
f6db1481 763 if_convert (0);
f6db1481 764 }
97b0ade3 765
f6db1481
RH
766 timevar_push (TV_JUMP);
767 cleanup_cfg (CLEANUP_EXPENSIVE);
fd743bc1 768 reg_scan (get_insns (), max_reg_num (), 0);
f6db1481 769 timevar_pop (TV_JUMP);
97b0ade3 770
f6db1481 771 close_dump_file (DFI_ce1, print_rtl_with_bb, get_insns ());
97b0ade3 772 timevar_pop (TV_IFCVT);
f6db1481
RH
773}
774
775/* Rerun if-conversion, as combine may have simplified things enough
776 to now meet sequence length restrictions. */
777static void
fd743bc1 778rest_of_handle_if_after_combine (void)
f6db1481
RH
779{
780 timevar_push (TV_IFCVT);
fd743bc1 781 open_dump_file (DFI_ce2, current_function_decl);
f6db1481
RH
782
783 no_new_pseudos = 0;
784 if_convert (1);
785 no_new_pseudos = 1;
786
fd743bc1 787 close_dump_file (DFI_ce2, print_rtl_with_bb, get_insns ());
f6db1481
RH
788 timevar_pop (TV_IFCVT);
789}
790
97b0ade3
PB
791static void
792rest_of_handle_if_after_reload (void)
793{
794 timevar_push (TV_IFCVT2);
795 open_dump_file (DFI_ce3, current_function_decl);
796
797 /* Last attempt to optimize CFG, as scheduling, peepholing and insn
798 splitting possibly introduced more crossjumping opportunities. */
799 cleanup_cfg (CLEANUP_EXPENSIVE
800 | CLEANUP_UPDATE_LIFE
801 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0));
802 if (flag_if_conversion2)
803 if_convert (1);
804 close_dump_file (DFI_ce3, print_rtl_with_bb, get_insns ());
805 timevar_pop (TV_IFCVT2);
806}
807
f6db1481 808static void
fd743bc1 809rest_of_handle_web (void)
f6db1481 810{
fd743bc1 811 open_dump_file (DFI_web, current_function_decl);
f6db1481
RH
812 timevar_push (TV_WEB);
813 web_main ();
fd743bc1 814 delete_trivially_dead_insns (get_insns (), max_reg_num ());
f6db1481
RH
815 cleanup_cfg (CLEANUP_EXPENSIVE);
816
817 timevar_pop (TV_WEB);
fd743bc1 818 close_dump_file (DFI_web, print_rtl_with_bb, get_insns ());
f6db1481
RH
819 reg_scan (get_insns (), max_reg_num (), 0);
820}
821
822/* Do branch profiling and static profile estimation passes. */
823static void
fd743bc1 824rest_of_handle_branch_prob (void)
f6db1481
RH
825{
826 struct loops loops;
97b0ade3 827
f6db1481 828 timevar_push (TV_BRANCH_PROB);
fd743bc1 829 open_dump_file (DFI_bp, current_function_decl);
f6db1481
RH
830
831 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
832 branch_prob ();
833
834 /* Discover and record the loop depth at the head of each basic
835 block. The loop infrastructure does the real job for us. */
836 flow_loops_find (&loops, LOOP_TREE);
837
838 if (dump_file)
839 flow_loops_dump (&loops, dump_file, NULL, 0);
840
841 /* Estimate using heuristics if no profiling info is available. */
842 if (flag_guess_branch_prob)
843 estimate_probability (&loops);
844
845 flow_loops_free (&loops);
846 free_dominance_info (CDI_DOMINATORS);
fd743bc1 847 close_dump_file (DFI_bp, print_rtl_with_bb, get_insns ());
f6db1481
RH
848 timevar_pop (TV_BRANCH_PROB);
849}
850
851/* Do optimizations based on expression value profiles. */
852static void
fd743bc1 853rest_of_handle_value_profile_transformations (void)
f6db1481 854{
fd743bc1 855 open_dump_file (DFI_vpt, current_function_decl);
f6db1481
RH
856 timevar_push (TV_VPT);
857
858 if (value_profile_transformations ())
859 cleanup_cfg (CLEANUP_EXPENSIVE);
860
861 timevar_pop (TV_VPT);
fd743bc1 862 close_dump_file (DFI_vpt, print_rtl_with_bb, get_insns ());
f6db1481
RH
863}
864
865/* Do control and data flow analysis; write some of the results to the
866 dump file. */
867static void
fd743bc1 868rest_of_handle_cfg (void)
f6db1481 869{
fd743bc1 870 open_dump_file (DFI_cfg, current_function_decl);
f6db1481
RH
871 if (dump_file)
872 dump_flow_info (dump_file);
873 if (optimize)
874 cleanup_cfg (CLEANUP_EXPENSIVE
875 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
876
877 /* It may make more sense to mark constant functions after dead code is
878 eliminated by life_analysis, but we need to do it early, as -fprofile-arcs
879 may insert code making function non-constant, but we still must consider
880 it as constant, otherwise -fbranch-probabilities will not read data back.
881
882 life_analysis rarely eliminates modification of external memory.
883 */
884 if (optimize)
885 {
886 /* Alias analysis depends on this information and mark_constant_function
887 depends on alias analysis. */
fd743bc1 888 reg_scan (get_insns (), max_reg_num (), 1);
f6db1481
RH
889 mark_constant_function ();
890 }
891
fd743bc1 892 close_dump_file (DFI_cfg, print_rtl_with_bb, get_insns ());
f6db1481
RH
893}
894
f6db1481
RH
895/* Perform jump bypassing and control flow optimizations. */
896static void
fd743bc1 897rest_of_handle_jump_bypass (void)
f6db1481
RH
898{
899 timevar_push (TV_BYPASS);
fd743bc1 900 open_dump_file (DFI_bypass, current_function_decl);
f6db1481
RH
901
902 cleanup_cfg (CLEANUP_EXPENSIVE);
fd743bc1 903 reg_scan (get_insns (), max_reg_num (), 1);
f6db1481
RH
904
905 if (bypass_jumps (dump_file))
906 {
fd743bc1 907 rebuild_jump_labels (get_insns ());
f6db1481 908 cleanup_cfg (CLEANUP_EXPENSIVE);
fd743bc1 909 delete_trivially_dead_insns (get_insns (), max_reg_num ());
f6db1481
RH
910 }
911
fd743bc1 912 close_dump_file (DFI_bypass, print_rtl_with_bb, get_insns ());
f6db1481
RH
913 timevar_pop (TV_BYPASS);
914
915 ggc_collect ();
916
917#ifdef ENABLE_CHECKING
918 verify_flow_info ();
919#endif
920}
921
f6db1481
RH
922/* Try combining insns through substitution. */
923static void
fd743bc1 924rest_of_handle_combine (void)
f6db1481
RH
925{
926 int rebuild_jump_labels_after_combine = 0;
927
928 timevar_push (TV_COMBINE);
fd743bc1 929 open_dump_file (DFI_combine, current_function_decl);
f6db1481
RH
930
931 rebuild_jump_labels_after_combine
fd743bc1 932 = combine_instructions (get_insns (), max_reg_num ());
f6db1481 933
97b0ade3 934 /* Combining insns may have turned an indirect jump into a
f6db1481
RH
935 direct jump. Rebuild the JUMP_LABEL fields of jumping
936 instructions. */
937 if (rebuild_jump_labels_after_combine)
938 {
939 timevar_push (TV_JUMP);
fd743bc1 940 rebuild_jump_labels (get_insns ());
f6db1481
RH
941 timevar_pop (TV_JUMP);
942
943 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
944 }
945
fd743bc1 946 close_dump_file (DFI_combine, print_rtl_with_bb, get_insns ());
f6db1481
RH
947 timevar_pop (TV_COMBINE);
948
949 ggc_collect ();
950}
951
952/* Perform life analysis. */
953static void
fd743bc1 954rest_of_handle_life (void)
f6db1481 955{
fd743bc1 956 open_dump_file (DFI_life, current_function_decl);
f6db1481
RH
957 regclass_init ();
958
959#ifdef ENABLE_CHECKING
960 verify_flow_info ();
961#endif
827c06b6 962 life_analysis (dump_file, PROP_FINAL);
f6db1481
RH
963 if (optimize)
964 cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_UPDATE_LIFE
965 | CLEANUP_LOG_LINKS
966 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
f6db1481 967
6de9cd9a 968 if (extra_warnings)
f6db1481 969 {
fd743bc1 970 setjmp_vars_warning (DECL_INITIAL (current_function_decl));
6de9cd9a 971 setjmp_args_warning ();
f6db1481
RH
972 }
973
974 if (optimize)
975 {
976 if (!flag_new_regalloc && initialize_uninitialized_subregs ())
977 {
978 /* Insns were inserted, and possibly pseudos created, so
979 things might look a bit different. */
f6db1481
RH
980 allocate_reg_life_data ();
981 update_life_info (NULL, UPDATE_LIFE_GLOBAL_RM_NOTES,
982 PROP_LOG_LINKS | PROP_REG_INFO | PROP_DEATH_NOTES);
983 }
984 }
985
986 no_new_pseudos = 1;
987
fd743bc1 988 close_dump_file (DFI_life, print_rtl_with_bb, get_insns ());
f6db1481
RH
989
990 ggc_collect ();
991}
992
993/* Perform common subexpression elimination. Nonzero value from
994 `cse_main' means that jumps were simplified and some code may now
995 be unreachable, so do jump optimization again. */
996static void
fd743bc1 997rest_of_handle_cse (void)
f6db1481
RH
998{
999 int tem;
97b0ade3 1000
fd743bc1 1001 open_dump_file (DFI_cse, current_function_decl);
f6db1481
RH
1002 if (dump_file)
1003 dump_flow_info (dump_file);
1004 timevar_push (TV_CSE);
1005
fd743bc1 1006 reg_scan (get_insns (), max_reg_num (), 1);
f6db1481 1007
5affca01 1008 tem = cse_main (get_insns (), max_reg_num (), dump_file);
f6db1481 1009 if (tem)
fd743bc1 1010 rebuild_jump_labels (get_insns ());
f6db1481
RH
1011 if (purge_all_dead_edges (0))
1012 delete_unreachable_blocks ();
1013
fd743bc1 1014 delete_trivially_dead_insns (get_insns (), max_reg_num ());
f6db1481
RH
1015
1016 /* If we are not running more CSE passes, then we are no longer
1017 expecting CSE to be run. But always rerun it in a cheap mode. */
1018 cse_not_expected = !flag_rerun_cse_after_loop && !flag_gcse;
1019
1020 if (tem || optimize > 1)
1021 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
f6db1481
RH
1022
1023 timevar_pop (TV_CSE);
fd743bc1 1024 close_dump_file (DFI_cse, print_rtl_with_bb, get_insns ());
97b0ade3
PB
1025
1026 ggc_collect ();
f6db1481
RH
1027}
1028
1029/* Run second CSE pass after loop optimizations. */
1030static void
fd743bc1 1031rest_of_handle_cse2 (void)
f6db1481
RH
1032{
1033 int tem;
97b0ade3 1034
f6db1481 1035 timevar_push (TV_CSE2);
fd743bc1 1036 open_dump_file (DFI_cse2, current_function_decl);
f6db1481
RH
1037 if (dump_file)
1038 dump_flow_info (dump_file);
1039 /* CFG is no longer maintained up-to-date. */
5affca01 1040 tem = cse_main (get_insns (), max_reg_num (), dump_file);
f6db1481
RH
1041
1042 /* Run a pass to eliminate duplicated assignments to condition code
1043 registers. We have to run this after bypass_jumps, because it
1044 makes it harder for that pass to determine whether a jump can be
1045 bypassed safely. */
1046 cse_condition_code_reg ();
1047
1048 purge_all_dead_edges (0);
fd743bc1 1049 delete_trivially_dead_insns (get_insns (), max_reg_num ());
f6db1481
RH
1050
1051 if (tem)
1052 {
1053 timevar_push (TV_JUMP);
fd743bc1 1054 rebuild_jump_labels (get_insns ());
f6db1481
RH
1055 cleanup_cfg (CLEANUP_EXPENSIVE);
1056 timevar_pop (TV_JUMP);
1057 }
fd743bc1
PB
1058 reg_scan (get_insns (), max_reg_num (), 0);
1059 close_dump_file (DFI_cse2, print_rtl_with_bb, get_insns ());
f6db1481 1060 timevar_pop (TV_CSE2);
97b0ade3
PB
1061
1062 ggc_collect ();
f6db1481
RH
1063}
1064
1065/* Perform global cse. */
1066static void
fd743bc1 1067rest_of_handle_gcse (void)
f6db1481
RH
1068{
1069 int save_csb, save_cfj;
1070 int tem2 = 0, tem;
97b0ade3 1071
f6db1481 1072 timevar_push (TV_GCSE);
fd743bc1 1073 open_dump_file (DFI_gcse, current_function_decl);
f6db1481 1074
fd743bc1
PB
1075 tem = gcse_main (get_insns (), dump_file);
1076 rebuild_jump_labels (get_insns ());
1077 delete_trivially_dead_insns (get_insns (), max_reg_num ());
f6db1481
RH
1078
1079 save_csb = flag_cse_skip_blocks;
1080 save_cfj = flag_cse_follow_jumps;
1081 flag_cse_skip_blocks = flag_cse_follow_jumps = 0;
1082
f6db1481
RH
1083 /* If -fexpensive-optimizations, re-run CSE to clean up things done
1084 by gcse. */
1085 if (flag_expensive_optimizations)
1086 {
1087 timevar_push (TV_CSE);
fd743bc1 1088 reg_scan (get_insns (), max_reg_num (), 1);
5affca01 1089 tem2 = cse_main (get_insns (), max_reg_num (), dump_file);
f6db1481 1090 purge_all_dead_edges (0);
fd743bc1 1091 delete_trivially_dead_insns (get_insns (), max_reg_num ());
f6db1481
RH
1092 timevar_pop (TV_CSE);
1093 cse_not_expected = !flag_rerun_cse_after_loop;
1094 }
1095
1096 /* If gcse or cse altered any jumps, rerun jump optimizations to clean
1097 things up. Then possibly re-run CSE again. */
1098 while (tem || tem2)
1099 {
1100 tem = tem2 = 0;
1101 timevar_push (TV_JUMP);
fd743bc1 1102 rebuild_jump_labels (get_insns ());
f6db1481
RH
1103 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
1104 timevar_pop (TV_JUMP);
1105
1106 if (flag_expensive_optimizations)
1107 {
1108 timevar_push (TV_CSE);
fd743bc1 1109 reg_scan (get_insns (), max_reg_num (), 1);
5affca01 1110 tem2 = cse_main (get_insns (), max_reg_num (), dump_file);
f6db1481 1111 purge_all_dead_edges (0);
fd743bc1 1112 delete_trivially_dead_insns (get_insns (), max_reg_num ());
f6db1481
RH
1113 timevar_pop (TV_CSE);
1114 }
1115 }
1116
fd743bc1 1117 close_dump_file (DFI_gcse, print_rtl_with_bb, get_insns ());
f6db1481
RH
1118 timevar_pop (TV_GCSE);
1119
1120 ggc_collect ();
1121 flag_cse_skip_blocks = save_csb;
1122 flag_cse_follow_jumps = save_cfj;
1123#ifdef ENABLE_CHECKING
1124 verify_flow_info ();
1125#endif
1126}
1127
1128/* Move constant computations out of loops. */
1129static void
fd743bc1 1130rest_of_handle_loop_optimize (void)
f6db1481 1131{
c94583fe 1132 int do_prefetch;
f6db1481
RH
1133
1134 timevar_push (TV_LOOP);
1135 delete_dead_jumptables ();
1136 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
fd743bc1 1137 open_dump_file (DFI_loop, current_function_decl);
f6db1481
RH
1138
1139 /* CFG is no longer maintained up-to-date. */
1140 free_bb_for_insn ();
1141
f6db1481
RH
1142 do_prefetch = flag_prefetch_loop_arrays ? LOOP_PREFETCH : 0;
1143
1144 if (flag_rerun_loop_opt)
1145 {
1146 cleanup_barriers ();
1147
1148 /* We only want to perform unrolling once. */
c94583fe 1149 loop_optimize (get_insns (), dump_file, 0);
f6db1481
RH
1150
1151 /* The first call to loop_optimize makes some instructions
1152 trivially dead. We delete those instructions now in the
1153 hope that doing so will make the heuristics in loop work
1154 better and possibly speed up compilation. */
fd743bc1 1155 delete_trivially_dead_insns (get_insns (), max_reg_num ());
f6db1481
RH
1156
1157 /* The regscan pass is currently necessary as the alias
1158 analysis code depends on this information. */
fd743bc1 1159 reg_scan (get_insns (), max_reg_num (), 1);
f6db1481
RH
1160 }
1161 cleanup_barriers ();
c94583fe 1162 loop_optimize (get_insns (), dump_file, do_prefetch);
f6db1481
RH
1163
1164 /* Loop can create trivially dead instructions. */
fd743bc1 1165 delete_trivially_dead_insns (get_insns (), max_reg_num ());
97b0ade3 1166 find_basic_blocks (get_insns (), max_reg_num (), dump_file);
fd743bc1 1167 close_dump_file (DFI_loop, print_rtl, get_insns ());
f6db1481 1168 timevar_pop (TV_LOOP);
f6db1481
RH
1169
1170 ggc_collect ();
1171}
1172
1173/* Perform loop optimizations. It might be better to do them a bit
1174 sooner, but we want the profile feedback to work more
1175 efficiently. */
1176static void
fd743bc1 1177rest_of_handle_loop2 (void)
f6db1481
RH
1178{
1179 struct loops *loops;
1180 basic_block bb;
1181
5e962776
ZD
1182 if (!flag_move_loop_invariants
1183 && !flag_unswitch_loops
689ba89d
ZD
1184 && !flag_peel_loops
1185 && !flag_unroll_loops
1186 && !flag_branch_on_count_reg)
1187 return;
1188
f6db1481 1189 timevar_push (TV_LOOP);
fd743bc1 1190 open_dump_file (DFI_loop2, current_function_decl);
f6db1481
RH
1191 if (dump_file)
1192 dump_flow_info (dump_file);
1193
1194 /* Initialize structures for layout changes. */
35b6b437 1195 cfg_layout_initialize (0);
f6db1481
RH
1196
1197 loops = loop_optimizer_init (dump_file);
1198
1199 if (loops)
1200 {
1201 /* The optimizations: */
5e962776
ZD
1202 if (flag_move_loop_invariants)
1203 move_loop_invariants (loops);
1204
f6db1481
RH
1205 if (flag_unswitch_loops)
1206 unswitch_loops (loops);
1207
1208 if (flag_peel_loops || flag_unroll_loops)
1209 unroll_and_peel_loops (loops,
1210 (flag_peel_loops ? UAP_PEEL : 0) |
1211 (flag_unroll_loops ? UAP_UNROLL : 0) |
1212 (flag_unroll_all_loops ? UAP_UNROLL_ALL : 0));
1213
689ba89d
ZD
1214#ifdef HAVE_doloop_end
1215 if (flag_branch_on_count_reg && HAVE_doloop_end)
1216 doloop_optimize_loops (loops);
1217#endif /* HAVE_doloop_end */
1218
f6db1481
RH
1219 loop_optimizer_finalize (loops, dump_file);
1220 }
1221
8a807136
ZD
1222 free_dominance_info (CDI_DOMINATORS);
1223
f6db1481
RH
1224 /* Finalize layout changes. */
1225 FOR_EACH_BB (bb)
1226 if (bb->next_bb != EXIT_BLOCK_PTR)
1227 bb->rbi->next = bb->next_bb;
1228 cfg_layout_finalize ();
1229
1230 cleanup_cfg (CLEANUP_EXPENSIVE);
fd743bc1
PB
1231 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1232 reg_scan (get_insns (), max_reg_num (), 0);
f6db1481
RH
1233 if (dump_file)
1234 dump_flow_info (dump_file);
1235 close_dump_file (DFI_loop2, print_rtl_with_bb, get_insns ());
1236 timevar_pop (TV_LOOP);
1237 ggc_collect ();
1238}
1239
97b0ade3
PB
1240static void
1241rest_of_handle_branch_target_load_optimize (void)
f6db1481 1242{
97b0ade3
PB
1243 static int warned = 0;
1244
1245 /* Leave this a warning for now so that it is possible to experiment
1246 with running this pass twice. In 3.6, we should either make this
1247 an error, or use separate dump files. */
1248 if (flag_branch_target_load_optimize
1249 && flag_branch_target_load_optimize2
1250 && !warned)
1251 {
1252 warning ("branch target register load optimization is not intended "
1253 "to be run twice");
f6db1481 1254
97b0ade3
PB
1255 warned = 1;
1256 }
f6db1481 1257
97b0ade3
PB
1258 open_dump_file (DFI_branch_target_load, current_function_decl);
1259 branch_target_load_optimize (epilogue_completed);
1260 close_dump_file (DFI_branch_target_load, print_rtl_with_bb, get_insns ());
f6db1481 1261 ggc_collect ();
97b0ade3 1262}
f6db1481 1263
97b0ade3
PB
1264#ifdef OPTIMIZE_MODE_SWITCHING
1265static void
1266rest_of_handle_mode_switching (void)
1267{
1268 timevar_push (TV_MODE_SWITCH);
f6db1481 1269
97b0ade3
PB
1270 no_new_pseudos = 0;
1271 optimize_mode_switching (NULL);
1272 no_new_pseudos = 1;
f6db1481 1273
97b0ade3
PB
1274 timevar_pop (TV_MODE_SWITCH);
1275}
1276#endif
f6db1481 1277
97b0ade3
PB
1278static void
1279rest_of_handle_jump (void)
1280{
1281 ggc_collect ();
f6db1481
RH
1282
1283 timevar_push (TV_JUMP);
fd743bc1 1284 open_dump_file (DFI_sibling, current_function_decl);
f6db1481 1285
6cb38cd4 1286 /* ??? We may get called either via tree_rest_of_compilation when the CFG
97b0ade3
PB
1287 is already built or directly (for instance from coverage code).
1288 The direct callers shall be updated. */
1289 if (!basic_block_info)
1290 {
1291 init_flow ();
1292 rebuild_jump_labels (get_insns ());
1293 find_exception_handler_labels ();
1294 find_basic_blocks (get_insns (), max_reg_num (), dump_file);
1295 }
1296
242229bb
JH
1297 /* ??? We may get called either via tree_rest_of_compilation when the CFG
1298 is already built or directly (for instance from coverage code).
1299 The direct callers shall be updated. */
1300 if (!basic_block_info)
1301 {
1302 init_flow ();
1303 rebuild_jump_labels (get_insns ());
1304 find_exception_handler_labels ();
1305 find_basic_blocks (get_insns (), max_reg_num (), dump_file);
1306 }
f6db1481 1307 delete_unreachable_blocks ();
242229bb 1308#ifdef ENABLE_CHECKING
97b0ade3 1309 verify_flow_info ();
242229bb 1310#endif
9f8628ba
PB
1311
1312 if (cfun->tail_call_emit)
1313 fixup_tail_calls ();
1314
1315 close_dump_file (DFI_sibling, print_rtl, get_insns ());
97b0ade3
PB
1316 timevar_pop (TV_JUMP);
1317}
f6db1481 1318
97b0ade3
PB
1319static void
1320rest_of_handle_eh (void)
1321{
f6db1481
RH
1322 insn_locators_initialize ();
1323 /* Complete generation of exception handling code. */
1324 if (doing_eh (0))
1325 {
1326 timevar_push (TV_JUMP);
fd743bc1 1327 open_dump_file (DFI_eh, current_function_decl);
f6db1481 1328
3fbd86b1
SB
1329 cleanup_cfg (CLEANUP_PRE_LOOP | CLEANUP_NO_INSN_DEL);
1330
f6db1481
RH
1331 finish_eh_generation ();
1332
3fbd86b1
SB
1333 cleanup_cfg (CLEANUP_PRE_LOOP | CLEANUP_NO_INSN_DEL);
1334
f6db1481
RH
1335 close_dump_file (DFI_eh, print_rtl, get_insns ());
1336 timevar_pop (TV_JUMP);
1337 }
97b0ade3 1338}
f6db1481 1339
f6db1481 1340
97b0ade3
PB
1341static void
1342rest_of_handle_prologue_epilogue (void)
1343{
1344 if (optimize && !flow2_completed)
1345 cleanup_cfg (CLEANUP_EXPENSIVE);
f6db1481 1346
97b0ade3
PB
1347 /* On some machines, the prologue and epilogue code, or parts thereof,
1348 can be represented as RTL. Doing so lets us schedule insns between
1349 it and the rest of the code and also allows delayed branch
1350 scheduling to operate in the epilogue. */
1351 thread_prologue_and_epilogue_insns (get_insns ());
1352 epilogue_completed = 1;
f6db1481 1353
97b0ade3
PB
1354 if (optimize && flow2_completed)
1355 life_analysis (dump_file, PROP_POSTRELOAD);
1356}
1357
1358static void
1359rest_of_handle_stack_adjustments (void)
1360{
1361 life_analysis (dump_file, PROP_POSTRELOAD);
1362 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE
1363 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0));
1364
1365 /* This is kind of a heuristic. We need to run combine_stack_adjustments
1366 even for machines with possibly nonzero RETURN_POPS_ARGS
1367 and ACCUMULATE_OUTGOING_ARGS. We expect that only ports having
1368 push instructions will have popping returns. */
1369#ifndef PUSH_ROUNDING
1370 if (!ACCUMULATE_OUTGOING_ARGS)
f6db1481 1371#endif
97b0ade3
PB
1372 combine_stack_adjustments ();
1373}
f6db1481 1374
97b0ade3
PB
1375static void
1376rest_of_handle_flow2 (void)
1377{
1378 timevar_push (TV_FLOW2);
1379 open_dump_file (DFI_flow2, current_function_decl);
f6db1481 1380
97b0ade3
PB
1381 /* Re-create the death notes which were deleted during reload. */
1382#ifdef ENABLE_CHECKING
1383 verify_flow_info ();
1384#endif
1385
1386 /* If optimizing, then go ahead and split insns now. */
1387#ifndef STACK_REGS
1388 if (optimize > 0)
1389#endif
1390 split_all_insns (0);
1391
1392 if (flag_branch_target_load_optimize)
1393 rest_of_handle_branch_target_load_optimize ();
1394
1395 if (!targetm.late_rtl_prologue_epilogue)
1396 rest_of_handle_prologue_epilogue ();
1397
1398 if (optimize)
1399 rest_of_handle_stack_adjustments ();
1400
1401 flow2_completed = 1;
1402
1403 close_dump_file (DFI_flow2, print_rtl_with_bb, get_insns ());
1404 timevar_pop (TV_FLOW2);
1405
1406 ggc_collect ();
1407}
1408
1409
1410static void
1411rest_of_handle_jump2 (void)
1412{
fd743bc1 1413 open_dump_file (DFI_jump, current_function_decl);
f6db1481
RH
1414
1415 /* Always do one jump optimization pass to ensure that JUMP_LABEL fields
1416 are initialized and to compute whether control can drop off the end
1417 of the function. */
1418
1419 timevar_push (TV_JUMP);
1420 /* Turn NOTE_INSN_EXPECTED_VALUE into REG_BR_PROB. Do this
1421 before jump optimization switches branch directions. */
1422 if (flag_guess_branch_prob)
1423 expected_value_to_br_prob ();
1424
fd743bc1 1425 delete_trivially_dead_insns (get_insns (), max_reg_num ());
97b0ade3 1426 reg_scan (get_insns (), max_reg_num (), 0);
f6db1481
RH
1427 if (dump_file)
1428 dump_flow_info (dump_file);
1429 cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_PRE_LOOP
1430 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
1431
6de9cd9a
DN
1432 create_loop_notes ();
1433
fd743bc1 1434 purge_line_number_notes (get_insns ());
f6db1481 1435
f6db1481
RH
1436 if (optimize)
1437 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
1438
f6db1481
RH
1439 /* Jump optimization, and the removal of NULL pointer checks, may
1440 have reduced the number of instructions substantially. CSE, and
1441 future passes, allocate arrays whose dimensions involve the
1442 maximum instruction UID, so if we can reduce the maximum UID
1443 we'll save big on memory. */
1444 renumber_insns (dump_file);
f6db1481 1445
fd743bc1 1446 close_dump_file (DFI_jump, print_rtl_with_bb, get_insns ());
97b0ade3 1447 timevar_pop (TV_JUMP);
f6db1481
RH
1448
1449 ggc_collect ();
97b0ade3
PB
1450}
1451
1452#ifdef HAVE_peephole2
1453static void
1454rest_of_handle_peephole2 (void)
1455{
1456 timevar_push (TV_PEEPHOLE2);
1457 open_dump_file (DFI_peephole2, current_function_decl);
1458
1459 peephole2_optimize (dump_file);
1460
1461 close_dump_file (DFI_peephole2, print_rtl_with_bb, get_insns ());
1462 timevar_pop (TV_PEEPHOLE2);
1463}
1464#endif
1465
1466static void
1467rest_of_handle_postreload (void)
1468{
1469 timevar_push (TV_RELOAD_CSE_REGS);
1470 open_dump_file (DFI_postreload, current_function_decl);
1471
1472 /* Do a very simple CSE pass over just the hard registers. */
1473 reload_cse_regs (get_insns ());
1474 /* reload_cse_regs can eliminate potentially-trapping MEMs.
1475 Remove any EH edges associated with them. */
1476 if (flag_non_call_exceptions)
1477 purge_all_dead_edges (0);
1478
1479 close_dump_file (DFI_postreload, print_rtl_with_bb, get_insns ());
1480 timevar_pop (TV_RELOAD_CSE_REGS);
1481}
1482
1483static void
1484rest_of_handle_shorten_branches (void)
1485{
1486 /* Shorten branches. */
1487 timevar_push (TV_SHORTEN_BRANCH);
1488 shorten_branches (get_insns ());
1489 timevar_pop (TV_SHORTEN_BRANCH);
1490}
1491
1492static void
1493rest_of_clean_state (void)
1494{
0a9aeefd 1495 rtx insn, next;
8d168c24 1496 coverage_end_function ();
0a9aeefd
JH
1497
1498 /* It is very important to decompose the RTL instruction chain here:
1499 debug information keeps pointing into CODE_LABEL insns inside the function
1500 body. If these remain pointing to the other insns, we end up preserving
1501 whole RTL chain and attached detailed debug info in memory. */
1502 for (insn = get_insns (); insn; insn = next)
1503 {
1504 next = NEXT_INSN (insn);
1505 NEXT_INSN (insn) = NULL;
1506 PREV_INSN (insn) = NULL;
1507 }
97b0ade3
PB
1508
1509 /* In case the function was not output,
1510 don't leave any temporary anonymous types
1511 queued up for sdb output. */
1512#ifdef SDB_DEBUGGING_INFO
1513 if (write_symbols == SDB_DEBUG)
1514 sdbout_types (NULL_TREE);
1515#endif
1516
1517 reload_completed = 0;
1518 epilogue_completed = 0;
1519 flow2_completed = 0;
1520 no_new_pseudos = 0;
1521
1522 timevar_push (TV_FINAL);
1523
1524 /* Clear out the insn_length contents now that they are no
1525 longer valid. */
1526 init_insn_lengths ();
1527
1528 /* Show no temporary slots allocated. */
1529 init_temp_slots ();
1530
1531 free_basic_block_vars ();
1532 free_bb_for_insn ();
1533
1534 timevar_pop (TV_FINAL);
1535
1536 if (targetm.binds_local_p (current_function_decl))
1537 {
1538 int pref = cfun->preferred_stack_boundary;
1539 if (cfun->recursive_call_emit
1540 && cfun->stack_alignment_needed > cfun->preferred_stack_boundary)
1541 pref = cfun->stack_alignment_needed;
1542 cgraph_rtl_info (current_function_decl)->preferred_incoming_stack_boundary
1543 = pref;
1544 }
1545
1546 /* Make sure volatile mem refs aren't considered valid operands for
1547 arithmetic insns. We must call this here if this is a nested inline
1548 function, since the above code leaves us in the init_recog state
1549 (from final.c), and the function context push/pop code does not
1550 save/restore volatile_ok.
1551
1552 ??? Maybe it isn't necessary for expand_start_function to call this
1553 anymore if we do it here? */
1554
1555 init_recog_no_volatile ();
1556
1557 /* We're done with this function. Free up memory if we can. */
1558 free_after_parsing (cfun);
80d8221e 1559 free_after_compilation (cfun);
97b0ade3
PB
1560}
1561\f
1562
3fbd86b1
SB
1563/* This function is called from the pass manager in tree-optimize.c
1564 after all tree passes have finished for a single function, and we
1565 have expanded the function body from trees to RTL.
1566 Once we are here, we have decided that we're supposed to output
89dbed81 1567 that function, i.e. that we should write assembler code for it.
3fbd86b1
SB
1568
1569 We run a series of low-level passes here on the function's RTL
1570 representation. Each pass is called via a rest_of_* function. */
97b0ade3
PB
1571
1572void
1573rest_of_compilation (void)
1574{
97b0ade3 1575 /* Convert from NOTE_INSN_EH_REGION style notes, and do other
9f8628ba 1576 sorts of eh initialization. */
97b0ade3
PB
1577 convert_from_eh_region_ranges ();
1578
1579 /* If we're emitting a nested function, make sure its parent gets
1580 emitted as well. Doing otherwise confuses debug info. */
1581 {
1582 tree parent;
1583 for (parent = DECL_CONTEXT (current_function_decl);
1584 parent != NULL_TREE;
1585 parent = get_containing_scope (parent))
1586 if (TREE_CODE (parent) == FUNCTION_DECL)
1587 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (parent)) = 1;
1588 }
1589
1590 /* We are now committed to emitting code for this function. Do any
1591 preparation, such as emitting abstract debug info for the inline
1592 before it gets mangled by optimization. */
1593 if (cgraph_function_possibly_inlined_p (current_function_decl))
1594 (*debug_hooks->outlining_inline_function) (current_function_decl);
1595
1596 /* Remove any notes we don't need. That will make iterating
1597 over the instruction sequence faster, and allow the garbage
1598 collector to reclaim the memory used by the notes. */
1599 remove_unnecessary_notes ();
1600
1601 /* Initialize some variables used by the optimizers. */
1602 init_function_for_compilation ();
1603
1604 TREE_ASM_WRITTEN (current_function_decl) = 1;
1605
97b0ade3
PB
1606 /* Early return if there were errors. We can run afoul of our
1607 consistency checks, and there's not really much point in fixing them. */
1608 if (rtl_dump_and_exit || flag_syntax_only || errorcount || sorrycount)
1609 goto exit_rest_of_compilation;
1610
1611 rest_of_handle_jump ();
97b0ade3 1612
97b0ade3
PB
1613 rest_of_handle_eh ();
1614
1615 /* Delay emitting hard_reg_initial_value sets until after EH landing pad
1616 generation, which might create new sets. */
1617 emit_initial_value_sets ();
1618
1619#ifdef FINALIZE_PIC
1620 /* If we are doing position-independent code generation, now
1621 is the time to output special prologues and epilogues.
1622 We do not want to do this earlier, because it just clutters
1623 up inline functions with meaningless insns. */
1624 if (flag_pic)
1625 FINALIZE_PIC;
1626#endif
1627
1628 /* Copy any shared structure that should not be shared. */
1629 unshare_all_rtl ();
1630
1631#ifdef SETJMP_VIA_SAVE_AREA
1632 /* This must be performed before virtual register instantiation.
1633 Please be aware that everything in the compiler that can look
1634 at the RTL up to this point must understand that REG_SAVE_AREA
1635 is just like a use of the REG contained inside. */
1636 if (current_function_calls_alloca)
1637 optimize_save_area_alloca ();
1638#endif
1639
1640 /* Instantiate all virtual registers. */
1641 instantiate_virtual_regs ();
1642
1643 rest_of_handle_jump2 ();
f6db1481
RH
1644
1645 if (optimize > 0)
fd743bc1 1646 rest_of_handle_cse ();
f6db1481 1647
f6db1481
RH
1648 if (optimize > 0)
1649 {
1650 if (flag_gcse)
fd743bc1 1651 rest_of_handle_gcse ();
f6db1481
RH
1652
1653 if (flag_loop_optimize)
fd743bc1 1654 rest_of_handle_loop_optimize ();
f6db1481
RH
1655
1656 if (flag_gcse)
fd743bc1 1657 rest_of_handle_jump_bypass ();
f6db1481
RH
1658 }
1659
1660 timevar_push (TV_FLOW);
fd743bc1 1661 rest_of_handle_cfg ();
f6db1481 1662
6de9cd9a
DN
1663 if (!flag_tree_based_profiling
1664 && (optimize > 0 || profile_arc_flag
1665 || flag_test_coverage || flag_branch_probabilities))
f6db1481 1666 {
6de9cd9a
DN
1667 rtl_register_profile_hooks ();
1668 rtl_register_value_prof_hooks ();
fd743bc1 1669 rest_of_handle_branch_prob ();
f6db1481
RH
1670
1671 if (flag_branch_probabilities
1672 && flag_profile_values
6d9901e7
ZD
1673 && (flag_value_profile_transformations
1674 || flag_speculative_prefetching))
fd743bc1 1675 rest_of_handle_value_profile_transformations ();
f6db1481
RH
1676
1677 /* Remove the death notes created for vpt. */
1678 if (flag_profile_values)
1679 count_or_remove_death_notes (NULL, 1);
1680 }
1681
1682 if (optimize > 0)
fd743bc1 1683 rest_of_handle_if_conversion ();
f6db1481 1684
97b0ade3 1685 if (optimize > 0 && flag_tracer)
fd743bc1 1686 rest_of_handle_tracer ();
f6db1481 1687
5e962776
ZD
1688 if (optimize > 0
1689 && flag_loop_optimize2)
fd743bc1 1690 rest_of_handle_loop2 ();
f6db1481 1691
97b0ade3 1692 if (optimize > 0 && flag_web)
fd743bc1 1693 rest_of_handle_web ();
f6db1481 1694
97b0ade3 1695 if (optimize > 0 && flag_rerun_cse_after_loop)
fd743bc1 1696 rest_of_handle_cse2 ();
f6db1481
RH
1697
1698 cse_not_expected = 1;
1699
fd743bc1 1700 rest_of_handle_life ();
97b0ade3 1701 timevar_pop (TV_FLOW);
f6db1481
RH
1702
1703 if (optimize > 0)
fd743bc1 1704 rest_of_handle_combine ();
f6db1481 1705
97b0ade3 1706 if (optimize > 0 && flag_if_conversion)
fd743bc1 1707 rest_of_handle_if_after_combine ();
f6db1481 1708
750054a2 1709 /* The optimization to partition hot/cold basic blocks into separate
8e8d5162
CT
1710 sections of the .o file does not work well with linkonce or with
1711 user defined section attributes. Don't call it if either case
1712 arises. */
750054a2 1713
9fb32434
CT
1714 if (flag_reorder_blocks_and_partition
1715 && !DECL_ONE_ONLY (current_function_decl)
1716 && !user_defined_section_attribute)
97b0ade3 1717 rest_of_handle_partition_blocks ();
750054a2 1718
f6db1481 1719 if (optimize > 0 && (flag_regmove || flag_expensive_optimizations))
fd743bc1 1720 rest_of_handle_regmove ();
f6db1481
RH
1721
1722 /* Do unconditional splitting before register allocation to allow machine
1723 description to add extra information not needed previously. */
1724 split_all_insns (1);
1725
1726#ifdef OPTIMIZE_MODE_SWITCHING
97b0ade3 1727 rest_of_handle_mode_switching ();
f6db1481
RH
1728#endif
1729
1730 /* Any of the several passes since flow1 will have munged register
1731 lifetime data a bit. We need it to be up to date for scheduling
1732 (see handling of reg_known_equiv in init_alias_analysis). */
fd743bc1 1733 recompute_reg_usage (get_insns (), !optimize_size);
f6db1481
RH
1734
1735#ifdef INSN_SCHEDULING
97b0ade3
PB
1736 if (optimize > 0 && flag_modulo_sched)
1737 rest_of_handle_sms ();
1738
1739 if (flag_schedule_insns)
1740 rest_of_handle_sched ();
f6db1481
RH
1741#endif
1742
1743 /* Determine if the current function is a leaf before running reload
1744 since this can impact optimizations done by the prologue and
1745 epilogue thus changing register elimination offsets. */
1746 current_function_is_leaf = leaf_function_p ();
1747
f6db1481
RH
1748 if (flag_new_regalloc)
1749 {
fd743bc1 1750 if (rest_of_handle_new_regalloc ())
f6db1481
RH
1751 goto exit_rest_of_compilation;
1752 }
1753 else
1754 {
fd743bc1 1755 if (rest_of_handle_old_regalloc ())
f6db1481
RH
1756 goto exit_rest_of_compilation;
1757 }
1758
f6db1481 1759 if (optimize > 0)
97b0ade3 1760 rest_of_handle_postreload ();
f6db1481 1761
f9957958 1762 if (optimize > 0 && flag_gcse_after_reload)
fd743bc1 1763 rest_of_handle_gcse2 ();
f9957958 1764
97b0ade3 1765 rest_of_handle_flow2 ();
f6db1481
RH
1766
1767#ifdef HAVE_peephole2
1768 if (optimize > 0 && flag_peephole2)
97b0ade3 1769 rest_of_handle_peephole2 ();
f6db1481
RH
1770#endif
1771
97b0ade3
PB
1772 if (optimize > 0)
1773 rest_of_handle_if_after_reload ();
f6db1481
RH
1774
1775 if (optimize > 0)
1776 {
1777 if (flag_rename_registers || flag_cprop_registers)
fd743bc1 1778 rest_of_handle_regrename ();
f6db1481 1779
fd743bc1 1780 rest_of_handle_reorder_blocks ();
f6db1481
RH
1781 }
1782
1783 if (flag_branch_target_load_optimize2)
97b0ade3 1784 rest_of_handle_branch_target_load_optimize ();
f6db1481 1785
f6db1481
RH
1786#ifdef LEAF_REGISTERS
1787 current_function_uses_only_leaf_regs
1788 = optimize > 0 && only_leaf_regs_used () && leaf_function_p ();
1789#endif
1790
9ac617d4 1791 if (targetm.late_rtl_prologue_epilogue)
97b0ade3 1792 rest_of_handle_prologue_epilogue ();
9ac617d4
EB
1793
1794#ifdef INSN_SCHEDULING
1795 if (optimize > 0 && flag_schedule_insns_after_reload)
1796 rest_of_handle_sched2 ();
1797#endif
1798
f6db1481 1799#ifdef STACK_REGS
fd743bc1 1800 rest_of_handle_stack_regs ();
f6db1481
RH
1801#endif
1802
1803 compute_alignments ();
1804
1805 if (flag_var_tracking)
fd743bc1 1806 rest_of_handle_variable_tracking ();
f6db1481
RH
1807
1808 /* CFG is no longer maintained up-to-date. */
1809 free_bb_for_insn ();
1810
1811 if (targetm.machine_dependent_reorg != 0)
fd743bc1 1812 rest_of_handle_machine_reorg ();
f6db1481 1813
fd743bc1 1814 purge_line_number_notes (get_insns ());
f6db1481
RH
1815 cleanup_barriers ();
1816
1817#ifdef DELAY_SLOTS
97b0ade3 1818 if (flag_delayed_branch)
fd743bc1 1819 rest_of_handle_delay_slots ();
f6db1481
RH
1820#endif
1821
1822#if defined (HAVE_ATTR_length) && !defined (STACK_REGS)
1823 timevar_push (TV_SHORTEN_BRANCH);
1824 split_all_insns_noflow ();
1825 timevar_pop (TV_SHORTEN_BRANCH);
1826#endif
1827
1828 convert_to_eh_region_ranges ();
1829
97b0ade3 1830 rest_of_handle_shorten_branches ();
f6db1481
RH
1831
1832 set_nothrow_function_flags ();
f6db1481 1833
fd743bc1 1834 rest_of_handle_final ();
f6db1481 1835
f6db1481
RH
1836 exit_rest_of_compilation:
1837
97b0ade3 1838 rest_of_clean_state ();
f6db1481
RH
1839}
1840
f6db1481
RH
1841void
1842finish_optimization_passes (void)
1843{
9f8628ba
PB
1844 enum tree_dump_index i;
1845 struct dump_file_info *dfi;
1846 char *name;
1847
97b0ade3 1848 timevar_push (TV_DUMP);
f6db1481
RH
1849 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
1850 {
f6db1481 1851 open_dump_file (DFI_bp, NULL);
f6db1481 1852 end_branch_prob ();
f6db1481 1853 close_dump_file (DFI_bp, NULL, NULL_RTX);
f6db1481
RH
1854 }
1855
1856 if (optimize > 0 && open_dump_file (DFI_combine, NULL))
1857 {
f6db1481
RH
1858 dump_combine_total_stats (dump_file);
1859 close_dump_file (DFI_combine, NULL, NULL_RTX);
f6db1481
RH
1860 }
1861
f6db1481
RH
1862 /* Do whatever is necessary to finish printing the graphs. */
1863 if (graph_dump_format != no_graph)
9f8628ba
PB
1864 for (i = DFI_MIN; (dfi = get_dump_file_info (i)) != NULL; ++i)
1865 if (dump_initialized_p (i)
1866 && (dfi->flags & TDF_RTL) != 0
1867 && (name = get_dump_file_name (i)) != NULL)
1868 {
1869 finish_graph_dump_file (name);
1870 free (name);
1871 }
f6db1481 1872
97b0ade3 1873 timevar_pop (TV_DUMP);
f6db1481
RH
1874}
1875
2f8e398b
PB
1876struct tree_opt_pass pass_rest_of_compilation =
1877{
9f8628ba 1878 NULL, /* name */
2f8e398b
PB
1879 NULL, /* gate */
1880 rest_of_compilation, /* execute */
1881 NULL, /* sub */
1882 NULL, /* next */
1883 0, /* static_pass_number */
1884 TV_REST_OF_COMPILATION, /* tv_id */
1885 PROP_rtl, /* properties_required */
1886 0, /* properties_provided */
1887 PROP_rtl, /* properties_destroyed */
1888 0, /* todo_flags_start */
9f8628ba
PB
1889 TODO_ggc_collect, /* todo_flags_finish */
1890 0 /* letter */
2f8e398b
PB
1891};
1892
1893
This page took 0.539133 seconds and 5 git commands to generate.