* dwarf2out.c (is_unit_die): New.
[official-gcc.git] / gcc / passes.c
blobbfd4ce34087e7846a06092c352c00db75df43922
1 /* Top level of GCC compilers (cc1, cc1plus, etc.)
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
4 2011, 2012 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 /* This is the top level of cc1/c++.
23 It parses command args, opens files, invokes the various passes
24 in the proper order, and counts the time used by each.
25 Error messages and low-level interface to malloc also handled here. */
27 #include "config.h"
28 #include "system.h"
29 #include "coretypes.h"
30 #include "tm.h"
31 #include "line-map.h"
32 #include "input.h"
33 #include "tree.h"
34 #include "rtl.h"
35 #include "tm_p.h"
36 #include "flags.h"
37 #include "insn-attr.h"
38 #include "insn-config.h"
39 #include "insn-flags.h"
40 #include "hard-reg-set.h"
41 #include "recog.h"
42 #include "output.h"
43 #include "except.h"
44 #include "function.h"
45 #include "toplev.h"
46 #include "expr.h"
47 #include "basic-block.h"
48 #include "intl.h"
49 #include "ggc.h"
50 #include "graph.h"
51 #include "regs.h"
52 #include "timevar.h"
53 #include "diagnostic-core.h"
54 #include "params.h"
55 #include "reload.h"
56 #include "debug.h"
57 #include "target.h"
58 #include "langhooks.h"
59 #include "cfgloop.h"
60 #include "hosthooks.h"
61 #include "cgraph.h"
62 #include "opts.h"
63 #include "coverage.h"
64 #include "value-prof.h"
65 #include "tree-inline.h"
66 #include "tree-flow.h"
67 #include "tree-pass.h"
68 #include "tree-dump.h"
69 #include "df.h"
70 #include "predict.h"
71 #include "lto-streamer.h"
72 #include "plugin.h"
73 #include "ipa-utils.h"
74 #include "tree-pretty-print.h" /* for dump_function_header */
76 /* This is used for debugging. It allows the current pass to printed
77 from anywhere in compilation.
78 The variable current_pass is also used for statistics and plugins. */
79 struct opt_pass *current_pass;
81 static void register_pass_name (struct opt_pass *, const char *);
83 /* Call from anywhere to find out what pass this is. Useful for
84 printing out debugging information deep inside an service
85 routine. */
86 void
87 print_current_pass (FILE *file)
89 if (current_pass)
90 fprintf (file, "current pass = %s (%d)\n",
91 current_pass->name, current_pass->static_pass_number);
92 else
93 fprintf (file, "no current pass.\n");
97 /* Call from the debugger to get the current pass name. */
98 DEBUG_FUNCTION void
99 debug_pass (void)
101 print_current_pass (stderr);
106 /* Global variables used to communicate with passes. */
107 int dump_flags;
108 bool in_gimple_form;
109 bool first_pass_instance;
112 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
113 and TYPE_DECL nodes.
115 This does nothing for local (non-static) variables, unless the
116 variable is a register variable with DECL_ASSEMBLER_NAME set. In
117 that case, or if the variable is not an automatic, it sets up the
118 RTL and outputs any assembler code (label definition, storage
119 allocation and initialization).
121 DECL is the declaration. TOP_LEVEL is nonzero
122 if this declaration is not within a function. */
124 void
125 rest_of_decl_compilation (tree decl,
126 int top_level,
127 int at_end)
129 /* We deferred calling assemble_alias so that we could collect
130 other attributes such as visibility. Emit the alias now. */
131 if (!in_lto_p)
133 tree alias;
134 alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
135 if (alias)
137 alias = TREE_VALUE (TREE_VALUE (alias));
138 alias = get_identifier (TREE_STRING_POINTER (alias));
139 /* A quirk of the initial implementation of aliases required that the
140 user add "extern" to all of them. Which is silly, but now
141 historical. Do note that the symbol is in fact locally defined. */
142 if (!lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))
143 DECL_EXTERNAL (decl) = 0;
144 assemble_alias (decl, alias);
148 /* Can't defer this, because it needs to happen before any
149 later function definitions are processed. */
150 if (DECL_ASSEMBLER_NAME_SET_P (decl) && DECL_REGISTER (decl))
151 make_decl_rtl (decl);
153 /* Forward declarations for nested functions are not "external",
154 but we need to treat them as if they were. */
155 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
156 || TREE_CODE (decl) == FUNCTION_DECL)
158 timevar_push (TV_VARCONST);
160 /* Don't output anything when a tentative file-scope definition
161 is seen. But at end of compilation, do output code for them.
163 We do output all variables and rely on
164 callgraph code to defer them except for forward declarations
165 (see gcc.c-torture/compile/920624-1.c) */
166 if ((at_end
167 || !DECL_DEFER_OUTPUT (decl)
168 || DECL_INITIAL (decl))
169 && (TREE_CODE (decl) != VAR_DECL || !DECL_HAS_VALUE_EXPR_P (decl))
170 && !DECL_EXTERNAL (decl))
172 /* When reading LTO unit, we also read varpool, so do not
173 rebuild it. */
174 if (in_lto_p && !at_end)
176 else if (TREE_CODE (decl) != FUNCTION_DECL)
177 varpool_finalize_decl (decl);
180 #ifdef ASM_FINISH_DECLARE_OBJECT
181 if (decl == last_assemble_variable_decl)
183 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
184 top_level, at_end);
186 #endif
188 timevar_pop (TV_VARCONST);
190 else if (TREE_CODE (decl) == TYPE_DECL
191 /* Like in rest_of_type_compilation, avoid confusing the debug
192 information machinery when there are errors. */
193 && !seen_error ())
195 timevar_push (TV_SYMOUT);
196 debug_hooks->type_decl (decl, !top_level);
197 timevar_pop (TV_SYMOUT);
200 /* Let cgraph know about the existence of variables. */
201 if (in_lto_p && !at_end)
203 else if (TREE_CODE (decl) == VAR_DECL && !DECL_EXTERNAL (decl)
204 && TREE_STATIC (decl))
205 varpool_node (decl);
208 /* Called after finishing a record, union or enumeral type. */
210 void
211 rest_of_type_compilation (tree type, int toplev)
213 /* Avoid confusing the debug information machinery when there are
214 errors. */
215 if (seen_error ())
216 return;
218 timevar_push (TV_SYMOUT);
219 debug_hooks->type_decl (TYPE_STUB_DECL (type), !toplev);
220 timevar_pop (TV_SYMOUT);
225 void
226 finish_optimization_passes (void)
228 int i;
229 struct dump_file_info *dfi;
230 char *name;
232 timevar_push (TV_DUMP);
233 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
235 dump_file = dump_begin (pass_profile.pass.static_pass_number, NULL);
236 end_branch_prob ();
237 if (dump_file)
238 dump_end (pass_profile.pass.static_pass_number, dump_file);
241 if (optimize > 0)
243 dump_file = dump_begin (pass_combine.pass.static_pass_number, NULL);
244 if (dump_file)
246 dump_combine_total_stats (dump_file);
247 dump_end (pass_combine.pass.static_pass_number, dump_file);
251 /* Do whatever is necessary to finish printing the graphs. */
252 if (graph_dump_format != no_graph)
253 for (i = TDI_end; (dfi = get_dump_file_info (i)) != NULL; ++i)
254 if (dump_initialized_p (i)
255 && (dfi->flags & TDF_GRAPH) != 0
256 && (name = get_dump_file_name (i)) != NULL)
258 finish_graph_dump_file (name);
259 free (name);
262 timevar_pop (TV_DUMP);
265 static unsigned int
266 execute_all_early_local_passes (void)
268 /* Once this pass (and its sub-passes) are complete, all functions
269 will be in SSA form. Technically this state change is happening
270 a tad early, since the sub-passes have not yet run, but since
271 none of the sub-passes are IPA passes and do not create new
272 functions, this is ok. We're setting this value for the benefit
273 of IPA passes that follow. */
274 if (cgraph_state < CGRAPH_STATE_IPA_SSA)
275 cgraph_state = CGRAPH_STATE_IPA_SSA;
276 return 0;
279 /* Gate: execute, or not, all of the non-trivial optimizations. */
281 static bool
282 gate_all_early_local_passes (void)
284 /* Don't bother doing anything if the program has errors. */
285 return (!seen_error () && !in_lto_p);
288 struct simple_ipa_opt_pass pass_early_local_passes =
291 SIMPLE_IPA_PASS,
292 "early_local_cleanups", /* name */
293 gate_all_early_local_passes, /* gate */
294 execute_all_early_local_passes, /* execute */
295 NULL, /* sub */
296 NULL, /* next */
297 0, /* static_pass_number */
298 TV_EARLY_LOCAL, /* tv_id */
299 0, /* properties_required */
300 0, /* properties_provided */
301 0, /* properties_destroyed */
302 0, /* todo_flags_start */
303 TODO_remove_functions /* todo_flags_finish */
307 /* Gate: execute, or not, all of the non-trivial optimizations. */
309 static bool
310 gate_all_early_optimizations (void)
312 return (optimize >= 1
313 /* Don't bother doing anything if the program has errors. */
314 && !seen_error ());
317 static struct gimple_opt_pass pass_all_early_optimizations =
320 GIMPLE_PASS,
321 "early_optimizations", /* name */
322 gate_all_early_optimizations, /* gate */
323 NULL, /* execute */
324 NULL, /* sub */
325 NULL, /* next */
326 0, /* static_pass_number */
327 TV_NONE, /* tv_id */
328 0, /* properties_required */
329 0, /* properties_provided */
330 0, /* properties_destroyed */
331 0, /* todo_flags_start */
332 0 /* todo_flags_finish */
336 /* Gate: execute, or not, all of the non-trivial optimizations. */
338 static bool
339 gate_all_optimizations (void)
341 return (optimize >= 1
342 /* Don't bother doing anything if the program has errors.
343 We have to pass down the queue if we already went into SSA */
344 && (!seen_error () || gimple_in_ssa_p (cfun)));
347 static struct gimple_opt_pass pass_all_optimizations =
350 GIMPLE_PASS,
351 "*all_optimizations", /* name */
352 gate_all_optimizations, /* gate */
353 NULL, /* execute */
354 NULL, /* sub */
355 NULL, /* next */
356 0, /* static_pass_number */
357 TV_OPTIMIZE, /* tv_id */
358 0, /* properties_required */
359 0, /* properties_provided */
360 0, /* properties_destroyed */
361 0, /* todo_flags_start */
362 0 /* todo_flags_finish */
366 static bool
367 gate_rest_of_compilation (void)
369 /* Early return if there were errors. We can run afoul of our
370 consistency checks, and there's not really much point in fixing them. */
371 return !(rtl_dump_and_exit || flag_syntax_only || seen_error ());
374 static struct rtl_opt_pass pass_rest_of_compilation =
377 RTL_PASS,
378 "*rest_of_compilation", /* name */
379 gate_rest_of_compilation, /* gate */
380 NULL, /* execute */
381 NULL, /* sub */
382 NULL, /* next */
383 0, /* static_pass_number */
384 TV_REST_OF_COMPILATION, /* tv_id */
385 PROP_rtl, /* properties_required */
386 0, /* properties_provided */
387 0, /* properties_destroyed */
388 0, /* todo_flags_start */
389 TODO_ggc_collect /* todo_flags_finish */
393 static bool
394 gate_postreload (void)
396 return reload_completed;
399 static struct rtl_opt_pass pass_postreload =
402 RTL_PASS,
403 "*all-postreload", /* name */
404 gate_postreload, /* gate */
405 NULL, /* execute */
406 NULL, /* sub */
407 NULL, /* next */
408 0, /* static_pass_number */
409 TV_POSTRELOAD, /* tv_id */
410 PROP_rtl, /* properties_required */
411 0, /* properties_provided */
412 0, /* properties_destroyed */
413 0, /* todo_flags_start */
414 TODO_ggc_collect | TODO_verify_rtl_sharing /* todo_flags_finish */
420 /* The root of the compilation pass tree, once constructed. */
421 struct opt_pass *all_passes, *all_small_ipa_passes, *all_lowering_passes,
422 *all_regular_ipa_passes, *all_late_ipa_passes, *all_lto_gen_passes;
424 /* This is used by plugins, and should also be used in register_pass. */
425 #define DEF_PASS_LIST(LIST) &LIST,
426 struct opt_pass **gcc_pass_lists[] = { GCC_PASS_LISTS NULL };
427 #undef DEF_PASS_LIST
429 /* A map from static pass id to optimization pass. */
430 struct opt_pass **passes_by_id;
431 int passes_by_id_size;
433 /* Set the static pass number of pass PASS to ID and record that
434 in the mapping from static pass number to pass. */
436 static void
437 set_pass_for_id (int id, struct opt_pass *pass)
439 pass->static_pass_number = id;
440 if (passes_by_id_size <= id)
442 passes_by_id = XRESIZEVEC (struct opt_pass *, passes_by_id, id + 1);
443 memset (passes_by_id + passes_by_id_size, 0,
444 (id + 1 - passes_by_id_size) * sizeof (void *));
445 passes_by_id_size = id + 1;
447 passes_by_id[id] = pass;
450 /* Return the pass with the static pass number ID. */
452 struct opt_pass *
453 get_pass_for_id (int id)
455 if (id >= passes_by_id_size)
456 return NULL;
457 return passes_by_id[id];
460 /* Iterate over the pass tree allocating dump file numbers. We want
461 to do this depth first, and independent of whether the pass is
462 enabled or not. */
464 void
465 register_one_dump_file (struct opt_pass *pass)
467 char *dot_name, *flag_name, *glob_name;
468 const char *name, *full_name, *prefix;
469 char num[10];
470 int flags, id;
472 /* See below in next_pass_1. */
473 num[0] = '\0';
474 if (pass->static_pass_number != -1)
475 sprintf (num, "%d", ((int) pass->static_pass_number < 0
476 ? 1 : pass->static_pass_number));
478 /* The name is both used to identify the pass for the purposes of plugins,
479 and to specify dump file name and option.
480 The latter two might want something short which is not quite unique; for
481 that reason, we may have a disambiguating prefix, followed by a space
482 to mark the start of the following dump file name / option string. */
483 name = strchr (pass->name, ' ');
484 name = name ? name + 1 : pass->name;
485 dot_name = concat (".", name, num, NULL);
486 if (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS)
487 prefix = "ipa-", flags = TDF_IPA;
488 else if (pass->type == GIMPLE_PASS)
489 prefix = "tree-", flags = TDF_TREE;
490 else
491 prefix = "rtl-", flags = TDF_RTL;
493 flag_name = concat (prefix, name, num, NULL);
494 glob_name = concat (prefix, name, NULL);
495 id = dump_register (dot_name, flag_name, glob_name, flags);
496 set_pass_for_id (id, pass);
497 full_name = concat (prefix, pass->name, num, NULL);
498 register_pass_name (pass, full_name);
499 free (CONST_CAST (char *, full_name));
502 /* Recursive worker function for register_dump_files. */
504 static int
505 register_dump_files_1 (struct opt_pass *pass, int properties)
509 int new_properties = (properties | pass->properties_provided)
510 & ~pass->properties_destroyed;
512 if (pass->name && pass->name[0] != '*')
513 register_one_dump_file (pass);
515 if (pass->sub)
516 new_properties = register_dump_files_1 (pass->sub, new_properties);
518 /* If we have a gate, combine the properties that we could have with
519 and without the pass being examined. */
520 if (pass->gate)
521 properties &= new_properties;
522 else
523 properties = new_properties;
525 pass = pass->next;
527 while (pass);
529 return properties;
532 /* Register the dump files for the pipeline starting at PASS.
533 PROPERTIES reflects the properties that are guaranteed to be available at
534 the beginning of the pipeline. */
536 static void
537 register_dump_files (struct opt_pass *pass,int properties)
539 pass->properties_required |= properties;
540 register_dump_files_1 (pass, properties);
543 struct pass_registry
545 const char* unique_name;
546 struct opt_pass *pass;
549 /* Pass registry hash function. */
551 static hashval_t
552 passr_hash (const void *p)
554 const struct pass_registry *const s = (const struct pass_registry *const) p;
555 return htab_hash_string (s->unique_name);
558 /* Hash equal function */
560 static int
561 passr_eq (const void *p1, const void *p2)
563 const struct pass_registry *const s1 = (const struct pass_registry *const) p1;
564 const struct pass_registry *const s2 = (const struct pass_registry *const) p2;
566 return !strcmp (s1->unique_name, s2->unique_name);
569 static htab_t name_to_pass_map = NULL;
571 /* Register PASS with NAME. */
573 static void
574 register_pass_name (struct opt_pass *pass, const char *name)
576 struct pass_registry **slot;
577 struct pass_registry pr;
579 if (!name_to_pass_map)
580 name_to_pass_map = htab_create (256, passr_hash, passr_eq, NULL);
582 pr.unique_name = name;
583 slot = (struct pass_registry **) htab_find_slot (name_to_pass_map, &pr, INSERT);
584 if (!*slot)
586 struct pass_registry *new_pr;
588 new_pr = XCNEW (struct pass_registry);
589 new_pr->unique_name = xstrdup (name);
590 new_pr->pass = pass;
591 *slot = new_pr;
593 else
594 return; /* Ignore plugin passes. */
597 /* Map from pass id to canonicalized pass name. */
599 typedef const char *char_ptr;
600 DEF_VEC_P(char_ptr);
601 DEF_VEC_ALLOC_P(char_ptr, heap);
602 static VEC(char_ptr, heap) *pass_tab = NULL;
604 /* Callback function for traversing NAME_TO_PASS_MAP. */
606 static int
607 pass_traverse (void **slot, void *data ATTRIBUTE_UNUSED)
609 struct pass_registry **p = (struct pass_registry **)slot;
610 struct opt_pass *pass = (*p)->pass;
612 gcc_assert (pass->static_pass_number > 0);
613 gcc_assert (pass_tab);
615 VEC_replace (char_ptr, pass_tab, pass->static_pass_number,
616 (*p)->unique_name);
618 return 1;
621 /* The function traverses NAME_TO_PASS_MAP and creates a pass info
622 table for dumping purpose. */
624 static void
625 create_pass_tab (void)
627 if (!flag_dump_passes)
628 return;
630 VEC_safe_grow_cleared (char_ptr, heap,
631 pass_tab, passes_by_id_size + 1);
632 htab_traverse (name_to_pass_map, pass_traverse, NULL);
635 static bool override_gate_status (struct opt_pass *, tree, bool);
637 /* Dump the instantiated name for PASS. IS_ON indicates if PASS
638 is turned on or not. */
640 static void
641 dump_one_pass (struct opt_pass *pass, int pass_indent)
643 int indent = 3 * pass_indent;
644 const char *pn;
645 bool is_on, is_really_on;
647 is_on = (pass->gate == NULL) ? true : pass->gate();
648 is_really_on = override_gate_status (pass, current_function_decl, is_on);
650 if (pass->static_pass_number <= 0)
651 pn = pass->name;
652 else
653 pn = VEC_index (char_ptr, pass_tab, pass->static_pass_number);
655 fprintf (stderr, "%*s%-40s%*s:%s%s\n", indent, " ", pn,
656 (15 - indent < 0 ? 0 : 15 - indent), " ",
657 is_on ? " ON" : " OFF",
658 ((!is_on) == (!is_really_on) ? ""
659 : (is_really_on ? " (FORCED_ON)" : " (FORCED_OFF)")));
662 /* Dump pass list PASS with indentation INDENT. */
664 static void
665 dump_pass_list (struct opt_pass *pass, int indent)
669 dump_one_pass (pass, indent);
670 if (pass->sub)
671 dump_pass_list (pass->sub, indent + 1);
672 pass = pass->next;
674 while (pass);
677 /* Dump all optimization passes. */
679 void
680 dump_passes (void)
682 struct cgraph_node *n, *node = NULL;
683 tree save_fndecl = current_function_decl;
685 create_pass_tab();
687 FOR_EACH_DEFINED_FUNCTION (n)
688 if (DECL_STRUCT_FUNCTION (n->symbol.decl))
690 node = n;
691 break;
694 if (!node)
695 return;
697 push_cfun (DECL_STRUCT_FUNCTION (node->symbol.decl));
698 current_function_decl = node->symbol.decl;
700 dump_pass_list (all_lowering_passes, 1);
701 dump_pass_list (all_small_ipa_passes, 1);
702 dump_pass_list (all_regular_ipa_passes, 1);
703 dump_pass_list (all_lto_gen_passes, 1);
704 dump_pass_list (all_late_ipa_passes, 1);
705 dump_pass_list (all_passes, 1);
707 pop_cfun ();
708 current_function_decl = save_fndecl;
712 /* Returns the pass with NAME. */
714 static struct opt_pass *
715 get_pass_by_name (const char *name)
717 struct pass_registry **slot, pr;
719 pr.unique_name = name;
720 slot = (struct pass_registry **) htab_find_slot (name_to_pass_map,
721 &pr, NO_INSERT);
723 if (!slot || !*slot)
724 return NULL;
726 return (*slot)->pass;
730 /* Range [start, last]. */
732 struct uid_range
734 unsigned int start;
735 unsigned int last;
736 const char *assem_name;
737 struct uid_range *next;
740 typedef struct uid_range *uid_range_p;
742 DEF_VEC_P(uid_range_p);
743 DEF_VEC_ALLOC_P(uid_range_p, heap);
745 static VEC(uid_range_p, heap) *enabled_pass_uid_range_tab = NULL;
746 static VEC(uid_range_p, heap) *disabled_pass_uid_range_tab = NULL;
749 /* Parse option string for -fdisable- and -fenable-
750 The syntax of the options:
752 -fenable-<pass_name>
753 -fdisable-<pass_name>
755 -fenable-<pass_name>=s1:e1,s2:e2,...
756 -fdisable-<pass_name>=s1:e1,s2:e2,...
759 static void
760 enable_disable_pass (const char *arg, bool is_enable)
762 struct opt_pass *pass;
763 char *range_str, *phase_name;
764 char *argstr = xstrdup (arg);
765 VEC(uid_range_p, heap) **tab = 0;
767 range_str = strchr (argstr,'=');
768 if (range_str)
770 *range_str = '\0';
771 range_str++;
774 phase_name = argstr;
775 if (!*phase_name)
777 if (is_enable)
778 error ("unrecognized option -fenable");
779 else
780 error ("unrecognized option -fdisable");
781 free (argstr);
782 return;
784 pass = get_pass_by_name (phase_name);
785 if (!pass || pass->static_pass_number == -1)
787 if (is_enable)
788 error ("unknown pass %s specified in -fenable", phase_name);
789 else
790 error ("unknown pass %s specified in -fdisable", phase_name);
791 free (argstr);
792 return;
795 if (is_enable)
796 tab = &enabled_pass_uid_range_tab;
797 else
798 tab = &disabled_pass_uid_range_tab;
800 if ((unsigned) pass->static_pass_number >= VEC_length (uid_range_p, *tab))
801 VEC_safe_grow_cleared (uid_range_p, heap,
802 *tab, pass->static_pass_number + 1);
804 if (!range_str)
806 uid_range_p slot;
807 uid_range_p new_range = XCNEW (struct uid_range);
809 new_range->start = 0;
810 new_range->last = (unsigned)-1;
812 slot = VEC_index (uid_range_p, *tab, pass->static_pass_number);
813 new_range->next = slot;
814 VEC_replace (uid_range_p, *tab, pass->static_pass_number,
815 new_range);
816 if (is_enable)
817 inform (UNKNOWN_LOCATION, "enable pass %s for functions in the range "
818 "of [%u, %u]", phase_name, new_range->start, new_range->last);
819 else
820 inform (UNKNOWN_LOCATION, "disable pass %s for functions in the range "
821 "of [%u, %u]", phase_name, new_range->start, new_range->last);
823 else
825 char *next_range = NULL;
826 char *one_range = range_str;
827 char *end_val = NULL;
831 uid_range_p slot;
832 uid_range_p new_range;
833 char *invalid = NULL;
834 long start;
835 char *func_name = NULL;
837 next_range = strchr (one_range, ',');
838 if (next_range)
840 *next_range = '\0';
841 next_range++;
844 end_val = strchr (one_range, ':');
845 if (end_val)
847 *end_val = '\0';
848 end_val++;
850 start = strtol (one_range, &invalid, 10);
851 if (*invalid || start < 0)
853 if (end_val || (one_range[0] >= '0'
854 && one_range[0] <= '9'))
856 error ("Invalid range %s in option %s",
857 one_range,
858 is_enable ? "-fenable" : "-fdisable");
859 free (argstr);
860 return;
862 func_name = one_range;
864 if (!end_val)
866 new_range = XCNEW (struct uid_range);
867 if (!func_name)
869 new_range->start = (unsigned) start;
870 new_range->last = (unsigned) start;
872 else
874 new_range->start = (unsigned) -1;
875 new_range->last = (unsigned) -1;
876 new_range->assem_name = xstrdup (func_name);
879 else
881 long last = strtol (end_val, &invalid, 10);
882 if (*invalid || last < start)
884 error ("Invalid range %s in option %s",
885 end_val,
886 is_enable ? "-fenable" : "-fdisable");
887 free (argstr);
888 return;
890 new_range = XCNEW (struct uid_range);
891 new_range->start = (unsigned) start;
892 new_range->last = (unsigned) last;
895 slot = VEC_index (uid_range_p, *tab, pass->static_pass_number);
896 new_range->next = slot;
897 VEC_replace (uid_range_p, *tab, pass->static_pass_number,
898 new_range);
899 if (is_enable)
901 if (new_range->assem_name)
902 inform (UNKNOWN_LOCATION,
903 "enable pass %s for function %s",
904 phase_name, new_range->assem_name);
905 else
906 inform (UNKNOWN_LOCATION,
907 "enable pass %s for functions in the range of [%u, %u]",
908 phase_name, new_range->start, new_range->last);
910 else
912 if (new_range->assem_name)
913 inform (UNKNOWN_LOCATION,
914 "disable pass %s for function %s",
915 phase_name, new_range->assem_name);
916 else
917 inform (UNKNOWN_LOCATION,
918 "disable pass %s for functions in the range of [%u, %u]",
919 phase_name, new_range->start, new_range->last);
922 one_range = next_range;
923 } while (next_range);
926 free (argstr);
929 /* Enable pass specified by ARG. */
931 void
932 enable_pass (const char *arg)
934 enable_disable_pass (arg, true);
937 /* Disable pass specified by ARG. */
939 void
940 disable_pass (const char *arg)
942 enable_disable_pass (arg, false);
945 /* Returns true if PASS is explicitly enabled/disabled for FUNC. */
947 static bool
948 is_pass_explicitly_enabled_or_disabled (struct opt_pass *pass,
949 tree func,
950 VEC(uid_range_p, heap) *tab)
952 uid_range_p slot, range;
953 int cgraph_uid;
954 const char *aname = NULL;
956 if (!tab
957 || (unsigned) pass->static_pass_number >= VEC_length (uid_range_p, tab)
958 || pass->static_pass_number == -1)
959 return false;
961 slot = VEC_index (uid_range_p, tab, pass->static_pass_number);
962 if (!slot)
963 return false;
965 cgraph_uid = func ? cgraph_get_node (func)->uid : 0;
966 if (func && DECL_ASSEMBLER_NAME_SET_P (func))
967 aname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func));
969 range = slot;
970 while (range)
972 if ((unsigned) cgraph_uid >= range->start
973 && (unsigned) cgraph_uid <= range->last)
974 return true;
975 if (range->assem_name && aname
976 && !strcmp (range->assem_name, aname))
977 return true;
978 range = range->next;
981 return false;
984 /* Look at the static_pass_number and duplicate the pass
985 if it is already added to a list. */
987 static struct opt_pass *
988 make_pass_instance (struct opt_pass *pass, bool track_duplicates)
990 /* A nonzero static_pass_number indicates that the
991 pass is already in the list. */
992 if (pass->static_pass_number)
994 struct opt_pass *new_pass;
996 if (pass->type == GIMPLE_PASS
997 || pass->type == RTL_PASS
998 || pass->type == SIMPLE_IPA_PASS)
1000 new_pass = XNEW (struct opt_pass);
1001 memcpy (new_pass, pass, sizeof (struct opt_pass));
1003 else if (pass->type == IPA_PASS)
1005 new_pass = (struct opt_pass *)XNEW (struct ipa_opt_pass_d);
1006 memcpy (new_pass, pass, sizeof (struct ipa_opt_pass_d));
1008 else
1009 gcc_unreachable ();
1011 new_pass->next = NULL;
1013 new_pass->todo_flags_start &= ~TODO_mark_first_instance;
1015 /* Indicate to register_dump_files that this pass has duplicates,
1016 and so it should rename the dump file. The first instance will
1017 be -1, and be number of duplicates = -static_pass_number - 1.
1018 Subsequent instances will be > 0 and just the duplicate number. */
1019 if ((pass->name && pass->name[0] != '*') || track_duplicates)
1021 pass->static_pass_number -= 1;
1022 new_pass->static_pass_number = -pass->static_pass_number;
1024 return new_pass;
1026 else
1028 pass->todo_flags_start |= TODO_mark_first_instance;
1029 pass->static_pass_number = -1;
1031 invoke_plugin_callbacks (PLUGIN_NEW_PASS, pass);
1033 return pass;
1036 /* Add a pass to the pass list. Duplicate the pass if it's already
1037 in the list. */
1039 static struct opt_pass **
1040 next_pass_1 (struct opt_pass **list, struct opt_pass *pass)
1042 /* Every pass should have a name so that plugins can refer to them. */
1043 gcc_assert (pass->name != NULL);
1045 *list = make_pass_instance (pass, false);
1047 return &(*list)->next;
1050 /* List node for an inserted pass instance. We need to keep track of all
1051 the newly-added pass instances (with 'added_pass_nodes' defined below)
1052 so that we can register their dump files after pass-positioning is finished.
1053 Registering dumping files needs to be post-processed or the
1054 static_pass_number of the opt_pass object would be modified and mess up
1055 the dump file names of future pass instances to be added. */
1057 struct pass_list_node
1059 struct opt_pass *pass;
1060 struct pass_list_node *next;
1063 static struct pass_list_node *added_pass_nodes = NULL;
1064 static struct pass_list_node *prev_added_pass_node;
1066 /* Insert the pass at the proper position. Return true if the pass
1067 is successfully added.
1069 NEW_PASS_INFO - new pass to be inserted
1070 PASS_LIST - root of the pass list to insert the new pass to */
1072 static bool
1073 position_pass (struct register_pass_info *new_pass_info,
1074 struct opt_pass **pass_list)
1076 struct opt_pass *pass = *pass_list, *prev_pass = NULL;
1077 bool success = false;
1079 for ( ; pass; prev_pass = pass, pass = pass->next)
1081 /* Check if the current pass is of the same type as the new pass and
1082 matches the name and the instance number of the reference pass. */
1083 if (pass->type == new_pass_info->pass->type
1084 && pass->name
1085 && !strcmp (pass->name, new_pass_info->reference_pass_name)
1086 && ((new_pass_info->ref_pass_instance_number == 0)
1087 || (new_pass_info->ref_pass_instance_number ==
1088 pass->static_pass_number)
1089 || (new_pass_info->ref_pass_instance_number == 1
1090 && pass->todo_flags_start & TODO_mark_first_instance)))
1092 struct opt_pass *new_pass;
1093 struct pass_list_node *new_pass_node;
1095 new_pass = make_pass_instance (new_pass_info->pass, true);
1097 /* Insert the new pass instance based on the positioning op. */
1098 switch (new_pass_info->pos_op)
1100 case PASS_POS_INSERT_AFTER:
1101 new_pass->next = pass->next;
1102 pass->next = new_pass;
1104 /* Skip newly inserted pass to avoid repeated
1105 insertions in the case where the new pass and the
1106 existing one have the same name. */
1107 pass = new_pass;
1108 break;
1109 case PASS_POS_INSERT_BEFORE:
1110 new_pass->next = pass;
1111 if (prev_pass)
1112 prev_pass->next = new_pass;
1113 else
1114 *pass_list = new_pass;
1115 break;
1116 case PASS_POS_REPLACE:
1117 new_pass->next = pass->next;
1118 if (prev_pass)
1119 prev_pass->next = new_pass;
1120 else
1121 *pass_list = new_pass;
1122 new_pass->sub = pass->sub;
1123 new_pass->tv_id = pass->tv_id;
1124 pass = new_pass;
1125 break;
1126 default:
1127 error ("invalid pass positioning operation");
1128 return false;
1131 /* Save the newly added pass (instance) in the added_pass_nodes
1132 list so that we can register its dump file later. Note that
1133 we cannot register the dump file now because doing so will modify
1134 the static_pass_number of the opt_pass object and therefore
1135 mess up the dump file name of future instances. */
1136 new_pass_node = XCNEW (struct pass_list_node);
1137 new_pass_node->pass = new_pass;
1138 if (!added_pass_nodes)
1139 added_pass_nodes = new_pass_node;
1140 else
1141 prev_added_pass_node->next = new_pass_node;
1142 prev_added_pass_node = new_pass_node;
1144 success = true;
1147 if (pass->sub && position_pass (new_pass_info, &pass->sub))
1148 success = true;
1151 return success;
1154 /* Hooks a new pass into the pass lists.
1156 PASS_INFO - pass information that specifies the opt_pass object,
1157 reference pass, instance number, and how to position
1158 the pass */
1160 void
1161 register_pass (struct register_pass_info *pass_info)
1163 bool all_instances, success;
1165 /* The checks below could fail in buggy plugins. Existing GCC
1166 passes should never fail these checks, so we mention plugin in
1167 the messages. */
1168 if (!pass_info->pass)
1169 fatal_error ("plugin cannot register a missing pass");
1171 if (!pass_info->pass->name)
1172 fatal_error ("plugin cannot register an unnamed pass");
1174 if (!pass_info->reference_pass_name)
1175 fatal_error
1176 ("plugin cannot register pass %qs without reference pass name",
1177 pass_info->pass->name);
1179 /* Try to insert the new pass to the pass lists. We need to check
1180 all five lists as the reference pass could be in one (or all) of
1181 them. */
1182 all_instances = pass_info->ref_pass_instance_number == 0;
1183 success = position_pass (pass_info, &all_lowering_passes);
1184 if (!success || all_instances)
1185 success |= position_pass (pass_info, &all_small_ipa_passes);
1186 if (!success || all_instances)
1187 success |= position_pass (pass_info, &all_regular_ipa_passes);
1188 if (!success || all_instances)
1189 success |= position_pass (pass_info, &all_lto_gen_passes);
1190 if (!success || all_instances)
1191 success |= position_pass (pass_info, &all_late_ipa_passes);
1192 if (!success || all_instances)
1193 success |= position_pass (pass_info, &all_passes);
1194 if (!success)
1195 fatal_error
1196 ("pass %qs not found but is referenced by new pass %qs",
1197 pass_info->reference_pass_name, pass_info->pass->name);
1199 /* OK, we have successfully inserted the new pass. We need to register
1200 the dump files for the newly added pass and its duplicates (if any).
1201 Because the registration of plugin/backend passes happens after the
1202 command-line options are parsed, the options that specify single
1203 pass dumping (e.g. -fdump-tree-PASSNAME) cannot be used for new
1204 passes. Therefore we currently can only enable dumping of
1205 new passes when the 'dump-all' flags (e.g. -fdump-tree-all)
1206 are specified. While doing so, we also delete the pass_list_node
1207 objects created during pass positioning. */
1208 while (added_pass_nodes)
1210 struct pass_list_node *next_node = added_pass_nodes->next;
1211 enum tree_dump_index tdi;
1212 register_one_dump_file (added_pass_nodes->pass);
1213 if (added_pass_nodes->pass->type == SIMPLE_IPA_PASS
1214 || added_pass_nodes->pass->type == IPA_PASS)
1215 tdi = TDI_ipa_all;
1216 else if (added_pass_nodes->pass->type == GIMPLE_PASS)
1217 tdi = TDI_tree_all;
1218 else
1219 tdi = TDI_rtl_all;
1220 /* Check if dump-all flag is specified. */
1221 if (get_dump_file_info (tdi)->state)
1222 get_dump_file_info (added_pass_nodes->pass->static_pass_number)
1223 ->state = get_dump_file_info (tdi)->state;
1224 XDELETE (added_pass_nodes);
1225 added_pass_nodes = next_node;
1229 /* Construct the pass tree. The sequencing of passes is driven by
1230 the cgraph routines:
1232 finalize_compilation_unit ()
1233 for each node N in the cgraph
1234 cgraph_analyze_function (N)
1235 cgraph_lower_function (N) -> all_lowering_passes
1237 If we are optimizing, compile is then invoked:
1239 compile ()
1240 ipa_passes () -> all_small_ipa_passes
1241 -> Analysis of all_regular_ipa_passes
1242 * possible LTO streaming at copmilation time *
1243 -> Execution of all_regular_ipa_passes
1244 * possible LTO streaming at link time *
1245 -> all_late_ipa_passes
1246 expand_all_functions ()
1247 for each node N in the cgraph
1248 expand_function (N) -> Transformation of all_regular_ipa_passes
1249 -> all_passes
1252 void
1253 init_optimization_passes (void)
1255 struct opt_pass **p;
1257 #define NEXT_PASS(PASS) (p = next_pass_1 (p, &((PASS).pass)))
1259 /* All passes needed to lower the function into shape optimizers can
1260 operate on. These passes are always run first on the function, but
1261 backend might produce already lowered functions that are not processed
1262 by these passes. */
1263 p = &all_lowering_passes;
1264 NEXT_PASS (pass_warn_unused_result);
1265 NEXT_PASS (pass_diagnose_omp_blocks);
1266 NEXT_PASS (pass_diagnose_tm_blocks);
1267 NEXT_PASS (pass_mudflap_1);
1268 NEXT_PASS (pass_lower_omp);
1269 NEXT_PASS (pass_lower_cf);
1270 NEXT_PASS (pass_lower_tm);
1271 NEXT_PASS (pass_refactor_eh);
1272 NEXT_PASS (pass_lower_eh);
1273 NEXT_PASS (pass_build_cfg);
1274 NEXT_PASS (pass_warn_function_return);
1275 NEXT_PASS (pass_build_cgraph_edges);
1276 *p = NULL;
1278 /* Interprocedural optimization passes. */
1279 p = &all_small_ipa_passes;
1280 NEXT_PASS (pass_ipa_free_lang_data);
1281 NEXT_PASS (pass_ipa_function_and_variable_visibility);
1282 NEXT_PASS (pass_early_local_passes);
1284 struct opt_pass **p = &pass_early_local_passes.pass.sub;
1285 NEXT_PASS (pass_fixup_cfg);
1286 NEXT_PASS (pass_init_datastructures);
1287 NEXT_PASS (pass_expand_omp);
1289 NEXT_PASS (pass_referenced_vars);
1290 NEXT_PASS (pass_build_ssa);
1291 NEXT_PASS (pass_lower_vector);
1292 NEXT_PASS (pass_early_warn_uninitialized);
1293 NEXT_PASS (pass_rebuild_cgraph_edges);
1294 NEXT_PASS (pass_inline_parameters);
1295 NEXT_PASS (pass_early_inline);
1296 NEXT_PASS (pass_all_early_optimizations);
1298 struct opt_pass **p = &pass_all_early_optimizations.pass.sub;
1299 NEXT_PASS (pass_remove_cgraph_callee_edges);
1300 NEXT_PASS (pass_rename_ssa_copies);
1301 NEXT_PASS (pass_ccp);
1302 NEXT_PASS (pass_forwprop);
1303 /* pass_build_ealias is a dummy pass that ensures that we
1304 execute TODO_rebuild_alias at this point. Re-building
1305 alias information also rewrites no longer addressed
1306 locals into SSA form if possible. */
1307 NEXT_PASS (pass_build_ealias);
1308 NEXT_PASS (pass_sra_early);
1309 NEXT_PASS (pass_fre);
1310 NEXT_PASS (pass_copy_prop);
1311 NEXT_PASS (pass_merge_phi);
1312 NEXT_PASS (pass_cd_dce);
1313 NEXT_PASS (pass_early_ipa_sra);
1314 NEXT_PASS (pass_tail_recursion);
1315 NEXT_PASS (pass_convert_switch);
1316 NEXT_PASS (pass_cleanup_eh);
1317 NEXT_PASS (pass_profile);
1318 NEXT_PASS (pass_local_pure_const);
1319 /* Split functions creates parts that are not run through
1320 early optimizations again. It is thus good idea to do this
1321 late. */
1322 NEXT_PASS (pass_split_functions);
1324 NEXT_PASS (pass_release_ssa_names);
1325 NEXT_PASS (pass_rebuild_cgraph_edges);
1326 NEXT_PASS (pass_inline_parameters);
1328 NEXT_PASS (pass_ipa_tree_profile);
1330 struct opt_pass **p = &pass_ipa_tree_profile.pass.sub;
1331 NEXT_PASS (pass_feedback_split_functions);
1333 NEXT_PASS (pass_ipa_increase_alignment);
1334 NEXT_PASS (pass_ipa_matrix_reorg);
1335 NEXT_PASS (pass_ipa_tm);
1336 NEXT_PASS (pass_ipa_lower_emutls);
1337 *p = NULL;
1339 p = &all_regular_ipa_passes;
1340 NEXT_PASS (pass_ipa_whole_program_visibility);
1341 NEXT_PASS (pass_ipa_profile);
1342 NEXT_PASS (pass_ipa_cp);
1343 NEXT_PASS (pass_ipa_cdtor_merge);
1344 NEXT_PASS (pass_ipa_inline);
1345 NEXT_PASS (pass_ipa_pure_const);
1346 NEXT_PASS (pass_ipa_reference);
1347 *p = NULL;
1349 p = &all_lto_gen_passes;
1350 NEXT_PASS (pass_ipa_lto_gimple_out);
1351 NEXT_PASS (pass_ipa_lto_finish_out); /* This must be the last LTO pass. */
1352 *p = NULL;
1354 /* Simple IPA passes executed after the regular passes. In WHOPR mode the
1355 passes are executed after partitioning and thus see just parts of the
1356 compiled unit. */
1357 p = &all_late_ipa_passes;
1358 NEXT_PASS (pass_ipa_pta);
1359 *p = NULL;
1361 /* These passes are run after IPA passes on every function that is being
1362 output to the assembler file. */
1363 p = &all_passes;
1364 NEXT_PASS (pass_fixup_cfg);
1365 NEXT_PASS (pass_lower_eh_dispatch);
1366 NEXT_PASS (pass_all_optimizations);
1368 struct opt_pass **p = &pass_all_optimizations.pass.sub;
1369 NEXT_PASS (pass_remove_cgraph_callee_edges);
1370 /* Initial scalar cleanups before alias computation.
1371 They ensure memory accesses are not indirect wherever possible. */
1372 NEXT_PASS (pass_strip_predict_hints);
1373 NEXT_PASS (pass_rename_ssa_copies);
1374 NEXT_PASS (pass_complete_unrolli);
1375 NEXT_PASS (pass_ccp);
1376 NEXT_PASS (pass_forwprop);
1377 NEXT_PASS (pass_call_cdce);
1378 /* pass_build_alias is a dummy pass that ensures that we
1379 execute TODO_rebuild_alias at this point. Re-building
1380 alias information also rewrites no longer addressed
1381 locals into SSA form if possible. */
1382 NEXT_PASS (pass_build_alias);
1383 NEXT_PASS (pass_return_slot);
1384 NEXT_PASS (pass_phiprop);
1385 NEXT_PASS (pass_fre);
1386 NEXT_PASS (pass_copy_prop);
1387 NEXT_PASS (pass_merge_phi);
1388 NEXT_PASS (pass_vrp);
1389 NEXT_PASS (pass_dce);
1390 NEXT_PASS (pass_cselim);
1391 NEXT_PASS (pass_tree_ifcombine);
1392 NEXT_PASS (pass_phiopt);
1393 NEXT_PASS (pass_tail_recursion);
1394 NEXT_PASS (pass_ch);
1395 NEXT_PASS (pass_stdarg);
1396 NEXT_PASS (pass_lower_complex);
1397 NEXT_PASS (pass_sra);
1398 NEXT_PASS (pass_rename_ssa_copies);
1399 /* The dom pass will also resolve all __builtin_constant_p calls
1400 that are still there to 0. This has to be done after some
1401 propagations have already run, but before some more dead code
1402 is removed, and this place fits nicely. Remember this when
1403 trying to move or duplicate pass_dominator somewhere earlier. */
1404 NEXT_PASS (pass_dominator);
1405 /* The only const/copy propagation opportunities left after
1406 DOM should be due to degenerate PHI nodes. So rather than
1407 run the full propagators, run a specialized pass which
1408 only examines PHIs to discover const/copy propagation
1409 opportunities. */
1410 NEXT_PASS (pass_phi_only_cprop);
1411 NEXT_PASS (pass_dse);
1412 NEXT_PASS (pass_reassoc);
1413 NEXT_PASS (pass_dce);
1414 NEXT_PASS (pass_forwprop);
1415 NEXT_PASS (pass_phiopt);
1416 NEXT_PASS (pass_object_sizes);
1417 NEXT_PASS (pass_strlen);
1418 NEXT_PASS (pass_ccp);
1419 NEXT_PASS (pass_copy_prop);
1420 NEXT_PASS (pass_cse_sincos);
1421 NEXT_PASS (pass_optimize_bswap);
1422 NEXT_PASS (pass_split_crit_edges);
1423 NEXT_PASS (pass_pre);
1424 NEXT_PASS (pass_sink_code);
1425 NEXT_PASS (pass_tree_loop);
1427 struct opt_pass **p = &pass_tree_loop.pass.sub;
1428 NEXT_PASS (pass_tree_loop_init);
1429 NEXT_PASS (pass_lim);
1430 NEXT_PASS (pass_copy_prop);
1431 NEXT_PASS (pass_dce_loop);
1432 NEXT_PASS (pass_tree_unswitch);
1433 NEXT_PASS (pass_scev_cprop);
1434 NEXT_PASS (pass_record_bounds);
1435 NEXT_PASS (pass_check_data_deps);
1436 NEXT_PASS (pass_loop_distribution);
1437 NEXT_PASS (pass_copy_prop);
1438 NEXT_PASS (pass_graphite);
1440 struct opt_pass **p = &pass_graphite.pass.sub;
1441 NEXT_PASS (pass_graphite_transforms);
1442 NEXT_PASS (pass_lim);
1443 NEXT_PASS (pass_copy_prop);
1444 NEXT_PASS (pass_dce_loop);
1446 NEXT_PASS (pass_iv_canon);
1447 NEXT_PASS (pass_if_conversion);
1448 NEXT_PASS (pass_vectorize);
1450 struct opt_pass **p = &pass_vectorize.pass.sub;
1451 NEXT_PASS (pass_dce_loop);
1453 NEXT_PASS (pass_predcom);
1454 NEXT_PASS (pass_complete_unroll);
1455 NEXT_PASS (pass_slp_vectorize);
1456 NEXT_PASS (pass_parallelize_loops);
1457 NEXT_PASS (pass_loop_prefetch);
1458 NEXT_PASS (pass_iv_optimize);
1459 NEXT_PASS (pass_lim);
1460 NEXT_PASS (pass_tree_loop_done);
1462 NEXT_PASS (pass_lower_vector_ssa);
1463 NEXT_PASS (pass_cse_reciprocals);
1464 NEXT_PASS (pass_reassoc);
1465 NEXT_PASS (pass_vrp);
1466 NEXT_PASS (pass_dominator);
1467 /* The only const/copy propagation opportunities left after
1468 DOM should be due to degenerate PHI nodes. So rather than
1469 run the full propagators, run a specialized pass which
1470 only examines PHIs to discover const/copy propagation
1471 opportunities. */
1472 NEXT_PASS (pass_phi_only_cprop);
1473 NEXT_PASS (pass_cd_dce);
1474 NEXT_PASS (pass_tracer);
1476 /* FIXME: If DCE is not run before checking for uninitialized uses,
1477 we may get false warnings (e.g., testsuite/gcc.dg/uninit-5.c).
1478 However, this also causes us to misdiagnose cases that should be
1479 real warnings (e.g., testsuite/gcc.dg/pr18501.c).
1481 To fix the false positives in uninit-5.c, we would have to
1482 account for the predicates protecting the set and the use of each
1483 variable. Using a representation like Gated Single Assignment
1484 may help. */
1485 NEXT_PASS (pass_late_warn_uninitialized);
1486 NEXT_PASS (pass_dse);
1487 NEXT_PASS (pass_forwprop);
1488 NEXT_PASS (pass_phiopt);
1489 NEXT_PASS (pass_fold_builtins);
1490 NEXT_PASS (pass_optimize_widening_mul);
1491 NEXT_PASS (pass_tail_calls);
1492 NEXT_PASS (pass_rename_ssa_copies);
1493 NEXT_PASS (pass_uncprop);
1494 NEXT_PASS (pass_local_pure_const);
1496 NEXT_PASS (pass_tm_init);
1498 struct opt_pass **p = &pass_tm_init.pass.sub;
1499 NEXT_PASS (pass_tm_mark);
1500 NEXT_PASS (pass_tm_memopt);
1501 NEXT_PASS (pass_tm_edges);
1503 NEXT_PASS (pass_lower_complex_O0);
1504 NEXT_PASS (pass_cleanup_eh);
1505 NEXT_PASS (pass_lower_resx);
1506 NEXT_PASS (pass_nrv);
1507 NEXT_PASS (pass_mudflap_2);
1508 NEXT_PASS (pass_cleanup_cfg_post_optimizing);
1509 NEXT_PASS (pass_warn_function_noreturn);
1511 NEXT_PASS (pass_expand);
1513 NEXT_PASS (pass_rest_of_compilation);
1515 struct opt_pass **p = &pass_rest_of_compilation.pass.sub;
1516 NEXT_PASS (pass_instantiate_virtual_regs);
1517 NEXT_PASS (pass_into_cfg_layout_mode);
1518 NEXT_PASS (pass_jump2);
1519 NEXT_PASS (pass_lower_subreg);
1520 NEXT_PASS (pass_df_initialize_opt);
1521 NEXT_PASS (pass_cse);
1522 NEXT_PASS (pass_rtl_fwprop);
1523 NEXT_PASS (pass_rtl_cprop);
1524 NEXT_PASS (pass_rtl_pre);
1525 NEXT_PASS (pass_rtl_hoist);
1526 NEXT_PASS (pass_rtl_cprop);
1527 NEXT_PASS (pass_rtl_store_motion);
1528 NEXT_PASS (pass_cse_after_global_opts);
1529 NEXT_PASS (pass_rtl_ifcvt);
1530 NEXT_PASS (pass_reginfo_init);
1531 /* Perform loop optimizations. It might be better to do them a bit
1532 sooner, but we want the profile feedback to work more
1533 efficiently. */
1534 NEXT_PASS (pass_loop2);
1536 struct opt_pass **p = &pass_loop2.pass.sub;
1537 NEXT_PASS (pass_rtl_loop_init);
1538 NEXT_PASS (pass_rtl_move_loop_invariants);
1539 NEXT_PASS (pass_rtl_unswitch);
1540 NEXT_PASS (pass_rtl_unroll_and_peel_loops);
1541 NEXT_PASS (pass_rtl_doloop);
1542 NEXT_PASS (pass_rtl_loop_done);
1543 *p = NULL;
1545 NEXT_PASS (pass_web);
1546 NEXT_PASS (pass_rtl_cprop);
1547 NEXT_PASS (pass_cse2);
1548 NEXT_PASS (pass_rtl_dse1);
1549 NEXT_PASS (pass_rtl_fwprop_addr);
1550 NEXT_PASS (pass_inc_dec);
1551 NEXT_PASS (pass_initialize_regs);
1552 NEXT_PASS (pass_ud_rtl_dce);
1553 NEXT_PASS (pass_combine);
1554 NEXT_PASS (pass_if_after_combine);
1555 NEXT_PASS (pass_partition_blocks);
1556 NEXT_PASS (pass_regmove);
1557 NEXT_PASS (pass_outof_cfg_layout_mode);
1558 NEXT_PASS (pass_split_all_insns);
1559 NEXT_PASS (pass_lower_subreg2);
1560 NEXT_PASS (pass_df_initialize_no_opt);
1561 NEXT_PASS (pass_stack_ptr_mod);
1562 NEXT_PASS (pass_mode_switching);
1563 NEXT_PASS (pass_match_asm_constraints);
1564 NEXT_PASS (pass_sms);
1565 NEXT_PASS (pass_sched);
1566 NEXT_PASS (pass_ira);
1567 NEXT_PASS (pass_reload);
1568 NEXT_PASS (pass_postreload);
1570 struct opt_pass **p = &pass_postreload.pass.sub;
1571 NEXT_PASS (pass_postreload_cse);
1572 NEXT_PASS (pass_gcse2);
1573 NEXT_PASS (pass_split_after_reload);
1574 NEXT_PASS (pass_ree);
1575 NEXT_PASS (pass_compare_elim_after_reload);
1576 NEXT_PASS (pass_branch_target_load_optimize1);
1577 NEXT_PASS (pass_thread_prologue_and_epilogue);
1578 NEXT_PASS (pass_rtl_dse2);
1579 NEXT_PASS (pass_stack_adjustments);
1580 NEXT_PASS (pass_peephole2);
1581 NEXT_PASS (pass_if_after_reload);
1582 NEXT_PASS (pass_regrename);
1583 NEXT_PASS (pass_cprop_hardreg);
1584 NEXT_PASS (pass_fast_rtl_dce);
1585 NEXT_PASS (pass_reorder_blocks);
1586 NEXT_PASS (pass_branch_target_load_optimize2);
1587 NEXT_PASS (pass_leaf_regs);
1588 NEXT_PASS (pass_split_before_sched2);
1589 NEXT_PASS (pass_sched2);
1590 NEXT_PASS (pass_stack_regs);
1592 struct opt_pass **p = &pass_stack_regs.pass.sub;
1593 NEXT_PASS (pass_split_before_regstack);
1594 NEXT_PASS (pass_stack_regs_run);
1596 NEXT_PASS (pass_compute_alignments);
1597 NEXT_PASS (pass_duplicate_computed_gotos);
1598 NEXT_PASS (pass_variable_tracking);
1599 NEXT_PASS (pass_free_cfg);
1600 NEXT_PASS (pass_machine_reorg);
1601 NEXT_PASS (pass_cleanup_barriers);
1602 NEXT_PASS (pass_delay_slots);
1603 NEXT_PASS (pass_split_for_shorten_branches);
1604 NEXT_PASS (pass_convert_to_eh_region_ranges);
1605 NEXT_PASS (pass_shorten_branches);
1606 NEXT_PASS (pass_set_nothrow_function_flags);
1607 NEXT_PASS (pass_dwarf2_frame);
1608 NEXT_PASS (pass_final);
1610 NEXT_PASS (pass_df_finish);
1612 NEXT_PASS (pass_clean_state);
1613 *p = NULL;
1615 #undef NEXT_PASS
1617 /* Register the passes with the tree dump code. */
1618 register_dump_files (all_lowering_passes, PROP_gimple_any);
1619 register_dump_files (all_small_ipa_passes,
1620 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
1621 | PROP_cfg);
1622 register_dump_files (all_regular_ipa_passes,
1623 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
1624 | PROP_cfg);
1625 register_dump_files (all_lto_gen_passes,
1626 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
1627 | PROP_cfg);
1628 register_dump_files (all_late_ipa_passes,
1629 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
1630 | PROP_cfg);
1631 register_dump_files (all_passes,
1632 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
1633 | PROP_cfg);
1636 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1637 function CALLBACK for every function in the call graph. Otherwise,
1638 call CALLBACK on the current function. */
1640 static void
1641 do_per_function (void (*callback) (void *data), void *data)
1643 if (current_function_decl)
1644 callback (data);
1645 else
1647 struct cgraph_node *node;
1648 FOR_EACH_DEFINED_FUNCTION (node)
1649 if (gimple_has_body_p (node->symbol.decl)
1650 && (!node->clone_of || node->symbol.decl != node->clone_of->symbol.decl))
1652 push_cfun (DECL_STRUCT_FUNCTION (node->symbol.decl));
1653 current_function_decl = node->symbol.decl;
1654 callback (data);
1655 if (!flag_wpa)
1657 free_dominance_info (CDI_DOMINATORS);
1658 free_dominance_info (CDI_POST_DOMINATORS);
1660 current_function_decl = NULL;
1661 pop_cfun ();
1662 ggc_collect ();
1667 /* Because inlining might remove no-longer reachable nodes, we need to
1668 keep the array visible to garbage collector to avoid reading collected
1669 out nodes. */
1670 static int nnodes;
1671 static GTY ((length ("nnodes"))) cgraph_node_ptr *order;
1673 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1674 function CALLBACK for every function in the call graph. Otherwise,
1675 call CALLBACK on the current function.
1676 This function is global so that plugins can use it. */
1677 void
1678 do_per_function_toporder (void (*callback) (void *data), void *data)
1680 int i;
1682 if (current_function_decl)
1683 callback (data);
1684 else
1686 gcc_assert (!order);
1687 order = ggc_alloc_vec_cgraph_node_ptr (cgraph_n_nodes);
1688 nnodes = ipa_reverse_postorder (order);
1689 for (i = nnodes - 1; i >= 0; i--)
1690 order[i]->process = 1;
1691 for (i = nnodes - 1; i >= 0; i--)
1693 struct cgraph_node *node = order[i];
1695 /* Allow possibly removed nodes to be garbage collected. */
1696 order[i] = NULL;
1697 node->process = 0;
1698 if (cgraph_function_with_gimple_body_p (node))
1700 push_cfun (DECL_STRUCT_FUNCTION (node->symbol.decl));
1701 current_function_decl = node->symbol.decl;
1702 callback (data);
1703 free_dominance_info (CDI_DOMINATORS);
1704 free_dominance_info (CDI_POST_DOMINATORS);
1705 current_function_decl = NULL;
1706 pop_cfun ();
1707 ggc_collect ();
1711 ggc_free (order);
1712 order = NULL;
1713 nnodes = 0;
1716 /* Helper function to perform function body dump. */
1718 static void
1719 execute_function_dump (void *data ATTRIBUTE_UNUSED)
1721 if (dump_file && current_function_decl)
1723 if (cfun->curr_properties & PROP_trees)
1724 dump_function_to_file (current_function_decl, dump_file, dump_flags);
1725 else
1727 if (dump_flags & TDF_SLIM)
1728 print_rtl_slim_with_bb (dump_file, get_insns (), dump_flags);
1729 else if ((cfun->curr_properties & PROP_cfg)
1730 && (dump_flags & TDF_BLOCKS))
1731 print_rtl_with_bb (dump_file, get_insns ());
1732 else
1733 print_rtl (dump_file, get_insns ());
1735 if ((cfun->curr_properties & PROP_cfg)
1736 && graph_dump_format != no_graph
1737 && (dump_flags & TDF_GRAPH))
1738 print_rtl_graph_with_bb (dump_file_name, get_insns ());
1741 /* Flush the file. If verification fails, we won't be able to
1742 close the file before aborting. */
1743 fflush (dump_file);
1747 /* Perform all TODO actions that ought to be done on each function. */
1749 static void
1750 execute_function_todo (void *data)
1752 unsigned int flags = (size_t)data;
1753 flags &= ~cfun->last_verified;
1754 if (!flags)
1755 return;
1757 /* Always cleanup the CFG before trying to update SSA. */
1758 if (flags & TODO_cleanup_cfg)
1760 bool cleanup = cleanup_tree_cfg ();
1762 if (cleanup && (cfun->curr_properties & PROP_ssa))
1763 flags |= TODO_remove_unused_locals;
1765 /* When cleanup_tree_cfg merges consecutive blocks, it may
1766 perform some simplistic propagation when removing single
1767 valued PHI nodes. This propagation may, in turn, cause the
1768 SSA form to become out-of-date (see PR 22037). So, even
1769 if the parent pass had not scheduled an SSA update, we may
1770 still need to do one. */
1771 if (!(flags & TODO_update_ssa_any) && need_ssa_update_p (cfun))
1772 flags |= TODO_update_ssa;
1775 if (flags & TODO_update_ssa_any)
1777 unsigned update_flags = flags & TODO_update_ssa_any;
1778 update_ssa (update_flags);
1779 cfun->last_verified &= ~TODO_verify_ssa;
1782 if (flags & TODO_rebuild_alias)
1784 execute_update_addresses_taken ();
1785 compute_may_aliases ();
1787 else if (optimize && (flags & TODO_update_address_taken))
1788 execute_update_addresses_taken ();
1790 if (flags & TODO_remove_unused_locals)
1791 remove_unused_locals ();
1793 if (flags & TODO_rebuild_frequencies)
1794 rebuild_frequencies ();
1796 if (flags & TODO_rebuild_cgraph_edges)
1797 rebuild_cgraph_edges ();
1799 /* If we've seen errors do not bother running any verifiers. */
1800 if (seen_error ())
1801 return;
1803 #if defined ENABLE_CHECKING
1804 if (flags & TODO_verify_ssa
1805 || (current_loops && loops_state_satisfies_p (LOOP_CLOSED_SSA)))
1807 verify_gimple_in_cfg (cfun);
1808 verify_ssa (true);
1810 else if (flags & TODO_verify_stmts)
1811 verify_gimple_in_cfg (cfun);
1812 if (flags & TODO_verify_flow)
1813 verify_flow_info ();
1814 if (current_loops && loops_state_satisfies_p (LOOP_CLOSED_SSA))
1815 verify_loop_closed_ssa (false);
1816 if (flags & TODO_verify_rtl_sharing)
1817 verify_rtl_sharing ();
1818 #endif
1820 cfun->last_verified = flags & TODO_verify_all;
1823 /* Perform all TODO actions. */
1824 static void
1825 execute_todo (unsigned int flags)
1827 #if defined ENABLE_CHECKING
1828 if (cfun
1829 && need_ssa_update_p (cfun))
1830 gcc_assert (flags & TODO_update_ssa_any);
1831 #endif
1833 timevar_push (TV_TODO);
1835 /* Inform the pass whether it is the first time it is run. */
1836 first_pass_instance = (flags & TODO_mark_first_instance) != 0;
1838 statistics_fini_pass ();
1840 do_per_function (execute_function_todo, (void *)(size_t) flags);
1842 /* Always remove functions just as before inlining: IPA passes might be
1843 interested to see bodies of extern inline functions that are not inlined
1844 to analyze side effects. The full removal is done just at the end
1845 of IPA pass queue. */
1846 if (flags & TODO_remove_functions)
1848 gcc_assert (!cfun);
1849 symtab_remove_unreachable_nodes (true, dump_file);
1852 if ((flags & TODO_dump_symtab) && dump_file && !current_function_decl)
1854 gcc_assert (!cfun);
1855 dump_symtab (dump_file);
1856 /* Flush the file. If verification fails, we won't be able to
1857 close the file before aborting. */
1858 fflush (dump_file);
1861 if (flags & TODO_ggc_collect)
1862 ggc_collect ();
1864 /* Now that the dumping has been done, we can get rid of the optional
1865 df problems. */
1866 if (flags & TODO_df_finish)
1867 df_finish_pass ((flags & TODO_df_verify) != 0);
1869 timevar_pop (TV_TODO);
1872 /* Verify invariants that should hold between passes. This is a place
1873 to put simple sanity checks. */
1875 static void
1876 verify_interpass_invariants (void)
1878 gcc_checking_assert (!fold_deferring_overflow_warnings_p ());
1881 /* Clear the last verified flag. */
1883 static void
1884 clear_last_verified (void *data ATTRIBUTE_UNUSED)
1886 cfun->last_verified = 0;
1889 /* Helper function. Verify that the properties has been turn into the
1890 properties expected by the pass. */
1892 #ifdef ENABLE_CHECKING
1893 static void
1894 verify_curr_properties (void *data)
1896 unsigned int props = (size_t)data;
1897 gcc_assert ((cfun->curr_properties & props) == props);
1899 #endif
1901 /* Initialize pass dump file. */
1902 /* This is non-static so that the plugins can use it. */
1904 bool
1905 pass_init_dump_file (struct opt_pass *pass)
1907 /* If a dump file name is present, open it if enabled. */
1908 if (pass->static_pass_number != -1)
1910 bool initializing_dump = !dump_initialized_p (pass->static_pass_number);
1911 dump_file_name = get_dump_file_name (pass->static_pass_number);
1912 dump_file = dump_begin (pass->static_pass_number, &dump_flags);
1913 if (dump_file && current_function_decl)
1914 dump_function_header (dump_file, current_function_decl, dump_flags);
1915 return initializing_dump;
1917 else
1918 return false;
1921 /* Flush PASS dump file. */
1922 /* This is non-static so that plugins can use it. */
1924 void
1925 pass_fini_dump_file (struct opt_pass *pass)
1927 /* Flush and close dump file. */
1928 if (dump_file_name)
1930 free (CONST_CAST (char *, dump_file_name));
1931 dump_file_name = NULL;
1934 if (dump_file)
1936 dump_end (pass->static_pass_number, dump_file);
1937 dump_file = NULL;
1941 /* After executing the pass, apply expected changes to the function
1942 properties. */
1944 static void
1945 update_properties_after_pass (void *data)
1947 struct opt_pass *pass = (struct opt_pass *) data;
1948 cfun->curr_properties = (cfun->curr_properties | pass->properties_provided)
1949 & ~pass->properties_destroyed;
1952 /* Execute summary generation for all of the passes in IPA_PASS. */
1954 void
1955 execute_ipa_summary_passes (struct ipa_opt_pass_d *ipa_pass)
1957 while (ipa_pass)
1959 struct opt_pass *pass = &ipa_pass->pass;
1961 /* Execute all of the IPA_PASSes in the list. */
1962 if (ipa_pass->pass.type == IPA_PASS
1963 && (!pass->gate || pass->gate ())
1964 && ipa_pass->generate_summary)
1966 pass_init_dump_file (pass);
1968 /* If a timevar is present, start it. */
1969 if (pass->tv_id)
1970 timevar_push (pass->tv_id);
1972 ipa_pass->generate_summary ();
1974 /* Stop timevar. */
1975 if (pass->tv_id)
1976 timevar_pop (pass->tv_id);
1978 pass_fini_dump_file (pass);
1980 ipa_pass = (struct ipa_opt_pass_d *)ipa_pass->pass.next;
1984 /* Execute IPA_PASS function transform on NODE. */
1986 static void
1987 execute_one_ipa_transform_pass (struct cgraph_node *node,
1988 struct ipa_opt_pass_d *ipa_pass)
1990 struct opt_pass *pass = &ipa_pass->pass;
1991 unsigned int todo_after = 0;
1993 current_pass = pass;
1994 if (!ipa_pass->function_transform)
1995 return;
1997 /* Note that the folders should only create gimple expressions.
1998 This is a hack until the new folder is ready. */
1999 in_gimple_form = (cfun && (cfun->curr_properties & PROP_trees)) != 0;
2001 pass_init_dump_file (pass);
2003 /* Run pre-pass verification. */
2004 execute_todo (ipa_pass->function_transform_todo_flags_start);
2006 /* If a timevar is present, start it. */
2007 if (pass->tv_id != TV_NONE)
2008 timevar_push (pass->tv_id);
2010 /* Do it! */
2011 todo_after = ipa_pass->function_transform (node);
2013 /* Stop timevar. */
2014 if (pass->tv_id != TV_NONE)
2015 timevar_pop (pass->tv_id);
2017 /* Run post-pass cleanup and verification. */
2018 execute_todo (todo_after);
2019 verify_interpass_invariants ();
2021 do_per_function (execute_function_dump, NULL);
2022 pass_fini_dump_file (pass);
2024 current_pass = NULL;
2027 /* For the current function, execute all ipa transforms. */
2029 void
2030 execute_all_ipa_transforms (void)
2032 struct cgraph_node *node;
2033 if (!cfun)
2034 return;
2035 node = cgraph_get_node (current_function_decl);
2037 if (node->ipa_transforms_to_apply)
2039 unsigned int i;
2041 for (i = 0; i < VEC_length (ipa_opt_pass, node->ipa_transforms_to_apply);
2042 i++)
2043 execute_one_ipa_transform_pass (node,
2044 VEC_index (ipa_opt_pass,
2045 node->ipa_transforms_to_apply,
2046 i));
2047 VEC_free (ipa_opt_pass, heap, node->ipa_transforms_to_apply);
2048 node->ipa_transforms_to_apply = NULL;
2052 /* Callback for do_per_function to apply all IPA transforms. */
2054 static void
2055 apply_ipa_transforms (void *data)
2057 struct cgraph_node *node = cgraph_get_node (current_function_decl);
2058 if (!node->global.inlined_to && node->ipa_transforms_to_apply)
2060 *(bool *)data = true;
2061 execute_all_ipa_transforms();
2062 rebuild_cgraph_edges ();
2066 /* Check if PASS is explicitly disabled or enabled and return
2067 the gate status. FUNC is the function to be processed, and
2068 GATE_STATUS is the gate status determined by pass manager by
2069 default. */
2071 static bool
2072 override_gate_status (struct opt_pass *pass, tree func, bool gate_status)
2074 bool explicitly_enabled = false;
2075 bool explicitly_disabled = false;
2077 explicitly_enabled
2078 = is_pass_explicitly_enabled_or_disabled (pass, func,
2079 enabled_pass_uid_range_tab);
2080 explicitly_disabled
2081 = is_pass_explicitly_enabled_or_disabled (pass, func,
2082 disabled_pass_uid_range_tab);
2084 gate_status = !explicitly_disabled && (gate_status || explicitly_enabled);
2086 return gate_status;
2090 /* Execute PASS. */
2092 bool
2093 execute_one_pass (struct opt_pass *pass)
2095 bool initializing_dump;
2096 unsigned int todo_after = 0;
2098 bool gate_status;
2100 /* IPA passes are executed on whole program, so cfun should be NULL.
2101 Other passes need function context set. */
2102 if (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS)
2103 gcc_assert (!cfun && !current_function_decl);
2104 else
2105 gcc_assert (cfun && current_function_decl);
2107 current_pass = pass;
2109 /* Check whether gate check should be avoided.
2110 User controls the value of the gate through the parameter "gate_status". */
2111 gate_status = (pass->gate == NULL) ? true : pass->gate();
2112 gate_status = override_gate_status (pass, current_function_decl, gate_status);
2114 /* Override gate with plugin. */
2115 invoke_plugin_callbacks (PLUGIN_OVERRIDE_GATE, &gate_status);
2117 if (!gate_status)
2119 current_pass = NULL;
2120 return false;
2123 /* Pass execution event trigger: useful to identify passes being
2124 executed. */
2125 invoke_plugin_callbacks (PLUGIN_PASS_EXECUTION, pass);
2127 /* SIPLE IPA passes do not handle callgraphs with IPA transforms in it.
2128 Apply all trnasforms first. */
2129 if (pass->type == SIMPLE_IPA_PASS)
2131 bool applied = false;
2132 do_per_function (apply_ipa_transforms, (void *)&applied);
2133 if (applied)
2134 symtab_remove_unreachable_nodes (true, dump_file);
2135 /* Restore current_pass. */
2136 current_pass = pass;
2139 if (!quiet_flag && !cfun)
2140 fprintf (stderr, " <%s>", pass->name ? pass->name : "");
2142 /* Note that the folders should only create gimple expressions.
2143 This is a hack until the new folder is ready. */
2144 in_gimple_form = (cfun && (cfun->curr_properties & PROP_trees)) != 0;
2146 initializing_dump = pass_init_dump_file (pass);
2148 /* Run pre-pass verification. */
2149 execute_todo (pass->todo_flags_start);
2151 #ifdef ENABLE_CHECKING
2152 do_per_function (verify_curr_properties,
2153 (void *)(size_t)pass->properties_required);
2154 #endif
2156 /* If a timevar is present, start it. */
2157 if (pass->tv_id != TV_NONE)
2158 timevar_push (pass->tv_id);
2160 /* Do it! */
2161 if (pass->execute)
2163 todo_after = pass->execute ();
2164 do_per_function (clear_last_verified, NULL);
2167 /* Stop timevar. */
2168 if (pass->tv_id != TV_NONE)
2169 timevar_pop (pass->tv_id);
2171 do_per_function (update_properties_after_pass, pass);
2173 if (initializing_dump
2174 && dump_file
2175 && graph_dump_format != no_graph
2176 && cfun
2177 && (cfun->curr_properties & (PROP_cfg | PROP_rtl))
2178 == (PROP_cfg | PROP_rtl))
2180 get_dump_file_info (pass->static_pass_number)->flags |= TDF_GRAPH;
2181 dump_flags |= TDF_GRAPH;
2182 clean_graph_dump_file (dump_file_name);
2185 /* Run post-pass cleanup and verification. */
2186 execute_todo (todo_after | pass->todo_flags_finish);
2187 verify_interpass_invariants ();
2188 do_per_function (execute_function_dump, NULL);
2189 if (pass->type == IPA_PASS)
2191 struct cgraph_node *node;
2192 FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node)
2193 VEC_safe_push (ipa_opt_pass, heap, node->ipa_transforms_to_apply,
2194 (struct ipa_opt_pass_d *)pass);
2197 if (!current_function_decl)
2198 cgraph_process_new_functions ();
2200 pass_fini_dump_file (pass);
2202 if (pass->type != SIMPLE_IPA_PASS && pass->type != IPA_PASS)
2203 gcc_assert (!(cfun->curr_properties & PROP_trees)
2204 || pass->type != RTL_PASS);
2206 current_pass = NULL;
2208 return true;
2211 void
2212 execute_pass_list (struct opt_pass *pass)
2216 gcc_assert (pass->type == GIMPLE_PASS
2217 || pass->type == RTL_PASS);
2218 if (execute_one_pass (pass) && pass->sub)
2219 execute_pass_list (pass->sub);
2220 pass = pass->next;
2222 while (pass);
2225 /* Same as execute_pass_list but assume that subpasses of IPA passes
2226 are local passes. If SET is not NULL, write out summaries of only
2227 those node in SET. */
2229 static void
2230 ipa_write_summaries_2 (struct opt_pass *pass, cgraph_node_set set,
2231 varpool_node_set vset,
2232 struct lto_out_decl_state *state)
2234 while (pass)
2236 struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *)pass;
2237 gcc_assert (!current_function_decl);
2238 gcc_assert (!cfun);
2239 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
2240 if (pass->type == IPA_PASS
2241 && ipa_pass->write_summary
2242 && (!pass->gate || pass->gate ()))
2244 /* If a timevar is present, start it. */
2245 if (pass->tv_id)
2246 timevar_push (pass->tv_id);
2248 pass_init_dump_file (pass);
2250 ipa_pass->write_summary (set,vset);
2252 pass_fini_dump_file (pass);
2254 /* If a timevar is present, start it. */
2255 if (pass->tv_id)
2256 timevar_pop (pass->tv_id);
2259 if (pass->sub && pass->sub->type != GIMPLE_PASS)
2260 ipa_write_summaries_2 (pass->sub, set, vset, state);
2262 pass = pass->next;
2266 /* Helper function of ipa_write_summaries. Creates and destroys the
2267 decl state and calls ipa_write_summaries_2 for all passes that have
2268 summaries. SET is the set of nodes to be written. */
2270 static void
2271 ipa_write_summaries_1 (cgraph_node_set set, varpool_node_set vset)
2273 struct lto_out_decl_state *state = lto_new_out_decl_state ();
2274 compute_ltrans_boundary (state, set, vset);
2276 lto_push_out_decl_state (state);
2278 gcc_assert (!flag_wpa);
2279 ipa_write_summaries_2 (all_regular_ipa_passes, set, vset, state);
2280 ipa_write_summaries_2 (all_lto_gen_passes, set, vset, state);
2282 gcc_assert (lto_get_out_decl_state () == state);
2283 lto_pop_out_decl_state ();
2284 lto_delete_out_decl_state (state);
2287 /* Write out summaries for all the nodes in the callgraph. */
2289 void
2290 ipa_write_summaries (void)
2292 cgraph_node_set set;
2293 varpool_node_set vset;
2294 struct cgraph_node **order;
2295 struct varpool_node *vnode;
2296 int i, order_pos;
2298 if (!flag_generate_lto || seen_error ())
2299 return;
2301 set = cgraph_node_set_new ();
2303 /* Create the callgraph set in the same order used in
2304 cgraph_expand_all_functions. This mostly facilitates debugging,
2305 since it causes the gimple file to be processed in the same order
2306 as the source code. */
2307 order = XCNEWVEC (struct cgraph_node *, cgraph_n_nodes);
2308 order_pos = ipa_reverse_postorder (order);
2309 gcc_assert (order_pos == cgraph_n_nodes);
2311 for (i = order_pos - 1; i >= 0; i--)
2313 struct cgraph_node *node = order[i];
2315 if (cgraph_function_with_gimple_body_p (node))
2317 /* When streaming out references to statements as part of some IPA
2318 pass summary, the statements need to have uids assigned and the
2319 following does that for all the IPA passes here. Naturally, this
2320 ordering then matches the one IPA-passes get in their stmt_fixup
2321 hooks. */
2323 push_cfun (DECL_STRUCT_FUNCTION (node->symbol.decl));
2324 renumber_gimple_stmt_uids ();
2325 pop_cfun ();
2327 if (node->analyzed)
2328 cgraph_node_set_add (set, node);
2330 vset = varpool_node_set_new ();
2332 FOR_EACH_DEFINED_VARIABLE (vnode)
2333 if ((!vnode->alias || vnode->alias_of))
2334 varpool_node_set_add (vset, vnode);
2336 ipa_write_summaries_1 (set, vset);
2338 free (order);
2339 free_cgraph_node_set (set);
2340 free_varpool_node_set (vset);
2343 /* Same as execute_pass_list but assume that subpasses of IPA passes
2344 are local passes. If SET is not NULL, write out optimization summaries of
2345 only those node in SET. */
2347 static void
2348 ipa_write_optimization_summaries_1 (struct opt_pass *pass, cgraph_node_set set,
2349 varpool_node_set vset,
2350 struct lto_out_decl_state *state)
2352 while (pass)
2354 struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *)pass;
2355 gcc_assert (!current_function_decl);
2356 gcc_assert (!cfun);
2357 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
2358 if (pass->type == IPA_PASS
2359 && ipa_pass->write_optimization_summary
2360 && (!pass->gate || pass->gate ()))
2362 /* If a timevar is present, start it. */
2363 if (pass->tv_id)
2364 timevar_push (pass->tv_id);
2366 pass_init_dump_file (pass);
2368 ipa_pass->write_optimization_summary (set, vset);
2370 pass_fini_dump_file (pass);
2372 /* If a timevar is present, start it. */
2373 if (pass->tv_id)
2374 timevar_pop (pass->tv_id);
2377 if (pass->sub && pass->sub->type != GIMPLE_PASS)
2378 ipa_write_optimization_summaries_1 (pass->sub, set, vset, state);
2380 pass = pass->next;
2384 /* Write all the optimization summaries for the cgraph nodes in SET. If SET is
2385 NULL, write out all summaries of all nodes. */
2387 void
2388 ipa_write_optimization_summaries (cgraph_node_set set, varpool_node_set vset)
2390 struct lto_out_decl_state *state = lto_new_out_decl_state ();
2391 cgraph_node_set_iterator csi;
2392 compute_ltrans_boundary (state, set, vset);
2394 lto_push_out_decl_state (state);
2395 for (csi = csi_start (set); !csi_end_p (csi); csi_next (&csi))
2397 struct cgraph_node *node = csi_node (csi);
2398 /* When streaming out references to statements as part of some IPA
2399 pass summary, the statements need to have uids assigned.
2401 For functions newly born at WPA stage we need to initialize
2402 the uids here. */
2403 if (node->analyzed
2404 && gimple_has_body_p (node->symbol.decl))
2406 push_cfun (DECL_STRUCT_FUNCTION (node->symbol.decl));
2407 renumber_gimple_stmt_uids ();
2408 pop_cfun ();
2412 gcc_assert (flag_wpa);
2413 ipa_write_optimization_summaries_1 (all_regular_ipa_passes, set, vset, state);
2414 ipa_write_optimization_summaries_1 (all_lto_gen_passes, set, vset, state);
2416 gcc_assert (lto_get_out_decl_state () == state);
2417 lto_pop_out_decl_state ();
2418 lto_delete_out_decl_state (state);
2421 /* Same as execute_pass_list but assume that subpasses of IPA passes
2422 are local passes. */
2424 static void
2425 ipa_read_summaries_1 (struct opt_pass *pass)
2427 while (pass)
2429 struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *) pass;
2431 gcc_assert (!current_function_decl);
2432 gcc_assert (!cfun);
2433 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
2435 if (pass->gate == NULL || pass->gate ())
2437 if (pass->type == IPA_PASS && ipa_pass->read_summary)
2439 /* If a timevar is present, start it. */
2440 if (pass->tv_id)
2441 timevar_push (pass->tv_id);
2443 pass_init_dump_file (pass);
2445 ipa_pass->read_summary ();
2447 pass_fini_dump_file (pass);
2449 /* Stop timevar. */
2450 if (pass->tv_id)
2451 timevar_pop (pass->tv_id);
2454 if (pass->sub && pass->sub->type != GIMPLE_PASS)
2455 ipa_read_summaries_1 (pass->sub);
2457 pass = pass->next;
2462 /* Read all the summaries for all_regular_ipa_passes and all_lto_gen_passes. */
2464 void
2465 ipa_read_summaries (void)
2467 ipa_read_summaries_1 (all_regular_ipa_passes);
2468 ipa_read_summaries_1 (all_lto_gen_passes);
2471 /* Same as execute_pass_list but assume that subpasses of IPA passes
2472 are local passes. */
2474 static void
2475 ipa_read_optimization_summaries_1 (struct opt_pass *pass)
2477 while (pass)
2479 struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *) pass;
2481 gcc_assert (!current_function_decl);
2482 gcc_assert (!cfun);
2483 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
2485 if (pass->gate == NULL || pass->gate ())
2487 if (pass->type == IPA_PASS && ipa_pass->read_optimization_summary)
2489 /* If a timevar is present, start it. */
2490 if (pass->tv_id)
2491 timevar_push (pass->tv_id);
2493 pass_init_dump_file (pass);
2495 ipa_pass->read_optimization_summary ();
2497 pass_fini_dump_file (pass);
2499 /* Stop timevar. */
2500 if (pass->tv_id)
2501 timevar_pop (pass->tv_id);
2504 if (pass->sub && pass->sub->type != GIMPLE_PASS)
2505 ipa_read_optimization_summaries_1 (pass->sub);
2507 pass = pass->next;
2511 /* Read all the summaries for all_regular_ipa_passes and all_lto_gen_passes. */
2513 void
2514 ipa_read_optimization_summaries (void)
2516 ipa_read_optimization_summaries_1 (all_regular_ipa_passes);
2517 ipa_read_optimization_summaries_1 (all_lto_gen_passes);
2520 /* Same as execute_pass_list but assume that subpasses of IPA passes
2521 are local passes. */
2522 void
2523 execute_ipa_pass_list (struct opt_pass *pass)
2527 gcc_assert (!current_function_decl);
2528 gcc_assert (!cfun);
2529 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
2530 if (execute_one_pass (pass) && pass->sub)
2532 if (pass->sub->type == GIMPLE_PASS)
2534 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_START, NULL);
2535 do_per_function_toporder ((void (*)(void *))execute_pass_list,
2536 pass->sub);
2537 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_END, NULL);
2539 else if (pass->sub->type == SIMPLE_IPA_PASS
2540 || pass->sub->type == IPA_PASS)
2541 execute_ipa_pass_list (pass->sub);
2542 else
2543 gcc_unreachable ();
2545 gcc_assert (!current_function_decl);
2546 cgraph_process_new_functions ();
2547 pass = pass->next;
2549 while (pass);
2552 /* Execute stmt fixup hooks of all passes in PASS for NODE and STMTS. */
2554 static void
2555 execute_ipa_stmt_fixups (struct opt_pass *pass,
2556 struct cgraph_node *node, gimple *stmts)
2558 while (pass)
2560 /* Execute all of the IPA_PASSes in the list. */
2561 if (pass->type == IPA_PASS
2562 && (!pass->gate || pass->gate ()))
2564 struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *) pass;
2566 if (ipa_pass->stmt_fixup)
2568 pass_init_dump_file (pass);
2569 /* If a timevar is present, start it. */
2570 if (pass->tv_id)
2571 timevar_push (pass->tv_id);
2573 ipa_pass->stmt_fixup (node, stmts);
2575 /* Stop timevar. */
2576 if (pass->tv_id)
2577 timevar_pop (pass->tv_id);
2578 pass_fini_dump_file (pass);
2580 if (pass->sub)
2581 execute_ipa_stmt_fixups (pass->sub, node, stmts);
2583 pass = pass->next;
2587 /* Execute stmt fixup hooks of all IPA passes for NODE and STMTS. */
2589 void
2590 execute_all_ipa_stmt_fixups (struct cgraph_node *node, gimple *stmts)
2592 execute_ipa_stmt_fixups (all_regular_ipa_passes, node, stmts);
2596 extern void debug_properties (unsigned int);
2597 extern void dump_properties (FILE *, unsigned int);
2599 DEBUG_FUNCTION void
2600 dump_properties (FILE *dump, unsigned int props)
2602 fprintf (dump, "Properties:\n");
2603 if (props & PROP_gimple_any)
2604 fprintf (dump, "PROP_gimple_any\n");
2605 if (props & PROP_gimple_lcf)
2606 fprintf (dump, "PROP_gimple_lcf\n");
2607 if (props & PROP_gimple_leh)
2608 fprintf (dump, "PROP_gimple_leh\n");
2609 if (props & PROP_cfg)
2610 fprintf (dump, "PROP_cfg\n");
2611 if (props & PROP_referenced_vars)
2612 fprintf (dump, "PROP_referenced_vars\n");
2613 if (props & PROP_ssa)
2614 fprintf (dump, "PROP_ssa\n");
2615 if (props & PROP_no_crit_edges)
2616 fprintf (dump, "PROP_no_crit_edges\n");
2617 if (props & PROP_rtl)
2618 fprintf (dump, "PROP_rtl\n");
2619 if (props & PROP_gimple_lomp)
2620 fprintf (dump, "PROP_gimple_lomp\n");
2621 if (props & PROP_gimple_lcx)
2622 fprintf (dump, "PROP_gimple_lcx\n");
2623 if (props & PROP_cfglayout)
2624 fprintf (dump, "PROP_cfglayout\n");
2627 DEBUG_FUNCTION void
2628 debug_properties (unsigned int props)
2630 dump_properties (stderr, props);
2633 /* Called by local passes to see if function is called by already processed nodes.
2634 Because we process nodes in topological order, this means that function is
2635 in recursive cycle or we introduced new direct calls. */
2636 bool
2637 function_called_by_processed_nodes_p (void)
2639 struct cgraph_edge *e;
2640 for (e = cgraph_get_node (current_function_decl)->callers;
2642 e = e->next_caller)
2644 if (e->caller->symbol.decl == current_function_decl)
2645 continue;
2646 if (!cgraph_function_with_gimple_body_p (e->caller))
2647 continue;
2648 if (TREE_ASM_WRITTEN (e->caller->symbol.decl))
2649 continue;
2650 if (!e->caller->process && !e->caller->global.inlined_to)
2651 break;
2653 if (dump_file && e)
2655 fprintf (dump_file, "Already processed call to:\n");
2656 dump_cgraph_node (dump_file, e->caller);
2658 return e != NULL;
2661 #include "gt-passes.h"