hppa: Export main in pr104869.C on hpux
[official-gcc.git] / gcc / passes.cc
blob6f894a41d22544507f7673950b4a9aa64a2548a3
1 /* Top level of GCC compilers (cc1, cc1plus, etc.)
2 Copyright (C) 1987-2023 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
9 version.
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
14 for more details.
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. */
25 #include "config.h"
26 #include "system.h"
27 #include "coretypes.h"
28 #include "backend.h"
29 #include "target.h"
30 #include "rtl.h"
31 #include "tree.h"
32 #include "gimple.h"
33 #include "cfghooks.h"
34 #include "df.h"
35 #include "memmodel.h"
36 #include "tm_p.h"
37 #include "ssa.h"
38 #include "emit-rtl.h"
39 #include "cgraph.h"
40 #include "lto-streamer.h"
41 #include "fold-const.h"
42 #include "varasm.h"
43 #include "output.h"
44 #include "graph.h"
45 #include "debug.h"
46 #include "cfgloop.h"
47 #include "value-prof.h"
48 #include "tree-cfg.h"
49 #include "tree-ssa-loop-manip.h"
50 #include "tree-into-ssa.h"
51 #include "tree-dfa.h"
52 #include "tree-ssa.h"
53 #include "tree-pass.h"
54 #include "plugin.h"
55 #include "ipa-utils.h"
56 #include "tree-pretty-print.h" /* for dump_function_header */
57 #include "context.h"
58 #include "pass_manager.h"
59 #include "cfgrtl.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"
65 #include "attribs.h"
67 using namespace gcc;
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
79 error to call it. */
81 opt_pass *
82 opt_pass::clone ()
84 internal_error ("pass %s does not support cloning", name);
87 void
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);
94 bool
95 opt_pass::gate (function *)
97 return true;
100 unsigned int
101 opt_pass::execute (function *)
103 return 0;
106 opt_pass::opt_pass (const pass_data &data, context *ctxt)
107 : pass_data (data),
108 sub (NULL),
109 next (NULL),
110 static_pass_number (0),
111 m_ctxt (ctxt)
116 void
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);
123 unsigned int
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
132 routine. */
133 void
134 print_current_pass (FILE *file)
136 if (current_pass)
137 fprintf (file, "current pass = %s (%d)\n",
138 current_pass->name, current_pass->static_pass_number);
139 else
140 fprintf (file, "no current pass.\n");
144 /* Call from the debugger to get the current pass name. */
145 DEBUG_FUNCTION void
146 debug_pass (void)
148 print_current_pass (stderr);
153 /* Global variables used to communicate with passes. */
154 bool in_gimple_form;
157 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
158 and TYPE_DECL nodes.
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. */
169 void
170 rest_of_decl_compilation (tree decl,
171 int top_level,
172 int at_end)
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. */
178 if (!in_lto_p)
180 tree alias;
181 alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
182 if (alias)
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);
192 finalize = false;
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) */
216 if ((at_end
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
223 rebuild it. */
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,
234 top_level, at_end);
236 #endif
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. */
248 && !seen_error ())
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
269 wrapped hooks. */
270 if (!in_lto_p
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
275 symbol table. */
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.
290 For example:
292 namespace S
298 int i = 42;
300 extern int i; // Local extern declaration.
301 return i;
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
318 properly. */
319 || (finalize
320 && VAR_P (decl)
321 && TREE_STATIC (decl) && !DECL_EXTERNAL (decl)))
322 /* Avoid confusing the debug information machinery when there are
323 errors. */
324 && !seen_error ())
325 (*debug_hooks->early_global_decl) (decl);
328 /* Called after finishing a record, union or enumeral type. */
330 void
331 rest_of_type_compilation (tree type, int toplev)
333 /* Avoid confusing the debug information machinery when there are
334 errors. */
335 if (seen_error ())
336 return;
338 timevar_push (TV_SYMOUT);
339 debug_hooks->type_decl (TYPE_STUB_DECL (type), !toplev);
340 timevar_pop (TV_SYMOUT);
345 void
346 pass_manager::
347 finish_optimization_passes (void)
349 int i;
350 struct dump_file_info *dfi;
351 char *name;
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);
358 end_branch_prob ();
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);
368 free (name);
371 timevar_pop (TV_DUMP);
374 static unsigned int
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;
385 return 0;
388 namespace {
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
407 public:
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 */
431 TV_NONE, /* tv_id */
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
441 public:
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 */
460 TV_NONE, /* tv_id */
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
470 public:
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
484 } // anon namespace
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);
504 namespace {
506 const pass_data pass_data_all_early_optimizations =
508 GIMPLE_PASS, /* type */
509 "early_optimizations", /* name */
510 OPTGROUP_NONE, /* optinfo_flags */
511 TV_NONE, /* tv_id */
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
521 public:
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. */
531 && !seen_error ());
534 }; // class pass_all_early_optimizations
536 } // anon namespace
538 static gimple_opt_pass *
539 make_pass_all_early_optimizations (gcc::context *ctxt)
541 return new pass_all_early_optimizations (ctxt);
544 namespace {
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
561 public:
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
574 } // anon namespace
576 static gimple_opt_pass *
577 make_pass_all_optimizations (gcc::context *ctxt)
579 return new pass_all_optimizations (ctxt);
582 namespace {
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
599 public:
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
612 } // anon namespace
614 static gimple_opt_pass *
615 make_pass_all_optimizations_g (gcc::context *ctxt)
617 return new pass_all_optimizations_g (ctxt);
620 namespace {
622 const pass_data pass_data_rest_of_compilation =
624 RTL_PASS, /* type */
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
637 public:
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
652 } // anon namespace
654 static rtl_opt_pass *
655 make_pass_rest_of_compilation (gcc::context *ctxt)
657 return new pass_rest_of_compilation (ctxt);
660 namespace {
662 const pass_data pass_data_postreload =
664 RTL_PASS, /* type */
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
677 public:
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
687 } // anon namespace
689 static rtl_opt_pass *
690 make_pass_postreload (gcc::context *ctxt)
692 return new pass_postreload (ctxt);
695 namespace {
697 const pass_data pass_data_late_compilation =
699 RTL_PASS, /* type */
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
712 public:
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
725 } // anon namespace
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. */
735 namespace {
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
752 public:
753 pass_pre_slp_scalar_cleanup (gcc::context *ctxt)
754 : gimple_opt_pass (pass_data_pre_slp_scalar_cleanup, ctxt)
758 bool
759 gate (function *fun) final override
761 return flag_tree_slp_vectorize
762 && (fun->pending_TODOs & PENDING_TODO_force_next_scalar_cleanup);
765 unsigned int
766 execute (function *fun) final override
768 fun->pending_TODOs &= ~PENDING_TODO_force_next_scalar_cleanup;
769 return 0;
772 }; // class pass_pre_slp_scalar_cleanup
774 } // anon namespace
776 gimple_opt_pass *
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. */
785 void
786 pass_manager::
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. */
802 opt_pass *
803 pass_manager::get_pass_for_id (int id) const
805 if (id >= passes_by_id_size)
806 return NULL;
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
812 enabled or not. */
814 void
815 register_one_dump_file (opt_pass *pass)
817 g->get_passes ()->register_one_dump_file (pass);
820 void
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. */
827 char num[11];
828 dump_kind dkind;
829 int id;
830 optgroup_flags_t optgroup_flags = OPTGROUP_NONE;
831 gcc::dump_manager *dumps = m_ctxt->get_dumps ();
833 /* See below in next_pass_1. */
834 num[0] = '\0';
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)
849 prefix = "ipa-";
850 dkind = DK_ipa;
851 optgroup_flags |= OPTGROUP_IPA;
853 else if (pass->type == GIMPLE_PASS)
855 prefix = "tree-";
856 dkind = DK_tree;
858 else
860 prefix = "rtl-";
861 dkind = DK_rtl;
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,
873 optgroup_flags,
874 true);
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. */
883 void
884 pass_manager::register_dump_files (opt_pass *pass)
888 if (pass->name && pass->name[0] != '*')
889 register_one_dump_file (pass);
891 if (pass->sub)
892 register_dump_files (pass->sub);
894 pass = pass->next;
896 while (pass);
899 /* Register PASS with NAME. */
901 void
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. */
921 bool
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;
929 return 1;
932 /* The function traverses NAME_TO_PASS_MAP and creates a pass info
933 table for dumping purpose. */
935 void
936 pass_manager::create_pass_tab (void) const
938 if (!flag_dump_passes)
939 return;
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. */
950 static void
951 dump_one_pass (opt_pass *pass, int pass_indent)
953 int indent = 3 * pass_indent;
954 const char *pn;
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)
961 pn = pass->name;
962 else
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. */
974 static void
975 dump_pass_list (opt_pass *pass, int indent)
979 dump_one_pass (pass, indent);
980 if (pass->sub)
981 dump_pass_list (pass->sub, indent + 1);
982 pass = pass->next;
984 while (pass);
987 /* Dump all optimization passes. */
989 void
990 dump_passes (void)
992 g->get_passes ()->dump_passes ();
995 void
996 pass_manager::dump_passes () const
998 push_dummy_function (true);
999 cgraph_node *node = cgraph_node::get_create (current_function_decl);
1001 create_pass_tab ();
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);
1009 node->remove ();
1010 pop_dummy_function ();
1013 /* Returns the pass with NAME. */
1015 opt_pass *
1016 pass_manager::get_pass_by_name (const char *name)
1018 opt_pass **p = m_name_to_pass_map->get (name);
1019 if (p)
1020 return *p;
1022 return NULL;
1026 /* Range [start, last]. */
1028 struct uid_range
1030 unsigned int start;
1031 unsigned int 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,...
1053 static void
1054 enable_disable_pass (const char *arg, bool is_enable)
1056 opt_pass *pass;
1057 char *range_str, *phase_name;
1058 char *argstr = xstrdup (arg);
1059 vec<uid_range_p> *tab = 0;
1061 range_str = strchr (argstr,'=');
1062 if (range_str)
1064 *range_str = '\0';
1065 range_str++;
1068 phase_name = argstr;
1069 if (!*phase_name)
1071 if (is_enable)
1072 error ("unrecognized option %<-fenable%>");
1073 else
1074 error ("unrecognized option %<-fdisable%>");
1075 free (argstr);
1076 return;
1078 pass = g->get_passes ()->get_pass_by_name (phase_name);
1079 if (!pass || pass->static_pass_number == -1)
1081 if (is_enable)
1082 error ("unknown pass %s specified in %<-fenable%>", phase_name);
1083 else
1084 error ("unknown pass %s specified in %<-fdisable%>", phase_name);
1085 free (argstr);
1086 return;
1089 if (is_enable)
1090 tab = &enabled_pass_uid_range_tab;
1091 else
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);
1097 if (!range_str)
1099 uid_range_p slot;
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;
1108 if (is_enable)
1109 inform (UNKNOWN_LOCATION, "enable pass %s for functions in the range "
1110 "of [%u, %u]", phase_name, new_range->start, new_range->last);
1111 else
1112 inform (UNKNOWN_LOCATION, "disable pass %s for functions in the range "
1113 "of [%u, %u]", phase_name, new_range->start, new_range->last);
1115 else
1117 char *next_range = NULL;
1118 char *one_range = range_str;
1119 char *end_val = NULL;
1123 uid_range_p slot;
1124 uid_range_p new_range;
1125 char *invalid = NULL;
1126 long start;
1127 char *func_name = NULL;
1129 next_range = strchr (one_range, ',');
1130 if (next_range)
1132 *next_range = '\0';
1133 next_range++;
1136 end_val = strchr (one_range, ':');
1137 if (end_val)
1139 *end_val = '\0';
1140 end_val++;
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",
1149 one_range,
1150 is_enable ? "-fenable" : "-fdisable");
1151 free (argstr);
1152 return;
1154 func_name = one_range;
1156 if (!end_val)
1158 new_range = XCNEW (struct uid_range);
1159 if (!func_name)
1161 new_range->start = (unsigned) start;
1162 new_range->last = (unsigned) start;
1164 else
1166 new_range->start = (unsigned) -1;
1167 new_range->last = (unsigned) -1;
1168 new_range->assem_name = xstrdup (func_name);
1171 else
1173 long last = strtol (end_val, &invalid, 10);
1174 if (*invalid || last < start)
1176 error ("Invalid range %s in option %s",
1177 end_val,
1178 is_enable ? "-fenable" : "-fdisable");
1179 free (argstr);
1180 return;
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;
1190 if (is_enable)
1192 if (new_range->assem_name)
1193 inform (UNKNOWN_LOCATION,
1194 "enable pass %s for function %s",
1195 phase_name, new_range->assem_name);
1196 else
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);
1201 else
1203 if (new_range->assem_name)
1204 inform (UNKNOWN_LOCATION,
1205 "disable pass %s for function %s",
1206 phase_name, new_range->assem_name);
1207 else
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);
1217 free (argstr);
1220 /* Enable pass specified by ARG. */
1222 void
1223 enable_pass (const char *arg)
1225 enable_disable_pass (arg, true);
1228 /* Disable pass specified by ARG. */
1230 void
1231 disable_pass (const char *arg)
1233 enable_disable_pass (arg, false);
1236 /* Returns true if PASS is explicitly enabled/disabled for FUNC. */
1238 static bool
1239 is_pass_explicitly_enabled_or_disabled (opt_pass *pass,
1240 tree func,
1241 vec<uid_range_p> tab)
1243 uid_range_p slot, range;
1244 int cgraph_uid;
1245 const char *aname = NULL;
1247 if (!tab.exists ()
1248 || (unsigned) pass->static_pass_number >= tab.length ()
1249 || pass->static_pass_number == -1)
1250 return false;
1252 slot = tab[pass->static_pass_number];
1253 if (!slot)
1254 return false;
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));
1260 range = slot;
1261 while (range)
1263 if ((unsigned) cgraph_uid >= range->start
1264 && (unsigned) cgraph_uid <= range->last)
1265 return true;
1266 if (range->assem_name && aname
1267 && !strcmp (range->assem_name, aname))
1268 return true;
1269 range = range->next;
1272 return false;
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) ) */
1304 static void
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;
1324 else
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
1335 in the list. */
1337 static opt_pass **
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);
1344 *list = 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
1358 opt_pass *pass;
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 */
1371 static bool
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
1382 && pass->name
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)))
1390 opt_pass *new_pass;
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);
1398 else
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. */
1414 pass = new_pass;
1415 break;
1416 case PASS_POS_INSERT_BEFORE:
1417 new_pass->next = pass;
1418 if (prev_pass)
1419 prev_pass->next = new_pass;
1420 else
1421 *pass_list = new_pass;
1422 break;
1423 case PASS_POS_REPLACE:
1424 new_pass->next = pass->next;
1425 if (prev_pass)
1426 prev_pass->next = new_pass;
1427 else
1428 *pass_list = new_pass;
1429 new_pass->sub = pass->sub;
1430 new_pass->tv_id = pass->tv_id;
1431 pass = new_pass;
1432 break;
1433 default:
1434 error ("invalid pass positioning operation");
1435 return false;
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;
1447 else
1448 prev_added_pass_node->next = new_pass_node;
1449 prev_added_pass_node = new_pass_node;
1451 success = true;
1454 if (pass->sub && position_pass (new_pass_info, &pass->sub))
1455 success = true;
1458 return success;
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
1465 the pass */
1467 void
1468 register_pass (struct register_pass_info *pass_info)
1470 g->get_passes ()->register_pass (pass_info);
1473 void
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;
1478 i.pass = pass;
1479 i.reference_pass_name = ref_pass_name;
1480 i.ref_pass_instance_number = ref_pass_inst_number;
1481 i.pos_op = pos;
1483 g->get_passes ()->register_pass (&i);
1486 void
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
1493 the messages. */
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)
1501 fatal_error
1502 (input_location,
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
1508 them. */
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);
1519 if (!success)
1520 fatal_error
1521 (input_location,
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:
1552 compile ()
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
1562 -> all_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)
1571 opt_pass **p;
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
1584 #undef NEXT_PASS
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;
1590 GCC_PASS_LISTS
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); \
1602 *p = NULL; \
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) \
1613 do { \
1614 gcc_assert (PASS ## _ ## NUM == NULL); \
1615 if ((NUM) == 1) \
1616 PASS ## _1 = make_##PASS (m_ctxt); \
1617 else \
1619 gcc_assert (PASS ## _1); \
1620 PASS ## _ ## NUM = PASS ## _1->clone (); \
1622 p = next_pass_1 (p, PASS ## _ ## NUM, PASS ## _1); \
1623 } while (0)
1625 #define NEXT_PASS_WITH_ARG(PASS, NUM, ARG) \
1626 do { \
1627 NEXT_PASS (PASS, NUM); \
1628 PASS ## _ ## NUM->set_pass_param (0, ARG); \
1629 } while (0)
1631 #include "pass-instances.def"
1633 #undef INSERT_PASSES_AFTER
1634 #undef PUSH_INSERT_PASSES_WITHIN
1635 #undef POP_INSERT_PASSES
1636 #undef NEXT_PASS
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);
1648 static void
1649 delete_pass_tree (opt_pass *pass)
1651 while (pass)
1653 /* Recurse into child passes. */
1654 delete_pass_tree (pass->sub);
1656 opt_pass *next = pass->next;
1658 /* Delete this pass. */
1659 delete pass;
1661 /* Iterate onto sibling passes. */
1662 pass = next;
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]);
1673 GCC_PASS_LISTS
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. */
1683 static void
1684 do_per_function (void (*callback) (function *, void *data), void *data)
1686 if (current_function_decl)
1687 callback (cfun, data);
1688 else
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. */
1701 static void
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. */
1711 static void
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. */
1721 static void
1722 duplicate_cgraph_node_to_order (cgraph_node *node, cgraph_node *node2,
1723 void *data)
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. */
1735 void
1736 do_per_function_toporder (void (*callback) (function *, void *data), void *data)
1738 int i;
1740 if (current_function_decl)
1741 callback (cfun, data);
1742 else
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,
1753 &removed_nodes);
1754 cgraph_node_hook_list *insertion_hook
1755 = symtab->add_cgraph_insertion_hook (insert_cgraph_node_to_order,
1756 &removed_nodes);
1757 cgraph_2node_hook_list *duplication_hook
1758 = symtab->add_cgraph_duplication_hook (duplicate_cgraph_node_to_order,
1759 &removed_nodes);
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))
1766 continue;
1768 node->process = 0;
1769 if (node->has_gimple_body_p ())
1771 struct function *fn = DECL_STRUCT_FUNCTION (node->decl);
1772 push_cfun (fn);
1773 callback (fn, data);
1774 pop_cfun ();
1777 symtab->remove_cgraph_removal_hook (removal_hook);
1778 symtab->remove_cgraph_insertion_hook (insertion_hook);
1779 symtab->remove_cgraph_duplication_hook (duplication_hook);
1781 free (order);
1785 /* Helper function to perform function body dump. */
1787 static void
1788 execute_function_dump (function *fn, void *data)
1790 opt_pass *pass = (opt_pass *)data;
1792 if (dump_file)
1794 push_cfun (fn);
1796 if (fn->curr_properties & PROP_gimple)
1797 dump_function_to_file (fn->decl, dump_file, dump_flags);
1798 else
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. */
1803 fflush (dump_file);
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);
1819 pop_cfun ();
1823 /* This function is called when an internal compiler error is encountered.
1824 Ensure that function dump is made available before compiler is aborted. */
1826 void
1827 emergency_dump_function ()
1829 if (!current_pass)
1830 return;
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)
1836 return;
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. */
1859 static void
1860 check_profile_consistency (int index, bool run)
1862 pass_manager *passes = g->get_passes ();
1863 if (index == -1)
1864 return;
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. */
1878 static void
1879 account_profile (int index, bool run)
1881 pass_manager *passes = g->get_passes ();
1882 if (index == -1)
1883 return;
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. */
1894 static void
1895 account_profile_1 (function *fn, void *data)
1897 opt_pass *pass = (opt_pass *)data;
1899 push_cfun (fn);
1900 check_profile_consistency (pass->static_pass_number, true);
1901 account_profile (pass->static_pass_number, true);
1902 pop_cfun ();
1905 /* Account profile chnages to all passes in list starting in SUB. */
1907 static void
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);
1914 if (sub->sub)
1915 account_profile_in_list (sub->sub);
1919 /* Output profile consistency. */
1921 void
1922 dump_profile_report (void)
1924 g->get_passes ()->dump_profile_report ();
1927 void
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;
1933 int last_size = 0;
1934 double rel_time_change, rel_size_change;
1935 gcc::dump_manager *dumps = m_ctxt->get_dumps ();
1937 if (!profile_record)
1938 return;
1940 FILE *dump_file = dump_begin (TDI_profile_report, NULL);
1941 if (dump_file == NULL)
1942 dump_file = stderr;
1944 fprintf (dump_file, "Profile consistency report:\n\n");
1945 fprintf (dump_file,
1946 "Pass dump id and name |static mismatch "
1947 "|dynamic mismatch "
1948 "|overall |\n");
1949 fprintf (dump_file,
1950 " |in count |out prob "
1951 "|in count |out prob "
1952 "|size |time |\n");
1954 for (int i = 1; i < passes_by_id_size; i++)
1955 if (profile_record[i].run)
1957 if (last_time)
1958 rel_time_change = (profile_record[i].time
1959 - last_time) * 100 / last_time;
1960 else
1961 rel_time_change = 0;
1962 if (last_size)
1963 rel_size_change = (profile_record[i].size
1964 - (double)last_size) * 100 / (double)last_size;
1965 else
1966 rel_size_change = 0;
1968 dump_file_info *dfi = dumps->get_dump_file_info (i);
1970 fprintf (dump_file, "%3i%c %-28s| %6i",
1971 dfi->num,
1972 passes_by_id[i]->type == GIMPLE_PASS ? 't'
1973 : passes_by_id[i]->type == RTL_PASS ? 'r'
1974 : 'i',
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
1980 - last_count_in);
1981 else
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
1988 - last_prob_out);
1989 else
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);
1998 else
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);
2006 else
2007 fprintf (dump_file, " ");
2009 /* Size/time units change across gimple and RTL. */
2010 if (i == pass_expand_1->static_pass_number)
2011 fprintf (dump_file,
2012 "|-------------------|--------------------------");
2013 else
2015 fprintf (dump_file, "| %8i", profile_record[i].size);
2016 if (rel_size_change)
2017 fprintf (dump_file, " %+8.1f%%", rel_size_change);
2018 else
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);
2027 else
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. */
2044 static void
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;
2050 if (!flags)
2051 return;
2053 push_cfun (fn);
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);
2089 else
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)
2099 && !from_ipa_pass)
2100 verify_flow_info ();
2101 if (current_loops
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;
2119 pop_cfun ();
2121 /* For IPA passes make sure to release dominator info, it can be
2122 computed by non-verifying TODOs. */
2123 if (from_ipa_pass)
2125 free_dominance_info (fn, CDI_DOMINATORS);
2126 free_dominance_info (fn, CDI_POST_DOMINATORS);
2130 /* Perform all TODO actions. */
2131 static void
2132 execute_todo (unsigned int flags)
2134 if (flag_checking
2135 && cfun
2136 && need_ssa_update_p (cfun))
2137 gcc_assert (flags & TODO_update_ssa_any);
2139 statistics_fini_pass ();
2141 if (flags)
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)
2155 gcc_assert (!cfun);
2156 symtab->remove_unreachable_nodes (dump_file);
2159 if ((flags & TODO_dump_symtab) && dump_file && !current_function_decl)
2161 gcc_assert (!cfun);
2162 symtab->dump (dump_file);
2163 /* Flush the file. If verification fails, we won't be able to
2164 close the file before aborting. */
2165 fflush (dump_file);
2168 /* Now that the dumping has been done, we can get rid of the optional
2169 df problems. */
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. */
2177 static void
2178 verify_interpass_invariants (void)
2180 gcc_checking_assert (!fold_deferring_overflow_warnings_p ());
2183 /* Clear the last verified flag. */
2185 static void
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. */
2194 static void
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. */
2203 static void
2204 release_dump_file_name (void)
2206 if (dump_file_name)
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. */
2216 bool
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;
2243 else
2244 return false;
2247 /* Flush PASS dump file. */
2248 /* This is non-static so that plugins can use it. */
2250 void
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
2263 properties. */
2265 static void
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. */
2275 void
2276 execute_ipa_summary_passes (ipa_opt_pass_d *ipa_pass)
2278 while (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. */
2290 if (pass->tv_id)
2291 timevar_push (pass->tv_id);
2293 current_pass = pass;
2294 ipa_pass->generate_summary ();
2296 /* Stop timevar. */
2297 if (pass->tv_id)
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. */
2308 static void
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)
2317 return;
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);
2332 /* Do it! */
2333 todo_after = ipa_pass->function_transform (node);
2335 /* Run post-pass cleanup and verification. */
2336 execute_todo (todo_after);
2337 verify_interpass_invariants ();
2339 /* Stop timevar. */
2340 if (pass->tv_id != TV_NONE)
2341 timevar_pop (pass->tv_id);
2343 if (dump_file)
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))
2352 ggc_collect ();
2355 /* For the current function, execute all ipa transforms. */
2357 void
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 ();
2372 int j = 0;
2373 gcc::pass_manager *passes = g->get_passes ();
2374 bool report = profile_report && (cfun->curr_properties & PROP_gimple) != 0;
2376 if (report)
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. */
2383 if (report)
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. */
2399 if (report)
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);
2411 pop_cfun ();
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
2419 default. */
2421 static bool
2422 override_gate_status (opt_pass *pass, tree func, bool gate_status)
2424 bool explicitly_enabled = false;
2425 bool explicitly_disabled = false;
2427 explicitly_enabled
2428 = is_pass_explicitly_enabled_or_disabled (pass, func,
2429 enabled_pass_uid_range_tab);
2430 explicitly_disabled
2431 = is_pass_explicitly_enabled_or_disabled (pass, func,
2432 disabled_pass_uid_range_tab);
2434 gate_status = !explicitly_disabled && (gate_status || explicitly_enabled);
2436 return gate_status;
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. */
2444 static bool
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'))
2456 return true;
2457 else
2459 if (criterion[namelen + 1] == '\0')
2460 --criterion[namelen];
2461 return false;
2464 else
2465 return false;
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. */
2473 static bool
2474 should_skip_pass_p (opt_pass *pass)
2476 if (!cfun)
2477 return false;
2478 if (!cfun->pass_startwith)
2479 return false;
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)
2489 if (!quiet_flag)
2490 fprintf (stderr, "starting anyway when leaving SSA: %s\n", pass->name);
2491 cfun->pass_startwith = NULL;
2492 return false;
2495 if (determine_pass_name_match (pass->name, cfun->pass_startwith))
2497 if (!quiet_flag)
2498 fprintf (stderr, "found starting pass: %s\n", pass->name);
2499 cfun->pass_startwith = NULL;
2500 return false;
2503 /* For GIMPLE passes, run any property provider (but continue skipping
2504 afterwards).
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)
2511 return false;
2513 /* We need to (re-)build cgraph edges as needed. */
2514 if (strstr (pass->name, "build_cgraph_edges") != NULL)
2515 return false;
2517 /* Don't skip df init; later RTL passes need it. */
2518 if (strstr (pass->name, "dfinit") != NULL
2519 || strstr (pass->name, "dfinish") != NULL)
2520 return false;
2522 if (!quiet_flag)
2523 fprintf (stderr, "skipping pass: %s\n", pass->name);
2525 /* If we get here, then we have a "startwith" that we haven't seen yet;
2526 skip the pass. */
2527 return true;
2530 /* Skip the given pass, for handling passes before "startwith"
2531 in __GIMPLE and__RTL-marked functions.
2532 In theory, this ought to be a no-op, but some of the RTL passes
2533 need additional processing here. */
2535 static void
2536 skip_pass (opt_pass *pass)
2538 /* Pass "reload" sets the global "reload_completed", and many
2539 things depend on this (e.g. instructions in .md files). */
2540 if (strcmp (pass->name, "reload") == 0)
2541 reload_completed = 1;
2543 /* Similar for pass "pro_and_epilogue" and the "epilogue_completed" global
2544 variable. */
2545 if (strcmp (pass->name, "pro_and_epilogue") == 0)
2546 epilogue_completed = 1;
2548 /* The INSN_ADDRESSES vec is normally set up by
2549 shorten_branches; set it up for the benefit of passes that
2550 run after this. */
2551 if (strcmp (pass->name, "shorten") == 0)
2552 INSN_ADDRESSES_ALLOC (get_max_uid ());
2554 /* Update the cfg hooks as appropriate. */
2555 if (strcmp (pass->name, "into_cfglayout") == 0)
2557 cfg_layout_rtl_register_cfg_hooks ();
2558 cfun->curr_properties |= PROP_cfglayout;
2560 if (strcmp (pass->name, "outof_cfglayout") == 0)
2562 rtl_register_cfg_hooks ();
2563 cfun->curr_properties &= ~PROP_cfglayout;
2567 /* Execute PASS. */
2569 bool
2570 execute_one_pass (opt_pass *pass)
2572 unsigned int todo_after = 0;
2574 bool gate_status;
2576 /* IPA passes are executed on whole program, so cfun should be NULL.
2577 Other passes need function context set. */
2578 if (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS)
2579 gcc_assert (!cfun && !current_function_decl);
2580 else
2581 gcc_assert (cfun && current_function_decl);
2583 current_pass = pass;
2585 /* Check whether gate check should be avoided.
2586 User controls the value of the gate through the parameter "gate_status". */
2587 gate_status = pass->gate (cfun);
2588 gate_status = override_gate_status (pass, current_function_decl, gate_status);
2590 /* Override gate with plugin. */
2591 invoke_plugin_callbacks (PLUGIN_OVERRIDE_GATE, &gate_status);
2593 if (!gate_status)
2595 /* Run so passes selectively disabling themselves on a given function
2596 are not miscounted. */
2597 if (profile_report && cfun && (cfun->curr_properties & PROP_cfg)
2598 && pass->type != IPA_PASS && pass->type != SIMPLE_IPA_PASS)
2600 check_profile_consistency (pass->static_pass_number, false);
2601 account_profile (pass->static_pass_number, false);
2602 if (pass->sub)
2603 account_profile_in_list (pass->sub);
2605 current_pass = NULL;
2606 return false;
2609 if (should_skip_pass_p (pass))
2611 skip_pass (pass);
2612 return true;
2615 /* Pass execution event trigger: useful to identify passes being
2616 executed. */
2617 invoke_plugin_callbacks (PLUGIN_PASS_EXECUTION, pass);
2619 if (!quiet_flag && !cfun)
2620 fprintf (stderr, " <%s>", pass->name ? pass->name : "");
2622 /* Note that the folders should only create gimple expressions.
2623 This is a hack until the new folder is ready. */
2624 in_gimple_form = (cfun && (cfun->curr_properties & PROP_gimple)) != 0;
2626 pass_init_dump_file (pass);
2628 /* If a timevar is present, start it. */
2629 if (pass->tv_id != TV_NONE)
2630 timevar_push (pass->tv_id);
2633 /* Run pre-pass verification. */
2634 execute_todo (pass->todo_flags_start);
2636 if (flag_checking)
2637 do_per_function (verify_curr_properties,
2638 (void *)(size_t)pass->properties_required);
2640 /* Do it! */
2641 todo_after = pass->execute (cfun);
2643 if (todo_after & TODO_discard_function)
2645 /* Stop timevar. */
2646 if (pass->tv_id != TV_NONE)
2647 timevar_pop (pass->tv_id);
2649 pass_fini_dump_file (pass);
2651 gcc_assert (cfun);
2652 /* As cgraph_node::release_body expects release dominators info,
2653 we have to release it. */
2654 if (dom_info_available_p (CDI_DOMINATORS))
2655 free_dominance_info (CDI_DOMINATORS);
2657 if (dom_info_available_p (CDI_POST_DOMINATORS))
2658 free_dominance_info (CDI_POST_DOMINATORS);
2660 if (cfun->assume_function)
2662 /* For assume functions, don't release body, keep it around. */
2663 cfun->curr_properties |= PROP_assumptions_done;
2664 pop_cfun ();
2665 current_pass = NULL;
2666 return true;
2669 tree fn = cfun->decl;
2670 pop_cfun ();
2671 gcc_assert (!cfun);
2672 cgraph_node::get (fn)->release_body ();
2674 current_pass = NULL;
2675 redirect_edge_var_map_empty ();
2677 ggc_collect ();
2679 return true;
2682 do_per_function (clear_last_verified, NULL);
2684 do_per_function (update_properties_after_pass, pass);
2686 /* Run post-pass cleanup and verification. */
2687 execute_todo (todo_after | pass->todo_flags_finish | TODO_verify_il);
2688 if (profile_report)
2690 /* IPA passes are accounted at transform time. */
2691 if (pass->type == IPA_PASS)
2693 else if (pass->type == SIMPLE_IPA_PASS)
2694 do_per_function (account_profile_1, pass);
2695 else if (cfun && (cfun->curr_properties & PROP_cfg))
2697 check_profile_consistency (pass->static_pass_number, true);
2698 account_profile (pass->static_pass_number, true);
2702 verify_interpass_invariants ();
2704 /* Stop timevar. */
2705 if (pass->tv_id != TV_NONE)
2706 timevar_pop (pass->tv_id);
2708 if (pass->type == IPA_PASS
2709 && ((ipa_opt_pass_d *)pass)->function_transform)
2711 struct cgraph_node *node;
2712 FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node)
2713 if (!node->inlined_to)
2714 node->ipa_transforms_to_apply.safe_push ((ipa_opt_pass_d *)pass);
2716 else if (dump_file)
2717 do_per_function (execute_function_dump, pass);
2719 if (!current_function_decl)
2720 symtab->process_new_functions ();
2722 pass_fini_dump_file (pass);
2724 if (pass->type != SIMPLE_IPA_PASS && pass->type != IPA_PASS)
2725 gcc_assert (!(cfun->curr_properties & PROP_gimple)
2726 || pass->type != RTL_PASS);
2728 current_pass = NULL;
2729 redirect_edge_var_map_empty ();
2731 /* Signal this is a suitable GC collection point. */
2732 if (!((todo_after | pass->todo_flags_finish) & TODO_do_not_ggc_collect))
2733 ggc_collect ();
2735 if (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS)
2736 report_heap_memory_use ();
2737 return true;
2740 static void
2741 execute_pass_list_1 (opt_pass *pass)
2745 gcc_assert (pass->type == GIMPLE_PASS
2746 || pass->type == RTL_PASS);
2748 if (cfun == NULL)
2749 return;
2750 if (execute_one_pass (pass) && pass->sub)
2751 execute_pass_list_1 (pass->sub);
2752 pass = pass->next;
2754 while (pass);
2757 void
2758 execute_pass_list (function *fn, opt_pass *pass)
2760 gcc_assert (fn == cfun);
2761 execute_pass_list_1 (pass);
2762 if (cfun && fn->cfg)
2764 free_dominance_info (CDI_DOMINATORS);
2765 free_dominance_info (CDI_POST_DOMINATORS);
2769 /* Write out all LTO data. */
2770 static void
2771 write_lto (void)
2773 timevar_push (TV_IPA_LTO_GIMPLE_OUT);
2774 lto_output ();
2775 timevar_pop (TV_IPA_LTO_GIMPLE_OUT);
2776 timevar_push (TV_IPA_LTO_DECL_OUT);
2777 produce_asm_for_decls ();
2778 timevar_pop (TV_IPA_LTO_DECL_OUT);
2781 /* Same as execute_pass_list but assume that subpasses of IPA passes
2782 are local passes. If SET is not NULL, write out summaries of only
2783 those node in SET. */
2785 static void
2786 ipa_write_summaries_2 (opt_pass *pass, struct lto_out_decl_state *state)
2788 while (pass)
2790 ipa_opt_pass_d *ipa_pass = (ipa_opt_pass_d *)pass;
2791 gcc_assert (!current_function_decl);
2792 gcc_assert (!cfun);
2793 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
2794 if (pass->type == IPA_PASS
2795 && ipa_pass->write_summary
2796 && pass->gate (cfun))
2798 /* If a timevar is present, start it. */
2799 if (pass->tv_id)
2800 timevar_push (pass->tv_id);
2802 pass_init_dump_file (pass);
2804 current_pass = pass;
2805 ipa_pass->write_summary ();
2807 pass_fini_dump_file (pass);
2809 /* If a timevar is present, start it. */
2810 if (pass->tv_id)
2811 timevar_pop (pass->tv_id);
2814 if (pass->sub && pass->sub->type != GIMPLE_PASS)
2815 ipa_write_summaries_2 (pass->sub, state);
2817 pass = pass->next;
2821 /* Helper function of ipa_write_summaries. Creates and destroys the
2822 decl state and calls ipa_write_summaries_2 for all passes that have
2823 summaries. SET is the set of nodes to be written. */
2825 static void
2826 ipa_write_summaries_1 (lto_symtab_encoder_t encoder)
2828 pass_manager *passes = g->get_passes ();
2829 struct lto_out_decl_state *state = lto_new_out_decl_state ();
2830 state->symtab_node_encoder = encoder;
2832 lto_output_init_mode_table ();
2833 lto_push_out_decl_state (state);
2835 gcc_assert (!flag_wpa);
2836 ipa_write_summaries_2 (passes->all_regular_ipa_passes, state);
2838 write_lto ();
2840 gcc_assert (lto_get_out_decl_state () == state);
2841 lto_pop_out_decl_state ();
2842 lto_delete_out_decl_state (state);
2845 /* Write out summaries for all the nodes in the callgraph. */
2847 void
2848 ipa_write_summaries (void)
2850 lto_symtab_encoder_t encoder;
2851 int i, order_pos;
2852 varpool_node *vnode;
2853 struct cgraph_node *node;
2854 struct cgraph_node **order;
2856 if ((!flag_generate_lto && !flag_generate_offload) || seen_error ())
2857 return;
2859 gcc_assert (!dump_file);
2860 streamer_dump_file = dump_begin (TDI_lto_stream_out, NULL);
2862 select_what_to_stream ();
2864 encoder = lto_symtab_encoder_new (false);
2866 /* Create the callgraph set in the same order used in
2867 cgraph_expand_all_functions. This mostly facilitates debugging,
2868 since it causes the gimple file to be processed in the same order
2869 as the source code. */
2870 order = XCNEWVEC (struct cgraph_node *, symtab->cgraph_count);
2871 order_pos = ipa_reverse_postorder (order);
2872 gcc_assert (order_pos == symtab->cgraph_count);
2874 for (i = order_pos - 1; i >= 0; i--)
2876 struct cgraph_node *node = order[i];
2878 if ((node->definition || node->declare_variant_alt)
2879 && node->need_lto_streaming)
2881 if (gimple_has_body_p (node->decl))
2882 lto_prepare_function_for_streaming (node);
2883 lto_set_symtab_encoder_in_partition (encoder, node);
2887 FOR_EACH_DEFINED_FUNCTION (node)
2888 if (node->alias && node->need_lto_streaming)
2889 lto_set_symtab_encoder_in_partition (encoder, node);
2890 FOR_EACH_DEFINED_VARIABLE (vnode)
2891 if (vnode->need_lto_streaming)
2892 lto_set_symtab_encoder_in_partition (encoder, vnode);
2894 ipa_write_summaries_1 (compute_ltrans_boundary (encoder));
2896 free (order);
2897 if (streamer_dump_file)
2899 dump_end (TDI_lto_stream_out, streamer_dump_file);
2900 streamer_dump_file = NULL;
2904 /* Same as execute_pass_list but assume that subpasses of IPA passes
2905 are local passes. If SET is not NULL, write out optimization summaries of
2906 only those node in SET. */
2908 static void
2909 ipa_write_optimization_summaries_1 (opt_pass *pass,
2910 struct lto_out_decl_state *state)
2912 while (pass)
2914 ipa_opt_pass_d *ipa_pass = (ipa_opt_pass_d *)pass;
2915 gcc_assert (!current_function_decl);
2916 gcc_assert (!cfun);
2917 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
2918 if (pass->type == IPA_PASS
2919 && ipa_pass->write_optimization_summary
2920 && pass->gate (cfun))
2922 /* If a timevar is present, start it. */
2923 if (pass->tv_id)
2924 timevar_push (pass->tv_id);
2926 pass_init_dump_file (pass);
2928 current_pass = pass;
2929 ipa_pass->write_optimization_summary ();
2931 pass_fini_dump_file (pass);
2933 /* If a timevar is present, start it. */
2934 if (pass->tv_id)
2935 timevar_pop (pass->tv_id);
2938 if (pass->sub && pass->sub->type != GIMPLE_PASS)
2939 ipa_write_optimization_summaries_1 (pass->sub, state);
2941 pass = pass->next;
2945 /* Write all the optimization summaries for the cgraph nodes in SET. If SET is
2946 NULL, write out all summaries of all nodes. */
2948 void
2949 ipa_write_optimization_summaries (lto_symtab_encoder_t encoder)
2951 struct lto_out_decl_state *state = lto_new_out_decl_state ();
2952 state->symtab_node_encoder = encoder;
2954 lto_output_init_mode_table ();
2955 lto_push_out_decl_state (state);
2957 /* Be sure that we did not forget to renumber stmt uids. */
2958 gcc_checking_assert (flag_wpa);
2960 gcc_assert (flag_wpa);
2961 pass_manager *passes = g->get_passes ();
2962 ipa_write_optimization_summaries_1 (passes->all_regular_ipa_passes, state);
2964 write_lto ();
2966 gcc_assert (lto_get_out_decl_state () == state);
2967 lto_pop_out_decl_state ();
2968 lto_delete_out_decl_state (state);
2971 /* Same as execute_pass_list but assume that subpasses of IPA passes
2972 are local passes. */
2974 static void
2975 ipa_read_summaries_1 (opt_pass *pass)
2977 while (pass)
2979 ipa_opt_pass_d *ipa_pass = (ipa_opt_pass_d *) pass;
2981 gcc_assert (!current_function_decl);
2982 gcc_assert (!cfun);
2983 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
2985 if (pass->gate (cfun))
2987 if (pass->type == IPA_PASS && ipa_pass->read_summary)
2989 /* If a timevar is present, start it. */
2990 if (pass->tv_id)
2991 timevar_push (pass->tv_id);
2992 if (!quiet_flag)
2993 fprintf (stderr, " <%s>", pass->name ? pass->name : "");
2995 pass_init_dump_file (pass);
2997 current_pass = pass;
2998 ipa_pass->read_summary ();
3000 pass_fini_dump_file (pass);
3002 /* Stop timevar. */
3003 if (pass->tv_id)
3004 timevar_pop (pass->tv_id);
3005 ggc_grow ();
3006 report_heap_memory_use ();
3009 if (pass->sub && pass->sub->type != GIMPLE_PASS)
3010 ipa_read_summaries_1 (pass->sub);
3012 pass = pass->next;
3017 /* Read all the summaries for all_regular_ipa_passes. */
3019 void
3020 ipa_read_summaries (void)
3022 pass_manager *passes = g->get_passes ();
3023 ipa_read_summaries_1 (passes->all_regular_ipa_passes);
3026 /* Same as execute_pass_list but assume that subpasses of IPA passes
3027 are local passes. */
3029 static void
3030 ipa_read_optimization_summaries_1 (opt_pass *pass)
3032 while (pass)
3034 ipa_opt_pass_d *ipa_pass = (ipa_opt_pass_d *) pass;
3036 gcc_assert (!current_function_decl);
3037 gcc_assert (!cfun);
3038 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
3040 if (pass->gate (cfun))
3042 if (pass->type == IPA_PASS && ipa_pass->read_optimization_summary)
3044 /* If a timevar is present, start it. */
3045 if (pass->tv_id)
3046 timevar_push (pass->tv_id);
3047 if (!quiet_flag)
3048 fprintf (stderr, " <%s>", pass->name ? pass->name : "");
3050 pass_init_dump_file (pass);
3052 current_pass = pass;
3053 ipa_pass->read_optimization_summary ();
3055 pass_fini_dump_file (pass);
3057 /* Stop timevar. */
3058 if (pass->tv_id)
3059 timevar_pop (pass->tv_id);
3062 if (pass->sub && pass->sub->type != GIMPLE_PASS)
3063 ipa_read_optimization_summaries_1 (pass->sub);
3064 ggc_grow ();
3065 report_heap_memory_use ();
3067 pass = pass->next;
3071 /* Read all the summaries for all_regular_ipa_passes. */
3073 void
3074 ipa_read_optimization_summaries (void)
3076 pass_manager *passes = g->get_passes ();
3077 ipa_read_optimization_summaries_1 (passes->all_regular_ipa_passes);
3080 /* Same as execute_pass_list but assume that subpasses of IPA passes
3081 are local passes. */
3082 void
3083 execute_ipa_pass_list (opt_pass *pass)
3087 gcc_assert (!current_function_decl);
3088 gcc_assert (!cfun);
3089 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
3090 if (execute_one_pass (pass) && pass->sub)
3092 if (pass->sub->type == GIMPLE_PASS)
3094 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_START, NULL);
3095 do_per_function_toporder ((void (*)(function *, void *))
3096 execute_pass_list,
3097 pass->sub);
3098 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_END, NULL);
3100 else if (pass->sub->type == SIMPLE_IPA_PASS
3101 || pass->sub->type == IPA_PASS)
3102 execute_ipa_pass_list (pass->sub);
3103 else
3104 gcc_unreachable ();
3106 gcc_assert (!current_function_decl);
3107 symtab->process_new_functions ();
3108 pass = pass->next;
3110 while (pass);
3113 /* Execute stmt fixup hooks of all passes in PASS for NODE and STMTS. */
3115 static void
3116 execute_ipa_stmt_fixups (opt_pass *pass,
3117 struct cgraph_node *node, gimple **stmts)
3119 while (pass)
3121 /* Execute all of the IPA_PASSes in the list. */
3122 if (pass->type == IPA_PASS
3123 && pass->gate (cfun))
3125 ipa_opt_pass_d *ipa_pass = (ipa_opt_pass_d *) pass;
3127 if (ipa_pass->stmt_fixup)
3129 pass_init_dump_file (pass);
3130 /* If a timevar is present, start it. */
3131 if (pass->tv_id)
3132 timevar_push (pass->tv_id);
3134 current_pass = pass;
3135 ipa_pass->stmt_fixup (node, stmts);
3137 /* Stop timevar. */
3138 if (pass->tv_id)
3139 timevar_pop (pass->tv_id);
3140 pass_fini_dump_file (pass);
3142 if (pass->sub)
3143 execute_ipa_stmt_fixups (pass->sub, node, stmts);
3145 pass = pass->next;
3149 /* Execute stmt fixup hooks of all IPA passes for NODE and STMTS. */
3151 void
3152 execute_all_ipa_stmt_fixups (struct cgraph_node *node, gimple **stmts)
3154 pass_manager *passes = g->get_passes ();
3155 execute_ipa_stmt_fixups (passes->all_regular_ipa_passes, node, stmts);
3159 extern void debug_properties (unsigned int);
3160 extern void dump_properties (FILE *, unsigned int);
3162 DEBUG_FUNCTION void
3163 dump_properties (FILE *dump, unsigned int props)
3165 fprintf (dump, "Properties:\n");
3166 if (props & PROP_gimple_any)
3167 fprintf (dump, "PROP_gimple_any\n");
3168 if (props & PROP_gimple_lcf)
3169 fprintf (dump, "PROP_gimple_lcf\n");
3170 if (props & PROP_gimple_leh)
3171 fprintf (dump, "PROP_gimple_leh\n");
3172 if (props & PROP_cfg)
3173 fprintf (dump, "PROP_cfg\n");
3174 if (props & PROP_ssa)
3175 fprintf (dump, "PROP_ssa\n");
3176 if (props & PROP_no_crit_edges)
3177 fprintf (dump, "PROP_no_crit_edges\n");
3178 if (props & PROP_rtl)
3179 fprintf (dump, "PROP_rtl\n");
3180 if (props & PROP_gimple_lomp)
3181 fprintf (dump, "PROP_gimple_lomp\n");
3182 if (props & PROP_gimple_lomp_dev)
3183 fprintf (dump, "PROP_gimple_lomp_dev\n");
3184 if (props & PROP_gimple_lcx)
3185 fprintf (dump, "PROP_gimple_lcx\n");
3186 if (props & PROP_gimple_lvec)
3187 fprintf (dump, "PROP_gimple_lvec\n");
3188 if (props & PROP_cfglayout)
3189 fprintf (dump, "PROP_cfglayout\n");
3192 DEBUG_FUNCTION void
3193 debug_properties (unsigned int props)
3195 dump_properties (stderr, props);
3198 /* Called by local passes to see if function is called by already processed nodes.
3199 Because we process nodes in topological order, this means that function is
3200 in recursive cycle or we introduced new direct calls. */
3201 bool
3202 function_called_by_processed_nodes_p (void)
3204 struct cgraph_edge *e;
3205 for (e = cgraph_node::get (current_function_decl)->callers;
3207 e = e->next_caller)
3209 if (e->caller->decl == current_function_decl)
3210 continue;
3211 if (!e->caller->has_gimple_body_p ())
3212 continue;
3213 if (TREE_ASM_WRITTEN (e->caller->decl))
3214 continue;
3215 if (!e->caller->process && !e->caller->inlined_to)
3216 break;
3218 if (dump_file && e)
3220 fprintf (dump_file, "Already processed call to:\n");
3221 e->caller->dump (dump_file);
3223 return e != NULL;