]> gcc.gnu.org Git - gcc.git/blame - gcc/passes.c
omp-low.c (expand_omp_parallel): Set function properties.
[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,
2090d6a0 3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
f6db1481
RH
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
366ccddb
KC
19Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
2002110-1301, USA. */
f6db1481
RH
21
22/* This is the top level of cc1/c++.
23 It parses command args, opens files, invokes the various passes
24 in the proper order, and counts the time used by each.
25 Error messages and low-level interface to malloc also handled here. */
26
27#include "config.h"
28#undef FLOAT /* This is for hpux. They should change hpux. */
29#undef FFS /* Some systems define this in param.h. */
30#include "system.h"
31#include "coretypes.h"
32#include "tm.h"
33#include <signal.h>
34
35#ifdef HAVE_SYS_RESOURCE_H
36# include <sys/resource.h>
37#endif
38
39#ifdef HAVE_SYS_TIMES_H
40# include <sys/times.h>
41#endif
42
43#include "line-map.h"
44#include "input.h"
45#include "tree.h"
46#include "rtl.h"
47#include "tm_p.h"
48#include "flags.h"
49#include "insn-attr.h"
50#include "insn-config.h"
51#include "insn-flags.h"
52#include "hard-reg-set.h"
53#include "recog.h"
54#include "output.h"
55#include "except.h"
56#include "function.h"
57#include "toplev.h"
58#include "expr.h"
59#include "basic-block.h"
60#include "intl.h"
61#include "ggc.h"
62#include "graph.h"
f6db1481
RH
63#include "regs.h"
64#include "timevar.h"
65#include "diagnostic.h"
66#include "params.h"
67#include "reload.h"
68#include "dwarf2asm.h"
69#include "integrate.h"
70#include "real.h"
71#include "debug.h"
72#include "target.h"
73#include "langhooks.h"
74#include "cfglayout.h"
75#include "cfgloop.h"
76#include "hosthooks.h"
77#include "cgraph.h"
78#include "opts.h"
79#include "coverage.h"
80#include "value-prof.h"
ef330312
PB
81#include "tree-inline.h"
82#include "tree-flow.h"
2f8e398b 83#include "tree-pass.h"
9f8628ba 84#include "tree-dump.h"
f6db1481
RH
85
86#if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
87#include "dwarf2out.h"
88#endif
89
97b0ade3 90#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
f6db1481
RH
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
ef330312
PB
103/* Global variables used to communicate with passes. */
104int dump_flags;
105bool in_gimple_form;
f6db1481 106
f6db1481
RH
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
0e6df31e
GK
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).
f6db1481 116
0e6df31e 117 DECL is the declaration. TOP_LEVEL is nonzero
f6db1481
RH
118 if this declaration is not within a function. */
119
120void
121rest_of_decl_compilation (tree decl,
f6db1481
RH
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
0e6df31e
GK
138 /* Can't defer this, because it needs to happen before any
139 later function definitions are processed. */
820cc88f 140 if (DECL_ASSEMBLER_NAME_SET_P (decl) && DECL_REGISTER (decl))
0e6df31e
GK
141 make_decl_rtl (decl);
142
f6db1481
RH
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
f6db1481
RH
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)
cd9c7bd2 158 || DECL_INITIAL (decl))
f6db1481
RH
159 && !DECL_EXTERNAL (decl))
160 {
db5f8b93 161 if (TREE_CODE (decl) != FUNCTION_DECL)
8a4a83ed 162 varpool_finalize_decl (decl);
f6db1481
RH
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 }
ef11c839
SB
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))
f6db1481
RH
181 {
182 timevar_push (TV_SYMOUT);
183 debug_hooks->type_decl (decl, !top_level);
184 timevar_pop (TV_SYMOUT);
185 }
e4d5432a 186
aabcd309 187 /* Let cgraph know about the existence of variables. */
e4d5432a 188 if (TREE_CODE (decl) == VAR_DECL && !DECL_EXTERNAL (decl))
8a4a83ed 189 varpool_node (decl);
f6db1481
RH
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
ef330312 207\f
f6db1481 208
ef330312
PB
209void
210finish_optimization_passes (void)
f6db1481 211{
ef330312
PB
212 enum tree_dump_index i;
213 struct dump_file_info *dfi;
214 char *name;
f6db1481 215
ef330312
PB
216 timevar_push (TV_DUMP);
217 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
f6db1481 218 {
3d47ea88 219 dump_file = dump_begin (pass_profile.static_pass_number, NULL);
ef330312
PB
220 end_branch_prob ();
221 if (dump_file)
3d47ea88 222 dump_end (pass_profile.static_pass_number, dump_file);
f6db1481 223 }
f6db1481 224
ef330312 225 if (optimize > 0)
f6db1481 226 {
ef330312
PB
227 dump_file = dump_begin (pass_combine.static_pass_number, NULL);
228 if (dump_file)
f6db1481 229 {
ef330312
PB
230 dump_combine_total_stats (dump_file);
231 dump_end (pass_combine.static_pass_number, dump_file);
f6db1481
RH
232 }
233 }
234
ef330312
PB
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)
5e34206b 239 && (dfi->flags & TDF_GRAPH) != 0
ef330312 240 && (name = get_dump_file_name (i)) != NULL)
5e34206b
JJ
241 {
242 finish_graph_dump_file (name);
243 free (name);
244 }
f6db1481 245
ef330312 246 timevar_pop (TV_DUMP);
f6db1481 247}
f6db1481 248
ef330312
PB
249static bool
250gate_rest_of_compilation (void)
f6db1481 251{
ef330312
PB
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);
f6db1481
RH
255}
256
ef330312 257struct tree_opt_pass pass_rest_of_compilation =
f6db1481 258{
ef330312
PB
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};
f6db1481 273
ef330312
PB
274static bool
275gate_postreload (void)
276{
277 return reload_completed;
f6db1481
RH
278}
279
ef330312 280struct tree_opt_pass pass_postreload =
f6db1481 281{
ef330312
PB
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};
f6db1481 296
97b0ade3 297
f6db1481 298
ef330312
PB
299/* The root of the compilation pass tree, once constructed. */
300struct tree_opt_pass *all_passes, *all_ipa_passes, *all_lowering_passes;
f6db1481 301
ef330312
PB
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. */
f6db1481 305
ef330312 306static void
bbbe4e7b 307register_one_dump_file (struct tree_opt_pass *pass, bool ipa, int properties)
ef330312
PB
308{
309 char *dot_name, *flag_name, *glob_name;
bbbe4e7b 310 const char *prefix;
ef330312 311 char num[10];
bbbe4e7b 312 int flags;
f6db1481 313
ef330312
PB
314 /* See below in next_pass_1. */
315 num[0] = '\0';
316 if (pass->static_pass_number != -1)
317 sprintf (num, "%d", ((int) pass->static_pass_number < 0
318 ? 1 : pass->static_pass_number));
f6db1481 319
ef330312
PB
320 dot_name = concat (".", pass->name, num, NULL);
321 if (ipa)
bbbe4e7b
PB
322 prefix = "ipa-", flags = TDF_IPA;
323 else if (properties & PROP_trees)
324 prefix = "tree-", flags = TDF_TREE;
f6db1481 325 else
bbbe4e7b
PB
326 prefix = "rtl-", flags = TDF_RTL;
327
328 flag_name = concat (prefix, pass->name, num, NULL);
329 glob_name = concat (prefix, pass->name, NULL);
330 pass->static_pass_number = dump_register (dot_name, flag_name, glob_name,
331 flags, pass->letter);
97b0ade3
PB
332}
333
bbbe4e7b
PB
334/* Recursive worker function for register_dump_files. */
335
ef330312 336static int
bbbe4e7b 337register_dump_files_1 (struct tree_opt_pass *pass, bool ipa, int properties)
97b0ade3 338{
ef330312
PB
339 do
340 {
bbbe4e7b
PB
341 int new_properties = (properties | pass->properties_provided)
342 & ~pass->properties_destroyed;
f6db1481 343
ef330312 344 if (pass->name)
bbbe4e7b 345 register_one_dump_file (pass, ipa, new_properties);
f6db1481 346
ef330312 347 if (pass->sub)
bbbe4e7b
PB
348 new_properties = register_dump_files_1 (pass->sub, false,
349 new_properties);
f6db1481 350
ef330312
PB
351 /* If we have a gate, combine the properties that we could have with
352 and without the pass being examined. */
353 if (pass->gate)
354 properties &= new_properties;
355 else
356 properties = new_properties;
f6db1481 357
ef330312 358 pass = pass->next;
f6db1481 359 }
ef330312 360 while (pass);
f6db1481 361
ef330312 362 return properties;
f6db1481 363}
f9957958 364
bbbe4e7b
PB
365/* Register the dump files for the pipeline starting at PASS. IPA is
366 true if the pass is inter-procedural, and PROPERTIES reflects the
c0220ea4 367 properties that are guaranteed to be available at the beginning of
bbbe4e7b
PB
368 the pipeline. */
369
370static void
371register_dump_files (struct tree_opt_pass *pass, bool ipa, int properties)
372{
373 pass->properties_required |= properties;
bbbe4e7b
PB
374 register_dump_files_1 (pass, ipa, properties);
375}
376
ef330312
PB
377/* Add a pass to the pass list. Duplicate the pass if it's already
378 in the list. */
f9957958 379
ef330312
PB
380static struct tree_opt_pass **
381next_pass_1 (struct tree_opt_pass **list, struct tree_opt_pass *pass)
f6db1481 382{
ef330312
PB
383 /* A nonzero static_pass_number indicates that the
384 pass is already in the list. */
385 if (pass->static_pass_number)
386 {
387 struct tree_opt_pass *new;
f6db1481 388
ef330312
PB
389 new = xmalloc (sizeof (*new));
390 memcpy (new, pass, sizeof (*new));
f6db1481 391
ef330312
PB
392 /* Indicate to register_dump_files that this pass has duplicates,
393 and so it should rename the dump file. The first instance will
394 be -1, and be number of duplicates = -static_pass_number - 1.
395 Subsequent instances will be > 0 and just the duplicate number. */
396 if (pass->name)
397 {
398 pass->static_pass_number -= 1;
399 new->static_pass_number = -pass->static_pass_number;
400 }
401
402 *list = new;
403 }
404 else
405 {
406 pass->static_pass_number = -1;
407 *list = pass;
408 }
409
410 return &(*list)->next;
411
f6db1481
RH
412}
413
dd97d271
DN
414/* Construct the pass tree. The sequencing of passes is driven by
415 the cgraph routines:
416
417 cgraph_finalize_compilation_unit ()
418 for each node N in the cgraph
419 cgraph_analyze_function (N)
420 cgraph_lower_function (N) -> all_lowering_passes
421
422 If we are optimizing, cgraph_optimize is then invoked:
423
424 cgraph_optimize ()
425 ipa_passes () -> all_ipa_passes
426 cgraph_expand_all_functions ()
427 for each node N in the cgraph
428 cgraph_expand_function (N)
429 cgraph_lower_function (N) -> Now a NOP.
430 lang_hooks.callgraph.expand_function (DECL (N))
431 tree_rest_of_compilation (DECL (N)) -> all_passes
432*/
97b0ade3 433
ef330312
PB
434void
435init_optimization_passes (void)
436{
437 struct tree_opt_pass **p;
438
439#define NEXT_PASS(PASS) (p = next_pass_1 (p, &PASS))
440 /* Interprocedural optimization passes. */
441 p = &all_ipa_passes;
442 NEXT_PASS (pass_early_ipa_inline);
443 NEXT_PASS (pass_early_local_passes);
57fb5341 444 NEXT_PASS (pass_ipa_cp);
ef330312 445 NEXT_PASS (pass_ipa_inline);
ea900239
DB
446 NEXT_PASS (pass_ipa_reference);
447 NEXT_PASS (pass_ipa_pure_const);
448 NEXT_PASS (pass_ipa_type_escape);
4cf4d6a3 449 NEXT_PASS (pass_ipa_pta);
ef330312
PB
450 *p = NULL;
451
dd97d271
DN
452 /* All passes needed to lower the function into shape optimizers can
453 operate on. */
ef330312
PB
454 p = &all_lowering_passes;
455 NEXT_PASS (pass_remove_useless_stmts);
456 NEXT_PASS (pass_mudflap_1);
953ff289 457 NEXT_PASS (pass_lower_omp);
ef330312
PB
458 NEXT_PASS (pass_lower_cf);
459 NEXT_PASS (pass_lower_eh);
460 NEXT_PASS (pass_build_cfg);
461 NEXT_PASS (pass_lower_complex_O0);
462 NEXT_PASS (pass_lower_vector);
463 NEXT_PASS (pass_warn_function_return);
464 NEXT_PASS (pass_early_tree_profile);
465 *p = NULL;
466
467 p = &pass_early_local_passes.sub;
468 NEXT_PASS (pass_tree_profile);
469 NEXT_PASS (pass_cleanup_cfg);
470 NEXT_PASS (pass_rebuild_cgraph_edges);
471 *p = NULL;
472
473 p = &all_passes;
474 NEXT_PASS (pass_fixup_cfg);
475 NEXT_PASS (pass_init_datastructures);
50674e96 476 NEXT_PASS (pass_expand_omp);
ef330312
PB
477 NEXT_PASS (pass_all_optimizations);
478 NEXT_PASS (pass_warn_function_noreturn);
479 NEXT_PASS (pass_mudflap_2);
480 NEXT_PASS (pass_free_datastructures);
481 NEXT_PASS (pass_free_cfg_annotations);
482 NEXT_PASS (pass_expand);
483 NEXT_PASS (pass_rest_of_compilation);
484 NEXT_PASS (pass_clean_state);
485 *p = NULL;
486
487 p = &pass_all_optimizations.sub;
488 NEXT_PASS (pass_referenced_vars);
fe1f8f44 489 NEXT_PASS (pass_reset_cc_flags);
ef330312
PB
490 NEXT_PASS (pass_create_structure_vars);
491 NEXT_PASS (pass_build_ssa);
ef330312
PB
492 NEXT_PASS (pass_may_alias);
493 NEXT_PASS (pass_return_slot);
ef330312
PB
494 NEXT_PASS (pass_rename_ssa_copies);
495 NEXT_PASS (pass_early_warn_uninitialized);
496
497 /* Initial scalar cleanups. */
498 NEXT_PASS (pass_ccp);
499 NEXT_PASS (pass_fre);
500 NEXT_PASS (pass_dce);
501 NEXT_PASS (pass_forwprop);
502 NEXT_PASS (pass_copy_prop);
2090d6a0 503 NEXT_PASS (pass_merge_phi);
ef330312
PB
504 NEXT_PASS (pass_vrp);
505 NEXT_PASS (pass_dce);
ef330312
PB
506 NEXT_PASS (pass_dominator);
507
e67c25c7
JL
508 /* The only const/copy propagation opportunities left after
509 DOM should be due to degenerate PHI nodes. So rather than
510 run the full propagators, run a specialized pass which
511 only examines PHIs to discover const/copy propagation
512 opportunities. */
513 NEXT_PASS (pass_phi_only_cprop);
f20731b7 514
ef330312 515 NEXT_PASS (pass_phiopt);
ef330312 516 NEXT_PASS (pass_may_alias);
ef330312
PB
517 NEXT_PASS (pass_tail_recursion);
518 NEXT_PASS (pass_profile);
519 NEXT_PASS (pass_ch);
520 NEXT_PASS (pass_stdarg);
521 NEXT_PASS (pass_lower_complex);
522 NEXT_PASS (pass_sra);
523 /* FIXME: SRA may generate arbitrary gimple code, exposing new
524 aliased and call-clobbered variables. As mentioned below,
525 pass_may_alias should be a TODO item. */
526 NEXT_PASS (pass_may_alias);
527 NEXT_PASS (pass_rename_ssa_copies);
528 NEXT_PASS (pass_dominator);
f20731b7 529
e67c25c7
JL
530 /* The only const/copy propagation opportunities left after
531 DOM should be due to degenerate PHI nodes. So rather than
532 run the full propagators, run a specialized pass which
533 only examines PHIs to discover const/copy propagation
534 opportunities. */
535 NEXT_PASS (pass_phi_only_cprop);
f20731b7 536
0e0ed594 537 NEXT_PASS (pass_reassoc);
ef330312
PB
538 NEXT_PASS (pass_dce);
539 NEXT_PASS (pass_dse);
540 NEXT_PASS (pass_may_alias);
541 NEXT_PASS (pass_forwprop);
542 NEXT_PASS (pass_phiopt);
543 NEXT_PASS (pass_object_sizes);
544 NEXT_PASS (pass_store_ccp);
545 NEXT_PASS (pass_store_copy_prop);
546 NEXT_PASS (pass_fold_builtins);
547 /* FIXME: May alias should a TODO but for 4.0.0,
548 we add may_alias right after fold builtins
549 which can create arbitrary GIMPLE. */
550 NEXT_PASS (pass_may_alias);
ef330312 551 NEXT_PASS (pass_split_crit_edges);
ef330312 552 NEXT_PASS (pass_pre);
c90186eb 553 NEXT_PASS (pass_may_alias);
ef330312 554 NEXT_PASS (pass_sink_code);
9fa26457 555 NEXT_PASS (pass_tree_loop);
bc23502b 556 NEXT_PASS (pass_cse_reciprocals);
0e0ed594 557 NEXT_PASS (pass_reassoc);
2090d6a0 558 NEXT_PASS (pass_vrp);
ef330312 559 NEXT_PASS (pass_dominator);
f20731b7 560
e67c25c7
JL
561 /* The only const/copy propagation opportunities left after
562 DOM should be due to degenerate PHI nodes. So rather than
563 run the full propagators, run a specialized pass which
564 only examines PHIs to discover const/copy propagation
565 opportunities. */
566 NEXT_PASS (pass_phi_only_cprop);
f20731b7 567
ef330312
PB
568 NEXT_PASS (pass_cd_dce);
569
570 /* FIXME: If DCE is not run before checking for uninitialized uses,
571 we may get false warnings (e.g., testsuite/gcc.dg/uninit-5.c).
572 However, this also causes us to misdiagnose cases that should be
573 real warnings (e.g., testsuite/gcc.dg/pr18501.c).
574
575 To fix the false positives in uninit-5.c, we would have to
576 account for the predicates protecting the set and the use of each
577 variable. Using a representation like Gated Single Assignment
578 may help. */
579 NEXT_PASS (pass_late_warn_uninitialized);
580 NEXT_PASS (pass_dse);
581 NEXT_PASS (pass_forwprop);
582 NEXT_PASS (pass_phiopt);
583 NEXT_PASS (pass_tail_calls);
584 NEXT_PASS (pass_rename_ssa_copies);
585 NEXT_PASS (pass_uncprop);
586 NEXT_PASS (pass_del_ssa);
587 NEXT_PASS (pass_nrv);
ef330312
PB
588 NEXT_PASS (pass_mark_used_blocks);
589 NEXT_PASS (pass_cleanup_cfg_post_optimizing);
590 *p = NULL;
591
9fa26457
SB
592 p = &pass_tree_loop.sub;
593 NEXT_PASS (pass_tree_loop_init);
ef330312
PB
594 NEXT_PASS (pass_copy_prop);
595 NEXT_PASS (pass_lim);
9fa26457 596 NEXT_PASS (pass_tree_unswitch);
ef330312 597 NEXT_PASS (pass_scev_cprop);
b7eae7b8 598 NEXT_PASS (pass_empty_loop);
ef330312
PB
599 NEXT_PASS (pass_record_bounds);
600 NEXT_PASS (pass_linear_transform);
601 NEXT_PASS (pass_iv_canon);
602 NEXT_PASS (pass_if_conversion);
603 NEXT_PASS (pass_vectorize);
604 /* NEXT_PASS (pass_may_alias) cannot be done again because the
605 vectorizer creates alias relations that are not supported by
606 pass_may_alias. */
ef330312 607 NEXT_PASS (pass_complete_unroll);
17684618 608 NEXT_PASS (pass_loop_prefetch);
ef330312 609 NEXT_PASS (pass_iv_optimize);
9fa26457 610 NEXT_PASS (pass_tree_loop_done);
ef330312
PB
611 *p = NULL;
612
b1e8be10 613 p = &pass_vectorize.sub;
5872662b 614 NEXT_PASS (pass_lower_vector_ssa);
49896738 615 NEXT_PASS (pass_dce_loop);
b1e8be10
RH
616 *p = NULL;
617
9fa26457
SB
618 p = &pass_loop2.sub;
619 NEXT_PASS (pass_rtl_loop_init);
620 NEXT_PASS (pass_rtl_move_loop_invariants);
621 NEXT_PASS (pass_rtl_unswitch);
622 NEXT_PASS (pass_rtl_unroll_and_peel_loops);
623 NEXT_PASS (pass_rtl_doloop);
624 NEXT_PASS (pass_rtl_loop_done);
625 *p = NULL;
626
ef330312 627 p = &pass_rest_of_compilation.sub;
ef330312
PB
628 NEXT_PASS (pass_init_function);
629 NEXT_PASS (pass_jump);
630 NEXT_PASS (pass_insn_locators_initialize);
631 NEXT_PASS (pass_rtl_eh);
632 NEXT_PASS (pass_initial_value_sets);
633 NEXT_PASS (pass_unshare_all_rtl);
634 NEXT_PASS (pass_instantiate_virtual_regs);
635 NEXT_PASS (pass_jump2);
636 NEXT_PASS (pass_cse);
a52b023a 637 NEXT_PASS (pass_rtl_fwprop);
ef330312 638 NEXT_PASS (pass_gcse);
ef330312 639 NEXT_PASS (pass_jump_bypass);
ef330312
PB
640 NEXT_PASS (pass_rtl_ifcvt);
641 NEXT_PASS (pass_tracer);
9fa26457
SB
642 /* Perform loop optimizations. It might be better to do them a bit
643 sooner, but we want the profile feedback to work more
644 efficiently. */
ef330312
PB
645 NEXT_PASS (pass_loop2);
646 NEXT_PASS (pass_web);
647 NEXT_PASS (pass_cse2);
a52b023a 648 NEXT_PASS (pass_rtl_fwprop_addr);
ef330312
PB
649 NEXT_PASS (pass_life);
650 NEXT_PASS (pass_combine);
651 NEXT_PASS (pass_if_after_combine);
652 NEXT_PASS (pass_partition_blocks);
653 NEXT_PASS (pass_regmove);
654 NEXT_PASS (pass_split_all_insns);
655 NEXT_PASS (pass_mode_switching);
8cd37d0b 656 NEXT_PASS (pass_see);
ef330312
PB
657 NEXT_PASS (pass_recompute_reg_usage);
658 NEXT_PASS (pass_sms);
659 NEXT_PASS (pass_sched);
660 NEXT_PASS (pass_local_alloc);
661 NEXT_PASS (pass_global_alloc);
662 NEXT_PASS (pass_postreload);
663 *p = NULL;
664
ef330312
PB
665 p = &pass_postreload.sub;
666 NEXT_PASS (pass_postreload_cse);
667 NEXT_PASS (pass_gcse2);
668 NEXT_PASS (pass_flow2);
38109dab 669 NEXT_PASS (pass_rtl_seqabstr);
ef330312
PB
670 NEXT_PASS (pass_stack_adjustments);
671 NEXT_PASS (pass_peephole2);
672 NEXT_PASS (pass_if_after_reload);
673 NEXT_PASS (pass_regrename);
674 NEXT_PASS (pass_reorder_blocks);
675 NEXT_PASS (pass_branch_target_load_optimize);
676 NEXT_PASS (pass_leaf_regs);
677 NEXT_PASS (pass_sched2);
678 NEXT_PASS (pass_split_before_regstack);
679 NEXT_PASS (pass_stack_regs);
680 NEXT_PASS (pass_compute_alignments);
681 NEXT_PASS (pass_duplicate_computed_gotos);
682 NEXT_PASS (pass_variable_tracking);
683 NEXT_PASS (pass_free_cfg);
684 NEXT_PASS (pass_machine_reorg);
ef330312
PB
685 NEXT_PASS (pass_cleanup_barriers);
686 NEXT_PASS (pass_delay_slots);
687 NEXT_PASS (pass_split_for_shorten_branches);
688 NEXT_PASS (pass_convert_to_eh_region_ranges);
689 NEXT_PASS (pass_shorten_branches);
690 NEXT_PASS (pass_set_nothrow_function_flags);
691 NEXT_PASS (pass_final);
692 *p = NULL;
693
694#undef NEXT_PASS
695
696 /* Register the passes with the tree dump code. */
a5093353
JH
697 register_dump_files (all_lowering_passes, false, PROP_gimple_any);
698 all_lowering_passes->todo_flags_start |= TODO_set_props;
bbbe4e7b
PB
699 register_dump_files (all_ipa_passes, true,
700 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
701 | PROP_cfg);
bbbe4e7b
PB
702 register_dump_files (all_passes, false,
703 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
704 | PROP_cfg);
ef330312
PB
705}
706
a5093353
JH
707/* If we are in IPA mode (i.e., current_function_decl is NULL), call
708 function CALLBACK for every function in the call graph. Otherwise,
709 call CALLBACK on the current function. */
bbbe4e7b 710
ef330312 711static void
a5093353 712do_per_function (void (*callback) (void *data), void *data)
ef330312 713{
a5093353
JH
714 if (current_function_decl)
715 callback (data);
716 else
717 {
718 struct cgraph_node *node;
719 for (node = cgraph_nodes; node; node = node->next)
720 if (node->analyzed)
721 {
722 push_cfun (DECL_STRUCT_FUNCTION (node->decl));
723 current_function_decl = node->decl;
724 callback (data);
725 free_dominance_info (CDI_DOMINATORS);
726 free_dominance_info (CDI_POST_DOMINATORS);
727 current_function_decl = NULL;
728 pop_cfun ();
729 ggc_collect ();
730 }
731 }
732}
733
734/* Perform all TODO actions that ought to be done on each function. */
ef330312 735
a5093353
JH
736static void
737execute_function_todo (void *data)
738{
739 unsigned int flags = (size_t)data;
740 if (cfun->curr_properties & PROP_ssa)
bbbe4e7b 741 flags |= TODO_verify_ssa;
a5093353 742 flags &= ~cfun->last_verified;
bbbe4e7b
PB
743 if (!flags)
744 return;
a6c550f9 745
a6c550f9 746 /* Always cleanup the CFG before trying to update SSA . */
ef330312
PB
747 if (flags & TODO_cleanup_cfg)
748 {
749 if (current_loops)
750 cleanup_tree_cfg_loop ();
751 else
752 cleanup_tree_cfg ();
c4f548b8
DN
753
754 /* When cleanup_tree_cfg merges consecutive blocks, it may
755 perform some simplistic propagation when removing single
756 valued PHI nodes. This propagation may, in turn, cause the
757 SSA form to become out-of-date (see PR 22037). So, even
758 if the parent pass had not scheduled an SSA update, we may
759 still need to do one. */
760 if (!(flags & TODO_update_ssa_any) && need_ssa_update_p ())
761 flags |= TODO_update_ssa;
ef330312 762 }
f6db1481 763
563cb6be
DN
764 if (flags & TODO_update_ssa_any)
765 {
766 unsigned update_flags = flags & TODO_update_ssa_any;
767 update_ssa (update_flags);
a5093353 768 cfun->last_verified &= ~TODO_verify_ssa;
563cb6be
DN
769 }
770
3f519b35
RG
771 if (flags & TODO_remove_unused_locals)
772 remove_unused_locals ();
773
ef330312
PB
774 if ((flags & TODO_dump_func)
775 && dump_file && current_function_decl)
776 {
a5093353 777 if (cfun->curr_properties & PROP_trees)
ef330312
PB
778 dump_function_to_file (current_function_decl,
779 dump_file, dump_flags);
a68e7e6c 780 else
5e34206b 781 {
a68e7e6c
PB
782 if (dump_flags & TDF_SLIM)
783 print_rtl_slim_with_bb (dump_file, get_insns (), dump_flags);
a5093353
JH
784 else if ((cfun->curr_properties & PROP_cfg)
785 && (dump_flags & TDF_BLOCKS))
a68e7e6c
PB
786 print_rtl_with_bb (dump_file, get_insns ());
787 else
788 print_rtl (dump_file, get_insns ());
789
a5093353 790 if (cfun->curr_properties & PROP_cfg
a68e7e6c 791 && graph_dump_format != no_graph
5e34206b
JJ
792 && (dump_flags & TDF_GRAPH))
793 print_rtl_graph_with_bb (dump_file_name, get_insns ());
794 }
ef330312
PB
795
796 /* Flush the file. If verification fails, we won't be able to
797 close the file before aborting. */
798 fflush (dump_file);
799 }
a5093353
JH
800
801#if defined ENABLE_CHECKING
802 if (flags & TODO_verify_ssa)
803 verify_ssa (true);
804 if (flags & TODO_verify_flow)
805 verify_flow_info ();
806 if (flags & TODO_verify_stmts)
807 verify_stmts ();
808 if (flags & TODO_verify_loops)
809 verify_loop_closed_ssa ();
810#endif
811
812 cfun->last_verified = flags & TODO_verify_all;
813}
814
815/* Perform all TODO actions. */
816static void
817execute_todo (unsigned int flags)
818{
819#if defined ENABLE_CHECKING
820 if (need_ssa_update_p ())
821 gcc_assert (flags & TODO_update_ssa_any);
822#endif
823
824 do_per_function (execute_function_todo, (void *)(size_t) flags);
825
ef330312
PB
826 if ((flags & TODO_dump_cgraph)
827 && dump_file && !current_function_decl)
828 {
829 dump_cgraph (dump_file);
830 /* Flush the file. If verification fails, we won't be able to
831 close the file before aborting. */
832 fflush (dump_file);
833 }
f6db1481 834
ef330312
PB
835 if (flags & TODO_ggc_collect)
836 {
837 ggc_collect ();
838 }
a5093353 839}
97b0ade3 840
a5093353
JH
841/* Clear the last verified flag. */
842
843static void
844clear_last_verified (void *data ATTRIBUTE_UNUSED)
845{
846 cfun->last_verified = 0;
847}
848
849/* Helper function. Verify that the properties has been turn into the
850 properties expected by the pass. */
bbbe4e7b 851
a5093353
JH
852static void
853verify_curr_properties (void *data)
854{
855 unsigned int props = (size_t)data;
856 gcc_assert ((cfun->curr_properties & props) == props);
857}
858
859/* After executing the pass, apply expected changes to the function
860 properties. */
861static void
862update_properties_after_pass (void *data)
863{
864 struct tree_opt_pass *pass = data;
865 cfun->curr_properties = (cfun->curr_properties | pass->properties_provided)
866 & ~pass->properties_destroyed;
f6db1481
RH
867}
868
ef330312
PB
869static bool
870execute_one_pass (struct tree_opt_pass *pass)
f6db1481 871{
bbbe4e7b 872 bool initializing_dump;
c2924966 873 unsigned int todo_after = 0;
97b0ade3 874
ef330312
PB
875 /* See if we're supposed to run this pass. */
876 if (pass->gate && !pass->gate ())
877 return false;
f6db1481 878
bbbe4e7b 879 if (pass->todo_flags_start & TODO_set_props)
a5093353 880 cfun->curr_properties = pass->properties_required;
bbbe4e7b 881
ef330312
PB
882 /* Note that the folders should only create gimple expressions.
883 This is a hack until the new folder is ready. */
a5093353 884 in_gimple_form = (cfun && (cfun->curr_properties & PROP_trees)) != 0;
f6db1481 885
ef330312 886 /* Run pre-pass verification. */
bbbe4e7b
PB
887 execute_todo (pass->todo_flags_start);
888
a5093353
JH
889#ifdef ENABLE_CHECKING
890 do_per_function (verify_curr_properties,
891 (void *)(size_t)pass->properties_required);
892#endif
f6db1481 893
ef330312
PB
894 /* If a dump file name is present, open it if enabled. */
895 if (pass->static_pass_number != -1)
896 {
bbbe4e7b 897 initializing_dump = !dump_initialized_p (pass->static_pass_number);
ef330312
PB
898 dump_file_name = get_dump_file_name (pass->static_pass_number);
899 dump_file = dump_begin (pass->static_pass_number, &dump_flags);
900 if (dump_file && current_function_decl)
901 {
902 const char *dname, *aname;
903 dname = lang_hooks.decl_printable_name (current_function_decl, 2);
904 aname = (IDENTIFIER_POINTER
905 (DECL_ASSEMBLER_NAME (current_function_decl)));
906 fprintf (dump_file, "\n;; Function %s (%s)%s\n\n", dname, aname,
907 cfun->function_frequency == FUNCTION_FREQUENCY_HOT
908 ? " (hot)"
909 : cfun->function_frequency == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED
910 ? " (unlikely executed)"
911 : "");
912 }
ef330312 913 }
bbbe4e7b
PB
914 else
915 initializing_dump = false;
f6db1481 916
ef330312
PB
917 /* If a timevar is present, start it. */
918 if (pass->tv_id)
919 timevar_push (pass->tv_id);
f6db1481 920
ef330312
PB
921 /* Do it! */
922 if (pass->execute)
bbbe4e7b 923 {
c2924966 924 todo_after = pass->execute ();
a5093353 925 do_per_function (clear_last_verified, NULL);
bbbe4e7b 926 }
f6db1481 927
ef330312
PB
928 /* Stop timevar. */
929 if (pass->tv_id)
930 timevar_pop (pass->tv_id);
f6db1481 931
a5093353 932 do_per_function (update_properties_after_pass, pass);
bbbe4e7b
PB
933
934 if (initializing_dump
935 && dump_file
936 && graph_dump_format != no_graph
a5093353
JH
937 && (cfun->curr_properties & (PROP_cfg | PROP_rtl))
938 == (PROP_cfg | PROP_rtl))
bbbe4e7b
PB
939 {
940 get_dump_file_info (pass->static_pass_number)->flags |= TDF_GRAPH;
941 dump_flags |= TDF_GRAPH;
942 clean_graph_dump_file (dump_file_name);
943 }
944
ef330312 945 /* Run post-pass cleanup and verification. */
c2924966 946 execute_todo (todo_after | pass->todo_flags_finish);
f6db1481 947
ef330312
PB
948 /* Flush and close dump file. */
949 if (dump_file_name)
f6db1481 950 {
ef330312
PB
951 free ((char *) dump_file_name);
952 dump_file_name = NULL;
f6db1481 953 }
cfaab3a9 954
ef330312 955 if (dump_file)
f6db1481 956 {
ef330312
PB
957 dump_end (pass->static_pass_number, dump_file);
958 dump_file = NULL;
f6db1481
RH
959 }
960
ef330312 961 return true;
f6db1481
RH
962}
963
ef330312
PB
964void
965execute_pass_list (struct tree_opt_pass *pass)
f6db1481 966{
ef330312 967 do
f6db1481 968 {
ef330312
PB
969 if (execute_one_pass (pass) && pass->sub)
970 execute_pass_list (pass->sub);
971 pass = pass->next;
f6db1481 972 }
ef330312 973 while (pass);
f6db1481
RH
974}
975
ef330312
PB
976/* Same as execute_pass_list but assume that subpasses of IPA passes
977 are local passes. */
978void
979execute_ipa_pass_list (struct tree_opt_pass *pass)
f6db1481 980{
ef330312 981 do
f6db1481 982 {
a5093353
JH
983 gcc_assert (!current_function_decl);
984 gcc_assert (!cfun);
ef330312 985 if (execute_one_pass (pass) && pass->sub)
a5093353 986 do_per_function ((void (*)(void *))execute_pass_list, pass->sub);
ef330312 987 pass = pass->next;
f6db1481 988 }
ef330312 989 while (pass);
97b0ade3 990}
This page took 1.247302 seconds and 5 git commands to generate.