1 /* Top level of GCC compilers (cc1, cc1plus, etc.)
2 Copyright (C) 1987-2024 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 "
91 "to handle the 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
|| condition_coverage_flag
|| flag_test_coverage
356 || flag_branch_probabilities
)
358 dumps
->dump_start (pass_profile_1
->static_pass_number
, NULL
);
360 dumps
->dump_finish (pass_profile_1
->static_pass_number
);
363 /* Do whatever is necessary to finish printing the graphs. */
364 for (i
= TDI_end
; (dfi
= dumps
->get_dump_file_info (i
)) != NULL
; ++i
)
365 if (dfi
->graph_dump_initialized
)
367 name
= dumps
->get_dump_file_name (dfi
);
368 finish_graph_dump_file (name
);
372 timevar_pop (TV_DUMP
);
376 execute_build_ssa_passes (void)
378 /* Once this pass (and its sub-passes) are complete, all functions
379 will be in SSA form. Technically this state change is happening
380 a tad early, since the sub-passes have not yet run, but since
381 none of the sub-passes are IPA passes and do not create new
382 functions, this is ok. We're setting this value for the benefit
383 of IPA passes that follow. */
384 if (symtab
->state
< IPA_SSA
)
385 symtab
->state
= IPA_SSA
;
391 const pass_data pass_data_build_ssa_passes
=
393 SIMPLE_IPA_PASS
, /* type */
394 "build_ssa_passes", /* name */
395 OPTGROUP_NONE
, /* optinfo_flags */
396 TV_EARLY_LOCAL
, /* tv_id */
397 0, /* properties_required */
398 0, /* properties_provided */
399 0, /* properties_destroyed */
400 0, /* todo_flags_start */
401 /* todo_flags_finish is executed before subpases. For this reason
402 it makes no sense to remove unreachable functions here. */
403 0, /* todo_flags_finish */
406 class pass_build_ssa_passes
: public simple_ipa_opt_pass
409 pass_build_ssa_passes (gcc::context
*ctxt
)
410 : simple_ipa_opt_pass (pass_data_build_ssa_passes
, ctxt
)
413 /* opt_pass methods: */
414 bool gate (function
*) final override
416 /* Don't bother doing anything if the program has errors. */
417 return (!seen_error () && !in_lto_p
);
420 unsigned int execute (function
*) final override
422 return execute_build_ssa_passes ();
425 }; // class pass_build_ssa_passes
427 const pass_data pass_data_local_optimization_passes
=
429 SIMPLE_IPA_PASS
, /* type */
430 "opt_local_passes", /* name */
431 OPTGROUP_NONE
, /* optinfo_flags */
433 0, /* properties_required */
434 0, /* properties_provided */
435 0, /* properties_destroyed */
436 0, /* todo_flags_start */
437 0, /* todo_flags_finish */
440 class pass_local_optimization_passes
: public simple_ipa_opt_pass
443 pass_local_optimization_passes (gcc::context
*ctxt
)
444 : simple_ipa_opt_pass (pass_data_local_optimization_passes
, ctxt
)
447 /* opt_pass methods: */
448 bool gate (function
*) final override
450 /* Don't bother doing anything if the program has errors. */
451 return (!seen_error () && !in_lto_p
);
454 }; // class pass_local_optimization_passes
456 const pass_data pass_data_ipa_remove_symbols
=
458 SIMPLE_IPA_PASS
, /* type */
459 "remove_symbols", /* name */
460 OPTGROUP_NONE
, /* optinfo_flags */
462 0, /* properties_required */
463 0, /* properties_provided */
464 0, /* properties_destroyed */
465 0, /* todo_flags_start */
466 TODO_remove_functions
| TODO_dump_symtab
, /* todo_flags_finish */
469 class pass_ipa_remove_symbols
: public simple_ipa_opt_pass
472 pass_ipa_remove_symbols (gcc::context
*ctxt
)
473 : simple_ipa_opt_pass (pass_data_ipa_remove_symbols
, ctxt
)
476 /* opt_pass methods: */
477 bool gate (function
*) final override
479 /* Don't bother doing anything if the program has errors. */
480 return (!seen_error () && !in_lto_p
);
483 }; // class pass_local_optimization_passes
487 simple_ipa_opt_pass
*
488 make_pass_build_ssa_passes (gcc::context
*ctxt
)
490 return new pass_build_ssa_passes (ctxt
);
493 simple_ipa_opt_pass
*
494 make_pass_local_optimization_passes (gcc::context
*ctxt
)
496 return new pass_local_optimization_passes (ctxt
);
499 simple_ipa_opt_pass
*
500 make_pass_ipa_remove_symbols (gcc::context
*ctxt
)
502 return new pass_ipa_remove_symbols (ctxt
);
507 const pass_data pass_data_all_early_optimizations
=
509 GIMPLE_PASS
, /* type */
510 "early_optimizations", /* name */
511 OPTGROUP_NONE
, /* optinfo_flags */
513 0, /* properties_required */
514 0, /* properties_provided */
515 0, /* properties_destroyed */
516 0, /* todo_flags_start */
517 0, /* todo_flags_finish */
520 class pass_all_early_optimizations
: public gimple_opt_pass
523 pass_all_early_optimizations (gcc::context
*ctxt
)
524 : gimple_opt_pass (pass_data_all_early_optimizations
, ctxt
)
527 /* opt_pass methods: */
528 bool gate (function
*) final override
530 return (optimize
>= 1
531 /* Don't bother doing anything if the program has errors. */
535 }; // class pass_all_early_optimizations
539 static gimple_opt_pass
*
540 make_pass_all_early_optimizations (gcc::context
*ctxt
)
542 return new pass_all_early_optimizations (ctxt
);
547 const pass_data pass_data_all_optimizations
=
549 GIMPLE_PASS
, /* type */
550 "*all_optimizations", /* name */
551 OPTGROUP_NONE
, /* optinfo_flags */
552 TV_OPTIMIZE
, /* tv_id */
553 0, /* properties_required */
554 0, /* properties_provided */
555 0, /* properties_destroyed */
556 0, /* todo_flags_start */
557 0, /* todo_flags_finish */
560 class pass_all_optimizations
: public gimple_opt_pass
563 pass_all_optimizations (gcc::context
*ctxt
)
564 : gimple_opt_pass (pass_data_all_optimizations
, ctxt
)
567 /* opt_pass methods: */
568 bool gate (function
*) final override
570 return optimize
>= 1 && !optimize_debug
;
573 }; // class pass_all_optimizations
577 static gimple_opt_pass
*
578 make_pass_all_optimizations (gcc::context
*ctxt
)
580 return new pass_all_optimizations (ctxt
);
585 const pass_data pass_data_all_optimizations_g
=
587 GIMPLE_PASS
, /* type */
588 "*all_optimizations_g", /* name */
589 OPTGROUP_NONE
, /* optinfo_flags */
590 TV_OPTIMIZE
, /* tv_id */
591 0, /* properties_required */
592 0, /* properties_provided */
593 0, /* properties_destroyed */
594 0, /* todo_flags_start */
595 0, /* todo_flags_finish */
598 class pass_all_optimizations_g
: public gimple_opt_pass
601 pass_all_optimizations_g (gcc::context
*ctxt
)
602 : gimple_opt_pass (pass_data_all_optimizations_g
, ctxt
)
605 /* opt_pass methods: */
606 bool gate (function
*) final override
608 return optimize
>= 1 && optimize_debug
;
611 }; // class pass_all_optimizations_g
615 static gimple_opt_pass
*
616 make_pass_all_optimizations_g (gcc::context
*ctxt
)
618 return new pass_all_optimizations_g (ctxt
);
623 const pass_data pass_data_rest_of_compilation
=
626 "*rest_of_compilation", /* name */
627 OPTGROUP_NONE
, /* optinfo_flags */
628 TV_REST_OF_COMPILATION
, /* tv_id */
629 PROP_rtl
, /* properties_required */
630 0, /* properties_provided */
631 0, /* properties_destroyed */
632 0, /* todo_flags_start */
633 0, /* todo_flags_finish */
636 class pass_rest_of_compilation
: public rtl_opt_pass
639 pass_rest_of_compilation (gcc::context
*ctxt
)
640 : rtl_opt_pass (pass_data_rest_of_compilation
, ctxt
)
643 /* opt_pass methods: */
644 bool gate (function
*) final override
646 /* Early return if there were errors. We can run afoul of our
647 consistency checks, and there's not really much point in fixing them. */
648 return !(rtl_dump_and_exit
|| flag_syntax_only
|| seen_error ());
651 }; // class pass_rest_of_compilation
655 static rtl_opt_pass
*
656 make_pass_rest_of_compilation (gcc::context
*ctxt
)
658 return new pass_rest_of_compilation (ctxt
);
663 const pass_data pass_data_postreload
=
666 "*all-postreload", /* name */
667 OPTGROUP_NONE
, /* optinfo_flags */
668 TV_POSTRELOAD
, /* 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_postreload
: public rtl_opt_pass
679 pass_postreload (gcc::context
*ctxt
)
680 : rtl_opt_pass (pass_data_postreload
, ctxt
)
683 /* opt_pass methods: */
684 bool gate (function
*) final override
{ return reload_completed
; }
686 }; // class pass_postreload
690 static rtl_opt_pass
*
691 make_pass_postreload (gcc::context
*ctxt
)
693 return new pass_postreload (ctxt
);
698 const pass_data pass_data_late_compilation
=
701 "*all-late_compilation", /* name */
702 OPTGROUP_NONE
, /* optinfo_flags */
703 TV_LATE_COMPILATION
, /* tv_id */
704 PROP_rtl
, /* properties_required */
705 0, /* properties_provided */
706 0, /* properties_destroyed */
707 0, /* todo_flags_start */
708 0, /* todo_flags_finish */
711 class pass_late_compilation
: public rtl_opt_pass
714 pass_late_compilation (gcc::context
*ctxt
)
715 : rtl_opt_pass (pass_data_late_compilation
, ctxt
)
718 /* opt_pass methods: */
719 bool gate (function
*) final override
721 return reload_completed
|| targetm
.no_register_allocation
;
724 }; // class pass_late_compilation
728 static rtl_opt_pass
*
729 make_pass_late_compilation (gcc::context
*ctxt
)
731 return new pass_late_compilation (ctxt
);
734 /* Pre-SLP scalar cleanup, it has several cleanup passes like FRE, DSE. */
738 const pass_data pass_data_pre_slp_scalar_cleanup
=
740 GIMPLE_PASS
, /* type */
741 "*pre_slp_scalar_cleanup", /* name */
742 OPTGROUP_LOOP
, /* optinfo_flags */
743 TV_SCALAR_CLEANUP
, /* tv_id */
744 ( PROP_cfg
| PROP_ssa
), /* properties_required */
745 0, /* properties_provided */
746 0, /* properties_destroyed */
747 0, /* todo_flags_start */
748 0, /* todo_flags_finish */
751 class pass_pre_slp_scalar_cleanup
: public gimple_opt_pass
754 pass_pre_slp_scalar_cleanup (gcc::context
*ctxt
)
755 : gimple_opt_pass (pass_data_pre_slp_scalar_cleanup
, ctxt
)
760 gate (function
*fun
) final override
762 return flag_tree_slp_vectorize
763 && (fun
->pending_TODOs
& PENDING_TODO_force_next_scalar_cleanup
);
767 execute (function
*fun
) final override
769 fun
->pending_TODOs
&= ~PENDING_TODO_force_next_scalar_cleanup
;
773 }; // class pass_pre_slp_scalar_cleanup
778 make_pass_pre_slp_scalar_cleanup (gcc::context
*ctxt
)
780 return new pass_pre_slp_scalar_cleanup (ctxt
);
783 /* Set the static pass number of pass PASS to ID and record that
784 in the mapping from static pass number to pass. */
788 set_pass_for_id (int id
, opt_pass
*pass
)
790 pass
->static_pass_number
= id
;
791 if (passes_by_id_size
<= id
)
793 passes_by_id
= XRESIZEVEC (opt_pass
*, passes_by_id
, id
+ 1);
794 memset (passes_by_id
+ passes_by_id_size
, 0,
795 (id
+ 1 - passes_by_id_size
) * sizeof (void *));
796 passes_by_id_size
= id
+ 1;
798 passes_by_id
[id
] = pass
;
801 /* Return the pass with the static pass number ID. */
804 pass_manager::get_pass_for_id (int id
) const
806 if (id
>= passes_by_id_size
)
808 return passes_by_id
[id
];
811 /* Iterate over the pass tree allocating dump file numbers. We want
812 to do this depth first, and independent of whether the pass is
816 register_one_dump_file (opt_pass
*pass
)
818 g
->get_passes ()->register_one_dump_file (pass
);
822 pass_manager::register_one_dump_file (opt_pass
*pass
)
824 char *dot_name
, *flag_name
, *glob_name
;
825 const char *name
, *full_name
, *prefix
;
827 /* Buffer big enough to format a 32-bit UINT_MAX into. */
831 optgroup_flags_t optgroup_flags
= OPTGROUP_NONE
;
832 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
834 /* See below in next_pass_1. */
836 if (pass
->static_pass_number
!= -1)
837 sprintf (num
, "%u", ((int) pass
->static_pass_number
< 0
838 ? 1 : pass
->static_pass_number
));
840 /* The name is both used to identify the pass for the purposes of plugins,
841 and to specify dump file name and option.
842 The latter two might want something short which is not quite unique; for
843 that reason, we may have a disambiguating prefix, followed by a space
844 to mark the start of the following dump file name / option string. */
845 name
= strchr (pass
->name
, ' ');
846 name
= name
? name
+ 1 : pass
->name
;
847 dot_name
= concat (".", name
, num
, NULL
);
848 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
852 optgroup_flags
|= OPTGROUP_IPA
;
854 else if (pass
->type
== GIMPLE_PASS
)
865 flag_name
= concat (prefix
, name
, num
, NULL
);
866 glob_name
= concat (prefix
, name
, NULL
);
867 optgroup_flags
|= pass
->optinfo_flags
;
868 /* For any passes that do not have an optgroup set, and which are not
869 IPA passes setup above, set the optgroup to OPTGROUP_OTHER so that
870 any dump messages are emitted properly under -fopt-info(-optall). */
871 if (optgroup_flags
== OPTGROUP_NONE
)
872 optgroup_flags
= OPTGROUP_OTHER
;
873 id
= dumps
->dump_register (dot_name
, flag_name
, glob_name
, dkind
,
876 set_pass_for_id (id
, pass
);
877 full_name
= concat (prefix
, pass
->name
, num
, NULL
);
878 register_pass_name (pass
, full_name
);
879 free (CONST_CAST (char *, full_name
));
882 /* Register the dump files for the pass_manager starting at PASS. */
885 pass_manager::register_dump_files (opt_pass
*pass
)
889 if (pass
->name
&& pass
->name
[0] != '*')
890 register_one_dump_file (pass
);
893 register_dump_files (pass
->sub
);
900 /* Register PASS with NAME. */
903 pass_manager::register_pass_name (opt_pass
*pass
, const char *name
)
905 if (!m_name_to_pass_map
)
906 m_name_to_pass_map
= new hash_map
<free_string_hash
, opt_pass
*> (256);
908 if (m_name_to_pass_map
->get (name
))
909 return; /* Ignore plugin passes. */
911 const char *unique_name
= xstrdup (name
);
912 m_name_to_pass_map
->put (unique_name
, pass
);
915 /* Map from pass id to canonicalized pass name. */
917 typedef const char *char_ptr
;
918 static vec
<char_ptr
> pass_tab
;
920 /* Callback function for traversing NAME_TO_PASS_MAP. */
923 passes_pass_traverse (const char *const &name
, opt_pass
*const &pass
, void *)
925 gcc_assert (pass
->static_pass_number
> 0);
926 gcc_assert (pass_tab
.exists ());
928 pass_tab
[pass
->static_pass_number
] = name
;
933 /* The function traverses NAME_TO_PASS_MAP and creates a pass info
934 table for dumping purpose. */
937 pass_manager::create_pass_tab (void) const
939 if (!flag_dump_passes
)
942 pass_tab
.safe_grow_cleared (passes_by_id_size
+ 1, true);
943 m_name_to_pass_map
->traverse
<void *, passes_pass_traverse
> (NULL
);
946 static bool override_gate_status (opt_pass
*, tree
, bool);
948 /* Dump the instantiated name for PASS. IS_ON indicates if PASS
949 is turned on or not. */
952 dump_one_pass (opt_pass
*pass
, int pass_indent
)
954 int indent
= 3 * pass_indent
;
956 bool is_on
, is_really_on
;
958 is_on
= pass
->gate (cfun
);
959 is_really_on
= override_gate_status (pass
, current_function_decl
, is_on
);
961 if (pass
->static_pass_number
<= 0)
964 pn
= pass_tab
[pass
->static_pass_number
];
966 fprintf (stderr
, "%*s%-40s%*s:%s%s\n", indent
, " ", pn
,
967 (15 - indent
< 0 ? 0 : 15 - indent
), " ",
968 is_on
? " ON" : " OFF",
969 ((!is_on
) == (!is_really_on
) ? ""
970 : (is_really_on
? " (FORCED_ON)" : " (FORCED_OFF)")));
973 /* Dump pass list PASS with indentation INDENT. */
976 dump_pass_list (opt_pass
*pass
, int indent
)
980 dump_one_pass (pass
, indent
);
982 dump_pass_list (pass
->sub
, indent
+ 1);
988 /* Dump all optimization passes. */
993 g
->get_passes ()->dump_passes ();
997 pass_manager::dump_passes () const
999 push_dummy_function (true);
1000 cgraph_node
*node
= cgraph_node::get_create (current_function_decl
);
1004 dump_pass_list (all_lowering_passes
, 1);
1005 dump_pass_list (all_small_ipa_passes
, 1);
1006 dump_pass_list (all_regular_ipa_passes
, 1);
1007 dump_pass_list (all_late_ipa_passes
, 1);
1008 dump_pass_list (all_passes
, 1);
1011 pop_dummy_function ();
1014 /* Returns the pass with NAME. */
1017 pass_manager::get_pass_by_name (const char *name
)
1019 opt_pass
**p
= m_name_to_pass_map
->get (name
);
1027 /* Range [start, last]. */
1033 const char *assem_name
;
1034 struct uid_range
*next
;
1037 typedef struct uid_range
*uid_range_p
;
1040 static vec
<uid_range_p
> enabled_pass_uid_range_tab
;
1041 static vec
<uid_range_p
> disabled_pass_uid_range_tab
;
1044 /* Parse option string for -fdisable- and -fenable-
1045 The syntax of the options:
1047 -fenable-<pass_name>
1048 -fdisable-<pass_name>
1050 -fenable-<pass_name>=s1:e1,s2:e2,...
1051 -fdisable-<pass_name>=s1:e1,s2:e2,...
1055 enable_disable_pass (const char *arg
, bool is_enable
)
1058 char *range_str
, *phase_name
;
1059 char *argstr
= xstrdup (arg
);
1060 vec
<uid_range_p
> *tab
= 0;
1062 range_str
= strchr (argstr
,'=');
1069 phase_name
= argstr
;
1073 error ("unrecognized option %<-fenable%>");
1075 error ("unrecognized option %<-fdisable%>");
1079 pass
= g
->get_passes ()->get_pass_by_name (phase_name
);
1080 if (!pass
|| pass
->static_pass_number
== -1)
1083 error ("unknown pass %s specified in %<-fenable%>", phase_name
);
1085 error ("unknown pass %s specified in %<-fdisable%>", phase_name
);
1091 tab
= &enabled_pass_uid_range_tab
;
1093 tab
= &disabled_pass_uid_range_tab
;
1095 if ((unsigned) pass
->static_pass_number
>= tab
->length ())
1096 tab
->safe_grow_cleared (pass
->static_pass_number
+ 1, true);
1101 uid_range_p new_range
= XCNEW (struct uid_range
);
1103 new_range
->start
= 0;
1104 new_range
->last
= (unsigned)-1;
1106 slot
= (*tab
)[pass
->static_pass_number
];
1107 new_range
->next
= slot
;
1108 (*tab
)[pass
->static_pass_number
] = new_range
;
1110 inform (UNKNOWN_LOCATION
, "enable pass %s for functions in the range "
1111 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
1113 inform (UNKNOWN_LOCATION
, "disable pass %s for functions in the range "
1114 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
1118 char *next_range
= NULL
;
1119 char *one_range
= range_str
;
1120 char *end_val
= NULL
;
1125 uid_range_p new_range
;
1126 char *invalid
= NULL
;
1128 char *func_name
= NULL
;
1130 next_range
= strchr (one_range
, ',');
1137 end_val
= strchr (one_range
, ':');
1143 start
= strtol (one_range
, &invalid
, 10);
1144 if (*invalid
|| start
< 0)
1146 if (end_val
|| (one_range
[0] >= '0'
1147 && one_range
[0] <= '9'))
1149 error ("Invalid range %s in option %s",
1151 is_enable
? "-fenable" : "-fdisable");
1155 func_name
= one_range
;
1159 new_range
= XCNEW (struct uid_range
);
1162 new_range
->start
= (unsigned) start
;
1163 new_range
->last
= (unsigned) start
;
1167 new_range
->start
= (unsigned) -1;
1168 new_range
->last
= (unsigned) -1;
1169 new_range
->assem_name
= xstrdup (func_name
);
1174 long last
= strtol (end_val
, &invalid
, 10);
1175 if (*invalid
|| last
< start
)
1177 error ("Invalid range %s in option %s",
1179 is_enable
? "-fenable" : "-fdisable");
1183 new_range
= XCNEW (struct uid_range
);
1184 new_range
->start
= (unsigned) start
;
1185 new_range
->last
= (unsigned) last
;
1188 slot
= (*tab
)[pass
->static_pass_number
];
1189 new_range
->next
= slot
;
1190 (*tab
)[pass
->static_pass_number
] = new_range
;
1193 if (new_range
->assem_name
)
1194 inform (UNKNOWN_LOCATION
,
1195 "enable pass %s for function %s",
1196 phase_name
, new_range
->assem_name
);
1198 inform (UNKNOWN_LOCATION
,
1199 "enable pass %s for functions in the range of [%u, %u]",
1200 phase_name
, new_range
->start
, new_range
->last
);
1204 if (new_range
->assem_name
)
1205 inform (UNKNOWN_LOCATION
,
1206 "disable pass %s for function %s",
1207 phase_name
, new_range
->assem_name
);
1209 inform (UNKNOWN_LOCATION
,
1210 "disable pass %s for functions in the range of [%u, %u]",
1211 phase_name
, new_range
->start
, new_range
->last
);
1214 one_range
= next_range
;
1215 } while (next_range
);
1221 /* Enable pass specified by ARG. */
1224 enable_pass (const char *arg
)
1226 enable_disable_pass (arg
, true);
1229 /* Disable pass specified by ARG. */
1232 disable_pass (const char *arg
)
1234 enable_disable_pass (arg
, false);
1237 /* Returns true if PASS is explicitly enabled/disabled for FUNC. */
1240 is_pass_explicitly_enabled_or_disabled (opt_pass
*pass
,
1242 vec
<uid_range_p
> tab
)
1244 uid_range_p slot
, range
;
1246 const char *aname
= NULL
;
1249 || (unsigned) pass
->static_pass_number
>= tab
.length ()
1250 || pass
->static_pass_number
== -1)
1253 slot
= tab
[pass
->static_pass_number
];
1257 cgraph_uid
= func
? cgraph_node::get (func
)->get_uid () : 0;
1258 if (func
&& DECL_ASSEMBLER_NAME_SET_P (func
))
1259 aname
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func
));
1264 if ((unsigned) cgraph_uid
>= range
->start
1265 && (unsigned) cgraph_uid
<= range
->last
)
1267 if (range
->assem_name
&& aname
1268 && !strcmp (range
->assem_name
, aname
))
1270 range
= range
->next
;
1277 /* Update static_pass_number for passes (and the flag
1278 TODO_mark_first_instance).
1280 Passes are constructed with static_pass_number preinitialized to 0
1282 This field is used in two different ways: initially as instance numbers
1283 of their kind, and then as ids within the entire pass manager.
1285 Within pass_manager::pass_manager:
1287 * In add_pass_instance(), as called by next_pass_1 in
1288 NEXT_PASS in init_optimization_passes
1290 * When the initial instance of a pass within a pass manager is seen,
1291 it is flagged, and its static_pass_number is set to -1
1293 * On subsequent times that it is seen, the static pass number
1294 is decremented each time, so that if there are e.g. 4 dups,
1295 they have static_pass_number -4, 2, 3, 4 respectively (note
1296 how the initial one is negative and gives the count); these
1297 can be thought of as instance numbers of the specific pass
1299 * Within the register_dump_files () traversal, set_pass_for_id()
1300 is called on each pass, using these instance numbers to create
1301 dumpfile switches, and then overwriting them with a pass id,
1302 which are global to the whole pass manager (based on
1303 (TDI_end + current value of extra_dump_files_in_use) ) */
1306 add_pass_instance (opt_pass
*new_pass
, bool track_duplicates
,
1307 opt_pass
*initial_pass
)
1309 /* Are we dealing with the first pass of its kind, or a clone? */
1310 if (new_pass
!= initial_pass
)
1312 /* We're dealing with a clone. */
1313 new_pass
->todo_flags_start
&= ~TODO_mark_first_instance
;
1315 /* Indicate to register_dump_files that this pass has duplicates,
1316 and so it should rename the dump file. The first instance will
1317 be -1, and be number of duplicates = -static_pass_number - 1.
1318 Subsequent instances will be > 0 and just the duplicate number. */
1319 if ((new_pass
->name
&& new_pass
->name
[0] != '*') || track_duplicates
)
1321 initial_pass
->static_pass_number
-= 1;
1322 new_pass
->static_pass_number
= -initial_pass
->static_pass_number
;
1327 /* We're dealing with the first pass of its kind. */
1328 new_pass
->todo_flags_start
|= TODO_mark_first_instance
;
1329 new_pass
->static_pass_number
= -1;
1331 invoke_plugin_callbacks (PLUGIN_NEW_PASS
, new_pass
);
1335 /* Add a pass to the pass list. Duplicate the pass if it's already
1339 next_pass_1 (opt_pass
**list
, opt_pass
*pass
, opt_pass
*initial_pass
)
1341 /* Every pass should have a name so that plugins can refer to them. */
1342 gcc_assert (pass
->name
!= NULL
);
1344 add_pass_instance (pass
, false, initial_pass
);
1347 return &(*list
)->next
;
1350 /* List node for an inserted pass instance. We need to keep track of all
1351 the newly-added pass instances (with 'added_pass_nodes' defined below)
1352 so that we can register their dump files after pass-positioning is finished.
1353 Registering dumping files needs to be post-processed or the
1354 static_pass_number of the opt_pass object would be modified and mess up
1355 the dump file names of future pass instances to be added. */
1357 struct pass_list_node
1360 struct pass_list_node
*next
;
1363 static struct pass_list_node
*added_pass_nodes
= NULL
;
1364 static struct pass_list_node
*prev_added_pass_node
;
1366 /* Insert the pass at the proper position. Return true if the pass
1367 is successfully added.
1369 NEW_PASS_INFO - new pass to be inserted
1370 PASS_LIST - root of the pass list to insert the new pass to */
1373 position_pass (struct register_pass_info
*new_pass_info
, opt_pass
**pass_list
)
1375 opt_pass
*pass
= *pass_list
, *prev_pass
= NULL
;
1376 bool success
= false;
1378 for ( ; pass
; prev_pass
= pass
, pass
= pass
->next
)
1380 /* Check if the current pass is of the same type as the new pass and
1381 matches the name and the instance number of the reference pass. */
1382 if (pass
->type
== new_pass_info
->pass
->type
1384 && !strcmp (pass
->name
, new_pass_info
->reference_pass_name
)
1385 && ((new_pass_info
->ref_pass_instance_number
== 0)
1386 || (new_pass_info
->ref_pass_instance_number
==
1387 pass
->static_pass_number
)
1388 || (new_pass_info
->ref_pass_instance_number
== 1
1389 && pass
->todo_flags_start
& TODO_mark_first_instance
)))
1392 struct pass_list_node
*new_pass_node
;
1394 if (new_pass_info
->ref_pass_instance_number
== 0)
1396 new_pass
= new_pass_info
->pass
->clone ();
1397 add_pass_instance (new_pass
, true, new_pass_info
->pass
);
1401 new_pass
= new_pass_info
->pass
;
1402 add_pass_instance (new_pass
, true, new_pass
);
1405 /* Insert the new pass instance based on the positioning op. */
1406 switch (new_pass_info
->pos_op
)
1408 case PASS_POS_INSERT_AFTER
:
1409 new_pass
->next
= pass
->next
;
1410 pass
->next
= new_pass
;
1412 /* Skip newly inserted pass to avoid repeated
1413 insertions in the case where the new pass and the
1414 existing one have the same name. */
1417 case PASS_POS_INSERT_BEFORE
:
1418 new_pass
->next
= pass
;
1420 prev_pass
->next
= new_pass
;
1422 *pass_list
= new_pass
;
1424 case PASS_POS_REPLACE
:
1425 new_pass
->next
= pass
->next
;
1427 prev_pass
->next
= new_pass
;
1429 *pass_list
= new_pass
;
1430 new_pass
->sub
= pass
->sub
;
1431 new_pass
->tv_id
= pass
->tv_id
;
1435 error ("invalid pass positioning operation");
1439 /* Save the newly added pass (instance) in the added_pass_nodes
1440 list so that we can register its dump file later. Note that
1441 we cannot register the dump file now because doing so will modify
1442 the static_pass_number of the opt_pass object and therefore
1443 mess up the dump file name of future instances. */
1444 new_pass_node
= XCNEW (struct pass_list_node
);
1445 new_pass_node
->pass
= new_pass
;
1446 if (!added_pass_nodes
)
1447 added_pass_nodes
= new_pass_node
;
1449 prev_added_pass_node
->next
= new_pass_node
;
1450 prev_added_pass_node
= new_pass_node
;
1455 if (pass
->sub
&& position_pass (new_pass_info
, &pass
->sub
))
1462 /* Hooks a new pass into the pass lists.
1464 PASS_INFO - pass information that specifies the opt_pass object,
1465 reference pass, instance number, and how to position
1469 register_pass (struct register_pass_info
*pass_info
)
1471 g
->get_passes ()->register_pass (pass_info
);
1475 register_pass (opt_pass
* pass
, pass_positioning_ops pos
,
1476 const char* ref_pass_name
, int ref_pass_inst_number
)
1478 register_pass_info i
;
1480 i
.reference_pass_name
= ref_pass_name
;
1481 i
.ref_pass_instance_number
= ref_pass_inst_number
;
1484 g
->get_passes ()->register_pass (&i
);
1488 pass_manager::register_pass (struct register_pass_info
*pass_info
)
1490 bool all_instances
, success
;
1492 /* The checks below could fail in buggy plugins. Existing GCC
1493 passes should never fail these checks, so we mention plugin in
1495 if (!pass_info
->pass
)
1496 fatal_error (input_location
, "plugin cannot register a missing pass");
1498 if (!pass_info
->pass
->name
)
1499 fatal_error (input_location
, "plugin cannot register an unnamed pass");
1501 if (!pass_info
->reference_pass_name
)
1504 "plugin cannot register pass %qs without reference pass name",
1505 pass_info
->pass
->name
);
1507 /* Try to insert the new pass to the pass lists. We need to check
1508 all five lists as the reference pass could be in one (or all) of
1510 all_instances
= pass_info
->ref_pass_instance_number
== 0;
1511 success
= position_pass (pass_info
, &all_lowering_passes
);
1512 if (!success
|| all_instances
)
1513 success
|= position_pass (pass_info
, &all_small_ipa_passes
);
1514 if (!success
|| all_instances
)
1515 success
|= position_pass (pass_info
, &all_regular_ipa_passes
);
1516 if (!success
|| all_instances
)
1517 success
|= position_pass (pass_info
, &all_late_ipa_passes
);
1518 if (!success
|| all_instances
)
1519 success
|= position_pass (pass_info
, &all_passes
);
1523 "pass %qs not found but is referenced by new pass %qs",
1524 pass_info
->reference_pass_name
, pass_info
->pass
->name
);
1526 /* OK, we have successfully inserted the new pass. We need to register
1527 the dump files for the newly added pass and its duplicates (if any).
1528 While doing so, we also delete the pass_list_node
1529 objects created during pass positioning. */
1530 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
1531 while (added_pass_nodes
)
1533 struct pass_list_node
*next_node
= added_pass_nodes
->next
;
1535 /* Handle -fdump-* and -fopt-info. */
1536 dumps
->register_pass (added_pass_nodes
->pass
);
1538 XDELETE (added_pass_nodes
);
1539 added_pass_nodes
= next_node
;
1543 /* Construct the pass tree. The sequencing of passes is driven by
1544 the cgraph routines:
1546 finalize_compilation_unit ()
1547 for each node N in the cgraph
1548 cgraph_analyze_function (N)
1549 cgraph_lower_function (N) -> all_lowering_passes
1551 If we are optimizing, compile is then invoked:
1554 ipa_passes () -> all_small_ipa_passes
1555 -> Analysis of all_regular_ipa_passes
1556 * possible LTO streaming at compilation time *
1557 -> Execution of all_regular_ipa_passes
1558 * possible LTO streaming at link time *
1559 -> all_late_ipa_passes
1560 expand_all_functions ()
1561 for each node N in the cgraph
1562 expand_function (N) -> Transformation of all_regular_ipa_passes
1566 pass_manager::pass_manager (context
*ctxt
)
1567 : all_passes (NULL
), all_small_ipa_passes (NULL
), all_lowering_passes (NULL
),
1568 all_regular_ipa_passes (NULL
),
1569 all_late_ipa_passes (NULL
), passes_by_id (NULL
), passes_by_id_size (0),
1570 m_ctxt (ctxt
), m_name_to_pass_map (NULL
)
1574 /* Zero-initialize pass members. */
1575 #define INSERT_PASSES_AFTER(PASS)
1576 #define PUSH_INSERT_PASSES_WITHIN(PASS)
1577 #define POP_INSERT_PASSES()
1578 #define NEXT_PASS(PASS, NUM) PASS ## _ ## NUM = NULL
1579 #define NEXT_PASS_WITH_ARG(PASS, NUM, ARG) NEXT_PASS (PASS, NUM)
1580 #define TERMINATE_PASS_LIST(PASS)
1581 #include "pass-instances.def"
1582 #undef INSERT_PASSES_AFTER
1583 #undef PUSH_INSERT_PASSES_WITHIN
1584 #undef POP_INSERT_PASSES
1586 #undef NEXT_PASS_WITH_ARG
1587 #undef TERMINATE_PASS_LIST
1589 /* Initialize the pass_lists array. */
1590 #define DEF_PASS_LIST(LIST) pass_lists[PASS_LIST_NO_##LIST] = &LIST;
1592 #undef DEF_PASS_LIST
1594 /* Build the tree of passes. */
1596 #define INSERT_PASSES_AFTER(PASS) \
1598 opt_pass **p_start; \
1599 p_start = p = &(PASS);
1601 #define TERMINATE_PASS_LIST(PASS) \
1602 gcc_assert (p_start == &PASS); \
1606 #define PUSH_INSERT_PASSES_WITHIN(PASS) \
1608 opt_pass **p = &(PASS ## _1)->sub;
1610 #define POP_INSERT_PASSES() \
1613 #define NEXT_PASS(PASS, NUM) \
1615 gcc_assert (PASS ## _ ## NUM == NULL); \
1617 PASS ## _1 = make_##PASS (m_ctxt); \
1620 gcc_assert (PASS ## _1); \
1621 PASS ## _ ## NUM = PASS ## _1->clone (); \
1623 p = next_pass_1 (p, PASS ## _ ## NUM, PASS ## _1); \
1626 #define NEXT_PASS_WITH_ARG(PASS, NUM, ARG) \
1628 NEXT_PASS (PASS, NUM); \
1629 PASS ## _ ## NUM->set_pass_param (0, ARG); \
1632 #include "pass-instances.def"
1634 #undef INSERT_PASSES_AFTER
1635 #undef PUSH_INSERT_PASSES_WITHIN
1636 #undef POP_INSERT_PASSES
1638 #undef NEXT_PASS_WITH_ARG
1639 #undef TERMINATE_PASS_LIST
1641 /* Register the passes with the tree dump code. */
1642 register_dump_files (all_lowering_passes
);
1643 register_dump_files (all_small_ipa_passes
);
1644 register_dump_files (all_regular_ipa_passes
);
1645 register_dump_files (all_late_ipa_passes
);
1646 register_dump_files (all_passes
);
1650 delete_pass_tree (opt_pass
*pass
)
1654 /* Recurse into child passes. */
1655 delete_pass_tree (pass
->sub
);
1657 opt_pass
*next
= pass
->next
;
1659 /* Delete this pass. */
1662 /* Iterate onto sibling passes. */
1667 pass_manager::~pass_manager ()
1669 XDELETEVEC (passes_by_id
);
1671 /* Call delete_pass_tree on each of the pass_lists. */
1672 #define DEF_PASS_LIST(LIST) \
1673 delete_pass_tree (*pass_lists[PASS_LIST_NO_##LIST]);
1675 #undef DEF_PASS_LIST
1677 delete m_name_to_pass_map
;
1680 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1681 function CALLBACK for every function in the call graph. Otherwise,
1682 call CALLBACK on the current function. */
1685 do_per_function (void (*callback
) (function
*, void *data
), void *data
)
1687 if (current_function_decl
)
1688 callback (cfun
, data
);
1691 struct cgraph_node
*node
;
1692 FOR_EACH_DEFINED_FUNCTION (node
)
1693 if (node
->analyzed
&& (gimple_has_body_p (node
->decl
) && !in_lto_p
)
1694 && (!node
->clone_of
|| node
->decl
!= node
->clone_of
->decl
))
1695 callback (DECL_STRUCT_FUNCTION (node
->decl
), data
);
1699 /* Hook called when NODE is removed and therefore should be
1700 excluded from order vector. DATA is a hash set with removed nodes. */
1703 remove_cgraph_node_from_order (cgraph_node
*node
, void *data
)
1705 hash_set
<cgraph_node
*> *removed_nodes
= (hash_set
<cgraph_node
*> *)data
;
1706 removed_nodes
->add (node
);
1709 /* Hook called when NODE is insert and therefore should be
1710 excluded from removed_nodes. DATA is a hash set with removed nodes. */
1713 insert_cgraph_node_to_order (cgraph_node
*node
, void *data
)
1715 hash_set
<cgraph_node
*> *removed_nodes
= (hash_set
<cgraph_node
*> *)data
;
1716 removed_nodes
->remove (node
);
1719 /* Hook called when NODE is duplicated and therefore should be
1720 excluded from removed_nodes. DATA is a hash set with removed nodes. */
1723 duplicate_cgraph_node_to_order (cgraph_node
*node
, cgraph_node
*node2
,
1726 hash_set
<cgraph_node
*> *removed_nodes
= (hash_set
<cgraph_node
*> *)data
;
1727 gcc_checking_assert (!removed_nodes
->contains (node
));
1728 removed_nodes
->remove (node2
);
1732 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1733 function CALLBACK for every function in the call graph. Otherwise,
1734 call CALLBACK on the current function.
1735 This function is global so that plugins can use it. */
1737 do_per_function_toporder (void (*callback
) (function
*, void *data
), void *data
)
1741 if (current_function_decl
)
1742 callback (cfun
, data
);
1745 hash_set
<cgraph_node
*> removed_nodes
;
1746 unsigned nnodes
= symtab
->cgraph_count
;
1747 cgraph_node
**order
= XNEWVEC (cgraph_node
*, nnodes
);
1749 nnodes
= ipa_reverse_postorder (order
);
1750 for (i
= nnodes
- 1; i
>= 0; i
--)
1751 order
[i
]->process
= 1;
1752 cgraph_node_hook_list
*removal_hook
1753 = symtab
->add_cgraph_removal_hook (remove_cgraph_node_from_order
,
1755 cgraph_node_hook_list
*insertion_hook
1756 = symtab
->add_cgraph_insertion_hook (insert_cgraph_node_to_order
,
1758 cgraph_2node_hook_list
*duplication_hook
1759 = symtab
->add_cgraph_duplication_hook (duplicate_cgraph_node_to_order
,
1761 for (i
= nnodes
- 1; i
>= 0; i
--)
1763 cgraph_node
*node
= order
[i
];
1765 /* Function could be inlined and removed as unreachable. */
1766 if (node
== NULL
|| removed_nodes
.contains (node
))
1770 if (node
->has_gimple_body_p ())
1772 struct function
*fn
= DECL_STRUCT_FUNCTION (node
->decl
);
1774 callback (fn
, data
);
1778 symtab
->remove_cgraph_removal_hook (removal_hook
);
1779 symtab
->remove_cgraph_insertion_hook (insertion_hook
);
1780 symtab
->remove_cgraph_duplication_hook (duplication_hook
);
1786 /* Helper function to perform function body dump. */
1789 execute_function_dump (function
*fn
, void *data
)
1791 opt_pass
*pass
= (opt_pass
*)data
;
1797 if (fn
->curr_properties
& PROP_gimple
)
1798 dump_function_to_file (fn
->decl
, dump_file
, dump_flags
);
1800 print_rtl_with_bb (dump_file
, get_insns (), dump_flags
);
1802 /* Flush the file. If verification fails, we won't be able to
1803 close the file before aborting. */
1806 if ((fn
->curr_properties
& PROP_cfg
)
1807 && (dump_flags
& TDF_GRAPH
))
1809 gcc::dump_manager
*dumps
= g
->get_dumps ();
1810 struct dump_file_info
*dfi
1811 = dumps
->get_dump_file_info (pass
->static_pass_number
);
1812 if (!dfi
->graph_dump_initialized
)
1814 clean_graph_dump_file (dump_file_name
);
1815 dfi
->graph_dump_initialized
= true;
1817 print_graph_cfg (dump_file_name
, fn
);
1824 /* This function is called when an internal compiler error is encountered.
1825 Ensure that function dump is made available before compiler is aborted. */
1828 emergency_dump_function ()
1832 enum opt_pass_type pt
= current_pass
->type
;
1833 fnotice (stderr
, "during %s pass: %s\n",
1834 pt
== GIMPLE_PASS
? "GIMPLE" : pt
== RTL_PASS
? "RTL" : "IPA",
1835 current_pass
->name
);
1836 if (!dump_file
|| !cfun
)
1838 fnotice (stderr
, "dump file: %s\n", dump_file_name
);
1839 fprintf (dump_file
, "\n\n\nEMERGENCY DUMP:\n\n");
1840 execute_function_dump (cfun
, current_pass
);
1842 /* Normally the passmanager will close the graphs as a pass could be wanting
1843 to print multiple digraphs. But during an emergency dump there can only be
1844 one and we must finish the graph manually. */
1845 if ((cfun
->curr_properties
& PROP_cfg
)
1846 && (dump_flags
& TDF_GRAPH
))
1847 finish_graph_dump_file (dump_file_name
);
1849 if (symtab
&& current_pass
->type
== IPA_PASS
)
1850 symtab
->dump (dump_file
);
1853 static struct profile_record
*profile_record
;
1855 /* Do profile consistency book-keeping for the pass with static number INDEX.
1856 RUN is true if the pass really runs, or FALSE
1857 if we are only book-keeping on passes that may have selectively disabled
1858 themselves on a given function. */
1861 check_profile_consistency (int index
, bool run
)
1863 pass_manager
*passes
= g
->get_passes ();
1866 if (!profile_record
)
1867 profile_record
= XCNEWVEC (struct profile_record
,
1868 passes
->passes_by_id_size
);
1869 gcc_assert (index
< passes
->passes_by_id_size
&& index
>= 0);
1870 profile_record
[index
].run
|= run
;
1871 profile_record_check_consistency (&profile_record
[index
]);
1874 /* Account profile the pass with static number INDEX.
1875 RUN is true if the pass really runs, or FALSE
1876 if we are only book-keeping on passes that may have selectively disabled
1877 themselves on a given function. */
1880 account_profile (int index
, bool run
)
1882 pass_manager
*passes
= g
->get_passes ();
1885 if (!profile_record
)
1886 profile_record
= XCNEWVEC (struct profile_record
,
1887 passes
->passes_by_id_size
);
1888 gcc_assert (index
< passes
->passes_by_id_size
&& index
>= 0);
1889 profile_record
[index
].run
|= run
;
1890 profile_record_account_profile (&profile_record
[index
]);
1893 /* Account profile for IPA pass. Callback for do_per_function. */
1896 account_profile_1 (function
*fn
, void *data
)
1898 opt_pass
*pass
= (opt_pass
*)data
;
1901 check_profile_consistency (pass
->static_pass_number
, true);
1902 account_profile (pass
->static_pass_number
, true);
1906 /* Account profile chnages to all passes in list starting in SUB. */
1909 account_profile_in_list (opt_pass
*sub
)
1911 for (; sub
; sub
= sub
->next
)
1913 check_profile_consistency (sub
->static_pass_number
, false);
1914 account_profile (sub
->static_pass_number
, false);
1916 account_profile_in_list (sub
->sub
);
1920 /* Output profile consistency. */
1923 dump_profile_report (void)
1925 g
->get_passes ()->dump_profile_report ();
1929 pass_manager::dump_profile_report () const
1931 int last_count_in
= 0, last_prob_out
= 0;
1932 double last_dyn_count_in
= 0, last_dyn_prob_out
= 0;
1933 double last_time
= 0;
1935 double rel_time_change
, rel_size_change
;
1936 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
1938 if (!profile_record
)
1941 FILE *dump_file
= dump_begin (TDI_profile_report
, NULL
);
1942 if (dump_file
== NULL
)
1945 fprintf (dump_file
, "Profile consistency report:\n\n");
1947 "Pass dump id and name |static mismatch "
1948 "|dynamic mismatch "
1951 " |in count |out prob "
1952 "|in count |out prob "
1955 for (int i
= 1; i
< passes_by_id_size
; i
++)
1956 if (profile_record
[i
].run
)
1959 rel_time_change
= (profile_record
[i
].time
1960 - last_time
) * 100 / last_time
;
1962 rel_time_change
= 0;
1964 rel_size_change
= (profile_record
[i
].size
1965 - (double)last_size
) * 100 / (double)last_size
;
1967 rel_size_change
= 0;
1969 dump_file_info
*dfi
= dumps
->get_dump_file_info (i
);
1971 fprintf (dump_file
, "%3i%c %-28s| %6i",
1973 passes_by_id
[i
]->type
== GIMPLE_PASS
? 't'
1974 : passes_by_id
[i
]->type
== RTL_PASS
? 'r'
1976 passes_by_id
[i
]->name
,
1977 profile_record
[i
].num_mismatched_count_in
);
1978 if (profile_record
[i
].num_mismatched_count_in
!= last_count_in
)
1979 fprintf (dump_file
, " %+5i",
1980 profile_record
[i
].num_mismatched_count_in
1983 fprintf (dump_file
, " ");
1984 fprintf (dump_file
, "| %6i",
1985 profile_record
[i
].num_mismatched_prob_out
);
1986 if (profile_record
[i
].num_mismatched_prob_out
!= last_prob_out
)
1987 fprintf (dump_file
, " %+5i",
1988 profile_record
[i
].num_mismatched_prob_out
1991 fprintf (dump_file
, " ");
1993 fprintf (dump_file
, "| %12.0f",
1994 profile_record
[i
].dyn_mismatched_count_in
);
1995 if (profile_record
[i
].dyn_mismatched_count_in
!= last_dyn_count_in
)
1996 fprintf (dump_file
, " %+12.0f",
1997 profile_record
[i
].dyn_mismatched_count_in
1998 - last_dyn_count_in
);
2000 fprintf (dump_file
, " ");
2001 fprintf (dump_file
, "| %12.0f",
2002 profile_record
[i
].dyn_mismatched_prob_out
);
2003 if (profile_record
[i
].dyn_mismatched_prob_out
!= last_dyn_prob_out
)
2004 fprintf (dump_file
, " %+12.0f",
2005 profile_record
[i
].dyn_mismatched_prob_out
2006 - last_dyn_prob_out
);
2008 fprintf (dump_file
, " ");
2010 /* Size/time units change across gimple and RTL. */
2011 if (i
== pass_expand_1
->static_pass_number
)
2013 "|-------------------|--------------------------");
2016 fprintf (dump_file
, "| %8i", profile_record
[i
].size
);
2017 if (rel_size_change
)
2018 fprintf (dump_file
, " %+8.1f%%", rel_size_change
);
2020 fprintf (dump_file
, " ");
2021 fprintf (dump_file
, "| %12.0f", profile_record
[i
].time
);
2022 /* Time units changes with profile estimate and feedback. */
2023 if (i
== pass_profile_1
->static_pass_number
2024 || i
== pass_ipa_tree_profile_1
->static_pass_number
)
2025 fprintf (dump_file
, "-------------");
2026 else if (rel_time_change
)
2027 fprintf (dump_file
, " %+11.1f%%", rel_time_change
);
2029 fprintf (dump_file
, " ");
2031 fprintf (dump_file
, "|\n");
2032 last_prob_out
= profile_record
[i
].num_mismatched_prob_out
;
2033 last_count_in
= profile_record
[i
].num_mismatched_count_in
;
2034 last_dyn_prob_out
= profile_record
[i
].dyn_mismatched_prob_out
;
2035 last_dyn_count_in
= profile_record
[i
].dyn_mismatched_count_in
;
2036 last_time
= profile_record
[i
].time
;
2037 last_size
= profile_record
[i
].size
;
2040 dump_end (TDI_profile_report
, dump_file
);
2043 /* Perform all TODO actions that ought to be done on each function. */
2046 execute_function_todo (function
*fn
, void *data
)
2048 bool from_ipa_pass
= (cfun
== NULL
);
2049 unsigned int flags
= (size_t)data
;
2050 flags
&= ~fn
->last_verified
;
2056 /* If we need to cleanup the CFG let it perform a needed SSA update. */
2057 if (flags
& TODO_cleanup_cfg
)
2058 cleanup_tree_cfg (flags
& TODO_update_ssa_any
);
2059 else if (flags
& TODO_update_ssa_any
)
2060 update_ssa (flags
& TODO_update_ssa_any
);
2061 gcc_assert (!need_ssa_update_p (fn
));
2063 if (flag_tree_pta
&& (flags
& TODO_rebuild_alias
))
2064 compute_may_aliases ();
2066 if (optimize
&& (flags
& TODO_update_address_taken
))
2067 execute_update_addresses_taken ();
2069 if (flags
& TODO_remove_unused_locals
)
2070 remove_unused_locals ();
2072 if (flags
& TODO_rebuild_cgraph_edges
)
2073 cgraph_edge::rebuild_edges ();
2075 gcc_assert (dom_info_state (fn
, CDI_POST_DOMINATORS
) == DOM_NONE
);
2076 /* If we've seen errors do not bother running any verifiers. */
2077 if (flag_checking
&& !seen_error ())
2079 dom_state pre_verify_state
= dom_info_state (fn
, CDI_DOMINATORS
);
2080 dom_state pre_verify_pstate
= dom_info_state (fn
, CDI_POST_DOMINATORS
);
2082 if (flags
& TODO_verify_il
)
2084 if (cfun
->curr_properties
& PROP_gimple
)
2086 if (cfun
->curr_properties
& PROP_cfg
)
2087 /* IPA passes leave stmts to be fixed up, so make sure to
2088 not verify stmts really throw. */
2089 verify_gimple_in_cfg (cfun
, !from_ipa_pass
);
2091 verify_gimple_in_seq (gimple_body (cfun
->decl
));
2093 if (cfun
->curr_properties
& PROP_ssa
)
2094 /* IPA passes leave stmts to be fixed up, so make sure to
2095 not verify SSA operands whose verifier will choke on that. */
2096 verify_ssa (true, !from_ipa_pass
);
2097 /* IPA passes leave basic-blocks unsplit, so make sure to
2098 not trip on that. */
2099 if ((cfun
->curr_properties
& PROP_cfg
)
2101 verify_flow_info ();
2103 && ! loops_state_satisfies_p (LOOPS_NEED_FIXUP
))
2105 verify_loop_structure ();
2106 if (loops_state_satisfies_p (LOOP_CLOSED_SSA
))
2107 verify_loop_closed_ssa (false);
2109 if (cfun
->curr_properties
& PROP_rtl
)
2110 verify_rtl_sharing ();
2113 /* Make sure verifiers don't change dominator state. */
2114 gcc_assert (dom_info_state (fn
, CDI_DOMINATORS
) == pre_verify_state
);
2115 gcc_assert (dom_info_state (fn
, CDI_POST_DOMINATORS
) == pre_verify_pstate
);
2118 fn
->last_verified
= flags
& TODO_verify_all
;
2122 /* For IPA passes make sure to release dominator info, it can be
2123 computed by non-verifying TODOs. */
2126 free_dominance_info (fn
, CDI_DOMINATORS
);
2127 free_dominance_info (fn
, CDI_POST_DOMINATORS
);
2131 /* Perform all TODO actions. */
2133 execute_todo (unsigned int flags
)
2137 && need_ssa_update_p (cfun
))
2138 gcc_assert (flags
& TODO_update_ssa_any
);
2140 statistics_fini_pass ();
2143 do_per_function (execute_function_todo
, (void *)(size_t) flags
);
2145 /* At this point we should not have any unreachable code in the
2146 CFG, so it is safe to flush the pending freelist for SSA_NAMES. */
2147 if (cfun
&& cfun
->gimple_df
)
2148 flush_ssaname_freelist ();
2150 /* Always remove functions just as before inlining: IPA passes might be
2151 interested to see bodies of extern inline functions that are not inlined
2152 to analyze side effects. The full removal is done just at the end
2153 of IPA pass queue. */
2154 if (flags
& TODO_remove_functions
)
2157 symtab
->remove_unreachable_nodes (dump_file
);
2160 if ((flags
& TODO_dump_symtab
) && dump_file
&& !current_function_decl
)
2163 symtab
->dump (dump_file
);
2164 /* Flush the file. If verification fails, we won't be able to
2165 close the file before aborting. */
2169 /* Now that the dumping has been done, we can get rid of the optional
2171 if (flags
& TODO_df_finish
)
2172 df_finish_pass ((flags
& TODO_df_verify
) != 0);
2175 /* Verify invariants that should hold between passes. This is a place
2176 to put simple sanity checks. */
2179 verify_interpass_invariants (void)
2181 gcc_checking_assert (!fold_deferring_overflow_warnings_p ());
2184 /* Clear the last verified flag. */
2187 clear_last_verified (function
*fn
, void *data ATTRIBUTE_UNUSED
)
2189 fn
->last_verified
= 0;
2192 /* Helper function. Verify that the properties has been turn into the
2193 properties expected by the pass. */
2196 verify_curr_properties (function
*fn
, void *data
)
2198 unsigned int props
= (size_t)data
;
2199 gcc_assert ((fn
->curr_properties
& props
) == props
);
2202 /* Release dump file name if set. */
2205 release_dump_file_name (void)
2209 free (CONST_CAST (char *, dump_file_name
));
2210 dump_file_name
= NULL
;
2214 /* Initialize pass dump file. */
2215 /* This is non-static so that the plugins can use it. */
2218 pass_init_dump_file (opt_pass
*pass
)
2220 /* If a dump file name is present, open it if enabled. */
2221 if (pass
->static_pass_number
!= -1)
2223 timevar_push (TV_DUMP
);
2224 gcc::dump_manager
*dumps
= g
->get_dumps ();
2225 bool initializing_dump
=
2226 !dumps
->dump_initialized_p (pass
->static_pass_number
);
2227 release_dump_file_name ();
2228 dump_file_name
= dumps
->get_dump_file_name (pass
->static_pass_number
);
2229 dumps
->dump_start (pass
->static_pass_number
, &dump_flags
);
2230 if (dump_file
&& current_function_decl
&& ! (dump_flags
& TDF_GIMPLE
))
2231 dump_function_header (dump_file
, current_function_decl
, dump_flags
);
2232 if (initializing_dump
2233 && dump_file
&& (dump_flags
& TDF_GRAPH
)
2234 && cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2236 clean_graph_dump_file (dump_file_name
);
2237 struct dump_file_info
*dfi
2238 = dumps
->get_dump_file_info (pass
->static_pass_number
);
2239 dfi
->graph_dump_initialized
= true;
2241 timevar_pop (TV_DUMP
);
2242 return initializing_dump
;
2248 /* Flush PASS dump file. */
2249 /* This is non-static so that plugins can use it. */
2252 pass_fini_dump_file (opt_pass
*pass
)
2254 timevar_push (TV_DUMP
);
2256 /* Flush and close dump file. */
2257 release_dump_file_name ();
2259 g
->get_dumps ()->dump_finish (pass
->static_pass_number
);
2260 timevar_pop (TV_DUMP
);
2263 /* After executing the pass, apply expected changes to the function
2267 update_properties_after_pass (function
*fn
, void *data
)
2269 opt_pass
*pass
= (opt_pass
*) data
;
2270 fn
->curr_properties
= (fn
->curr_properties
| pass
->properties_provided
)
2271 & ~pass
->properties_destroyed
;
2274 /* Execute summary generation for all of the passes in IPA_PASS. */
2277 execute_ipa_summary_passes (ipa_opt_pass_d
*ipa_pass
)
2281 opt_pass
*pass
= ipa_pass
;
2283 /* Execute all of the IPA_PASSes in the list. */
2284 if (ipa_pass
->type
== IPA_PASS
2285 && pass
->gate (cfun
)
2286 && ipa_pass
->generate_summary
)
2288 pass_init_dump_file (pass
);
2290 /* If a timevar is present, start it. */
2292 timevar_push (pass
->tv_id
);
2294 current_pass
= pass
;
2295 ipa_pass
->generate_summary ();
2299 timevar_pop (pass
->tv_id
);
2301 pass_fini_dump_file (pass
);
2303 ipa_pass
= (ipa_opt_pass_d
*)ipa_pass
->next
;
2307 /* Execute IPA_PASS function transform on NODE. */
2310 execute_one_ipa_transform_pass (struct cgraph_node
*node
,
2311 ipa_opt_pass_d
*ipa_pass
, bool do_not_collect
)
2313 opt_pass
*pass
= ipa_pass
;
2314 unsigned int todo_after
= 0;
2316 current_pass
= pass
;
2317 if (!ipa_pass
->function_transform
)
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_gimple
)) != 0;
2324 pass_init_dump_file (pass
);
2326 /* If a timevar is present, start it. */
2327 if (pass
->tv_id
!= TV_NONE
)
2328 timevar_push (pass
->tv_id
);
2330 /* Run pre-pass verification. */
2331 execute_todo (ipa_pass
->function_transform_todo_flags_start
);
2334 todo_after
= ipa_pass
->function_transform (node
);
2336 /* Run post-pass cleanup and verification. */
2337 execute_todo (todo_after
);
2338 verify_interpass_invariants ();
2341 if (pass
->tv_id
!= TV_NONE
)
2342 timevar_pop (pass
->tv_id
);
2345 do_per_function (execute_function_dump
, pass
);
2346 pass_fini_dump_file (pass
);
2348 current_pass
= NULL
;
2349 redirect_edge_var_map_empty ();
2351 /* Signal this is a suitable GC collection point. */
2352 if (!do_not_collect
&& !(todo_after
& TODO_do_not_ggc_collect
))
2356 /* For the current function, execute all ipa transforms. */
2359 execute_all_ipa_transforms (bool do_not_collect
)
2361 struct cgraph_node
*node
;
2362 node
= cgraph_node::get (current_function_decl
);
2365 cgraph_node
*next_clone
;
2366 for (cgraph_node
*n
= node
->clones
; n
; n
= next_clone
)
2368 next_clone
= n
->next_sibling_clone
;
2369 if (n
->decl
!= node
->decl
)
2370 n
->materialize_clone ();
2374 gcc::pass_manager
*passes
= g
->get_passes ();
2375 bool report
= profile_report
&& (cfun
->curr_properties
& PROP_gimple
) != 0;
2378 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
2380 for (auto p
: node
->ipa_transforms_to_apply
)
2382 /* To get consistent statistics, we need to account each functio
2383 to each IPA pass. */
2386 for (;j
< p
->static_pass_number
; j
++)
2387 if (passes
->get_pass_for_id (j
)
2388 && passes
->get_pass_for_id (j
)->type
== IPA_PASS
2389 && ((ipa_opt_pass_d
*)passes
->get_pass_for_id (j
))
2390 ->function_transform
)
2392 check_profile_consistency (j
, true);
2393 account_profile (j
, true);
2395 gcc_checking_assert (passes
->get_pass_for_id (j
) == p
);
2397 execute_one_ipa_transform_pass (node
, p
, do_not_collect
);
2399 /* Account remaining IPA passes. */
2402 for (;!passes
->get_pass_for_id (j
)
2403 || passes
->get_pass_for_id (j
)->type
!= RTL_PASS
; j
++)
2404 if (passes
->get_pass_for_id (j
)
2405 && passes
->get_pass_for_id (j
)->type
== IPA_PASS
2406 && ((ipa_opt_pass_d
*)passes
->get_pass_for_id (j
))
2407 ->function_transform
)
2409 check_profile_consistency (j
, true);
2410 account_profile (j
, true);
2414 node
->ipa_transforms_to_apply
.release ();
2417 /* Check if PASS is explicitly disabled or enabled and return
2418 the gate status. FUNC is the function to be processed, and
2419 GATE_STATUS is the gate status determined by pass manager by
2423 override_gate_status (opt_pass
*pass
, tree func
, bool gate_status
)
2425 bool explicitly_enabled
= false;
2426 bool explicitly_disabled
= false;
2429 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2430 enabled_pass_uid_range_tab
);
2432 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2433 disabled_pass_uid_range_tab
);
2435 gate_status
= !explicitly_disabled
&& (gate_status
|| explicitly_enabled
);
2440 /* Determine if PASS_NAME matches CRITERION.
2441 Not a pure predicate, since it can update CRITERION, to support
2442 matching the Nth invocation of a pass.
2443 Subroutine of should_skip_pass_p. */
2446 determine_pass_name_match (const char *pass_name
, char *criterion
)
2448 size_t namelen
= strlen (pass_name
);
2449 if (! strncmp (pass_name
, criterion
, namelen
))
2451 /* The following supports starting with the Nth invocation
2452 of a pass (where N does not necessarily is equal to the
2453 dump file suffix). */
2454 if (criterion
[namelen
] == '\0'
2455 || (criterion
[namelen
] == '1'
2456 && criterion
[namelen
+ 1] == '\0'))
2460 if (criterion
[namelen
+ 1] == '\0')
2461 --criterion
[namelen
];
2469 /* For skipping passes until "startwith" pass.
2470 Return true iff PASS should be skipped.
2471 Clear cfun->pass_startwith when encountering the "startwith" pass,
2472 so that all subsequent passes are run. */
2475 should_skip_pass_p (opt_pass
*pass
)
2479 if (!cfun
->pass_startwith
)
2482 /* For __GIMPLE functions, we have to at least start when we leave
2483 SSA. Hence, we need to detect the "expand" pass, and stop skipping
2484 when we encounter it. A cheap way to identify "expand" is it to
2485 detect the destruction of PROP_ssa.
2486 For __RTL functions, we invoke "rest_of_compilation" directly, which
2487 is after "expand", and hence we don't reach this conditional. */
2488 if (pass
->properties_destroyed
& PROP_ssa
)
2491 fprintf (stderr
, "starting anyway when leaving SSA: %s\n", pass
->name
);
2492 cfun
->pass_startwith
= NULL
;
2496 if (determine_pass_name_match (pass
->name
, cfun
->pass_startwith
))
2499 fprintf (stderr
, "found starting pass: %s\n", pass
->name
);
2500 cfun
->pass_startwith
= NULL
;
2504 /* For GIMPLE passes, run any property provider (but continue skipping
2506 We don't want to force running RTL passes that are property providers:
2507 "expand" is covered above, and the only pass other than "expand" that
2508 provides a property is "into_cfglayout" (PROP_cfglayout), which does
2509 too much for a dumped __RTL function. */
2510 if (pass
->type
== GIMPLE_PASS
2511 && pass
->properties_provided
!= 0)
2514 /* We need to (re-)build cgraph edges as needed. */
2515 if (strstr (pass
->name
, "build_cgraph_edges") != NULL
)
2518 /* We need to run ISEL as that lowers VEC_COND_EXPR but doesn't provide
2520 if (strstr (pass
->name
, "isel") != NULL
)
2523 /* Don't skip df init; later RTL passes need it. */
2524 if (strstr (pass
->name
, "dfinit") != NULL
2525 || strstr (pass
->name
, "dfinish") != NULL
)
2529 fprintf (stderr
, "skipping pass: %s\n", pass
->name
);
2531 /* If we get here, then we have a "startwith" that we haven't seen yet;
2536 /* Skip the given pass, for handling passes before "startwith"
2537 in __GIMPLE and__RTL-marked functions.
2538 In theory, this ought to be a no-op, but some of the RTL passes
2539 need additional processing here. */
2542 skip_pass (opt_pass
*pass
)
2544 /* Pass "reload" sets the global "reload_completed", and many
2545 things depend on this (e.g. instructions in .md files). */
2546 if (strcmp (pass
->name
, "reload") == 0)
2547 reload_completed
= 1;
2549 /* Similar for pass "pro_and_epilogue" and the "epilogue_completed" global
2551 if (strcmp (pass
->name
, "pro_and_epilogue") == 0)
2552 epilogue_completed
= 1;
2554 /* The INSN_ADDRESSES vec is normally set up by
2555 shorten_branches; set it up for the benefit of passes that
2557 if (strcmp (pass
->name
, "shorten") == 0)
2558 INSN_ADDRESSES_ALLOC (get_max_uid ());
2560 /* Update the cfg hooks as appropriate. */
2561 if (strcmp (pass
->name
, "into_cfglayout") == 0)
2563 cfg_layout_rtl_register_cfg_hooks ();
2564 cfun
->curr_properties
|= PROP_cfglayout
;
2566 if (strcmp (pass
->name
, "outof_cfglayout") == 0)
2568 rtl_register_cfg_hooks ();
2569 cfun
->curr_properties
&= ~PROP_cfglayout
;
2576 execute_one_pass (opt_pass
*pass
)
2578 unsigned int todo_after
= 0;
2582 /* IPA passes are executed on whole program, so cfun should be NULL.
2583 Other passes need function context set. */
2584 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
2585 gcc_assert (!cfun
&& !current_function_decl
);
2587 gcc_assert (cfun
&& current_function_decl
);
2589 current_pass
= pass
;
2591 /* Check whether gate check should be avoided.
2592 User controls the value of the gate through the parameter "gate_status". */
2593 gate_status
= pass
->gate (cfun
);
2594 gate_status
= override_gate_status (pass
, current_function_decl
, gate_status
);
2596 /* Override gate with plugin. */
2597 invoke_plugin_callbacks (PLUGIN_OVERRIDE_GATE
, &gate_status
);
2601 /* Run so passes selectively disabling themselves on a given function
2602 are not miscounted. */
2603 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
)
2604 && pass
->type
!= IPA_PASS
&& pass
->type
!= SIMPLE_IPA_PASS
)
2606 check_profile_consistency (pass
->static_pass_number
, false);
2607 account_profile (pass
->static_pass_number
, false);
2609 account_profile_in_list (pass
->sub
);
2611 current_pass
= NULL
;
2615 if (should_skip_pass_p (pass
))
2621 /* Pass execution event trigger: useful to identify passes being
2623 invoke_plugin_callbacks (PLUGIN_PASS_EXECUTION
, pass
);
2625 if (!quiet_flag
&& !cfun
)
2626 fprintf (stderr
, " <%s>", pass
->name
? pass
->name
: "");
2628 /* Note that the folders should only create gimple expressions.
2629 This is a hack until the new folder is ready. */
2630 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_gimple
)) != 0;
2632 pass_init_dump_file (pass
);
2634 /* If a timevar is present, start it. */
2635 if (pass
->tv_id
!= TV_NONE
)
2636 timevar_push (pass
->tv_id
);
2639 /* Run pre-pass verification. */
2640 execute_todo (pass
->todo_flags_start
);
2643 do_per_function (verify_curr_properties
,
2644 (void *)(size_t)pass
->properties_required
);
2647 todo_after
= pass
->execute (cfun
);
2649 if (todo_after
& TODO_discard_function
)
2652 if (pass
->tv_id
!= TV_NONE
)
2653 timevar_pop (pass
->tv_id
);
2655 pass_fini_dump_file (pass
);
2658 /* As cgraph_node::release_body expects release dominators info,
2659 we have to release it. */
2660 if (dom_info_available_p (CDI_DOMINATORS
))
2661 free_dominance_info (CDI_DOMINATORS
);
2663 if (dom_info_available_p (CDI_POST_DOMINATORS
))
2664 free_dominance_info (CDI_POST_DOMINATORS
);
2666 if (cfun
->assume_function
)
2668 /* For assume functions, don't release body, keep it around. */
2669 cfun
->curr_properties
|= PROP_assumptions_done
;
2671 current_pass
= NULL
;
2675 tree fn
= cfun
->decl
;
2678 cgraph_node::get (fn
)->release_body ();
2680 current_pass
= NULL
;
2681 redirect_edge_var_map_empty ();
2688 do_per_function (clear_last_verified
, NULL
);
2690 do_per_function (update_properties_after_pass
, pass
);
2692 /* Run post-pass cleanup and verification. */
2693 execute_todo (todo_after
| pass
->todo_flags_finish
| TODO_verify_il
);
2696 /* IPA passes are accounted at transform time. */
2697 if (pass
->type
== IPA_PASS
)
2699 else if (pass
->type
== SIMPLE_IPA_PASS
)
2700 do_per_function (account_profile_1
, pass
);
2701 else if (cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2703 check_profile_consistency (pass
->static_pass_number
, true);
2704 account_profile (pass
->static_pass_number
, true);
2708 verify_interpass_invariants ();
2711 if (pass
->tv_id
!= TV_NONE
)
2712 timevar_pop (pass
->tv_id
);
2714 if (pass
->type
== IPA_PASS
2715 && ((ipa_opt_pass_d
*)pass
)->function_transform
)
2717 struct cgraph_node
*node
;
2718 FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node
)
2719 if (!node
->inlined_to
)
2720 node
->ipa_transforms_to_apply
.safe_push ((ipa_opt_pass_d
*)pass
);
2723 do_per_function (execute_function_dump
, pass
);
2725 if (!current_function_decl
)
2726 symtab
->process_new_functions ();
2728 pass_fini_dump_file (pass
);
2730 if (pass
->type
!= SIMPLE_IPA_PASS
&& pass
->type
!= IPA_PASS
)
2731 gcc_assert (!(cfun
->curr_properties
& PROP_gimple
)
2732 || pass
->type
!= RTL_PASS
);
2734 current_pass
= NULL
;
2735 redirect_edge_var_map_empty ();
2737 /* Signal this is a suitable GC collection point. */
2738 if (!((todo_after
| pass
->todo_flags_finish
) & TODO_do_not_ggc_collect
))
2741 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
2742 report_heap_memory_use ();
2747 execute_pass_list_1 (opt_pass
*pass
)
2751 gcc_assert (pass
->type
== GIMPLE_PASS
2752 || pass
->type
== RTL_PASS
);
2756 if (execute_one_pass (pass
) && pass
->sub
)
2757 execute_pass_list_1 (pass
->sub
);
2764 execute_pass_list (function
*fn
, opt_pass
*pass
)
2766 gcc_assert (fn
== cfun
);
2767 execute_pass_list_1 (pass
);
2768 if (cfun
&& fn
->cfg
)
2770 free_dominance_info (CDI_DOMINATORS
);
2771 free_dominance_info (CDI_POST_DOMINATORS
);
2775 /* Write out all LTO data. */
2779 timevar_push (TV_IPA_LTO_GIMPLE_OUT
);
2781 timevar_pop (TV_IPA_LTO_GIMPLE_OUT
);
2782 timevar_push (TV_IPA_LTO_DECL_OUT
);
2783 produce_asm_for_decls ();
2784 timevar_pop (TV_IPA_LTO_DECL_OUT
);
2787 /* Same as execute_pass_list but assume that subpasses of IPA passes
2788 are local passes. If SET is not NULL, write out summaries of only
2789 those node in SET. */
2792 ipa_write_summaries_2 (opt_pass
*pass
, struct lto_out_decl_state
*state
)
2796 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*)pass
;
2797 gcc_assert (!current_function_decl
);
2799 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2800 if (pass
->type
== IPA_PASS
2801 && ipa_pass
->write_summary
2802 && pass
->gate (cfun
))
2804 /* If a timevar is present, start it. */
2806 timevar_push (pass
->tv_id
);
2808 pass_init_dump_file (pass
);
2810 current_pass
= pass
;
2811 ipa_pass
->write_summary ();
2813 pass_fini_dump_file (pass
);
2815 /* If a timevar is present, start it. */
2817 timevar_pop (pass
->tv_id
);
2820 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2821 ipa_write_summaries_2 (pass
->sub
, state
);
2827 /* Helper function of ipa_write_summaries. Creates and destroys the
2828 decl state and calls ipa_write_summaries_2 for all passes that have
2829 summaries. SET is the set of nodes to be written. */
2832 ipa_write_summaries_1 (lto_symtab_encoder_t encoder
)
2834 pass_manager
*passes
= g
->get_passes ();
2835 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2836 state
->symtab_node_encoder
= encoder
;
2838 lto_output_init_mode_table ();
2839 lto_push_out_decl_state (state
);
2841 gcc_assert (!flag_wpa
);
2842 ipa_write_summaries_2 (passes
->all_regular_ipa_passes
, state
);
2846 gcc_assert (lto_get_out_decl_state () == state
);
2847 lto_pop_out_decl_state ();
2848 lto_delete_out_decl_state (state
);
2851 /* Write out summaries for all the nodes in the callgraph. */
2854 ipa_write_summaries (void)
2856 lto_symtab_encoder_t encoder
;
2858 varpool_node
*vnode
;
2859 struct cgraph_node
*node
;
2860 struct cgraph_node
**order
;
2862 if ((!flag_generate_lto
&& !flag_generate_offload
) || seen_error ())
2865 gcc_assert (!dump_file
);
2866 streamer_dump_file
= dump_begin (TDI_lto_stream_out
, NULL
);
2868 select_what_to_stream ();
2870 encoder
= lto_symtab_encoder_new (false);
2872 /* Create the callgraph set in the same order used in
2873 cgraph_expand_all_functions. This mostly facilitates debugging,
2874 since it causes the gimple file to be processed in the same order
2875 as the source code. */
2876 order
= XCNEWVEC (struct cgraph_node
*, symtab
->cgraph_count
);
2877 order_pos
= ipa_reverse_postorder (order
);
2878 gcc_assert (order_pos
== symtab
->cgraph_count
);
2880 for (i
= order_pos
- 1; i
>= 0; i
--)
2882 struct cgraph_node
*node
= order
[i
];
2884 if ((node
->definition
|| node
->declare_variant_alt
)
2885 && node
->need_lto_streaming
)
2887 if (gimple_has_body_p (node
->decl
))
2888 lto_prepare_function_for_streaming (node
);
2889 lto_set_symtab_encoder_in_partition (encoder
, node
);
2893 FOR_EACH_DEFINED_FUNCTION (node
)
2894 if (node
->alias
&& node
->need_lto_streaming
)
2895 lto_set_symtab_encoder_in_partition (encoder
, node
);
2896 FOR_EACH_DEFINED_VARIABLE (vnode
)
2897 if (vnode
->need_lto_streaming
)
2898 lto_set_symtab_encoder_in_partition (encoder
, vnode
);
2900 ipa_write_summaries_1 (compute_ltrans_boundary (encoder
));
2903 if (streamer_dump_file
)
2905 dump_end (TDI_lto_stream_out
, streamer_dump_file
);
2906 streamer_dump_file
= NULL
;
2910 /* Same as execute_pass_list but assume that subpasses of IPA passes
2911 are local passes. If SET is not NULL, write out optimization summaries of
2912 only those node in SET. */
2915 ipa_write_optimization_summaries_1 (opt_pass
*pass
,
2916 struct lto_out_decl_state
*state
)
2920 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*)pass
;
2921 gcc_assert (!current_function_decl
);
2923 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2924 if (pass
->type
== IPA_PASS
2925 && ipa_pass
->write_optimization_summary
2926 && pass
->gate (cfun
))
2928 /* If a timevar is present, start it. */
2930 timevar_push (pass
->tv_id
);
2932 pass_init_dump_file (pass
);
2934 current_pass
= pass
;
2935 ipa_pass
->write_optimization_summary ();
2937 pass_fini_dump_file (pass
);
2939 /* If a timevar is present, start it. */
2941 timevar_pop (pass
->tv_id
);
2944 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2945 ipa_write_optimization_summaries_1 (pass
->sub
, state
);
2951 /* Write all the optimization summaries for the cgraph nodes in SET. If SET is
2952 NULL, write out all summaries of all nodes. */
2955 ipa_write_optimization_summaries (lto_symtab_encoder_t encoder
)
2957 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2958 state
->symtab_node_encoder
= encoder
;
2960 lto_output_init_mode_table ();
2961 lto_push_out_decl_state (state
);
2963 /* Be sure that we did not forget to renumber stmt uids. */
2964 gcc_checking_assert (flag_wpa
);
2966 gcc_assert (flag_wpa
);
2967 pass_manager
*passes
= g
->get_passes ();
2968 ipa_write_optimization_summaries_1 (passes
->all_regular_ipa_passes
, state
);
2972 gcc_assert (lto_get_out_decl_state () == state
);
2973 lto_pop_out_decl_state ();
2974 lto_delete_out_decl_state (state
);
2977 /* Same as execute_pass_list but assume that subpasses of IPA passes
2978 are local passes. */
2981 ipa_read_summaries_1 (opt_pass
*pass
)
2985 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
2987 gcc_assert (!current_function_decl
);
2989 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2991 if (pass
->gate (cfun
))
2993 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_summary
)
2995 /* If a timevar is present, start it. */
2997 timevar_push (pass
->tv_id
);
2999 fprintf (stderr
, " <%s>", pass
->name
? pass
->name
: "");
3001 pass_init_dump_file (pass
);
3003 current_pass
= pass
;
3004 ipa_pass
->read_summary ();
3006 pass_fini_dump_file (pass
);
3010 timevar_pop (pass
->tv_id
);
3012 report_heap_memory_use ();
3015 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
3016 ipa_read_summaries_1 (pass
->sub
);
3023 /* Read all the summaries for all_regular_ipa_passes. */
3026 ipa_read_summaries (void)
3028 pass_manager
*passes
= g
->get_passes ();
3029 ipa_read_summaries_1 (passes
->all_regular_ipa_passes
);
3032 /* Same as execute_pass_list but assume that subpasses of IPA passes
3033 are local passes. */
3036 ipa_read_optimization_summaries_1 (opt_pass
*pass
)
3040 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
3042 gcc_assert (!current_function_decl
);
3044 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
3046 if (pass
->gate (cfun
))
3048 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_optimization_summary
)
3050 /* If a timevar is present, start it. */
3052 timevar_push (pass
->tv_id
);
3054 fprintf (stderr
, " <%s>", pass
->name
? pass
->name
: "");
3056 pass_init_dump_file (pass
);
3058 current_pass
= pass
;
3059 ipa_pass
->read_optimization_summary ();
3061 pass_fini_dump_file (pass
);
3065 timevar_pop (pass
->tv_id
);
3068 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
3069 ipa_read_optimization_summaries_1 (pass
->sub
);
3071 report_heap_memory_use ();
3077 /* Read all the summaries for all_regular_ipa_passes. */
3080 ipa_read_optimization_summaries (void)
3082 pass_manager
*passes
= g
->get_passes ();
3083 ipa_read_optimization_summaries_1 (passes
->all_regular_ipa_passes
);
3086 /* Same as execute_pass_list but assume that subpasses of IPA passes
3087 are local passes. */
3089 execute_ipa_pass_list (opt_pass
*pass
)
3093 gcc_assert (!current_function_decl
);
3095 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
3096 if (execute_one_pass (pass
) && pass
->sub
)
3098 if (pass
->sub
->type
== GIMPLE_PASS
)
3100 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_START
, NULL
);
3101 do_per_function_toporder ((void (*)(function
*, void *))
3104 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_END
, NULL
);
3106 else if (pass
->sub
->type
== SIMPLE_IPA_PASS
3107 || pass
->sub
->type
== IPA_PASS
)
3108 execute_ipa_pass_list (pass
->sub
);
3112 gcc_assert (!current_function_decl
);
3113 symtab
->process_new_functions ();
3119 /* Execute stmt fixup hooks of all passes in PASS for NODE and STMTS. */
3122 execute_ipa_stmt_fixups (opt_pass
*pass
,
3123 struct cgraph_node
*node
, gimple
**stmts
)
3127 /* Execute all of the IPA_PASSes in the list. */
3128 if (pass
->type
== IPA_PASS
3129 && pass
->gate (cfun
))
3131 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
3133 if (ipa_pass
->stmt_fixup
)
3135 pass_init_dump_file (pass
);
3136 /* If a timevar is present, start it. */
3138 timevar_push (pass
->tv_id
);
3140 current_pass
= pass
;
3141 ipa_pass
->stmt_fixup (node
, stmts
);
3145 timevar_pop (pass
->tv_id
);
3146 pass_fini_dump_file (pass
);
3149 execute_ipa_stmt_fixups (pass
->sub
, node
, stmts
);
3155 /* Execute stmt fixup hooks of all IPA passes for NODE and STMTS. */
3158 execute_all_ipa_stmt_fixups (struct cgraph_node
*node
, gimple
**stmts
)
3160 pass_manager
*passes
= g
->get_passes ();
3161 execute_ipa_stmt_fixups (passes
->all_regular_ipa_passes
, node
, stmts
);
3165 extern void debug_properties (unsigned int);
3166 extern void dump_properties (FILE *, unsigned int);
3169 dump_properties (FILE *dump
, unsigned int props
)
3171 fprintf (dump
, "Properties:\n");
3172 if (props
& PROP_gimple_any
)
3173 fprintf (dump
, "PROP_gimple_any\n");
3174 if (props
& PROP_gimple_lcf
)
3175 fprintf (dump
, "PROP_gimple_lcf\n");
3176 if (props
& PROP_gimple_leh
)
3177 fprintf (dump
, "PROP_gimple_leh\n");
3178 if (props
& PROP_cfg
)
3179 fprintf (dump
, "PROP_cfg\n");
3180 if (props
& PROP_ssa
)
3181 fprintf (dump
, "PROP_ssa\n");
3182 if (props
& PROP_no_crit_edges
)
3183 fprintf (dump
, "PROP_no_crit_edges\n");
3184 if (props
& PROP_rtl
)
3185 fprintf (dump
, "PROP_rtl\n");
3186 if (props
& PROP_gimple_lomp
)
3187 fprintf (dump
, "PROP_gimple_lomp\n");
3188 if (props
& PROP_gimple_lomp_dev
)
3189 fprintf (dump
, "PROP_gimple_lomp_dev\n");
3190 if (props
& PROP_gimple_lcx
)
3191 fprintf (dump
, "PROP_gimple_lcx\n");
3192 if (props
& PROP_gimple_lvec
)
3193 fprintf (dump
, "PROP_gimple_lvec\n");
3194 if (props
& PROP_cfglayout
)
3195 fprintf (dump
, "PROP_cfglayout\n");
3199 debug_properties (unsigned int props
)
3201 dump_properties (stderr
, props
);
3204 /* Called by local passes to see if function is called by already processed nodes.
3205 Because we process nodes in topological order, this means that function is
3206 in recursive cycle or we introduced new direct calls. */
3208 function_called_by_processed_nodes_p (void)
3210 struct cgraph_edge
*e
;
3211 for (e
= cgraph_node::get (current_function_decl
)->callers
;
3215 if (e
->caller
->decl
== current_function_decl
)
3217 if (!e
->caller
->has_gimple_body_p ())
3219 if (TREE_ASM_WRITTEN (e
->caller
->decl
))
3221 if (!e
->caller
->process
&& !e
->caller
->inlined_to
)
3226 fprintf (dump_file
, "Already processed call to:\n");
3227 e
->caller
->dump (dump_file
);