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
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
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
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. */
29 #undef FLOAT /* This is for hpux. They should change hpux. */
30 #undef FFS /* Some systems define this in param.h. */
32 #include "coretypes.h"
36 #ifdef HAVE_SYS_RESOURCE_H
37 # include <sys/resource.h>
40 #ifdef HAVE_SYS_TIMES_H
41 # include <sys/times.h>
50 #include "insn-attr.h"
51 #include "insn-config.h"
52 #include "insn-flags.h"
53 #include "hard-reg-set.h"
60 #include "basic-block.h"
66 #include "diagnostic.h"
69 #include "dwarf2asm.h"
70 #include "integrate.h"
74 #include "langhooks.h"
75 #include "cfglayout.h"
77 #include "hosthooks.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"
88 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
89 #include "dwarf2out.h"
92 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
96 #ifdef SDB_DEBUGGING_INFO
100 #ifdef XCOFF_DEBUGGING_INFO
101 #include "xcoffout.h" /* Needed for external data
102 declarations for e.g. AIX 4.x. */
105 /* Global variables used to communicate with passes. */
108 bool first_pass_instance;
111 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
114 This does nothing for local (non-static) variables, unless the
115 variable is a register variable with DECL_ASSEMBLER_NAME set. In
116 that case, or if the variable is not an automatic, it sets up the
117 RTL and outputs any assembler code (label definition, storage
118 allocation and initialization).
120 DECL is the declaration. TOP_LEVEL is nonzero
121 if this declaration is not within a function. */
124 rest_of_decl_compilation (tree decl,
128 /* We deferred calling assemble_alias so that we could collect
129 other attributes such as visibility. Emit the alias now. */
132 alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
135 alias = TREE_VALUE (TREE_VALUE (alias));
136 alias = get_identifier (TREE_STRING_POINTER (alias));
137 assemble_alias (decl, alias);
141 /* Can't defer this, because it needs to happen before any
142 later function definitions are processed. */
143 if (DECL_ASSEMBLER_NAME_SET_P (decl) && DECL_REGISTER (decl))
144 make_decl_rtl (decl);
146 /* Forward declarations for nested functions are not "external",
147 but we need to treat them as if they were. */
148 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
149 || TREE_CODE (decl) == FUNCTION_DECL)
151 timevar_push (TV_VARCONST);
153 /* Don't output anything when a tentative file-scope definition
154 is seen. But at end of compilation, do output code for them.
156 We do output all variables when unit-at-a-time is active and rely on
157 callgraph code to defer them except for forward declarations
158 (see gcc.c-torture/compile/920624-1.c) */
160 || !DECL_DEFER_OUTPUT (decl)
161 || DECL_INITIAL (decl))
162 && !DECL_EXTERNAL (decl))
164 if (TREE_CODE (decl) != FUNCTION_DECL)
165 varpool_finalize_decl (decl);
167 assemble_variable (decl, top_level, at_end, 0);
170 #ifdef ASM_FINISH_DECLARE_OBJECT
171 if (decl == last_assemble_variable_decl)
173 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
178 timevar_pop (TV_VARCONST);
180 else if (TREE_CODE (decl) == TYPE_DECL
181 /* Like in rest_of_type_compilation, avoid confusing the debug
182 information machinery when there are errors. */
183 && !(sorrycount || errorcount))
185 timevar_push (TV_SYMOUT);
186 debug_hooks->type_decl (decl, !top_level);
187 timevar_pop (TV_SYMOUT);
190 /* Let cgraph know about the existence of variables. */
191 if (TREE_CODE (decl) == VAR_DECL && !DECL_EXTERNAL (decl))
195 /* Called after finishing a record, union or enumeral type. */
198 rest_of_type_compilation (tree type, int toplev)
200 /* Avoid confusing the debug information machinery when there are
202 if (errorcount != 0 || sorrycount != 0)
205 timevar_push (TV_SYMOUT);
206 debug_hooks->type_decl (TYPE_STUB_DECL (type), !toplev);
207 timevar_pop (TV_SYMOUT);
213 finish_optimization_passes (void)
215 enum tree_dump_index i;
216 struct dump_file_info *dfi;
219 timevar_push (TV_DUMP);
220 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
222 dump_file = dump_begin (pass_profile.static_pass_number, NULL);
225 dump_end (pass_profile.static_pass_number, dump_file);
230 dump_file = dump_begin (pass_combine.static_pass_number, NULL);
233 dump_combine_total_stats (dump_file);
234 dump_end (pass_combine.static_pass_number, dump_file);
238 /* Do whatever is necessary to finish printing the graphs. */
239 if (graph_dump_format != no_graph)
240 for (i = TDI_end; (dfi = get_dump_file_info (i)) != NULL; ++i)
241 if (dump_initialized_p (i)
242 && (dfi->flags & TDF_GRAPH) != 0
243 && (name = get_dump_file_name (i)) != NULL)
245 finish_graph_dump_file (name);
249 timevar_pop (TV_DUMP);
253 gate_rest_of_compilation (void)
255 /* Early return if there were errors. We can run afoul of our
256 consistency checks, and there's not really much point in fixing them. */
257 return !(rtl_dump_and_exit || flag_syntax_only || errorcount || sorrycount);
260 struct tree_opt_pass pass_rest_of_compilation =
263 gate_rest_of_compilation, /* gate */
267 0, /* static_pass_number */
268 TV_REST_OF_COMPILATION, /* tv_id */
269 PROP_rtl, /* properties_required */
270 0, /* properties_provided */
271 0, /* properties_destroyed */
272 0, /* todo_flags_start */
273 TODO_ggc_collect, /* todo_flags_finish */
278 gate_postreload (void)
280 return reload_completed;
283 struct tree_opt_pass pass_postreload =
286 gate_postreload, /* gate */
290 0, /* static_pass_number */
292 PROP_rtl, /* properties_required */
293 0, /* properties_provided */
294 0, /* properties_destroyed */
295 0, /* todo_flags_start */
296 TODO_ggc_collect, /* todo_flags_finish */
302 /* The root of the compilation pass tree, once constructed. */
303 struct tree_opt_pass *all_passes, *all_ipa_passes, *all_lowering_passes;
305 /* Iterate over the pass tree allocating dump file numbers. We want
306 to do this depth first, and independent of whether the pass is
310 register_one_dump_file (struct tree_opt_pass *pass, bool ipa, int properties)
312 char *dot_name, *flag_name, *glob_name;
317 /* See below in next_pass_1. */
319 if (pass->static_pass_number != -1)
320 sprintf (num, "%d", ((int) pass->static_pass_number < 0
321 ? 1 : pass->static_pass_number));
323 dot_name = concat (".", pass->name, num, NULL);
325 prefix = "ipa-", flags = TDF_IPA;
326 else if (properties & PROP_trees)
327 prefix = "tree-", flags = TDF_TREE;
329 prefix = "rtl-", flags = TDF_RTL;
331 flag_name = concat (prefix, pass->name, num, NULL);
332 glob_name = concat (prefix, pass->name, NULL);
333 pass->static_pass_number = dump_register (dot_name, flag_name, glob_name,
334 flags, pass->letter);
337 /* Recursive worker function for register_dump_files. */
340 register_dump_files_1 (struct tree_opt_pass *pass, bool ipa, int properties)
344 int new_properties = (properties | pass->properties_provided)
345 & ~pass->properties_destroyed;
348 register_one_dump_file (pass, ipa, new_properties);
351 new_properties = register_dump_files_1 (pass->sub, false,
354 /* If we have a gate, combine the properties that we could have with
355 and without the pass being examined. */
357 properties &= new_properties;
359 properties = new_properties;
368 /* Register the dump files for the pipeline starting at PASS. IPA is
369 true if the pass is inter-procedural, and PROPERTIES reflects the
370 properties that are guaranteed to be available at the beginning of
374 register_dump_files (struct tree_opt_pass *pass, bool ipa, int properties)
376 pass->properties_required |= properties;
377 register_dump_files_1 (pass, ipa, properties);
380 /* Add a pass to the pass list. Duplicate the pass if it's already
383 static struct tree_opt_pass **
384 next_pass_1 (struct tree_opt_pass **list, struct tree_opt_pass *pass)
386 /* A nonzero static_pass_number indicates that the
387 pass is already in the list. */
388 if (pass->static_pass_number)
390 struct tree_opt_pass *new;
392 new = xmalloc (sizeof (*new));
393 memcpy (new, pass, sizeof (*new));
396 new->todo_flags_start &= ~TODO_mark_first_instance;
398 /* Indicate to register_dump_files that this pass has duplicates,
399 and so it should rename the dump file. The first instance will
400 be -1, and be number of duplicates = -static_pass_number - 1.
401 Subsequent instances will be > 0 and just the duplicate number. */
404 pass->static_pass_number -= 1;
405 new->static_pass_number = -pass->static_pass_number;
412 pass->todo_flags_start |= TODO_mark_first_instance;
413 pass->static_pass_number = -1;
417 return &(*list)->next;
421 /* Construct the pass tree. The sequencing of passes is driven by
424 cgraph_finalize_compilation_unit ()
425 for each node N in the cgraph
426 cgraph_analyze_function (N)
427 cgraph_lower_function (N) -> all_lowering_passes
429 If we are optimizing, cgraph_optimize is then invoked:
432 ipa_passes () -> all_ipa_passes
433 cgraph_expand_all_functions ()
434 for each node N in the cgraph
435 cgraph_expand_function (N)
436 lang_hooks.callgraph.expand_function (DECL (N))
437 tree_rest_of_compilation (DECL (N)) -> all_passes
441 init_optimization_passes (void)
443 struct tree_opt_pass **p;
445 #define NEXT_PASS(PASS) (p = next_pass_1 (p, &PASS))
447 /* All passes needed to lower the function into shape optimizers can
448 operate on. These passes are always run first on the function, but
449 backend might produce already lowered functions that are not processed
451 p = &all_lowering_passes;
452 NEXT_PASS (pass_remove_useless_stmts);
453 NEXT_PASS (pass_mudflap_1);
454 NEXT_PASS (pass_lower_omp);
455 NEXT_PASS (pass_lower_cf);
456 NEXT_PASS (pass_lower_eh);
457 NEXT_PASS (pass_build_cfg);
458 NEXT_PASS (pass_lower_complex_O0);
459 NEXT_PASS (pass_lower_vector);
460 NEXT_PASS (pass_warn_function_return);
461 NEXT_PASS (pass_build_cgraph_edges);
462 NEXT_PASS (pass_inline_parameters);
465 /* Interprocedural optimization passes.
466 All these passes are ignored in -fno-unit-at-a-time
467 except for subpasses of early_local_passes. */
469 NEXT_PASS (pass_ipa_function_and_variable_visibility);
470 NEXT_PASS (pass_ipa_early_inline);
472 struct tree_opt_pass **p = &pass_ipa_early_inline.sub;
473 NEXT_PASS (pass_early_inline);
474 NEXT_PASS (pass_inline_parameters);
475 NEXT_PASS (pass_rebuild_cgraph_edges);
477 NEXT_PASS (pass_early_local_passes);
479 struct tree_opt_pass **p = &pass_early_local_passes.sub;
480 NEXT_PASS (pass_tree_profile);
481 NEXT_PASS (pass_cleanup_cfg);
482 NEXT_PASS (pass_init_datastructures);
483 NEXT_PASS (pass_expand_omp);
484 NEXT_PASS (pass_all_early_optimizations);
486 struct tree_opt_pass **p = &pass_all_early_optimizations.sub;
487 NEXT_PASS (pass_referenced_vars);
488 NEXT_PASS (pass_reset_cc_flags);
489 NEXT_PASS (pass_build_ssa);
490 NEXT_PASS (pass_early_warn_uninitialized);
491 NEXT_PASS (pass_rebuild_cgraph_edges);
492 NEXT_PASS (pass_early_inline);
493 NEXT_PASS (pass_cleanup_cfg);
494 NEXT_PASS (pass_rename_ssa_copies);
495 NEXT_PASS (pass_ccp);
496 NEXT_PASS (pass_forwprop);
497 NEXT_PASS (pass_sra_early);
498 NEXT_PASS (pass_copy_prop);
499 NEXT_PASS (pass_merge_phi);
500 NEXT_PASS (pass_dce);
501 NEXT_PASS (pass_tail_recursion);
502 NEXT_PASS (pass_profile);
503 NEXT_PASS (pass_release_ssa_names);
505 NEXT_PASS (pass_rebuild_cgraph_edges);
506 NEXT_PASS (pass_inline_parameters);
508 NEXT_PASS (pass_ipa_increase_alignment);
509 NEXT_PASS (pass_ipa_cp);
510 NEXT_PASS (pass_ipa_inline);
511 NEXT_PASS (pass_ipa_reference);
512 NEXT_PASS (pass_ipa_pure_const);
513 NEXT_PASS (pass_ipa_type_escape);
514 NEXT_PASS (pass_ipa_pta);
517 /* These passes are run after IPA passes on every function that is being
518 output to the assembler file. */
520 NEXT_PASS (pass_apply_inline);
521 NEXT_PASS (pass_all_optimizations);
523 struct tree_opt_pass **p = &pass_all_optimizations.sub;
524 NEXT_PASS (pass_create_structure_vars);
525 NEXT_PASS (pass_may_alias);
526 NEXT_PASS (pass_return_slot);
527 NEXT_PASS (pass_rename_ssa_copies);
529 /* Initial scalar cleanups. */
530 NEXT_PASS (pass_ccp);
531 NEXT_PASS (pass_phiprop);
532 NEXT_PASS (pass_fre);
533 NEXT_PASS (pass_dce);
534 NEXT_PASS (pass_forwprop);
535 NEXT_PASS (pass_copy_prop);
536 NEXT_PASS (pass_merge_phi);
537 NEXT_PASS (pass_vrp);
538 NEXT_PASS (pass_dce);
539 NEXT_PASS (pass_dominator);
541 /* The only const/copy propagation opportunities left after
542 DOM should be due to degenerate PHI nodes. So rather than
543 run the full propagators, run a specialized pass which
544 only examines PHIs to discover const/copy propagation
546 NEXT_PASS (pass_phi_only_cprop);
548 NEXT_PASS (pass_phiopt);
549 NEXT_PASS (pass_may_alias);
550 NEXT_PASS (pass_tail_recursion);
552 NEXT_PASS (pass_stdarg);
553 NEXT_PASS (pass_lower_complex);
554 NEXT_PASS (pass_sra);
555 /* FIXME: SRA may generate arbitrary gimple code, exposing new
556 aliased and call-clobbered variables. As mentioned below,
557 pass_may_alias should be a TODO item. */
558 NEXT_PASS (pass_may_alias);
559 NEXT_PASS (pass_rename_ssa_copies);
560 NEXT_PASS (pass_dominator);
562 /* The only const/copy propagation opportunities left after
563 DOM should be due to degenerate PHI nodes. So rather than
564 run the full propagators, run a specialized pass which
565 only examines PHIs to discover const/copy propagation
567 NEXT_PASS (pass_phi_only_cprop);
569 NEXT_PASS (pass_reassoc);
570 NEXT_PASS (pass_dce);
571 NEXT_PASS (pass_dse);
572 NEXT_PASS (pass_may_alias);
573 NEXT_PASS (pass_forwprop);
574 NEXT_PASS (pass_phiopt);
575 NEXT_PASS (pass_object_sizes);
576 NEXT_PASS (pass_store_ccp);
577 NEXT_PASS (pass_store_copy_prop);
578 NEXT_PASS (pass_fold_builtins);
579 NEXT_PASS (pass_cse_sincos);
580 /* FIXME: May alias should a TODO but for 4.0.0,
581 we add may_alias right after fold builtins
582 which can create arbitrary GIMPLE. */
583 NEXT_PASS (pass_may_alias);
584 NEXT_PASS (pass_split_crit_edges);
585 NEXT_PASS (pass_pre);
586 NEXT_PASS (pass_may_alias);
587 NEXT_PASS (pass_sink_code);
588 NEXT_PASS (pass_tree_loop);
590 struct tree_opt_pass **p = &pass_tree_loop.sub;
591 NEXT_PASS (pass_tree_loop_init);
592 NEXT_PASS (pass_copy_prop);
593 NEXT_PASS (pass_lim);
594 NEXT_PASS (pass_tree_unswitch);
595 NEXT_PASS (pass_scev_cprop);
596 NEXT_PASS (pass_empty_loop);
597 NEXT_PASS (pass_record_bounds);
598 NEXT_PASS (pass_check_data_deps);
599 NEXT_PASS (pass_linear_transform);
600 NEXT_PASS (pass_iv_canon);
601 NEXT_PASS (pass_if_conversion);
602 NEXT_PASS (pass_vectorize);
604 struct tree_opt_pass **p = &pass_vectorize.sub;
605 NEXT_PASS (pass_lower_vector_ssa);
606 NEXT_PASS (pass_dce_loop);
608 /* NEXT_PASS (pass_may_alias) cannot be done again because the
609 vectorizer creates alias relations that are not supported by
611 NEXT_PASS (pass_complete_unroll);
612 NEXT_PASS (pass_loop_prefetch);
613 NEXT_PASS (pass_iv_optimize);
614 NEXT_PASS (pass_tree_loop_done);
616 NEXT_PASS (pass_cse_reciprocals);
617 NEXT_PASS (pass_reassoc);
618 NEXT_PASS (pass_vrp);
619 NEXT_PASS (pass_dominator);
621 /* The only const/copy propagation opportunities left after
622 DOM should be due to degenerate PHI nodes. So rather than
623 run the full propagators, run a specialized pass which
624 only examines PHIs to discover const/copy propagation
626 NEXT_PASS (pass_phi_only_cprop);
628 NEXT_PASS (pass_cd_dce);
630 /* FIXME: If DCE is not run before checking for uninitialized uses,
631 we may get false warnings (e.g., testsuite/gcc.dg/uninit-5.c).
632 However, this also causes us to misdiagnose cases that should be
633 real warnings (e.g., testsuite/gcc.dg/pr18501.c).
635 To fix the false positives in uninit-5.c, we would have to
636 account for the predicates protecting the set and the use of each
637 variable. Using a representation like Gated Single Assignment
639 NEXT_PASS (pass_late_warn_uninitialized);
640 NEXT_PASS (pass_dse);
641 NEXT_PASS (pass_forwprop);
642 NEXT_PASS (pass_phiopt);
643 NEXT_PASS (pass_tail_calls);
644 NEXT_PASS (pass_rename_ssa_copies);
645 NEXT_PASS (pass_uncprop);
646 NEXT_PASS (pass_del_ssa);
647 NEXT_PASS (pass_nrv);
648 NEXT_PASS (pass_mark_used_blocks);
649 NEXT_PASS (pass_cleanup_cfg_post_optimizing);
651 NEXT_PASS (pass_warn_function_noreturn);
652 NEXT_PASS (pass_free_datastructures);
653 NEXT_PASS (pass_mudflap_2);
654 NEXT_PASS (pass_free_cfg_annotations);
655 NEXT_PASS (pass_expand);
656 NEXT_PASS (pass_rest_of_compilation);
658 struct tree_opt_pass **p = &pass_rest_of_compilation.sub;
659 NEXT_PASS (pass_init_function);
660 NEXT_PASS (pass_jump);
661 NEXT_PASS (pass_rtl_eh);
662 NEXT_PASS (pass_initial_value_sets);
663 NEXT_PASS (pass_unshare_all_rtl);
664 NEXT_PASS (pass_instantiate_virtual_regs);
665 NEXT_PASS (pass_into_cfg_layout_mode);
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_rtl_ifcvt);
672 NEXT_PASS (pass_tracer);
673 /* Perform loop optimizations. It might be better to do them a bit
674 sooner, but we want the profile feedback to work more
676 NEXT_PASS (pass_loop2);
678 struct tree_opt_pass **p = &pass_loop2.sub;
679 NEXT_PASS (pass_rtl_loop_init);
680 NEXT_PASS (pass_rtl_move_loop_invariants);
681 NEXT_PASS (pass_rtl_unswitch);
682 NEXT_PASS (pass_rtl_unroll_and_peel_loops);
683 NEXT_PASS (pass_rtl_doloop);
684 NEXT_PASS (pass_rtl_loop_done);
687 NEXT_PASS (pass_web);
688 NEXT_PASS (pass_jump_bypass);
689 NEXT_PASS (pass_cse2);
690 NEXT_PASS (pass_rtl_fwprop_addr);
691 NEXT_PASS (pass_outof_cfg_layout_mode);
692 NEXT_PASS (pass_life);
693 NEXT_PASS (pass_combine);
694 NEXT_PASS (pass_if_after_combine);
695 NEXT_PASS (pass_partition_blocks);
696 NEXT_PASS (pass_regmove);
697 NEXT_PASS (pass_split_all_insns);
698 NEXT_PASS (pass_lower_subreg2);
699 NEXT_PASS (pass_mode_switching);
700 NEXT_PASS (pass_see);
701 NEXT_PASS (pass_recompute_reg_usage);
702 NEXT_PASS (pass_sms);
703 NEXT_PASS (pass_sched);
704 NEXT_PASS (pass_local_alloc);
705 NEXT_PASS (pass_global_alloc);
706 NEXT_PASS (pass_postreload);
708 struct tree_opt_pass **p = &pass_postreload.sub;
709 NEXT_PASS (pass_postreload_cse);
710 NEXT_PASS (pass_gcse2);
711 NEXT_PASS (pass_flow2);
712 NEXT_PASS (pass_rtl_seqabstr);
713 NEXT_PASS (pass_stack_adjustments);
714 NEXT_PASS (pass_peephole2);
715 NEXT_PASS (pass_if_after_reload);
716 NEXT_PASS (pass_regrename);
717 NEXT_PASS (pass_reorder_blocks);
718 NEXT_PASS (pass_branch_target_load_optimize);
719 NEXT_PASS (pass_leaf_regs);
720 NEXT_PASS (pass_sched2);
721 NEXT_PASS (pass_split_before_regstack);
722 NEXT_PASS (pass_stack_regs);
723 NEXT_PASS (pass_compute_alignments);
724 NEXT_PASS (pass_duplicate_computed_gotos);
725 NEXT_PASS (pass_variable_tracking);
726 NEXT_PASS (pass_free_cfg);
727 NEXT_PASS (pass_machine_reorg);
728 NEXT_PASS (pass_cleanup_barriers);
729 NEXT_PASS (pass_delay_slots);
730 NEXT_PASS (pass_split_for_shorten_branches);
731 NEXT_PASS (pass_convert_to_eh_region_ranges);
732 NEXT_PASS (pass_shorten_branches);
733 NEXT_PASS (pass_set_nothrow_function_flags);
734 NEXT_PASS (pass_final);
737 NEXT_PASS (pass_clean_state);
742 /* Register the passes with the tree dump code. */
743 register_dump_files (all_lowering_passes, false, PROP_gimple_any);
744 all_lowering_passes->todo_flags_start |= TODO_set_props;
745 register_dump_files (all_ipa_passes, true,
746 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
748 register_dump_files (all_passes, false,
749 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
753 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
754 function CALLBACK for every function in the call graph. Otherwise,
755 call CALLBACK on the current function. */
758 do_per_function (void (*callback) (void *data), void *data)
760 if (current_function_decl)
764 struct cgraph_node *node;
765 for (node = cgraph_nodes; node; node = node->next)
768 push_cfun (DECL_STRUCT_FUNCTION (node->decl));
769 current_function_decl = node->decl;
771 free_dominance_info (CDI_DOMINATORS);
772 free_dominance_info (CDI_POST_DOMINATORS);
773 current_function_decl = NULL;
780 /* Because inlining might remove no-longer reachable nodes, we need to
781 keep the array visible to garbage collector to avoid reading collected
784 static GTY ((length ("nnodes"))) struct cgraph_node **order;
786 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
787 function CALLBACK for every function in the call graph. Otherwise,
788 call CALLBACK on the current function. */
791 do_per_function_toporder (void (*callback) (void *data), void *data)
795 if (current_function_decl)
800 order = ggc_alloc (sizeof (*order) * cgraph_n_nodes);
801 nnodes = cgraph_postorder (order);
802 for (i = nnodes - 1; i >= 0; i--)
804 struct cgraph_node *node = order[i];
806 /* Allow possibly removed nodes to be garbage collected. */
808 if (node->analyzed && (node->needed || node->reachable))
810 push_cfun (DECL_STRUCT_FUNCTION (node->decl));
811 current_function_decl = node->decl;
813 free_dominance_info (CDI_DOMINATORS);
814 free_dominance_info (CDI_POST_DOMINATORS);
815 current_function_decl = NULL;
826 /* Perform all TODO actions that ought to be done on each function. */
829 execute_function_todo (void *data)
831 unsigned int flags = (size_t)data;
832 if (cfun->curr_properties & PROP_ssa)
833 flags |= TODO_verify_ssa;
834 flags &= ~cfun->last_verified;
838 /* Always cleanup the CFG before trying to update SSA. */
839 if (flags & TODO_cleanup_cfg)
844 cleanup = cleanup_tree_cfg_loop ();
846 cleanup = cleanup_tree_cfg ();
848 if (cleanup && (cfun->curr_properties & PROP_ssa))
849 flags |= TODO_remove_unused_locals;
851 /* When cleanup_tree_cfg merges consecutive blocks, it may
852 perform some simplistic propagation when removing single
853 valued PHI nodes. This propagation may, in turn, cause the
854 SSA form to become out-of-date (see PR 22037). So, even
855 if the parent pass had not scheduled an SSA update, we may
856 still need to do one. */
857 if (!(flags & TODO_update_ssa_any) && need_ssa_update_p ())
858 flags |= TODO_update_ssa;
861 if (flags & TODO_update_ssa_any)
863 unsigned update_flags = flags & TODO_update_ssa_any;
864 update_ssa (update_flags);
865 cfun->last_verified &= ~TODO_verify_ssa;
868 if (flags & TODO_remove_unused_locals)
869 remove_unused_locals ();
871 if ((flags & TODO_dump_func)
872 && dump_file && current_function_decl)
874 if (cfun->curr_properties & PROP_trees)
875 dump_function_to_file (current_function_decl,
876 dump_file, dump_flags);
879 if (dump_flags & TDF_SLIM)
880 print_rtl_slim_with_bb (dump_file, get_insns (), dump_flags);
881 else if ((cfun->curr_properties & PROP_cfg)
882 && (dump_flags & TDF_BLOCKS))
883 print_rtl_with_bb (dump_file, get_insns ());
885 print_rtl (dump_file, get_insns ());
887 if (cfun->curr_properties & PROP_cfg
888 && graph_dump_format != no_graph
889 && (dump_flags & TDF_GRAPH))
890 print_rtl_graph_with_bb (dump_file_name, get_insns ());
893 /* Flush the file. If verification fails, we won't be able to
894 close the file before aborting. */
898 if (flags & TODO_rebuild_frequencies)
900 if (profile_status == PROFILE_GUESSED)
902 loop_optimizer_init (0);
903 add_noreturn_fake_exit_edges ();
904 mark_irreducible_loops ();
905 connect_infinite_loops_to_exit ();
906 estimate_bb_frequencies ();
907 remove_fake_exit_edges ();
908 loop_optimizer_finalize ();
910 else if (profile_status == PROFILE_READ)
916 #if defined ENABLE_CHECKING
917 if (flags & TODO_verify_ssa)
919 if (flags & TODO_verify_flow)
921 if (flags & TODO_verify_stmts)
923 if (flags & TODO_verify_loops)
924 verify_loop_closed_ssa ();
927 cfun->last_verified = flags & TODO_verify_all;
930 /* Perform all TODO actions. */
932 execute_todo (unsigned int flags)
934 #if defined ENABLE_CHECKING
935 if (need_ssa_update_p ())
936 gcc_assert (flags & TODO_update_ssa_any);
939 /* Inform the pass whether it is the first time it is run. */
940 first_pass_instance = (flags & TODO_mark_first_instance) != 0;
942 do_per_function (execute_function_todo, (void *)(size_t) flags);
944 /* Always remove functions just as before inlining: IPA passes might be
945 interested to see bodies of extern inline functions that are not inlined
946 to analyze side effects. The full removal is done just at the end
947 of IPA pass queue. */
948 if (flags & TODO_remove_functions)
949 cgraph_remove_unreachable_nodes (true, dump_file);
951 if ((flags & TODO_dump_cgraph)
952 && dump_file && !current_function_decl)
954 dump_cgraph (dump_file);
955 /* Flush the file. If verification fails, we won't be able to
956 close the file before aborting. */
960 if (flags & TODO_ggc_collect)
966 /* Verify invariants that should hold between passes. This is a place
967 to put simple sanity checks. */
970 verify_interpass_invariants (void)
972 #ifdef ENABLE_CHECKING
973 gcc_assert (!fold_deferring_overflow_warnings_p ());
977 /* Clear the last verified flag. */
980 clear_last_verified (void *data ATTRIBUTE_UNUSED)
982 cfun->last_verified = 0;
985 /* Helper function. Verify that the properties has been turn into the
986 properties expected by the pass. */
988 #ifdef ENABLE_CHECKING
990 verify_curr_properties (void *data)
992 unsigned int props = (size_t)data;
993 gcc_assert ((cfun->curr_properties & props) == props);
997 /* After executing the pass, apply expected changes to the function
1000 update_properties_after_pass (void *data)
1002 struct tree_opt_pass *pass = data;
1003 cfun->curr_properties = (cfun->curr_properties | pass->properties_provided)
1004 & ~pass->properties_destroyed;
1008 execute_one_pass (struct tree_opt_pass *pass)
1010 bool initializing_dump;
1011 unsigned int todo_after = 0;
1013 /* See if we're supposed to run this pass. */
1014 if (pass->gate && !pass->gate ())
1017 if (!quiet_flag && !cfun)
1018 fprintf (stderr, " <%s>", pass->name ? pass->name : "");
1020 if (pass->todo_flags_start & TODO_set_props)
1021 cfun->curr_properties = pass->properties_required;
1023 /* Note that the folders should only create gimple expressions.
1024 This is a hack until the new folder is ready. */
1025 in_gimple_form = (cfun && (cfun->curr_properties & PROP_trees)) != 0;
1027 /* Run pre-pass verification. */
1028 execute_todo (pass->todo_flags_start);
1030 #ifdef ENABLE_CHECKING
1031 do_per_function (verify_curr_properties,
1032 (void *)(size_t)pass->properties_required);
1035 /* If a dump file name is present, open it if enabled. */
1036 if (pass->static_pass_number != -1)
1038 initializing_dump = !dump_initialized_p (pass->static_pass_number);
1039 dump_file_name = get_dump_file_name (pass->static_pass_number);
1040 dump_file = dump_begin (pass->static_pass_number, &dump_flags);
1041 if (dump_file && current_function_decl)
1043 const char *dname, *aname;
1044 dname = lang_hooks.decl_printable_name (current_function_decl, 2);
1045 aname = (IDENTIFIER_POINTER
1046 (DECL_ASSEMBLER_NAME (current_function_decl)));
1047 fprintf (dump_file, "\n;; Function %s (%s)%s\n\n", dname, aname,
1048 cfun->function_frequency == FUNCTION_FREQUENCY_HOT
1050 : cfun->function_frequency == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED
1051 ? " (unlikely executed)"
1056 initializing_dump = false;
1058 /* If a timevar is present, start it. */
1060 timevar_push (pass->tv_id);
1065 todo_after = pass->execute ();
1066 do_per_function (clear_last_verified, NULL);
1071 timevar_pop (pass->tv_id);
1073 do_per_function (update_properties_after_pass, pass);
1075 if (initializing_dump
1077 && graph_dump_format != no_graph
1078 && (cfun->curr_properties & (PROP_cfg | PROP_rtl))
1079 == (PROP_cfg | PROP_rtl))
1081 get_dump_file_info (pass->static_pass_number)->flags |= TDF_GRAPH;
1082 dump_flags |= TDF_GRAPH;
1083 clean_graph_dump_file (dump_file_name);
1086 /* Run post-pass cleanup and verification. */
1087 execute_todo (todo_after | pass->todo_flags_finish);
1088 verify_interpass_invariants ();
1090 if (!current_function_decl)
1091 cgraph_process_new_functions ();
1093 /* Flush and close dump file. */
1096 free ((char *) dump_file_name);
1097 dump_file_name = NULL;
1102 dump_end (pass->static_pass_number, dump_file);
1106 /* Reset in_gimple_form to not break non-unit-at-a-time mode. */
1107 in_gimple_form = false;
1113 execute_pass_list (struct tree_opt_pass *pass)
1117 if (execute_one_pass (pass) && pass->sub)
1118 execute_pass_list (pass->sub);
1124 /* Same as execute_pass_list but assume that subpasses of IPA passes
1125 are local passes. */
1127 execute_ipa_pass_list (struct tree_opt_pass *pass)
1131 gcc_assert (!current_function_decl);
1133 if (execute_one_pass (pass) && pass->sub)
1134 do_per_function_toporder ((void (*)(void *))execute_pass_list,
1136 if (!current_function_decl)
1137 cgraph_process_new_functions ();
1142 #include "gt-passes.h"