Make std::vector<bool> meet C++11 allocator requirements.
[official-gcc.git] / gcc / passes.c
blobf9d15b89205d914b8bd22b9f446a061267195494
1 /* Top level of GCC compilers (cc1, cc1plus, etc.)
2 Copyright (C) 1987-2014 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 "tm.h"
29 #include "line-map.h"
30 #include "input.h"
31 #include "tree.h"
32 #include "varasm.h"
33 #include "rtl.h"
34 #include "tm_p.h"
35 #include "flags.h"
36 #include "insn-attr.h"
37 #include "insn-config.h"
38 #include "insn-flags.h"
39 #include "hard-reg-set.h"
40 #include "recog.h"
41 #include "output.h"
42 #include "except.h"
43 #include "hashtab.h"
44 #include "hash-set.h"
45 #include "vec.h"
46 #include "machmode.h"
47 #include "function.h"
48 #include "toplev.h"
49 #include "expr.h"
50 #include "predict.h"
51 #include "basic-block.h"
52 #include "intl.h"
53 #include "graph.h"
54 #include "regs.h"
55 #include "diagnostic-core.h"
56 #include "params.h"
57 #include "reload.h"
58 #include "debug.h"
59 #include "target.h"
60 #include "langhooks.h"
61 #include "cfgloop.h"
62 #include "hosthooks.h"
63 #include "opts.h"
64 #include "coverage.h"
65 #include "value-prof.h"
66 #include "tree-inline.h"
67 #include "tree-ssa-alias.h"
68 #include "internal-fn.h"
69 #include "gimple-expr.h"
70 #include "is-a.h"
71 #include "gimple.h"
72 #include "gimple-ssa.h"
73 #include "tree-cfg.h"
74 #include "stringpool.h"
75 #include "tree-ssanames.h"
76 #include "tree-ssa-loop-manip.h"
77 #include "tree-into-ssa.h"
78 #include "tree-dfa.h"
79 #include "tree-ssa.h"
80 #include "tree-pass.h"
81 #include "tree-dump.h"
82 #include "df.h"
83 #include "hash-map.h"
84 #include "plugin-api.h"
85 #include "ipa-ref.h"
86 #include "cgraph.h"
87 #include "lto-streamer.h"
88 #include "plugin.h"
89 #include "ipa-utils.h"
90 #include "tree-pretty-print.h" /* for dump_function_header */
91 #include "context.h"
92 #include "pass_manager.h"
93 #include "tree-ssa-live.h" /* For remove_unused_locals. */
94 #include "tree-cfgcleanup.h"
96 using namespace gcc;
98 /* This is used for debugging. It allows the current pass to printed
99 from anywhere in compilation.
100 The variable current_pass is also used for statistics and plugins. */
101 opt_pass *current_pass;
103 static void register_pass_name (opt_pass *, const char *);
105 /* Most passes are single-instance (within their context) and thus don't
106 need to implement cloning, but passes that support multiple instances
107 *must* provide their own implementation of the clone method.
109 Handle this by providing a default implemenation, but make it a fatal
110 error to call it. */
112 opt_pass *
113 opt_pass::clone ()
115 internal_error ("pass %s does not support cloning", name);
118 bool
119 opt_pass::gate (function *)
121 return true;
124 unsigned int
125 opt_pass::execute (function *)
127 return 0;
130 opt_pass::opt_pass (const pass_data &data, context *ctxt)
131 : pass_data (data),
132 sub (NULL),
133 next (NULL),
134 static_pass_number (0),
135 m_ctxt (ctxt)
140 void
141 pass_manager::execute_early_local_passes ()
143 execute_pass_list (cfun, pass_early_local_passes_1->sub);
146 unsigned int
147 pass_manager::execute_pass_mode_switching ()
149 return pass_mode_switching_1->execute (cfun);
153 /* Call from anywhere to find out what pass this is. Useful for
154 printing out debugging information deep inside an service
155 routine. */
156 void
157 print_current_pass (FILE *file)
159 if (current_pass)
160 fprintf (file, "current pass = %s (%d)\n",
161 current_pass->name, current_pass->static_pass_number);
162 else
163 fprintf (file, "no current pass.\n");
167 /* Call from the debugger to get the current pass name. */
168 DEBUG_FUNCTION void
169 debug_pass (void)
171 print_current_pass (stderr);
176 /* Global variables used to communicate with passes. */
177 bool in_gimple_form;
178 bool first_pass_instance;
181 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
182 and TYPE_DECL nodes.
184 This does nothing for local (non-static) variables, unless the
185 variable is a register variable with DECL_ASSEMBLER_NAME set. In
186 that case, or if the variable is not an automatic, it sets up the
187 RTL and outputs any assembler code (label definition, storage
188 allocation and initialization).
190 DECL is the declaration. TOP_LEVEL is nonzero
191 if this declaration is not within a function. */
193 void
194 rest_of_decl_compilation (tree decl,
195 int top_level,
196 int at_end)
198 bool finalize = true;
200 /* We deferred calling assemble_alias so that we could collect
201 other attributes such as visibility. Emit the alias now. */
202 if (!in_lto_p)
204 tree alias;
205 alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
206 if (alias)
208 alias = TREE_VALUE (TREE_VALUE (alias));
209 alias = get_identifier (TREE_STRING_POINTER (alias));
210 /* A quirk of the initial implementation of aliases required that the
211 user add "extern" to all of them. Which is silly, but now
212 historical. Do note that the symbol is in fact locally defined. */
213 DECL_EXTERNAL (decl) = 0;
214 TREE_STATIC (decl) = 1;
215 assemble_alias (decl, alias);
216 finalize = false;
220 /* Can't defer this, because it needs to happen before any
221 later function definitions are processed. */
222 if (DECL_ASSEMBLER_NAME_SET_P (decl) && DECL_REGISTER (decl))
223 make_decl_rtl (decl);
225 /* Forward declarations for nested functions are not "external",
226 but we need to treat them as if they were. */
227 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
228 || TREE_CODE (decl) == FUNCTION_DECL)
230 timevar_push (TV_VARCONST);
232 /* Don't output anything when a tentative file-scope definition
233 is seen. But at end of compilation, do output code for them.
235 We do output all variables and rely on
236 callgraph code to defer them except for forward declarations
237 (see gcc.c-torture/compile/920624-1.c) */
238 if ((at_end
239 || !DECL_DEFER_OUTPUT (decl)
240 || DECL_INITIAL (decl))
241 && (TREE_CODE (decl) != VAR_DECL || !DECL_HAS_VALUE_EXPR_P (decl))
242 && !DECL_EXTERNAL (decl))
244 /* When reading LTO unit, we also read varpool, so do not
245 rebuild it. */
246 if (in_lto_p && !at_end)
248 else if (finalize && TREE_CODE (decl) != FUNCTION_DECL)
249 varpool_node::finalize_decl (decl);
252 #ifdef ASM_FINISH_DECLARE_OBJECT
253 if (decl == last_assemble_variable_decl)
255 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
256 top_level, at_end);
258 #endif
260 timevar_pop (TV_VARCONST);
262 else if (TREE_CODE (decl) == TYPE_DECL
263 /* Like in rest_of_type_compilation, avoid confusing the debug
264 information machinery when there are errors. */
265 && !seen_error ())
267 timevar_push (TV_SYMOUT);
268 debug_hooks->type_decl (decl, !top_level);
269 timevar_pop (TV_SYMOUT);
272 /* Let cgraph know about the existence of variables. */
273 if (in_lto_p && !at_end)
275 else if (TREE_CODE (decl) == VAR_DECL && !DECL_EXTERNAL (decl)
276 && TREE_STATIC (decl))
277 varpool_node::get_create (decl);
280 /* Called after finishing a record, union or enumeral type. */
282 void
283 rest_of_type_compilation (tree type, int toplev)
285 /* Avoid confusing the debug information machinery when there are
286 errors. */
287 if (seen_error ())
288 return;
290 timevar_push (TV_SYMOUT);
291 debug_hooks->type_decl (TYPE_STUB_DECL (type), !toplev);
292 timevar_pop (TV_SYMOUT);
297 void
298 pass_manager::
299 finish_optimization_passes (void)
301 int i;
302 struct dump_file_info *dfi;
303 char *name;
304 gcc::dump_manager *dumps = m_ctxt->get_dumps ();
306 timevar_push (TV_DUMP);
307 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
309 dumps->dump_start (pass_profile_1->static_pass_number, NULL);
310 end_branch_prob ();
311 dumps->dump_finish (pass_profile_1->static_pass_number);
314 if (optimize > 0)
316 dumps->dump_start (pass_profile_1->static_pass_number, NULL);
317 print_combine_total_stats ();
318 dumps->dump_finish (pass_profile_1->static_pass_number);
321 /* Do whatever is necessary to finish printing the graphs. */
322 for (i = TDI_end; (dfi = dumps->get_dump_file_info (i)) != NULL; ++i)
323 if (dumps->dump_initialized_p (i)
324 && (dfi->pflags & TDF_GRAPH) != 0
325 && (name = dumps->get_dump_file_name (i)) != NULL)
327 finish_graph_dump_file (name);
328 free (name);
331 timevar_pop (TV_DUMP);
334 static unsigned int
335 execute_all_early_local_passes (void)
337 /* Once this pass (and its sub-passes) are complete, all functions
338 will be in SSA form. Technically this state change is happening
339 a tad early, since the sub-passes have not yet run, but since
340 none of the sub-passes are IPA passes and do not create new
341 functions, this is ok. We're setting this value for the benefit
342 of IPA passes that follow. */
343 if (symtab->state < IPA_SSA)
344 symtab->state = IPA_SSA;
345 return 0;
348 namespace {
350 const pass_data pass_data_early_local_passes =
352 SIMPLE_IPA_PASS, /* type */
353 "early_local_cleanups", /* name */
354 OPTGROUP_NONE, /* optinfo_flags */
355 TV_EARLY_LOCAL, /* tv_id */
356 0, /* properties_required */
357 0, /* properties_provided */
358 0, /* properties_destroyed */
359 0, /* todo_flags_start */
360 /* todo_flags_finish is executed before subpases. For this reason
361 it makes no sense to remove unreachable functions here. */
362 0, /* todo_flags_finish */
365 class pass_early_local_passes : public simple_ipa_opt_pass
367 public:
368 pass_early_local_passes (gcc::context *ctxt)
369 : simple_ipa_opt_pass (pass_data_early_local_passes, ctxt)
372 /* opt_pass methods: */
373 virtual bool gate (function *)
375 /* Don't bother doing anything if the program has errors. */
376 return (!seen_error () && !in_lto_p);
379 virtual unsigned int execute (function *)
381 return execute_all_early_local_passes ();
384 }; // class pass_early_local_passes
386 } // anon namespace
388 simple_ipa_opt_pass *
389 make_pass_early_local_passes (gcc::context *ctxt)
391 return new pass_early_local_passes (ctxt);
394 namespace {
396 const pass_data pass_data_all_early_optimizations =
398 GIMPLE_PASS, /* type */
399 "early_optimizations", /* name */
400 OPTGROUP_NONE, /* optinfo_flags */
401 TV_NONE, /* tv_id */
402 0, /* properties_required */
403 0, /* properties_provided */
404 0, /* properties_destroyed */
405 0, /* todo_flags_start */
406 0, /* todo_flags_finish */
409 class pass_all_early_optimizations : public gimple_opt_pass
411 public:
412 pass_all_early_optimizations (gcc::context *ctxt)
413 : gimple_opt_pass (pass_data_all_early_optimizations, ctxt)
416 /* opt_pass methods: */
417 virtual bool gate (function *)
419 return (optimize >= 1
420 /* Don't bother doing anything if the program has errors. */
421 && !seen_error ());
424 }; // class pass_all_early_optimizations
426 } // anon namespace
428 static gimple_opt_pass *
429 make_pass_all_early_optimizations (gcc::context *ctxt)
431 return new pass_all_early_optimizations (ctxt);
434 namespace {
436 const pass_data pass_data_all_optimizations =
438 GIMPLE_PASS, /* type */
439 "*all_optimizations", /* name */
440 OPTGROUP_NONE, /* optinfo_flags */
441 TV_OPTIMIZE, /* tv_id */
442 0, /* properties_required */
443 0, /* properties_provided */
444 0, /* properties_destroyed */
445 0, /* todo_flags_start */
446 0, /* todo_flags_finish */
449 class pass_all_optimizations : public gimple_opt_pass
451 public:
452 pass_all_optimizations (gcc::context *ctxt)
453 : gimple_opt_pass (pass_data_all_optimizations, ctxt)
456 /* opt_pass methods: */
457 virtual bool gate (function *) { return optimize >= 1 && !optimize_debug; }
459 }; // class pass_all_optimizations
461 } // anon namespace
463 static gimple_opt_pass *
464 make_pass_all_optimizations (gcc::context *ctxt)
466 return new pass_all_optimizations (ctxt);
469 namespace {
471 const pass_data pass_data_all_optimizations_g =
473 GIMPLE_PASS, /* type */
474 "*all_optimizations_g", /* name */
475 OPTGROUP_NONE, /* optinfo_flags */
476 TV_OPTIMIZE, /* tv_id */
477 0, /* properties_required */
478 0, /* properties_provided */
479 0, /* properties_destroyed */
480 0, /* todo_flags_start */
481 0, /* todo_flags_finish */
484 class pass_all_optimizations_g : public gimple_opt_pass
486 public:
487 pass_all_optimizations_g (gcc::context *ctxt)
488 : gimple_opt_pass (pass_data_all_optimizations_g, ctxt)
491 /* opt_pass methods: */
492 virtual bool gate (function *) { return optimize >= 1 && optimize_debug; }
494 }; // class pass_all_optimizations_g
496 } // anon namespace
498 static gimple_opt_pass *
499 make_pass_all_optimizations_g (gcc::context *ctxt)
501 return new pass_all_optimizations_g (ctxt);
504 namespace {
506 const pass_data pass_data_rest_of_compilation =
508 RTL_PASS, /* type */
509 "*rest_of_compilation", /* name */
510 OPTGROUP_NONE, /* optinfo_flags */
511 TV_REST_OF_COMPILATION, /* tv_id */
512 PROP_rtl, /* properties_required */
513 0, /* properties_provided */
514 0, /* properties_destroyed */
515 0, /* todo_flags_start */
516 0, /* todo_flags_finish */
519 class pass_rest_of_compilation : public rtl_opt_pass
521 public:
522 pass_rest_of_compilation (gcc::context *ctxt)
523 : rtl_opt_pass (pass_data_rest_of_compilation, ctxt)
526 /* opt_pass methods: */
527 virtual bool gate (function *)
529 /* Early return if there were errors. We can run afoul of our
530 consistency checks, and there's not really much point in fixing them. */
531 return !(rtl_dump_and_exit || flag_syntax_only || seen_error ());
534 }; // class pass_rest_of_compilation
536 } // anon namespace
538 static rtl_opt_pass *
539 make_pass_rest_of_compilation (gcc::context *ctxt)
541 return new pass_rest_of_compilation (ctxt);
544 namespace {
546 const pass_data pass_data_postreload =
548 RTL_PASS, /* type */
549 "*all-postreload", /* name */
550 OPTGROUP_NONE, /* optinfo_flags */
551 TV_POSTRELOAD, /* tv_id */
552 PROP_rtl, /* properties_required */
553 0, /* properties_provided */
554 0, /* properties_destroyed */
555 0, /* todo_flags_start */
556 0, /* todo_flags_finish */
559 class pass_postreload : public rtl_opt_pass
561 public:
562 pass_postreload (gcc::context *ctxt)
563 : rtl_opt_pass (pass_data_postreload, ctxt)
566 /* opt_pass methods: */
567 virtual bool gate (function *) { return reload_completed; }
569 }; // class pass_postreload
571 } // anon namespace
573 static rtl_opt_pass *
574 make_pass_postreload (gcc::context *ctxt)
576 return new pass_postreload (ctxt);
581 /* Set the static pass number of pass PASS to ID and record that
582 in the mapping from static pass number to pass. */
584 void
585 pass_manager::
586 set_pass_for_id (int id, opt_pass *pass)
588 pass->static_pass_number = id;
589 if (passes_by_id_size <= id)
591 passes_by_id = XRESIZEVEC (opt_pass *, passes_by_id, id + 1);
592 memset (passes_by_id + passes_by_id_size, 0,
593 (id + 1 - passes_by_id_size) * sizeof (void *));
594 passes_by_id_size = id + 1;
596 passes_by_id[id] = pass;
599 /* Return the pass with the static pass number ID. */
601 opt_pass *
602 pass_manager::get_pass_for_id (int id) const
604 if (id >= passes_by_id_size)
605 return NULL;
606 return passes_by_id[id];
609 /* Iterate over the pass tree allocating dump file numbers. We want
610 to do this depth first, and independent of whether the pass is
611 enabled or not. */
613 void
614 register_one_dump_file (opt_pass *pass)
616 g->get_passes ()->register_one_dump_file (pass);
619 void
620 pass_manager::register_one_dump_file (opt_pass *pass)
622 char *dot_name, *flag_name, *glob_name;
623 const char *name, *full_name, *prefix;
624 char num[10];
625 int flags, id;
626 int optgroup_flags = OPTGROUP_NONE;
627 gcc::dump_manager *dumps = m_ctxt->get_dumps ();
629 /* See below in next_pass_1. */
630 num[0] = '\0';
631 if (pass->static_pass_number != -1)
632 sprintf (num, "%d", ((int) pass->static_pass_number < 0
633 ? 1 : pass->static_pass_number));
635 /* The name is both used to identify the pass for the purposes of plugins,
636 and to specify dump file name and option.
637 The latter two might want something short which is not quite unique; for
638 that reason, we may have a disambiguating prefix, followed by a space
639 to mark the start of the following dump file name / option string. */
640 name = strchr (pass->name, ' ');
641 name = name ? name + 1 : pass->name;
642 dot_name = concat (".", name, num, NULL);
643 if (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS)
645 prefix = "ipa-";
646 flags = TDF_IPA;
647 optgroup_flags |= OPTGROUP_IPA;
649 else if (pass->type == GIMPLE_PASS)
651 prefix = "tree-";
652 flags = TDF_TREE;
654 else
656 prefix = "rtl-";
657 flags = TDF_RTL;
660 flag_name = concat (prefix, name, num, NULL);
661 glob_name = concat (prefix, name, NULL);
662 optgroup_flags |= pass->optinfo_flags;
663 /* For any passes that do not have an optgroup set, and which are not
664 IPA passes setup above, set the optgroup to OPTGROUP_OTHER so that
665 any dump messages are emitted properly under -fopt-info(-optall). */
666 if (optgroup_flags == OPTGROUP_NONE)
667 optgroup_flags = OPTGROUP_OTHER;
668 id = dumps->dump_register (dot_name, flag_name, glob_name, flags,
669 optgroup_flags);
670 set_pass_for_id (id, pass);
671 full_name = concat (prefix, pass->name, num, NULL);
672 register_pass_name (pass, full_name);
673 free (CONST_CAST (char *, full_name));
676 /* Register the dump files for the pass_manager starting at PASS. */
678 void
679 pass_manager::register_dump_files (opt_pass *pass)
683 if (pass->name && pass->name[0] != '*')
684 register_one_dump_file (pass);
686 if (pass->sub)
687 register_dump_files (pass->sub);
689 pass = pass->next;
691 while (pass);
694 /* Helper for pass_registry hash table. */
696 struct pass_registry_hasher : default_hashmap_traits
698 static inline hashval_t hash (const char *);
699 static inline bool equal_keys (const char *, const char *);
702 /* Pass registry hash function. */
704 inline hashval_t
705 pass_registry_hasher::hash (const char *name)
707 return htab_hash_string (name);
710 /* Hash equal function */
712 inline bool
713 pass_registry_hasher::equal_keys (const char *s1, const char *s2)
715 return !strcmp (s1, s2);
718 static hash_map<const char *, opt_pass *, pass_registry_hasher>
719 *name_to_pass_map;
721 /* Register PASS with NAME. */
723 static void
724 register_pass_name (opt_pass *pass, const char *name)
726 if (!name_to_pass_map)
727 name_to_pass_map
728 = new hash_map<const char *, opt_pass *, pass_registry_hasher> (256);
730 if (name_to_pass_map->get (name))
731 return; /* Ignore plugin passes. */
733 const char *unique_name = xstrdup (name);
734 name_to_pass_map->put (unique_name, pass);
737 /* Map from pass id to canonicalized pass name. */
739 typedef const char *char_ptr;
740 static vec<char_ptr> pass_tab = vNULL;
742 /* Callback function for traversing NAME_TO_PASS_MAP. */
744 bool
745 passes_pass_traverse (const char *const &name, opt_pass *const &pass, void *)
747 gcc_assert (pass->static_pass_number > 0);
748 gcc_assert (pass_tab.exists ());
750 pass_tab[pass->static_pass_number] = name;
752 return 1;
755 /* The function traverses NAME_TO_PASS_MAP and creates a pass info
756 table for dumping purpose. */
758 static void
759 create_pass_tab (void)
761 if (!flag_dump_passes)
762 return;
764 pass_tab.safe_grow_cleared (g->get_passes ()->passes_by_id_size + 1);
765 name_to_pass_map->traverse <void *, passes_pass_traverse> (NULL);
768 static bool override_gate_status (opt_pass *, tree, bool);
770 /* Dump the instantiated name for PASS. IS_ON indicates if PASS
771 is turned on or not. */
773 static void
774 dump_one_pass (opt_pass *pass, int pass_indent)
776 int indent = 3 * pass_indent;
777 const char *pn;
778 bool is_on, is_really_on;
780 is_on = pass->gate (cfun);
781 is_really_on = override_gate_status (pass, current_function_decl, is_on);
783 if (pass->static_pass_number <= 0)
784 pn = pass->name;
785 else
786 pn = pass_tab[pass->static_pass_number];
788 fprintf (stderr, "%*s%-40s%*s:%s%s\n", indent, " ", pn,
789 (15 - indent < 0 ? 0 : 15 - indent), " ",
790 is_on ? " ON" : " OFF",
791 ((!is_on) == (!is_really_on) ? ""
792 : (is_really_on ? " (FORCED_ON)" : " (FORCED_OFF)")));
795 /* Dump pass list PASS with indentation INDENT. */
797 static void
798 dump_pass_list (opt_pass *pass, int indent)
802 dump_one_pass (pass, indent);
803 if (pass->sub)
804 dump_pass_list (pass->sub, indent + 1);
805 pass = pass->next;
807 while (pass);
810 /* Dump all optimization passes. */
812 void
813 dump_passes (void)
815 g->get_passes ()->dump_passes ();
818 void
819 pass_manager::dump_passes () const
821 struct cgraph_node *n, *node = NULL;
823 create_pass_tab ();
825 FOR_EACH_FUNCTION (n)
826 if (DECL_STRUCT_FUNCTION (n->decl))
828 node = n;
829 break;
832 if (!node)
833 return;
835 push_cfun (DECL_STRUCT_FUNCTION (node->decl));
837 dump_pass_list (all_lowering_passes, 1);
838 dump_pass_list (all_small_ipa_passes, 1);
839 dump_pass_list (all_regular_ipa_passes, 1);
840 dump_pass_list (all_late_ipa_passes, 1);
841 dump_pass_list (all_passes, 1);
843 pop_cfun ();
847 /* Returns the pass with NAME. */
849 static opt_pass *
850 get_pass_by_name (const char *name)
852 opt_pass **p = name_to_pass_map->get (name);
853 if (p)
854 return *p;
856 return NULL;
860 /* Range [start, last]. */
862 struct uid_range
864 unsigned int start;
865 unsigned int last;
866 const char *assem_name;
867 struct uid_range *next;
870 typedef struct uid_range *uid_range_p;
873 static vec<uid_range_p>
874 enabled_pass_uid_range_tab = vNULL;
875 static vec<uid_range_p>
876 disabled_pass_uid_range_tab = vNULL;
879 /* Parse option string for -fdisable- and -fenable-
880 The syntax of the options:
882 -fenable-<pass_name>
883 -fdisable-<pass_name>
885 -fenable-<pass_name>=s1:e1,s2:e2,...
886 -fdisable-<pass_name>=s1:e1,s2:e2,...
889 static void
890 enable_disable_pass (const char *arg, bool is_enable)
892 opt_pass *pass;
893 char *range_str, *phase_name;
894 char *argstr = xstrdup (arg);
895 vec<uid_range_p> *tab = 0;
897 range_str = strchr (argstr,'=');
898 if (range_str)
900 *range_str = '\0';
901 range_str++;
904 phase_name = argstr;
905 if (!*phase_name)
907 if (is_enable)
908 error ("unrecognized option -fenable");
909 else
910 error ("unrecognized option -fdisable");
911 free (argstr);
912 return;
914 pass = get_pass_by_name (phase_name);
915 if (!pass || pass->static_pass_number == -1)
917 if (is_enable)
918 error ("unknown pass %s specified in -fenable", phase_name);
919 else
920 error ("unknown pass %s specified in -fdisable", phase_name);
921 free (argstr);
922 return;
925 if (is_enable)
926 tab = &enabled_pass_uid_range_tab;
927 else
928 tab = &disabled_pass_uid_range_tab;
930 if ((unsigned) pass->static_pass_number >= tab->length ())
931 tab->safe_grow_cleared (pass->static_pass_number + 1);
933 if (!range_str)
935 uid_range_p slot;
936 uid_range_p new_range = XCNEW (struct uid_range);
938 new_range->start = 0;
939 new_range->last = (unsigned)-1;
941 slot = (*tab)[pass->static_pass_number];
942 new_range->next = slot;
943 (*tab)[pass->static_pass_number] = new_range;
944 if (is_enable)
945 inform (UNKNOWN_LOCATION, "enable pass %s for functions in the range "
946 "of [%u, %u]", phase_name, new_range->start, new_range->last);
947 else
948 inform (UNKNOWN_LOCATION, "disable pass %s for functions in the range "
949 "of [%u, %u]", phase_name, new_range->start, new_range->last);
951 else
953 char *next_range = NULL;
954 char *one_range = range_str;
955 char *end_val = NULL;
959 uid_range_p slot;
960 uid_range_p new_range;
961 char *invalid = NULL;
962 long start;
963 char *func_name = NULL;
965 next_range = strchr (one_range, ',');
966 if (next_range)
968 *next_range = '\0';
969 next_range++;
972 end_val = strchr (one_range, ':');
973 if (end_val)
975 *end_val = '\0';
976 end_val++;
978 start = strtol (one_range, &invalid, 10);
979 if (*invalid || start < 0)
981 if (end_val || (one_range[0] >= '0'
982 && one_range[0] <= '9'))
984 error ("Invalid range %s in option %s",
985 one_range,
986 is_enable ? "-fenable" : "-fdisable");
987 free (argstr);
988 return;
990 func_name = one_range;
992 if (!end_val)
994 new_range = XCNEW (struct uid_range);
995 if (!func_name)
997 new_range->start = (unsigned) start;
998 new_range->last = (unsigned) start;
1000 else
1002 new_range->start = (unsigned) -1;
1003 new_range->last = (unsigned) -1;
1004 new_range->assem_name = xstrdup (func_name);
1007 else
1009 long last = strtol (end_val, &invalid, 10);
1010 if (*invalid || last < start)
1012 error ("Invalid range %s in option %s",
1013 end_val,
1014 is_enable ? "-fenable" : "-fdisable");
1015 free (argstr);
1016 return;
1018 new_range = XCNEW (struct uid_range);
1019 new_range->start = (unsigned) start;
1020 new_range->last = (unsigned) last;
1023 slot = (*tab)[pass->static_pass_number];
1024 new_range->next = slot;
1025 (*tab)[pass->static_pass_number] = new_range;
1026 if (is_enable)
1028 if (new_range->assem_name)
1029 inform (UNKNOWN_LOCATION,
1030 "enable pass %s for function %s",
1031 phase_name, new_range->assem_name);
1032 else
1033 inform (UNKNOWN_LOCATION,
1034 "enable pass %s for functions in the range of [%u, %u]",
1035 phase_name, new_range->start, new_range->last);
1037 else
1039 if (new_range->assem_name)
1040 inform (UNKNOWN_LOCATION,
1041 "disable pass %s for function %s",
1042 phase_name, new_range->assem_name);
1043 else
1044 inform (UNKNOWN_LOCATION,
1045 "disable pass %s for functions in the range of [%u, %u]",
1046 phase_name, new_range->start, new_range->last);
1049 one_range = next_range;
1050 } while (next_range);
1053 free (argstr);
1056 /* Enable pass specified by ARG. */
1058 void
1059 enable_pass (const char *arg)
1061 enable_disable_pass (arg, true);
1064 /* Disable pass specified by ARG. */
1066 void
1067 disable_pass (const char *arg)
1069 enable_disable_pass (arg, false);
1072 /* Returns true if PASS is explicitly enabled/disabled for FUNC. */
1074 static bool
1075 is_pass_explicitly_enabled_or_disabled (opt_pass *pass,
1076 tree func,
1077 vec<uid_range_p> tab)
1079 uid_range_p slot, range;
1080 int cgraph_uid;
1081 const char *aname = NULL;
1083 if (!tab.exists ()
1084 || (unsigned) pass->static_pass_number >= tab.length ()
1085 || pass->static_pass_number == -1)
1086 return false;
1088 slot = tab[pass->static_pass_number];
1089 if (!slot)
1090 return false;
1092 cgraph_uid = func ? cgraph_node::get (func)->uid : 0;
1093 if (func && DECL_ASSEMBLER_NAME_SET_P (func))
1094 aname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func));
1096 range = slot;
1097 while (range)
1099 if ((unsigned) cgraph_uid >= range->start
1100 && (unsigned) cgraph_uid <= range->last)
1101 return true;
1102 if (range->assem_name && aname
1103 && !strcmp (range->assem_name, aname))
1104 return true;
1105 range = range->next;
1108 return false;
1112 /* Update static_pass_number for passes (and the flag
1113 TODO_mark_first_instance).
1115 Passes are constructed with static_pass_number preinitialized to 0
1117 This field is used in two different ways: initially as instance numbers
1118 of their kind, and then as ids within the entire pass manager.
1120 Within pass_manager::pass_manager:
1122 * In add_pass_instance(), as called by next_pass_1 in
1123 NEXT_PASS in init_optimization_passes
1125 * When the initial instance of a pass within a pass manager is seen,
1126 it is flagged, and its static_pass_number is set to -1
1128 * On subsequent times that it is seen, the static pass number
1129 is decremented each time, so that if there are e.g. 4 dups,
1130 they have static_pass_number -4, 2, 3, 4 respectively (note
1131 how the initial one is negative and gives the count); these
1132 can be thought of as instance numbers of the specific pass
1134 * Within the register_dump_files () traversal, set_pass_for_id()
1135 is called on each pass, using these instance numbers to create
1136 dumpfile switches, and then overwriting them with a pass id,
1137 which are global to the whole pass manager (based on
1138 (TDI_end + current value of extra_dump_files_in_use) ) */
1140 static void
1141 add_pass_instance (opt_pass *new_pass, bool track_duplicates,
1142 opt_pass *initial_pass)
1144 /* Are we dealing with the first pass of its kind, or a clone? */
1145 if (new_pass != initial_pass)
1147 /* We're dealing with a clone. */
1148 new_pass->todo_flags_start &= ~TODO_mark_first_instance;
1150 /* Indicate to register_dump_files that this pass has duplicates,
1151 and so it should rename the dump file. The first instance will
1152 be -1, and be number of duplicates = -static_pass_number - 1.
1153 Subsequent instances will be > 0 and just the duplicate number. */
1154 if ((new_pass->name && new_pass->name[0] != '*') || track_duplicates)
1156 initial_pass->static_pass_number -= 1;
1157 new_pass->static_pass_number = -initial_pass->static_pass_number;
1160 else
1162 /* We're dealing with the first pass of its kind. */
1163 new_pass->todo_flags_start |= TODO_mark_first_instance;
1164 new_pass->static_pass_number = -1;
1166 invoke_plugin_callbacks (PLUGIN_NEW_PASS, new_pass);
1170 /* Add a pass to the pass list. Duplicate the pass if it's already
1171 in the list. */
1173 static opt_pass **
1174 next_pass_1 (opt_pass **list, opt_pass *pass, opt_pass *initial_pass)
1176 /* Every pass should have a name so that plugins can refer to them. */
1177 gcc_assert (pass->name != NULL);
1179 add_pass_instance (pass, false, initial_pass);
1180 *list = pass;
1182 return &(*list)->next;
1185 /* List node for an inserted pass instance. We need to keep track of all
1186 the newly-added pass instances (with 'added_pass_nodes' defined below)
1187 so that we can register their dump files after pass-positioning is finished.
1188 Registering dumping files needs to be post-processed or the
1189 static_pass_number of the opt_pass object would be modified and mess up
1190 the dump file names of future pass instances to be added. */
1192 struct pass_list_node
1194 opt_pass *pass;
1195 struct pass_list_node *next;
1198 static struct pass_list_node *added_pass_nodes = NULL;
1199 static struct pass_list_node *prev_added_pass_node;
1201 /* Insert the pass at the proper position. Return true if the pass
1202 is successfully added.
1204 NEW_PASS_INFO - new pass to be inserted
1205 PASS_LIST - root of the pass list to insert the new pass to */
1207 static bool
1208 position_pass (struct register_pass_info *new_pass_info, opt_pass **pass_list)
1210 opt_pass *pass = *pass_list, *prev_pass = NULL;
1211 bool success = false;
1213 for ( ; pass; prev_pass = pass, pass = pass->next)
1215 /* Check if the current pass is of the same type as the new pass and
1216 matches the name and the instance number of the reference pass. */
1217 if (pass->type == new_pass_info->pass->type
1218 && pass->name
1219 && !strcmp (pass->name, new_pass_info->reference_pass_name)
1220 && ((new_pass_info->ref_pass_instance_number == 0)
1221 || (new_pass_info->ref_pass_instance_number ==
1222 pass->static_pass_number)
1223 || (new_pass_info->ref_pass_instance_number == 1
1224 && pass->todo_flags_start & TODO_mark_first_instance)))
1226 opt_pass *new_pass;
1227 struct pass_list_node *new_pass_node;
1229 if (new_pass_info->ref_pass_instance_number == 0)
1231 new_pass = new_pass_info->pass->clone ();
1232 add_pass_instance (new_pass, true, new_pass_info->pass);
1234 else
1236 new_pass = new_pass_info->pass;
1237 add_pass_instance (new_pass, true, new_pass);
1240 /* Insert the new pass instance based on the positioning op. */
1241 switch (new_pass_info->pos_op)
1243 case PASS_POS_INSERT_AFTER:
1244 new_pass->next = pass->next;
1245 pass->next = new_pass;
1247 /* Skip newly inserted pass to avoid repeated
1248 insertions in the case where the new pass and the
1249 existing one have the same name. */
1250 pass = new_pass;
1251 break;
1252 case PASS_POS_INSERT_BEFORE:
1253 new_pass->next = pass;
1254 if (prev_pass)
1255 prev_pass->next = new_pass;
1256 else
1257 *pass_list = new_pass;
1258 break;
1259 case PASS_POS_REPLACE:
1260 new_pass->next = pass->next;
1261 if (prev_pass)
1262 prev_pass->next = new_pass;
1263 else
1264 *pass_list = new_pass;
1265 new_pass->sub = pass->sub;
1266 new_pass->tv_id = pass->tv_id;
1267 pass = new_pass;
1268 break;
1269 default:
1270 error ("invalid pass positioning operation");
1271 return false;
1274 /* Save the newly added pass (instance) in the added_pass_nodes
1275 list so that we can register its dump file later. Note that
1276 we cannot register the dump file now because doing so will modify
1277 the static_pass_number of the opt_pass object and therefore
1278 mess up the dump file name of future instances. */
1279 new_pass_node = XCNEW (struct pass_list_node);
1280 new_pass_node->pass = new_pass;
1281 if (!added_pass_nodes)
1282 added_pass_nodes = new_pass_node;
1283 else
1284 prev_added_pass_node->next = new_pass_node;
1285 prev_added_pass_node = new_pass_node;
1287 success = true;
1290 if (pass->sub && position_pass (new_pass_info, &pass->sub))
1291 success = true;
1294 return success;
1297 /* Hooks a new pass into the pass lists.
1299 PASS_INFO - pass information that specifies the opt_pass object,
1300 reference pass, instance number, and how to position
1301 the pass */
1303 void
1304 register_pass (struct register_pass_info *pass_info)
1306 g->get_passes ()->register_pass (pass_info);
1309 void
1310 register_pass (opt_pass* pass, pass_positioning_ops pos,
1311 const char* ref_pass_name, int ref_pass_inst_number)
1313 register_pass_info i;
1314 i.pass = pass;
1315 i.reference_pass_name = ref_pass_name;
1316 i.ref_pass_instance_number = ref_pass_inst_number;
1317 i.pos_op = pos;
1319 g->get_passes ()->register_pass (&i);
1322 void
1323 pass_manager::register_pass (struct register_pass_info *pass_info)
1325 bool all_instances, success;
1326 gcc::dump_manager *dumps = m_ctxt->get_dumps ();
1328 /* The checks below could fail in buggy plugins. Existing GCC
1329 passes should never fail these checks, so we mention plugin in
1330 the messages. */
1331 if (!pass_info->pass)
1332 fatal_error ("plugin cannot register a missing pass");
1334 if (!pass_info->pass->name)
1335 fatal_error ("plugin cannot register an unnamed pass");
1337 if (!pass_info->reference_pass_name)
1338 fatal_error
1339 ("plugin cannot register pass %qs without reference pass name",
1340 pass_info->pass->name);
1342 /* Try to insert the new pass to the pass lists. We need to check
1343 all five lists as the reference pass could be in one (or all) of
1344 them. */
1345 all_instances = pass_info->ref_pass_instance_number == 0;
1346 success = position_pass (pass_info, &all_lowering_passes);
1347 if (!success || all_instances)
1348 success |= position_pass (pass_info, &all_small_ipa_passes);
1349 if (!success || all_instances)
1350 success |= position_pass (pass_info, &all_regular_ipa_passes);
1351 if (!success || all_instances)
1352 success |= position_pass (pass_info, &all_late_ipa_passes);
1353 if (!success || all_instances)
1354 success |= position_pass (pass_info, &all_passes);
1355 if (!success)
1356 fatal_error
1357 ("pass %qs not found but is referenced by new pass %qs",
1358 pass_info->reference_pass_name, pass_info->pass->name);
1360 /* OK, we have successfully inserted the new pass. We need to register
1361 the dump files for the newly added pass and its duplicates (if any).
1362 Because the registration of plugin/backend passes happens after the
1363 command-line options are parsed, the options that specify single
1364 pass dumping (e.g. -fdump-tree-PASSNAME) cannot be used for new
1365 passes. Therefore we currently can only enable dumping of
1366 new passes when the 'dump-all' flags (e.g. -fdump-tree-all)
1367 are specified. While doing so, we also delete the pass_list_node
1368 objects created during pass positioning. */
1369 while (added_pass_nodes)
1371 struct pass_list_node *next_node = added_pass_nodes->next;
1372 enum tree_dump_index tdi;
1373 register_one_dump_file (added_pass_nodes->pass);
1374 if (added_pass_nodes->pass->type == SIMPLE_IPA_PASS
1375 || added_pass_nodes->pass->type == IPA_PASS)
1376 tdi = TDI_ipa_all;
1377 else if (added_pass_nodes->pass->type == GIMPLE_PASS)
1378 tdi = TDI_tree_all;
1379 else
1380 tdi = TDI_rtl_all;
1381 /* Check if dump-all flag is specified. */
1382 if (dumps->get_dump_file_info (tdi)->pstate)
1383 dumps->get_dump_file_info (added_pass_nodes->pass->static_pass_number)
1384 ->pstate = dumps->get_dump_file_info (tdi)->pstate;
1385 XDELETE (added_pass_nodes);
1386 added_pass_nodes = next_node;
1390 /* Construct the pass tree. The sequencing of passes is driven by
1391 the cgraph routines:
1393 finalize_compilation_unit ()
1394 for each node N in the cgraph
1395 cgraph_analyze_function (N)
1396 cgraph_lower_function (N) -> all_lowering_passes
1398 If we are optimizing, compile is then invoked:
1400 compile ()
1401 ipa_passes () -> all_small_ipa_passes
1402 -> Analysis of all_regular_ipa_passes
1403 * possible LTO streaming at copmilation time *
1404 -> Execution of all_regular_ipa_passes
1405 * possible LTO streaming at link time *
1406 -> all_late_ipa_passes
1407 expand_all_functions ()
1408 for each node N in the cgraph
1409 expand_function (N) -> Transformation of all_regular_ipa_passes
1410 -> all_passes
1413 void *
1414 pass_manager::operator new (size_t sz)
1416 /* Ensure that all fields of the pass manager are zero-initialized. */
1417 return xcalloc (1, sz);
1420 pass_manager::pass_manager (context *ctxt)
1421 : all_passes (NULL), all_small_ipa_passes (NULL), all_lowering_passes (NULL),
1422 all_regular_ipa_passes (NULL),
1423 all_late_ipa_passes (NULL), passes_by_id (NULL), passes_by_id_size (0),
1424 m_ctxt (ctxt)
1426 opt_pass **p;
1428 /* Initialize the pass_lists array. */
1429 #define DEF_PASS_LIST(LIST) pass_lists[PASS_LIST_NO_##LIST] = &LIST;
1430 GCC_PASS_LISTS
1431 #undef DEF_PASS_LIST
1433 /* Build the tree of passes. */
1435 #define INSERT_PASSES_AFTER(PASS) \
1436 p = &(PASS);
1438 #define PUSH_INSERT_PASSES_WITHIN(PASS) \
1440 opt_pass **p = &(PASS ## _1)->sub;
1442 #define POP_INSERT_PASSES() \
1445 #define NEXT_PASS(PASS, NUM) \
1446 do { \
1447 gcc_assert (NULL == PASS ## _ ## NUM); \
1448 if ((NUM) == 1) \
1449 PASS ## _1 = make_##PASS (m_ctxt); \
1450 else \
1452 gcc_assert (PASS ## _1); \
1453 PASS ## _ ## NUM = PASS ## _1->clone (); \
1455 p = next_pass_1 (p, PASS ## _ ## NUM, PASS ## _1); \
1456 } while (0)
1458 #define TERMINATE_PASS_LIST() \
1459 *p = NULL;
1461 #include "pass-instances.def"
1463 #undef INSERT_PASSES_AFTER
1464 #undef PUSH_INSERT_PASSES_WITHIN
1465 #undef POP_INSERT_PASSES
1466 #undef NEXT_PASS
1467 #undef TERMINATE_PASS_LIST
1469 /* Register the passes with the tree dump code. */
1470 register_dump_files (all_lowering_passes);
1471 register_dump_files (all_small_ipa_passes);
1472 register_dump_files (all_regular_ipa_passes);
1473 register_dump_files (all_late_ipa_passes);
1474 register_dump_files (all_passes);
1477 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1478 function CALLBACK for every function in the call graph. Otherwise,
1479 call CALLBACK on the current function. */
1481 static void
1482 do_per_function (void (*callback) (function *, void *data), void *data)
1484 if (current_function_decl)
1485 callback (cfun, data);
1486 else
1488 struct cgraph_node *node;
1489 FOR_EACH_DEFINED_FUNCTION (node)
1490 if (node->analyzed && (gimple_has_body_p (node->decl) && !in_lto_p)
1491 && (!node->clone_of || node->decl != node->clone_of->decl))
1492 callback (DECL_STRUCT_FUNCTION (node->decl), data);
1496 /* Because inlining might remove no-longer reachable nodes, we need to
1497 keep the array visible to garbage collector to avoid reading collected
1498 out nodes. */
1499 static int nnodes;
1500 static GTY ((length ("nnodes"))) cgraph_node **order;
1502 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1503 function CALLBACK for every function in the call graph. Otherwise,
1504 call CALLBACK on the current function.
1505 This function is global so that plugins can use it. */
1506 void
1507 do_per_function_toporder (void (*callback) (function *, void *data), void *data)
1509 int i;
1511 if (current_function_decl)
1512 callback (cfun, data);
1513 else
1515 gcc_assert (!order);
1516 order = ggc_vec_alloc<cgraph_node *> (symtab->cgraph_count);
1517 nnodes = ipa_reverse_postorder (order);
1518 for (i = nnodes - 1; i >= 0; i--)
1519 order[i]->process = 1;
1520 for (i = nnodes - 1; i >= 0; i--)
1522 struct cgraph_node *node = order[i];
1524 /* Allow possibly removed nodes to be garbage collected. */
1525 order[i] = NULL;
1526 node->process = 0;
1527 if (node->has_gimple_body_p ())
1528 callback (DECL_STRUCT_FUNCTION (node->decl), data);
1531 ggc_free (order);
1532 order = NULL;
1533 nnodes = 0;
1536 /* Helper function to perform function body dump. */
1538 static void
1539 execute_function_dump (function *fn, void *data)
1541 opt_pass *pass = (opt_pass *)data;
1543 if (dump_file)
1545 push_cfun (fn);
1547 if (fn->curr_properties & PROP_trees)
1548 dump_function_to_file (fn->decl, dump_file, dump_flags);
1549 else
1550 print_rtl_with_bb (dump_file, get_insns (), dump_flags);
1552 /* Flush the file. If verification fails, we won't be able to
1553 close the file before aborting. */
1554 fflush (dump_file);
1556 if ((fn->curr_properties & PROP_cfg)
1557 && (dump_flags & TDF_GRAPH))
1559 if (!pass->graph_dump_initialized)
1561 clean_graph_dump_file (dump_file_name);
1562 pass->graph_dump_initialized = true;
1564 print_graph_cfg (dump_file_name, fn);
1567 pop_cfun ();
1571 static struct profile_record *profile_record;
1573 /* Do profile consistency book-keeping for the pass with static number INDEX.
1574 If SUBPASS is zero, we run _before_ the pass, and if SUBPASS is one, then
1575 we run _after_ the pass. RUN is true if the pass really runs, or FALSE
1576 if we are only book-keeping on passes that may have selectively disabled
1577 themselves on a given function. */
1578 static void
1579 check_profile_consistency (int index, int subpass, bool run)
1581 pass_manager *passes = g->get_passes ();
1582 if (index == -1)
1583 return;
1584 if (!profile_record)
1585 profile_record = XCNEWVEC (struct profile_record,
1586 passes->passes_by_id_size);
1587 gcc_assert (index < passes->passes_by_id_size && index >= 0);
1588 gcc_assert (subpass < 2);
1589 profile_record[index].run |= run;
1590 account_profile_record (&profile_record[index], subpass);
1593 /* Output profile consistency. */
1595 void
1596 dump_profile_report (void)
1598 g->get_passes ()->dump_profile_report ();
1601 void
1602 pass_manager::dump_profile_report () const
1604 int i, j;
1605 int last_freq_in = 0, last_count_in = 0, last_freq_out = 0, last_count_out = 0;
1606 gcov_type last_time = 0, last_size = 0;
1607 double rel_time_change, rel_size_change;
1608 int last_reported = 0;
1610 if (!profile_record)
1611 return;
1612 fprintf (stderr, "\nProfile consistency report:\n\n");
1613 fprintf (stderr, "Pass name |mismatch in |mismated out|Overall\n");
1614 fprintf (stderr, " |freq count |freq count |size time\n");
1616 for (i = 0; i < passes_by_id_size; i++)
1617 for (j = 0 ; j < 2; j++)
1618 if (profile_record[i].run)
1620 if (last_time)
1621 rel_time_change = (profile_record[i].time[j]
1622 - (double)last_time) * 100 / (double)last_time;
1623 else
1624 rel_time_change = 0;
1625 if (last_size)
1626 rel_size_change = (profile_record[i].size[j]
1627 - (double)last_size) * 100 / (double)last_size;
1628 else
1629 rel_size_change = 0;
1631 if (profile_record[i].num_mismatched_freq_in[j] != last_freq_in
1632 || profile_record[i].num_mismatched_freq_out[j] != last_freq_out
1633 || profile_record[i].num_mismatched_count_in[j] != last_count_in
1634 || profile_record[i].num_mismatched_count_out[j] != last_count_out
1635 || rel_time_change || rel_size_change)
1637 last_reported = i;
1638 fprintf (stderr, "%-20s %s",
1639 passes_by_id [i]->name,
1640 j ? "(after TODO)" : " ");
1641 if (profile_record[i].num_mismatched_freq_in[j] != last_freq_in)
1642 fprintf (stderr, "| %+5i",
1643 profile_record[i].num_mismatched_freq_in[j]
1644 - last_freq_in);
1645 else
1646 fprintf (stderr, "| ");
1647 if (profile_record[i].num_mismatched_count_in[j] != last_count_in)
1648 fprintf (stderr, " %+5i",
1649 profile_record[i].num_mismatched_count_in[j]
1650 - last_count_in);
1651 else
1652 fprintf (stderr, " ");
1653 if (profile_record[i].num_mismatched_freq_out[j] != last_freq_out)
1654 fprintf (stderr, "| %+5i",
1655 profile_record[i].num_mismatched_freq_out[j]
1656 - last_freq_out);
1657 else
1658 fprintf (stderr, "| ");
1659 if (profile_record[i].num_mismatched_count_out[j] != last_count_out)
1660 fprintf (stderr, " %+5i",
1661 profile_record[i].num_mismatched_count_out[j]
1662 - last_count_out);
1663 else
1664 fprintf (stderr, " ");
1666 /* Size/time units change across gimple and RTL. */
1667 if (i == pass_expand_1->static_pass_number)
1668 fprintf (stderr, "|----------");
1669 else
1671 if (rel_size_change)
1672 fprintf (stderr, "| %+8.4f%%", rel_size_change);
1673 else
1674 fprintf (stderr, "| ");
1675 if (rel_time_change)
1676 fprintf (stderr, " %+8.4f%%", rel_time_change);
1678 fprintf (stderr, "\n");
1679 last_freq_in = profile_record[i].num_mismatched_freq_in[j];
1680 last_freq_out = profile_record[i].num_mismatched_freq_out[j];
1681 last_count_in = profile_record[i].num_mismatched_count_in[j];
1682 last_count_out = profile_record[i].num_mismatched_count_out[j];
1684 else if (j && last_reported != i)
1686 last_reported = i;
1687 fprintf (stderr, "%-20s ------------| | |\n",
1688 passes_by_id [i]->name);
1690 last_time = profile_record[i].time[j];
1691 last_size = profile_record[i].size[j];
1695 /* Perform all TODO actions that ought to be done on each function. */
1697 static void
1698 execute_function_todo (function *fn, void *data)
1700 bool from_ipa_pass = (cfun == NULL);
1701 unsigned int flags = (size_t)data;
1702 flags &= ~fn->last_verified;
1703 if (!flags)
1704 return;
1706 push_cfun (fn);
1708 /* Always cleanup the CFG before trying to update SSA. */
1709 if (flags & TODO_cleanup_cfg)
1711 cleanup_tree_cfg ();
1713 /* When cleanup_tree_cfg merges consecutive blocks, it may
1714 perform some simplistic propagation when removing single
1715 valued PHI nodes. This propagation may, in turn, cause the
1716 SSA form to become out-of-date (see PR 22037). So, even
1717 if the parent pass had not scheduled an SSA update, we may
1718 still need to do one. */
1719 if (!(flags & TODO_update_ssa_any) && need_ssa_update_p (cfun))
1720 flags |= TODO_update_ssa;
1723 if (flags & TODO_update_ssa_any)
1725 unsigned update_flags = flags & TODO_update_ssa_any;
1726 update_ssa (update_flags);
1729 if (flag_tree_pta && (flags & TODO_rebuild_alias))
1730 compute_may_aliases ();
1732 if (optimize && (flags & TODO_update_address_taken))
1733 execute_update_addresses_taken ();
1735 if (flags & TODO_remove_unused_locals)
1736 remove_unused_locals ();
1738 if (flags & TODO_rebuild_frequencies)
1739 rebuild_frequencies ();
1741 if (flags & TODO_rebuild_cgraph_edges)
1742 cgraph_edge::rebuild_edges ();
1744 /* If we've seen errors do not bother running any verifiers. */
1745 if (!seen_error ())
1747 #if defined ENABLE_CHECKING
1748 dom_state pre_verify_state = dom_info_state (fn, CDI_DOMINATORS);
1749 dom_state pre_verify_pstate = dom_info_state (fn, CDI_POST_DOMINATORS);
1751 if (flags & TODO_verify_il)
1753 if (cfun->curr_properties & PROP_trees)
1755 if (cfun->curr_properties & PROP_cfg)
1756 /* IPA passes leave stmts to be fixed up, so make sure to
1757 not verify stmts really throw. */
1758 verify_gimple_in_cfg (cfun, !from_ipa_pass);
1759 else
1760 verify_gimple_in_seq (gimple_body (cfun->decl));
1762 if (cfun->curr_properties & PROP_ssa)
1763 /* IPA passes leave stmts to be fixed up, so make sure to
1764 not verify SSA operands whose verifier will choke on that. */
1765 verify_ssa (true, !from_ipa_pass);
1766 /* IPA passes leave basic-blocks unsplit, so make sure to
1767 not trip on that. */
1768 if ((cfun->curr_properties & PROP_cfg)
1769 && !from_ipa_pass)
1770 verify_flow_info ();
1771 if (current_loops
1772 && loops_state_satisfies_p (LOOP_CLOSED_SSA))
1773 verify_loop_closed_ssa (false);
1774 if (cfun->curr_properties & PROP_rtl)
1775 verify_rtl_sharing ();
1778 /* Make sure verifiers don't change dominator state. */
1779 gcc_assert (dom_info_state (fn, CDI_DOMINATORS) == pre_verify_state);
1780 gcc_assert (dom_info_state (fn, CDI_POST_DOMINATORS) == pre_verify_pstate);
1781 #endif
1784 fn->last_verified = flags & TODO_verify_all;
1786 pop_cfun ();
1788 /* For IPA passes make sure to release dominator info, it can be
1789 computed by non-verifying TODOs. */
1790 if (from_ipa_pass)
1792 free_dominance_info (fn, CDI_DOMINATORS);
1793 free_dominance_info (fn, CDI_POST_DOMINATORS);
1797 /* Perform all TODO actions. */
1798 static void
1799 execute_todo (unsigned int flags)
1801 #if defined ENABLE_CHECKING
1802 if (cfun
1803 && need_ssa_update_p (cfun))
1804 gcc_assert (flags & TODO_update_ssa_any);
1805 #endif
1807 timevar_push (TV_TODO);
1809 /* Inform the pass whether it is the first time it is run. */
1810 first_pass_instance = (flags & TODO_mark_first_instance) != 0;
1812 statistics_fini_pass ();
1814 if (flags)
1815 do_per_function (execute_function_todo, (void *)(size_t) flags);
1817 /* Always remove functions just as before inlining: IPA passes might be
1818 interested to see bodies of extern inline functions that are not inlined
1819 to analyze side effects. The full removal is done just at the end
1820 of IPA pass queue. */
1821 if (flags & TODO_remove_functions)
1823 gcc_assert (!cfun);
1824 symtab->remove_unreachable_nodes (true, dump_file);
1827 if ((flags & TODO_dump_symtab) && dump_file && !current_function_decl)
1829 gcc_assert (!cfun);
1830 symtab_node::dump_table (dump_file);
1831 /* Flush the file. If verification fails, we won't be able to
1832 close the file before aborting. */
1833 fflush (dump_file);
1836 /* Now that the dumping has been done, we can get rid of the optional
1837 df problems. */
1838 if (flags & TODO_df_finish)
1839 df_finish_pass ((flags & TODO_df_verify) != 0);
1841 timevar_pop (TV_TODO);
1844 /* Verify invariants that should hold between passes. This is a place
1845 to put simple sanity checks. */
1847 static void
1848 verify_interpass_invariants (void)
1850 gcc_checking_assert (!fold_deferring_overflow_warnings_p ());
1853 /* Clear the last verified flag. */
1855 static void
1856 clear_last_verified (function *fn, void *data ATTRIBUTE_UNUSED)
1858 fn->last_verified = 0;
1861 /* Helper function. Verify that the properties has been turn into the
1862 properties expected by the pass. */
1864 #ifdef ENABLE_CHECKING
1865 static void
1866 verify_curr_properties (function *fn, void *data)
1868 unsigned int props = (size_t)data;
1869 gcc_assert ((fn->curr_properties & props) == props);
1871 #endif
1873 /* Initialize pass dump file. */
1874 /* This is non-static so that the plugins can use it. */
1876 bool
1877 pass_init_dump_file (opt_pass *pass)
1879 /* If a dump file name is present, open it if enabled. */
1880 if (pass->static_pass_number != -1)
1882 timevar_push (TV_DUMP);
1883 gcc::dump_manager *dumps = g->get_dumps ();
1884 bool initializing_dump =
1885 !dumps->dump_initialized_p (pass->static_pass_number);
1886 dump_file_name = dumps->get_dump_file_name (pass->static_pass_number);
1887 dumps->dump_start (pass->static_pass_number, &dump_flags);
1888 if (dump_file && current_function_decl)
1889 dump_function_header (dump_file, current_function_decl, dump_flags);
1890 if (initializing_dump
1891 && dump_file && (dump_flags & TDF_GRAPH)
1892 && cfun && (cfun->curr_properties & PROP_cfg))
1894 clean_graph_dump_file (dump_file_name);
1895 pass->graph_dump_initialized = true;
1897 timevar_pop (TV_DUMP);
1898 return initializing_dump;
1900 else
1901 return false;
1904 /* Flush PASS dump file. */
1905 /* This is non-static so that plugins can use it. */
1907 void
1908 pass_fini_dump_file (opt_pass *pass)
1910 timevar_push (TV_DUMP);
1912 /* Flush and close dump file. */
1913 if (dump_file_name)
1915 free (CONST_CAST (char *, dump_file_name));
1916 dump_file_name = NULL;
1919 g->get_dumps ()->dump_finish (pass->static_pass_number);
1920 timevar_pop (TV_DUMP);
1923 /* After executing the pass, apply expected changes to the function
1924 properties. */
1926 static void
1927 update_properties_after_pass (function *fn, void *data)
1929 opt_pass *pass = (opt_pass *) data;
1930 fn->curr_properties = (fn->curr_properties | pass->properties_provided)
1931 & ~pass->properties_destroyed;
1934 /* Execute summary generation for all of the passes in IPA_PASS. */
1936 void
1937 execute_ipa_summary_passes (ipa_opt_pass_d *ipa_pass)
1939 while (ipa_pass)
1941 opt_pass *pass = ipa_pass;
1943 /* Execute all of the IPA_PASSes in the list. */
1944 if (ipa_pass->type == IPA_PASS
1945 && pass->gate (cfun)
1946 && ipa_pass->generate_summary)
1948 pass_init_dump_file (pass);
1950 /* If a timevar is present, start it. */
1951 if (pass->tv_id)
1952 timevar_push (pass->tv_id);
1954 current_pass = pass;
1955 ipa_pass->generate_summary ();
1957 /* Stop timevar. */
1958 if (pass->tv_id)
1959 timevar_pop (pass->tv_id);
1961 pass_fini_dump_file (pass);
1963 ipa_pass = (ipa_opt_pass_d *)ipa_pass->next;
1967 /* Execute IPA_PASS function transform on NODE. */
1969 static void
1970 execute_one_ipa_transform_pass (struct cgraph_node *node,
1971 ipa_opt_pass_d *ipa_pass)
1973 opt_pass *pass = ipa_pass;
1974 unsigned int todo_after = 0;
1976 current_pass = pass;
1977 if (!ipa_pass->function_transform)
1978 return;
1980 /* Note that the folders should only create gimple expressions.
1981 This is a hack until the new folder is ready. */
1982 in_gimple_form = (cfun && (cfun->curr_properties & PROP_trees)) != 0;
1984 pass_init_dump_file (pass);
1986 /* Run pre-pass verification. */
1987 execute_todo (ipa_pass->function_transform_todo_flags_start);
1989 /* If a timevar is present, start it. */
1990 if (pass->tv_id != TV_NONE)
1991 timevar_push (pass->tv_id);
1993 /* Do it! */
1994 todo_after = ipa_pass->function_transform (node);
1996 /* Stop timevar. */
1997 if (pass->tv_id != TV_NONE)
1998 timevar_pop (pass->tv_id);
2000 if (profile_report && cfun && (cfun->curr_properties & PROP_cfg))
2001 check_profile_consistency (pass->static_pass_number, 0, true);
2003 /* Run post-pass cleanup and verification. */
2004 execute_todo (todo_after);
2005 verify_interpass_invariants ();
2006 if (profile_report && cfun && (cfun->curr_properties & PROP_cfg))
2007 check_profile_consistency (pass->static_pass_number, 1, true);
2009 if (dump_file)
2010 do_per_function (execute_function_dump, NULL);
2011 pass_fini_dump_file (pass);
2013 current_pass = NULL;
2015 /* Signal this is a suitable GC collection point. */
2016 if (!(todo_after & TODO_do_not_ggc_collect))
2017 ggc_collect ();
2020 /* For the current function, execute all ipa transforms. */
2022 void
2023 execute_all_ipa_transforms (void)
2025 struct cgraph_node *node;
2026 if (!cfun)
2027 return;
2028 node = cgraph_node::get (current_function_decl);
2030 if (node->ipa_transforms_to_apply.exists ())
2032 unsigned int i;
2034 for (i = 0; i < node->ipa_transforms_to_apply.length (); i++)
2035 execute_one_ipa_transform_pass (node, node->ipa_transforms_to_apply[i]);
2036 node->ipa_transforms_to_apply.release ();
2040 /* Check if PASS is explicitly disabled or enabled and return
2041 the gate status. FUNC is the function to be processed, and
2042 GATE_STATUS is the gate status determined by pass manager by
2043 default. */
2045 static bool
2046 override_gate_status (opt_pass *pass, tree func, bool gate_status)
2048 bool explicitly_enabled = false;
2049 bool explicitly_disabled = false;
2051 explicitly_enabled
2052 = is_pass_explicitly_enabled_or_disabled (pass, func,
2053 enabled_pass_uid_range_tab);
2054 explicitly_disabled
2055 = is_pass_explicitly_enabled_or_disabled (pass, func,
2056 disabled_pass_uid_range_tab);
2058 gate_status = !explicitly_disabled && (gate_status || explicitly_enabled);
2060 return gate_status;
2064 /* Execute PASS. */
2066 bool
2067 execute_one_pass (opt_pass *pass)
2069 unsigned int todo_after = 0;
2071 bool gate_status;
2073 /* IPA passes are executed on whole program, so cfun should be NULL.
2074 Other passes need function context set. */
2075 if (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS)
2076 gcc_assert (!cfun && !current_function_decl);
2077 else
2078 gcc_assert (cfun && current_function_decl);
2080 current_pass = pass;
2082 /* Check whether gate check should be avoided.
2083 User controls the value of the gate through the parameter "gate_status". */
2084 gate_status = pass->gate (cfun);
2085 gate_status = override_gate_status (pass, current_function_decl, gate_status);
2087 /* Override gate with plugin. */
2088 invoke_plugin_callbacks (PLUGIN_OVERRIDE_GATE, &gate_status);
2090 if (!gate_status)
2092 /* Run so passes selectively disabling themselves on a given function
2093 are not miscounted. */
2094 if (profile_report && cfun && (cfun->curr_properties & PROP_cfg))
2096 check_profile_consistency (pass->static_pass_number, 0, false);
2097 check_profile_consistency (pass->static_pass_number, 1, false);
2099 current_pass = NULL;
2100 return false;
2103 /* Pass execution event trigger: useful to identify passes being
2104 executed. */
2105 invoke_plugin_callbacks (PLUGIN_PASS_EXECUTION, pass);
2107 /* SIPLE IPA passes do not handle callgraphs with IPA transforms in it.
2108 Apply all trnasforms first. */
2109 if (pass->type == SIMPLE_IPA_PASS)
2111 struct cgraph_node *node;
2112 bool applied = false;
2113 FOR_EACH_DEFINED_FUNCTION (node)
2114 if (node->analyzed
2115 && node->has_gimple_body_p ()
2116 && (!node->clone_of || node->decl != node->clone_of->decl))
2118 if (!node->global.inlined_to
2119 && node->ipa_transforms_to_apply.exists ())
2121 node->get_body ();
2122 push_cfun (DECL_STRUCT_FUNCTION (node->decl));
2123 execute_all_ipa_transforms ();
2124 cgraph_edge::rebuild_edges ();
2125 free_dominance_info (CDI_DOMINATORS);
2126 free_dominance_info (CDI_POST_DOMINATORS);
2127 pop_cfun ();
2128 applied = true;
2131 if (applied)
2132 symtab->remove_unreachable_nodes (false, dump_file);
2133 /* Restore current_pass. */
2134 current_pass = pass;
2137 if (!quiet_flag && !cfun)
2138 fprintf (stderr, " <%s>", pass->name ? pass->name : "");
2140 /* Note that the folders should only create gimple expressions.
2141 This is a hack until the new folder is ready. */
2142 in_gimple_form = (cfun && (cfun->curr_properties & PROP_trees)) != 0;
2144 pass_init_dump_file (pass);
2146 /* Run pre-pass verification. */
2147 execute_todo (pass->todo_flags_start);
2149 #ifdef ENABLE_CHECKING
2150 do_per_function (verify_curr_properties,
2151 (void *)(size_t)pass->properties_required);
2152 #endif
2154 /* If a timevar is present, start it. */
2155 if (pass->tv_id != TV_NONE)
2156 timevar_push (pass->tv_id);
2158 /* Do it! */
2159 todo_after = pass->execute (cfun);
2160 do_per_function (clear_last_verified, NULL);
2162 /* Stop timevar. */
2163 if (pass->tv_id != TV_NONE)
2164 timevar_pop (pass->tv_id);
2166 do_per_function (update_properties_after_pass, pass);
2168 if (profile_report && cfun && (cfun->curr_properties & PROP_cfg))
2169 check_profile_consistency (pass->static_pass_number, 0, true);
2171 /* Run post-pass cleanup and verification. */
2172 execute_todo (todo_after | pass->todo_flags_finish | TODO_verify_il);
2173 if (profile_report && cfun && (cfun->curr_properties & PROP_cfg))
2174 check_profile_consistency (pass->static_pass_number, 1, true);
2176 verify_interpass_invariants ();
2177 if (dump_file)
2178 do_per_function (execute_function_dump, pass);
2179 if (pass->type == IPA_PASS)
2181 struct cgraph_node *node;
2182 FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node)
2183 node->ipa_transforms_to_apply.safe_push ((ipa_opt_pass_d *)pass);
2186 if (!current_function_decl)
2187 symtab->process_new_functions ();
2189 pass_fini_dump_file (pass);
2191 if (pass->type != SIMPLE_IPA_PASS && pass->type != IPA_PASS)
2192 gcc_assert (!(cfun->curr_properties & PROP_trees)
2193 || pass->type != RTL_PASS);
2195 current_pass = NULL;
2197 /* Signal this is a suitable GC collection point. */
2198 if (!((todo_after | pass->todo_flags_finish) & TODO_do_not_ggc_collect))
2199 ggc_collect ();
2201 return true;
2204 static void
2205 execute_pass_list_1 (opt_pass *pass)
2209 gcc_assert (pass->type == GIMPLE_PASS
2210 || pass->type == RTL_PASS);
2211 if (execute_one_pass (pass) && pass->sub)
2212 execute_pass_list_1 (pass->sub);
2213 pass = pass->next;
2215 while (pass);
2218 void
2219 execute_pass_list (function *fn, opt_pass *pass)
2221 push_cfun (fn);
2222 execute_pass_list_1 (pass);
2223 if (fn->cfg)
2225 free_dominance_info (CDI_DOMINATORS);
2226 free_dominance_info (CDI_POST_DOMINATORS);
2228 pop_cfun ();
2231 /* Write out all LTO data. */
2232 static void
2233 write_lto (void)
2235 timevar_push (TV_IPA_LTO_GIMPLE_OUT);
2236 lto_output ();
2237 timevar_pop (TV_IPA_LTO_GIMPLE_OUT);
2238 timevar_push (TV_IPA_LTO_DECL_OUT);
2239 produce_asm_for_decls ();
2240 timevar_pop (TV_IPA_LTO_DECL_OUT);
2243 /* Same as execute_pass_list but assume that subpasses of IPA passes
2244 are local passes. If SET is not NULL, write out summaries of only
2245 those node in SET. */
2247 static void
2248 ipa_write_summaries_2 (opt_pass *pass, struct lto_out_decl_state *state)
2250 while (pass)
2252 ipa_opt_pass_d *ipa_pass = (ipa_opt_pass_d *)pass;
2253 gcc_assert (!current_function_decl);
2254 gcc_assert (!cfun);
2255 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
2256 if (pass->type == IPA_PASS
2257 && ipa_pass->write_summary
2258 && pass->gate (cfun))
2260 /* If a timevar is present, start it. */
2261 if (pass->tv_id)
2262 timevar_push (pass->tv_id);
2264 pass_init_dump_file (pass);
2266 current_pass = pass;
2267 ipa_pass->write_summary ();
2269 pass_fini_dump_file (pass);
2271 /* If a timevar is present, start it. */
2272 if (pass->tv_id)
2273 timevar_pop (pass->tv_id);
2276 if (pass->sub && pass->sub->type != GIMPLE_PASS)
2277 ipa_write_summaries_2 (pass->sub, state);
2279 pass = pass->next;
2283 /* Helper function of ipa_write_summaries. Creates and destroys the
2284 decl state and calls ipa_write_summaries_2 for all passes that have
2285 summaries. SET is the set of nodes to be written. */
2287 static void
2288 ipa_write_summaries_1 (lto_symtab_encoder_t encoder)
2290 pass_manager *passes = g->get_passes ();
2291 struct lto_out_decl_state *state = lto_new_out_decl_state ();
2292 state->symtab_node_encoder = encoder;
2294 lto_push_out_decl_state (state);
2296 gcc_assert (!flag_wpa);
2297 ipa_write_summaries_2 (passes->all_regular_ipa_passes, state);
2299 write_lto ();
2301 gcc_assert (lto_get_out_decl_state () == state);
2302 lto_pop_out_decl_state ();
2303 lto_delete_out_decl_state (state);
2306 /* Write out summaries for all the nodes in the callgraph. */
2308 void
2309 ipa_write_summaries (void)
2311 lto_symtab_encoder_t encoder;
2312 int i, order_pos;
2313 varpool_node *vnode;
2314 struct cgraph_node *node;
2315 struct cgraph_node **order;
2317 if (!flag_generate_lto || seen_error ())
2318 return;
2320 encoder = lto_symtab_encoder_new (false);
2322 /* Create the callgraph set in the same order used in
2323 cgraph_expand_all_functions. This mostly facilitates debugging,
2324 since it causes the gimple file to be processed in the same order
2325 as the source code. */
2326 order = XCNEWVEC (struct cgraph_node *, symtab->cgraph_count);
2327 order_pos = ipa_reverse_postorder (order);
2328 gcc_assert (order_pos == symtab->cgraph_count);
2330 for (i = order_pos - 1; i >= 0; i--)
2332 struct cgraph_node *node = order[i];
2334 if (node->has_gimple_body_p ())
2336 /* When streaming out references to statements as part of some IPA
2337 pass summary, the statements need to have uids assigned and the
2338 following does that for all the IPA passes here. Naturally, this
2339 ordering then matches the one IPA-passes get in their stmt_fixup
2340 hooks. */
2342 push_cfun (DECL_STRUCT_FUNCTION (node->decl));
2343 renumber_gimple_stmt_uids ();
2344 pop_cfun ();
2346 if (node->definition)
2347 lto_set_symtab_encoder_in_partition (encoder, node);
2350 FOR_EACH_DEFINED_FUNCTION (node)
2351 if (node->alias)
2352 lto_set_symtab_encoder_in_partition (encoder, node);
2353 FOR_EACH_DEFINED_VARIABLE (vnode)
2354 lto_set_symtab_encoder_in_partition (encoder, vnode);
2356 ipa_write_summaries_1 (compute_ltrans_boundary (encoder));
2358 free (order);
2361 /* Same as execute_pass_list but assume that subpasses of IPA passes
2362 are local passes. If SET is not NULL, write out optimization summaries of
2363 only those node in SET. */
2365 static void
2366 ipa_write_optimization_summaries_1 (opt_pass *pass,
2367 struct lto_out_decl_state *state)
2369 while (pass)
2371 ipa_opt_pass_d *ipa_pass = (ipa_opt_pass_d *)pass;
2372 gcc_assert (!current_function_decl);
2373 gcc_assert (!cfun);
2374 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
2375 if (pass->type == IPA_PASS
2376 && ipa_pass->write_optimization_summary
2377 && pass->gate (cfun))
2379 /* If a timevar is present, start it. */
2380 if (pass->tv_id)
2381 timevar_push (pass->tv_id);
2383 pass_init_dump_file (pass);
2385 current_pass = pass;
2386 ipa_pass->write_optimization_summary ();
2388 pass_fini_dump_file (pass);
2390 /* If a timevar is present, start it. */
2391 if (pass->tv_id)
2392 timevar_pop (pass->tv_id);
2395 if (pass->sub && pass->sub->type != GIMPLE_PASS)
2396 ipa_write_optimization_summaries_1 (pass->sub, state);
2398 pass = pass->next;
2402 /* Write all the optimization summaries for the cgraph nodes in SET. If SET is
2403 NULL, write out all summaries of all nodes. */
2405 void
2406 ipa_write_optimization_summaries (lto_symtab_encoder_t encoder)
2408 struct lto_out_decl_state *state = lto_new_out_decl_state ();
2409 lto_symtab_encoder_iterator lsei;
2410 state->symtab_node_encoder = encoder;
2412 lto_push_out_decl_state (state);
2413 for (lsei = lsei_start_function_in_partition (encoder);
2414 !lsei_end_p (lsei); lsei_next_function_in_partition (&lsei))
2416 struct cgraph_node *node = lsei_cgraph_node (lsei);
2417 /* When streaming out references to statements as part of some IPA
2418 pass summary, the statements need to have uids assigned.
2420 For functions newly born at WPA stage we need to initialize
2421 the uids here. */
2422 if (node->definition
2423 && gimple_has_body_p (node->decl))
2425 push_cfun (DECL_STRUCT_FUNCTION (node->decl));
2426 renumber_gimple_stmt_uids ();
2427 pop_cfun ();
2431 gcc_assert (flag_wpa);
2432 pass_manager *passes = g->get_passes ();
2433 ipa_write_optimization_summaries_1 (passes->all_regular_ipa_passes, state);
2435 write_lto ();
2437 gcc_assert (lto_get_out_decl_state () == state);
2438 lto_pop_out_decl_state ();
2439 lto_delete_out_decl_state (state);
2442 /* Same as execute_pass_list but assume that subpasses of IPA passes
2443 are local passes. */
2445 static void
2446 ipa_read_summaries_1 (opt_pass *pass)
2448 while (pass)
2450 ipa_opt_pass_d *ipa_pass = (ipa_opt_pass_d *) pass;
2452 gcc_assert (!current_function_decl);
2453 gcc_assert (!cfun);
2454 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
2456 if (pass->gate (cfun))
2458 if (pass->type == IPA_PASS && ipa_pass->read_summary)
2460 /* If a timevar is present, start it. */
2461 if (pass->tv_id)
2462 timevar_push (pass->tv_id);
2464 pass_init_dump_file (pass);
2466 current_pass = pass;
2467 ipa_pass->read_summary ();
2469 pass_fini_dump_file (pass);
2471 /* Stop timevar. */
2472 if (pass->tv_id)
2473 timevar_pop (pass->tv_id);
2476 if (pass->sub && pass->sub->type != GIMPLE_PASS)
2477 ipa_read_summaries_1 (pass->sub);
2479 pass = pass->next;
2484 /* Read all the summaries for all_regular_ipa_passes. */
2486 void
2487 ipa_read_summaries (void)
2489 pass_manager *passes = g->get_passes ();
2490 ipa_read_summaries_1 (passes->all_regular_ipa_passes);
2493 /* Same as execute_pass_list but assume that subpasses of IPA passes
2494 are local passes. */
2496 static void
2497 ipa_read_optimization_summaries_1 (opt_pass *pass)
2499 while (pass)
2501 ipa_opt_pass_d *ipa_pass = (ipa_opt_pass_d *) pass;
2503 gcc_assert (!current_function_decl);
2504 gcc_assert (!cfun);
2505 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
2507 if (pass->gate (cfun))
2509 if (pass->type == IPA_PASS && ipa_pass->read_optimization_summary)
2511 /* If a timevar is present, start it. */
2512 if (pass->tv_id)
2513 timevar_push (pass->tv_id);
2515 pass_init_dump_file (pass);
2517 current_pass = pass;
2518 ipa_pass->read_optimization_summary ();
2520 pass_fini_dump_file (pass);
2522 /* Stop timevar. */
2523 if (pass->tv_id)
2524 timevar_pop (pass->tv_id);
2527 if (pass->sub && pass->sub->type != GIMPLE_PASS)
2528 ipa_read_optimization_summaries_1 (pass->sub);
2530 pass = pass->next;
2534 /* Read all the summaries for all_regular_ipa_passes. */
2536 void
2537 ipa_read_optimization_summaries (void)
2539 pass_manager *passes = g->get_passes ();
2540 ipa_read_optimization_summaries_1 (passes->all_regular_ipa_passes);
2543 /* Same as execute_pass_list but assume that subpasses of IPA passes
2544 are local passes. */
2545 void
2546 execute_ipa_pass_list (opt_pass *pass)
2550 gcc_assert (!current_function_decl);
2551 gcc_assert (!cfun);
2552 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
2553 if (execute_one_pass (pass) && pass->sub)
2555 if (pass->sub->type == GIMPLE_PASS)
2557 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_START, NULL);
2558 do_per_function_toporder ((void (*)(function *, void *))
2559 execute_pass_list,
2560 pass->sub);
2561 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_END, NULL);
2563 else if (pass->sub->type == SIMPLE_IPA_PASS
2564 || pass->sub->type == IPA_PASS)
2565 execute_ipa_pass_list (pass->sub);
2566 else
2567 gcc_unreachable ();
2569 gcc_assert (!current_function_decl);
2570 symtab->process_new_functions ();
2571 pass = pass->next;
2573 while (pass);
2576 /* Execute stmt fixup hooks of all passes in PASS for NODE and STMTS. */
2578 static void
2579 execute_ipa_stmt_fixups (opt_pass *pass,
2580 struct cgraph_node *node, gimple *stmts)
2582 while (pass)
2584 /* Execute all of the IPA_PASSes in the list. */
2585 if (pass->type == IPA_PASS
2586 && pass->gate (cfun))
2588 ipa_opt_pass_d *ipa_pass = (ipa_opt_pass_d *) pass;
2590 if (ipa_pass->stmt_fixup)
2592 pass_init_dump_file (pass);
2593 /* If a timevar is present, start it. */
2594 if (pass->tv_id)
2595 timevar_push (pass->tv_id);
2597 current_pass = pass;
2598 ipa_pass->stmt_fixup (node, stmts);
2600 /* Stop timevar. */
2601 if (pass->tv_id)
2602 timevar_pop (pass->tv_id);
2603 pass_fini_dump_file (pass);
2605 if (pass->sub)
2606 execute_ipa_stmt_fixups (pass->sub, node, stmts);
2608 pass = pass->next;
2612 /* Execute stmt fixup hooks of all IPA passes for NODE and STMTS. */
2614 void
2615 execute_all_ipa_stmt_fixups (struct cgraph_node *node, gimple *stmts)
2617 pass_manager *passes = g->get_passes ();
2618 execute_ipa_stmt_fixups (passes->all_regular_ipa_passes, node, stmts);
2622 extern void debug_properties (unsigned int);
2623 extern void dump_properties (FILE *, unsigned int);
2625 DEBUG_FUNCTION void
2626 dump_properties (FILE *dump, unsigned int props)
2628 fprintf (dump, "Properties:\n");
2629 if (props & PROP_gimple_any)
2630 fprintf (dump, "PROP_gimple_any\n");
2631 if (props & PROP_gimple_lcf)
2632 fprintf (dump, "PROP_gimple_lcf\n");
2633 if (props & PROP_gimple_leh)
2634 fprintf (dump, "PROP_gimple_leh\n");
2635 if (props & PROP_cfg)
2636 fprintf (dump, "PROP_cfg\n");
2637 if (props & PROP_ssa)
2638 fprintf (dump, "PROP_ssa\n");
2639 if (props & PROP_no_crit_edges)
2640 fprintf (dump, "PROP_no_crit_edges\n");
2641 if (props & PROP_rtl)
2642 fprintf (dump, "PROP_rtl\n");
2643 if (props & PROP_gimple_lomp)
2644 fprintf (dump, "PROP_gimple_lomp\n");
2645 if (props & PROP_gimple_lcx)
2646 fprintf (dump, "PROP_gimple_lcx\n");
2647 if (props & PROP_gimple_lvec)
2648 fprintf (dump, "PROP_gimple_lvec\n");
2649 if (props & PROP_cfglayout)
2650 fprintf (dump, "PROP_cfglayout\n");
2653 DEBUG_FUNCTION void
2654 debug_properties (unsigned int props)
2656 dump_properties (stderr, props);
2659 /* Called by local passes to see if function is called by already processed nodes.
2660 Because we process nodes in topological order, this means that function is
2661 in recursive cycle or we introduced new direct calls. */
2662 bool
2663 function_called_by_processed_nodes_p (void)
2665 struct cgraph_edge *e;
2666 for (e = cgraph_node::get (current_function_decl)->callers;
2668 e = e->next_caller)
2670 if (e->caller->decl == current_function_decl)
2671 continue;
2672 if (!e->caller->has_gimple_body_p ())
2673 continue;
2674 if (TREE_ASM_WRITTEN (e->caller->decl))
2675 continue;
2676 if (!e->caller->process && !e->caller->global.inlined_to)
2677 break;
2679 if (dump_file && e)
2681 fprintf (dump_file, "Already processed call to:\n");
2682 e->caller->dump (dump_file);
2684 return e != NULL;
2687 #include "gt-passes.h"