1 /* Top level of GCC compilers (cc1, cc1plus, etc.)
2 Copyright (C) 1987-2015 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 /* This is the top level of cc1/c++.
21 It parses command args, opens files, invokes the various passes
22 in the proper order, and counts the time used by each.
23 Error messages and low-level interface to malloc also handled here. */
27 #include "coretypes.h"
35 #include "fold-const.h"
39 #include "insn-attr.h"
40 #include "insn-config.h"
41 #include "insn-flags.h"
56 #include "diagnostic-core.h"
61 #include "langhooks.h"
63 #include "hosthooks.h"
66 #include "value-prof.h"
67 #include "tree-inline.h"
68 #include "internal-fn.h"
70 #include "tree-ssa-loop-manip.h"
71 #include "tree-into-ssa.h"
74 #include "tree-pass.h"
75 #include "tree-dump.h"
77 #include "lto-streamer.h"
79 #include "ipa-utils.h"
80 #include "tree-pretty-print.h" /* for dump_function_header */
82 #include "pass_manager.h"
84 #include "tree-ssa-live.h" /* For remove_unused_locals. */
85 #include "tree-cfgcleanup.h"
89 /* This is used for debugging. It allows the current pass to printed
90 from anywhere in compilation.
91 The variable current_pass is also used for statistics and plugins. */
92 opt_pass
*current_pass
;
94 static void register_pass_name (opt_pass
*, const char *);
96 /* Most passes are single-instance (within their context) and thus don't
97 need to implement cloning, but passes that support multiple instances
98 *must* provide their own implementation of the clone method.
100 Handle this by providing a default implemenation, but make it a fatal
106 internal_error ("pass %s does not support cloning", name
);
110 opt_pass::gate (function
*)
116 opt_pass::execute (function
*)
121 opt_pass::opt_pass (const pass_data
&data
, context
*ctxt
)
125 static_pass_number (0),
132 pass_manager::execute_early_local_passes ()
134 execute_pass_list (cfun
, pass_build_ssa_passes_1
->sub
);
135 if (flag_check_pointer_bounds
)
136 execute_pass_list (cfun
, pass_chkp_instrumentation_passes_1
->sub
);
137 execute_pass_list (cfun
, pass_local_optimization_passes_1
->sub
);
141 pass_manager::execute_pass_mode_switching ()
143 return pass_mode_switching_1
->execute (cfun
);
147 /* Call from anywhere to find out what pass this is. Useful for
148 printing out debugging information deep inside an service
151 print_current_pass (FILE *file
)
154 fprintf (file
, "current pass = %s (%d)\n",
155 current_pass
->name
, current_pass
->static_pass_number
);
157 fprintf (file
, "no current pass.\n");
161 /* Call from the debugger to get the current pass name. */
165 print_current_pass (stderr
);
170 /* Global variables used to communicate with passes. */
172 bool first_pass_instance
;
175 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
178 This does nothing for local (non-static) variables, unless the
179 variable is a register variable with DECL_ASSEMBLER_NAME set. In
180 that case, or if the variable is not an automatic, it sets up the
181 RTL and outputs any assembler code (label definition, storage
182 allocation and initialization).
184 DECL is the declaration. TOP_LEVEL is nonzero
185 if this declaration is not within a function. */
188 rest_of_decl_compilation (tree decl
,
192 bool finalize
= true;
194 /* We deferred calling assemble_alias so that we could collect
195 other attributes such as visibility. Emit the alias now. */
199 alias
= lookup_attribute ("alias", DECL_ATTRIBUTES (decl
));
202 alias
= TREE_VALUE (TREE_VALUE (alias
));
203 alias
= get_identifier (TREE_STRING_POINTER (alias
));
204 /* A quirk of the initial implementation of aliases required that the
205 user add "extern" to all of them. Which is silly, but now
206 historical. Do note that the symbol is in fact locally defined. */
207 DECL_EXTERNAL (decl
) = 0;
208 TREE_STATIC (decl
) = 1;
209 assemble_alias (decl
, alias
);
214 /* Can't defer this, because it needs to happen before any
215 later function definitions are processed. */
216 if (DECL_ASSEMBLER_NAME_SET_P (decl
) && DECL_REGISTER (decl
))
217 make_decl_rtl (decl
);
219 /* Forward declarations for nested functions are not "external",
220 but we need to treat them as if they were. */
221 if (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)
222 || TREE_CODE (decl
) == FUNCTION_DECL
)
224 timevar_push (TV_VARCONST
);
226 /* Don't output anything when a tentative file-scope definition
227 is seen. But at end of compilation, do output code for them.
229 We do output all variables and rely on
230 callgraph code to defer them except for forward declarations
231 (see gcc.c-torture/compile/920624-1.c) */
233 || !DECL_DEFER_OUTPUT (decl
)
234 || DECL_INITIAL (decl
))
235 && (TREE_CODE (decl
) != VAR_DECL
|| !DECL_HAS_VALUE_EXPR_P (decl
))
236 && !DECL_EXTERNAL (decl
))
238 /* When reading LTO unit, we also read varpool, so do not
240 if (in_lto_p
&& !at_end
)
242 else if (finalize
&& TREE_CODE (decl
) != FUNCTION_DECL
)
243 varpool_node::finalize_decl (decl
);
246 #ifdef ASM_FINISH_DECLARE_OBJECT
247 if (decl
== last_assemble_variable_decl
)
249 ASM_FINISH_DECLARE_OBJECT (asm_out_file
, decl
,
254 timevar_pop (TV_VARCONST
);
256 else if (TREE_CODE (decl
) == TYPE_DECL
257 /* Like in rest_of_type_compilation, avoid confusing the debug
258 information machinery when there are errors. */
261 timevar_push (TV_SYMOUT
);
262 debug_hooks
->type_decl (decl
, !top_level
);
263 timevar_pop (TV_SYMOUT
);
266 /* Let cgraph know about the existence of variables. */
267 if (in_lto_p
&& !at_end
)
269 else if (TREE_CODE (decl
) == VAR_DECL
&& !DECL_EXTERNAL (decl
)
270 && TREE_STATIC (decl
))
271 varpool_node::get_create (decl
);
273 /* Generate early debug for global variables. Any local variables will
274 be handled by either handling reachable functions from
275 finalize_compilation_unit (and by consequence, locally scoped
276 symbols), or by rest_of_type_compilation below.
278 Also, pick up function prototypes, which will be mostly ignored
279 by the different early_global_decl() hooks, but will at least be
280 used by Go's hijack of the debug_hooks to implement
283 && (TREE_CODE (decl
) != FUNCTION_DECL
284 /* This will pick up function prototypes with no bodies,
285 which are not visible in finalize_compilation_unit()
286 while iterating with FOR_EACH_*_FUNCTION through the
288 || !DECL_SAVED_TREE (decl
))
290 /* We need to check both decl_function_context and
291 current_function_decl here to make sure local extern
292 declarations end up with the correct context.
294 For local extern declarations, decl_function_context is
295 empty, but current_function_decl is set to the function where
296 the extern was declared . Without the check for
297 !current_function_decl below, the local extern ends up
298 incorrectly with a top-level context.
310 extern int i; // Local extern declaration.
317 && !decl_function_context (decl
)
318 && !current_function_decl
319 && DECL_SOURCE_LOCATION (decl
) != BUILTINS_LOCATION
320 && !decl_type_context (decl
))
321 (*debug_hooks
->early_global_decl
) (decl
);
324 /* Called after finishing a record, union or enumeral type. */
327 rest_of_type_compilation (tree type
, int toplev
)
329 /* Avoid confusing the debug information machinery when there are
334 timevar_push (TV_SYMOUT
);
335 debug_hooks
->type_decl (TYPE_STUB_DECL (type
), !toplev
);
336 timevar_pop (TV_SYMOUT
);
343 finish_optimization_passes (void)
346 struct dump_file_info
*dfi
;
348 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
350 timevar_push (TV_DUMP
);
351 if (profile_arc_flag
|| flag_test_coverage
|| flag_branch_probabilities
)
353 dumps
->dump_start (pass_profile_1
->static_pass_number
, NULL
);
355 dumps
->dump_finish (pass_profile_1
->static_pass_number
);
360 dumps
->dump_start (pass_profile_1
->static_pass_number
, NULL
);
361 print_combine_total_stats ();
362 dumps
->dump_finish (pass_profile_1
->static_pass_number
);
365 /* Do whatever is necessary to finish printing the graphs. */
366 for (i
= TDI_end
; (dfi
= dumps
->get_dump_file_info (i
)) != NULL
; ++i
)
367 if (dumps
->dump_initialized_p (i
)
368 && (dfi
->pflags
& TDF_GRAPH
) != 0
369 && (name
= dumps
->get_dump_file_name (i
)) != NULL
)
371 finish_graph_dump_file (name
);
375 timevar_pop (TV_DUMP
);
379 execute_build_ssa_passes (void)
381 /* Once this pass (and its sub-passes) are complete, all functions
382 will be in SSA form. Technically this state change is happening
383 a tad early, since the sub-passes have not yet run, but since
384 none of the sub-passes are IPA passes and do not create new
385 functions, this is ok. We're setting this value for the benefit
386 of IPA passes that follow. */
387 if (symtab
->state
< IPA_SSA
)
388 symtab
->state
= IPA_SSA
;
394 const pass_data pass_data_build_ssa_passes
=
396 SIMPLE_IPA_PASS
, /* type */
397 "build_ssa_passes", /* name */
398 OPTGROUP_NONE
, /* optinfo_flags */
399 TV_EARLY_LOCAL
, /* tv_id */
400 0, /* properties_required */
401 0, /* properties_provided */
402 0, /* properties_destroyed */
403 0, /* todo_flags_start */
404 /* todo_flags_finish is executed before subpases. For this reason
405 it makes no sense to remove unreachable functions here. */
406 0, /* todo_flags_finish */
409 class pass_build_ssa_passes
: public simple_ipa_opt_pass
412 pass_build_ssa_passes (gcc::context
*ctxt
)
413 : simple_ipa_opt_pass (pass_data_build_ssa_passes
, ctxt
)
416 /* opt_pass methods: */
417 virtual bool gate (function
*)
419 /* Don't bother doing anything if the program has errors. */
420 return (!seen_error () && !in_lto_p
);
423 virtual unsigned int execute (function
*)
425 return execute_build_ssa_passes ();
428 }; // class pass_build_ssa_passes
430 const pass_data pass_data_chkp_instrumentation_passes
=
432 SIMPLE_IPA_PASS
, /* type */
433 "chkp_passes", /* name */
434 OPTGROUP_NONE
, /* optinfo_flags */
436 0, /* properties_required */
437 0, /* properties_provided */
438 0, /* properties_destroyed */
439 0, /* todo_flags_start */
440 0, /* todo_flags_finish */
443 class pass_chkp_instrumentation_passes
: public simple_ipa_opt_pass
446 pass_chkp_instrumentation_passes (gcc::context
*ctxt
)
447 : simple_ipa_opt_pass (pass_data_chkp_instrumentation_passes
, ctxt
)
450 /* opt_pass methods: */
451 virtual bool gate (function
*)
453 /* Don't bother doing anything if the program has errors. */
454 return (flag_check_pointer_bounds
455 && !seen_error () && !in_lto_p
);
458 }; // class pass_chkp_instrumentation_passes
460 const pass_data pass_data_local_optimization_passes
=
462 SIMPLE_IPA_PASS
, /* type */
463 "opt_local_passes", /* name */
464 OPTGROUP_NONE
, /* optinfo_flags */
466 0, /* properties_required */
467 0, /* properties_provided */
468 0, /* properties_destroyed */
469 0, /* todo_flags_start */
470 0, /* todo_flags_finish */
473 class pass_local_optimization_passes
: public simple_ipa_opt_pass
476 pass_local_optimization_passes (gcc::context
*ctxt
)
477 : simple_ipa_opt_pass (pass_data_local_optimization_passes
, ctxt
)
480 /* opt_pass methods: */
481 virtual bool gate (function
*)
483 /* Don't bother doing anything if the program has errors. */
484 return (!seen_error () && !in_lto_p
);
487 }; // class pass_local_optimization_passes
491 simple_ipa_opt_pass
*
492 make_pass_build_ssa_passes (gcc::context
*ctxt
)
494 return new pass_build_ssa_passes (ctxt
);
497 simple_ipa_opt_pass
*
498 make_pass_chkp_instrumentation_passes (gcc::context
*ctxt
)
500 return new pass_chkp_instrumentation_passes (ctxt
);
503 simple_ipa_opt_pass
*
504 make_pass_local_optimization_passes (gcc::context
*ctxt
)
506 return new pass_local_optimization_passes (ctxt
);
511 const pass_data pass_data_all_early_optimizations
=
513 GIMPLE_PASS
, /* type */
514 "early_optimizations", /* name */
515 OPTGROUP_NONE
, /* optinfo_flags */
517 0, /* properties_required */
518 0, /* properties_provided */
519 0, /* properties_destroyed */
520 0, /* todo_flags_start */
521 0, /* todo_flags_finish */
524 class pass_all_early_optimizations
: public gimple_opt_pass
527 pass_all_early_optimizations (gcc::context
*ctxt
)
528 : gimple_opt_pass (pass_data_all_early_optimizations
, ctxt
)
531 /* opt_pass methods: */
532 virtual bool gate (function
*)
534 return (optimize
>= 1
535 /* Don't bother doing anything if the program has errors. */
539 }; // class pass_all_early_optimizations
543 static gimple_opt_pass
*
544 make_pass_all_early_optimizations (gcc::context
*ctxt
)
546 return new pass_all_early_optimizations (ctxt
);
551 const pass_data pass_data_all_optimizations
=
553 GIMPLE_PASS
, /* type */
554 "*all_optimizations", /* name */
555 OPTGROUP_NONE
, /* optinfo_flags */
556 TV_OPTIMIZE
, /* tv_id */
557 0, /* properties_required */
558 0, /* properties_provided */
559 0, /* properties_destroyed */
560 0, /* todo_flags_start */
561 0, /* todo_flags_finish */
564 class pass_all_optimizations
: public gimple_opt_pass
567 pass_all_optimizations (gcc::context
*ctxt
)
568 : gimple_opt_pass (pass_data_all_optimizations
, ctxt
)
571 /* opt_pass methods: */
572 virtual bool gate (function
*) { return optimize
>= 1 && !optimize_debug
; }
574 }; // class pass_all_optimizations
578 static gimple_opt_pass
*
579 make_pass_all_optimizations (gcc::context
*ctxt
)
581 return new pass_all_optimizations (ctxt
);
586 const pass_data pass_data_all_optimizations_g
=
588 GIMPLE_PASS
, /* type */
589 "*all_optimizations_g", /* name */
590 OPTGROUP_NONE
, /* optinfo_flags */
591 TV_OPTIMIZE
, /* tv_id */
592 0, /* properties_required */
593 0, /* properties_provided */
594 0, /* properties_destroyed */
595 0, /* todo_flags_start */
596 0, /* todo_flags_finish */
599 class pass_all_optimizations_g
: public gimple_opt_pass
602 pass_all_optimizations_g (gcc::context
*ctxt
)
603 : gimple_opt_pass (pass_data_all_optimizations_g
, ctxt
)
606 /* opt_pass methods: */
607 virtual bool gate (function
*) { return optimize
>= 1 && optimize_debug
; }
609 }; // class pass_all_optimizations_g
613 static gimple_opt_pass
*
614 make_pass_all_optimizations_g (gcc::context
*ctxt
)
616 return new pass_all_optimizations_g (ctxt
);
621 const pass_data pass_data_rest_of_compilation
=
624 "*rest_of_compilation", /* name */
625 OPTGROUP_NONE
, /* optinfo_flags */
626 TV_REST_OF_COMPILATION
, /* tv_id */
627 PROP_rtl
, /* properties_required */
628 0, /* properties_provided */
629 0, /* properties_destroyed */
630 0, /* todo_flags_start */
631 0, /* todo_flags_finish */
634 class pass_rest_of_compilation
: public rtl_opt_pass
637 pass_rest_of_compilation (gcc::context
*ctxt
)
638 : rtl_opt_pass (pass_data_rest_of_compilation
, ctxt
)
641 /* opt_pass methods: */
642 virtual bool gate (function
*)
644 /* Early return if there were errors. We can run afoul of our
645 consistency checks, and there's not really much point in fixing them. */
646 return !(rtl_dump_and_exit
|| flag_syntax_only
|| seen_error ());
649 }; // class pass_rest_of_compilation
653 static rtl_opt_pass
*
654 make_pass_rest_of_compilation (gcc::context
*ctxt
)
656 return new pass_rest_of_compilation (ctxt
);
661 const pass_data pass_data_postreload
=
664 "*all-postreload", /* name */
665 OPTGROUP_NONE
, /* optinfo_flags */
666 TV_POSTRELOAD
, /* tv_id */
667 PROP_rtl
, /* properties_required */
668 0, /* properties_provided */
669 0, /* properties_destroyed */
670 0, /* todo_flags_start */
671 0, /* todo_flags_finish */
674 class pass_postreload
: public rtl_opt_pass
677 pass_postreload (gcc::context
*ctxt
)
678 : rtl_opt_pass (pass_data_postreload
, ctxt
)
681 /* opt_pass methods: */
682 virtual bool gate (function
*) { return reload_completed
; }
684 }; // class pass_postreload
688 static rtl_opt_pass
*
689 make_pass_postreload (gcc::context
*ctxt
)
691 return new pass_postreload (ctxt
);
696 const pass_data pass_data_late_compilation
=
699 "*all-late_compilation", /* name */
700 OPTGROUP_NONE
, /* optinfo_flags */
701 TV_LATE_COMPILATION
, /* tv_id */
702 PROP_rtl
, /* properties_required */
703 0, /* properties_provided */
704 0, /* properties_destroyed */
705 0, /* todo_flags_start */
706 0, /* todo_flags_finish */
709 class pass_late_compilation
: public rtl_opt_pass
712 pass_late_compilation (gcc::context
*ctxt
)
713 : rtl_opt_pass (pass_data_late_compilation
, ctxt
)
716 /* opt_pass methods: */
717 virtual bool gate (function
*)
719 return reload_completed
|| targetm
.no_register_allocation
;
722 }; // class pass_late_compilation
726 static rtl_opt_pass
*
727 make_pass_late_compilation (gcc::context
*ctxt
)
729 return new pass_late_compilation (ctxt
);
734 /* Set the static pass number of pass PASS to ID and record that
735 in the mapping from static pass number to pass. */
739 set_pass_for_id (int id
, opt_pass
*pass
)
741 pass
->static_pass_number
= id
;
742 if (passes_by_id_size
<= id
)
744 passes_by_id
= XRESIZEVEC (opt_pass
*, passes_by_id
, id
+ 1);
745 memset (passes_by_id
+ passes_by_id_size
, 0,
746 (id
+ 1 - passes_by_id_size
) * sizeof (void *));
747 passes_by_id_size
= id
+ 1;
749 passes_by_id
[id
] = pass
;
752 /* Return the pass with the static pass number ID. */
755 pass_manager::get_pass_for_id (int id
) const
757 if (id
>= passes_by_id_size
)
759 return passes_by_id
[id
];
762 /* Iterate over the pass tree allocating dump file numbers. We want
763 to do this depth first, and independent of whether the pass is
767 register_one_dump_file (opt_pass
*pass
)
769 g
->get_passes ()->register_one_dump_file (pass
);
773 pass_manager::register_one_dump_file (opt_pass
*pass
)
775 char *dot_name
, *flag_name
, *glob_name
;
776 const char *name
, *full_name
, *prefix
;
779 int optgroup_flags
= OPTGROUP_NONE
;
780 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
782 /* See below in next_pass_1. */
784 if (pass
->static_pass_number
!= -1)
785 sprintf (num
, "%d", ((int) pass
->static_pass_number
< 0
786 ? 1 : pass
->static_pass_number
));
788 /* The name is both used to identify the pass for the purposes of plugins,
789 and to specify dump file name and option.
790 The latter two might want something short which is not quite unique; for
791 that reason, we may have a disambiguating prefix, followed by a space
792 to mark the start of the following dump file name / option string. */
793 name
= strchr (pass
->name
, ' ');
794 name
= name
? name
+ 1 : pass
->name
;
795 dot_name
= concat (".", name
, num
, NULL
);
796 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
800 optgroup_flags
|= OPTGROUP_IPA
;
802 else if (pass
->type
== GIMPLE_PASS
)
813 flag_name
= concat (prefix
, name
, num
, NULL
);
814 glob_name
= concat (prefix
, name
, NULL
);
815 optgroup_flags
|= pass
->optinfo_flags
;
816 /* For any passes that do not have an optgroup set, and which are not
817 IPA passes setup above, set the optgroup to OPTGROUP_OTHER so that
818 any dump messages are emitted properly under -fopt-info(-optall). */
819 if (optgroup_flags
== OPTGROUP_NONE
)
820 optgroup_flags
= OPTGROUP_OTHER
;
821 id
= dumps
->dump_register (dot_name
, flag_name
, glob_name
, flags
,
824 set_pass_for_id (id
, pass
);
825 full_name
= concat (prefix
, pass
->name
, num
, NULL
);
826 register_pass_name (pass
, full_name
);
827 free (CONST_CAST (char *, full_name
));
830 /* Register the dump files for the pass_manager starting at PASS. */
833 pass_manager::register_dump_files (opt_pass
*pass
)
837 if (pass
->name
&& pass
->name
[0] != '*')
838 register_one_dump_file (pass
);
841 register_dump_files (pass
->sub
);
848 static hash_map
<nofree_string_hash
, opt_pass
*> *name_to_pass_map
;
850 /* Register PASS with NAME. */
853 register_pass_name (opt_pass
*pass
, const char *name
)
855 if (!name_to_pass_map
)
856 name_to_pass_map
= new hash_map
<nofree_string_hash
, opt_pass
*> (256);
858 if (name_to_pass_map
->get (name
))
859 return; /* Ignore plugin passes. */
861 const char *unique_name
= xstrdup (name
);
862 name_to_pass_map
->put (unique_name
, pass
);
865 /* Map from pass id to canonicalized pass name. */
867 typedef const char *char_ptr
;
868 static vec
<char_ptr
> pass_tab
= vNULL
;
870 /* Callback function for traversing NAME_TO_PASS_MAP. */
873 passes_pass_traverse (const char *const &name
, opt_pass
*const &pass
, void *)
875 gcc_assert (pass
->static_pass_number
> 0);
876 gcc_assert (pass_tab
.exists ());
878 pass_tab
[pass
->static_pass_number
] = name
;
883 /* The function traverses NAME_TO_PASS_MAP and creates a pass info
884 table for dumping purpose. */
887 create_pass_tab (void)
889 if (!flag_dump_passes
)
892 pass_tab
.safe_grow_cleared (g
->get_passes ()->passes_by_id_size
+ 1);
893 name_to_pass_map
->traverse
<void *, passes_pass_traverse
> (NULL
);
896 static bool override_gate_status (opt_pass
*, tree
, bool);
898 /* Dump the instantiated name for PASS. IS_ON indicates if PASS
899 is turned on or not. */
902 dump_one_pass (opt_pass
*pass
, int pass_indent
)
904 int indent
= 3 * pass_indent
;
906 bool is_on
, is_really_on
;
908 is_on
= pass
->gate (cfun
);
909 is_really_on
= override_gate_status (pass
, current_function_decl
, is_on
);
911 if (pass
->static_pass_number
<= 0)
914 pn
= pass_tab
[pass
->static_pass_number
];
916 fprintf (stderr
, "%*s%-40s%*s:%s%s\n", indent
, " ", pn
,
917 (15 - indent
< 0 ? 0 : 15 - indent
), " ",
918 is_on
? " ON" : " OFF",
919 ((!is_on
) == (!is_really_on
) ? ""
920 : (is_really_on
? " (FORCED_ON)" : " (FORCED_OFF)")));
923 /* Dump pass list PASS with indentation INDENT. */
926 dump_pass_list (opt_pass
*pass
, int indent
)
930 dump_one_pass (pass
, indent
);
932 dump_pass_list (pass
->sub
, indent
+ 1);
938 /* Dump all optimization passes. */
943 g
->get_passes ()->dump_passes ();
947 pass_manager::dump_passes () const
949 push_dummy_function (true);
953 dump_pass_list (all_lowering_passes
, 1);
954 dump_pass_list (all_small_ipa_passes
, 1);
955 dump_pass_list (all_regular_ipa_passes
, 1);
956 dump_pass_list (all_late_ipa_passes
, 1);
957 dump_pass_list (all_passes
, 1);
959 pop_dummy_function ();
962 /* Returns the pass with NAME. */
965 get_pass_by_name (const char *name
)
967 opt_pass
**p
= name_to_pass_map
->get (name
);
975 /* Range [start, last]. */
981 const char *assem_name
;
982 struct uid_range
*next
;
985 typedef struct uid_range
*uid_range_p
;
988 static vec
<uid_range_p
>
989 enabled_pass_uid_range_tab
= vNULL
;
990 static vec
<uid_range_p
>
991 disabled_pass_uid_range_tab
= vNULL
;
994 /* Parse option string for -fdisable- and -fenable-
995 The syntax of the options:
998 -fdisable-<pass_name>
1000 -fenable-<pass_name>=s1:e1,s2:e2,...
1001 -fdisable-<pass_name>=s1:e1,s2:e2,...
1005 enable_disable_pass (const char *arg
, bool is_enable
)
1008 char *range_str
, *phase_name
;
1009 char *argstr
= xstrdup (arg
);
1010 vec
<uid_range_p
> *tab
= 0;
1012 range_str
= strchr (argstr
,'=');
1019 phase_name
= argstr
;
1023 error ("unrecognized option -fenable");
1025 error ("unrecognized option -fdisable");
1029 pass
= get_pass_by_name (phase_name
);
1030 if (!pass
|| pass
->static_pass_number
== -1)
1033 error ("unknown pass %s specified in -fenable", phase_name
);
1035 error ("unknown pass %s specified in -fdisable", phase_name
);
1041 tab
= &enabled_pass_uid_range_tab
;
1043 tab
= &disabled_pass_uid_range_tab
;
1045 if ((unsigned) pass
->static_pass_number
>= tab
->length ())
1046 tab
->safe_grow_cleared (pass
->static_pass_number
+ 1);
1051 uid_range_p new_range
= XCNEW (struct uid_range
);
1053 new_range
->start
= 0;
1054 new_range
->last
= (unsigned)-1;
1056 slot
= (*tab
)[pass
->static_pass_number
];
1057 new_range
->next
= slot
;
1058 (*tab
)[pass
->static_pass_number
] = new_range
;
1060 inform (UNKNOWN_LOCATION
, "enable pass %s for functions in the range "
1061 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
1063 inform (UNKNOWN_LOCATION
, "disable pass %s for functions in the range "
1064 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
1068 char *next_range
= NULL
;
1069 char *one_range
= range_str
;
1070 char *end_val
= NULL
;
1075 uid_range_p new_range
;
1076 char *invalid
= NULL
;
1078 char *func_name
= NULL
;
1080 next_range
= strchr (one_range
, ',');
1087 end_val
= strchr (one_range
, ':');
1093 start
= strtol (one_range
, &invalid
, 10);
1094 if (*invalid
|| start
< 0)
1096 if (end_val
|| (one_range
[0] >= '0'
1097 && one_range
[0] <= '9'))
1099 error ("Invalid range %s in option %s",
1101 is_enable
? "-fenable" : "-fdisable");
1105 func_name
= one_range
;
1109 new_range
= XCNEW (struct uid_range
);
1112 new_range
->start
= (unsigned) start
;
1113 new_range
->last
= (unsigned) start
;
1117 new_range
->start
= (unsigned) -1;
1118 new_range
->last
= (unsigned) -1;
1119 new_range
->assem_name
= xstrdup (func_name
);
1124 long last
= strtol (end_val
, &invalid
, 10);
1125 if (*invalid
|| last
< start
)
1127 error ("Invalid range %s in option %s",
1129 is_enable
? "-fenable" : "-fdisable");
1133 new_range
= XCNEW (struct uid_range
);
1134 new_range
->start
= (unsigned) start
;
1135 new_range
->last
= (unsigned) last
;
1138 slot
= (*tab
)[pass
->static_pass_number
];
1139 new_range
->next
= slot
;
1140 (*tab
)[pass
->static_pass_number
] = new_range
;
1143 if (new_range
->assem_name
)
1144 inform (UNKNOWN_LOCATION
,
1145 "enable pass %s for function %s",
1146 phase_name
, new_range
->assem_name
);
1148 inform (UNKNOWN_LOCATION
,
1149 "enable pass %s for functions in the range of [%u, %u]",
1150 phase_name
, new_range
->start
, new_range
->last
);
1154 if (new_range
->assem_name
)
1155 inform (UNKNOWN_LOCATION
,
1156 "disable pass %s for function %s",
1157 phase_name
, new_range
->assem_name
);
1159 inform (UNKNOWN_LOCATION
,
1160 "disable pass %s for functions in the range of [%u, %u]",
1161 phase_name
, new_range
->start
, new_range
->last
);
1164 one_range
= next_range
;
1165 } while (next_range
);
1171 /* Enable pass specified by ARG. */
1174 enable_pass (const char *arg
)
1176 enable_disable_pass (arg
, true);
1179 /* Disable pass specified by ARG. */
1182 disable_pass (const char *arg
)
1184 enable_disable_pass (arg
, false);
1187 /* Returns true if PASS is explicitly enabled/disabled for FUNC. */
1190 is_pass_explicitly_enabled_or_disabled (opt_pass
*pass
,
1192 vec
<uid_range_p
> tab
)
1194 uid_range_p slot
, range
;
1196 const char *aname
= NULL
;
1199 || (unsigned) pass
->static_pass_number
>= tab
.length ()
1200 || pass
->static_pass_number
== -1)
1203 slot
= tab
[pass
->static_pass_number
];
1207 cgraph_uid
= func
? cgraph_node::get (func
)->uid
: 0;
1208 if (func
&& DECL_ASSEMBLER_NAME_SET_P (func
))
1209 aname
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func
));
1214 if ((unsigned) cgraph_uid
>= range
->start
1215 && (unsigned) cgraph_uid
<= range
->last
)
1217 if (range
->assem_name
&& aname
1218 && !strcmp (range
->assem_name
, aname
))
1220 range
= range
->next
;
1227 /* Update static_pass_number for passes (and the flag
1228 TODO_mark_first_instance).
1230 Passes are constructed with static_pass_number preinitialized to 0
1232 This field is used in two different ways: initially as instance numbers
1233 of their kind, and then as ids within the entire pass manager.
1235 Within pass_manager::pass_manager:
1237 * In add_pass_instance(), as called by next_pass_1 in
1238 NEXT_PASS in init_optimization_passes
1240 * When the initial instance of a pass within a pass manager is seen,
1241 it is flagged, and its static_pass_number is set to -1
1243 * On subsequent times that it is seen, the static pass number
1244 is decremented each time, so that if there are e.g. 4 dups,
1245 they have static_pass_number -4, 2, 3, 4 respectively (note
1246 how the initial one is negative and gives the count); these
1247 can be thought of as instance numbers of the specific pass
1249 * Within the register_dump_files () traversal, set_pass_for_id()
1250 is called on each pass, using these instance numbers to create
1251 dumpfile switches, and then overwriting them with a pass id,
1252 which are global to the whole pass manager (based on
1253 (TDI_end + current value of extra_dump_files_in_use) ) */
1256 add_pass_instance (opt_pass
*new_pass
, bool track_duplicates
,
1257 opt_pass
*initial_pass
)
1259 /* Are we dealing with the first pass of its kind, or a clone? */
1260 if (new_pass
!= initial_pass
)
1262 /* We're dealing with a clone. */
1263 new_pass
->todo_flags_start
&= ~TODO_mark_first_instance
;
1265 /* Indicate to register_dump_files that this pass has duplicates,
1266 and so it should rename the dump file. The first instance will
1267 be -1, and be number of duplicates = -static_pass_number - 1.
1268 Subsequent instances will be > 0 and just the duplicate number. */
1269 if ((new_pass
->name
&& new_pass
->name
[0] != '*') || track_duplicates
)
1271 initial_pass
->static_pass_number
-= 1;
1272 new_pass
->static_pass_number
= -initial_pass
->static_pass_number
;
1277 /* We're dealing with the first pass of its kind. */
1278 new_pass
->todo_flags_start
|= TODO_mark_first_instance
;
1279 new_pass
->static_pass_number
= -1;
1281 invoke_plugin_callbacks (PLUGIN_NEW_PASS
, new_pass
);
1285 /* Add a pass to the pass list. Duplicate the pass if it's already
1289 next_pass_1 (opt_pass
**list
, opt_pass
*pass
, opt_pass
*initial_pass
)
1291 /* Every pass should have a name so that plugins can refer to them. */
1292 gcc_assert (pass
->name
!= NULL
);
1294 add_pass_instance (pass
, false, initial_pass
);
1297 return &(*list
)->next
;
1300 /* List node for an inserted pass instance. We need to keep track of all
1301 the newly-added pass instances (with 'added_pass_nodes' defined below)
1302 so that we can register their dump files after pass-positioning is finished.
1303 Registering dumping files needs to be post-processed or the
1304 static_pass_number of the opt_pass object would be modified and mess up
1305 the dump file names of future pass instances to be added. */
1307 struct pass_list_node
1310 struct pass_list_node
*next
;
1313 static struct pass_list_node
*added_pass_nodes
= NULL
;
1314 static struct pass_list_node
*prev_added_pass_node
;
1316 /* Insert the pass at the proper position. Return true if the pass
1317 is successfully added.
1319 NEW_PASS_INFO - new pass to be inserted
1320 PASS_LIST - root of the pass list to insert the new pass to */
1323 position_pass (struct register_pass_info
*new_pass_info
, opt_pass
**pass_list
)
1325 opt_pass
*pass
= *pass_list
, *prev_pass
= NULL
;
1326 bool success
= false;
1328 for ( ; pass
; prev_pass
= pass
, pass
= pass
->next
)
1330 /* Check if the current pass is of the same type as the new pass and
1331 matches the name and the instance number of the reference pass. */
1332 if (pass
->type
== new_pass_info
->pass
->type
1334 && !strcmp (pass
->name
, new_pass_info
->reference_pass_name
)
1335 && ((new_pass_info
->ref_pass_instance_number
== 0)
1336 || (new_pass_info
->ref_pass_instance_number
==
1337 pass
->static_pass_number
)
1338 || (new_pass_info
->ref_pass_instance_number
== 1
1339 && pass
->todo_flags_start
& TODO_mark_first_instance
)))
1342 struct pass_list_node
*new_pass_node
;
1344 if (new_pass_info
->ref_pass_instance_number
== 0)
1346 new_pass
= new_pass_info
->pass
->clone ();
1347 add_pass_instance (new_pass
, true, new_pass_info
->pass
);
1351 new_pass
= new_pass_info
->pass
;
1352 add_pass_instance (new_pass
, true, new_pass
);
1355 /* Insert the new pass instance based on the positioning op. */
1356 switch (new_pass_info
->pos_op
)
1358 case PASS_POS_INSERT_AFTER
:
1359 new_pass
->next
= pass
->next
;
1360 pass
->next
= new_pass
;
1362 /* Skip newly inserted pass to avoid repeated
1363 insertions in the case where the new pass and the
1364 existing one have the same name. */
1367 case PASS_POS_INSERT_BEFORE
:
1368 new_pass
->next
= pass
;
1370 prev_pass
->next
= new_pass
;
1372 *pass_list
= new_pass
;
1374 case PASS_POS_REPLACE
:
1375 new_pass
->next
= pass
->next
;
1377 prev_pass
->next
= new_pass
;
1379 *pass_list
= new_pass
;
1380 new_pass
->sub
= pass
->sub
;
1381 new_pass
->tv_id
= pass
->tv_id
;
1385 error ("invalid pass positioning operation");
1389 /* Save the newly added pass (instance) in the added_pass_nodes
1390 list so that we can register its dump file later. Note that
1391 we cannot register the dump file now because doing so will modify
1392 the static_pass_number of the opt_pass object and therefore
1393 mess up the dump file name of future instances. */
1394 new_pass_node
= XCNEW (struct pass_list_node
);
1395 new_pass_node
->pass
= new_pass
;
1396 if (!added_pass_nodes
)
1397 added_pass_nodes
= new_pass_node
;
1399 prev_added_pass_node
->next
= new_pass_node
;
1400 prev_added_pass_node
= new_pass_node
;
1405 if (pass
->sub
&& position_pass (new_pass_info
, &pass
->sub
))
1412 /* Hooks a new pass into the pass lists.
1414 PASS_INFO - pass information that specifies the opt_pass object,
1415 reference pass, instance number, and how to position
1419 register_pass (struct register_pass_info
*pass_info
)
1421 g
->get_passes ()->register_pass (pass_info
);
1425 register_pass (opt_pass
* pass
, pass_positioning_ops pos
,
1426 const char* ref_pass_name
, int ref_pass_inst_number
)
1428 register_pass_info i
;
1430 i
.reference_pass_name
= ref_pass_name
;
1431 i
.ref_pass_instance_number
= ref_pass_inst_number
;
1434 g
->get_passes ()->register_pass (&i
);
1438 pass_manager::register_pass (struct register_pass_info
*pass_info
)
1440 bool all_instances
, success
;
1441 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
1443 /* The checks below could fail in buggy plugins. Existing GCC
1444 passes should never fail these checks, so we mention plugin in
1446 if (!pass_info
->pass
)
1447 fatal_error (input_location
, "plugin cannot register a missing pass");
1449 if (!pass_info
->pass
->name
)
1450 fatal_error (input_location
, "plugin cannot register an unnamed pass");
1452 if (!pass_info
->reference_pass_name
)
1455 "plugin cannot register pass %qs without reference pass name",
1456 pass_info
->pass
->name
);
1458 /* Try to insert the new pass to the pass lists. We need to check
1459 all five lists as the reference pass could be in one (or all) of
1461 all_instances
= pass_info
->ref_pass_instance_number
== 0;
1462 success
= position_pass (pass_info
, &all_lowering_passes
);
1463 if (!success
|| all_instances
)
1464 success
|= position_pass (pass_info
, &all_small_ipa_passes
);
1465 if (!success
|| all_instances
)
1466 success
|= position_pass (pass_info
, &all_regular_ipa_passes
);
1467 if (!success
|| all_instances
)
1468 success
|= position_pass (pass_info
, &all_late_ipa_passes
);
1469 if (!success
|| all_instances
)
1470 success
|= position_pass (pass_info
, &all_passes
);
1474 "pass %qs not found but is referenced by new pass %qs",
1475 pass_info
->reference_pass_name
, pass_info
->pass
->name
);
1477 /* OK, we have successfully inserted the new pass. We need to register
1478 the dump files for the newly added pass and its duplicates (if any).
1479 Because the registration of plugin/backend passes happens after the
1480 command-line options are parsed, the options that specify single
1481 pass dumping (e.g. -fdump-tree-PASSNAME) cannot be used for new
1482 passes. Therefore we currently can only enable dumping of
1483 new passes when the 'dump-all' flags (e.g. -fdump-tree-all)
1484 are specified. While doing so, we also delete the pass_list_node
1485 objects created during pass positioning. */
1486 while (added_pass_nodes
)
1488 struct pass_list_node
*next_node
= added_pass_nodes
->next
;
1489 enum tree_dump_index tdi
;
1490 register_one_dump_file (added_pass_nodes
->pass
);
1491 if (added_pass_nodes
->pass
->type
== SIMPLE_IPA_PASS
1492 || added_pass_nodes
->pass
->type
== IPA_PASS
)
1494 else if (added_pass_nodes
->pass
->type
== GIMPLE_PASS
)
1498 /* Check if dump-all flag is specified. */
1499 if (dumps
->get_dump_file_info (tdi
)->pstate
)
1500 dumps
->get_dump_file_info (added_pass_nodes
->pass
->static_pass_number
)
1501 ->pstate
= dumps
->get_dump_file_info (tdi
)->pstate
;
1502 XDELETE (added_pass_nodes
);
1503 added_pass_nodes
= next_node
;
1507 /* Construct the pass tree. The sequencing of passes is driven by
1508 the cgraph routines:
1510 finalize_compilation_unit ()
1511 for each node N in the cgraph
1512 cgraph_analyze_function (N)
1513 cgraph_lower_function (N) -> all_lowering_passes
1515 If we are optimizing, compile is then invoked:
1518 ipa_passes () -> all_small_ipa_passes
1519 -> Analysis of all_regular_ipa_passes
1520 * possible LTO streaming at copmilation time *
1521 -> Execution of all_regular_ipa_passes
1522 * possible LTO streaming at link time *
1523 -> all_late_ipa_passes
1524 expand_all_functions ()
1525 for each node N in the cgraph
1526 expand_function (N) -> Transformation of all_regular_ipa_passes
1531 pass_manager::operator new (size_t sz
)
1533 /* Ensure that all fields of the pass manager are zero-initialized. */
1534 return xcalloc (1, sz
);
1538 pass_manager::operator delete (void *ptr
)
1543 pass_manager::pass_manager (context
*ctxt
)
1544 : all_passes (NULL
), all_small_ipa_passes (NULL
), all_lowering_passes (NULL
),
1545 all_regular_ipa_passes (NULL
),
1546 all_late_ipa_passes (NULL
), passes_by_id (NULL
), passes_by_id_size (0),
1551 /* Initialize the pass_lists array. */
1552 #define DEF_PASS_LIST(LIST) pass_lists[PASS_LIST_NO_##LIST] = &LIST;
1554 #undef DEF_PASS_LIST
1556 /* Build the tree of passes. */
1558 #define INSERT_PASSES_AFTER(PASS) \
1561 #define PUSH_INSERT_PASSES_WITHIN(PASS) \
1563 opt_pass **p = &(PASS ## _1)->sub;
1565 #define POP_INSERT_PASSES() \
1568 #define NEXT_PASS(PASS, NUM) \
1570 gcc_assert (NULL == PASS ## _ ## NUM); \
1572 PASS ## _1 = make_##PASS (m_ctxt); \
1575 gcc_assert (PASS ## _1); \
1576 PASS ## _ ## NUM = PASS ## _1->clone (); \
1578 p = next_pass_1 (p, PASS ## _ ## NUM, PASS ## _1); \
1581 #define TERMINATE_PASS_LIST() \
1584 #include "pass-instances.def"
1586 #undef INSERT_PASSES_AFTER
1587 #undef PUSH_INSERT_PASSES_WITHIN
1588 #undef POP_INSERT_PASSES
1590 #undef TERMINATE_PASS_LIST
1592 /* Register the passes with the tree dump code. */
1593 register_dump_files (all_lowering_passes
);
1594 register_dump_files (all_small_ipa_passes
);
1595 register_dump_files (all_regular_ipa_passes
);
1596 register_dump_files (all_late_ipa_passes
);
1597 register_dump_files (all_passes
);
1601 delete_pass_tree (opt_pass
*pass
)
1605 /* Recurse into child passes. */
1606 delete_pass_tree (pass
->sub
);
1608 opt_pass
*next
= pass
->next
;
1610 /* Delete this pass. */
1613 /* Iterate onto sibling passes. */
1618 pass_manager::~pass_manager ()
1620 XDELETEVEC (passes_by_id
);
1622 /* Call delete_pass_tree on each of the pass_lists. */
1623 #define DEF_PASS_LIST(LIST) \
1624 delete_pass_tree (*pass_lists[PASS_LIST_NO_##LIST]);
1626 #undef DEF_PASS_LIST
1630 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1631 function CALLBACK for every function in the call graph. Otherwise,
1632 call CALLBACK on the current function. */
1635 do_per_function (void (*callback
) (function
*, void *data
), void *data
)
1637 if (current_function_decl
)
1638 callback (cfun
, data
);
1641 struct cgraph_node
*node
;
1642 FOR_EACH_DEFINED_FUNCTION (node
)
1643 if (node
->analyzed
&& (gimple_has_body_p (node
->decl
) && !in_lto_p
)
1644 && (!node
->clone_of
|| node
->decl
!= node
->clone_of
->decl
))
1645 callback (DECL_STRUCT_FUNCTION (node
->decl
), data
);
1649 /* Because inlining might remove no-longer reachable nodes, we need to
1650 keep the array visible to garbage collector to avoid reading collected
1653 static GTY ((length ("nnodes"))) cgraph_node
**order
;
1655 /* Hook called when NODE is removed and therefore should be
1656 excluded from order vector. DATA is an array of integers.
1657 DATA[0] holds max index it may be accessed by. For cgraph
1658 node DATA[node->uid + 1] holds index of this node in order
1661 remove_cgraph_node_from_order (cgraph_node
*node
, void *data
)
1663 int *order_idx
= (int *)data
;
1665 if (node
->uid
>= order_idx
[0])
1668 int idx
= order_idx
[node
->uid
+ 1];
1669 if (idx
>= 0 && idx
< nnodes
&& order
[idx
] == node
)
1673 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1674 function CALLBACK for every function in the call graph. Otherwise,
1675 call CALLBACK on the current function.
1676 This function is global so that plugins can use it. */
1678 do_per_function_toporder (void (*callback
) (function
*, void *data
), void *data
)
1682 if (current_function_decl
)
1683 callback (cfun
, data
);
1686 cgraph_node_hook_list
*hook
;
1688 gcc_assert (!order
);
1689 order
= ggc_vec_alloc
<cgraph_node
*> (symtab
->cgraph_count
);
1691 order_idx
= XALLOCAVEC (int, symtab
->cgraph_max_uid
+ 1);
1692 memset (order_idx
+ 1, -1, sizeof (int) * symtab
->cgraph_max_uid
);
1693 order_idx
[0] = symtab
->cgraph_max_uid
;
1695 nnodes
= ipa_reverse_postorder (order
);
1696 for (i
= nnodes
- 1; i
>= 0; i
--)
1698 order
[i
]->process
= 1;
1699 order_idx
[order
[i
]->uid
+ 1] = i
;
1701 hook
= symtab
->add_cgraph_removal_hook (remove_cgraph_node_from_order
,
1703 for (i
= nnodes
- 1; i
>= 0; i
--)
1705 /* Function could be inlined and removed as unreachable. */
1709 struct cgraph_node
*node
= order
[i
];
1711 /* Allow possibly removed nodes to be garbage collected. */
1714 if (node
->has_gimple_body_p ())
1715 callback (DECL_STRUCT_FUNCTION (node
->decl
), data
);
1717 symtab
->remove_cgraph_removal_hook (hook
);
1724 /* Helper function to perform function body dump. */
1727 execute_function_dump (function
*fn
, void *data
)
1729 opt_pass
*pass
= (opt_pass
*)data
;
1735 if (fn
->curr_properties
& PROP_trees
)
1736 dump_function_to_file (fn
->decl
, dump_file
, dump_flags
);
1738 print_rtl_with_bb (dump_file
, get_insns (), dump_flags
);
1740 /* Flush the file. If verification fails, we won't be able to
1741 close the file before aborting. */
1744 if ((fn
->curr_properties
& PROP_cfg
)
1745 && (dump_flags
& TDF_GRAPH
))
1747 if (!pass
->graph_dump_initialized
)
1749 clean_graph_dump_file (dump_file_name
);
1750 pass
->graph_dump_initialized
= true;
1752 print_graph_cfg (dump_file_name
, fn
);
1759 static struct profile_record
*profile_record
;
1761 /* Do profile consistency book-keeping for the pass with static number INDEX.
1762 If SUBPASS is zero, we run _before_ the pass, and if SUBPASS is one, then
1763 we run _after_ the pass. RUN is true if the pass really runs, or FALSE
1764 if we are only book-keeping on passes that may have selectively disabled
1765 themselves on a given function. */
1767 check_profile_consistency (int index
, int subpass
, bool run
)
1769 pass_manager
*passes
= g
->get_passes ();
1772 if (!profile_record
)
1773 profile_record
= XCNEWVEC (struct profile_record
,
1774 passes
->passes_by_id_size
);
1775 gcc_assert (index
< passes
->passes_by_id_size
&& index
>= 0);
1776 gcc_assert (subpass
< 2);
1777 profile_record
[index
].run
|= run
;
1778 account_profile_record (&profile_record
[index
], subpass
);
1781 /* Output profile consistency. */
1784 dump_profile_report (void)
1786 g
->get_passes ()->dump_profile_report ();
1790 pass_manager::dump_profile_report () const
1793 int last_freq_in
= 0, last_count_in
= 0, last_freq_out
= 0, last_count_out
= 0;
1794 gcov_type last_time
= 0, last_size
= 0;
1795 double rel_time_change
, rel_size_change
;
1796 int last_reported
= 0;
1798 if (!profile_record
)
1800 fprintf (stderr
, "\nProfile consistency report:\n\n");
1801 fprintf (stderr
, "Pass name |mismatch in |mismated out|Overall\n");
1802 fprintf (stderr
, " |freq count |freq count |size time\n");
1804 for (i
= 0; i
< passes_by_id_size
; i
++)
1805 for (j
= 0 ; j
< 2; j
++)
1806 if (profile_record
[i
].run
)
1809 rel_time_change
= (profile_record
[i
].time
[j
]
1810 - (double)last_time
) * 100 / (double)last_time
;
1812 rel_time_change
= 0;
1814 rel_size_change
= (profile_record
[i
].size
[j
]
1815 - (double)last_size
) * 100 / (double)last_size
;
1817 rel_size_change
= 0;
1819 if (profile_record
[i
].num_mismatched_freq_in
[j
] != last_freq_in
1820 || profile_record
[i
].num_mismatched_freq_out
[j
] != last_freq_out
1821 || profile_record
[i
].num_mismatched_count_in
[j
] != last_count_in
1822 || profile_record
[i
].num_mismatched_count_out
[j
] != last_count_out
1823 || rel_time_change
|| rel_size_change
)
1826 fprintf (stderr
, "%-20s %s",
1827 passes_by_id
[i
]->name
,
1828 j
? "(after TODO)" : " ");
1829 if (profile_record
[i
].num_mismatched_freq_in
[j
] != last_freq_in
)
1830 fprintf (stderr
, "| %+5i",
1831 profile_record
[i
].num_mismatched_freq_in
[j
]
1834 fprintf (stderr
, "| ");
1835 if (profile_record
[i
].num_mismatched_count_in
[j
] != last_count_in
)
1836 fprintf (stderr
, " %+5i",
1837 profile_record
[i
].num_mismatched_count_in
[j
]
1840 fprintf (stderr
, " ");
1841 if (profile_record
[i
].num_mismatched_freq_out
[j
] != last_freq_out
)
1842 fprintf (stderr
, "| %+5i",
1843 profile_record
[i
].num_mismatched_freq_out
[j
]
1846 fprintf (stderr
, "| ");
1847 if (profile_record
[i
].num_mismatched_count_out
[j
] != last_count_out
)
1848 fprintf (stderr
, " %+5i",
1849 profile_record
[i
].num_mismatched_count_out
[j
]
1852 fprintf (stderr
, " ");
1854 /* Size/time units change across gimple and RTL. */
1855 if (i
== pass_expand_1
->static_pass_number
)
1856 fprintf (stderr
, "|----------");
1859 if (rel_size_change
)
1860 fprintf (stderr
, "| %+8.4f%%", rel_size_change
);
1862 fprintf (stderr
, "| ");
1863 if (rel_time_change
)
1864 fprintf (stderr
, " %+8.4f%%", rel_time_change
);
1866 fprintf (stderr
, "\n");
1867 last_freq_in
= profile_record
[i
].num_mismatched_freq_in
[j
];
1868 last_freq_out
= profile_record
[i
].num_mismatched_freq_out
[j
];
1869 last_count_in
= profile_record
[i
].num_mismatched_count_in
[j
];
1870 last_count_out
= profile_record
[i
].num_mismatched_count_out
[j
];
1872 else if (j
&& last_reported
!= i
)
1875 fprintf (stderr
, "%-20s ------------| | |\n",
1876 passes_by_id
[i
]->name
);
1878 last_time
= profile_record
[i
].time
[j
];
1879 last_size
= profile_record
[i
].size
[j
];
1883 /* Perform all TODO actions that ought to be done on each function. */
1886 execute_function_todo (function
*fn
, void *data
)
1888 bool from_ipa_pass
= (cfun
== NULL
);
1889 unsigned int flags
= (size_t)data
;
1890 flags
&= ~fn
->last_verified
;
1896 /* Always cleanup the CFG before trying to update SSA. */
1897 if (flags
& TODO_cleanup_cfg
)
1899 cleanup_tree_cfg ();
1901 /* When cleanup_tree_cfg merges consecutive blocks, it may
1902 perform some simplistic propagation when removing single
1903 valued PHI nodes. This propagation may, in turn, cause the
1904 SSA form to become out-of-date (see PR 22037). So, even
1905 if the parent pass had not scheduled an SSA update, we may
1906 still need to do one. */
1907 if (!(flags
& TODO_update_ssa_any
) && need_ssa_update_p (cfun
))
1908 flags
|= TODO_update_ssa
;
1911 if (flags
& TODO_update_ssa_any
)
1913 unsigned update_flags
= flags
& TODO_update_ssa_any
;
1914 update_ssa (update_flags
);
1917 if (flag_tree_pta
&& (flags
& TODO_rebuild_alias
))
1918 compute_may_aliases ();
1920 if (optimize
&& (flags
& TODO_update_address_taken
))
1921 execute_update_addresses_taken ();
1923 if (flags
& TODO_remove_unused_locals
)
1924 remove_unused_locals ();
1926 if (flags
& TODO_rebuild_frequencies
)
1927 rebuild_frequencies ();
1929 if (flags
& TODO_rebuild_cgraph_edges
)
1930 cgraph_edge::rebuild_edges ();
1932 gcc_assert (dom_info_state (fn
, CDI_POST_DOMINATORS
) == DOM_NONE
);
1933 /* If we've seen errors do not bother running any verifiers. */
1936 #if defined ENABLE_CHECKING
1937 dom_state pre_verify_state
= dom_info_state (fn
, CDI_DOMINATORS
);
1938 dom_state pre_verify_pstate
= dom_info_state (fn
, CDI_POST_DOMINATORS
);
1940 if (flags
& TODO_verify_il
)
1942 if (cfun
->curr_properties
& PROP_trees
)
1944 if (cfun
->curr_properties
& PROP_cfg
)
1945 /* IPA passes leave stmts to be fixed up, so make sure to
1946 not verify stmts really throw. */
1947 verify_gimple_in_cfg (cfun
, !from_ipa_pass
);
1949 verify_gimple_in_seq (gimple_body (cfun
->decl
));
1951 if (cfun
->curr_properties
& PROP_ssa
)
1952 /* IPA passes leave stmts to be fixed up, so make sure to
1953 not verify SSA operands whose verifier will choke on that. */
1954 verify_ssa (true, !from_ipa_pass
);
1955 /* IPA passes leave basic-blocks unsplit, so make sure to
1956 not trip on that. */
1957 if ((cfun
->curr_properties
& PROP_cfg
)
1959 verify_flow_info ();
1961 && loops_state_satisfies_p (LOOP_CLOSED_SSA
))
1962 verify_loop_closed_ssa (false);
1963 if (cfun
->curr_properties
& PROP_rtl
)
1964 verify_rtl_sharing ();
1967 /* Make sure verifiers don't change dominator state. */
1968 gcc_assert (dom_info_state (fn
, CDI_DOMINATORS
) == pre_verify_state
);
1969 gcc_assert (dom_info_state (fn
, CDI_POST_DOMINATORS
) == pre_verify_pstate
);
1973 fn
->last_verified
= flags
& TODO_verify_all
;
1977 /* For IPA passes make sure to release dominator info, it can be
1978 computed by non-verifying TODOs. */
1981 free_dominance_info (fn
, CDI_DOMINATORS
);
1982 free_dominance_info (fn
, CDI_POST_DOMINATORS
);
1986 /* Perform all TODO actions. */
1988 execute_todo (unsigned int flags
)
1990 #if defined ENABLE_CHECKING
1992 && need_ssa_update_p (cfun
))
1993 gcc_assert (flags
& TODO_update_ssa_any
);
1996 timevar_push (TV_TODO
);
1998 /* Inform the pass whether it is the first time it is run. */
1999 first_pass_instance
= (flags
& TODO_mark_first_instance
) != 0;
2001 statistics_fini_pass ();
2004 do_per_function (execute_function_todo
, (void *)(size_t) flags
);
2006 /* Always remove functions just as before inlining: IPA passes might be
2007 interested to see bodies of extern inline functions that are not inlined
2008 to analyze side effects. The full removal is done just at the end
2009 of IPA pass queue. */
2010 if (flags
& TODO_remove_functions
)
2013 symtab
->remove_unreachable_nodes (dump_file
);
2016 if ((flags
& TODO_dump_symtab
) && dump_file
&& !current_function_decl
)
2019 symtab_node::dump_table (dump_file
);
2020 /* Flush the file. If verification fails, we won't be able to
2021 close the file before aborting. */
2025 /* Now that the dumping has been done, we can get rid of the optional
2027 if (flags
& TODO_df_finish
)
2028 df_finish_pass ((flags
& TODO_df_verify
) != 0);
2030 timevar_pop (TV_TODO
);
2033 /* Verify invariants that should hold between passes. This is a place
2034 to put simple sanity checks. */
2037 verify_interpass_invariants (void)
2039 gcc_checking_assert (!fold_deferring_overflow_warnings_p ());
2042 /* Clear the last verified flag. */
2045 clear_last_verified (function
*fn
, void *data ATTRIBUTE_UNUSED
)
2047 fn
->last_verified
= 0;
2050 /* Helper function. Verify that the properties has been turn into the
2051 properties expected by the pass. */
2053 #ifdef ENABLE_CHECKING
2055 verify_curr_properties (function
*fn
, void *data
)
2057 unsigned int props
= (size_t)data
;
2058 gcc_assert ((fn
->curr_properties
& props
) == props
);
2062 /* Initialize pass dump file. */
2063 /* This is non-static so that the plugins can use it. */
2066 pass_init_dump_file (opt_pass
*pass
)
2068 /* If a dump file name is present, open it if enabled. */
2069 if (pass
->static_pass_number
!= -1)
2071 timevar_push (TV_DUMP
);
2072 gcc::dump_manager
*dumps
= g
->get_dumps ();
2073 bool initializing_dump
=
2074 !dumps
->dump_initialized_p (pass
->static_pass_number
);
2075 dump_file_name
= dumps
->get_dump_file_name (pass
->static_pass_number
);
2076 dumps
->dump_start (pass
->static_pass_number
, &dump_flags
);
2077 if (dump_file
&& current_function_decl
)
2078 dump_function_header (dump_file
, current_function_decl
, dump_flags
);
2079 if (initializing_dump
2080 && dump_file
&& (dump_flags
& TDF_GRAPH
)
2081 && cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2083 clean_graph_dump_file (dump_file_name
);
2084 pass
->graph_dump_initialized
= true;
2086 timevar_pop (TV_DUMP
);
2087 return initializing_dump
;
2093 /* Flush PASS dump file. */
2094 /* This is non-static so that plugins can use it. */
2097 pass_fini_dump_file (opt_pass
*pass
)
2099 timevar_push (TV_DUMP
);
2101 /* Flush and close dump file. */
2104 free (CONST_CAST (char *, dump_file_name
));
2105 dump_file_name
= NULL
;
2108 g
->get_dumps ()->dump_finish (pass
->static_pass_number
);
2109 timevar_pop (TV_DUMP
);
2112 /* After executing the pass, apply expected changes to the function
2116 update_properties_after_pass (function
*fn
, void *data
)
2118 opt_pass
*pass
= (opt_pass
*) data
;
2119 fn
->curr_properties
= (fn
->curr_properties
| pass
->properties_provided
)
2120 & ~pass
->properties_destroyed
;
2123 /* Execute summary generation for all of the passes in IPA_PASS. */
2126 execute_ipa_summary_passes (ipa_opt_pass_d
*ipa_pass
)
2130 opt_pass
*pass
= ipa_pass
;
2132 /* Execute all of the IPA_PASSes in the list. */
2133 if (ipa_pass
->type
== IPA_PASS
2134 && pass
->gate (cfun
)
2135 && ipa_pass
->generate_summary
)
2137 pass_init_dump_file (pass
);
2139 /* If a timevar is present, start it. */
2141 timevar_push (pass
->tv_id
);
2143 current_pass
= pass
;
2144 ipa_pass
->generate_summary ();
2148 timevar_pop (pass
->tv_id
);
2150 pass_fini_dump_file (pass
);
2152 ipa_pass
= (ipa_opt_pass_d
*)ipa_pass
->next
;
2156 /* Execute IPA_PASS function transform on NODE. */
2159 execute_one_ipa_transform_pass (struct cgraph_node
*node
,
2160 ipa_opt_pass_d
*ipa_pass
)
2162 opt_pass
*pass
= ipa_pass
;
2163 unsigned int todo_after
= 0;
2165 current_pass
= pass
;
2166 if (!ipa_pass
->function_transform
)
2169 /* Note that the folders should only create gimple expressions.
2170 This is a hack until the new folder is ready. */
2171 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
2173 pass_init_dump_file (pass
);
2175 /* Run pre-pass verification. */
2176 execute_todo (ipa_pass
->function_transform_todo_flags_start
);
2178 /* If a timevar is present, start it. */
2179 if (pass
->tv_id
!= TV_NONE
)
2180 timevar_push (pass
->tv_id
);
2183 todo_after
= ipa_pass
->function_transform (node
);
2186 if (pass
->tv_id
!= TV_NONE
)
2187 timevar_pop (pass
->tv_id
);
2189 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2190 check_profile_consistency (pass
->static_pass_number
, 0, true);
2192 /* Run post-pass cleanup and verification. */
2193 execute_todo (todo_after
);
2194 verify_interpass_invariants ();
2195 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2196 check_profile_consistency (pass
->static_pass_number
, 1, true);
2199 do_per_function (execute_function_dump
, NULL
);
2200 pass_fini_dump_file (pass
);
2202 current_pass
= NULL
;
2204 /* Signal this is a suitable GC collection point. */
2205 if (!(todo_after
& TODO_do_not_ggc_collect
))
2209 /* For the current function, execute all ipa transforms. */
2212 execute_all_ipa_transforms (void)
2214 struct cgraph_node
*node
;
2217 node
= cgraph_node::get (current_function_decl
);
2219 if (node
->ipa_transforms_to_apply
.exists ())
2223 for (i
= 0; i
< node
->ipa_transforms_to_apply
.length (); i
++)
2224 execute_one_ipa_transform_pass (node
, node
->ipa_transforms_to_apply
[i
]);
2225 node
->ipa_transforms_to_apply
.release ();
2229 /* Check if PASS is explicitly disabled or enabled and return
2230 the gate status. FUNC is the function to be processed, and
2231 GATE_STATUS is the gate status determined by pass manager by
2235 override_gate_status (opt_pass
*pass
, tree func
, bool gate_status
)
2237 bool explicitly_enabled
= false;
2238 bool explicitly_disabled
= false;
2241 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2242 enabled_pass_uid_range_tab
);
2244 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2245 disabled_pass_uid_range_tab
);
2247 gate_status
= !explicitly_disabled
&& (gate_status
|| explicitly_enabled
);
2256 execute_one_pass (opt_pass
*pass
)
2258 unsigned int todo_after
= 0;
2262 /* IPA passes are executed on whole program, so cfun should be NULL.
2263 Other passes need function context set. */
2264 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
2265 gcc_assert (!cfun
&& !current_function_decl
);
2267 gcc_assert (cfun
&& current_function_decl
);
2269 current_pass
= pass
;
2271 /* Check whether gate check should be avoided.
2272 User controls the value of the gate through the parameter "gate_status". */
2273 gate_status
= pass
->gate (cfun
);
2274 gate_status
= override_gate_status (pass
, current_function_decl
, gate_status
);
2276 /* Override gate with plugin. */
2277 invoke_plugin_callbacks (PLUGIN_OVERRIDE_GATE
, &gate_status
);
2281 /* Run so passes selectively disabling themselves on a given function
2282 are not miscounted. */
2283 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2285 check_profile_consistency (pass
->static_pass_number
, 0, false);
2286 check_profile_consistency (pass
->static_pass_number
, 1, false);
2288 current_pass
= NULL
;
2292 /* Pass execution event trigger: useful to identify passes being
2294 invoke_plugin_callbacks (PLUGIN_PASS_EXECUTION
, pass
);
2296 if (!quiet_flag
&& !cfun
)
2297 fprintf (stderr
, " <%s>", pass
->name
? pass
->name
: "");
2299 /* Note that the folders should only create gimple expressions.
2300 This is a hack until the new folder is ready. */
2301 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
2303 pass_init_dump_file (pass
);
2305 /* Run pre-pass verification. */
2306 execute_todo (pass
->todo_flags_start
);
2308 #ifdef ENABLE_CHECKING
2309 do_per_function (verify_curr_properties
,
2310 (void *)(size_t)pass
->properties_required
);
2313 /* If a timevar is present, start it. */
2314 if (pass
->tv_id
!= TV_NONE
)
2315 timevar_push (pass
->tv_id
);
2318 todo_after
= pass
->execute (cfun
);
2319 do_per_function (clear_last_verified
, NULL
);
2322 if (pass
->tv_id
!= TV_NONE
)
2323 timevar_pop (pass
->tv_id
);
2325 do_per_function (update_properties_after_pass
, pass
);
2327 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2328 check_profile_consistency (pass
->static_pass_number
, 0, true);
2330 /* Run post-pass cleanup and verification. */
2331 execute_todo (todo_after
| pass
->todo_flags_finish
| TODO_verify_il
);
2332 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2333 check_profile_consistency (pass
->static_pass_number
, 1, true);
2335 verify_interpass_invariants ();
2337 do_per_function (execute_function_dump
, pass
);
2338 if (pass
->type
== IPA_PASS
)
2340 struct cgraph_node
*node
;
2341 if (((ipa_opt_pass_d
*)pass
)->function_transform
)
2342 FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node
)
2343 node
->ipa_transforms_to_apply
.safe_push ((ipa_opt_pass_d
*)pass
);
2346 if (!current_function_decl
)
2347 symtab
->process_new_functions ();
2349 pass_fini_dump_file (pass
);
2351 if (pass
->type
!= SIMPLE_IPA_PASS
&& pass
->type
!= IPA_PASS
)
2352 gcc_assert (!(cfun
->curr_properties
& PROP_trees
)
2353 || pass
->type
!= RTL_PASS
);
2355 current_pass
= NULL
;
2357 /* Signal this is a suitable GC collection point. */
2358 if (!((todo_after
| pass
->todo_flags_finish
) & TODO_do_not_ggc_collect
))
2365 execute_pass_list_1 (opt_pass
*pass
)
2369 gcc_assert (pass
->type
== GIMPLE_PASS
2370 || pass
->type
== RTL_PASS
);
2371 if (execute_one_pass (pass
) && pass
->sub
)
2372 execute_pass_list_1 (pass
->sub
);
2379 execute_pass_list (function
*fn
, opt_pass
*pass
)
2382 execute_pass_list_1 (pass
);
2385 free_dominance_info (CDI_DOMINATORS
);
2386 free_dominance_info (CDI_POST_DOMINATORS
);
2391 /* Write out all LTO data. */
2395 timevar_push (TV_IPA_LTO_GIMPLE_OUT
);
2397 timevar_pop (TV_IPA_LTO_GIMPLE_OUT
);
2398 timevar_push (TV_IPA_LTO_DECL_OUT
);
2399 produce_asm_for_decls ();
2400 timevar_pop (TV_IPA_LTO_DECL_OUT
);
2403 /* Same as execute_pass_list but assume that subpasses of IPA passes
2404 are local passes. If SET is not NULL, write out summaries of only
2405 those node in SET. */
2408 ipa_write_summaries_2 (opt_pass
*pass
, struct lto_out_decl_state
*state
)
2412 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*)pass
;
2413 gcc_assert (!current_function_decl
);
2415 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2416 if (pass
->type
== IPA_PASS
2417 && ipa_pass
->write_summary
2418 && pass
->gate (cfun
))
2420 /* If a timevar is present, start it. */
2422 timevar_push (pass
->tv_id
);
2424 pass_init_dump_file (pass
);
2426 current_pass
= pass
;
2427 ipa_pass
->write_summary ();
2429 pass_fini_dump_file (pass
);
2431 /* If a timevar is present, start it. */
2433 timevar_pop (pass
->tv_id
);
2436 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2437 ipa_write_summaries_2 (pass
->sub
, state
);
2443 /* Helper function of ipa_write_summaries. Creates and destroys the
2444 decl state and calls ipa_write_summaries_2 for all passes that have
2445 summaries. SET is the set of nodes to be written. */
2448 ipa_write_summaries_1 (lto_symtab_encoder_t encoder
)
2450 pass_manager
*passes
= g
->get_passes ();
2451 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2452 state
->symtab_node_encoder
= encoder
;
2454 lto_output_init_mode_table ();
2455 lto_push_out_decl_state (state
);
2457 gcc_assert (!flag_wpa
);
2458 ipa_write_summaries_2 (passes
->all_regular_ipa_passes
, state
);
2462 gcc_assert (lto_get_out_decl_state () == state
);
2463 lto_pop_out_decl_state ();
2464 lto_delete_out_decl_state (state
);
2467 /* Write out summaries for all the nodes in the callgraph. */
2470 ipa_write_summaries (void)
2472 lto_symtab_encoder_t encoder
;
2474 varpool_node
*vnode
;
2475 struct cgraph_node
*node
;
2476 struct cgraph_node
**order
;
2478 if ((!flag_generate_lto
&& !flag_generate_offload
) || seen_error ())
2481 select_what_to_stream ();
2483 encoder
= lto_symtab_encoder_new (false);
2485 /* Create the callgraph set in the same order used in
2486 cgraph_expand_all_functions. This mostly facilitates debugging,
2487 since it causes the gimple file to be processed in the same order
2488 as the source code. */
2489 order
= XCNEWVEC (struct cgraph_node
*, symtab
->cgraph_count
);
2490 order_pos
= ipa_reverse_postorder (order
);
2491 gcc_assert (order_pos
== symtab
->cgraph_count
);
2493 for (i
= order_pos
- 1; i
>= 0; i
--)
2495 struct cgraph_node
*node
= order
[i
];
2497 if (node
->has_gimple_body_p ())
2499 /* When streaming out references to statements as part of some IPA
2500 pass summary, the statements need to have uids assigned and the
2501 following does that for all the IPA passes here. Naturally, this
2502 ordering then matches the one IPA-passes get in their stmt_fixup
2505 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
2506 renumber_gimple_stmt_uids ();
2509 if (node
->definition
&& node
->need_lto_streaming
)
2510 lto_set_symtab_encoder_in_partition (encoder
, node
);
2513 FOR_EACH_DEFINED_FUNCTION (node
)
2514 if (node
->alias
&& node
->need_lto_streaming
)
2515 lto_set_symtab_encoder_in_partition (encoder
, node
);
2516 FOR_EACH_DEFINED_VARIABLE (vnode
)
2517 if (vnode
->need_lto_streaming
)
2518 lto_set_symtab_encoder_in_partition (encoder
, vnode
);
2520 ipa_write_summaries_1 (compute_ltrans_boundary (encoder
));
2525 /* Same as execute_pass_list but assume that subpasses of IPA passes
2526 are local passes. If SET is not NULL, write out optimization summaries of
2527 only those node in SET. */
2530 ipa_write_optimization_summaries_1 (opt_pass
*pass
,
2531 struct lto_out_decl_state
*state
)
2535 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*)pass
;
2536 gcc_assert (!current_function_decl
);
2538 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2539 if (pass
->type
== IPA_PASS
2540 && ipa_pass
->write_optimization_summary
2541 && pass
->gate (cfun
))
2543 /* If a timevar is present, start it. */
2545 timevar_push (pass
->tv_id
);
2547 pass_init_dump_file (pass
);
2549 current_pass
= pass
;
2550 ipa_pass
->write_optimization_summary ();
2552 pass_fini_dump_file (pass
);
2554 /* If a timevar is present, start it. */
2556 timevar_pop (pass
->tv_id
);
2559 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2560 ipa_write_optimization_summaries_1 (pass
->sub
, state
);
2566 /* Write all the optimization summaries for the cgraph nodes in SET. If SET is
2567 NULL, write out all summaries of all nodes. */
2570 ipa_write_optimization_summaries (lto_symtab_encoder_t encoder
)
2572 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2573 lto_symtab_encoder_iterator lsei
;
2574 state
->symtab_node_encoder
= encoder
;
2576 lto_output_init_mode_table ();
2577 lto_push_out_decl_state (state
);
2578 for (lsei
= lsei_start_function_in_partition (encoder
);
2579 !lsei_end_p (lsei
); lsei_next_function_in_partition (&lsei
))
2581 struct cgraph_node
*node
= lsei_cgraph_node (lsei
);
2582 /* When streaming out references to statements as part of some IPA
2583 pass summary, the statements need to have uids assigned.
2585 For functions newly born at WPA stage we need to initialize
2587 if (node
->definition
2588 && gimple_has_body_p (node
->decl
))
2590 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
2591 renumber_gimple_stmt_uids ();
2596 gcc_assert (flag_wpa
);
2597 pass_manager
*passes
= g
->get_passes ();
2598 ipa_write_optimization_summaries_1 (passes
->all_regular_ipa_passes
, state
);
2602 gcc_assert (lto_get_out_decl_state () == state
);
2603 lto_pop_out_decl_state ();
2604 lto_delete_out_decl_state (state
);
2607 /* Same as execute_pass_list but assume that subpasses of IPA passes
2608 are local passes. */
2611 ipa_read_summaries_1 (opt_pass
*pass
)
2615 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
2617 gcc_assert (!current_function_decl
);
2619 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2621 if (pass
->gate (cfun
))
2623 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_summary
)
2625 /* If a timevar is present, start it. */
2627 timevar_push (pass
->tv_id
);
2629 pass_init_dump_file (pass
);
2631 current_pass
= pass
;
2632 ipa_pass
->read_summary ();
2634 pass_fini_dump_file (pass
);
2638 timevar_pop (pass
->tv_id
);
2641 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2642 ipa_read_summaries_1 (pass
->sub
);
2649 /* Read all the summaries for all_regular_ipa_passes. */
2652 ipa_read_summaries (void)
2654 pass_manager
*passes
= g
->get_passes ();
2655 ipa_read_summaries_1 (passes
->all_regular_ipa_passes
);
2658 /* Same as execute_pass_list but assume that subpasses of IPA passes
2659 are local passes. */
2662 ipa_read_optimization_summaries_1 (opt_pass
*pass
)
2666 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
2668 gcc_assert (!current_function_decl
);
2670 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2672 if (pass
->gate (cfun
))
2674 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_optimization_summary
)
2676 /* If a timevar is present, start it. */
2678 timevar_push (pass
->tv_id
);
2680 pass_init_dump_file (pass
);
2682 current_pass
= pass
;
2683 ipa_pass
->read_optimization_summary ();
2685 pass_fini_dump_file (pass
);
2689 timevar_pop (pass
->tv_id
);
2692 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2693 ipa_read_optimization_summaries_1 (pass
->sub
);
2699 /* Read all the summaries for all_regular_ipa_passes. */
2702 ipa_read_optimization_summaries (void)
2704 pass_manager
*passes
= g
->get_passes ();
2705 ipa_read_optimization_summaries_1 (passes
->all_regular_ipa_passes
);
2708 /* Same as execute_pass_list but assume that subpasses of IPA passes
2709 are local passes. */
2711 execute_ipa_pass_list (opt_pass
*pass
)
2715 gcc_assert (!current_function_decl
);
2717 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2718 if (execute_one_pass (pass
) && pass
->sub
)
2720 if (pass
->sub
->type
== GIMPLE_PASS
)
2722 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_START
, NULL
);
2723 do_per_function_toporder ((void (*)(function
*, void *))
2726 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_END
, NULL
);
2728 else if (pass
->sub
->type
== SIMPLE_IPA_PASS
2729 || pass
->sub
->type
== IPA_PASS
)
2730 execute_ipa_pass_list (pass
->sub
);
2734 gcc_assert (!current_function_decl
);
2735 symtab
->process_new_functions ();
2741 /* Execute stmt fixup hooks of all passes in PASS for NODE and STMTS. */
2744 execute_ipa_stmt_fixups (opt_pass
*pass
,
2745 struct cgraph_node
*node
, gimple
*stmts
)
2749 /* Execute all of the IPA_PASSes in the list. */
2750 if (pass
->type
== IPA_PASS
2751 && pass
->gate (cfun
))
2753 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
2755 if (ipa_pass
->stmt_fixup
)
2757 pass_init_dump_file (pass
);
2758 /* If a timevar is present, start it. */
2760 timevar_push (pass
->tv_id
);
2762 current_pass
= pass
;
2763 ipa_pass
->stmt_fixup (node
, stmts
);
2767 timevar_pop (pass
->tv_id
);
2768 pass_fini_dump_file (pass
);
2771 execute_ipa_stmt_fixups (pass
->sub
, node
, stmts
);
2777 /* Execute stmt fixup hooks of all IPA passes for NODE and STMTS. */
2780 execute_all_ipa_stmt_fixups (struct cgraph_node
*node
, gimple
*stmts
)
2782 pass_manager
*passes
= g
->get_passes ();
2783 execute_ipa_stmt_fixups (passes
->all_regular_ipa_passes
, node
, stmts
);
2787 extern void debug_properties (unsigned int);
2788 extern void dump_properties (FILE *, unsigned int);
2791 dump_properties (FILE *dump
, unsigned int props
)
2793 fprintf (dump
, "Properties:\n");
2794 if (props
& PROP_gimple_any
)
2795 fprintf (dump
, "PROP_gimple_any\n");
2796 if (props
& PROP_gimple_lcf
)
2797 fprintf (dump
, "PROP_gimple_lcf\n");
2798 if (props
& PROP_gimple_leh
)
2799 fprintf (dump
, "PROP_gimple_leh\n");
2800 if (props
& PROP_cfg
)
2801 fprintf (dump
, "PROP_cfg\n");
2802 if (props
& PROP_ssa
)
2803 fprintf (dump
, "PROP_ssa\n");
2804 if (props
& PROP_no_crit_edges
)
2805 fprintf (dump
, "PROP_no_crit_edges\n");
2806 if (props
& PROP_rtl
)
2807 fprintf (dump
, "PROP_rtl\n");
2808 if (props
& PROP_gimple_lomp
)
2809 fprintf (dump
, "PROP_gimple_lomp\n");
2810 if (props
& PROP_gimple_lcx
)
2811 fprintf (dump
, "PROP_gimple_lcx\n");
2812 if (props
& PROP_gimple_lvec
)
2813 fprintf (dump
, "PROP_gimple_lvec\n");
2814 if (props
& PROP_cfglayout
)
2815 fprintf (dump
, "PROP_cfglayout\n");
2819 debug_properties (unsigned int props
)
2821 dump_properties (stderr
, props
);
2824 /* Called by local passes to see if function is called by already processed nodes.
2825 Because we process nodes in topological order, this means that function is
2826 in recursive cycle or we introduced new direct calls. */
2828 function_called_by_processed_nodes_p (void)
2830 struct cgraph_edge
*e
;
2831 for (e
= cgraph_node::get (current_function_decl
)->callers
;
2835 if (e
->caller
->decl
== current_function_decl
)
2837 if (!e
->caller
->has_gimple_body_p ())
2839 if (TREE_ASM_WRITTEN (e
->caller
->decl
))
2841 if (!e
->caller
->process
&& !e
->caller
->global
.inlined_to
)
2846 fprintf (dump_file
, "Already processed call to:\n");
2847 e
->caller
->dump (dump_file
);
2852 #include "gt-passes.h"