]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/passes.c
* tree-pretty-print.c (dump_generic_node): Handle
[thirdparty/gcc.git] / gcc / passes.c
CommitLineData
a49a878f 1/* Top level of GCC compilers (cc1, cc1plus, etc.)
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
fee1d116 3 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
a49a878f 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
67ce556b 19Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
2002110-1301, USA. */
a49a878f 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"
a49a878f 63#include "regs.h"
64#include "timevar.h"
65#include "diagnostic.h"
66#include "params.h"
67#include "reload.h"
68#include "dwarf2asm.h"
69#include "integrate.h"
70#include "real.h"
71#include "debug.h"
72#include "target.h"
73#include "langhooks.h"
74#include "cfglayout.h"
75#include "cfgloop.h"
76#include "hosthooks.h"
77#include "cgraph.h"
78#include "opts.h"
79#include "coverage.h"
80#include "value-prof.h"
77fce4cd 81#include "tree-inline.h"
82#include "tree-flow.h"
5290ebdb 83#include "tree-pass.h"
0f9005dd 84#include "tree-dump.h"
a49a878f 85
86#if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
87#include "dwarf2out.h"
88#endif
89
da2f1613 90#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
a49a878f 91#include "dbxout.h"
92#endif
93
94#ifdef SDB_DEBUGGING_INFO
95#include "sdbout.h"
96#endif
97
98#ifdef XCOFF_DEBUGGING_INFO
99#include "xcoffout.h" /* Needed for external data
100 declarations for e.g. AIX 4.x. */
101#endif
102
77fce4cd 103/* Global variables used to communicate with passes. */
104int dump_flags;
105bool in_gimple_form;
a49a878f 106
a49a878f 107
108/* This is called from various places for FUNCTION_DECL, VAR_DECL,
109 and TYPE_DECL nodes.
110
111 This does nothing for local (non-static) variables, unless the
b2c4af5e 112 variable is a register variable with DECL_ASSEMBLER_NAME set. In
113 that case, or if the variable is not an automatic, it sets up the
114 RTL and outputs any assembler code (label definition, storage
115 allocation and initialization).
a49a878f 116
b2c4af5e 117 DECL is the declaration. TOP_LEVEL is nonzero
a49a878f 118 if this declaration is not within a function. */
119
120void
121rest_of_decl_compilation (tree decl,
a49a878f 122 int top_level,
123 int at_end)
124{
125 /* We deferred calling assemble_alias so that we could collect
126 other attributes such as visibility. Emit the alias now. */
127 {
128 tree alias;
129 alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
130 if (alias)
131 {
132 alias = TREE_VALUE (TREE_VALUE (alias));
133 alias = get_identifier (TREE_STRING_POINTER (alias));
134 assemble_alias (decl, alias);
135 }
136 }
137
b2c4af5e 138 /* Can't defer this, because it needs to happen before any
139 later function definitions are processed. */
5ded8c6f 140 if (DECL_ASSEMBLER_NAME_SET_P (decl) && DECL_REGISTER (decl))
b2c4af5e 141 make_decl_rtl (decl);
142
a49a878f 143 /* Forward declarations for nested functions are not "external",
144 but we need to treat them as if they were. */
145 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
146 || TREE_CODE (decl) == FUNCTION_DECL)
147 {
148 timevar_push (TV_VARCONST);
149
a49a878f 150 /* Don't output anything when a tentative file-scope definition
151 is seen. But at end of compilation, do output code for them.
152
153 We do output all variables when unit-at-a-time is active and rely on
154 callgraph code to defer them except for forward declarations
155 (see gcc.c-torture/compile/920624-1.c) */
156 if ((at_end
157 || !DECL_DEFER_OUTPUT (decl)
c1dcd13c 158 || DECL_INITIAL (decl))
a49a878f 159 && !DECL_EXTERNAL (decl))
160 {
c131e678 161 if (TREE_CODE (decl) != FUNCTION_DECL)
a49a878f 162 cgraph_varpool_finalize_decl (decl);
163 else
164 assemble_variable (decl, top_level, at_end, 0);
165 }
166
167#ifdef ASM_FINISH_DECLARE_OBJECT
168 if (decl == last_assemble_variable_decl)
169 {
170 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
171 top_level, at_end);
172 }
173#endif
174
175 timevar_pop (TV_VARCONST);
176 }
76512af6 177 else if (TREE_CODE (decl) == TYPE_DECL
178 /* Like in rest_of_type_compilation, avoid confusing the debug
179 information machinery when there are errors. */
180 && !(sorrycount || errorcount))
a49a878f 181 {
182 timevar_push (TV_SYMOUT);
183 debug_hooks->type_decl (decl, !top_level);
184 timevar_pop (TV_SYMOUT);
185 }
d7401838 186
06b27565 187 /* Let cgraph know about the existence of variables. */
d7401838 188 if (TREE_CODE (decl) == VAR_DECL && !DECL_EXTERNAL (decl))
189 cgraph_varpool_node (decl);
a49a878f 190}
191
192/* Called after finishing a record, union or enumeral type. */
193
194void
195rest_of_type_compilation (tree type, int toplev)
196{
197 /* Avoid confusing the debug information machinery when there are
198 errors. */
199 if (errorcount != 0 || sorrycount != 0)
200 return;
201
202 timevar_push (TV_SYMOUT);
203 debug_hooks->type_decl (TYPE_STUB_DECL (type), !toplev);
204 timevar_pop (TV_SYMOUT);
205}
206
77fce4cd 207\f
a49a878f 208
77fce4cd 209void
210finish_optimization_passes (void)
a49a878f 211{
77fce4cd 212 enum tree_dump_index i;
213 struct dump_file_info *dfi;
214 char *name;
a49a878f 215
77fce4cd 216 timevar_push (TV_DUMP);
217 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
a49a878f 218 {
77fce4cd 219 dump_file = dump_begin (pass_branch_prob.static_pass_number, NULL);
220 end_branch_prob ();
221 if (dump_file)
222 dump_end (pass_branch_prob.static_pass_number, dump_file);
a49a878f 223 }
a49a878f 224
77fce4cd 225 if (optimize > 0)
a49a878f 226 {
77fce4cd 227 dump_file = dump_begin (pass_combine.static_pass_number, NULL);
228 if (dump_file)
a49a878f 229 {
77fce4cd 230 dump_combine_total_stats (dump_file);
231 dump_end (pass_combine.static_pass_number, dump_file);
a49a878f 232 }
233 }
234
77fce4cd 235 /* Do whatever is necessary to finish printing the graphs. */
236 if (graph_dump_format != no_graph)
237 for (i = TDI_end; (dfi = get_dump_file_info (i)) != NULL; ++i)
238 if (dump_initialized_p (i)
5f0ef107 239 && (dfi->flags & TDF_GRAPH) != 0
77fce4cd 240 && (name = get_dump_file_name (i)) != NULL)
5f0ef107 241 {
242 finish_graph_dump_file (name);
243 free (name);
244 }
a49a878f 245
77fce4cd 246 timevar_pop (TV_DUMP);
a49a878f 247}
a49a878f 248
77fce4cd 249static bool
250gate_rest_of_compilation (void)
a49a878f 251{
77fce4cd 252 /* Early return if there were errors. We can run afoul of our
253 consistency checks, and there's not really much point in fixing them. */
254 return !(rtl_dump_and_exit || flag_syntax_only || errorcount || sorrycount);
a49a878f 255}
256
77fce4cd 257struct tree_opt_pass pass_rest_of_compilation =
a49a878f 258{
77fce4cd 259 NULL, /* name */
260 gate_rest_of_compilation, /* gate */
261 NULL, /* execute */
262 NULL, /* sub */
263 NULL, /* next */
264 0, /* static_pass_number */
265 TV_REST_OF_COMPILATION, /* tv_id */
266 PROP_rtl, /* properties_required */
267 0, /* properties_provided */
268 0, /* properties_destroyed */
269 0, /* todo_flags_start */
270 TODO_ggc_collect, /* todo_flags_finish */
271 0 /* letter */
272};
a49a878f 273
77fce4cd 274static bool
275gate_postreload (void)
276{
277 return reload_completed;
a49a878f 278}
279
77fce4cd 280struct tree_opt_pass pass_postreload =
a49a878f 281{
77fce4cd 282 NULL, /* name */
283 gate_postreload, /* gate */
284 NULL, /* execute */
285 NULL, /* sub */
286 NULL, /* next */
287 0, /* static_pass_number */
288 0, /* tv_id */
289 PROP_rtl, /* properties_required */
290 0, /* properties_provided */
291 0, /* properties_destroyed */
292 0, /* todo_flags_start */
293 TODO_ggc_collect, /* todo_flags_finish */
294 0 /* letter */
295};
a49a878f 296
da2f1613 297
a49a878f 298
77fce4cd 299/* The root of the compilation pass tree, once constructed. */
300struct tree_opt_pass *all_passes, *all_ipa_passes, *all_lowering_passes;
a49a878f 301
77fce4cd 302/* Iterate over the pass tree allocating dump file numbers. We want
303 to do this depth first, and independent of whether the pass is
304 enabled or not. */
a49a878f 305
77fce4cd 306static void
307register_one_dump_file (struct tree_opt_pass *pass, bool ipa, int n)
308{
309 char *dot_name, *flag_name, *glob_name;
310 char num[10];
a49a878f 311
77fce4cd 312 /* See below in next_pass_1. */
313 num[0] = '\0';
314 if (pass->static_pass_number != -1)
315 sprintf (num, "%d", ((int) pass->static_pass_number < 0
316 ? 1 : pass->static_pass_number));
a49a878f 317
77fce4cd 318 dot_name = concat (".", pass->name, num, NULL);
319 if (ipa)
a49a878f 320 {
77fce4cd 321 flag_name = concat ("ipa-", pass->name, num, NULL);
322 glob_name = concat ("ipa-", pass->name, NULL);
323 /* First IPA dump is cgraph that is dumped via separate channels. */
324 pass->static_pass_number = dump_register (dot_name, flag_name, glob_name,
325 TDF_IPA, n + 1, 0);
a49a878f 326 }
77fce4cd 327 else if (pass->properties_provided & PROP_trees)
a49a878f 328 {
77fce4cd 329 flag_name = concat ("tree-", pass->name, num, NULL);
330 glob_name = concat ("tree-", pass->name, NULL);
331 pass->static_pass_number = dump_register (dot_name, flag_name, glob_name,
332 TDF_TREE, n + TDI_tree_all, 0);
a49a878f 333 }
a49a878f 334 else
335 {
77fce4cd 336 flag_name = concat ("rtl-", pass->name, num, NULL);
337 glob_name = concat ("rtl-", pass->name, NULL);
338 pass->static_pass_number = dump_register (dot_name, flag_name, glob_name,
339 TDF_RTL, n, pass->letter);
a49a878f 340 }
da2f1613 341}
342
77fce4cd 343static int
344register_dump_files (struct tree_opt_pass *pass, bool ipa, int properties)
da2f1613 345{
77fce4cd 346 static int n = 0;
347 do
348 {
349 int new_properties;
350 int pass_number;
a49a878f 351
77fce4cd 352 pass->properties_required = properties;
353 new_properties =
354 (properties | pass->properties_provided) & ~pass->properties_destroyed;
a49a878f 355
77fce4cd 356 /* Reset the counter when we reach RTL-based passes. */
357 if ((new_properties ^ pass->properties_required) & PROP_rtl)
358 n = 0;
a49a878f 359
77fce4cd 360 pass_number = n;
361 if (pass->name)
362 n++;
a49a878f 363
77fce4cd 364 if (pass->sub)
365 new_properties = register_dump_files (pass->sub, false, new_properties);
a49a878f 366
77fce4cd 367 /* If we have a gate, combine the properties that we could have with
368 and without the pass being examined. */
369 if (pass->gate)
370 properties &= new_properties;
371 else
372 properties = new_properties;
a49a878f 373
77fce4cd 374 pass->properties_provided = properties;
375 if (pass->name)
376 register_one_dump_file (pass, ipa, pass_number);
a49a878f 377
77fce4cd 378 pass = pass->next;
a49a878f 379 }
77fce4cd 380 while (pass);
a49a878f 381
77fce4cd 382 return properties;
a49a878f 383}
839f8415 384
77fce4cd 385/* Add a pass to the pass list. Duplicate the pass if it's already
386 in the list. */
839f8415 387
77fce4cd 388static struct tree_opt_pass **
389next_pass_1 (struct tree_opt_pass **list, struct tree_opt_pass *pass)
a49a878f 390{
a49a878f 391
77fce4cd 392 /* A nonzero static_pass_number indicates that the
393 pass is already in the list. */
394 if (pass->static_pass_number)
395 {
396 struct tree_opt_pass *new;
a49a878f 397
77fce4cd 398 new = xmalloc (sizeof (*new));
399 memcpy (new, pass, sizeof (*new));
a49a878f 400
77fce4cd 401 /* Indicate to register_dump_files that this pass has duplicates,
402 and so it should rename the dump file. The first instance will
403 be -1, and be number of duplicates = -static_pass_number - 1.
404 Subsequent instances will be > 0 and just the duplicate number. */
405 if (pass->name)
406 {
407 pass->static_pass_number -= 1;
408 new->static_pass_number = -pass->static_pass_number;
409 }
410
411 *list = new;
412 }
413 else
414 {
415 pass->static_pass_number = -1;
416 *list = pass;
417 }
418
419 return &(*list)->next;
420
a49a878f 421}
422
ae6ad54a 423/* Construct the pass tree. The sequencing of passes is driven by
424 the cgraph routines:
425
426 cgraph_finalize_compilation_unit ()
427 for each node N in the cgraph
428 cgraph_analyze_function (N)
429 cgraph_lower_function (N) -> all_lowering_passes
430
431 If we are optimizing, cgraph_optimize is then invoked:
432
433 cgraph_optimize ()
434 ipa_passes () -> all_ipa_passes
435 cgraph_expand_all_functions ()
436 for each node N in the cgraph
437 cgraph_expand_function (N)
438 cgraph_lower_function (N) -> Now a NOP.
439 lang_hooks.callgraph.expand_function (DECL (N))
440 tree_rest_of_compilation (DECL (N)) -> all_passes
441*/
da2f1613 442
77fce4cd 443void
444init_optimization_passes (void)
445{
446 struct tree_opt_pass **p;
447
448#define NEXT_PASS(PASS) (p = next_pass_1 (p, &PASS))
449 /* Interprocedural optimization passes. */
450 p = &all_ipa_passes;
451 NEXT_PASS (pass_early_ipa_inline);
452 NEXT_PASS (pass_early_local_passes);
b5d36404 453 NEXT_PASS (pass_ipa_cp);
77fce4cd 454 NEXT_PASS (pass_ipa_inline);
f7d118a9 455 NEXT_PASS (pass_ipa_reference);
456 NEXT_PASS (pass_ipa_pure_const);
457 NEXT_PASS (pass_ipa_type_escape);
77fce4cd 458 *p = NULL;
459
ae6ad54a 460 /* All passes needed to lower the function into shape optimizers can
461 operate on. */
77fce4cd 462 p = &all_lowering_passes;
463 NEXT_PASS (pass_remove_useless_stmts);
464 NEXT_PASS (pass_mudflap_1);
1e8e9920 465 NEXT_PASS (pass_lower_omp);
77fce4cd 466 NEXT_PASS (pass_lower_cf);
467 NEXT_PASS (pass_lower_eh);
468 NEXT_PASS (pass_build_cfg);
469 NEXT_PASS (pass_lower_complex_O0);
470 NEXT_PASS (pass_lower_vector);
471 NEXT_PASS (pass_warn_function_return);
472 NEXT_PASS (pass_early_tree_profile);
473 *p = NULL;
474
475 p = &pass_early_local_passes.sub;
476 NEXT_PASS (pass_tree_profile);
477 NEXT_PASS (pass_cleanup_cfg);
478 NEXT_PASS (pass_rebuild_cgraph_edges);
479 *p = NULL;
480
481 p = &all_passes;
482 NEXT_PASS (pass_fixup_cfg);
483 NEXT_PASS (pass_init_datastructures);
773c5ba7 484 NEXT_PASS (pass_expand_omp);
77fce4cd 485 NEXT_PASS (pass_all_optimizations);
486 NEXT_PASS (pass_warn_function_noreturn);
487 NEXT_PASS (pass_mudflap_2);
488 NEXT_PASS (pass_free_datastructures);
489 NEXT_PASS (pass_free_cfg_annotations);
490 NEXT_PASS (pass_expand);
491 NEXT_PASS (pass_rest_of_compilation);
492 NEXT_PASS (pass_clean_state);
493 *p = NULL;
494
495 p = &pass_all_optimizations.sub;
496 NEXT_PASS (pass_referenced_vars);
497 NEXT_PASS (pass_create_structure_vars);
498 NEXT_PASS (pass_build_ssa);
77fce4cd 499 NEXT_PASS (pass_may_alias);
500 NEXT_PASS (pass_return_slot);
77fce4cd 501 NEXT_PASS (pass_rename_ssa_copies);
502 NEXT_PASS (pass_early_warn_uninitialized);
503
504 /* Initial scalar cleanups. */
505 NEXT_PASS (pass_ccp);
506 NEXT_PASS (pass_fre);
507 NEXT_PASS (pass_dce);
508 NEXT_PASS (pass_forwprop);
509 NEXT_PASS (pass_copy_prop);
510 NEXT_PASS (pass_vrp);
511 NEXT_PASS (pass_dce);
512 NEXT_PASS (pass_merge_phi);
513 NEXT_PASS (pass_dominator);
514
421828b0 515 /* The only copy propagation opportunities left after DOM
516 should be due to degenerate PHI nodes. So rather than
517 run the full copy propagator, just discover and copy
518 propagate away the degenerate PHI nodes. */
519 NEXT_PASS (pass_phi_only_copy_prop);
520
77fce4cd 521 NEXT_PASS (pass_phiopt);
77fce4cd 522 NEXT_PASS (pass_may_alias);
77fce4cd 523 NEXT_PASS (pass_tail_recursion);
524 NEXT_PASS (pass_profile);
525 NEXT_PASS (pass_ch);
526 NEXT_PASS (pass_stdarg);
527 NEXT_PASS (pass_lower_complex);
528 NEXT_PASS (pass_sra);
529 /* FIXME: SRA may generate arbitrary gimple code, exposing new
530 aliased and call-clobbered variables. As mentioned below,
531 pass_may_alias should be a TODO item. */
532 NEXT_PASS (pass_may_alias);
533 NEXT_PASS (pass_rename_ssa_copies);
534 NEXT_PASS (pass_dominator);
421828b0 535
536 /* The only copy propagation opportunities left after DOM
537 should be due to degenerate PHI nodes. So rather than
538 run the full copy propagator, just discover and copy
539 propagate away the degenerate PHI nodes. */
540 NEXT_PASS (pass_phi_only_copy_prop);
541
54aceb26 542 NEXT_PASS (pass_reassoc);
77fce4cd 543 NEXT_PASS (pass_dce);
544 NEXT_PASS (pass_dse);
545 NEXT_PASS (pass_may_alias);
546 NEXT_PASS (pass_forwprop);
547 NEXT_PASS (pass_phiopt);
548 NEXT_PASS (pass_object_sizes);
549 NEXT_PASS (pass_store_ccp);
550 NEXT_PASS (pass_store_copy_prop);
551 NEXT_PASS (pass_fold_builtins);
552 /* FIXME: May alias should a TODO but for 4.0.0,
553 we add may_alias right after fold builtins
554 which can create arbitrary GIMPLE. */
555 NEXT_PASS (pass_may_alias);
77fce4cd 556 NEXT_PASS (pass_split_crit_edges);
77fce4cd 557 NEXT_PASS (pass_pre);
25928e34 558 NEXT_PASS (pass_may_alias);
77fce4cd 559 NEXT_PASS (pass_sink_code);
0526a3ff 560 NEXT_PASS (pass_tree_loop);
ac70caad 561 NEXT_PASS (pass_cse_reciprocals);
54aceb26 562 NEXT_PASS (pass_reassoc);
77fce4cd 563 NEXT_PASS (pass_dominator);
421828b0 564
565 /* The only copy propagation opportunities left after DOM
566 should be due to degenerate PHI nodes. So rather than
567 run the full copy propagator, just discover and copy
568 propagate away the degenerate PHI nodes. */
569 NEXT_PASS (pass_phi_only_copy_prop);
570
77fce4cd 571 NEXT_PASS (pass_cd_dce);
572
573 /* FIXME: If DCE is not run before checking for uninitialized uses,
574 we may get false warnings (e.g., testsuite/gcc.dg/uninit-5.c).
575 However, this also causes us to misdiagnose cases that should be
576 real warnings (e.g., testsuite/gcc.dg/pr18501.c).
577
578 To fix the false positives in uninit-5.c, we would have to
579 account for the predicates protecting the set and the use of each
580 variable. Using a representation like Gated Single Assignment
581 may help. */
582 NEXT_PASS (pass_late_warn_uninitialized);
583 NEXT_PASS (pass_dse);
584 NEXT_PASS (pass_forwprop);
585 NEXT_PASS (pass_phiopt);
586 NEXT_PASS (pass_tail_calls);
587 NEXT_PASS (pass_rename_ssa_copies);
588 NEXT_PASS (pass_uncprop);
589 NEXT_PASS (pass_del_ssa);
590 NEXT_PASS (pass_nrv);
77fce4cd 591 NEXT_PASS (pass_mark_used_blocks);
592 NEXT_PASS (pass_cleanup_cfg_post_optimizing);
593 *p = NULL;
594
0526a3ff 595 p = &pass_tree_loop.sub;
596 NEXT_PASS (pass_tree_loop_init);
77fce4cd 597 NEXT_PASS (pass_copy_prop);
598 NEXT_PASS (pass_lim);
0526a3ff 599 NEXT_PASS (pass_tree_unswitch);
77fce4cd 600 NEXT_PASS (pass_scev_cprop);
8feba661 601 NEXT_PASS (pass_empty_loop);
77fce4cd 602 NEXT_PASS (pass_record_bounds);
603 NEXT_PASS (pass_linear_transform);
604 NEXT_PASS (pass_iv_canon);
605 NEXT_PASS (pass_if_conversion);
606 NEXT_PASS (pass_vectorize);
607 /* NEXT_PASS (pass_may_alias) cannot be done again because the
608 vectorizer creates alias relations that are not supported by
609 pass_may_alias. */
77fce4cd 610 NEXT_PASS (pass_complete_unroll);
611 NEXT_PASS (pass_iv_optimize);
0526a3ff 612 NEXT_PASS (pass_tree_loop_done);
77fce4cd 613 *p = NULL;
614
823e5999 615 p = &pass_vectorize.sub;
922f49a3 616 NEXT_PASS (pass_lower_vector_ssa);
78eb8231 617 NEXT_PASS (pass_dce_loop);
823e5999 618 *p = NULL;
619
0526a3ff 620 p = &pass_loop2.sub;
621 NEXT_PASS (pass_rtl_loop_init);
622 NEXT_PASS (pass_rtl_move_loop_invariants);
623 NEXT_PASS (pass_rtl_unswitch);
624 NEXT_PASS (pass_rtl_unroll_and_peel_loops);
625 NEXT_PASS (pass_rtl_doloop);
626 NEXT_PASS (pass_rtl_loop_done);
627 *p = NULL;
628
77fce4cd 629 p = &pass_rest_of_compilation.sub;
630 NEXT_PASS (pass_remove_unnecessary_notes);
631 NEXT_PASS (pass_init_function);
632 NEXT_PASS (pass_jump);
633 NEXT_PASS (pass_insn_locators_initialize);
634 NEXT_PASS (pass_rtl_eh);
635 NEXT_PASS (pass_initial_value_sets);
636 NEXT_PASS (pass_unshare_all_rtl);
637 NEXT_PASS (pass_instantiate_virtual_regs);
638 NEXT_PASS (pass_jump2);
639 NEXT_PASS (pass_cse);
640 NEXT_PASS (pass_gcse);
641 NEXT_PASS (pass_loop_optimize);
642 NEXT_PASS (pass_jump_bypass);
643 NEXT_PASS (pass_cfg);
ed4294da 644 NEXT_PASS (pass_branch_prob);
77fce4cd 645 NEXT_PASS (pass_rtl_ifcvt);
646 NEXT_PASS (pass_tracer);
0526a3ff 647 /* Perform loop optimizations. It might be better to do them a bit
648 sooner, but we want the profile feedback to work more
649 efficiently. */
77fce4cd 650 NEXT_PASS (pass_loop2);
651 NEXT_PASS (pass_web);
652 NEXT_PASS (pass_cse2);
653 NEXT_PASS (pass_life);
654 NEXT_PASS (pass_combine);
655 NEXT_PASS (pass_if_after_combine);
656 NEXT_PASS (pass_partition_blocks);
657 NEXT_PASS (pass_regmove);
658 NEXT_PASS (pass_split_all_insns);
659 NEXT_PASS (pass_mode_switching);
660 NEXT_PASS (pass_recompute_reg_usage);
661 NEXT_PASS (pass_sms);
662 NEXT_PASS (pass_sched);
663 NEXT_PASS (pass_local_alloc);
664 NEXT_PASS (pass_global_alloc);
665 NEXT_PASS (pass_postreload);
666 *p = NULL;
667
77fce4cd 668 p = &pass_postreload.sub;
669 NEXT_PASS (pass_postreload_cse);
670 NEXT_PASS (pass_gcse2);
671 NEXT_PASS (pass_flow2);
89140b26 672 NEXT_PASS (pass_rtl_seqabstr);
77fce4cd 673 NEXT_PASS (pass_stack_adjustments);
674 NEXT_PASS (pass_peephole2);
675 NEXT_PASS (pass_if_after_reload);
676 NEXT_PASS (pass_regrename);
677 NEXT_PASS (pass_reorder_blocks);
678 NEXT_PASS (pass_branch_target_load_optimize);
679 NEXT_PASS (pass_leaf_regs);
680 NEXT_PASS (pass_sched2);
681 NEXT_PASS (pass_split_before_regstack);
682 NEXT_PASS (pass_stack_regs);
683 NEXT_PASS (pass_compute_alignments);
684 NEXT_PASS (pass_duplicate_computed_gotos);
685 NEXT_PASS (pass_variable_tracking);
686 NEXT_PASS (pass_free_cfg);
687 NEXT_PASS (pass_machine_reorg);
688 NEXT_PASS (pass_purge_lineno_notes);
689 NEXT_PASS (pass_cleanup_barriers);
690 NEXT_PASS (pass_delay_slots);
691 NEXT_PASS (pass_split_for_shorten_branches);
692 NEXT_PASS (pass_convert_to_eh_region_ranges);
693 NEXT_PASS (pass_shorten_branches);
694 NEXT_PASS (pass_set_nothrow_function_flags);
695 NEXT_PASS (pass_final);
696 *p = NULL;
697
698#undef NEXT_PASS
699
700 /* Register the passes with the tree dump code. */
c24b15e4 701 register_dump_files (all_ipa_passes, true, PROP_gimple_leh | PROP_cfg);
77fce4cd 702 register_dump_files (all_lowering_passes, false, PROP_gimple_any);
c24b15e4 703 register_dump_files (all_passes, false, PROP_gimple_leh | PROP_cfg);
77fce4cd 704}
705
706static unsigned int last_verified;
77fce4cd 707static void
708execute_todo (struct tree_opt_pass *pass, unsigned int flags, bool use_required)
709{
710 int properties
711 = use_required ? pass->properties_required : pass->properties_provided;
712
713#if defined ENABLE_CHECKING
714 if (need_ssa_update_p ())
715 gcc_assert (flags & TODO_update_ssa_any);
716#endif
717
91be5bb8 718 /* Always cleanup the CFG before doing anything else. */
77fce4cd 719 if (flags & TODO_cleanup_cfg)
720 {
721 if (current_loops)
722 cleanup_tree_cfg_loop ();
723 else
724 cleanup_tree_cfg ();
ae79515f 725
726 /* When cleanup_tree_cfg merges consecutive blocks, it may
727 perform some simplistic propagation when removing single
728 valued PHI nodes. This propagation may, in turn, cause the
729 SSA form to become out-of-date (see PR 22037). So, even
730 if the parent pass had not scheduled an SSA update, we may
731 still need to do one. */
732 if (!(flags & TODO_update_ssa_any) && need_ssa_update_p ())
733 flags |= TODO_update_ssa;
77fce4cd 734 }
a49a878f 735
91be5bb8 736 if (flags & TODO_update_ssa_any)
737 {
738 unsigned update_flags = flags & TODO_update_ssa_any;
739 update_ssa (update_flags);
740 }
741
db22d3cc 742 if (flags & TODO_remove_unused_locals)
743 remove_unused_locals ();
744
77fce4cd 745 if ((flags & TODO_dump_func)
746 && dump_file && current_function_decl)
747 {
748 if (properties & PROP_trees)
749 dump_function_to_file (current_function_decl,
750 dump_file, dump_flags);
751 else if (properties & PROP_cfg)
5f0ef107 752 {
753 print_rtl_with_bb (dump_file, get_insns ());
754
755 if (graph_dump_format != no_graph
756 && (dump_flags & TDF_GRAPH))
757 print_rtl_graph_with_bb (dump_file_name, get_insns ());
758 }
77fce4cd 759 else
760 print_rtl (dump_file, get_insns ());
761
762 /* Flush the file. If verification fails, we won't be able to
763 close the file before aborting. */
764 fflush (dump_file);
765 }
766 if ((flags & TODO_dump_cgraph)
767 && dump_file && !current_function_decl)
768 {
769 dump_cgraph (dump_file);
770 /* Flush the file. If verification fails, we won't be able to
771 close the file before aborting. */
772 fflush (dump_file);
773 }
a49a878f 774
77fce4cd 775 if (flags & TODO_ggc_collect)
776 {
777 ggc_collect ();
778 }
da2f1613 779
77fce4cd 780#if defined ENABLE_CHECKING
781 if ((pass->properties_required & PROP_ssa)
782 && !(pass->properties_destroyed & PROP_ssa))
783 verify_ssa (true);
784 if (flags & TODO_verify_flow)
785 verify_flow_info ();
786 if (flags & TODO_verify_stmts)
787 verify_stmts ();
788 if (flags & TODO_verify_loops)
789 verify_loop_closed_ssa ();
790#endif
a49a878f 791}
792
77fce4cd 793static bool
794execute_one_pass (struct tree_opt_pass *pass)
a49a878f 795{
77fce4cd 796 unsigned int todo;
da2f1613 797
77fce4cd 798 /* See if we're supposed to run this pass. */
799 if (pass->gate && !pass->gate ())
800 return false;
a49a878f 801
77fce4cd 802 /* Note that the folders should only create gimple expressions.
803 This is a hack until the new folder is ready. */
804 in_gimple_form = (pass->properties_provided & PROP_trees) != 0;
a49a878f 805
77fce4cd 806 /* Run pre-pass verification. */
807 todo = pass->todo_flags_start & ~last_verified;
808 if (todo)
809 execute_todo (pass, todo, true);
a49a878f 810
77fce4cd 811 /* If a dump file name is present, open it if enabled. */
812 if (pass->static_pass_number != -1)
813 {
814 bool initializing_dump = !dump_initialized_p (pass->static_pass_number);
815 dump_file_name = get_dump_file_name (pass->static_pass_number);
816 dump_file = dump_begin (pass->static_pass_number, &dump_flags);
817 if (dump_file && current_function_decl)
818 {
819 const char *dname, *aname;
820 dname = lang_hooks.decl_printable_name (current_function_decl, 2);
821 aname = (IDENTIFIER_POINTER
822 (DECL_ASSEMBLER_NAME (current_function_decl)));
823 fprintf (dump_file, "\n;; Function %s (%s)%s\n\n", dname, aname,
824 cfun->function_frequency == FUNCTION_FREQUENCY_HOT
825 ? " (hot)"
826 : cfun->function_frequency == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED
827 ? " (unlikely executed)"
828 : "");
829 }
a49a878f 830
77fce4cd 831 if (initializing_dump
5f0ef107 832 && dump_file
833 && graph_dump_format != no_graph
77fce4cd 834 && (pass->properties_provided & (PROP_cfg | PROP_rtl))
835 == (PROP_cfg | PROP_rtl))
5f0ef107 836 {
837 get_dump_file_info (pass->static_pass_number)->flags |= TDF_GRAPH;
838 dump_flags |= TDF_GRAPH;
839 clean_graph_dump_file (dump_file_name);
840 }
77fce4cd 841 }
a49a878f 842
77fce4cd 843 /* If a timevar is present, start it. */
844 if (pass->tv_id)
845 timevar_push (pass->tv_id);
a49a878f 846
77fce4cd 847 /* Do it! */
848 if (pass->execute)
849 pass->execute ();
a49a878f 850
77fce4cd 851 /* Stop timevar. */
852 if (pass->tv_id)
853 timevar_pop (pass->tv_id);
a49a878f 854
77fce4cd 855 /* Run post-pass cleanup and verification. */
856 todo = pass->todo_flags_finish;
857 last_verified = todo & TODO_verify_all;
858 if (todo)
859 execute_todo (pass, todo, false);
a49a878f 860
77fce4cd 861 /* Flush and close dump file. */
862 if (dump_file_name)
a49a878f 863 {
77fce4cd 864 free ((char *) dump_file_name);
865 dump_file_name = NULL;
a49a878f 866 }
77fce4cd 867 if (dump_file)
a49a878f 868 {
77fce4cd 869 dump_end (pass->static_pass_number, dump_file);
870 dump_file = NULL;
a49a878f 871 }
872
77fce4cd 873 return true;
a49a878f 874}
875
77fce4cd 876void
877execute_pass_list (struct tree_opt_pass *pass)
a49a878f 878{
77fce4cd 879 do
a49a878f 880 {
77fce4cd 881 if (execute_one_pass (pass) && pass->sub)
882 execute_pass_list (pass->sub);
883 pass = pass->next;
a49a878f 884 }
77fce4cd 885 while (pass);
a49a878f 886}
887
77fce4cd 888/* Same as execute_pass_list but assume that subpasses of IPA passes
889 are local passes. */
890void
891execute_ipa_pass_list (struct tree_opt_pass *pass)
a49a878f 892{
77fce4cd 893 do
a49a878f 894 {
77fce4cd 895 if (execute_one_pass (pass) && pass->sub)
a49a878f 896 {
77fce4cd 897 struct cgraph_node *node;
898 for (node = cgraph_nodes; node; node = node->next)
899 if (node->analyzed)
900 {
901 push_cfun (DECL_STRUCT_FUNCTION (node->decl));
902 current_function_decl = node->decl;
903 execute_pass_list (pass->sub);
904 free_dominance_info (CDI_DOMINATORS);
905 free_dominance_info (CDI_POST_DOMINATORS);
906 current_function_decl = NULL;
907 pop_cfun ();
908 ggc_collect ();
909 }
a49a878f 910 }
77fce4cd 911 pass = pass->next;
a49a878f 912 }
77fce4cd 913 while (pass);
da2f1613 914}