1 /* Top level of GCC compilers (cc1, cc1plus, etc.)
2 Copyright (C) 1987-2015 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 /* This is the top level of cc1/c++.
21 It parses command args, opens files, invokes the various passes
22 in the proper order, and counts the time used by each.
23 Error messages and low-level interface to malloc also handled here. */
27 #include "coretypes.h"
38 #include "insn-config.h"
44 #include "lto-streamer.h"
45 #include "diagnostic-core.h"
47 #include "fold-const.h"
50 #include "insn-attr.h"
51 #include "insn-flags.h"
65 #include "langhooks.h"
67 #include "hosthooks.h"
69 #include "value-prof.h"
70 #include "tree-inline.h"
71 #include "internal-fn.h"
73 #include "tree-ssa-loop-manip.h"
74 #include "tree-into-ssa.h"
77 #include "tree-pass.h"
78 #include "tree-dump.h"
80 #include "ipa-utils.h"
81 #include "tree-pretty-print.h" /* for dump_function_header */
83 #include "pass_manager.h"
85 #include "tree-ssa-live.h" /* For remove_unused_locals. */
86 #include "tree-cfgcleanup.h"
90 /* This is used for debugging. It allows the current pass to printed
91 from anywhere in compilation.
92 The variable current_pass is also used for statistics and plugins. */
93 opt_pass
*current_pass
;
95 static void register_pass_name (opt_pass
*, const char *);
97 /* Most passes are single-instance (within their context) and thus don't
98 need to implement cloning, but passes that support multiple instances
99 *must* provide their own implementation of the clone method.
101 Handle this by providing a default implemenation, but make it a fatal
107 internal_error ("pass %s does not support cloning", name
);
111 opt_pass::gate (function
*)
117 opt_pass::execute (function
*)
122 opt_pass::opt_pass (const pass_data
&data
, context
*ctxt
)
126 static_pass_number (0),
133 pass_manager::execute_early_local_passes ()
135 execute_pass_list (cfun
, pass_build_ssa_passes_1
->sub
);
136 if (flag_check_pointer_bounds
)
137 execute_pass_list (cfun
, pass_chkp_instrumentation_passes_1
->sub
);
138 execute_pass_list (cfun
, pass_local_optimization_passes_1
->sub
);
142 pass_manager::execute_pass_mode_switching ()
144 return pass_mode_switching_1
->execute (cfun
);
148 /* Call from anywhere to find out what pass this is. Useful for
149 printing out debugging information deep inside an service
152 print_current_pass (FILE *file
)
155 fprintf (file
, "current pass = %s (%d)\n",
156 current_pass
->name
, current_pass
->static_pass_number
);
158 fprintf (file
, "no current pass.\n");
162 /* Call from the debugger to get the current pass name. */
166 print_current_pass (stderr
);
171 /* Global variables used to communicate with passes. */
173 bool first_pass_instance
;
176 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
179 This does nothing for local (non-static) variables, unless the
180 variable is a register variable with DECL_ASSEMBLER_NAME set. In
181 that case, or if the variable is not an automatic, it sets up the
182 RTL and outputs any assembler code (label definition, storage
183 allocation and initialization).
185 DECL is the declaration. TOP_LEVEL is nonzero
186 if this declaration is not within a function. */
189 rest_of_decl_compilation (tree decl
,
193 bool finalize
= true;
195 /* We deferred calling assemble_alias so that we could collect
196 other attributes such as visibility. Emit the alias now. */
200 alias
= lookup_attribute ("alias", DECL_ATTRIBUTES (decl
));
203 alias
= TREE_VALUE (TREE_VALUE (alias
));
204 alias
= get_identifier (TREE_STRING_POINTER (alias
));
205 /* A quirk of the initial implementation of aliases required that the
206 user add "extern" to all of them. Which is silly, but now
207 historical. Do note that the symbol is in fact locally defined. */
208 DECL_EXTERNAL (decl
) = 0;
209 TREE_STATIC (decl
) = 1;
210 assemble_alias (decl
, alias
);
215 /* Can't defer this, because it needs to happen before any
216 later function definitions are processed. */
217 if (DECL_ASSEMBLER_NAME_SET_P (decl
) && DECL_REGISTER (decl
))
218 make_decl_rtl (decl
);
220 /* Forward declarations for nested functions are not "external",
221 but we need to treat them as if they were. */
222 if (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)
223 || TREE_CODE (decl
) == FUNCTION_DECL
)
225 timevar_push (TV_VARCONST
);
227 /* Don't output anything when a tentative file-scope definition
228 is seen. But at end of compilation, do output code for them.
230 We do output all variables and rely on
231 callgraph code to defer them except for forward declarations
232 (see gcc.c-torture/compile/920624-1.c) */
234 || !DECL_DEFER_OUTPUT (decl
)
235 || DECL_INITIAL (decl
))
236 && (TREE_CODE (decl
) != VAR_DECL
|| !DECL_HAS_VALUE_EXPR_P (decl
))
237 && !DECL_EXTERNAL (decl
))
239 /* When reading LTO unit, we also read varpool, so do not
241 if (in_lto_p
&& !at_end
)
243 else if (finalize
&& TREE_CODE (decl
) != FUNCTION_DECL
)
244 varpool_node::finalize_decl (decl
);
247 #ifdef ASM_FINISH_DECLARE_OBJECT
248 if (decl
== last_assemble_variable_decl
)
250 ASM_FINISH_DECLARE_OBJECT (asm_out_file
, decl
,
255 /* Now that we have activated any function-specific attributes
256 that might affect function decl, particularly align, relayout it. */
257 if (TREE_CODE (decl
) == FUNCTION_DECL
)
258 targetm
.target_option
.relayout_function (decl
);
260 timevar_pop (TV_VARCONST
);
262 else if (TREE_CODE (decl
) == TYPE_DECL
263 /* Like in rest_of_type_compilation, avoid confusing the debug
264 information machinery when there are errors. */
267 timevar_push (TV_SYMOUT
);
268 debug_hooks
->type_decl (decl
, !top_level
);
269 timevar_pop (TV_SYMOUT
);
272 /* Let cgraph know about the existence of variables. */
273 if (in_lto_p
&& !at_end
)
275 else if (TREE_CODE (decl
) == VAR_DECL
&& !DECL_EXTERNAL (decl
)
276 && TREE_STATIC (decl
))
277 varpool_node::get_create (decl
);
279 /* Generate early debug for global variables. Any local variables will
280 be handled by either handling reachable functions from
281 finalize_compilation_unit (and by consequence, locally scoped
282 symbols), or by rest_of_type_compilation below.
284 Also, pick up function prototypes, which will be mostly ignored
285 by the different early_global_decl() hooks, but will at least be
286 used by Go's hijack of the debug_hooks to implement
289 && (TREE_CODE (decl
) != FUNCTION_DECL
290 /* This will pick up function prototypes with no bodies,
291 which are not visible in finalize_compilation_unit()
292 while iterating with FOR_EACH_*_FUNCTION through the
294 || !DECL_SAVED_TREE (decl
))
296 /* We need to check both decl_function_context and
297 current_function_decl here to make sure local extern
298 declarations end up with the correct context.
300 For local extern declarations, decl_function_context is
301 empty, but current_function_decl is set to the function where
302 the extern was declared . Without the check for
303 !current_function_decl below, the local extern ends up
304 incorrectly with a top-level context.
316 extern int i; // Local extern declaration.
323 && !decl_function_context (decl
)
324 && !current_function_decl
325 && DECL_SOURCE_LOCATION (decl
) != BUILTINS_LOCATION
326 && (!decl_type_context (decl
)
327 /* If we created a varpool node for the decl make sure to
328 call early_global_decl. Otherwise we miss changes
329 introduced by member definitions like
330 struct A { static int staticdatamember; };
331 int A::staticdatamember;
332 and thus have incomplete early debug and late debug
333 called from varpool node removal fails to handle it
336 && TREE_CODE (decl
) == VAR_DECL
337 && TREE_STATIC (decl
) && !DECL_EXTERNAL (decl
)))
338 /* Avoid confusing the debug information machinery when there are
341 (*debug_hooks
->early_global_decl
) (decl
);
344 /* Called after finishing a record, union or enumeral type. */
347 rest_of_type_compilation (tree type
, int toplev
)
349 /* Avoid confusing the debug information machinery when there are
354 timevar_push (TV_SYMOUT
);
355 debug_hooks
->type_decl (TYPE_STUB_DECL (type
), !toplev
);
356 timevar_pop (TV_SYMOUT
);
363 finish_optimization_passes (void)
366 struct dump_file_info
*dfi
;
368 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
370 timevar_push (TV_DUMP
);
371 if (profile_arc_flag
|| flag_test_coverage
|| flag_branch_probabilities
)
373 dumps
->dump_start (pass_profile_1
->static_pass_number
, NULL
);
375 dumps
->dump_finish (pass_profile_1
->static_pass_number
);
380 dumps
->dump_start (pass_profile_1
->static_pass_number
, NULL
);
381 print_combine_total_stats ();
382 dumps
->dump_finish (pass_profile_1
->static_pass_number
);
385 /* Do whatever is necessary to finish printing the graphs. */
386 for (i
= TDI_end
; (dfi
= dumps
->get_dump_file_info (i
)) != NULL
; ++i
)
387 if (dumps
->dump_initialized_p (i
)
388 && (dfi
->pflags
& TDF_GRAPH
) != 0
389 && (name
= dumps
->get_dump_file_name (i
)) != NULL
)
391 finish_graph_dump_file (name
);
395 timevar_pop (TV_DUMP
);
399 execute_build_ssa_passes (void)
401 /* Once this pass (and its sub-passes) are complete, all functions
402 will be in SSA form. Technically this state change is happening
403 a tad early, since the sub-passes have not yet run, but since
404 none of the sub-passes are IPA passes and do not create new
405 functions, this is ok. We're setting this value for the benefit
406 of IPA passes that follow. */
407 if (symtab
->state
< IPA_SSA
)
408 symtab
->state
= IPA_SSA
;
414 const pass_data pass_data_build_ssa_passes
=
416 SIMPLE_IPA_PASS
, /* type */
417 "build_ssa_passes", /* name */
418 OPTGROUP_NONE
, /* optinfo_flags */
419 TV_EARLY_LOCAL
, /* tv_id */
420 0, /* properties_required */
421 0, /* properties_provided */
422 0, /* properties_destroyed */
423 0, /* todo_flags_start */
424 /* todo_flags_finish is executed before subpases. For this reason
425 it makes no sense to remove unreachable functions here. */
426 0, /* todo_flags_finish */
429 class pass_build_ssa_passes
: public simple_ipa_opt_pass
432 pass_build_ssa_passes (gcc::context
*ctxt
)
433 : simple_ipa_opt_pass (pass_data_build_ssa_passes
, ctxt
)
436 /* opt_pass methods: */
437 virtual bool gate (function
*)
439 /* Don't bother doing anything if the program has errors. */
440 return (!seen_error () && !in_lto_p
);
443 virtual unsigned int execute (function
*)
445 return execute_build_ssa_passes ();
448 }; // class pass_build_ssa_passes
450 const pass_data pass_data_chkp_instrumentation_passes
=
452 SIMPLE_IPA_PASS
, /* type */
453 "chkp_passes", /* name */
454 OPTGROUP_NONE
, /* optinfo_flags */
456 0, /* properties_required */
457 0, /* properties_provided */
458 0, /* properties_destroyed */
459 0, /* todo_flags_start */
460 0, /* todo_flags_finish */
463 class pass_chkp_instrumentation_passes
: public simple_ipa_opt_pass
466 pass_chkp_instrumentation_passes (gcc::context
*ctxt
)
467 : simple_ipa_opt_pass (pass_data_chkp_instrumentation_passes
, ctxt
)
470 /* opt_pass methods: */
471 virtual bool gate (function
*)
473 /* Don't bother doing anything if the program has errors. */
474 return (flag_check_pointer_bounds
475 && !seen_error () && !in_lto_p
);
478 }; // class pass_chkp_instrumentation_passes
480 const pass_data pass_data_local_optimization_passes
=
482 SIMPLE_IPA_PASS
, /* type */
483 "opt_local_passes", /* name */
484 OPTGROUP_NONE
, /* optinfo_flags */
486 0, /* properties_required */
487 0, /* properties_provided */
488 0, /* properties_destroyed */
489 0, /* todo_flags_start */
490 0, /* todo_flags_finish */
493 class pass_local_optimization_passes
: public simple_ipa_opt_pass
496 pass_local_optimization_passes (gcc::context
*ctxt
)
497 : simple_ipa_opt_pass (pass_data_local_optimization_passes
, ctxt
)
500 /* opt_pass methods: */
501 virtual bool gate (function
*)
503 /* Don't bother doing anything if the program has errors. */
504 return (!seen_error () && !in_lto_p
);
507 }; // class pass_local_optimization_passes
511 simple_ipa_opt_pass
*
512 make_pass_build_ssa_passes (gcc::context
*ctxt
)
514 return new pass_build_ssa_passes (ctxt
);
517 simple_ipa_opt_pass
*
518 make_pass_chkp_instrumentation_passes (gcc::context
*ctxt
)
520 return new pass_chkp_instrumentation_passes (ctxt
);
523 simple_ipa_opt_pass
*
524 make_pass_local_optimization_passes (gcc::context
*ctxt
)
526 return new pass_local_optimization_passes (ctxt
);
531 const pass_data pass_data_all_early_optimizations
=
533 GIMPLE_PASS
, /* type */
534 "early_optimizations", /* name */
535 OPTGROUP_NONE
, /* optinfo_flags */
537 0, /* properties_required */
538 0, /* properties_provided */
539 0, /* properties_destroyed */
540 0, /* todo_flags_start */
541 0, /* todo_flags_finish */
544 class pass_all_early_optimizations
: public gimple_opt_pass
547 pass_all_early_optimizations (gcc::context
*ctxt
)
548 : gimple_opt_pass (pass_data_all_early_optimizations
, ctxt
)
551 /* opt_pass methods: */
552 virtual bool gate (function
*)
554 return (optimize
>= 1
555 /* Don't bother doing anything if the program has errors. */
559 }; // class pass_all_early_optimizations
563 static gimple_opt_pass
*
564 make_pass_all_early_optimizations (gcc::context
*ctxt
)
566 return new pass_all_early_optimizations (ctxt
);
571 const pass_data pass_data_all_optimizations
=
573 GIMPLE_PASS
, /* type */
574 "*all_optimizations", /* name */
575 OPTGROUP_NONE
, /* optinfo_flags */
576 TV_OPTIMIZE
, /* tv_id */
577 0, /* properties_required */
578 0, /* properties_provided */
579 0, /* properties_destroyed */
580 0, /* todo_flags_start */
581 0, /* todo_flags_finish */
584 class pass_all_optimizations
: public gimple_opt_pass
587 pass_all_optimizations (gcc::context
*ctxt
)
588 : gimple_opt_pass (pass_data_all_optimizations
, ctxt
)
591 /* opt_pass methods: */
592 virtual bool gate (function
*) { return optimize
>= 1 && !optimize_debug
; }
594 }; // class pass_all_optimizations
598 static gimple_opt_pass
*
599 make_pass_all_optimizations (gcc::context
*ctxt
)
601 return new pass_all_optimizations (ctxt
);
606 const pass_data pass_data_all_optimizations_g
=
608 GIMPLE_PASS
, /* type */
609 "*all_optimizations_g", /* name */
610 OPTGROUP_NONE
, /* optinfo_flags */
611 TV_OPTIMIZE
, /* tv_id */
612 0, /* properties_required */
613 0, /* properties_provided */
614 0, /* properties_destroyed */
615 0, /* todo_flags_start */
616 0, /* todo_flags_finish */
619 class pass_all_optimizations_g
: public gimple_opt_pass
622 pass_all_optimizations_g (gcc::context
*ctxt
)
623 : gimple_opt_pass (pass_data_all_optimizations_g
, ctxt
)
626 /* opt_pass methods: */
627 virtual bool gate (function
*) { return optimize
>= 1 && optimize_debug
; }
629 }; // class pass_all_optimizations_g
633 static gimple_opt_pass
*
634 make_pass_all_optimizations_g (gcc::context
*ctxt
)
636 return new pass_all_optimizations_g (ctxt
);
641 const pass_data pass_data_rest_of_compilation
=
644 "*rest_of_compilation", /* name */
645 OPTGROUP_NONE
, /* optinfo_flags */
646 TV_REST_OF_COMPILATION
, /* tv_id */
647 PROP_rtl
, /* properties_required */
648 0, /* properties_provided */
649 0, /* properties_destroyed */
650 0, /* todo_flags_start */
651 0, /* todo_flags_finish */
654 class pass_rest_of_compilation
: public rtl_opt_pass
657 pass_rest_of_compilation (gcc::context
*ctxt
)
658 : rtl_opt_pass (pass_data_rest_of_compilation
, ctxt
)
661 /* opt_pass methods: */
662 virtual bool gate (function
*)
664 /* Early return if there were errors. We can run afoul of our
665 consistency checks, and there's not really much point in fixing them. */
666 return !(rtl_dump_and_exit
|| flag_syntax_only
|| seen_error ());
669 }; // class pass_rest_of_compilation
673 static rtl_opt_pass
*
674 make_pass_rest_of_compilation (gcc::context
*ctxt
)
676 return new pass_rest_of_compilation (ctxt
);
681 const pass_data pass_data_postreload
=
684 "*all-postreload", /* name */
685 OPTGROUP_NONE
, /* optinfo_flags */
686 TV_POSTRELOAD
, /* tv_id */
687 PROP_rtl
, /* properties_required */
688 0, /* properties_provided */
689 0, /* properties_destroyed */
690 0, /* todo_flags_start */
691 0, /* todo_flags_finish */
694 class pass_postreload
: public rtl_opt_pass
697 pass_postreload (gcc::context
*ctxt
)
698 : rtl_opt_pass (pass_data_postreload
, ctxt
)
701 /* opt_pass methods: */
702 virtual bool gate (function
*) { return reload_completed
; }
704 }; // class pass_postreload
708 static rtl_opt_pass
*
709 make_pass_postreload (gcc::context
*ctxt
)
711 return new pass_postreload (ctxt
);
716 const pass_data pass_data_late_compilation
=
719 "*all-late_compilation", /* name */
720 OPTGROUP_NONE
, /* optinfo_flags */
721 TV_LATE_COMPILATION
, /* tv_id */
722 PROP_rtl
, /* properties_required */
723 0, /* properties_provided */
724 0, /* properties_destroyed */
725 0, /* todo_flags_start */
726 0, /* todo_flags_finish */
729 class pass_late_compilation
: public rtl_opt_pass
732 pass_late_compilation (gcc::context
*ctxt
)
733 : rtl_opt_pass (pass_data_late_compilation
, ctxt
)
736 /* opt_pass methods: */
737 virtual bool gate (function
*)
739 return reload_completed
|| targetm
.no_register_allocation
;
742 }; // class pass_late_compilation
746 static rtl_opt_pass
*
747 make_pass_late_compilation (gcc::context
*ctxt
)
749 return new pass_late_compilation (ctxt
);
754 /* Set the static pass number of pass PASS to ID and record that
755 in the mapping from static pass number to pass. */
759 set_pass_for_id (int id
, opt_pass
*pass
)
761 pass
->static_pass_number
= id
;
762 if (passes_by_id_size
<= id
)
764 passes_by_id
= XRESIZEVEC (opt_pass
*, passes_by_id
, id
+ 1);
765 memset (passes_by_id
+ passes_by_id_size
, 0,
766 (id
+ 1 - passes_by_id_size
) * sizeof (void *));
767 passes_by_id_size
= id
+ 1;
769 passes_by_id
[id
] = pass
;
772 /* Return the pass with the static pass number ID. */
775 pass_manager::get_pass_for_id (int id
) const
777 if (id
>= passes_by_id_size
)
779 return passes_by_id
[id
];
782 /* Iterate over the pass tree allocating dump file numbers. We want
783 to do this depth first, and independent of whether the pass is
787 register_one_dump_file (opt_pass
*pass
)
789 g
->get_passes ()->register_one_dump_file (pass
);
793 pass_manager::register_one_dump_file (opt_pass
*pass
)
795 char *dot_name
, *flag_name
, *glob_name
;
796 const char *name
, *full_name
, *prefix
;
799 int optgroup_flags
= OPTGROUP_NONE
;
800 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
802 /* See below in next_pass_1. */
804 if (pass
->static_pass_number
!= -1)
805 sprintf (num
, "%d", ((int) pass
->static_pass_number
< 0
806 ? 1 : pass
->static_pass_number
));
808 /* The name is both used to identify the pass for the purposes of plugins,
809 and to specify dump file name and option.
810 The latter two might want something short which is not quite unique; for
811 that reason, we may have a disambiguating prefix, followed by a space
812 to mark the start of the following dump file name / option string. */
813 name
= strchr (pass
->name
, ' ');
814 name
= name
? name
+ 1 : pass
->name
;
815 dot_name
= concat (".", name
, num
, NULL
);
816 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
820 optgroup_flags
|= OPTGROUP_IPA
;
822 else if (pass
->type
== GIMPLE_PASS
)
833 flag_name
= concat (prefix
, name
, num
, NULL
);
834 glob_name
= concat (prefix
, name
, NULL
);
835 optgroup_flags
|= pass
->optinfo_flags
;
836 /* For any passes that do not have an optgroup set, and which are not
837 IPA passes setup above, set the optgroup to OPTGROUP_OTHER so that
838 any dump messages are emitted properly under -fopt-info(-optall). */
839 if (optgroup_flags
== OPTGROUP_NONE
)
840 optgroup_flags
= OPTGROUP_OTHER
;
841 id
= dumps
->dump_register (dot_name
, flag_name
, glob_name
, flags
,
844 set_pass_for_id (id
, pass
);
845 full_name
= concat (prefix
, pass
->name
, num
, NULL
);
846 register_pass_name (pass
, full_name
);
847 free (CONST_CAST (char *, full_name
));
850 /* Register the dump files for the pass_manager starting at PASS. */
853 pass_manager::register_dump_files (opt_pass
*pass
)
857 if (pass
->name
&& pass
->name
[0] != '*')
858 register_one_dump_file (pass
);
861 register_dump_files (pass
->sub
);
868 static hash_map
<nofree_string_hash
, opt_pass
*> *name_to_pass_map
;
870 /* Register PASS with NAME. */
873 register_pass_name (opt_pass
*pass
, const char *name
)
875 if (!name_to_pass_map
)
876 name_to_pass_map
= new hash_map
<nofree_string_hash
, opt_pass
*> (256);
878 if (name_to_pass_map
->get (name
))
879 return; /* Ignore plugin passes. */
881 const char *unique_name
= xstrdup (name
);
882 name_to_pass_map
->put (unique_name
, pass
);
885 /* Map from pass id to canonicalized pass name. */
887 typedef const char *char_ptr
;
888 static vec
<char_ptr
> pass_tab
= vNULL
;
890 /* Callback function for traversing NAME_TO_PASS_MAP. */
893 passes_pass_traverse (const char *const &name
, opt_pass
*const &pass
, void *)
895 gcc_assert (pass
->static_pass_number
> 0);
896 gcc_assert (pass_tab
.exists ());
898 pass_tab
[pass
->static_pass_number
] = name
;
903 /* The function traverses NAME_TO_PASS_MAP and creates a pass info
904 table for dumping purpose. */
907 create_pass_tab (void)
909 if (!flag_dump_passes
)
912 pass_tab
.safe_grow_cleared (g
->get_passes ()->passes_by_id_size
+ 1);
913 name_to_pass_map
->traverse
<void *, passes_pass_traverse
> (NULL
);
916 static bool override_gate_status (opt_pass
*, tree
, bool);
918 /* Dump the instantiated name for PASS. IS_ON indicates if PASS
919 is turned on or not. */
922 dump_one_pass (opt_pass
*pass
, int pass_indent
)
924 int indent
= 3 * pass_indent
;
926 bool is_on
, is_really_on
;
928 is_on
= pass
->gate (cfun
);
929 is_really_on
= override_gate_status (pass
, current_function_decl
, is_on
);
931 if (pass
->static_pass_number
<= 0)
934 pn
= pass_tab
[pass
->static_pass_number
];
936 fprintf (stderr
, "%*s%-40s%*s:%s%s\n", indent
, " ", pn
,
937 (15 - indent
< 0 ? 0 : 15 - indent
), " ",
938 is_on
? " ON" : " OFF",
939 ((!is_on
) == (!is_really_on
) ? ""
940 : (is_really_on
? " (FORCED_ON)" : " (FORCED_OFF)")));
943 /* Dump pass list PASS with indentation INDENT. */
946 dump_pass_list (opt_pass
*pass
, int indent
)
950 dump_one_pass (pass
, indent
);
952 dump_pass_list (pass
->sub
, indent
+ 1);
958 /* Dump all optimization passes. */
963 g
->get_passes ()->dump_passes ();
967 pass_manager::dump_passes () const
969 push_dummy_function (true);
973 dump_pass_list (all_lowering_passes
, 1);
974 dump_pass_list (all_small_ipa_passes
, 1);
975 dump_pass_list (all_regular_ipa_passes
, 1);
976 dump_pass_list (all_late_ipa_passes
, 1);
977 dump_pass_list (all_passes
, 1);
979 pop_dummy_function ();
982 /* Returns the pass with NAME. */
985 get_pass_by_name (const char *name
)
987 opt_pass
**p
= name_to_pass_map
->get (name
);
995 /* Range [start, last]. */
1001 const char *assem_name
;
1002 struct uid_range
*next
;
1005 typedef struct uid_range
*uid_range_p
;
1008 static vec
<uid_range_p
>
1009 enabled_pass_uid_range_tab
= vNULL
;
1010 static vec
<uid_range_p
>
1011 disabled_pass_uid_range_tab
= vNULL
;
1014 /* Parse option string for -fdisable- and -fenable-
1015 The syntax of the options:
1017 -fenable-<pass_name>
1018 -fdisable-<pass_name>
1020 -fenable-<pass_name>=s1:e1,s2:e2,...
1021 -fdisable-<pass_name>=s1:e1,s2:e2,...
1025 enable_disable_pass (const char *arg
, bool is_enable
)
1028 char *range_str
, *phase_name
;
1029 char *argstr
= xstrdup (arg
);
1030 vec
<uid_range_p
> *tab
= 0;
1032 range_str
= strchr (argstr
,'=');
1039 phase_name
= argstr
;
1043 error ("unrecognized option -fenable");
1045 error ("unrecognized option -fdisable");
1049 pass
= get_pass_by_name (phase_name
);
1050 if (!pass
|| pass
->static_pass_number
== -1)
1053 error ("unknown pass %s specified in -fenable", phase_name
);
1055 error ("unknown pass %s specified in -fdisable", phase_name
);
1061 tab
= &enabled_pass_uid_range_tab
;
1063 tab
= &disabled_pass_uid_range_tab
;
1065 if ((unsigned) pass
->static_pass_number
>= tab
->length ())
1066 tab
->safe_grow_cleared (pass
->static_pass_number
+ 1);
1071 uid_range_p new_range
= XCNEW (struct uid_range
);
1073 new_range
->start
= 0;
1074 new_range
->last
= (unsigned)-1;
1076 slot
= (*tab
)[pass
->static_pass_number
];
1077 new_range
->next
= slot
;
1078 (*tab
)[pass
->static_pass_number
] = new_range
;
1080 inform (UNKNOWN_LOCATION
, "enable pass %s for functions in the range "
1081 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
1083 inform (UNKNOWN_LOCATION
, "disable pass %s for functions in the range "
1084 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
1088 char *next_range
= NULL
;
1089 char *one_range
= range_str
;
1090 char *end_val
= NULL
;
1095 uid_range_p new_range
;
1096 char *invalid
= NULL
;
1098 char *func_name
= NULL
;
1100 next_range
= strchr (one_range
, ',');
1107 end_val
= strchr (one_range
, ':');
1113 start
= strtol (one_range
, &invalid
, 10);
1114 if (*invalid
|| start
< 0)
1116 if (end_val
|| (one_range
[0] >= '0'
1117 && one_range
[0] <= '9'))
1119 error ("Invalid range %s in option %s",
1121 is_enable
? "-fenable" : "-fdisable");
1125 func_name
= one_range
;
1129 new_range
= XCNEW (struct uid_range
);
1132 new_range
->start
= (unsigned) start
;
1133 new_range
->last
= (unsigned) start
;
1137 new_range
->start
= (unsigned) -1;
1138 new_range
->last
= (unsigned) -1;
1139 new_range
->assem_name
= xstrdup (func_name
);
1144 long last
= strtol (end_val
, &invalid
, 10);
1145 if (*invalid
|| last
< start
)
1147 error ("Invalid range %s in option %s",
1149 is_enable
? "-fenable" : "-fdisable");
1153 new_range
= XCNEW (struct uid_range
);
1154 new_range
->start
= (unsigned) start
;
1155 new_range
->last
= (unsigned) last
;
1158 slot
= (*tab
)[pass
->static_pass_number
];
1159 new_range
->next
= slot
;
1160 (*tab
)[pass
->static_pass_number
] = new_range
;
1163 if (new_range
->assem_name
)
1164 inform (UNKNOWN_LOCATION
,
1165 "enable pass %s for function %s",
1166 phase_name
, new_range
->assem_name
);
1168 inform (UNKNOWN_LOCATION
,
1169 "enable pass %s for functions in the range of [%u, %u]",
1170 phase_name
, new_range
->start
, new_range
->last
);
1174 if (new_range
->assem_name
)
1175 inform (UNKNOWN_LOCATION
,
1176 "disable pass %s for function %s",
1177 phase_name
, new_range
->assem_name
);
1179 inform (UNKNOWN_LOCATION
,
1180 "disable pass %s for functions in the range of [%u, %u]",
1181 phase_name
, new_range
->start
, new_range
->last
);
1184 one_range
= next_range
;
1185 } while (next_range
);
1191 /* Enable pass specified by ARG. */
1194 enable_pass (const char *arg
)
1196 enable_disable_pass (arg
, true);
1199 /* Disable pass specified by ARG. */
1202 disable_pass (const char *arg
)
1204 enable_disable_pass (arg
, false);
1207 /* Returns true if PASS is explicitly enabled/disabled for FUNC. */
1210 is_pass_explicitly_enabled_or_disabled (opt_pass
*pass
,
1212 vec
<uid_range_p
> tab
)
1214 uid_range_p slot
, range
;
1216 const char *aname
= NULL
;
1219 || (unsigned) pass
->static_pass_number
>= tab
.length ()
1220 || pass
->static_pass_number
== -1)
1223 slot
= tab
[pass
->static_pass_number
];
1227 cgraph_uid
= func
? cgraph_node::get (func
)->uid
: 0;
1228 if (func
&& DECL_ASSEMBLER_NAME_SET_P (func
))
1229 aname
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func
));
1234 if ((unsigned) cgraph_uid
>= range
->start
1235 && (unsigned) cgraph_uid
<= range
->last
)
1237 if (range
->assem_name
&& aname
1238 && !strcmp (range
->assem_name
, aname
))
1240 range
= range
->next
;
1247 /* Update static_pass_number for passes (and the flag
1248 TODO_mark_first_instance).
1250 Passes are constructed with static_pass_number preinitialized to 0
1252 This field is used in two different ways: initially as instance numbers
1253 of their kind, and then as ids within the entire pass manager.
1255 Within pass_manager::pass_manager:
1257 * In add_pass_instance(), as called by next_pass_1 in
1258 NEXT_PASS in init_optimization_passes
1260 * When the initial instance of a pass within a pass manager is seen,
1261 it is flagged, and its static_pass_number is set to -1
1263 * On subsequent times that it is seen, the static pass number
1264 is decremented each time, so that if there are e.g. 4 dups,
1265 they have static_pass_number -4, 2, 3, 4 respectively (note
1266 how the initial one is negative and gives the count); these
1267 can be thought of as instance numbers of the specific pass
1269 * Within the register_dump_files () traversal, set_pass_for_id()
1270 is called on each pass, using these instance numbers to create
1271 dumpfile switches, and then overwriting them with a pass id,
1272 which are global to the whole pass manager (based on
1273 (TDI_end + current value of extra_dump_files_in_use) ) */
1276 add_pass_instance (opt_pass
*new_pass
, bool track_duplicates
,
1277 opt_pass
*initial_pass
)
1279 /* Are we dealing with the first pass of its kind, or a clone? */
1280 if (new_pass
!= initial_pass
)
1282 /* We're dealing with a clone. */
1283 new_pass
->todo_flags_start
&= ~TODO_mark_first_instance
;
1285 /* Indicate to register_dump_files that this pass has duplicates,
1286 and so it should rename the dump file. The first instance will
1287 be -1, and be number of duplicates = -static_pass_number - 1.
1288 Subsequent instances will be > 0 and just the duplicate number. */
1289 if ((new_pass
->name
&& new_pass
->name
[0] != '*') || track_duplicates
)
1291 initial_pass
->static_pass_number
-= 1;
1292 new_pass
->static_pass_number
= -initial_pass
->static_pass_number
;
1297 /* We're dealing with the first pass of its kind. */
1298 new_pass
->todo_flags_start
|= TODO_mark_first_instance
;
1299 new_pass
->static_pass_number
= -1;
1301 invoke_plugin_callbacks (PLUGIN_NEW_PASS
, new_pass
);
1305 /* Add a pass to the pass list. Duplicate the pass if it's already
1309 next_pass_1 (opt_pass
**list
, opt_pass
*pass
, opt_pass
*initial_pass
)
1311 /* Every pass should have a name so that plugins can refer to them. */
1312 gcc_assert (pass
->name
!= NULL
);
1314 add_pass_instance (pass
, false, initial_pass
);
1317 return &(*list
)->next
;
1320 /* List node for an inserted pass instance. We need to keep track of all
1321 the newly-added pass instances (with 'added_pass_nodes' defined below)
1322 so that we can register their dump files after pass-positioning is finished.
1323 Registering dumping files needs to be post-processed or the
1324 static_pass_number of the opt_pass object would be modified and mess up
1325 the dump file names of future pass instances to be added. */
1327 struct pass_list_node
1330 struct pass_list_node
*next
;
1333 static struct pass_list_node
*added_pass_nodes
= NULL
;
1334 static struct pass_list_node
*prev_added_pass_node
;
1336 /* Insert the pass at the proper position. Return true if the pass
1337 is successfully added.
1339 NEW_PASS_INFO - new pass to be inserted
1340 PASS_LIST - root of the pass list to insert the new pass to */
1343 position_pass (struct register_pass_info
*new_pass_info
, opt_pass
**pass_list
)
1345 opt_pass
*pass
= *pass_list
, *prev_pass
= NULL
;
1346 bool success
= false;
1348 for ( ; pass
; prev_pass
= pass
, pass
= pass
->next
)
1350 /* Check if the current pass is of the same type as the new pass and
1351 matches the name and the instance number of the reference pass. */
1352 if (pass
->type
== new_pass_info
->pass
->type
1354 && !strcmp (pass
->name
, new_pass_info
->reference_pass_name
)
1355 && ((new_pass_info
->ref_pass_instance_number
== 0)
1356 || (new_pass_info
->ref_pass_instance_number
==
1357 pass
->static_pass_number
)
1358 || (new_pass_info
->ref_pass_instance_number
== 1
1359 && pass
->todo_flags_start
& TODO_mark_first_instance
)))
1362 struct pass_list_node
*new_pass_node
;
1364 if (new_pass_info
->ref_pass_instance_number
== 0)
1366 new_pass
= new_pass_info
->pass
->clone ();
1367 add_pass_instance (new_pass
, true, new_pass_info
->pass
);
1371 new_pass
= new_pass_info
->pass
;
1372 add_pass_instance (new_pass
, true, new_pass
);
1375 /* Insert the new pass instance based on the positioning op. */
1376 switch (new_pass_info
->pos_op
)
1378 case PASS_POS_INSERT_AFTER
:
1379 new_pass
->next
= pass
->next
;
1380 pass
->next
= new_pass
;
1382 /* Skip newly inserted pass to avoid repeated
1383 insertions in the case where the new pass and the
1384 existing one have the same name. */
1387 case PASS_POS_INSERT_BEFORE
:
1388 new_pass
->next
= pass
;
1390 prev_pass
->next
= new_pass
;
1392 *pass_list
= new_pass
;
1394 case PASS_POS_REPLACE
:
1395 new_pass
->next
= pass
->next
;
1397 prev_pass
->next
= new_pass
;
1399 *pass_list
= new_pass
;
1400 new_pass
->sub
= pass
->sub
;
1401 new_pass
->tv_id
= pass
->tv_id
;
1405 error ("invalid pass positioning operation");
1409 /* Save the newly added pass (instance) in the added_pass_nodes
1410 list so that we can register its dump file later. Note that
1411 we cannot register the dump file now because doing so will modify
1412 the static_pass_number of the opt_pass object and therefore
1413 mess up the dump file name of future instances. */
1414 new_pass_node
= XCNEW (struct pass_list_node
);
1415 new_pass_node
->pass
= new_pass
;
1416 if (!added_pass_nodes
)
1417 added_pass_nodes
= new_pass_node
;
1419 prev_added_pass_node
->next
= new_pass_node
;
1420 prev_added_pass_node
= new_pass_node
;
1425 if (pass
->sub
&& position_pass (new_pass_info
, &pass
->sub
))
1432 /* Hooks a new pass into the pass lists.
1434 PASS_INFO - pass information that specifies the opt_pass object,
1435 reference pass, instance number, and how to position
1439 register_pass (struct register_pass_info
*pass_info
)
1441 g
->get_passes ()->register_pass (pass_info
);
1445 register_pass (opt_pass
* pass
, pass_positioning_ops pos
,
1446 const char* ref_pass_name
, int ref_pass_inst_number
)
1448 register_pass_info i
;
1450 i
.reference_pass_name
= ref_pass_name
;
1451 i
.ref_pass_instance_number
= ref_pass_inst_number
;
1454 g
->get_passes ()->register_pass (&i
);
1458 pass_manager::register_pass (struct register_pass_info
*pass_info
)
1460 bool all_instances
, success
;
1461 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
1463 /* The checks below could fail in buggy plugins. Existing GCC
1464 passes should never fail these checks, so we mention plugin in
1466 if (!pass_info
->pass
)
1467 fatal_error (input_location
, "plugin cannot register a missing pass");
1469 if (!pass_info
->pass
->name
)
1470 fatal_error (input_location
, "plugin cannot register an unnamed pass");
1472 if (!pass_info
->reference_pass_name
)
1475 "plugin cannot register pass %qs without reference pass name",
1476 pass_info
->pass
->name
);
1478 /* Try to insert the new pass to the pass lists. We need to check
1479 all five lists as the reference pass could be in one (or all) of
1481 all_instances
= pass_info
->ref_pass_instance_number
== 0;
1482 success
= position_pass (pass_info
, &all_lowering_passes
);
1483 if (!success
|| all_instances
)
1484 success
|= position_pass (pass_info
, &all_small_ipa_passes
);
1485 if (!success
|| all_instances
)
1486 success
|= position_pass (pass_info
, &all_regular_ipa_passes
);
1487 if (!success
|| all_instances
)
1488 success
|= position_pass (pass_info
, &all_late_ipa_passes
);
1489 if (!success
|| all_instances
)
1490 success
|= position_pass (pass_info
, &all_passes
);
1494 "pass %qs not found but is referenced by new pass %qs",
1495 pass_info
->reference_pass_name
, pass_info
->pass
->name
);
1497 /* OK, we have successfully inserted the new pass. We need to register
1498 the dump files for the newly added pass and its duplicates (if any).
1499 Because the registration of plugin/backend passes happens after the
1500 command-line options are parsed, the options that specify single
1501 pass dumping (e.g. -fdump-tree-PASSNAME) cannot be used for new
1502 passes. Therefore we currently can only enable dumping of
1503 new passes when the 'dump-all' flags (e.g. -fdump-tree-all)
1504 are specified. While doing so, we also delete the pass_list_node
1505 objects created during pass positioning. */
1506 while (added_pass_nodes
)
1508 struct pass_list_node
*next_node
= added_pass_nodes
->next
;
1509 enum tree_dump_index tdi
;
1510 register_one_dump_file (added_pass_nodes
->pass
);
1511 if (added_pass_nodes
->pass
->type
== SIMPLE_IPA_PASS
1512 || added_pass_nodes
->pass
->type
== IPA_PASS
)
1514 else if (added_pass_nodes
->pass
->type
== GIMPLE_PASS
)
1518 /* Check if dump-all flag is specified. */
1519 if (dumps
->get_dump_file_info (tdi
)->pstate
)
1520 dumps
->get_dump_file_info (added_pass_nodes
->pass
->static_pass_number
)
1521 ->pstate
= dumps
->get_dump_file_info (tdi
)->pstate
;
1522 XDELETE (added_pass_nodes
);
1523 added_pass_nodes
= next_node
;
1527 /* Construct the pass tree. The sequencing of passes is driven by
1528 the cgraph routines:
1530 finalize_compilation_unit ()
1531 for each node N in the cgraph
1532 cgraph_analyze_function (N)
1533 cgraph_lower_function (N) -> all_lowering_passes
1535 If we are optimizing, compile is then invoked:
1538 ipa_passes () -> all_small_ipa_passes
1539 -> Analysis of all_regular_ipa_passes
1540 * possible LTO streaming at copmilation time *
1541 -> Execution of all_regular_ipa_passes
1542 * possible LTO streaming at link time *
1543 -> all_late_ipa_passes
1544 expand_all_functions ()
1545 for each node N in the cgraph
1546 expand_function (N) -> Transformation of all_regular_ipa_passes
1551 pass_manager::operator new (size_t sz
)
1553 /* Ensure that all fields of the pass manager are zero-initialized. */
1554 return xcalloc (1, sz
);
1558 pass_manager::operator delete (void *ptr
)
1563 pass_manager::pass_manager (context
*ctxt
)
1564 : all_passes (NULL
), all_small_ipa_passes (NULL
), all_lowering_passes (NULL
),
1565 all_regular_ipa_passes (NULL
),
1566 all_late_ipa_passes (NULL
), passes_by_id (NULL
), passes_by_id_size (0),
1571 /* Initialize the pass_lists array. */
1572 #define DEF_PASS_LIST(LIST) pass_lists[PASS_LIST_NO_##LIST] = &LIST;
1574 #undef DEF_PASS_LIST
1576 /* Build the tree of passes. */
1578 #define INSERT_PASSES_AFTER(PASS) \
1581 #define PUSH_INSERT_PASSES_WITHIN(PASS) \
1583 opt_pass **p = &(PASS ## _1)->sub;
1585 #define POP_INSERT_PASSES() \
1588 #define NEXT_PASS(PASS, NUM) \
1590 gcc_assert (NULL == PASS ## _ ## NUM); \
1592 PASS ## _1 = make_##PASS (m_ctxt); \
1595 gcc_assert (PASS ## _1); \
1596 PASS ## _ ## NUM = PASS ## _1->clone (); \
1598 p = next_pass_1 (p, PASS ## _ ## NUM, PASS ## _1); \
1601 #define TERMINATE_PASS_LIST() \
1604 #include "pass-instances.def"
1606 #undef INSERT_PASSES_AFTER
1607 #undef PUSH_INSERT_PASSES_WITHIN
1608 #undef POP_INSERT_PASSES
1610 #undef TERMINATE_PASS_LIST
1612 /* Register the passes with the tree dump code. */
1613 register_dump_files (all_lowering_passes
);
1614 register_dump_files (all_small_ipa_passes
);
1615 register_dump_files (all_regular_ipa_passes
);
1616 register_dump_files (all_late_ipa_passes
);
1617 register_dump_files (all_passes
);
1621 delete_pass_tree (opt_pass
*pass
)
1625 /* Recurse into child passes. */
1626 delete_pass_tree (pass
->sub
);
1628 opt_pass
*next
= pass
->next
;
1630 /* Delete this pass. */
1633 /* Iterate onto sibling passes. */
1638 pass_manager::~pass_manager ()
1640 XDELETEVEC (passes_by_id
);
1642 /* Call delete_pass_tree on each of the pass_lists. */
1643 #define DEF_PASS_LIST(LIST) \
1644 delete_pass_tree (*pass_lists[PASS_LIST_NO_##LIST]);
1646 #undef DEF_PASS_LIST
1650 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1651 function CALLBACK for every function in the call graph. Otherwise,
1652 call CALLBACK on the current function. */
1655 do_per_function (void (*callback
) (function
*, void *data
), void *data
)
1657 if (current_function_decl
)
1658 callback (cfun
, data
);
1661 struct cgraph_node
*node
;
1662 FOR_EACH_DEFINED_FUNCTION (node
)
1663 if (node
->analyzed
&& (gimple_has_body_p (node
->decl
) && !in_lto_p
)
1664 && (!node
->clone_of
|| node
->decl
!= node
->clone_of
->decl
))
1665 callback (DECL_STRUCT_FUNCTION (node
->decl
), data
);
1669 /* Because inlining might remove no-longer reachable nodes, we need to
1670 keep the array visible to garbage collector to avoid reading collected
1673 static GTY ((length ("nnodes"))) cgraph_node
**order
;
1675 /* Hook called when NODE is removed and therefore should be
1676 excluded from order vector. DATA is an array of integers.
1677 DATA[0] holds max index it may be accessed by. For cgraph
1678 node DATA[node->uid + 1] holds index of this node in order
1681 remove_cgraph_node_from_order (cgraph_node
*node
, void *data
)
1683 int *order_idx
= (int *)data
;
1685 if (node
->uid
>= order_idx
[0])
1688 int idx
= order_idx
[node
->uid
+ 1];
1689 if (idx
>= 0 && idx
< nnodes
&& order
[idx
] == node
)
1693 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1694 function CALLBACK for every function in the call graph. Otherwise,
1695 call CALLBACK on the current function.
1696 This function is global so that plugins can use it. */
1698 do_per_function_toporder (void (*callback
) (function
*, void *data
), void *data
)
1702 if (current_function_decl
)
1703 callback (cfun
, data
);
1706 cgraph_node_hook_list
*hook
;
1708 gcc_assert (!order
);
1709 order
= ggc_vec_alloc
<cgraph_node
*> (symtab
->cgraph_count
);
1711 order_idx
= XALLOCAVEC (int, symtab
->cgraph_max_uid
+ 1);
1712 memset (order_idx
+ 1, -1, sizeof (int) * symtab
->cgraph_max_uid
);
1713 order_idx
[0] = symtab
->cgraph_max_uid
;
1715 nnodes
= ipa_reverse_postorder (order
);
1716 for (i
= nnodes
- 1; i
>= 0; i
--)
1718 order
[i
]->process
= 1;
1719 order_idx
[order
[i
]->uid
+ 1] = i
;
1721 hook
= symtab
->add_cgraph_removal_hook (remove_cgraph_node_from_order
,
1723 for (i
= nnodes
- 1; i
>= 0; i
--)
1725 /* Function could be inlined and removed as unreachable. */
1729 struct cgraph_node
*node
= order
[i
];
1731 /* Allow possibly removed nodes to be garbage collected. */
1734 if (node
->has_gimple_body_p ())
1735 callback (DECL_STRUCT_FUNCTION (node
->decl
), data
);
1737 symtab
->remove_cgraph_removal_hook (hook
);
1744 /* Helper function to perform function body dump. */
1747 execute_function_dump (function
*fn
, void *data
)
1749 opt_pass
*pass
= (opt_pass
*)data
;
1755 if (fn
->curr_properties
& PROP_trees
)
1756 dump_function_to_file (fn
->decl
, dump_file
, dump_flags
);
1758 print_rtl_with_bb (dump_file
, get_insns (), dump_flags
);
1760 /* Flush the file. If verification fails, we won't be able to
1761 close the file before aborting. */
1764 if ((fn
->curr_properties
& PROP_cfg
)
1765 && (dump_flags
& TDF_GRAPH
))
1767 if (!pass
->graph_dump_initialized
)
1769 clean_graph_dump_file (dump_file_name
);
1770 pass
->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 timevar_push (TV_TODO
);
2015 /* Inform the pass whether it is the first time it is run. */
2016 first_pass_instance
= (flags
& TODO_mark_first_instance
) != 0;
2018 statistics_fini_pass ();
2021 do_per_function (execute_function_todo
, (void *)(size_t) flags
);
2023 /* At this point we should not have any unreachable code in the
2024 CFG, so it is safe to flush the pending freelist for SSA_NAMES. */
2025 if (cfun
&& cfun
->gimple_df
)
2026 flush_ssaname_freelist ();
2028 /* Always remove functions just as before inlining: IPA passes might be
2029 interested to see bodies of extern inline functions that are not inlined
2030 to analyze side effects. The full removal is done just at the end
2031 of IPA pass queue. */
2032 if (flags
& TODO_remove_functions
)
2035 symtab
->remove_unreachable_nodes (dump_file
);
2038 if ((flags
& TODO_dump_symtab
) && dump_file
&& !current_function_decl
)
2041 symtab_node::dump_table (dump_file
);
2042 /* Flush the file. If verification fails, we won't be able to
2043 close the file before aborting. */
2047 /* Now that the dumping has been done, we can get rid of the optional
2049 if (flags
& TODO_df_finish
)
2050 df_finish_pass ((flags
& TODO_df_verify
) != 0);
2052 timevar_pop (TV_TODO
);
2055 /* Verify invariants that should hold between passes. This is a place
2056 to put simple sanity checks. */
2059 verify_interpass_invariants (void)
2061 gcc_checking_assert (!fold_deferring_overflow_warnings_p ());
2064 /* Clear the last verified flag. */
2067 clear_last_verified (function
*fn
, void *data ATTRIBUTE_UNUSED
)
2069 fn
->last_verified
= 0;
2072 /* Helper function. Verify that the properties has been turn into the
2073 properties expected by the pass. */
2076 verify_curr_properties (function
*fn
, void *data
)
2078 unsigned int props
= (size_t)data
;
2079 gcc_assert ((fn
->curr_properties
& props
) == props
);
2082 /* Initialize pass dump file. */
2083 /* This is non-static so that the plugins can use it. */
2086 pass_init_dump_file (opt_pass
*pass
)
2088 /* If a dump file name is present, open it if enabled. */
2089 if (pass
->static_pass_number
!= -1)
2091 timevar_push (TV_DUMP
);
2092 gcc::dump_manager
*dumps
= g
->get_dumps ();
2093 bool initializing_dump
=
2094 !dumps
->dump_initialized_p (pass
->static_pass_number
);
2095 dump_file_name
= dumps
->get_dump_file_name (pass
->static_pass_number
);
2096 dumps
->dump_start (pass
->static_pass_number
, &dump_flags
);
2097 if (dump_file
&& current_function_decl
)
2098 dump_function_header (dump_file
, current_function_decl
, dump_flags
);
2099 if (initializing_dump
2100 && dump_file
&& (dump_flags
& TDF_GRAPH
)
2101 && cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2103 clean_graph_dump_file (dump_file_name
);
2104 pass
->graph_dump_initialized
= true;
2106 timevar_pop (TV_DUMP
);
2107 return initializing_dump
;
2113 /* Flush PASS dump file. */
2114 /* This is non-static so that plugins can use it. */
2117 pass_fini_dump_file (opt_pass
*pass
)
2119 timevar_push (TV_DUMP
);
2121 /* Flush and close dump file. */
2124 free (CONST_CAST (char *, dump_file_name
));
2125 dump_file_name
= NULL
;
2128 g
->get_dumps ()->dump_finish (pass
->static_pass_number
);
2129 timevar_pop (TV_DUMP
);
2132 /* After executing the pass, apply expected changes to the function
2136 update_properties_after_pass (function
*fn
, void *data
)
2138 opt_pass
*pass
= (opt_pass
*) data
;
2139 fn
->curr_properties
= (fn
->curr_properties
| pass
->properties_provided
)
2140 & ~pass
->properties_destroyed
;
2143 /* Execute summary generation for all of the passes in IPA_PASS. */
2146 execute_ipa_summary_passes (ipa_opt_pass_d
*ipa_pass
)
2150 opt_pass
*pass
= ipa_pass
;
2152 /* Execute all of the IPA_PASSes in the list. */
2153 if (ipa_pass
->type
== IPA_PASS
2154 && pass
->gate (cfun
)
2155 && ipa_pass
->generate_summary
)
2157 pass_init_dump_file (pass
);
2159 /* If a timevar is present, start it. */
2161 timevar_push (pass
->tv_id
);
2163 current_pass
= pass
;
2164 ipa_pass
->generate_summary ();
2168 timevar_pop (pass
->tv_id
);
2170 pass_fini_dump_file (pass
);
2172 ipa_pass
= (ipa_opt_pass_d
*)ipa_pass
->next
;
2176 /* Execute IPA_PASS function transform on NODE. */
2179 execute_one_ipa_transform_pass (struct cgraph_node
*node
,
2180 ipa_opt_pass_d
*ipa_pass
)
2182 opt_pass
*pass
= ipa_pass
;
2183 unsigned int todo_after
= 0;
2185 current_pass
= pass
;
2186 if (!ipa_pass
->function_transform
)
2189 /* Note that the folders should only create gimple expressions.
2190 This is a hack until the new folder is ready. */
2191 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
2193 pass_init_dump_file (pass
);
2195 /* Run pre-pass verification. */
2196 execute_todo (ipa_pass
->function_transform_todo_flags_start
);
2198 /* If a timevar is present, start it. */
2199 if (pass
->tv_id
!= TV_NONE
)
2200 timevar_push (pass
->tv_id
);
2203 todo_after
= ipa_pass
->function_transform (node
);
2206 if (pass
->tv_id
!= TV_NONE
)
2207 timevar_pop (pass
->tv_id
);
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 do_per_function (execute_function_dump
, NULL
);
2220 pass_fini_dump_file (pass
);
2222 current_pass
= NULL
;
2224 /* Signal this is a suitable GC collection point. */
2225 if (!(todo_after
& TODO_do_not_ggc_collect
))
2229 /* For the current function, execute all ipa transforms. */
2232 execute_all_ipa_transforms (void)
2234 struct cgraph_node
*node
;
2237 node
= cgraph_node::get (current_function_decl
);
2239 if (node
->ipa_transforms_to_apply
.exists ())
2243 for (i
= 0; i
< node
->ipa_transforms_to_apply
.length (); i
++)
2244 execute_one_ipa_transform_pass (node
, node
->ipa_transforms_to_apply
[i
]);
2245 node
->ipa_transforms_to_apply
.release ();
2249 /* Check if PASS is explicitly disabled or enabled and return
2250 the gate status. FUNC is the function to be processed, and
2251 GATE_STATUS is the gate status determined by pass manager by
2255 override_gate_status (opt_pass
*pass
, tree func
, bool gate_status
)
2257 bool explicitly_enabled
= false;
2258 bool explicitly_disabled
= false;
2261 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2262 enabled_pass_uid_range_tab
);
2264 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2265 disabled_pass_uid_range_tab
);
2267 gate_status
= !explicitly_disabled
&& (gate_status
|| explicitly_enabled
);
2276 execute_one_pass (opt_pass
*pass
)
2278 unsigned int todo_after
= 0;
2282 /* IPA passes are executed on whole program, so cfun should be NULL.
2283 Other passes need function context set. */
2284 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
2285 gcc_assert (!cfun
&& !current_function_decl
);
2287 gcc_assert (cfun
&& current_function_decl
);
2289 current_pass
= pass
;
2291 /* Check whether gate check should be avoided.
2292 User controls the value of the gate through the parameter "gate_status". */
2293 gate_status
= pass
->gate (cfun
);
2294 gate_status
= override_gate_status (pass
, current_function_decl
, gate_status
);
2296 /* Override gate with plugin. */
2297 invoke_plugin_callbacks (PLUGIN_OVERRIDE_GATE
, &gate_status
);
2301 /* Run so passes selectively disabling themselves on a given function
2302 are not miscounted. */
2303 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2305 check_profile_consistency (pass
->static_pass_number
, 0, false);
2306 check_profile_consistency (pass
->static_pass_number
, 1, false);
2308 current_pass
= NULL
;
2312 /* Pass execution event trigger: useful to identify passes being
2314 invoke_plugin_callbacks (PLUGIN_PASS_EXECUTION
, pass
);
2316 if (!quiet_flag
&& !cfun
)
2317 fprintf (stderr
, " <%s>", pass
->name
? pass
->name
: "");
2319 /* Note that the folders should only create gimple expressions.
2320 This is a hack until the new folder is ready. */
2321 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
2323 pass_init_dump_file (pass
);
2325 /* Run pre-pass verification. */
2326 execute_todo (pass
->todo_flags_start
);
2329 do_per_function (verify_curr_properties
,
2330 (void *)(size_t)pass
->properties_required
);
2332 /* If a timevar is present, start it. */
2333 if (pass
->tv_id
!= TV_NONE
)
2334 timevar_push (pass
->tv_id
);
2337 todo_after
= pass
->execute (cfun
);
2338 do_per_function (clear_last_verified
, NULL
);
2341 if (pass
->tv_id
!= TV_NONE
)
2342 timevar_pop (pass
->tv_id
);
2344 do_per_function (update_properties_after_pass
, pass
);
2346 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2347 check_profile_consistency (pass
->static_pass_number
, 0, true);
2349 /* Run post-pass cleanup and verification. */
2350 execute_todo (todo_after
| pass
->todo_flags_finish
| TODO_verify_il
);
2351 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2352 check_profile_consistency (pass
->static_pass_number
, 1, true);
2354 verify_interpass_invariants ();
2356 do_per_function (execute_function_dump
, pass
);
2357 if (pass
->type
== IPA_PASS
)
2359 struct cgraph_node
*node
;
2360 if (((ipa_opt_pass_d
*)pass
)->function_transform
)
2361 FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node
)
2362 node
->ipa_transforms_to_apply
.safe_push ((ipa_opt_pass_d
*)pass
);
2365 if (!current_function_decl
)
2366 symtab
->process_new_functions ();
2368 pass_fini_dump_file (pass
);
2370 if (pass
->type
!= SIMPLE_IPA_PASS
&& pass
->type
!= IPA_PASS
)
2371 gcc_assert (!(cfun
->curr_properties
& PROP_trees
)
2372 || pass
->type
!= RTL_PASS
);
2374 current_pass
= NULL
;
2376 /* Signal this is a suitable GC collection point. */
2377 if (!((todo_after
| pass
->todo_flags_finish
) & TODO_do_not_ggc_collect
))
2384 execute_pass_list_1 (opt_pass
*pass
)
2388 gcc_assert (pass
->type
== GIMPLE_PASS
2389 || pass
->type
== RTL_PASS
);
2390 if (execute_one_pass (pass
) && pass
->sub
)
2391 execute_pass_list_1 (pass
->sub
);
2398 execute_pass_list (function
*fn
, opt_pass
*pass
)
2401 execute_pass_list_1 (pass
);
2404 free_dominance_info (CDI_DOMINATORS
);
2405 free_dominance_info (CDI_POST_DOMINATORS
);
2410 /* Write out all LTO data. */
2414 timevar_push (TV_IPA_LTO_GIMPLE_OUT
);
2416 timevar_pop (TV_IPA_LTO_GIMPLE_OUT
);
2417 timevar_push (TV_IPA_LTO_DECL_OUT
);
2418 produce_asm_for_decls ();
2419 timevar_pop (TV_IPA_LTO_DECL_OUT
);
2422 /* Same as execute_pass_list but assume that subpasses of IPA passes
2423 are local passes. If SET is not NULL, write out summaries of only
2424 those node in SET. */
2427 ipa_write_summaries_2 (opt_pass
*pass
, struct lto_out_decl_state
*state
)
2431 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*)pass
;
2432 gcc_assert (!current_function_decl
);
2434 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2435 if (pass
->type
== IPA_PASS
2436 && ipa_pass
->write_summary
2437 && pass
->gate (cfun
))
2439 /* If a timevar is present, start it. */
2441 timevar_push (pass
->tv_id
);
2443 pass_init_dump_file (pass
);
2445 current_pass
= pass
;
2446 ipa_pass
->write_summary ();
2448 pass_fini_dump_file (pass
);
2450 /* If a timevar is present, start it. */
2452 timevar_pop (pass
->tv_id
);
2455 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2456 ipa_write_summaries_2 (pass
->sub
, state
);
2462 /* Helper function of ipa_write_summaries. Creates and destroys the
2463 decl state and calls ipa_write_summaries_2 for all passes that have
2464 summaries. SET is the set of nodes to be written. */
2467 ipa_write_summaries_1 (lto_symtab_encoder_t encoder
)
2469 pass_manager
*passes
= g
->get_passes ();
2470 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2471 state
->symtab_node_encoder
= encoder
;
2473 lto_output_init_mode_table ();
2474 lto_push_out_decl_state (state
);
2476 gcc_assert (!flag_wpa
);
2477 ipa_write_summaries_2 (passes
->all_regular_ipa_passes
, state
);
2481 gcc_assert (lto_get_out_decl_state () == state
);
2482 lto_pop_out_decl_state ();
2483 lto_delete_out_decl_state (state
);
2486 /* Write out summaries for all the nodes in the callgraph. */
2489 ipa_write_summaries (void)
2491 lto_symtab_encoder_t encoder
;
2493 varpool_node
*vnode
;
2494 struct cgraph_node
*node
;
2495 struct cgraph_node
**order
;
2497 if ((!flag_generate_lto
&& !flag_generate_offload
) || seen_error ())
2500 select_what_to_stream ();
2502 encoder
= lto_symtab_encoder_new (false);
2504 /* Create the callgraph set in the same order used in
2505 cgraph_expand_all_functions. This mostly facilitates debugging,
2506 since it causes the gimple file to be processed in the same order
2507 as the source code. */
2508 order
= XCNEWVEC (struct cgraph_node
*, symtab
->cgraph_count
);
2509 order_pos
= ipa_reverse_postorder (order
);
2510 gcc_assert (order_pos
== symtab
->cgraph_count
);
2512 for (i
= order_pos
- 1; i
>= 0; i
--)
2514 struct cgraph_node
*node
= order
[i
];
2516 if (node
->has_gimple_body_p ())
2518 /* When streaming out references to statements as part of some IPA
2519 pass summary, the statements need to have uids assigned and the
2520 following does that for all the IPA passes here. Naturally, this
2521 ordering then matches the one IPA-passes get in their stmt_fixup
2524 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
2525 renumber_gimple_stmt_uids ();
2528 if (node
->definition
&& node
->need_lto_streaming
)
2529 lto_set_symtab_encoder_in_partition (encoder
, node
);
2532 FOR_EACH_DEFINED_FUNCTION (node
)
2533 if (node
->alias
&& node
->need_lto_streaming
)
2534 lto_set_symtab_encoder_in_partition (encoder
, node
);
2535 FOR_EACH_DEFINED_VARIABLE (vnode
)
2536 if (vnode
->need_lto_streaming
)
2537 lto_set_symtab_encoder_in_partition (encoder
, vnode
);
2539 ipa_write_summaries_1 (compute_ltrans_boundary (encoder
));
2544 /* Same as execute_pass_list but assume that subpasses of IPA passes
2545 are local passes. If SET is not NULL, write out optimization summaries of
2546 only those node in SET. */
2549 ipa_write_optimization_summaries_1 (opt_pass
*pass
,
2550 struct lto_out_decl_state
*state
)
2554 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*)pass
;
2555 gcc_assert (!current_function_decl
);
2557 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2558 if (pass
->type
== IPA_PASS
2559 && ipa_pass
->write_optimization_summary
2560 && pass
->gate (cfun
))
2562 /* If a timevar is present, start it. */
2564 timevar_push (pass
->tv_id
);
2566 pass_init_dump_file (pass
);
2568 current_pass
= pass
;
2569 ipa_pass
->write_optimization_summary ();
2571 pass_fini_dump_file (pass
);
2573 /* If a timevar is present, start it. */
2575 timevar_pop (pass
->tv_id
);
2578 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2579 ipa_write_optimization_summaries_1 (pass
->sub
, state
);
2585 /* Write all the optimization summaries for the cgraph nodes in SET. If SET is
2586 NULL, write out all summaries of all nodes. */
2589 ipa_write_optimization_summaries (lto_symtab_encoder_t encoder
)
2591 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2592 lto_symtab_encoder_iterator lsei
;
2593 state
->symtab_node_encoder
= encoder
;
2595 lto_output_init_mode_table ();
2596 lto_push_out_decl_state (state
);
2597 for (lsei
= lsei_start_function_in_partition (encoder
);
2598 !lsei_end_p (lsei
); lsei_next_function_in_partition (&lsei
))
2600 struct cgraph_node
*node
= lsei_cgraph_node (lsei
);
2601 /* When streaming out references to statements as part of some IPA
2602 pass summary, the statements need to have uids assigned.
2604 For functions newly born at WPA stage we need to initialize
2606 if (node
->definition
2607 && gimple_has_body_p (node
->decl
))
2609 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
2610 renumber_gimple_stmt_uids ();
2615 gcc_assert (flag_wpa
);
2616 pass_manager
*passes
= g
->get_passes ();
2617 ipa_write_optimization_summaries_1 (passes
->all_regular_ipa_passes
, state
);
2621 gcc_assert (lto_get_out_decl_state () == state
);
2622 lto_pop_out_decl_state ();
2623 lto_delete_out_decl_state (state
);
2626 /* Same as execute_pass_list but assume that subpasses of IPA passes
2627 are local passes. */
2630 ipa_read_summaries_1 (opt_pass
*pass
)
2634 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
2636 gcc_assert (!current_function_decl
);
2638 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2640 if (pass
->gate (cfun
))
2642 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_summary
)
2644 /* If a timevar is present, start it. */
2646 timevar_push (pass
->tv_id
);
2648 pass_init_dump_file (pass
);
2650 current_pass
= pass
;
2651 ipa_pass
->read_summary ();
2653 pass_fini_dump_file (pass
);
2657 timevar_pop (pass
->tv_id
);
2660 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2661 ipa_read_summaries_1 (pass
->sub
);
2668 /* Read all the summaries for all_regular_ipa_passes. */
2671 ipa_read_summaries (void)
2673 pass_manager
*passes
= g
->get_passes ();
2674 ipa_read_summaries_1 (passes
->all_regular_ipa_passes
);
2677 /* Same as execute_pass_list but assume that subpasses of IPA passes
2678 are local passes. */
2681 ipa_read_optimization_summaries_1 (opt_pass
*pass
)
2685 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
2687 gcc_assert (!current_function_decl
);
2689 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2691 if (pass
->gate (cfun
))
2693 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_optimization_summary
)
2695 /* If a timevar is present, start it. */
2697 timevar_push (pass
->tv_id
);
2699 pass_init_dump_file (pass
);
2701 current_pass
= pass
;
2702 ipa_pass
->read_optimization_summary ();
2704 pass_fini_dump_file (pass
);
2708 timevar_pop (pass
->tv_id
);
2711 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2712 ipa_read_optimization_summaries_1 (pass
->sub
);
2718 /* Read all the summaries for all_regular_ipa_passes. */
2721 ipa_read_optimization_summaries (void)
2723 pass_manager
*passes
= g
->get_passes ();
2724 ipa_read_optimization_summaries_1 (passes
->all_regular_ipa_passes
);
2727 /* Same as execute_pass_list but assume that subpasses of IPA passes
2728 are local passes. */
2730 execute_ipa_pass_list (opt_pass
*pass
)
2734 gcc_assert (!current_function_decl
);
2736 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2737 if (execute_one_pass (pass
) && pass
->sub
)
2739 if (pass
->sub
->type
== GIMPLE_PASS
)
2741 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_START
, NULL
);
2742 do_per_function_toporder ((void (*)(function
*, void *))
2745 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_END
, NULL
);
2747 else if (pass
->sub
->type
== SIMPLE_IPA_PASS
2748 || pass
->sub
->type
== IPA_PASS
)
2749 execute_ipa_pass_list (pass
->sub
);
2753 gcc_assert (!current_function_decl
);
2754 symtab
->process_new_functions ();
2760 /* Execute stmt fixup hooks of all passes in PASS for NODE and STMTS. */
2763 execute_ipa_stmt_fixups (opt_pass
*pass
,
2764 struct cgraph_node
*node
, gimple
**stmts
)
2768 /* Execute all of the IPA_PASSes in the list. */
2769 if (pass
->type
== IPA_PASS
2770 && pass
->gate (cfun
))
2772 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
2774 if (ipa_pass
->stmt_fixup
)
2776 pass_init_dump_file (pass
);
2777 /* If a timevar is present, start it. */
2779 timevar_push (pass
->tv_id
);
2781 current_pass
= pass
;
2782 ipa_pass
->stmt_fixup (node
, stmts
);
2786 timevar_pop (pass
->tv_id
);
2787 pass_fini_dump_file (pass
);
2790 execute_ipa_stmt_fixups (pass
->sub
, node
, stmts
);
2796 /* Execute stmt fixup hooks of all IPA passes for NODE and STMTS. */
2799 execute_all_ipa_stmt_fixups (struct cgraph_node
*node
, gimple
**stmts
)
2801 pass_manager
*passes
= g
->get_passes ();
2802 execute_ipa_stmt_fixups (passes
->all_regular_ipa_passes
, node
, stmts
);
2806 extern void debug_properties (unsigned int);
2807 extern void dump_properties (FILE *, unsigned int);
2810 dump_properties (FILE *dump
, unsigned int props
)
2812 fprintf (dump
, "Properties:\n");
2813 if (props
& PROP_gimple_any
)
2814 fprintf (dump
, "PROP_gimple_any\n");
2815 if (props
& PROP_gimple_lcf
)
2816 fprintf (dump
, "PROP_gimple_lcf\n");
2817 if (props
& PROP_gimple_leh
)
2818 fprintf (dump
, "PROP_gimple_leh\n");
2819 if (props
& PROP_cfg
)
2820 fprintf (dump
, "PROP_cfg\n");
2821 if (props
& PROP_ssa
)
2822 fprintf (dump
, "PROP_ssa\n");
2823 if (props
& PROP_no_crit_edges
)
2824 fprintf (dump
, "PROP_no_crit_edges\n");
2825 if (props
& PROP_rtl
)
2826 fprintf (dump
, "PROP_rtl\n");
2827 if (props
& PROP_gimple_lomp
)
2828 fprintf (dump
, "PROP_gimple_lomp\n");
2829 if (props
& PROP_gimple_lcx
)
2830 fprintf (dump
, "PROP_gimple_lcx\n");
2831 if (props
& PROP_gimple_lvec
)
2832 fprintf (dump
, "PROP_gimple_lvec\n");
2833 if (props
& PROP_cfglayout
)
2834 fprintf (dump
, "PROP_cfglayout\n");
2838 debug_properties (unsigned int props
)
2840 dump_properties (stderr
, props
);
2843 /* Called by local passes to see if function is called by already processed nodes.
2844 Because we process nodes in topological order, this means that function is
2845 in recursive cycle or we introduced new direct calls. */
2847 function_called_by_processed_nodes_p (void)
2849 struct cgraph_edge
*e
;
2850 for (e
= cgraph_node::get (current_function_decl
)->callers
;
2854 if (e
->caller
->decl
== current_function_decl
)
2856 if (!e
->caller
->has_gimple_body_p ())
2858 if (TREE_ASM_WRITTEN (e
->caller
->decl
))
2860 if (!e
->caller
->process
&& !e
->caller
->global
.inlined_to
)
2865 fprintf (dump_file
, "Already processed call to:\n");
2866 e
->caller
->dump (dump_file
);
2871 #include "gt-passes.h"