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"
36 #include "fold-const.h"
40 #include "insn-attr.h"
41 #include "insn-config.h"
42 #include "insn-flags.h"
57 #include "diagnostic-core.h"
62 #include "langhooks.h"
64 #include "hosthooks.h"
67 #include "value-prof.h"
68 #include "tree-inline.h"
69 #include "internal-fn.h"
71 #include "tree-ssa-loop-manip.h"
72 #include "tree-into-ssa.h"
75 #include "tree-pass.h"
76 #include "tree-dump.h"
78 #include "lto-streamer.h"
80 #include "ipa-utils.h"
81 #include "tree-pretty-print.h" /* for dump_function_header */
83 #include "pass_manager.h"
85 #include "tree-ssa-live.h" /* For remove_unused_locals. */
86 #include "tree-cfgcleanup.h"
90 /* This is used for debugging. It allows the current pass to printed
91 from anywhere in compilation.
92 The variable current_pass is also used for statistics and plugins. */
93 opt_pass
*current_pass
;
95 static void register_pass_name (opt_pass
*, const char *);
97 /* Most passes are single-instance (within their context) and thus don't
98 need to implement cloning, but passes that support multiple instances
99 *must* provide their own implementation of the clone method.
101 Handle this by providing a default implemenation, but make it a fatal
107 internal_error ("pass %s does not support cloning", name
);
111 opt_pass::gate (function
*)
117 opt_pass::execute (function
*)
122 opt_pass::opt_pass (const pass_data
&data
, context
*ctxt
)
126 static_pass_number (0),
133 pass_manager::execute_early_local_passes ()
135 execute_pass_list (cfun
, pass_build_ssa_passes_1
->sub
);
136 if (flag_check_pointer_bounds
)
137 execute_pass_list (cfun
, pass_chkp_instrumentation_passes_1
->sub
);
138 execute_pass_list (cfun
, pass_local_optimization_passes_1
->sub
);
142 pass_manager::execute_pass_mode_switching ()
144 return pass_mode_switching_1
->execute (cfun
);
148 /* Call from anywhere to find out what pass this is. Useful for
149 printing out debugging information deep inside an service
152 print_current_pass (FILE *file
)
155 fprintf (file
, "current pass = %s (%d)\n",
156 current_pass
->name
, current_pass
->static_pass_number
);
158 fprintf (file
, "no current pass.\n");
162 /* Call from the debugger to get the current pass name. */
166 print_current_pass (stderr
);
171 /* Global variables used to communicate with passes. */
173 bool first_pass_instance
;
176 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
179 This does nothing for local (non-static) variables, unless the
180 variable is a register variable with DECL_ASSEMBLER_NAME set. In
181 that case, or if the variable is not an automatic, it sets up the
182 RTL and outputs any assembler code (label definition, storage
183 allocation and initialization).
185 DECL is the declaration. TOP_LEVEL is nonzero
186 if this declaration is not within a function. */
189 rest_of_decl_compilation (tree decl
,
193 bool finalize
= true;
195 /* We deferred calling assemble_alias so that we could collect
196 other attributes such as visibility. Emit the alias now. */
200 alias
= lookup_attribute ("alias", DECL_ATTRIBUTES (decl
));
203 alias
= TREE_VALUE (TREE_VALUE (alias
));
204 alias
= get_identifier (TREE_STRING_POINTER (alias
));
205 /* A quirk of the initial implementation of aliases required that the
206 user add "extern" to all of them. Which is silly, but now
207 historical. Do note that the symbol is in fact locally defined. */
208 DECL_EXTERNAL (decl
) = 0;
209 TREE_STATIC (decl
) = 1;
210 assemble_alias (decl
, alias
);
215 /* Can't defer this, because it needs to happen before any
216 later function definitions are processed. */
217 if (DECL_ASSEMBLER_NAME_SET_P (decl
) && DECL_REGISTER (decl
))
218 make_decl_rtl (decl
);
220 /* Forward declarations for nested functions are not "external",
221 but we need to treat them as if they were. */
222 if (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)
223 || TREE_CODE (decl
) == FUNCTION_DECL
)
225 timevar_push (TV_VARCONST
);
227 /* Don't output anything when a tentative file-scope definition
228 is seen. But at end of compilation, do output code for them.
230 We do output all variables and rely on
231 callgraph code to defer them except for forward declarations
232 (see gcc.c-torture/compile/920624-1.c) */
234 || !DECL_DEFER_OUTPUT (decl
)
235 || DECL_INITIAL (decl
))
236 && (TREE_CODE (decl
) != VAR_DECL
|| !DECL_HAS_VALUE_EXPR_P (decl
))
237 && !DECL_EXTERNAL (decl
))
239 /* When reading LTO unit, we also read varpool, so do not
241 if (in_lto_p
&& !at_end
)
243 else if (finalize
&& TREE_CODE (decl
) != FUNCTION_DECL
)
244 varpool_node::finalize_decl (decl
);
247 #ifdef ASM_FINISH_DECLARE_OBJECT
248 if (decl
== last_assemble_variable_decl
)
250 ASM_FINISH_DECLARE_OBJECT (asm_out_file
, decl
,
255 timevar_pop (TV_VARCONST
);
257 else if (TREE_CODE (decl
) == TYPE_DECL
258 /* Like in rest_of_type_compilation, avoid confusing the debug
259 information machinery when there are errors. */
262 timevar_push (TV_SYMOUT
);
263 debug_hooks
->type_decl (decl
, !top_level
);
264 timevar_pop (TV_SYMOUT
);
267 /* Let cgraph know about the existence of variables. */
268 if (in_lto_p
&& !at_end
)
270 else if (TREE_CODE (decl
) == VAR_DECL
&& !DECL_EXTERNAL (decl
)
271 && TREE_STATIC (decl
))
272 varpool_node::get_create (decl
);
274 /* Generate early debug for global variables. Any local variables will
275 be handled by either handling reachable functions from
276 finalize_compilation_unit (and by consequence, locally scoped
277 symbols), or by rest_of_type_compilation below.
279 Also, pick up function prototypes, which will be mostly ignored
280 by the different early_global_decl() hooks, but will at least be
281 used by Go's hijack of the debug_hooks to implement
284 && (TREE_CODE (decl
) != FUNCTION_DECL
285 /* This will pick up function prototypes with no bodies,
286 which are not visible in finalize_compilation_unit()
287 while iterating with FOR_EACH_*_FUNCTION through the
289 || !DECL_SAVED_TREE (decl
))
291 /* We need to check both decl_function_context and
292 current_function_decl here to make sure local extern
293 declarations end up with the correct context.
295 For local extern declarations, decl_function_context is
296 empty, but current_function_decl is set to the function where
297 the extern was declared . Without the check for
298 !current_function_decl below, the local extern ends up
299 incorrectly with a top-level context.
311 extern int i; // Local extern declaration.
318 && !decl_function_context (decl
)
319 && !current_function_decl
320 && DECL_SOURCE_LOCATION (decl
) != BUILTINS_LOCATION
321 && (!decl_type_context (decl
)
322 /* If we created a varpool node for the decl make sure to
323 call early_global_decl. Otherwise we miss changes
324 introduced by member definitions like
325 struct A { static int staticdatamember; };
326 int A::staticdatamember;
327 and thus have incomplete early debug and late debug
328 called from varpool node removal fails to handle it
330 || (TREE_CODE (decl
) == VAR_DECL
331 && TREE_STATIC (decl
) && !DECL_EXTERNAL (decl
)))
332 /* Avoid confusing the debug information machinery when there are
335 (*debug_hooks
->early_global_decl
) (decl
);
338 /* Called after finishing a record, union or enumeral type. */
341 rest_of_type_compilation (tree type
, int toplev
)
343 /* Avoid confusing the debug information machinery when there are
348 timevar_push (TV_SYMOUT
);
349 debug_hooks
->type_decl (TYPE_STUB_DECL (type
), !toplev
);
350 timevar_pop (TV_SYMOUT
);
357 finish_optimization_passes (void)
360 struct dump_file_info
*dfi
;
362 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
364 timevar_push (TV_DUMP
);
365 if (profile_arc_flag
|| flag_test_coverage
|| flag_branch_probabilities
)
367 dumps
->dump_start (pass_profile_1
->static_pass_number
, NULL
);
369 dumps
->dump_finish (pass_profile_1
->static_pass_number
);
374 dumps
->dump_start (pass_profile_1
->static_pass_number
, NULL
);
375 print_combine_total_stats ();
376 dumps
->dump_finish (pass_profile_1
->static_pass_number
);
379 /* Do whatever is necessary to finish printing the graphs. */
380 for (i
= TDI_end
; (dfi
= dumps
->get_dump_file_info (i
)) != NULL
; ++i
)
381 if (dumps
->dump_initialized_p (i
)
382 && (dfi
->pflags
& TDF_GRAPH
) != 0
383 && (name
= dumps
->get_dump_file_name (i
)) != NULL
)
385 finish_graph_dump_file (name
);
389 timevar_pop (TV_DUMP
);
393 execute_build_ssa_passes (void)
395 /* Once this pass (and its sub-passes) are complete, all functions
396 will be in SSA form. Technically this state change is happening
397 a tad early, since the sub-passes have not yet run, but since
398 none of the sub-passes are IPA passes and do not create new
399 functions, this is ok. We're setting this value for the benefit
400 of IPA passes that follow. */
401 if (symtab
->state
< IPA_SSA
)
402 symtab
->state
= IPA_SSA
;
408 const pass_data pass_data_build_ssa_passes
=
410 SIMPLE_IPA_PASS
, /* type */
411 "build_ssa_passes", /* name */
412 OPTGROUP_NONE
, /* optinfo_flags */
413 TV_EARLY_LOCAL
, /* tv_id */
414 0, /* properties_required */
415 0, /* properties_provided */
416 0, /* properties_destroyed */
417 0, /* todo_flags_start */
418 /* todo_flags_finish is executed before subpases. For this reason
419 it makes no sense to remove unreachable functions here. */
420 0, /* todo_flags_finish */
423 class pass_build_ssa_passes
: public simple_ipa_opt_pass
426 pass_build_ssa_passes (gcc::context
*ctxt
)
427 : simple_ipa_opt_pass (pass_data_build_ssa_passes
, ctxt
)
430 /* opt_pass methods: */
431 virtual bool gate (function
*)
433 /* Don't bother doing anything if the program has errors. */
434 return (!seen_error () && !in_lto_p
);
437 virtual unsigned int execute (function
*)
439 return execute_build_ssa_passes ();
442 }; // class pass_build_ssa_passes
444 const pass_data pass_data_chkp_instrumentation_passes
=
446 SIMPLE_IPA_PASS
, /* type */
447 "chkp_passes", /* name */
448 OPTGROUP_NONE
, /* optinfo_flags */
450 0, /* properties_required */
451 0, /* properties_provided */
452 0, /* properties_destroyed */
453 0, /* todo_flags_start */
454 0, /* todo_flags_finish */
457 class pass_chkp_instrumentation_passes
: public simple_ipa_opt_pass
460 pass_chkp_instrumentation_passes (gcc::context
*ctxt
)
461 : simple_ipa_opt_pass (pass_data_chkp_instrumentation_passes
, ctxt
)
464 /* opt_pass methods: */
465 virtual bool gate (function
*)
467 /* Don't bother doing anything if the program has errors. */
468 return (flag_check_pointer_bounds
469 && !seen_error () && !in_lto_p
);
472 }; // class pass_chkp_instrumentation_passes
474 const pass_data pass_data_local_optimization_passes
=
476 SIMPLE_IPA_PASS
, /* type */
477 "opt_local_passes", /* name */
478 OPTGROUP_NONE
, /* optinfo_flags */
480 0, /* properties_required */
481 0, /* properties_provided */
482 0, /* properties_destroyed */
483 0, /* todo_flags_start */
484 0, /* todo_flags_finish */
487 class pass_local_optimization_passes
: public simple_ipa_opt_pass
490 pass_local_optimization_passes (gcc::context
*ctxt
)
491 : simple_ipa_opt_pass (pass_data_local_optimization_passes
, ctxt
)
494 /* opt_pass methods: */
495 virtual bool gate (function
*)
497 /* Don't bother doing anything if the program has errors. */
498 return (!seen_error () && !in_lto_p
);
501 }; // class pass_local_optimization_passes
505 simple_ipa_opt_pass
*
506 make_pass_build_ssa_passes (gcc::context
*ctxt
)
508 return new pass_build_ssa_passes (ctxt
);
511 simple_ipa_opt_pass
*
512 make_pass_chkp_instrumentation_passes (gcc::context
*ctxt
)
514 return new pass_chkp_instrumentation_passes (ctxt
);
517 simple_ipa_opt_pass
*
518 make_pass_local_optimization_passes (gcc::context
*ctxt
)
520 return new pass_local_optimization_passes (ctxt
);
525 const pass_data pass_data_all_early_optimizations
=
527 GIMPLE_PASS
, /* type */
528 "early_optimizations", /* name */
529 OPTGROUP_NONE
, /* optinfo_flags */
531 0, /* properties_required */
532 0, /* properties_provided */
533 0, /* properties_destroyed */
534 0, /* todo_flags_start */
535 0, /* todo_flags_finish */
538 class pass_all_early_optimizations
: public gimple_opt_pass
541 pass_all_early_optimizations (gcc::context
*ctxt
)
542 : gimple_opt_pass (pass_data_all_early_optimizations
, ctxt
)
545 /* opt_pass methods: */
546 virtual bool gate (function
*)
548 return (optimize
>= 1
549 /* Don't bother doing anything if the program has errors. */
553 }; // class pass_all_early_optimizations
557 static gimple_opt_pass
*
558 make_pass_all_early_optimizations (gcc::context
*ctxt
)
560 return new pass_all_early_optimizations (ctxt
);
565 const pass_data pass_data_all_optimizations
=
567 GIMPLE_PASS
, /* type */
568 "*all_optimizations", /* name */
569 OPTGROUP_NONE
, /* optinfo_flags */
570 TV_OPTIMIZE
, /* tv_id */
571 0, /* properties_required */
572 0, /* properties_provided */
573 0, /* properties_destroyed */
574 0, /* todo_flags_start */
575 0, /* todo_flags_finish */
578 class pass_all_optimizations
: public gimple_opt_pass
581 pass_all_optimizations (gcc::context
*ctxt
)
582 : gimple_opt_pass (pass_data_all_optimizations
, ctxt
)
585 /* opt_pass methods: */
586 virtual bool gate (function
*) { return optimize
>= 1 && !optimize_debug
; }
588 }; // class pass_all_optimizations
592 static gimple_opt_pass
*
593 make_pass_all_optimizations (gcc::context
*ctxt
)
595 return new pass_all_optimizations (ctxt
);
600 const pass_data pass_data_all_optimizations_g
=
602 GIMPLE_PASS
, /* type */
603 "*all_optimizations_g", /* name */
604 OPTGROUP_NONE
, /* optinfo_flags */
605 TV_OPTIMIZE
, /* tv_id */
606 0, /* properties_required */
607 0, /* properties_provided */
608 0, /* properties_destroyed */
609 0, /* todo_flags_start */
610 0, /* todo_flags_finish */
613 class pass_all_optimizations_g
: public gimple_opt_pass
616 pass_all_optimizations_g (gcc::context
*ctxt
)
617 : gimple_opt_pass (pass_data_all_optimizations_g
, ctxt
)
620 /* opt_pass methods: */
621 virtual bool gate (function
*) { return optimize
>= 1 && optimize_debug
; }
623 }; // class pass_all_optimizations_g
627 static gimple_opt_pass
*
628 make_pass_all_optimizations_g (gcc::context
*ctxt
)
630 return new pass_all_optimizations_g (ctxt
);
635 const pass_data pass_data_rest_of_compilation
=
638 "*rest_of_compilation", /* name */
639 OPTGROUP_NONE
, /* optinfo_flags */
640 TV_REST_OF_COMPILATION
, /* tv_id */
641 PROP_rtl
, /* properties_required */
642 0, /* properties_provided */
643 0, /* properties_destroyed */
644 0, /* todo_flags_start */
645 0, /* todo_flags_finish */
648 class pass_rest_of_compilation
: public rtl_opt_pass
651 pass_rest_of_compilation (gcc::context
*ctxt
)
652 : rtl_opt_pass (pass_data_rest_of_compilation
, ctxt
)
655 /* opt_pass methods: */
656 virtual bool gate (function
*)
658 /* Early return if there were errors. We can run afoul of our
659 consistency checks, and there's not really much point in fixing them. */
660 return !(rtl_dump_and_exit
|| flag_syntax_only
|| seen_error ());
663 }; // class pass_rest_of_compilation
667 static rtl_opt_pass
*
668 make_pass_rest_of_compilation (gcc::context
*ctxt
)
670 return new pass_rest_of_compilation (ctxt
);
675 const pass_data pass_data_postreload
=
678 "*all-postreload", /* name */
679 OPTGROUP_NONE
, /* optinfo_flags */
680 TV_POSTRELOAD
, /* tv_id */
681 PROP_rtl
, /* properties_required */
682 0, /* properties_provided */
683 0, /* properties_destroyed */
684 0, /* todo_flags_start */
685 0, /* todo_flags_finish */
688 class pass_postreload
: public rtl_opt_pass
691 pass_postreload (gcc::context
*ctxt
)
692 : rtl_opt_pass (pass_data_postreload
, ctxt
)
695 /* opt_pass methods: */
696 virtual bool gate (function
*) { return reload_completed
; }
698 }; // class pass_postreload
702 static rtl_opt_pass
*
703 make_pass_postreload (gcc::context
*ctxt
)
705 return new pass_postreload (ctxt
);
710 const pass_data pass_data_late_compilation
=
713 "*all-late_compilation", /* name */
714 OPTGROUP_NONE
, /* optinfo_flags */
715 TV_LATE_COMPILATION
, /* tv_id */
716 PROP_rtl
, /* properties_required */
717 0, /* properties_provided */
718 0, /* properties_destroyed */
719 0, /* todo_flags_start */
720 0, /* todo_flags_finish */
723 class pass_late_compilation
: public rtl_opt_pass
726 pass_late_compilation (gcc::context
*ctxt
)
727 : rtl_opt_pass (pass_data_late_compilation
, ctxt
)
730 /* opt_pass methods: */
731 virtual bool gate (function
*)
733 return reload_completed
|| targetm
.no_register_allocation
;
736 }; // class pass_late_compilation
740 static rtl_opt_pass
*
741 make_pass_late_compilation (gcc::context
*ctxt
)
743 return new pass_late_compilation (ctxt
);
748 /* Set the static pass number of pass PASS to ID and record that
749 in the mapping from static pass number to pass. */
753 set_pass_for_id (int id
, opt_pass
*pass
)
755 pass
->static_pass_number
= id
;
756 if (passes_by_id_size
<= id
)
758 passes_by_id
= XRESIZEVEC (opt_pass
*, passes_by_id
, id
+ 1);
759 memset (passes_by_id
+ passes_by_id_size
, 0,
760 (id
+ 1 - passes_by_id_size
) * sizeof (void *));
761 passes_by_id_size
= id
+ 1;
763 passes_by_id
[id
] = pass
;
766 /* Return the pass with the static pass number ID. */
769 pass_manager::get_pass_for_id (int id
) const
771 if (id
>= passes_by_id_size
)
773 return passes_by_id
[id
];
776 /* Iterate over the pass tree allocating dump file numbers. We want
777 to do this depth first, and independent of whether the pass is
781 register_one_dump_file (opt_pass
*pass
)
783 g
->get_passes ()->register_one_dump_file (pass
);
787 pass_manager::register_one_dump_file (opt_pass
*pass
)
789 char *dot_name
, *flag_name
, *glob_name
;
790 const char *name
, *full_name
, *prefix
;
793 int optgroup_flags
= OPTGROUP_NONE
;
794 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
796 /* See below in next_pass_1. */
798 if (pass
->static_pass_number
!= -1)
799 sprintf (num
, "%d", ((int) pass
->static_pass_number
< 0
800 ? 1 : pass
->static_pass_number
));
802 /* The name is both used to identify the pass for the purposes of plugins,
803 and to specify dump file name and option.
804 The latter two might want something short which is not quite unique; for
805 that reason, we may have a disambiguating prefix, followed by a space
806 to mark the start of the following dump file name / option string. */
807 name
= strchr (pass
->name
, ' ');
808 name
= name
? name
+ 1 : pass
->name
;
809 dot_name
= concat (".", name
, num
, NULL
);
810 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
814 optgroup_flags
|= OPTGROUP_IPA
;
816 else if (pass
->type
== GIMPLE_PASS
)
827 flag_name
= concat (prefix
, name
, num
, NULL
);
828 glob_name
= concat (prefix
, name
, NULL
);
829 optgroup_flags
|= pass
->optinfo_flags
;
830 /* For any passes that do not have an optgroup set, and which are not
831 IPA passes setup above, set the optgroup to OPTGROUP_OTHER so that
832 any dump messages are emitted properly under -fopt-info(-optall). */
833 if (optgroup_flags
== OPTGROUP_NONE
)
834 optgroup_flags
= OPTGROUP_OTHER
;
835 id
= dumps
->dump_register (dot_name
, flag_name
, glob_name
, flags
,
838 set_pass_for_id (id
, pass
);
839 full_name
= concat (prefix
, pass
->name
, num
, NULL
);
840 register_pass_name (pass
, full_name
);
841 free (CONST_CAST (char *, full_name
));
844 /* Register the dump files for the pass_manager starting at PASS. */
847 pass_manager::register_dump_files (opt_pass
*pass
)
851 if (pass
->name
&& pass
->name
[0] != '*')
852 register_one_dump_file (pass
);
855 register_dump_files (pass
->sub
);
862 static hash_map
<nofree_string_hash
, opt_pass
*> *name_to_pass_map
;
864 /* Register PASS with NAME. */
867 register_pass_name (opt_pass
*pass
, const char *name
)
869 if (!name_to_pass_map
)
870 name_to_pass_map
= new hash_map
<nofree_string_hash
, opt_pass
*> (256);
872 if (name_to_pass_map
->get (name
))
873 return; /* Ignore plugin passes. */
875 const char *unique_name
= xstrdup (name
);
876 name_to_pass_map
->put (unique_name
, pass
);
879 /* Map from pass id to canonicalized pass name. */
881 typedef const char *char_ptr
;
882 static vec
<char_ptr
> pass_tab
= vNULL
;
884 /* Callback function for traversing NAME_TO_PASS_MAP. */
887 passes_pass_traverse (const char *const &name
, opt_pass
*const &pass
, void *)
889 gcc_assert (pass
->static_pass_number
> 0);
890 gcc_assert (pass_tab
.exists ());
892 pass_tab
[pass
->static_pass_number
] = name
;
897 /* The function traverses NAME_TO_PASS_MAP and creates a pass info
898 table for dumping purpose. */
901 create_pass_tab (void)
903 if (!flag_dump_passes
)
906 pass_tab
.safe_grow_cleared (g
->get_passes ()->passes_by_id_size
+ 1);
907 name_to_pass_map
->traverse
<void *, passes_pass_traverse
> (NULL
);
910 static bool override_gate_status (opt_pass
*, tree
, bool);
912 /* Dump the instantiated name for PASS. IS_ON indicates if PASS
913 is turned on or not. */
916 dump_one_pass (opt_pass
*pass
, int pass_indent
)
918 int indent
= 3 * pass_indent
;
920 bool is_on
, is_really_on
;
922 is_on
= pass
->gate (cfun
);
923 is_really_on
= override_gate_status (pass
, current_function_decl
, is_on
);
925 if (pass
->static_pass_number
<= 0)
928 pn
= pass_tab
[pass
->static_pass_number
];
930 fprintf (stderr
, "%*s%-40s%*s:%s%s\n", indent
, " ", pn
,
931 (15 - indent
< 0 ? 0 : 15 - indent
), " ",
932 is_on
? " ON" : " OFF",
933 ((!is_on
) == (!is_really_on
) ? ""
934 : (is_really_on
? " (FORCED_ON)" : " (FORCED_OFF)")));
937 /* Dump pass list PASS with indentation INDENT. */
940 dump_pass_list (opt_pass
*pass
, int indent
)
944 dump_one_pass (pass
, indent
);
946 dump_pass_list (pass
->sub
, indent
+ 1);
952 /* Dump all optimization passes. */
957 g
->get_passes ()->dump_passes ();
961 pass_manager::dump_passes () const
963 push_dummy_function (true);
967 dump_pass_list (all_lowering_passes
, 1);
968 dump_pass_list (all_small_ipa_passes
, 1);
969 dump_pass_list (all_regular_ipa_passes
, 1);
970 dump_pass_list (all_late_ipa_passes
, 1);
971 dump_pass_list (all_passes
, 1);
973 pop_dummy_function ();
976 /* Returns the pass with NAME. */
979 get_pass_by_name (const char *name
)
981 opt_pass
**p
= name_to_pass_map
->get (name
);
989 /* Range [start, last]. */
995 const char *assem_name
;
996 struct uid_range
*next
;
999 typedef struct uid_range
*uid_range_p
;
1002 static vec
<uid_range_p
>
1003 enabled_pass_uid_range_tab
= vNULL
;
1004 static vec
<uid_range_p
>
1005 disabled_pass_uid_range_tab
= vNULL
;
1008 /* Parse option string for -fdisable- and -fenable-
1009 The syntax of the options:
1011 -fenable-<pass_name>
1012 -fdisable-<pass_name>
1014 -fenable-<pass_name>=s1:e1,s2:e2,...
1015 -fdisable-<pass_name>=s1:e1,s2:e2,...
1019 enable_disable_pass (const char *arg
, bool is_enable
)
1022 char *range_str
, *phase_name
;
1023 char *argstr
= xstrdup (arg
);
1024 vec
<uid_range_p
> *tab
= 0;
1026 range_str
= strchr (argstr
,'=');
1033 phase_name
= argstr
;
1037 error ("unrecognized option -fenable");
1039 error ("unrecognized option -fdisable");
1043 pass
= get_pass_by_name (phase_name
);
1044 if (!pass
|| pass
->static_pass_number
== -1)
1047 error ("unknown pass %s specified in -fenable", phase_name
);
1049 error ("unknown pass %s specified in -fdisable", phase_name
);
1055 tab
= &enabled_pass_uid_range_tab
;
1057 tab
= &disabled_pass_uid_range_tab
;
1059 if ((unsigned) pass
->static_pass_number
>= tab
->length ())
1060 tab
->safe_grow_cleared (pass
->static_pass_number
+ 1);
1065 uid_range_p new_range
= XCNEW (struct uid_range
);
1067 new_range
->start
= 0;
1068 new_range
->last
= (unsigned)-1;
1070 slot
= (*tab
)[pass
->static_pass_number
];
1071 new_range
->next
= slot
;
1072 (*tab
)[pass
->static_pass_number
] = new_range
;
1074 inform (UNKNOWN_LOCATION
, "enable pass %s for functions in the range "
1075 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
1077 inform (UNKNOWN_LOCATION
, "disable pass %s for functions in the range "
1078 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
1082 char *next_range
= NULL
;
1083 char *one_range
= range_str
;
1084 char *end_val
= NULL
;
1089 uid_range_p new_range
;
1090 char *invalid
= NULL
;
1092 char *func_name
= NULL
;
1094 next_range
= strchr (one_range
, ',');
1101 end_val
= strchr (one_range
, ':');
1107 start
= strtol (one_range
, &invalid
, 10);
1108 if (*invalid
|| start
< 0)
1110 if (end_val
|| (one_range
[0] >= '0'
1111 && one_range
[0] <= '9'))
1113 error ("Invalid range %s in option %s",
1115 is_enable
? "-fenable" : "-fdisable");
1119 func_name
= one_range
;
1123 new_range
= XCNEW (struct uid_range
);
1126 new_range
->start
= (unsigned) start
;
1127 new_range
->last
= (unsigned) start
;
1131 new_range
->start
= (unsigned) -1;
1132 new_range
->last
= (unsigned) -1;
1133 new_range
->assem_name
= xstrdup (func_name
);
1138 long last
= strtol (end_val
, &invalid
, 10);
1139 if (*invalid
|| last
< start
)
1141 error ("Invalid range %s in option %s",
1143 is_enable
? "-fenable" : "-fdisable");
1147 new_range
= XCNEW (struct uid_range
);
1148 new_range
->start
= (unsigned) start
;
1149 new_range
->last
= (unsigned) last
;
1152 slot
= (*tab
)[pass
->static_pass_number
];
1153 new_range
->next
= slot
;
1154 (*tab
)[pass
->static_pass_number
] = new_range
;
1157 if (new_range
->assem_name
)
1158 inform (UNKNOWN_LOCATION
,
1159 "enable pass %s for function %s",
1160 phase_name
, new_range
->assem_name
);
1162 inform (UNKNOWN_LOCATION
,
1163 "enable pass %s for functions in the range of [%u, %u]",
1164 phase_name
, new_range
->start
, new_range
->last
);
1168 if (new_range
->assem_name
)
1169 inform (UNKNOWN_LOCATION
,
1170 "disable pass %s for function %s",
1171 phase_name
, new_range
->assem_name
);
1173 inform (UNKNOWN_LOCATION
,
1174 "disable pass %s for functions in the range of [%u, %u]",
1175 phase_name
, new_range
->start
, new_range
->last
);
1178 one_range
= next_range
;
1179 } while (next_range
);
1185 /* Enable pass specified by ARG. */
1188 enable_pass (const char *arg
)
1190 enable_disable_pass (arg
, true);
1193 /* Disable pass specified by ARG. */
1196 disable_pass (const char *arg
)
1198 enable_disable_pass (arg
, false);
1201 /* Returns true if PASS is explicitly enabled/disabled for FUNC. */
1204 is_pass_explicitly_enabled_or_disabled (opt_pass
*pass
,
1206 vec
<uid_range_p
> tab
)
1208 uid_range_p slot
, range
;
1210 const char *aname
= NULL
;
1213 || (unsigned) pass
->static_pass_number
>= tab
.length ()
1214 || pass
->static_pass_number
== -1)
1217 slot
= tab
[pass
->static_pass_number
];
1221 cgraph_uid
= func
? cgraph_node::get (func
)->uid
: 0;
1222 if (func
&& DECL_ASSEMBLER_NAME_SET_P (func
))
1223 aname
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func
));
1228 if ((unsigned) cgraph_uid
>= range
->start
1229 && (unsigned) cgraph_uid
<= range
->last
)
1231 if (range
->assem_name
&& aname
1232 && !strcmp (range
->assem_name
, aname
))
1234 range
= range
->next
;
1241 /* Update static_pass_number for passes (and the flag
1242 TODO_mark_first_instance).
1244 Passes are constructed with static_pass_number preinitialized to 0
1246 This field is used in two different ways: initially as instance numbers
1247 of their kind, and then as ids within the entire pass manager.
1249 Within pass_manager::pass_manager:
1251 * In add_pass_instance(), as called by next_pass_1 in
1252 NEXT_PASS in init_optimization_passes
1254 * When the initial instance of a pass within a pass manager is seen,
1255 it is flagged, and its static_pass_number is set to -1
1257 * On subsequent times that it is seen, the static pass number
1258 is decremented each time, so that if there are e.g. 4 dups,
1259 they have static_pass_number -4, 2, 3, 4 respectively (note
1260 how the initial one is negative and gives the count); these
1261 can be thought of as instance numbers of the specific pass
1263 * Within the register_dump_files () traversal, set_pass_for_id()
1264 is called on each pass, using these instance numbers to create
1265 dumpfile switches, and then overwriting them with a pass id,
1266 which are global to the whole pass manager (based on
1267 (TDI_end + current value of extra_dump_files_in_use) ) */
1270 add_pass_instance (opt_pass
*new_pass
, bool track_duplicates
,
1271 opt_pass
*initial_pass
)
1273 /* Are we dealing with the first pass of its kind, or a clone? */
1274 if (new_pass
!= initial_pass
)
1276 /* We're dealing with a clone. */
1277 new_pass
->todo_flags_start
&= ~TODO_mark_first_instance
;
1279 /* Indicate to register_dump_files that this pass has duplicates,
1280 and so it should rename the dump file. The first instance will
1281 be -1, and be number of duplicates = -static_pass_number - 1.
1282 Subsequent instances will be > 0 and just the duplicate number. */
1283 if ((new_pass
->name
&& new_pass
->name
[0] != '*') || track_duplicates
)
1285 initial_pass
->static_pass_number
-= 1;
1286 new_pass
->static_pass_number
= -initial_pass
->static_pass_number
;
1291 /* We're dealing with the first pass of its kind. */
1292 new_pass
->todo_flags_start
|= TODO_mark_first_instance
;
1293 new_pass
->static_pass_number
= -1;
1295 invoke_plugin_callbacks (PLUGIN_NEW_PASS
, new_pass
);
1299 /* Add a pass to the pass list. Duplicate the pass if it's already
1303 next_pass_1 (opt_pass
**list
, opt_pass
*pass
, opt_pass
*initial_pass
)
1305 /* Every pass should have a name so that plugins can refer to them. */
1306 gcc_assert (pass
->name
!= NULL
);
1308 add_pass_instance (pass
, false, initial_pass
);
1311 return &(*list
)->next
;
1314 /* List node for an inserted pass instance. We need to keep track of all
1315 the newly-added pass instances (with 'added_pass_nodes' defined below)
1316 so that we can register their dump files after pass-positioning is finished.
1317 Registering dumping files needs to be post-processed or the
1318 static_pass_number of the opt_pass object would be modified and mess up
1319 the dump file names of future pass instances to be added. */
1321 struct pass_list_node
1324 struct pass_list_node
*next
;
1327 static struct pass_list_node
*added_pass_nodes
= NULL
;
1328 static struct pass_list_node
*prev_added_pass_node
;
1330 /* Insert the pass at the proper position. Return true if the pass
1331 is successfully added.
1333 NEW_PASS_INFO - new pass to be inserted
1334 PASS_LIST - root of the pass list to insert the new pass to */
1337 position_pass (struct register_pass_info
*new_pass_info
, opt_pass
**pass_list
)
1339 opt_pass
*pass
= *pass_list
, *prev_pass
= NULL
;
1340 bool success
= false;
1342 for ( ; pass
; prev_pass
= pass
, pass
= pass
->next
)
1344 /* Check if the current pass is of the same type as the new pass and
1345 matches the name and the instance number of the reference pass. */
1346 if (pass
->type
== new_pass_info
->pass
->type
1348 && !strcmp (pass
->name
, new_pass_info
->reference_pass_name
)
1349 && ((new_pass_info
->ref_pass_instance_number
== 0)
1350 || (new_pass_info
->ref_pass_instance_number
==
1351 pass
->static_pass_number
)
1352 || (new_pass_info
->ref_pass_instance_number
== 1
1353 && pass
->todo_flags_start
& TODO_mark_first_instance
)))
1356 struct pass_list_node
*new_pass_node
;
1358 if (new_pass_info
->ref_pass_instance_number
== 0)
1360 new_pass
= new_pass_info
->pass
->clone ();
1361 add_pass_instance (new_pass
, true, new_pass_info
->pass
);
1365 new_pass
= new_pass_info
->pass
;
1366 add_pass_instance (new_pass
, true, new_pass
);
1369 /* Insert the new pass instance based on the positioning op. */
1370 switch (new_pass_info
->pos_op
)
1372 case PASS_POS_INSERT_AFTER
:
1373 new_pass
->next
= pass
->next
;
1374 pass
->next
= new_pass
;
1376 /* Skip newly inserted pass to avoid repeated
1377 insertions in the case where the new pass and the
1378 existing one have the same name. */
1381 case PASS_POS_INSERT_BEFORE
:
1382 new_pass
->next
= pass
;
1384 prev_pass
->next
= new_pass
;
1386 *pass_list
= new_pass
;
1388 case PASS_POS_REPLACE
:
1389 new_pass
->next
= pass
->next
;
1391 prev_pass
->next
= new_pass
;
1393 *pass_list
= new_pass
;
1394 new_pass
->sub
= pass
->sub
;
1395 new_pass
->tv_id
= pass
->tv_id
;
1399 error ("invalid pass positioning operation");
1403 /* Save the newly added pass (instance) in the added_pass_nodes
1404 list so that we can register its dump file later. Note that
1405 we cannot register the dump file now because doing so will modify
1406 the static_pass_number of the opt_pass object and therefore
1407 mess up the dump file name of future instances. */
1408 new_pass_node
= XCNEW (struct pass_list_node
);
1409 new_pass_node
->pass
= new_pass
;
1410 if (!added_pass_nodes
)
1411 added_pass_nodes
= new_pass_node
;
1413 prev_added_pass_node
->next
= new_pass_node
;
1414 prev_added_pass_node
= new_pass_node
;
1419 if (pass
->sub
&& position_pass (new_pass_info
, &pass
->sub
))
1426 /* Hooks a new pass into the pass lists.
1428 PASS_INFO - pass information that specifies the opt_pass object,
1429 reference pass, instance number, and how to position
1433 register_pass (struct register_pass_info
*pass_info
)
1435 g
->get_passes ()->register_pass (pass_info
);
1439 register_pass (opt_pass
* pass
, pass_positioning_ops pos
,
1440 const char* ref_pass_name
, int ref_pass_inst_number
)
1442 register_pass_info i
;
1444 i
.reference_pass_name
= ref_pass_name
;
1445 i
.ref_pass_instance_number
= ref_pass_inst_number
;
1448 g
->get_passes ()->register_pass (&i
);
1452 pass_manager::register_pass (struct register_pass_info
*pass_info
)
1454 bool all_instances
, success
;
1455 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
1457 /* The checks below could fail in buggy plugins. Existing GCC
1458 passes should never fail these checks, so we mention plugin in
1460 if (!pass_info
->pass
)
1461 fatal_error (input_location
, "plugin cannot register a missing pass");
1463 if (!pass_info
->pass
->name
)
1464 fatal_error (input_location
, "plugin cannot register an unnamed pass");
1466 if (!pass_info
->reference_pass_name
)
1469 "plugin cannot register pass %qs without reference pass name",
1470 pass_info
->pass
->name
);
1472 /* Try to insert the new pass to the pass lists. We need to check
1473 all five lists as the reference pass could be in one (or all) of
1475 all_instances
= pass_info
->ref_pass_instance_number
== 0;
1476 success
= position_pass (pass_info
, &all_lowering_passes
);
1477 if (!success
|| all_instances
)
1478 success
|= position_pass (pass_info
, &all_small_ipa_passes
);
1479 if (!success
|| all_instances
)
1480 success
|= position_pass (pass_info
, &all_regular_ipa_passes
);
1481 if (!success
|| all_instances
)
1482 success
|= position_pass (pass_info
, &all_late_ipa_passes
);
1483 if (!success
|| all_instances
)
1484 success
|= position_pass (pass_info
, &all_passes
);
1488 "pass %qs not found but is referenced by new pass %qs",
1489 pass_info
->reference_pass_name
, pass_info
->pass
->name
);
1491 /* OK, we have successfully inserted the new pass. We need to register
1492 the dump files for the newly added pass and its duplicates (if any).
1493 Because the registration of plugin/backend passes happens after the
1494 command-line options are parsed, the options that specify single
1495 pass dumping (e.g. -fdump-tree-PASSNAME) cannot be used for new
1496 passes. Therefore we currently can only enable dumping of
1497 new passes when the 'dump-all' flags (e.g. -fdump-tree-all)
1498 are specified. While doing so, we also delete the pass_list_node
1499 objects created during pass positioning. */
1500 while (added_pass_nodes
)
1502 struct pass_list_node
*next_node
= added_pass_nodes
->next
;
1503 enum tree_dump_index tdi
;
1504 register_one_dump_file (added_pass_nodes
->pass
);
1505 if (added_pass_nodes
->pass
->type
== SIMPLE_IPA_PASS
1506 || added_pass_nodes
->pass
->type
== IPA_PASS
)
1508 else if (added_pass_nodes
->pass
->type
== GIMPLE_PASS
)
1512 /* Check if dump-all flag is specified. */
1513 if (dumps
->get_dump_file_info (tdi
)->pstate
)
1514 dumps
->get_dump_file_info (added_pass_nodes
->pass
->static_pass_number
)
1515 ->pstate
= dumps
->get_dump_file_info (tdi
)->pstate
;
1516 XDELETE (added_pass_nodes
);
1517 added_pass_nodes
= next_node
;
1521 /* Construct the pass tree. The sequencing of passes is driven by
1522 the cgraph routines:
1524 finalize_compilation_unit ()
1525 for each node N in the cgraph
1526 cgraph_analyze_function (N)
1527 cgraph_lower_function (N) -> all_lowering_passes
1529 If we are optimizing, compile is then invoked:
1532 ipa_passes () -> all_small_ipa_passes
1533 -> Analysis of all_regular_ipa_passes
1534 * possible LTO streaming at copmilation time *
1535 -> Execution of all_regular_ipa_passes
1536 * possible LTO streaming at link time *
1537 -> all_late_ipa_passes
1538 expand_all_functions ()
1539 for each node N in the cgraph
1540 expand_function (N) -> Transformation of all_regular_ipa_passes
1545 pass_manager::operator new (size_t sz
)
1547 /* Ensure that all fields of the pass manager are zero-initialized. */
1548 return xcalloc (1, sz
);
1552 pass_manager::operator delete (void *ptr
)
1557 pass_manager::pass_manager (context
*ctxt
)
1558 : all_passes (NULL
), all_small_ipa_passes (NULL
), all_lowering_passes (NULL
),
1559 all_regular_ipa_passes (NULL
),
1560 all_late_ipa_passes (NULL
), passes_by_id (NULL
), passes_by_id_size (0),
1565 /* Initialize the pass_lists array. */
1566 #define DEF_PASS_LIST(LIST) pass_lists[PASS_LIST_NO_##LIST] = &LIST;
1568 #undef DEF_PASS_LIST
1570 /* Build the tree of passes. */
1572 #define INSERT_PASSES_AFTER(PASS) \
1575 #define PUSH_INSERT_PASSES_WITHIN(PASS) \
1577 opt_pass **p = &(PASS ## _1)->sub;
1579 #define POP_INSERT_PASSES() \
1582 #define NEXT_PASS(PASS, NUM) \
1584 gcc_assert (NULL == PASS ## _ ## NUM); \
1586 PASS ## _1 = make_##PASS (m_ctxt); \
1589 gcc_assert (PASS ## _1); \
1590 PASS ## _ ## NUM = PASS ## _1->clone (); \
1592 p = next_pass_1 (p, PASS ## _ ## NUM, PASS ## _1); \
1595 #define TERMINATE_PASS_LIST() \
1598 #include "pass-instances.def"
1600 #undef INSERT_PASSES_AFTER
1601 #undef PUSH_INSERT_PASSES_WITHIN
1602 #undef POP_INSERT_PASSES
1604 #undef TERMINATE_PASS_LIST
1606 /* Register the passes with the tree dump code. */
1607 register_dump_files (all_lowering_passes
);
1608 register_dump_files (all_small_ipa_passes
);
1609 register_dump_files (all_regular_ipa_passes
);
1610 register_dump_files (all_late_ipa_passes
);
1611 register_dump_files (all_passes
);
1615 delete_pass_tree (opt_pass
*pass
)
1619 /* Recurse into child passes. */
1620 delete_pass_tree (pass
->sub
);
1622 opt_pass
*next
= pass
->next
;
1624 /* Delete this pass. */
1627 /* Iterate onto sibling passes. */
1632 pass_manager::~pass_manager ()
1634 XDELETEVEC (passes_by_id
);
1636 /* Call delete_pass_tree on each of the pass_lists. */
1637 #define DEF_PASS_LIST(LIST) \
1638 delete_pass_tree (*pass_lists[PASS_LIST_NO_##LIST]);
1640 #undef DEF_PASS_LIST
1644 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1645 function CALLBACK for every function in the call graph. Otherwise,
1646 call CALLBACK on the current function. */
1649 do_per_function (void (*callback
) (function
*, void *data
), void *data
)
1651 if (current_function_decl
)
1652 callback (cfun
, data
);
1655 struct cgraph_node
*node
;
1656 FOR_EACH_DEFINED_FUNCTION (node
)
1657 if (node
->analyzed
&& (gimple_has_body_p (node
->decl
) && !in_lto_p
)
1658 && (!node
->clone_of
|| node
->decl
!= node
->clone_of
->decl
))
1659 callback (DECL_STRUCT_FUNCTION (node
->decl
), data
);
1663 /* Because inlining might remove no-longer reachable nodes, we need to
1664 keep the array visible to garbage collector to avoid reading collected
1667 static GTY ((length ("nnodes"))) cgraph_node
**order
;
1669 /* Hook called when NODE is removed and therefore should be
1670 excluded from order vector. DATA is an array of integers.
1671 DATA[0] holds max index it may be accessed by. For cgraph
1672 node DATA[node->uid + 1] holds index of this node in order
1675 remove_cgraph_node_from_order (cgraph_node
*node
, void *data
)
1677 int *order_idx
= (int *)data
;
1679 if (node
->uid
>= order_idx
[0])
1682 int idx
= order_idx
[node
->uid
+ 1];
1683 if (idx
>= 0 && idx
< nnodes
&& order
[idx
] == node
)
1687 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1688 function CALLBACK for every function in the call graph. Otherwise,
1689 call CALLBACK on the current function.
1690 This function is global so that plugins can use it. */
1692 do_per_function_toporder (void (*callback
) (function
*, void *data
), void *data
)
1696 if (current_function_decl
)
1697 callback (cfun
, data
);
1700 cgraph_node_hook_list
*hook
;
1702 gcc_assert (!order
);
1703 order
= ggc_vec_alloc
<cgraph_node
*> (symtab
->cgraph_count
);
1705 order_idx
= XALLOCAVEC (int, symtab
->cgraph_max_uid
+ 1);
1706 memset (order_idx
+ 1, -1, sizeof (int) * symtab
->cgraph_max_uid
);
1707 order_idx
[0] = symtab
->cgraph_max_uid
;
1709 nnodes
= ipa_reverse_postorder (order
);
1710 for (i
= nnodes
- 1; i
>= 0; i
--)
1712 order
[i
]->process
= 1;
1713 order_idx
[order
[i
]->uid
+ 1] = i
;
1715 hook
= symtab
->add_cgraph_removal_hook (remove_cgraph_node_from_order
,
1717 for (i
= nnodes
- 1; i
>= 0; i
--)
1719 /* Function could be inlined and removed as unreachable. */
1723 struct cgraph_node
*node
= order
[i
];
1725 /* Allow possibly removed nodes to be garbage collected. */
1728 if (node
->has_gimple_body_p ())
1729 callback (DECL_STRUCT_FUNCTION (node
->decl
), data
);
1731 symtab
->remove_cgraph_removal_hook (hook
);
1738 /* Helper function to perform function body dump. */
1741 execute_function_dump (function
*fn
, void *data
)
1743 opt_pass
*pass
= (opt_pass
*)data
;
1749 if (fn
->curr_properties
& PROP_trees
)
1750 dump_function_to_file (fn
->decl
, dump_file
, dump_flags
);
1752 print_rtl_with_bb (dump_file
, get_insns (), dump_flags
);
1754 /* Flush the file. If verification fails, we won't be able to
1755 close the file before aborting. */
1758 if ((fn
->curr_properties
& PROP_cfg
)
1759 && (dump_flags
& TDF_GRAPH
))
1761 if (!pass
->graph_dump_initialized
)
1763 clean_graph_dump_file (dump_file_name
);
1764 pass
->graph_dump_initialized
= true;
1766 print_graph_cfg (dump_file_name
, fn
);
1773 static struct profile_record
*profile_record
;
1775 /* Do profile consistency book-keeping for the pass with static number INDEX.
1776 If SUBPASS is zero, we run _before_ the pass, and if SUBPASS is one, then
1777 we run _after_ the pass. RUN is true if the pass really runs, or FALSE
1778 if we are only book-keeping on passes that may have selectively disabled
1779 themselves on a given function. */
1781 check_profile_consistency (int index
, int subpass
, bool run
)
1783 pass_manager
*passes
= g
->get_passes ();
1786 if (!profile_record
)
1787 profile_record
= XCNEWVEC (struct profile_record
,
1788 passes
->passes_by_id_size
);
1789 gcc_assert (index
< passes
->passes_by_id_size
&& index
>= 0);
1790 gcc_assert (subpass
< 2);
1791 profile_record
[index
].run
|= run
;
1792 account_profile_record (&profile_record
[index
], subpass
);
1795 /* Output profile consistency. */
1798 dump_profile_report (void)
1800 g
->get_passes ()->dump_profile_report ();
1804 pass_manager::dump_profile_report () const
1807 int last_freq_in
= 0, last_count_in
= 0, last_freq_out
= 0, last_count_out
= 0;
1808 gcov_type last_time
= 0, last_size
= 0;
1809 double rel_time_change
, rel_size_change
;
1810 int last_reported
= 0;
1812 if (!profile_record
)
1814 fprintf (stderr
, "\nProfile consistency report:\n\n");
1815 fprintf (stderr
, "Pass name |mismatch in |mismated out|Overall\n");
1816 fprintf (stderr
, " |freq count |freq count |size time\n");
1818 for (i
= 0; i
< passes_by_id_size
; i
++)
1819 for (j
= 0 ; j
< 2; j
++)
1820 if (profile_record
[i
].run
)
1823 rel_time_change
= (profile_record
[i
].time
[j
]
1824 - (double)last_time
) * 100 / (double)last_time
;
1826 rel_time_change
= 0;
1828 rel_size_change
= (profile_record
[i
].size
[j
]
1829 - (double)last_size
) * 100 / (double)last_size
;
1831 rel_size_change
= 0;
1833 if (profile_record
[i
].num_mismatched_freq_in
[j
] != last_freq_in
1834 || profile_record
[i
].num_mismatched_freq_out
[j
] != last_freq_out
1835 || profile_record
[i
].num_mismatched_count_in
[j
] != last_count_in
1836 || profile_record
[i
].num_mismatched_count_out
[j
] != last_count_out
1837 || rel_time_change
|| rel_size_change
)
1840 fprintf (stderr
, "%-20s %s",
1841 passes_by_id
[i
]->name
,
1842 j
? "(after TODO)" : " ");
1843 if (profile_record
[i
].num_mismatched_freq_in
[j
] != last_freq_in
)
1844 fprintf (stderr
, "| %+5i",
1845 profile_record
[i
].num_mismatched_freq_in
[j
]
1848 fprintf (stderr
, "| ");
1849 if (profile_record
[i
].num_mismatched_count_in
[j
] != last_count_in
)
1850 fprintf (stderr
, " %+5i",
1851 profile_record
[i
].num_mismatched_count_in
[j
]
1854 fprintf (stderr
, " ");
1855 if (profile_record
[i
].num_mismatched_freq_out
[j
] != last_freq_out
)
1856 fprintf (stderr
, "| %+5i",
1857 profile_record
[i
].num_mismatched_freq_out
[j
]
1860 fprintf (stderr
, "| ");
1861 if (profile_record
[i
].num_mismatched_count_out
[j
] != last_count_out
)
1862 fprintf (stderr
, " %+5i",
1863 profile_record
[i
].num_mismatched_count_out
[j
]
1866 fprintf (stderr
, " ");
1868 /* Size/time units change across gimple and RTL. */
1869 if (i
== pass_expand_1
->static_pass_number
)
1870 fprintf (stderr
, "|----------");
1873 if (rel_size_change
)
1874 fprintf (stderr
, "| %+8.4f%%", rel_size_change
);
1876 fprintf (stderr
, "| ");
1877 if (rel_time_change
)
1878 fprintf (stderr
, " %+8.4f%%", rel_time_change
);
1880 fprintf (stderr
, "\n");
1881 last_freq_in
= profile_record
[i
].num_mismatched_freq_in
[j
];
1882 last_freq_out
= profile_record
[i
].num_mismatched_freq_out
[j
];
1883 last_count_in
= profile_record
[i
].num_mismatched_count_in
[j
];
1884 last_count_out
= profile_record
[i
].num_mismatched_count_out
[j
];
1886 else if (j
&& last_reported
!= i
)
1889 fprintf (stderr
, "%-20s ------------| | |\n",
1890 passes_by_id
[i
]->name
);
1892 last_time
= profile_record
[i
].time
[j
];
1893 last_size
= profile_record
[i
].size
[j
];
1897 /* Perform all TODO actions that ought to be done on each function. */
1900 execute_function_todo (function
*fn
, void *data
)
1902 bool from_ipa_pass
= (cfun
== NULL
);
1903 unsigned int flags
= (size_t)data
;
1904 flags
&= ~fn
->last_verified
;
1910 /* Always cleanup the CFG before trying to update SSA. */
1911 if (flags
& TODO_cleanup_cfg
)
1913 cleanup_tree_cfg ();
1915 /* When cleanup_tree_cfg merges consecutive blocks, it may
1916 perform some simplistic propagation when removing single
1917 valued PHI nodes. This propagation may, in turn, cause the
1918 SSA form to become out-of-date (see PR 22037). So, even
1919 if the parent pass had not scheduled an SSA update, we may
1920 still need to do one. */
1921 if (!(flags
& TODO_update_ssa_any
) && need_ssa_update_p (cfun
))
1922 flags
|= TODO_update_ssa
;
1925 if (flags
& TODO_update_ssa_any
)
1927 unsigned update_flags
= flags
& TODO_update_ssa_any
;
1928 update_ssa (update_flags
);
1931 if (flag_tree_pta
&& (flags
& TODO_rebuild_alias
))
1932 compute_may_aliases ();
1934 if (optimize
&& (flags
& TODO_update_address_taken
))
1935 execute_update_addresses_taken ();
1937 if (flags
& TODO_remove_unused_locals
)
1938 remove_unused_locals ();
1940 if (flags
& TODO_rebuild_frequencies
)
1941 rebuild_frequencies ();
1943 if (flags
& TODO_rebuild_cgraph_edges
)
1944 cgraph_edge::rebuild_edges ();
1946 gcc_assert (dom_info_state (fn
, CDI_POST_DOMINATORS
) == DOM_NONE
);
1947 /* If we've seen errors do not bother running any verifiers. */
1950 #if defined ENABLE_CHECKING
1951 dom_state pre_verify_state
= dom_info_state (fn
, CDI_DOMINATORS
);
1952 dom_state pre_verify_pstate
= dom_info_state (fn
, CDI_POST_DOMINATORS
);
1954 if (flags
& TODO_verify_il
)
1956 if (cfun
->curr_properties
& PROP_trees
)
1958 if (cfun
->curr_properties
& PROP_cfg
)
1959 /* IPA passes leave stmts to be fixed up, so make sure to
1960 not verify stmts really throw. */
1961 verify_gimple_in_cfg (cfun
, !from_ipa_pass
);
1963 verify_gimple_in_seq (gimple_body (cfun
->decl
));
1965 if (cfun
->curr_properties
& PROP_ssa
)
1966 /* IPA passes leave stmts to be fixed up, so make sure to
1967 not verify SSA operands whose verifier will choke on that. */
1968 verify_ssa (true, !from_ipa_pass
);
1969 /* IPA passes leave basic-blocks unsplit, so make sure to
1970 not trip on that. */
1971 if ((cfun
->curr_properties
& PROP_cfg
)
1973 verify_flow_info ();
1975 && loops_state_satisfies_p (LOOP_CLOSED_SSA
))
1976 verify_loop_closed_ssa (false);
1977 if (cfun
->curr_properties
& PROP_rtl
)
1978 verify_rtl_sharing ();
1981 /* Make sure verifiers don't change dominator state. */
1982 gcc_assert (dom_info_state (fn
, CDI_DOMINATORS
) == pre_verify_state
);
1983 gcc_assert (dom_info_state (fn
, CDI_POST_DOMINATORS
) == pre_verify_pstate
);
1987 fn
->last_verified
= flags
& TODO_verify_all
;
1991 /* For IPA passes make sure to release dominator info, it can be
1992 computed by non-verifying TODOs. */
1995 free_dominance_info (fn
, CDI_DOMINATORS
);
1996 free_dominance_info (fn
, CDI_POST_DOMINATORS
);
2000 /* Perform all TODO actions. */
2002 execute_todo (unsigned int flags
)
2004 #if defined ENABLE_CHECKING
2006 && need_ssa_update_p (cfun
))
2007 gcc_assert (flags
& TODO_update_ssa_any
);
2010 timevar_push (TV_TODO
);
2012 /* Inform the pass whether it is the first time it is run. */
2013 first_pass_instance
= (flags
& TODO_mark_first_instance
) != 0;
2015 statistics_fini_pass ();
2018 do_per_function (execute_function_todo
, (void *)(size_t) flags
);
2020 /* Always remove functions just as before inlining: IPA passes might be
2021 interested to see bodies of extern inline functions that are not inlined
2022 to analyze side effects. The full removal is done just at the end
2023 of IPA pass queue. */
2024 if (flags
& TODO_remove_functions
)
2027 symtab
->remove_unreachable_nodes (dump_file
);
2030 if ((flags
& TODO_dump_symtab
) && dump_file
&& !current_function_decl
)
2033 symtab_node::dump_table (dump_file
);
2034 /* Flush the file. If verification fails, we won't be able to
2035 close the file before aborting. */
2039 /* Now that the dumping has been done, we can get rid of the optional
2041 if (flags
& TODO_df_finish
)
2042 df_finish_pass ((flags
& TODO_df_verify
) != 0);
2044 timevar_pop (TV_TODO
);
2047 /* Verify invariants that should hold between passes. This is a place
2048 to put simple sanity checks. */
2051 verify_interpass_invariants (void)
2053 gcc_checking_assert (!fold_deferring_overflow_warnings_p ());
2056 /* Clear the last verified flag. */
2059 clear_last_verified (function
*fn
, void *data ATTRIBUTE_UNUSED
)
2061 fn
->last_verified
= 0;
2064 /* Helper function. Verify that the properties has been turn into the
2065 properties expected by the pass. */
2067 #ifdef ENABLE_CHECKING
2069 verify_curr_properties (function
*fn
, void *data
)
2071 unsigned int props
= (size_t)data
;
2072 gcc_assert ((fn
->curr_properties
& props
) == props
);
2076 /* Initialize pass dump file. */
2077 /* This is non-static so that the plugins can use it. */
2080 pass_init_dump_file (opt_pass
*pass
)
2082 /* If a dump file name is present, open it if enabled. */
2083 if (pass
->static_pass_number
!= -1)
2085 timevar_push (TV_DUMP
);
2086 gcc::dump_manager
*dumps
= g
->get_dumps ();
2087 bool initializing_dump
=
2088 !dumps
->dump_initialized_p (pass
->static_pass_number
);
2089 dump_file_name
= dumps
->get_dump_file_name (pass
->static_pass_number
);
2090 dumps
->dump_start (pass
->static_pass_number
, &dump_flags
);
2091 if (dump_file
&& current_function_decl
)
2092 dump_function_header (dump_file
, current_function_decl
, dump_flags
);
2093 if (initializing_dump
2094 && dump_file
&& (dump_flags
& TDF_GRAPH
)
2095 && cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2097 clean_graph_dump_file (dump_file_name
);
2098 pass
->graph_dump_initialized
= true;
2100 timevar_pop (TV_DUMP
);
2101 return initializing_dump
;
2107 /* Flush PASS dump file. */
2108 /* This is non-static so that plugins can use it. */
2111 pass_fini_dump_file (opt_pass
*pass
)
2113 timevar_push (TV_DUMP
);
2115 /* Flush and close dump file. */
2118 free (CONST_CAST (char *, dump_file_name
));
2119 dump_file_name
= NULL
;
2122 g
->get_dumps ()->dump_finish (pass
->static_pass_number
);
2123 timevar_pop (TV_DUMP
);
2126 /* After executing the pass, apply expected changes to the function
2130 update_properties_after_pass (function
*fn
, void *data
)
2132 opt_pass
*pass
= (opt_pass
*) data
;
2133 fn
->curr_properties
= (fn
->curr_properties
| pass
->properties_provided
)
2134 & ~pass
->properties_destroyed
;
2137 /* Execute summary generation for all of the passes in IPA_PASS. */
2140 execute_ipa_summary_passes (ipa_opt_pass_d
*ipa_pass
)
2144 opt_pass
*pass
= ipa_pass
;
2146 /* Execute all of the IPA_PASSes in the list. */
2147 if (ipa_pass
->type
== IPA_PASS
2148 && pass
->gate (cfun
)
2149 && ipa_pass
->generate_summary
)
2151 pass_init_dump_file (pass
);
2153 /* If a timevar is present, start it. */
2155 timevar_push (pass
->tv_id
);
2157 current_pass
= pass
;
2158 ipa_pass
->generate_summary ();
2162 timevar_pop (pass
->tv_id
);
2164 pass_fini_dump_file (pass
);
2166 ipa_pass
= (ipa_opt_pass_d
*)ipa_pass
->next
;
2170 /* Execute IPA_PASS function transform on NODE. */
2173 execute_one_ipa_transform_pass (struct cgraph_node
*node
,
2174 ipa_opt_pass_d
*ipa_pass
)
2176 opt_pass
*pass
= ipa_pass
;
2177 unsigned int todo_after
= 0;
2179 current_pass
= pass
;
2180 if (!ipa_pass
->function_transform
)
2183 /* Note that the folders should only create gimple expressions.
2184 This is a hack until the new folder is ready. */
2185 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
2187 pass_init_dump_file (pass
);
2189 /* Run pre-pass verification. */
2190 execute_todo (ipa_pass
->function_transform_todo_flags_start
);
2192 /* If a timevar is present, start it. */
2193 if (pass
->tv_id
!= TV_NONE
)
2194 timevar_push (pass
->tv_id
);
2197 todo_after
= ipa_pass
->function_transform (node
);
2200 if (pass
->tv_id
!= TV_NONE
)
2201 timevar_pop (pass
->tv_id
);
2203 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2204 check_profile_consistency (pass
->static_pass_number
, 0, true);
2206 /* Run post-pass cleanup and verification. */
2207 execute_todo (todo_after
);
2208 verify_interpass_invariants ();
2209 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2210 check_profile_consistency (pass
->static_pass_number
, 1, true);
2213 do_per_function (execute_function_dump
, NULL
);
2214 pass_fini_dump_file (pass
);
2216 current_pass
= NULL
;
2218 /* Signal this is a suitable GC collection point. */
2219 if (!(todo_after
& TODO_do_not_ggc_collect
))
2223 /* For the current function, execute all ipa transforms. */
2226 execute_all_ipa_transforms (void)
2228 struct cgraph_node
*node
;
2231 node
= cgraph_node::get (current_function_decl
);
2233 if (node
->ipa_transforms_to_apply
.exists ())
2237 for (i
= 0; i
< node
->ipa_transforms_to_apply
.length (); i
++)
2238 execute_one_ipa_transform_pass (node
, node
->ipa_transforms_to_apply
[i
]);
2239 node
->ipa_transforms_to_apply
.release ();
2243 /* Check if PASS is explicitly disabled or enabled and return
2244 the gate status. FUNC is the function to be processed, and
2245 GATE_STATUS is the gate status determined by pass manager by
2249 override_gate_status (opt_pass
*pass
, tree func
, bool gate_status
)
2251 bool explicitly_enabled
= false;
2252 bool explicitly_disabled
= false;
2255 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2256 enabled_pass_uid_range_tab
);
2258 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2259 disabled_pass_uid_range_tab
);
2261 gate_status
= !explicitly_disabled
&& (gate_status
|| explicitly_enabled
);
2270 execute_one_pass (opt_pass
*pass
)
2272 unsigned int todo_after
= 0;
2276 /* IPA passes are executed on whole program, so cfun should be NULL.
2277 Other passes need function context set. */
2278 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
2279 gcc_assert (!cfun
&& !current_function_decl
);
2281 gcc_assert (cfun
&& current_function_decl
);
2283 current_pass
= pass
;
2285 /* Check whether gate check should be avoided.
2286 User controls the value of the gate through the parameter "gate_status". */
2287 gate_status
= pass
->gate (cfun
);
2288 gate_status
= override_gate_status (pass
, current_function_decl
, gate_status
);
2290 /* Override gate with plugin. */
2291 invoke_plugin_callbacks (PLUGIN_OVERRIDE_GATE
, &gate_status
);
2295 /* Run so passes selectively disabling themselves on a given function
2296 are not miscounted. */
2297 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2299 check_profile_consistency (pass
->static_pass_number
, 0, false);
2300 check_profile_consistency (pass
->static_pass_number
, 1, false);
2302 current_pass
= NULL
;
2306 /* Pass execution event trigger: useful to identify passes being
2308 invoke_plugin_callbacks (PLUGIN_PASS_EXECUTION
, pass
);
2310 if (!quiet_flag
&& !cfun
)
2311 fprintf (stderr
, " <%s>", pass
->name
? pass
->name
: "");
2313 /* Note that the folders should only create gimple expressions.
2314 This is a hack until the new folder is ready. */
2315 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
2317 pass_init_dump_file (pass
);
2319 /* Run pre-pass verification. */
2320 execute_todo (pass
->todo_flags_start
);
2322 #ifdef ENABLE_CHECKING
2323 do_per_function (verify_curr_properties
,
2324 (void *)(size_t)pass
->properties_required
);
2327 /* If a timevar is present, start it. */
2328 if (pass
->tv_id
!= TV_NONE
)
2329 timevar_push (pass
->tv_id
);
2332 todo_after
= pass
->execute (cfun
);
2333 do_per_function (clear_last_verified
, NULL
);
2336 if (pass
->tv_id
!= TV_NONE
)
2337 timevar_pop (pass
->tv_id
);
2339 do_per_function (update_properties_after_pass
, pass
);
2341 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2342 check_profile_consistency (pass
->static_pass_number
, 0, true);
2344 /* Run post-pass cleanup and verification. */
2345 execute_todo (todo_after
| pass
->todo_flags_finish
| TODO_verify_il
);
2346 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2347 check_profile_consistency (pass
->static_pass_number
, 1, true);
2349 verify_interpass_invariants ();
2351 do_per_function (execute_function_dump
, pass
);
2352 if (pass
->type
== IPA_PASS
)
2354 struct cgraph_node
*node
;
2355 if (((ipa_opt_pass_d
*)pass
)->function_transform
)
2356 FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node
)
2357 node
->ipa_transforms_to_apply
.safe_push ((ipa_opt_pass_d
*)pass
);
2360 if (!current_function_decl
)
2361 symtab
->process_new_functions ();
2363 pass_fini_dump_file (pass
);
2365 if (pass
->type
!= SIMPLE_IPA_PASS
&& pass
->type
!= IPA_PASS
)
2366 gcc_assert (!(cfun
->curr_properties
& PROP_trees
)
2367 || pass
->type
!= RTL_PASS
);
2369 current_pass
= NULL
;
2371 /* Signal this is a suitable GC collection point. */
2372 if (!((todo_after
| pass
->todo_flags_finish
) & TODO_do_not_ggc_collect
))
2379 execute_pass_list_1 (opt_pass
*pass
)
2383 gcc_assert (pass
->type
== GIMPLE_PASS
2384 || pass
->type
== RTL_PASS
);
2385 if (execute_one_pass (pass
) && pass
->sub
)
2386 execute_pass_list_1 (pass
->sub
);
2393 execute_pass_list (function
*fn
, opt_pass
*pass
)
2396 execute_pass_list_1 (pass
);
2399 free_dominance_info (CDI_DOMINATORS
);
2400 free_dominance_info (CDI_POST_DOMINATORS
);
2405 /* Write out all LTO data. */
2409 timevar_push (TV_IPA_LTO_GIMPLE_OUT
);
2411 timevar_pop (TV_IPA_LTO_GIMPLE_OUT
);
2412 timevar_push (TV_IPA_LTO_DECL_OUT
);
2413 produce_asm_for_decls ();
2414 timevar_pop (TV_IPA_LTO_DECL_OUT
);
2417 /* Same as execute_pass_list but assume that subpasses of IPA passes
2418 are local passes. If SET is not NULL, write out summaries of only
2419 those node in SET. */
2422 ipa_write_summaries_2 (opt_pass
*pass
, struct lto_out_decl_state
*state
)
2426 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*)pass
;
2427 gcc_assert (!current_function_decl
);
2429 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2430 if (pass
->type
== IPA_PASS
2431 && ipa_pass
->write_summary
2432 && pass
->gate (cfun
))
2434 /* If a timevar is present, start it. */
2436 timevar_push (pass
->tv_id
);
2438 pass_init_dump_file (pass
);
2440 current_pass
= pass
;
2441 ipa_pass
->write_summary ();
2443 pass_fini_dump_file (pass
);
2445 /* If a timevar is present, start it. */
2447 timevar_pop (pass
->tv_id
);
2450 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2451 ipa_write_summaries_2 (pass
->sub
, state
);
2457 /* Helper function of ipa_write_summaries. Creates and destroys the
2458 decl state and calls ipa_write_summaries_2 for all passes that have
2459 summaries. SET is the set of nodes to be written. */
2462 ipa_write_summaries_1 (lto_symtab_encoder_t encoder
)
2464 pass_manager
*passes
= g
->get_passes ();
2465 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2466 state
->symtab_node_encoder
= encoder
;
2468 lto_output_init_mode_table ();
2469 lto_push_out_decl_state (state
);
2471 gcc_assert (!flag_wpa
);
2472 ipa_write_summaries_2 (passes
->all_regular_ipa_passes
, state
);
2476 gcc_assert (lto_get_out_decl_state () == state
);
2477 lto_pop_out_decl_state ();
2478 lto_delete_out_decl_state (state
);
2481 /* Write out summaries for all the nodes in the callgraph. */
2484 ipa_write_summaries (void)
2486 lto_symtab_encoder_t encoder
;
2488 varpool_node
*vnode
;
2489 struct cgraph_node
*node
;
2490 struct cgraph_node
**order
;
2492 if ((!flag_generate_lto
&& !flag_generate_offload
) || seen_error ())
2495 select_what_to_stream ();
2497 encoder
= lto_symtab_encoder_new (false);
2499 /* Create the callgraph set in the same order used in
2500 cgraph_expand_all_functions. This mostly facilitates debugging,
2501 since it causes the gimple file to be processed in the same order
2502 as the source code. */
2503 order
= XCNEWVEC (struct cgraph_node
*, symtab
->cgraph_count
);
2504 order_pos
= ipa_reverse_postorder (order
);
2505 gcc_assert (order_pos
== symtab
->cgraph_count
);
2507 for (i
= order_pos
- 1; i
>= 0; i
--)
2509 struct cgraph_node
*node
= order
[i
];
2511 if (node
->has_gimple_body_p ())
2513 /* When streaming out references to statements as part of some IPA
2514 pass summary, the statements need to have uids assigned and the
2515 following does that for all the IPA passes here. Naturally, this
2516 ordering then matches the one IPA-passes get in their stmt_fixup
2519 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
2520 renumber_gimple_stmt_uids ();
2523 if (node
->definition
&& node
->need_lto_streaming
)
2524 lto_set_symtab_encoder_in_partition (encoder
, node
);
2527 FOR_EACH_DEFINED_FUNCTION (node
)
2528 if (node
->alias
&& node
->need_lto_streaming
)
2529 lto_set_symtab_encoder_in_partition (encoder
, node
);
2530 FOR_EACH_DEFINED_VARIABLE (vnode
)
2531 if (vnode
->need_lto_streaming
)
2532 lto_set_symtab_encoder_in_partition (encoder
, vnode
);
2534 ipa_write_summaries_1 (compute_ltrans_boundary (encoder
));
2539 /* Same as execute_pass_list but assume that subpasses of IPA passes
2540 are local passes. If SET is not NULL, write out optimization summaries of
2541 only those node in SET. */
2544 ipa_write_optimization_summaries_1 (opt_pass
*pass
,
2545 struct lto_out_decl_state
*state
)
2549 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*)pass
;
2550 gcc_assert (!current_function_decl
);
2552 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2553 if (pass
->type
== IPA_PASS
2554 && ipa_pass
->write_optimization_summary
2555 && pass
->gate (cfun
))
2557 /* If a timevar is present, start it. */
2559 timevar_push (pass
->tv_id
);
2561 pass_init_dump_file (pass
);
2563 current_pass
= pass
;
2564 ipa_pass
->write_optimization_summary ();
2566 pass_fini_dump_file (pass
);
2568 /* If a timevar is present, start it. */
2570 timevar_pop (pass
->tv_id
);
2573 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2574 ipa_write_optimization_summaries_1 (pass
->sub
, state
);
2580 /* Write all the optimization summaries for the cgraph nodes in SET. If SET is
2581 NULL, write out all summaries of all nodes. */
2584 ipa_write_optimization_summaries (lto_symtab_encoder_t encoder
)
2586 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2587 lto_symtab_encoder_iterator lsei
;
2588 state
->symtab_node_encoder
= encoder
;
2590 lto_output_init_mode_table ();
2591 lto_push_out_decl_state (state
);
2592 for (lsei
= lsei_start_function_in_partition (encoder
);
2593 !lsei_end_p (lsei
); lsei_next_function_in_partition (&lsei
))
2595 struct cgraph_node
*node
= lsei_cgraph_node (lsei
);
2596 /* When streaming out references to statements as part of some IPA
2597 pass summary, the statements need to have uids assigned.
2599 For functions newly born at WPA stage we need to initialize
2601 if (node
->definition
2602 && gimple_has_body_p (node
->decl
))
2604 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
2605 renumber_gimple_stmt_uids ();
2610 gcc_assert (flag_wpa
);
2611 pass_manager
*passes
= g
->get_passes ();
2612 ipa_write_optimization_summaries_1 (passes
->all_regular_ipa_passes
, state
);
2616 gcc_assert (lto_get_out_decl_state () == state
);
2617 lto_pop_out_decl_state ();
2618 lto_delete_out_decl_state (state
);
2621 /* Same as execute_pass_list but assume that subpasses of IPA passes
2622 are local passes. */
2625 ipa_read_summaries_1 (opt_pass
*pass
)
2629 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
2631 gcc_assert (!current_function_decl
);
2633 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2635 if (pass
->gate (cfun
))
2637 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_summary
)
2639 /* If a timevar is present, start it. */
2641 timevar_push (pass
->tv_id
);
2643 pass_init_dump_file (pass
);
2645 current_pass
= pass
;
2646 ipa_pass
->read_summary ();
2648 pass_fini_dump_file (pass
);
2652 timevar_pop (pass
->tv_id
);
2655 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2656 ipa_read_summaries_1 (pass
->sub
);
2663 /* Read all the summaries for all_regular_ipa_passes. */
2666 ipa_read_summaries (void)
2668 pass_manager
*passes
= g
->get_passes ();
2669 ipa_read_summaries_1 (passes
->all_regular_ipa_passes
);
2672 /* Same as execute_pass_list but assume that subpasses of IPA passes
2673 are local passes. */
2676 ipa_read_optimization_summaries_1 (opt_pass
*pass
)
2680 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
2682 gcc_assert (!current_function_decl
);
2684 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2686 if (pass
->gate (cfun
))
2688 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_optimization_summary
)
2690 /* If a timevar is present, start it. */
2692 timevar_push (pass
->tv_id
);
2694 pass_init_dump_file (pass
);
2696 current_pass
= pass
;
2697 ipa_pass
->read_optimization_summary ();
2699 pass_fini_dump_file (pass
);
2703 timevar_pop (pass
->tv_id
);
2706 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2707 ipa_read_optimization_summaries_1 (pass
->sub
);
2713 /* Read all the summaries for all_regular_ipa_passes. */
2716 ipa_read_optimization_summaries (void)
2718 pass_manager
*passes
= g
->get_passes ();
2719 ipa_read_optimization_summaries_1 (passes
->all_regular_ipa_passes
);
2722 /* Same as execute_pass_list but assume that subpasses of IPA passes
2723 are local passes. */
2725 execute_ipa_pass_list (opt_pass
*pass
)
2729 gcc_assert (!current_function_decl
);
2731 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2732 if (execute_one_pass (pass
) && pass
->sub
)
2734 if (pass
->sub
->type
== GIMPLE_PASS
)
2736 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_START
, NULL
);
2737 do_per_function_toporder ((void (*)(function
*, void *))
2740 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_END
, NULL
);
2742 else if (pass
->sub
->type
== SIMPLE_IPA_PASS
2743 || pass
->sub
->type
== IPA_PASS
)
2744 execute_ipa_pass_list (pass
->sub
);
2748 gcc_assert (!current_function_decl
);
2749 symtab
->process_new_functions ();
2755 /* Execute stmt fixup hooks of all passes in PASS for NODE and STMTS. */
2758 execute_ipa_stmt_fixups (opt_pass
*pass
,
2759 struct cgraph_node
*node
, gimple
*stmts
)
2763 /* Execute all of the IPA_PASSes in the list. */
2764 if (pass
->type
== IPA_PASS
2765 && pass
->gate (cfun
))
2767 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
2769 if (ipa_pass
->stmt_fixup
)
2771 pass_init_dump_file (pass
);
2772 /* If a timevar is present, start it. */
2774 timevar_push (pass
->tv_id
);
2776 current_pass
= pass
;
2777 ipa_pass
->stmt_fixup (node
, stmts
);
2781 timevar_pop (pass
->tv_id
);
2782 pass_fini_dump_file (pass
);
2785 execute_ipa_stmt_fixups (pass
->sub
, node
, stmts
);
2791 /* Execute stmt fixup hooks of all IPA passes for NODE and STMTS. */
2794 execute_all_ipa_stmt_fixups (struct cgraph_node
*node
, gimple
*stmts
)
2796 pass_manager
*passes
= g
->get_passes ();
2797 execute_ipa_stmt_fixups (passes
->all_regular_ipa_passes
, node
, stmts
);
2801 extern void debug_properties (unsigned int);
2802 extern void dump_properties (FILE *, unsigned int);
2805 dump_properties (FILE *dump
, unsigned int props
)
2807 fprintf (dump
, "Properties:\n");
2808 if (props
& PROP_gimple_any
)
2809 fprintf (dump
, "PROP_gimple_any\n");
2810 if (props
& PROP_gimple_lcf
)
2811 fprintf (dump
, "PROP_gimple_lcf\n");
2812 if (props
& PROP_gimple_leh
)
2813 fprintf (dump
, "PROP_gimple_leh\n");
2814 if (props
& PROP_cfg
)
2815 fprintf (dump
, "PROP_cfg\n");
2816 if (props
& PROP_ssa
)
2817 fprintf (dump
, "PROP_ssa\n");
2818 if (props
& PROP_no_crit_edges
)
2819 fprintf (dump
, "PROP_no_crit_edges\n");
2820 if (props
& PROP_rtl
)
2821 fprintf (dump
, "PROP_rtl\n");
2822 if (props
& PROP_gimple_lomp
)
2823 fprintf (dump
, "PROP_gimple_lomp\n");
2824 if (props
& PROP_gimple_lcx
)
2825 fprintf (dump
, "PROP_gimple_lcx\n");
2826 if (props
& PROP_gimple_lvec
)
2827 fprintf (dump
, "PROP_gimple_lvec\n");
2828 if (props
& PROP_cfglayout
)
2829 fprintf (dump
, "PROP_cfglayout\n");
2833 debug_properties (unsigned int props
)
2835 dump_properties (stderr
, props
);
2838 /* Called by local passes to see if function is called by already processed nodes.
2839 Because we process nodes in topological order, this means that function is
2840 in recursive cycle or we introduced new direct calls. */
2842 function_called_by_processed_nodes_p (void)
2844 struct cgraph_edge
*e
;
2845 for (e
= cgraph_node::get (current_function_decl
)->callers
;
2849 if (e
->caller
->decl
== current_function_decl
)
2851 if (!e
->caller
->has_gimple_body_p ())
2853 if (TREE_ASM_WRITTEN (e
->caller
->decl
))
2855 if (!e
->caller
->process
&& !e
->caller
->global
.inlined_to
)
2860 fprintf (dump_file
, "Already processed call to:\n");
2861 e
->caller
->dump (dump_file
);
2866 #include "gt-passes.h"