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 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
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. */
28 #undef FLOAT /* This is for hpux. They should change hpux. */
29 #undef FFS /* Some systems define this in param.h. */
31 #include "coretypes.h"
35 #ifdef HAVE_SYS_RESOURCE_H
36 # include <sys/resource.h>
39 #ifdef HAVE_SYS_TIMES_H
40 # include <sys/times.h>
49 #include "insn-attr.h"
50 #include "insn-config.h"
51 #include "insn-flags.h"
52 #include "hard-reg-set.h"
59 #include "basic-block.h"
65 #include "diagnostic.h"
68 #include "dwarf2asm.h"
69 #include "integrate.h"
73 #include "langhooks.h"
74 #include "cfglayout.h"
76 #include "hosthooks.h"
80 #include "value-prof.h"
81 #include "tree-inline.h"
82 #include "tree-flow.h"
83 #include "tree-pass.h"
84 #include "tree-dump.h"
86 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
87 #include "dwarf2out.h"
90 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
94 #ifdef SDB_DEBUGGING_INFO
98 #ifdef XCOFF_DEBUGGING_INFO
99 #include "xcoffout.h" /* Needed for external data
100 declarations for e.g. AIX 4.x. */
103 /* Global variables used to communicate with passes. */
108 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
111 This does nothing for local (non-static) variables, unless the
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).
117 DECL is the declaration. TOP_LEVEL is nonzero
118 if this declaration is not within a function. */
121 rest_of_decl_compilation (tree decl
,
125 /* We deferred calling assemble_alias so that we could collect
126 other attributes such as visibility. Emit the alias now. */
129 alias
= lookup_attribute ("alias", DECL_ATTRIBUTES (decl
));
132 alias
= TREE_VALUE (TREE_VALUE (alias
));
133 alias
= get_identifier (TREE_STRING_POINTER (alias
));
134 assemble_alias (decl
, alias
);
138 /* Can't defer this, because it needs to happen before any
139 later function definitions are processed. */
140 if (DECL_ASSEMBLER_NAME_SET_P (decl
) && DECL_REGISTER (decl
))
141 make_decl_rtl (decl
);
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
)
148 timevar_push (TV_VARCONST
);
150 /* Don't output anything when a tentative file-scope definition
151 is seen. But at end of compilation, do output code for them.
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) */
157 || !DECL_DEFER_OUTPUT (decl
)
158 || DECL_INITIAL (decl
))
159 && !DECL_EXTERNAL (decl
))
161 if (TREE_CODE (decl
) != FUNCTION_DECL
)
162 varpool_finalize_decl (decl
);
164 assemble_variable (decl
, top_level
, at_end
, 0);
167 #ifdef ASM_FINISH_DECLARE_OBJECT
168 if (decl
== last_assemble_variable_decl
)
170 ASM_FINISH_DECLARE_OBJECT (asm_out_file
, decl
,
175 timevar_pop (TV_VARCONST
);
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
))
182 timevar_push (TV_SYMOUT
);
183 debug_hooks
->type_decl (decl
, !top_level
);
184 timevar_pop (TV_SYMOUT
);
187 /* Let cgraph know about the existence of variables. */
188 if (TREE_CODE (decl
) == VAR_DECL
&& !DECL_EXTERNAL (decl
))
192 /* Called after finishing a record, union or enumeral type. */
195 rest_of_type_compilation (tree type
, int toplev
)
197 /* Avoid confusing the debug information machinery when there are
199 if (errorcount
!= 0 || sorrycount
!= 0)
202 timevar_push (TV_SYMOUT
);
203 debug_hooks
->type_decl (TYPE_STUB_DECL (type
), !toplev
);
204 timevar_pop (TV_SYMOUT
);
210 finish_optimization_passes (void)
212 enum tree_dump_index i
;
213 struct dump_file_info
*dfi
;
216 timevar_push (TV_DUMP
);
217 if (profile_arc_flag
|| flag_test_coverage
|| flag_branch_probabilities
)
219 dump_file
= dump_begin (pass_profile
.static_pass_number
, NULL
);
222 dump_end (pass_profile
.static_pass_number
, dump_file
);
227 dump_file
= dump_begin (pass_combine
.static_pass_number
, NULL
);
230 dump_combine_total_stats (dump_file
);
231 dump_end (pass_combine
.static_pass_number
, dump_file
);
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
)
239 && (dfi
->flags
& TDF_GRAPH
) != 0
240 && (name
= get_dump_file_name (i
)) != NULL
)
242 finish_graph_dump_file (name
);
246 timevar_pop (TV_DUMP
);
250 gate_rest_of_compilation (void)
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
);
257 struct tree_opt_pass pass_rest_of_compilation
=
260 gate_rest_of_compilation
, /* gate */
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 */
275 gate_postreload (void)
277 return reload_completed
;
280 struct tree_opt_pass pass_postreload
=
283 gate_postreload
, /* gate */
287 0, /* static_pass_number */
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 */
299 /* The root of the compilation pass tree, once constructed. */
300 struct tree_opt_pass
*all_passes
, *all_ipa_passes
, *all_lowering_passes
;
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
307 register_one_dump_file (struct tree_opt_pass
*pass
, bool ipa
, int properties
)
309 char *dot_name
, *flag_name
, *glob_name
;
314 /* See below in next_pass_1. */
316 if (pass
->static_pass_number
!= -1)
317 sprintf (num
, "%d", ((int) pass
->static_pass_number
< 0
318 ? 1 : pass
->static_pass_number
));
320 dot_name
= concat (".", pass
->name
, num
, NULL
);
322 prefix
= "ipa-", flags
= TDF_IPA
;
323 else if (properties
& PROP_trees
)
324 prefix
= "tree-", flags
= TDF_TREE
;
326 prefix
= "rtl-", flags
= TDF_RTL
;
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
);
334 /* Recursive worker function for register_dump_files. */
337 register_dump_files_1 (struct tree_opt_pass
*pass
, bool ipa
, int properties
)
341 int new_properties
= (properties
| pass
->properties_provided
)
342 & ~pass
->properties_destroyed
;
345 register_one_dump_file (pass
, ipa
, new_properties
);
348 new_properties
= register_dump_files_1 (pass
->sub
, false,
351 /* If we have a gate, combine the properties that we could have with
352 and without the pass being examined. */
354 properties
&= new_properties
;
356 properties
= new_properties
;
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
367 properties that are guaranteed to be available at the beginning of
371 register_dump_files (struct tree_opt_pass
*pass
, bool ipa
, int properties
)
373 pass
->properties_required
|= properties
;
374 register_dump_files_1 (pass
, ipa
, properties
);
377 /* Add a pass to the pass list. Duplicate the pass if it's already
380 static struct tree_opt_pass
**
381 next_pass_1 (struct tree_opt_pass
**list
, struct tree_opt_pass
*pass
)
383 /* A nonzero static_pass_number indicates that the
384 pass is already in the list. */
385 if (pass
->static_pass_number
)
387 struct tree_opt_pass
*new;
389 new = xmalloc (sizeof (*new));
390 memcpy (new, pass
, sizeof (*new));
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. */
398 pass
->static_pass_number
-= 1;
399 new->static_pass_number
= -pass
->static_pass_number
;
406 pass
->static_pass_number
= -1;
410 return &(*list
)->next
;
414 /* Construct the pass tree. The sequencing of passes is driven by
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
422 If we are optimizing, cgraph_optimize is then invoked:
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
435 init_optimization_passes (void)
437 struct tree_opt_pass
**p
;
439 #define NEXT_PASS(PASS) (p = next_pass_1 (p, &PASS))
441 /* Interprocedural optimization passes. */
443 NEXT_PASS (pass_ipa_function_and_variable_visibility
);
444 NEXT_PASS (pass_ipa_early_inline
);
445 NEXT_PASS (pass_early_local_passes
);
446 NEXT_PASS (pass_ipa_increase_alignment
);
447 NEXT_PASS (pass_ipa_cp
);
448 NEXT_PASS (pass_ipa_inline
);
449 NEXT_PASS (pass_ipa_reference
);
450 NEXT_PASS (pass_ipa_pure_const
);
451 NEXT_PASS (pass_ipa_type_escape
);
452 NEXT_PASS (pass_ipa_pta
);
455 p
= &pass_ipa_early_inline
.sub
;
456 NEXT_PASS (pass_early_inline
);
457 NEXT_PASS (pass_inline_parameters
);
458 NEXT_PASS (pass_rebuild_cgraph_edges
);
461 /* All passes needed to lower the function into shape optimizers can
463 p
= &all_lowering_passes
;
464 NEXT_PASS (pass_remove_useless_stmts
);
465 NEXT_PASS (pass_mudflap_1
);
466 NEXT_PASS (pass_lower_omp
);
467 NEXT_PASS (pass_lower_cf
);
468 NEXT_PASS (pass_lower_eh
);
469 NEXT_PASS (pass_build_cfg
);
470 NEXT_PASS (pass_lower_complex_O0
);
471 NEXT_PASS (pass_lower_vector
);
472 NEXT_PASS (pass_warn_function_return
);
473 NEXT_PASS (pass_build_cgraph_edges
);
474 NEXT_PASS (pass_inline_parameters
);
477 p
= &pass_early_local_passes
.sub
;
478 NEXT_PASS (pass_tree_profile
);
479 NEXT_PASS (pass_cleanup_cfg
);
480 NEXT_PASS (pass_init_datastructures
);
481 NEXT_PASS (pass_expand_omp
);
482 NEXT_PASS (pass_all_early_optimizations
);
483 NEXT_PASS (pass_rebuild_cgraph_edges
);
484 NEXT_PASS (pass_inline_parameters
);
487 p
= &pass_all_early_optimizations
.sub
;
488 NEXT_PASS (pass_referenced_vars
);
489 NEXT_PASS (pass_reset_cc_flags
);
490 NEXT_PASS (pass_build_ssa
);
491 NEXT_PASS (pass_early_warn_uninitialized
);
492 NEXT_PASS (pass_rebuild_cgraph_edges
);
493 NEXT_PASS (pass_early_inline
);
494 NEXT_PASS (pass_cleanup_cfg
);
495 NEXT_PASS (pass_rename_ssa_copies
);
496 NEXT_PASS (pass_ccp
);
498 NEXT_PASS (pass_forwprop
);
499 NEXT_PASS (pass_copy_prop
);
500 NEXT_PASS (pass_merge_phi
);
501 NEXT_PASS (pass_dce
);
502 NEXT_PASS (pass_tail_recursion
);
503 NEXT_PASS (pass_release_ssa_names
);
508 NEXT_PASS (pass_apply_inline
);
509 NEXT_PASS (pass_all_optimizations
);
510 NEXT_PASS (pass_warn_function_noreturn
);
511 NEXT_PASS (pass_free_datastructures
);
512 NEXT_PASS (pass_mudflap_2
);
513 NEXT_PASS (pass_free_cfg_annotations
);
514 NEXT_PASS (pass_expand
);
515 NEXT_PASS (pass_rest_of_compilation
);
516 NEXT_PASS (pass_clean_state
);
519 p
= &pass_all_optimizations
.sub
;
520 NEXT_PASS (pass_create_structure_vars
);
521 NEXT_PASS (pass_may_alias
);
522 NEXT_PASS (pass_return_slot
);
523 NEXT_PASS (pass_rename_ssa_copies
);
525 /* Initial scalar cleanups. */
526 NEXT_PASS (pass_ccp
);
527 NEXT_PASS (pass_fre
);
528 NEXT_PASS (pass_dce
);
529 NEXT_PASS (pass_forwprop
);
530 NEXT_PASS (pass_copy_prop
);
531 NEXT_PASS (pass_merge_phi
);
532 NEXT_PASS (pass_vrp
);
533 NEXT_PASS (pass_dce
);
534 NEXT_PASS (pass_dominator
);
536 /* The only const/copy propagation opportunities left after
537 DOM should be due to degenerate PHI nodes. So rather than
538 run the full propagators, run a specialized pass which
539 only examines PHIs to discover const/copy propagation
541 NEXT_PASS (pass_phi_only_cprop
);
543 NEXT_PASS (pass_phiopt
);
544 NEXT_PASS (pass_may_alias
);
545 NEXT_PASS (pass_tail_recursion
);
546 NEXT_PASS (pass_profile
);
548 NEXT_PASS (pass_stdarg
);
549 NEXT_PASS (pass_lower_complex
);
550 NEXT_PASS (pass_sra
);
551 /* FIXME: SRA may generate arbitrary gimple code, exposing new
552 aliased and call-clobbered variables. As mentioned below,
553 pass_may_alias should be a TODO item. */
554 NEXT_PASS (pass_may_alias
);
555 NEXT_PASS (pass_rename_ssa_copies
);
556 NEXT_PASS (pass_dominator
);
558 /* The only const/copy propagation opportunities left after
559 DOM should be due to degenerate PHI nodes. So rather than
560 run the full propagators, run a specialized pass which
561 only examines PHIs to discover const/copy propagation
563 NEXT_PASS (pass_phi_only_cprop
);
565 NEXT_PASS (pass_reassoc
);
566 NEXT_PASS (pass_dce
);
567 NEXT_PASS (pass_dse
);
568 NEXT_PASS (pass_may_alias
);
569 NEXT_PASS (pass_forwprop
);
570 NEXT_PASS (pass_phiopt
);
571 NEXT_PASS (pass_object_sizes
);
572 NEXT_PASS (pass_store_ccp
);
573 NEXT_PASS (pass_store_copy_prop
);
574 NEXT_PASS (pass_fold_builtins
);
575 NEXT_PASS (pass_cse_sincos
);
576 /* FIXME: May alias should a TODO but for 4.0.0,
577 we add may_alias right after fold builtins
578 which can create arbitrary GIMPLE. */
579 NEXT_PASS (pass_may_alias
);
580 NEXT_PASS (pass_split_crit_edges
);
581 NEXT_PASS (pass_pre
);
582 NEXT_PASS (pass_may_alias
);
583 NEXT_PASS (pass_sink_code
);
584 NEXT_PASS (pass_tree_loop
);
585 NEXT_PASS (pass_cse_reciprocals
);
586 NEXT_PASS (pass_reassoc
);
587 NEXT_PASS (pass_vrp
);
588 NEXT_PASS (pass_dominator
);
590 /* The only const/copy propagation opportunities left after
591 DOM should be due to degenerate PHI nodes. So rather than
592 run the full propagators, run a specialized pass which
593 only examines PHIs to discover const/copy propagation
595 NEXT_PASS (pass_phi_only_cprop
);
597 NEXT_PASS (pass_cd_dce
);
599 /* FIXME: If DCE is not run before checking for uninitialized uses,
600 we may get false warnings (e.g., testsuite/gcc.dg/uninit-5.c).
601 However, this also causes us to misdiagnose cases that should be
602 real warnings (e.g., testsuite/gcc.dg/pr18501.c).
604 To fix the false positives in uninit-5.c, we would have to
605 account for the predicates protecting the set and the use of each
606 variable. Using a representation like Gated Single Assignment
608 NEXT_PASS (pass_late_warn_uninitialized
);
609 NEXT_PASS (pass_dse
);
610 NEXT_PASS (pass_forwprop
);
611 NEXT_PASS (pass_phiopt
);
612 NEXT_PASS (pass_tail_calls
);
613 NEXT_PASS (pass_rename_ssa_copies
);
614 NEXT_PASS (pass_uncprop
);
615 NEXT_PASS (pass_del_ssa
);
616 NEXT_PASS (pass_nrv
);
617 NEXT_PASS (pass_mark_used_blocks
);
618 NEXT_PASS (pass_cleanup_cfg_post_optimizing
);
621 p
= &pass_tree_loop
.sub
;
622 NEXT_PASS (pass_tree_loop_init
);
623 NEXT_PASS (pass_copy_prop
);
624 NEXT_PASS (pass_lim
);
625 NEXT_PASS (pass_tree_unswitch
);
626 NEXT_PASS (pass_scev_cprop
);
627 NEXT_PASS (pass_empty_loop
);
628 NEXT_PASS (pass_record_bounds
);
629 NEXT_PASS (pass_linear_transform
);
630 NEXT_PASS (pass_iv_canon
);
631 NEXT_PASS (pass_if_conversion
);
632 NEXT_PASS (pass_vectorize
);
633 /* NEXT_PASS (pass_may_alias) cannot be done again because the
634 vectorizer creates alias relations that are not supported by
636 NEXT_PASS (pass_complete_unroll
);
637 NEXT_PASS (pass_loop_prefetch
);
638 NEXT_PASS (pass_iv_optimize
);
639 NEXT_PASS (pass_tree_loop_done
);
642 p
= &pass_vectorize
.sub
;
643 NEXT_PASS (pass_lower_vector_ssa
);
644 NEXT_PASS (pass_dce_loop
);
648 NEXT_PASS (pass_rtl_loop_init
);
649 NEXT_PASS (pass_rtl_move_loop_invariants
);
650 NEXT_PASS (pass_rtl_unswitch
);
651 NEXT_PASS (pass_rtl_unroll_and_peel_loops
);
652 NEXT_PASS (pass_rtl_doloop
);
653 NEXT_PASS (pass_rtl_loop_done
);
656 p
= &pass_rest_of_compilation
.sub
;
657 NEXT_PASS (pass_init_function
);
658 NEXT_PASS (pass_jump
);
659 NEXT_PASS (pass_insn_locators_initialize
);
660 NEXT_PASS (pass_rtl_eh
);
661 NEXT_PASS (pass_initial_value_sets
);
662 NEXT_PASS (pass_unshare_all_rtl
);
663 NEXT_PASS (pass_instantiate_virtual_regs
);
664 NEXT_PASS (pass_jump2
);
665 NEXT_PASS (pass_cse
);
666 NEXT_PASS (pass_rtl_fwprop
);
667 NEXT_PASS (pass_gcse
);
668 NEXT_PASS (pass_jump_bypass
);
669 NEXT_PASS (pass_rtl_ifcvt
);
670 NEXT_PASS (pass_tracer
);
671 /* Perform loop optimizations. It might be better to do them a bit
672 sooner, but we want the profile feedback to work more
674 NEXT_PASS (pass_loop2
);
675 NEXT_PASS (pass_web
);
676 NEXT_PASS (pass_cse2
);
677 NEXT_PASS (pass_rtl_fwprop_addr
);
678 NEXT_PASS (pass_life
);
679 NEXT_PASS (pass_combine
);
680 NEXT_PASS (pass_if_after_combine
);
681 NEXT_PASS (pass_partition_blocks
);
682 NEXT_PASS (pass_regmove
);
683 NEXT_PASS (pass_split_all_insns
);
684 NEXT_PASS (pass_mode_switching
);
685 NEXT_PASS (pass_see
);
686 NEXT_PASS (pass_recompute_reg_usage
);
687 NEXT_PASS (pass_sms
);
688 NEXT_PASS (pass_sched
);
689 NEXT_PASS (pass_local_alloc
);
690 NEXT_PASS (pass_global_alloc
);
691 NEXT_PASS (pass_postreload
);
694 p
= &pass_postreload
.sub
;
695 NEXT_PASS (pass_postreload_cse
);
696 NEXT_PASS (pass_gcse2
);
697 NEXT_PASS (pass_flow2
);
698 NEXT_PASS (pass_rtl_seqabstr
);
699 NEXT_PASS (pass_stack_adjustments
);
700 NEXT_PASS (pass_peephole2
);
701 NEXT_PASS (pass_if_after_reload
);
702 NEXT_PASS (pass_regrename
);
703 NEXT_PASS (pass_reorder_blocks
);
704 NEXT_PASS (pass_branch_target_load_optimize
);
705 NEXT_PASS (pass_leaf_regs
);
706 NEXT_PASS (pass_sched2
);
707 NEXT_PASS (pass_split_before_regstack
);
708 NEXT_PASS (pass_stack_regs
);
709 NEXT_PASS (pass_compute_alignments
);
710 NEXT_PASS (pass_duplicate_computed_gotos
);
711 NEXT_PASS (pass_variable_tracking
);
712 NEXT_PASS (pass_free_cfg
);
713 NEXT_PASS (pass_machine_reorg
);
714 NEXT_PASS (pass_cleanup_barriers
);
715 NEXT_PASS (pass_delay_slots
);
716 NEXT_PASS (pass_split_for_shorten_branches
);
717 NEXT_PASS (pass_convert_to_eh_region_ranges
);
718 NEXT_PASS (pass_shorten_branches
);
719 NEXT_PASS (pass_set_nothrow_function_flags
);
720 NEXT_PASS (pass_final
);
725 /* Register the passes with the tree dump code. */
726 register_dump_files (all_lowering_passes
, false, PROP_gimple_any
);
727 all_lowering_passes
->todo_flags_start
|= TODO_set_props
;
728 register_dump_files (all_ipa_passes
, true,
729 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
731 register_dump_files (all_passes
, false,
732 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
736 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
737 function CALLBACK for every function in the call graph. Otherwise,
738 call CALLBACK on the current function. */
741 do_per_function (void (*callback
) (void *data
), void *data
)
743 if (current_function_decl
)
747 struct cgraph_node
*node
;
748 for (node
= cgraph_nodes
; node
; node
= node
->next
)
751 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
752 current_function_decl
= node
->decl
;
754 free_dominance_info (CDI_DOMINATORS
);
755 free_dominance_info (CDI_POST_DOMINATORS
);
756 current_function_decl
= NULL
;
763 /* Because inlining might remove no-longer reachable nodes, we need to
764 keep the array visible to garbage collector to avoid reading collected
767 static GTY ((length ("nnodes"))) struct cgraph_node
**order
;
769 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
770 function CALLBACK for every function in the call graph. Otherwise,
771 call CALLBACK on the current function. */
774 do_per_function_toporder (void (*callback
) (void *data
), void *data
)
778 if (current_function_decl
)
783 order
= ggc_alloc (sizeof (*order
) * cgraph_n_nodes
);
784 nnodes
= cgraph_postorder (order
);
785 for (i
= nnodes
- 1; i
>= 0; i
--)
787 struct cgraph_node
*node
= order
[i
];
789 /* Allow possibly removed nodes to be garbage collected. */
791 if (node
->analyzed
&& (node
->needed
|| node
->reachable
))
793 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
794 current_function_decl
= node
->decl
;
796 free_dominance_info (CDI_DOMINATORS
);
797 free_dominance_info (CDI_POST_DOMINATORS
);
798 current_function_decl
= NULL
;
809 /* Perform all TODO actions that ought to be done on each function. */
812 execute_function_todo (void *data
)
814 unsigned int flags
= (size_t)data
;
815 if (cfun
->curr_properties
& PROP_ssa
)
816 flags
|= TODO_verify_ssa
;
817 flags
&= ~cfun
->last_verified
;
821 /* Always cleanup the CFG before trying to update SSA. */
822 if (flags
& TODO_cleanup_cfg
)
827 cleanup
= cleanup_tree_cfg_loop ();
829 cleanup
= cleanup_tree_cfg ();
831 if (cleanup
&& (cfun
->curr_properties
& PROP_ssa
))
832 flags
|= TODO_remove_unused_locals
;
834 /* When cleanup_tree_cfg merges consecutive blocks, it may
835 perform some simplistic propagation when removing single
836 valued PHI nodes. This propagation may, in turn, cause the
837 SSA form to become out-of-date (see PR 22037). So, even
838 if the parent pass had not scheduled an SSA update, we may
839 still need to do one. */
840 if (!(flags
& TODO_update_ssa_any
) && need_ssa_update_p ())
841 flags
|= TODO_update_ssa
;
844 if (flags
& TODO_update_ssa_any
)
846 unsigned update_flags
= flags
& TODO_update_ssa_any
;
847 update_ssa (update_flags
);
848 cfun
->last_verified
&= ~TODO_verify_ssa
;
851 if (flags
& TODO_remove_unused_locals
)
852 remove_unused_locals ();
854 if ((flags
& TODO_dump_func
)
855 && dump_file
&& current_function_decl
)
857 if (cfun
->curr_properties
& PROP_trees
)
858 dump_function_to_file (current_function_decl
,
859 dump_file
, dump_flags
);
862 if (dump_flags
& TDF_SLIM
)
863 print_rtl_slim_with_bb (dump_file
, get_insns (), dump_flags
);
864 else if ((cfun
->curr_properties
& PROP_cfg
)
865 && (dump_flags
& TDF_BLOCKS
))
866 print_rtl_with_bb (dump_file
, get_insns ());
868 print_rtl (dump_file
, get_insns ());
870 if (cfun
->curr_properties
& PROP_cfg
871 && graph_dump_format
!= no_graph
872 && (dump_flags
& TDF_GRAPH
))
873 print_rtl_graph_with_bb (dump_file_name
, get_insns ());
876 /* Flush the file. If verification fails, we won't be able to
877 close the file before aborting. */
881 #if defined ENABLE_CHECKING
882 if (flags
& TODO_verify_ssa
)
884 if (flags
& TODO_verify_flow
)
886 if (flags
& TODO_verify_stmts
)
888 if (flags
& TODO_verify_loops
)
889 verify_loop_closed_ssa ();
892 cfun
->last_verified
= flags
& TODO_verify_all
;
895 /* Perform all TODO actions. */
897 execute_todo (unsigned int flags
)
899 #if defined ENABLE_CHECKING
900 if (need_ssa_update_p ())
901 gcc_assert (flags
& TODO_update_ssa_any
);
904 do_per_function (execute_function_todo
, (void *)(size_t) flags
);
906 /* Always remove functions just as before inlining: IPA passes might be
907 interested to see bodies of extern inline functions that are not inlined
908 to analyze side effects. The full removal is done just at the end
909 of IPA pass queue. */
910 if (flags
& TODO_remove_functions
)
911 cgraph_remove_unreachable_nodes (true, dump_file
);
913 if ((flags
& TODO_dump_cgraph
)
914 && dump_file
&& !current_function_decl
)
916 dump_cgraph (dump_file
);
917 /* Flush the file. If verification fails, we won't be able to
918 close the file before aborting. */
922 if (flags
& TODO_ggc_collect
)
928 /* Clear the last verified flag. */
931 clear_last_verified (void *data ATTRIBUTE_UNUSED
)
933 cfun
->last_verified
= 0;
936 /* Helper function. Verify that the properties has been turn into the
937 properties expected by the pass. */
939 #ifdef ENABLE_CHECKING
941 verify_curr_properties (void *data
)
943 unsigned int props
= (size_t)data
;
944 gcc_assert ((cfun
->curr_properties
& props
) == props
);
948 /* After executing the pass, apply expected changes to the function
951 update_properties_after_pass (void *data
)
953 struct tree_opt_pass
*pass
= data
;
954 cfun
->curr_properties
= (cfun
->curr_properties
| pass
->properties_provided
)
955 & ~pass
->properties_destroyed
;
959 execute_one_pass (struct tree_opt_pass
*pass
)
961 bool initializing_dump
;
962 unsigned int todo_after
= 0;
964 /* See if we're supposed to run this pass. */
965 if (pass
->gate
&& !pass
->gate ())
968 if (!quiet_flag
&& !cfun
)
969 fprintf (stderr
, " <%s>", pass
->name
? pass
->name
: "");
971 if (pass
->todo_flags_start
& TODO_set_props
)
972 cfun
->curr_properties
= pass
->properties_required
;
974 /* Note that the folders should only create gimple expressions.
975 This is a hack until the new folder is ready. */
976 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
978 /* Run pre-pass verification. */
979 execute_todo (pass
->todo_flags_start
);
981 #ifdef ENABLE_CHECKING
982 do_per_function (verify_curr_properties
,
983 (void *)(size_t)pass
->properties_required
);
986 /* If a dump file name is present, open it if enabled. */
987 if (pass
->static_pass_number
!= -1)
989 initializing_dump
= !dump_initialized_p (pass
->static_pass_number
);
990 dump_file_name
= get_dump_file_name (pass
->static_pass_number
);
991 dump_file
= dump_begin (pass
->static_pass_number
, &dump_flags
);
992 if (dump_file
&& current_function_decl
)
994 const char *dname
, *aname
;
995 dname
= lang_hooks
.decl_printable_name (current_function_decl
, 2);
996 aname
= (IDENTIFIER_POINTER
997 (DECL_ASSEMBLER_NAME (current_function_decl
)));
998 fprintf (dump_file
, "\n;; Function %s (%s)%s\n\n", dname
, aname
,
999 cfun
->function_frequency
== FUNCTION_FREQUENCY_HOT
1001 : cfun
->function_frequency
== FUNCTION_FREQUENCY_UNLIKELY_EXECUTED
1002 ? " (unlikely executed)"
1007 initializing_dump
= false;
1009 /* If a timevar is present, start it. */
1011 timevar_push (pass
->tv_id
);
1016 todo_after
= pass
->execute ();
1017 do_per_function (clear_last_verified
, NULL
);
1022 timevar_pop (pass
->tv_id
);
1024 do_per_function (update_properties_after_pass
, pass
);
1026 if (initializing_dump
1028 && graph_dump_format
!= no_graph
1029 && (cfun
->curr_properties
& (PROP_cfg
| PROP_rtl
))
1030 == (PROP_cfg
| PROP_rtl
))
1032 get_dump_file_info (pass
->static_pass_number
)->flags
|= TDF_GRAPH
;
1033 dump_flags
|= TDF_GRAPH
;
1034 clean_graph_dump_file (dump_file_name
);
1037 /* Run post-pass cleanup and verification. */
1038 execute_todo (todo_after
| pass
->todo_flags_finish
);
1040 if (!current_function_decl
)
1041 cgraph_process_new_functions ();
1043 /* Flush and close dump file. */
1046 free ((char *) dump_file_name
);
1047 dump_file_name
= NULL
;
1052 dump_end (pass
->static_pass_number
, dump_file
);
1060 execute_pass_list (struct tree_opt_pass
*pass
)
1064 if (execute_one_pass (pass
) && pass
->sub
)
1065 execute_pass_list (pass
->sub
);
1071 /* Same as execute_pass_list but assume that subpasses of IPA passes
1072 are local passes. */
1074 execute_ipa_pass_list (struct tree_opt_pass
*pass
)
1078 gcc_assert (!current_function_decl
);
1080 if (execute_one_pass (pass
) && pass
->sub
)
1081 do_per_function_toporder ((void (*)(void *))execute_pass_list
,
1083 if (!current_function_decl
)
1084 cgraph_process_new_functions ();
1089 #include "gt-passes.h"