1 /* Top level of GCC compilers (cc1, cc1plus, etc.)
2 Copyright (C) 1987-2018 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 /* This is the top level of cc1/c++.
21 It parses command args, opens files, invokes the various passes
22 in the proper order, and counts the time used by each.
23 Error messages and low-level interface to malloc also handled here. */
27 #include "coretypes.h"
40 #include "lto-streamer.h"
41 #include "fold-const.h"
47 #include "value-prof.h"
49 #include "tree-ssa-loop-manip.h"
50 #include "tree-into-ssa.h"
53 #include "tree-pass.h"
55 #include "ipa-utils.h"
56 #include "tree-pretty-print.h" /* for dump_function_header */
58 #include "pass_manager.h"
60 #include "tree-ssa-live.h" /* For remove_unused_locals. */
61 #include "tree-cfgcleanup.h"
62 #include "insn-addr.h" /* for INSN_ADDRESSES_ALLOC. */
63 #include "diagnostic-core.h" /* for fnotice */
64 #include "stringpool.h"
69 /* This is used for debugging. It allows the current pass to printed
70 from anywhere in compilation.
71 The variable current_pass is also used for statistics and plugins. */
72 opt_pass
*current_pass
;
74 /* Most passes are single-instance (within their context) and thus don't
75 need to implement cloning, but passes that support multiple instances
76 *must* provide their own implementation of the clone method.
78 Handle this by providing a default implemenation, but make it a fatal
84 internal_error ("pass %s does not support cloning", name
);
88 opt_pass::set_pass_param (unsigned int, bool)
90 internal_error ("pass %s needs a set_pass_param implementation to handle the"
91 " extra argument in NEXT_PASS", name
);
95 opt_pass::gate (function
*)
101 opt_pass::execute (function
*)
106 opt_pass::opt_pass (const pass_data
&data
, context
*ctxt
)
110 static_pass_number (0),
117 pass_manager::execute_early_local_passes ()
119 execute_pass_list (cfun
, pass_build_ssa_passes_1
->sub
);
120 execute_pass_list (cfun
, pass_local_optimization_passes_1
->sub
);
124 pass_manager::execute_pass_mode_switching ()
126 return pass_mode_switching_1
->execute (cfun
);
130 /* Call from anywhere to find out what pass this is. Useful for
131 printing out debugging information deep inside an service
134 print_current_pass (FILE *file
)
137 fprintf (file
, "current pass = %s (%d)\n",
138 current_pass
->name
, current_pass
->static_pass_number
);
140 fprintf (file
, "no current pass.\n");
144 /* Call from the debugger to get the current pass name. */
148 print_current_pass (stderr
);
153 /* Global variables used to communicate with passes. */
157 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
160 This does nothing for local (non-static) variables, unless the
161 variable is a register variable with DECL_ASSEMBLER_NAME set. In
162 that case, or if the variable is not an automatic, it sets up the
163 RTL and outputs any assembler code (label definition, storage
164 allocation and initialization).
166 DECL is the declaration. TOP_LEVEL is nonzero
167 if this declaration is not within a function. */
170 rest_of_decl_compilation (tree decl
,
174 bool finalize
= true;
176 /* We deferred calling assemble_alias so that we could collect
177 other attributes such as visibility. Emit the alias now. */
181 alias
= lookup_attribute ("alias", DECL_ATTRIBUTES (decl
));
184 alias
= TREE_VALUE (TREE_VALUE (alias
));
185 alias
= get_identifier (TREE_STRING_POINTER (alias
));
186 /* A quirk of the initial implementation of aliases required that the
187 user add "extern" to all of them. Which is silly, but now
188 historical. Do note that the symbol is in fact locally defined. */
189 DECL_EXTERNAL (decl
) = 0;
190 TREE_STATIC (decl
) = 1;
191 assemble_alias (decl
, alias
);
196 /* Can't defer this, because it needs to happen before any
197 later function definitions are processed. */
198 if (HAS_DECL_ASSEMBLER_NAME_P (decl
)
199 && DECL_ASSEMBLER_NAME_SET_P (decl
)
200 && DECL_REGISTER (decl
))
201 make_decl_rtl (decl
);
203 /* Forward declarations for nested functions are not "external",
204 but we need to treat them as if they were. */
205 if (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)
206 || TREE_CODE (decl
) == FUNCTION_DECL
)
208 timevar_push (TV_VARCONST
);
210 /* Don't output anything when a tentative file-scope definition
211 is seen. But at end of compilation, do output code for them.
213 We do output all variables and rely on
214 callgraph code to defer them except for forward declarations
215 (see gcc.c-torture/compile/920624-1.c) */
217 || !DECL_DEFER_OUTPUT (decl
)
218 || DECL_INITIAL (decl
))
219 && (!VAR_P (decl
) || !DECL_HAS_VALUE_EXPR_P (decl
))
220 && !DECL_EXTERNAL (decl
))
222 /* When reading LTO unit, we also read varpool, so do not
224 if (in_lto_p
&& !at_end
)
226 else if (finalize
&& TREE_CODE (decl
) != FUNCTION_DECL
)
227 varpool_node::finalize_decl (decl
);
230 #ifdef ASM_FINISH_DECLARE_OBJECT
231 if (decl
== last_assemble_variable_decl
)
233 ASM_FINISH_DECLARE_OBJECT (asm_out_file
, decl
,
238 /* Now that we have activated any function-specific attributes
239 that might affect function decl, particularly align, relayout it. */
240 if (TREE_CODE (decl
) == FUNCTION_DECL
)
241 targetm
.target_option
.relayout_function (decl
);
243 timevar_pop (TV_VARCONST
);
245 else if (TREE_CODE (decl
) == TYPE_DECL
246 /* Like in rest_of_type_compilation, avoid confusing the debug
247 information machinery when there are errors. */
250 timevar_push (TV_SYMOUT
);
251 debug_hooks
->type_decl (decl
, !top_level
);
252 timevar_pop (TV_SYMOUT
);
255 /* Let cgraph know about the existence of variables. */
256 if (in_lto_p
&& !at_end
)
258 else if (VAR_P (decl
) && !DECL_EXTERNAL (decl
)
259 && TREE_STATIC (decl
))
260 varpool_node::get_create (decl
);
262 /* Generate early debug for global variables. Any local variables will
263 be handled by either handling reachable functions from
264 finalize_compilation_unit (and by consequence, locally scoped
265 symbols), or by rest_of_type_compilation below.
267 For Go's hijack of the debug_hooks to implement -fdump-go-spec, pick up
268 function prototypes. Go's debug_hooks will not forward them to the
271 && (TREE_CODE (decl
) != FUNCTION_DECL
272 /* This will pick up function prototypes with no bodies,
273 which are not visible in finalize_compilation_unit()
274 while iterating with FOR_EACH_*_FUNCTION through the
276 || (flag_dump_go_spec
!= NULL
277 && !DECL_SAVED_TREE (decl
)
278 && DECL_STRUCT_FUNCTION (decl
) == NULL
))
280 /* We need to check both decl_function_context and
281 current_function_decl here to make sure local extern
282 declarations end up with the correct context.
284 For local extern declarations, decl_function_context is
285 empty, but current_function_decl is set to the function where
286 the extern was declared . Without the check for
287 !current_function_decl below, the local extern ends up
288 incorrectly with a top-level context.
300 extern int i; // Local extern declaration.
307 && !decl_function_context (decl
)
308 && !current_function_decl
309 && DECL_SOURCE_LOCATION (decl
) != BUILTINS_LOCATION
310 && (!decl_type_context (decl
)
311 /* If we created a varpool node for the decl make sure to
312 call early_global_decl. Otherwise we miss changes
313 introduced by member definitions like
314 struct A { static int staticdatamember; };
315 int A::staticdatamember;
316 and thus have incomplete early debug and late debug
317 called from varpool node removal fails to handle it
321 && TREE_STATIC (decl
) && !DECL_EXTERNAL (decl
)))
322 /* Avoid confusing the debug information machinery when there are
325 (*debug_hooks
->early_global_decl
) (decl
);
328 /* Called after finishing a record, union or enumeral type. */
331 rest_of_type_compilation (tree type
, int toplev
)
333 /* Avoid confusing the debug information machinery when there are
338 timevar_push (TV_SYMOUT
);
339 debug_hooks
->type_decl (TYPE_STUB_DECL (type
), !toplev
);
340 timevar_pop (TV_SYMOUT
);
347 finish_optimization_passes (void)
350 struct dump_file_info
*dfi
;
352 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
354 timevar_push (TV_DUMP
);
355 if (profile_arc_flag
|| flag_test_coverage
|| flag_branch_probabilities
)
357 dumps
->dump_start (pass_profile_1
->static_pass_number
, NULL
);
359 dumps
->dump_finish (pass_profile_1
->static_pass_number
);
364 dumps
->dump_start (pass_profile_1
->static_pass_number
, NULL
);
365 print_combine_total_stats ();
366 dumps
->dump_finish (pass_profile_1
->static_pass_number
);
369 /* Do whatever is necessary to finish printing the graphs. */
370 for (i
= TDI_end
; (dfi
= dumps
->get_dump_file_info (i
)) != NULL
; ++i
)
371 if (dfi
->graph_dump_initialized
)
373 name
= dumps
->get_dump_file_name (dfi
);
374 finish_graph_dump_file (name
);
378 timevar_pop (TV_DUMP
);
382 execute_build_ssa_passes (void)
384 /* Once this pass (and its sub-passes) are complete, all functions
385 will be in SSA form. Technically this state change is happening
386 a tad early, since the sub-passes have not yet run, but since
387 none of the sub-passes are IPA passes and do not create new
388 functions, this is ok. We're setting this value for the benefit
389 of IPA passes that follow. */
390 if (symtab
->state
< IPA_SSA
)
391 symtab
->state
= IPA_SSA
;
397 const pass_data pass_data_build_ssa_passes
=
399 SIMPLE_IPA_PASS
, /* type */
400 "build_ssa_passes", /* name */
401 OPTGROUP_NONE
, /* optinfo_flags */
402 TV_EARLY_LOCAL
, /* tv_id */
403 0, /* properties_required */
404 0, /* properties_provided */
405 0, /* properties_destroyed */
406 0, /* todo_flags_start */
407 /* todo_flags_finish is executed before subpases. For this reason
408 it makes no sense to remove unreachable functions here. */
409 0, /* todo_flags_finish */
412 class pass_build_ssa_passes
: public simple_ipa_opt_pass
415 pass_build_ssa_passes (gcc::context
*ctxt
)
416 : simple_ipa_opt_pass (pass_data_build_ssa_passes
, ctxt
)
419 /* opt_pass methods: */
420 virtual bool gate (function
*)
422 /* Don't bother doing anything if the program has errors. */
423 return (!seen_error () && !in_lto_p
);
426 virtual unsigned int execute (function
*)
428 return execute_build_ssa_passes ();
431 }; // class pass_build_ssa_passes
433 const pass_data pass_data_local_optimization_passes
=
435 SIMPLE_IPA_PASS
, /* type */
436 "opt_local_passes", /* name */
437 OPTGROUP_NONE
, /* optinfo_flags */
439 0, /* properties_required */
440 0, /* properties_provided */
441 0, /* properties_destroyed */
442 0, /* todo_flags_start */
443 0, /* todo_flags_finish */
446 class pass_local_optimization_passes
: public simple_ipa_opt_pass
449 pass_local_optimization_passes (gcc::context
*ctxt
)
450 : simple_ipa_opt_pass (pass_data_local_optimization_passes
, ctxt
)
453 /* opt_pass methods: */
454 virtual bool gate (function
*)
456 /* Don't bother doing anything if the program has errors. */
457 return (!seen_error () && !in_lto_p
);
460 }; // class pass_local_optimization_passes
464 simple_ipa_opt_pass
*
465 make_pass_build_ssa_passes (gcc::context
*ctxt
)
467 return new pass_build_ssa_passes (ctxt
);
470 simple_ipa_opt_pass
*
471 make_pass_local_optimization_passes (gcc::context
*ctxt
)
473 return new pass_local_optimization_passes (ctxt
);
478 const pass_data pass_data_all_early_optimizations
=
480 GIMPLE_PASS
, /* type */
481 "early_optimizations", /* name */
482 OPTGROUP_NONE
, /* optinfo_flags */
484 0, /* properties_required */
485 0, /* properties_provided */
486 0, /* properties_destroyed */
487 0, /* todo_flags_start */
488 0, /* todo_flags_finish */
491 class pass_all_early_optimizations
: public gimple_opt_pass
494 pass_all_early_optimizations (gcc::context
*ctxt
)
495 : gimple_opt_pass (pass_data_all_early_optimizations
, ctxt
)
498 /* opt_pass methods: */
499 virtual bool gate (function
*)
501 return (optimize
>= 1
502 /* Don't bother doing anything if the program has errors. */
506 }; // class pass_all_early_optimizations
510 static gimple_opt_pass
*
511 make_pass_all_early_optimizations (gcc::context
*ctxt
)
513 return new pass_all_early_optimizations (ctxt
);
518 const pass_data pass_data_all_optimizations
=
520 GIMPLE_PASS
, /* type */
521 "*all_optimizations", /* name */
522 OPTGROUP_NONE
, /* optinfo_flags */
523 TV_OPTIMIZE
, /* tv_id */
524 0, /* properties_required */
525 0, /* properties_provided */
526 0, /* properties_destroyed */
527 0, /* todo_flags_start */
528 0, /* todo_flags_finish */
531 class pass_all_optimizations
: public gimple_opt_pass
534 pass_all_optimizations (gcc::context
*ctxt
)
535 : gimple_opt_pass (pass_data_all_optimizations
, ctxt
)
538 /* opt_pass methods: */
539 virtual bool gate (function
*) { return optimize
>= 1 && !optimize_debug
; }
541 }; // class pass_all_optimizations
545 static gimple_opt_pass
*
546 make_pass_all_optimizations (gcc::context
*ctxt
)
548 return new pass_all_optimizations (ctxt
);
553 const pass_data pass_data_all_optimizations_g
=
555 GIMPLE_PASS
, /* type */
556 "*all_optimizations_g", /* name */
557 OPTGROUP_NONE
, /* optinfo_flags */
558 TV_OPTIMIZE
, /* tv_id */
559 0, /* properties_required */
560 0, /* properties_provided */
561 0, /* properties_destroyed */
562 0, /* todo_flags_start */
563 0, /* todo_flags_finish */
566 class pass_all_optimizations_g
: public gimple_opt_pass
569 pass_all_optimizations_g (gcc::context
*ctxt
)
570 : gimple_opt_pass (pass_data_all_optimizations_g
, ctxt
)
573 /* opt_pass methods: */
574 virtual bool gate (function
*) { return optimize
>= 1 && optimize_debug
; }
576 }; // class pass_all_optimizations_g
580 static gimple_opt_pass
*
581 make_pass_all_optimizations_g (gcc::context
*ctxt
)
583 return new pass_all_optimizations_g (ctxt
);
588 const pass_data pass_data_rest_of_compilation
=
591 "*rest_of_compilation", /* name */
592 OPTGROUP_NONE
, /* optinfo_flags */
593 TV_REST_OF_COMPILATION
, /* tv_id */
594 PROP_rtl
, /* properties_required */
595 0, /* properties_provided */
596 0, /* properties_destroyed */
597 0, /* todo_flags_start */
598 0, /* todo_flags_finish */
601 class pass_rest_of_compilation
: public rtl_opt_pass
604 pass_rest_of_compilation (gcc::context
*ctxt
)
605 : rtl_opt_pass (pass_data_rest_of_compilation
, ctxt
)
608 /* opt_pass methods: */
609 virtual bool gate (function
*)
611 /* Early return if there were errors. We can run afoul of our
612 consistency checks, and there's not really much point in fixing them. */
613 return !(rtl_dump_and_exit
|| flag_syntax_only
|| seen_error ());
616 }; // class pass_rest_of_compilation
620 static rtl_opt_pass
*
621 make_pass_rest_of_compilation (gcc::context
*ctxt
)
623 return new pass_rest_of_compilation (ctxt
);
628 const pass_data pass_data_postreload
=
631 "*all-postreload", /* name */
632 OPTGROUP_NONE
, /* optinfo_flags */
633 TV_POSTRELOAD
, /* tv_id */
634 PROP_rtl
, /* properties_required */
635 0, /* properties_provided */
636 0, /* properties_destroyed */
637 0, /* todo_flags_start */
638 0, /* todo_flags_finish */
641 class pass_postreload
: public rtl_opt_pass
644 pass_postreload (gcc::context
*ctxt
)
645 : rtl_opt_pass (pass_data_postreload
, ctxt
)
648 /* opt_pass methods: */
649 virtual bool gate (function
*) { return reload_completed
; }
651 }; // class pass_postreload
655 static rtl_opt_pass
*
656 make_pass_postreload (gcc::context
*ctxt
)
658 return new pass_postreload (ctxt
);
663 const pass_data pass_data_late_compilation
=
666 "*all-late_compilation", /* name */
667 OPTGROUP_NONE
, /* optinfo_flags */
668 TV_LATE_COMPILATION
, /* tv_id */
669 PROP_rtl
, /* properties_required */
670 0, /* properties_provided */
671 0, /* properties_destroyed */
672 0, /* todo_flags_start */
673 0, /* todo_flags_finish */
676 class pass_late_compilation
: public rtl_opt_pass
679 pass_late_compilation (gcc::context
*ctxt
)
680 : rtl_opt_pass (pass_data_late_compilation
, ctxt
)
683 /* opt_pass methods: */
684 virtual bool gate (function
*)
686 return reload_completed
|| targetm
.no_register_allocation
;
689 }; // class pass_late_compilation
693 static rtl_opt_pass
*
694 make_pass_late_compilation (gcc::context
*ctxt
)
696 return new pass_late_compilation (ctxt
);
701 /* Set the static pass number of pass PASS to ID and record that
702 in the mapping from static pass number to pass. */
706 set_pass_for_id (int id
, opt_pass
*pass
)
708 pass
->static_pass_number
= id
;
709 if (passes_by_id_size
<= id
)
711 passes_by_id
= XRESIZEVEC (opt_pass
*, passes_by_id
, id
+ 1);
712 memset (passes_by_id
+ passes_by_id_size
, 0,
713 (id
+ 1 - passes_by_id_size
) * sizeof (void *));
714 passes_by_id_size
= id
+ 1;
716 passes_by_id
[id
] = pass
;
719 /* Return the pass with the static pass number ID. */
722 pass_manager::get_pass_for_id (int id
) const
724 if (id
>= passes_by_id_size
)
726 return passes_by_id
[id
];
729 /* Iterate over the pass tree allocating dump file numbers. We want
730 to do this depth first, and independent of whether the pass is
734 register_one_dump_file (opt_pass
*pass
)
736 g
->get_passes ()->register_one_dump_file (pass
);
740 pass_manager::register_one_dump_file (opt_pass
*pass
)
742 char *dot_name
, *flag_name
, *glob_name
;
743 const char *name
, *full_name
, *prefix
;
745 /* Buffer big enough to format a 32-bit UINT_MAX into. */
749 optgroup_flags_t optgroup_flags
= OPTGROUP_NONE
;
750 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
752 /* See below in next_pass_1. */
754 if (pass
->static_pass_number
!= -1)
755 sprintf (num
, "%u", ((int) pass
->static_pass_number
< 0
756 ? 1 : pass
->static_pass_number
));
758 /* The name is both used to identify the pass for the purposes of plugins,
759 and to specify dump file name and option.
760 The latter two might want something short which is not quite unique; for
761 that reason, we may have a disambiguating prefix, followed by a space
762 to mark the start of the following dump file name / option string. */
763 name
= strchr (pass
->name
, ' ');
764 name
= name
? name
+ 1 : pass
->name
;
765 dot_name
= concat (".", name
, num
, NULL
);
766 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
770 optgroup_flags
|= OPTGROUP_IPA
;
772 else if (pass
->type
== GIMPLE_PASS
)
783 flag_name
= concat (prefix
, name
, num
, NULL
);
784 glob_name
= concat (prefix
, name
, NULL
);
785 optgroup_flags
|= pass
->optinfo_flags
;
786 /* For any passes that do not have an optgroup set, and which are not
787 IPA passes setup above, set the optgroup to OPTGROUP_OTHER so that
788 any dump messages are emitted properly under -fopt-info(-optall). */
789 if (optgroup_flags
== OPTGROUP_NONE
)
790 optgroup_flags
= OPTGROUP_OTHER
;
791 id
= dumps
->dump_register (dot_name
, flag_name
, glob_name
, dkind
,
794 set_pass_for_id (id
, pass
);
795 full_name
= concat (prefix
, pass
->name
, num
, NULL
);
796 register_pass_name (pass
, full_name
);
797 free (CONST_CAST (char *, full_name
));
800 /* Register the dump files for the pass_manager starting at PASS. */
803 pass_manager::register_dump_files (opt_pass
*pass
)
807 if (pass
->name
&& pass
->name
[0] != '*')
808 register_one_dump_file (pass
);
811 register_dump_files (pass
->sub
);
818 /* Register PASS with NAME. */
821 pass_manager::register_pass_name (opt_pass
*pass
, const char *name
)
823 if (!m_name_to_pass_map
)
824 m_name_to_pass_map
= new hash_map
<nofree_string_hash
, opt_pass
*> (256);
826 if (m_name_to_pass_map
->get (name
))
827 return; /* Ignore plugin passes. */
829 const char *unique_name
= xstrdup (name
);
830 m_name_to_pass_map
->put (unique_name
, pass
);
833 /* Map from pass id to canonicalized pass name. */
835 typedef const char *char_ptr
;
836 static vec
<char_ptr
> pass_tab
;
838 /* Callback function for traversing NAME_TO_PASS_MAP. */
841 passes_pass_traverse (const char *const &name
, opt_pass
*const &pass
, void *)
843 gcc_assert (pass
->static_pass_number
> 0);
844 gcc_assert (pass_tab
.exists ());
846 pass_tab
[pass
->static_pass_number
] = name
;
851 /* The function traverses NAME_TO_PASS_MAP and creates a pass info
852 table for dumping purpose. */
855 pass_manager::create_pass_tab (void) const
857 if (!flag_dump_passes
)
860 pass_tab
.safe_grow_cleared (passes_by_id_size
+ 1);
861 m_name_to_pass_map
->traverse
<void *, passes_pass_traverse
> (NULL
);
864 static bool override_gate_status (opt_pass
*, tree
, bool);
866 /* Dump the instantiated name for PASS. IS_ON indicates if PASS
867 is turned on or not. */
870 dump_one_pass (opt_pass
*pass
, int pass_indent
)
872 int indent
= 3 * pass_indent
;
874 bool is_on
, is_really_on
;
876 is_on
= pass
->gate (cfun
);
877 is_really_on
= override_gate_status (pass
, current_function_decl
, is_on
);
879 if (pass
->static_pass_number
<= 0)
882 pn
= pass_tab
[pass
->static_pass_number
];
884 fprintf (stderr
, "%*s%-40s%*s:%s%s\n", indent
, " ", pn
,
885 (15 - indent
< 0 ? 0 : 15 - indent
), " ",
886 is_on
? " ON" : " OFF",
887 ((!is_on
) == (!is_really_on
) ? ""
888 : (is_really_on
? " (FORCED_ON)" : " (FORCED_OFF)")));
891 /* Dump pass list PASS with indentation INDENT. */
894 dump_pass_list (opt_pass
*pass
, int indent
)
898 dump_one_pass (pass
, indent
);
900 dump_pass_list (pass
->sub
, indent
+ 1);
906 /* Dump all optimization passes. */
911 g
->get_passes ()->dump_passes ();
915 pass_manager::dump_passes () const
917 push_dummy_function (true);
921 dump_pass_list (all_lowering_passes
, 1);
922 dump_pass_list (all_small_ipa_passes
, 1);
923 dump_pass_list (all_regular_ipa_passes
, 1);
924 dump_pass_list (all_late_ipa_passes
, 1);
925 dump_pass_list (all_passes
, 1);
927 pop_dummy_function ();
930 /* Returns the pass with NAME. */
933 pass_manager::get_pass_by_name (const char *name
)
935 opt_pass
**p
= m_name_to_pass_map
->get (name
);
943 /* Range [start, last]. */
949 const char *assem_name
;
950 struct uid_range
*next
;
953 typedef struct uid_range
*uid_range_p
;
956 static vec
<uid_range_p
> enabled_pass_uid_range_tab
;
957 static vec
<uid_range_p
> disabled_pass_uid_range_tab
;
960 /* Parse option string for -fdisable- and -fenable-
961 The syntax of the options:
964 -fdisable-<pass_name>
966 -fenable-<pass_name>=s1:e1,s2:e2,...
967 -fdisable-<pass_name>=s1:e1,s2:e2,...
971 enable_disable_pass (const char *arg
, bool is_enable
)
974 char *range_str
, *phase_name
;
975 char *argstr
= xstrdup (arg
);
976 vec
<uid_range_p
> *tab
= 0;
978 range_str
= strchr (argstr
,'=');
989 error ("unrecognized option -fenable");
991 error ("unrecognized option -fdisable");
995 pass
= g
->get_passes ()->get_pass_by_name (phase_name
);
996 if (!pass
|| pass
->static_pass_number
== -1)
999 error ("unknown pass %s specified in -fenable", phase_name
);
1001 error ("unknown pass %s specified in -fdisable", phase_name
);
1007 tab
= &enabled_pass_uid_range_tab
;
1009 tab
= &disabled_pass_uid_range_tab
;
1011 if ((unsigned) pass
->static_pass_number
>= tab
->length ())
1012 tab
->safe_grow_cleared (pass
->static_pass_number
+ 1);
1017 uid_range_p new_range
= XCNEW (struct uid_range
);
1019 new_range
->start
= 0;
1020 new_range
->last
= (unsigned)-1;
1022 slot
= (*tab
)[pass
->static_pass_number
];
1023 new_range
->next
= slot
;
1024 (*tab
)[pass
->static_pass_number
] = new_range
;
1026 inform (UNKNOWN_LOCATION
, "enable pass %s for functions in the range "
1027 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
1029 inform (UNKNOWN_LOCATION
, "disable pass %s for functions in the range "
1030 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
1034 char *next_range
= NULL
;
1035 char *one_range
= range_str
;
1036 char *end_val
= NULL
;
1041 uid_range_p new_range
;
1042 char *invalid
= NULL
;
1044 char *func_name
= NULL
;
1046 next_range
= strchr (one_range
, ',');
1053 end_val
= strchr (one_range
, ':');
1059 start
= strtol (one_range
, &invalid
, 10);
1060 if (*invalid
|| start
< 0)
1062 if (end_val
|| (one_range
[0] >= '0'
1063 && one_range
[0] <= '9'))
1065 error ("Invalid range %s in option %s",
1067 is_enable
? "-fenable" : "-fdisable");
1071 func_name
= one_range
;
1075 new_range
= XCNEW (struct uid_range
);
1078 new_range
->start
= (unsigned) start
;
1079 new_range
->last
= (unsigned) start
;
1083 new_range
->start
= (unsigned) -1;
1084 new_range
->last
= (unsigned) -1;
1085 new_range
->assem_name
= xstrdup (func_name
);
1090 long last
= strtol (end_val
, &invalid
, 10);
1091 if (*invalid
|| last
< start
)
1093 error ("Invalid range %s in option %s",
1095 is_enable
? "-fenable" : "-fdisable");
1099 new_range
= XCNEW (struct uid_range
);
1100 new_range
->start
= (unsigned) start
;
1101 new_range
->last
= (unsigned) last
;
1104 slot
= (*tab
)[pass
->static_pass_number
];
1105 new_range
->next
= slot
;
1106 (*tab
)[pass
->static_pass_number
] = new_range
;
1109 if (new_range
->assem_name
)
1110 inform (UNKNOWN_LOCATION
,
1111 "enable pass %s for function %s",
1112 phase_name
, new_range
->assem_name
);
1114 inform (UNKNOWN_LOCATION
,
1115 "enable pass %s for functions in the range of [%u, %u]",
1116 phase_name
, new_range
->start
, new_range
->last
);
1120 if (new_range
->assem_name
)
1121 inform (UNKNOWN_LOCATION
,
1122 "disable pass %s for function %s",
1123 phase_name
, new_range
->assem_name
);
1125 inform (UNKNOWN_LOCATION
,
1126 "disable pass %s for functions in the range of [%u, %u]",
1127 phase_name
, new_range
->start
, new_range
->last
);
1130 one_range
= next_range
;
1131 } while (next_range
);
1137 /* Enable pass specified by ARG. */
1140 enable_pass (const char *arg
)
1142 enable_disable_pass (arg
, true);
1145 /* Disable pass specified by ARG. */
1148 disable_pass (const char *arg
)
1150 enable_disable_pass (arg
, false);
1153 /* Returns true if PASS is explicitly enabled/disabled for FUNC. */
1156 is_pass_explicitly_enabled_or_disabled (opt_pass
*pass
,
1158 vec
<uid_range_p
> tab
)
1160 uid_range_p slot
, range
;
1162 const char *aname
= NULL
;
1165 || (unsigned) pass
->static_pass_number
>= tab
.length ()
1166 || pass
->static_pass_number
== -1)
1169 slot
= tab
[pass
->static_pass_number
];
1173 cgraph_uid
= func
? cgraph_node::get (func
)->get_uid () : 0;
1174 if (func
&& DECL_ASSEMBLER_NAME_SET_P (func
))
1175 aname
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func
));
1180 if ((unsigned) cgraph_uid
>= range
->start
1181 && (unsigned) cgraph_uid
<= range
->last
)
1183 if (range
->assem_name
&& aname
1184 && !strcmp (range
->assem_name
, aname
))
1186 range
= range
->next
;
1193 /* Update static_pass_number for passes (and the flag
1194 TODO_mark_first_instance).
1196 Passes are constructed with static_pass_number preinitialized to 0
1198 This field is used in two different ways: initially as instance numbers
1199 of their kind, and then as ids within the entire pass manager.
1201 Within pass_manager::pass_manager:
1203 * In add_pass_instance(), as called by next_pass_1 in
1204 NEXT_PASS in init_optimization_passes
1206 * When the initial instance of a pass within a pass manager is seen,
1207 it is flagged, and its static_pass_number is set to -1
1209 * On subsequent times that it is seen, the static pass number
1210 is decremented each time, so that if there are e.g. 4 dups,
1211 they have static_pass_number -4, 2, 3, 4 respectively (note
1212 how the initial one is negative and gives the count); these
1213 can be thought of as instance numbers of the specific pass
1215 * Within the register_dump_files () traversal, set_pass_for_id()
1216 is called on each pass, using these instance numbers to create
1217 dumpfile switches, and then overwriting them with a pass id,
1218 which are global to the whole pass manager (based on
1219 (TDI_end + current value of extra_dump_files_in_use) ) */
1222 add_pass_instance (opt_pass
*new_pass
, bool track_duplicates
,
1223 opt_pass
*initial_pass
)
1225 /* Are we dealing with the first pass of its kind, or a clone? */
1226 if (new_pass
!= initial_pass
)
1228 /* We're dealing with a clone. */
1229 new_pass
->todo_flags_start
&= ~TODO_mark_first_instance
;
1231 /* Indicate to register_dump_files that this pass has duplicates,
1232 and so it should rename the dump file. The first instance will
1233 be -1, and be number of duplicates = -static_pass_number - 1.
1234 Subsequent instances will be > 0 and just the duplicate number. */
1235 if ((new_pass
->name
&& new_pass
->name
[0] != '*') || track_duplicates
)
1237 initial_pass
->static_pass_number
-= 1;
1238 new_pass
->static_pass_number
= -initial_pass
->static_pass_number
;
1243 /* We're dealing with the first pass of its kind. */
1244 new_pass
->todo_flags_start
|= TODO_mark_first_instance
;
1245 new_pass
->static_pass_number
= -1;
1247 invoke_plugin_callbacks (PLUGIN_NEW_PASS
, new_pass
);
1251 /* Add a pass to the pass list. Duplicate the pass if it's already
1255 next_pass_1 (opt_pass
**list
, opt_pass
*pass
, opt_pass
*initial_pass
)
1257 /* Every pass should have a name so that plugins can refer to them. */
1258 gcc_assert (pass
->name
!= NULL
);
1260 add_pass_instance (pass
, false, initial_pass
);
1263 return &(*list
)->next
;
1266 /* List node for an inserted pass instance. We need to keep track of all
1267 the newly-added pass instances (with 'added_pass_nodes' defined below)
1268 so that we can register their dump files after pass-positioning is finished.
1269 Registering dumping files needs to be post-processed or the
1270 static_pass_number of the opt_pass object would be modified and mess up
1271 the dump file names of future pass instances to be added. */
1273 struct pass_list_node
1276 struct pass_list_node
*next
;
1279 static struct pass_list_node
*added_pass_nodes
= NULL
;
1280 static struct pass_list_node
*prev_added_pass_node
;
1282 /* Insert the pass at the proper position. Return true if the pass
1283 is successfully added.
1285 NEW_PASS_INFO - new pass to be inserted
1286 PASS_LIST - root of the pass list to insert the new pass to */
1289 position_pass (struct register_pass_info
*new_pass_info
, opt_pass
**pass_list
)
1291 opt_pass
*pass
= *pass_list
, *prev_pass
= NULL
;
1292 bool success
= false;
1294 for ( ; pass
; prev_pass
= pass
, pass
= pass
->next
)
1296 /* Check if the current pass is of the same type as the new pass and
1297 matches the name and the instance number of the reference pass. */
1298 if (pass
->type
== new_pass_info
->pass
->type
1300 && !strcmp (pass
->name
, new_pass_info
->reference_pass_name
)
1301 && ((new_pass_info
->ref_pass_instance_number
== 0)
1302 || (new_pass_info
->ref_pass_instance_number
==
1303 pass
->static_pass_number
)
1304 || (new_pass_info
->ref_pass_instance_number
== 1
1305 && pass
->todo_flags_start
& TODO_mark_first_instance
)))
1308 struct pass_list_node
*new_pass_node
;
1310 if (new_pass_info
->ref_pass_instance_number
== 0)
1312 new_pass
= new_pass_info
->pass
->clone ();
1313 add_pass_instance (new_pass
, true, new_pass_info
->pass
);
1317 new_pass
= new_pass_info
->pass
;
1318 add_pass_instance (new_pass
, true, new_pass
);
1321 /* Insert the new pass instance based on the positioning op. */
1322 switch (new_pass_info
->pos_op
)
1324 case PASS_POS_INSERT_AFTER
:
1325 new_pass
->next
= pass
->next
;
1326 pass
->next
= new_pass
;
1328 /* Skip newly inserted pass to avoid repeated
1329 insertions in the case where the new pass and the
1330 existing one have the same name. */
1333 case PASS_POS_INSERT_BEFORE
:
1334 new_pass
->next
= pass
;
1336 prev_pass
->next
= new_pass
;
1338 *pass_list
= new_pass
;
1340 case PASS_POS_REPLACE
:
1341 new_pass
->next
= pass
->next
;
1343 prev_pass
->next
= new_pass
;
1345 *pass_list
= new_pass
;
1346 new_pass
->sub
= pass
->sub
;
1347 new_pass
->tv_id
= pass
->tv_id
;
1351 error ("invalid pass positioning operation");
1355 /* Save the newly added pass (instance) in the added_pass_nodes
1356 list so that we can register its dump file later. Note that
1357 we cannot register the dump file now because doing so will modify
1358 the static_pass_number of the opt_pass object and therefore
1359 mess up the dump file name of future instances. */
1360 new_pass_node
= XCNEW (struct pass_list_node
);
1361 new_pass_node
->pass
= new_pass
;
1362 if (!added_pass_nodes
)
1363 added_pass_nodes
= new_pass_node
;
1365 prev_added_pass_node
->next
= new_pass_node
;
1366 prev_added_pass_node
= new_pass_node
;
1371 if (pass
->sub
&& position_pass (new_pass_info
, &pass
->sub
))
1378 /* Hooks a new pass into the pass lists.
1380 PASS_INFO - pass information that specifies the opt_pass object,
1381 reference pass, instance number, and how to position
1385 register_pass (struct register_pass_info
*pass_info
)
1387 g
->get_passes ()->register_pass (pass_info
);
1391 register_pass (opt_pass
* pass
, pass_positioning_ops pos
,
1392 const char* ref_pass_name
, int ref_pass_inst_number
)
1394 register_pass_info i
;
1396 i
.reference_pass_name
= ref_pass_name
;
1397 i
.ref_pass_instance_number
= ref_pass_inst_number
;
1400 g
->get_passes ()->register_pass (&i
);
1404 pass_manager::register_pass (struct register_pass_info
*pass_info
)
1406 bool all_instances
, success
;
1408 /* The checks below could fail in buggy plugins. Existing GCC
1409 passes should never fail these checks, so we mention plugin in
1411 if (!pass_info
->pass
)
1412 fatal_error (input_location
, "plugin cannot register a missing pass");
1414 if (!pass_info
->pass
->name
)
1415 fatal_error (input_location
, "plugin cannot register an unnamed pass");
1417 if (!pass_info
->reference_pass_name
)
1420 "plugin cannot register pass %qs without reference pass name",
1421 pass_info
->pass
->name
);
1423 /* Try to insert the new pass to the pass lists. We need to check
1424 all five lists as the reference pass could be in one (or all) of
1426 all_instances
= pass_info
->ref_pass_instance_number
== 0;
1427 success
= position_pass (pass_info
, &all_lowering_passes
);
1428 if (!success
|| all_instances
)
1429 success
|= position_pass (pass_info
, &all_small_ipa_passes
);
1430 if (!success
|| all_instances
)
1431 success
|= position_pass (pass_info
, &all_regular_ipa_passes
);
1432 if (!success
|| all_instances
)
1433 success
|= position_pass (pass_info
, &all_late_ipa_passes
);
1434 if (!success
|| all_instances
)
1435 success
|= position_pass (pass_info
, &all_passes
);
1439 "pass %qs not found but is referenced by new pass %qs",
1440 pass_info
->reference_pass_name
, pass_info
->pass
->name
);
1442 /* OK, we have successfully inserted the new pass. We need to register
1443 the dump files for the newly added pass and its duplicates (if any).
1444 While doing so, we also delete the pass_list_node
1445 objects created during pass positioning. */
1446 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
1447 while (added_pass_nodes
)
1449 struct pass_list_node
*next_node
= added_pass_nodes
->next
;
1451 /* Handle -fdump-* and -fopt-info. */
1452 dumps
->register_pass (added_pass_nodes
->pass
);
1454 XDELETE (added_pass_nodes
);
1455 added_pass_nodes
= next_node
;
1459 /* Construct the pass tree. The sequencing of passes is driven by
1460 the cgraph routines:
1462 finalize_compilation_unit ()
1463 for each node N in the cgraph
1464 cgraph_analyze_function (N)
1465 cgraph_lower_function (N) -> all_lowering_passes
1467 If we are optimizing, compile is then invoked:
1470 ipa_passes () -> all_small_ipa_passes
1471 -> Analysis of all_regular_ipa_passes
1472 * possible LTO streaming at copmilation time *
1473 -> Execution of all_regular_ipa_passes
1474 * possible LTO streaming at link time *
1475 -> all_late_ipa_passes
1476 expand_all_functions ()
1477 for each node N in the cgraph
1478 expand_function (N) -> Transformation of all_regular_ipa_passes
1482 pass_manager::pass_manager (context
*ctxt
)
1483 : all_passes (NULL
), all_small_ipa_passes (NULL
), all_lowering_passes (NULL
),
1484 all_regular_ipa_passes (NULL
),
1485 all_late_ipa_passes (NULL
), passes_by_id (NULL
), passes_by_id_size (0),
1486 m_ctxt (ctxt
), m_name_to_pass_map (NULL
)
1490 /* Zero-initialize pass members. */
1491 #define INSERT_PASSES_AFTER(PASS)
1492 #define PUSH_INSERT_PASSES_WITHIN(PASS)
1493 #define POP_INSERT_PASSES()
1494 #define NEXT_PASS(PASS, NUM) PASS ## _ ## NUM = NULL
1495 #define NEXT_PASS_WITH_ARG(PASS, NUM, ARG) NEXT_PASS (PASS, NUM)
1496 #define TERMINATE_PASS_LIST(PASS)
1497 #include "pass-instances.def"
1498 #undef INSERT_PASSES_AFTER
1499 #undef PUSH_INSERT_PASSES_WITHIN
1500 #undef POP_INSERT_PASSES
1502 #undef NEXT_PASS_WITH_ARG
1503 #undef TERMINATE_PASS_LIST
1505 /* Initialize the pass_lists array. */
1506 #define DEF_PASS_LIST(LIST) pass_lists[PASS_LIST_NO_##LIST] = &LIST;
1508 #undef DEF_PASS_LIST
1510 /* Build the tree of passes. */
1512 #define INSERT_PASSES_AFTER(PASS) \
1514 opt_pass **p_start; \
1515 p_start = p = &(PASS);
1517 #define TERMINATE_PASS_LIST(PASS) \
1518 gcc_assert (p_start == &PASS); \
1522 #define PUSH_INSERT_PASSES_WITHIN(PASS) \
1524 opt_pass **p = &(PASS ## _1)->sub;
1526 #define POP_INSERT_PASSES() \
1529 #define NEXT_PASS(PASS, NUM) \
1531 gcc_assert (PASS ## _ ## NUM == NULL); \
1533 PASS ## _1 = make_##PASS (m_ctxt); \
1536 gcc_assert (PASS ## _1); \
1537 PASS ## _ ## NUM = PASS ## _1->clone (); \
1539 p = next_pass_1 (p, PASS ## _ ## NUM, PASS ## _1); \
1542 #define NEXT_PASS_WITH_ARG(PASS, NUM, ARG) \
1544 NEXT_PASS (PASS, NUM); \
1545 PASS ## _ ## NUM->set_pass_param (0, ARG); \
1548 #include "pass-instances.def"
1550 #undef INSERT_PASSES_AFTER
1551 #undef PUSH_INSERT_PASSES_WITHIN
1552 #undef POP_INSERT_PASSES
1554 #undef NEXT_PASS_WITH_ARG
1555 #undef TERMINATE_PASS_LIST
1557 /* Register the passes with the tree dump code. */
1558 register_dump_files (all_lowering_passes
);
1559 register_dump_files (all_small_ipa_passes
);
1560 register_dump_files (all_regular_ipa_passes
);
1561 register_dump_files (all_late_ipa_passes
);
1562 register_dump_files (all_passes
);
1566 delete_pass_tree (opt_pass
*pass
)
1570 /* Recurse into child passes. */
1571 delete_pass_tree (pass
->sub
);
1573 opt_pass
*next
= pass
->next
;
1575 /* Delete this pass. */
1578 /* Iterate onto sibling passes. */
1583 pass_manager::~pass_manager ()
1585 XDELETEVEC (passes_by_id
);
1587 /* Call delete_pass_tree on each of the pass_lists. */
1588 #define DEF_PASS_LIST(LIST) \
1589 delete_pass_tree (*pass_lists[PASS_LIST_NO_##LIST]);
1591 #undef DEF_PASS_LIST
1595 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1596 function CALLBACK for every function in the call graph. Otherwise,
1597 call CALLBACK on the current function. */
1600 do_per_function (void (*callback
) (function
*, void *data
), void *data
)
1602 if (current_function_decl
)
1603 callback (cfun
, data
);
1606 struct cgraph_node
*node
;
1607 FOR_EACH_DEFINED_FUNCTION (node
)
1608 if (node
->analyzed
&& (gimple_has_body_p (node
->decl
) && !in_lto_p
)
1609 && (!node
->clone_of
|| node
->decl
!= node
->clone_of
->decl
))
1610 callback (DECL_STRUCT_FUNCTION (node
->decl
), data
);
1614 /* Because inlining might remove no-longer reachable nodes, we need to
1615 keep the array visible to garbage collector to avoid reading collected
1618 static GTY ((length ("nnodes"))) cgraph_node
**order
;
1620 #define uid_hash_t hash_set<int_hash <int, 0, -1> >
1622 /* Hook called when NODE is removed and therefore should be
1623 excluded from order vector. DATA is a hash set with removed nodes. */
1626 remove_cgraph_node_from_order (cgraph_node
*node
, void *data
)
1628 uid_hash_t
*removed_nodes
= (uid_hash_t
*)data
;
1629 removed_nodes
->add (node
->get_uid ());
1632 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1633 function CALLBACK for every function in the call graph. Otherwise,
1634 call CALLBACK on the current function.
1635 This function is global so that plugins can use it. */
1637 do_per_function_toporder (void (*callback
) (function
*, void *data
), void *data
)
1641 if (current_function_decl
)
1642 callback (cfun
, data
);
1645 cgraph_node_hook_list
*hook
;
1646 uid_hash_t removed_nodes
;
1647 gcc_assert (!order
);
1648 order
= ggc_vec_alloc
<cgraph_node
*> (symtab
->cgraph_count
);
1650 nnodes
= ipa_reverse_postorder (order
);
1651 for (i
= nnodes
- 1; i
>= 0; i
--)
1652 order
[i
]->process
= 1;
1653 hook
= symtab
->add_cgraph_removal_hook (remove_cgraph_node_from_order
,
1655 for (i
= nnodes
- 1; i
>= 0; i
--)
1657 cgraph_node
*node
= order
[i
];
1659 /* Function could be inlined and removed as unreachable. */
1660 if (node
== NULL
|| removed_nodes
.contains (node
->get_uid ()))
1663 /* Allow possibly removed nodes to be garbage collected. */
1666 if (node
->has_gimple_body_p ())
1668 struct function
*fn
= DECL_STRUCT_FUNCTION (node
->decl
);
1670 callback (fn
, data
);
1674 symtab
->remove_cgraph_removal_hook (hook
);
1681 /* Helper function to perform function body dump. */
1684 execute_function_dump (function
*fn
, void *data
)
1686 opt_pass
*pass
= (opt_pass
*)data
;
1692 if (fn
->curr_properties
& PROP_trees
)
1693 dump_function_to_file (fn
->decl
, dump_file
, dump_flags
);
1695 print_rtl_with_bb (dump_file
, get_insns (), dump_flags
);
1697 /* Flush the file. If verification fails, we won't be able to
1698 close the file before aborting. */
1701 if ((fn
->curr_properties
& PROP_cfg
)
1702 && (dump_flags
& TDF_GRAPH
))
1704 gcc::dump_manager
*dumps
= g
->get_dumps ();
1705 struct dump_file_info
*dfi
1706 = dumps
->get_dump_file_info (pass
->static_pass_number
);
1707 if (!dfi
->graph_dump_initialized
)
1709 clean_graph_dump_file (dump_file_name
);
1710 dfi
->graph_dump_initialized
= true;
1712 print_graph_cfg (dump_file_name
, fn
);
1719 /* This function is called when an internal compiler error is encountered.
1720 Ensure that function dump is made available before compiler is aborted. */
1723 emergency_dump_function ()
1727 enum opt_pass_type pt
= current_pass
->type
;
1728 fnotice (stderr
, "during %s pass: %s\n",
1729 pt
== GIMPLE_PASS
? "GIMPLE" : pt
== RTL_PASS
? "RTL" : "IPA",
1730 current_pass
->name
);
1731 if (!dump_file
|| !cfun
)
1733 fnotice (stderr
, "dump file: %s\n", dump_file_name
);
1734 fprintf (dump_file
, "\n\n\nEMERGENCY DUMP:\n\n");
1735 execute_function_dump (cfun
, current_pass
);
1738 static struct profile_record
*profile_record
;
1740 /* Do profile consistency book-keeping for the pass with static number INDEX.
1741 If SUBPASS is zero, we run _before_ the pass, and if SUBPASS is one, then
1742 we run _after_ the pass. RUN is true if the pass really runs, or FALSE
1743 if we are only book-keeping on passes that may have selectively disabled
1744 themselves on a given function. */
1746 check_profile_consistency (int index
, int subpass
, bool run
)
1748 pass_manager
*passes
= g
->get_passes ();
1751 if (!profile_record
)
1752 profile_record
= XCNEWVEC (struct profile_record
,
1753 passes
->passes_by_id_size
);
1754 gcc_assert (index
< passes
->passes_by_id_size
&& index
>= 0);
1755 gcc_assert (subpass
< 2);
1756 profile_record
[index
].run
|= run
;
1757 account_profile_record (&profile_record
[index
], subpass
);
1760 /* Output profile consistency. */
1763 dump_profile_report (void)
1765 g
->get_passes ()->dump_profile_report ();
1769 pass_manager::dump_profile_report () const
1772 int last_freq_in
= 0, last_count_in
= 0, last_freq_out
= 0, last_count_out
= 0;
1773 gcov_type last_time
= 0, last_size
= 0;
1774 double rel_time_change
, rel_size_change
;
1775 int last_reported
= 0;
1777 if (!profile_record
)
1779 fprintf (stderr
, "\nProfile consistency report:\n\n");
1780 fprintf (stderr
, "Pass name |mismatch in |mismated out|Overall\n");
1781 fprintf (stderr
, " |freq count |freq count |size time\n");
1783 for (i
= 0; i
< passes_by_id_size
; i
++)
1784 for (j
= 0 ; j
< 2; j
++)
1785 if (profile_record
[i
].run
)
1788 rel_time_change
= (profile_record
[i
].time
[j
]
1789 - (double)last_time
) * 100 / (double)last_time
;
1791 rel_time_change
= 0;
1793 rel_size_change
= (profile_record
[i
].size
[j
]
1794 - (double)last_size
) * 100 / (double)last_size
;
1796 rel_size_change
= 0;
1798 if (profile_record
[i
].num_mismatched_freq_in
[j
] != last_freq_in
1799 || profile_record
[i
].num_mismatched_freq_out
[j
] != last_freq_out
1800 || profile_record
[i
].num_mismatched_count_in
[j
] != last_count_in
1801 || profile_record
[i
].num_mismatched_count_out
[j
] != last_count_out
1802 || rel_time_change
|| rel_size_change
)
1805 fprintf (stderr
, "%-20s %s",
1806 passes_by_id
[i
]->name
,
1807 j
? "(after TODO)" : " ");
1808 if (profile_record
[i
].num_mismatched_freq_in
[j
] != last_freq_in
)
1809 fprintf (stderr
, "| %+5i",
1810 profile_record
[i
].num_mismatched_freq_in
[j
]
1813 fprintf (stderr
, "| ");
1814 if (profile_record
[i
].num_mismatched_count_in
[j
] != last_count_in
)
1815 fprintf (stderr
, " %+5i",
1816 profile_record
[i
].num_mismatched_count_in
[j
]
1819 fprintf (stderr
, " ");
1820 if (profile_record
[i
].num_mismatched_freq_out
[j
] != last_freq_out
)
1821 fprintf (stderr
, "| %+5i",
1822 profile_record
[i
].num_mismatched_freq_out
[j
]
1825 fprintf (stderr
, "| ");
1826 if (profile_record
[i
].num_mismatched_count_out
[j
] != last_count_out
)
1827 fprintf (stderr
, " %+5i",
1828 profile_record
[i
].num_mismatched_count_out
[j
]
1831 fprintf (stderr
, " ");
1833 /* Size/time units change across gimple and RTL. */
1834 if (i
== pass_expand_1
->static_pass_number
)
1835 fprintf (stderr
, "|----------");
1838 if (rel_size_change
)
1839 fprintf (stderr
, "| %+8.4f%%", rel_size_change
);
1841 fprintf (stderr
, "| ");
1842 if (rel_time_change
)
1843 fprintf (stderr
, " %+8.4f%%", rel_time_change
);
1845 fprintf (stderr
, "\n");
1846 last_freq_in
= profile_record
[i
].num_mismatched_freq_in
[j
];
1847 last_freq_out
= profile_record
[i
].num_mismatched_freq_out
[j
];
1848 last_count_in
= profile_record
[i
].num_mismatched_count_in
[j
];
1849 last_count_out
= profile_record
[i
].num_mismatched_count_out
[j
];
1851 else if (j
&& last_reported
!= i
)
1854 fprintf (stderr
, "%-20s ------------| | |\n",
1855 passes_by_id
[i
]->name
);
1857 last_time
= profile_record
[i
].time
[j
];
1858 last_size
= profile_record
[i
].size
[j
];
1862 /* Perform all TODO actions that ought to be done on each function. */
1865 execute_function_todo (function
*fn
, void *data
)
1867 bool from_ipa_pass
= (cfun
== NULL
);
1868 unsigned int flags
= (size_t)data
;
1869 flags
&= ~fn
->last_verified
;
1875 /* Always cleanup the CFG before trying to update SSA. */
1876 if (flags
& TODO_cleanup_cfg
)
1878 cleanup_tree_cfg ();
1880 /* When cleanup_tree_cfg merges consecutive blocks, it may
1881 perform some simplistic propagation when removing single
1882 valued PHI nodes. This propagation may, in turn, cause the
1883 SSA form to become out-of-date (see PR 22037). So, even
1884 if the parent pass had not scheduled an SSA update, we may
1885 still need to do one. */
1886 if (!(flags
& TODO_update_ssa_any
) && need_ssa_update_p (cfun
))
1887 flags
|= TODO_update_ssa
;
1890 if (flags
& TODO_update_ssa_any
)
1892 unsigned update_flags
= flags
& TODO_update_ssa_any
;
1893 update_ssa (update_flags
);
1896 if (flag_tree_pta
&& (flags
& TODO_rebuild_alias
))
1897 compute_may_aliases ();
1899 if (optimize
&& (flags
& TODO_update_address_taken
))
1900 execute_update_addresses_taken ();
1902 if (flags
& TODO_remove_unused_locals
)
1903 remove_unused_locals ();
1905 if (flags
& TODO_rebuild_frequencies
)
1906 rebuild_frequencies ();
1908 if (flags
& TODO_rebuild_cgraph_edges
)
1909 cgraph_edge::rebuild_edges ();
1911 gcc_assert (dom_info_state (fn
, CDI_POST_DOMINATORS
) == DOM_NONE
);
1912 /* If we've seen errors do not bother running any verifiers. */
1913 if (flag_checking
&& !seen_error ())
1915 dom_state pre_verify_state
= dom_info_state (fn
, CDI_DOMINATORS
);
1916 dom_state pre_verify_pstate
= dom_info_state (fn
, CDI_POST_DOMINATORS
);
1918 if (flags
& TODO_verify_il
)
1920 if (cfun
->curr_properties
& PROP_trees
)
1922 if (cfun
->curr_properties
& PROP_cfg
)
1923 /* IPA passes leave stmts to be fixed up, so make sure to
1924 not verify stmts really throw. */
1925 verify_gimple_in_cfg (cfun
, !from_ipa_pass
);
1927 verify_gimple_in_seq (gimple_body (cfun
->decl
));
1929 if (cfun
->curr_properties
& PROP_ssa
)
1930 /* IPA passes leave stmts to be fixed up, so make sure to
1931 not verify SSA operands whose verifier will choke on that. */
1932 verify_ssa (true, !from_ipa_pass
);
1933 /* IPA passes leave basic-blocks unsplit, so make sure to
1934 not trip on that. */
1935 if ((cfun
->curr_properties
& PROP_cfg
)
1937 verify_flow_info ();
1939 && ! loops_state_satisfies_p (LOOPS_NEED_FIXUP
))
1941 verify_loop_structure ();
1942 if (loops_state_satisfies_p (LOOP_CLOSED_SSA
))
1943 verify_loop_closed_ssa (false);
1945 if (cfun
->curr_properties
& PROP_rtl
)
1946 verify_rtl_sharing ();
1949 /* Make sure verifiers don't change dominator state. */
1950 gcc_assert (dom_info_state (fn
, CDI_DOMINATORS
) == pre_verify_state
);
1951 gcc_assert (dom_info_state (fn
, CDI_POST_DOMINATORS
) == pre_verify_pstate
);
1954 fn
->last_verified
= flags
& TODO_verify_all
;
1958 /* For IPA passes make sure to release dominator info, it can be
1959 computed by non-verifying TODOs. */
1962 free_dominance_info (fn
, CDI_DOMINATORS
);
1963 free_dominance_info (fn
, CDI_POST_DOMINATORS
);
1967 /* Perform all TODO actions. */
1969 execute_todo (unsigned int flags
)
1973 && need_ssa_update_p (cfun
))
1974 gcc_assert (flags
& TODO_update_ssa_any
);
1976 statistics_fini_pass ();
1979 do_per_function (execute_function_todo
, (void *)(size_t) flags
);
1981 /* At this point we should not have any unreachable code in the
1982 CFG, so it is safe to flush the pending freelist for SSA_NAMES. */
1983 if (cfun
&& cfun
->gimple_df
)
1984 flush_ssaname_freelist ();
1986 /* Always remove functions just as before inlining: IPA passes might be
1987 interested to see bodies of extern inline functions that are not inlined
1988 to analyze side effects. The full removal is done just at the end
1989 of IPA pass queue. */
1990 if (flags
& TODO_remove_functions
)
1993 symtab
->remove_unreachable_nodes (dump_file
);
1996 if ((flags
& TODO_dump_symtab
) && dump_file
&& !current_function_decl
)
1999 symtab
->dump (dump_file
);
2000 /* Flush the file. If verification fails, we won't be able to
2001 close the file before aborting. */
2005 /* Now that the dumping has been done, we can get rid of the optional
2007 if (flags
& TODO_df_finish
)
2008 df_finish_pass ((flags
& TODO_df_verify
) != 0);
2011 /* Verify invariants that should hold between passes. This is a place
2012 to put simple sanity checks. */
2015 verify_interpass_invariants (void)
2017 gcc_checking_assert (!fold_deferring_overflow_warnings_p ());
2020 /* Clear the last verified flag. */
2023 clear_last_verified (function
*fn
, void *data ATTRIBUTE_UNUSED
)
2025 fn
->last_verified
= 0;
2028 /* Helper function. Verify that the properties has been turn into the
2029 properties expected by the pass. */
2032 verify_curr_properties (function
*fn
, void *data
)
2034 unsigned int props
= (size_t)data
;
2035 gcc_assert ((fn
->curr_properties
& props
) == props
);
2038 /* Release dump file name if set. */
2041 release_dump_file_name (void)
2045 free (CONST_CAST (char *, dump_file_name
));
2046 dump_file_name
= NULL
;
2050 /* Initialize pass dump file. */
2051 /* This is non-static so that the plugins can use it. */
2054 pass_init_dump_file (opt_pass
*pass
)
2056 /* If a dump file name is present, open it if enabled. */
2057 if (pass
->static_pass_number
!= -1)
2059 timevar_push (TV_DUMP
);
2060 gcc::dump_manager
*dumps
= g
->get_dumps ();
2061 bool initializing_dump
=
2062 !dumps
->dump_initialized_p (pass
->static_pass_number
);
2063 release_dump_file_name ();
2064 dump_file_name
= dumps
->get_dump_file_name (pass
->static_pass_number
);
2065 dumps
->dump_start (pass
->static_pass_number
, &dump_flags
);
2066 if (dump_file
&& current_function_decl
&& ! (dump_flags
& TDF_GIMPLE
))
2067 dump_function_header (dump_file
, current_function_decl
, dump_flags
);
2068 if (initializing_dump
2069 && dump_file
&& (dump_flags
& TDF_GRAPH
)
2070 && cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2072 clean_graph_dump_file (dump_file_name
);
2073 struct dump_file_info
*dfi
2074 = dumps
->get_dump_file_info (pass
->static_pass_number
);
2075 dfi
->graph_dump_initialized
= true;
2077 timevar_pop (TV_DUMP
);
2078 return initializing_dump
;
2084 /* Flush PASS dump file. */
2085 /* This is non-static so that plugins can use it. */
2088 pass_fini_dump_file (opt_pass
*pass
)
2090 timevar_push (TV_DUMP
);
2092 /* Flush and close dump file. */
2093 release_dump_file_name ();
2095 g
->get_dumps ()->dump_finish (pass
->static_pass_number
);
2096 timevar_pop (TV_DUMP
);
2099 /* After executing the pass, apply expected changes to the function
2103 update_properties_after_pass (function
*fn
, void *data
)
2105 opt_pass
*pass
= (opt_pass
*) data
;
2106 fn
->curr_properties
= (fn
->curr_properties
| pass
->properties_provided
)
2107 & ~pass
->properties_destroyed
;
2110 /* Execute summary generation for all of the passes in IPA_PASS. */
2113 execute_ipa_summary_passes (ipa_opt_pass_d
*ipa_pass
)
2117 opt_pass
*pass
= ipa_pass
;
2119 /* Execute all of the IPA_PASSes in the list. */
2120 if (ipa_pass
->type
== IPA_PASS
2121 && pass
->gate (cfun
)
2122 && ipa_pass
->generate_summary
)
2124 pass_init_dump_file (pass
);
2126 /* If a timevar is present, start it. */
2128 timevar_push (pass
->tv_id
);
2130 current_pass
= pass
;
2131 ipa_pass
->generate_summary ();
2135 timevar_pop (pass
->tv_id
);
2137 pass_fini_dump_file (pass
);
2139 ipa_pass
= (ipa_opt_pass_d
*)ipa_pass
->next
;
2143 /* Execute IPA_PASS function transform on NODE. */
2146 execute_one_ipa_transform_pass (struct cgraph_node
*node
,
2147 ipa_opt_pass_d
*ipa_pass
)
2149 opt_pass
*pass
= ipa_pass
;
2150 unsigned int todo_after
= 0;
2152 current_pass
= pass
;
2153 if (!ipa_pass
->function_transform
)
2156 /* Note that the folders should only create gimple expressions.
2157 This is a hack until the new folder is ready. */
2158 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
2160 pass_init_dump_file (pass
);
2162 /* If a timevar is present, start it. */
2163 if (pass
->tv_id
!= TV_NONE
)
2164 timevar_push (pass
->tv_id
);
2166 /* Run pre-pass verification. */
2167 execute_todo (ipa_pass
->function_transform_todo_flags_start
);
2170 todo_after
= ipa_pass
->function_transform (node
);
2172 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2173 check_profile_consistency (pass
->static_pass_number
, 0, true);
2175 /* Run post-pass cleanup and verification. */
2176 execute_todo (todo_after
);
2177 verify_interpass_invariants ();
2178 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2179 check_profile_consistency (pass
->static_pass_number
, 1, true);
2182 if (pass
->tv_id
!= TV_NONE
)
2183 timevar_pop (pass
->tv_id
);
2186 do_per_function (execute_function_dump
, pass
);
2187 pass_fini_dump_file (pass
);
2189 current_pass
= NULL
;
2190 redirect_edge_var_map_empty ();
2192 /* Signal this is a suitable GC collection point. */
2193 if (!(todo_after
& TODO_do_not_ggc_collect
))
2197 /* For the current function, execute all ipa transforms. */
2200 execute_all_ipa_transforms (void)
2202 struct cgraph_node
*node
;
2205 node
= cgraph_node::get (current_function_decl
);
2207 if (node
->ipa_transforms_to_apply
.exists ())
2211 for (i
= 0; i
< node
->ipa_transforms_to_apply
.length (); i
++)
2212 execute_one_ipa_transform_pass (node
, node
->ipa_transforms_to_apply
[i
]);
2213 node
->ipa_transforms_to_apply
.release ();
2217 /* Check if PASS is explicitly disabled or enabled and return
2218 the gate status. FUNC is the function to be processed, and
2219 GATE_STATUS is the gate status determined by pass manager by
2223 override_gate_status (opt_pass
*pass
, tree func
, bool gate_status
)
2225 bool explicitly_enabled
= false;
2226 bool explicitly_disabled
= false;
2229 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2230 enabled_pass_uid_range_tab
);
2232 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2233 disabled_pass_uid_range_tab
);
2235 gate_status
= !explicitly_disabled
&& (gate_status
|| explicitly_enabled
);
2240 /* Determine if PASS_NAME matches CRITERION.
2241 Not a pure predicate, since it can update CRITERION, to support
2242 matching the Nth invocation of a pass.
2243 Subroutine of should_skip_pass_p. */
2246 determine_pass_name_match (const char *pass_name
, char *criterion
)
2248 size_t namelen
= strlen (pass_name
);
2249 if (! strncmp (pass_name
, criterion
, namelen
))
2251 /* The following supports starting with the Nth invocation
2252 of a pass (where N does not necessarily is equal to the
2253 dump file suffix). */
2254 if (criterion
[namelen
] == '\0'
2255 || (criterion
[namelen
] == '1'
2256 && criterion
[namelen
+ 1] == '\0'))
2260 if (criterion
[namelen
+ 1] == '\0')
2261 --criterion
[namelen
];
2269 /* For skipping passes until "startwith" pass.
2270 Return true iff PASS should be skipped.
2271 Clear cfun->pass_startwith when encountering the "startwith" pass,
2272 so that all subsequent passes are run. */
2275 should_skip_pass_p (opt_pass
*pass
)
2279 if (!cfun
->pass_startwith
)
2282 /* For __GIMPLE functions, we have to at least start when we leave
2283 SSA. Hence, we need to detect the "expand" pass, and stop skipping
2284 when we encounter it. A cheap way to identify "expand" is it to
2285 detect the destruction of PROP_ssa.
2286 For __RTL functions, we invoke "rest_of_compilation" directly, which
2287 is after "expand", and hence we don't reach this conditional. */
2288 if (pass
->properties_destroyed
& PROP_ssa
)
2291 fprintf (stderr
, "starting anyway when leaving SSA: %s\n", pass
->name
);
2292 cfun
->pass_startwith
= NULL
;
2296 if (determine_pass_name_match (pass
->name
, cfun
->pass_startwith
))
2299 fprintf (stderr
, "found starting pass: %s\n", pass
->name
);
2300 cfun
->pass_startwith
= NULL
;
2304 /* For GIMPLE passes, run any property provider (but continue skipping
2306 We don't want to force running RTL passes that are property providers:
2307 "expand" is covered above, and the only pass other than "expand" that
2308 provides a property is "into_cfglayout" (PROP_cfglayout), which does
2309 too much for a dumped __RTL function. */
2310 if (pass
->type
== GIMPLE_PASS
2311 && pass
->properties_provided
!= 0)
2314 /* Don't skip df init; later RTL passes need it. */
2315 if (strstr (pass
->name
, "dfinit") != NULL
)
2319 fprintf (stderr
, "skipping pass: %s\n", pass
->name
);
2321 /* If we get here, then we have a "startwith" that we haven't seen yet;
2326 /* Skip the given pass, for handling passes before "startwith"
2327 in __GIMPLE and__RTL-marked functions.
2328 In theory, this ought to be a no-op, but some of the RTL passes
2329 need additional processing here. */
2332 skip_pass (opt_pass
*pass
)
2334 /* Pass "reload" sets the global "reload_completed", and many
2335 things depend on this (e.g. instructions in .md files). */
2336 if (strcmp (pass
->name
, "reload") == 0)
2337 reload_completed
= 1;
2339 /* The INSN_ADDRESSES vec is normally set up by
2340 shorten_branches; set it up for the benefit of passes that
2342 if (strcmp (pass
->name
, "shorten") == 0)
2343 INSN_ADDRESSES_ALLOC (get_max_uid ());
2345 /* Update the cfg hooks as appropriate. */
2346 if (strcmp (pass
->name
, "into_cfglayout") == 0)
2348 cfg_layout_rtl_register_cfg_hooks ();
2349 cfun
->curr_properties
|= PROP_cfglayout
;
2351 if (strcmp (pass
->name
, "outof_cfglayout") == 0)
2353 rtl_register_cfg_hooks ();
2354 cfun
->curr_properties
&= ~PROP_cfglayout
;
2361 execute_one_pass (opt_pass
*pass
)
2363 unsigned int todo_after
= 0;
2367 /* IPA passes are executed on whole program, so cfun should be NULL.
2368 Other passes need function context set. */
2369 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
2370 gcc_assert (!cfun
&& !current_function_decl
);
2372 gcc_assert (cfun
&& current_function_decl
);
2374 current_pass
= pass
;
2376 /* Check whether gate check should be avoided.
2377 User controls the value of the gate through the parameter "gate_status". */
2378 gate_status
= pass
->gate (cfun
);
2379 gate_status
= override_gate_status (pass
, current_function_decl
, gate_status
);
2381 /* Override gate with plugin. */
2382 invoke_plugin_callbacks (PLUGIN_OVERRIDE_GATE
, &gate_status
);
2386 /* Run so passes selectively disabling themselves on a given function
2387 are not miscounted. */
2388 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2390 check_profile_consistency (pass
->static_pass_number
, 0, false);
2391 check_profile_consistency (pass
->static_pass_number
, 1, false);
2393 current_pass
= NULL
;
2397 if (should_skip_pass_p (pass
))
2403 /* Pass execution event trigger: useful to identify passes being
2405 invoke_plugin_callbacks (PLUGIN_PASS_EXECUTION
, pass
);
2407 if (!quiet_flag
&& !cfun
)
2408 fprintf (stderr
, " <%s>", pass
->name
? pass
->name
: "");
2410 /* Note that the folders should only create gimple expressions.
2411 This is a hack until the new folder is ready. */
2412 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
2414 pass_init_dump_file (pass
);
2416 /* If a timevar is present, start it. */
2417 if (pass
->tv_id
!= TV_NONE
)
2418 timevar_push (pass
->tv_id
);
2420 /* Run pre-pass verification. */
2421 execute_todo (pass
->todo_flags_start
);
2424 do_per_function (verify_curr_properties
,
2425 (void *)(size_t)pass
->properties_required
);
2428 todo_after
= pass
->execute (cfun
);
2430 if (todo_after
& TODO_discard_function
)
2433 if (pass
->tv_id
!= TV_NONE
)
2434 timevar_pop (pass
->tv_id
);
2436 pass_fini_dump_file (pass
);
2439 /* As cgraph_node::release_body expects release dominators info,
2440 we have to release it. */
2441 if (dom_info_available_p (CDI_DOMINATORS
))
2442 free_dominance_info (CDI_DOMINATORS
);
2444 if (dom_info_available_p (CDI_POST_DOMINATORS
))
2445 free_dominance_info (CDI_POST_DOMINATORS
);
2447 tree fn
= cfun
->decl
;
2450 cgraph_node::get (fn
)->release_body ();
2452 current_pass
= NULL
;
2453 redirect_edge_var_map_empty ();
2460 do_per_function (clear_last_verified
, NULL
);
2462 do_per_function (update_properties_after_pass
, pass
);
2464 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2465 check_profile_consistency (pass
->static_pass_number
, 0, true);
2467 /* Run post-pass cleanup and verification. */
2468 execute_todo (todo_after
| pass
->todo_flags_finish
| TODO_verify_il
);
2469 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2470 check_profile_consistency (pass
->static_pass_number
, 1, true);
2472 verify_interpass_invariants ();
2475 if (pass
->tv_id
!= TV_NONE
)
2476 timevar_pop (pass
->tv_id
);
2478 if (pass
->type
== IPA_PASS
2479 && ((ipa_opt_pass_d
*)pass
)->function_transform
)
2481 struct cgraph_node
*node
;
2482 FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node
)
2483 node
->ipa_transforms_to_apply
.safe_push ((ipa_opt_pass_d
*)pass
);
2486 do_per_function (execute_function_dump
, pass
);
2488 if (!current_function_decl
)
2489 symtab
->process_new_functions ();
2491 pass_fini_dump_file (pass
);
2493 if (pass
->type
!= SIMPLE_IPA_PASS
&& pass
->type
!= IPA_PASS
)
2494 gcc_assert (!(cfun
->curr_properties
& PROP_trees
)
2495 || pass
->type
!= RTL_PASS
);
2497 current_pass
= NULL
;
2498 redirect_edge_var_map_empty ();
2500 /* Signal this is a suitable GC collection point. */
2501 if (!((todo_after
| pass
->todo_flags_finish
) & TODO_do_not_ggc_collect
))
2508 execute_pass_list_1 (opt_pass
*pass
)
2512 gcc_assert (pass
->type
== GIMPLE_PASS
2513 || pass
->type
== RTL_PASS
);
2517 if (execute_one_pass (pass
) && pass
->sub
)
2518 execute_pass_list_1 (pass
->sub
);
2525 execute_pass_list (function
*fn
, opt_pass
*pass
)
2527 gcc_assert (fn
== cfun
);
2528 execute_pass_list_1 (pass
);
2529 if (cfun
&& fn
->cfg
)
2531 free_dominance_info (CDI_DOMINATORS
);
2532 free_dominance_info (CDI_POST_DOMINATORS
);
2536 /* Write out all LTO data. */
2540 timevar_push (TV_IPA_LTO_GIMPLE_OUT
);
2542 timevar_pop (TV_IPA_LTO_GIMPLE_OUT
);
2543 timevar_push (TV_IPA_LTO_DECL_OUT
);
2544 produce_asm_for_decls ();
2545 timevar_pop (TV_IPA_LTO_DECL_OUT
);
2548 /* Same as execute_pass_list but assume that subpasses of IPA passes
2549 are local passes. If SET is not NULL, write out summaries of only
2550 those node in SET. */
2553 ipa_write_summaries_2 (opt_pass
*pass
, struct lto_out_decl_state
*state
)
2557 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*)pass
;
2558 gcc_assert (!current_function_decl
);
2560 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2561 if (pass
->type
== IPA_PASS
2562 && ipa_pass
->write_summary
2563 && pass
->gate (cfun
))
2565 /* If a timevar is present, start it. */
2567 timevar_push (pass
->tv_id
);
2569 pass_init_dump_file (pass
);
2571 current_pass
= pass
;
2572 ipa_pass
->write_summary ();
2574 pass_fini_dump_file (pass
);
2576 /* If a timevar is present, start it. */
2578 timevar_pop (pass
->tv_id
);
2581 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2582 ipa_write_summaries_2 (pass
->sub
, state
);
2588 /* Helper function of ipa_write_summaries. Creates and destroys the
2589 decl state and calls ipa_write_summaries_2 for all passes that have
2590 summaries. SET is the set of nodes to be written. */
2593 ipa_write_summaries_1 (lto_symtab_encoder_t encoder
)
2595 pass_manager
*passes
= g
->get_passes ();
2596 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2597 state
->symtab_node_encoder
= encoder
;
2599 lto_output_init_mode_table ();
2600 lto_push_out_decl_state (state
);
2602 gcc_assert (!flag_wpa
);
2603 ipa_write_summaries_2 (passes
->all_regular_ipa_passes
, state
);
2607 gcc_assert (lto_get_out_decl_state () == state
);
2608 lto_pop_out_decl_state ();
2609 lto_delete_out_decl_state (state
);
2612 /* Write out summaries for all the nodes in the callgraph. */
2615 ipa_write_summaries (void)
2617 lto_symtab_encoder_t encoder
;
2619 varpool_node
*vnode
;
2620 struct cgraph_node
*node
;
2621 struct cgraph_node
**order
;
2623 if ((!flag_generate_lto
&& !flag_generate_offload
) || seen_error ())
2626 gcc_assert (!dump_file
);
2627 streamer_dump_file
= dump_begin (TDI_lto_stream_out
, NULL
);
2629 select_what_to_stream ();
2631 encoder
= lto_symtab_encoder_new (false);
2633 /* Create the callgraph set in the same order used in
2634 cgraph_expand_all_functions. This mostly facilitates debugging,
2635 since it causes the gimple file to be processed in the same order
2636 as the source code. */
2637 order
= XCNEWVEC (struct cgraph_node
*, symtab
->cgraph_count
);
2638 order_pos
= ipa_reverse_postorder (order
);
2639 gcc_assert (order_pos
== symtab
->cgraph_count
);
2641 for (i
= order_pos
- 1; i
>= 0; i
--)
2643 struct cgraph_node
*node
= order
[i
];
2645 if (gimple_has_body_p (node
->decl
))
2647 /* When streaming out references to statements as part of some IPA
2648 pass summary, the statements need to have uids assigned and the
2649 following does that for all the IPA passes here. Naturally, this
2650 ordering then matches the one IPA-passes get in their stmt_fixup
2653 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
2654 renumber_gimple_stmt_uids ();
2657 if (node
->definition
&& node
->need_lto_streaming
)
2658 lto_set_symtab_encoder_in_partition (encoder
, node
);
2661 FOR_EACH_DEFINED_FUNCTION (node
)
2662 if (node
->alias
&& node
->need_lto_streaming
)
2663 lto_set_symtab_encoder_in_partition (encoder
, node
);
2664 FOR_EACH_DEFINED_VARIABLE (vnode
)
2665 if (vnode
->need_lto_streaming
)
2666 lto_set_symtab_encoder_in_partition (encoder
, vnode
);
2668 ipa_write_summaries_1 (compute_ltrans_boundary (encoder
));
2671 if (streamer_dump_file
)
2673 dump_end (TDI_lto_stream_out
, streamer_dump_file
);
2674 streamer_dump_file
= NULL
;
2678 /* Same as execute_pass_list but assume that subpasses of IPA passes
2679 are local passes. If SET is not NULL, write out optimization summaries of
2680 only those node in SET. */
2683 ipa_write_optimization_summaries_1 (opt_pass
*pass
,
2684 struct lto_out_decl_state
*state
)
2688 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*)pass
;
2689 gcc_assert (!current_function_decl
);
2691 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2692 if (pass
->type
== IPA_PASS
2693 && ipa_pass
->write_optimization_summary
2694 && pass
->gate (cfun
))
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
->write_optimization_summary ();
2705 pass_fini_dump_file (pass
);
2707 /* If a timevar is present, start it. */
2709 timevar_pop (pass
->tv_id
);
2712 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2713 ipa_write_optimization_summaries_1 (pass
->sub
, state
);
2719 /* Write all the optimization summaries for the cgraph nodes in SET. If SET is
2720 NULL, write out all summaries of all nodes. */
2723 ipa_write_optimization_summaries (lto_symtab_encoder_t encoder
)
2725 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2726 lto_symtab_encoder_iterator lsei
;
2727 state
->symtab_node_encoder
= encoder
;
2729 lto_output_init_mode_table ();
2730 lto_push_out_decl_state (state
);
2731 for (lsei
= lsei_start_function_in_partition (encoder
);
2732 !lsei_end_p (lsei
); lsei_next_function_in_partition (&lsei
))
2734 struct cgraph_node
*node
= lsei_cgraph_node (lsei
);
2735 /* When streaming out references to statements as part of some IPA
2736 pass summary, the statements need to have uids assigned.
2738 For functions newly born at WPA stage we need to initialize
2740 if (node
->definition
2741 && gimple_has_body_p (node
->decl
))
2743 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
2744 renumber_gimple_stmt_uids ();
2749 gcc_assert (flag_wpa
);
2750 pass_manager
*passes
= g
->get_passes ();
2751 ipa_write_optimization_summaries_1 (passes
->all_regular_ipa_passes
, state
);
2755 gcc_assert (lto_get_out_decl_state () == state
);
2756 lto_pop_out_decl_state ();
2757 lto_delete_out_decl_state (state
);
2760 /* Same as execute_pass_list but assume that subpasses of IPA passes
2761 are local passes. */
2764 ipa_read_summaries_1 (opt_pass
*pass
)
2768 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
2770 gcc_assert (!current_function_decl
);
2772 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2774 if (pass
->gate (cfun
))
2776 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_summary
)
2778 /* If a timevar is present, start it. */
2780 timevar_push (pass
->tv_id
);
2782 pass_init_dump_file (pass
);
2784 current_pass
= pass
;
2785 ipa_pass
->read_summary ();
2787 pass_fini_dump_file (pass
);
2791 timevar_pop (pass
->tv_id
);
2794 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2795 ipa_read_summaries_1 (pass
->sub
);
2802 /* Read all the summaries for all_regular_ipa_passes. */
2805 ipa_read_summaries (void)
2807 pass_manager
*passes
= g
->get_passes ();
2808 ipa_read_summaries_1 (passes
->all_regular_ipa_passes
);
2811 /* Same as execute_pass_list but assume that subpasses of IPA passes
2812 are local passes. */
2815 ipa_read_optimization_summaries_1 (opt_pass
*pass
)
2819 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
2821 gcc_assert (!current_function_decl
);
2823 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2825 if (pass
->gate (cfun
))
2827 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_optimization_summary
)
2829 /* If a timevar is present, start it. */
2831 timevar_push (pass
->tv_id
);
2833 pass_init_dump_file (pass
);
2835 current_pass
= pass
;
2836 ipa_pass
->read_optimization_summary ();
2838 pass_fini_dump_file (pass
);
2842 timevar_pop (pass
->tv_id
);
2845 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2846 ipa_read_optimization_summaries_1 (pass
->sub
);
2852 /* Read all the summaries for all_regular_ipa_passes. */
2855 ipa_read_optimization_summaries (void)
2857 pass_manager
*passes
= g
->get_passes ();
2858 ipa_read_optimization_summaries_1 (passes
->all_regular_ipa_passes
);
2861 /* Same as execute_pass_list but assume that subpasses of IPA passes
2862 are local passes. */
2864 execute_ipa_pass_list (opt_pass
*pass
)
2868 gcc_assert (!current_function_decl
);
2870 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2871 if (execute_one_pass (pass
) && pass
->sub
)
2873 if (pass
->sub
->type
== GIMPLE_PASS
)
2875 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_START
, NULL
);
2876 do_per_function_toporder ((void (*)(function
*, void *))
2879 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_END
, NULL
);
2881 else if (pass
->sub
->type
== SIMPLE_IPA_PASS
2882 || pass
->sub
->type
== IPA_PASS
)
2883 execute_ipa_pass_list (pass
->sub
);
2887 gcc_assert (!current_function_decl
);
2888 symtab
->process_new_functions ();
2894 /* Execute stmt fixup hooks of all passes in PASS for NODE and STMTS. */
2897 execute_ipa_stmt_fixups (opt_pass
*pass
,
2898 struct cgraph_node
*node
, gimple
**stmts
)
2902 /* Execute all of the IPA_PASSes in the list. */
2903 if (pass
->type
== IPA_PASS
2904 && pass
->gate (cfun
))
2906 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
2908 if (ipa_pass
->stmt_fixup
)
2910 pass_init_dump_file (pass
);
2911 /* If a timevar is present, start it. */
2913 timevar_push (pass
->tv_id
);
2915 current_pass
= pass
;
2916 ipa_pass
->stmt_fixup (node
, stmts
);
2920 timevar_pop (pass
->tv_id
);
2921 pass_fini_dump_file (pass
);
2924 execute_ipa_stmt_fixups (pass
->sub
, node
, stmts
);
2930 /* Execute stmt fixup hooks of all IPA passes for NODE and STMTS. */
2933 execute_all_ipa_stmt_fixups (struct cgraph_node
*node
, gimple
**stmts
)
2935 pass_manager
*passes
= g
->get_passes ();
2936 execute_ipa_stmt_fixups (passes
->all_regular_ipa_passes
, node
, stmts
);
2940 extern void debug_properties (unsigned int);
2941 extern void dump_properties (FILE *, unsigned int);
2944 dump_properties (FILE *dump
, unsigned int props
)
2946 fprintf (dump
, "Properties:\n");
2947 if (props
& PROP_gimple_any
)
2948 fprintf (dump
, "PROP_gimple_any\n");
2949 if (props
& PROP_gimple_lcf
)
2950 fprintf (dump
, "PROP_gimple_lcf\n");
2951 if (props
& PROP_gimple_leh
)
2952 fprintf (dump
, "PROP_gimple_leh\n");
2953 if (props
& PROP_cfg
)
2954 fprintf (dump
, "PROP_cfg\n");
2955 if (props
& PROP_ssa
)
2956 fprintf (dump
, "PROP_ssa\n");
2957 if (props
& PROP_no_crit_edges
)
2958 fprintf (dump
, "PROP_no_crit_edges\n");
2959 if (props
& PROP_rtl
)
2960 fprintf (dump
, "PROP_rtl\n");
2961 if (props
& PROP_gimple_lomp
)
2962 fprintf (dump
, "PROP_gimple_lomp\n");
2963 if (props
& PROP_gimple_lomp_dev
)
2964 fprintf (dump
, "PROP_gimple_lomp_dev\n");
2965 if (props
& PROP_gimple_lcx
)
2966 fprintf (dump
, "PROP_gimple_lcx\n");
2967 if (props
& PROP_gimple_lvec
)
2968 fprintf (dump
, "PROP_gimple_lvec\n");
2969 if (props
& PROP_cfglayout
)
2970 fprintf (dump
, "PROP_cfglayout\n");
2974 debug_properties (unsigned int props
)
2976 dump_properties (stderr
, props
);
2979 /* Called by local passes to see if function is called by already processed nodes.
2980 Because we process nodes in topological order, this means that function is
2981 in recursive cycle or we introduced new direct calls. */
2983 function_called_by_processed_nodes_p (void)
2985 struct cgraph_edge
*e
;
2986 for (e
= cgraph_node::get (current_function_decl
)->callers
;
2990 if (e
->caller
->decl
== current_function_decl
)
2992 if (!e
->caller
->has_gimple_body_p ())
2994 if (TREE_ASM_WRITTEN (e
->caller
->decl
))
2996 if (!e
->caller
->process
&& !e
->caller
->global
.inlined_to
)
3001 fprintf (dump_file
, "Already processed call to:\n");
3002 e
->caller
->dump (dump_file
);
3007 #include "gt-passes.h"