1 /* Top level of GCC compilers (cc1, cc1plus, etc.)
2 Copyright (C) 1987-2016 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"
39 #include "lto-streamer.h"
40 #include "fold-const.h"
46 #include "value-prof.h"
48 #include "tree-ssa-loop-manip.h"
49 #include "tree-into-ssa.h"
52 #include "tree-pass.h"
54 #include "ipa-utils.h"
55 #include "tree-pretty-print.h" /* for dump_function_header */
57 #include "pass_manager.h"
59 #include "tree-ssa-live.h" /* For remove_unused_locals. */
60 #include "tree-cfgcleanup.h"
64 /* This is used for debugging. It allows the current pass to printed
65 from anywhere in compilation.
66 The variable current_pass is also used for statistics and plugins. */
67 opt_pass
*current_pass
;
69 /* Most passes are single-instance (within their context) and thus don't
70 need to implement cloning, but passes that support multiple instances
71 *must* provide their own implementation of the clone method.
73 Handle this by providing a default implemenation, but make it a fatal
79 internal_error ("pass %s does not support cloning", name
);
83 opt_pass::set_pass_param (unsigned int, bool)
85 internal_error ("pass %s needs a set_pass_param implementation to handle the"
86 " extra argument in NEXT_PASS", name
);
90 opt_pass::gate (function
*)
96 opt_pass::execute (function
*)
101 opt_pass::opt_pass (const pass_data
&data
, context
*ctxt
)
105 static_pass_number (0),
112 pass_manager::execute_early_local_passes ()
114 execute_pass_list (cfun
, pass_build_ssa_passes_1
->sub
);
115 if (flag_check_pointer_bounds
)
116 execute_pass_list (cfun
, pass_chkp_instrumentation_passes_1
->sub
);
117 execute_pass_list (cfun
, pass_local_optimization_passes_1
->sub
);
121 pass_manager::execute_pass_mode_switching ()
123 return pass_mode_switching_1
->execute (cfun
);
127 /* Call from anywhere to find out what pass this is. Useful for
128 printing out debugging information deep inside an service
131 print_current_pass (FILE *file
)
134 fprintf (file
, "current pass = %s (%d)\n",
135 current_pass
->name
, current_pass
->static_pass_number
);
137 fprintf (file
, "no current pass.\n");
141 /* Call from the debugger to get the current pass name. */
145 print_current_pass (stderr
);
150 /* Global variables used to communicate with passes. */
154 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
157 This does nothing for local (non-static) variables, unless the
158 variable is a register variable with DECL_ASSEMBLER_NAME set. In
159 that case, or if the variable is not an automatic, it sets up the
160 RTL and outputs any assembler code (label definition, storage
161 allocation and initialization).
163 DECL is the declaration. TOP_LEVEL is nonzero
164 if this declaration is not within a function. */
167 rest_of_decl_compilation (tree decl
,
171 bool finalize
= true;
173 /* We deferred calling assemble_alias so that we could collect
174 other attributes such as visibility. Emit the alias now. */
178 alias
= lookup_attribute ("alias", DECL_ATTRIBUTES (decl
));
181 alias
= TREE_VALUE (TREE_VALUE (alias
));
182 alias
= get_identifier (TREE_STRING_POINTER (alias
));
183 /* A quirk of the initial implementation of aliases required that the
184 user add "extern" to all of them. Which is silly, but now
185 historical. Do note that the symbol is in fact locally defined. */
186 DECL_EXTERNAL (decl
) = 0;
187 TREE_STATIC (decl
) = 1;
188 assemble_alias (decl
, alias
);
193 /* Can't defer this, because it needs to happen before any
194 later function definitions are processed. */
195 if (DECL_ASSEMBLER_NAME_SET_P (decl
) && DECL_REGISTER (decl
))
196 make_decl_rtl (decl
);
198 /* Forward declarations for nested functions are not "external",
199 but we need to treat them as if they were. */
200 if (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)
201 || TREE_CODE (decl
) == FUNCTION_DECL
)
203 timevar_push (TV_VARCONST
);
205 /* Don't output anything when a tentative file-scope definition
206 is seen. But at end of compilation, do output code for them.
208 We do output all variables and rely on
209 callgraph code to defer them except for forward declarations
210 (see gcc.c-torture/compile/920624-1.c) */
212 || !DECL_DEFER_OUTPUT (decl
)
213 || DECL_INITIAL (decl
))
214 && (TREE_CODE (decl
) != VAR_DECL
|| !DECL_HAS_VALUE_EXPR_P (decl
))
215 && !DECL_EXTERNAL (decl
))
217 /* When reading LTO unit, we also read varpool, so do not
219 if (in_lto_p
&& !at_end
)
221 else if (finalize
&& TREE_CODE (decl
) != FUNCTION_DECL
)
222 varpool_node::finalize_decl (decl
);
225 #ifdef ASM_FINISH_DECLARE_OBJECT
226 if (decl
== last_assemble_variable_decl
)
228 ASM_FINISH_DECLARE_OBJECT (asm_out_file
, decl
,
233 /* Now that we have activated any function-specific attributes
234 that might affect function decl, particularly align, relayout it. */
235 if (TREE_CODE (decl
) == FUNCTION_DECL
)
236 targetm
.target_option
.relayout_function (decl
);
238 timevar_pop (TV_VARCONST
);
240 else if (TREE_CODE (decl
) == TYPE_DECL
241 /* Like in rest_of_type_compilation, avoid confusing the debug
242 information machinery when there are errors. */
245 timevar_push (TV_SYMOUT
);
246 debug_hooks
->type_decl (decl
, !top_level
);
247 timevar_pop (TV_SYMOUT
);
250 /* Let cgraph know about the existence of variables. */
251 if (in_lto_p
&& !at_end
)
253 else if (TREE_CODE (decl
) == VAR_DECL
&& !DECL_EXTERNAL (decl
)
254 && TREE_STATIC (decl
))
255 varpool_node::get_create (decl
);
257 /* Generate early debug for global variables. Any local variables will
258 be handled by either handling reachable functions from
259 finalize_compilation_unit (and by consequence, locally scoped
260 symbols), or by rest_of_type_compilation below.
262 Also, pick up function prototypes, which will be mostly ignored
263 by the different early_global_decl() hooks, but will at least be
264 used by Go's hijack of the debug_hooks to implement
267 && (TREE_CODE (decl
) != FUNCTION_DECL
268 /* This will pick up function prototypes with no bodies,
269 which are not visible in finalize_compilation_unit()
270 while iterating with FOR_EACH_*_FUNCTION through the
272 || !DECL_SAVED_TREE (decl
))
274 /* We need to check both decl_function_context and
275 current_function_decl here to make sure local extern
276 declarations end up with the correct context.
278 For local extern declarations, decl_function_context is
279 empty, but current_function_decl is set to the function where
280 the extern was declared . Without the check for
281 !current_function_decl below, the local extern ends up
282 incorrectly with a top-level context.
294 extern int i; // Local extern declaration.
301 && !decl_function_context (decl
)
302 && !current_function_decl
303 && DECL_SOURCE_LOCATION (decl
) != BUILTINS_LOCATION
304 && (!decl_type_context (decl
)
305 /* If we created a varpool node for the decl make sure to
306 call early_global_decl. Otherwise we miss changes
307 introduced by member definitions like
308 struct A { static int staticdatamember; };
309 int A::staticdatamember;
310 and thus have incomplete early debug and late debug
311 called from varpool node removal fails to handle it
314 && TREE_CODE (decl
) == VAR_DECL
315 && TREE_STATIC (decl
) && !DECL_EXTERNAL (decl
)))
316 /* Avoid confusing the debug information machinery when there are
319 (*debug_hooks
->early_global_decl
) (decl
);
322 /* Called after finishing a record, union or enumeral type. */
325 rest_of_type_compilation (tree type
, int toplev
)
327 /* Avoid confusing the debug information machinery when there are
332 timevar_push (TV_SYMOUT
);
333 debug_hooks
->type_decl (TYPE_STUB_DECL (type
), !toplev
);
334 timevar_pop (TV_SYMOUT
);
341 finish_optimization_passes (void)
344 struct dump_file_info
*dfi
;
346 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
348 timevar_push (TV_DUMP
);
349 if (profile_arc_flag
|| flag_test_coverage
|| flag_branch_probabilities
)
351 dumps
->dump_start (pass_profile_1
->static_pass_number
, NULL
);
353 dumps
->dump_finish (pass_profile_1
->static_pass_number
);
358 dumps
->dump_start (pass_profile_1
->static_pass_number
, NULL
);
359 print_combine_total_stats ();
360 dumps
->dump_finish (pass_profile_1
->static_pass_number
);
363 /* Do whatever is necessary to finish printing the graphs. */
364 for (i
= TDI_end
; (dfi
= dumps
->get_dump_file_info (i
)) != NULL
; ++i
)
365 if (dfi
->graph_dump_initialized
)
367 name
= dumps
->get_dump_file_name (dfi
);
368 finish_graph_dump_file (name
);
372 timevar_pop (TV_DUMP
);
376 execute_build_ssa_passes (void)
378 /* Once this pass (and its sub-passes) are complete, all functions
379 will be in SSA form. Technically this state change is happening
380 a tad early, since the sub-passes have not yet run, but since
381 none of the sub-passes are IPA passes and do not create new
382 functions, this is ok. We're setting this value for the benefit
383 of IPA passes that follow. */
384 if (symtab
->state
< IPA_SSA
)
385 symtab
->state
= IPA_SSA
;
391 const pass_data pass_data_build_ssa_passes
=
393 SIMPLE_IPA_PASS
, /* type */
394 "build_ssa_passes", /* name */
395 OPTGROUP_NONE
, /* optinfo_flags */
396 TV_EARLY_LOCAL
, /* tv_id */
397 0, /* properties_required */
398 0, /* properties_provided */
399 0, /* properties_destroyed */
400 0, /* todo_flags_start */
401 /* todo_flags_finish is executed before subpases. For this reason
402 it makes no sense to remove unreachable functions here. */
403 0, /* todo_flags_finish */
406 class pass_build_ssa_passes
: public simple_ipa_opt_pass
409 pass_build_ssa_passes (gcc::context
*ctxt
)
410 : simple_ipa_opt_pass (pass_data_build_ssa_passes
, ctxt
)
413 /* opt_pass methods: */
414 virtual bool gate (function
*)
416 /* Don't bother doing anything if the program has errors. */
417 return (!seen_error () && !in_lto_p
);
420 virtual unsigned int execute (function
*)
422 return execute_build_ssa_passes ();
425 }; // class pass_build_ssa_passes
427 const pass_data pass_data_chkp_instrumentation_passes
=
429 SIMPLE_IPA_PASS
, /* type */
430 "chkp_passes", /* name */
431 OPTGROUP_NONE
, /* optinfo_flags */
433 0, /* properties_required */
434 0, /* properties_provided */
435 0, /* properties_destroyed */
436 0, /* todo_flags_start */
437 0, /* todo_flags_finish */
440 class pass_chkp_instrumentation_passes
: public simple_ipa_opt_pass
443 pass_chkp_instrumentation_passes (gcc::context
*ctxt
)
444 : simple_ipa_opt_pass (pass_data_chkp_instrumentation_passes
, ctxt
)
447 /* opt_pass methods: */
448 virtual bool gate (function
*)
450 /* Don't bother doing anything if the program has errors. */
451 return (flag_check_pointer_bounds
452 && !seen_error () && !in_lto_p
);
455 }; // class pass_chkp_instrumentation_passes
457 const pass_data pass_data_local_optimization_passes
=
459 SIMPLE_IPA_PASS
, /* type */
460 "opt_local_passes", /* name */
461 OPTGROUP_NONE
, /* optinfo_flags */
463 0, /* properties_required */
464 0, /* properties_provided */
465 0, /* properties_destroyed */
466 0, /* todo_flags_start */
467 0, /* todo_flags_finish */
470 class pass_local_optimization_passes
: public simple_ipa_opt_pass
473 pass_local_optimization_passes (gcc::context
*ctxt
)
474 : simple_ipa_opt_pass (pass_data_local_optimization_passes
, ctxt
)
477 /* opt_pass methods: */
478 virtual bool gate (function
*)
480 /* Don't bother doing anything if the program has errors. */
481 return (!seen_error () && !in_lto_p
);
484 }; // class pass_local_optimization_passes
488 simple_ipa_opt_pass
*
489 make_pass_build_ssa_passes (gcc::context
*ctxt
)
491 return new pass_build_ssa_passes (ctxt
);
494 simple_ipa_opt_pass
*
495 make_pass_chkp_instrumentation_passes (gcc::context
*ctxt
)
497 return new pass_chkp_instrumentation_passes (ctxt
);
500 simple_ipa_opt_pass
*
501 make_pass_local_optimization_passes (gcc::context
*ctxt
)
503 return new pass_local_optimization_passes (ctxt
);
508 const pass_data pass_data_all_early_optimizations
=
510 GIMPLE_PASS
, /* type */
511 "early_optimizations", /* name */
512 OPTGROUP_NONE
, /* optinfo_flags */
514 0, /* properties_required */
515 0, /* properties_provided */
516 0, /* properties_destroyed */
517 0, /* todo_flags_start */
518 0, /* todo_flags_finish */
521 class pass_all_early_optimizations
: public gimple_opt_pass
524 pass_all_early_optimizations (gcc::context
*ctxt
)
525 : gimple_opt_pass (pass_data_all_early_optimizations
, ctxt
)
528 /* opt_pass methods: */
529 virtual bool gate (function
*)
531 return (optimize
>= 1
532 /* Don't bother doing anything if the program has errors. */
536 }; // class pass_all_early_optimizations
540 static gimple_opt_pass
*
541 make_pass_all_early_optimizations (gcc::context
*ctxt
)
543 return new pass_all_early_optimizations (ctxt
);
548 const pass_data pass_data_all_optimizations
=
550 GIMPLE_PASS
, /* type */
551 "*all_optimizations", /* name */
552 OPTGROUP_NONE
, /* optinfo_flags */
553 TV_OPTIMIZE
, /* tv_id */
554 0, /* properties_required */
555 0, /* properties_provided */
556 0, /* properties_destroyed */
557 0, /* todo_flags_start */
558 0, /* todo_flags_finish */
561 class pass_all_optimizations
: public gimple_opt_pass
564 pass_all_optimizations (gcc::context
*ctxt
)
565 : gimple_opt_pass (pass_data_all_optimizations
, ctxt
)
568 /* opt_pass methods: */
569 virtual bool gate (function
*) { return optimize
>= 1 && !optimize_debug
; }
571 }; // class pass_all_optimizations
575 static gimple_opt_pass
*
576 make_pass_all_optimizations (gcc::context
*ctxt
)
578 return new pass_all_optimizations (ctxt
);
583 const pass_data pass_data_all_optimizations_g
=
585 GIMPLE_PASS
, /* type */
586 "*all_optimizations_g", /* name */
587 OPTGROUP_NONE
, /* optinfo_flags */
588 TV_OPTIMIZE
, /* tv_id */
589 0, /* properties_required */
590 0, /* properties_provided */
591 0, /* properties_destroyed */
592 0, /* todo_flags_start */
593 0, /* todo_flags_finish */
596 class pass_all_optimizations_g
: public gimple_opt_pass
599 pass_all_optimizations_g (gcc::context
*ctxt
)
600 : gimple_opt_pass (pass_data_all_optimizations_g
, ctxt
)
603 /* opt_pass methods: */
604 virtual bool gate (function
*) { return optimize
>= 1 && optimize_debug
; }
606 }; // class pass_all_optimizations_g
610 static gimple_opt_pass
*
611 make_pass_all_optimizations_g (gcc::context
*ctxt
)
613 return new pass_all_optimizations_g (ctxt
);
618 const pass_data pass_data_rest_of_compilation
=
621 "*rest_of_compilation", /* name */
622 OPTGROUP_NONE
, /* optinfo_flags */
623 TV_REST_OF_COMPILATION
, /* tv_id */
624 PROP_rtl
, /* properties_required */
625 0, /* properties_provided */
626 0, /* properties_destroyed */
627 0, /* todo_flags_start */
628 0, /* todo_flags_finish */
631 class pass_rest_of_compilation
: public rtl_opt_pass
634 pass_rest_of_compilation (gcc::context
*ctxt
)
635 : rtl_opt_pass (pass_data_rest_of_compilation
, ctxt
)
638 /* opt_pass methods: */
639 virtual bool gate (function
*)
641 /* Early return if there were errors. We can run afoul of our
642 consistency checks, and there's not really much point in fixing them. */
643 return !(rtl_dump_and_exit
|| flag_syntax_only
|| seen_error ());
646 }; // class pass_rest_of_compilation
650 static rtl_opt_pass
*
651 make_pass_rest_of_compilation (gcc::context
*ctxt
)
653 return new pass_rest_of_compilation (ctxt
);
658 const pass_data pass_data_postreload
=
661 "*all-postreload", /* name */
662 OPTGROUP_NONE
, /* optinfo_flags */
663 TV_POSTRELOAD
, /* tv_id */
664 PROP_rtl
, /* properties_required */
665 0, /* properties_provided */
666 0, /* properties_destroyed */
667 0, /* todo_flags_start */
668 0, /* todo_flags_finish */
671 class pass_postreload
: public rtl_opt_pass
674 pass_postreload (gcc::context
*ctxt
)
675 : rtl_opt_pass (pass_data_postreload
, ctxt
)
678 /* opt_pass methods: */
679 virtual bool gate (function
*) { return reload_completed
; }
681 }; // class pass_postreload
685 static rtl_opt_pass
*
686 make_pass_postreload (gcc::context
*ctxt
)
688 return new pass_postreload (ctxt
);
693 const pass_data pass_data_late_compilation
=
696 "*all-late_compilation", /* name */
697 OPTGROUP_NONE
, /* optinfo_flags */
698 TV_LATE_COMPILATION
, /* tv_id */
699 PROP_rtl
, /* properties_required */
700 0, /* properties_provided */
701 0, /* properties_destroyed */
702 0, /* todo_flags_start */
703 0, /* todo_flags_finish */
706 class pass_late_compilation
: public rtl_opt_pass
709 pass_late_compilation (gcc::context
*ctxt
)
710 : rtl_opt_pass (pass_data_late_compilation
, ctxt
)
713 /* opt_pass methods: */
714 virtual bool gate (function
*)
716 return reload_completed
|| targetm
.no_register_allocation
;
719 }; // class pass_late_compilation
723 static rtl_opt_pass
*
724 make_pass_late_compilation (gcc::context
*ctxt
)
726 return new pass_late_compilation (ctxt
);
731 /* Set the static pass number of pass PASS to ID and record that
732 in the mapping from static pass number to pass. */
736 set_pass_for_id (int id
, opt_pass
*pass
)
738 pass
->static_pass_number
= id
;
739 if (passes_by_id_size
<= id
)
741 passes_by_id
= XRESIZEVEC (opt_pass
*, passes_by_id
, id
+ 1);
742 memset (passes_by_id
+ passes_by_id_size
, 0,
743 (id
+ 1 - passes_by_id_size
) * sizeof (void *));
744 passes_by_id_size
= id
+ 1;
746 passes_by_id
[id
] = pass
;
749 /* Return the pass with the static pass number ID. */
752 pass_manager::get_pass_for_id (int id
) const
754 if (id
>= passes_by_id_size
)
756 return passes_by_id
[id
];
759 /* Iterate over the pass tree allocating dump file numbers. We want
760 to do this depth first, and independent of whether the pass is
764 register_one_dump_file (opt_pass
*pass
)
766 g
->get_passes ()->register_one_dump_file (pass
);
770 pass_manager::register_one_dump_file (opt_pass
*pass
)
772 char *dot_name
, *flag_name
, *glob_name
;
773 const char *name
, *full_name
, *prefix
;
775 /* Buffer big enough to format a 32-bit UINT_MAX into. */
778 int optgroup_flags
= OPTGROUP_NONE
;
779 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
781 /* See below in next_pass_1. */
783 if (pass
->static_pass_number
!= -1)
784 sprintf (num
, "%u", ((int) pass
->static_pass_number
< 0
785 ? 1 : pass
->static_pass_number
));
787 /* The name is both used to identify the pass for the purposes of plugins,
788 and to specify dump file name and option.
789 The latter two might want something short which is not quite unique; for
790 that reason, we may have a disambiguating prefix, followed by a space
791 to mark the start of the following dump file name / option string. */
792 name
= strchr (pass
->name
, ' ');
793 name
= name
? name
+ 1 : pass
->name
;
794 dot_name
= concat (".", name
, num
, NULL
);
795 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
799 optgroup_flags
|= OPTGROUP_IPA
;
801 else if (pass
->type
== GIMPLE_PASS
)
812 flag_name
= concat (prefix
, name
, num
, NULL
);
813 glob_name
= concat (prefix
, name
, NULL
);
814 optgroup_flags
|= pass
->optinfo_flags
;
815 /* For any passes that do not have an optgroup set, and which are not
816 IPA passes setup above, set the optgroup to OPTGROUP_OTHER so that
817 any dump messages are emitted properly under -fopt-info(-optall). */
818 if (optgroup_flags
== OPTGROUP_NONE
)
819 optgroup_flags
= OPTGROUP_OTHER
;
820 id
= dumps
->dump_register (dot_name
, flag_name
, glob_name
, flags
,
823 set_pass_for_id (id
, pass
);
824 full_name
= concat (prefix
, pass
->name
, num
, NULL
);
825 register_pass_name (pass
, full_name
);
826 free (CONST_CAST (char *, full_name
));
829 /* Register the dump files for the pass_manager starting at PASS. */
832 pass_manager::register_dump_files (opt_pass
*pass
)
836 if (pass
->name
&& pass
->name
[0] != '*')
837 register_one_dump_file (pass
);
840 register_dump_files (pass
->sub
);
847 /* Register PASS with NAME. */
850 pass_manager::register_pass_name (opt_pass
*pass
, const char *name
)
852 if (!m_name_to_pass_map
)
853 m_name_to_pass_map
= new hash_map
<nofree_string_hash
, opt_pass
*> (256);
855 if (m_name_to_pass_map
->get (name
))
856 return; /* Ignore plugin passes. */
858 const char *unique_name
= xstrdup (name
);
859 m_name_to_pass_map
->put (unique_name
, pass
);
862 /* Map from pass id to canonicalized pass name. */
864 typedef const char *char_ptr
;
865 static vec
<char_ptr
> pass_tab
= vNULL
;
867 /* Callback function for traversing NAME_TO_PASS_MAP. */
870 passes_pass_traverse (const char *const &name
, opt_pass
*const &pass
, void *)
872 gcc_assert (pass
->static_pass_number
> 0);
873 gcc_assert (pass_tab
.exists ());
875 pass_tab
[pass
->static_pass_number
] = name
;
880 /* The function traverses NAME_TO_PASS_MAP and creates a pass info
881 table for dumping purpose. */
884 pass_manager::create_pass_tab (void) const
886 if (!flag_dump_passes
)
889 pass_tab
.safe_grow_cleared (passes_by_id_size
+ 1);
890 m_name_to_pass_map
->traverse
<void *, passes_pass_traverse
> (NULL
);
893 static bool override_gate_status (opt_pass
*, tree
, bool);
895 /* Dump the instantiated name for PASS. IS_ON indicates if PASS
896 is turned on or not. */
899 dump_one_pass (opt_pass
*pass
, int pass_indent
)
901 int indent
= 3 * pass_indent
;
903 bool is_on
, is_really_on
;
905 is_on
= pass
->gate (cfun
);
906 is_really_on
= override_gate_status (pass
, current_function_decl
, is_on
);
908 if (pass
->static_pass_number
<= 0)
911 pn
= pass_tab
[pass
->static_pass_number
];
913 fprintf (stderr
, "%*s%-40s%*s:%s%s\n", indent
, " ", pn
,
914 (15 - indent
< 0 ? 0 : 15 - indent
), " ",
915 is_on
? " ON" : " OFF",
916 ((!is_on
) == (!is_really_on
) ? ""
917 : (is_really_on
? " (FORCED_ON)" : " (FORCED_OFF)")));
920 /* Dump pass list PASS with indentation INDENT. */
923 dump_pass_list (opt_pass
*pass
, int indent
)
927 dump_one_pass (pass
, indent
);
929 dump_pass_list (pass
->sub
, indent
+ 1);
935 /* Dump all optimization passes. */
940 g
->get_passes ()->dump_passes ();
944 pass_manager::dump_passes () const
946 push_dummy_function (true);
950 dump_pass_list (all_lowering_passes
, 1);
951 dump_pass_list (all_small_ipa_passes
, 1);
952 dump_pass_list (all_regular_ipa_passes
, 1);
953 dump_pass_list (all_late_ipa_passes
, 1);
954 dump_pass_list (all_passes
, 1);
956 pop_dummy_function ();
959 /* Returns the pass with NAME. */
962 pass_manager::get_pass_by_name (const char *name
)
964 opt_pass
**p
= m_name_to_pass_map
->get (name
);
972 /* Range [start, last]. */
978 const char *assem_name
;
979 struct uid_range
*next
;
982 typedef struct uid_range
*uid_range_p
;
985 static vec
<uid_range_p
>
986 enabled_pass_uid_range_tab
= vNULL
;
987 static vec
<uid_range_p
>
988 disabled_pass_uid_range_tab
= vNULL
;
991 /* Parse option string for -fdisable- and -fenable-
992 The syntax of the options:
995 -fdisable-<pass_name>
997 -fenable-<pass_name>=s1:e1,s2:e2,...
998 -fdisable-<pass_name>=s1:e1,s2:e2,...
1002 enable_disable_pass (const char *arg
, bool is_enable
)
1005 char *range_str
, *phase_name
;
1006 char *argstr
= xstrdup (arg
);
1007 vec
<uid_range_p
> *tab
= 0;
1009 range_str
= strchr (argstr
,'=');
1016 phase_name
= argstr
;
1020 error ("unrecognized option -fenable");
1022 error ("unrecognized option -fdisable");
1026 pass
= g
->get_passes ()->get_pass_by_name (phase_name
);
1027 if (!pass
|| pass
->static_pass_number
== -1)
1030 error ("unknown pass %s specified in -fenable", phase_name
);
1032 error ("unknown pass %s specified in -fdisable", phase_name
);
1038 tab
= &enabled_pass_uid_range_tab
;
1040 tab
= &disabled_pass_uid_range_tab
;
1042 if ((unsigned) pass
->static_pass_number
>= tab
->length ())
1043 tab
->safe_grow_cleared (pass
->static_pass_number
+ 1);
1048 uid_range_p new_range
= XCNEW (struct uid_range
);
1050 new_range
->start
= 0;
1051 new_range
->last
= (unsigned)-1;
1053 slot
= (*tab
)[pass
->static_pass_number
];
1054 new_range
->next
= slot
;
1055 (*tab
)[pass
->static_pass_number
] = new_range
;
1057 inform (UNKNOWN_LOCATION
, "enable pass %s for functions in the range "
1058 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
1060 inform (UNKNOWN_LOCATION
, "disable pass %s for functions in the range "
1061 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
1065 char *next_range
= NULL
;
1066 char *one_range
= range_str
;
1067 char *end_val
= NULL
;
1072 uid_range_p new_range
;
1073 char *invalid
= NULL
;
1075 char *func_name
= NULL
;
1077 next_range
= strchr (one_range
, ',');
1084 end_val
= strchr (one_range
, ':');
1090 start
= strtol (one_range
, &invalid
, 10);
1091 if (*invalid
|| start
< 0)
1093 if (end_val
|| (one_range
[0] >= '0'
1094 && one_range
[0] <= '9'))
1096 error ("Invalid range %s in option %s",
1098 is_enable
? "-fenable" : "-fdisable");
1102 func_name
= one_range
;
1106 new_range
= XCNEW (struct uid_range
);
1109 new_range
->start
= (unsigned) start
;
1110 new_range
->last
= (unsigned) start
;
1114 new_range
->start
= (unsigned) -1;
1115 new_range
->last
= (unsigned) -1;
1116 new_range
->assem_name
= xstrdup (func_name
);
1121 long last
= strtol (end_val
, &invalid
, 10);
1122 if (*invalid
|| last
< start
)
1124 error ("Invalid range %s in option %s",
1126 is_enable
? "-fenable" : "-fdisable");
1130 new_range
= XCNEW (struct uid_range
);
1131 new_range
->start
= (unsigned) start
;
1132 new_range
->last
= (unsigned) last
;
1135 slot
= (*tab
)[pass
->static_pass_number
];
1136 new_range
->next
= slot
;
1137 (*tab
)[pass
->static_pass_number
] = new_range
;
1140 if (new_range
->assem_name
)
1141 inform (UNKNOWN_LOCATION
,
1142 "enable pass %s for function %s",
1143 phase_name
, new_range
->assem_name
);
1145 inform (UNKNOWN_LOCATION
,
1146 "enable pass %s for functions in the range of [%u, %u]",
1147 phase_name
, new_range
->start
, new_range
->last
);
1151 if (new_range
->assem_name
)
1152 inform (UNKNOWN_LOCATION
,
1153 "disable pass %s for function %s",
1154 phase_name
, new_range
->assem_name
);
1156 inform (UNKNOWN_LOCATION
,
1157 "disable pass %s for functions in the range of [%u, %u]",
1158 phase_name
, new_range
->start
, new_range
->last
);
1161 one_range
= next_range
;
1162 } while (next_range
);
1168 /* Enable pass specified by ARG. */
1171 enable_pass (const char *arg
)
1173 enable_disable_pass (arg
, true);
1176 /* Disable pass specified by ARG. */
1179 disable_pass (const char *arg
)
1181 enable_disable_pass (arg
, false);
1184 /* Returns true if PASS is explicitly enabled/disabled for FUNC. */
1187 is_pass_explicitly_enabled_or_disabled (opt_pass
*pass
,
1189 vec
<uid_range_p
> tab
)
1191 uid_range_p slot
, range
;
1193 const char *aname
= NULL
;
1196 || (unsigned) pass
->static_pass_number
>= tab
.length ()
1197 || pass
->static_pass_number
== -1)
1200 slot
= tab
[pass
->static_pass_number
];
1204 cgraph_uid
= func
? cgraph_node::get (func
)->uid
: 0;
1205 if (func
&& DECL_ASSEMBLER_NAME_SET_P (func
))
1206 aname
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func
));
1211 if ((unsigned) cgraph_uid
>= range
->start
1212 && (unsigned) cgraph_uid
<= range
->last
)
1214 if (range
->assem_name
&& aname
1215 && !strcmp (range
->assem_name
, aname
))
1217 range
= range
->next
;
1224 /* Update static_pass_number for passes (and the flag
1225 TODO_mark_first_instance).
1227 Passes are constructed with static_pass_number preinitialized to 0
1229 This field is used in two different ways: initially as instance numbers
1230 of their kind, and then as ids within the entire pass manager.
1232 Within pass_manager::pass_manager:
1234 * In add_pass_instance(), as called by next_pass_1 in
1235 NEXT_PASS in init_optimization_passes
1237 * When the initial instance of a pass within a pass manager is seen,
1238 it is flagged, and its static_pass_number is set to -1
1240 * On subsequent times that it is seen, the static pass number
1241 is decremented each time, so that if there are e.g. 4 dups,
1242 they have static_pass_number -4, 2, 3, 4 respectively (note
1243 how the initial one is negative and gives the count); these
1244 can be thought of as instance numbers of the specific pass
1246 * Within the register_dump_files () traversal, set_pass_for_id()
1247 is called on each pass, using these instance numbers to create
1248 dumpfile switches, and then overwriting them with a pass id,
1249 which are global to the whole pass manager (based on
1250 (TDI_end + current value of extra_dump_files_in_use) ) */
1253 add_pass_instance (opt_pass
*new_pass
, bool track_duplicates
,
1254 opt_pass
*initial_pass
)
1256 /* Are we dealing with the first pass of its kind, or a clone? */
1257 if (new_pass
!= initial_pass
)
1259 /* We're dealing with a clone. */
1260 new_pass
->todo_flags_start
&= ~TODO_mark_first_instance
;
1262 /* Indicate to register_dump_files that this pass has duplicates,
1263 and so it should rename the dump file. The first instance will
1264 be -1, and be number of duplicates = -static_pass_number - 1.
1265 Subsequent instances will be > 0 and just the duplicate number. */
1266 if ((new_pass
->name
&& new_pass
->name
[0] != '*') || track_duplicates
)
1268 initial_pass
->static_pass_number
-= 1;
1269 new_pass
->static_pass_number
= -initial_pass
->static_pass_number
;
1274 /* We're dealing with the first pass of its kind. */
1275 new_pass
->todo_flags_start
|= TODO_mark_first_instance
;
1276 new_pass
->static_pass_number
= -1;
1278 invoke_plugin_callbacks (PLUGIN_NEW_PASS
, new_pass
);
1282 /* Add a pass to the pass list. Duplicate the pass if it's already
1286 next_pass_1 (opt_pass
**list
, opt_pass
*pass
, opt_pass
*initial_pass
)
1288 /* Every pass should have a name so that plugins can refer to them. */
1289 gcc_assert (pass
->name
!= NULL
);
1291 add_pass_instance (pass
, false, initial_pass
);
1294 return &(*list
)->next
;
1297 /* List node for an inserted pass instance. We need to keep track of all
1298 the newly-added pass instances (with 'added_pass_nodes' defined below)
1299 so that we can register their dump files after pass-positioning is finished.
1300 Registering dumping files needs to be post-processed or the
1301 static_pass_number of the opt_pass object would be modified and mess up
1302 the dump file names of future pass instances to be added. */
1304 struct pass_list_node
1307 struct pass_list_node
*next
;
1310 static struct pass_list_node
*added_pass_nodes
= NULL
;
1311 static struct pass_list_node
*prev_added_pass_node
;
1313 /* Insert the pass at the proper position. Return true if the pass
1314 is successfully added.
1316 NEW_PASS_INFO - new pass to be inserted
1317 PASS_LIST - root of the pass list to insert the new pass to */
1320 position_pass (struct register_pass_info
*new_pass_info
, opt_pass
**pass_list
)
1322 opt_pass
*pass
= *pass_list
, *prev_pass
= NULL
;
1323 bool success
= false;
1325 for ( ; pass
; prev_pass
= pass
, pass
= pass
->next
)
1327 /* Check if the current pass is of the same type as the new pass and
1328 matches the name and the instance number of the reference pass. */
1329 if (pass
->type
== new_pass_info
->pass
->type
1331 && !strcmp (pass
->name
, new_pass_info
->reference_pass_name
)
1332 && ((new_pass_info
->ref_pass_instance_number
== 0)
1333 || (new_pass_info
->ref_pass_instance_number
==
1334 pass
->static_pass_number
)
1335 || (new_pass_info
->ref_pass_instance_number
== 1
1336 && pass
->todo_flags_start
& TODO_mark_first_instance
)))
1339 struct pass_list_node
*new_pass_node
;
1341 if (new_pass_info
->ref_pass_instance_number
== 0)
1343 new_pass
= new_pass_info
->pass
->clone ();
1344 add_pass_instance (new_pass
, true, new_pass_info
->pass
);
1348 new_pass
= new_pass_info
->pass
;
1349 add_pass_instance (new_pass
, true, new_pass
);
1352 /* Insert the new pass instance based on the positioning op. */
1353 switch (new_pass_info
->pos_op
)
1355 case PASS_POS_INSERT_AFTER
:
1356 new_pass
->next
= pass
->next
;
1357 pass
->next
= new_pass
;
1359 /* Skip newly inserted pass to avoid repeated
1360 insertions in the case where the new pass and the
1361 existing one have the same name. */
1364 case PASS_POS_INSERT_BEFORE
:
1365 new_pass
->next
= pass
;
1367 prev_pass
->next
= new_pass
;
1369 *pass_list
= new_pass
;
1371 case PASS_POS_REPLACE
:
1372 new_pass
->next
= pass
->next
;
1374 prev_pass
->next
= new_pass
;
1376 *pass_list
= new_pass
;
1377 new_pass
->sub
= pass
->sub
;
1378 new_pass
->tv_id
= pass
->tv_id
;
1382 error ("invalid pass positioning operation");
1386 /* Save the newly added pass (instance) in the added_pass_nodes
1387 list so that we can register its dump file later. Note that
1388 we cannot register the dump file now because doing so will modify
1389 the static_pass_number of the opt_pass object and therefore
1390 mess up the dump file name of future instances. */
1391 new_pass_node
= XCNEW (struct pass_list_node
);
1392 new_pass_node
->pass
= new_pass
;
1393 if (!added_pass_nodes
)
1394 added_pass_nodes
= new_pass_node
;
1396 prev_added_pass_node
->next
= new_pass_node
;
1397 prev_added_pass_node
= new_pass_node
;
1402 if (pass
->sub
&& position_pass (new_pass_info
, &pass
->sub
))
1409 /* Hooks a new pass into the pass lists.
1411 PASS_INFO - pass information that specifies the opt_pass object,
1412 reference pass, instance number, and how to position
1416 register_pass (struct register_pass_info
*pass_info
)
1418 g
->get_passes ()->register_pass (pass_info
);
1422 register_pass (opt_pass
* pass
, pass_positioning_ops pos
,
1423 const char* ref_pass_name
, int ref_pass_inst_number
)
1425 register_pass_info i
;
1427 i
.reference_pass_name
= ref_pass_name
;
1428 i
.ref_pass_instance_number
= ref_pass_inst_number
;
1431 g
->get_passes ()->register_pass (&i
);
1435 pass_manager::register_pass (struct register_pass_info
*pass_info
)
1437 bool all_instances
, success
;
1438 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
1440 /* The checks below could fail in buggy plugins. Existing GCC
1441 passes should never fail these checks, so we mention plugin in
1443 if (!pass_info
->pass
)
1444 fatal_error (input_location
, "plugin cannot register a missing pass");
1446 if (!pass_info
->pass
->name
)
1447 fatal_error (input_location
, "plugin cannot register an unnamed pass");
1449 if (!pass_info
->reference_pass_name
)
1452 "plugin cannot register pass %qs without reference pass name",
1453 pass_info
->pass
->name
);
1455 /* Try to insert the new pass to the pass lists. We need to check
1456 all five lists as the reference pass could be in one (or all) of
1458 all_instances
= pass_info
->ref_pass_instance_number
== 0;
1459 success
= position_pass (pass_info
, &all_lowering_passes
);
1460 if (!success
|| all_instances
)
1461 success
|= position_pass (pass_info
, &all_small_ipa_passes
);
1462 if (!success
|| all_instances
)
1463 success
|= position_pass (pass_info
, &all_regular_ipa_passes
);
1464 if (!success
|| all_instances
)
1465 success
|= position_pass (pass_info
, &all_late_ipa_passes
);
1466 if (!success
|| all_instances
)
1467 success
|= position_pass (pass_info
, &all_passes
);
1471 "pass %qs not found but is referenced by new pass %qs",
1472 pass_info
->reference_pass_name
, pass_info
->pass
->name
);
1474 /* OK, we have successfully inserted the new pass. We need to register
1475 the dump files for the newly added pass and its duplicates (if any).
1476 Because the registration of plugin/backend passes happens after the
1477 command-line options are parsed, the options that specify single
1478 pass dumping (e.g. -fdump-tree-PASSNAME) cannot be used for new
1479 passes. Therefore we currently can only enable dumping of
1480 new passes when the 'dump-all' flags (e.g. -fdump-tree-all)
1481 are specified. While doing so, we also delete the pass_list_node
1482 objects created during pass positioning. */
1483 while (added_pass_nodes
)
1485 struct pass_list_node
*next_node
= added_pass_nodes
->next
;
1486 enum tree_dump_index tdi
;
1487 register_one_dump_file (added_pass_nodes
->pass
);
1488 if (added_pass_nodes
->pass
->type
== SIMPLE_IPA_PASS
1489 || added_pass_nodes
->pass
->type
== IPA_PASS
)
1491 else if (added_pass_nodes
->pass
->type
== GIMPLE_PASS
)
1495 /* Check if dump-all flag is specified. */
1496 if (dumps
->get_dump_file_info (tdi
)->pstate
)
1498 dumps
->get_dump_file_info (added_pass_nodes
->pass
->static_pass_number
)
1499 ->pstate
= dumps
->get_dump_file_info (tdi
)->pstate
;
1500 dumps
->get_dump_file_info (added_pass_nodes
->pass
->static_pass_number
)
1501 ->pflags
= dumps
->get_dump_file_info (tdi
)->pflags
;
1503 XDELETE (added_pass_nodes
);
1504 added_pass_nodes
= next_node
;
1508 /* Construct the pass tree. The sequencing of passes is driven by
1509 the cgraph routines:
1511 finalize_compilation_unit ()
1512 for each node N in the cgraph
1513 cgraph_analyze_function (N)
1514 cgraph_lower_function (N) -> all_lowering_passes
1516 If we are optimizing, compile is then invoked:
1519 ipa_passes () -> all_small_ipa_passes
1520 -> Analysis of all_regular_ipa_passes
1521 * possible LTO streaming at copmilation time *
1522 -> Execution of all_regular_ipa_passes
1523 * possible LTO streaming at link time *
1524 -> all_late_ipa_passes
1525 expand_all_functions ()
1526 for each node N in the cgraph
1527 expand_function (N) -> Transformation of all_regular_ipa_passes
1532 pass_manager::operator new (size_t sz
)
1534 /* Ensure that all fields of the pass manager are zero-initialized. */
1535 return xcalloc (1, sz
);
1539 pass_manager::operator delete (void *ptr
)
1544 pass_manager::pass_manager (context
*ctxt
)
1545 : all_passes (NULL
), all_small_ipa_passes (NULL
), all_lowering_passes (NULL
),
1546 all_regular_ipa_passes (NULL
),
1547 all_late_ipa_passes (NULL
), passes_by_id (NULL
), passes_by_id_size (0),
1552 /* Initialize the pass_lists array. */
1553 #define DEF_PASS_LIST(LIST) pass_lists[PASS_LIST_NO_##LIST] = &LIST;
1555 #undef DEF_PASS_LIST
1557 /* Build the tree of passes. */
1559 #define INSERT_PASSES_AFTER(PASS) \
1561 opt_pass **p_start; \
1562 p_start = p = &(PASS);
1564 #define TERMINATE_PASS_LIST(PASS) \
1565 gcc_assert (p_start == &PASS); \
1569 #define PUSH_INSERT_PASSES_WITHIN(PASS) \
1571 opt_pass **p = &(PASS ## _1)->sub;
1573 #define POP_INSERT_PASSES() \
1576 #define NEXT_PASS(PASS, NUM) \
1578 gcc_assert (NULL == PASS ## _ ## NUM); \
1580 PASS ## _1 = make_##PASS (m_ctxt); \
1583 gcc_assert (PASS ## _1); \
1584 PASS ## _ ## NUM = PASS ## _1->clone (); \
1586 p = next_pass_1 (p, PASS ## _ ## NUM, PASS ## _1); \
1589 #define NEXT_PASS_WITH_ARG(PASS, NUM, ARG) \
1591 NEXT_PASS (PASS, NUM); \
1592 PASS ## _ ## NUM->set_pass_param (0, ARG); \
1595 #include "pass-instances.def"
1597 #undef INSERT_PASSES_AFTER
1598 #undef PUSH_INSERT_PASSES_WITHIN
1599 #undef POP_INSERT_PASSES
1601 #undef NEXT_PASS_WITH_ARG
1602 #undef TERMINATE_PASS_LIST
1604 /* Register the passes with the tree dump code. */
1605 register_dump_files (all_lowering_passes
);
1606 register_dump_files (all_small_ipa_passes
);
1607 register_dump_files (all_regular_ipa_passes
);
1608 register_dump_files (all_late_ipa_passes
);
1609 register_dump_files (all_passes
);
1613 delete_pass_tree (opt_pass
*pass
)
1617 /* Recurse into child passes. */
1618 delete_pass_tree (pass
->sub
);
1620 opt_pass
*next
= pass
->next
;
1622 /* Delete this pass. */
1625 /* Iterate onto sibling passes. */
1630 pass_manager::~pass_manager ()
1632 XDELETEVEC (passes_by_id
);
1634 /* Call delete_pass_tree on each of the pass_lists. */
1635 #define DEF_PASS_LIST(LIST) \
1636 delete_pass_tree (*pass_lists[PASS_LIST_NO_##LIST]);
1638 #undef DEF_PASS_LIST
1642 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1643 function CALLBACK for every function in the call graph. Otherwise,
1644 call CALLBACK on the current function. */
1647 do_per_function (void (*callback
) (function
*, void *data
), void *data
)
1649 if (current_function_decl
)
1650 callback (cfun
, data
);
1653 struct cgraph_node
*node
;
1654 FOR_EACH_DEFINED_FUNCTION (node
)
1655 if (node
->analyzed
&& (gimple_has_body_p (node
->decl
) && !in_lto_p
)
1656 && (!node
->clone_of
|| node
->decl
!= node
->clone_of
->decl
))
1657 callback (DECL_STRUCT_FUNCTION (node
->decl
), data
);
1661 /* Because inlining might remove no-longer reachable nodes, we need to
1662 keep the array visible to garbage collector to avoid reading collected
1665 static GTY ((length ("nnodes"))) cgraph_node
**order
;
1667 /* Hook called when NODE is removed and therefore should be
1668 excluded from order vector. DATA is an array of integers.
1669 DATA[0] holds max index it may be accessed by. For cgraph
1670 node DATA[node->uid + 1] holds index of this node in order
1673 remove_cgraph_node_from_order (cgraph_node
*node
, void *data
)
1675 int *order_idx
= (int *)data
;
1677 if (node
->uid
>= order_idx
[0])
1680 int idx
= order_idx
[node
->uid
+ 1];
1681 if (idx
>= 0 && idx
< nnodes
&& order
[idx
] == node
)
1685 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1686 function CALLBACK for every function in the call graph. Otherwise,
1687 call CALLBACK on the current function.
1688 This function is global so that plugins can use it. */
1690 do_per_function_toporder (void (*callback
) (function
*, void *data
), void *data
)
1694 if (current_function_decl
)
1695 callback (cfun
, data
);
1698 cgraph_node_hook_list
*hook
;
1700 gcc_assert (!order
);
1701 order
= ggc_vec_alloc
<cgraph_node
*> (symtab
->cgraph_count
);
1703 order_idx
= XALLOCAVEC (int, symtab
->cgraph_max_uid
+ 1);
1704 memset (order_idx
+ 1, -1, sizeof (int) * symtab
->cgraph_max_uid
);
1705 order_idx
[0] = symtab
->cgraph_max_uid
;
1707 nnodes
= ipa_reverse_postorder (order
);
1708 for (i
= nnodes
- 1; i
>= 0; i
--)
1710 order
[i
]->process
= 1;
1711 order_idx
[order
[i
]->uid
+ 1] = i
;
1713 hook
= symtab
->add_cgraph_removal_hook (remove_cgraph_node_from_order
,
1715 for (i
= nnodes
- 1; i
>= 0; i
--)
1717 /* Function could be inlined and removed as unreachable. */
1721 struct cgraph_node
*node
= order
[i
];
1723 /* Allow possibly removed nodes to be garbage collected. */
1726 if (node
->has_gimple_body_p ())
1728 struct function
*fn
= DECL_STRUCT_FUNCTION (node
->decl
);
1730 callback (fn
, data
);
1734 symtab
->remove_cgraph_removal_hook (hook
);
1741 /* Helper function to perform function body dump. */
1744 execute_function_dump (function
*fn
, void *data
)
1746 opt_pass
*pass
= (opt_pass
*)data
;
1752 if (fn
->curr_properties
& PROP_trees
)
1753 dump_function_to_file (fn
->decl
, dump_file
, dump_flags
);
1755 print_rtl_with_bb (dump_file
, get_insns (), dump_flags
);
1757 /* Flush the file. If verification fails, we won't be able to
1758 close the file before aborting. */
1761 if ((fn
->curr_properties
& PROP_cfg
)
1762 && (dump_flags
& TDF_GRAPH
))
1764 gcc::dump_manager
*dumps
= g
->get_dumps ();
1765 struct dump_file_info
*dfi
1766 = dumps
->get_dump_file_info (pass
->static_pass_number
);
1767 if (!dfi
->graph_dump_initialized
)
1769 clean_graph_dump_file (dump_file_name
);
1770 dfi
->graph_dump_initialized
= true;
1772 print_graph_cfg (dump_file_name
, fn
);
1779 static struct profile_record
*profile_record
;
1781 /* Do profile consistency book-keeping for the pass with static number INDEX.
1782 If SUBPASS is zero, we run _before_ the pass, and if SUBPASS is one, then
1783 we run _after_ the pass. RUN is true if the pass really runs, or FALSE
1784 if we are only book-keeping on passes that may have selectively disabled
1785 themselves on a given function. */
1787 check_profile_consistency (int index
, int subpass
, bool run
)
1789 pass_manager
*passes
= g
->get_passes ();
1792 if (!profile_record
)
1793 profile_record
= XCNEWVEC (struct profile_record
,
1794 passes
->passes_by_id_size
);
1795 gcc_assert (index
< passes
->passes_by_id_size
&& index
>= 0);
1796 gcc_assert (subpass
< 2);
1797 profile_record
[index
].run
|= run
;
1798 account_profile_record (&profile_record
[index
], subpass
);
1801 /* Output profile consistency. */
1804 dump_profile_report (void)
1806 g
->get_passes ()->dump_profile_report ();
1810 pass_manager::dump_profile_report () const
1813 int last_freq_in
= 0, last_count_in
= 0, last_freq_out
= 0, last_count_out
= 0;
1814 gcov_type last_time
= 0, last_size
= 0;
1815 double rel_time_change
, rel_size_change
;
1816 int last_reported
= 0;
1818 if (!profile_record
)
1820 fprintf (stderr
, "\nProfile consistency report:\n\n");
1821 fprintf (stderr
, "Pass name |mismatch in |mismated out|Overall\n");
1822 fprintf (stderr
, " |freq count |freq count |size time\n");
1824 for (i
= 0; i
< passes_by_id_size
; i
++)
1825 for (j
= 0 ; j
< 2; j
++)
1826 if (profile_record
[i
].run
)
1829 rel_time_change
= (profile_record
[i
].time
[j
]
1830 - (double)last_time
) * 100 / (double)last_time
;
1832 rel_time_change
= 0;
1834 rel_size_change
= (profile_record
[i
].size
[j
]
1835 - (double)last_size
) * 100 / (double)last_size
;
1837 rel_size_change
= 0;
1839 if (profile_record
[i
].num_mismatched_freq_in
[j
] != last_freq_in
1840 || profile_record
[i
].num_mismatched_freq_out
[j
] != last_freq_out
1841 || profile_record
[i
].num_mismatched_count_in
[j
] != last_count_in
1842 || profile_record
[i
].num_mismatched_count_out
[j
] != last_count_out
1843 || rel_time_change
|| rel_size_change
)
1846 fprintf (stderr
, "%-20s %s",
1847 passes_by_id
[i
]->name
,
1848 j
? "(after TODO)" : " ");
1849 if (profile_record
[i
].num_mismatched_freq_in
[j
] != last_freq_in
)
1850 fprintf (stderr
, "| %+5i",
1851 profile_record
[i
].num_mismatched_freq_in
[j
]
1854 fprintf (stderr
, "| ");
1855 if (profile_record
[i
].num_mismatched_count_in
[j
] != last_count_in
)
1856 fprintf (stderr
, " %+5i",
1857 profile_record
[i
].num_mismatched_count_in
[j
]
1860 fprintf (stderr
, " ");
1861 if (profile_record
[i
].num_mismatched_freq_out
[j
] != last_freq_out
)
1862 fprintf (stderr
, "| %+5i",
1863 profile_record
[i
].num_mismatched_freq_out
[j
]
1866 fprintf (stderr
, "| ");
1867 if (profile_record
[i
].num_mismatched_count_out
[j
] != last_count_out
)
1868 fprintf (stderr
, " %+5i",
1869 profile_record
[i
].num_mismatched_count_out
[j
]
1872 fprintf (stderr
, " ");
1874 /* Size/time units change across gimple and RTL. */
1875 if (i
== pass_expand_1
->static_pass_number
)
1876 fprintf (stderr
, "|----------");
1879 if (rel_size_change
)
1880 fprintf (stderr
, "| %+8.4f%%", rel_size_change
);
1882 fprintf (stderr
, "| ");
1883 if (rel_time_change
)
1884 fprintf (stderr
, " %+8.4f%%", rel_time_change
);
1886 fprintf (stderr
, "\n");
1887 last_freq_in
= profile_record
[i
].num_mismatched_freq_in
[j
];
1888 last_freq_out
= profile_record
[i
].num_mismatched_freq_out
[j
];
1889 last_count_in
= profile_record
[i
].num_mismatched_count_in
[j
];
1890 last_count_out
= profile_record
[i
].num_mismatched_count_out
[j
];
1892 else if (j
&& last_reported
!= i
)
1895 fprintf (stderr
, "%-20s ------------| | |\n",
1896 passes_by_id
[i
]->name
);
1898 last_time
= profile_record
[i
].time
[j
];
1899 last_size
= profile_record
[i
].size
[j
];
1903 /* Perform all TODO actions that ought to be done on each function. */
1906 execute_function_todo (function
*fn
, void *data
)
1908 bool from_ipa_pass
= (cfun
== NULL
);
1909 unsigned int flags
= (size_t)data
;
1910 flags
&= ~fn
->last_verified
;
1916 /* Always cleanup the CFG before trying to update SSA. */
1917 if (flags
& TODO_cleanup_cfg
)
1919 cleanup_tree_cfg ();
1921 /* When cleanup_tree_cfg merges consecutive blocks, it may
1922 perform some simplistic propagation when removing single
1923 valued PHI nodes. This propagation may, in turn, cause the
1924 SSA form to become out-of-date (see PR 22037). So, even
1925 if the parent pass had not scheduled an SSA update, we may
1926 still need to do one. */
1927 if (!(flags
& TODO_update_ssa_any
) && need_ssa_update_p (cfun
))
1928 flags
|= TODO_update_ssa
;
1931 if (flags
& TODO_update_ssa_any
)
1933 unsigned update_flags
= flags
& TODO_update_ssa_any
;
1934 update_ssa (update_flags
);
1937 if (flag_tree_pta
&& (flags
& TODO_rebuild_alias
))
1938 compute_may_aliases ();
1940 if (optimize
&& (flags
& TODO_update_address_taken
))
1941 execute_update_addresses_taken ();
1943 if (flags
& TODO_remove_unused_locals
)
1944 remove_unused_locals ();
1946 if (flags
& TODO_rebuild_frequencies
)
1947 rebuild_frequencies ();
1949 if (flags
& TODO_rebuild_cgraph_edges
)
1950 cgraph_edge::rebuild_edges ();
1952 gcc_assert (dom_info_state (fn
, CDI_POST_DOMINATORS
) == DOM_NONE
);
1953 /* If we've seen errors do not bother running any verifiers. */
1954 if (flag_checking
&& !seen_error ())
1956 dom_state pre_verify_state
= dom_info_state (fn
, CDI_DOMINATORS
);
1957 dom_state pre_verify_pstate
= dom_info_state (fn
, CDI_POST_DOMINATORS
);
1959 if (flags
& TODO_verify_il
)
1961 if (cfun
->curr_properties
& PROP_trees
)
1963 if (cfun
->curr_properties
& PROP_cfg
)
1964 /* IPA passes leave stmts to be fixed up, so make sure to
1965 not verify stmts really throw. */
1966 verify_gimple_in_cfg (cfun
, !from_ipa_pass
);
1968 verify_gimple_in_seq (gimple_body (cfun
->decl
));
1970 if (cfun
->curr_properties
& PROP_ssa
)
1971 /* IPA passes leave stmts to be fixed up, so make sure to
1972 not verify SSA operands whose verifier will choke on that. */
1973 verify_ssa (true, !from_ipa_pass
);
1974 /* IPA passes leave basic-blocks unsplit, so make sure to
1975 not trip on that. */
1976 if ((cfun
->curr_properties
& PROP_cfg
)
1978 verify_flow_info ();
1980 && loops_state_satisfies_p (LOOP_CLOSED_SSA
))
1981 verify_loop_closed_ssa (false);
1982 if (cfun
->curr_properties
& PROP_rtl
)
1983 verify_rtl_sharing ();
1986 /* Make sure verifiers don't change dominator state. */
1987 gcc_assert (dom_info_state (fn
, CDI_DOMINATORS
) == pre_verify_state
);
1988 gcc_assert (dom_info_state (fn
, CDI_POST_DOMINATORS
) == pre_verify_pstate
);
1991 fn
->last_verified
= flags
& TODO_verify_all
;
1995 /* For IPA passes make sure to release dominator info, it can be
1996 computed by non-verifying TODOs. */
1999 free_dominance_info (fn
, CDI_DOMINATORS
);
2000 free_dominance_info (fn
, CDI_POST_DOMINATORS
);
2004 /* Perform all TODO actions. */
2006 execute_todo (unsigned int flags
)
2010 && need_ssa_update_p (cfun
))
2011 gcc_assert (flags
& TODO_update_ssa_any
);
2013 statistics_fini_pass ();
2016 do_per_function (execute_function_todo
, (void *)(size_t) flags
);
2018 /* At this point we should not have any unreachable code in the
2019 CFG, so it is safe to flush the pending freelist for SSA_NAMES. */
2020 if (cfun
&& cfun
->gimple_df
)
2021 flush_ssaname_freelist ();
2023 /* Always remove functions just as before inlining: IPA passes might be
2024 interested to see bodies of extern inline functions that are not inlined
2025 to analyze side effects. The full removal is done just at the end
2026 of IPA pass queue. */
2027 if (flags
& TODO_remove_functions
)
2030 symtab
->remove_unreachable_nodes (dump_file
);
2033 if ((flags
& TODO_dump_symtab
) && dump_file
&& !current_function_decl
)
2036 symtab_node::dump_table (dump_file
);
2037 /* Flush the file. If verification fails, we won't be able to
2038 close the file before aborting. */
2042 /* Now that the dumping has been done, we can get rid of the optional
2044 if (flags
& TODO_df_finish
)
2045 df_finish_pass ((flags
& TODO_df_verify
) != 0);
2048 /* Verify invariants that should hold between passes. This is a place
2049 to put simple sanity checks. */
2052 verify_interpass_invariants (void)
2054 gcc_checking_assert (!fold_deferring_overflow_warnings_p ());
2057 /* Clear the last verified flag. */
2060 clear_last_verified (function
*fn
, void *data ATTRIBUTE_UNUSED
)
2062 fn
->last_verified
= 0;
2065 /* Helper function. Verify that the properties has been turn into the
2066 properties expected by the pass. */
2069 verify_curr_properties (function
*fn
, void *data
)
2071 unsigned int props
= (size_t)data
;
2072 gcc_assert ((fn
->curr_properties
& props
) == props
);
2075 /* Release dump file name if set. */
2078 release_dump_file_name (void)
2082 free (CONST_CAST (char *, dump_file_name
));
2083 dump_file_name
= NULL
;
2087 /* Initialize pass dump file. */
2088 /* This is non-static so that the plugins can use it. */
2091 pass_init_dump_file (opt_pass
*pass
)
2093 /* If a dump file name is present, open it if enabled. */
2094 if (pass
->static_pass_number
!= -1)
2096 timevar_push (TV_DUMP
);
2097 gcc::dump_manager
*dumps
= g
->get_dumps ();
2098 bool initializing_dump
=
2099 !dumps
->dump_initialized_p (pass
->static_pass_number
);
2100 release_dump_file_name ();
2101 dump_file_name
= dumps
->get_dump_file_name (pass
->static_pass_number
);
2102 dumps
->dump_start (pass
->static_pass_number
, &dump_flags
);
2103 if (dump_file
&& current_function_decl
)
2104 dump_function_header (dump_file
, current_function_decl
, dump_flags
);
2105 if (initializing_dump
2106 && dump_file
&& (dump_flags
& TDF_GRAPH
)
2107 && cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2109 clean_graph_dump_file (dump_file_name
);
2110 struct dump_file_info
*dfi
2111 = dumps
->get_dump_file_info (pass
->static_pass_number
);
2112 dfi
->graph_dump_initialized
= true;
2114 timevar_pop (TV_DUMP
);
2115 return initializing_dump
;
2121 /* Flush PASS dump file. */
2122 /* This is non-static so that plugins can use it. */
2125 pass_fini_dump_file (opt_pass
*pass
)
2127 timevar_push (TV_DUMP
);
2129 /* Flush and close dump file. */
2130 release_dump_file_name ();
2132 g
->get_dumps ()->dump_finish (pass
->static_pass_number
);
2133 timevar_pop (TV_DUMP
);
2136 /* After executing the pass, apply expected changes to the function
2140 update_properties_after_pass (function
*fn
, void *data
)
2142 opt_pass
*pass
= (opt_pass
*) data
;
2143 fn
->curr_properties
= (fn
->curr_properties
| pass
->properties_provided
)
2144 & ~pass
->properties_destroyed
;
2147 /* Execute summary generation for all of the passes in IPA_PASS. */
2150 execute_ipa_summary_passes (ipa_opt_pass_d
*ipa_pass
)
2154 opt_pass
*pass
= ipa_pass
;
2156 /* Execute all of the IPA_PASSes in the list. */
2157 if (ipa_pass
->type
== IPA_PASS
2158 && pass
->gate (cfun
)
2159 && ipa_pass
->generate_summary
)
2161 pass_init_dump_file (pass
);
2163 /* If a timevar is present, start it. */
2165 timevar_push (pass
->tv_id
);
2167 current_pass
= pass
;
2168 ipa_pass
->generate_summary ();
2172 timevar_pop (pass
->tv_id
);
2174 pass_fini_dump_file (pass
);
2176 ipa_pass
= (ipa_opt_pass_d
*)ipa_pass
->next
;
2180 /* Execute IPA_PASS function transform on NODE. */
2183 execute_one_ipa_transform_pass (struct cgraph_node
*node
,
2184 ipa_opt_pass_d
*ipa_pass
)
2186 opt_pass
*pass
= ipa_pass
;
2187 unsigned int todo_after
= 0;
2189 current_pass
= pass
;
2190 if (!ipa_pass
->function_transform
)
2193 /* Note that the folders should only create gimple expressions.
2194 This is a hack until the new folder is ready. */
2195 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
2197 pass_init_dump_file (pass
);
2199 /* If a timevar is present, start it. */
2200 if (pass
->tv_id
!= TV_NONE
)
2201 timevar_push (pass
->tv_id
);
2203 /* Run pre-pass verification. */
2204 execute_todo (ipa_pass
->function_transform_todo_flags_start
);
2207 todo_after
= ipa_pass
->function_transform (node
);
2209 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2210 check_profile_consistency (pass
->static_pass_number
, 0, true);
2212 /* Run post-pass cleanup and verification. */
2213 execute_todo (todo_after
);
2214 verify_interpass_invariants ();
2215 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2216 check_profile_consistency (pass
->static_pass_number
, 1, true);
2219 if (pass
->tv_id
!= TV_NONE
)
2220 timevar_pop (pass
->tv_id
);
2223 do_per_function (execute_function_dump
, pass
);
2224 pass_fini_dump_file (pass
);
2226 current_pass
= NULL
;
2227 redirect_edge_var_map_empty ();
2229 /* Signal this is a suitable GC collection point. */
2230 if (!(todo_after
& TODO_do_not_ggc_collect
))
2234 /* For the current function, execute all ipa transforms. */
2237 execute_all_ipa_transforms (void)
2239 struct cgraph_node
*node
;
2242 node
= cgraph_node::get (current_function_decl
);
2244 if (node
->ipa_transforms_to_apply
.exists ())
2248 for (i
= 0; i
< node
->ipa_transforms_to_apply
.length (); i
++)
2249 execute_one_ipa_transform_pass (node
, node
->ipa_transforms_to_apply
[i
]);
2250 node
->ipa_transforms_to_apply
.release ();
2254 /* Check if PASS is explicitly disabled or enabled and return
2255 the gate status. FUNC is the function to be processed, and
2256 GATE_STATUS is the gate status determined by pass manager by
2260 override_gate_status (opt_pass
*pass
, tree func
, bool gate_status
)
2262 bool explicitly_enabled
= false;
2263 bool explicitly_disabled
= false;
2266 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2267 enabled_pass_uid_range_tab
);
2269 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2270 disabled_pass_uid_range_tab
);
2272 gate_status
= !explicitly_disabled
&& (gate_status
|| explicitly_enabled
);
2281 execute_one_pass (opt_pass
*pass
)
2283 unsigned int todo_after
= 0;
2287 /* IPA passes are executed on whole program, so cfun should be NULL.
2288 Other passes need function context set. */
2289 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
2290 gcc_assert (!cfun
&& !current_function_decl
);
2292 gcc_assert (cfun
&& current_function_decl
);
2294 current_pass
= pass
;
2296 /* Check whether gate check should be avoided.
2297 User controls the value of the gate through the parameter "gate_status". */
2298 gate_status
= pass
->gate (cfun
);
2299 gate_status
= override_gate_status (pass
, current_function_decl
, gate_status
);
2301 /* Override gate with plugin. */
2302 invoke_plugin_callbacks (PLUGIN_OVERRIDE_GATE
, &gate_status
);
2306 /* Run so passes selectively disabling themselves on a given function
2307 are not miscounted. */
2308 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2310 check_profile_consistency (pass
->static_pass_number
, 0, false);
2311 check_profile_consistency (pass
->static_pass_number
, 1, false);
2313 current_pass
= NULL
;
2317 /* Pass execution event trigger: useful to identify passes being
2319 invoke_plugin_callbacks (PLUGIN_PASS_EXECUTION
, pass
);
2321 if (!quiet_flag
&& !cfun
)
2322 fprintf (stderr
, " <%s>", pass
->name
? pass
->name
: "");
2324 /* Note that the folders should only create gimple expressions.
2325 This is a hack until the new folder is ready. */
2326 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
2328 pass_init_dump_file (pass
);
2330 /* If a timevar is present, start it. */
2331 if (pass
->tv_id
!= TV_NONE
)
2332 timevar_push (pass
->tv_id
);
2334 /* Run pre-pass verification. */
2335 execute_todo (pass
->todo_flags_start
);
2338 do_per_function (verify_curr_properties
,
2339 (void *)(size_t)pass
->properties_required
);
2342 todo_after
= pass
->execute (cfun
);
2344 if (todo_after
& TODO_discard_function
)
2347 if (pass
->tv_id
!= TV_NONE
)
2348 timevar_pop (pass
->tv_id
);
2350 pass_fini_dump_file (pass
);
2353 /* As cgraph_node::release_body expects release dominators info,
2354 we have to release it. */
2355 if (dom_info_available_p (CDI_DOMINATORS
))
2356 free_dominance_info (CDI_DOMINATORS
);
2358 if (dom_info_available_p (CDI_POST_DOMINATORS
))
2359 free_dominance_info (CDI_POST_DOMINATORS
);
2361 tree fn
= cfun
->decl
;
2364 cgraph_node::get (fn
)->release_body ();
2366 current_pass
= NULL
;
2367 redirect_edge_var_map_empty ();
2374 do_per_function (clear_last_verified
, NULL
);
2376 do_per_function (update_properties_after_pass
, pass
);
2378 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2379 check_profile_consistency (pass
->static_pass_number
, 0, true);
2381 /* Run post-pass cleanup and verification. */
2382 execute_todo (todo_after
| pass
->todo_flags_finish
| TODO_verify_il
);
2383 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2384 check_profile_consistency (pass
->static_pass_number
, 1, true);
2386 verify_interpass_invariants ();
2389 if (pass
->tv_id
!= TV_NONE
)
2390 timevar_pop (pass
->tv_id
);
2392 if (pass
->type
== IPA_PASS
2393 && ((ipa_opt_pass_d
*)pass
)->function_transform
)
2395 struct cgraph_node
*node
;
2396 FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node
)
2397 node
->ipa_transforms_to_apply
.safe_push ((ipa_opt_pass_d
*)pass
);
2400 do_per_function (execute_function_dump
, pass
);
2402 if (!current_function_decl
)
2403 symtab
->process_new_functions ();
2405 pass_fini_dump_file (pass
);
2407 if (pass
->type
!= SIMPLE_IPA_PASS
&& pass
->type
!= IPA_PASS
)
2408 gcc_assert (!(cfun
->curr_properties
& PROP_trees
)
2409 || pass
->type
!= RTL_PASS
);
2411 current_pass
= NULL
;
2412 redirect_edge_var_map_empty ();
2414 /* Signal this is a suitable GC collection point. */
2415 if (!((todo_after
| pass
->todo_flags_finish
) & TODO_do_not_ggc_collect
))
2422 execute_pass_list_1 (opt_pass
*pass
)
2426 gcc_assert (pass
->type
== GIMPLE_PASS
2427 || pass
->type
== RTL_PASS
);
2431 if (execute_one_pass (pass
) && pass
->sub
)
2432 execute_pass_list_1 (pass
->sub
);
2439 execute_pass_list (function
*fn
, opt_pass
*pass
)
2441 gcc_assert (fn
== cfun
);
2442 execute_pass_list_1 (pass
);
2443 if (cfun
&& fn
->cfg
)
2445 free_dominance_info (CDI_DOMINATORS
);
2446 free_dominance_info (CDI_POST_DOMINATORS
);
2450 /* Write out all LTO data. */
2454 timevar_push (TV_IPA_LTO_GIMPLE_OUT
);
2456 timevar_pop (TV_IPA_LTO_GIMPLE_OUT
);
2457 timevar_push (TV_IPA_LTO_DECL_OUT
);
2458 produce_asm_for_decls ();
2459 timevar_pop (TV_IPA_LTO_DECL_OUT
);
2462 /* Same as execute_pass_list but assume that subpasses of IPA passes
2463 are local passes. If SET is not NULL, write out summaries of only
2464 those node in SET. */
2467 ipa_write_summaries_2 (opt_pass
*pass
, struct lto_out_decl_state
*state
)
2471 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*)pass
;
2472 gcc_assert (!current_function_decl
);
2474 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2475 if (pass
->type
== IPA_PASS
2476 && ipa_pass
->write_summary
2477 && pass
->gate (cfun
))
2479 /* If a timevar is present, start it. */
2481 timevar_push (pass
->tv_id
);
2483 pass_init_dump_file (pass
);
2485 current_pass
= pass
;
2486 ipa_pass
->write_summary ();
2488 pass_fini_dump_file (pass
);
2490 /* If a timevar is present, start it. */
2492 timevar_pop (pass
->tv_id
);
2495 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2496 ipa_write_summaries_2 (pass
->sub
, state
);
2502 /* Helper function of ipa_write_summaries. Creates and destroys the
2503 decl state and calls ipa_write_summaries_2 for all passes that have
2504 summaries. SET is the set of nodes to be written. */
2507 ipa_write_summaries_1 (lto_symtab_encoder_t encoder
)
2509 pass_manager
*passes
= g
->get_passes ();
2510 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2511 state
->symtab_node_encoder
= encoder
;
2513 lto_output_init_mode_table ();
2514 lto_push_out_decl_state (state
);
2516 gcc_assert (!flag_wpa
);
2517 ipa_write_summaries_2 (passes
->all_regular_ipa_passes
, state
);
2521 gcc_assert (lto_get_out_decl_state () == state
);
2522 lto_pop_out_decl_state ();
2523 lto_delete_out_decl_state (state
);
2526 /* Write out summaries for all the nodes in the callgraph. */
2529 ipa_write_summaries (void)
2531 lto_symtab_encoder_t encoder
;
2533 varpool_node
*vnode
;
2534 struct cgraph_node
*node
;
2535 struct cgraph_node
**order
;
2537 if ((!flag_generate_lto
&& !flag_generate_offload
) || seen_error ())
2540 select_what_to_stream ();
2542 encoder
= lto_symtab_encoder_new (false);
2544 /* Create the callgraph set in the same order used in
2545 cgraph_expand_all_functions. This mostly facilitates debugging,
2546 since it causes the gimple file to be processed in the same order
2547 as the source code. */
2548 order
= XCNEWVEC (struct cgraph_node
*, symtab
->cgraph_count
);
2549 order_pos
= ipa_reverse_postorder (order
);
2550 gcc_assert (order_pos
== symtab
->cgraph_count
);
2552 for (i
= order_pos
- 1; i
>= 0; i
--)
2554 struct cgraph_node
*node
= order
[i
];
2556 if (node
->has_gimple_body_p ())
2558 /* When streaming out references to statements as part of some IPA
2559 pass summary, the statements need to have uids assigned and the
2560 following does that for all the IPA passes here. Naturally, this
2561 ordering then matches the one IPA-passes get in their stmt_fixup
2564 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
2565 renumber_gimple_stmt_uids ();
2568 if (node
->definition
&& node
->need_lto_streaming
)
2569 lto_set_symtab_encoder_in_partition (encoder
, node
);
2572 FOR_EACH_DEFINED_FUNCTION (node
)
2573 if (node
->alias
&& node
->need_lto_streaming
)
2574 lto_set_symtab_encoder_in_partition (encoder
, node
);
2575 FOR_EACH_DEFINED_VARIABLE (vnode
)
2576 if (vnode
->need_lto_streaming
)
2577 lto_set_symtab_encoder_in_partition (encoder
, vnode
);
2579 ipa_write_summaries_1 (compute_ltrans_boundary (encoder
));
2584 /* Same as execute_pass_list but assume that subpasses of IPA passes
2585 are local passes. If SET is not NULL, write out optimization summaries of
2586 only those node in SET. */
2589 ipa_write_optimization_summaries_1 (opt_pass
*pass
,
2590 struct lto_out_decl_state
*state
)
2594 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*)pass
;
2595 gcc_assert (!current_function_decl
);
2597 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2598 if (pass
->type
== IPA_PASS
2599 && ipa_pass
->write_optimization_summary
2600 && pass
->gate (cfun
))
2602 /* If a timevar is present, start it. */
2604 timevar_push (pass
->tv_id
);
2606 pass_init_dump_file (pass
);
2608 current_pass
= pass
;
2609 ipa_pass
->write_optimization_summary ();
2611 pass_fini_dump_file (pass
);
2613 /* If a timevar is present, start it. */
2615 timevar_pop (pass
->tv_id
);
2618 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2619 ipa_write_optimization_summaries_1 (pass
->sub
, state
);
2625 /* Write all the optimization summaries for the cgraph nodes in SET. If SET is
2626 NULL, write out all summaries of all nodes. */
2629 ipa_write_optimization_summaries (lto_symtab_encoder_t encoder
)
2631 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2632 lto_symtab_encoder_iterator lsei
;
2633 state
->symtab_node_encoder
= encoder
;
2635 lto_output_init_mode_table ();
2636 lto_push_out_decl_state (state
);
2637 for (lsei
= lsei_start_function_in_partition (encoder
);
2638 !lsei_end_p (lsei
); lsei_next_function_in_partition (&lsei
))
2640 struct cgraph_node
*node
= lsei_cgraph_node (lsei
);
2641 /* When streaming out references to statements as part of some IPA
2642 pass summary, the statements need to have uids assigned.
2644 For functions newly born at WPA stage we need to initialize
2646 if (node
->definition
2647 && gimple_has_body_p (node
->decl
))
2649 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
2650 renumber_gimple_stmt_uids ();
2655 gcc_assert (flag_wpa
);
2656 pass_manager
*passes
= g
->get_passes ();
2657 ipa_write_optimization_summaries_1 (passes
->all_regular_ipa_passes
, state
);
2661 gcc_assert (lto_get_out_decl_state () == state
);
2662 lto_pop_out_decl_state ();
2663 lto_delete_out_decl_state (state
);
2666 /* Same as execute_pass_list but assume that subpasses of IPA passes
2667 are local passes. */
2670 ipa_read_summaries_1 (opt_pass
*pass
)
2674 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
2676 gcc_assert (!current_function_decl
);
2678 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2680 if (pass
->gate (cfun
))
2682 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_summary
)
2684 /* If a timevar is present, start it. */
2686 timevar_push (pass
->tv_id
);
2688 pass_init_dump_file (pass
);
2690 current_pass
= pass
;
2691 ipa_pass
->read_summary ();
2693 pass_fini_dump_file (pass
);
2697 timevar_pop (pass
->tv_id
);
2700 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2701 ipa_read_summaries_1 (pass
->sub
);
2708 /* Read all the summaries for all_regular_ipa_passes. */
2711 ipa_read_summaries (void)
2713 pass_manager
*passes
= g
->get_passes ();
2714 ipa_read_summaries_1 (passes
->all_regular_ipa_passes
);
2717 /* Same as execute_pass_list but assume that subpasses of IPA passes
2718 are local passes. */
2721 ipa_read_optimization_summaries_1 (opt_pass
*pass
)
2725 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
2727 gcc_assert (!current_function_decl
);
2729 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2731 if (pass
->gate (cfun
))
2733 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_optimization_summary
)
2735 /* If a timevar is present, start it. */
2737 timevar_push (pass
->tv_id
);
2739 pass_init_dump_file (pass
);
2741 current_pass
= pass
;
2742 ipa_pass
->read_optimization_summary ();
2744 pass_fini_dump_file (pass
);
2748 timevar_pop (pass
->tv_id
);
2751 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2752 ipa_read_optimization_summaries_1 (pass
->sub
);
2758 /* Read all the summaries for all_regular_ipa_passes. */
2761 ipa_read_optimization_summaries (void)
2763 pass_manager
*passes
= g
->get_passes ();
2764 ipa_read_optimization_summaries_1 (passes
->all_regular_ipa_passes
);
2767 /* Same as execute_pass_list but assume that subpasses of IPA passes
2768 are local passes. */
2770 execute_ipa_pass_list (opt_pass
*pass
)
2774 gcc_assert (!current_function_decl
);
2776 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2777 if (execute_one_pass (pass
) && pass
->sub
)
2779 if (pass
->sub
->type
== GIMPLE_PASS
)
2781 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_START
, NULL
);
2782 do_per_function_toporder ((void (*)(function
*, void *))
2785 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_END
, NULL
);
2787 else if (pass
->sub
->type
== SIMPLE_IPA_PASS
2788 || pass
->sub
->type
== IPA_PASS
)
2789 execute_ipa_pass_list (pass
->sub
);
2793 gcc_assert (!current_function_decl
);
2794 symtab
->process_new_functions ();
2800 /* Execute stmt fixup hooks of all passes in PASS for NODE and STMTS. */
2803 execute_ipa_stmt_fixups (opt_pass
*pass
,
2804 struct cgraph_node
*node
, gimple
**stmts
)
2808 /* Execute all of the IPA_PASSes in the list. */
2809 if (pass
->type
== IPA_PASS
2810 && pass
->gate (cfun
))
2812 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
2814 if (ipa_pass
->stmt_fixup
)
2816 pass_init_dump_file (pass
);
2817 /* If a timevar is present, start it. */
2819 timevar_push (pass
->tv_id
);
2821 current_pass
= pass
;
2822 ipa_pass
->stmt_fixup (node
, stmts
);
2826 timevar_pop (pass
->tv_id
);
2827 pass_fini_dump_file (pass
);
2830 execute_ipa_stmt_fixups (pass
->sub
, node
, stmts
);
2836 /* Execute stmt fixup hooks of all IPA passes for NODE and STMTS. */
2839 execute_all_ipa_stmt_fixups (struct cgraph_node
*node
, gimple
**stmts
)
2841 pass_manager
*passes
= g
->get_passes ();
2842 execute_ipa_stmt_fixups (passes
->all_regular_ipa_passes
, node
, stmts
);
2846 extern void debug_properties (unsigned int);
2847 extern void dump_properties (FILE *, unsigned int);
2850 dump_properties (FILE *dump
, unsigned int props
)
2852 fprintf (dump
, "Properties:\n");
2853 if (props
& PROP_gimple_any
)
2854 fprintf (dump
, "PROP_gimple_any\n");
2855 if (props
& PROP_gimple_lcf
)
2856 fprintf (dump
, "PROP_gimple_lcf\n");
2857 if (props
& PROP_gimple_leh
)
2858 fprintf (dump
, "PROP_gimple_leh\n");
2859 if (props
& PROP_cfg
)
2860 fprintf (dump
, "PROP_cfg\n");
2861 if (props
& PROP_ssa
)
2862 fprintf (dump
, "PROP_ssa\n");
2863 if (props
& PROP_no_crit_edges
)
2864 fprintf (dump
, "PROP_no_crit_edges\n");
2865 if (props
& PROP_rtl
)
2866 fprintf (dump
, "PROP_rtl\n");
2867 if (props
& PROP_gimple_lomp
)
2868 fprintf (dump
, "PROP_gimple_lomp\n");
2869 if (props
& PROP_gimple_lcx
)
2870 fprintf (dump
, "PROP_gimple_lcx\n");
2871 if (props
& PROP_gimple_lvec
)
2872 fprintf (dump
, "PROP_gimple_lvec\n");
2873 if (props
& PROP_cfglayout
)
2874 fprintf (dump
, "PROP_cfglayout\n");
2878 debug_properties (unsigned int props
)
2880 dump_properties (stderr
, props
);
2883 /* Called by local passes to see if function is called by already processed nodes.
2884 Because we process nodes in topological order, this means that function is
2885 in recursive cycle or we introduced new direct calls. */
2887 function_called_by_processed_nodes_p (void)
2889 struct cgraph_edge
*e
;
2890 for (e
= cgraph_node::get (current_function_decl
)->callers
;
2894 if (e
->caller
->decl
== current_function_decl
)
2896 if (!e
->caller
->has_gimple_body_p ())
2898 if (TREE_ASM_WRITTEN (e
->caller
->decl
))
2900 if (!e
->caller
->process
&& !e
->caller
->global
.inlined_to
)
2905 fprintf (dump_file
, "Already processed call to:\n");
2906 e
->caller
->dump (dump_file
);
2911 #include "gt-passes.h"