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
|| 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
);
362 /* Do whatever is necessary to finish printing the graphs. */
363 for (i
= TDI_end
; (dfi
= dumps
->get_dump_file_info (i
)) != NULL
; ++i
)
364 if (dfi
->graph_dump_initialized
)
366 name
= dumps
->get_dump_file_name (dfi
);
367 finish_graph_dump_file (name
);
371 timevar_pop (TV_DUMP
);
375 execute_build_ssa_passes (void)
377 /* Once this pass (and its sub-passes) are complete, all functions
378 will be in SSA form. Technically this state change is happening
379 a tad early, since the sub-passes have not yet run, but since
380 none of the sub-passes are IPA passes and do not create new
381 functions, this is ok. We're setting this value for the benefit
382 of IPA passes that follow. */
383 if (symtab
->state
< IPA_SSA
)
384 symtab
->state
= IPA_SSA
;
390 const pass_data pass_data_build_ssa_passes
=
392 SIMPLE_IPA_PASS
, /* type */
393 "build_ssa_passes", /* name */
394 OPTGROUP_NONE
, /* optinfo_flags */
395 TV_EARLY_LOCAL
, /* tv_id */
396 0, /* properties_required */
397 0, /* properties_provided */
398 0, /* properties_destroyed */
399 0, /* todo_flags_start */
400 /* todo_flags_finish is executed before subpases. For this reason
401 it makes no sense to remove unreachable functions here. */
402 0, /* todo_flags_finish */
405 class pass_build_ssa_passes
: public simple_ipa_opt_pass
408 pass_build_ssa_passes (gcc::context
*ctxt
)
409 : simple_ipa_opt_pass (pass_data_build_ssa_passes
, ctxt
)
412 /* opt_pass methods: */
413 bool gate (function
*) final override
415 /* Don't bother doing anything if the program has errors. */
416 return (!seen_error () && !in_lto_p
);
419 unsigned int execute (function
*) final override
421 return execute_build_ssa_passes ();
424 }; // class pass_build_ssa_passes
426 const pass_data pass_data_local_optimization_passes
=
428 SIMPLE_IPA_PASS
, /* type */
429 "opt_local_passes", /* name */
430 OPTGROUP_NONE
, /* optinfo_flags */
432 0, /* properties_required */
433 0, /* properties_provided */
434 0, /* properties_destroyed */
435 0, /* todo_flags_start */
436 0, /* todo_flags_finish */
439 class pass_local_optimization_passes
: public simple_ipa_opt_pass
442 pass_local_optimization_passes (gcc::context
*ctxt
)
443 : simple_ipa_opt_pass (pass_data_local_optimization_passes
, ctxt
)
446 /* opt_pass methods: */
447 bool gate (function
*) final override
449 /* Don't bother doing anything if the program has errors. */
450 return (!seen_error () && !in_lto_p
);
453 }; // class pass_local_optimization_passes
455 const pass_data pass_data_ipa_remove_symbols
=
457 SIMPLE_IPA_PASS
, /* type */
458 "remove_symbols", /* name */
459 OPTGROUP_NONE
, /* optinfo_flags */
461 0, /* properties_required */
462 0, /* properties_provided */
463 0, /* properties_destroyed */
464 0, /* todo_flags_start */
465 TODO_remove_functions
| TODO_dump_symtab
, /* todo_flags_finish */
468 class pass_ipa_remove_symbols
: public simple_ipa_opt_pass
471 pass_ipa_remove_symbols (gcc::context
*ctxt
)
472 : simple_ipa_opt_pass (pass_data_ipa_remove_symbols
, ctxt
)
475 /* opt_pass methods: */
476 bool gate (function
*) final override
478 /* Don't bother doing anything if the program has errors. */
479 return (!seen_error () && !in_lto_p
);
482 }; // class pass_local_optimization_passes
486 simple_ipa_opt_pass
*
487 make_pass_build_ssa_passes (gcc::context
*ctxt
)
489 return new pass_build_ssa_passes (ctxt
);
492 simple_ipa_opt_pass
*
493 make_pass_local_optimization_passes (gcc::context
*ctxt
)
495 return new pass_local_optimization_passes (ctxt
);
498 simple_ipa_opt_pass
*
499 make_pass_ipa_remove_symbols (gcc::context
*ctxt
)
501 return new pass_ipa_remove_symbols (ctxt
);
506 const pass_data pass_data_all_early_optimizations
=
508 GIMPLE_PASS
, /* type */
509 "early_optimizations", /* name */
510 OPTGROUP_NONE
, /* optinfo_flags */
512 0, /* properties_required */
513 0, /* properties_provided */
514 0, /* properties_destroyed */
515 0, /* todo_flags_start */
516 0, /* todo_flags_finish */
519 class pass_all_early_optimizations
: public gimple_opt_pass
522 pass_all_early_optimizations (gcc::context
*ctxt
)
523 : gimple_opt_pass (pass_data_all_early_optimizations
, ctxt
)
526 /* opt_pass methods: */
527 bool gate (function
*) final override
529 return (optimize
>= 1
530 /* Don't bother doing anything if the program has errors. */
534 }; // class pass_all_early_optimizations
538 static gimple_opt_pass
*
539 make_pass_all_early_optimizations (gcc::context
*ctxt
)
541 return new pass_all_early_optimizations (ctxt
);
546 const pass_data pass_data_all_optimizations
=
548 GIMPLE_PASS
, /* type */
549 "*all_optimizations", /* name */
550 OPTGROUP_NONE
, /* optinfo_flags */
551 TV_OPTIMIZE
, /* tv_id */
552 0, /* properties_required */
553 0, /* properties_provided */
554 0, /* properties_destroyed */
555 0, /* todo_flags_start */
556 0, /* todo_flags_finish */
559 class pass_all_optimizations
: public gimple_opt_pass
562 pass_all_optimizations (gcc::context
*ctxt
)
563 : gimple_opt_pass (pass_data_all_optimizations
, ctxt
)
566 /* opt_pass methods: */
567 bool gate (function
*) final override
569 return optimize
>= 1 && !optimize_debug
;
572 }; // class pass_all_optimizations
576 static gimple_opt_pass
*
577 make_pass_all_optimizations (gcc::context
*ctxt
)
579 return new pass_all_optimizations (ctxt
);
584 const pass_data pass_data_all_optimizations_g
=
586 GIMPLE_PASS
, /* type */
587 "*all_optimizations_g", /* name */
588 OPTGROUP_NONE
, /* optinfo_flags */
589 TV_OPTIMIZE
, /* tv_id */
590 0, /* properties_required */
591 0, /* properties_provided */
592 0, /* properties_destroyed */
593 0, /* todo_flags_start */
594 0, /* todo_flags_finish */
597 class pass_all_optimizations_g
: public gimple_opt_pass
600 pass_all_optimizations_g (gcc::context
*ctxt
)
601 : gimple_opt_pass (pass_data_all_optimizations_g
, ctxt
)
604 /* opt_pass methods: */
605 bool gate (function
*) final override
607 return optimize
>= 1 && optimize_debug
;
610 }; // class pass_all_optimizations_g
614 static gimple_opt_pass
*
615 make_pass_all_optimizations_g (gcc::context
*ctxt
)
617 return new pass_all_optimizations_g (ctxt
);
622 const pass_data pass_data_rest_of_compilation
=
625 "*rest_of_compilation", /* name */
626 OPTGROUP_NONE
, /* optinfo_flags */
627 TV_REST_OF_COMPILATION
, /* tv_id */
628 PROP_rtl
, /* properties_required */
629 0, /* properties_provided */
630 0, /* properties_destroyed */
631 0, /* todo_flags_start */
632 0, /* todo_flags_finish */
635 class pass_rest_of_compilation
: public rtl_opt_pass
638 pass_rest_of_compilation (gcc::context
*ctxt
)
639 : rtl_opt_pass (pass_data_rest_of_compilation
, ctxt
)
642 /* opt_pass methods: */
643 bool gate (function
*) final override
645 /* Early return if there were errors. We can run afoul of our
646 consistency checks, and there's not really much point in fixing them. */
647 return !(rtl_dump_and_exit
|| flag_syntax_only
|| seen_error ());
650 }; // class pass_rest_of_compilation
654 static rtl_opt_pass
*
655 make_pass_rest_of_compilation (gcc::context
*ctxt
)
657 return new pass_rest_of_compilation (ctxt
);
662 const pass_data pass_data_postreload
=
665 "*all-postreload", /* name */
666 OPTGROUP_NONE
, /* optinfo_flags */
667 TV_POSTRELOAD
, /* tv_id */
668 PROP_rtl
, /* properties_required */
669 0, /* properties_provided */
670 0, /* properties_destroyed */
671 0, /* todo_flags_start */
672 0, /* todo_flags_finish */
675 class pass_postreload
: public rtl_opt_pass
678 pass_postreload (gcc::context
*ctxt
)
679 : rtl_opt_pass (pass_data_postreload
, ctxt
)
682 /* opt_pass methods: */
683 bool gate (function
*) final override
{ return reload_completed
; }
685 }; // class pass_postreload
689 static rtl_opt_pass
*
690 make_pass_postreload (gcc::context
*ctxt
)
692 return new pass_postreload (ctxt
);
697 const pass_data pass_data_late_compilation
=
700 "*all-late_compilation", /* name */
701 OPTGROUP_NONE
, /* optinfo_flags */
702 TV_LATE_COMPILATION
, /* tv_id */
703 PROP_rtl
, /* properties_required */
704 0, /* properties_provided */
705 0, /* properties_destroyed */
706 0, /* todo_flags_start */
707 0, /* todo_flags_finish */
710 class pass_late_compilation
: public rtl_opt_pass
713 pass_late_compilation (gcc::context
*ctxt
)
714 : rtl_opt_pass (pass_data_late_compilation
, ctxt
)
717 /* opt_pass methods: */
718 bool gate (function
*) final override
720 return reload_completed
|| targetm
.no_register_allocation
;
723 }; // class pass_late_compilation
727 static rtl_opt_pass
*
728 make_pass_late_compilation (gcc::context
*ctxt
)
730 return new pass_late_compilation (ctxt
);
733 /* Pre-SLP scalar cleanup, it has several cleanup passes like FRE, DSE. */
737 const pass_data pass_data_pre_slp_scalar_cleanup
=
739 GIMPLE_PASS
, /* type */
740 "*pre_slp_scalar_cleanup", /* name */
741 OPTGROUP_LOOP
, /* optinfo_flags */
742 TV_SCALAR_CLEANUP
, /* tv_id */
743 ( PROP_cfg
| PROP_ssa
), /* properties_required */
744 0, /* properties_provided */
745 0, /* properties_destroyed */
746 0, /* todo_flags_start */
747 0, /* todo_flags_finish */
750 class pass_pre_slp_scalar_cleanup
: public gimple_opt_pass
753 pass_pre_slp_scalar_cleanup (gcc::context
*ctxt
)
754 : gimple_opt_pass (pass_data_pre_slp_scalar_cleanup
, ctxt
)
759 gate (function
*fun
) final override
761 return flag_tree_slp_vectorize
762 && (fun
->pending_TODOs
& PENDING_TODO_force_next_scalar_cleanup
);
766 execute (function
*fun
) final override
768 fun
->pending_TODOs
&= ~PENDING_TODO_force_next_scalar_cleanup
;
772 }; // class pass_pre_slp_scalar_cleanup
777 make_pass_pre_slp_scalar_cleanup (gcc::context
*ctxt
)
779 return new pass_pre_slp_scalar_cleanup (ctxt
);
782 /* Set the static pass number of pass PASS to ID and record that
783 in the mapping from static pass number to pass. */
787 set_pass_for_id (int id
, opt_pass
*pass
)
789 pass
->static_pass_number
= id
;
790 if (passes_by_id_size
<= id
)
792 passes_by_id
= XRESIZEVEC (opt_pass
*, passes_by_id
, id
+ 1);
793 memset (passes_by_id
+ passes_by_id_size
, 0,
794 (id
+ 1 - passes_by_id_size
) * sizeof (void *));
795 passes_by_id_size
= id
+ 1;
797 passes_by_id
[id
] = pass
;
800 /* Return the pass with the static pass number ID. */
803 pass_manager::get_pass_for_id (int id
) const
805 if (id
>= passes_by_id_size
)
807 return passes_by_id
[id
];
810 /* Iterate over the pass tree allocating dump file numbers. We want
811 to do this depth first, and independent of whether the pass is
815 register_one_dump_file (opt_pass
*pass
)
817 g
->get_passes ()->register_one_dump_file (pass
);
821 pass_manager::register_one_dump_file (opt_pass
*pass
)
823 char *dot_name
, *flag_name
, *glob_name
;
824 const char *name
, *full_name
, *prefix
;
826 /* Buffer big enough to format a 32-bit UINT_MAX into. */
830 optgroup_flags_t optgroup_flags
= OPTGROUP_NONE
;
831 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
833 /* See below in next_pass_1. */
835 if (pass
->static_pass_number
!= -1)
836 sprintf (num
, "%u", ((int) pass
->static_pass_number
< 0
837 ? 1 : pass
->static_pass_number
));
839 /* The name is both used to identify the pass for the purposes of plugins,
840 and to specify dump file name and option.
841 The latter two might want something short which is not quite unique; for
842 that reason, we may have a disambiguating prefix, followed by a space
843 to mark the start of the following dump file name / option string. */
844 name
= strchr (pass
->name
, ' ');
845 name
= name
? name
+ 1 : pass
->name
;
846 dot_name
= concat (".", name
, num
, NULL
);
847 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
851 optgroup_flags
|= OPTGROUP_IPA
;
853 else if (pass
->type
== GIMPLE_PASS
)
864 flag_name
= concat (prefix
, name
, num
, NULL
);
865 glob_name
= concat (prefix
, name
, NULL
);
866 optgroup_flags
|= pass
->optinfo_flags
;
867 /* For any passes that do not have an optgroup set, and which are not
868 IPA passes setup above, set the optgroup to OPTGROUP_OTHER so that
869 any dump messages are emitted properly under -fopt-info(-optall). */
870 if (optgroup_flags
== OPTGROUP_NONE
)
871 optgroup_flags
= OPTGROUP_OTHER
;
872 id
= dumps
->dump_register (dot_name
, flag_name
, glob_name
, dkind
,
875 set_pass_for_id (id
, pass
);
876 full_name
= concat (prefix
, pass
->name
, num
, NULL
);
877 register_pass_name (pass
, full_name
);
878 free (CONST_CAST (char *, full_name
));
881 /* Register the dump files for the pass_manager starting at PASS. */
884 pass_manager::register_dump_files (opt_pass
*pass
)
888 if (pass
->name
&& pass
->name
[0] != '*')
889 register_one_dump_file (pass
);
892 register_dump_files (pass
->sub
);
899 /* Register PASS with NAME. */
902 pass_manager::register_pass_name (opt_pass
*pass
, const char *name
)
904 if (!m_name_to_pass_map
)
905 m_name_to_pass_map
= new hash_map
<free_string_hash
, opt_pass
*> (256);
907 if (m_name_to_pass_map
->get (name
))
908 return; /* Ignore plugin passes. */
910 const char *unique_name
= xstrdup (name
);
911 m_name_to_pass_map
->put (unique_name
, pass
);
914 /* Map from pass id to canonicalized pass name. */
916 typedef const char *char_ptr
;
917 static vec
<char_ptr
> pass_tab
;
919 /* Callback function for traversing NAME_TO_PASS_MAP. */
922 passes_pass_traverse (const char *const &name
, opt_pass
*const &pass
, void *)
924 gcc_assert (pass
->static_pass_number
> 0);
925 gcc_assert (pass_tab
.exists ());
927 pass_tab
[pass
->static_pass_number
] = name
;
932 /* The function traverses NAME_TO_PASS_MAP and creates a pass info
933 table for dumping purpose. */
936 pass_manager::create_pass_tab (void) const
938 if (!flag_dump_passes
)
941 pass_tab
.safe_grow_cleared (passes_by_id_size
+ 1, true);
942 m_name_to_pass_map
->traverse
<void *, passes_pass_traverse
> (NULL
);
945 static bool override_gate_status (opt_pass
*, tree
, bool);
947 /* Dump the instantiated name for PASS. IS_ON indicates if PASS
948 is turned on or not. */
951 dump_one_pass (opt_pass
*pass
, int pass_indent
)
953 int indent
= 3 * pass_indent
;
955 bool is_on
, is_really_on
;
957 is_on
= pass
->gate (cfun
);
958 is_really_on
= override_gate_status (pass
, current_function_decl
, is_on
);
960 if (pass
->static_pass_number
<= 0)
963 pn
= pass_tab
[pass
->static_pass_number
];
965 fprintf (stderr
, "%*s%-40s%*s:%s%s\n", indent
, " ", pn
,
966 (15 - indent
< 0 ? 0 : 15 - indent
), " ",
967 is_on
? " ON" : " OFF",
968 ((!is_on
) == (!is_really_on
) ? ""
969 : (is_really_on
? " (FORCED_ON)" : " (FORCED_OFF)")));
972 /* Dump pass list PASS with indentation INDENT. */
975 dump_pass_list (opt_pass
*pass
, int indent
)
979 dump_one_pass (pass
, indent
);
981 dump_pass_list (pass
->sub
, indent
+ 1);
987 /* Dump all optimization passes. */
992 g
->get_passes ()->dump_passes ();
996 pass_manager::dump_passes () const
998 push_dummy_function (true);
999 cgraph_node
*node
= cgraph_node::get_create (current_function_decl
);
1003 dump_pass_list (all_lowering_passes
, 1);
1004 dump_pass_list (all_small_ipa_passes
, 1);
1005 dump_pass_list (all_regular_ipa_passes
, 1);
1006 dump_pass_list (all_late_ipa_passes
, 1);
1007 dump_pass_list (all_passes
, 1);
1010 pop_dummy_function ();
1013 /* Returns the pass with NAME. */
1016 pass_manager::get_pass_by_name (const char *name
)
1018 opt_pass
**p
= m_name_to_pass_map
->get (name
);
1026 /* Range [start, last]. */
1032 const char *assem_name
;
1033 struct uid_range
*next
;
1036 typedef struct uid_range
*uid_range_p
;
1039 static vec
<uid_range_p
> enabled_pass_uid_range_tab
;
1040 static vec
<uid_range_p
> disabled_pass_uid_range_tab
;
1043 /* Parse option string for -fdisable- and -fenable-
1044 The syntax of the options:
1046 -fenable-<pass_name>
1047 -fdisable-<pass_name>
1049 -fenable-<pass_name>=s1:e1,s2:e2,...
1050 -fdisable-<pass_name>=s1:e1,s2:e2,...
1054 enable_disable_pass (const char *arg
, bool is_enable
)
1057 char *range_str
, *phase_name
;
1058 char *argstr
= xstrdup (arg
);
1059 vec
<uid_range_p
> *tab
= 0;
1061 range_str
= strchr (argstr
,'=');
1068 phase_name
= argstr
;
1072 error ("unrecognized option %<-fenable%>");
1074 error ("unrecognized option %<-fdisable%>");
1078 pass
= g
->get_passes ()->get_pass_by_name (phase_name
);
1079 if (!pass
|| pass
->static_pass_number
== -1)
1082 error ("unknown pass %s specified in %<-fenable%>", phase_name
);
1084 error ("unknown pass %s specified in %<-fdisable%>", phase_name
);
1090 tab
= &enabled_pass_uid_range_tab
;
1092 tab
= &disabled_pass_uid_range_tab
;
1094 if ((unsigned) pass
->static_pass_number
>= tab
->length ())
1095 tab
->safe_grow_cleared (pass
->static_pass_number
+ 1, true);
1100 uid_range_p new_range
= XCNEW (struct uid_range
);
1102 new_range
->start
= 0;
1103 new_range
->last
= (unsigned)-1;
1105 slot
= (*tab
)[pass
->static_pass_number
];
1106 new_range
->next
= slot
;
1107 (*tab
)[pass
->static_pass_number
] = new_range
;
1109 inform (UNKNOWN_LOCATION
, "enable pass %s for functions in the range "
1110 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
1112 inform (UNKNOWN_LOCATION
, "disable pass %s for functions in the range "
1113 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
1117 char *next_range
= NULL
;
1118 char *one_range
= range_str
;
1119 char *end_val
= NULL
;
1124 uid_range_p new_range
;
1125 char *invalid
= NULL
;
1127 char *func_name
= NULL
;
1129 next_range
= strchr (one_range
, ',');
1136 end_val
= strchr (one_range
, ':');
1142 start
= strtol (one_range
, &invalid
, 10);
1143 if (*invalid
|| start
< 0)
1145 if (end_val
|| (one_range
[0] >= '0'
1146 && one_range
[0] <= '9'))
1148 error ("Invalid range %s in option %s",
1150 is_enable
? "-fenable" : "-fdisable");
1154 func_name
= one_range
;
1158 new_range
= XCNEW (struct uid_range
);
1161 new_range
->start
= (unsigned) start
;
1162 new_range
->last
= (unsigned) start
;
1166 new_range
->start
= (unsigned) -1;
1167 new_range
->last
= (unsigned) -1;
1168 new_range
->assem_name
= xstrdup (func_name
);
1173 long last
= strtol (end_val
, &invalid
, 10);
1174 if (*invalid
|| last
< start
)
1176 error ("Invalid range %s in option %s",
1178 is_enable
? "-fenable" : "-fdisable");
1182 new_range
= XCNEW (struct uid_range
);
1183 new_range
->start
= (unsigned) start
;
1184 new_range
->last
= (unsigned) last
;
1187 slot
= (*tab
)[pass
->static_pass_number
];
1188 new_range
->next
= slot
;
1189 (*tab
)[pass
->static_pass_number
] = new_range
;
1192 if (new_range
->assem_name
)
1193 inform (UNKNOWN_LOCATION
,
1194 "enable pass %s for function %s",
1195 phase_name
, new_range
->assem_name
);
1197 inform (UNKNOWN_LOCATION
,
1198 "enable pass %s for functions in the range of [%u, %u]",
1199 phase_name
, new_range
->start
, new_range
->last
);
1203 if (new_range
->assem_name
)
1204 inform (UNKNOWN_LOCATION
,
1205 "disable pass %s for function %s",
1206 phase_name
, new_range
->assem_name
);
1208 inform (UNKNOWN_LOCATION
,
1209 "disable pass %s for functions in the range of [%u, %u]",
1210 phase_name
, new_range
->start
, new_range
->last
);
1213 one_range
= next_range
;
1214 } while (next_range
);
1220 /* Enable pass specified by ARG. */
1223 enable_pass (const char *arg
)
1225 enable_disable_pass (arg
, true);
1228 /* Disable pass specified by ARG. */
1231 disable_pass (const char *arg
)
1233 enable_disable_pass (arg
, false);
1236 /* Returns true if PASS is explicitly enabled/disabled for FUNC. */
1239 is_pass_explicitly_enabled_or_disabled (opt_pass
*pass
,
1241 vec
<uid_range_p
> tab
)
1243 uid_range_p slot
, range
;
1245 const char *aname
= NULL
;
1248 || (unsigned) pass
->static_pass_number
>= tab
.length ()
1249 || pass
->static_pass_number
== -1)
1252 slot
= tab
[pass
->static_pass_number
];
1256 cgraph_uid
= func
? cgraph_node::get (func
)->get_uid () : 0;
1257 if (func
&& DECL_ASSEMBLER_NAME_SET_P (func
))
1258 aname
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func
));
1263 if ((unsigned) cgraph_uid
>= range
->start
1264 && (unsigned) cgraph_uid
<= range
->last
)
1266 if (range
->assem_name
&& aname
1267 && !strcmp (range
->assem_name
, aname
))
1269 range
= range
->next
;
1276 /* Update static_pass_number for passes (and the flag
1277 TODO_mark_first_instance).
1279 Passes are constructed with static_pass_number preinitialized to 0
1281 This field is used in two different ways: initially as instance numbers
1282 of their kind, and then as ids within the entire pass manager.
1284 Within pass_manager::pass_manager:
1286 * In add_pass_instance(), as called by next_pass_1 in
1287 NEXT_PASS in init_optimization_passes
1289 * When the initial instance of a pass within a pass manager is seen,
1290 it is flagged, and its static_pass_number is set to -1
1292 * On subsequent times that it is seen, the static pass number
1293 is decremented each time, so that if there are e.g. 4 dups,
1294 they have static_pass_number -4, 2, 3, 4 respectively (note
1295 how the initial one is negative and gives the count); these
1296 can be thought of as instance numbers of the specific pass
1298 * Within the register_dump_files () traversal, set_pass_for_id()
1299 is called on each pass, using these instance numbers to create
1300 dumpfile switches, and then overwriting them with a pass id,
1301 which are global to the whole pass manager (based on
1302 (TDI_end + current value of extra_dump_files_in_use) ) */
1305 add_pass_instance (opt_pass
*new_pass
, bool track_duplicates
,
1306 opt_pass
*initial_pass
)
1308 /* Are we dealing with the first pass of its kind, or a clone? */
1309 if (new_pass
!= initial_pass
)
1311 /* We're dealing with a clone. */
1312 new_pass
->todo_flags_start
&= ~TODO_mark_first_instance
;
1314 /* Indicate to register_dump_files that this pass has duplicates,
1315 and so it should rename the dump file. The first instance will
1316 be -1, and be number of duplicates = -static_pass_number - 1.
1317 Subsequent instances will be > 0 and just the duplicate number. */
1318 if ((new_pass
->name
&& new_pass
->name
[0] != '*') || track_duplicates
)
1320 initial_pass
->static_pass_number
-= 1;
1321 new_pass
->static_pass_number
= -initial_pass
->static_pass_number
;
1326 /* We're dealing with the first pass of its kind. */
1327 new_pass
->todo_flags_start
|= TODO_mark_first_instance
;
1328 new_pass
->static_pass_number
= -1;
1330 invoke_plugin_callbacks (PLUGIN_NEW_PASS
, new_pass
);
1334 /* Add a pass to the pass list. Duplicate the pass if it's already
1338 next_pass_1 (opt_pass
**list
, opt_pass
*pass
, opt_pass
*initial_pass
)
1340 /* Every pass should have a name so that plugins can refer to them. */
1341 gcc_assert (pass
->name
!= NULL
);
1343 add_pass_instance (pass
, false, initial_pass
);
1346 return &(*list
)->next
;
1349 /* List node for an inserted pass instance. We need to keep track of all
1350 the newly-added pass instances (with 'added_pass_nodes' defined below)
1351 so that we can register their dump files after pass-positioning is finished.
1352 Registering dumping files needs to be post-processed or the
1353 static_pass_number of the opt_pass object would be modified and mess up
1354 the dump file names of future pass instances to be added. */
1356 struct pass_list_node
1359 struct pass_list_node
*next
;
1362 static struct pass_list_node
*added_pass_nodes
= NULL
;
1363 static struct pass_list_node
*prev_added_pass_node
;
1365 /* Insert the pass at the proper position. Return true if the pass
1366 is successfully added.
1368 NEW_PASS_INFO - new pass to be inserted
1369 PASS_LIST - root of the pass list to insert the new pass to */
1372 position_pass (struct register_pass_info
*new_pass_info
, opt_pass
**pass_list
)
1374 opt_pass
*pass
= *pass_list
, *prev_pass
= NULL
;
1375 bool success
= false;
1377 for ( ; pass
; prev_pass
= pass
, pass
= pass
->next
)
1379 /* Check if the current pass is of the same type as the new pass and
1380 matches the name and the instance number of the reference pass. */
1381 if (pass
->type
== new_pass_info
->pass
->type
1383 && !strcmp (pass
->name
, new_pass_info
->reference_pass_name
)
1384 && ((new_pass_info
->ref_pass_instance_number
== 0)
1385 || (new_pass_info
->ref_pass_instance_number
==
1386 pass
->static_pass_number
)
1387 || (new_pass_info
->ref_pass_instance_number
== 1
1388 && pass
->todo_flags_start
& TODO_mark_first_instance
)))
1391 struct pass_list_node
*new_pass_node
;
1393 if (new_pass_info
->ref_pass_instance_number
== 0)
1395 new_pass
= new_pass_info
->pass
->clone ();
1396 add_pass_instance (new_pass
, true, new_pass_info
->pass
);
1400 new_pass
= new_pass_info
->pass
;
1401 add_pass_instance (new_pass
, true, new_pass
);
1404 /* Insert the new pass instance based on the positioning op. */
1405 switch (new_pass_info
->pos_op
)
1407 case PASS_POS_INSERT_AFTER
:
1408 new_pass
->next
= pass
->next
;
1409 pass
->next
= new_pass
;
1411 /* Skip newly inserted pass to avoid repeated
1412 insertions in the case where the new pass and the
1413 existing one have the same name. */
1416 case PASS_POS_INSERT_BEFORE
:
1417 new_pass
->next
= pass
;
1419 prev_pass
->next
= new_pass
;
1421 *pass_list
= new_pass
;
1423 case PASS_POS_REPLACE
:
1424 new_pass
->next
= pass
->next
;
1426 prev_pass
->next
= new_pass
;
1428 *pass_list
= new_pass
;
1429 new_pass
->sub
= pass
->sub
;
1430 new_pass
->tv_id
= pass
->tv_id
;
1434 error ("invalid pass positioning operation");
1438 /* Save the newly added pass (instance) in the added_pass_nodes
1439 list so that we can register its dump file later. Note that
1440 we cannot register the dump file now because doing so will modify
1441 the static_pass_number of the opt_pass object and therefore
1442 mess up the dump file name of future instances. */
1443 new_pass_node
= XCNEW (struct pass_list_node
);
1444 new_pass_node
->pass
= new_pass
;
1445 if (!added_pass_nodes
)
1446 added_pass_nodes
= new_pass_node
;
1448 prev_added_pass_node
->next
= new_pass_node
;
1449 prev_added_pass_node
= new_pass_node
;
1454 if (pass
->sub
&& position_pass (new_pass_info
, &pass
->sub
))
1461 /* Hooks a new pass into the pass lists.
1463 PASS_INFO - pass information that specifies the opt_pass object,
1464 reference pass, instance number, and how to position
1468 register_pass (struct register_pass_info
*pass_info
)
1470 g
->get_passes ()->register_pass (pass_info
);
1474 register_pass (opt_pass
* pass
, pass_positioning_ops pos
,
1475 const char* ref_pass_name
, int ref_pass_inst_number
)
1477 register_pass_info i
;
1479 i
.reference_pass_name
= ref_pass_name
;
1480 i
.ref_pass_instance_number
= ref_pass_inst_number
;
1483 g
->get_passes ()->register_pass (&i
);
1487 pass_manager::register_pass (struct register_pass_info
*pass_info
)
1489 bool all_instances
, success
;
1491 /* The checks below could fail in buggy plugins. Existing GCC
1492 passes should never fail these checks, so we mention plugin in
1494 if (!pass_info
->pass
)
1495 fatal_error (input_location
, "plugin cannot register a missing pass");
1497 if (!pass_info
->pass
->name
)
1498 fatal_error (input_location
, "plugin cannot register an unnamed pass");
1500 if (!pass_info
->reference_pass_name
)
1503 "plugin cannot register pass %qs without reference pass name",
1504 pass_info
->pass
->name
);
1506 /* Try to insert the new pass to the pass lists. We need to check
1507 all five lists as the reference pass could be in one (or all) of
1509 all_instances
= pass_info
->ref_pass_instance_number
== 0;
1510 success
= position_pass (pass_info
, &all_lowering_passes
);
1511 if (!success
|| all_instances
)
1512 success
|= position_pass (pass_info
, &all_small_ipa_passes
);
1513 if (!success
|| all_instances
)
1514 success
|= position_pass (pass_info
, &all_regular_ipa_passes
);
1515 if (!success
|| all_instances
)
1516 success
|= position_pass (pass_info
, &all_late_ipa_passes
);
1517 if (!success
|| all_instances
)
1518 success
|= position_pass (pass_info
, &all_passes
);
1522 "pass %qs not found but is referenced by new pass %qs",
1523 pass_info
->reference_pass_name
, pass_info
->pass
->name
);
1525 /* OK, we have successfully inserted the new pass. We need to register
1526 the dump files for the newly added pass and its duplicates (if any).
1527 While doing so, we also delete the pass_list_node
1528 objects created during pass positioning. */
1529 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
1530 while (added_pass_nodes
)
1532 struct pass_list_node
*next_node
= added_pass_nodes
->next
;
1534 /* Handle -fdump-* and -fopt-info. */
1535 dumps
->register_pass (added_pass_nodes
->pass
);
1537 XDELETE (added_pass_nodes
);
1538 added_pass_nodes
= next_node
;
1542 /* Construct the pass tree. The sequencing of passes is driven by
1543 the cgraph routines:
1545 finalize_compilation_unit ()
1546 for each node N in the cgraph
1547 cgraph_analyze_function (N)
1548 cgraph_lower_function (N) -> all_lowering_passes
1550 If we are optimizing, compile is then invoked:
1553 ipa_passes () -> all_small_ipa_passes
1554 -> Analysis of all_regular_ipa_passes
1555 * possible LTO streaming at compilation time *
1556 -> Execution of all_regular_ipa_passes
1557 * possible LTO streaming at link time *
1558 -> all_late_ipa_passes
1559 expand_all_functions ()
1560 for each node N in the cgraph
1561 expand_function (N) -> Transformation of all_regular_ipa_passes
1565 pass_manager::pass_manager (context
*ctxt
)
1566 : all_passes (NULL
), all_small_ipa_passes (NULL
), all_lowering_passes (NULL
),
1567 all_regular_ipa_passes (NULL
),
1568 all_late_ipa_passes (NULL
), passes_by_id (NULL
), passes_by_id_size (0),
1569 m_ctxt (ctxt
), m_name_to_pass_map (NULL
)
1573 /* Zero-initialize pass members. */
1574 #define INSERT_PASSES_AFTER(PASS)
1575 #define PUSH_INSERT_PASSES_WITHIN(PASS)
1576 #define POP_INSERT_PASSES()
1577 #define NEXT_PASS(PASS, NUM) PASS ## _ ## NUM = NULL
1578 #define NEXT_PASS_WITH_ARG(PASS, NUM, ARG) NEXT_PASS (PASS, NUM)
1579 #define TERMINATE_PASS_LIST(PASS)
1580 #include "pass-instances.def"
1581 #undef INSERT_PASSES_AFTER
1582 #undef PUSH_INSERT_PASSES_WITHIN
1583 #undef POP_INSERT_PASSES
1585 #undef NEXT_PASS_WITH_ARG
1586 #undef TERMINATE_PASS_LIST
1588 /* Initialize the pass_lists array. */
1589 #define DEF_PASS_LIST(LIST) pass_lists[PASS_LIST_NO_##LIST] = &LIST;
1591 #undef DEF_PASS_LIST
1593 /* Build the tree of passes. */
1595 #define INSERT_PASSES_AFTER(PASS) \
1597 opt_pass **p_start; \
1598 p_start = p = &(PASS);
1600 #define TERMINATE_PASS_LIST(PASS) \
1601 gcc_assert (p_start == &PASS); \
1605 #define PUSH_INSERT_PASSES_WITHIN(PASS) \
1607 opt_pass **p = &(PASS ## _1)->sub;
1609 #define POP_INSERT_PASSES() \
1612 #define NEXT_PASS(PASS, NUM) \
1614 gcc_assert (PASS ## _ ## NUM == NULL); \
1616 PASS ## _1 = make_##PASS (m_ctxt); \
1619 gcc_assert (PASS ## _1); \
1620 PASS ## _ ## NUM = PASS ## _1->clone (); \
1622 p = next_pass_1 (p, PASS ## _ ## NUM, PASS ## _1); \
1625 #define NEXT_PASS_WITH_ARG(PASS, NUM, ARG) \
1627 NEXT_PASS (PASS, NUM); \
1628 PASS ## _ ## NUM->set_pass_param (0, ARG); \
1631 #include "pass-instances.def"
1633 #undef INSERT_PASSES_AFTER
1634 #undef PUSH_INSERT_PASSES_WITHIN
1635 #undef POP_INSERT_PASSES
1637 #undef NEXT_PASS_WITH_ARG
1638 #undef TERMINATE_PASS_LIST
1640 /* Register the passes with the tree dump code. */
1641 register_dump_files (all_lowering_passes
);
1642 register_dump_files (all_small_ipa_passes
);
1643 register_dump_files (all_regular_ipa_passes
);
1644 register_dump_files (all_late_ipa_passes
);
1645 register_dump_files (all_passes
);
1649 delete_pass_tree (opt_pass
*pass
)
1653 /* Recurse into child passes. */
1654 delete_pass_tree (pass
->sub
);
1656 opt_pass
*next
= pass
->next
;
1658 /* Delete this pass. */
1661 /* Iterate onto sibling passes. */
1666 pass_manager::~pass_manager ()
1668 XDELETEVEC (passes_by_id
);
1670 /* Call delete_pass_tree on each of the pass_lists. */
1671 #define DEF_PASS_LIST(LIST) \
1672 delete_pass_tree (*pass_lists[PASS_LIST_NO_##LIST]);
1674 #undef DEF_PASS_LIST
1676 delete m_name_to_pass_map
;
1679 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1680 function CALLBACK for every function in the call graph. Otherwise,
1681 call CALLBACK on the current function. */
1684 do_per_function (void (*callback
) (function
*, void *data
), void *data
)
1686 if (current_function_decl
)
1687 callback (cfun
, data
);
1690 struct cgraph_node
*node
;
1691 FOR_EACH_DEFINED_FUNCTION (node
)
1692 if (node
->analyzed
&& (gimple_has_body_p (node
->decl
) && !in_lto_p
)
1693 && (!node
->clone_of
|| node
->decl
!= node
->clone_of
->decl
))
1694 callback (DECL_STRUCT_FUNCTION (node
->decl
), data
);
1698 /* Hook called when NODE is removed and therefore should be
1699 excluded from order vector. DATA is a hash set with removed nodes. */
1702 remove_cgraph_node_from_order (cgraph_node
*node
, void *data
)
1704 hash_set
<cgraph_node
*> *removed_nodes
= (hash_set
<cgraph_node
*> *)data
;
1705 removed_nodes
->add (node
);
1708 /* Hook called when NODE is insert and therefore should be
1709 excluded from removed_nodes. DATA is a hash set with removed nodes. */
1712 insert_cgraph_node_to_order (cgraph_node
*node
, void *data
)
1714 hash_set
<cgraph_node
*> *removed_nodes
= (hash_set
<cgraph_node
*> *)data
;
1715 removed_nodes
->remove (node
);
1718 /* Hook called when NODE is duplicated and therefore should be
1719 excluded from removed_nodes. DATA is a hash set with removed nodes. */
1722 duplicate_cgraph_node_to_order (cgraph_node
*node
, cgraph_node
*node2
,
1725 hash_set
<cgraph_node
*> *removed_nodes
= (hash_set
<cgraph_node
*> *)data
;
1726 gcc_checking_assert (!removed_nodes
->contains (node
));
1727 removed_nodes
->remove (node2
);
1731 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1732 function CALLBACK for every function in the call graph. Otherwise,
1733 call CALLBACK on the current function.
1734 This function is global so that plugins can use it. */
1736 do_per_function_toporder (void (*callback
) (function
*, void *data
), void *data
)
1740 if (current_function_decl
)
1741 callback (cfun
, data
);
1744 hash_set
<cgraph_node
*> removed_nodes
;
1745 unsigned nnodes
= symtab
->cgraph_count
;
1746 cgraph_node
**order
= XNEWVEC (cgraph_node
*, nnodes
);
1748 nnodes
= ipa_reverse_postorder (order
);
1749 for (i
= nnodes
- 1; i
>= 0; i
--)
1750 order
[i
]->process
= 1;
1751 cgraph_node_hook_list
*removal_hook
1752 = symtab
->add_cgraph_removal_hook (remove_cgraph_node_from_order
,
1754 cgraph_node_hook_list
*insertion_hook
1755 = symtab
->add_cgraph_insertion_hook (insert_cgraph_node_to_order
,
1757 cgraph_2node_hook_list
*duplication_hook
1758 = symtab
->add_cgraph_duplication_hook (duplicate_cgraph_node_to_order
,
1760 for (i
= nnodes
- 1; i
>= 0; i
--)
1762 cgraph_node
*node
= order
[i
];
1764 /* Function could be inlined and removed as unreachable. */
1765 if (node
== NULL
|| removed_nodes
.contains (node
))
1769 if (node
->has_gimple_body_p ())
1771 struct function
*fn
= DECL_STRUCT_FUNCTION (node
->decl
);
1773 callback (fn
, data
);
1777 symtab
->remove_cgraph_removal_hook (removal_hook
);
1778 symtab
->remove_cgraph_insertion_hook (insertion_hook
);
1779 symtab
->remove_cgraph_duplication_hook (duplication_hook
);
1785 /* Helper function to perform function body dump. */
1788 execute_function_dump (function
*fn
, void *data
)
1790 opt_pass
*pass
= (opt_pass
*)data
;
1796 if (fn
->curr_properties
& PROP_gimple
)
1797 dump_function_to_file (fn
->decl
, dump_file
, dump_flags
);
1799 print_rtl_with_bb (dump_file
, get_insns (), dump_flags
);
1801 /* Flush the file. If verification fails, we won't be able to
1802 close the file before aborting. */
1805 if ((fn
->curr_properties
& PROP_cfg
)
1806 && (dump_flags
& TDF_GRAPH
))
1808 gcc::dump_manager
*dumps
= g
->get_dumps ();
1809 struct dump_file_info
*dfi
1810 = dumps
->get_dump_file_info (pass
->static_pass_number
);
1811 if (!dfi
->graph_dump_initialized
)
1813 clean_graph_dump_file (dump_file_name
);
1814 dfi
->graph_dump_initialized
= true;
1816 print_graph_cfg (dump_file_name
, fn
);
1823 /* This function is called when an internal compiler error is encountered.
1824 Ensure that function dump is made available before compiler is aborted. */
1827 emergency_dump_function ()
1831 enum opt_pass_type pt
= current_pass
->type
;
1832 fnotice (stderr
, "during %s pass: %s\n",
1833 pt
== GIMPLE_PASS
? "GIMPLE" : pt
== RTL_PASS
? "RTL" : "IPA",
1834 current_pass
->name
);
1835 if (!dump_file
|| !cfun
)
1837 fnotice (stderr
, "dump file: %s\n", dump_file_name
);
1838 fprintf (dump_file
, "\n\n\nEMERGENCY DUMP:\n\n");
1839 execute_function_dump (cfun
, current_pass
);
1841 /* Normally the passmanager will close the graphs as a pass could be wanting
1842 to print multiple digraphs. But during an emergency dump there can only be
1843 one and we must finish the graph manually. */
1844 if ((cfun
->curr_properties
& PROP_cfg
)
1845 && (dump_flags
& TDF_GRAPH
))
1846 finish_graph_dump_file (dump_file_name
);
1848 if (symtab
&& current_pass
->type
== IPA_PASS
)
1849 symtab
->dump (dump_file
);
1852 static struct profile_record
*profile_record
;
1854 /* Do profile consistency book-keeping for the pass with static number INDEX.
1855 RUN is true if the pass really runs, or FALSE
1856 if we are only book-keeping on passes that may have selectively disabled
1857 themselves on a given function. */
1860 check_profile_consistency (int index
, bool run
)
1862 pass_manager
*passes
= g
->get_passes ();
1865 if (!profile_record
)
1866 profile_record
= XCNEWVEC (struct profile_record
,
1867 passes
->passes_by_id_size
);
1868 gcc_assert (index
< passes
->passes_by_id_size
&& index
>= 0);
1869 profile_record
[index
].run
|= run
;
1870 profile_record_check_consistency (&profile_record
[index
]);
1873 /* Account profile the pass with static number INDEX.
1874 RUN is true if the pass really runs, or FALSE
1875 if we are only book-keeping on passes that may have selectively disabled
1876 themselves on a given function. */
1879 account_profile (int index
, bool run
)
1881 pass_manager
*passes
= g
->get_passes ();
1884 if (!profile_record
)
1885 profile_record
= XCNEWVEC (struct profile_record
,
1886 passes
->passes_by_id_size
);
1887 gcc_assert (index
< passes
->passes_by_id_size
&& index
>= 0);
1888 profile_record
[index
].run
|= run
;
1889 profile_record_account_profile (&profile_record
[index
]);
1892 /* Account profile for IPA pass. Callback for do_per_function. */
1895 account_profile_1 (function
*fn
, void *data
)
1897 opt_pass
*pass
= (opt_pass
*)data
;
1900 check_profile_consistency (pass
->static_pass_number
, true);
1901 account_profile (pass
->static_pass_number
, true);
1905 /* Account profile chnages to all passes in list starting in SUB. */
1908 account_profile_in_list (opt_pass
*sub
)
1910 for (; sub
; sub
= sub
->next
)
1912 check_profile_consistency (sub
->static_pass_number
, false);
1913 account_profile (sub
->static_pass_number
, false);
1915 account_profile_in_list (sub
->sub
);
1919 /* Output profile consistency. */
1922 dump_profile_report (void)
1924 g
->get_passes ()->dump_profile_report ();
1928 pass_manager::dump_profile_report () const
1930 int last_count_in
= 0, last_prob_out
= 0;
1931 double last_dyn_count_in
= 0, last_dyn_prob_out
= 0;
1932 double last_time
= 0;
1934 double rel_time_change
, rel_size_change
;
1935 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
1937 if (!profile_record
)
1940 FILE *dump_file
= dump_begin (TDI_profile_report
, NULL
);
1941 if (dump_file
== NULL
)
1944 fprintf (dump_file
, "Profile consistency report:\n\n");
1946 "Pass dump id and name |static mismatch "
1947 "|dynamic mismatch "
1950 " |in count |out prob "
1951 "|in count |out prob "
1954 for (int i
= 1; i
< passes_by_id_size
; i
++)
1955 if (profile_record
[i
].run
)
1958 rel_time_change
= (profile_record
[i
].time
1959 - last_time
) * 100 / last_time
;
1961 rel_time_change
= 0;
1963 rel_size_change
= (profile_record
[i
].size
1964 - (double)last_size
) * 100 / (double)last_size
;
1966 rel_size_change
= 0;
1968 dump_file_info
*dfi
= dumps
->get_dump_file_info (i
);
1970 fprintf (dump_file
, "%3i%c %-28s| %6i",
1972 passes_by_id
[i
]->type
== GIMPLE_PASS
? 't'
1973 : passes_by_id
[i
]->type
== RTL_PASS
? 'r'
1975 passes_by_id
[i
]->name
,
1976 profile_record
[i
].num_mismatched_count_in
);
1977 if (profile_record
[i
].num_mismatched_count_in
!= last_count_in
)
1978 fprintf (dump_file
, " %+5i",
1979 profile_record
[i
].num_mismatched_count_in
1982 fprintf (dump_file
, " ");
1983 fprintf (dump_file
, "| %6i",
1984 profile_record
[i
].num_mismatched_prob_out
);
1985 if (profile_record
[i
].num_mismatched_prob_out
!= last_prob_out
)
1986 fprintf (dump_file
, " %+5i",
1987 profile_record
[i
].num_mismatched_prob_out
1990 fprintf (dump_file
, " ");
1992 fprintf (dump_file
, "| %12.0f",
1993 profile_record
[i
].dyn_mismatched_count_in
);
1994 if (profile_record
[i
].dyn_mismatched_count_in
!= last_dyn_count_in
)
1995 fprintf (dump_file
, " %+12.0f",
1996 profile_record
[i
].dyn_mismatched_count_in
1997 - last_dyn_count_in
);
1999 fprintf (dump_file
, " ");
2000 fprintf (dump_file
, "| %12.0f",
2001 profile_record
[i
].dyn_mismatched_prob_out
);
2002 if (profile_record
[i
].dyn_mismatched_prob_out
!= last_dyn_prob_out
)
2003 fprintf (dump_file
, " %+12.0f",
2004 profile_record
[i
].dyn_mismatched_prob_out
2005 - last_dyn_prob_out
);
2007 fprintf (dump_file
, " ");
2009 /* Size/time units change across gimple and RTL. */
2010 if (i
== pass_expand_1
->static_pass_number
)
2012 "|-------------------|--------------------------");
2015 fprintf (dump_file
, "| %8i", profile_record
[i
].size
);
2016 if (rel_size_change
)
2017 fprintf (dump_file
, " %+8.1f%%", rel_size_change
);
2019 fprintf (dump_file
, " ");
2020 fprintf (dump_file
, "| %12.0f", profile_record
[i
].time
);
2021 /* Time units changes with profile estimate and feedback. */
2022 if (i
== pass_profile_1
->static_pass_number
2023 || i
== pass_ipa_tree_profile_1
->static_pass_number
)
2024 fprintf (dump_file
, "-------------");
2025 else if (rel_time_change
)
2026 fprintf (dump_file
, " %+11.1f%%", rel_time_change
);
2028 fprintf (dump_file
, " ");
2030 fprintf (dump_file
, "|\n");
2031 last_prob_out
= profile_record
[i
].num_mismatched_prob_out
;
2032 last_count_in
= profile_record
[i
].num_mismatched_count_in
;
2033 last_dyn_prob_out
= profile_record
[i
].dyn_mismatched_prob_out
;
2034 last_dyn_count_in
= profile_record
[i
].dyn_mismatched_count_in
;
2035 last_time
= profile_record
[i
].time
;
2036 last_size
= profile_record
[i
].size
;
2039 dump_end (TDI_profile_report
, dump_file
);
2042 /* Perform all TODO actions that ought to be done on each function. */
2045 execute_function_todo (function
*fn
, void *data
)
2047 bool from_ipa_pass
= (cfun
== NULL
);
2048 unsigned int flags
= (size_t)data
;
2049 flags
&= ~fn
->last_verified
;
2055 /* If we need to cleanup the CFG let it perform a needed SSA update. */
2056 if (flags
& TODO_cleanup_cfg
)
2057 cleanup_tree_cfg (flags
& TODO_update_ssa_any
);
2058 else if (flags
& TODO_update_ssa_any
)
2059 update_ssa (flags
& TODO_update_ssa_any
);
2060 gcc_assert (!need_ssa_update_p (fn
));
2062 if (flag_tree_pta
&& (flags
& TODO_rebuild_alias
))
2063 compute_may_aliases ();
2065 if (optimize
&& (flags
& TODO_update_address_taken
))
2066 execute_update_addresses_taken ();
2068 if (flags
& TODO_remove_unused_locals
)
2069 remove_unused_locals ();
2071 if (flags
& TODO_rebuild_cgraph_edges
)
2072 cgraph_edge::rebuild_edges ();
2074 gcc_assert (dom_info_state (fn
, CDI_POST_DOMINATORS
) == DOM_NONE
);
2075 /* If we've seen errors do not bother running any verifiers. */
2076 if (flag_checking
&& !seen_error ())
2078 dom_state pre_verify_state
= dom_info_state (fn
, CDI_DOMINATORS
);
2079 dom_state pre_verify_pstate
= dom_info_state (fn
, CDI_POST_DOMINATORS
);
2081 if (flags
& TODO_verify_il
)
2083 if (cfun
->curr_properties
& PROP_gimple
)
2085 if (cfun
->curr_properties
& PROP_cfg
)
2086 /* IPA passes leave stmts to be fixed up, so make sure to
2087 not verify stmts really throw. */
2088 verify_gimple_in_cfg (cfun
, !from_ipa_pass
);
2090 verify_gimple_in_seq (gimple_body (cfun
->decl
));
2092 if (cfun
->curr_properties
& PROP_ssa
)
2093 /* IPA passes leave stmts to be fixed up, so make sure to
2094 not verify SSA operands whose verifier will choke on that. */
2095 verify_ssa (true, !from_ipa_pass
);
2096 /* IPA passes leave basic-blocks unsplit, so make sure to
2097 not trip on that. */
2098 if ((cfun
->curr_properties
& PROP_cfg
)
2100 verify_flow_info ();
2102 && ! loops_state_satisfies_p (LOOPS_NEED_FIXUP
))
2104 verify_loop_structure ();
2105 if (loops_state_satisfies_p (LOOP_CLOSED_SSA
))
2106 verify_loop_closed_ssa (false);
2108 if (cfun
->curr_properties
& PROP_rtl
)
2109 verify_rtl_sharing ();
2112 /* Make sure verifiers don't change dominator state. */
2113 gcc_assert (dom_info_state (fn
, CDI_DOMINATORS
) == pre_verify_state
);
2114 gcc_assert (dom_info_state (fn
, CDI_POST_DOMINATORS
) == pre_verify_pstate
);
2117 fn
->last_verified
= flags
& TODO_verify_all
;
2121 /* For IPA passes make sure to release dominator info, it can be
2122 computed by non-verifying TODOs. */
2125 free_dominance_info (fn
, CDI_DOMINATORS
);
2126 free_dominance_info (fn
, CDI_POST_DOMINATORS
);
2130 /* Perform all TODO actions. */
2132 execute_todo (unsigned int flags
)
2136 && need_ssa_update_p (cfun
))
2137 gcc_assert (flags
& TODO_update_ssa_any
);
2139 statistics_fini_pass ();
2142 do_per_function (execute_function_todo
, (void *)(size_t) flags
);
2144 /* At this point we should not have any unreachable code in the
2145 CFG, so it is safe to flush the pending freelist for SSA_NAMES. */
2146 if (cfun
&& cfun
->gimple_df
)
2147 flush_ssaname_freelist ();
2149 /* Always remove functions just as before inlining: IPA passes might be
2150 interested to see bodies of extern inline functions that are not inlined
2151 to analyze side effects. The full removal is done just at the end
2152 of IPA pass queue. */
2153 if (flags
& TODO_remove_functions
)
2156 symtab
->remove_unreachable_nodes (dump_file
);
2159 if ((flags
& TODO_dump_symtab
) && dump_file
&& !current_function_decl
)
2162 symtab
->dump (dump_file
);
2163 /* Flush the file. If verification fails, we won't be able to
2164 close the file before aborting. */
2168 /* Now that the dumping has been done, we can get rid of the optional
2170 if (flags
& TODO_df_finish
)
2171 df_finish_pass ((flags
& TODO_df_verify
) != 0);
2174 /* Verify invariants that should hold between passes. This is a place
2175 to put simple sanity checks. */
2178 verify_interpass_invariants (void)
2180 gcc_checking_assert (!fold_deferring_overflow_warnings_p ());
2183 /* Clear the last verified flag. */
2186 clear_last_verified (function
*fn
, void *data ATTRIBUTE_UNUSED
)
2188 fn
->last_verified
= 0;
2191 /* Helper function. Verify that the properties has been turn into the
2192 properties expected by the pass. */
2195 verify_curr_properties (function
*fn
, void *data
)
2197 unsigned int props
= (size_t)data
;
2198 gcc_assert ((fn
->curr_properties
& props
) == props
);
2201 /* Release dump file name if set. */
2204 release_dump_file_name (void)
2208 free (CONST_CAST (char *, dump_file_name
));
2209 dump_file_name
= NULL
;
2213 /* Initialize pass dump file. */
2214 /* This is non-static so that the plugins can use it. */
2217 pass_init_dump_file (opt_pass
*pass
)
2219 /* If a dump file name is present, open it if enabled. */
2220 if (pass
->static_pass_number
!= -1)
2222 timevar_push (TV_DUMP
);
2223 gcc::dump_manager
*dumps
= g
->get_dumps ();
2224 bool initializing_dump
=
2225 !dumps
->dump_initialized_p (pass
->static_pass_number
);
2226 release_dump_file_name ();
2227 dump_file_name
= dumps
->get_dump_file_name (pass
->static_pass_number
);
2228 dumps
->dump_start (pass
->static_pass_number
, &dump_flags
);
2229 if (dump_file
&& current_function_decl
&& ! (dump_flags
& TDF_GIMPLE
))
2230 dump_function_header (dump_file
, current_function_decl
, dump_flags
);
2231 if (initializing_dump
2232 && dump_file
&& (dump_flags
& TDF_GRAPH
)
2233 && cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2235 clean_graph_dump_file (dump_file_name
);
2236 struct dump_file_info
*dfi
2237 = dumps
->get_dump_file_info (pass
->static_pass_number
);
2238 dfi
->graph_dump_initialized
= true;
2240 timevar_pop (TV_DUMP
);
2241 return initializing_dump
;
2247 /* Flush PASS dump file. */
2248 /* This is non-static so that plugins can use it. */
2251 pass_fini_dump_file (opt_pass
*pass
)
2253 timevar_push (TV_DUMP
);
2255 /* Flush and close dump file. */
2256 release_dump_file_name ();
2258 g
->get_dumps ()->dump_finish (pass
->static_pass_number
);
2259 timevar_pop (TV_DUMP
);
2262 /* After executing the pass, apply expected changes to the function
2266 update_properties_after_pass (function
*fn
, void *data
)
2268 opt_pass
*pass
= (opt_pass
*) data
;
2269 fn
->curr_properties
= (fn
->curr_properties
| pass
->properties_provided
)
2270 & ~pass
->properties_destroyed
;
2273 /* Execute summary generation for all of the passes in IPA_PASS. */
2276 execute_ipa_summary_passes (ipa_opt_pass_d
*ipa_pass
)
2280 opt_pass
*pass
= ipa_pass
;
2282 /* Execute all of the IPA_PASSes in the list. */
2283 if (ipa_pass
->type
== IPA_PASS
2284 && pass
->gate (cfun
)
2285 && ipa_pass
->generate_summary
)
2287 pass_init_dump_file (pass
);
2289 /* If a timevar is present, start it. */
2291 timevar_push (pass
->tv_id
);
2293 current_pass
= pass
;
2294 ipa_pass
->generate_summary ();
2298 timevar_pop (pass
->tv_id
);
2300 pass_fini_dump_file (pass
);
2302 ipa_pass
= (ipa_opt_pass_d
*)ipa_pass
->next
;
2306 /* Execute IPA_PASS function transform on NODE. */
2309 execute_one_ipa_transform_pass (struct cgraph_node
*node
,
2310 ipa_opt_pass_d
*ipa_pass
, bool do_not_collect
)
2312 opt_pass
*pass
= ipa_pass
;
2313 unsigned int todo_after
= 0;
2315 current_pass
= pass
;
2316 if (!ipa_pass
->function_transform
)
2319 /* Note that the folders should only create gimple expressions.
2320 This is a hack until the new folder is ready. */
2321 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_gimple
)) != 0;
2323 pass_init_dump_file (pass
);
2325 /* If a timevar is present, start it. */
2326 if (pass
->tv_id
!= TV_NONE
)
2327 timevar_push (pass
->tv_id
);
2329 /* Run pre-pass verification. */
2330 execute_todo (ipa_pass
->function_transform_todo_flags_start
);
2333 todo_after
= ipa_pass
->function_transform (node
);
2335 /* Run post-pass cleanup and verification. */
2336 execute_todo (todo_after
);
2337 verify_interpass_invariants ();
2340 if (pass
->tv_id
!= TV_NONE
)
2341 timevar_pop (pass
->tv_id
);
2344 do_per_function (execute_function_dump
, pass
);
2345 pass_fini_dump_file (pass
);
2347 current_pass
= NULL
;
2348 redirect_edge_var_map_empty ();
2350 /* Signal this is a suitable GC collection point. */
2351 if (!do_not_collect
&& !(todo_after
& TODO_do_not_ggc_collect
))
2355 /* For the current function, execute all ipa transforms. */
2358 execute_all_ipa_transforms (bool do_not_collect
)
2360 struct cgraph_node
*node
;
2361 node
= cgraph_node::get (current_function_decl
);
2364 cgraph_node
*next_clone
;
2365 for (cgraph_node
*n
= node
->clones
; n
; n
= next_clone
)
2367 next_clone
= n
->next_sibling_clone
;
2368 if (n
->decl
!= node
->decl
)
2369 n
->materialize_clone ();
2373 gcc::pass_manager
*passes
= g
->get_passes ();
2374 bool report
= profile_report
&& (cfun
->curr_properties
& PROP_gimple
) != 0;
2377 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
2379 for (auto p
: node
->ipa_transforms_to_apply
)
2381 /* To get consistent statistics, we need to account each functio
2382 to each IPA pass. */
2385 for (;j
< p
->static_pass_number
; j
++)
2386 if (passes
->get_pass_for_id (j
)
2387 && passes
->get_pass_for_id (j
)->type
== IPA_PASS
2388 && ((ipa_opt_pass_d
*)passes
->get_pass_for_id (j
))
2389 ->function_transform
)
2391 check_profile_consistency (j
, true);
2392 account_profile (j
, true);
2394 gcc_checking_assert (passes
->get_pass_for_id (j
) == p
);
2396 execute_one_ipa_transform_pass (node
, p
, do_not_collect
);
2398 /* Account remaining IPA passes. */
2401 for (;!passes
->get_pass_for_id (j
)
2402 || passes
->get_pass_for_id (j
)->type
!= RTL_PASS
; j
++)
2403 if (passes
->get_pass_for_id (j
)
2404 && passes
->get_pass_for_id (j
)->type
== IPA_PASS
2405 && ((ipa_opt_pass_d
*)passes
->get_pass_for_id (j
))
2406 ->function_transform
)
2408 check_profile_consistency (j
, true);
2409 account_profile (j
, true);
2413 node
->ipa_transforms_to_apply
.release ();
2416 /* Check if PASS is explicitly disabled or enabled and return
2417 the gate status. FUNC is the function to be processed, and
2418 GATE_STATUS is the gate status determined by pass manager by
2422 override_gate_status (opt_pass
*pass
, tree func
, bool gate_status
)
2424 bool explicitly_enabled
= false;
2425 bool explicitly_disabled
= false;
2428 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2429 enabled_pass_uid_range_tab
);
2431 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2432 disabled_pass_uid_range_tab
);
2434 gate_status
= !explicitly_disabled
&& (gate_status
|| explicitly_enabled
);
2439 /* Determine if PASS_NAME matches CRITERION.
2440 Not a pure predicate, since it can update CRITERION, to support
2441 matching the Nth invocation of a pass.
2442 Subroutine of should_skip_pass_p. */
2445 determine_pass_name_match (const char *pass_name
, char *criterion
)
2447 size_t namelen
= strlen (pass_name
);
2448 if (! strncmp (pass_name
, criterion
, namelen
))
2450 /* The following supports starting with the Nth invocation
2451 of a pass (where N does not necessarily is equal to the
2452 dump file suffix). */
2453 if (criterion
[namelen
] == '\0'
2454 || (criterion
[namelen
] == '1'
2455 && criterion
[namelen
+ 1] == '\0'))
2459 if (criterion
[namelen
+ 1] == '\0')
2460 --criterion
[namelen
];
2468 /* For skipping passes until "startwith" pass.
2469 Return true iff PASS should be skipped.
2470 Clear cfun->pass_startwith when encountering the "startwith" pass,
2471 so that all subsequent passes are run. */
2474 should_skip_pass_p (opt_pass
*pass
)
2478 if (!cfun
->pass_startwith
)
2481 /* For __GIMPLE functions, we have to at least start when we leave
2482 SSA. Hence, we need to detect the "expand" pass, and stop skipping
2483 when we encounter it. A cheap way to identify "expand" is it to
2484 detect the destruction of PROP_ssa.
2485 For __RTL functions, we invoke "rest_of_compilation" directly, which
2486 is after "expand", and hence we don't reach this conditional. */
2487 if (pass
->properties_destroyed
& PROP_ssa
)
2490 fprintf (stderr
, "starting anyway when leaving SSA: %s\n", pass
->name
);
2491 cfun
->pass_startwith
= NULL
;
2495 if (determine_pass_name_match (pass
->name
, cfun
->pass_startwith
))
2498 fprintf (stderr
, "found starting pass: %s\n", pass
->name
);
2499 cfun
->pass_startwith
= NULL
;
2503 /* For GIMPLE passes, run any property provider (but continue skipping
2505 We don't want to force running RTL passes that are property providers:
2506 "expand" is covered above, and the only pass other than "expand" that
2507 provides a property is "into_cfglayout" (PROP_cfglayout), which does
2508 too much for a dumped __RTL function. */
2509 if (pass
->type
== GIMPLE_PASS
2510 && pass
->properties_provided
!= 0)
2513 /* We need to (re-)build cgraph edges as needed. */
2514 if (strstr (pass
->name
, "build_cgraph_edges") != NULL
)
2517 /* We need to run ISEL as that lowers VEC_COND_EXPR but doesn't provide
2519 if (strstr (pass
->name
, "isel") != NULL
)
2522 /* Don't skip df init; later RTL passes need it. */
2523 if (strstr (pass
->name
, "dfinit") != NULL
2524 || strstr (pass
->name
, "dfinish") != NULL
)
2528 fprintf (stderr
, "skipping pass: %s\n", pass
->name
);
2530 /* If we get here, then we have a "startwith" that we haven't seen yet;
2535 /* Skip the given pass, for handling passes before "startwith"
2536 in __GIMPLE and__RTL-marked functions.
2537 In theory, this ought to be a no-op, but some of the RTL passes
2538 need additional processing here. */
2541 skip_pass (opt_pass
*pass
)
2543 /* Pass "reload" sets the global "reload_completed", and many
2544 things depend on this (e.g. instructions in .md files). */
2545 if (strcmp (pass
->name
, "reload") == 0)
2546 reload_completed
= 1;
2548 /* Similar for pass "pro_and_epilogue" and the "epilogue_completed" global
2550 if (strcmp (pass
->name
, "pro_and_epilogue") == 0)
2551 epilogue_completed
= 1;
2553 /* The INSN_ADDRESSES vec is normally set up by
2554 shorten_branches; set it up for the benefit of passes that
2556 if (strcmp (pass
->name
, "shorten") == 0)
2557 INSN_ADDRESSES_ALLOC (get_max_uid ());
2559 /* Update the cfg hooks as appropriate. */
2560 if (strcmp (pass
->name
, "into_cfglayout") == 0)
2562 cfg_layout_rtl_register_cfg_hooks ();
2563 cfun
->curr_properties
|= PROP_cfglayout
;
2565 if (strcmp (pass
->name
, "outof_cfglayout") == 0)
2567 rtl_register_cfg_hooks ();
2568 cfun
->curr_properties
&= ~PROP_cfglayout
;
2575 execute_one_pass (opt_pass
*pass
)
2577 unsigned int todo_after
= 0;
2581 /* IPA passes are executed on whole program, so cfun should be NULL.
2582 Other passes need function context set. */
2583 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
2584 gcc_assert (!cfun
&& !current_function_decl
);
2586 gcc_assert (cfun
&& current_function_decl
);
2588 current_pass
= pass
;
2590 /* Check whether gate check should be avoided.
2591 User controls the value of the gate through the parameter "gate_status". */
2592 gate_status
= pass
->gate (cfun
);
2593 gate_status
= override_gate_status (pass
, current_function_decl
, gate_status
);
2595 /* Override gate with plugin. */
2596 invoke_plugin_callbacks (PLUGIN_OVERRIDE_GATE
, &gate_status
);
2600 /* Run so passes selectively disabling themselves on a given function
2601 are not miscounted. */
2602 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
)
2603 && pass
->type
!= IPA_PASS
&& pass
->type
!= SIMPLE_IPA_PASS
)
2605 check_profile_consistency (pass
->static_pass_number
, false);
2606 account_profile (pass
->static_pass_number
, false);
2608 account_profile_in_list (pass
->sub
);
2610 current_pass
= NULL
;
2614 if (should_skip_pass_p (pass
))
2620 /* Pass execution event trigger: useful to identify passes being
2622 invoke_plugin_callbacks (PLUGIN_PASS_EXECUTION
, pass
);
2624 if (!quiet_flag
&& !cfun
)
2625 fprintf (stderr
, " <%s>", pass
->name
? pass
->name
: "");
2627 /* Note that the folders should only create gimple expressions.
2628 This is a hack until the new folder is ready. */
2629 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_gimple
)) != 0;
2631 pass_init_dump_file (pass
);
2633 /* If a timevar is present, start it. */
2634 if (pass
->tv_id
!= TV_NONE
)
2635 timevar_push (pass
->tv_id
);
2638 /* Run pre-pass verification. */
2639 execute_todo (pass
->todo_flags_start
);
2642 do_per_function (verify_curr_properties
,
2643 (void *)(size_t)pass
->properties_required
);
2646 todo_after
= pass
->execute (cfun
);
2648 if (todo_after
& TODO_discard_function
)
2651 if (pass
->tv_id
!= TV_NONE
)
2652 timevar_pop (pass
->tv_id
);
2654 pass_fini_dump_file (pass
);
2657 /* As cgraph_node::release_body expects release dominators info,
2658 we have to release it. */
2659 if (dom_info_available_p (CDI_DOMINATORS
))
2660 free_dominance_info (CDI_DOMINATORS
);
2662 if (dom_info_available_p (CDI_POST_DOMINATORS
))
2663 free_dominance_info (CDI_POST_DOMINATORS
);
2665 if (cfun
->assume_function
)
2667 /* For assume functions, don't release body, keep it around. */
2668 cfun
->curr_properties
|= PROP_assumptions_done
;
2670 current_pass
= NULL
;
2674 tree fn
= cfun
->decl
;
2677 cgraph_node::get (fn
)->release_body ();
2679 current_pass
= NULL
;
2680 redirect_edge_var_map_empty ();
2687 do_per_function (clear_last_verified
, NULL
);
2689 do_per_function (update_properties_after_pass
, pass
);
2691 /* Run post-pass cleanup and verification. */
2692 execute_todo (todo_after
| pass
->todo_flags_finish
| TODO_verify_il
);
2695 /* IPA passes are accounted at transform time. */
2696 if (pass
->type
== IPA_PASS
)
2698 else if (pass
->type
== SIMPLE_IPA_PASS
)
2699 do_per_function (account_profile_1
, pass
);
2700 else if (cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2702 check_profile_consistency (pass
->static_pass_number
, true);
2703 account_profile (pass
->static_pass_number
, true);
2707 verify_interpass_invariants ();
2710 if (pass
->tv_id
!= TV_NONE
)
2711 timevar_pop (pass
->tv_id
);
2713 if (pass
->type
== IPA_PASS
2714 && ((ipa_opt_pass_d
*)pass
)->function_transform
)
2716 struct cgraph_node
*node
;
2717 FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node
)
2718 if (!node
->inlined_to
)
2719 node
->ipa_transforms_to_apply
.safe_push ((ipa_opt_pass_d
*)pass
);
2722 do_per_function (execute_function_dump
, pass
);
2724 if (!current_function_decl
)
2725 symtab
->process_new_functions ();
2727 pass_fini_dump_file (pass
);
2729 if (pass
->type
!= SIMPLE_IPA_PASS
&& pass
->type
!= IPA_PASS
)
2730 gcc_assert (!(cfun
->curr_properties
& PROP_gimple
)
2731 || pass
->type
!= RTL_PASS
);
2733 current_pass
= NULL
;
2734 redirect_edge_var_map_empty ();
2736 /* Signal this is a suitable GC collection point. */
2737 if (!((todo_after
| pass
->todo_flags_finish
) & TODO_do_not_ggc_collect
))
2740 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
2741 report_heap_memory_use ();
2746 execute_pass_list_1 (opt_pass
*pass
)
2750 gcc_assert (pass
->type
== GIMPLE_PASS
2751 || pass
->type
== RTL_PASS
);
2755 if (execute_one_pass (pass
) && pass
->sub
)
2756 execute_pass_list_1 (pass
->sub
);
2763 execute_pass_list (function
*fn
, opt_pass
*pass
)
2765 gcc_assert (fn
== cfun
);
2766 execute_pass_list_1 (pass
);
2767 if (cfun
&& fn
->cfg
)
2769 free_dominance_info (CDI_DOMINATORS
);
2770 free_dominance_info (CDI_POST_DOMINATORS
);
2774 /* Write out all LTO data. */
2778 timevar_push (TV_IPA_LTO_GIMPLE_OUT
);
2780 timevar_pop (TV_IPA_LTO_GIMPLE_OUT
);
2781 timevar_push (TV_IPA_LTO_DECL_OUT
);
2782 produce_asm_for_decls ();
2783 timevar_pop (TV_IPA_LTO_DECL_OUT
);
2786 /* Same as execute_pass_list but assume that subpasses of IPA passes
2787 are local passes. If SET is not NULL, write out summaries of only
2788 those node in SET. */
2791 ipa_write_summaries_2 (opt_pass
*pass
, struct lto_out_decl_state
*state
)
2795 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*)pass
;
2796 gcc_assert (!current_function_decl
);
2798 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2799 if (pass
->type
== IPA_PASS
2800 && ipa_pass
->write_summary
2801 && pass
->gate (cfun
))
2803 /* If a timevar is present, start it. */
2805 timevar_push (pass
->tv_id
);
2807 pass_init_dump_file (pass
);
2809 current_pass
= pass
;
2810 ipa_pass
->write_summary ();
2812 pass_fini_dump_file (pass
);
2814 /* If a timevar is present, start it. */
2816 timevar_pop (pass
->tv_id
);
2819 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2820 ipa_write_summaries_2 (pass
->sub
, state
);
2826 /* Helper function of ipa_write_summaries. Creates and destroys the
2827 decl state and calls ipa_write_summaries_2 for all passes that have
2828 summaries. SET is the set of nodes to be written. */
2831 ipa_write_summaries_1 (lto_symtab_encoder_t encoder
)
2833 pass_manager
*passes
= g
->get_passes ();
2834 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2835 state
->symtab_node_encoder
= encoder
;
2837 lto_output_init_mode_table ();
2838 lto_push_out_decl_state (state
);
2840 gcc_assert (!flag_wpa
);
2841 ipa_write_summaries_2 (passes
->all_regular_ipa_passes
, state
);
2845 gcc_assert (lto_get_out_decl_state () == state
);
2846 lto_pop_out_decl_state ();
2847 lto_delete_out_decl_state (state
);
2850 /* Write out summaries for all the nodes in the callgraph. */
2853 ipa_write_summaries (void)
2855 lto_symtab_encoder_t encoder
;
2857 varpool_node
*vnode
;
2858 struct cgraph_node
*node
;
2859 struct cgraph_node
**order
;
2861 if ((!flag_generate_lto
&& !flag_generate_offload
) || seen_error ())
2864 gcc_assert (!dump_file
);
2865 streamer_dump_file
= dump_begin (TDI_lto_stream_out
, NULL
);
2867 select_what_to_stream ();
2869 encoder
= lto_symtab_encoder_new (false);
2871 /* Create the callgraph set in the same order used in
2872 cgraph_expand_all_functions. This mostly facilitates debugging,
2873 since it causes the gimple file to be processed in the same order
2874 as the source code. */
2875 order
= XCNEWVEC (struct cgraph_node
*, symtab
->cgraph_count
);
2876 order_pos
= ipa_reverse_postorder (order
);
2877 gcc_assert (order_pos
== symtab
->cgraph_count
);
2879 for (i
= order_pos
- 1; i
>= 0; i
--)
2881 struct cgraph_node
*node
= order
[i
];
2883 if ((node
->definition
|| node
->declare_variant_alt
)
2884 && node
->need_lto_streaming
)
2886 if (gimple_has_body_p (node
->decl
))
2887 lto_prepare_function_for_streaming (node
);
2888 lto_set_symtab_encoder_in_partition (encoder
, node
);
2892 FOR_EACH_DEFINED_FUNCTION (node
)
2893 if (node
->alias
&& node
->need_lto_streaming
)
2894 lto_set_symtab_encoder_in_partition (encoder
, node
);
2895 FOR_EACH_DEFINED_VARIABLE (vnode
)
2896 if (vnode
->need_lto_streaming
)
2897 lto_set_symtab_encoder_in_partition (encoder
, vnode
);
2899 ipa_write_summaries_1 (compute_ltrans_boundary (encoder
));
2902 if (streamer_dump_file
)
2904 dump_end (TDI_lto_stream_out
, streamer_dump_file
);
2905 streamer_dump_file
= NULL
;
2909 /* Same as execute_pass_list but assume that subpasses of IPA passes
2910 are local passes. If SET is not NULL, write out optimization summaries of
2911 only those node in SET. */
2914 ipa_write_optimization_summaries_1 (opt_pass
*pass
,
2915 struct lto_out_decl_state
*state
)
2919 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*)pass
;
2920 gcc_assert (!current_function_decl
);
2922 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2923 if (pass
->type
== IPA_PASS
2924 && ipa_pass
->write_optimization_summary
2925 && pass
->gate (cfun
))
2927 /* If a timevar is present, start it. */
2929 timevar_push (pass
->tv_id
);
2931 pass_init_dump_file (pass
);
2933 current_pass
= pass
;
2934 ipa_pass
->write_optimization_summary ();
2936 pass_fini_dump_file (pass
);
2938 /* If a timevar is present, start it. */
2940 timevar_pop (pass
->tv_id
);
2943 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2944 ipa_write_optimization_summaries_1 (pass
->sub
, state
);
2950 /* Write all the optimization summaries for the cgraph nodes in SET. If SET is
2951 NULL, write out all summaries of all nodes. */
2954 ipa_write_optimization_summaries (lto_symtab_encoder_t encoder
)
2956 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2957 state
->symtab_node_encoder
= encoder
;
2959 lto_output_init_mode_table ();
2960 lto_push_out_decl_state (state
);
2962 /* Be sure that we did not forget to renumber stmt uids. */
2963 gcc_checking_assert (flag_wpa
);
2965 gcc_assert (flag_wpa
);
2966 pass_manager
*passes
= g
->get_passes ();
2967 ipa_write_optimization_summaries_1 (passes
->all_regular_ipa_passes
, state
);
2971 gcc_assert (lto_get_out_decl_state () == state
);
2972 lto_pop_out_decl_state ();
2973 lto_delete_out_decl_state (state
);
2976 /* Same as execute_pass_list but assume that subpasses of IPA passes
2977 are local passes. */
2980 ipa_read_summaries_1 (opt_pass
*pass
)
2984 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
2986 gcc_assert (!current_function_decl
);
2988 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2990 if (pass
->gate (cfun
))
2992 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_summary
)
2994 /* If a timevar is present, start it. */
2996 timevar_push (pass
->tv_id
);
2998 fprintf (stderr
, " <%s>", pass
->name
? pass
->name
: "");
3000 pass_init_dump_file (pass
);
3002 current_pass
= pass
;
3003 ipa_pass
->read_summary ();
3005 pass_fini_dump_file (pass
);
3009 timevar_pop (pass
->tv_id
);
3011 report_heap_memory_use ();
3014 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
3015 ipa_read_summaries_1 (pass
->sub
);
3022 /* Read all the summaries for all_regular_ipa_passes. */
3025 ipa_read_summaries (void)
3027 pass_manager
*passes
= g
->get_passes ();
3028 ipa_read_summaries_1 (passes
->all_regular_ipa_passes
);
3031 /* Same as execute_pass_list but assume that subpasses of IPA passes
3032 are local passes. */
3035 ipa_read_optimization_summaries_1 (opt_pass
*pass
)
3039 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
3041 gcc_assert (!current_function_decl
);
3043 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
3045 if (pass
->gate (cfun
))
3047 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_optimization_summary
)
3049 /* If a timevar is present, start it. */
3051 timevar_push (pass
->tv_id
);
3053 fprintf (stderr
, " <%s>", pass
->name
? pass
->name
: "");
3055 pass_init_dump_file (pass
);
3057 current_pass
= pass
;
3058 ipa_pass
->read_optimization_summary ();
3060 pass_fini_dump_file (pass
);
3064 timevar_pop (pass
->tv_id
);
3067 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
3068 ipa_read_optimization_summaries_1 (pass
->sub
);
3070 report_heap_memory_use ();
3076 /* Read all the summaries for all_regular_ipa_passes. */
3079 ipa_read_optimization_summaries (void)
3081 pass_manager
*passes
= g
->get_passes ();
3082 ipa_read_optimization_summaries_1 (passes
->all_regular_ipa_passes
);
3085 /* Same as execute_pass_list but assume that subpasses of IPA passes
3086 are local passes. */
3088 execute_ipa_pass_list (opt_pass
*pass
)
3092 gcc_assert (!current_function_decl
);
3094 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
3095 if (execute_one_pass (pass
) && pass
->sub
)
3097 if (pass
->sub
->type
== GIMPLE_PASS
)
3099 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_START
, NULL
);
3100 do_per_function_toporder ((void (*)(function
*, void *))
3103 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_END
, NULL
);
3105 else if (pass
->sub
->type
== SIMPLE_IPA_PASS
3106 || pass
->sub
->type
== IPA_PASS
)
3107 execute_ipa_pass_list (pass
->sub
);
3111 gcc_assert (!current_function_decl
);
3112 symtab
->process_new_functions ();
3118 /* Execute stmt fixup hooks of all passes in PASS for NODE and STMTS. */
3121 execute_ipa_stmt_fixups (opt_pass
*pass
,
3122 struct cgraph_node
*node
, gimple
**stmts
)
3126 /* Execute all of the IPA_PASSes in the list. */
3127 if (pass
->type
== IPA_PASS
3128 && pass
->gate (cfun
))
3130 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
3132 if (ipa_pass
->stmt_fixup
)
3134 pass_init_dump_file (pass
);
3135 /* If a timevar is present, start it. */
3137 timevar_push (pass
->tv_id
);
3139 current_pass
= pass
;
3140 ipa_pass
->stmt_fixup (node
, stmts
);
3144 timevar_pop (pass
->tv_id
);
3145 pass_fini_dump_file (pass
);
3148 execute_ipa_stmt_fixups (pass
->sub
, node
, stmts
);
3154 /* Execute stmt fixup hooks of all IPA passes for NODE and STMTS. */
3157 execute_all_ipa_stmt_fixups (struct cgraph_node
*node
, gimple
**stmts
)
3159 pass_manager
*passes
= g
->get_passes ();
3160 execute_ipa_stmt_fixups (passes
->all_regular_ipa_passes
, node
, stmts
);
3164 extern void debug_properties (unsigned int);
3165 extern void dump_properties (FILE *, unsigned int);
3168 dump_properties (FILE *dump
, unsigned int props
)
3170 fprintf (dump
, "Properties:\n");
3171 if (props
& PROP_gimple_any
)
3172 fprintf (dump
, "PROP_gimple_any\n");
3173 if (props
& PROP_gimple_lcf
)
3174 fprintf (dump
, "PROP_gimple_lcf\n");
3175 if (props
& PROP_gimple_leh
)
3176 fprintf (dump
, "PROP_gimple_leh\n");
3177 if (props
& PROP_cfg
)
3178 fprintf (dump
, "PROP_cfg\n");
3179 if (props
& PROP_ssa
)
3180 fprintf (dump
, "PROP_ssa\n");
3181 if (props
& PROP_no_crit_edges
)
3182 fprintf (dump
, "PROP_no_crit_edges\n");
3183 if (props
& PROP_rtl
)
3184 fprintf (dump
, "PROP_rtl\n");
3185 if (props
& PROP_gimple_lomp
)
3186 fprintf (dump
, "PROP_gimple_lomp\n");
3187 if (props
& PROP_gimple_lomp_dev
)
3188 fprintf (dump
, "PROP_gimple_lomp_dev\n");
3189 if (props
& PROP_gimple_lcx
)
3190 fprintf (dump
, "PROP_gimple_lcx\n");
3191 if (props
& PROP_gimple_lvec
)
3192 fprintf (dump
, "PROP_gimple_lvec\n");
3193 if (props
& PROP_cfglayout
)
3194 fprintf (dump
, "PROP_cfglayout\n");
3198 debug_properties (unsigned int props
)
3200 dump_properties (stderr
, props
);
3203 /* Called by local passes to see if function is called by already processed nodes.
3204 Because we process nodes in topological order, this means that function is
3205 in recursive cycle or we introduced new direct calls. */
3207 function_called_by_processed_nodes_p (void)
3209 struct cgraph_edge
*e
;
3210 for (e
= cgraph_node::get (current_function_decl
)->callers
;
3214 if (e
->caller
->decl
== current_function_decl
)
3216 if (!e
->caller
->has_gimple_body_p ())
3218 if (TREE_ASM_WRITTEN (e
->caller
->decl
))
3220 if (!e
->caller
->process
&& !e
->caller
->inlined_to
)
3225 fprintf (dump_file
, "Already processed call to:\n");
3226 e
->caller
->dump (dump_file
);