* gcc.dg/guality/guality.exp: Skip on AIX.
[official-gcc.git] / gcc / passes.c
blob94fb58688ca07b03fa9f457d1ede64fbcb0fbfa6
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 */
74 /* This is used for debugging. It allows the current pass to printed
75 from anywhere in compilation.
76 The variable current_pass is also used for statistics and plugins. */
77 struct opt_pass *current_pass;
79 static void register_pass_name (struct opt_pass *, const char *);
81 /* Call from anywhere to find out what pass this is. Useful for
82 printing out debugging information deep inside an service
83 routine. */
84 void
85 print_current_pass (FILE *file)
87 if (current_pass)
88 fprintf (file, "current pass = %s (%d)\n",
89 current_pass->name, current_pass->static_pass_number);
90 else
91 fprintf (file, "no current pass.\n");
95 /* Call from the debugger to get the current pass name. */
96 DEBUG_FUNCTION void
97 debug_pass (void)
99 print_current_pass (stderr);
104 /* Global variables used to communicate with passes. */
105 bool in_gimple_form;
106 bool first_pass_instance;
109 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
110 and TYPE_DECL nodes.
112 This does nothing for local (non-static) variables, unless the
113 variable is a register variable with DECL_ASSEMBLER_NAME set. In
114 that case, or if the variable is not an automatic, it sets up the
115 RTL and outputs any assembler code (label definition, storage
116 allocation and initialization).
118 DECL is the declaration. TOP_LEVEL is nonzero
119 if this declaration is not within a function. */
121 void
122 rest_of_decl_compilation (tree decl,
123 int top_level,
124 int at_end)
126 /* We deferred calling assemble_alias so that we could collect
127 other attributes such as visibility. Emit the alias now. */
128 if (!in_lto_p)
130 tree alias;
131 alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
132 if (alias)
134 alias = TREE_VALUE (TREE_VALUE (alias));
135 alias = get_identifier (TREE_STRING_POINTER (alias));
136 /* A quirk of the initial implementation of aliases required that the
137 user add "extern" to all of them. Which is silly, but now
138 historical. Do note that the symbol is in fact locally defined. */
139 DECL_EXTERNAL (decl) = 0;
140 TREE_STATIC (decl) = 1;
141 assemble_alias (decl, alias);
145 /* Can't defer this, because it needs to happen before any
146 later function definitions are processed. */
147 if (DECL_ASSEMBLER_NAME_SET_P (decl) && DECL_REGISTER (decl))
148 make_decl_rtl (decl);
150 /* Forward declarations for nested functions are not "external",
151 but we need to treat them as if they were. */
152 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
153 || TREE_CODE (decl) == FUNCTION_DECL)
155 timevar_push (TV_VARCONST);
157 /* Don't output anything when a tentative file-scope definition
158 is seen. But at end of compilation, do output code for them.
160 We do output all variables and rely on
161 callgraph code to defer them except for forward declarations
162 (see gcc.c-torture/compile/920624-1.c) */
163 if ((at_end
164 || !DECL_DEFER_OUTPUT (decl)
165 || DECL_INITIAL (decl))
166 && (TREE_CODE (decl) != VAR_DECL || !DECL_HAS_VALUE_EXPR_P (decl))
167 && !DECL_EXTERNAL (decl))
169 /* When reading LTO unit, we also read varpool, so do not
170 rebuild it. */
171 if (in_lto_p && !at_end)
173 else if (TREE_CODE (decl) != FUNCTION_DECL)
174 varpool_finalize_decl (decl);
177 #ifdef ASM_FINISH_DECLARE_OBJECT
178 if (decl == last_assemble_variable_decl)
180 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
181 top_level, at_end);
183 #endif
185 timevar_pop (TV_VARCONST);
187 else if (TREE_CODE (decl) == TYPE_DECL
188 /* Like in rest_of_type_compilation, avoid confusing the debug
189 information machinery when there are errors. */
190 && !seen_error ())
192 timevar_push (TV_SYMOUT);
193 debug_hooks->type_decl (decl, !top_level);
194 timevar_pop (TV_SYMOUT);
197 /* Let cgraph know about the existence of variables. */
198 if (in_lto_p && !at_end)
200 else if (TREE_CODE (decl) == VAR_DECL && !DECL_EXTERNAL (decl)
201 && TREE_STATIC (decl))
202 varpool_node_for_decl (decl);
205 /* Called after finishing a record, union or enumeral type. */
207 void
208 rest_of_type_compilation (tree type, int toplev)
210 /* Avoid confusing the debug information machinery when there are
211 errors. */
212 if (seen_error ())
213 return;
215 timevar_push (TV_SYMOUT);
216 debug_hooks->type_decl (TYPE_STUB_DECL (type), !toplev);
217 timevar_pop (TV_SYMOUT);
222 void
223 finish_optimization_passes (void)
225 int i;
226 struct dump_file_info *dfi;
227 char *name;
229 timevar_push (TV_DUMP);
230 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
232 dump_start (pass_profile.pass.static_pass_number, NULL);
233 end_branch_prob ();
234 dump_finish (pass_profile.pass.static_pass_number);
237 if (optimize > 0)
239 dump_start (pass_profile.pass.static_pass_number, NULL);
240 print_combine_total_stats ();
241 dump_finish (pass_profile.pass.static_pass_number);
244 /* Do whatever is necessary to finish printing the graphs. */
245 for (i = TDI_end; (dfi = get_dump_file_info (i)) != NULL; ++i)
246 if (dump_initialized_p (i)
247 && (dfi->pflags & TDF_GRAPH) != 0
248 && (name = get_dump_file_name (i)) != NULL)
250 finish_graph_dump_file (name);
251 free (name);
254 timevar_pop (TV_DUMP);
257 static unsigned int
258 execute_all_early_local_passes (void)
260 /* Once this pass (and its sub-passes) are complete, all functions
261 will be in SSA form. Technically this state change is happening
262 a tad early, since the sub-passes have not yet run, but since
263 none of the sub-passes are IPA passes and do not create new
264 functions, this is ok. We're setting this value for the benefit
265 of IPA passes that follow. */
266 if (cgraph_state < CGRAPH_STATE_IPA_SSA)
267 cgraph_state = CGRAPH_STATE_IPA_SSA;
268 return 0;
271 /* Gate: execute, or not, all of the non-trivial optimizations. */
273 static bool
274 gate_all_early_local_passes (void)
276 /* Don't bother doing anything if the program has errors. */
277 return (!seen_error () && !in_lto_p);
280 struct simple_ipa_opt_pass pass_early_local_passes =
283 SIMPLE_IPA_PASS,
284 "early_local_cleanups", /* name */
285 OPTGROUP_NONE, /* optinfo_flags */
286 gate_all_early_local_passes, /* gate */
287 execute_all_early_local_passes, /* execute */
288 NULL, /* sub */
289 NULL, /* next */
290 0, /* static_pass_number */
291 TV_EARLY_LOCAL, /* tv_id */
292 0, /* properties_required */
293 0, /* properties_provided */
294 0, /* properties_destroyed */
295 0, /* todo_flags_start */
296 TODO_remove_functions /* todo_flags_finish */
300 /* Gate: execute, or not, all of the non-trivial optimizations. */
302 static bool
303 gate_all_early_optimizations (void)
305 return (optimize >= 1
306 /* Don't bother doing anything if the program has errors. */
307 && !seen_error ());
310 static struct gimple_opt_pass pass_all_early_optimizations =
313 GIMPLE_PASS,
314 "early_optimizations", /* name */
315 OPTGROUP_NONE, /* optinfo_flags */
316 gate_all_early_optimizations, /* gate */
317 NULL, /* execute */
318 NULL, /* sub */
319 NULL, /* next */
320 0, /* static_pass_number */
321 TV_NONE, /* tv_id */
322 0, /* properties_required */
323 0, /* properties_provided */
324 0, /* properties_destroyed */
325 0, /* todo_flags_start */
326 0 /* todo_flags_finish */
330 /* Gate: execute, or not, all of the non-trivial optimizations. */
332 static bool
333 gate_all_optimizations (void)
335 return optimize >= 1 && !optimize_debug;
338 static struct gimple_opt_pass pass_all_optimizations =
341 GIMPLE_PASS,
342 "*all_optimizations", /* name */
343 OPTGROUP_NONE, /* optinfo_flags */
344 gate_all_optimizations, /* gate */
345 NULL, /* execute */
346 NULL, /* sub */
347 NULL, /* next */
348 0, /* static_pass_number */
349 TV_OPTIMIZE, /* tv_id */
350 0, /* properties_required */
351 0, /* properties_provided */
352 0, /* properties_destroyed */
353 0, /* todo_flags_start */
354 0 /* todo_flags_finish */
358 /* Gate: execute, or not, all of the non-trivial optimizations. */
360 static bool
361 gate_all_optimizations_g (void)
363 return optimize >= 1 && optimize_debug;
366 static struct gimple_opt_pass pass_all_optimizations_g =
369 GIMPLE_PASS,
370 "*all_optimizations_g", /* name */
371 OPTGROUP_NONE, /* optinfo_flags */
372 gate_all_optimizations_g, /* gate */
373 NULL, /* execute */
374 NULL, /* sub */
375 NULL, /* next */
376 0, /* static_pass_number */
377 TV_OPTIMIZE, /* tv_id */
378 0, /* properties_required */
379 0, /* properties_provided */
380 0, /* properties_destroyed */
381 0, /* todo_flags_start */
382 0 /* todo_flags_finish */
386 static bool
387 gate_rest_of_compilation (void)
389 /* Early return if there were errors. We can run afoul of our
390 consistency checks, and there's not really much point in fixing them. */
391 return !(rtl_dump_and_exit || flag_syntax_only || seen_error ());
394 static struct rtl_opt_pass pass_rest_of_compilation =
397 RTL_PASS,
398 "*rest_of_compilation", /* name */
399 OPTGROUP_NONE, /* optinfo_flags */
400 gate_rest_of_compilation, /* gate */
401 NULL, /* execute */
402 NULL, /* sub */
403 NULL, /* next */
404 0, /* static_pass_number */
405 TV_REST_OF_COMPILATION, /* tv_id */
406 PROP_rtl, /* properties_required */
407 0, /* properties_provided */
408 0, /* properties_destroyed */
409 0, /* todo_flags_start */
410 0 /* todo_flags_finish */
414 static bool
415 gate_postreload (void)
417 return reload_completed;
420 static struct rtl_opt_pass pass_postreload =
423 RTL_PASS,
424 "*all-postreload", /* name */
425 OPTGROUP_NONE, /* optinfo_flags */
426 gate_postreload, /* gate */
427 NULL, /* execute */
428 NULL, /* sub */
429 NULL, /* next */
430 0, /* static_pass_number */
431 TV_POSTRELOAD, /* tv_id */
432 PROP_rtl, /* properties_required */
433 0, /* properties_provided */
434 0, /* properties_destroyed */
435 0, /* todo_flags_start */
436 TODO_verify_rtl_sharing /* todo_flags_finish */
442 /* The root of the compilation pass tree, once constructed. */
443 struct opt_pass *all_passes, *all_small_ipa_passes, *all_lowering_passes,
444 *all_regular_ipa_passes, *all_late_ipa_passes, *all_lto_gen_passes;
446 /* This is used by plugins, and should also be used in register_pass. */
447 #define DEF_PASS_LIST(LIST) &LIST,
448 struct opt_pass **gcc_pass_lists[] = { GCC_PASS_LISTS NULL };
449 #undef DEF_PASS_LIST
451 /* A map from static pass id to optimization pass. */
452 struct opt_pass **passes_by_id;
453 int passes_by_id_size;
455 /* Set the static pass number of pass PASS to ID and record that
456 in the mapping from static pass number to pass. */
458 static void
459 set_pass_for_id (int id, struct opt_pass *pass)
461 pass->static_pass_number = id;
462 if (passes_by_id_size <= id)
464 passes_by_id = XRESIZEVEC (struct opt_pass *, passes_by_id, id + 1);
465 memset (passes_by_id + passes_by_id_size, 0,
466 (id + 1 - passes_by_id_size) * sizeof (void *));
467 passes_by_id_size = id + 1;
469 passes_by_id[id] = pass;
472 /* Return the pass with the static pass number ID. */
474 struct opt_pass *
475 get_pass_for_id (int id)
477 if (id >= passes_by_id_size)
478 return NULL;
479 return passes_by_id[id];
482 /* Iterate over the pass tree allocating dump file numbers. We want
483 to do this depth first, and independent of whether the pass is
484 enabled or not. */
486 void
487 register_one_dump_file (struct opt_pass *pass)
489 char *dot_name, *flag_name, *glob_name;
490 const char *name, *full_name, *prefix;
491 char num[10];
492 int flags, id;
493 int optgroup_flags = OPTGROUP_NONE;
495 /* See below in next_pass_1. */
496 num[0] = '\0';
497 if (pass->static_pass_number != -1)
498 sprintf (num, "%d", ((int) pass->static_pass_number < 0
499 ? 1 : pass->static_pass_number));
501 /* The name is both used to identify the pass for the purposes of plugins,
502 and to specify dump file name and option.
503 The latter two might want something short which is not quite unique; for
504 that reason, we may have a disambiguating prefix, followed by a space
505 to mark the start of the following dump file name / option string. */
506 name = strchr (pass->name, ' ');
507 name = name ? name + 1 : pass->name;
508 dot_name = concat (".", name, num, NULL);
509 if (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS)
511 prefix = "ipa-";
512 flags = TDF_IPA;
513 optgroup_flags |= OPTGROUP_IPA;
515 else if (pass->type == GIMPLE_PASS)
517 prefix = "tree-";
518 flags = TDF_TREE;
520 else
522 prefix = "rtl-";
523 flags = TDF_RTL;
526 flag_name = concat (prefix, name, num, NULL);
527 glob_name = concat (prefix, name, NULL);
528 optgroup_flags |= pass->optinfo_flags;
529 id = dump_register (dot_name, flag_name, glob_name, flags, optgroup_flags);
530 set_pass_for_id (id, pass);
531 full_name = concat (prefix, pass->name, num, NULL);
532 register_pass_name (pass, full_name);
533 free (CONST_CAST (char *, full_name));
536 /* Recursive worker function for register_dump_files. */
538 static int
539 register_dump_files_1 (struct opt_pass *pass, int properties)
543 int new_properties = (properties | pass->properties_provided)
544 & ~pass->properties_destroyed;
546 if (pass->name && pass->name[0] != '*')
547 register_one_dump_file (pass);
549 if (pass->sub)
550 new_properties = register_dump_files_1 (pass->sub, new_properties);
552 /* If we have a gate, combine the properties that we could have with
553 and without the pass being examined. */
554 if (pass->gate)
555 properties &= new_properties;
556 else
557 properties = new_properties;
559 pass = pass->next;
561 while (pass);
563 return properties;
566 /* Register the dump files for the pipeline starting at PASS.
567 PROPERTIES reflects the properties that are guaranteed to be available at
568 the beginning of the pipeline. */
570 static void
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 (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 struct cgraph_node *n, *node = NULL;
719 create_pass_tab();
721 FOR_EACH_FUNCTION (n)
722 if (DECL_STRUCT_FUNCTION (n->symbol.decl))
724 node = n;
725 break;
728 if (!node)
729 return;
731 push_cfun (DECL_STRUCT_FUNCTION (node->symbol.decl));
733 dump_pass_list (all_lowering_passes, 1);
734 dump_pass_list (all_small_ipa_passes, 1);
735 dump_pass_list (all_regular_ipa_passes, 1);
736 dump_pass_list (all_lto_gen_passes, 1);
737 dump_pass_list (all_late_ipa_passes, 1);
738 dump_pass_list (all_passes, 1);
740 pop_cfun ();
744 /* Returns the pass with NAME. */
746 static struct opt_pass *
747 get_pass_by_name (const char *name)
749 struct pass_registry **slot, pr;
751 pr.unique_name = name;
752 slot = name_to_pass_map.find_slot (&pr, NO_INSERT);
754 if (!slot || !*slot)
755 return NULL;
757 return (*slot)->pass;
761 /* Range [start, last]. */
763 struct uid_range
765 unsigned int start;
766 unsigned int last;
767 const char *assem_name;
768 struct uid_range *next;
771 typedef struct uid_range *uid_range_p;
774 static vec<uid_range_p>
775 enabled_pass_uid_range_tab = vNULL;
776 static vec<uid_range_p>
777 disabled_pass_uid_range_tab = vNULL;
780 /* Parse option string for -fdisable- and -fenable-
781 The syntax of the options:
783 -fenable-<pass_name>
784 -fdisable-<pass_name>
786 -fenable-<pass_name>=s1:e1,s2:e2,...
787 -fdisable-<pass_name>=s1:e1,s2:e2,...
790 static void
791 enable_disable_pass (const char *arg, bool is_enable)
793 struct opt_pass *pass;
794 char *range_str, *phase_name;
795 char *argstr = xstrdup (arg);
796 vec<uid_range_p> *tab = 0;
798 range_str = strchr (argstr,'=');
799 if (range_str)
801 *range_str = '\0';
802 range_str++;
805 phase_name = argstr;
806 if (!*phase_name)
808 if (is_enable)
809 error ("unrecognized option -fenable");
810 else
811 error ("unrecognized option -fdisable");
812 free (argstr);
813 return;
815 pass = get_pass_by_name (phase_name);
816 if (!pass || pass->static_pass_number == -1)
818 if (is_enable)
819 error ("unknown pass %s specified in -fenable", phase_name);
820 else
821 error ("unknown pass %s specified in -fdisable", phase_name);
822 free (argstr);
823 return;
826 if (is_enable)
827 tab = &enabled_pass_uid_range_tab;
828 else
829 tab = &disabled_pass_uid_range_tab;
831 if ((unsigned) pass->static_pass_number >= tab->length ())
832 tab->safe_grow_cleared (pass->static_pass_number + 1);
834 if (!range_str)
836 uid_range_p slot;
837 uid_range_p new_range = XCNEW (struct uid_range);
839 new_range->start = 0;
840 new_range->last = (unsigned)-1;
842 slot = (*tab)[pass->static_pass_number];
843 new_range->next = slot;
844 (*tab)[pass->static_pass_number] = new_range;
845 if (is_enable)
846 inform (UNKNOWN_LOCATION, "enable pass %s for functions in the range "
847 "of [%u, %u]", phase_name, new_range->start, new_range->last);
848 else
849 inform (UNKNOWN_LOCATION, "disable pass %s for functions in the range "
850 "of [%u, %u]", phase_name, new_range->start, new_range->last);
852 else
854 char *next_range = NULL;
855 char *one_range = range_str;
856 char *end_val = NULL;
860 uid_range_p slot;
861 uid_range_p new_range;
862 char *invalid = NULL;
863 long start;
864 char *func_name = NULL;
866 next_range = strchr (one_range, ',');
867 if (next_range)
869 *next_range = '\0';
870 next_range++;
873 end_val = strchr (one_range, ':');
874 if (end_val)
876 *end_val = '\0';
877 end_val++;
879 start = strtol (one_range, &invalid, 10);
880 if (*invalid || start < 0)
882 if (end_val || (one_range[0] >= '0'
883 && one_range[0] <= '9'))
885 error ("Invalid range %s in option %s",
886 one_range,
887 is_enable ? "-fenable" : "-fdisable");
888 free (argstr);
889 return;
891 func_name = one_range;
893 if (!end_val)
895 new_range = XCNEW (struct uid_range);
896 if (!func_name)
898 new_range->start = (unsigned) start;
899 new_range->last = (unsigned) start;
901 else
903 new_range->start = (unsigned) -1;
904 new_range->last = (unsigned) -1;
905 new_range->assem_name = xstrdup (func_name);
908 else
910 long last = strtol (end_val, &invalid, 10);
911 if (*invalid || last < start)
913 error ("Invalid range %s in option %s",
914 end_val,
915 is_enable ? "-fenable" : "-fdisable");
916 free (argstr);
917 return;
919 new_range = XCNEW (struct uid_range);
920 new_range->start = (unsigned) start;
921 new_range->last = (unsigned) last;
924 slot = (*tab)[pass->static_pass_number];
925 new_range->next = slot;
926 (*tab)[pass->static_pass_number] = new_range;
927 if (is_enable)
929 if (new_range->assem_name)
930 inform (UNKNOWN_LOCATION,
931 "enable pass %s for function %s",
932 phase_name, new_range->assem_name);
933 else
934 inform (UNKNOWN_LOCATION,
935 "enable pass %s for functions in the range of [%u, %u]",
936 phase_name, new_range->start, new_range->last);
938 else
940 if (new_range->assem_name)
941 inform (UNKNOWN_LOCATION,
942 "disable pass %s for function %s",
943 phase_name, new_range->assem_name);
944 else
945 inform (UNKNOWN_LOCATION,
946 "disable pass %s for functions in the range of [%u, %u]",
947 phase_name, new_range->start, new_range->last);
950 one_range = next_range;
951 } while (next_range);
954 free (argstr);
957 /* Enable pass specified by ARG. */
959 void
960 enable_pass (const char *arg)
962 enable_disable_pass (arg, true);
965 /* Disable pass specified by ARG. */
967 void
968 disable_pass (const char *arg)
970 enable_disable_pass (arg, false);
973 /* Returns true if PASS is explicitly enabled/disabled for FUNC. */
975 static bool
976 is_pass_explicitly_enabled_or_disabled (struct opt_pass *pass,
977 tree func,
978 vec<uid_range_p> tab)
980 uid_range_p slot, range;
981 int cgraph_uid;
982 const char *aname = NULL;
984 if (!tab.exists ()
985 || (unsigned) pass->static_pass_number >= tab.length ()
986 || pass->static_pass_number == -1)
987 return false;
989 slot = tab[pass->static_pass_number];
990 if (!slot)
991 return false;
993 cgraph_uid = func ? cgraph_get_node (func)->uid : 0;
994 if (func && DECL_ASSEMBLER_NAME_SET_P (func))
995 aname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func));
997 range = slot;
998 while (range)
1000 if ((unsigned) cgraph_uid >= range->start
1001 && (unsigned) cgraph_uid <= range->last)
1002 return true;
1003 if (range->assem_name && aname
1004 && !strcmp (range->assem_name, aname))
1005 return true;
1006 range = range->next;
1009 return false;
1012 /* Look at the static_pass_number and duplicate the pass
1013 if it is already added to a list. */
1015 static struct opt_pass *
1016 make_pass_instance (struct opt_pass *pass, bool track_duplicates)
1018 /* A nonzero static_pass_number indicates that the
1019 pass is already in the list. */
1020 if (pass->static_pass_number)
1022 struct opt_pass *new_pass;
1024 if (pass->type == GIMPLE_PASS
1025 || pass->type == RTL_PASS
1026 || pass->type == SIMPLE_IPA_PASS)
1028 new_pass = XNEW (struct opt_pass);
1029 memcpy (new_pass, pass, sizeof (struct opt_pass));
1031 else if (pass->type == IPA_PASS)
1033 new_pass = (struct opt_pass *)XNEW (struct ipa_opt_pass_d);
1034 memcpy (new_pass, pass, sizeof (struct ipa_opt_pass_d));
1036 else
1037 gcc_unreachable ();
1039 new_pass->next = NULL;
1041 new_pass->todo_flags_start &= ~TODO_mark_first_instance;
1043 /* Indicate to register_dump_files that this pass has duplicates,
1044 and so it should rename the dump file. The first instance will
1045 be -1, and be number of duplicates = -static_pass_number - 1.
1046 Subsequent instances will be > 0 and just the duplicate number. */
1047 if ((pass->name && pass->name[0] != '*') || track_duplicates)
1049 pass->static_pass_number -= 1;
1050 new_pass->static_pass_number = -pass->static_pass_number;
1052 return new_pass;
1054 else
1056 pass->todo_flags_start |= TODO_mark_first_instance;
1057 pass->static_pass_number = -1;
1059 invoke_plugin_callbacks (PLUGIN_NEW_PASS, pass);
1061 return pass;
1064 /* Add a pass to the pass list. Duplicate the pass if it's already
1065 in the list. */
1067 static struct opt_pass **
1068 next_pass_1 (struct opt_pass **list, struct opt_pass *pass)
1070 /* Every pass should have a name so that plugins can refer to them. */
1071 gcc_assert (pass->name != NULL);
1073 *list = make_pass_instance (pass, false);
1075 return &(*list)->next;
1078 /* List node for an inserted pass instance. We need to keep track of all
1079 the newly-added pass instances (with 'added_pass_nodes' defined below)
1080 so that we can register their dump files after pass-positioning is finished.
1081 Registering dumping files needs to be post-processed or the
1082 static_pass_number of the opt_pass object would be modified and mess up
1083 the dump file names of future pass instances to be added. */
1085 struct pass_list_node
1087 struct opt_pass *pass;
1088 struct pass_list_node *next;
1091 static struct pass_list_node *added_pass_nodes = NULL;
1092 static struct pass_list_node *prev_added_pass_node;
1094 /* Insert the pass at the proper position. Return true if the pass
1095 is successfully added.
1097 NEW_PASS_INFO - new pass to be inserted
1098 PASS_LIST - root of the pass list to insert the new pass to */
1100 static bool
1101 position_pass (struct register_pass_info *new_pass_info,
1102 struct opt_pass **pass_list)
1104 struct opt_pass *pass = *pass_list, *prev_pass = NULL;
1105 bool success = false;
1107 for ( ; pass; prev_pass = pass, pass = pass->next)
1109 /* Check if the current pass is of the same type as the new pass and
1110 matches the name and the instance number of the reference pass. */
1111 if (pass->type == new_pass_info->pass->type
1112 && pass->name
1113 && !strcmp (pass->name, new_pass_info->reference_pass_name)
1114 && ((new_pass_info->ref_pass_instance_number == 0)
1115 || (new_pass_info->ref_pass_instance_number ==
1116 pass->static_pass_number)
1117 || (new_pass_info->ref_pass_instance_number == 1
1118 && pass->todo_flags_start & TODO_mark_first_instance)))
1120 struct opt_pass *new_pass;
1121 struct pass_list_node *new_pass_node;
1123 new_pass = make_pass_instance (new_pass_info->pass, true);
1125 /* Insert the new pass instance based on the positioning op. */
1126 switch (new_pass_info->pos_op)
1128 case PASS_POS_INSERT_AFTER:
1129 new_pass->next = pass->next;
1130 pass->next = new_pass;
1132 /* Skip newly inserted pass to avoid repeated
1133 insertions in the case where the new pass and the
1134 existing one have the same name. */
1135 pass = new_pass;
1136 break;
1137 case PASS_POS_INSERT_BEFORE:
1138 new_pass->next = pass;
1139 if (prev_pass)
1140 prev_pass->next = new_pass;
1141 else
1142 *pass_list = new_pass;
1143 break;
1144 case PASS_POS_REPLACE:
1145 new_pass->next = pass->next;
1146 if (prev_pass)
1147 prev_pass->next = new_pass;
1148 else
1149 *pass_list = new_pass;
1150 new_pass->sub = pass->sub;
1151 new_pass->tv_id = pass->tv_id;
1152 pass = new_pass;
1153 break;
1154 default:
1155 error ("invalid pass positioning operation");
1156 return false;
1159 /* Save the newly added pass (instance) in the added_pass_nodes
1160 list so that we can register its dump file later. Note that
1161 we cannot register the dump file now because doing so will modify
1162 the static_pass_number of the opt_pass object and therefore
1163 mess up the dump file name of future instances. */
1164 new_pass_node = XCNEW (struct pass_list_node);
1165 new_pass_node->pass = new_pass;
1166 if (!added_pass_nodes)
1167 added_pass_nodes = new_pass_node;
1168 else
1169 prev_added_pass_node->next = new_pass_node;
1170 prev_added_pass_node = new_pass_node;
1172 success = true;
1175 if (pass->sub && position_pass (new_pass_info, &pass->sub))
1176 success = true;
1179 return success;
1182 /* Hooks a new pass into the pass lists.
1184 PASS_INFO - pass information that specifies the opt_pass object,
1185 reference pass, instance number, and how to position
1186 the pass */
1188 void
1189 register_pass (struct register_pass_info *pass_info)
1191 bool all_instances, success;
1193 /* The checks below could fail in buggy plugins. Existing GCC
1194 passes should never fail these checks, so we mention plugin in
1195 the messages. */
1196 if (!pass_info->pass)
1197 fatal_error ("plugin cannot register a missing pass");
1199 if (!pass_info->pass->name)
1200 fatal_error ("plugin cannot register an unnamed pass");
1202 if (!pass_info->reference_pass_name)
1203 fatal_error
1204 ("plugin cannot register pass %qs without reference pass name",
1205 pass_info->pass->name);
1207 /* Try to insert the new pass to the pass lists. We need to check
1208 all five lists as the reference pass could be in one (or all) of
1209 them. */
1210 all_instances = pass_info->ref_pass_instance_number == 0;
1211 success = position_pass (pass_info, &all_lowering_passes);
1212 if (!success || all_instances)
1213 success |= position_pass (pass_info, &all_small_ipa_passes);
1214 if (!success || all_instances)
1215 success |= position_pass (pass_info, &all_regular_ipa_passes);
1216 if (!success || all_instances)
1217 success |= position_pass (pass_info, &all_lto_gen_passes);
1218 if (!success || all_instances)
1219 success |= position_pass (pass_info, &all_late_ipa_passes);
1220 if (!success || all_instances)
1221 success |= position_pass (pass_info, &all_passes);
1222 if (!success)
1223 fatal_error
1224 ("pass %qs not found but is referenced by new pass %qs",
1225 pass_info->reference_pass_name, pass_info->pass->name);
1227 /* OK, we have successfully inserted the new pass. We need to register
1228 the dump files for the newly added pass and its duplicates (if any).
1229 Because the registration of plugin/backend passes happens after the
1230 command-line options are parsed, the options that specify single
1231 pass dumping (e.g. -fdump-tree-PASSNAME) cannot be used for new
1232 passes. Therefore we currently can only enable dumping of
1233 new passes when the 'dump-all' flags (e.g. -fdump-tree-all)
1234 are specified. While doing so, we also delete the pass_list_node
1235 objects created during pass positioning. */
1236 while (added_pass_nodes)
1238 struct pass_list_node *next_node = added_pass_nodes->next;
1239 enum tree_dump_index tdi;
1240 register_one_dump_file (added_pass_nodes->pass);
1241 if (added_pass_nodes->pass->type == SIMPLE_IPA_PASS
1242 || added_pass_nodes->pass->type == IPA_PASS)
1243 tdi = TDI_ipa_all;
1244 else if (added_pass_nodes->pass->type == GIMPLE_PASS)
1245 tdi = TDI_tree_all;
1246 else
1247 tdi = TDI_rtl_all;
1248 /* Check if dump-all flag is specified. */
1249 if (get_dump_file_info (tdi)->pstate)
1250 get_dump_file_info (added_pass_nodes->pass->static_pass_number)
1251 ->pstate = get_dump_file_info (tdi)->pstate;
1252 XDELETE (added_pass_nodes);
1253 added_pass_nodes = next_node;
1257 /* Construct the pass tree. The sequencing of passes is driven by
1258 the cgraph routines:
1260 finalize_compilation_unit ()
1261 for each node N in the cgraph
1262 cgraph_analyze_function (N)
1263 cgraph_lower_function (N) -> all_lowering_passes
1265 If we are optimizing, compile is then invoked:
1267 compile ()
1268 ipa_passes () -> all_small_ipa_passes
1269 -> Analysis of all_regular_ipa_passes
1270 * possible LTO streaming at copmilation time *
1271 -> Execution of all_regular_ipa_passes
1272 * possible LTO streaming at link time *
1273 -> all_late_ipa_passes
1274 expand_all_functions ()
1275 for each node N in the cgraph
1276 expand_function (N) -> Transformation of all_regular_ipa_passes
1277 -> all_passes
1280 void
1281 init_optimization_passes (void)
1283 struct opt_pass **p;
1285 #define INSERT_PASSES_AFTER(PASS) \
1286 p = &(PASS);
1288 #define PUSH_INSERT_PASSES_WITHIN(PASS) \
1290 struct opt_pass **p = &(PASS).pass.sub;
1292 #define POP_INSERT_PASSES() \
1295 #define NEXT_PASS(PASS) (p = next_pass_1 (p, &((PASS).pass)))
1297 #define TERMINATE_PASS_LIST() \
1298 *p = NULL;
1300 #include "passes.def"
1302 #undef INSERT_PASSES_AFTER
1303 #undef PUSH_INSERT_PASSES_WITHIN
1304 #undef POP_INSERT_PASSES
1305 #undef NEXT_PASS
1306 #undef TERMINATE_PASS_LIST
1308 /* Register the passes with the tree dump code. */
1309 register_dump_files (all_lowering_passes, PROP_gimple_any);
1310 register_dump_files (all_small_ipa_passes,
1311 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
1312 | PROP_cfg);
1313 register_dump_files (all_regular_ipa_passes,
1314 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
1315 | PROP_cfg);
1316 register_dump_files (all_lto_gen_passes,
1317 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
1318 | PROP_cfg);
1319 register_dump_files (all_late_ipa_passes,
1320 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
1321 | PROP_cfg);
1322 register_dump_files (all_passes,
1323 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
1324 | PROP_cfg);
1327 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1328 function CALLBACK for every function in the call graph. Otherwise,
1329 call CALLBACK on the current function. */
1331 static void
1332 do_per_function (void (*callback) (void *data), void *data)
1334 if (current_function_decl)
1335 callback (data);
1336 else
1338 struct cgraph_node *node;
1339 FOR_EACH_DEFINED_FUNCTION (node)
1340 if (node->symbol.analyzed && gimple_has_body_p (node->symbol.decl)
1341 && (!node->clone_of || node->symbol.decl != node->clone_of->symbol.decl))
1343 push_cfun (DECL_STRUCT_FUNCTION (node->symbol.decl));
1344 callback (data);
1345 if (!flag_wpa)
1347 free_dominance_info (CDI_DOMINATORS);
1348 free_dominance_info (CDI_POST_DOMINATORS);
1350 pop_cfun ();
1351 ggc_collect ();
1356 /* Because inlining might remove no-longer reachable nodes, we need to
1357 keep the array visible to garbage collector to avoid reading collected
1358 out nodes. */
1359 static int nnodes;
1360 static GTY ((length ("nnodes"))) cgraph_node_ptr *order;
1362 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1363 function CALLBACK for every function in the call graph. Otherwise,
1364 call CALLBACK on the current function.
1365 This function is global so that plugins can use it. */
1366 void
1367 do_per_function_toporder (void (*callback) (void *data), void *data)
1369 int i;
1371 if (current_function_decl)
1372 callback (data);
1373 else
1375 gcc_assert (!order);
1376 order = ggc_alloc_vec_cgraph_node_ptr (cgraph_n_nodes);
1377 nnodes = ipa_reverse_postorder (order);
1378 for (i = nnodes - 1; i >= 0; i--)
1379 order[i]->process = 1;
1380 for (i = nnodes - 1; i >= 0; i--)
1382 struct cgraph_node *node = order[i];
1384 /* Allow possibly removed nodes to be garbage collected. */
1385 order[i] = NULL;
1386 node->process = 0;
1387 if (cgraph_function_with_gimple_body_p (node))
1389 push_cfun (DECL_STRUCT_FUNCTION (node->symbol.decl));
1390 callback (data);
1391 free_dominance_info (CDI_DOMINATORS);
1392 free_dominance_info (CDI_POST_DOMINATORS);
1393 pop_cfun ();
1394 ggc_collect ();
1398 ggc_free (order);
1399 order = NULL;
1400 nnodes = 0;
1403 /* Helper function to perform function body dump. */
1405 static void
1406 execute_function_dump (void *data ATTRIBUTE_UNUSED)
1408 if (dump_file && current_function_decl)
1410 if (cfun->curr_properties & PROP_trees)
1411 dump_function_to_file (current_function_decl, dump_file, dump_flags);
1412 else
1413 print_rtl_with_bb (dump_file, get_insns (), dump_flags);
1415 /* Flush the file. If verification fails, we won't be able to
1416 close the file before aborting. */
1417 fflush (dump_file);
1419 if ((cfun->curr_properties & PROP_cfg)
1420 && (dump_flags & TDF_GRAPH))
1421 print_graph_cfg (dump_file_name, cfun);
1425 static struct profile_record *profile_record;
1427 /* Do profile consistency book-keeping for the pass with static number INDEX.
1428 If SUBPASS is zero, we run _before_ the pass, and if SUBPASS is one, then
1429 we run _after_ the pass. RUN is true if the pass really runs, or FALSE
1430 if we are only book-keeping on passes that may have selectively disabled
1431 themselves on a given function. */
1432 static void
1433 check_profile_consistency (int index, int subpass, bool run)
1435 if (index == -1)
1436 return;
1437 if (!profile_record)
1438 profile_record = XCNEWVEC (struct profile_record,
1439 passes_by_id_size);
1440 gcc_assert (index < passes_by_id_size && index >= 0);
1441 gcc_assert (subpass < 2);
1442 profile_record[index].run |= run;
1443 account_profile_record (&profile_record[index], subpass);
1446 /* Output profile consistency. */
1448 void
1449 dump_profile_report (void)
1451 int i, j;
1452 int last_freq_in = 0, last_count_in = 0, last_freq_out = 0, last_count_out = 0;
1453 gcov_type last_time = 0, last_size = 0;
1454 double rel_time_change, rel_size_change;
1455 int last_reported = 0;
1457 if (!profile_record)
1458 return;
1459 fprintf (stderr, "\nProfile consistency report:\n\n");
1460 fprintf (stderr, "Pass name |mismatch in |mismated out|Overall\n");
1461 fprintf (stderr, " |freq count |freq count |size time\n");
1463 for (i = 0; i < passes_by_id_size; i++)
1464 for (j = 0 ; j < 2; j++)
1465 if (profile_record[i].run)
1467 if (last_time)
1468 rel_time_change = (profile_record[i].time[j]
1469 - (double)last_time) * 100 / (double)last_time;
1470 else
1471 rel_time_change = 0;
1472 if (last_size)
1473 rel_size_change = (profile_record[i].size[j]
1474 - (double)last_size) * 100 / (double)last_size;
1475 else
1476 rel_size_change = 0;
1478 if (profile_record[i].num_mismatched_freq_in[j] != last_freq_in
1479 || profile_record[i].num_mismatched_freq_out[j] != last_freq_out
1480 || profile_record[i].num_mismatched_count_in[j] != last_count_in
1481 || profile_record[i].num_mismatched_count_out[j] != last_count_out
1482 || rel_time_change || rel_size_change)
1484 last_reported = i;
1485 fprintf (stderr, "%-20s %s",
1486 passes_by_id [i]->name,
1487 j ? "(after TODO)" : " ");
1488 if (profile_record[i].num_mismatched_freq_in[j] != last_freq_in)
1489 fprintf (stderr, "| %+5i",
1490 profile_record[i].num_mismatched_freq_in[j]
1491 - last_freq_in);
1492 else
1493 fprintf (stderr, "| ");
1494 if (profile_record[i].num_mismatched_count_in[j] != last_count_in)
1495 fprintf (stderr, " %+5i",
1496 profile_record[i].num_mismatched_count_in[j]
1497 - last_count_in);
1498 else
1499 fprintf (stderr, " ");
1500 if (profile_record[i].num_mismatched_freq_out[j] != last_freq_out)
1501 fprintf (stderr, "| %+5i",
1502 profile_record[i].num_mismatched_freq_out[j]
1503 - last_freq_out);
1504 else
1505 fprintf (stderr, "| ");
1506 if (profile_record[i].num_mismatched_count_out[j] != last_count_out)
1507 fprintf (stderr, " %+5i",
1508 profile_record[i].num_mismatched_count_out[j]
1509 - last_count_out);
1510 else
1511 fprintf (stderr, " ");
1513 /* Size/time units change across gimple and RTL. */
1514 if (i == pass_expand.pass.static_pass_number)
1515 fprintf (stderr, "|----------");
1516 else
1518 if (rel_size_change)
1519 fprintf (stderr, "| %+8.4f%%", rel_size_change);
1520 else
1521 fprintf (stderr, "| ");
1522 if (rel_time_change)
1523 fprintf (stderr, " %+8.4f%%", rel_time_change);
1525 fprintf (stderr, "\n");
1526 last_freq_in = profile_record[i].num_mismatched_freq_in[j];
1527 last_freq_out = profile_record[i].num_mismatched_freq_out[j];
1528 last_count_in = profile_record[i].num_mismatched_count_in[j];
1529 last_count_out = profile_record[i].num_mismatched_count_out[j];
1531 else if (j && last_reported != i)
1533 last_reported = i;
1534 fprintf (stderr, "%-20s ------------| | |\n",
1535 passes_by_id [i]->name);
1537 last_time = profile_record[i].time[j];
1538 last_size = profile_record[i].size[j];
1542 /* Perform all TODO actions that ought to be done on each function. */
1544 static void
1545 execute_function_todo (void *data)
1547 unsigned int flags = (size_t)data;
1548 flags &= ~cfun->last_verified;
1549 if (!flags)
1550 return;
1552 /* Always cleanup the CFG before trying to update SSA. */
1553 if (flags & TODO_cleanup_cfg)
1555 cleanup_tree_cfg ();
1557 /* When cleanup_tree_cfg merges consecutive blocks, it may
1558 perform some simplistic propagation when removing single
1559 valued PHI nodes. This propagation may, in turn, cause the
1560 SSA form to become out-of-date (see PR 22037). So, even
1561 if the parent pass had not scheduled an SSA update, we may
1562 still need to do one. */
1563 if (!(flags & TODO_update_ssa_any) && need_ssa_update_p (cfun))
1564 flags |= TODO_update_ssa;
1567 if (flags & TODO_update_ssa_any)
1569 unsigned update_flags = flags & TODO_update_ssa_any;
1570 update_ssa (update_flags);
1571 cfun->last_verified &= ~TODO_verify_ssa;
1574 if (flag_tree_pta && (flags & TODO_rebuild_alias))
1575 compute_may_aliases ();
1577 if (optimize && (flags & TODO_update_address_taken))
1578 execute_update_addresses_taken ();
1580 if (flags & TODO_remove_unused_locals)
1581 remove_unused_locals ();
1583 if (flags & TODO_rebuild_frequencies)
1584 rebuild_frequencies ();
1586 if (flags & TODO_rebuild_cgraph_edges)
1587 rebuild_cgraph_edges ();
1589 /* If we've seen errors do not bother running any verifiers. */
1590 if (seen_error ())
1591 return;
1593 #if defined ENABLE_CHECKING
1594 if (flags & TODO_verify_ssa
1595 || (current_loops && loops_state_satisfies_p (LOOP_CLOSED_SSA)))
1597 verify_gimple_in_cfg (cfun);
1598 verify_ssa (true);
1600 else if (flags & TODO_verify_stmts)
1601 verify_gimple_in_cfg (cfun);
1602 if (flags & TODO_verify_flow)
1603 verify_flow_info ();
1604 if (current_loops && loops_state_satisfies_p (LOOP_CLOSED_SSA))
1605 verify_loop_closed_ssa (false);
1606 if (flags & TODO_verify_rtl_sharing)
1607 verify_rtl_sharing ();
1608 #endif
1610 cfun->last_verified = flags & TODO_verify_all;
1613 /* Perform all TODO actions. */
1614 static void
1615 execute_todo (unsigned int flags)
1617 #if defined ENABLE_CHECKING
1618 if (cfun
1619 && need_ssa_update_p (cfun))
1620 gcc_assert (flags & TODO_update_ssa_any);
1621 #endif
1623 timevar_push (TV_TODO);
1625 /* Inform the pass whether it is the first time it is run. */
1626 first_pass_instance = (flags & TODO_mark_first_instance) != 0;
1628 statistics_fini_pass ();
1630 do_per_function (execute_function_todo, (void *)(size_t) flags);
1632 /* Always remove functions just as before inlining: IPA passes might be
1633 interested to see bodies of extern inline functions that are not inlined
1634 to analyze side effects. The full removal is done just at the end
1635 of IPA pass queue. */
1636 if (flags & TODO_remove_functions)
1638 gcc_assert (!cfun);
1639 symtab_remove_unreachable_nodes (true, dump_file);
1642 if ((flags & TODO_dump_symtab) && dump_file && !current_function_decl)
1644 gcc_assert (!cfun);
1645 dump_symtab (dump_file);
1646 /* Flush the file. If verification fails, we won't be able to
1647 close the file before aborting. */
1648 fflush (dump_file);
1651 /* Now that the dumping has been done, we can get rid of the optional
1652 df problems. */
1653 if (flags & TODO_df_finish)
1654 df_finish_pass ((flags & TODO_df_verify) != 0);
1656 timevar_pop (TV_TODO);
1659 /* Verify invariants that should hold between passes. This is a place
1660 to put simple sanity checks. */
1662 static void
1663 verify_interpass_invariants (void)
1665 gcc_checking_assert (!fold_deferring_overflow_warnings_p ());
1668 /* Clear the last verified flag. */
1670 static void
1671 clear_last_verified (void *data ATTRIBUTE_UNUSED)
1673 cfun->last_verified = 0;
1676 /* Helper function. Verify that the properties has been turn into the
1677 properties expected by the pass. */
1679 #ifdef ENABLE_CHECKING
1680 static void
1681 verify_curr_properties (void *data)
1683 unsigned int props = (size_t)data;
1684 gcc_assert ((cfun->curr_properties & props) == props);
1686 #endif
1688 /* Initialize pass dump file. */
1689 /* This is non-static so that the plugins can use it. */
1691 bool
1692 pass_init_dump_file (struct opt_pass *pass)
1694 /* If a dump file name is present, open it if enabled. */
1695 if (pass->static_pass_number != -1)
1697 timevar_push (TV_DUMP);
1698 bool initializing_dump = !dump_initialized_p (pass->static_pass_number);
1699 dump_file_name = get_dump_file_name (pass->static_pass_number);
1700 dump_start (pass->static_pass_number, &dump_flags);
1701 if (dump_file && current_function_decl)
1702 dump_function_header (dump_file, current_function_decl, dump_flags);
1703 if (initializing_dump
1704 && dump_file && (dump_flags & TDF_GRAPH)
1705 && cfun && (cfun->curr_properties & PROP_cfg))
1706 clean_graph_dump_file (dump_file_name);
1707 timevar_pop (TV_DUMP);
1708 return initializing_dump;
1710 else
1711 return false;
1714 /* Flush PASS dump file. */
1715 /* This is non-static so that plugins can use it. */
1717 void
1718 pass_fini_dump_file (struct opt_pass *pass)
1720 timevar_push (TV_DUMP);
1722 /* Flush and close dump file. */
1723 if (dump_file_name)
1725 free (CONST_CAST (char *, dump_file_name));
1726 dump_file_name = NULL;
1729 dump_finish (pass->static_pass_number);
1730 timevar_pop (TV_DUMP);
1733 /* After executing the pass, apply expected changes to the function
1734 properties. */
1736 static void
1737 update_properties_after_pass (void *data)
1739 struct opt_pass *pass = (struct opt_pass *) data;
1740 cfun->curr_properties = (cfun->curr_properties | pass->properties_provided)
1741 & ~pass->properties_destroyed;
1744 /* Execute summary generation for all of the passes in IPA_PASS. */
1746 void
1747 execute_ipa_summary_passes (struct ipa_opt_pass_d *ipa_pass)
1749 while (ipa_pass)
1751 struct opt_pass *pass = &ipa_pass->pass;
1753 /* Execute all of the IPA_PASSes in the list. */
1754 if (ipa_pass->pass.type == IPA_PASS
1755 && (!pass->gate || pass->gate ())
1756 && ipa_pass->generate_summary)
1758 pass_init_dump_file (pass);
1760 /* If a timevar is present, start it. */
1761 if (pass->tv_id)
1762 timevar_push (pass->tv_id);
1764 ipa_pass->generate_summary ();
1766 /* Stop timevar. */
1767 if (pass->tv_id)
1768 timevar_pop (pass->tv_id);
1770 pass_fini_dump_file (pass);
1772 ipa_pass = (struct ipa_opt_pass_d *)ipa_pass->pass.next;
1776 /* Execute IPA_PASS function transform on NODE. */
1778 static void
1779 execute_one_ipa_transform_pass (struct cgraph_node *node,
1780 struct ipa_opt_pass_d *ipa_pass)
1782 struct opt_pass *pass = &ipa_pass->pass;
1783 unsigned int todo_after = 0;
1785 current_pass = pass;
1786 if (!ipa_pass->function_transform)
1787 return;
1789 /* Note that the folders should only create gimple expressions.
1790 This is a hack until the new folder is ready. */
1791 in_gimple_form = (cfun && (cfun->curr_properties & PROP_trees)) != 0;
1793 pass_init_dump_file (pass);
1795 /* Run pre-pass verification. */
1796 execute_todo (ipa_pass->function_transform_todo_flags_start);
1798 /* If a timevar is present, start it. */
1799 if (pass->tv_id != TV_NONE)
1800 timevar_push (pass->tv_id);
1802 /* Do it! */
1803 todo_after = ipa_pass->function_transform (node);
1805 /* Stop timevar. */
1806 if (pass->tv_id != TV_NONE)
1807 timevar_pop (pass->tv_id);
1809 if (profile_report && cfun && (cfun->curr_properties & PROP_cfg))
1810 check_profile_consistency (pass->static_pass_number, 0, true);
1812 /* Run post-pass cleanup and verification. */
1813 execute_todo (todo_after);
1814 verify_interpass_invariants ();
1815 if (profile_report && cfun && (cfun->curr_properties & PROP_cfg))
1816 check_profile_consistency (pass->static_pass_number, 1, true);
1818 do_per_function (execute_function_dump, NULL);
1819 pass_fini_dump_file (pass);
1821 current_pass = NULL;
1823 /* Signal this is a suitable GC collection point. */
1824 if (!(todo_after & TODO_do_not_ggc_collect))
1825 ggc_collect ();
1828 /* For the current function, execute all ipa transforms. */
1830 void
1831 execute_all_ipa_transforms (void)
1833 struct cgraph_node *node;
1834 if (!cfun)
1835 return;
1836 node = cgraph_get_node (current_function_decl);
1838 if (node->ipa_transforms_to_apply.exists ())
1840 unsigned int i;
1842 for (i = 0; i < node->ipa_transforms_to_apply.length (); i++)
1843 execute_one_ipa_transform_pass (node, node->ipa_transforms_to_apply[i]);
1844 node->ipa_transforms_to_apply.release ();
1848 /* Callback for do_per_function to apply all IPA transforms. */
1850 static void
1851 apply_ipa_transforms (void *data)
1853 struct cgraph_node *node = cgraph_get_node (current_function_decl);
1854 if (!node->global.inlined_to && node->ipa_transforms_to_apply.exists ())
1856 *(bool *)data = true;
1857 execute_all_ipa_transforms();
1858 rebuild_cgraph_edges ();
1862 /* Check if PASS is explicitly disabled or enabled and return
1863 the gate status. FUNC is the function to be processed, and
1864 GATE_STATUS is the gate status determined by pass manager by
1865 default. */
1867 static bool
1868 override_gate_status (struct opt_pass *pass, tree func, bool gate_status)
1870 bool explicitly_enabled = false;
1871 bool explicitly_disabled = false;
1873 explicitly_enabled
1874 = is_pass_explicitly_enabled_or_disabled (pass, func,
1875 enabled_pass_uid_range_tab);
1876 explicitly_disabled
1877 = is_pass_explicitly_enabled_or_disabled (pass, func,
1878 disabled_pass_uid_range_tab);
1880 gate_status = !explicitly_disabled && (gate_status || explicitly_enabled);
1882 return gate_status;
1886 /* Execute PASS. */
1888 bool
1889 execute_one_pass (struct opt_pass *pass)
1891 unsigned int todo_after = 0;
1893 bool gate_status;
1895 /* IPA passes are executed on whole program, so cfun should be NULL.
1896 Other passes need function context set. */
1897 if (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS)
1898 gcc_assert (!cfun && !current_function_decl);
1899 else
1900 gcc_assert (cfun && current_function_decl);
1902 current_pass = pass;
1904 /* Check whether gate check should be avoided.
1905 User controls the value of the gate through the parameter "gate_status". */
1906 gate_status = (pass->gate == NULL) ? true : pass->gate();
1907 gate_status = override_gate_status (pass, current_function_decl, gate_status);
1909 /* Override gate with plugin. */
1910 invoke_plugin_callbacks (PLUGIN_OVERRIDE_GATE, &gate_status);
1912 if (!gate_status)
1914 /* Run so passes selectively disabling themselves on a given function
1915 are not miscounted. */
1916 if (profile_report && cfun && (cfun->curr_properties & PROP_cfg))
1918 check_profile_consistency (pass->static_pass_number, 0, false);
1919 check_profile_consistency (pass->static_pass_number, 1, false);
1921 current_pass = NULL;
1922 return false;
1925 /* Pass execution event trigger: useful to identify passes being
1926 executed. */
1927 invoke_plugin_callbacks (PLUGIN_PASS_EXECUTION, pass);
1929 /* SIPLE IPA passes do not handle callgraphs with IPA transforms in it.
1930 Apply all trnasforms first. */
1931 if (pass->type == SIMPLE_IPA_PASS)
1933 bool applied = false;
1934 do_per_function (apply_ipa_transforms, (void *)&applied);
1935 if (applied)
1936 symtab_remove_unreachable_nodes (true, dump_file);
1937 /* Restore current_pass. */
1938 current_pass = pass;
1941 if (!quiet_flag && !cfun)
1942 fprintf (stderr, " <%s>", pass->name ? pass->name : "");
1944 /* Note that the folders should only create gimple expressions.
1945 This is a hack until the new folder is ready. */
1946 in_gimple_form = (cfun && (cfun->curr_properties & PROP_trees)) != 0;
1948 pass_init_dump_file (pass);
1950 /* Run pre-pass verification. */
1951 execute_todo (pass->todo_flags_start);
1953 #ifdef ENABLE_CHECKING
1954 do_per_function (verify_curr_properties,
1955 (void *)(size_t)pass->properties_required);
1956 #endif
1958 /* If a timevar is present, start it. */
1959 if (pass->tv_id != TV_NONE)
1960 timevar_push (pass->tv_id);
1962 /* Do it! */
1963 if (pass->execute)
1965 todo_after = pass->execute ();
1966 do_per_function (clear_last_verified, NULL);
1969 /* Stop timevar. */
1970 if (pass->tv_id != TV_NONE)
1971 timevar_pop (pass->tv_id);
1973 do_per_function (update_properties_after_pass, pass);
1975 if (profile_report && cfun && (cfun->curr_properties & PROP_cfg))
1976 check_profile_consistency (pass->static_pass_number, 0, true);
1978 /* Run post-pass cleanup and verification. */
1979 execute_todo (todo_after | pass->todo_flags_finish);
1980 if (profile_report && cfun && (cfun->curr_properties & PROP_cfg))
1981 check_profile_consistency (pass->static_pass_number, 1, true);
1983 verify_interpass_invariants ();
1984 do_per_function (execute_function_dump, NULL);
1985 if (pass->type == IPA_PASS)
1987 struct cgraph_node *node;
1988 FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node)
1989 node->ipa_transforms_to_apply.safe_push ((struct ipa_opt_pass_d *)pass);
1992 if (!current_function_decl)
1993 cgraph_process_new_functions ();
1995 pass_fini_dump_file (pass);
1997 if (pass->type != SIMPLE_IPA_PASS && pass->type != IPA_PASS)
1998 gcc_assert (!(cfun->curr_properties & PROP_trees)
1999 || pass->type != RTL_PASS);
2001 current_pass = NULL;
2003 /* Signal this is a suitable GC collection point. */
2004 if (!((todo_after | pass->todo_flags_finish) & TODO_do_not_ggc_collect))
2005 ggc_collect ();
2007 return true;
2010 void
2011 execute_pass_list (struct opt_pass *pass)
2015 gcc_assert (pass->type == GIMPLE_PASS
2016 || pass->type == RTL_PASS);
2017 if (execute_one_pass (pass) && pass->sub)
2018 execute_pass_list (pass->sub);
2019 pass = pass->next;
2021 while (pass);
2024 /* Same as execute_pass_list but assume that subpasses of IPA passes
2025 are local passes. If SET is not NULL, write out summaries of only
2026 those node in SET. */
2028 static void
2029 ipa_write_summaries_2 (struct opt_pass *pass, struct lto_out_decl_state *state)
2031 while (pass)
2033 struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *)pass;
2034 gcc_assert (!current_function_decl);
2035 gcc_assert (!cfun);
2036 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
2037 if (pass->type == IPA_PASS
2038 && ipa_pass->write_summary
2039 && (!pass->gate || pass->gate ()))
2041 /* If a timevar is present, start it. */
2042 if (pass->tv_id)
2043 timevar_push (pass->tv_id);
2045 pass_init_dump_file (pass);
2047 ipa_pass->write_summary ();
2049 pass_fini_dump_file (pass);
2051 /* If a timevar is present, start it. */
2052 if (pass->tv_id)
2053 timevar_pop (pass->tv_id);
2056 if (pass->sub && pass->sub->type != GIMPLE_PASS)
2057 ipa_write_summaries_2 (pass->sub, state);
2059 pass = pass->next;
2063 /* Helper function of ipa_write_summaries. Creates and destroys the
2064 decl state and calls ipa_write_summaries_2 for all passes that have
2065 summaries. SET is the set of nodes to be written. */
2067 static void
2068 ipa_write_summaries_1 (lto_symtab_encoder_t encoder)
2070 struct lto_out_decl_state *state = lto_new_out_decl_state ();
2071 state->symtab_node_encoder = encoder;
2073 lto_push_out_decl_state (state);
2075 gcc_assert (!flag_wpa);
2076 ipa_write_summaries_2 (all_regular_ipa_passes, state);
2077 ipa_write_summaries_2 (all_lto_gen_passes, state);
2079 gcc_assert (lto_get_out_decl_state () == state);
2080 lto_pop_out_decl_state ();
2081 lto_delete_out_decl_state (state);
2084 /* Write out summaries for all the nodes in the callgraph. */
2086 void
2087 ipa_write_summaries (void)
2089 lto_symtab_encoder_t encoder;
2090 int i, order_pos;
2091 struct varpool_node *vnode;
2092 struct cgraph_node *node;
2093 struct cgraph_node **order;
2095 if (!flag_generate_lto || seen_error ())
2096 return;
2098 encoder = lto_symtab_encoder_new (false);
2100 /* Create the callgraph set in the same order used in
2101 cgraph_expand_all_functions. This mostly facilitates debugging,
2102 since it causes the gimple file to be processed in the same order
2103 as the source code. */
2104 order = XCNEWVEC (struct cgraph_node *, cgraph_n_nodes);
2105 order_pos = ipa_reverse_postorder (order);
2106 gcc_assert (order_pos == cgraph_n_nodes);
2108 for (i = order_pos - 1; i >= 0; i--)
2110 struct cgraph_node *node = order[i];
2112 if (cgraph_function_with_gimple_body_p (node))
2114 /* When streaming out references to statements as part of some IPA
2115 pass summary, the statements need to have uids assigned and the
2116 following does that for all the IPA passes here. Naturally, this
2117 ordering then matches the one IPA-passes get in their stmt_fixup
2118 hooks. */
2120 push_cfun (DECL_STRUCT_FUNCTION (node->symbol.decl));
2121 renumber_gimple_stmt_uids ();
2122 pop_cfun ();
2124 if (node->symbol.definition)
2125 lto_set_symtab_encoder_in_partition (encoder, (symtab_node)node);
2128 FOR_EACH_DEFINED_FUNCTION (node)
2129 if (node->symbol.alias)
2130 lto_set_symtab_encoder_in_partition (encoder, (symtab_node)node);
2131 FOR_EACH_DEFINED_VARIABLE (vnode)
2132 lto_set_symtab_encoder_in_partition (encoder, (symtab_node)vnode);
2134 ipa_write_summaries_1 (compute_ltrans_boundary (encoder));
2136 free (order);
2139 /* Same as execute_pass_list but assume that subpasses of IPA passes
2140 are local passes. If SET is not NULL, write out optimization summaries of
2141 only those node in SET. */
2143 static void
2144 ipa_write_optimization_summaries_1 (struct opt_pass *pass, struct lto_out_decl_state *state)
2146 while (pass)
2148 struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *)pass;
2149 gcc_assert (!current_function_decl);
2150 gcc_assert (!cfun);
2151 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
2152 if (pass->type == IPA_PASS
2153 && ipa_pass->write_optimization_summary
2154 && (!pass->gate || pass->gate ()))
2156 /* If a timevar is present, start it. */
2157 if (pass->tv_id)
2158 timevar_push (pass->tv_id);
2160 pass_init_dump_file (pass);
2162 ipa_pass->write_optimization_summary ();
2164 pass_fini_dump_file (pass);
2166 /* If a timevar is present, start it. */
2167 if (pass->tv_id)
2168 timevar_pop (pass->tv_id);
2171 if (pass->sub && pass->sub->type != GIMPLE_PASS)
2172 ipa_write_optimization_summaries_1 (pass->sub, state);
2174 pass = pass->next;
2178 /* Write all the optimization summaries for the cgraph nodes in SET. If SET is
2179 NULL, write out all summaries of all nodes. */
2181 void
2182 ipa_write_optimization_summaries (lto_symtab_encoder_t encoder)
2184 struct lto_out_decl_state *state = lto_new_out_decl_state ();
2185 lto_symtab_encoder_iterator lsei;
2186 state->symtab_node_encoder = encoder;
2188 lto_push_out_decl_state (state);
2189 for (lsei = lsei_start_function_in_partition (encoder);
2190 !lsei_end_p (lsei); lsei_next_function_in_partition (&lsei))
2192 struct cgraph_node *node = lsei_cgraph_node (lsei);
2193 /* When streaming out references to statements as part of some IPA
2194 pass summary, the statements need to have uids assigned.
2196 For functions newly born at WPA stage we need to initialize
2197 the uids here. */
2198 if (node->symbol.definition
2199 && gimple_has_body_p (node->symbol.decl))
2201 push_cfun (DECL_STRUCT_FUNCTION (node->symbol.decl));
2202 renumber_gimple_stmt_uids ();
2203 pop_cfun ();
2207 gcc_assert (flag_wpa);
2208 ipa_write_optimization_summaries_1 (all_regular_ipa_passes, state);
2209 ipa_write_optimization_summaries_1 (all_lto_gen_passes, state);
2211 gcc_assert (lto_get_out_decl_state () == state);
2212 lto_pop_out_decl_state ();
2213 lto_delete_out_decl_state (state);
2216 /* Same as execute_pass_list but assume that subpasses of IPA passes
2217 are local passes. */
2219 static void
2220 ipa_read_summaries_1 (struct opt_pass *pass)
2222 while (pass)
2224 struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *) pass;
2226 gcc_assert (!current_function_decl);
2227 gcc_assert (!cfun);
2228 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
2230 if (pass->gate == NULL || pass->gate ())
2232 if (pass->type == IPA_PASS && ipa_pass->read_summary)
2234 /* If a timevar is present, start it. */
2235 if (pass->tv_id)
2236 timevar_push (pass->tv_id);
2238 pass_init_dump_file (pass);
2240 ipa_pass->read_summary ();
2242 pass_fini_dump_file (pass);
2244 /* Stop timevar. */
2245 if (pass->tv_id)
2246 timevar_pop (pass->tv_id);
2249 if (pass->sub && pass->sub->type != GIMPLE_PASS)
2250 ipa_read_summaries_1 (pass->sub);
2252 pass = pass->next;
2257 /* Read all the summaries for all_regular_ipa_passes and all_lto_gen_passes. */
2259 void
2260 ipa_read_summaries (void)
2262 ipa_read_summaries_1 (all_regular_ipa_passes);
2263 ipa_read_summaries_1 (all_lto_gen_passes);
2266 /* Same as execute_pass_list but assume that subpasses of IPA passes
2267 are local passes. */
2269 static void
2270 ipa_read_optimization_summaries_1 (struct opt_pass *pass)
2272 while (pass)
2274 struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *) pass;
2276 gcc_assert (!current_function_decl);
2277 gcc_assert (!cfun);
2278 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
2280 if (pass->gate == NULL || pass->gate ())
2282 if (pass->type == IPA_PASS && ipa_pass->read_optimization_summary)
2284 /* If a timevar is present, start it. */
2285 if (pass->tv_id)
2286 timevar_push (pass->tv_id);
2288 pass_init_dump_file (pass);
2290 ipa_pass->read_optimization_summary ();
2292 pass_fini_dump_file (pass);
2294 /* Stop timevar. */
2295 if (pass->tv_id)
2296 timevar_pop (pass->tv_id);
2299 if (pass->sub && pass->sub->type != GIMPLE_PASS)
2300 ipa_read_optimization_summaries_1 (pass->sub);
2302 pass = pass->next;
2306 /* Read all the summaries for all_regular_ipa_passes and all_lto_gen_passes. */
2308 void
2309 ipa_read_optimization_summaries (void)
2311 ipa_read_optimization_summaries_1 (all_regular_ipa_passes);
2312 ipa_read_optimization_summaries_1 (all_lto_gen_passes);
2315 /* Same as execute_pass_list but assume that subpasses of IPA passes
2316 are local passes. */
2317 void
2318 execute_ipa_pass_list (struct opt_pass *pass)
2322 gcc_assert (!current_function_decl);
2323 gcc_assert (!cfun);
2324 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
2325 if (execute_one_pass (pass) && pass->sub)
2327 if (pass->sub->type == GIMPLE_PASS)
2329 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_START, NULL);
2330 do_per_function_toporder ((void (*)(void *))execute_pass_list,
2331 pass->sub);
2332 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_END, NULL);
2334 else if (pass->sub->type == SIMPLE_IPA_PASS
2335 || pass->sub->type == IPA_PASS)
2336 execute_ipa_pass_list (pass->sub);
2337 else
2338 gcc_unreachable ();
2340 gcc_assert (!current_function_decl);
2341 cgraph_process_new_functions ();
2342 pass = pass->next;
2344 while (pass);
2347 /* Execute stmt fixup hooks of all passes in PASS for NODE and STMTS. */
2349 static void
2350 execute_ipa_stmt_fixups (struct opt_pass *pass,
2351 struct cgraph_node *node, gimple *stmts)
2353 while (pass)
2355 /* Execute all of the IPA_PASSes in the list. */
2356 if (pass->type == IPA_PASS
2357 && (!pass->gate || pass->gate ()))
2359 struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *) pass;
2361 if (ipa_pass->stmt_fixup)
2363 pass_init_dump_file (pass);
2364 /* If a timevar is present, start it. */
2365 if (pass->tv_id)
2366 timevar_push (pass->tv_id);
2368 ipa_pass->stmt_fixup (node, stmts);
2370 /* Stop timevar. */
2371 if (pass->tv_id)
2372 timevar_pop (pass->tv_id);
2373 pass_fini_dump_file (pass);
2375 if (pass->sub)
2376 execute_ipa_stmt_fixups (pass->sub, node, stmts);
2378 pass = pass->next;
2382 /* Execute stmt fixup hooks of all IPA passes for NODE and STMTS. */
2384 void
2385 execute_all_ipa_stmt_fixups (struct cgraph_node *node, gimple *stmts)
2387 execute_ipa_stmt_fixups (all_regular_ipa_passes, node, stmts);
2391 extern void debug_properties (unsigned int);
2392 extern void dump_properties (FILE *, unsigned int);
2394 DEBUG_FUNCTION void
2395 dump_properties (FILE *dump, unsigned int props)
2397 fprintf (dump, "Properties:\n");
2398 if (props & PROP_gimple_any)
2399 fprintf (dump, "PROP_gimple_any\n");
2400 if (props & PROP_gimple_lcf)
2401 fprintf (dump, "PROP_gimple_lcf\n");
2402 if (props & PROP_gimple_leh)
2403 fprintf (dump, "PROP_gimple_leh\n");
2404 if (props & PROP_cfg)
2405 fprintf (dump, "PROP_cfg\n");
2406 if (props & PROP_ssa)
2407 fprintf (dump, "PROP_ssa\n");
2408 if (props & PROP_no_crit_edges)
2409 fprintf (dump, "PROP_no_crit_edges\n");
2410 if (props & PROP_rtl)
2411 fprintf (dump, "PROP_rtl\n");
2412 if (props & PROP_gimple_lomp)
2413 fprintf (dump, "PROP_gimple_lomp\n");
2414 if (props & PROP_gimple_lcx)
2415 fprintf (dump, "PROP_gimple_lcx\n");
2416 if (props & PROP_gimple_lvec)
2417 fprintf (dump, "PROP_gimple_lvec\n");
2418 if (props & PROP_cfglayout)
2419 fprintf (dump, "PROP_cfglayout\n");
2422 DEBUG_FUNCTION void
2423 debug_properties (unsigned int props)
2425 dump_properties (stderr, props);
2428 /* Called by local passes to see if function is called by already processed nodes.
2429 Because we process nodes in topological order, this means that function is
2430 in recursive cycle or we introduced new direct calls. */
2431 bool
2432 function_called_by_processed_nodes_p (void)
2434 struct cgraph_edge *e;
2435 for (e = cgraph_get_node (current_function_decl)->callers;
2437 e = e->next_caller)
2439 if (e->caller->symbol.decl == current_function_decl)
2440 continue;
2441 if (!cgraph_function_with_gimple_body_p (e->caller))
2442 continue;
2443 if (TREE_ASM_WRITTEN (e->caller->symbol.decl))
2444 continue;
2445 if (!e->caller->process && !e->caller->global.inlined_to)
2446 break;
2448 if (dump_file && e)
2450 fprintf (dump_file, "Already processed call to:\n");
2451 dump_cgraph_node (dump_file, e->caller);
2453 return e != NULL;
2456 #include "gt-passes.h"