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. */
110 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
113 This does nothing for local (non-static) variables, unless the
114 variable is a register variable with DECL_ASSEMBLER_NAME set. In
115 that case, or if the variable is not an automatic, it sets up the
116 RTL and outputs any assembler code (label definition, storage
117 allocation and initialization).
119 DECL is the declaration. TOP_LEVEL is nonzero
120 if this declaration is not within a function. */
123 rest_of_decl_compilation (tree decl
,
127 /* We deferred calling assemble_alias so that we could collect
128 other attributes such as visibility. Emit the alias now. */
131 alias
= lookup_attribute ("alias", DECL_ATTRIBUTES (decl
));
134 alias
= TREE_VALUE (TREE_VALUE (alias
));
135 alias
= get_identifier (TREE_STRING_POINTER (alias
));
136 assemble_alias (decl
, alias
);
140 /* Can't defer this, because it needs to happen before any
141 later function definitions are processed. */
142 if (DECL_ASSEMBLER_NAME_SET_P (decl
) && DECL_REGISTER (decl
))
143 make_decl_rtl (decl
);
145 /* Forward declarations for nested functions are not "external",
146 but we need to treat them as if they were. */
147 if (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)
148 || TREE_CODE (decl
) == FUNCTION_DECL
)
150 timevar_push (TV_VARCONST
);
152 /* Don't output anything when a tentative file-scope definition
153 is seen. But at end of compilation, do output code for them.
155 We do output all variables when unit-at-a-time is active and rely on
156 callgraph code to defer them except for forward declarations
157 (see gcc.c-torture/compile/920624-1.c) */
159 || !DECL_DEFER_OUTPUT (decl
)
160 || DECL_INITIAL (decl
))
161 && !DECL_EXTERNAL (decl
))
163 if (TREE_CODE (decl
) != FUNCTION_DECL
)
164 varpool_finalize_decl (decl
);
166 assemble_variable (decl
, top_level
, at_end
, 0);
169 #ifdef ASM_FINISH_DECLARE_OBJECT
170 if (decl
== last_assemble_variable_decl
)
172 ASM_FINISH_DECLARE_OBJECT (asm_out_file
, decl
,
177 timevar_pop (TV_VARCONST
);
179 else if (TREE_CODE (decl
) == TYPE_DECL
180 /* Like in rest_of_type_compilation, avoid confusing the debug
181 information machinery when there are errors. */
182 && !(sorrycount
|| errorcount
))
184 timevar_push (TV_SYMOUT
);
185 debug_hooks
->type_decl (decl
, !top_level
);
186 timevar_pop (TV_SYMOUT
);
189 /* Let cgraph know about the existence of variables. */
190 if (TREE_CODE (decl
) == VAR_DECL
&& !DECL_EXTERNAL (decl
))
194 /* Called after finishing a record, union or enumeral type. */
197 rest_of_type_compilation (tree type
, int toplev
)
199 /* Avoid confusing the debug information machinery when there are
201 if (errorcount
!= 0 || sorrycount
!= 0)
204 timevar_push (TV_SYMOUT
);
205 debug_hooks
->type_decl (TYPE_STUB_DECL (type
), !toplev
);
206 timevar_pop (TV_SYMOUT
);
212 finish_optimization_passes (void)
214 enum tree_dump_index i
;
215 struct dump_file_info
*dfi
;
218 timevar_push (TV_DUMP
);
219 if (profile_arc_flag
|| flag_test_coverage
|| flag_branch_probabilities
)
221 dump_file
= dump_begin (pass_profile
.static_pass_number
, NULL
);
224 dump_end (pass_profile
.static_pass_number
, dump_file
);
229 dump_file
= dump_begin (pass_combine
.static_pass_number
, NULL
);
232 dump_combine_total_stats (dump_file
);
233 dump_end (pass_combine
.static_pass_number
, dump_file
);
237 /* Do whatever is necessary to finish printing the graphs. */
238 if (graph_dump_format
!= no_graph
)
239 for (i
= TDI_end
; (dfi
= get_dump_file_info (i
)) != NULL
; ++i
)
240 if (dump_initialized_p (i
)
241 && (dfi
->flags
& TDF_GRAPH
) != 0
242 && (name
= get_dump_file_name (i
)) != NULL
)
244 finish_graph_dump_file (name
);
248 timevar_pop (TV_DUMP
);
252 gate_rest_of_compilation (void)
254 /* Early return if there were errors. We can run afoul of our
255 consistency checks, and there's not really much point in fixing them. */
256 return !(rtl_dump_and_exit
|| flag_syntax_only
|| errorcount
|| sorrycount
);
259 struct tree_opt_pass pass_rest_of_compilation
=
262 gate_rest_of_compilation
, /* gate */
266 0, /* static_pass_number */
267 TV_REST_OF_COMPILATION
, /* tv_id */
268 PROP_rtl
, /* properties_required */
269 0, /* properties_provided */
270 0, /* properties_destroyed */
271 0, /* todo_flags_start */
272 TODO_ggc_collect
, /* todo_flags_finish */
277 gate_postreload (void)
279 return reload_completed
;
282 struct tree_opt_pass pass_postreload
=
285 gate_postreload
, /* gate */
289 0, /* static_pass_number */
291 PROP_rtl
, /* properties_required */
292 0, /* properties_provided */
293 0, /* properties_destroyed */
294 0, /* todo_flags_start */
295 TODO_ggc_collect
, /* todo_flags_finish */
301 /* The root of the compilation pass tree, once constructed. */
302 struct tree_opt_pass
*all_passes
, *all_ipa_passes
, *all_lowering_passes
;
304 /* Iterate over the pass tree allocating dump file numbers. We want
305 to do this depth first, and independent of whether the pass is
309 register_one_dump_file (struct tree_opt_pass
*pass
, bool ipa
, int properties
)
311 char *dot_name
, *flag_name
, *glob_name
;
316 /* See below in next_pass_1. */
318 if (pass
->static_pass_number
!= -1)
319 sprintf (num
, "%d", ((int) pass
->static_pass_number
< 0
320 ? 1 : pass
->static_pass_number
));
322 dot_name
= concat (".", pass
->name
, num
, NULL
);
324 prefix
= "ipa-", flags
= TDF_IPA
;
325 else if (properties
& PROP_trees
)
326 prefix
= "tree-", flags
= TDF_TREE
;
328 prefix
= "rtl-", flags
= TDF_RTL
;
330 flag_name
= concat (prefix
, pass
->name
, num
, NULL
);
331 glob_name
= concat (prefix
, pass
->name
, NULL
);
332 pass
->static_pass_number
= dump_register (dot_name
, flag_name
, glob_name
,
333 flags
, pass
->letter
);
336 /* Recursive worker function for register_dump_files. */
339 register_dump_files_1 (struct tree_opt_pass
*pass
, bool ipa
, int properties
)
343 int new_properties
= (properties
| pass
->properties_provided
)
344 & ~pass
->properties_destroyed
;
347 register_one_dump_file (pass
, ipa
, new_properties
);
350 new_properties
= register_dump_files_1 (pass
->sub
, false,
353 /* If we have a gate, combine the properties that we could have with
354 and without the pass being examined. */
356 properties
&= new_properties
;
358 properties
= new_properties
;
367 /* Register the dump files for the pipeline starting at PASS. IPA is
368 true if the pass is inter-procedural, and PROPERTIES reflects the
369 properties that are guaranteed to be available at the beginning of
373 register_dump_files (struct tree_opt_pass
*pass
, bool ipa
, int properties
)
375 pass
->properties_required
|= properties
;
376 register_dump_files_1 (pass
, ipa
, properties
);
379 /* Add a pass to the pass list. Duplicate the pass if it's already
382 static struct tree_opt_pass
**
383 next_pass_1 (struct tree_opt_pass
**list
, struct tree_opt_pass
*pass
)
385 /* A nonzero static_pass_number indicates that the
386 pass is already in the list. */
387 if (pass
->static_pass_number
)
389 struct tree_opt_pass
*new;
391 new = xmalloc (sizeof (*new));
392 memcpy (new, pass
, sizeof (*new));
394 /* Indicate to register_dump_files that this pass has duplicates,
395 and so it should rename the dump file. The first instance will
396 be -1, and be number of duplicates = -static_pass_number - 1.
397 Subsequent instances will be > 0 and just the duplicate number. */
400 pass
->static_pass_number
-= 1;
401 new->static_pass_number
= -pass
->static_pass_number
;
408 pass
->static_pass_number
= -1;
412 return &(*list
)->next
;
416 /* Construct the pass tree. The sequencing of passes is driven by
419 cgraph_finalize_compilation_unit ()
420 for each node N in the cgraph
421 cgraph_analyze_function (N)
422 cgraph_lower_function (N) -> all_lowering_passes
424 If we are optimizing, cgraph_optimize is then invoked:
427 ipa_passes () -> all_ipa_passes
428 cgraph_expand_all_functions ()
429 for each node N in the cgraph
430 cgraph_expand_function (N)
431 lang_hooks.callgraph.expand_function (DECL (N))
432 tree_rest_of_compilation (DECL (N)) -> all_passes
436 init_optimization_passes (void)
438 struct tree_opt_pass
**p
;
440 #define NEXT_PASS(PASS) (p = next_pass_1 (p, &PASS))
442 /* All passes needed to lower the function into shape optimizers can
443 operate on. These passes are always run first on the function, but
444 backend might produce already lowered functions that are not processed
446 p
= &all_lowering_passes
;
447 NEXT_PASS (pass_remove_useless_stmts
);
448 NEXT_PASS (pass_mudflap_1
);
449 NEXT_PASS (pass_lower_omp
);
450 NEXT_PASS (pass_lower_cf
);
451 NEXT_PASS (pass_lower_eh
);
452 NEXT_PASS (pass_build_cfg
);
453 NEXT_PASS (pass_lower_complex_O0
);
454 NEXT_PASS (pass_lower_vector
);
455 NEXT_PASS (pass_warn_function_return
);
456 NEXT_PASS (pass_build_cgraph_edges
);
457 NEXT_PASS (pass_inline_parameters
);
460 /* Interprocedural optimization passes.
461 All these passes are ignored in -fno-unit-at-a-time
462 except for subpases of early_local_pases. */
464 NEXT_PASS (pass_ipa_function_and_variable_visibility
);
465 NEXT_PASS (pass_ipa_early_inline
);
467 struct tree_opt_pass
**p
= &pass_ipa_early_inline
.sub
;
468 NEXT_PASS (pass_early_inline
);
469 NEXT_PASS (pass_inline_parameters
);
470 NEXT_PASS (pass_rebuild_cgraph_edges
);
472 NEXT_PASS (pass_early_local_passes
);
474 struct tree_opt_pass
**p
= &pass_early_local_passes
.sub
;
475 NEXT_PASS (pass_tree_profile
);
476 NEXT_PASS (pass_cleanup_cfg
);
477 NEXT_PASS (pass_init_datastructures
);
478 NEXT_PASS (pass_expand_omp
);
479 NEXT_PASS (pass_all_early_optimizations
);
481 struct tree_opt_pass
**p
= &pass_all_early_optimizations
.sub
;
482 NEXT_PASS (pass_referenced_vars
);
483 NEXT_PASS (pass_reset_cc_flags
);
484 NEXT_PASS (pass_build_ssa
);
485 NEXT_PASS (pass_early_warn_uninitialized
);
486 NEXT_PASS (pass_rebuild_cgraph_edges
);
487 NEXT_PASS (pass_early_inline
);
488 NEXT_PASS (pass_cleanup_cfg
);
489 NEXT_PASS (pass_rename_ssa_copies
);
490 NEXT_PASS (pass_ccp
);
491 NEXT_PASS (pass_forwprop
);
492 NEXT_PASS (pass_sra
);
493 NEXT_PASS (pass_copy_prop
);
494 NEXT_PASS (pass_merge_phi
);
495 NEXT_PASS (pass_dce
);
496 NEXT_PASS (pass_tail_recursion
);
497 NEXT_PASS (pass_profile
);
498 NEXT_PASS (pass_release_ssa_names
);
500 NEXT_PASS (pass_rebuild_cgraph_edges
);
501 NEXT_PASS (pass_inline_parameters
);
503 NEXT_PASS (pass_ipa_increase_alignment
);
504 NEXT_PASS (pass_ipa_cp
);
505 NEXT_PASS (pass_ipa_inline
);
506 NEXT_PASS (pass_ipa_reference
);
507 NEXT_PASS (pass_ipa_pure_const
);
508 NEXT_PASS (pass_ipa_type_escape
);
509 NEXT_PASS (pass_ipa_pta
);
512 /* These passes are run after IPA passes on every function that is being
513 output to the assembler file. */
515 NEXT_PASS (pass_apply_inline
);
516 NEXT_PASS (pass_all_optimizations
);
518 struct tree_opt_pass
**p
= &pass_all_optimizations
.sub
;
519 NEXT_PASS (pass_create_structure_vars
);
520 NEXT_PASS (pass_may_alias
);
521 NEXT_PASS (pass_return_slot
);
522 NEXT_PASS (pass_rename_ssa_copies
);
524 /* Initial scalar cleanups. */
525 NEXT_PASS (pass_ccp
);
526 NEXT_PASS (pass_fre
);
527 NEXT_PASS (pass_dce
);
528 NEXT_PASS (pass_forwprop
);
529 NEXT_PASS (pass_copy_prop
);
530 NEXT_PASS (pass_merge_phi
);
531 NEXT_PASS (pass_vrp
);
532 NEXT_PASS (pass_dce
);
533 NEXT_PASS (pass_dominator
);
535 /* The only const/copy propagation opportunities left after
536 DOM should be due to degenerate PHI nodes. So rather than
537 run the full propagators, run a specialized pass which
538 only examines PHIs to discover const/copy propagation
540 NEXT_PASS (pass_phi_only_cprop
);
542 NEXT_PASS (pass_phiopt
);
543 NEXT_PASS (pass_may_alias
);
544 NEXT_PASS (pass_tail_recursion
);
546 NEXT_PASS (pass_stdarg
);
547 NEXT_PASS (pass_lower_complex
);
548 NEXT_PASS (pass_sra
);
549 /* FIXME: SRA may generate arbitrary gimple code, exposing new
550 aliased and call-clobbered variables. As mentioned below,
551 pass_may_alias should be a TODO item. */
552 NEXT_PASS (pass_may_alias
);
553 NEXT_PASS (pass_rename_ssa_copies
);
554 NEXT_PASS (pass_dominator
);
556 /* The only const/copy propagation opportunities left after
557 DOM should be due to degenerate PHI nodes. So rather than
558 run the full propagators, run a specialized pass which
559 only examines PHIs to discover const/copy propagation
561 NEXT_PASS (pass_phi_only_cprop
);
563 NEXT_PASS (pass_reassoc
);
564 NEXT_PASS (pass_dce
);
565 NEXT_PASS (pass_dse
);
566 NEXT_PASS (pass_may_alias
);
567 NEXT_PASS (pass_forwprop
);
568 NEXT_PASS (pass_phiopt
);
569 NEXT_PASS (pass_object_sizes
);
570 NEXT_PASS (pass_store_ccp
);
571 NEXT_PASS (pass_store_copy_prop
);
572 NEXT_PASS (pass_fold_builtins
);
573 NEXT_PASS (pass_cse_sincos
);
574 /* FIXME: May alias should a TODO but for 4.0.0,
575 we add may_alias right after fold builtins
576 which can create arbitrary GIMPLE. */
577 NEXT_PASS (pass_may_alias
);
578 NEXT_PASS (pass_split_crit_edges
);
579 NEXT_PASS (pass_pre
);
580 NEXT_PASS (pass_may_alias
);
581 NEXT_PASS (pass_sink_code
);
582 NEXT_PASS (pass_tree_loop
);
584 struct tree_opt_pass
**p
= &pass_tree_loop
.sub
;
585 NEXT_PASS (pass_tree_loop_init
);
586 NEXT_PASS (pass_copy_prop
);
587 NEXT_PASS (pass_lim
);
588 NEXT_PASS (pass_tree_unswitch
);
589 NEXT_PASS (pass_scev_cprop
);
590 NEXT_PASS (pass_empty_loop
);
591 NEXT_PASS (pass_record_bounds
);
592 NEXT_PASS (pass_linear_transform
);
593 NEXT_PASS (pass_iv_canon
);
594 NEXT_PASS (pass_if_conversion
);
595 NEXT_PASS (pass_vectorize
);
597 struct tree_opt_pass
**p
= &pass_vectorize
.sub
;
598 NEXT_PASS (pass_lower_vector_ssa
);
599 NEXT_PASS (pass_dce_loop
);
601 /* NEXT_PASS (pass_may_alias) cannot be done again because the
602 vectorizer creates alias relations that are not supported by
604 NEXT_PASS (pass_complete_unroll
);
605 NEXT_PASS (pass_loop_prefetch
);
606 NEXT_PASS (pass_iv_optimize
);
607 NEXT_PASS (pass_tree_loop_done
);
609 NEXT_PASS (pass_cse_reciprocals
);
610 NEXT_PASS (pass_reassoc
);
611 NEXT_PASS (pass_vrp
);
612 NEXT_PASS (pass_dominator
);
614 /* The only const/copy propagation opportunities left after
615 DOM should be due to degenerate PHI nodes. So rather than
616 run the full propagators, run a specialized pass which
617 only examines PHIs to discover const/copy propagation
619 NEXT_PASS (pass_phi_only_cprop
);
621 NEXT_PASS (pass_cd_dce
);
623 /* FIXME: If DCE is not run before checking for uninitialized uses,
624 we may get false warnings (e.g., testsuite/gcc.dg/uninit-5.c).
625 However, this also causes us to misdiagnose cases that should be
626 real warnings (e.g., testsuite/gcc.dg/pr18501.c).
628 To fix the false positives in uninit-5.c, we would have to
629 account for the predicates protecting the set and the use of each
630 variable. Using a representation like Gated Single Assignment
632 NEXT_PASS (pass_late_warn_uninitialized
);
633 NEXT_PASS (pass_dse
);
634 NEXT_PASS (pass_forwprop
);
635 NEXT_PASS (pass_phiopt
);
636 NEXT_PASS (pass_tail_calls
);
637 NEXT_PASS (pass_rename_ssa_copies
);
638 NEXT_PASS (pass_uncprop
);
639 NEXT_PASS (pass_del_ssa
);
640 NEXT_PASS (pass_nrv
);
641 NEXT_PASS (pass_mark_used_blocks
);
642 NEXT_PASS (pass_cleanup_cfg_post_optimizing
);
644 NEXT_PASS (pass_warn_function_noreturn
);
645 NEXT_PASS (pass_free_datastructures
);
646 NEXT_PASS (pass_mudflap_2
);
647 NEXT_PASS (pass_free_cfg_annotations
);
648 NEXT_PASS (pass_expand
);
649 NEXT_PASS (pass_rest_of_compilation
);
651 struct tree_opt_pass
**p
= &pass_rest_of_compilation
.sub
;
652 NEXT_PASS (pass_init_function
);
653 NEXT_PASS (pass_jump
);
654 NEXT_PASS (pass_insn_locators_initialize
);
655 NEXT_PASS (pass_rtl_eh
);
656 NEXT_PASS (pass_initial_value_sets
);
657 NEXT_PASS (pass_unshare_all_rtl
);
658 NEXT_PASS (pass_instantiate_virtual_regs
);
659 NEXT_PASS (pass_jump2
);
660 NEXT_PASS (pass_lower_subreg
);
661 NEXT_PASS (pass_cse
);
662 NEXT_PASS (pass_rtl_fwprop
);
663 NEXT_PASS (pass_gcse
);
664 NEXT_PASS (pass_jump_bypass
);
665 NEXT_PASS (pass_rtl_ifcvt
);
666 NEXT_PASS (pass_tracer
);
667 /* Perform loop optimizations. It might be better to do them a bit
668 sooner, but we want the profile feedback to work more
670 NEXT_PASS (pass_loop2
);
672 struct tree_opt_pass
**p
= &pass_loop2
.sub
;
673 NEXT_PASS (pass_rtl_loop_init
);
674 NEXT_PASS (pass_rtl_move_loop_invariants
);
675 NEXT_PASS (pass_rtl_unswitch
);
676 NEXT_PASS (pass_rtl_unroll_and_peel_loops
);
677 NEXT_PASS (pass_rtl_doloop
);
678 NEXT_PASS (pass_rtl_loop_done
);
681 NEXT_PASS (pass_web
);
682 NEXT_PASS (pass_cse2
);
683 NEXT_PASS (pass_rtl_fwprop_addr
);
684 NEXT_PASS (pass_life
);
685 NEXT_PASS (pass_combine
);
686 NEXT_PASS (pass_if_after_combine
);
687 NEXT_PASS (pass_partition_blocks
);
688 NEXT_PASS (pass_regmove
);
689 NEXT_PASS (pass_split_all_insns
);
690 NEXT_PASS (pass_lower_subreg2
);
691 NEXT_PASS (pass_mode_switching
);
692 NEXT_PASS (pass_see
);
693 NEXT_PASS (pass_recompute_reg_usage
);
694 NEXT_PASS (pass_sms
);
695 NEXT_PASS (pass_sched
);
696 NEXT_PASS (pass_local_alloc
);
697 NEXT_PASS (pass_global_alloc
);
698 NEXT_PASS (pass_postreload
);
700 struct tree_opt_pass
**p
= &pass_postreload
.sub
;
701 NEXT_PASS (pass_postreload_cse
);
702 NEXT_PASS (pass_gcse2
);
703 NEXT_PASS (pass_flow2
);
704 NEXT_PASS (pass_rtl_seqabstr
);
705 NEXT_PASS (pass_stack_adjustments
);
706 NEXT_PASS (pass_peephole2
);
707 NEXT_PASS (pass_if_after_reload
);
708 NEXT_PASS (pass_regrename
);
709 NEXT_PASS (pass_reorder_blocks
);
710 NEXT_PASS (pass_branch_target_load_optimize
);
711 NEXT_PASS (pass_leaf_regs
);
712 NEXT_PASS (pass_sched2
);
713 NEXT_PASS (pass_split_before_regstack
);
714 NEXT_PASS (pass_stack_regs
);
715 NEXT_PASS (pass_compute_alignments
);
716 NEXT_PASS (pass_duplicate_computed_gotos
);
717 NEXT_PASS (pass_variable_tracking
);
718 NEXT_PASS (pass_free_cfg
);
719 NEXT_PASS (pass_machine_reorg
);
720 NEXT_PASS (pass_cleanup_barriers
);
721 NEXT_PASS (pass_delay_slots
);
722 NEXT_PASS (pass_split_for_shorten_branches
);
723 NEXT_PASS (pass_convert_to_eh_region_ranges
);
724 NEXT_PASS (pass_shorten_branches
);
725 NEXT_PASS (pass_set_nothrow_function_flags
);
726 NEXT_PASS (pass_final
);
729 NEXT_PASS (pass_clean_state
);
734 /* Register the passes with the tree dump code. */
735 register_dump_files (all_lowering_passes
, false, PROP_gimple_any
);
736 all_lowering_passes
->todo_flags_start
|= TODO_set_props
;
737 register_dump_files (all_ipa_passes
, true,
738 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
740 register_dump_files (all_passes
, false,
741 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
745 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
746 function CALLBACK for every function in the call graph. Otherwise,
747 call CALLBACK on the current function. */
750 do_per_function (void (*callback
) (void *data
), void *data
)
752 if (current_function_decl
)
756 struct cgraph_node
*node
;
757 for (node
= cgraph_nodes
; node
; node
= node
->next
)
760 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
761 current_function_decl
= node
->decl
;
763 free_dominance_info (CDI_DOMINATORS
);
764 free_dominance_info (CDI_POST_DOMINATORS
);
765 current_function_decl
= NULL
;
772 /* Because inlining might remove no-longer reachable nodes, we need to
773 keep the array visible to garbage collector to avoid reading collected
776 static GTY ((length ("nnodes"))) struct cgraph_node
**order
;
778 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
779 function CALLBACK for every function in the call graph. Otherwise,
780 call CALLBACK on the current function. */
783 do_per_function_toporder (void (*callback
) (void *data
), void *data
)
787 if (current_function_decl
)
792 order
= ggc_alloc (sizeof (*order
) * cgraph_n_nodes
);
793 nnodes
= cgraph_postorder (order
);
794 for (i
= nnodes
- 1; i
>= 0; i
--)
796 struct cgraph_node
*node
= order
[i
];
798 /* Allow possibly removed nodes to be garbage collected. */
800 if (node
->analyzed
&& (node
->needed
|| node
->reachable
))
802 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
803 current_function_decl
= node
->decl
;
805 free_dominance_info (CDI_DOMINATORS
);
806 free_dominance_info (CDI_POST_DOMINATORS
);
807 current_function_decl
= NULL
;
818 /* Perform all TODO actions that ought to be done on each function. */
821 execute_function_todo (void *data
)
823 unsigned int flags
= (size_t)data
;
824 if (cfun
->curr_properties
& PROP_ssa
)
825 flags
|= TODO_verify_ssa
;
826 flags
&= ~cfun
->last_verified
;
830 /* Always cleanup the CFG before trying to update SSA. */
831 if (flags
& TODO_cleanup_cfg
)
836 cleanup
= cleanup_tree_cfg_loop ();
838 cleanup
= cleanup_tree_cfg ();
840 if (cleanup
&& (cfun
->curr_properties
& PROP_ssa
))
841 flags
|= TODO_remove_unused_locals
;
843 /* When cleanup_tree_cfg merges consecutive blocks, it may
844 perform some simplistic propagation when removing single
845 valued PHI nodes. This propagation may, in turn, cause the
846 SSA form to become out-of-date (see PR 22037). So, even
847 if the parent pass had not scheduled an SSA update, we may
848 still need to do one. */
849 if (!(flags
& TODO_update_ssa_any
) && need_ssa_update_p ())
850 flags
|= TODO_update_ssa
;
853 if (flags
& TODO_update_ssa_any
)
855 unsigned update_flags
= flags
& TODO_update_ssa_any
;
856 update_ssa (update_flags
);
857 cfun
->last_verified
&= ~TODO_verify_ssa
;
860 if (flags
& TODO_remove_unused_locals
)
861 remove_unused_locals ();
863 if ((flags
& TODO_dump_func
)
864 && dump_file
&& current_function_decl
)
866 if (cfun
->curr_properties
& PROP_trees
)
867 dump_function_to_file (current_function_decl
,
868 dump_file
, dump_flags
);
871 if (dump_flags
& TDF_SLIM
)
872 print_rtl_slim_with_bb (dump_file
, get_insns (), dump_flags
);
873 else if ((cfun
->curr_properties
& PROP_cfg
)
874 && (dump_flags
& TDF_BLOCKS
))
875 print_rtl_with_bb (dump_file
, get_insns ());
877 print_rtl (dump_file
, get_insns ());
879 if (cfun
->curr_properties
& PROP_cfg
880 && graph_dump_format
!= no_graph
881 && (dump_flags
& TDF_GRAPH
))
882 print_rtl_graph_with_bb (dump_file_name
, get_insns ());
885 /* Flush the file. If verification fails, we won't be able to
886 close the file before aborting. */
890 if (flags
& TODO_rebuild_frequencies
)
892 if (profile_status
== PROFILE_GUESSED
)
894 loop_optimizer_init (0);
895 add_noreturn_fake_exit_edges ();
896 mark_irreducible_loops ();
897 connect_infinite_loops_to_exit ();
898 estimate_bb_frequencies ();
899 remove_fake_exit_edges ();
900 loop_optimizer_finalize ();
902 else if (profile_status
== PROFILE_READ
)
908 #if defined ENABLE_CHECKING
909 if (flags
& TODO_verify_ssa
)
911 if (flags
& TODO_verify_flow
)
913 if (flags
& TODO_verify_stmts
)
915 if (flags
& TODO_verify_loops
)
916 verify_loop_closed_ssa ();
919 cfun
->last_verified
= flags
& TODO_verify_all
;
922 /* Perform all TODO actions. */
924 execute_todo (unsigned int flags
)
926 #if defined ENABLE_CHECKING
927 if (need_ssa_update_p ())
928 gcc_assert (flags
& TODO_update_ssa_any
);
931 do_per_function (execute_function_todo
, (void *)(size_t) flags
);
933 /* Always remove functions just as before inlining: IPA passes might be
934 interested to see bodies of extern inline functions that are not inlined
935 to analyze side effects. The full removal is done just at the end
936 of IPA pass queue. */
937 if (flags
& TODO_remove_functions
)
938 cgraph_remove_unreachable_nodes (true, dump_file
);
940 if ((flags
& TODO_dump_cgraph
)
941 && dump_file
&& !current_function_decl
)
943 dump_cgraph (dump_file
);
944 /* Flush the file. If verification fails, we won't be able to
945 close the file before aborting. */
949 if (flags
& TODO_ggc_collect
)
955 /* Clear the last verified flag. */
958 clear_last_verified (void *data ATTRIBUTE_UNUSED
)
960 cfun
->last_verified
= 0;
963 /* Helper function. Verify that the properties has been turn into the
964 properties expected by the pass. */
966 #ifdef ENABLE_CHECKING
968 verify_curr_properties (void *data
)
970 unsigned int props
= (size_t)data
;
971 gcc_assert ((cfun
->curr_properties
& props
) == props
);
975 /* After executing the pass, apply expected changes to the function
978 update_properties_after_pass (void *data
)
980 struct tree_opt_pass
*pass
= data
;
981 cfun
->curr_properties
= (cfun
->curr_properties
| pass
->properties_provided
)
982 & ~pass
->properties_destroyed
;
986 execute_one_pass (struct tree_opt_pass
*pass
)
988 bool initializing_dump
;
989 unsigned int todo_after
= 0;
991 /* See if we're supposed to run this pass. */
992 if (pass
->gate
&& !pass
->gate ())
995 if (!quiet_flag
&& !cfun
)
996 fprintf (stderr
, " <%s>", pass
->name
? pass
->name
: "");
998 if (pass
->todo_flags_start
& TODO_set_props
)
999 cfun
->curr_properties
= pass
->properties_required
;
1001 /* Note that the folders should only create gimple expressions.
1002 This is a hack until the new folder is ready. */
1003 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
1005 /* Run pre-pass verification. */
1006 execute_todo (pass
->todo_flags_start
);
1008 #ifdef ENABLE_CHECKING
1009 do_per_function (verify_curr_properties
,
1010 (void *)(size_t)pass
->properties_required
);
1013 /* If a dump file name is present, open it if enabled. */
1014 if (pass
->static_pass_number
!= -1)
1016 initializing_dump
= !dump_initialized_p (pass
->static_pass_number
);
1017 dump_file_name
= get_dump_file_name (pass
->static_pass_number
);
1018 dump_file
= dump_begin (pass
->static_pass_number
, &dump_flags
);
1019 if (dump_file
&& current_function_decl
)
1021 const char *dname
, *aname
;
1022 dname
= lang_hooks
.decl_printable_name (current_function_decl
, 2);
1023 aname
= (IDENTIFIER_POINTER
1024 (DECL_ASSEMBLER_NAME (current_function_decl
)));
1025 fprintf (dump_file
, "\n;; Function %s (%s)%s\n\n", dname
, aname
,
1026 cfun
->function_frequency
== FUNCTION_FREQUENCY_HOT
1028 : cfun
->function_frequency
== FUNCTION_FREQUENCY_UNLIKELY_EXECUTED
1029 ? " (unlikely executed)"
1034 initializing_dump
= false;
1036 /* If a timevar is present, start it. */
1038 timevar_push (pass
->tv_id
);
1043 todo_after
= pass
->execute ();
1044 do_per_function (clear_last_verified
, NULL
);
1049 timevar_pop (pass
->tv_id
);
1051 do_per_function (update_properties_after_pass
, pass
);
1053 if (initializing_dump
1055 && graph_dump_format
!= no_graph
1056 && (cfun
->curr_properties
& (PROP_cfg
| PROP_rtl
))
1057 == (PROP_cfg
| PROP_rtl
))
1059 get_dump_file_info (pass
->static_pass_number
)->flags
|= TDF_GRAPH
;
1060 dump_flags
|= TDF_GRAPH
;
1061 clean_graph_dump_file (dump_file_name
);
1064 /* Run post-pass cleanup and verification. */
1065 execute_todo (todo_after
| pass
->todo_flags_finish
);
1067 if (!current_function_decl
)
1068 cgraph_process_new_functions ();
1070 /* Flush and close dump file. */
1073 free ((char *) dump_file_name
);
1074 dump_file_name
= NULL
;
1079 dump_end (pass
->static_pass_number
, dump_file
);
1083 /* Reset in_gimple_form to not break non-unit-at-a-time mode. */
1084 in_gimple_form
= false;
1090 execute_pass_list (struct tree_opt_pass
*pass
)
1094 if (execute_one_pass (pass
) && pass
->sub
)
1095 execute_pass_list (pass
->sub
);
1101 /* Same as execute_pass_list but assume that subpasses of IPA passes
1102 are local passes. */
1104 execute_ipa_pass_list (struct tree_opt_pass
*pass
)
1108 gcc_assert (!current_function_decl
);
1110 if (execute_one_pass (pass
) && pass
->sub
)
1111 do_per_function_toporder ((void (*)(void *))execute_pass_list
,
1113 if (!current_function_decl
)
1114 cgraph_process_new_functions ();
1119 #include "gt-passes.h"