]> gcc.gnu.org Git - gcc.git/blame - gcc/passes.c
re PR c++/16337 (bug defining multiple altivec vectors in same C++ statement)
[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
1383 /* Finalize layout changes. */
1384 FOR_EACH_BB (bb)
1385 if (bb->next_bb != EXIT_BLOCK_PTR)
1386 bb->rbi->next = bb->next_bb;
1387 cfg_layout_finalize ();
1388
1389 cleanup_cfg (CLEANUP_EXPENSIVE);
fd743bc1
PB
1390 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1391 reg_scan (get_insns (), max_reg_num (), 0);
f6db1481
RH
1392 if (dump_file)
1393 dump_flow_info (dump_file);
1394 close_dump_file (DFI_loop2, print_rtl_with_bb, get_insns ());
1395 timevar_pop (TV_LOOP);
1396 ggc_collect ();
1397}
1398
97b0ade3
PB
1399static void
1400rest_of_handle_branch_target_load_optimize (void)
f6db1481 1401{
97b0ade3
PB
1402 static int warned = 0;
1403
1404 /* Leave this a warning for now so that it is possible to experiment
1405 with running this pass twice. In 3.6, we should either make this
1406 an error, or use separate dump files. */
1407 if (flag_branch_target_load_optimize
1408 && flag_branch_target_load_optimize2
1409 && !warned)
1410 {
1411 warning ("branch target register load optimization is not intended "
1412 "to be run twice");
f6db1481 1413
97b0ade3
PB
1414 warned = 1;
1415 }
f6db1481 1416
97b0ade3
PB
1417 open_dump_file (DFI_branch_target_load, current_function_decl);
1418 branch_target_load_optimize (epilogue_completed);
1419 close_dump_file (DFI_branch_target_load, print_rtl_with_bb, get_insns ());
f6db1481 1420 ggc_collect ();
97b0ade3 1421}
f6db1481 1422
97b0ade3
PB
1423#ifdef OPTIMIZE_MODE_SWITCHING
1424static void
1425rest_of_handle_mode_switching (void)
1426{
1427 timevar_push (TV_MODE_SWITCH);
f6db1481 1428
97b0ade3
PB
1429 no_new_pseudos = 0;
1430 optimize_mode_switching (NULL);
1431 no_new_pseudos = 1;
f6db1481 1432
97b0ade3
PB
1433 timevar_pop (TV_MODE_SWITCH);
1434}
1435#endif
f6db1481 1436
97b0ade3
PB
1437static void
1438rest_of_handle_jump (void)
1439{
1440 ggc_collect ();
f6db1481
RH
1441
1442 timevar_push (TV_JUMP);
fd743bc1 1443 open_dump_file (DFI_sibling, current_function_decl);
f6db1481 1444
97b0ade3
PB
1445 /* ??? We may get caled either via tree_rest_of_compilation when the CFG
1446 is already built or directly (for instance from coverage code).
1447 The direct callers shall be updated. */
1448 if (!basic_block_info)
1449 {
1450 init_flow ();
1451 rebuild_jump_labels (get_insns ());
1452 find_exception_handler_labels ();
1453 find_basic_blocks (get_insns (), max_reg_num (), dump_file);
1454 }
1455
242229bb
JH
1456 /* ??? We may get called either via tree_rest_of_compilation when the CFG
1457 is already built or directly (for instance from coverage code).
1458 The direct callers shall be updated. */
1459 if (!basic_block_info)
1460 {
1461 init_flow ();
1462 rebuild_jump_labels (get_insns ());
1463 find_exception_handler_labels ();
1464 find_basic_blocks (get_insns (), max_reg_num (), dump_file);
1465 }
f6db1481 1466 delete_unreachable_blocks ();
242229bb 1467#ifdef ENABLE_CHECKING
97b0ade3 1468 verify_flow_info ();
242229bb 1469#endif
97b0ade3
PB
1470 timevar_pop (TV_JUMP);
1471}
f6db1481 1472
97b0ade3
PB
1473static void
1474rest_of_handle_guess_branch_prob (void)
1475{
f6db1481
RH
1476 /* Turn NOTE_INSN_PREDICTIONs into branch predictions. */
1477 if (flag_guess_branch_prob)
1478 {
1479 timevar_push (TV_BRANCH_PROB);
1480 note_prediction_to_br_prob ();
1481 timevar_pop (TV_BRANCH_PROB);
1482 }
97b0ade3 1483}
f6db1481 1484
97b0ade3
PB
1485static void
1486rest_of_handle_eh (void)
1487{
f6db1481
RH
1488 insn_locators_initialize ();
1489 /* Complete generation of exception handling code. */
1490 if (doing_eh (0))
1491 {
1492 timevar_push (TV_JUMP);
fd743bc1 1493 open_dump_file (DFI_eh, current_function_decl);
f6db1481
RH
1494
1495 finish_eh_generation ();
1496
1497 close_dump_file (DFI_eh, print_rtl, get_insns ());
1498 timevar_pop (TV_JUMP);
1499 }
97b0ade3 1500}
f6db1481 1501
f6db1481 1502
97b0ade3
PB
1503static void
1504rest_of_handle_prologue_epilogue (void)
1505{
1506 if (optimize && !flow2_completed)
1507 cleanup_cfg (CLEANUP_EXPENSIVE);
f6db1481 1508
97b0ade3
PB
1509 /* On some machines, the prologue and epilogue code, or parts thereof,
1510 can be represented as RTL. Doing so lets us schedule insns between
1511 it and the rest of the code and also allows delayed branch
1512 scheduling to operate in the epilogue. */
1513 thread_prologue_and_epilogue_insns (get_insns ());
1514 epilogue_completed = 1;
f6db1481 1515
97b0ade3
PB
1516 if (optimize && flow2_completed)
1517 life_analysis (dump_file, PROP_POSTRELOAD);
1518}
1519
1520static void
1521rest_of_handle_stack_adjustments (void)
1522{
1523 life_analysis (dump_file, PROP_POSTRELOAD);
1524 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE
1525 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0));
1526
1527 /* This is kind of a heuristic. We need to run combine_stack_adjustments
1528 even for machines with possibly nonzero RETURN_POPS_ARGS
1529 and ACCUMULATE_OUTGOING_ARGS. We expect that only ports having
1530 push instructions will have popping returns. */
1531#ifndef PUSH_ROUNDING
1532 if (!ACCUMULATE_OUTGOING_ARGS)
f6db1481 1533#endif
97b0ade3
PB
1534 combine_stack_adjustments ();
1535}
f6db1481 1536
97b0ade3
PB
1537static void
1538rest_of_handle_flow2 (void)
1539{
1540 timevar_push (TV_FLOW2);
1541 open_dump_file (DFI_flow2, current_function_decl);
f6db1481 1542
97b0ade3
PB
1543 /* Re-create the death notes which were deleted during reload. */
1544#ifdef ENABLE_CHECKING
1545 verify_flow_info ();
1546#endif
1547
1548 /* If optimizing, then go ahead and split insns now. */
1549#ifndef STACK_REGS
1550 if (optimize > 0)
1551#endif
1552 split_all_insns (0);
1553
1554 if (flag_branch_target_load_optimize)
1555 rest_of_handle_branch_target_load_optimize ();
1556
1557 if (!targetm.late_rtl_prologue_epilogue)
1558 rest_of_handle_prologue_epilogue ();
1559
1560 if (optimize)
1561 rest_of_handle_stack_adjustments ();
1562
1563 flow2_completed = 1;
1564
1565 close_dump_file (DFI_flow2, print_rtl_with_bb, get_insns ());
1566 timevar_pop (TV_FLOW2);
1567
1568 ggc_collect ();
1569}
1570
1571
1572static void
1573rest_of_handle_jump2 (void)
1574{
fd743bc1 1575 open_dump_file (DFI_jump, current_function_decl);
f6db1481
RH
1576
1577 /* Always do one jump optimization pass to ensure that JUMP_LABEL fields
1578 are initialized and to compute whether control can drop off the end
1579 of the function. */
1580
1581 timevar_push (TV_JUMP);
1582 /* Turn NOTE_INSN_EXPECTED_VALUE into REG_BR_PROB. Do this
1583 before jump optimization switches branch directions. */
1584 if (flag_guess_branch_prob)
1585 expected_value_to_br_prob ();
1586
fd743bc1 1587 delete_trivially_dead_insns (get_insns (), max_reg_num ());
97b0ade3 1588 reg_scan (get_insns (), max_reg_num (), 0);
f6db1481
RH
1589 if (dump_file)
1590 dump_flow_info (dump_file);
1591 cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_PRE_LOOP
1592 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
1593
6de9cd9a
DN
1594 create_loop_notes ();
1595
fd743bc1 1596 purge_line_number_notes (get_insns ());
f6db1481 1597
f6db1481
RH
1598 if (optimize)
1599 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
1600
f6db1481
RH
1601 /* Jump optimization, and the removal of NULL pointer checks, may
1602 have reduced the number of instructions substantially. CSE, and
1603 future passes, allocate arrays whose dimensions involve the
1604 maximum instruction UID, so if we can reduce the maximum UID
1605 we'll save big on memory. */
1606 renumber_insns (dump_file);
f6db1481 1607
fd743bc1 1608 close_dump_file (DFI_jump, print_rtl_with_bb, get_insns ());
97b0ade3 1609 timevar_pop (TV_JUMP);
f6db1481
RH
1610
1611 ggc_collect ();
97b0ade3
PB
1612}
1613
1614#ifdef HAVE_peephole2
1615static void
1616rest_of_handle_peephole2 (void)
1617{
1618 timevar_push (TV_PEEPHOLE2);
1619 open_dump_file (DFI_peephole2, current_function_decl);
1620
1621 peephole2_optimize (dump_file);
1622
1623 close_dump_file (DFI_peephole2, print_rtl_with_bb, get_insns ());
1624 timevar_pop (TV_PEEPHOLE2);
1625}
1626#endif
1627
1628static void
1629rest_of_handle_postreload (void)
1630{
1631 timevar_push (TV_RELOAD_CSE_REGS);
1632 open_dump_file (DFI_postreload, current_function_decl);
1633
1634 /* Do a very simple CSE pass over just the hard registers. */
1635 reload_cse_regs (get_insns ());
1636 /* reload_cse_regs can eliminate potentially-trapping MEMs.
1637 Remove any EH edges associated with them. */
1638 if (flag_non_call_exceptions)
1639 purge_all_dead_edges (0);
1640
1641 close_dump_file (DFI_postreload, print_rtl_with_bb, get_insns ());
1642 timevar_pop (TV_RELOAD_CSE_REGS);
1643}
1644
1645static void
1646rest_of_handle_shorten_branches (void)
1647{
1648 /* Shorten branches. */
1649 timevar_push (TV_SHORTEN_BRANCH);
1650 shorten_branches (get_insns ());
1651 timevar_pop (TV_SHORTEN_BRANCH);
1652}
1653
1654static void
1655rest_of_clean_state (void)
1656{
1657 coverage_end_function ();
1658
1659 /* In case the function was not output,
1660 don't leave any temporary anonymous types
1661 queued up for sdb output. */
1662#ifdef SDB_DEBUGGING_INFO
1663 if (write_symbols == SDB_DEBUG)
1664 sdbout_types (NULL_TREE);
1665#endif
1666
1667 reload_completed = 0;
1668 epilogue_completed = 0;
1669 flow2_completed = 0;
1670 no_new_pseudos = 0;
1671
1672 timevar_push (TV_FINAL);
1673
1674 /* Clear out the insn_length contents now that they are no
1675 longer valid. */
1676 init_insn_lengths ();
1677
1678 /* Show no temporary slots allocated. */
1679 init_temp_slots ();
1680
1681 free_basic_block_vars ();
1682 free_bb_for_insn ();
1683
1684 timevar_pop (TV_FINAL);
1685
1686 if (targetm.binds_local_p (current_function_decl))
1687 {
1688 int pref = cfun->preferred_stack_boundary;
1689 if (cfun->recursive_call_emit
1690 && cfun->stack_alignment_needed > cfun->preferred_stack_boundary)
1691 pref = cfun->stack_alignment_needed;
1692 cgraph_rtl_info (current_function_decl)->preferred_incoming_stack_boundary
1693 = pref;
1694 }
1695
1696 /* Make sure volatile mem refs aren't considered valid operands for
1697 arithmetic insns. We must call this here if this is a nested inline
1698 function, since the above code leaves us in the init_recog state
1699 (from final.c), and the function context push/pop code does not
1700 save/restore volatile_ok.
1701
1702 ??? Maybe it isn't necessary for expand_start_function to call this
1703 anymore if we do it here? */
1704
1705 init_recog_no_volatile ();
1706
1707 /* We're done with this function. Free up memory if we can. */
1708 free_after_parsing (cfun);
1709}
1710\f
1711
1712/* This is called from finish_function (within langhooks.parse_file)
1713 after each top-level definition is parsed.
1714 It is supposed to compile that function or variable
1715 and output the assembler code for it.
1716 After we return, the tree storage is freed. */
1717
1718void
1719rest_of_compilation (void)
1720{
1721 /* There's no need to defer outputting this function any more; we
1722 know we want to output it. */
1723 DECL_DEFER_OUTPUT (current_function_decl) = 0;
1724
1725 /* Register rtl specific functions for cfg. */
1726 rtl_register_cfg_hooks ();
1727
1728 /* Now that we're out of the frontend, we shouldn't have any more
1729 CONCATs anywhere. */
1730 generating_concat_p = 0;
1731
1732 /* When processing delayed functions, prepare_function_start () won't
1733 have been run to re-initialize it. */
1734 cse_not_expected = ! optimize;
1735
1736 finalize_block_changes ();
1737
1738 /* Dump the rtl code if we are dumping rtl. */
1739 if (open_dump_file (DFI_rtl, current_function_decl))
1740 close_dump_file (DFI_rtl, print_rtl, get_insns ());
1741
1742 /* Convert from NOTE_INSN_EH_REGION style notes, and do other
1743 sorts of eh initialization. Delay this until after the
1744 initial rtl dump so that we can see the original nesting. */
1745 convert_from_eh_region_ranges ();
1746
1747 /* If we're emitting a nested function, make sure its parent gets
1748 emitted as well. Doing otherwise confuses debug info. */
1749 {
1750 tree parent;
1751 for (parent = DECL_CONTEXT (current_function_decl);
1752 parent != NULL_TREE;
1753 parent = get_containing_scope (parent))
1754 if (TREE_CODE (parent) == FUNCTION_DECL)
1755 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (parent)) = 1;
1756 }
1757
1758 /* We are now committed to emitting code for this function. Do any
1759 preparation, such as emitting abstract debug info for the inline
1760 before it gets mangled by optimization. */
1761 if (cgraph_function_possibly_inlined_p (current_function_decl))
1762 (*debug_hooks->outlining_inline_function) (current_function_decl);
1763
1764 /* Remove any notes we don't need. That will make iterating
1765 over the instruction sequence faster, and allow the garbage
1766 collector to reclaim the memory used by the notes. */
1767 remove_unnecessary_notes ();
1768
1769 /* Initialize some variables used by the optimizers. */
1770 init_function_for_compilation ();
1771
1772 TREE_ASM_WRITTEN (current_function_decl) = 1;
1773
1774 /* Now that integrate will no longer see our rtl, we need not
1775 distinguish between the return value of this function and the
1776 return value of called functions. Also, we can remove all SETs
1777 of subregs of hard registers; they are only here because of
1778 integrate. Also, we can now initialize pseudos intended to
1779 carry magic hard reg data throughout the function.
1780
1781 FIXME: All this looks thoroughly obsolete... maybe we can
1782 get rid of both these lines unconditionally? */
1783 rtx_equal_function_value_matters = 0;
1784 purge_hard_subreg_sets (get_insns ());
1785
1786 /* Early return if there were errors. We can run afoul of our
1787 consistency checks, and there's not really much point in fixing them. */
1788 if (rtl_dump_and_exit || flag_syntax_only || errorcount || sorrycount)
1789 goto exit_rest_of_compilation;
1790
1791 rest_of_handle_jump ();
1792 rest_of_handle_guess_branch_prob ();
1793
1794 if (cfun->tail_call_emit)
1795 fixup_tail_calls ();
1796
1797 rest_of_handle_eh ();
1798
1799 /* Delay emitting hard_reg_initial_value sets until after EH landing pad
1800 generation, which might create new sets. */
1801 emit_initial_value_sets ();
1802
1803#ifdef FINALIZE_PIC
1804 /* If we are doing position-independent code generation, now
1805 is the time to output special prologues and epilogues.
1806 We do not want to do this earlier, because it just clutters
1807 up inline functions with meaningless insns. */
1808 if (flag_pic)
1809 FINALIZE_PIC;
1810#endif
1811
1812 /* Copy any shared structure that should not be shared. */
1813 unshare_all_rtl ();
1814
1815#ifdef SETJMP_VIA_SAVE_AREA
1816 /* This must be performed before virtual register instantiation.
1817 Please be aware that everything in the compiler that can look
1818 at the RTL up to this point must understand that REG_SAVE_AREA
1819 is just like a use of the REG contained inside. */
1820 if (current_function_calls_alloca)
1821 optimize_save_area_alloca ();
1822#endif
1823
1824 /* Instantiate all virtual registers. */
1825 instantiate_virtual_regs ();
1826
1827 rest_of_handle_jump2 ();
f6db1481
RH
1828
1829 if (optimize > 0)
fd743bc1 1830 rest_of_handle_cse ();
f6db1481 1831
f6db1481
RH
1832 if (optimize > 0)
1833 {
1834 if (flag_gcse)
fd743bc1 1835 rest_of_handle_gcse ();
f6db1481
RH
1836
1837 if (flag_loop_optimize)
fd743bc1 1838 rest_of_handle_loop_optimize ();
f6db1481
RH
1839
1840 if (flag_gcse)
fd743bc1 1841 rest_of_handle_jump_bypass ();
f6db1481
RH
1842 }
1843
1844 timevar_push (TV_FLOW);
fd743bc1 1845 rest_of_handle_cfg ();
f6db1481 1846
6de9cd9a
DN
1847 if (!flag_tree_based_profiling
1848 && (optimize > 0 || profile_arc_flag
1849 || flag_test_coverage || flag_branch_probabilities))
f6db1481 1850 {
6de9cd9a
DN
1851 rtl_register_profile_hooks ();
1852 rtl_register_value_prof_hooks ();
fd743bc1 1853 rest_of_handle_branch_prob ();
f6db1481
RH
1854
1855 if (flag_branch_probabilities
1856 && flag_profile_values
1857 && flag_value_profile_transformations)
fd743bc1 1858 rest_of_handle_value_profile_transformations ();
f6db1481
RH
1859
1860 /* Remove the death notes created for vpt. */
1861 if (flag_profile_values)
1862 count_or_remove_death_notes (NULL, 1);
1863 }
1864
1865 if (optimize > 0)
fd743bc1 1866 rest_of_handle_if_conversion ();
f6db1481 1867
97b0ade3 1868 if (optimize > 0 && flag_tracer)
fd743bc1 1869 rest_of_handle_tracer ();
f6db1481 1870
5e962776
ZD
1871 if (optimize > 0
1872 && flag_loop_optimize2)
fd743bc1 1873 rest_of_handle_loop2 ();
f6db1481 1874
97b0ade3 1875 if (optimize > 0 && flag_web)
fd743bc1 1876 rest_of_handle_web ();
f6db1481 1877
97b0ade3 1878 if (optimize > 0 && flag_rerun_cse_after_loop)
fd743bc1 1879 rest_of_handle_cse2 ();
f6db1481
RH
1880
1881 cse_not_expected = 1;
1882
fd743bc1 1883 rest_of_handle_life ();
97b0ade3 1884 timevar_pop (TV_FLOW);
f6db1481
RH
1885
1886 if (optimize > 0)
fd743bc1 1887 rest_of_handle_combine ();
f6db1481 1888
97b0ade3 1889 if (optimize > 0 && flag_if_conversion)
fd743bc1 1890 rest_of_handle_if_after_combine ();
f6db1481 1891
750054a2
CT
1892 /* The optimization to partition hot/cold basic blocks into separate
1893 sections of the .o file does not work well with exception handling.
9cf737f8 1894 Don't call it if there are exceptions. */
750054a2 1895
97b0ade3
PB
1896 if (optimize > 0 && flag_reorder_blocks_and_partition && !flag_exceptions)
1897 rest_of_handle_partition_blocks ();
750054a2 1898
f6db1481 1899 if (optimize > 0 && (flag_regmove || flag_expensive_optimizations))
fd743bc1 1900 rest_of_handle_regmove ();
f6db1481
RH
1901
1902 /* Do unconditional splitting before register allocation to allow machine
1903 description to add extra information not needed previously. */
1904 split_all_insns (1);
1905
1906#ifdef OPTIMIZE_MODE_SWITCHING
97b0ade3 1907 rest_of_handle_mode_switching ();
f6db1481
RH
1908#endif
1909
1910 /* Any of the several passes since flow1 will have munged register
1911 lifetime data a bit. We need it to be up to date for scheduling
1912 (see handling of reg_known_equiv in init_alias_analysis). */
fd743bc1 1913 recompute_reg_usage (get_insns (), !optimize_size);
f6db1481
RH
1914
1915#ifdef INSN_SCHEDULING
97b0ade3
PB
1916 if (optimize > 0 && flag_modulo_sched)
1917 rest_of_handle_sms ();
1918
1919 if (flag_schedule_insns)
1920 rest_of_handle_sched ();
f6db1481
RH
1921#endif
1922
1923 /* Determine if the current function is a leaf before running reload
1924 since this can impact optimizations done by the prologue and
1925 epilogue thus changing register elimination offsets. */
1926 current_function_is_leaf = leaf_function_p ();
1927
f6db1481
RH
1928 if (flag_new_regalloc)
1929 {
fd743bc1 1930 if (rest_of_handle_new_regalloc ())
f6db1481
RH
1931 goto exit_rest_of_compilation;
1932 }
1933 else
1934 {
fd743bc1 1935 if (rest_of_handle_old_regalloc ())
f6db1481
RH
1936 goto exit_rest_of_compilation;
1937 }
1938
f6db1481 1939 if (optimize > 0)
97b0ade3 1940 rest_of_handle_postreload ();
f6db1481 1941
f9957958 1942 if (optimize > 0 && flag_gcse_after_reload)
fd743bc1 1943 rest_of_handle_gcse2 ();
f9957958 1944
97b0ade3 1945 rest_of_handle_flow2 ();
f6db1481
RH
1946
1947#ifdef HAVE_peephole2
1948 if (optimize > 0 && flag_peephole2)
97b0ade3 1949 rest_of_handle_peephole2 ();
f6db1481
RH
1950#endif
1951
97b0ade3
PB
1952 if (optimize > 0)
1953 rest_of_handle_if_after_reload ();
f6db1481
RH
1954
1955 if (optimize > 0)
1956 {
1957 if (flag_rename_registers || flag_cprop_registers)
fd743bc1 1958 rest_of_handle_regrename ();
f6db1481 1959
fd743bc1 1960 rest_of_handle_reorder_blocks ();
f6db1481
RH
1961 }
1962
1963 if (flag_branch_target_load_optimize2)
97b0ade3 1964 rest_of_handle_branch_target_load_optimize ();
f6db1481 1965
f6db1481
RH
1966#ifdef LEAF_REGISTERS
1967 current_function_uses_only_leaf_regs
1968 = optimize > 0 && only_leaf_regs_used () && leaf_function_p ();
1969#endif
1970
9ac617d4 1971 if (targetm.late_rtl_prologue_epilogue)
97b0ade3 1972 rest_of_handle_prologue_epilogue ();
9ac617d4
EB
1973
1974#ifdef INSN_SCHEDULING
1975 if (optimize > 0 && flag_schedule_insns_after_reload)
1976 rest_of_handle_sched2 ();
1977#endif
1978
f6db1481 1979#ifdef STACK_REGS
fd743bc1 1980 rest_of_handle_stack_regs ();
f6db1481
RH
1981#endif
1982
1983 compute_alignments ();
1984
1985 if (flag_var_tracking)
fd743bc1 1986 rest_of_handle_variable_tracking ();
f6db1481
RH
1987
1988 /* CFG is no longer maintained up-to-date. */
1989 free_bb_for_insn ();
1990
1991 if (targetm.machine_dependent_reorg != 0)
fd743bc1 1992 rest_of_handle_machine_reorg ();
f6db1481 1993
fd743bc1 1994 purge_line_number_notes (get_insns ());
f6db1481
RH
1995 cleanup_barriers ();
1996
1997#ifdef DELAY_SLOTS
97b0ade3 1998 if (flag_delayed_branch)
fd743bc1 1999 rest_of_handle_delay_slots ();
f6db1481
RH
2000#endif
2001
2002#if defined (HAVE_ATTR_length) && !defined (STACK_REGS)
2003 timevar_push (TV_SHORTEN_BRANCH);
2004 split_all_insns_noflow ();
2005 timevar_pop (TV_SHORTEN_BRANCH);
2006#endif
2007
2008 convert_to_eh_region_ranges ();
2009
97b0ade3 2010 rest_of_handle_shorten_branches ();
f6db1481
RH
2011
2012 set_nothrow_function_flags ();
f6db1481 2013
fd743bc1 2014 rest_of_handle_final ();
f6db1481 2015
f6db1481
RH
2016 exit_rest_of_compilation:
2017
97b0ade3 2018 rest_of_clean_state ();
f6db1481
RH
2019}
2020
2021void
2022init_optimization_passes (void)
2023{
6868bb1c
JH
2024 open_dump_file (DFI_cgraph, NULL);
2025 cgraph_dump_file = dump_file;
2026 dump_file = NULL;
f6db1481
RH
2027}
2028
2029void
2030finish_optimization_passes (void)
2031{
97b0ade3 2032 timevar_push (TV_DUMP);
f6db1481
RH
2033 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
2034 {
f6db1481 2035 open_dump_file (DFI_bp, NULL);
f6db1481 2036 end_branch_prob ();
f6db1481 2037 close_dump_file (DFI_bp, NULL, NULL_RTX);
f6db1481
RH
2038 }
2039
2040 if (optimize > 0 && open_dump_file (DFI_combine, NULL))
2041 {
f6db1481
RH
2042 dump_combine_total_stats (dump_file);
2043 close_dump_file (DFI_combine, NULL, NULL_RTX);
f6db1481
RH
2044 }
2045
6868bb1c
JH
2046 dump_file = cgraph_dump_file;
2047 cgraph_dump_file = NULL;
2048 close_dump_file (DFI_cgraph, NULL, NULL_RTX);
f6db1481
RH
2049
2050 /* Do whatever is necessary to finish printing the graphs. */
2051 if (graph_dump_format != no_graph)
2052 {
2053 int i;
2054
2055 for (i = 0; i < (int) DFI_MAX; ++i)
2056 if (dump_file_tbl[i].initialized && dump_file_tbl[i].graph_dump_p)
2057 {
2058 char seq[16];
2059 char *suffix;
2060
2061 sprintf (seq, DUMPFILE_FORMAT, i);
2062 suffix = concat (seq, dump_file_tbl[i].extension, NULL);
2063 finish_graph_dump_file (dump_base_name, suffix);
2064 free (suffix);
2065 }
2066 }
2067
97b0ade3 2068 timevar_pop (TV_DUMP);
f6db1481
RH
2069}
2070
2071bool
2072enable_rtl_dump_file (int letter)
2073{
2074 bool matched = false;
2075 int i;
2076
2077 if (letter == 'a')
2078 {
2079 for (i = 0; i < (int) DFI_MAX; ++i)
2080 dump_file_tbl[i].enabled = 1;
2081 matched = true;
2082 }
2083 else
2084 {
2085 for (i = 0; i < (int) DFI_MAX; ++i)
2086 if (letter == dump_file_tbl[i].debug_switch)
2087 {
2088 dump_file_tbl[i].enabled = 1;
2089 matched = true;
2090 }
2091 }
2092
2093 return matched;
2094}
2f8e398b
PB
2095
2096struct tree_opt_pass pass_rest_of_compilation =
2097{
2098 "rest of compilation", /* name */
2099 NULL, /* gate */
2100 rest_of_compilation, /* execute */
2101 NULL, /* sub */
2102 NULL, /* next */
2103 0, /* static_pass_number */
2104 TV_REST_OF_COMPILATION, /* tv_id */
2105 PROP_rtl, /* properties_required */
2106 0, /* properties_provided */
2107 PROP_rtl, /* properties_destroyed */
2108 0, /* todo_flags_start */
2109 TODO_ggc_collect /* todo_flags_finish */
2110};
2111
2112
This page took 0.449718 seconds and 5 git commands to generate.