graph.c (init_graph_slim_pretty_print): Remove.
[official-gcc.git] / gcc / passes.c
bloba43a58809af38fc35ca641197b7b6509a8aee037
1 /* Top level of GCC compilers (cc1, cc1plus, etc.)
2 Copyright (C) 1987-2013 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 "hash-table.h"
31 #include "input.h"
32 #include "tree.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 "function.h"
44 #include "toplev.h"
45 #include "expr.h"
46 #include "basic-block.h"
47 #include "intl.h"
48 #include "ggc.h"
49 #include "graph.h"
50 #include "regs.h"
51 #include "diagnostic-core.h"
52 #include "params.h"
53 #include "reload.h"
54 #include "debug.h"
55 #include "target.h"
56 #include "langhooks.h"
57 #include "cfgloop.h"
58 #include "hosthooks.h"
59 #include "cgraph.h"
60 #include "opts.h"
61 #include "coverage.h"
62 #include "value-prof.h"
63 #include "tree-inline.h"
64 #include "tree-flow.h"
65 #include "tree-pass.h"
66 #include "tree-dump.h"
67 #include "df.h"
68 #include "predict.h"
69 #include "lto-streamer.h"
70 #include "plugin.h"
71 #include "ipa-utils.h"
72 #include "tree-pretty-print.h" /* for dump_function_header */
73 #include "context.h"
74 #include "pass_manager.h"
76 using namespace gcc;
78 /* This is used for debugging. It allows the current pass to printed
79 from anywhere in compilation.
80 The variable current_pass is also used for statistics and plugins. */
81 struct opt_pass *current_pass;
83 static void register_pass_name (struct opt_pass *, const char *);
85 /* Call from anywhere to find out what pass this is. Useful for
86 printing out debugging information deep inside an service
87 routine. */
88 void
89 print_current_pass (FILE *file)
91 if (current_pass)
92 fprintf (file, "current pass = %s (%d)\n",
93 current_pass->name, current_pass->static_pass_number);
94 else
95 fprintf (file, "no current pass.\n");
99 /* Call from the debugger to get the current pass name. */
100 DEBUG_FUNCTION void
101 debug_pass (void)
103 print_current_pass (stderr);
108 /* Global variables used to communicate with passes. */
109 bool in_gimple_form;
110 bool first_pass_instance;
113 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
114 and TYPE_DECL nodes.
116 This does nothing for local (non-static) variables, unless the
117 variable is a register variable with DECL_ASSEMBLER_NAME set. In
118 that case, or if the variable is not an automatic, it sets up the
119 RTL and outputs any assembler code (label definition, storage
120 allocation and initialization).
122 DECL is the declaration. TOP_LEVEL is nonzero
123 if this declaration is not within a function. */
125 void
126 rest_of_decl_compilation (tree decl,
127 int top_level,
128 int at_end)
130 /* We deferred calling assemble_alias so that we could collect
131 other attributes such as visibility. Emit the alias now. */
132 if (!in_lto_p)
134 tree alias;
135 alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
136 if (alias)
138 alias = TREE_VALUE (TREE_VALUE (alias));
139 alias = get_identifier (TREE_STRING_POINTER (alias));
140 /* A quirk of the initial implementation of aliases required that the
141 user add "extern" to all of them. Which is silly, but now
142 historical. Do note that the symbol is in fact locally defined. */
143 DECL_EXTERNAL (decl) = 0;
144 TREE_STATIC (decl) = 1;
145 assemble_alias (decl, alias);
149 /* Can't defer this, because it needs to happen before any
150 later function definitions are processed. */
151 if (DECL_ASSEMBLER_NAME_SET_P (decl) && DECL_REGISTER (decl))
152 make_decl_rtl (decl);
154 /* Forward declarations for nested functions are not "external",
155 but we need to treat them as if they were. */
156 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
157 || TREE_CODE (decl) == FUNCTION_DECL)
159 timevar_push (TV_VARCONST);
161 /* Don't output anything when a tentative file-scope definition
162 is seen. But at end of compilation, do output code for them.
164 We do output all variables and rely on
165 callgraph code to defer them except for forward declarations
166 (see gcc.c-torture/compile/920624-1.c) */
167 if ((at_end
168 || !DECL_DEFER_OUTPUT (decl)
169 || DECL_INITIAL (decl))
170 && (TREE_CODE (decl) != VAR_DECL || !DECL_HAS_VALUE_EXPR_P (decl))
171 && !DECL_EXTERNAL (decl))
173 /* When reading LTO unit, we also read varpool, so do not
174 rebuild it. */
175 if (in_lto_p && !at_end)
177 else if (TREE_CODE (decl) != FUNCTION_DECL)
178 varpool_finalize_decl (decl);
181 #ifdef ASM_FINISH_DECLARE_OBJECT
182 if (decl == last_assemble_variable_decl)
184 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
185 top_level, at_end);
187 #endif
189 timevar_pop (TV_VARCONST);
191 else if (TREE_CODE (decl) == TYPE_DECL
192 /* Like in rest_of_type_compilation, avoid confusing the debug
193 information machinery when there are errors. */
194 && !seen_error ())
196 timevar_push (TV_SYMOUT);
197 debug_hooks->type_decl (decl, !top_level);
198 timevar_pop (TV_SYMOUT);
201 /* Let cgraph know about the existence of variables. */
202 if (in_lto_p && !at_end)
204 else if (TREE_CODE (decl) == VAR_DECL && !DECL_EXTERNAL (decl)
205 && TREE_STATIC (decl))
206 varpool_node_for_decl (decl);
209 /* Called after finishing a record, union or enumeral type. */
211 void
212 rest_of_type_compilation (tree type, int toplev)
214 /* Avoid confusing the debug information machinery when there are
215 errors. */
216 if (seen_error ())
217 return;
219 timevar_push (TV_SYMOUT);
220 debug_hooks->type_decl (TYPE_STUB_DECL (type), !toplev);
221 timevar_pop (TV_SYMOUT);
226 void
227 finish_optimization_passes (void)
229 int i;
230 struct dump_file_info *dfi;
231 char *name;
233 timevar_push (TV_DUMP);
234 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
236 dump_start (pass_profile.pass.static_pass_number, NULL);
237 end_branch_prob ();
238 dump_finish (pass_profile.pass.static_pass_number);
241 if (optimize > 0)
243 dump_start (pass_profile.pass.static_pass_number, NULL);
244 print_combine_total_stats ();
245 dump_finish (pass_profile.pass.static_pass_number);
248 /* Do whatever is necessary to finish printing the graphs. */
249 for (i = TDI_end; (dfi = get_dump_file_info (i)) != NULL; ++i)
250 if (dump_initialized_p (i)
251 && (dfi->pflags & TDF_GRAPH) != 0
252 && (name = get_dump_file_name (i)) != NULL)
254 finish_graph_dump_file (name);
255 free (name);
258 timevar_pop (TV_DUMP);
261 static unsigned int
262 execute_all_early_local_passes (void)
264 /* Once this pass (and its sub-passes) are complete, all functions
265 will be in SSA form. Technically this state change is happening
266 a tad early, since the sub-passes have not yet run, but since
267 none of the sub-passes are IPA passes and do not create new
268 functions, this is ok. We're setting this value for the benefit
269 of IPA passes that follow. */
270 if (cgraph_state < CGRAPH_STATE_IPA_SSA)
271 cgraph_state = CGRAPH_STATE_IPA_SSA;
272 return 0;
275 /* Gate: execute, or not, all of the non-trivial optimizations. */
277 static bool
278 gate_all_early_local_passes (void)
280 /* Don't bother doing anything if the program has errors. */
281 return (!seen_error () && !in_lto_p);
284 struct simple_ipa_opt_pass pass_early_local_passes =
287 SIMPLE_IPA_PASS,
288 "early_local_cleanups", /* name */
289 OPTGROUP_NONE, /* optinfo_flags */
290 gate_all_early_local_passes, /* gate */
291 execute_all_early_local_passes, /* execute */
292 NULL, /* sub */
293 NULL, /* next */
294 0, /* static_pass_number */
295 TV_EARLY_LOCAL, /* tv_id */
296 0, /* properties_required */
297 0, /* properties_provided */
298 0, /* properties_destroyed */
299 0, /* todo_flags_start */
300 TODO_remove_functions /* todo_flags_finish */
304 /* Gate: execute, or not, all of the non-trivial optimizations. */
306 static bool
307 gate_all_early_optimizations (void)
309 return (optimize >= 1
310 /* Don't bother doing anything if the program has errors. */
311 && !seen_error ());
314 static struct gimple_opt_pass pass_all_early_optimizations =
317 GIMPLE_PASS,
318 "early_optimizations", /* name */
319 OPTGROUP_NONE, /* optinfo_flags */
320 gate_all_early_optimizations, /* gate */
321 NULL, /* execute */
322 NULL, /* sub */
323 NULL, /* next */
324 0, /* static_pass_number */
325 TV_NONE, /* tv_id */
326 0, /* properties_required */
327 0, /* properties_provided */
328 0, /* properties_destroyed */
329 0, /* todo_flags_start */
330 0 /* todo_flags_finish */
334 /* Gate: execute, or not, all of the non-trivial optimizations. */
336 static bool
337 gate_all_optimizations (void)
339 return optimize >= 1 && !optimize_debug;
342 static struct gimple_opt_pass pass_all_optimizations =
345 GIMPLE_PASS,
346 "*all_optimizations", /* name */
347 OPTGROUP_NONE, /* optinfo_flags */
348 gate_all_optimizations, /* gate */
349 NULL, /* execute */
350 NULL, /* sub */
351 NULL, /* next */
352 0, /* static_pass_number */
353 TV_OPTIMIZE, /* tv_id */
354 0, /* properties_required */
355 0, /* properties_provided */
356 0, /* properties_destroyed */
357 0, /* todo_flags_start */
358 0 /* todo_flags_finish */
362 /* Gate: execute, or not, all of the non-trivial optimizations. */
364 static bool
365 gate_all_optimizations_g (void)
367 return optimize >= 1 && optimize_debug;
370 static struct gimple_opt_pass pass_all_optimizations_g =
373 GIMPLE_PASS,
374 "*all_optimizations_g", /* name */
375 OPTGROUP_NONE, /* optinfo_flags */
376 gate_all_optimizations_g, /* gate */
377 NULL, /* execute */
378 NULL, /* sub */
379 NULL, /* next */
380 0, /* static_pass_number */
381 TV_OPTIMIZE, /* tv_id */
382 0, /* properties_required */
383 0, /* properties_provided */
384 0, /* properties_destroyed */
385 0, /* todo_flags_start */
386 0 /* todo_flags_finish */
390 static bool
391 gate_rest_of_compilation (void)
393 /* Early return if there were errors. We can run afoul of our
394 consistency checks, and there's not really much point in fixing them. */
395 return !(rtl_dump_and_exit || flag_syntax_only || seen_error ());
398 static struct rtl_opt_pass pass_rest_of_compilation =
401 RTL_PASS,
402 "*rest_of_compilation", /* name */
403 OPTGROUP_NONE, /* optinfo_flags */
404 gate_rest_of_compilation, /* gate */
405 NULL, /* execute */
406 NULL, /* sub */
407 NULL, /* next */
408 0, /* static_pass_number */
409 TV_REST_OF_COMPILATION, /* tv_id */
410 PROP_rtl, /* properties_required */
411 0, /* properties_provided */
412 0, /* properties_destroyed */
413 0, /* todo_flags_start */
414 0 /* todo_flags_finish */
418 static bool
419 gate_postreload (void)
421 return reload_completed;
424 static struct rtl_opt_pass pass_postreload =
427 RTL_PASS,
428 "*all-postreload", /* name */
429 OPTGROUP_NONE, /* optinfo_flags */
430 gate_postreload, /* gate */
431 NULL, /* execute */
432 NULL, /* sub */
433 NULL, /* next */
434 0, /* static_pass_number */
435 TV_POSTRELOAD, /* tv_id */
436 PROP_rtl, /* properties_required */
437 0, /* properties_provided */
438 0, /* properties_destroyed */
439 0, /* todo_flags_start */
440 TODO_verify_rtl_sharing /* todo_flags_finish */
446 /* Set the static pass number of pass PASS to ID and record that
447 in the mapping from static pass number to pass. */
449 void
450 pass_manager::
451 set_pass_for_id (int id, struct opt_pass *pass)
453 pass->static_pass_number = id;
454 if (passes_by_id_size <= id)
456 passes_by_id = XRESIZEVEC (struct opt_pass *, passes_by_id, id + 1);
457 memset (passes_by_id + passes_by_id_size, 0,
458 (id + 1 - passes_by_id_size) * sizeof (void *));
459 passes_by_id_size = id + 1;
461 passes_by_id[id] = pass;
464 /* Return the pass with the static pass number ID. */
466 struct opt_pass *
467 pass_manager::get_pass_for_id (int id) const
469 if (id >= passes_by_id_size)
470 return NULL;
471 return passes_by_id[id];
474 /* Iterate over the pass tree allocating dump file numbers. We want
475 to do this depth first, and independent of whether the pass is
476 enabled or not. */
478 void
479 register_one_dump_file (struct opt_pass *pass)
481 g->get_passes ()->register_one_dump_file (pass);
484 void
485 pass_manager::register_one_dump_file (struct opt_pass *pass)
487 char *dot_name, *flag_name, *glob_name;
488 const char *name, *full_name, *prefix;
489 char num[10];
490 int flags, id;
491 int optgroup_flags = OPTGROUP_NONE;
493 /* See below in next_pass_1. */
494 num[0] = '\0';
495 if (pass->static_pass_number != -1)
496 sprintf (num, "%d", ((int) pass->static_pass_number < 0
497 ? 1 : pass->static_pass_number));
499 /* The name is both used to identify the pass for the purposes of plugins,
500 and to specify dump file name and option.
501 The latter two might want something short which is not quite unique; for
502 that reason, we may have a disambiguating prefix, followed by a space
503 to mark the start of the following dump file name / option string. */
504 name = strchr (pass->name, ' ');
505 name = name ? name + 1 : pass->name;
506 dot_name = concat (".", name, num, NULL);
507 if (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS)
509 prefix = "ipa-";
510 flags = TDF_IPA;
511 optgroup_flags |= OPTGROUP_IPA;
513 else if (pass->type == GIMPLE_PASS)
515 prefix = "tree-";
516 flags = TDF_TREE;
518 else
520 prefix = "rtl-";
521 flags = TDF_RTL;
524 flag_name = concat (prefix, name, num, NULL);
525 glob_name = concat (prefix, name, NULL);
526 optgroup_flags |= pass->optinfo_flags;
527 id = dump_register (dot_name, flag_name, glob_name, flags, optgroup_flags);
528 set_pass_for_id (id, pass);
529 full_name = concat (prefix, pass->name, num, NULL);
530 register_pass_name (pass, full_name);
531 free (CONST_CAST (char *, full_name));
534 /* Recursive worker function for register_dump_files. */
537 pass_manager::
538 register_dump_files_1 (struct opt_pass *pass, int properties)
542 int new_properties = (properties | pass->properties_provided)
543 & ~pass->properties_destroyed;
545 if (pass->name && pass->name[0] != '*')
546 register_one_dump_file (pass);
548 if (pass->sub)
549 new_properties = register_dump_files_1 (pass->sub, new_properties);
551 /* If we have a gate, combine the properties that we could have with
552 and without the pass being examined. */
553 if (pass->gate)
554 properties &= new_properties;
555 else
556 properties = new_properties;
558 pass = pass->next;
560 while (pass);
562 return properties;
565 /* Register the dump files for the pass_manager starting at PASS.
566 PROPERTIES reflects the properties that are guaranteed to be available at
567 the beginning of the pipeline. */
569 void
570 pass_manager::
571 register_dump_files (struct opt_pass *pass,int properties)
573 pass->properties_required |= properties;
574 register_dump_files_1 (pass, properties);
577 struct pass_registry
579 const char* unique_name;
580 struct opt_pass *pass;
583 /* Helper for pass_registry hash table. */
585 struct pass_registry_hasher : typed_noop_remove <pass_registry>
587 typedef pass_registry value_type;
588 typedef pass_registry compare_type;
589 static inline hashval_t hash (const value_type *);
590 static inline bool equal (const value_type *, const compare_type *);
593 /* Pass registry hash function. */
595 inline hashval_t
596 pass_registry_hasher::hash (const value_type *s)
598 return htab_hash_string (s->unique_name);
601 /* Hash equal function */
603 inline bool
604 pass_registry_hasher::equal (const value_type *s1, const compare_type *s2)
606 return !strcmp (s1->unique_name, s2->unique_name);
609 static hash_table <pass_registry_hasher> name_to_pass_map;
611 /* Register PASS with NAME. */
613 static void
614 register_pass_name (struct opt_pass *pass, const char *name)
616 struct pass_registry **slot;
617 struct pass_registry pr;
619 if (!name_to_pass_map.is_created ())
620 name_to_pass_map.create (256);
622 pr.unique_name = name;
623 slot = name_to_pass_map.find_slot (&pr, INSERT);
624 if (!*slot)
626 struct pass_registry *new_pr;
628 new_pr = XCNEW (struct pass_registry);
629 new_pr->unique_name = xstrdup (name);
630 new_pr->pass = pass;
631 *slot = new_pr;
633 else
634 return; /* Ignore plugin passes. */
637 /* Map from pass id to canonicalized pass name. */
639 typedef const char *char_ptr;
640 static vec<char_ptr> pass_tab = vNULL;
642 /* Callback function for traversing NAME_TO_PASS_MAP. */
645 passes_pass_traverse (pass_registry **p, void *data ATTRIBUTE_UNUSED)
647 struct opt_pass *pass = (*p)->pass;
649 gcc_assert (pass->static_pass_number > 0);
650 gcc_assert (pass_tab.exists ());
652 pass_tab[pass->static_pass_number] = (*p)->unique_name;
654 return 1;
657 /* The function traverses NAME_TO_PASS_MAP and creates a pass info
658 table for dumping purpose. */
660 static void
661 create_pass_tab (void)
663 if (!flag_dump_passes)
664 return;
666 pass_tab.safe_grow_cleared (g->get_passes ()->passes_by_id_size + 1);
667 name_to_pass_map.traverse <void *, passes_pass_traverse> (NULL);
670 static bool override_gate_status (struct opt_pass *, tree, bool);
672 /* Dump the instantiated name for PASS. IS_ON indicates if PASS
673 is turned on or not. */
675 static void
676 dump_one_pass (struct opt_pass *pass, int pass_indent)
678 int indent = 3 * pass_indent;
679 const char *pn;
680 bool is_on, is_really_on;
682 is_on = (pass->gate == NULL) ? true : pass->gate();
683 is_really_on = override_gate_status (pass, current_function_decl, is_on);
685 if (pass->static_pass_number <= 0)
686 pn = pass->name;
687 else
688 pn = pass_tab[pass->static_pass_number];
690 fprintf (stderr, "%*s%-40s%*s:%s%s\n", indent, " ", pn,
691 (15 - indent < 0 ? 0 : 15 - indent), " ",
692 is_on ? " ON" : " OFF",
693 ((!is_on) == (!is_really_on) ? ""
694 : (is_really_on ? " (FORCED_ON)" : " (FORCED_OFF)")));
697 /* Dump pass list PASS with indentation INDENT. */
699 static void
700 dump_pass_list (struct opt_pass *pass, int indent)
704 dump_one_pass (pass, indent);
705 if (pass->sub)
706 dump_pass_list (pass->sub, indent + 1);
707 pass = pass->next;
709 while (pass);
712 /* Dump all optimization passes. */
714 void
715 dump_passes (void)
717 g->get_passes ()->dump_passes ();
720 void
721 pass_manager::dump_passes () const
723 struct cgraph_node *n, *node = NULL;
725 create_pass_tab();
727 FOR_EACH_FUNCTION (n)
728 if (DECL_STRUCT_FUNCTION (n->symbol.decl))
730 node = n;
731 break;
734 if (!node)
735 return;
737 push_cfun (DECL_STRUCT_FUNCTION (node->symbol.decl));
739 dump_pass_list (all_lowering_passes, 1);
740 dump_pass_list (all_small_ipa_passes, 1);
741 dump_pass_list (all_regular_ipa_passes, 1);
742 dump_pass_list (all_lto_gen_passes, 1);
743 dump_pass_list (all_late_ipa_passes, 1);
744 dump_pass_list (all_passes, 1);
746 pop_cfun ();
750 /* Returns the pass with NAME. */
752 static struct opt_pass *
753 get_pass_by_name (const char *name)
755 struct pass_registry **slot, pr;
757 pr.unique_name = name;
758 slot = name_to_pass_map.find_slot (&pr, NO_INSERT);
760 if (!slot || !*slot)
761 return NULL;
763 return (*slot)->pass;
767 /* Range [start, last]. */
769 struct uid_range
771 unsigned int start;
772 unsigned int last;
773 const char *assem_name;
774 struct uid_range *next;
777 typedef struct uid_range *uid_range_p;
780 static vec<uid_range_p>
781 enabled_pass_uid_range_tab = vNULL;
782 static vec<uid_range_p>
783 disabled_pass_uid_range_tab = vNULL;
786 /* Parse option string for -fdisable- and -fenable-
787 The syntax of the options:
789 -fenable-<pass_name>
790 -fdisable-<pass_name>
792 -fenable-<pass_name>=s1:e1,s2:e2,...
793 -fdisable-<pass_name>=s1:e1,s2:e2,...
796 static void
797 enable_disable_pass (const char *arg, bool is_enable)
799 struct opt_pass *pass;
800 char *range_str, *phase_name;
801 char *argstr = xstrdup (arg);
802 vec<uid_range_p> *tab = 0;
804 range_str = strchr (argstr,'=');
805 if (range_str)
807 *range_str = '\0';
808 range_str++;
811 phase_name = argstr;
812 if (!*phase_name)
814 if (is_enable)
815 error ("unrecognized option -fenable");
816 else
817 error ("unrecognized option -fdisable");
818 free (argstr);
819 return;
821 pass = get_pass_by_name (phase_name);
822 if (!pass || pass->static_pass_number == -1)
824 if (is_enable)
825 error ("unknown pass %s specified in -fenable", phase_name);
826 else
827 error ("unknown pass %s specified in -fdisable", phase_name);
828 free (argstr);
829 return;
832 if (is_enable)
833 tab = &enabled_pass_uid_range_tab;
834 else
835 tab = &disabled_pass_uid_range_tab;
837 if ((unsigned) pass->static_pass_number >= tab->length ())
838 tab->safe_grow_cleared (pass->static_pass_number + 1);
840 if (!range_str)
842 uid_range_p slot;
843 uid_range_p new_range = XCNEW (struct uid_range);
845 new_range->start = 0;
846 new_range->last = (unsigned)-1;
848 slot = (*tab)[pass->static_pass_number];
849 new_range->next = slot;
850 (*tab)[pass->static_pass_number] = new_range;
851 if (is_enable)
852 inform (UNKNOWN_LOCATION, "enable pass %s for functions in the range "
853 "of [%u, %u]", phase_name, new_range->start, new_range->last);
854 else
855 inform (UNKNOWN_LOCATION, "disable pass %s for functions in the range "
856 "of [%u, %u]", phase_name, new_range->start, new_range->last);
858 else
860 char *next_range = NULL;
861 char *one_range = range_str;
862 char *end_val = NULL;
866 uid_range_p slot;
867 uid_range_p new_range;
868 char *invalid = NULL;
869 long start;
870 char *func_name = NULL;
872 next_range = strchr (one_range, ',');
873 if (next_range)
875 *next_range = '\0';
876 next_range++;
879 end_val = strchr (one_range, ':');
880 if (end_val)
882 *end_val = '\0';
883 end_val++;
885 start = strtol (one_range, &invalid, 10);
886 if (*invalid || start < 0)
888 if (end_val || (one_range[0] >= '0'
889 && one_range[0] <= '9'))
891 error ("Invalid range %s in option %s",
892 one_range,
893 is_enable ? "-fenable" : "-fdisable");
894 free (argstr);
895 return;
897 func_name = one_range;
899 if (!end_val)
901 new_range = XCNEW (struct uid_range);
902 if (!func_name)
904 new_range->start = (unsigned) start;
905 new_range->last = (unsigned) start;
907 else
909 new_range->start = (unsigned) -1;
910 new_range->last = (unsigned) -1;
911 new_range->assem_name = xstrdup (func_name);
914 else
916 long last = strtol (end_val, &invalid, 10);
917 if (*invalid || last < start)
919 error ("Invalid range %s in option %s",
920 end_val,
921 is_enable ? "-fenable" : "-fdisable");
922 free (argstr);
923 return;
925 new_range = XCNEW (struct uid_range);
926 new_range->start = (unsigned) start;
927 new_range->last = (unsigned) last;
930 slot = (*tab)[pass->static_pass_number];
931 new_range->next = slot;
932 (*tab)[pass->static_pass_number] = new_range;
933 if (is_enable)
935 if (new_range->assem_name)
936 inform (UNKNOWN_LOCATION,
937 "enable pass %s for function %s",
938 phase_name, new_range->assem_name);
939 else
940 inform (UNKNOWN_LOCATION,
941 "enable pass %s for functions in the range of [%u, %u]",
942 phase_name, new_range->start, new_range->last);
944 else
946 if (new_range->assem_name)
947 inform (UNKNOWN_LOCATION,
948 "disable pass %s for function %s",
949 phase_name, new_range->assem_name);
950 else
951 inform (UNKNOWN_LOCATION,
952 "disable pass %s for functions in the range of [%u, %u]",
953 phase_name, new_range->start, new_range->last);
956 one_range = next_range;
957 } while (next_range);
960 free (argstr);
963 /* Enable pass specified by ARG. */
965 void
966 enable_pass (const char *arg)
968 enable_disable_pass (arg, true);
971 /* Disable pass specified by ARG. */
973 void
974 disable_pass (const char *arg)
976 enable_disable_pass (arg, false);
979 /* Returns true if PASS is explicitly enabled/disabled for FUNC. */
981 static bool
982 is_pass_explicitly_enabled_or_disabled (struct opt_pass *pass,
983 tree func,
984 vec<uid_range_p> tab)
986 uid_range_p slot, range;
987 int cgraph_uid;
988 const char *aname = NULL;
990 if (!tab.exists ()
991 || (unsigned) pass->static_pass_number >= tab.length ()
992 || pass->static_pass_number == -1)
993 return false;
995 slot = tab[pass->static_pass_number];
996 if (!slot)
997 return false;
999 cgraph_uid = func ? cgraph_get_node (func)->uid : 0;
1000 if (func && DECL_ASSEMBLER_NAME_SET_P (func))
1001 aname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func));
1003 range = slot;
1004 while (range)
1006 if ((unsigned) cgraph_uid >= range->start
1007 && (unsigned) cgraph_uid <= range->last)
1008 return true;
1009 if (range->assem_name && aname
1010 && !strcmp (range->assem_name, aname))
1011 return true;
1012 range = range->next;
1015 return false;
1018 /* Look at the static_pass_number and duplicate the pass
1019 if it is already added to a list. */
1021 static struct opt_pass *
1022 make_pass_instance (struct opt_pass *pass, bool track_duplicates)
1024 /* A nonzero static_pass_number indicates that the
1025 pass is already in the list. */
1026 if (pass->static_pass_number)
1028 struct opt_pass *new_pass;
1030 if (pass->type == GIMPLE_PASS
1031 || pass->type == RTL_PASS
1032 || pass->type == SIMPLE_IPA_PASS)
1034 new_pass = XNEW (struct opt_pass);
1035 memcpy (new_pass, pass, sizeof (struct opt_pass));
1037 else if (pass->type == IPA_PASS)
1039 new_pass = (struct opt_pass *)XNEW (struct ipa_opt_pass_d);
1040 memcpy (new_pass, pass, sizeof (struct ipa_opt_pass_d));
1042 else
1043 gcc_unreachable ();
1045 new_pass->next = NULL;
1047 new_pass->todo_flags_start &= ~TODO_mark_first_instance;
1049 /* Indicate to register_dump_files that this pass has duplicates,
1050 and so it should rename the dump file. The first instance will
1051 be -1, and be number of duplicates = -static_pass_number - 1.
1052 Subsequent instances will be > 0 and just the duplicate number. */
1053 if ((pass->name && pass->name[0] != '*') || track_duplicates)
1055 pass->static_pass_number -= 1;
1056 new_pass->static_pass_number = -pass->static_pass_number;
1058 return new_pass;
1060 else
1062 pass->todo_flags_start |= TODO_mark_first_instance;
1063 pass->static_pass_number = -1;
1065 invoke_plugin_callbacks (PLUGIN_NEW_PASS, pass);
1067 return pass;
1070 /* Add a pass to the pass list. Duplicate the pass if it's already
1071 in the list. */
1073 static struct opt_pass **
1074 next_pass_1 (struct opt_pass **list, struct opt_pass *pass)
1076 /* Every pass should have a name so that plugins can refer to them. */
1077 gcc_assert (pass->name != NULL);
1079 *list = make_pass_instance (pass, false);
1081 return &(*list)->next;
1084 /* List node for an inserted pass instance. We need to keep track of all
1085 the newly-added pass instances (with 'added_pass_nodes' defined below)
1086 so that we can register their dump files after pass-positioning is finished.
1087 Registering dumping files needs to be post-processed or the
1088 static_pass_number of the opt_pass object would be modified and mess up
1089 the dump file names of future pass instances to be added. */
1091 struct pass_list_node
1093 struct opt_pass *pass;
1094 struct pass_list_node *next;
1097 static struct pass_list_node *added_pass_nodes = NULL;
1098 static struct pass_list_node *prev_added_pass_node;
1100 /* Insert the pass at the proper position. Return true if the pass
1101 is successfully added.
1103 NEW_PASS_INFO - new pass to be inserted
1104 PASS_LIST - root of the pass list to insert the new pass to */
1106 static bool
1107 position_pass (struct register_pass_info *new_pass_info,
1108 struct opt_pass **pass_list)
1110 struct opt_pass *pass = *pass_list, *prev_pass = NULL;
1111 bool success = false;
1113 for ( ; pass; prev_pass = pass, pass = pass->next)
1115 /* Check if the current pass is of the same type as the new pass and
1116 matches the name and the instance number of the reference pass. */
1117 if (pass->type == new_pass_info->pass->type
1118 && pass->name
1119 && !strcmp (pass->name, new_pass_info->reference_pass_name)
1120 && ((new_pass_info->ref_pass_instance_number == 0)
1121 || (new_pass_info->ref_pass_instance_number ==
1122 pass->static_pass_number)
1123 || (new_pass_info->ref_pass_instance_number == 1
1124 && pass->todo_flags_start & TODO_mark_first_instance)))
1126 struct opt_pass *new_pass;
1127 struct pass_list_node *new_pass_node;
1129 new_pass = make_pass_instance (new_pass_info->pass, true);
1131 /* Insert the new pass instance based on the positioning op. */
1132 switch (new_pass_info->pos_op)
1134 case PASS_POS_INSERT_AFTER:
1135 new_pass->next = pass->next;
1136 pass->next = new_pass;
1138 /* Skip newly inserted pass to avoid repeated
1139 insertions in the case where the new pass and the
1140 existing one have the same name. */
1141 pass = new_pass;
1142 break;
1143 case PASS_POS_INSERT_BEFORE:
1144 new_pass->next = pass;
1145 if (prev_pass)
1146 prev_pass->next = new_pass;
1147 else
1148 *pass_list = new_pass;
1149 break;
1150 case PASS_POS_REPLACE:
1151 new_pass->next = pass->next;
1152 if (prev_pass)
1153 prev_pass->next = new_pass;
1154 else
1155 *pass_list = new_pass;
1156 new_pass->sub = pass->sub;
1157 new_pass->tv_id = pass->tv_id;
1158 pass = new_pass;
1159 break;
1160 default:
1161 error ("invalid pass positioning operation");
1162 return false;
1165 /* Save the newly added pass (instance) in the added_pass_nodes
1166 list so that we can register its dump file later. Note that
1167 we cannot register the dump file now because doing so will modify
1168 the static_pass_number of the opt_pass object and therefore
1169 mess up the dump file name of future instances. */
1170 new_pass_node = XCNEW (struct pass_list_node);
1171 new_pass_node->pass = new_pass;
1172 if (!added_pass_nodes)
1173 added_pass_nodes = new_pass_node;
1174 else
1175 prev_added_pass_node->next = new_pass_node;
1176 prev_added_pass_node = new_pass_node;
1178 success = true;
1181 if (pass->sub && position_pass (new_pass_info, &pass->sub))
1182 success = true;
1185 return success;
1188 /* Hooks a new pass into the pass lists.
1190 PASS_INFO - pass information that specifies the opt_pass object,
1191 reference pass, instance number, and how to position
1192 the pass */
1194 void
1195 register_pass (struct register_pass_info *pass_info)
1197 g->get_passes ()->register_pass (pass_info);
1201 void
1202 pass_manager::register_pass (struct register_pass_info *pass_info)
1204 bool all_instances, success;
1206 /* The checks below could fail in buggy plugins. Existing GCC
1207 passes should never fail these checks, so we mention plugin in
1208 the messages. */
1209 if (!pass_info->pass)
1210 fatal_error ("plugin cannot register a missing pass");
1212 if (!pass_info->pass->name)
1213 fatal_error ("plugin cannot register an unnamed pass");
1215 if (!pass_info->reference_pass_name)
1216 fatal_error
1217 ("plugin cannot register pass %qs without reference pass name",
1218 pass_info->pass->name);
1220 /* Try to insert the new pass to the pass lists. We need to check
1221 all five lists as the reference pass could be in one (or all) of
1222 them. */
1223 all_instances = pass_info->ref_pass_instance_number == 0;
1224 success = position_pass (pass_info, &all_lowering_passes);
1225 if (!success || all_instances)
1226 success |= position_pass (pass_info, &all_small_ipa_passes);
1227 if (!success || all_instances)
1228 success |= position_pass (pass_info, &all_regular_ipa_passes);
1229 if (!success || all_instances)
1230 success |= position_pass (pass_info, &all_lto_gen_passes);
1231 if (!success || all_instances)
1232 success |= position_pass (pass_info, &all_late_ipa_passes);
1233 if (!success || all_instances)
1234 success |= position_pass (pass_info, &all_passes);
1235 if (!success)
1236 fatal_error
1237 ("pass %qs not found but is referenced by new pass %qs",
1238 pass_info->reference_pass_name, pass_info->pass->name);
1240 /* OK, we have successfully inserted the new pass. We need to register
1241 the dump files for the newly added pass and its duplicates (if any).
1242 Because the registration of plugin/backend passes happens after the
1243 command-line options are parsed, the options that specify single
1244 pass dumping (e.g. -fdump-tree-PASSNAME) cannot be used for new
1245 passes. Therefore we currently can only enable dumping of
1246 new passes when the 'dump-all' flags (e.g. -fdump-tree-all)
1247 are specified. While doing so, we also delete the pass_list_node
1248 objects created during pass positioning. */
1249 while (added_pass_nodes)
1251 struct pass_list_node *next_node = added_pass_nodes->next;
1252 enum tree_dump_index tdi;
1253 register_one_dump_file (added_pass_nodes->pass);
1254 if (added_pass_nodes->pass->type == SIMPLE_IPA_PASS
1255 || added_pass_nodes->pass->type == IPA_PASS)
1256 tdi = TDI_ipa_all;
1257 else if (added_pass_nodes->pass->type == GIMPLE_PASS)
1258 tdi = TDI_tree_all;
1259 else
1260 tdi = TDI_rtl_all;
1261 /* Check if dump-all flag is specified. */
1262 if (get_dump_file_info (tdi)->pstate)
1263 get_dump_file_info (added_pass_nodes->pass->static_pass_number)
1264 ->pstate = get_dump_file_info (tdi)->pstate;
1265 XDELETE (added_pass_nodes);
1266 added_pass_nodes = next_node;
1270 /* Construct the pass tree. The sequencing of passes is driven by
1271 the cgraph routines:
1273 finalize_compilation_unit ()
1274 for each node N in the cgraph
1275 cgraph_analyze_function (N)
1276 cgraph_lower_function (N) -> all_lowering_passes
1278 If we are optimizing, compile is then invoked:
1280 compile ()
1281 ipa_passes () -> all_small_ipa_passes
1282 -> Analysis of all_regular_ipa_passes
1283 * possible LTO streaming at copmilation time *
1284 -> Execution of all_regular_ipa_passes
1285 * possible LTO streaming at link time *
1286 -> all_late_ipa_passes
1287 expand_all_functions ()
1288 for each node N in the cgraph
1289 expand_function (N) -> Transformation of all_regular_ipa_passes
1290 -> all_passes
1293 pass_manager::pass_manager (context *ctxt)
1294 : all_passes(NULL), all_small_ipa_passes(NULL), all_lowering_passes(NULL),
1295 all_regular_ipa_passes(NULL), all_lto_gen_passes(NULL),
1296 all_late_ipa_passes(NULL), passes_by_id(NULL), passes_by_id_size(0),
1297 ctxt_(ctxt)
1299 struct opt_pass **p;
1301 /* Initialize the pass_lists array. */
1302 #define DEF_PASS_LIST(LIST) pass_lists[PASS_LIST_NO_##LIST] = &LIST;
1303 GCC_PASS_LISTS
1304 #undef DEF_PASS_LIST
1306 /* Build the tree of passes. */
1308 #define INSERT_PASSES_AFTER(PASS) \
1309 p = &(PASS);
1311 #define PUSH_INSERT_PASSES_WITHIN(PASS) \
1313 struct opt_pass **p = &(PASS).pass.sub;
1315 #define POP_INSERT_PASSES() \
1318 #define NEXT_PASS(PASS, NUM) (p = next_pass_1 (p, &((PASS).pass)))
1320 #define TERMINATE_PASS_LIST() \
1321 *p = NULL;
1323 #include "pass-instances.def"
1325 #undef INSERT_PASSES_AFTER
1326 #undef PUSH_INSERT_PASSES_WITHIN
1327 #undef POP_INSERT_PASSES
1328 #undef NEXT_PASS
1329 #undef TERMINATE_PASS_LIST
1331 /* Register the passes with the tree dump code. */
1332 register_dump_files (all_lowering_passes, PROP_gimple_any);
1333 register_dump_files (all_small_ipa_passes,
1334 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
1335 | PROP_cfg);
1336 register_dump_files (all_regular_ipa_passes,
1337 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
1338 | PROP_cfg);
1339 register_dump_files (all_lto_gen_passes,
1340 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
1341 | PROP_cfg);
1342 register_dump_files (all_late_ipa_passes,
1343 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
1344 | PROP_cfg);
1345 register_dump_files (all_passes,
1346 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
1347 | PROP_cfg);
1350 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1351 function CALLBACK for every function in the call graph. Otherwise,
1352 call CALLBACK on the current function. */
1354 static void
1355 do_per_function (void (*callback) (void *data), void *data)
1357 if (current_function_decl)
1358 callback (data);
1359 else
1361 struct cgraph_node *node;
1362 FOR_EACH_DEFINED_FUNCTION (node)
1363 if (node->symbol.analyzed && gimple_has_body_p (node->symbol.decl)
1364 && (!node->clone_of || node->symbol.decl != node->clone_of->symbol.decl))
1366 push_cfun (DECL_STRUCT_FUNCTION (node->symbol.decl));
1367 callback (data);
1368 if (!flag_wpa)
1370 free_dominance_info (CDI_DOMINATORS);
1371 free_dominance_info (CDI_POST_DOMINATORS);
1373 pop_cfun ();
1374 ggc_collect ();
1379 /* Because inlining might remove no-longer reachable nodes, we need to
1380 keep the array visible to garbage collector to avoid reading collected
1381 out nodes. */
1382 static int nnodes;
1383 static GTY ((length ("nnodes"))) cgraph_node_ptr *order;
1385 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1386 function CALLBACK for every function in the call graph. Otherwise,
1387 call CALLBACK on the current function.
1388 This function is global so that plugins can use it. */
1389 void
1390 do_per_function_toporder (void (*callback) (void *data), void *data)
1392 int i;
1394 if (current_function_decl)
1395 callback (data);
1396 else
1398 gcc_assert (!order);
1399 order = ggc_alloc_vec_cgraph_node_ptr (cgraph_n_nodes);
1400 nnodes = ipa_reverse_postorder (order);
1401 for (i = nnodes - 1; i >= 0; i--)
1402 order[i]->process = 1;
1403 for (i = nnodes - 1; i >= 0; i--)
1405 struct cgraph_node *node = order[i];
1407 /* Allow possibly removed nodes to be garbage collected. */
1408 order[i] = NULL;
1409 node->process = 0;
1410 if (cgraph_function_with_gimple_body_p (node))
1412 push_cfun (DECL_STRUCT_FUNCTION (node->symbol.decl));
1413 callback (data);
1414 free_dominance_info (CDI_DOMINATORS);
1415 free_dominance_info (CDI_POST_DOMINATORS);
1416 pop_cfun ();
1417 ggc_collect ();
1421 ggc_free (order);
1422 order = NULL;
1423 nnodes = 0;
1426 /* Helper function to perform function body dump. */
1428 static void
1429 execute_function_dump (void *data ATTRIBUTE_UNUSED)
1431 if (dump_file && current_function_decl)
1433 if (cfun->curr_properties & PROP_trees)
1434 dump_function_to_file (current_function_decl, dump_file, dump_flags);
1435 else
1436 print_rtl_with_bb (dump_file, get_insns (), dump_flags);
1438 /* Flush the file. If verification fails, we won't be able to
1439 close the file before aborting. */
1440 fflush (dump_file);
1442 if ((cfun->curr_properties & PROP_cfg)
1443 && (dump_flags & TDF_GRAPH))
1444 print_graph_cfg (dump_file_name, cfun);
1448 static struct profile_record *profile_record;
1450 /* Do profile consistency book-keeping for the pass with static number INDEX.
1451 If SUBPASS is zero, we run _before_ the pass, and if SUBPASS is one, then
1452 we run _after_ the pass. RUN is true if the pass really runs, or FALSE
1453 if we are only book-keeping on passes that may have selectively disabled
1454 themselves on a given function. */
1455 static void
1456 check_profile_consistency (int index, int subpass, bool run)
1458 pass_manager *passes = g->get_passes ();
1459 if (index == -1)
1460 return;
1461 if (!profile_record)
1462 profile_record = XCNEWVEC (struct profile_record,
1463 passes->passes_by_id_size);
1464 gcc_assert (index < passes->passes_by_id_size && index >= 0);
1465 gcc_assert (subpass < 2);
1466 profile_record[index].run |= run;
1467 account_profile_record (&profile_record[index], subpass);
1470 /* Output profile consistency. */
1472 void
1473 dump_profile_report (void)
1475 g->get_passes ()->dump_profile_report ();
1478 void
1479 pass_manager::dump_profile_report () const
1481 int i, j;
1482 int last_freq_in = 0, last_count_in = 0, last_freq_out = 0, last_count_out = 0;
1483 gcov_type last_time = 0, last_size = 0;
1484 double rel_time_change, rel_size_change;
1485 int last_reported = 0;
1487 if (!profile_record)
1488 return;
1489 fprintf (stderr, "\nProfile consistency report:\n\n");
1490 fprintf (stderr, "Pass name |mismatch in |mismated out|Overall\n");
1491 fprintf (stderr, " |freq count |freq count |size time\n");
1493 for (i = 0; i < passes_by_id_size; i++)
1494 for (j = 0 ; j < 2; j++)
1495 if (profile_record[i].run)
1497 if (last_time)
1498 rel_time_change = (profile_record[i].time[j]
1499 - (double)last_time) * 100 / (double)last_time;
1500 else
1501 rel_time_change = 0;
1502 if (last_size)
1503 rel_size_change = (profile_record[i].size[j]
1504 - (double)last_size) * 100 / (double)last_size;
1505 else
1506 rel_size_change = 0;
1508 if (profile_record[i].num_mismatched_freq_in[j] != last_freq_in
1509 || profile_record[i].num_mismatched_freq_out[j] != last_freq_out
1510 || profile_record[i].num_mismatched_count_in[j] != last_count_in
1511 || profile_record[i].num_mismatched_count_out[j] != last_count_out
1512 || rel_time_change || rel_size_change)
1514 last_reported = i;
1515 fprintf (stderr, "%-20s %s",
1516 passes_by_id [i]->name,
1517 j ? "(after TODO)" : " ");
1518 if (profile_record[i].num_mismatched_freq_in[j] != last_freq_in)
1519 fprintf (stderr, "| %+5i",
1520 profile_record[i].num_mismatched_freq_in[j]
1521 - last_freq_in);
1522 else
1523 fprintf (stderr, "| ");
1524 if (profile_record[i].num_mismatched_count_in[j] != last_count_in)
1525 fprintf (stderr, " %+5i",
1526 profile_record[i].num_mismatched_count_in[j]
1527 - last_count_in);
1528 else
1529 fprintf (stderr, " ");
1530 if (profile_record[i].num_mismatched_freq_out[j] != last_freq_out)
1531 fprintf (stderr, "| %+5i",
1532 profile_record[i].num_mismatched_freq_out[j]
1533 - last_freq_out);
1534 else
1535 fprintf (stderr, "| ");
1536 if (profile_record[i].num_mismatched_count_out[j] != last_count_out)
1537 fprintf (stderr, " %+5i",
1538 profile_record[i].num_mismatched_count_out[j]
1539 - last_count_out);
1540 else
1541 fprintf (stderr, " ");
1543 /* Size/time units change across gimple and RTL. */
1544 if (i == pass_expand.pass.static_pass_number)
1545 fprintf (stderr, "|----------");
1546 else
1548 if (rel_size_change)
1549 fprintf (stderr, "| %+8.4f%%", rel_size_change);
1550 else
1551 fprintf (stderr, "| ");
1552 if (rel_time_change)
1553 fprintf (stderr, " %+8.4f%%", rel_time_change);
1555 fprintf (stderr, "\n");
1556 last_freq_in = profile_record[i].num_mismatched_freq_in[j];
1557 last_freq_out = profile_record[i].num_mismatched_freq_out[j];
1558 last_count_in = profile_record[i].num_mismatched_count_in[j];
1559 last_count_out = profile_record[i].num_mismatched_count_out[j];
1561 else if (j && last_reported != i)
1563 last_reported = i;
1564 fprintf (stderr, "%-20s ------------| | |\n",
1565 passes_by_id [i]->name);
1567 last_time = profile_record[i].time[j];
1568 last_size = profile_record[i].size[j];
1572 /* Perform all TODO actions that ought to be done on each function. */
1574 static void
1575 execute_function_todo (void *data)
1577 unsigned int flags = (size_t)data;
1578 flags &= ~cfun->last_verified;
1579 if (!flags)
1580 return;
1582 /* Always cleanup the CFG before trying to update SSA. */
1583 if (flags & TODO_cleanup_cfg)
1585 cleanup_tree_cfg ();
1587 /* When cleanup_tree_cfg merges consecutive blocks, it may
1588 perform some simplistic propagation when removing single
1589 valued PHI nodes. This propagation may, in turn, cause the
1590 SSA form to become out-of-date (see PR 22037). So, even
1591 if the parent pass had not scheduled an SSA update, we may
1592 still need to do one. */
1593 if (!(flags & TODO_update_ssa_any) && need_ssa_update_p (cfun))
1594 flags |= TODO_update_ssa;
1597 if (flags & TODO_update_ssa_any)
1599 unsigned update_flags = flags & TODO_update_ssa_any;
1600 update_ssa (update_flags);
1601 cfun->last_verified &= ~TODO_verify_ssa;
1604 if (flag_tree_pta && (flags & TODO_rebuild_alias))
1605 compute_may_aliases ();
1607 if (optimize && (flags & TODO_update_address_taken))
1608 execute_update_addresses_taken ();
1610 if (flags & TODO_remove_unused_locals)
1611 remove_unused_locals ();
1613 if (flags & TODO_rebuild_frequencies)
1614 rebuild_frequencies ();
1616 if (flags & TODO_rebuild_cgraph_edges)
1617 rebuild_cgraph_edges ();
1619 /* If we've seen errors do not bother running any verifiers. */
1620 if (seen_error ())
1621 return;
1623 #if defined ENABLE_CHECKING
1624 if (flags & TODO_verify_ssa
1625 || (current_loops && loops_state_satisfies_p (LOOP_CLOSED_SSA)))
1627 verify_gimple_in_cfg (cfun);
1628 verify_ssa (true);
1630 else if (flags & TODO_verify_stmts)
1631 verify_gimple_in_cfg (cfun);
1632 if (flags & TODO_verify_flow)
1633 verify_flow_info ();
1634 if (current_loops && loops_state_satisfies_p (LOOP_CLOSED_SSA))
1635 verify_loop_closed_ssa (false);
1636 if (flags & TODO_verify_rtl_sharing)
1637 verify_rtl_sharing ();
1638 #endif
1640 cfun->last_verified = flags & TODO_verify_all;
1643 /* Perform all TODO actions. */
1644 static void
1645 execute_todo (unsigned int flags)
1647 #if defined ENABLE_CHECKING
1648 if (cfun
1649 && need_ssa_update_p (cfun))
1650 gcc_assert (flags & TODO_update_ssa_any);
1651 #endif
1653 timevar_push (TV_TODO);
1655 /* Inform the pass whether it is the first time it is run. */
1656 first_pass_instance = (flags & TODO_mark_first_instance) != 0;
1658 statistics_fini_pass ();
1660 do_per_function (execute_function_todo, (void *)(size_t) flags);
1662 /* Always remove functions just as before inlining: IPA passes might be
1663 interested to see bodies of extern inline functions that are not inlined
1664 to analyze side effects. The full removal is done just at the end
1665 of IPA pass queue. */
1666 if (flags & TODO_remove_functions)
1668 gcc_assert (!cfun);
1669 symtab_remove_unreachable_nodes (true, dump_file);
1672 if ((flags & TODO_dump_symtab) && dump_file && !current_function_decl)
1674 gcc_assert (!cfun);
1675 dump_symtab (dump_file);
1676 /* Flush the file. If verification fails, we won't be able to
1677 close the file before aborting. */
1678 fflush (dump_file);
1681 /* Now that the dumping has been done, we can get rid of the optional
1682 df problems. */
1683 if (flags & TODO_df_finish)
1684 df_finish_pass ((flags & TODO_df_verify) != 0);
1686 timevar_pop (TV_TODO);
1689 /* Verify invariants that should hold between passes. This is a place
1690 to put simple sanity checks. */
1692 static void
1693 verify_interpass_invariants (void)
1695 gcc_checking_assert (!fold_deferring_overflow_warnings_p ());
1698 /* Clear the last verified flag. */
1700 static void
1701 clear_last_verified (void *data ATTRIBUTE_UNUSED)
1703 cfun->last_verified = 0;
1706 /* Helper function. Verify that the properties has been turn into the
1707 properties expected by the pass. */
1709 #ifdef ENABLE_CHECKING
1710 static void
1711 verify_curr_properties (void *data)
1713 unsigned int props = (size_t)data;
1714 gcc_assert ((cfun->curr_properties & props) == props);
1716 #endif
1718 /* Initialize pass dump file. */
1719 /* This is non-static so that the plugins can use it. */
1721 bool
1722 pass_init_dump_file (struct opt_pass *pass)
1724 /* If a dump file name is present, open it if enabled. */
1725 if (pass->static_pass_number != -1)
1727 timevar_push (TV_DUMP);
1728 bool initializing_dump = !dump_initialized_p (pass->static_pass_number);
1729 dump_file_name = get_dump_file_name (pass->static_pass_number);
1730 dump_start (pass->static_pass_number, &dump_flags);
1731 if (dump_file && current_function_decl)
1732 dump_function_header (dump_file, current_function_decl, dump_flags);
1733 if (initializing_dump
1734 && dump_file && (dump_flags & TDF_GRAPH)
1735 && cfun && (cfun->curr_properties & PROP_cfg))
1736 clean_graph_dump_file (dump_file_name);
1737 timevar_pop (TV_DUMP);
1738 return initializing_dump;
1740 else
1741 return false;
1744 /* Flush PASS dump file. */
1745 /* This is non-static so that plugins can use it. */
1747 void
1748 pass_fini_dump_file (struct opt_pass *pass)
1750 timevar_push (TV_DUMP);
1752 /* Flush and close dump file. */
1753 if (dump_file_name)
1755 free (CONST_CAST (char *, dump_file_name));
1756 dump_file_name = NULL;
1759 dump_finish (pass->static_pass_number);
1760 timevar_pop (TV_DUMP);
1763 /* After executing the pass, apply expected changes to the function
1764 properties. */
1766 static void
1767 update_properties_after_pass (void *data)
1769 struct opt_pass *pass = (struct opt_pass *) data;
1770 cfun->curr_properties = (cfun->curr_properties | pass->properties_provided)
1771 & ~pass->properties_destroyed;
1774 /* Execute summary generation for all of the passes in IPA_PASS. */
1776 void
1777 execute_ipa_summary_passes (struct ipa_opt_pass_d *ipa_pass)
1779 while (ipa_pass)
1781 struct opt_pass *pass = &ipa_pass->pass;
1783 /* Execute all of the IPA_PASSes in the list. */
1784 if (ipa_pass->pass.type == IPA_PASS
1785 && (!pass->gate || pass->gate ())
1786 && ipa_pass->generate_summary)
1788 pass_init_dump_file (pass);
1790 /* If a timevar is present, start it. */
1791 if (pass->tv_id)
1792 timevar_push (pass->tv_id);
1794 ipa_pass->generate_summary ();
1796 /* Stop timevar. */
1797 if (pass->tv_id)
1798 timevar_pop (pass->tv_id);
1800 pass_fini_dump_file (pass);
1802 ipa_pass = (struct ipa_opt_pass_d *)ipa_pass->pass.next;
1806 /* Execute IPA_PASS function transform on NODE. */
1808 static void
1809 execute_one_ipa_transform_pass (struct cgraph_node *node,
1810 struct ipa_opt_pass_d *ipa_pass)
1812 struct opt_pass *pass = &ipa_pass->pass;
1813 unsigned int todo_after = 0;
1815 current_pass = pass;
1816 if (!ipa_pass->function_transform)
1817 return;
1819 /* Note that the folders should only create gimple expressions.
1820 This is a hack until the new folder is ready. */
1821 in_gimple_form = (cfun && (cfun->curr_properties & PROP_trees)) != 0;
1823 pass_init_dump_file (pass);
1825 /* Run pre-pass verification. */
1826 execute_todo (ipa_pass->function_transform_todo_flags_start);
1828 /* If a timevar is present, start it. */
1829 if (pass->tv_id != TV_NONE)
1830 timevar_push (pass->tv_id);
1832 /* Do it! */
1833 todo_after = ipa_pass->function_transform (node);
1835 /* Stop timevar. */
1836 if (pass->tv_id != TV_NONE)
1837 timevar_pop (pass->tv_id);
1839 if (profile_report && cfun && (cfun->curr_properties & PROP_cfg))
1840 check_profile_consistency (pass->static_pass_number, 0, true);
1842 /* Run post-pass cleanup and verification. */
1843 execute_todo (todo_after);
1844 verify_interpass_invariants ();
1845 if (profile_report && cfun && (cfun->curr_properties & PROP_cfg))
1846 check_profile_consistency (pass->static_pass_number, 1, true);
1848 do_per_function (execute_function_dump, NULL);
1849 pass_fini_dump_file (pass);
1851 current_pass = NULL;
1853 /* Signal this is a suitable GC collection point. */
1854 if (!(todo_after & TODO_do_not_ggc_collect))
1855 ggc_collect ();
1858 /* For the current function, execute all ipa transforms. */
1860 void
1861 execute_all_ipa_transforms (void)
1863 struct cgraph_node *node;
1864 if (!cfun)
1865 return;
1866 node = cgraph_get_node (current_function_decl);
1868 if (node->ipa_transforms_to_apply.exists ())
1870 unsigned int i;
1872 for (i = 0; i < node->ipa_transforms_to_apply.length (); i++)
1873 execute_one_ipa_transform_pass (node, node->ipa_transforms_to_apply[i]);
1874 node->ipa_transforms_to_apply.release ();
1878 /* Callback for do_per_function to apply all IPA transforms. */
1880 static void
1881 apply_ipa_transforms (void *data)
1883 struct cgraph_node *node = cgraph_get_node (current_function_decl);
1884 if (!node->global.inlined_to && node->ipa_transforms_to_apply.exists ())
1886 *(bool *)data = true;
1887 execute_all_ipa_transforms();
1888 rebuild_cgraph_edges ();
1892 /* Check if PASS is explicitly disabled or enabled and return
1893 the gate status. FUNC is the function to be processed, and
1894 GATE_STATUS is the gate status determined by pass manager by
1895 default. */
1897 static bool
1898 override_gate_status (struct opt_pass *pass, tree func, bool gate_status)
1900 bool explicitly_enabled = false;
1901 bool explicitly_disabled = false;
1903 explicitly_enabled
1904 = is_pass_explicitly_enabled_or_disabled (pass, func,
1905 enabled_pass_uid_range_tab);
1906 explicitly_disabled
1907 = is_pass_explicitly_enabled_or_disabled (pass, func,
1908 disabled_pass_uid_range_tab);
1910 gate_status = !explicitly_disabled && (gate_status || explicitly_enabled);
1912 return gate_status;
1916 /* Execute PASS. */
1918 bool
1919 execute_one_pass (struct opt_pass *pass)
1921 unsigned int todo_after = 0;
1923 bool gate_status;
1925 /* IPA passes are executed on whole program, so cfun should be NULL.
1926 Other passes need function context set. */
1927 if (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS)
1928 gcc_assert (!cfun && !current_function_decl);
1929 else
1930 gcc_assert (cfun && current_function_decl);
1932 current_pass = pass;
1934 /* Check whether gate check should be avoided.
1935 User controls the value of the gate through the parameter "gate_status". */
1936 gate_status = (pass->gate == NULL) ? true : pass->gate();
1937 gate_status = override_gate_status (pass, current_function_decl, gate_status);
1939 /* Override gate with plugin. */
1940 invoke_plugin_callbacks (PLUGIN_OVERRIDE_GATE, &gate_status);
1942 if (!gate_status)
1944 /* Run so passes selectively disabling themselves on a given function
1945 are not miscounted. */
1946 if (profile_report && cfun && (cfun->curr_properties & PROP_cfg))
1948 check_profile_consistency (pass->static_pass_number, 0, false);
1949 check_profile_consistency (pass->static_pass_number, 1, false);
1951 current_pass = NULL;
1952 return false;
1955 /* Pass execution event trigger: useful to identify passes being
1956 executed. */
1957 invoke_plugin_callbacks (PLUGIN_PASS_EXECUTION, pass);
1959 /* SIPLE IPA passes do not handle callgraphs with IPA transforms in it.
1960 Apply all trnasforms first. */
1961 if (pass->type == SIMPLE_IPA_PASS)
1963 bool applied = false;
1964 do_per_function (apply_ipa_transforms, (void *)&applied);
1965 if (applied)
1966 symtab_remove_unreachable_nodes (true, dump_file);
1967 /* Restore current_pass. */
1968 current_pass = pass;
1971 if (!quiet_flag && !cfun)
1972 fprintf (stderr, " <%s>", pass->name ? pass->name : "");
1974 /* Note that the folders should only create gimple expressions.
1975 This is a hack until the new folder is ready. */
1976 in_gimple_form = (cfun && (cfun->curr_properties & PROP_trees)) != 0;
1978 pass_init_dump_file (pass);
1980 /* Run pre-pass verification. */
1981 execute_todo (pass->todo_flags_start);
1983 #ifdef ENABLE_CHECKING
1984 do_per_function (verify_curr_properties,
1985 (void *)(size_t)pass->properties_required);
1986 #endif
1988 /* If a timevar is present, start it. */
1989 if (pass->tv_id != TV_NONE)
1990 timevar_push (pass->tv_id);
1992 /* Do it! */
1993 if (pass->execute)
1995 todo_after = pass->execute ();
1996 do_per_function (clear_last_verified, NULL);
1999 /* Stop timevar. */
2000 if (pass->tv_id != TV_NONE)
2001 timevar_pop (pass->tv_id);
2003 do_per_function (update_properties_after_pass, pass);
2005 if (profile_report && cfun && (cfun->curr_properties & PROP_cfg))
2006 check_profile_consistency (pass->static_pass_number, 0, true);
2008 /* Run post-pass cleanup and verification. */
2009 execute_todo (todo_after | pass->todo_flags_finish);
2010 if (profile_report && cfun && (cfun->curr_properties & PROP_cfg))
2011 check_profile_consistency (pass->static_pass_number, 1, true);
2013 verify_interpass_invariants ();
2014 do_per_function (execute_function_dump, NULL);
2015 if (pass->type == IPA_PASS)
2017 struct cgraph_node *node;
2018 FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node)
2019 node->ipa_transforms_to_apply.safe_push ((struct ipa_opt_pass_d *)pass);
2022 if (!current_function_decl)
2023 cgraph_process_new_functions ();
2025 pass_fini_dump_file (pass);
2027 if (pass->type != SIMPLE_IPA_PASS && pass->type != IPA_PASS)
2028 gcc_assert (!(cfun->curr_properties & PROP_trees)
2029 || pass->type != RTL_PASS);
2031 current_pass = NULL;
2033 /* Signal this is a suitable GC collection point. */
2034 if (!((todo_after | pass->todo_flags_finish) & TODO_do_not_ggc_collect))
2035 ggc_collect ();
2037 return true;
2040 void
2041 execute_pass_list (struct opt_pass *pass)
2045 gcc_assert (pass->type == GIMPLE_PASS
2046 || pass->type == RTL_PASS);
2047 if (execute_one_pass (pass) && pass->sub)
2048 execute_pass_list (pass->sub);
2049 pass = pass->next;
2051 while (pass);
2054 /* Same as execute_pass_list but assume that subpasses of IPA passes
2055 are local passes. If SET is not NULL, write out summaries of only
2056 those node in SET. */
2058 static void
2059 ipa_write_summaries_2 (struct opt_pass *pass, struct lto_out_decl_state *state)
2061 while (pass)
2063 struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *)pass;
2064 gcc_assert (!current_function_decl);
2065 gcc_assert (!cfun);
2066 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
2067 if (pass->type == IPA_PASS
2068 && ipa_pass->write_summary
2069 && (!pass->gate || pass->gate ()))
2071 /* If a timevar is present, start it. */
2072 if (pass->tv_id)
2073 timevar_push (pass->tv_id);
2075 pass_init_dump_file (pass);
2077 ipa_pass->write_summary ();
2079 pass_fini_dump_file (pass);
2081 /* If a timevar is present, start it. */
2082 if (pass->tv_id)
2083 timevar_pop (pass->tv_id);
2086 if (pass->sub && pass->sub->type != GIMPLE_PASS)
2087 ipa_write_summaries_2 (pass->sub, state);
2089 pass = pass->next;
2093 /* Helper function of ipa_write_summaries. Creates and destroys the
2094 decl state and calls ipa_write_summaries_2 for all passes that have
2095 summaries. SET is the set of nodes to be written. */
2097 static void
2098 ipa_write_summaries_1 (lto_symtab_encoder_t encoder)
2100 pass_manager *passes = g->get_passes ();
2101 struct lto_out_decl_state *state = lto_new_out_decl_state ();
2102 state->symtab_node_encoder = encoder;
2104 lto_push_out_decl_state (state);
2106 gcc_assert (!flag_wpa);
2107 ipa_write_summaries_2 (passes->all_regular_ipa_passes, state);
2108 ipa_write_summaries_2 (passes->all_lto_gen_passes, state);
2110 gcc_assert (lto_get_out_decl_state () == state);
2111 lto_pop_out_decl_state ();
2112 lto_delete_out_decl_state (state);
2115 /* Write out summaries for all the nodes in the callgraph. */
2117 void
2118 ipa_write_summaries (void)
2120 lto_symtab_encoder_t encoder;
2121 int i, order_pos;
2122 struct varpool_node *vnode;
2123 struct cgraph_node *node;
2124 struct cgraph_node **order;
2126 if (!flag_generate_lto || seen_error ())
2127 return;
2129 encoder = lto_symtab_encoder_new (false);
2131 /* Create the callgraph set in the same order used in
2132 cgraph_expand_all_functions. This mostly facilitates debugging,
2133 since it causes the gimple file to be processed in the same order
2134 as the source code. */
2135 order = XCNEWVEC (struct cgraph_node *, cgraph_n_nodes);
2136 order_pos = ipa_reverse_postorder (order);
2137 gcc_assert (order_pos == cgraph_n_nodes);
2139 for (i = order_pos - 1; i >= 0; i--)
2141 struct cgraph_node *node = order[i];
2143 if (cgraph_function_with_gimple_body_p (node))
2145 /* When streaming out references to statements as part of some IPA
2146 pass summary, the statements need to have uids assigned and the
2147 following does that for all the IPA passes here. Naturally, this
2148 ordering then matches the one IPA-passes get in their stmt_fixup
2149 hooks. */
2151 push_cfun (DECL_STRUCT_FUNCTION (node->symbol.decl));
2152 renumber_gimple_stmt_uids ();
2153 pop_cfun ();
2155 if (node->symbol.definition)
2156 lto_set_symtab_encoder_in_partition (encoder, (symtab_node)node);
2159 FOR_EACH_DEFINED_FUNCTION (node)
2160 if (node->symbol.alias)
2161 lto_set_symtab_encoder_in_partition (encoder, (symtab_node)node);
2162 FOR_EACH_DEFINED_VARIABLE (vnode)
2163 lto_set_symtab_encoder_in_partition (encoder, (symtab_node)vnode);
2165 ipa_write_summaries_1 (compute_ltrans_boundary (encoder));
2167 free (order);
2170 /* Same as execute_pass_list but assume that subpasses of IPA passes
2171 are local passes. If SET is not NULL, write out optimization summaries of
2172 only those node in SET. */
2174 static void
2175 ipa_write_optimization_summaries_1 (struct opt_pass *pass, struct lto_out_decl_state *state)
2177 while (pass)
2179 struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *)pass;
2180 gcc_assert (!current_function_decl);
2181 gcc_assert (!cfun);
2182 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
2183 if (pass->type == IPA_PASS
2184 && ipa_pass->write_optimization_summary
2185 && (!pass->gate || pass->gate ()))
2187 /* If a timevar is present, start it. */
2188 if (pass->tv_id)
2189 timevar_push (pass->tv_id);
2191 pass_init_dump_file (pass);
2193 ipa_pass->write_optimization_summary ();
2195 pass_fini_dump_file (pass);
2197 /* If a timevar is present, start it. */
2198 if (pass->tv_id)
2199 timevar_pop (pass->tv_id);
2202 if (pass->sub && pass->sub->type != GIMPLE_PASS)
2203 ipa_write_optimization_summaries_1 (pass->sub, state);
2205 pass = pass->next;
2209 /* Write all the optimization summaries for the cgraph nodes in SET. If SET is
2210 NULL, write out all summaries of all nodes. */
2212 void
2213 ipa_write_optimization_summaries (lto_symtab_encoder_t encoder)
2215 struct lto_out_decl_state *state = lto_new_out_decl_state ();
2216 lto_symtab_encoder_iterator lsei;
2217 state->symtab_node_encoder = encoder;
2219 lto_push_out_decl_state (state);
2220 for (lsei = lsei_start_function_in_partition (encoder);
2221 !lsei_end_p (lsei); lsei_next_function_in_partition (&lsei))
2223 struct cgraph_node *node = lsei_cgraph_node (lsei);
2224 /* When streaming out references to statements as part of some IPA
2225 pass summary, the statements need to have uids assigned.
2227 For functions newly born at WPA stage we need to initialize
2228 the uids here. */
2229 if (node->symbol.definition
2230 && gimple_has_body_p (node->symbol.decl))
2232 push_cfun (DECL_STRUCT_FUNCTION (node->symbol.decl));
2233 renumber_gimple_stmt_uids ();
2234 pop_cfun ();
2238 gcc_assert (flag_wpa);
2239 pass_manager *passes = g->get_passes ();
2240 ipa_write_optimization_summaries_1 (passes->all_regular_ipa_passes, state);
2241 ipa_write_optimization_summaries_1 (passes->all_lto_gen_passes, state);
2243 gcc_assert (lto_get_out_decl_state () == state);
2244 lto_pop_out_decl_state ();
2245 lto_delete_out_decl_state (state);
2248 /* Same as execute_pass_list but assume that subpasses of IPA passes
2249 are local passes. */
2251 static void
2252 ipa_read_summaries_1 (struct opt_pass *pass)
2254 while (pass)
2256 struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *) pass;
2258 gcc_assert (!current_function_decl);
2259 gcc_assert (!cfun);
2260 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
2262 if (pass->gate == NULL || pass->gate ())
2264 if (pass->type == IPA_PASS && ipa_pass->read_summary)
2266 /* If a timevar is present, start it. */
2267 if (pass->tv_id)
2268 timevar_push (pass->tv_id);
2270 pass_init_dump_file (pass);
2272 ipa_pass->read_summary ();
2274 pass_fini_dump_file (pass);
2276 /* Stop timevar. */
2277 if (pass->tv_id)
2278 timevar_pop (pass->tv_id);
2281 if (pass->sub && pass->sub->type != GIMPLE_PASS)
2282 ipa_read_summaries_1 (pass->sub);
2284 pass = pass->next;
2289 /* Read all the summaries for all_regular_ipa_passes and all_lto_gen_passes. */
2291 void
2292 ipa_read_summaries (void)
2294 pass_manager *passes = g->get_passes ();
2295 ipa_read_summaries_1 (passes->all_regular_ipa_passes);
2296 ipa_read_summaries_1 (passes->all_lto_gen_passes);
2299 /* Same as execute_pass_list but assume that subpasses of IPA passes
2300 are local passes. */
2302 static void
2303 ipa_read_optimization_summaries_1 (struct opt_pass *pass)
2305 while (pass)
2307 struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *) pass;
2309 gcc_assert (!current_function_decl);
2310 gcc_assert (!cfun);
2311 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
2313 if (pass->gate == NULL || pass->gate ())
2315 if (pass->type == IPA_PASS && ipa_pass->read_optimization_summary)
2317 /* If a timevar is present, start it. */
2318 if (pass->tv_id)
2319 timevar_push (pass->tv_id);
2321 pass_init_dump_file (pass);
2323 ipa_pass->read_optimization_summary ();
2325 pass_fini_dump_file (pass);
2327 /* Stop timevar. */
2328 if (pass->tv_id)
2329 timevar_pop (pass->tv_id);
2332 if (pass->sub && pass->sub->type != GIMPLE_PASS)
2333 ipa_read_optimization_summaries_1 (pass->sub);
2335 pass = pass->next;
2339 /* Read all the summaries for all_regular_ipa_passes and all_lto_gen_passes. */
2341 void
2342 ipa_read_optimization_summaries (void)
2344 pass_manager *passes = g->get_passes ();
2345 ipa_read_optimization_summaries_1 (passes->all_regular_ipa_passes);
2346 ipa_read_optimization_summaries_1 (passes->all_lto_gen_passes);
2349 /* Same as execute_pass_list but assume that subpasses of IPA passes
2350 are local passes. */
2351 void
2352 execute_ipa_pass_list (struct opt_pass *pass)
2356 gcc_assert (!current_function_decl);
2357 gcc_assert (!cfun);
2358 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
2359 if (execute_one_pass (pass) && pass->sub)
2361 if (pass->sub->type == GIMPLE_PASS)
2363 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_START, NULL);
2364 do_per_function_toporder ((void (*)(void *))execute_pass_list,
2365 pass->sub);
2366 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_END, NULL);
2368 else if (pass->sub->type == SIMPLE_IPA_PASS
2369 || pass->sub->type == IPA_PASS)
2370 execute_ipa_pass_list (pass->sub);
2371 else
2372 gcc_unreachable ();
2374 gcc_assert (!current_function_decl);
2375 cgraph_process_new_functions ();
2376 pass = pass->next;
2378 while (pass);
2381 /* Execute stmt fixup hooks of all passes in PASS for NODE and STMTS. */
2383 static void
2384 execute_ipa_stmt_fixups (struct opt_pass *pass,
2385 struct cgraph_node *node, gimple *stmts)
2387 while (pass)
2389 /* Execute all of the IPA_PASSes in the list. */
2390 if (pass->type == IPA_PASS
2391 && (!pass->gate || pass->gate ()))
2393 struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *) pass;
2395 if (ipa_pass->stmt_fixup)
2397 pass_init_dump_file (pass);
2398 /* If a timevar is present, start it. */
2399 if (pass->tv_id)
2400 timevar_push (pass->tv_id);
2402 ipa_pass->stmt_fixup (node, stmts);
2404 /* Stop timevar. */
2405 if (pass->tv_id)
2406 timevar_pop (pass->tv_id);
2407 pass_fini_dump_file (pass);
2409 if (pass->sub)
2410 execute_ipa_stmt_fixups (pass->sub, node, stmts);
2412 pass = pass->next;
2416 /* Execute stmt fixup hooks of all IPA passes for NODE and STMTS. */
2418 void
2419 execute_all_ipa_stmt_fixups (struct cgraph_node *node, gimple *stmts)
2421 pass_manager *passes = g->get_passes ();
2422 execute_ipa_stmt_fixups (passes->all_regular_ipa_passes, node, stmts);
2426 extern void debug_properties (unsigned int);
2427 extern void dump_properties (FILE *, unsigned int);
2429 DEBUG_FUNCTION void
2430 dump_properties (FILE *dump, unsigned int props)
2432 fprintf (dump, "Properties:\n");
2433 if (props & PROP_gimple_any)
2434 fprintf (dump, "PROP_gimple_any\n");
2435 if (props & PROP_gimple_lcf)
2436 fprintf (dump, "PROP_gimple_lcf\n");
2437 if (props & PROP_gimple_leh)
2438 fprintf (dump, "PROP_gimple_leh\n");
2439 if (props & PROP_cfg)
2440 fprintf (dump, "PROP_cfg\n");
2441 if (props & PROP_ssa)
2442 fprintf (dump, "PROP_ssa\n");
2443 if (props & PROP_no_crit_edges)
2444 fprintf (dump, "PROP_no_crit_edges\n");
2445 if (props & PROP_rtl)
2446 fprintf (dump, "PROP_rtl\n");
2447 if (props & PROP_gimple_lomp)
2448 fprintf (dump, "PROP_gimple_lomp\n");
2449 if (props & PROP_gimple_lcx)
2450 fprintf (dump, "PROP_gimple_lcx\n");
2451 if (props & PROP_gimple_lvec)
2452 fprintf (dump, "PROP_gimple_lvec\n");
2453 if (props & PROP_cfglayout)
2454 fprintf (dump, "PROP_cfglayout\n");
2457 DEBUG_FUNCTION void
2458 debug_properties (unsigned int props)
2460 dump_properties (stderr, props);
2463 /* Called by local passes to see if function is called by already processed nodes.
2464 Because we process nodes in topological order, this means that function is
2465 in recursive cycle or we introduced new direct calls. */
2466 bool
2467 function_called_by_processed_nodes_p (void)
2469 struct cgraph_edge *e;
2470 for (e = cgraph_get_node (current_function_decl)->callers;
2472 e = e->next_caller)
2474 if (e->caller->symbol.decl == current_function_decl)
2475 continue;
2476 if (!cgraph_function_with_gimple_body_p (e->caller))
2477 continue;
2478 if (TREE_ASM_WRITTEN (e->caller->symbol.decl))
2479 continue;
2480 if (!e->caller->process && !e->caller->global.inlined_to)
2481 break;
2483 if (dump_file && e)
2485 fprintf (dump_file, "Already processed call to:\n");
2486 dump_cgraph_node (dump_file, e->caller);
2488 return e != NULL;
2491 #include "gt-passes.h"