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