1 /* Top level of GCC compilers (cc1, cc1plus, etc.)
2 Copyright (C) 1987-2015 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 /* This is the top level of cc1/c++.
21 It parses command args, opens files, invokes the various passes
22 in the proper order, and counts the time used by each.
23 Error messages and low-level interface to malloc also handled here. */
27 #include "coretypes.h"
36 #include "fold-const.h"
40 #include "insn-attr.h"
41 #include "insn-config.h"
42 #include "insn-flags.h"
57 #include "diagnostic-core.h"
62 #include "langhooks.h"
64 #include "hosthooks.h"
67 #include "value-prof.h"
68 #include "tree-inline.h"
69 #include "internal-fn.h"
71 #include "tree-ssa-loop-manip.h"
72 #include "tree-into-ssa.h"
75 #include "tree-pass.h"
76 #include "tree-dump.h"
78 #include "lto-streamer.h"
80 #include "ipa-utils.h"
81 #include "tree-pretty-print.h" /* for dump_function_header */
83 #include "pass_manager.h"
85 #include "tree-ssa-live.h" /* For remove_unused_locals. */
86 #include "tree-cfgcleanup.h"
87 #include "tree-ssanames.h"
91 /* This is used for debugging. It allows the current pass to printed
92 from anywhere in compilation.
93 The variable current_pass is also used for statistics and plugins. */
94 opt_pass
*current_pass
;
96 static void register_pass_name (opt_pass
*, const char *);
98 /* Most passes are single-instance (within their context) and thus don't
99 need to implement cloning, but passes that support multiple instances
100 *must* provide their own implementation of the clone method.
102 Handle this by providing a default implemenation, but make it a fatal
108 internal_error ("pass %s does not support cloning", name
);
112 opt_pass::gate (function
*)
118 opt_pass::execute (function
*)
123 opt_pass::opt_pass (const pass_data
&data
, context
*ctxt
)
127 static_pass_number (0),
134 pass_manager::execute_early_local_passes ()
136 execute_pass_list (cfun
, pass_build_ssa_passes_1
->sub
);
137 if (flag_check_pointer_bounds
)
138 execute_pass_list (cfun
, pass_chkp_instrumentation_passes_1
->sub
);
139 execute_pass_list (cfun
, pass_local_optimization_passes_1
->sub
);
143 pass_manager::execute_pass_mode_switching ()
145 return pass_mode_switching_1
->execute (cfun
);
149 /* Call from anywhere to find out what pass this is. Useful for
150 printing out debugging information deep inside an service
153 print_current_pass (FILE *file
)
156 fprintf (file
, "current pass = %s (%d)\n",
157 current_pass
->name
, current_pass
->static_pass_number
);
159 fprintf (file
, "no current pass.\n");
163 /* Call from the debugger to get the current pass name. */
167 print_current_pass (stderr
);
172 /* Global variables used to communicate with passes. */
174 bool first_pass_instance
;
177 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
180 This does nothing for local (non-static) variables, unless the
181 variable is a register variable with DECL_ASSEMBLER_NAME set. In
182 that case, or if the variable is not an automatic, it sets up the
183 RTL and outputs any assembler code (label definition, storage
184 allocation and initialization).
186 DECL is the declaration. TOP_LEVEL is nonzero
187 if this declaration is not within a function. */
190 rest_of_decl_compilation (tree decl
,
194 bool finalize
= true;
196 /* We deferred calling assemble_alias so that we could collect
197 other attributes such as visibility. Emit the alias now. */
201 alias
= lookup_attribute ("alias", DECL_ATTRIBUTES (decl
));
204 alias
= TREE_VALUE (TREE_VALUE (alias
));
205 alias
= get_identifier (TREE_STRING_POINTER (alias
));
206 /* A quirk of the initial implementation of aliases required that the
207 user add "extern" to all of them. Which is silly, but now
208 historical. Do note that the symbol is in fact locally defined. */
209 DECL_EXTERNAL (decl
) = 0;
210 TREE_STATIC (decl
) = 1;
211 assemble_alias (decl
, alias
);
216 /* Can't defer this, because it needs to happen before any
217 later function definitions are processed. */
218 if (DECL_ASSEMBLER_NAME_SET_P (decl
) && DECL_REGISTER (decl
))
219 make_decl_rtl (decl
);
221 /* Forward declarations for nested functions are not "external",
222 but we need to treat them as if they were. */
223 if (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)
224 || TREE_CODE (decl
) == FUNCTION_DECL
)
226 timevar_push (TV_VARCONST
);
228 /* Don't output anything when a tentative file-scope definition
229 is seen. But at end of compilation, do output code for them.
231 We do output all variables and rely on
232 callgraph code to defer them except for forward declarations
233 (see gcc.c-torture/compile/920624-1.c) */
235 || !DECL_DEFER_OUTPUT (decl
)
236 || DECL_INITIAL (decl
))
237 && (TREE_CODE (decl
) != VAR_DECL
|| !DECL_HAS_VALUE_EXPR_P (decl
))
238 && !DECL_EXTERNAL (decl
))
240 /* When reading LTO unit, we also read varpool, so do not
242 if (in_lto_p
&& !at_end
)
244 else if (finalize
&& TREE_CODE (decl
) != FUNCTION_DECL
)
245 varpool_node::finalize_decl (decl
);
248 #ifdef ASM_FINISH_DECLARE_OBJECT
249 if (decl
== last_assemble_variable_decl
)
251 ASM_FINISH_DECLARE_OBJECT (asm_out_file
, decl
,
256 /* Now that we have activated any function-specific attributes
257 that might affect function decl, particularly align, relayout it. */
258 if (TREE_CODE (decl
) == FUNCTION_DECL
)
259 targetm
.target_option
.relayout_function (decl
);
261 timevar_pop (TV_VARCONST
);
263 else if (TREE_CODE (decl
) == TYPE_DECL
264 /* Like in rest_of_type_compilation, avoid confusing the debug
265 information machinery when there are errors. */
268 timevar_push (TV_SYMOUT
);
269 debug_hooks
->type_decl (decl
, !top_level
);
270 timevar_pop (TV_SYMOUT
);
273 /* Let cgraph know about the existence of variables. */
274 if (in_lto_p
&& !at_end
)
276 else if (TREE_CODE (decl
) == VAR_DECL
&& !DECL_EXTERNAL (decl
)
277 && TREE_STATIC (decl
))
278 varpool_node::get_create (decl
);
280 /* Generate early debug for global variables. Any local variables will
281 be handled by either handling reachable functions from
282 finalize_compilation_unit (and by consequence, locally scoped
283 symbols), or by rest_of_type_compilation below.
285 Also, pick up function prototypes, which will be mostly ignored
286 by the different early_global_decl() hooks, but will at least be
287 used by Go's hijack of the debug_hooks to implement
290 && (TREE_CODE (decl
) != FUNCTION_DECL
291 /* This will pick up function prototypes with no bodies,
292 which are not visible in finalize_compilation_unit()
293 while iterating with FOR_EACH_*_FUNCTION through the
295 || !DECL_SAVED_TREE (decl
))
297 /* We need to check both decl_function_context and
298 current_function_decl here to make sure local extern
299 declarations end up with the correct context.
301 For local extern declarations, decl_function_context is
302 empty, but current_function_decl is set to the function where
303 the extern was declared . Without the check for
304 !current_function_decl below, the local extern ends up
305 incorrectly with a top-level context.
317 extern int i; // Local extern declaration.
324 && !decl_function_context (decl
)
325 && !current_function_decl
326 && DECL_SOURCE_LOCATION (decl
) != BUILTINS_LOCATION
327 && (!decl_type_context (decl
)
328 /* If we created a varpool node for the decl make sure to
329 call early_global_decl. Otherwise we miss changes
330 introduced by member definitions like
331 struct A { static int staticdatamember; };
332 int A::staticdatamember;
333 and thus have incomplete early debug and late debug
334 called from varpool node removal fails to handle it
337 && TREE_CODE (decl
) == VAR_DECL
338 && TREE_STATIC (decl
) && !DECL_EXTERNAL (decl
)))
339 /* Avoid confusing the debug information machinery when there are
342 (*debug_hooks
->early_global_decl
) (decl
);
345 /* Called after finishing a record, union or enumeral type. */
348 rest_of_type_compilation (tree type
, int toplev
)
350 /* Avoid confusing the debug information machinery when there are
355 timevar_push (TV_SYMOUT
);
356 debug_hooks
->type_decl (TYPE_STUB_DECL (type
), !toplev
);
357 timevar_pop (TV_SYMOUT
);
364 finish_optimization_passes (void)
367 struct dump_file_info
*dfi
;
369 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
371 timevar_push (TV_DUMP
);
372 if (profile_arc_flag
|| flag_test_coverage
|| flag_branch_probabilities
)
374 dumps
->dump_start (pass_profile_1
->static_pass_number
, NULL
);
376 dumps
->dump_finish (pass_profile_1
->static_pass_number
);
381 dumps
->dump_start (pass_profile_1
->static_pass_number
, NULL
);
382 print_combine_total_stats ();
383 dumps
->dump_finish (pass_profile_1
->static_pass_number
);
386 /* Do whatever is necessary to finish printing the graphs. */
387 for (i
= TDI_end
; (dfi
= dumps
->get_dump_file_info (i
)) != NULL
; ++i
)
388 if (dumps
->dump_initialized_p (i
)
389 && (dfi
->pflags
& TDF_GRAPH
) != 0
390 && (name
= dumps
->get_dump_file_name (i
)) != NULL
)
392 finish_graph_dump_file (name
);
396 timevar_pop (TV_DUMP
);
400 execute_build_ssa_passes (void)
402 /* Once this pass (and its sub-passes) are complete, all functions
403 will be in SSA form. Technically this state change is happening
404 a tad early, since the sub-passes have not yet run, but since
405 none of the sub-passes are IPA passes and do not create new
406 functions, this is ok. We're setting this value for the benefit
407 of IPA passes that follow. */
408 if (symtab
->state
< IPA_SSA
)
409 symtab
->state
= IPA_SSA
;
415 const pass_data pass_data_build_ssa_passes
=
417 SIMPLE_IPA_PASS
, /* type */
418 "build_ssa_passes", /* name */
419 OPTGROUP_NONE
, /* optinfo_flags */
420 TV_EARLY_LOCAL
, /* tv_id */
421 0, /* properties_required */
422 0, /* properties_provided */
423 0, /* properties_destroyed */
424 0, /* todo_flags_start */
425 /* todo_flags_finish is executed before subpases. For this reason
426 it makes no sense to remove unreachable functions here. */
427 0, /* todo_flags_finish */
430 class pass_build_ssa_passes
: public simple_ipa_opt_pass
433 pass_build_ssa_passes (gcc::context
*ctxt
)
434 : simple_ipa_opt_pass (pass_data_build_ssa_passes
, ctxt
)
437 /* opt_pass methods: */
438 virtual bool gate (function
*)
440 /* Don't bother doing anything if the program has errors. */
441 return (!seen_error () && !in_lto_p
);
444 virtual unsigned int execute (function
*)
446 return execute_build_ssa_passes ();
449 }; // class pass_build_ssa_passes
451 const pass_data pass_data_chkp_instrumentation_passes
=
453 SIMPLE_IPA_PASS
, /* type */
454 "chkp_passes", /* name */
455 OPTGROUP_NONE
, /* optinfo_flags */
457 0, /* properties_required */
458 0, /* properties_provided */
459 0, /* properties_destroyed */
460 0, /* todo_flags_start */
461 0, /* todo_flags_finish */
464 class pass_chkp_instrumentation_passes
: public simple_ipa_opt_pass
467 pass_chkp_instrumentation_passes (gcc::context
*ctxt
)
468 : simple_ipa_opt_pass (pass_data_chkp_instrumentation_passes
, ctxt
)
471 /* opt_pass methods: */
472 virtual bool gate (function
*)
474 /* Don't bother doing anything if the program has errors. */
475 return (flag_check_pointer_bounds
476 && !seen_error () && !in_lto_p
);
479 }; // class pass_chkp_instrumentation_passes
481 const pass_data pass_data_local_optimization_passes
=
483 SIMPLE_IPA_PASS
, /* type */
484 "opt_local_passes", /* name */
485 OPTGROUP_NONE
, /* optinfo_flags */
487 0, /* properties_required */
488 0, /* properties_provided */
489 0, /* properties_destroyed */
490 0, /* todo_flags_start */
491 0, /* todo_flags_finish */
494 class pass_local_optimization_passes
: public simple_ipa_opt_pass
497 pass_local_optimization_passes (gcc::context
*ctxt
)
498 : simple_ipa_opt_pass (pass_data_local_optimization_passes
, ctxt
)
501 /* opt_pass methods: */
502 virtual bool gate (function
*)
504 /* Don't bother doing anything if the program has errors. */
505 return (!seen_error () && !in_lto_p
);
508 }; // class pass_local_optimization_passes
512 simple_ipa_opt_pass
*
513 make_pass_build_ssa_passes (gcc::context
*ctxt
)
515 return new pass_build_ssa_passes (ctxt
);
518 simple_ipa_opt_pass
*
519 make_pass_chkp_instrumentation_passes (gcc::context
*ctxt
)
521 return new pass_chkp_instrumentation_passes (ctxt
);
524 simple_ipa_opt_pass
*
525 make_pass_local_optimization_passes (gcc::context
*ctxt
)
527 return new pass_local_optimization_passes (ctxt
);
532 const pass_data pass_data_all_early_optimizations
=
534 GIMPLE_PASS
, /* type */
535 "early_optimizations", /* name */
536 OPTGROUP_NONE
, /* optinfo_flags */
538 0, /* properties_required */
539 0, /* properties_provided */
540 0, /* properties_destroyed */
541 0, /* todo_flags_start */
542 0, /* todo_flags_finish */
545 class pass_all_early_optimizations
: public gimple_opt_pass
548 pass_all_early_optimizations (gcc::context
*ctxt
)
549 : gimple_opt_pass (pass_data_all_early_optimizations
, ctxt
)
552 /* opt_pass methods: */
553 virtual bool gate (function
*)
555 return (optimize
>= 1
556 /* Don't bother doing anything if the program has errors. */
560 }; // class pass_all_early_optimizations
564 static gimple_opt_pass
*
565 make_pass_all_early_optimizations (gcc::context
*ctxt
)
567 return new pass_all_early_optimizations (ctxt
);
572 const pass_data pass_data_all_optimizations
=
574 GIMPLE_PASS
, /* type */
575 "*all_optimizations", /* name */
576 OPTGROUP_NONE
, /* optinfo_flags */
577 TV_OPTIMIZE
, /* tv_id */
578 0, /* properties_required */
579 0, /* properties_provided */
580 0, /* properties_destroyed */
581 0, /* todo_flags_start */
582 0, /* todo_flags_finish */
585 class pass_all_optimizations
: public gimple_opt_pass
588 pass_all_optimizations (gcc::context
*ctxt
)
589 : gimple_opt_pass (pass_data_all_optimizations
, ctxt
)
592 /* opt_pass methods: */
593 virtual bool gate (function
*) { return optimize
>= 1 && !optimize_debug
; }
595 }; // class pass_all_optimizations
599 static gimple_opt_pass
*
600 make_pass_all_optimizations (gcc::context
*ctxt
)
602 return new pass_all_optimizations (ctxt
);
607 const pass_data pass_data_all_optimizations_g
=
609 GIMPLE_PASS
, /* type */
610 "*all_optimizations_g", /* name */
611 OPTGROUP_NONE
, /* optinfo_flags */
612 TV_OPTIMIZE
, /* tv_id */
613 0, /* properties_required */
614 0, /* properties_provided */
615 0, /* properties_destroyed */
616 0, /* todo_flags_start */
617 0, /* todo_flags_finish */
620 class pass_all_optimizations_g
: public gimple_opt_pass
623 pass_all_optimizations_g (gcc::context
*ctxt
)
624 : gimple_opt_pass (pass_data_all_optimizations_g
, ctxt
)
627 /* opt_pass methods: */
628 virtual bool gate (function
*) { return optimize
>= 1 && optimize_debug
; }
630 }; // class pass_all_optimizations_g
634 static gimple_opt_pass
*
635 make_pass_all_optimizations_g (gcc::context
*ctxt
)
637 return new pass_all_optimizations_g (ctxt
);
642 const pass_data pass_data_rest_of_compilation
=
645 "*rest_of_compilation", /* name */
646 OPTGROUP_NONE
, /* optinfo_flags */
647 TV_REST_OF_COMPILATION
, /* tv_id */
648 PROP_rtl
, /* properties_required */
649 0, /* properties_provided */
650 0, /* properties_destroyed */
651 0, /* todo_flags_start */
652 0, /* todo_flags_finish */
655 class pass_rest_of_compilation
: public rtl_opt_pass
658 pass_rest_of_compilation (gcc::context
*ctxt
)
659 : rtl_opt_pass (pass_data_rest_of_compilation
, ctxt
)
662 /* opt_pass methods: */
663 virtual bool gate (function
*)
665 /* Early return if there were errors. We can run afoul of our
666 consistency checks, and there's not really much point in fixing them. */
667 return !(rtl_dump_and_exit
|| flag_syntax_only
|| seen_error ());
670 }; // class pass_rest_of_compilation
674 static rtl_opt_pass
*
675 make_pass_rest_of_compilation (gcc::context
*ctxt
)
677 return new pass_rest_of_compilation (ctxt
);
682 const pass_data pass_data_postreload
=
685 "*all-postreload", /* name */
686 OPTGROUP_NONE
, /* optinfo_flags */
687 TV_POSTRELOAD
, /* tv_id */
688 PROP_rtl
, /* properties_required */
689 0, /* properties_provided */
690 0, /* properties_destroyed */
691 0, /* todo_flags_start */
692 0, /* todo_flags_finish */
695 class pass_postreload
: public rtl_opt_pass
698 pass_postreload (gcc::context
*ctxt
)
699 : rtl_opt_pass (pass_data_postreload
, ctxt
)
702 /* opt_pass methods: */
703 virtual bool gate (function
*) { return reload_completed
; }
705 }; // class pass_postreload
709 static rtl_opt_pass
*
710 make_pass_postreload (gcc::context
*ctxt
)
712 return new pass_postreload (ctxt
);
717 const pass_data pass_data_late_compilation
=
720 "*all-late_compilation", /* name */
721 OPTGROUP_NONE
, /* optinfo_flags */
722 TV_LATE_COMPILATION
, /* tv_id */
723 PROP_rtl
, /* properties_required */
724 0, /* properties_provided */
725 0, /* properties_destroyed */
726 0, /* todo_flags_start */
727 0, /* todo_flags_finish */
730 class pass_late_compilation
: public rtl_opt_pass
733 pass_late_compilation (gcc::context
*ctxt
)
734 : rtl_opt_pass (pass_data_late_compilation
, ctxt
)
737 /* opt_pass methods: */
738 virtual bool gate (function
*)
740 return reload_completed
|| targetm
.no_register_allocation
;
743 }; // class pass_late_compilation
747 static rtl_opt_pass
*
748 make_pass_late_compilation (gcc::context
*ctxt
)
750 return new pass_late_compilation (ctxt
);
755 /* Set the static pass number of pass PASS to ID and record that
756 in the mapping from static pass number to pass. */
760 set_pass_for_id (int id
, opt_pass
*pass
)
762 pass
->static_pass_number
= id
;
763 if (passes_by_id_size
<= id
)
765 passes_by_id
= XRESIZEVEC (opt_pass
*, passes_by_id
, id
+ 1);
766 memset (passes_by_id
+ passes_by_id_size
, 0,
767 (id
+ 1 - passes_by_id_size
) * sizeof (void *));
768 passes_by_id_size
= id
+ 1;
770 passes_by_id
[id
] = pass
;
773 /* Return the pass with the static pass number ID. */
776 pass_manager::get_pass_for_id (int id
) const
778 if (id
>= passes_by_id_size
)
780 return passes_by_id
[id
];
783 /* Iterate over the pass tree allocating dump file numbers. We want
784 to do this depth first, and independent of whether the pass is
788 register_one_dump_file (opt_pass
*pass
)
790 g
->get_passes ()->register_one_dump_file (pass
);
794 pass_manager::register_one_dump_file (opt_pass
*pass
)
796 char *dot_name
, *flag_name
, *glob_name
;
797 const char *name
, *full_name
, *prefix
;
800 int optgroup_flags
= OPTGROUP_NONE
;
801 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
803 /* See below in next_pass_1. */
805 if (pass
->static_pass_number
!= -1)
806 sprintf (num
, "%d", ((int) pass
->static_pass_number
< 0
807 ? 1 : pass
->static_pass_number
));
809 /* The name is both used to identify the pass for the purposes of plugins,
810 and to specify dump file name and option.
811 The latter two might want something short which is not quite unique; for
812 that reason, we may have a disambiguating prefix, followed by a space
813 to mark the start of the following dump file name / option string. */
814 name
= strchr (pass
->name
, ' ');
815 name
= name
? name
+ 1 : pass
->name
;
816 dot_name
= concat (".", name
, num
, NULL
);
817 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
821 optgroup_flags
|= OPTGROUP_IPA
;
823 else if (pass
->type
== GIMPLE_PASS
)
834 flag_name
= concat (prefix
, name
, num
, NULL
);
835 glob_name
= concat (prefix
, name
, NULL
);
836 optgroup_flags
|= pass
->optinfo_flags
;
837 /* For any passes that do not have an optgroup set, and which are not
838 IPA passes setup above, set the optgroup to OPTGROUP_OTHER so that
839 any dump messages are emitted properly under -fopt-info(-optall). */
840 if (optgroup_flags
== OPTGROUP_NONE
)
841 optgroup_flags
= OPTGROUP_OTHER
;
842 id
= dumps
->dump_register (dot_name
, flag_name
, glob_name
, flags
,
845 set_pass_for_id (id
, pass
);
846 full_name
= concat (prefix
, pass
->name
, num
, NULL
);
847 register_pass_name (pass
, full_name
);
848 free (CONST_CAST (char *, full_name
));
851 /* Register the dump files for the pass_manager starting at PASS. */
854 pass_manager::register_dump_files (opt_pass
*pass
)
858 if (pass
->name
&& pass
->name
[0] != '*')
859 register_one_dump_file (pass
);
862 register_dump_files (pass
->sub
);
869 static hash_map
<nofree_string_hash
, opt_pass
*> *name_to_pass_map
;
871 /* Register PASS with NAME. */
874 register_pass_name (opt_pass
*pass
, const char *name
)
876 if (!name_to_pass_map
)
877 name_to_pass_map
= new hash_map
<nofree_string_hash
, opt_pass
*> (256);
879 if (name_to_pass_map
->get (name
))
880 return; /* Ignore plugin passes. */
882 const char *unique_name
= xstrdup (name
);
883 name_to_pass_map
->put (unique_name
, pass
);
886 /* Map from pass id to canonicalized pass name. */
888 typedef const char *char_ptr
;
889 static vec
<char_ptr
> pass_tab
= vNULL
;
891 /* Callback function for traversing NAME_TO_PASS_MAP. */
894 passes_pass_traverse (const char *const &name
, opt_pass
*const &pass
, void *)
896 gcc_assert (pass
->static_pass_number
> 0);
897 gcc_assert (pass_tab
.exists ());
899 pass_tab
[pass
->static_pass_number
] = name
;
904 /* The function traverses NAME_TO_PASS_MAP and creates a pass info
905 table for dumping purpose. */
908 create_pass_tab (void)
910 if (!flag_dump_passes
)
913 pass_tab
.safe_grow_cleared (g
->get_passes ()->passes_by_id_size
+ 1);
914 name_to_pass_map
->traverse
<void *, passes_pass_traverse
> (NULL
);
917 static bool override_gate_status (opt_pass
*, tree
, bool);
919 /* Dump the instantiated name for PASS. IS_ON indicates if PASS
920 is turned on or not. */
923 dump_one_pass (opt_pass
*pass
, int pass_indent
)
925 int indent
= 3 * pass_indent
;
927 bool is_on
, is_really_on
;
929 is_on
= pass
->gate (cfun
);
930 is_really_on
= override_gate_status (pass
, current_function_decl
, is_on
);
932 if (pass
->static_pass_number
<= 0)
935 pn
= pass_tab
[pass
->static_pass_number
];
937 fprintf (stderr
, "%*s%-40s%*s:%s%s\n", indent
, " ", pn
,
938 (15 - indent
< 0 ? 0 : 15 - indent
), " ",
939 is_on
? " ON" : " OFF",
940 ((!is_on
) == (!is_really_on
) ? ""
941 : (is_really_on
? " (FORCED_ON)" : " (FORCED_OFF)")));
944 /* Dump pass list PASS with indentation INDENT. */
947 dump_pass_list (opt_pass
*pass
, int indent
)
951 dump_one_pass (pass
, indent
);
953 dump_pass_list (pass
->sub
, indent
+ 1);
959 /* Dump all optimization passes. */
964 g
->get_passes ()->dump_passes ();
968 pass_manager::dump_passes () const
970 push_dummy_function (true);
974 dump_pass_list (all_lowering_passes
, 1);
975 dump_pass_list (all_small_ipa_passes
, 1);
976 dump_pass_list (all_regular_ipa_passes
, 1);
977 dump_pass_list (all_late_ipa_passes
, 1);
978 dump_pass_list (all_passes
, 1);
980 pop_dummy_function ();
983 /* Returns the pass with NAME. */
986 get_pass_by_name (const char *name
)
988 opt_pass
**p
= name_to_pass_map
->get (name
);
996 /* Range [start, last]. */
1002 const char *assem_name
;
1003 struct uid_range
*next
;
1006 typedef struct uid_range
*uid_range_p
;
1009 static vec
<uid_range_p
>
1010 enabled_pass_uid_range_tab
= vNULL
;
1011 static vec
<uid_range_p
>
1012 disabled_pass_uid_range_tab
= vNULL
;
1015 /* Parse option string for -fdisable- and -fenable-
1016 The syntax of the options:
1018 -fenable-<pass_name>
1019 -fdisable-<pass_name>
1021 -fenable-<pass_name>=s1:e1,s2:e2,...
1022 -fdisable-<pass_name>=s1:e1,s2:e2,...
1026 enable_disable_pass (const char *arg
, bool is_enable
)
1029 char *range_str
, *phase_name
;
1030 char *argstr
= xstrdup (arg
);
1031 vec
<uid_range_p
> *tab
= 0;
1033 range_str
= strchr (argstr
,'=');
1040 phase_name
= argstr
;
1044 error ("unrecognized option -fenable");
1046 error ("unrecognized option -fdisable");
1050 pass
= get_pass_by_name (phase_name
);
1051 if (!pass
|| pass
->static_pass_number
== -1)
1054 error ("unknown pass %s specified in -fenable", phase_name
);
1056 error ("unknown pass %s specified in -fdisable", phase_name
);
1062 tab
= &enabled_pass_uid_range_tab
;
1064 tab
= &disabled_pass_uid_range_tab
;
1066 if ((unsigned) pass
->static_pass_number
>= tab
->length ())
1067 tab
->safe_grow_cleared (pass
->static_pass_number
+ 1);
1072 uid_range_p new_range
= XCNEW (struct uid_range
);
1074 new_range
->start
= 0;
1075 new_range
->last
= (unsigned)-1;
1077 slot
= (*tab
)[pass
->static_pass_number
];
1078 new_range
->next
= slot
;
1079 (*tab
)[pass
->static_pass_number
] = new_range
;
1081 inform (UNKNOWN_LOCATION
, "enable pass %s for functions in the range "
1082 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
1084 inform (UNKNOWN_LOCATION
, "disable pass %s for functions in the range "
1085 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
1089 char *next_range
= NULL
;
1090 char *one_range
= range_str
;
1091 char *end_val
= NULL
;
1096 uid_range_p new_range
;
1097 char *invalid
= NULL
;
1099 char *func_name
= NULL
;
1101 next_range
= strchr (one_range
, ',');
1108 end_val
= strchr (one_range
, ':');
1114 start
= strtol (one_range
, &invalid
, 10);
1115 if (*invalid
|| start
< 0)
1117 if (end_val
|| (one_range
[0] >= '0'
1118 && one_range
[0] <= '9'))
1120 error ("Invalid range %s in option %s",
1122 is_enable
? "-fenable" : "-fdisable");
1126 func_name
= one_range
;
1130 new_range
= XCNEW (struct uid_range
);
1133 new_range
->start
= (unsigned) start
;
1134 new_range
->last
= (unsigned) start
;
1138 new_range
->start
= (unsigned) -1;
1139 new_range
->last
= (unsigned) -1;
1140 new_range
->assem_name
= xstrdup (func_name
);
1145 long last
= strtol (end_val
, &invalid
, 10);
1146 if (*invalid
|| last
< start
)
1148 error ("Invalid range %s in option %s",
1150 is_enable
? "-fenable" : "-fdisable");
1154 new_range
= XCNEW (struct uid_range
);
1155 new_range
->start
= (unsigned) start
;
1156 new_range
->last
= (unsigned) last
;
1159 slot
= (*tab
)[pass
->static_pass_number
];
1160 new_range
->next
= slot
;
1161 (*tab
)[pass
->static_pass_number
] = new_range
;
1164 if (new_range
->assem_name
)
1165 inform (UNKNOWN_LOCATION
,
1166 "enable pass %s for function %s",
1167 phase_name
, new_range
->assem_name
);
1169 inform (UNKNOWN_LOCATION
,
1170 "enable pass %s for functions in the range of [%u, %u]",
1171 phase_name
, new_range
->start
, new_range
->last
);
1175 if (new_range
->assem_name
)
1176 inform (UNKNOWN_LOCATION
,
1177 "disable pass %s for function %s",
1178 phase_name
, new_range
->assem_name
);
1180 inform (UNKNOWN_LOCATION
,
1181 "disable pass %s for functions in the range of [%u, %u]",
1182 phase_name
, new_range
->start
, new_range
->last
);
1185 one_range
= next_range
;
1186 } while (next_range
);
1192 /* Enable pass specified by ARG. */
1195 enable_pass (const char *arg
)
1197 enable_disable_pass (arg
, true);
1200 /* Disable pass specified by ARG. */
1203 disable_pass (const char *arg
)
1205 enable_disable_pass (arg
, false);
1208 /* Returns true if PASS is explicitly enabled/disabled for FUNC. */
1211 is_pass_explicitly_enabled_or_disabled (opt_pass
*pass
,
1213 vec
<uid_range_p
> tab
)
1215 uid_range_p slot
, range
;
1217 const char *aname
= NULL
;
1220 || (unsigned) pass
->static_pass_number
>= tab
.length ()
1221 || pass
->static_pass_number
== -1)
1224 slot
= tab
[pass
->static_pass_number
];
1228 cgraph_uid
= func
? cgraph_node::get (func
)->uid
: 0;
1229 if (func
&& DECL_ASSEMBLER_NAME_SET_P (func
))
1230 aname
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func
));
1235 if ((unsigned) cgraph_uid
>= range
->start
1236 && (unsigned) cgraph_uid
<= range
->last
)
1238 if (range
->assem_name
&& aname
1239 && !strcmp (range
->assem_name
, aname
))
1241 range
= range
->next
;
1248 /* Update static_pass_number for passes (and the flag
1249 TODO_mark_first_instance).
1251 Passes are constructed with static_pass_number preinitialized to 0
1253 This field is used in two different ways: initially as instance numbers
1254 of their kind, and then as ids within the entire pass manager.
1256 Within pass_manager::pass_manager:
1258 * In add_pass_instance(), as called by next_pass_1 in
1259 NEXT_PASS in init_optimization_passes
1261 * When the initial instance of a pass within a pass manager is seen,
1262 it is flagged, and its static_pass_number is set to -1
1264 * On subsequent times that it is seen, the static pass number
1265 is decremented each time, so that if there are e.g. 4 dups,
1266 they have static_pass_number -4, 2, 3, 4 respectively (note
1267 how the initial one is negative and gives the count); these
1268 can be thought of as instance numbers of the specific pass
1270 * Within the register_dump_files () traversal, set_pass_for_id()
1271 is called on each pass, using these instance numbers to create
1272 dumpfile switches, and then overwriting them with a pass id,
1273 which are global to the whole pass manager (based on
1274 (TDI_end + current value of extra_dump_files_in_use) ) */
1277 add_pass_instance (opt_pass
*new_pass
, bool track_duplicates
,
1278 opt_pass
*initial_pass
)
1280 /* Are we dealing with the first pass of its kind, or a clone? */
1281 if (new_pass
!= initial_pass
)
1283 /* We're dealing with a clone. */
1284 new_pass
->todo_flags_start
&= ~TODO_mark_first_instance
;
1286 /* Indicate to register_dump_files that this pass has duplicates,
1287 and so it should rename the dump file. The first instance will
1288 be -1, and be number of duplicates = -static_pass_number - 1.
1289 Subsequent instances will be > 0 and just the duplicate number. */
1290 if ((new_pass
->name
&& new_pass
->name
[0] != '*') || track_duplicates
)
1292 initial_pass
->static_pass_number
-= 1;
1293 new_pass
->static_pass_number
= -initial_pass
->static_pass_number
;
1298 /* We're dealing with the first pass of its kind. */
1299 new_pass
->todo_flags_start
|= TODO_mark_first_instance
;
1300 new_pass
->static_pass_number
= -1;
1302 invoke_plugin_callbacks (PLUGIN_NEW_PASS
, new_pass
);
1306 /* Add a pass to the pass list. Duplicate the pass if it's already
1310 next_pass_1 (opt_pass
**list
, opt_pass
*pass
, opt_pass
*initial_pass
)
1312 /* Every pass should have a name so that plugins can refer to them. */
1313 gcc_assert (pass
->name
!= NULL
);
1315 add_pass_instance (pass
, false, initial_pass
);
1318 return &(*list
)->next
;
1321 /* List node for an inserted pass instance. We need to keep track of all
1322 the newly-added pass instances (with 'added_pass_nodes' defined below)
1323 so that we can register their dump files after pass-positioning is finished.
1324 Registering dumping files needs to be post-processed or the
1325 static_pass_number of the opt_pass object would be modified and mess up
1326 the dump file names of future pass instances to be added. */
1328 struct pass_list_node
1331 struct pass_list_node
*next
;
1334 static struct pass_list_node
*added_pass_nodes
= NULL
;
1335 static struct pass_list_node
*prev_added_pass_node
;
1337 /* Insert the pass at the proper position. Return true if the pass
1338 is successfully added.
1340 NEW_PASS_INFO - new pass to be inserted
1341 PASS_LIST - root of the pass list to insert the new pass to */
1344 position_pass (struct register_pass_info
*new_pass_info
, opt_pass
**pass_list
)
1346 opt_pass
*pass
= *pass_list
, *prev_pass
= NULL
;
1347 bool success
= false;
1349 for ( ; pass
; prev_pass
= pass
, pass
= pass
->next
)
1351 /* Check if the current pass is of the same type as the new pass and
1352 matches the name and the instance number of the reference pass. */
1353 if (pass
->type
== new_pass_info
->pass
->type
1355 && !strcmp (pass
->name
, new_pass_info
->reference_pass_name
)
1356 && ((new_pass_info
->ref_pass_instance_number
== 0)
1357 || (new_pass_info
->ref_pass_instance_number
==
1358 pass
->static_pass_number
)
1359 || (new_pass_info
->ref_pass_instance_number
== 1
1360 && pass
->todo_flags_start
& TODO_mark_first_instance
)))
1363 struct pass_list_node
*new_pass_node
;
1365 if (new_pass_info
->ref_pass_instance_number
== 0)
1367 new_pass
= new_pass_info
->pass
->clone ();
1368 add_pass_instance (new_pass
, true, new_pass_info
->pass
);
1372 new_pass
= new_pass_info
->pass
;
1373 add_pass_instance (new_pass
, true, new_pass
);
1376 /* Insert the new pass instance based on the positioning op. */
1377 switch (new_pass_info
->pos_op
)
1379 case PASS_POS_INSERT_AFTER
:
1380 new_pass
->next
= pass
->next
;
1381 pass
->next
= new_pass
;
1383 /* Skip newly inserted pass to avoid repeated
1384 insertions in the case where the new pass and the
1385 existing one have the same name. */
1388 case PASS_POS_INSERT_BEFORE
:
1389 new_pass
->next
= pass
;
1391 prev_pass
->next
= new_pass
;
1393 *pass_list
= new_pass
;
1395 case PASS_POS_REPLACE
:
1396 new_pass
->next
= pass
->next
;
1398 prev_pass
->next
= new_pass
;
1400 *pass_list
= new_pass
;
1401 new_pass
->sub
= pass
->sub
;
1402 new_pass
->tv_id
= pass
->tv_id
;
1406 error ("invalid pass positioning operation");
1410 /* Save the newly added pass (instance) in the added_pass_nodes
1411 list so that we can register its dump file later. Note that
1412 we cannot register the dump file now because doing so will modify
1413 the static_pass_number of the opt_pass object and therefore
1414 mess up the dump file name of future instances. */
1415 new_pass_node
= XCNEW (struct pass_list_node
);
1416 new_pass_node
->pass
= new_pass
;
1417 if (!added_pass_nodes
)
1418 added_pass_nodes
= new_pass_node
;
1420 prev_added_pass_node
->next
= new_pass_node
;
1421 prev_added_pass_node
= new_pass_node
;
1426 if (pass
->sub
&& position_pass (new_pass_info
, &pass
->sub
))
1433 /* Hooks a new pass into the pass lists.
1435 PASS_INFO - pass information that specifies the opt_pass object,
1436 reference pass, instance number, and how to position
1440 register_pass (struct register_pass_info
*pass_info
)
1442 g
->get_passes ()->register_pass (pass_info
);
1446 register_pass (opt_pass
* pass
, pass_positioning_ops pos
,
1447 const char* ref_pass_name
, int ref_pass_inst_number
)
1449 register_pass_info i
;
1451 i
.reference_pass_name
= ref_pass_name
;
1452 i
.ref_pass_instance_number
= ref_pass_inst_number
;
1455 g
->get_passes ()->register_pass (&i
);
1459 pass_manager::register_pass (struct register_pass_info
*pass_info
)
1461 bool all_instances
, success
;
1462 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
1464 /* The checks below could fail in buggy plugins. Existing GCC
1465 passes should never fail these checks, so we mention plugin in
1467 if (!pass_info
->pass
)
1468 fatal_error (input_location
, "plugin cannot register a missing pass");
1470 if (!pass_info
->pass
->name
)
1471 fatal_error (input_location
, "plugin cannot register an unnamed pass");
1473 if (!pass_info
->reference_pass_name
)
1476 "plugin cannot register pass %qs without reference pass name",
1477 pass_info
->pass
->name
);
1479 /* Try to insert the new pass to the pass lists. We need to check
1480 all five lists as the reference pass could be in one (or all) of
1482 all_instances
= pass_info
->ref_pass_instance_number
== 0;
1483 success
= position_pass (pass_info
, &all_lowering_passes
);
1484 if (!success
|| all_instances
)
1485 success
|= position_pass (pass_info
, &all_small_ipa_passes
);
1486 if (!success
|| all_instances
)
1487 success
|= position_pass (pass_info
, &all_regular_ipa_passes
);
1488 if (!success
|| all_instances
)
1489 success
|= position_pass (pass_info
, &all_late_ipa_passes
);
1490 if (!success
|| all_instances
)
1491 success
|= position_pass (pass_info
, &all_passes
);
1495 "pass %qs not found but is referenced by new pass %qs",
1496 pass_info
->reference_pass_name
, pass_info
->pass
->name
);
1498 /* OK, we have successfully inserted the new pass. We need to register
1499 the dump files for the newly added pass and its duplicates (if any).
1500 Because the registration of plugin/backend passes happens after the
1501 command-line options are parsed, the options that specify single
1502 pass dumping (e.g. -fdump-tree-PASSNAME) cannot be used for new
1503 passes. Therefore we currently can only enable dumping of
1504 new passes when the 'dump-all' flags (e.g. -fdump-tree-all)
1505 are specified. While doing so, we also delete the pass_list_node
1506 objects created during pass positioning. */
1507 while (added_pass_nodes
)
1509 struct pass_list_node
*next_node
= added_pass_nodes
->next
;
1510 enum tree_dump_index tdi
;
1511 register_one_dump_file (added_pass_nodes
->pass
);
1512 if (added_pass_nodes
->pass
->type
== SIMPLE_IPA_PASS
1513 || added_pass_nodes
->pass
->type
== IPA_PASS
)
1515 else if (added_pass_nodes
->pass
->type
== GIMPLE_PASS
)
1519 /* Check if dump-all flag is specified. */
1520 if (dumps
->get_dump_file_info (tdi
)->pstate
)
1521 dumps
->get_dump_file_info (added_pass_nodes
->pass
->static_pass_number
)
1522 ->pstate
= dumps
->get_dump_file_info (tdi
)->pstate
;
1523 XDELETE (added_pass_nodes
);
1524 added_pass_nodes
= next_node
;
1528 /* Construct the pass tree. The sequencing of passes is driven by
1529 the cgraph routines:
1531 finalize_compilation_unit ()
1532 for each node N in the cgraph
1533 cgraph_analyze_function (N)
1534 cgraph_lower_function (N) -> all_lowering_passes
1536 If we are optimizing, compile is then invoked:
1539 ipa_passes () -> all_small_ipa_passes
1540 -> Analysis of all_regular_ipa_passes
1541 * possible LTO streaming at copmilation time *
1542 -> Execution of all_regular_ipa_passes
1543 * possible LTO streaming at link time *
1544 -> all_late_ipa_passes
1545 expand_all_functions ()
1546 for each node N in the cgraph
1547 expand_function (N) -> Transformation of all_regular_ipa_passes
1552 pass_manager::operator new (size_t sz
)
1554 /* Ensure that all fields of the pass manager are zero-initialized. */
1555 return xcalloc (1, sz
);
1559 pass_manager::operator delete (void *ptr
)
1564 pass_manager::pass_manager (context
*ctxt
)
1565 : all_passes (NULL
), all_small_ipa_passes (NULL
), all_lowering_passes (NULL
),
1566 all_regular_ipa_passes (NULL
),
1567 all_late_ipa_passes (NULL
), passes_by_id (NULL
), passes_by_id_size (0),
1572 /* Initialize the pass_lists array. */
1573 #define DEF_PASS_LIST(LIST) pass_lists[PASS_LIST_NO_##LIST] = &LIST;
1575 #undef DEF_PASS_LIST
1577 /* Build the tree of passes. */
1579 #define INSERT_PASSES_AFTER(PASS) \
1582 #define PUSH_INSERT_PASSES_WITHIN(PASS) \
1584 opt_pass **p = &(PASS ## _1)->sub;
1586 #define POP_INSERT_PASSES() \
1589 #define NEXT_PASS(PASS, NUM) \
1591 gcc_assert (NULL == PASS ## _ ## NUM); \
1593 PASS ## _1 = make_##PASS (m_ctxt); \
1596 gcc_assert (PASS ## _1); \
1597 PASS ## _ ## NUM = PASS ## _1->clone (); \
1599 p = next_pass_1 (p, PASS ## _ ## NUM, PASS ## _1); \
1602 #define TERMINATE_PASS_LIST() \
1605 #include "pass-instances.def"
1607 #undef INSERT_PASSES_AFTER
1608 #undef PUSH_INSERT_PASSES_WITHIN
1609 #undef POP_INSERT_PASSES
1611 #undef TERMINATE_PASS_LIST
1613 /* Register the passes with the tree dump code. */
1614 register_dump_files (all_lowering_passes
);
1615 register_dump_files (all_small_ipa_passes
);
1616 register_dump_files (all_regular_ipa_passes
);
1617 register_dump_files (all_late_ipa_passes
);
1618 register_dump_files (all_passes
);
1622 delete_pass_tree (opt_pass
*pass
)
1626 /* Recurse into child passes. */
1627 delete_pass_tree (pass
->sub
);
1629 opt_pass
*next
= pass
->next
;
1631 /* Delete this pass. */
1634 /* Iterate onto sibling passes. */
1639 pass_manager::~pass_manager ()
1641 XDELETEVEC (passes_by_id
);
1643 /* Call delete_pass_tree on each of the pass_lists. */
1644 #define DEF_PASS_LIST(LIST) \
1645 delete_pass_tree (*pass_lists[PASS_LIST_NO_##LIST]);
1647 #undef DEF_PASS_LIST
1651 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1652 function CALLBACK for every function in the call graph. Otherwise,
1653 call CALLBACK on the current function. */
1656 do_per_function (void (*callback
) (function
*, void *data
), void *data
)
1658 if (current_function_decl
)
1659 callback (cfun
, data
);
1662 struct cgraph_node
*node
;
1663 FOR_EACH_DEFINED_FUNCTION (node
)
1664 if (node
->analyzed
&& (gimple_has_body_p (node
->decl
) && !in_lto_p
)
1665 && (!node
->clone_of
|| node
->decl
!= node
->clone_of
->decl
))
1666 callback (DECL_STRUCT_FUNCTION (node
->decl
), data
);
1670 /* Because inlining might remove no-longer reachable nodes, we need to
1671 keep the array visible to garbage collector to avoid reading collected
1674 static GTY ((length ("nnodes"))) cgraph_node
**order
;
1676 /* Hook called when NODE is removed and therefore should be
1677 excluded from order vector. DATA is an array of integers.
1678 DATA[0] holds max index it may be accessed by. For cgraph
1679 node DATA[node->uid + 1] holds index of this node in order
1682 remove_cgraph_node_from_order (cgraph_node
*node
, void *data
)
1684 int *order_idx
= (int *)data
;
1686 if (node
->uid
>= order_idx
[0])
1689 int idx
= order_idx
[node
->uid
+ 1];
1690 if (idx
>= 0 && idx
< nnodes
&& order
[idx
] == node
)
1694 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1695 function CALLBACK for every function in the call graph. Otherwise,
1696 call CALLBACK on the current function.
1697 This function is global so that plugins can use it. */
1699 do_per_function_toporder (void (*callback
) (function
*, void *data
), void *data
)
1703 if (current_function_decl
)
1704 callback (cfun
, data
);
1707 cgraph_node_hook_list
*hook
;
1709 gcc_assert (!order
);
1710 order
= ggc_vec_alloc
<cgraph_node
*> (symtab
->cgraph_count
);
1712 order_idx
= XALLOCAVEC (int, symtab
->cgraph_max_uid
+ 1);
1713 memset (order_idx
+ 1, -1, sizeof (int) * symtab
->cgraph_max_uid
);
1714 order_idx
[0] = symtab
->cgraph_max_uid
;
1716 nnodes
= ipa_reverse_postorder (order
);
1717 for (i
= nnodes
- 1; i
>= 0; i
--)
1719 order
[i
]->process
= 1;
1720 order_idx
[order
[i
]->uid
+ 1] = i
;
1722 hook
= symtab
->add_cgraph_removal_hook (remove_cgraph_node_from_order
,
1724 for (i
= nnodes
- 1; i
>= 0; i
--)
1726 /* Function could be inlined and removed as unreachable. */
1730 struct cgraph_node
*node
= order
[i
];
1732 /* Allow possibly removed nodes to be garbage collected. */
1735 if (node
->has_gimple_body_p ())
1736 callback (DECL_STRUCT_FUNCTION (node
->decl
), data
);
1738 symtab
->remove_cgraph_removal_hook (hook
);
1745 /* Helper function to perform function body dump. */
1748 execute_function_dump (function
*fn
, void *data
)
1750 opt_pass
*pass
= (opt_pass
*)data
;
1756 if (fn
->curr_properties
& PROP_trees
)
1757 dump_function_to_file (fn
->decl
, dump_file
, dump_flags
);
1759 print_rtl_with_bb (dump_file
, get_insns (), dump_flags
);
1761 /* Flush the file. If verification fails, we won't be able to
1762 close the file before aborting. */
1765 if ((fn
->curr_properties
& PROP_cfg
)
1766 && (dump_flags
& TDF_GRAPH
))
1768 if (!pass
->graph_dump_initialized
)
1770 clean_graph_dump_file (dump_file_name
);
1771 pass
->graph_dump_initialized
= true;
1773 print_graph_cfg (dump_file_name
, fn
);
1780 static struct profile_record
*profile_record
;
1782 /* Do profile consistency book-keeping for the pass with static number INDEX.
1783 If SUBPASS is zero, we run _before_ the pass, and if SUBPASS is one, then
1784 we run _after_ the pass. RUN is true if the pass really runs, or FALSE
1785 if we are only book-keeping on passes that may have selectively disabled
1786 themselves on a given function. */
1788 check_profile_consistency (int index
, int subpass
, bool run
)
1790 pass_manager
*passes
= g
->get_passes ();
1793 if (!profile_record
)
1794 profile_record
= XCNEWVEC (struct profile_record
,
1795 passes
->passes_by_id_size
);
1796 gcc_assert (index
< passes
->passes_by_id_size
&& index
>= 0);
1797 gcc_assert (subpass
< 2);
1798 profile_record
[index
].run
|= run
;
1799 account_profile_record (&profile_record
[index
], subpass
);
1802 /* Output profile consistency. */
1805 dump_profile_report (void)
1807 g
->get_passes ()->dump_profile_report ();
1811 pass_manager::dump_profile_report () const
1814 int last_freq_in
= 0, last_count_in
= 0, last_freq_out
= 0, last_count_out
= 0;
1815 gcov_type last_time
= 0, last_size
= 0;
1816 double rel_time_change
, rel_size_change
;
1817 int last_reported
= 0;
1819 if (!profile_record
)
1821 fprintf (stderr
, "\nProfile consistency report:\n\n");
1822 fprintf (stderr
, "Pass name |mismatch in |mismated out|Overall\n");
1823 fprintf (stderr
, " |freq count |freq count |size time\n");
1825 for (i
= 0; i
< passes_by_id_size
; i
++)
1826 for (j
= 0 ; j
< 2; j
++)
1827 if (profile_record
[i
].run
)
1830 rel_time_change
= (profile_record
[i
].time
[j
]
1831 - (double)last_time
) * 100 / (double)last_time
;
1833 rel_time_change
= 0;
1835 rel_size_change
= (profile_record
[i
].size
[j
]
1836 - (double)last_size
) * 100 / (double)last_size
;
1838 rel_size_change
= 0;
1840 if (profile_record
[i
].num_mismatched_freq_in
[j
] != last_freq_in
1841 || profile_record
[i
].num_mismatched_freq_out
[j
] != last_freq_out
1842 || profile_record
[i
].num_mismatched_count_in
[j
] != last_count_in
1843 || profile_record
[i
].num_mismatched_count_out
[j
] != last_count_out
1844 || rel_time_change
|| rel_size_change
)
1847 fprintf (stderr
, "%-20s %s",
1848 passes_by_id
[i
]->name
,
1849 j
? "(after TODO)" : " ");
1850 if (profile_record
[i
].num_mismatched_freq_in
[j
] != last_freq_in
)
1851 fprintf (stderr
, "| %+5i",
1852 profile_record
[i
].num_mismatched_freq_in
[j
]
1855 fprintf (stderr
, "| ");
1856 if (profile_record
[i
].num_mismatched_count_in
[j
] != last_count_in
)
1857 fprintf (stderr
, " %+5i",
1858 profile_record
[i
].num_mismatched_count_in
[j
]
1861 fprintf (stderr
, " ");
1862 if (profile_record
[i
].num_mismatched_freq_out
[j
] != last_freq_out
)
1863 fprintf (stderr
, "| %+5i",
1864 profile_record
[i
].num_mismatched_freq_out
[j
]
1867 fprintf (stderr
, "| ");
1868 if (profile_record
[i
].num_mismatched_count_out
[j
] != last_count_out
)
1869 fprintf (stderr
, " %+5i",
1870 profile_record
[i
].num_mismatched_count_out
[j
]
1873 fprintf (stderr
, " ");
1875 /* Size/time units change across gimple and RTL. */
1876 if (i
== pass_expand_1
->static_pass_number
)
1877 fprintf (stderr
, "|----------");
1880 if (rel_size_change
)
1881 fprintf (stderr
, "| %+8.4f%%", rel_size_change
);
1883 fprintf (stderr
, "| ");
1884 if (rel_time_change
)
1885 fprintf (stderr
, " %+8.4f%%", rel_time_change
);
1887 fprintf (stderr
, "\n");
1888 last_freq_in
= profile_record
[i
].num_mismatched_freq_in
[j
];
1889 last_freq_out
= profile_record
[i
].num_mismatched_freq_out
[j
];
1890 last_count_in
= profile_record
[i
].num_mismatched_count_in
[j
];
1891 last_count_out
= profile_record
[i
].num_mismatched_count_out
[j
];
1893 else if (j
&& last_reported
!= i
)
1896 fprintf (stderr
, "%-20s ------------| | |\n",
1897 passes_by_id
[i
]->name
);
1899 last_time
= profile_record
[i
].time
[j
];
1900 last_size
= profile_record
[i
].size
[j
];
1904 /* Perform all TODO actions that ought to be done on each function. */
1907 execute_function_todo (function
*fn
, void *data
)
1909 bool from_ipa_pass
= (cfun
== NULL
);
1910 unsigned int flags
= (size_t)data
;
1911 flags
&= ~fn
->last_verified
;
1917 /* Always cleanup the CFG before trying to update SSA. */
1918 if (flags
& TODO_cleanup_cfg
)
1920 cleanup_tree_cfg ();
1922 /* When cleanup_tree_cfg merges consecutive blocks, it may
1923 perform some simplistic propagation when removing single
1924 valued PHI nodes. This propagation may, in turn, cause the
1925 SSA form to become out-of-date (see PR 22037). So, even
1926 if the parent pass had not scheduled an SSA update, we may
1927 still need to do one. */
1928 if (!(flags
& TODO_update_ssa_any
) && need_ssa_update_p (cfun
))
1929 flags
|= TODO_update_ssa
;
1932 if (flags
& TODO_update_ssa_any
)
1934 unsigned update_flags
= flags
& TODO_update_ssa_any
;
1935 update_ssa (update_flags
);
1938 if (flag_tree_pta
&& (flags
& TODO_rebuild_alias
))
1939 compute_may_aliases ();
1941 if (optimize
&& (flags
& TODO_update_address_taken
))
1942 execute_update_addresses_taken ();
1944 if (flags
& TODO_remove_unused_locals
)
1945 remove_unused_locals ();
1947 if (flags
& TODO_rebuild_frequencies
)
1948 rebuild_frequencies ();
1950 if (flags
& TODO_rebuild_cgraph_edges
)
1951 cgraph_edge::rebuild_edges ();
1953 gcc_assert (dom_info_state (fn
, CDI_POST_DOMINATORS
) == DOM_NONE
);
1954 /* If we've seen errors do not bother running any verifiers. */
1955 if (flag_checking
&& !seen_error ())
1957 dom_state pre_verify_state
= dom_info_state (fn
, CDI_DOMINATORS
);
1958 dom_state pre_verify_pstate
= dom_info_state (fn
, CDI_POST_DOMINATORS
);
1960 if (flags
& TODO_verify_il
)
1962 if (cfun
->curr_properties
& PROP_trees
)
1964 if (cfun
->curr_properties
& PROP_cfg
)
1965 /* IPA passes leave stmts to be fixed up, so make sure to
1966 not verify stmts really throw. */
1967 verify_gimple_in_cfg (cfun
, !from_ipa_pass
);
1969 verify_gimple_in_seq (gimple_body (cfun
->decl
));
1971 if (cfun
->curr_properties
& PROP_ssa
)
1972 /* IPA passes leave stmts to be fixed up, so make sure to
1973 not verify SSA operands whose verifier will choke on that. */
1974 verify_ssa (true, !from_ipa_pass
);
1975 /* IPA passes leave basic-blocks unsplit, so make sure to
1976 not trip on that. */
1977 if ((cfun
->curr_properties
& PROP_cfg
)
1979 verify_flow_info ();
1981 && loops_state_satisfies_p (LOOP_CLOSED_SSA
))
1982 verify_loop_closed_ssa (false);
1983 if (cfun
->curr_properties
& PROP_rtl
)
1984 verify_rtl_sharing ();
1987 /* Make sure verifiers don't change dominator state. */
1988 gcc_assert (dom_info_state (fn
, CDI_DOMINATORS
) == pre_verify_state
);
1989 gcc_assert (dom_info_state (fn
, CDI_POST_DOMINATORS
) == pre_verify_pstate
);
1992 fn
->last_verified
= flags
& TODO_verify_all
;
1996 /* For IPA passes make sure to release dominator info, it can be
1997 computed by non-verifying TODOs. */
2000 free_dominance_info (fn
, CDI_DOMINATORS
);
2001 free_dominance_info (fn
, CDI_POST_DOMINATORS
);
2005 /* Perform all TODO actions. */
2007 execute_todo (unsigned int flags
)
2011 && need_ssa_update_p (cfun
))
2012 gcc_assert (flags
& TODO_update_ssa_any
);
2014 timevar_push (TV_TODO
);
2016 /* Inform the pass whether it is the first time it is run. */
2017 first_pass_instance
= (flags
& TODO_mark_first_instance
) != 0;
2019 statistics_fini_pass ();
2022 do_per_function (execute_function_todo
, (void *)(size_t) flags
);
2024 /* At this point we should not have any unreachable code in the
2025 CFG, so it is safe to flush the pending freelist for SSA_NAMES. */
2026 if (cfun
&& cfun
->gimple_df
)
2027 flush_ssaname_freelist ();
2029 /* Always remove functions just as before inlining: IPA passes might be
2030 interested to see bodies of extern inline functions that are not inlined
2031 to analyze side effects. The full removal is done just at the end
2032 of IPA pass queue. */
2033 if (flags
& TODO_remove_functions
)
2036 symtab
->remove_unreachable_nodes (dump_file
);
2039 if ((flags
& TODO_dump_symtab
) && dump_file
&& !current_function_decl
)
2042 symtab_node::dump_table (dump_file
);
2043 /* Flush the file. If verification fails, we won't be able to
2044 close the file before aborting. */
2048 /* Now that the dumping has been done, we can get rid of the optional
2050 if (flags
& TODO_df_finish
)
2051 df_finish_pass ((flags
& TODO_df_verify
) != 0);
2053 timevar_pop (TV_TODO
);
2056 /* Verify invariants that should hold between passes. This is a place
2057 to put simple sanity checks. */
2060 verify_interpass_invariants (void)
2062 gcc_checking_assert (!fold_deferring_overflow_warnings_p ());
2065 /* Clear the last verified flag. */
2068 clear_last_verified (function
*fn
, void *data ATTRIBUTE_UNUSED
)
2070 fn
->last_verified
= 0;
2073 /* Helper function. Verify that the properties has been turn into the
2074 properties expected by the pass. */
2076 static void DEBUG_FUNCTION
2077 verify_curr_properties (function
*fn
, void *data
)
2079 unsigned int props
= (size_t)data
;
2080 gcc_assert ((fn
->curr_properties
& props
) == props
);
2083 /* Initialize pass dump file. */
2084 /* This is non-static so that the plugins can use it. */
2087 pass_init_dump_file (opt_pass
*pass
)
2089 /* If a dump file name is present, open it if enabled. */
2090 if (pass
->static_pass_number
!= -1)
2092 timevar_push (TV_DUMP
);
2093 gcc::dump_manager
*dumps
= g
->get_dumps ();
2094 bool initializing_dump
=
2095 !dumps
->dump_initialized_p (pass
->static_pass_number
);
2096 dump_file_name
= dumps
->get_dump_file_name (pass
->static_pass_number
);
2097 dumps
->dump_start (pass
->static_pass_number
, &dump_flags
);
2098 if (dump_file
&& current_function_decl
)
2099 dump_function_header (dump_file
, current_function_decl
, dump_flags
);
2100 if (initializing_dump
2101 && dump_file
&& (dump_flags
& TDF_GRAPH
)
2102 && cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2104 clean_graph_dump_file (dump_file_name
);
2105 pass
->graph_dump_initialized
= true;
2107 timevar_pop (TV_DUMP
);
2108 return initializing_dump
;
2114 /* Flush PASS dump file. */
2115 /* This is non-static so that plugins can use it. */
2118 pass_fini_dump_file (opt_pass
*pass
)
2120 timevar_push (TV_DUMP
);
2122 /* Flush and close dump file. */
2125 free (CONST_CAST (char *, dump_file_name
));
2126 dump_file_name
= NULL
;
2129 g
->get_dumps ()->dump_finish (pass
->static_pass_number
);
2130 timevar_pop (TV_DUMP
);
2133 /* After executing the pass, apply expected changes to the function
2137 update_properties_after_pass (function
*fn
, void *data
)
2139 opt_pass
*pass
= (opt_pass
*) data
;
2140 fn
->curr_properties
= (fn
->curr_properties
| pass
->properties_provided
)
2141 & ~pass
->properties_destroyed
;
2144 /* Execute summary generation for all of the passes in IPA_PASS. */
2147 execute_ipa_summary_passes (ipa_opt_pass_d
*ipa_pass
)
2151 opt_pass
*pass
= ipa_pass
;
2153 /* Execute all of the IPA_PASSes in the list. */
2154 if (ipa_pass
->type
== IPA_PASS
2155 && pass
->gate (cfun
)
2156 && ipa_pass
->generate_summary
)
2158 pass_init_dump_file (pass
);
2160 /* If a timevar is present, start it. */
2162 timevar_push (pass
->tv_id
);
2164 current_pass
= pass
;
2165 ipa_pass
->generate_summary ();
2169 timevar_pop (pass
->tv_id
);
2171 pass_fini_dump_file (pass
);
2173 ipa_pass
= (ipa_opt_pass_d
*)ipa_pass
->next
;
2177 /* Execute IPA_PASS function transform on NODE. */
2180 execute_one_ipa_transform_pass (struct cgraph_node
*node
,
2181 ipa_opt_pass_d
*ipa_pass
)
2183 opt_pass
*pass
= ipa_pass
;
2184 unsigned int todo_after
= 0;
2186 current_pass
= pass
;
2187 if (!ipa_pass
->function_transform
)
2190 /* Note that the folders should only create gimple expressions.
2191 This is a hack until the new folder is ready. */
2192 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
2194 pass_init_dump_file (pass
);
2196 /* Run pre-pass verification. */
2197 execute_todo (ipa_pass
->function_transform_todo_flags_start
);
2199 /* If a timevar is present, start it. */
2200 if (pass
->tv_id
!= TV_NONE
)
2201 timevar_push (pass
->tv_id
);
2204 todo_after
= ipa_pass
->function_transform (node
);
2207 if (pass
->tv_id
!= TV_NONE
)
2208 timevar_pop (pass
->tv_id
);
2210 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2211 check_profile_consistency (pass
->static_pass_number
, 0, true);
2213 /* Run post-pass cleanup and verification. */
2214 execute_todo (todo_after
);
2215 verify_interpass_invariants ();
2216 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2217 check_profile_consistency (pass
->static_pass_number
, 1, true);
2220 do_per_function (execute_function_dump
, NULL
);
2221 pass_fini_dump_file (pass
);
2223 current_pass
= NULL
;
2225 /* Signal this is a suitable GC collection point. */
2226 if (!(todo_after
& TODO_do_not_ggc_collect
))
2230 /* For the current function, execute all ipa transforms. */
2233 execute_all_ipa_transforms (void)
2235 struct cgraph_node
*node
;
2238 node
= cgraph_node::get (current_function_decl
);
2240 if (node
->ipa_transforms_to_apply
.exists ())
2244 for (i
= 0; i
< node
->ipa_transforms_to_apply
.length (); i
++)
2245 execute_one_ipa_transform_pass (node
, node
->ipa_transforms_to_apply
[i
]);
2246 node
->ipa_transforms_to_apply
.release ();
2250 /* Check if PASS is explicitly disabled or enabled and return
2251 the gate status. FUNC is the function to be processed, and
2252 GATE_STATUS is the gate status determined by pass manager by
2256 override_gate_status (opt_pass
*pass
, tree func
, bool gate_status
)
2258 bool explicitly_enabled
= false;
2259 bool explicitly_disabled
= false;
2262 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2263 enabled_pass_uid_range_tab
);
2265 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2266 disabled_pass_uid_range_tab
);
2268 gate_status
= !explicitly_disabled
&& (gate_status
|| explicitly_enabled
);
2277 execute_one_pass (opt_pass
*pass
)
2279 unsigned int todo_after
= 0;
2283 /* IPA passes are executed on whole program, so cfun should be NULL.
2284 Other passes need function context set. */
2285 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
2286 gcc_assert (!cfun
&& !current_function_decl
);
2288 gcc_assert (cfun
&& current_function_decl
);
2290 current_pass
= pass
;
2292 /* Check whether gate check should be avoided.
2293 User controls the value of the gate through the parameter "gate_status". */
2294 gate_status
= pass
->gate (cfun
);
2295 gate_status
= override_gate_status (pass
, current_function_decl
, gate_status
);
2297 /* Override gate with plugin. */
2298 invoke_plugin_callbacks (PLUGIN_OVERRIDE_GATE
, &gate_status
);
2302 /* Run so passes selectively disabling themselves on a given function
2303 are not miscounted. */
2304 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2306 check_profile_consistency (pass
->static_pass_number
, 0, false);
2307 check_profile_consistency (pass
->static_pass_number
, 1, false);
2309 current_pass
= NULL
;
2313 /* Pass execution event trigger: useful to identify passes being
2315 invoke_plugin_callbacks (PLUGIN_PASS_EXECUTION
, pass
);
2317 if (!quiet_flag
&& !cfun
)
2318 fprintf (stderr
, " <%s>", pass
->name
? pass
->name
: "");
2320 /* Note that the folders should only create gimple expressions.
2321 This is a hack until the new folder is ready. */
2322 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
2324 pass_init_dump_file (pass
);
2326 /* Run pre-pass verification. */
2327 execute_todo (pass
->todo_flags_start
);
2330 do_per_function (verify_curr_properties
,
2331 (void *)(size_t)pass
->properties_required
);
2333 /* If a timevar is present, start it. */
2334 if (pass
->tv_id
!= TV_NONE
)
2335 timevar_push (pass
->tv_id
);
2338 todo_after
= pass
->execute (cfun
);
2339 do_per_function (clear_last_verified
, NULL
);
2342 if (pass
->tv_id
!= TV_NONE
)
2343 timevar_pop (pass
->tv_id
);
2345 do_per_function (update_properties_after_pass
, pass
);
2347 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2348 check_profile_consistency (pass
->static_pass_number
, 0, true);
2350 /* Run post-pass cleanup and verification. */
2351 execute_todo (todo_after
| pass
->todo_flags_finish
| TODO_verify_il
);
2352 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2353 check_profile_consistency (pass
->static_pass_number
, 1, true);
2355 verify_interpass_invariants ();
2357 do_per_function (execute_function_dump
, pass
);
2358 if (pass
->type
== IPA_PASS
)
2360 struct cgraph_node
*node
;
2361 if (((ipa_opt_pass_d
*)pass
)->function_transform
)
2362 FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node
)
2363 node
->ipa_transforms_to_apply
.safe_push ((ipa_opt_pass_d
*)pass
);
2366 if (!current_function_decl
)
2367 symtab
->process_new_functions ();
2369 pass_fini_dump_file (pass
);
2371 if (pass
->type
!= SIMPLE_IPA_PASS
&& pass
->type
!= IPA_PASS
)
2372 gcc_assert (!(cfun
->curr_properties
& PROP_trees
)
2373 || pass
->type
!= RTL_PASS
);
2375 current_pass
= NULL
;
2377 /* Signal this is a suitable GC collection point. */
2378 if (!((todo_after
| pass
->todo_flags_finish
) & TODO_do_not_ggc_collect
))
2385 execute_pass_list_1 (opt_pass
*pass
)
2389 gcc_assert (pass
->type
== GIMPLE_PASS
2390 || pass
->type
== RTL_PASS
);
2391 if (execute_one_pass (pass
) && pass
->sub
)
2392 execute_pass_list_1 (pass
->sub
);
2399 execute_pass_list (function
*fn
, opt_pass
*pass
)
2402 execute_pass_list_1 (pass
);
2405 free_dominance_info (CDI_DOMINATORS
);
2406 free_dominance_info (CDI_POST_DOMINATORS
);
2411 /* Write out all LTO data. */
2415 timevar_push (TV_IPA_LTO_GIMPLE_OUT
);
2417 timevar_pop (TV_IPA_LTO_GIMPLE_OUT
);
2418 timevar_push (TV_IPA_LTO_DECL_OUT
);
2419 produce_asm_for_decls ();
2420 timevar_pop (TV_IPA_LTO_DECL_OUT
);
2423 /* Same as execute_pass_list but assume that subpasses of IPA passes
2424 are local passes. If SET is not NULL, write out summaries of only
2425 those node in SET. */
2428 ipa_write_summaries_2 (opt_pass
*pass
, struct lto_out_decl_state
*state
)
2432 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*)pass
;
2433 gcc_assert (!current_function_decl
);
2435 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2436 if (pass
->type
== IPA_PASS
2437 && ipa_pass
->write_summary
2438 && pass
->gate (cfun
))
2440 /* If a timevar is present, start it. */
2442 timevar_push (pass
->tv_id
);
2444 pass_init_dump_file (pass
);
2446 current_pass
= pass
;
2447 ipa_pass
->write_summary ();
2449 pass_fini_dump_file (pass
);
2451 /* If a timevar is present, start it. */
2453 timevar_pop (pass
->tv_id
);
2456 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2457 ipa_write_summaries_2 (pass
->sub
, state
);
2463 /* Helper function of ipa_write_summaries. Creates and destroys the
2464 decl state and calls ipa_write_summaries_2 for all passes that have
2465 summaries. SET is the set of nodes to be written. */
2468 ipa_write_summaries_1 (lto_symtab_encoder_t encoder
)
2470 pass_manager
*passes
= g
->get_passes ();
2471 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2472 state
->symtab_node_encoder
= encoder
;
2474 lto_output_init_mode_table ();
2475 lto_push_out_decl_state (state
);
2477 gcc_assert (!flag_wpa
);
2478 ipa_write_summaries_2 (passes
->all_regular_ipa_passes
, state
);
2482 gcc_assert (lto_get_out_decl_state () == state
);
2483 lto_pop_out_decl_state ();
2484 lto_delete_out_decl_state (state
);
2487 /* Write out summaries for all the nodes in the callgraph. */
2490 ipa_write_summaries (void)
2492 lto_symtab_encoder_t encoder
;
2494 varpool_node
*vnode
;
2495 struct cgraph_node
*node
;
2496 struct cgraph_node
**order
;
2498 if ((!flag_generate_lto
&& !flag_generate_offload
) || seen_error ())
2501 select_what_to_stream ();
2503 encoder
= lto_symtab_encoder_new (false);
2505 /* Create the callgraph set in the same order used in
2506 cgraph_expand_all_functions. This mostly facilitates debugging,
2507 since it causes the gimple file to be processed in the same order
2508 as the source code. */
2509 order
= XCNEWVEC (struct cgraph_node
*, symtab
->cgraph_count
);
2510 order_pos
= ipa_reverse_postorder (order
);
2511 gcc_assert (order_pos
== symtab
->cgraph_count
);
2513 for (i
= order_pos
- 1; i
>= 0; i
--)
2515 struct cgraph_node
*node
= order
[i
];
2517 if (node
->has_gimple_body_p ())
2519 /* When streaming out references to statements as part of some IPA
2520 pass summary, the statements need to have uids assigned and the
2521 following does that for all the IPA passes here. Naturally, this
2522 ordering then matches the one IPA-passes get in their stmt_fixup
2525 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
2526 renumber_gimple_stmt_uids ();
2529 if (node
->definition
&& node
->need_lto_streaming
)
2530 lto_set_symtab_encoder_in_partition (encoder
, node
);
2533 FOR_EACH_DEFINED_FUNCTION (node
)
2534 if (node
->alias
&& node
->need_lto_streaming
)
2535 lto_set_symtab_encoder_in_partition (encoder
, node
);
2536 FOR_EACH_DEFINED_VARIABLE (vnode
)
2537 if (vnode
->need_lto_streaming
)
2538 lto_set_symtab_encoder_in_partition (encoder
, vnode
);
2540 ipa_write_summaries_1 (compute_ltrans_boundary (encoder
));
2545 /* Same as execute_pass_list but assume that subpasses of IPA passes
2546 are local passes. If SET is not NULL, write out optimization summaries of
2547 only those node in SET. */
2550 ipa_write_optimization_summaries_1 (opt_pass
*pass
,
2551 struct lto_out_decl_state
*state
)
2555 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*)pass
;
2556 gcc_assert (!current_function_decl
);
2558 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2559 if (pass
->type
== IPA_PASS
2560 && ipa_pass
->write_optimization_summary
2561 && pass
->gate (cfun
))
2563 /* If a timevar is present, start it. */
2565 timevar_push (pass
->tv_id
);
2567 pass_init_dump_file (pass
);
2569 current_pass
= pass
;
2570 ipa_pass
->write_optimization_summary ();
2572 pass_fini_dump_file (pass
);
2574 /* If a timevar is present, start it. */
2576 timevar_pop (pass
->tv_id
);
2579 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2580 ipa_write_optimization_summaries_1 (pass
->sub
, state
);
2586 /* Write all the optimization summaries for the cgraph nodes in SET. If SET is
2587 NULL, write out all summaries of all nodes. */
2590 ipa_write_optimization_summaries (lto_symtab_encoder_t encoder
)
2592 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2593 lto_symtab_encoder_iterator lsei
;
2594 state
->symtab_node_encoder
= encoder
;
2596 lto_output_init_mode_table ();
2597 lto_push_out_decl_state (state
);
2598 for (lsei
= lsei_start_function_in_partition (encoder
);
2599 !lsei_end_p (lsei
); lsei_next_function_in_partition (&lsei
))
2601 struct cgraph_node
*node
= lsei_cgraph_node (lsei
);
2602 /* When streaming out references to statements as part of some IPA
2603 pass summary, the statements need to have uids assigned.
2605 For functions newly born at WPA stage we need to initialize
2607 if (node
->definition
2608 && gimple_has_body_p (node
->decl
))
2610 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
2611 renumber_gimple_stmt_uids ();
2616 gcc_assert (flag_wpa
);
2617 pass_manager
*passes
= g
->get_passes ();
2618 ipa_write_optimization_summaries_1 (passes
->all_regular_ipa_passes
, state
);
2622 gcc_assert (lto_get_out_decl_state () == state
);
2623 lto_pop_out_decl_state ();
2624 lto_delete_out_decl_state (state
);
2627 /* Same as execute_pass_list but assume that subpasses of IPA passes
2628 are local passes. */
2631 ipa_read_summaries_1 (opt_pass
*pass
)
2635 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
2637 gcc_assert (!current_function_decl
);
2639 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2641 if (pass
->gate (cfun
))
2643 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_summary
)
2645 /* If a timevar is present, start it. */
2647 timevar_push (pass
->tv_id
);
2649 pass_init_dump_file (pass
);
2651 current_pass
= pass
;
2652 ipa_pass
->read_summary ();
2654 pass_fini_dump_file (pass
);
2658 timevar_pop (pass
->tv_id
);
2661 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2662 ipa_read_summaries_1 (pass
->sub
);
2669 /* Read all the summaries for all_regular_ipa_passes. */
2672 ipa_read_summaries (void)
2674 pass_manager
*passes
= g
->get_passes ();
2675 ipa_read_summaries_1 (passes
->all_regular_ipa_passes
);
2678 /* Same as execute_pass_list but assume that subpasses of IPA passes
2679 are local passes. */
2682 ipa_read_optimization_summaries_1 (opt_pass
*pass
)
2686 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
2688 gcc_assert (!current_function_decl
);
2690 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2692 if (pass
->gate (cfun
))
2694 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_optimization_summary
)
2696 /* If a timevar is present, start it. */
2698 timevar_push (pass
->tv_id
);
2700 pass_init_dump_file (pass
);
2702 current_pass
= pass
;
2703 ipa_pass
->read_optimization_summary ();
2705 pass_fini_dump_file (pass
);
2709 timevar_pop (pass
->tv_id
);
2712 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2713 ipa_read_optimization_summaries_1 (pass
->sub
);
2719 /* Read all the summaries for all_regular_ipa_passes. */
2722 ipa_read_optimization_summaries (void)
2724 pass_manager
*passes
= g
->get_passes ();
2725 ipa_read_optimization_summaries_1 (passes
->all_regular_ipa_passes
);
2728 /* Same as execute_pass_list but assume that subpasses of IPA passes
2729 are local passes. */
2731 execute_ipa_pass_list (opt_pass
*pass
)
2735 gcc_assert (!current_function_decl
);
2737 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2738 if (execute_one_pass (pass
) && pass
->sub
)
2740 if (pass
->sub
->type
== GIMPLE_PASS
)
2742 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_START
, NULL
);
2743 do_per_function_toporder ((void (*)(function
*, void *))
2746 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_END
, NULL
);
2748 else if (pass
->sub
->type
== SIMPLE_IPA_PASS
2749 || pass
->sub
->type
== IPA_PASS
)
2750 execute_ipa_pass_list (pass
->sub
);
2754 gcc_assert (!current_function_decl
);
2755 symtab
->process_new_functions ();
2761 /* Execute stmt fixup hooks of all passes in PASS for NODE and STMTS. */
2764 execute_ipa_stmt_fixups (opt_pass
*pass
,
2765 struct cgraph_node
*node
, gimple
**stmts
)
2769 /* Execute all of the IPA_PASSes in the list. */
2770 if (pass
->type
== IPA_PASS
2771 && pass
->gate (cfun
))
2773 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
2775 if (ipa_pass
->stmt_fixup
)
2777 pass_init_dump_file (pass
);
2778 /* If a timevar is present, start it. */
2780 timevar_push (pass
->tv_id
);
2782 current_pass
= pass
;
2783 ipa_pass
->stmt_fixup (node
, stmts
);
2787 timevar_pop (pass
->tv_id
);
2788 pass_fini_dump_file (pass
);
2791 execute_ipa_stmt_fixups (pass
->sub
, node
, stmts
);
2797 /* Execute stmt fixup hooks of all IPA passes for NODE and STMTS. */
2800 execute_all_ipa_stmt_fixups (struct cgraph_node
*node
, gimple
**stmts
)
2802 pass_manager
*passes
= g
->get_passes ();
2803 execute_ipa_stmt_fixups (passes
->all_regular_ipa_passes
, node
, stmts
);
2807 extern void debug_properties (unsigned int);
2808 extern void dump_properties (FILE *, unsigned int);
2811 dump_properties (FILE *dump
, unsigned int props
)
2813 fprintf (dump
, "Properties:\n");
2814 if (props
& PROP_gimple_any
)
2815 fprintf (dump
, "PROP_gimple_any\n");
2816 if (props
& PROP_gimple_lcf
)
2817 fprintf (dump
, "PROP_gimple_lcf\n");
2818 if (props
& PROP_gimple_leh
)
2819 fprintf (dump
, "PROP_gimple_leh\n");
2820 if (props
& PROP_cfg
)
2821 fprintf (dump
, "PROP_cfg\n");
2822 if (props
& PROP_ssa
)
2823 fprintf (dump
, "PROP_ssa\n");
2824 if (props
& PROP_no_crit_edges
)
2825 fprintf (dump
, "PROP_no_crit_edges\n");
2826 if (props
& PROP_rtl
)
2827 fprintf (dump
, "PROP_rtl\n");
2828 if (props
& PROP_gimple_lomp
)
2829 fprintf (dump
, "PROP_gimple_lomp\n");
2830 if (props
& PROP_gimple_lcx
)
2831 fprintf (dump
, "PROP_gimple_lcx\n");
2832 if (props
& PROP_gimple_lvec
)
2833 fprintf (dump
, "PROP_gimple_lvec\n");
2834 if (props
& PROP_cfglayout
)
2835 fprintf (dump
, "PROP_cfglayout\n");
2839 debug_properties (unsigned int props
)
2841 dump_properties (stderr
, props
);
2844 /* Called by local passes to see if function is called by already processed nodes.
2845 Because we process nodes in topological order, this means that function is
2846 in recursive cycle or we introduced new direct calls. */
2848 function_called_by_processed_nodes_p (void)
2850 struct cgraph_edge
*e
;
2851 for (e
= cgraph_node::get (current_function_decl
)->callers
;
2855 if (e
->caller
->decl
== current_function_decl
)
2857 if (!e
->caller
->has_gimple_body_p ())
2859 if (TREE_ASM_WRITTEN (e
->caller
->decl
))
2861 if (!e
->caller
->process
&& !e
->caller
->global
.inlined_to
)
2866 fprintf (dump_file
, "Already processed call to:\n");
2867 e
->caller
->dump (dump_file
);
2872 #include "gt-passes.h"