* dependency.c (gfc_check_dependency) <EXPR_ARRAY>: Implement
[official-gcc.git] / gcc / passes.c
blobd700ae93bcf598860748d5c8e3a7ffc8ae2e49e2
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, 2005, 2006, 2007
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
21 02110-1301, USA. */
23 /* This is the top level of cc1/c++.
24 It parses command args, opens files, invokes the various passes
25 in the proper order, and counts the time used by each.
26 Error messages and low-level interface to malloc also handled here. */
28 #include "config.h"
29 #undef FLOAT /* This is for hpux. They should change hpux. */
30 #undef FFS /* Some systems define this in param.h. */
31 #include "system.h"
32 #include "coretypes.h"
33 #include "tm.h"
34 #include <signal.h>
36 #ifdef HAVE_SYS_RESOURCE_H
37 # include <sys/resource.h>
38 #endif
40 #ifdef HAVE_SYS_TIMES_H
41 # include <sys/times.h>
42 #endif
44 #include "line-map.h"
45 #include "input.h"
46 #include "tree.h"
47 #include "rtl.h"
48 #include "tm_p.h"
49 #include "flags.h"
50 #include "insn-attr.h"
51 #include "insn-config.h"
52 #include "insn-flags.h"
53 #include "hard-reg-set.h"
54 #include "recog.h"
55 #include "output.h"
56 #include "except.h"
57 #include "function.h"
58 #include "toplev.h"
59 #include "expr.h"
60 #include "basic-block.h"
61 #include "intl.h"
62 #include "ggc.h"
63 #include "graph.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 "tree-inline.h"
83 #include "tree-flow.h"
84 #include "tree-pass.h"
85 #include "tree-dump.h"
87 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
88 #include "dwarf2out.h"
89 #endif
91 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
92 #include "dbxout.h"
93 #endif
95 #ifdef SDB_DEBUGGING_INFO
96 #include "sdbout.h"
97 #endif
99 #ifdef XCOFF_DEBUGGING_INFO
100 #include "xcoffout.h" /* Needed for external data
101 declarations for e.g. AIX 4.x. */
102 #endif
104 /* Global variables used to communicate with passes. */
105 int dump_flags;
106 bool in_gimple_form;
109 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
110 and TYPE_DECL nodes.
112 This does nothing for local (non-static) variables, unless the
113 variable is a register variable with DECL_ASSEMBLER_NAME set. In
114 that case, or if the variable is not an automatic, it sets up the
115 RTL and outputs any assembler code (label definition, storage
116 allocation and initialization).
118 DECL is the declaration. TOP_LEVEL is nonzero
119 if this declaration is not within a function. */
121 void
122 rest_of_decl_compilation (tree decl,
123 int top_level,
124 int at_end)
126 /* We deferred calling assemble_alias so that we could collect
127 other attributes such as visibility. Emit the alias now. */
129 tree alias;
130 alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
131 if (alias)
133 alias = TREE_VALUE (TREE_VALUE (alias));
134 alias = get_identifier (TREE_STRING_POINTER (alias));
135 assemble_alias (decl, alias);
139 /* Can't defer this, because it needs to happen before any
140 later function definitions are processed. */
141 if (DECL_ASSEMBLER_NAME_SET_P (decl) && DECL_REGISTER (decl))
142 make_decl_rtl (decl);
144 /* Forward declarations for nested functions are not "external",
145 but we need to treat them as if they were. */
146 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
147 || TREE_CODE (decl) == FUNCTION_DECL)
149 timevar_push (TV_VARCONST);
151 /* Don't output anything when a tentative file-scope definition
152 is seen. But at end of compilation, do output code for them.
154 We do output all variables when unit-at-a-time is active and rely on
155 callgraph code to defer them except for forward declarations
156 (see gcc.c-torture/compile/920624-1.c) */
157 if ((at_end
158 || !DECL_DEFER_OUTPUT (decl)
159 || DECL_INITIAL (decl))
160 && !DECL_EXTERNAL (decl))
162 if (TREE_CODE (decl) != FUNCTION_DECL)
163 varpool_finalize_decl (decl);
164 else
165 assemble_variable (decl, top_level, at_end, 0);
168 #ifdef ASM_FINISH_DECLARE_OBJECT
169 if (decl == last_assemble_variable_decl)
171 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
172 top_level, at_end);
174 #endif
176 timevar_pop (TV_VARCONST);
178 else if (TREE_CODE (decl) == TYPE_DECL
179 /* Like in rest_of_type_compilation, avoid confusing the debug
180 information machinery when there are errors. */
181 && !(sorrycount || errorcount))
183 timevar_push (TV_SYMOUT);
184 debug_hooks->type_decl (decl, !top_level);
185 timevar_pop (TV_SYMOUT);
188 /* Let cgraph know about the existence of variables. */
189 if (TREE_CODE (decl) == VAR_DECL && !DECL_EXTERNAL (decl))
190 varpool_node (decl);
193 /* Called after finishing a record, union or enumeral type. */
195 void
196 rest_of_type_compilation (tree type, int toplev)
198 /* Avoid confusing the debug information machinery when there are
199 errors. */
200 if (errorcount != 0 || sorrycount != 0)
201 return;
203 timevar_push (TV_SYMOUT);
204 debug_hooks->type_decl (TYPE_STUB_DECL (type), !toplev);
205 timevar_pop (TV_SYMOUT);
210 void
211 finish_optimization_passes (void)
213 enum tree_dump_index i;
214 struct dump_file_info *dfi;
215 char *name;
217 timevar_push (TV_DUMP);
218 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
220 dump_file = dump_begin (pass_profile.static_pass_number, NULL);
221 end_branch_prob ();
222 if (dump_file)
223 dump_end (pass_profile.static_pass_number, dump_file);
226 if (optimize > 0)
228 dump_file = dump_begin (pass_combine.static_pass_number, NULL);
229 if (dump_file)
231 dump_combine_total_stats (dump_file);
232 dump_end (pass_combine.static_pass_number, dump_file);
236 /* Do whatever is necessary to finish printing the graphs. */
237 if (graph_dump_format != no_graph)
238 for (i = TDI_end; (dfi = get_dump_file_info (i)) != NULL; ++i)
239 if (dump_initialized_p (i)
240 && (dfi->flags & TDF_GRAPH) != 0
241 && (name = get_dump_file_name (i)) != NULL)
243 finish_graph_dump_file (name);
244 free (name);
247 timevar_pop (TV_DUMP);
250 static bool
251 gate_rest_of_compilation (void)
253 /* Early return if there were errors. We can run afoul of our
254 consistency checks, and there's not really much point in fixing them. */
255 return !(rtl_dump_and_exit || flag_syntax_only || errorcount || sorrycount);
258 struct tree_opt_pass pass_rest_of_compilation =
260 NULL, /* name */
261 gate_rest_of_compilation, /* gate */
262 NULL, /* execute */
263 NULL, /* sub */
264 NULL, /* next */
265 0, /* static_pass_number */
266 TV_REST_OF_COMPILATION, /* tv_id */
267 PROP_rtl, /* properties_required */
268 0, /* properties_provided */
269 0, /* properties_destroyed */
270 0, /* todo_flags_start */
271 TODO_ggc_collect, /* todo_flags_finish */
272 0 /* letter */
275 static bool
276 gate_postreload (void)
278 return reload_completed;
281 struct tree_opt_pass pass_postreload =
283 NULL, /* name */
284 gate_postreload, /* gate */
285 NULL, /* execute */
286 NULL, /* sub */
287 NULL, /* next */
288 0, /* static_pass_number */
289 0, /* tv_id */
290 PROP_rtl, /* properties_required */
291 0, /* properties_provided */
292 0, /* properties_destroyed */
293 0, /* todo_flags_start */
294 TODO_ggc_collect, /* todo_flags_finish */
295 0 /* letter */
300 /* The root of the compilation pass tree, once constructed. */
301 struct tree_opt_pass *all_passes, *all_ipa_passes, *all_lowering_passes;
303 /* Iterate over the pass tree allocating dump file numbers. We want
304 to do this depth first, and independent of whether the pass is
305 enabled or not. */
307 static void
308 register_one_dump_file (struct tree_opt_pass *pass, bool ipa, int properties)
310 char *dot_name, *flag_name, *glob_name;
311 const char *prefix;
312 char num[10];
313 int flags;
315 /* See below in next_pass_1. */
316 num[0] = '\0';
317 if (pass->static_pass_number != -1)
318 sprintf (num, "%d", ((int) pass->static_pass_number < 0
319 ? 1 : pass->static_pass_number));
321 dot_name = concat (".", pass->name, num, NULL);
322 if (ipa)
323 prefix = "ipa-", flags = TDF_IPA;
324 else if (properties & PROP_trees)
325 prefix = "tree-", flags = TDF_TREE;
326 else
327 prefix = "rtl-", flags = TDF_RTL;
329 flag_name = concat (prefix, pass->name, num, NULL);
330 glob_name = concat (prefix, pass->name, NULL);
331 pass->static_pass_number = dump_register (dot_name, flag_name, glob_name,
332 flags, pass->letter);
335 /* Recursive worker function for register_dump_files. */
337 static int
338 register_dump_files_1 (struct tree_opt_pass *pass, bool ipa, int properties)
342 int new_properties = (properties | pass->properties_provided)
343 & ~pass->properties_destroyed;
345 if (pass->name)
346 register_one_dump_file (pass, ipa, new_properties);
348 if (pass->sub)
349 new_properties = register_dump_files_1 (pass->sub, false,
350 new_properties);
352 /* If we have a gate, combine the properties that we could have with
353 and without the pass being examined. */
354 if (pass->gate)
355 properties &= new_properties;
356 else
357 properties = new_properties;
359 pass = pass->next;
361 while (pass);
363 return properties;
366 /* Register the dump files for the pipeline starting at PASS. IPA is
367 true if the pass is inter-procedural, and PROPERTIES reflects the
368 properties that are guaranteed to be available at the beginning of
369 the pipeline. */
371 static void
372 register_dump_files (struct tree_opt_pass *pass, bool ipa, int properties)
374 pass->properties_required |= properties;
375 register_dump_files_1 (pass, ipa, properties);
378 /* Add a pass to the pass list. Duplicate the pass if it's already
379 in the list. */
381 static struct tree_opt_pass **
382 next_pass_1 (struct tree_opt_pass **list, struct tree_opt_pass *pass)
384 /* A nonzero static_pass_number indicates that the
385 pass is already in the list. */
386 if (pass->static_pass_number)
388 struct tree_opt_pass *new;
390 new = xmalloc (sizeof (*new));
391 memcpy (new, pass, sizeof (*new));
393 /* Indicate to register_dump_files that this pass has duplicates,
394 and so it should rename the dump file. The first instance will
395 be -1, and be number of duplicates = -static_pass_number - 1.
396 Subsequent instances will be > 0 and just the duplicate number. */
397 if (pass->name)
399 pass->static_pass_number -= 1;
400 new->static_pass_number = -pass->static_pass_number;
403 *list = new;
405 else
407 pass->static_pass_number = -1;
408 *list = pass;
411 return &(*list)->next;
415 /* Construct the pass tree. The sequencing of passes is driven by
416 the cgraph routines:
418 cgraph_finalize_compilation_unit ()
419 for each node N in the cgraph
420 cgraph_analyze_function (N)
421 cgraph_lower_function (N) -> all_lowering_passes
423 If we are optimizing, cgraph_optimize is then invoked:
425 cgraph_optimize ()
426 ipa_passes () -> all_ipa_passes
427 cgraph_expand_all_functions ()
428 for each node N in the cgraph
429 cgraph_expand_function (N)
430 cgraph_lower_function (N) -> Now a NOP.
431 lang_hooks.callgraph.expand_function (DECL (N))
432 tree_rest_of_compilation (DECL (N)) -> all_passes
435 void
436 init_optimization_passes (void)
438 struct tree_opt_pass **p;
440 #define NEXT_PASS(PASS) (p = next_pass_1 (p, &PASS))
442 /* Interprocedural optimization passes. */
443 p = &all_ipa_passes;
444 NEXT_PASS (pass_ipa_function_and_variable_visibility);
445 NEXT_PASS (pass_ipa_early_inline);
446 NEXT_PASS (pass_early_local_passes);
447 NEXT_PASS (pass_ipa_increase_alignment);
448 NEXT_PASS (pass_ipa_cp);
449 NEXT_PASS (pass_ipa_inline);
450 NEXT_PASS (pass_ipa_reference);
451 NEXT_PASS (pass_ipa_pure_const);
452 NEXT_PASS (pass_ipa_type_escape);
453 NEXT_PASS (pass_ipa_pta);
454 *p = NULL;
456 p = &pass_ipa_early_inline.sub;
457 NEXT_PASS (pass_early_inline);
458 NEXT_PASS (pass_inline_parameters);
459 NEXT_PASS (pass_rebuild_cgraph_edges);
460 *p = NULL;
462 /* All passes needed to lower the function into shape optimizers can
463 operate on. */
464 p = &all_lowering_passes;
465 NEXT_PASS (pass_remove_useless_stmts);
466 NEXT_PASS (pass_mudflap_1);
467 NEXT_PASS (pass_lower_omp);
468 NEXT_PASS (pass_lower_cf);
469 NEXT_PASS (pass_lower_eh);
470 NEXT_PASS (pass_build_cfg);
471 NEXT_PASS (pass_lower_complex_O0);
472 NEXT_PASS (pass_lower_vector);
473 NEXT_PASS (pass_warn_function_return);
474 NEXT_PASS (pass_build_cgraph_edges);
475 NEXT_PASS (pass_inline_parameters);
476 *p = NULL;
478 p = &pass_early_local_passes.sub;
479 NEXT_PASS (pass_tree_profile);
480 NEXT_PASS (pass_cleanup_cfg);
481 NEXT_PASS (pass_init_datastructures);
482 NEXT_PASS (pass_expand_omp);
483 NEXT_PASS (pass_all_early_optimizations);
484 NEXT_PASS (pass_rebuild_cgraph_edges);
485 NEXT_PASS (pass_inline_parameters);
486 *p = NULL;
488 p = &pass_all_early_optimizations.sub;
489 NEXT_PASS (pass_referenced_vars);
490 NEXT_PASS (pass_reset_cc_flags);
491 NEXT_PASS (pass_build_ssa);
492 NEXT_PASS (pass_early_warn_uninitialized);
493 NEXT_PASS (pass_rebuild_cgraph_edges);
494 NEXT_PASS (pass_early_inline);
495 NEXT_PASS (pass_cleanup_cfg);
496 NEXT_PASS (pass_rename_ssa_copies);
497 NEXT_PASS (pass_ccp);
499 NEXT_PASS (pass_forwprop);
500 NEXT_PASS (pass_sra);
501 NEXT_PASS (pass_copy_prop);
502 NEXT_PASS (pass_merge_phi);
503 NEXT_PASS (pass_dce);
504 NEXT_PASS (pass_tail_recursion);
505 NEXT_PASS (pass_release_ssa_names);
507 *p = NULL;
509 p = &all_passes;
510 NEXT_PASS (pass_apply_inline);
511 NEXT_PASS (pass_all_optimizations);
512 NEXT_PASS (pass_warn_function_noreturn);
513 NEXT_PASS (pass_free_datastructures);
514 NEXT_PASS (pass_mudflap_2);
515 NEXT_PASS (pass_free_cfg_annotations);
516 NEXT_PASS (pass_expand);
517 NEXT_PASS (pass_rest_of_compilation);
518 NEXT_PASS (pass_clean_state);
519 *p = NULL;
521 p = &pass_all_optimizations.sub;
522 NEXT_PASS (pass_create_structure_vars);
523 NEXT_PASS (pass_may_alias);
524 NEXT_PASS (pass_return_slot);
525 NEXT_PASS (pass_rename_ssa_copies);
527 /* Initial scalar cleanups. */
528 NEXT_PASS (pass_ccp);
529 NEXT_PASS (pass_fre);
530 NEXT_PASS (pass_dce);
531 NEXT_PASS (pass_forwprop);
532 NEXT_PASS (pass_copy_prop);
533 NEXT_PASS (pass_merge_phi);
534 NEXT_PASS (pass_vrp);
535 NEXT_PASS (pass_dce);
536 NEXT_PASS (pass_dominator);
538 /* The only const/copy propagation opportunities left after
539 DOM should be due to degenerate PHI nodes. So rather than
540 run the full propagators, run a specialized pass which
541 only examines PHIs to discover const/copy propagation
542 opportunities. */
543 NEXT_PASS (pass_phi_only_cprop);
545 NEXT_PASS (pass_phiopt);
546 NEXT_PASS (pass_may_alias);
547 NEXT_PASS (pass_tail_recursion);
548 NEXT_PASS (pass_profile);
549 NEXT_PASS (pass_ch);
550 NEXT_PASS (pass_stdarg);
551 NEXT_PASS (pass_lower_complex);
552 NEXT_PASS (pass_sra);
553 /* FIXME: SRA may generate arbitrary gimple code, exposing new
554 aliased and call-clobbered variables. As mentioned below,
555 pass_may_alias should be a TODO item. */
556 NEXT_PASS (pass_may_alias);
557 NEXT_PASS (pass_rename_ssa_copies);
558 NEXT_PASS (pass_dominator);
560 /* The only const/copy propagation opportunities left after
561 DOM should be due to degenerate PHI nodes. So rather than
562 run the full propagators, run a specialized pass which
563 only examines PHIs to discover const/copy propagation
564 opportunities. */
565 NEXT_PASS (pass_phi_only_cprop);
567 NEXT_PASS (pass_reassoc);
568 NEXT_PASS (pass_dce);
569 NEXT_PASS (pass_dse);
570 NEXT_PASS (pass_may_alias);
571 NEXT_PASS (pass_forwprop);
572 NEXT_PASS (pass_phiopt);
573 NEXT_PASS (pass_object_sizes);
574 NEXT_PASS (pass_store_ccp);
575 NEXT_PASS (pass_store_copy_prop);
576 NEXT_PASS (pass_fold_builtins);
577 NEXT_PASS (pass_cse_sincos);
578 /* FIXME: May alias should a TODO but for 4.0.0,
579 we add may_alias right after fold builtins
580 which can create arbitrary GIMPLE. */
581 NEXT_PASS (pass_may_alias);
582 NEXT_PASS (pass_split_crit_edges);
583 NEXT_PASS (pass_pre);
584 NEXT_PASS (pass_may_alias);
585 NEXT_PASS (pass_sink_code);
586 NEXT_PASS (pass_tree_loop);
587 NEXT_PASS (pass_cse_reciprocals);
588 NEXT_PASS (pass_reassoc);
589 NEXT_PASS (pass_vrp);
590 NEXT_PASS (pass_dominator);
592 /* The only const/copy propagation opportunities left after
593 DOM should be due to degenerate PHI nodes. So rather than
594 run the full propagators, run a specialized pass which
595 only examines PHIs to discover const/copy propagation
596 opportunities. */
597 NEXT_PASS (pass_phi_only_cprop);
599 NEXT_PASS (pass_cd_dce);
601 /* FIXME: If DCE is not run before checking for uninitialized uses,
602 we may get false warnings (e.g., testsuite/gcc.dg/uninit-5.c).
603 However, this also causes us to misdiagnose cases that should be
604 real warnings (e.g., testsuite/gcc.dg/pr18501.c).
606 To fix the false positives in uninit-5.c, we would have to
607 account for the predicates protecting the set and the use of each
608 variable. Using a representation like Gated Single Assignment
609 may help. */
610 NEXT_PASS (pass_late_warn_uninitialized);
611 NEXT_PASS (pass_dse);
612 NEXT_PASS (pass_forwprop);
613 NEXT_PASS (pass_phiopt);
614 NEXT_PASS (pass_tail_calls);
615 NEXT_PASS (pass_rename_ssa_copies);
616 NEXT_PASS (pass_uncprop);
617 NEXT_PASS (pass_del_ssa);
618 NEXT_PASS (pass_nrv);
619 NEXT_PASS (pass_mark_used_blocks);
620 NEXT_PASS (pass_cleanup_cfg_post_optimizing);
621 *p = NULL;
623 p = &pass_tree_loop.sub;
624 NEXT_PASS (pass_tree_loop_init);
625 NEXT_PASS (pass_copy_prop);
626 NEXT_PASS (pass_lim);
627 NEXT_PASS (pass_tree_unswitch);
628 NEXT_PASS (pass_scev_cprop);
629 NEXT_PASS (pass_empty_loop);
630 NEXT_PASS (pass_record_bounds);
631 NEXT_PASS (pass_linear_transform);
632 NEXT_PASS (pass_iv_canon);
633 NEXT_PASS (pass_if_conversion);
634 NEXT_PASS (pass_vectorize);
635 /* NEXT_PASS (pass_may_alias) cannot be done again because the
636 vectorizer creates alias relations that are not supported by
637 pass_may_alias. */
638 NEXT_PASS (pass_complete_unroll);
639 NEXT_PASS (pass_loop_prefetch);
640 NEXT_PASS (pass_iv_optimize);
641 NEXT_PASS (pass_tree_loop_done);
642 *p = NULL;
644 p = &pass_vectorize.sub;
645 NEXT_PASS (pass_lower_vector_ssa);
646 NEXT_PASS (pass_dce_loop);
647 *p = NULL;
649 p = &pass_loop2.sub;
650 NEXT_PASS (pass_rtl_loop_init);
651 NEXT_PASS (pass_rtl_move_loop_invariants);
652 NEXT_PASS (pass_rtl_unswitch);
653 NEXT_PASS (pass_rtl_unroll_and_peel_loops);
654 NEXT_PASS (pass_rtl_doloop);
655 NEXT_PASS (pass_rtl_loop_done);
656 *p = NULL;
658 p = &pass_rest_of_compilation.sub;
659 NEXT_PASS (pass_init_function);
660 NEXT_PASS (pass_jump);
661 NEXT_PASS (pass_insn_locators_initialize);
662 NEXT_PASS (pass_rtl_eh);
663 NEXT_PASS (pass_initial_value_sets);
664 NEXT_PASS (pass_unshare_all_rtl);
665 NEXT_PASS (pass_instantiate_virtual_regs);
666 NEXT_PASS (pass_jump2);
667 NEXT_PASS (pass_lower_subreg);
668 NEXT_PASS (pass_cse);
669 NEXT_PASS (pass_rtl_fwprop);
670 NEXT_PASS (pass_gcse);
671 NEXT_PASS (pass_jump_bypass);
672 NEXT_PASS (pass_rtl_ifcvt);
673 NEXT_PASS (pass_tracer);
674 /* Perform loop optimizations. It might be better to do them a bit
675 sooner, but we want the profile feedback to work more
676 efficiently. */
677 NEXT_PASS (pass_loop2);
678 NEXT_PASS (pass_web);
679 NEXT_PASS (pass_cse2);
680 NEXT_PASS (pass_rtl_fwprop_addr);
681 NEXT_PASS (pass_life);
682 NEXT_PASS (pass_combine);
683 NEXT_PASS (pass_if_after_combine);
684 NEXT_PASS (pass_partition_blocks);
685 NEXT_PASS (pass_regmove);
686 NEXT_PASS (pass_split_all_insns);
687 NEXT_PASS (pass_lower_subreg2);
688 NEXT_PASS (pass_mode_switching);
689 NEXT_PASS (pass_see);
690 NEXT_PASS (pass_recompute_reg_usage);
691 NEXT_PASS (pass_sms);
692 NEXT_PASS (pass_sched);
693 NEXT_PASS (pass_local_alloc);
694 NEXT_PASS (pass_global_alloc);
695 NEXT_PASS (pass_postreload);
696 *p = NULL;
698 p = &pass_postreload.sub;
699 NEXT_PASS (pass_postreload_cse);
700 NEXT_PASS (pass_gcse2);
701 NEXT_PASS (pass_flow2);
702 NEXT_PASS (pass_rtl_seqabstr);
703 NEXT_PASS (pass_stack_adjustments);
704 NEXT_PASS (pass_peephole2);
705 NEXT_PASS (pass_if_after_reload);
706 NEXT_PASS (pass_regrename);
707 NEXT_PASS (pass_reorder_blocks);
708 NEXT_PASS (pass_branch_target_load_optimize);
709 NEXT_PASS (pass_leaf_regs);
710 NEXT_PASS (pass_sched2);
711 NEXT_PASS (pass_split_before_regstack);
712 NEXT_PASS (pass_stack_regs);
713 NEXT_PASS (pass_compute_alignments);
714 NEXT_PASS (pass_duplicate_computed_gotos);
715 NEXT_PASS (pass_variable_tracking);
716 NEXT_PASS (pass_free_cfg);
717 NEXT_PASS (pass_machine_reorg);
718 NEXT_PASS (pass_cleanup_barriers);
719 NEXT_PASS (pass_delay_slots);
720 NEXT_PASS (pass_split_for_shorten_branches);
721 NEXT_PASS (pass_convert_to_eh_region_ranges);
722 NEXT_PASS (pass_shorten_branches);
723 NEXT_PASS (pass_set_nothrow_function_flags);
724 NEXT_PASS (pass_final);
725 *p = NULL;
727 #undef NEXT_PASS
729 /* Register the passes with the tree dump code. */
730 register_dump_files (all_lowering_passes, false, PROP_gimple_any);
731 all_lowering_passes->todo_flags_start |= TODO_set_props;
732 register_dump_files (all_ipa_passes, true,
733 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
734 | PROP_cfg);
735 register_dump_files (all_passes, false,
736 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
737 | PROP_cfg);
740 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
741 function CALLBACK for every function in the call graph. Otherwise,
742 call CALLBACK on the current function. */
744 static void
745 do_per_function (void (*callback) (void *data), void *data)
747 if (current_function_decl)
748 callback (data);
749 else
751 struct cgraph_node *node;
752 for (node = cgraph_nodes; node; node = node->next)
753 if (node->analyzed)
755 push_cfun (DECL_STRUCT_FUNCTION (node->decl));
756 current_function_decl = node->decl;
757 callback (data);
758 free_dominance_info (CDI_DOMINATORS);
759 free_dominance_info (CDI_POST_DOMINATORS);
760 current_function_decl = NULL;
761 pop_cfun ();
762 ggc_collect ();
767 /* Because inlining might remove no-longer reachable nodes, we need to
768 keep the array visible to garbage collector to avoid reading collected
769 out nodes. */
770 static int nnodes;
771 static GTY ((length ("nnodes"))) struct cgraph_node **order;
773 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
774 function CALLBACK for every function in the call graph. Otherwise,
775 call CALLBACK on the current function. */
777 static void
778 do_per_function_toporder (void (*callback) (void *data), void *data)
780 int i;
782 if (current_function_decl)
783 callback (data);
784 else
786 gcc_assert (!order);
787 order = ggc_alloc (sizeof (*order) * cgraph_n_nodes);
788 nnodes = cgraph_postorder (order);
789 for (i = nnodes - 1; i >= 0; i--)
791 struct cgraph_node *node = order[i];
793 /* Allow possibly removed nodes to be garbage collected. */
794 order[i] = NULL;
795 if (node->analyzed && (node->needed || node->reachable))
797 push_cfun (DECL_STRUCT_FUNCTION (node->decl));
798 current_function_decl = node->decl;
799 callback (data);
800 free_dominance_info (CDI_DOMINATORS);
801 free_dominance_info (CDI_POST_DOMINATORS);
802 current_function_decl = NULL;
803 pop_cfun ();
804 ggc_collect ();
808 ggc_free (order);
809 order = NULL;
810 nnodes = 0;
813 /* Perform all TODO actions that ought to be done on each function. */
815 static void
816 execute_function_todo (void *data)
818 unsigned int flags = (size_t)data;
819 if (cfun->curr_properties & PROP_ssa)
820 flags |= TODO_verify_ssa;
821 flags &= ~cfun->last_verified;
822 if (!flags)
823 return;
825 /* Always cleanup the CFG before trying to update SSA. */
826 if (flags & TODO_cleanup_cfg)
828 bool cleanup;
830 if (current_loops)
831 cleanup = cleanup_tree_cfg_loop ();
832 else
833 cleanup = cleanup_tree_cfg ();
835 if (cleanup && (cfun->curr_properties & PROP_ssa))
836 flags |= TODO_remove_unused_locals;
838 /* When cleanup_tree_cfg merges consecutive blocks, it may
839 perform some simplistic propagation when removing single
840 valued PHI nodes. This propagation may, in turn, cause the
841 SSA form to become out-of-date (see PR 22037). So, even
842 if the parent pass had not scheduled an SSA update, we may
843 still need to do one. */
844 if (!(flags & TODO_update_ssa_any) && need_ssa_update_p ())
845 flags |= TODO_update_ssa;
848 if (flags & TODO_update_ssa_any)
850 unsigned update_flags = flags & TODO_update_ssa_any;
851 update_ssa (update_flags);
852 cfun->last_verified &= ~TODO_verify_ssa;
855 if (flags & TODO_remove_unused_locals)
856 remove_unused_locals ();
858 if ((flags & TODO_dump_func)
859 && dump_file && current_function_decl)
861 if (cfun->curr_properties & PROP_trees)
862 dump_function_to_file (current_function_decl,
863 dump_file, dump_flags);
864 else
866 if (dump_flags & TDF_SLIM)
867 print_rtl_slim_with_bb (dump_file, get_insns (), dump_flags);
868 else if ((cfun->curr_properties & PROP_cfg)
869 && (dump_flags & TDF_BLOCKS))
870 print_rtl_with_bb (dump_file, get_insns ());
871 else
872 print_rtl (dump_file, get_insns ());
874 if (cfun->curr_properties & PROP_cfg
875 && graph_dump_format != no_graph
876 && (dump_flags & TDF_GRAPH))
877 print_rtl_graph_with_bb (dump_file_name, get_insns ());
880 /* Flush the file. If verification fails, we won't be able to
881 close the file before aborting. */
882 fflush (dump_file);
885 #if defined ENABLE_CHECKING
886 if (flags & TODO_verify_ssa)
887 verify_ssa (true);
888 if (flags & TODO_verify_flow)
889 verify_flow_info ();
890 if (flags & TODO_verify_stmts)
891 verify_stmts ();
892 if (flags & TODO_verify_loops)
893 verify_loop_closed_ssa ();
894 #endif
896 cfun->last_verified = flags & TODO_verify_all;
899 /* Perform all TODO actions. */
900 static void
901 execute_todo (unsigned int flags)
903 #if defined ENABLE_CHECKING
904 if (need_ssa_update_p ())
905 gcc_assert (flags & TODO_update_ssa_any);
906 #endif
908 do_per_function (execute_function_todo, (void *)(size_t) flags);
910 /* Always remove functions just as before inlining: IPA passes might be
911 interested to see bodies of extern inline functions that are not inlined
912 to analyze side effects. The full removal is done just at the end
913 of IPA pass queue. */
914 if (flags & TODO_remove_functions)
915 cgraph_remove_unreachable_nodes (true, dump_file);
917 if ((flags & TODO_dump_cgraph)
918 && dump_file && !current_function_decl)
920 dump_cgraph (dump_file);
921 /* Flush the file. If verification fails, we won't be able to
922 close the file before aborting. */
923 fflush (dump_file);
926 if (flags & TODO_ggc_collect)
928 ggc_collect ();
932 /* Clear the last verified flag. */
934 static void
935 clear_last_verified (void *data ATTRIBUTE_UNUSED)
937 cfun->last_verified = 0;
940 /* Helper function. Verify that the properties has been turn into the
941 properties expected by the pass. */
943 #ifdef ENABLE_CHECKING
944 static void
945 verify_curr_properties (void *data)
947 unsigned int props = (size_t)data;
948 gcc_assert ((cfun->curr_properties & props) == props);
950 #endif
952 /* After executing the pass, apply expected changes to the function
953 properties. */
954 static void
955 update_properties_after_pass (void *data)
957 struct tree_opt_pass *pass = data;
958 cfun->curr_properties = (cfun->curr_properties | pass->properties_provided)
959 & ~pass->properties_destroyed;
962 static bool
963 execute_one_pass (struct tree_opt_pass *pass)
965 bool initializing_dump;
966 unsigned int todo_after = 0;
968 /* See if we're supposed to run this pass. */
969 if (pass->gate && !pass->gate ())
970 return false;
972 if (!quiet_flag && !cfun)
973 fprintf (stderr, " <%s>", pass->name ? pass->name : "");
975 if (pass->todo_flags_start & TODO_set_props)
976 cfun->curr_properties = pass->properties_required;
978 /* Note that the folders should only create gimple expressions.
979 This is a hack until the new folder is ready. */
980 in_gimple_form = (cfun && (cfun->curr_properties & PROP_trees)) != 0;
982 /* Run pre-pass verification. */
983 execute_todo (pass->todo_flags_start);
985 #ifdef ENABLE_CHECKING
986 do_per_function (verify_curr_properties,
987 (void *)(size_t)pass->properties_required);
988 #endif
990 /* If a dump file name is present, open it if enabled. */
991 if (pass->static_pass_number != -1)
993 initializing_dump = !dump_initialized_p (pass->static_pass_number);
994 dump_file_name = get_dump_file_name (pass->static_pass_number);
995 dump_file = dump_begin (pass->static_pass_number, &dump_flags);
996 if (dump_file && current_function_decl)
998 const char *dname, *aname;
999 dname = lang_hooks.decl_printable_name (current_function_decl, 2);
1000 aname = (IDENTIFIER_POINTER
1001 (DECL_ASSEMBLER_NAME (current_function_decl)));
1002 fprintf (dump_file, "\n;; Function %s (%s)%s\n\n", dname, aname,
1003 cfun->function_frequency == FUNCTION_FREQUENCY_HOT
1004 ? " (hot)"
1005 : cfun->function_frequency == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED
1006 ? " (unlikely executed)"
1007 : "");
1010 else
1011 initializing_dump = false;
1013 /* If a timevar is present, start it. */
1014 if (pass->tv_id)
1015 timevar_push (pass->tv_id);
1017 /* Do it! */
1018 if (pass->execute)
1020 todo_after = pass->execute ();
1021 do_per_function (clear_last_verified, NULL);
1024 /* Stop timevar. */
1025 if (pass->tv_id)
1026 timevar_pop (pass->tv_id);
1028 do_per_function (update_properties_after_pass, pass);
1030 if (initializing_dump
1031 && dump_file
1032 && graph_dump_format != no_graph
1033 && (cfun->curr_properties & (PROP_cfg | PROP_rtl))
1034 == (PROP_cfg | PROP_rtl))
1036 get_dump_file_info (pass->static_pass_number)->flags |= TDF_GRAPH;
1037 dump_flags |= TDF_GRAPH;
1038 clean_graph_dump_file (dump_file_name);
1041 /* Run post-pass cleanup and verification. */
1042 execute_todo (todo_after | pass->todo_flags_finish);
1044 if (!current_function_decl)
1045 cgraph_process_new_functions ();
1047 /* Flush and close dump file. */
1048 if (dump_file_name)
1050 free ((char *) dump_file_name);
1051 dump_file_name = NULL;
1054 if (dump_file)
1056 dump_end (pass->static_pass_number, dump_file);
1057 dump_file = NULL;
1060 /* Reset in_gimple_form to not break non-unit-at-a-time mode. */
1061 in_gimple_form = false;
1063 return true;
1066 void
1067 execute_pass_list (struct tree_opt_pass *pass)
1071 if (execute_one_pass (pass) && pass->sub)
1072 execute_pass_list (pass->sub);
1073 pass = pass->next;
1075 while (pass);
1078 /* Same as execute_pass_list but assume that subpasses of IPA passes
1079 are local passes. */
1080 void
1081 execute_ipa_pass_list (struct tree_opt_pass *pass)
1085 gcc_assert (!current_function_decl);
1086 gcc_assert (!cfun);
1087 if (execute_one_pass (pass) && pass->sub)
1088 do_per_function_toporder ((void (*)(void *))execute_pass_list,
1089 pass->sub);
1090 if (!current_function_decl)
1091 cgraph_process_new_functions ();
1092 pass = pass->next;
1094 while (pass);
1096 #include "gt-passes.h"