1 /* Top level of GCC compilers (cc1, cc1plus, etc.)
2 Copyright (C) 1987-2017 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"
40 #include "lto-streamer.h"
41 #include "fold-const.h"
47 #include "value-prof.h"
49 #include "tree-ssa-loop-manip.h"
50 #include "tree-into-ssa.h"
53 #include "tree-pass.h"
55 #include "ipa-utils.h"
56 #include "tree-pretty-print.h" /* for dump_function_header */
58 #include "pass_manager.h"
60 #include "tree-ssa-live.h" /* For remove_unused_locals. */
61 #include "tree-cfgcleanup.h"
65 /* This is used for debugging. It allows the current pass to printed
66 from anywhere in compilation.
67 The variable current_pass is also used for statistics and plugins. */
68 opt_pass
*current_pass
;
70 /* Most passes are single-instance (within their context) and thus don't
71 need to implement cloning, but passes that support multiple instances
72 *must* provide their own implementation of the clone method.
74 Handle this by providing a default implemenation, but make it a fatal
80 internal_error ("pass %s does not support cloning", name
);
84 opt_pass::set_pass_param (unsigned int, bool)
86 internal_error ("pass %s needs a set_pass_param implementation to handle the"
87 " extra argument in NEXT_PASS", name
);
91 opt_pass::gate (function
*)
97 opt_pass::execute (function
*)
102 opt_pass::opt_pass (const pass_data
&data
, context
*ctxt
)
106 static_pass_number (0),
113 pass_manager::execute_early_local_passes ()
115 execute_pass_list (cfun
, pass_build_ssa_passes_1
->sub
);
116 if (flag_check_pointer_bounds
)
117 execute_pass_list (cfun
, pass_chkp_instrumentation_passes_1
->sub
);
118 execute_pass_list (cfun
, pass_local_optimization_passes_1
->sub
);
122 pass_manager::execute_pass_mode_switching ()
124 return pass_mode_switching_1
->execute (cfun
);
128 /* Call from anywhere to find out what pass this is. Useful for
129 printing out debugging information deep inside an service
132 print_current_pass (FILE *file
)
135 fprintf (file
, "current pass = %s (%d)\n",
136 current_pass
->name
, current_pass
->static_pass_number
);
138 fprintf (file
, "no current pass.\n");
142 /* Call from the debugger to get the current pass name. */
146 print_current_pass (stderr
);
151 /* Global variables used to communicate with passes. */
155 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
158 This does nothing for local (non-static) variables, unless the
159 variable is a register variable with DECL_ASSEMBLER_NAME set. In
160 that case, or if the variable is not an automatic, it sets up the
161 RTL and outputs any assembler code (label definition, storage
162 allocation and initialization).
164 DECL is the declaration. TOP_LEVEL is nonzero
165 if this declaration is not within a function. */
168 rest_of_decl_compilation (tree decl
,
172 bool finalize
= true;
174 /* We deferred calling assemble_alias so that we could collect
175 other attributes such as visibility. Emit the alias now. */
179 alias
= lookup_attribute ("alias", DECL_ATTRIBUTES (decl
));
182 alias
= TREE_VALUE (TREE_VALUE (alias
));
183 alias
= get_identifier (TREE_STRING_POINTER (alias
));
184 /* A quirk of the initial implementation of aliases required that the
185 user add "extern" to all of them. Which is silly, but now
186 historical. Do note that the symbol is in fact locally defined. */
187 DECL_EXTERNAL (decl
) = 0;
188 TREE_STATIC (decl
) = 1;
189 assemble_alias (decl
, alias
);
194 /* Can't defer this, because it needs to happen before any
195 later function definitions are processed. */
196 if (DECL_ASSEMBLER_NAME_SET_P (decl
) && DECL_REGISTER (decl
))
197 make_decl_rtl (decl
);
199 /* Forward declarations for nested functions are not "external",
200 but we need to treat them as if they were. */
201 if (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)
202 || TREE_CODE (decl
) == FUNCTION_DECL
)
204 timevar_push (TV_VARCONST
);
206 /* Don't output anything when a tentative file-scope definition
207 is seen. But at end of compilation, do output code for them.
209 We do output all variables and rely on
210 callgraph code to defer them except for forward declarations
211 (see gcc.c-torture/compile/920624-1.c) */
213 || !DECL_DEFER_OUTPUT (decl
)
214 || DECL_INITIAL (decl
))
215 && (!VAR_P (decl
) || !DECL_HAS_VALUE_EXPR_P (decl
))
216 && !DECL_EXTERNAL (decl
))
218 /* When reading LTO unit, we also read varpool, so do not
220 if (in_lto_p
&& !at_end
)
222 else if (finalize
&& TREE_CODE (decl
) != FUNCTION_DECL
)
223 varpool_node::finalize_decl (decl
);
226 #ifdef ASM_FINISH_DECLARE_OBJECT
227 if (decl
== last_assemble_variable_decl
)
229 ASM_FINISH_DECLARE_OBJECT (asm_out_file
, decl
,
234 /* Now that we have activated any function-specific attributes
235 that might affect function decl, particularly align, relayout it. */
236 if (TREE_CODE (decl
) == FUNCTION_DECL
)
237 targetm
.target_option
.relayout_function (decl
);
239 timevar_pop (TV_VARCONST
);
241 else if (TREE_CODE (decl
) == TYPE_DECL
242 /* Like in rest_of_type_compilation, avoid confusing the debug
243 information machinery when there are errors. */
246 timevar_push (TV_SYMOUT
);
247 debug_hooks
->type_decl (decl
, !top_level
);
248 timevar_pop (TV_SYMOUT
);
251 /* Let cgraph know about the existence of variables. */
252 if (in_lto_p
&& !at_end
)
254 else if (VAR_P (decl
) && !DECL_EXTERNAL (decl
)
255 && TREE_STATIC (decl
))
256 varpool_node::get_create (decl
);
258 /* Generate early debug for global variables. Any local variables will
259 be handled by either handling reachable functions from
260 finalize_compilation_unit (and by consequence, locally scoped
261 symbols), or by rest_of_type_compilation below.
263 Also, pick up function prototypes, which will be mostly ignored
264 by the different early_global_decl() hooks, but will at least be
265 used by Go's hijack of the debug_hooks to implement
268 && (TREE_CODE (decl
) != FUNCTION_DECL
269 /* This will pick up function prototypes with no bodies,
270 which are not visible in finalize_compilation_unit()
271 while iterating with FOR_EACH_*_FUNCTION through the
273 || !DECL_SAVED_TREE (decl
))
275 /* We need to check both decl_function_context and
276 current_function_decl here to make sure local extern
277 declarations end up with the correct context.
279 For local extern declarations, decl_function_context is
280 empty, but current_function_decl is set to the function where
281 the extern was declared . Without the check for
282 !current_function_decl below, the local extern ends up
283 incorrectly with a top-level context.
295 extern int i; // Local extern declaration.
302 && !decl_function_context (decl
)
303 && !current_function_decl
304 && DECL_SOURCE_LOCATION (decl
) != BUILTINS_LOCATION
305 && (!decl_type_context (decl
)
306 /* If we created a varpool node for the decl make sure to
307 call early_global_decl. Otherwise we miss changes
308 introduced by member definitions like
309 struct A { static int staticdatamember; };
310 int A::staticdatamember;
311 and thus have incomplete early debug and late debug
312 called from varpool node removal fails to handle it
316 && TREE_STATIC (decl
) && !DECL_EXTERNAL (decl
)))
317 /* Avoid confusing the debug information machinery when there are
320 (*debug_hooks
->early_global_decl
) (decl
);
323 /* Called after finishing a record, union or enumeral type. */
326 rest_of_type_compilation (tree type
, int toplev
)
328 /* Avoid confusing the debug information machinery when there are
333 timevar_push (TV_SYMOUT
);
334 debug_hooks
->type_decl (TYPE_STUB_DECL (type
), !toplev
);
335 timevar_pop (TV_SYMOUT
);
342 finish_optimization_passes (void)
345 struct dump_file_info
*dfi
;
347 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
349 timevar_push (TV_DUMP
);
350 if (profile_arc_flag
|| flag_test_coverage
|| flag_branch_probabilities
)
352 dumps
->dump_start (pass_profile_1
->static_pass_number
, NULL
);
354 dumps
->dump_finish (pass_profile_1
->static_pass_number
);
359 dumps
->dump_start (pass_profile_1
->static_pass_number
, NULL
);
360 print_combine_total_stats ();
361 dumps
->dump_finish (pass_profile_1
->static_pass_number
);
364 /* Do whatever is necessary to finish printing the graphs. */
365 for (i
= TDI_end
; (dfi
= dumps
->get_dump_file_info (i
)) != NULL
; ++i
)
366 if (dfi
->graph_dump_initialized
)
368 name
= dumps
->get_dump_file_name (dfi
);
369 finish_graph_dump_file (name
);
373 timevar_pop (TV_DUMP
);
377 execute_build_ssa_passes (void)
379 /* Once this pass (and its sub-passes) are complete, all functions
380 will be in SSA form. Technically this state change is happening
381 a tad early, since the sub-passes have not yet run, but since
382 none of the sub-passes are IPA passes and do not create new
383 functions, this is ok. We're setting this value for the benefit
384 of IPA passes that follow. */
385 if (symtab
->state
< IPA_SSA
)
386 symtab
->state
= IPA_SSA
;
392 const pass_data pass_data_build_ssa_passes
=
394 SIMPLE_IPA_PASS
, /* type */
395 "build_ssa_passes", /* name */
396 OPTGROUP_NONE
, /* optinfo_flags */
397 TV_EARLY_LOCAL
, /* tv_id */
398 0, /* properties_required */
399 0, /* properties_provided */
400 0, /* properties_destroyed */
401 0, /* todo_flags_start */
402 /* todo_flags_finish is executed before subpases. For this reason
403 it makes no sense to remove unreachable functions here. */
404 0, /* todo_flags_finish */
407 class pass_build_ssa_passes
: public simple_ipa_opt_pass
410 pass_build_ssa_passes (gcc::context
*ctxt
)
411 : simple_ipa_opt_pass (pass_data_build_ssa_passes
, ctxt
)
414 /* opt_pass methods: */
415 virtual bool gate (function
*)
417 /* Don't bother doing anything if the program has errors. */
418 return (!seen_error () && !in_lto_p
);
421 virtual unsigned int execute (function
*)
423 return execute_build_ssa_passes ();
426 }; // class pass_build_ssa_passes
428 const pass_data pass_data_chkp_instrumentation_passes
=
430 SIMPLE_IPA_PASS
, /* type */
431 "chkp_passes", /* name */
432 OPTGROUP_NONE
, /* optinfo_flags */
434 0, /* properties_required */
435 0, /* properties_provided */
436 0, /* properties_destroyed */
437 0, /* todo_flags_start */
438 0, /* todo_flags_finish */
441 class pass_chkp_instrumentation_passes
: public simple_ipa_opt_pass
444 pass_chkp_instrumentation_passes (gcc::context
*ctxt
)
445 : simple_ipa_opt_pass (pass_data_chkp_instrumentation_passes
, ctxt
)
448 /* opt_pass methods: */
449 virtual bool gate (function
*)
451 /* Don't bother doing anything if the program has errors. */
452 return (flag_check_pointer_bounds
453 && !seen_error () && !in_lto_p
);
456 }; // class pass_chkp_instrumentation_passes
458 const pass_data pass_data_local_optimization_passes
=
460 SIMPLE_IPA_PASS
, /* type */
461 "opt_local_passes", /* name */
462 OPTGROUP_NONE
, /* optinfo_flags */
464 0, /* properties_required */
465 0, /* properties_provided */
466 0, /* properties_destroyed */
467 0, /* todo_flags_start */
468 0, /* todo_flags_finish */
471 class pass_local_optimization_passes
: public simple_ipa_opt_pass
474 pass_local_optimization_passes (gcc::context
*ctxt
)
475 : simple_ipa_opt_pass (pass_data_local_optimization_passes
, ctxt
)
478 /* opt_pass methods: */
479 virtual bool gate (function
*)
481 /* Don't bother doing anything if the program has errors. */
482 return (!seen_error () && !in_lto_p
);
485 }; // class pass_local_optimization_passes
489 simple_ipa_opt_pass
*
490 make_pass_build_ssa_passes (gcc::context
*ctxt
)
492 return new pass_build_ssa_passes (ctxt
);
495 simple_ipa_opt_pass
*
496 make_pass_chkp_instrumentation_passes (gcc::context
*ctxt
)
498 return new pass_chkp_instrumentation_passes (ctxt
);
501 simple_ipa_opt_pass
*
502 make_pass_local_optimization_passes (gcc::context
*ctxt
)
504 return new pass_local_optimization_passes (ctxt
);
509 const pass_data pass_data_all_early_optimizations
=
511 GIMPLE_PASS
, /* type */
512 "early_optimizations", /* name */
513 OPTGROUP_NONE
, /* optinfo_flags */
515 0, /* properties_required */
516 0, /* properties_provided */
517 0, /* properties_destroyed */
518 0, /* todo_flags_start */
519 0, /* todo_flags_finish */
522 class pass_all_early_optimizations
: public gimple_opt_pass
525 pass_all_early_optimizations (gcc::context
*ctxt
)
526 : gimple_opt_pass (pass_data_all_early_optimizations
, ctxt
)
529 /* opt_pass methods: */
530 virtual bool gate (function
*)
532 return (optimize
>= 1
533 /* Don't bother doing anything if the program has errors. */
537 }; // class pass_all_early_optimizations
541 static gimple_opt_pass
*
542 make_pass_all_early_optimizations (gcc::context
*ctxt
)
544 return new pass_all_early_optimizations (ctxt
);
549 const pass_data pass_data_all_optimizations
=
551 GIMPLE_PASS
, /* type */
552 "*all_optimizations", /* name */
553 OPTGROUP_NONE
, /* optinfo_flags */
554 TV_OPTIMIZE
, /* tv_id */
555 0, /* properties_required */
556 0, /* properties_provided */
557 0, /* properties_destroyed */
558 0, /* todo_flags_start */
559 0, /* todo_flags_finish */
562 class pass_all_optimizations
: public gimple_opt_pass
565 pass_all_optimizations (gcc::context
*ctxt
)
566 : gimple_opt_pass (pass_data_all_optimizations
, ctxt
)
569 /* opt_pass methods: */
570 virtual bool gate (function
*) { return optimize
>= 1 && !optimize_debug
; }
572 }; // class pass_all_optimizations
576 static gimple_opt_pass
*
577 make_pass_all_optimizations (gcc::context
*ctxt
)
579 return new pass_all_optimizations (ctxt
);
584 const pass_data pass_data_all_optimizations_g
=
586 GIMPLE_PASS
, /* type */
587 "*all_optimizations_g", /* name */
588 OPTGROUP_NONE
, /* optinfo_flags */
589 TV_OPTIMIZE
, /* tv_id */
590 0, /* properties_required */
591 0, /* properties_provided */
592 0, /* properties_destroyed */
593 0, /* todo_flags_start */
594 0, /* todo_flags_finish */
597 class pass_all_optimizations_g
: public gimple_opt_pass
600 pass_all_optimizations_g (gcc::context
*ctxt
)
601 : gimple_opt_pass (pass_data_all_optimizations_g
, ctxt
)
604 /* opt_pass methods: */
605 virtual bool gate (function
*) { return optimize
>= 1 && optimize_debug
; }
607 }; // class pass_all_optimizations_g
611 static gimple_opt_pass
*
612 make_pass_all_optimizations_g (gcc::context
*ctxt
)
614 return new pass_all_optimizations_g (ctxt
);
619 const pass_data pass_data_rest_of_compilation
=
622 "*rest_of_compilation", /* name */
623 OPTGROUP_NONE
, /* optinfo_flags */
624 TV_REST_OF_COMPILATION
, /* tv_id */
625 PROP_rtl
, /* properties_required */
626 0, /* properties_provided */
627 0, /* properties_destroyed */
628 0, /* todo_flags_start */
629 0, /* todo_flags_finish */
632 class pass_rest_of_compilation
: public rtl_opt_pass
635 pass_rest_of_compilation (gcc::context
*ctxt
)
636 : rtl_opt_pass (pass_data_rest_of_compilation
, ctxt
)
639 /* opt_pass methods: */
640 virtual bool gate (function
*)
642 /* Early return if there were errors. We can run afoul of our
643 consistency checks, and there's not really much point in fixing them. */
644 return !(rtl_dump_and_exit
|| flag_syntax_only
|| seen_error ());
647 }; // class pass_rest_of_compilation
651 static rtl_opt_pass
*
652 make_pass_rest_of_compilation (gcc::context
*ctxt
)
654 return new pass_rest_of_compilation (ctxt
);
659 const pass_data pass_data_postreload
=
662 "*all-postreload", /* name */
663 OPTGROUP_NONE
, /* optinfo_flags */
664 TV_POSTRELOAD
, /* tv_id */
665 PROP_rtl
, /* properties_required */
666 0, /* properties_provided */
667 0, /* properties_destroyed */
668 0, /* todo_flags_start */
669 0, /* todo_flags_finish */
672 class pass_postreload
: public rtl_opt_pass
675 pass_postreload (gcc::context
*ctxt
)
676 : rtl_opt_pass (pass_data_postreload
, ctxt
)
679 /* opt_pass methods: */
680 virtual bool gate (function
*) { return reload_completed
; }
682 }; // class pass_postreload
686 static rtl_opt_pass
*
687 make_pass_postreload (gcc::context
*ctxt
)
689 return new pass_postreload (ctxt
);
694 const pass_data pass_data_late_compilation
=
697 "*all-late_compilation", /* name */
698 OPTGROUP_NONE
, /* optinfo_flags */
699 TV_LATE_COMPILATION
, /* tv_id */
700 PROP_rtl
, /* properties_required */
701 0, /* properties_provided */
702 0, /* properties_destroyed */
703 0, /* todo_flags_start */
704 0, /* todo_flags_finish */
707 class pass_late_compilation
: public rtl_opt_pass
710 pass_late_compilation (gcc::context
*ctxt
)
711 : rtl_opt_pass (pass_data_late_compilation
, ctxt
)
714 /* opt_pass methods: */
715 virtual bool gate (function
*)
717 return reload_completed
|| targetm
.no_register_allocation
;
720 }; // class pass_late_compilation
724 static rtl_opt_pass
*
725 make_pass_late_compilation (gcc::context
*ctxt
)
727 return new pass_late_compilation (ctxt
);
732 /* Set the static pass number of pass PASS to ID and record that
733 in the mapping from static pass number to pass. */
737 set_pass_for_id (int id
, opt_pass
*pass
)
739 pass
->static_pass_number
= id
;
740 if (passes_by_id_size
<= id
)
742 passes_by_id
= XRESIZEVEC (opt_pass
*, passes_by_id
, id
+ 1);
743 memset (passes_by_id
+ passes_by_id_size
, 0,
744 (id
+ 1 - passes_by_id_size
) * sizeof (void *));
745 passes_by_id_size
= id
+ 1;
747 passes_by_id
[id
] = pass
;
750 /* Return the pass with the static pass number ID. */
753 pass_manager::get_pass_for_id (int id
) const
755 if (id
>= passes_by_id_size
)
757 return passes_by_id
[id
];
760 /* Iterate over the pass tree allocating dump file numbers. We want
761 to do this depth first, and independent of whether the pass is
765 register_one_dump_file (opt_pass
*pass
)
767 g
->get_passes ()->register_one_dump_file (pass
);
771 pass_manager::register_one_dump_file (opt_pass
*pass
)
773 char *dot_name
, *flag_name
, *glob_name
;
774 const char *name
, *full_name
, *prefix
;
776 /* Buffer big enough to format a 32-bit UINT_MAX into. */
779 int optgroup_flags
= OPTGROUP_NONE
;
780 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
782 /* See below in next_pass_1. */
784 if (pass
->static_pass_number
!= -1)
785 sprintf (num
, "%u", ((int) pass
->static_pass_number
< 0
786 ? 1 : pass
->static_pass_number
));
788 /* The name is both used to identify the pass for the purposes of plugins,
789 and to specify dump file name and option.
790 The latter two might want something short which is not quite unique; for
791 that reason, we may have a disambiguating prefix, followed by a space
792 to mark the start of the following dump file name / option string. */
793 name
= strchr (pass
->name
, ' ');
794 name
= name
? name
+ 1 : pass
->name
;
795 dot_name
= concat (".", name
, num
, NULL
);
796 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
800 optgroup_flags
|= OPTGROUP_IPA
;
802 else if (pass
->type
== GIMPLE_PASS
)
813 flag_name
= concat (prefix
, name
, num
, NULL
);
814 glob_name
= concat (prefix
, name
, NULL
);
815 optgroup_flags
|= pass
->optinfo_flags
;
816 /* For any passes that do not have an optgroup set, and which are not
817 IPA passes setup above, set the optgroup to OPTGROUP_OTHER so that
818 any dump messages are emitted properly under -fopt-info(-optall). */
819 if (optgroup_flags
== OPTGROUP_NONE
)
820 optgroup_flags
= OPTGROUP_OTHER
;
821 id
= dumps
->dump_register (dot_name
, flag_name
, glob_name
, flags
,
824 set_pass_for_id (id
, pass
);
825 full_name
= concat (prefix
, pass
->name
, num
, NULL
);
826 register_pass_name (pass
, full_name
);
827 free (CONST_CAST (char *, full_name
));
830 /* Register the dump files for the pass_manager starting at PASS. */
833 pass_manager::register_dump_files (opt_pass
*pass
)
837 if (pass
->name
&& pass
->name
[0] != '*')
838 register_one_dump_file (pass
);
841 register_dump_files (pass
->sub
);
848 /* Register PASS with NAME. */
851 pass_manager::register_pass_name (opt_pass
*pass
, const char *name
)
853 if (!m_name_to_pass_map
)
854 m_name_to_pass_map
= new hash_map
<nofree_string_hash
, opt_pass
*> (256);
856 if (m_name_to_pass_map
->get (name
))
857 return; /* Ignore plugin passes. */
859 const char *unique_name
= xstrdup (name
);
860 m_name_to_pass_map
->put (unique_name
, pass
);
863 /* Map from pass id to canonicalized pass name. */
865 typedef const char *char_ptr
;
866 static vec
<char_ptr
> pass_tab
;
868 /* Callback function for traversing NAME_TO_PASS_MAP. */
871 passes_pass_traverse (const char *const &name
, opt_pass
*const &pass
, void *)
873 gcc_assert (pass
->static_pass_number
> 0);
874 gcc_assert (pass_tab
.exists ());
876 pass_tab
[pass
->static_pass_number
] = name
;
881 /* The function traverses NAME_TO_PASS_MAP and creates a pass info
882 table for dumping purpose. */
885 pass_manager::create_pass_tab (void) const
887 if (!flag_dump_passes
)
890 pass_tab
.safe_grow_cleared (passes_by_id_size
+ 1);
891 m_name_to_pass_map
->traverse
<void *, passes_pass_traverse
> (NULL
);
894 static bool override_gate_status (opt_pass
*, tree
, bool);
896 /* Dump the instantiated name for PASS. IS_ON indicates if PASS
897 is turned on or not. */
900 dump_one_pass (opt_pass
*pass
, int pass_indent
)
902 int indent
= 3 * pass_indent
;
904 bool is_on
, is_really_on
;
906 is_on
= pass
->gate (cfun
);
907 is_really_on
= override_gate_status (pass
, current_function_decl
, is_on
);
909 if (pass
->static_pass_number
<= 0)
912 pn
= pass_tab
[pass
->static_pass_number
];
914 fprintf (stderr
, "%*s%-40s%*s:%s%s\n", indent
, " ", pn
,
915 (15 - indent
< 0 ? 0 : 15 - indent
), " ",
916 is_on
? " ON" : " OFF",
917 ((!is_on
) == (!is_really_on
) ? ""
918 : (is_really_on
? " (FORCED_ON)" : " (FORCED_OFF)")));
921 /* Dump pass list PASS with indentation INDENT. */
924 dump_pass_list (opt_pass
*pass
, int indent
)
928 dump_one_pass (pass
, indent
);
930 dump_pass_list (pass
->sub
, indent
+ 1);
936 /* Dump all optimization passes. */
941 g
->get_passes ()->dump_passes ();
945 pass_manager::dump_passes () const
947 push_dummy_function (true);
951 dump_pass_list (all_lowering_passes
, 1);
952 dump_pass_list (all_small_ipa_passes
, 1);
953 dump_pass_list (all_regular_ipa_passes
, 1);
954 dump_pass_list (all_late_ipa_passes
, 1);
955 dump_pass_list (all_passes
, 1);
957 pop_dummy_function ();
960 /* Returns the pass with NAME. */
963 pass_manager::get_pass_by_name (const char *name
)
965 opt_pass
**p
= m_name_to_pass_map
->get (name
);
973 /* Range [start, last]. */
979 const char *assem_name
;
980 struct uid_range
*next
;
983 typedef struct uid_range
*uid_range_p
;
986 static vec
<uid_range_p
> enabled_pass_uid_range_tab
;
987 static vec
<uid_range_p
> disabled_pass_uid_range_tab
;
990 /* Parse option string for -fdisable- and -fenable-
991 The syntax of the options:
994 -fdisable-<pass_name>
996 -fenable-<pass_name>=s1:e1,s2:e2,...
997 -fdisable-<pass_name>=s1:e1,s2:e2,...
1001 enable_disable_pass (const char *arg
, bool is_enable
)
1004 char *range_str
, *phase_name
;
1005 char *argstr
= xstrdup (arg
);
1006 vec
<uid_range_p
> *tab
= 0;
1008 range_str
= strchr (argstr
,'=');
1015 phase_name
= argstr
;
1019 error ("unrecognized option -fenable");
1021 error ("unrecognized option -fdisable");
1025 pass
= g
->get_passes ()->get_pass_by_name (phase_name
);
1026 if (!pass
|| pass
->static_pass_number
== -1)
1029 error ("unknown pass %s specified in -fenable", phase_name
);
1031 error ("unknown pass %s specified in -fdisable", phase_name
);
1037 tab
= &enabled_pass_uid_range_tab
;
1039 tab
= &disabled_pass_uid_range_tab
;
1041 if ((unsigned) pass
->static_pass_number
>= tab
->length ())
1042 tab
->safe_grow_cleared (pass
->static_pass_number
+ 1);
1047 uid_range_p new_range
= XCNEW (struct uid_range
);
1049 new_range
->start
= 0;
1050 new_range
->last
= (unsigned)-1;
1052 slot
= (*tab
)[pass
->static_pass_number
];
1053 new_range
->next
= slot
;
1054 (*tab
)[pass
->static_pass_number
] = new_range
;
1056 inform (UNKNOWN_LOCATION
, "enable pass %s for functions in the range "
1057 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
1059 inform (UNKNOWN_LOCATION
, "disable pass %s for functions in the range "
1060 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
1064 char *next_range
= NULL
;
1065 char *one_range
= range_str
;
1066 char *end_val
= NULL
;
1071 uid_range_p new_range
;
1072 char *invalid
= NULL
;
1074 char *func_name
= NULL
;
1076 next_range
= strchr (one_range
, ',');
1083 end_val
= strchr (one_range
, ':');
1089 start
= strtol (one_range
, &invalid
, 10);
1090 if (*invalid
|| start
< 0)
1092 if (end_val
|| (one_range
[0] >= '0'
1093 && one_range
[0] <= '9'))
1095 error ("Invalid range %s in option %s",
1097 is_enable
? "-fenable" : "-fdisable");
1101 func_name
= one_range
;
1105 new_range
= XCNEW (struct uid_range
);
1108 new_range
->start
= (unsigned) start
;
1109 new_range
->last
= (unsigned) start
;
1113 new_range
->start
= (unsigned) -1;
1114 new_range
->last
= (unsigned) -1;
1115 new_range
->assem_name
= xstrdup (func_name
);
1120 long last
= strtol (end_val
, &invalid
, 10);
1121 if (*invalid
|| last
< start
)
1123 error ("Invalid range %s in option %s",
1125 is_enable
? "-fenable" : "-fdisable");
1129 new_range
= XCNEW (struct uid_range
);
1130 new_range
->start
= (unsigned) start
;
1131 new_range
->last
= (unsigned) last
;
1134 slot
= (*tab
)[pass
->static_pass_number
];
1135 new_range
->next
= slot
;
1136 (*tab
)[pass
->static_pass_number
] = new_range
;
1139 if (new_range
->assem_name
)
1140 inform (UNKNOWN_LOCATION
,
1141 "enable pass %s for function %s",
1142 phase_name
, new_range
->assem_name
);
1144 inform (UNKNOWN_LOCATION
,
1145 "enable pass %s for functions in the range of [%u, %u]",
1146 phase_name
, new_range
->start
, new_range
->last
);
1150 if (new_range
->assem_name
)
1151 inform (UNKNOWN_LOCATION
,
1152 "disable pass %s for function %s",
1153 phase_name
, new_range
->assem_name
);
1155 inform (UNKNOWN_LOCATION
,
1156 "disable pass %s for functions in the range of [%u, %u]",
1157 phase_name
, new_range
->start
, new_range
->last
);
1160 one_range
= next_range
;
1161 } while (next_range
);
1167 /* Enable pass specified by ARG. */
1170 enable_pass (const char *arg
)
1172 enable_disable_pass (arg
, true);
1175 /* Disable pass specified by ARG. */
1178 disable_pass (const char *arg
)
1180 enable_disable_pass (arg
, false);
1183 /* Returns true if PASS is explicitly enabled/disabled for FUNC. */
1186 is_pass_explicitly_enabled_or_disabled (opt_pass
*pass
,
1188 vec
<uid_range_p
> tab
)
1190 uid_range_p slot
, range
;
1192 const char *aname
= NULL
;
1195 || (unsigned) pass
->static_pass_number
>= tab
.length ()
1196 || pass
->static_pass_number
== -1)
1199 slot
= tab
[pass
->static_pass_number
];
1203 cgraph_uid
= func
? cgraph_node::get (func
)->uid
: 0;
1204 if (func
&& DECL_ASSEMBLER_NAME_SET_P (func
))
1205 aname
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func
));
1210 if ((unsigned) cgraph_uid
>= range
->start
1211 && (unsigned) cgraph_uid
<= range
->last
)
1213 if (range
->assem_name
&& aname
1214 && !strcmp (range
->assem_name
, aname
))
1216 range
= range
->next
;
1223 /* Update static_pass_number for passes (and the flag
1224 TODO_mark_first_instance).
1226 Passes are constructed with static_pass_number preinitialized to 0
1228 This field is used in two different ways: initially as instance numbers
1229 of their kind, and then as ids within the entire pass manager.
1231 Within pass_manager::pass_manager:
1233 * In add_pass_instance(), as called by next_pass_1 in
1234 NEXT_PASS in init_optimization_passes
1236 * When the initial instance of a pass within a pass manager is seen,
1237 it is flagged, and its static_pass_number is set to -1
1239 * On subsequent times that it is seen, the static pass number
1240 is decremented each time, so that if there are e.g. 4 dups,
1241 they have static_pass_number -4, 2, 3, 4 respectively (note
1242 how the initial one is negative and gives the count); these
1243 can be thought of as instance numbers of the specific pass
1245 * Within the register_dump_files () traversal, set_pass_for_id()
1246 is called on each pass, using these instance numbers to create
1247 dumpfile switches, and then overwriting them with a pass id,
1248 which are global to the whole pass manager (based on
1249 (TDI_end + current value of extra_dump_files_in_use) ) */
1252 add_pass_instance (opt_pass
*new_pass
, bool track_duplicates
,
1253 opt_pass
*initial_pass
)
1255 /* Are we dealing with the first pass of its kind, or a clone? */
1256 if (new_pass
!= initial_pass
)
1258 /* We're dealing with a clone. */
1259 new_pass
->todo_flags_start
&= ~TODO_mark_first_instance
;
1261 /* Indicate to register_dump_files that this pass has duplicates,
1262 and so it should rename the dump file. The first instance will
1263 be -1, and be number of duplicates = -static_pass_number - 1.
1264 Subsequent instances will be > 0 and just the duplicate number. */
1265 if ((new_pass
->name
&& new_pass
->name
[0] != '*') || track_duplicates
)
1267 initial_pass
->static_pass_number
-= 1;
1268 new_pass
->static_pass_number
= -initial_pass
->static_pass_number
;
1273 /* We're dealing with the first pass of its kind. */
1274 new_pass
->todo_flags_start
|= TODO_mark_first_instance
;
1275 new_pass
->static_pass_number
= -1;
1277 invoke_plugin_callbacks (PLUGIN_NEW_PASS
, new_pass
);
1281 /* Add a pass to the pass list. Duplicate the pass if it's already
1285 next_pass_1 (opt_pass
**list
, opt_pass
*pass
, opt_pass
*initial_pass
)
1287 /* Every pass should have a name so that plugins can refer to them. */
1288 gcc_assert (pass
->name
!= NULL
);
1290 add_pass_instance (pass
, false, initial_pass
);
1293 return &(*list
)->next
;
1296 /* List node for an inserted pass instance. We need to keep track of all
1297 the newly-added pass instances (with 'added_pass_nodes' defined below)
1298 so that we can register their dump files after pass-positioning is finished.
1299 Registering dumping files needs to be post-processed or the
1300 static_pass_number of the opt_pass object would be modified and mess up
1301 the dump file names of future pass instances to be added. */
1303 struct pass_list_node
1306 struct pass_list_node
*next
;
1309 static struct pass_list_node
*added_pass_nodes
= NULL
;
1310 static struct pass_list_node
*prev_added_pass_node
;
1312 /* Insert the pass at the proper position. Return true if the pass
1313 is successfully added.
1315 NEW_PASS_INFO - new pass to be inserted
1316 PASS_LIST - root of the pass list to insert the new pass to */
1319 position_pass (struct register_pass_info
*new_pass_info
, opt_pass
**pass_list
)
1321 opt_pass
*pass
= *pass_list
, *prev_pass
= NULL
;
1322 bool success
= false;
1324 for ( ; pass
; prev_pass
= pass
, pass
= pass
->next
)
1326 /* Check if the current pass is of the same type as the new pass and
1327 matches the name and the instance number of the reference pass. */
1328 if (pass
->type
== new_pass_info
->pass
->type
1330 && !strcmp (pass
->name
, new_pass_info
->reference_pass_name
)
1331 && ((new_pass_info
->ref_pass_instance_number
== 0)
1332 || (new_pass_info
->ref_pass_instance_number
==
1333 pass
->static_pass_number
)
1334 || (new_pass_info
->ref_pass_instance_number
== 1
1335 && pass
->todo_flags_start
& TODO_mark_first_instance
)))
1338 struct pass_list_node
*new_pass_node
;
1340 if (new_pass_info
->ref_pass_instance_number
== 0)
1342 new_pass
= new_pass_info
->pass
->clone ();
1343 add_pass_instance (new_pass
, true, new_pass_info
->pass
);
1347 new_pass
= new_pass_info
->pass
;
1348 add_pass_instance (new_pass
, true, new_pass
);
1351 /* Insert the new pass instance based on the positioning op. */
1352 switch (new_pass_info
->pos_op
)
1354 case PASS_POS_INSERT_AFTER
:
1355 new_pass
->next
= pass
->next
;
1356 pass
->next
= new_pass
;
1358 /* Skip newly inserted pass to avoid repeated
1359 insertions in the case where the new pass and the
1360 existing one have the same name. */
1363 case PASS_POS_INSERT_BEFORE
:
1364 new_pass
->next
= pass
;
1366 prev_pass
->next
= new_pass
;
1368 *pass_list
= new_pass
;
1370 case PASS_POS_REPLACE
:
1371 new_pass
->next
= pass
->next
;
1373 prev_pass
->next
= new_pass
;
1375 *pass_list
= new_pass
;
1376 new_pass
->sub
= pass
->sub
;
1377 new_pass
->tv_id
= pass
->tv_id
;
1381 error ("invalid pass positioning operation");
1385 /* Save the newly added pass (instance) in the added_pass_nodes
1386 list so that we can register its dump file later. Note that
1387 we cannot register the dump file now because doing so will modify
1388 the static_pass_number of the opt_pass object and therefore
1389 mess up the dump file name of future instances. */
1390 new_pass_node
= XCNEW (struct pass_list_node
);
1391 new_pass_node
->pass
= new_pass
;
1392 if (!added_pass_nodes
)
1393 added_pass_nodes
= new_pass_node
;
1395 prev_added_pass_node
->next
= new_pass_node
;
1396 prev_added_pass_node
= new_pass_node
;
1401 if (pass
->sub
&& position_pass (new_pass_info
, &pass
->sub
))
1408 /* Hooks a new pass into the pass lists.
1410 PASS_INFO - pass information that specifies the opt_pass object,
1411 reference pass, instance number, and how to position
1415 register_pass (struct register_pass_info
*pass_info
)
1417 g
->get_passes ()->register_pass (pass_info
);
1421 register_pass (opt_pass
* pass
, pass_positioning_ops pos
,
1422 const char* ref_pass_name
, int ref_pass_inst_number
)
1424 register_pass_info i
;
1426 i
.reference_pass_name
= ref_pass_name
;
1427 i
.ref_pass_instance_number
= ref_pass_inst_number
;
1430 g
->get_passes ()->register_pass (&i
);
1434 pass_manager::register_pass (struct register_pass_info
*pass_info
)
1436 bool all_instances
, success
;
1437 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
1439 /* The checks below could fail in buggy plugins. Existing GCC
1440 passes should never fail these checks, so we mention plugin in
1442 if (!pass_info
->pass
)
1443 fatal_error (input_location
, "plugin cannot register a missing pass");
1445 if (!pass_info
->pass
->name
)
1446 fatal_error (input_location
, "plugin cannot register an unnamed pass");
1448 if (!pass_info
->reference_pass_name
)
1451 "plugin cannot register pass %qs without reference pass name",
1452 pass_info
->pass
->name
);
1454 /* Try to insert the new pass to the pass lists. We need to check
1455 all five lists as the reference pass could be in one (or all) of
1457 all_instances
= pass_info
->ref_pass_instance_number
== 0;
1458 success
= position_pass (pass_info
, &all_lowering_passes
);
1459 if (!success
|| all_instances
)
1460 success
|= position_pass (pass_info
, &all_small_ipa_passes
);
1461 if (!success
|| all_instances
)
1462 success
|= position_pass (pass_info
, &all_regular_ipa_passes
);
1463 if (!success
|| all_instances
)
1464 success
|= position_pass (pass_info
, &all_late_ipa_passes
);
1465 if (!success
|| all_instances
)
1466 success
|= position_pass (pass_info
, &all_passes
);
1470 "pass %qs not found but is referenced by new pass %qs",
1471 pass_info
->reference_pass_name
, pass_info
->pass
->name
);
1473 /* OK, we have successfully inserted the new pass. We need to register
1474 the dump files for the newly added pass and its duplicates (if any).
1475 Because the registration of plugin/backend passes happens after the
1476 command-line options are parsed, the options that specify single
1477 pass dumping (e.g. -fdump-tree-PASSNAME) cannot be used for new
1478 passes. Therefore we currently can only enable dumping of
1479 new passes when the 'dump-all' flags (e.g. -fdump-tree-all)
1480 are specified. While doing so, we also delete the pass_list_node
1481 objects created during pass positioning. */
1482 while (added_pass_nodes
)
1484 struct pass_list_node
*next_node
= added_pass_nodes
->next
;
1485 enum tree_dump_index tdi
;
1486 register_one_dump_file (added_pass_nodes
->pass
);
1487 if (added_pass_nodes
->pass
->type
== SIMPLE_IPA_PASS
1488 || added_pass_nodes
->pass
->type
== IPA_PASS
)
1490 else if (added_pass_nodes
->pass
->type
== GIMPLE_PASS
)
1494 /* Check if dump-all flag is specified. */
1495 if (dumps
->get_dump_file_info (tdi
)->pstate
)
1497 dumps
->get_dump_file_info (added_pass_nodes
->pass
->static_pass_number
)
1498 ->pstate
= dumps
->get_dump_file_info (tdi
)->pstate
;
1499 dumps
->get_dump_file_info (added_pass_nodes
->pass
->static_pass_number
)
1500 ->pflags
= dumps
->get_dump_file_info (tdi
)->pflags
;
1502 XDELETE (added_pass_nodes
);
1503 added_pass_nodes
= next_node
;
1507 /* Construct the pass tree. The sequencing of passes is driven by
1508 the cgraph routines:
1510 finalize_compilation_unit ()
1511 for each node N in the cgraph
1512 cgraph_analyze_function (N)
1513 cgraph_lower_function (N) -> all_lowering_passes
1515 If we are optimizing, compile is then invoked:
1518 ipa_passes () -> all_small_ipa_passes
1519 -> Analysis of all_regular_ipa_passes
1520 * possible LTO streaming at copmilation time *
1521 -> Execution of all_regular_ipa_passes
1522 * possible LTO streaming at link time *
1523 -> all_late_ipa_passes
1524 expand_all_functions ()
1525 for each node N in the cgraph
1526 expand_function (N) -> Transformation of all_regular_ipa_passes
1531 pass_manager::operator new (size_t sz
)
1533 /* Ensure that all fields of the pass manager are zero-initialized. */
1534 return xcalloc (1, sz
);
1538 pass_manager::operator delete (void *ptr
)
1543 pass_manager::pass_manager (context
*ctxt
)
1544 : all_passes (NULL
), all_small_ipa_passes (NULL
), all_lowering_passes (NULL
),
1545 all_regular_ipa_passes (NULL
),
1546 all_late_ipa_passes (NULL
), passes_by_id (NULL
), passes_by_id_size (0),
1551 /* Initialize the pass_lists array. */
1552 #define DEF_PASS_LIST(LIST) pass_lists[PASS_LIST_NO_##LIST] = &LIST;
1554 #undef DEF_PASS_LIST
1556 /* Build the tree of passes. */
1558 #define INSERT_PASSES_AFTER(PASS) \
1560 opt_pass **p_start; \
1561 p_start = p = &(PASS);
1563 #define TERMINATE_PASS_LIST(PASS) \
1564 gcc_assert (p_start == &PASS); \
1568 #define PUSH_INSERT_PASSES_WITHIN(PASS) \
1570 opt_pass **p = &(PASS ## _1)->sub;
1572 #define POP_INSERT_PASSES() \
1575 #define NEXT_PASS(PASS, NUM) \
1577 gcc_assert (NULL == PASS ## _ ## NUM); \
1579 PASS ## _1 = make_##PASS (m_ctxt); \
1582 gcc_assert (PASS ## _1); \
1583 PASS ## _ ## NUM = PASS ## _1->clone (); \
1585 p = next_pass_1 (p, PASS ## _ ## NUM, PASS ## _1); \
1588 #define NEXT_PASS_WITH_ARG(PASS, NUM, ARG) \
1590 NEXT_PASS (PASS, NUM); \
1591 PASS ## _ ## NUM->set_pass_param (0, ARG); \
1594 #include "pass-instances.def"
1596 #undef INSERT_PASSES_AFTER
1597 #undef PUSH_INSERT_PASSES_WITHIN
1598 #undef POP_INSERT_PASSES
1600 #undef NEXT_PASS_WITH_ARG
1601 #undef TERMINATE_PASS_LIST
1603 /* Register the passes with the tree dump code. */
1604 register_dump_files (all_lowering_passes
);
1605 register_dump_files (all_small_ipa_passes
);
1606 register_dump_files (all_regular_ipa_passes
);
1607 register_dump_files (all_late_ipa_passes
);
1608 register_dump_files (all_passes
);
1612 delete_pass_tree (opt_pass
*pass
)
1616 /* Recurse into child passes. */
1617 delete_pass_tree (pass
->sub
);
1619 opt_pass
*next
= pass
->next
;
1621 /* Delete this pass. */
1624 /* Iterate onto sibling passes. */
1629 pass_manager::~pass_manager ()
1631 XDELETEVEC (passes_by_id
);
1633 /* Call delete_pass_tree on each of the pass_lists. */
1634 #define DEF_PASS_LIST(LIST) \
1635 delete_pass_tree (*pass_lists[PASS_LIST_NO_##LIST]);
1637 #undef DEF_PASS_LIST
1641 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1642 function CALLBACK for every function in the call graph. Otherwise,
1643 call CALLBACK on the current function. */
1646 do_per_function (void (*callback
) (function
*, void *data
), void *data
)
1648 if (current_function_decl
)
1649 callback (cfun
, data
);
1652 struct cgraph_node
*node
;
1653 FOR_EACH_DEFINED_FUNCTION (node
)
1654 if (node
->analyzed
&& (gimple_has_body_p (node
->decl
) && !in_lto_p
)
1655 && (!node
->clone_of
|| node
->decl
!= node
->clone_of
->decl
))
1656 callback (DECL_STRUCT_FUNCTION (node
->decl
), data
);
1660 /* Because inlining might remove no-longer reachable nodes, we need to
1661 keep the array visible to garbage collector to avoid reading collected
1664 static GTY ((length ("nnodes"))) cgraph_node
**order
;
1666 /* Hook called when NODE is removed and therefore should be
1667 excluded from order vector. DATA is an array of integers.
1668 DATA[0] holds max index it may be accessed by. For cgraph
1669 node DATA[node->uid + 1] holds index of this node in order
1672 remove_cgraph_node_from_order (cgraph_node
*node
, void *data
)
1674 int *order_idx
= (int *)data
;
1676 if (node
->uid
>= order_idx
[0])
1679 int idx
= order_idx
[node
->uid
+ 1];
1680 if (idx
>= 0 && idx
< nnodes
&& order
[idx
] == node
)
1684 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1685 function CALLBACK for every function in the call graph. Otherwise,
1686 call CALLBACK on the current function.
1687 This function is global so that plugins can use it. */
1689 do_per_function_toporder (void (*callback
) (function
*, void *data
), void *data
)
1693 if (current_function_decl
)
1694 callback (cfun
, data
);
1697 cgraph_node_hook_list
*hook
;
1699 gcc_assert (!order
);
1700 order
= ggc_vec_alloc
<cgraph_node
*> (symtab
->cgraph_count
);
1702 order_idx
= XALLOCAVEC (int, symtab
->cgraph_max_uid
+ 1);
1703 memset (order_idx
+ 1, -1, sizeof (int) * symtab
->cgraph_max_uid
);
1704 order_idx
[0] = symtab
->cgraph_max_uid
;
1706 nnodes
= ipa_reverse_postorder (order
);
1707 for (i
= nnodes
- 1; i
>= 0; i
--)
1709 order
[i
]->process
= 1;
1710 order_idx
[order
[i
]->uid
+ 1] = i
;
1712 hook
= symtab
->add_cgraph_removal_hook (remove_cgraph_node_from_order
,
1714 for (i
= nnodes
- 1; i
>= 0; i
--)
1716 /* Function could be inlined and removed as unreachable. */
1720 struct cgraph_node
*node
= order
[i
];
1722 /* Allow possibly removed nodes to be garbage collected. */
1725 if (node
->has_gimple_body_p ())
1727 struct function
*fn
= DECL_STRUCT_FUNCTION (node
->decl
);
1729 callback (fn
, data
);
1733 symtab
->remove_cgraph_removal_hook (hook
);
1740 /* Helper function to perform function body dump. */
1743 execute_function_dump (function
*fn
, void *data
)
1745 opt_pass
*pass
= (opt_pass
*)data
;
1751 if (fn
->curr_properties
& PROP_trees
)
1752 dump_function_to_file (fn
->decl
, dump_file
, dump_flags
);
1754 print_rtl_with_bb (dump_file
, get_insns (), dump_flags
);
1756 /* Flush the file. If verification fails, we won't be able to
1757 close the file before aborting. */
1760 if ((fn
->curr_properties
& PROP_cfg
)
1761 && (dump_flags
& TDF_GRAPH
))
1763 gcc::dump_manager
*dumps
= g
->get_dumps ();
1764 struct dump_file_info
*dfi
1765 = dumps
->get_dump_file_info (pass
->static_pass_number
);
1766 if (!dfi
->graph_dump_initialized
)
1768 clean_graph_dump_file (dump_file_name
);
1769 dfi
->graph_dump_initialized
= true;
1771 print_graph_cfg (dump_file_name
, fn
);
1778 static struct profile_record
*profile_record
;
1780 /* Do profile consistency book-keeping for the pass with static number INDEX.
1781 If SUBPASS is zero, we run _before_ the pass, and if SUBPASS is one, then
1782 we run _after_ the pass. RUN is true if the pass really runs, or FALSE
1783 if we are only book-keeping on passes that may have selectively disabled
1784 themselves on a given function. */
1786 check_profile_consistency (int index
, int subpass
, bool run
)
1788 pass_manager
*passes
= g
->get_passes ();
1791 if (!profile_record
)
1792 profile_record
= XCNEWVEC (struct profile_record
,
1793 passes
->passes_by_id_size
);
1794 gcc_assert (index
< passes
->passes_by_id_size
&& index
>= 0);
1795 gcc_assert (subpass
< 2);
1796 profile_record
[index
].run
|= run
;
1797 account_profile_record (&profile_record
[index
], subpass
);
1800 /* Output profile consistency. */
1803 dump_profile_report (void)
1805 g
->get_passes ()->dump_profile_report ();
1809 pass_manager::dump_profile_report () const
1812 int last_freq_in
= 0, last_count_in
= 0, last_freq_out
= 0, last_count_out
= 0;
1813 gcov_type last_time
= 0, last_size
= 0;
1814 double rel_time_change
, rel_size_change
;
1815 int last_reported
= 0;
1817 if (!profile_record
)
1819 fprintf (stderr
, "\nProfile consistency report:\n\n");
1820 fprintf (stderr
, "Pass name |mismatch in |mismated out|Overall\n");
1821 fprintf (stderr
, " |freq count |freq count |size time\n");
1823 for (i
= 0; i
< passes_by_id_size
; i
++)
1824 for (j
= 0 ; j
< 2; j
++)
1825 if (profile_record
[i
].run
)
1828 rel_time_change
= (profile_record
[i
].time
[j
]
1829 - (double)last_time
) * 100 / (double)last_time
;
1831 rel_time_change
= 0;
1833 rel_size_change
= (profile_record
[i
].size
[j
]
1834 - (double)last_size
) * 100 / (double)last_size
;
1836 rel_size_change
= 0;
1838 if (profile_record
[i
].num_mismatched_freq_in
[j
] != last_freq_in
1839 || profile_record
[i
].num_mismatched_freq_out
[j
] != last_freq_out
1840 || profile_record
[i
].num_mismatched_count_in
[j
] != last_count_in
1841 || profile_record
[i
].num_mismatched_count_out
[j
] != last_count_out
1842 || rel_time_change
|| rel_size_change
)
1845 fprintf (stderr
, "%-20s %s",
1846 passes_by_id
[i
]->name
,
1847 j
? "(after TODO)" : " ");
1848 if (profile_record
[i
].num_mismatched_freq_in
[j
] != last_freq_in
)
1849 fprintf (stderr
, "| %+5i",
1850 profile_record
[i
].num_mismatched_freq_in
[j
]
1853 fprintf (stderr
, "| ");
1854 if (profile_record
[i
].num_mismatched_count_in
[j
] != last_count_in
)
1855 fprintf (stderr
, " %+5i",
1856 profile_record
[i
].num_mismatched_count_in
[j
]
1859 fprintf (stderr
, " ");
1860 if (profile_record
[i
].num_mismatched_freq_out
[j
] != last_freq_out
)
1861 fprintf (stderr
, "| %+5i",
1862 profile_record
[i
].num_mismatched_freq_out
[j
]
1865 fprintf (stderr
, "| ");
1866 if (profile_record
[i
].num_mismatched_count_out
[j
] != last_count_out
)
1867 fprintf (stderr
, " %+5i",
1868 profile_record
[i
].num_mismatched_count_out
[j
]
1871 fprintf (stderr
, " ");
1873 /* Size/time units change across gimple and RTL. */
1874 if (i
== pass_expand_1
->static_pass_number
)
1875 fprintf (stderr
, "|----------");
1878 if (rel_size_change
)
1879 fprintf (stderr
, "| %+8.4f%%", rel_size_change
);
1881 fprintf (stderr
, "| ");
1882 if (rel_time_change
)
1883 fprintf (stderr
, " %+8.4f%%", rel_time_change
);
1885 fprintf (stderr
, "\n");
1886 last_freq_in
= profile_record
[i
].num_mismatched_freq_in
[j
];
1887 last_freq_out
= profile_record
[i
].num_mismatched_freq_out
[j
];
1888 last_count_in
= profile_record
[i
].num_mismatched_count_in
[j
];
1889 last_count_out
= profile_record
[i
].num_mismatched_count_out
[j
];
1891 else if (j
&& last_reported
!= i
)
1894 fprintf (stderr
, "%-20s ------------| | |\n",
1895 passes_by_id
[i
]->name
);
1897 last_time
= profile_record
[i
].time
[j
];
1898 last_size
= profile_record
[i
].size
[j
];
1902 /* Perform all TODO actions that ought to be done on each function. */
1905 execute_function_todo (function
*fn
, void *data
)
1907 bool from_ipa_pass
= (cfun
== NULL
);
1908 unsigned int flags
= (size_t)data
;
1909 flags
&= ~fn
->last_verified
;
1915 /* Always cleanup the CFG before trying to update SSA. */
1916 if (flags
& TODO_cleanup_cfg
)
1918 cleanup_tree_cfg ();
1920 /* When cleanup_tree_cfg merges consecutive blocks, it may
1921 perform some simplistic propagation when removing single
1922 valued PHI nodes. This propagation may, in turn, cause the
1923 SSA form to become out-of-date (see PR 22037). So, even
1924 if the parent pass had not scheduled an SSA update, we may
1925 still need to do one. */
1926 if (!(flags
& TODO_update_ssa_any
) && need_ssa_update_p (cfun
))
1927 flags
|= TODO_update_ssa
;
1930 if (flags
& TODO_update_ssa_any
)
1932 unsigned update_flags
= flags
& TODO_update_ssa_any
;
1933 update_ssa (update_flags
);
1936 if (flag_tree_pta
&& (flags
& TODO_rebuild_alias
))
1937 compute_may_aliases ();
1939 if (optimize
&& (flags
& TODO_update_address_taken
))
1940 execute_update_addresses_taken ();
1942 if (flags
& TODO_remove_unused_locals
)
1943 remove_unused_locals ();
1945 if (flags
& TODO_rebuild_frequencies
)
1946 rebuild_frequencies ();
1948 if (flags
& TODO_rebuild_cgraph_edges
)
1949 cgraph_edge::rebuild_edges ();
1951 gcc_assert (dom_info_state (fn
, CDI_POST_DOMINATORS
) == DOM_NONE
);
1952 /* If we've seen errors do not bother running any verifiers. */
1953 if (flag_checking
&& !seen_error ())
1955 dom_state pre_verify_state
= dom_info_state (fn
, CDI_DOMINATORS
);
1956 dom_state pre_verify_pstate
= dom_info_state (fn
, CDI_POST_DOMINATORS
);
1958 if (flags
& TODO_verify_il
)
1960 if (cfun
->curr_properties
& PROP_trees
)
1962 if (cfun
->curr_properties
& PROP_cfg
)
1963 /* IPA passes leave stmts to be fixed up, so make sure to
1964 not verify stmts really throw. */
1965 verify_gimple_in_cfg (cfun
, !from_ipa_pass
);
1967 verify_gimple_in_seq (gimple_body (cfun
->decl
));
1969 if (cfun
->curr_properties
& PROP_ssa
)
1970 /* IPA passes leave stmts to be fixed up, so make sure to
1971 not verify SSA operands whose verifier will choke on that. */
1972 verify_ssa (true, !from_ipa_pass
);
1973 /* IPA passes leave basic-blocks unsplit, so make sure to
1974 not trip on that. */
1975 if ((cfun
->curr_properties
& PROP_cfg
)
1977 verify_flow_info ();
1979 && loops_state_satisfies_p (LOOP_CLOSED_SSA
))
1980 verify_loop_closed_ssa (false);
1981 if (cfun
->curr_properties
& PROP_rtl
)
1982 verify_rtl_sharing ();
1985 /* Make sure verifiers don't change dominator state. */
1986 gcc_assert (dom_info_state (fn
, CDI_DOMINATORS
) == pre_verify_state
);
1987 gcc_assert (dom_info_state (fn
, CDI_POST_DOMINATORS
) == pre_verify_pstate
);
1990 fn
->last_verified
= flags
& TODO_verify_all
;
1994 /* For IPA passes make sure to release dominator info, it can be
1995 computed by non-verifying TODOs. */
1998 free_dominance_info (fn
, CDI_DOMINATORS
);
1999 free_dominance_info (fn
, CDI_POST_DOMINATORS
);
2003 /* Perform all TODO actions. */
2005 execute_todo (unsigned int flags
)
2009 && need_ssa_update_p (cfun
))
2010 gcc_assert (flags
& TODO_update_ssa_any
);
2012 statistics_fini_pass ();
2015 do_per_function (execute_function_todo
, (void *)(size_t) flags
);
2017 /* At this point we should not have any unreachable code in the
2018 CFG, so it is safe to flush the pending freelist for SSA_NAMES. */
2019 if (cfun
&& cfun
->gimple_df
)
2020 flush_ssaname_freelist ();
2022 /* Always remove functions just as before inlining: IPA passes might be
2023 interested to see bodies of extern inline functions that are not inlined
2024 to analyze side effects. The full removal is done just at the end
2025 of IPA pass queue. */
2026 if (flags
& TODO_remove_functions
)
2029 symtab
->remove_unreachable_nodes (dump_file
);
2032 if ((flags
& TODO_dump_symtab
) && dump_file
&& !current_function_decl
)
2035 symtab_node::dump_table (dump_file
);
2036 /* Flush the file. If verification fails, we won't be able to
2037 close the file before aborting. */
2041 /* Now that the dumping has been done, we can get rid of the optional
2043 if (flags
& TODO_df_finish
)
2044 df_finish_pass ((flags
& TODO_df_verify
) != 0);
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. */
2068 verify_curr_properties (function
*fn
, void *data
)
2070 unsigned int props
= (size_t)data
;
2071 gcc_assert ((fn
->curr_properties
& props
) == props
);
2074 /* Release dump file name if set. */
2077 release_dump_file_name (void)
2081 free (CONST_CAST (char *, dump_file_name
));
2082 dump_file_name
= NULL
;
2086 /* Initialize pass dump file. */
2087 /* This is non-static so that the plugins can use it. */
2090 pass_init_dump_file (opt_pass
*pass
)
2092 /* If a dump file name is present, open it if enabled. */
2093 if (pass
->static_pass_number
!= -1)
2095 timevar_push (TV_DUMP
);
2096 gcc::dump_manager
*dumps
= g
->get_dumps ();
2097 bool initializing_dump
=
2098 !dumps
->dump_initialized_p (pass
->static_pass_number
);
2099 release_dump_file_name ();
2100 dump_file_name
= dumps
->get_dump_file_name (pass
->static_pass_number
);
2101 dumps
->dump_start (pass
->static_pass_number
, &dump_flags
);
2102 if (dump_file
&& current_function_decl
&& ! (dump_flags
& TDF_GIMPLE
))
2103 dump_function_header (dump_file
, current_function_decl
, dump_flags
);
2104 if (initializing_dump
2105 && dump_file
&& (dump_flags
& TDF_GRAPH
)
2106 && cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2108 clean_graph_dump_file (dump_file_name
);
2109 struct dump_file_info
*dfi
2110 = dumps
->get_dump_file_info (pass
->static_pass_number
);
2111 dfi
->graph_dump_initialized
= true;
2113 timevar_pop (TV_DUMP
);
2114 return initializing_dump
;
2120 /* Flush PASS dump file. */
2121 /* This is non-static so that plugins can use it. */
2124 pass_fini_dump_file (opt_pass
*pass
)
2126 timevar_push (TV_DUMP
);
2128 /* Flush and close dump file. */
2129 release_dump_file_name ();
2131 g
->get_dumps ()->dump_finish (pass
->static_pass_number
);
2132 timevar_pop (TV_DUMP
);
2135 /* After executing the pass, apply expected changes to the function
2139 update_properties_after_pass (function
*fn
, void *data
)
2141 opt_pass
*pass
= (opt_pass
*) data
;
2142 fn
->curr_properties
= (fn
->curr_properties
| pass
->properties_provided
)
2143 & ~pass
->properties_destroyed
;
2146 /* Execute summary generation for all of the passes in IPA_PASS. */
2149 execute_ipa_summary_passes (ipa_opt_pass_d
*ipa_pass
)
2153 opt_pass
*pass
= ipa_pass
;
2155 /* Execute all of the IPA_PASSes in the list. */
2156 if (ipa_pass
->type
== IPA_PASS
2157 && pass
->gate (cfun
)
2158 && ipa_pass
->generate_summary
)
2160 pass_init_dump_file (pass
);
2162 /* If a timevar is present, start it. */
2164 timevar_push (pass
->tv_id
);
2166 current_pass
= pass
;
2167 ipa_pass
->generate_summary ();
2171 timevar_pop (pass
->tv_id
);
2173 pass_fini_dump_file (pass
);
2175 ipa_pass
= (ipa_opt_pass_d
*)ipa_pass
->next
;
2179 /* Execute IPA_PASS function transform on NODE. */
2182 execute_one_ipa_transform_pass (struct cgraph_node
*node
,
2183 ipa_opt_pass_d
*ipa_pass
)
2185 opt_pass
*pass
= ipa_pass
;
2186 unsigned int todo_after
= 0;
2188 current_pass
= pass
;
2189 if (!ipa_pass
->function_transform
)
2192 /* Note that the folders should only create gimple expressions.
2193 This is a hack until the new folder is ready. */
2194 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
2196 pass_init_dump_file (pass
);
2198 /* If a timevar is present, start it. */
2199 if (pass
->tv_id
!= TV_NONE
)
2200 timevar_push (pass
->tv_id
);
2202 /* Run pre-pass verification. */
2203 execute_todo (ipa_pass
->function_transform_todo_flags_start
);
2206 todo_after
= ipa_pass
->function_transform (node
);
2208 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2209 check_profile_consistency (pass
->static_pass_number
, 0, true);
2211 /* Run post-pass cleanup and verification. */
2212 execute_todo (todo_after
);
2213 verify_interpass_invariants ();
2214 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2215 check_profile_consistency (pass
->static_pass_number
, 1, true);
2218 if (pass
->tv_id
!= TV_NONE
)
2219 timevar_pop (pass
->tv_id
);
2222 do_per_function (execute_function_dump
, pass
);
2223 pass_fini_dump_file (pass
);
2225 current_pass
= NULL
;
2226 redirect_edge_var_map_empty ();
2228 /* Signal this is a suitable GC collection point. */
2229 if (!(todo_after
& TODO_do_not_ggc_collect
))
2233 /* For the current function, execute all ipa transforms. */
2236 execute_all_ipa_transforms (void)
2238 struct cgraph_node
*node
;
2241 node
= cgraph_node::get (current_function_decl
);
2243 if (node
->ipa_transforms_to_apply
.exists ())
2247 for (i
= 0; i
< node
->ipa_transforms_to_apply
.length (); i
++)
2248 execute_one_ipa_transform_pass (node
, node
->ipa_transforms_to_apply
[i
]);
2249 node
->ipa_transforms_to_apply
.release ();
2253 /* Check if PASS is explicitly disabled or enabled and return
2254 the gate status. FUNC is the function to be processed, and
2255 GATE_STATUS is the gate status determined by pass manager by
2259 override_gate_status (opt_pass
*pass
, tree func
, bool gate_status
)
2261 bool explicitly_enabled
= false;
2262 bool explicitly_disabled
= false;
2265 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2266 enabled_pass_uid_range_tab
);
2268 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2269 disabled_pass_uid_range_tab
);
2271 gate_status
= !explicitly_disabled
&& (gate_status
|| explicitly_enabled
);
2276 /* Determine if PASS_NAME matches CRITERION.
2277 Not a pure predicate, since it can update CRITERION, to support
2278 matching the Nth invocation of a pass.
2279 Subroutine of should_skip_pass_p. */
2282 determine_pass_name_match (const char *pass_name
, char *criterion
)
2284 size_t namelen
= strlen (pass_name
);
2285 if (! strncmp (pass_name
, criterion
, namelen
))
2287 /* The following supports starting with the Nth invocation
2288 of a pass (where N does not necessarily is equal to the
2289 dump file suffix). */
2290 if (criterion
[namelen
] == '\0'
2291 || (criterion
[namelen
] == '1'
2292 && criterion
[namelen
+ 1] == '\0'))
2296 if (criterion
[namelen
+ 1] == '\0')
2297 --criterion
[namelen
];
2305 /* For skipping passes until "startwith" pass.
2306 Return true iff PASS should be skipped.
2307 Clear cfun->pass_startwith when encountering the "startwith" pass,
2308 so that all subsequent passes are run. */
2311 should_skip_pass_p (opt_pass
*pass
)
2315 if (!cfun
->pass_startwith
)
2318 /* We can't skip the lowering phase yet -- ideally we'd
2319 drive that phase fully via properties. */
2320 if (!(cfun
->curr_properties
& PROP_ssa
))
2323 if (determine_pass_name_match (pass
->name
, cfun
->pass_startwith
))
2325 cfun
->pass_startwith
= NULL
;
2329 /* And also run any property provider. */
2330 if (pass
->properties_provided
!= 0)
2333 /* If we get here, then we have a "startwith" that we haven't seen yet;
2341 execute_one_pass (opt_pass
*pass
)
2343 unsigned int todo_after
= 0;
2347 /* IPA passes are executed on whole program, so cfun should be NULL.
2348 Other passes need function context set. */
2349 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
2350 gcc_assert (!cfun
&& !current_function_decl
);
2352 gcc_assert (cfun
&& current_function_decl
);
2354 current_pass
= pass
;
2356 /* Check whether gate check should be avoided.
2357 User controls the value of the gate through the parameter "gate_status". */
2358 gate_status
= pass
->gate (cfun
);
2359 gate_status
= override_gate_status (pass
, current_function_decl
, gate_status
);
2361 /* Override gate with plugin. */
2362 invoke_plugin_callbacks (PLUGIN_OVERRIDE_GATE
, &gate_status
);
2366 /* Run so passes selectively disabling themselves on a given function
2367 are not miscounted. */
2368 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2370 check_profile_consistency (pass
->static_pass_number
, 0, false);
2371 check_profile_consistency (pass
->static_pass_number
, 1, false);
2373 current_pass
= NULL
;
2377 if (should_skip_pass_p (pass
))
2380 /* Pass execution event trigger: useful to identify passes being
2382 invoke_plugin_callbacks (PLUGIN_PASS_EXECUTION
, pass
);
2384 if (!quiet_flag
&& !cfun
)
2385 fprintf (stderr
, " <%s>", pass
->name
? pass
->name
: "");
2387 /* Note that the folders should only create gimple expressions.
2388 This is a hack until the new folder is ready. */
2389 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
2391 pass_init_dump_file (pass
);
2393 /* If a timevar is present, start it. */
2394 if (pass
->tv_id
!= TV_NONE
)
2395 timevar_push (pass
->tv_id
);
2397 /* Run pre-pass verification. */
2398 execute_todo (pass
->todo_flags_start
);
2401 do_per_function (verify_curr_properties
,
2402 (void *)(size_t)pass
->properties_required
);
2405 todo_after
= pass
->execute (cfun
);
2407 if (todo_after
& TODO_discard_function
)
2410 if (pass
->tv_id
!= TV_NONE
)
2411 timevar_pop (pass
->tv_id
);
2413 pass_fini_dump_file (pass
);
2416 /* As cgraph_node::release_body expects release dominators info,
2417 we have to release it. */
2418 if (dom_info_available_p (CDI_DOMINATORS
))
2419 free_dominance_info (CDI_DOMINATORS
);
2421 if (dom_info_available_p (CDI_POST_DOMINATORS
))
2422 free_dominance_info (CDI_POST_DOMINATORS
);
2424 tree fn
= cfun
->decl
;
2427 cgraph_node::get (fn
)->release_body ();
2429 current_pass
= NULL
;
2430 redirect_edge_var_map_empty ();
2437 do_per_function (clear_last_verified
, NULL
);
2439 do_per_function (update_properties_after_pass
, pass
);
2441 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2442 check_profile_consistency (pass
->static_pass_number
, 0, true);
2444 /* Run post-pass cleanup and verification. */
2445 execute_todo (todo_after
| pass
->todo_flags_finish
| TODO_verify_il
);
2446 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2447 check_profile_consistency (pass
->static_pass_number
, 1, true);
2449 verify_interpass_invariants ();
2452 if (pass
->tv_id
!= TV_NONE
)
2453 timevar_pop (pass
->tv_id
);
2455 if (pass
->type
== IPA_PASS
2456 && ((ipa_opt_pass_d
*)pass
)->function_transform
)
2458 struct cgraph_node
*node
;
2459 FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node
)
2460 node
->ipa_transforms_to_apply
.safe_push ((ipa_opt_pass_d
*)pass
);
2463 do_per_function (execute_function_dump
, pass
);
2465 if (!current_function_decl
)
2466 symtab
->process_new_functions ();
2468 pass_fini_dump_file (pass
);
2470 if (pass
->type
!= SIMPLE_IPA_PASS
&& pass
->type
!= IPA_PASS
)
2471 gcc_assert (!(cfun
->curr_properties
& PROP_trees
)
2472 || pass
->type
!= RTL_PASS
);
2474 current_pass
= NULL
;
2475 redirect_edge_var_map_empty ();
2477 /* Signal this is a suitable GC collection point. */
2478 if (!((todo_after
| pass
->todo_flags_finish
) & TODO_do_not_ggc_collect
))
2485 execute_pass_list_1 (opt_pass
*pass
)
2489 gcc_assert (pass
->type
== GIMPLE_PASS
2490 || pass
->type
== RTL_PASS
);
2494 if (execute_one_pass (pass
) && pass
->sub
)
2495 execute_pass_list_1 (pass
->sub
);
2502 execute_pass_list (function
*fn
, opt_pass
*pass
)
2504 gcc_assert (fn
== cfun
);
2505 execute_pass_list_1 (pass
);
2506 if (cfun
&& fn
->cfg
)
2508 free_dominance_info (CDI_DOMINATORS
);
2509 free_dominance_info (CDI_POST_DOMINATORS
);
2513 /* Write out all LTO data. */
2517 timevar_push (TV_IPA_LTO_GIMPLE_OUT
);
2519 timevar_pop (TV_IPA_LTO_GIMPLE_OUT
);
2520 timevar_push (TV_IPA_LTO_DECL_OUT
);
2521 produce_asm_for_decls ();
2522 timevar_pop (TV_IPA_LTO_DECL_OUT
);
2525 /* Same as execute_pass_list but assume that subpasses of IPA passes
2526 are local passes. If SET is not NULL, write out summaries of only
2527 those node in SET. */
2530 ipa_write_summaries_2 (opt_pass
*pass
, struct lto_out_decl_state
*state
)
2534 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*)pass
;
2535 gcc_assert (!current_function_decl
);
2537 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2538 if (pass
->type
== IPA_PASS
2539 && ipa_pass
->write_summary
2540 && pass
->gate (cfun
))
2542 /* If a timevar is present, start it. */
2544 timevar_push (pass
->tv_id
);
2546 pass_init_dump_file (pass
);
2548 current_pass
= pass
;
2549 ipa_pass
->write_summary ();
2551 pass_fini_dump_file (pass
);
2553 /* If a timevar is present, start it. */
2555 timevar_pop (pass
->tv_id
);
2558 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2559 ipa_write_summaries_2 (pass
->sub
, state
);
2565 /* Helper function of ipa_write_summaries. Creates and destroys the
2566 decl state and calls ipa_write_summaries_2 for all passes that have
2567 summaries. SET is the set of nodes to be written. */
2570 ipa_write_summaries_1 (lto_symtab_encoder_t encoder
)
2572 pass_manager
*passes
= g
->get_passes ();
2573 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2574 state
->symtab_node_encoder
= encoder
;
2576 lto_output_init_mode_table ();
2577 lto_push_out_decl_state (state
);
2579 gcc_assert (!flag_wpa
);
2580 ipa_write_summaries_2 (passes
->all_regular_ipa_passes
, state
);
2584 gcc_assert (lto_get_out_decl_state () == state
);
2585 lto_pop_out_decl_state ();
2586 lto_delete_out_decl_state (state
);
2589 /* Write out summaries for all the nodes in the callgraph. */
2592 ipa_write_summaries (void)
2594 lto_symtab_encoder_t encoder
;
2596 varpool_node
*vnode
;
2597 struct cgraph_node
*node
;
2598 struct cgraph_node
**order
;
2600 if ((!flag_generate_lto
&& !flag_generate_offload
) || seen_error ())
2603 select_what_to_stream ();
2605 encoder
= lto_symtab_encoder_new (false);
2607 /* Create the callgraph set in the same order used in
2608 cgraph_expand_all_functions. This mostly facilitates debugging,
2609 since it causes the gimple file to be processed in the same order
2610 as the source code. */
2611 order
= XCNEWVEC (struct cgraph_node
*, symtab
->cgraph_count
);
2612 order_pos
= ipa_reverse_postorder (order
);
2613 gcc_assert (order_pos
== symtab
->cgraph_count
);
2615 for (i
= order_pos
- 1; i
>= 0; i
--)
2617 struct cgraph_node
*node
= order
[i
];
2619 if (node
->has_gimple_body_p ())
2621 /* When streaming out references to statements as part of some IPA
2622 pass summary, the statements need to have uids assigned and the
2623 following does that for all the IPA passes here. Naturally, this
2624 ordering then matches the one IPA-passes get in their stmt_fixup
2627 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
2628 renumber_gimple_stmt_uids ();
2631 if (node
->definition
&& node
->need_lto_streaming
)
2632 lto_set_symtab_encoder_in_partition (encoder
, node
);
2635 FOR_EACH_DEFINED_FUNCTION (node
)
2636 if (node
->alias
&& node
->need_lto_streaming
)
2637 lto_set_symtab_encoder_in_partition (encoder
, node
);
2638 FOR_EACH_DEFINED_VARIABLE (vnode
)
2639 if (vnode
->need_lto_streaming
)
2640 lto_set_symtab_encoder_in_partition (encoder
, vnode
);
2642 ipa_write_summaries_1 (compute_ltrans_boundary (encoder
));
2647 /* Same as execute_pass_list but assume that subpasses of IPA passes
2648 are local passes. If SET is not NULL, write out optimization summaries of
2649 only those node in SET. */
2652 ipa_write_optimization_summaries_1 (opt_pass
*pass
,
2653 struct lto_out_decl_state
*state
)
2657 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*)pass
;
2658 gcc_assert (!current_function_decl
);
2660 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2661 if (pass
->type
== IPA_PASS
2662 && ipa_pass
->write_optimization_summary
2663 && pass
->gate (cfun
))
2665 /* If a timevar is present, start it. */
2667 timevar_push (pass
->tv_id
);
2669 pass_init_dump_file (pass
);
2671 current_pass
= pass
;
2672 ipa_pass
->write_optimization_summary ();
2674 pass_fini_dump_file (pass
);
2676 /* If a timevar is present, start it. */
2678 timevar_pop (pass
->tv_id
);
2681 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2682 ipa_write_optimization_summaries_1 (pass
->sub
, state
);
2688 /* Write all the optimization summaries for the cgraph nodes in SET. If SET is
2689 NULL, write out all summaries of all nodes. */
2692 ipa_write_optimization_summaries (lto_symtab_encoder_t encoder
)
2694 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2695 lto_symtab_encoder_iterator lsei
;
2696 state
->symtab_node_encoder
= encoder
;
2698 lto_output_init_mode_table ();
2699 lto_push_out_decl_state (state
);
2700 for (lsei
= lsei_start_function_in_partition (encoder
);
2701 !lsei_end_p (lsei
); lsei_next_function_in_partition (&lsei
))
2703 struct cgraph_node
*node
= lsei_cgraph_node (lsei
);
2704 /* When streaming out references to statements as part of some IPA
2705 pass summary, the statements need to have uids assigned.
2707 For functions newly born at WPA stage we need to initialize
2709 if (node
->definition
2710 && gimple_has_body_p (node
->decl
))
2712 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
2713 renumber_gimple_stmt_uids ();
2718 gcc_assert (flag_wpa
);
2719 pass_manager
*passes
= g
->get_passes ();
2720 ipa_write_optimization_summaries_1 (passes
->all_regular_ipa_passes
, state
);
2724 gcc_assert (lto_get_out_decl_state () == state
);
2725 lto_pop_out_decl_state ();
2726 lto_delete_out_decl_state (state
);
2729 /* Same as execute_pass_list but assume that subpasses of IPA passes
2730 are local passes. */
2733 ipa_read_summaries_1 (opt_pass
*pass
)
2737 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
2739 gcc_assert (!current_function_decl
);
2741 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2743 if (pass
->gate (cfun
))
2745 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_summary
)
2747 /* If a timevar is present, start it. */
2749 timevar_push (pass
->tv_id
);
2751 pass_init_dump_file (pass
);
2753 current_pass
= pass
;
2754 ipa_pass
->read_summary ();
2756 pass_fini_dump_file (pass
);
2760 timevar_pop (pass
->tv_id
);
2763 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2764 ipa_read_summaries_1 (pass
->sub
);
2771 /* Read all the summaries for all_regular_ipa_passes. */
2774 ipa_read_summaries (void)
2776 pass_manager
*passes
= g
->get_passes ();
2777 ipa_read_summaries_1 (passes
->all_regular_ipa_passes
);
2780 /* Same as execute_pass_list but assume that subpasses of IPA passes
2781 are local passes. */
2784 ipa_read_optimization_summaries_1 (opt_pass
*pass
)
2788 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
2790 gcc_assert (!current_function_decl
);
2792 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2794 if (pass
->gate (cfun
))
2796 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_optimization_summary
)
2798 /* If a timevar is present, start it. */
2800 timevar_push (pass
->tv_id
);
2802 pass_init_dump_file (pass
);
2804 current_pass
= pass
;
2805 ipa_pass
->read_optimization_summary ();
2807 pass_fini_dump_file (pass
);
2811 timevar_pop (pass
->tv_id
);
2814 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2815 ipa_read_optimization_summaries_1 (pass
->sub
);
2821 /* Read all the summaries for all_regular_ipa_passes. */
2824 ipa_read_optimization_summaries (void)
2826 pass_manager
*passes
= g
->get_passes ();
2827 ipa_read_optimization_summaries_1 (passes
->all_regular_ipa_passes
);
2830 /* Same as execute_pass_list but assume that subpasses of IPA passes
2831 are local passes. */
2833 execute_ipa_pass_list (opt_pass
*pass
)
2837 gcc_assert (!current_function_decl
);
2839 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2840 if (execute_one_pass (pass
) && pass
->sub
)
2842 if (pass
->sub
->type
== GIMPLE_PASS
)
2844 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_START
, NULL
);
2845 do_per_function_toporder ((void (*)(function
*, void *))
2848 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_END
, NULL
);
2850 else if (pass
->sub
->type
== SIMPLE_IPA_PASS
2851 || pass
->sub
->type
== IPA_PASS
)
2852 execute_ipa_pass_list (pass
->sub
);
2856 gcc_assert (!current_function_decl
);
2857 symtab
->process_new_functions ();
2863 /* Execute stmt fixup hooks of all passes in PASS for NODE and STMTS. */
2866 execute_ipa_stmt_fixups (opt_pass
*pass
,
2867 struct cgraph_node
*node
, gimple
**stmts
)
2871 /* Execute all of the IPA_PASSes in the list. */
2872 if (pass
->type
== IPA_PASS
2873 && pass
->gate (cfun
))
2875 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
2877 if (ipa_pass
->stmt_fixup
)
2879 pass_init_dump_file (pass
);
2880 /* If a timevar is present, start it. */
2882 timevar_push (pass
->tv_id
);
2884 current_pass
= pass
;
2885 ipa_pass
->stmt_fixup (node
, stmts
);
2889 timevar_pop (pass
->tv_id
);
2890 pass_fini_dump_file (pass
);
2893 execute_ipa_stmt_fixups (pass
->sub
, node
, stmts
);
2899 /* Execute stmt fixup hooks of all IPA passes for NODE and STMTS. */
2902 execute_all_ipa_stmt_fixups (struct cgraph_node
*node
, gimple
**stmts
)
2904 pass_manager
*passes
= g
->get_passes ();
2905 execute_ipa_stmt_fixups (passes
->all_regular_ipa_passes
, node
, stmts
);
2909 extern void debug_properties (unsigned int);
2910 extern void dump_properties (FILE *, unsigned int);
2913 dump_properties (FILE *dump
, unsigned int props
)
2915 fprintf (dump
, "Properties:\n");
2916 if (props
& PROP_gimple_any
)
2917 fprintf (dump
, "PROP_gimple_any\n");
2918 if (props
& PROP_gimple_lcf
)
2919 fprintf (dump
, "PROP_gimple_lcf\n");
2920 if (props
& PROP_gimple_leh
)
2921 fprintf (dump
, "PROP_gimple_leh\n");
2922 if (props
& PROP_cfg
)
2923 fprintf (dump
, "PROP_cfg\n");
2924 if (props
& PROP_ssa
)
2925 fprintf (dump
, "PROP_ssa\n");
2926 if (props
& PROP_no_crit_edges
)
2927 fprintf (dump
, "PROP_no_crit_edges\n");
2928 if (props
& PROP_rtl
)
2929 fprintf (dump
, "PROP_rtl\n");
2930 if (props
& PROP_gimple_lomp
)
2931 fprintf (dump
, "PROP_gimple_lomp\n");
2932 if (props
& PROP_gimple_lcx
)
2933 fprintf (dump
, "PROP_gimple_lcx\n");
2934 if (props
& PROP_gimple_lvec
)
2935 fprintf (dump
, "PROP_gimple_lvec\n");
2936 if (props
& PROP_cfglayout
)
2937 fprintf (dump
, "PROP_cfglayout\n");
2941 debug_properties (unsigned int props
)
2943 dump_properties (stderr
, props
);
2946 /* Called by local passes to see if function is called by already processed nodes.
2947 Because we process nodes in topological order, this means that function is
2948 in recursive cycle or we introduced new direct calls. */
2950 function_called_by_processed_nodes_p (void)
2952 struct cgraph_edge
*e
;
2953 for (e
= cgraph_node::get (current_function_decl
)->callers
;
2957 if (e
->caller
->decl
== current_function_decl
)
2959 if (!e
->caller
->has_gimple_body_p ())
2961 if (TREE_ASM_WRITTEN (e
->caller
->decl
))
2963 if (!e
->caller
->process
&& !e
->caller
->global
.inlined_to
)
2968 fprintf (dump_file
, "Already processed call to:\n");
2969 e
->caller
->dump (dump_file
);
2974 #include "gt-passes.h"