This patch suppresses the messages printed when the primary module is not found.
[official-gcc.git] / gcc-4_7 / gcc / passes.c
blobc277d80f0fbaebcfb1b021c92aad9d5176f3ffa6
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 "dwarf2asm.h"
57 #include "integrate.h"
58 #include "debug.h"
59 #include "target.h"
60 #include "langhooks.h"
61 #include "cfglayout.h"
62 #include "cfgloop.h"
63 #include "hosthooks.h"
64 #include "cgraph.h"
65 #include "opts.h"
66 #include "coverage.h"
67 #include "value-prof.h"
68 #include "tree-inline.h"
69 #include "tree-flow.h"
70 #include "tree-pass.h"
71 #include "tree-dump.h"
72 #include "df.h"
73 #include "predict.h"
74 #include "lto-streamer.h"
75 #include "plugin.h"
76 #include "l-ipo.h"
77 #include "ipa-utils.h"
78 #include "tree-pretty-print.h"
80 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
81 #include "dwarf2out.h"
82 #endif
84 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
85 #include "dbxout.h"
86 #endif
88 #ifdef SDB_DEBUGGING_INFO
89 #include "sdbout.h"
90 #endif
92 #ifdef XCOFF_DEBUGGING_INFO
93 #include "xcoffout.h" /* Needed for external data
94 declarations for e.g. AIX 4.x. */
95 #endif
97 /* This is used for debugging. It allows the current pass to printed
98 from anywhere in compilation.
99 The variable current_pass is also used for statistics and plugins. */
100 struct opt_pass *current_pass;
102 static void register_pass_name (struct opt_pass *, const char *);
104 /* Call from anywhere to find out what pass this is. Useful for
105 printing out debugging information deep inside an service
106 routine. */
107 void
108 print_current_pass (FILE *file)
110 if (current_pass)
111 fprintf (file, "current pass = %s (%d)\n",
112 current_pass->name, current_pass->static_pass_number);
113 else
114 fprintf (file, "no current pass.\n");
118 /* Call from the debugger to get the current pass name. */
119 DEBUG_FUNCTION void
120 debug_pass (void)
122 print_current_pass (stderr);
127 /* Global variables used to communicate with passes. */
128 int dump_flags;
129 bool in_gimple_form;
130 bool first_pass_instance;
133 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
134 and TYPE_DECL nodes.
136 This does nothing for local (non-static) variables, unless the
137 variable is a register variable with DECL_ASSEMBLER_NAME set. In
138 that case, or if the variable is not an automatic, it sets up the
139 RTL and outputs any assembler code (label definition, storage
140 allocation and initialization).
142 DECL is the declaration. TOP_LEVEL is nonzero
143 if this declaration is not within a function. */
145 void
146 rest_of_decl_compilation (tree decl,
147 int top_level,
148 int at_end)
150 /* We deferred calling assemble_alias so that we could collect
151 other attributes such as visibility. Emit the alias now. */
152 if (!in_lto_p)
154 tree alias;
155 alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
156 if (alias)
158 alias = TREE_VALUE (TREE_VALUE (alias));
159 alias = get_identifier (TREE_STRING_POINTER (alias));
160 /* A quirk of the initial implementation of aliases required that the
161 user add "extern" to all of them. Which is silly, but now
162 historical. Do note that the symbol is in fact locally defined. */
163 if (!lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))
164 DECL_EXTERNAL (decl) = 0;
165 assemble_alias (decl, alias);
169 /* Can't defer this, because it needs to happen before any
170 later function definitions are processed. */
171 if (DECL_ASSEMBLER_NAME_SET_P (decl) && DECL_REGISTER (decl))
172 make_decl_rtl (decl);
174 /* Forward declarations for nested functions are not "external",
175 but we need to treat them as if they were. */
176 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
177 || TREE_CODE (decl) == FUNCTION_DECL)
179 timevar_push (TV_VARCONST);
181 /* Don't output anything when a tentative file-scope definition
182 is seen. But at end of compilation, do output code for them.
184 We do output all variables and rely on
185 callgraph code to defer them except for forward declarations
186 (see gcc.c-torture/compile/920624-1.c) */
187 if ((at_end
188 || !DECL_DEFER_OUTPUT (decl)
189 || DECL_INITIAL (decl))
190 && !DECL_EXTERNAL (decl))
192 /* When reading LTO unit, we also read varpool, so do not
193 rebuild it. */
194 if (in_lto_p && !at_end)
196 else if (TREE_CODE (decl) != FUNCTION_DECL)
197 varpool_finalize_decl (decl);
200 #ifdef ASM_FINISH_DECLARE_OBJECT
201 if (decl == last_assemble_variable_decl)
203 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
204 top_level, at_end);
206 #endif
207 if (L_IPO_COMP_MODE)
209 /* Create the node early during parsing so
210 that module id can be captured. */
211 if (TREE_CODE (decl) == VAR_DECL)
212 varpool_node (decl);
215 timevar_pop (TV_VARCONST);
217 else if (TREE_CODE (decl) == TYPE_DECL
218 /* Like in rest_of_type_compilation, avoid confusing the debug
219 information machinery when there are errors. */
220 && !seen_error ())
222 timevar_push (TV_SYMOUT);
223 debug_hooks->type_decl (decl, !top_level);
224 timevar_pop (TV_SYMOUT);
227 /* Let cgraph know about the existence of variables. */
228 if (in_lto_p && !at_end)
230 else if (TREE_CODE (decl) == VAR_DECL && !DECL_EXTERNAL (decl)
231 && TREE_STATIC (decl))
232 varpool_node (decl);
235 /* Called after finishing a record, union or enumeral type. */
237 void
238 rest_of_type_compilation (tree type, int toplev)
240 /* Avoid confusing the debug information machinery when there are
241 errors. */
242 if (seen_error ())
243 return;
245 timevar_push (TV_SYMOUT);
246 debug_hooks->type_decl (TYPE_STUB_DECL (type), !toplev);
247 timevar_pop (TV_SYMOUT);
252 void
253 finish_optimization_passes (void)
255 int i;
256 struct dump_file_info *dfi;
257 char *name;
259 timevar_push (TV_DUMP);
260 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
262 dump_file = dump_begin (pass_profile.pass.static_pass_number, NULL);
263 end_branch_prob ();
264 if (dump_file)
265 dump_end (pass_profile.pass.static_pass_number, dump_file);
268 if (optimize > 0)
270 dump_file = dump_begin (pass_combine.pass.static_pass_number, NULL);
271 if (dump_file)
273 dump_combine_total_stats (dump_file);
274 dump_end (pass_combine.pass.static_pass_number, dump_file);
278 /* Do whatever is necessary to finish printing the graphs. */
279 if (graph_dump_format != no_graph)
280 for (i = TDI_end; (dfi = get_dump_file_info (i)) != NULL; ++i)
281 if (dump_initialized_p (i)
282 && (dfi->flags & TDF_GRAPH) != 0
283 && (name = get_dump_file_name (i)) != NULL)
285 finish_graph_dump_file (name);
286 free (name);
289 timevar_pop (TV_DUMP);
292 static bool
293 gate_rest_of_compilation (void)
295 /* Early return if there were errors. We can run afoul of our
296 consistency checks, and there's not really much point in fixing them. */
297 return !(rtl_dump_and_exit || flag_syntax_only || seen_error ());
300 struct gimple_opt_pass pass_rest_of_compilation =
303 GIMPLE_PASS,
304 "*rest_of_compilation", /* name */
305 gate_rest_of_compilation, /* gate */
306 NULL, /* execute */
307 NULL, /* sub */
308 NULL, /* next */
309 0, /* static_pass_number */
310 TV_REST_OF_COMPILATION, /* tv_id */
311 PROP_rtl, /* properties_required */
312 0, /* properties_provided */
313 0, /* properties_destroyed */
314 0, /* todo_flags_start */
315 TODO_ggc_collect /* todo_flags_finish */
319 static bool
320 gate_postreload (void)
322 return reload_completed;
325 struct rtl_opt_pass pass_postreload =
328 RTL_PASS,
329 "*all-postreload", /* name */
330 gate_postreload, /* gate */
331 NULL, /* execute */
332 NULL, /* sub */
333 NULL, /* next */
334 0, /* static_pass_number */
335 TV_POSTRELOAD, /* tv_id */
336 PROP_rtl, /* properties_required */
337 0, /* properties_provided */
338 0, /* properties_destroyed */
339 0, /* todo_flags_start */
340 TODO_ggc_collect | TODO_verify_rtl_sharing /* todo_flags_finish */
346 /* The root of the compilation pass tree, once constructed. */
347 struct opt_pass *all_passes, *all_small_ipa_passes, *all_lowering_passes,
348 *all_regular_ipa_passes, *all_late_ipa_passes, *all_lto_gen_passes;
350 /* This is used by plugins, and should also be used in register_pass. */
351 #define DEF_PASS_LIST(LIST) &LIST,
352 struct opt_pass **gcc_pass_lists[] = { GCC_PASS_LISTS NULL };
353 #undef DEF_PASS_LIST
355 /* A map from static pass id to optimization pass. */
356 struct opt_pass **passes_by_id;
357 int passes_by_id_size;
359 /* Set the static pass number of pass PASS to ID and record that
360 in the mapping from static pass number to pass. */
362 static void
363 set_pass_for_id (int id, struct opt_pass *pass)
365 pass->static_pass_number = id;
366 if (passes_by_id_size <= id)
368 passes_by_id = XRESIZEVEC (struct opt_pass *, passes_by_id, id + 1);
369 memset (passes_by_id + passes_by_id_size, 0,
370 (id + 1 - passes_by_id_size) * sizeof (void *));
371 passes_by_id_size = id + 1;
373 passes_by_id[id] = pass;
376 /* Return the pass with the static pass number ID. */
378 struct opt_pass *
379 get_pass_for_id (int id)
381 if (id >= passes_by_id_size)
382 return NULL;
383 return passes_by_id[id];
386 /* Iterate over the pass tree allocating dump file numbers. We want
387 to do this depth first, and independent of whether the pass is
388 enabled or not. */
390 void
391 register_one_dump_file (struct opt_pass *pass)
393 char *dot_name, *flag_name, *glob_name;
394 const char *name, *full_name, *prefix;
395 char num[10];
396 int flags, id;
398 /* See below in next_pass_1. */
399 num[0] = '\0';
400 if (pass->static_pass_number != -1)
401 sprintf (num, "%d", ((int) pass->static_pass_number < 0
402 ? 1 : pass->static_pass_number));
404 /* The name is both used to identify the pass for the purposes of plugins,
405 and to specify dump file name and option.
406 The latter two might want something short which is not quite unique; for
407 that reason, we may have a disambiguating prefix, followed by a space
408 to mark the start of the following dump file name / option string. */
409 name = strchr (pass->name, ' ');
410 name = name ? name + 1 : pass->name;
411 dot_name = concat (".", name, num, NULL);
412 if (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS)
413 prefix = "ipa-", flags = TDF_IPA;
414 else if (pass->type == GIMPLE_PASS)
415 prefix = "tree-", flags = TDF_TREE;
416 else
417 prefix = "rtl-", flags = TDF_RTL;
419 flag_name = concat (prefix, name, num, NULL);
420 glob_name = concat (prefix, name, NULL);
421 id = dump_register (dot_name, flag_name, glob_name, flags);
422 set_pass_for_id (id, pass);
423 full_name = concat (prefix, pass->name, num, NULL);
424 register_pass_name (pass, full_name);
425 free (CONST_CAST (char *, full_name));
428 /* Recursive worker function for register_dump_files. */
430 static int
431 register_dump_files_1 (struct opt_pass *pass, int properties)
435 int new_properties = (properties | pass->properties_provided)
436 & ~pass->properties_destroyed;
438 if (pass->name && pass->name[0] != '*')
439 register_one_dump_file (pass);
441 if (pass->sub)
442 new_properties = register_dump_files_1 (pass->sub, new_properties);
444 /* If we have a gate, combine the properties that we could have with
445 and without the pass being examined. */
446 if (pass->gate)
447 properties &= new_properties;
448 else
449 properties = new_properties;
451 pass = pass->next;
453 while (pass);
455 return properties;
458 /* Register the dump files for the pipeline starting at PASS.
459 PROPERTIES reflects the properties that are guaranteed to be available at
460 the beginning of the pipeline. */
462 static void
463 register_dump_files (struct opt_pass *pass,int properties)
465 pass->properties_required |= properties;
466 register_dump_files_1 (pass, properties);
469 struct pass_registry
471 const char* unique_name;
472 struct opt_pass *pass;
475 /* Pass registry hash function. */
477 static hashval_t
478 passr_hash (const void *p)
480 const struct pass_registry *const s = (const struct pass_registry *const) p;
481 return htab_hash_string (s->unique_name);
484 /* Hash equal function */
486 static int
487 passr_eq (const void *p1, const void *p2)
489 const struct pass_registry *const s1 = (const struct pass_registry *const) p1;
490 const struct pass_registry *const s2 = (const struct pass_registry *const) p2;
492 return !strcmp (s1->unique_name, s2->unique_name);
495 static htab_t name_to_pass_map = NULL;
497 /* Register PASS with NAME. */
499 static void
500 register_pass_name (struct opt_pass *pass, const char *name)
502 struct pass_registry **slot;
503 struct pass_registry pr;
505 if (!name_to_pass_map)
506 name_to_pass_map = htab_create (256, passr_hash, passr_eq, NULL);
508 pr.unique_name = name;
509 slot = (struct pass_registry **) htab_find_slot (name_to_pass_map, &pr, INSERT);
510 if (!*slot)
512 struct pass_registry *new_pr;
514 new_pr = XCNEW (struct pass_registry);
515 new_pr->unique_name = xstrdup (name);
516 new_pr->pass = pass;
517 *slot = new_pr;
519 else
520 return; /* Ignore plugin passes. */
523 /* Map from pass id to canonicalized pass name. */
525 typedef const char *char_ptr;
526 DEF_VEC_P(char_ptr);
527 DEF_VEC_ALLOC_P(char_ptr, heap);
528 static VEC(char_ptr, heap) *pass_tab = NULL;
530 /* Callback function for traversing NAME_TO_PASS_MAP. */
532 static int
533 pass_traverse (void **slot, void *data ATTRIBUTE_UNUSED)
535 struct pass_registry **p = (struct pass_registry **)slot;
536 struct opt_pass *pass = (*p)->pass;
538 gcc_assert (pass->static_pass_number > 0);
539 gcc_assert (pass_tab);
541 VEC_replace (char_ptr, pass_tab, pass->static_pass_number,
542 (*p)->unique_name);
544 return 1;
547 /* The function traverses NAME_TO_PASS_MAP and creates a pass info
548 table for dumping purpose. */
550 static void
551 create_pass_tab (void)
553 if (!flag_dump_passes)
554 return;
556 VEC_safe_grow_cleared (char_ptr, heap,
557 pass_tab, passes_by_id_size + 1);
558 htab_traverse (name_to_pass_map, pass_traverse, NULL);
561 static bool override_gate_status (struct opt_pass *, tree, bool);
563 /* Dump the instantiated name for PASS. IS_ON indicates if PASS
564 is turned on or not. */
566 static void
567 dump_one_pass (struct opt_pass *pass, int pass_indent)
569 int indent = 3 * pass_indent;
570 const char *pn;
571 bool is_on, is_really_on;
573 is_on = (pass->gate == NULL) ? true : pass->gate();
574 is_really_on = override_gate_status (pass, current_function_decl, is_on);
576 if (pass->static_pass_number <= 0)
577 pn = pass->name;
578 else
579 pn = VEC_index (char_ptr, pass_tab, pass->static_pass_number);
581 fprintf (stderr, "%*s%-40s%*s:%s%s\n", indent, " ", pn,
582 (15 - indent < 0 ? 0 : 15 - indent), " ",
583 is_on ? " ON" : " OFF",
584 ((!is_on) == (!is_really_on) ? ""
585 : (is_really_on ? " (FORCED_ON)" : " (FORCED_OFF)")));
588 /* Dump pass list PASS with indentation INDENT. */
590 static void
591 dump_pass_list (struct opt_pass *pass, int indent)
595 dump_one_pass (pass, indent);
596 if (pass->sub)
597 dump_pass_list (pass->sub, indent + 1);
598 pass = pass->next;
600 while (pass);
603 /* Dump all optimization passes. */
605 void
606 dump_passes (void)
608 struct cgraph_node *n, *node = NULL;
609 tree save_fndecl = current_function_decl;
611 create_pass_tab();
613 n = cgraph_nodes;
614 while (n)
616 if (DECL_STRUCT_FUNCTION (n->decl))
618 node = n;
619 break;
621 n = n->next;
624 if (!node)
625 return;
627 push_cfun (DECL_STRUCT_FUNCTION (node->decl));
628 current_function_decl = node->decl;
630 dump_pass_list (all_lowering_passes, 1);
631 dump_pass_list (all_small_ipa_passes, 1);
632 dump_pass_list (all_regular_ipa_passes, 1);
633 dump_pass_list (all_lto_gen_passes, 1);
634 dump_pass_list (all_late_ipa_passes, 1);
635 dump_pass_list (all_passes, 1);
637 pop_cfun ();
638 current_function_decl = save_fndecl;
642 /* Returns the pass with NAME. */
644 static struct opt_pass *
645 get_pass_by_name (const char *name)
647 struct pass_registry **slot, pr;
649 pr.unique_name = name;
650 slot = (struct pass_registry **) htab_find_slot (name_to_pass_map,
651 &pr, NO_INSERT);
653 if (!slot || !*slot)
654 return NULL;
656 return (*slot)->pass;
660 /* Range [start, last]. */
662 struct uid_range
664 unsigned int start;
665 unsigned int last;
666 const char *assem_name;
667 struct uid_range *next;
670 typedef struct uid_range *uid_range_p;
672 DEF_VEC_P(uid_range_p);
673 DEF_VEC_ALLOC_P(uid_range_p, heap);
675 static VEC(uid_range_p, heap) *enabled_pass_uid_range_tab = NULL;
676 static VEC(uid_range_p, heap) *disabled_pass_uid_range_tab = NULL;
679 /* Parse option string for -fdisable- and -fenable-
680 The syntax of the options:
682 -fenable-<pass_name>
683 -fdisable-<pass_name>
685 -fenable-<pass_name>=s1:e1,s2:e2,...
686 -fdisable-<pass_name>=s1:e1,s2:e2,...
689 static void
690 enable_disable_pass (const char *arg, bool is_enable)
692 struct opt_pass *pass;
693 char *range_str, *phase_name;
694 char *argstr = xstrdup (arg);
695 VEC(uid_range_p, heap) **tab = 0;
697 range_str = strchr (argstr,'=');
698 if (range_str)
700 *range_str = '\0';
701 range_str++;
704 phase_name = argstr;
705 if (!*phase_name)
707 if (is_enable)
708 error ("unrecognized option -fenable");
709 else
710 error ("unrecognized option -fdisable");
711 free (argstr);
712 return;
714 pass = get_pass_by_name (phase_name);
715 if (!pass || pass->static_pass_number == -1)
717 if (is_enable)
718 error ("unknown pass %s specified in -fenable", phase_name);
719 else
720 error ("unknown pass %s specified in -fdisable", phase_name);
721 free (argstr);
722 return;
725 if (is_enable)
726 tab = &enabled_pass_uid_range_tab;
727 else
728 tab = &disabled_pass_uid_range_tab;
730 if ((unsigned) pass->static_pass_number >= VEC_length (uid_range_p, *tab))
731 VEC_safe_grow_cleared (uid_range_p, heap,
732 *tab, pass->static_pass_number + 1);
734 if (!range_str)
736 uid_range_p slot;
737 uid_range_p new_range = XCNEW (struct uid_range);
739 new_range->start = 0;
740 new_range->last = (unsigned)-1;
742 slot = VEC_index (uid_range_p, *tab, pass->static_pass_number);
743 new_range->next = slot;
744 VEC_replace (uid_range_p, *tab, pass->static_pass_number,
745 new_range);
746 if (is_enable)
747 inform (UNKNOWN_LOCATION, "enable pass %s for functions in the range "
748 "of [%u, %u]", phase_name, new_range->start, new_range->last);
749 else
750 inform (UNKNOWN_LOCATION, "disable pass %s for functions in the range "
751 "of [%u, %u]", phase_name, new_range->start, new_range->last);
753 else
755 char *next_range = NULL;
756 char *one_range = range_str;
757 char *end_val = NULL;
761 uid_range_p slot;
762 uid_range_p new_range;
763 char *invalid = NULL;
764 long start;
765 char *func_name = NULL;
767 next_range = strchr (one_range, ',');
768 if (next_range)
770 *next_range = '\0';
771 next_range++;
774 end_val = strchr (one_range, ':');
775 if (end_val)
777 *end_val = '\0';
778 end_val++;
780 start = strtol (one_range, &invalid, 10);
781 if (*invalid || start < 0)
783 if (end_val || (one_range[0] >= '0'
784 && one_range[0] <= '9'))
786 error ("Invalid range %s in option %s",
787 one_range,
788 is_enable ? "-fenable" : "-fdisable");
789 free (argstr);
790 return;
792 func_name = one_range;
794 if (!end_val)
796 new_range = XCNEW (struct uid_range);
797 if (!func_name)
799 new_range->start = (unsigned) start;
800 new_range->last = (unsigned) start;
802 else
804 new_range->start = (unsigned) -1;
805 new_range->last = (unsigned) -1;
806 new_range->assem_name = xstrdup (func_name);
809 else
811 long last = strtol (end_val, &invalid, 10);
812 if (*invalid || last < start)
814 error ("Invalid range %s in option %s",
815 end_val,
816 is_enable ? "-fenable" : "-fdisable");
817 free (argstr);
818 return;
820 new_range = XCNEW (struct uid_range);
821 new_range->start = (unsigned) start;
822 new_range->last = (unsigned) last;
825 slot = VEC_index (uid_range_p, *tab, pass->static_pass_number);
826 new_range->next = slot;
827 VEC_replace (uid_range_p, *tab, pass->static_pass_number,
828 new_range);
829 if (is_enable)
831 if (new_range->assem_name)
832 inform (UNKNOWN_LOCATION,
833 "enable pass %s for function %s",
834 phase_name, new_range->assem_name);
835 else
836 inform (UNKNOWN_LOCATION,
837 "enable pass %s for functions in the range of [%u, %u]",
838 phase_name, new_range->start, new_range->last);
840 else
842 if (new_range->assem_name)
843 inform (UNKNOWN_LOCATION,
844 "disable pass %s for function %s",
845 phase_name, new_range->assem_name);
846 else
847 inform (UNKNOWN_LOCATION,
848 "disable pass %s for functions in the range of [%u, %u]",
849 phase_name, new_range->start, new_range->last);
852 one_range = next_range;
853 } while (next_range);
856 free (argstr);
859 /* Enable pass specified by ARG. */
861 void
862 enable_pass (const char *arg)
864 enable_disable_pass (arg, true);
867 /* Disable pass specified by ARG. */
869 void
870 disable_pass (const char *arg)
872 enable_disable_pass (arg, false);
875 /* Returns true if PASS is explicitly enabled/disabled for FUNC. */
877 static bool
878 is_pass_explicitly_enabled_or_disabled (struct opt_pass *pass,
879 tree func,
880 VEC(uid_range_p, heap) *tab)
882 uid_range_p slot, range;
883 int cgraph_uid;
884 const char *aname = NULL;
886 if (!tab
887 || (unsigned) pass->static_pass_number >= VEC_length (uid_range_p, tab)
888 || pass->static_pass_number == -1)
889 return false;
891 slot = VEC_index (uid_range_p, tab, pass->static_pass_number);
892 if (!slot)
893 return false;
895 cgraph_uid = func ? cgraph_get_node (func)->uid : 0;
896 if (func && DECL_ASSEMBLER_NAME_SET_P (func))
897 aname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func));
899 range = slot;
900 while (range)
902 if ((unsigned) cgraph_uid >= range->start
903 && (unsigned) cgraph_uid <= range->last)
904 return true;
905 if (range->assem_name && aname
906 && !strcmp (range->assem_name, aname))
907 return true;
908 range = range->next;
911 return false;
914 /* Look at the static_pass_number and duplicate the pass
915 if it is already added to a list. */
917 static struct opt_pass *
918 make_pass_instance (struct opt_pass *pass, bool track_duplicates)
920 /* A nonzero static_pass_number indicates that the
921 pass is already in the list. */
922 if (pass->static_pass_number)
924 struct opt_pass *new_pass;
926 if (pass->type == GIMPLE_PASS
927 || pass->type == RTL_PASS
928 || pass->type == SIMPLE_IPA_PASS)
930 new_pass = XNEW (struct opt_pass);
931 memcpy (new_pass, pass, sizeof (struct opt_pass));
933 else if (pass->type == IPA_PASS)
935 new_pass = (struct opt_pass *)XNEW (struct ipa_opt_pass_d);
936 memcpy (new_pass, pass, sizeof (struct ipa_opt_pass_d));
938 else
939 gcc_unreachable ();
941 new_pass->next = NULL;
943 new_pass->todo_flags_start &= ~TODO_mark_first_instance;
945 /* Indicate to register_dump_files that this pass has duplicates,
946 and so it should rename the dump file. The first instance will
947 be -1, and be number of duplicates = -static_pass_number - 1.
948 Subsequent instances will be > 0 and just the duplicate number. */
949 if ((pass->name && pass->name[0] != '*') || track_duplicates)
951 pass->static_pass_number -= 1;
952 new_pass->static_pass_number = -pass->static_pass_number;
954 return new_pass;
956 else
958 pass->todo_flags_start |= TODO_mark_first_instance;
959 pass->static_pass_number = -1;
961 invoke_plugin_callbacks (PLUGIN_NEW_PASS, pass);
963 return pass;
966 /* Add a pass to the pass list. Duplicate the pass if it's already
967 in the list. */
969 static struct opt_pass **
970 next_pass_1 (struct opt_pass **list, struct opt_pass *pass)
972 /* Every pass should have a name so that plugins can refer to them. */
973 gcc_assert (pass->name != NULL);
975 *list = make_pass_instance (pass, false);
977 return &(*list)->next;
980 /* List node for an inserted pass instance. We need to keep track of all
981 the newly-added pass instances (with 'added_pass_nodes' defined below)
982 so that we can register their dump files after pass-positioning is finished.
983 Registering dumping files needs to be post-processed or the
984 static_pass_number of the opt_pass object would be modified and mess up
985 the dump file names of future pass instances to be added. */
987 struct pass_list_node
989 struct opt_pass *pass;
990 struct pass_list_node *next;
993 static struct pass_list_node *added_pass_nodes = NULL;
994 static struct pass_list_node *prev_added_pass_node;
996 /* Insert the pass at the proper position. Return true if the pass
997 is successfully added.
999 NEW_PASS_INFO - new pass to be inserted
1000 PASS_LIST - root of the pass list to insert the new pass to */
1002 static bool
1003 position_pass (struct register_pass_info *new_pass_info,
1004 struct opt_pass **pass_list)
1006 struct opt_pass *pass = *pass_list, *prev_pass = NULL;
1007 bool success = false;
1009 for ( ; pass; prev_pass = pass, pass = pass->next)
1011 /* Check if the current pass is of the same type as the new pass and
1012 matches the name and the instance number of the reference pass. */
1013 if (pass->type == new_pass_info->pass->type
1014 && pass->name
1015 && !strcmp (pass->name, new_pass_info->reference_pass_name)
1016 && ((new_pass_info->ref_pass_instance_number == 0)
1017 || (new_pass_info->ref_pass_instance_number ==
1018 pass->static_pass_number)
1019 || (new_pass_info->ref_pass_instance_number == 1
1020 && pass->todo_flags_start & TODO_mark_first_instance)))
1022 struct opt_pass *new_pass;
1023 struct pass_list_node *new_pass_node;
1025 new_pass = make_pass_instance (new_pass_info->pass, true);
1027 /* Insert the new pass instance based on the positioning op. */
1028 switch (new_pass_info->pos_op)
1030 case PASS_POS_INSERT_AFTER:
1031 new_pass->next = pass->next;
1032 pass->next = new_pass;
1034 /* Skip newly inserted pass to avoid repeated
1035 insertions in the case where the new pass and the
1036 existing one have the same name. */
1037 pass = new_pass;
1038 break;
1039 case PASS_POS_INSERT_BEFORE:
1040 new_pass->next = pass;
1041 if (prev_pass)
1042 prev_pass->next = new_pass;
1043 else
1044 *pass_list = new_pass;
1045 break;
1046 case PASS_POS_REPLACE:
1047 new_pass->next = pass->next;
1048 if (prev_pass)
1049 prev_pass->next = new_pass;
1050 else
1051 *pass_list = new_pass;
1052 new_pass->sub = pass->sub;
1053 new_pass->tv_id = pass->tv_id;
1054 pass = new_pass;
1055 break;
1056 default:
1057 error ("invalid pass positioning operation");
1058 return false;
1061 /* Save the newly added pass (instance) in the added_pass_nodes
1062 list so that we can register its dump file later. Note that
1063 we cannot register the dump file now because doing so will modify
1064 the static_pass_number of the opt_pass object and therefore
1065 mess up the dump file name of future instances. */
1066 new_pass_node = XCNEW (struct pass_list_node);
1067 new_pass_node->pass = new_pass;
1068 if (!added_pass_nodes)
1069 added_pass_nodes = new_pass_node;
1070 else
1071 prev_added_pass_node->next = new_pass_node;
1072 prev_added_pass_node = new_pass_node;
1074 success = true;
1077 if (pass->sub && position_pass (new_pass_info, &pass->sub))
1078 success = true;
1081 return success;
1084 /* Hooks a new pass into the pass lists.
1086 PASS_INFO - pass information that specifies the opt_pass object,
1087 reference pass, instance number, and how to position
1088 the pass */
1090 void
1091 register_pass (struct register_pass_info *pass_info)
1093 bool all_instances, success;
1095 /* The checks below could fail in buggy plugins. Existing GCC
1096 passes should never fail these checks, so we mention plugin in
1097 the messages. */
1098 if (!pass_info->pass)
1099 fatal_error ("plugin cannot register a missing pass");
1101 if (!pass_info->pass->name)
1102 fatal_error ("plugin cannot register an unnamed pass");
1104 if (!pass_info->reference_pass_name)
1105 fatal_error
1106 ("plugin cannot register pass %qs without reference pass name",
1107 pass_info->pass->name);
1109 /* Try to insert the new pass to the pass lists. We need to check
1110 all five lists as the reference pass could be in one (or all) of
1111 them. */
1112 all_instances = pass_info->ref_pass_instance_number == 0;
1113 success = position_pass (pass_info, &all_lowering_passes);
1114 if (!success || all_instances)
1115 success |= position_pass (pass_info, &all_small_ipa_passes);
1116 if (!success || all_instances)
1117 success |= position_pass (pass_info, &all_regular_ipa_passes);
1118 if (!success || all_instances)
1119 success |= position_pass (pass_info, &all_lto_gen_passes);
1120 if (!success || all_instances)
1121 success |= position_pass (pass_info, &all_late_ipa_passes);
1122 if (!success || all_instances)
1123 success |= position_pass (pass_info, &all_passes);
1124 if (!success)
1125 fatal_error
1126 ("pass %qs not found but is referenced by new pass %qs",
1127 pass_info->reference_pass_name, pass_info->pass->name);
1129 /* OK, we have successfully inserted the new pass. We need to register
1130 the dump files for the newly added pass and its duplicates (if any).
1131 Because the registration of plugin/backend passes happens after the
1132 command-line options are parsed, the options that specify single
1133 pass dumping (e.g. -fdump-tree-PASSNAME) cannot be used for new
1134 passes. Therefore we currently can only enable dumping of
1135 new passes when the 'dump-all' flags (e.g. -fdump-tree-all)
1136 are specified. While doing so, we also delete the pass_list_node
1137 objects created during pass positioning. */
1138 while (added_pass_nodes)
1140 struct pass_list_node *next_node = added_pass_nodes->next;
1141 enum tree_dump_index tdi;
1142 register_one_dump_file (added_pass_nodes->pass);
1143 if (added_pass_nodes->pass->type == SIMPLE_IPA_PASS
1144 || added_pass_nodes->pass->type == IPA_PASS)
1145 tdi = TDI_ipa_all;
1146 else if (added_pass_nodes->pass->type == GIMPLE_PASS)
1147 tdi = TDI_tree_all;
1148 else
1149 tdi = TDI_rtl_all;
1150 /* Check if dump-all flag is specified. */
1151 if (get_dump_file_info (tdi)->state)
1152 get_dump_file_info (added_pass_nodes->pass->static_pass_number)
1153 ->state = get_dump_file_info (tdi)->state;
1154 XDELETE (added_pass_nodes);
1155 added_pass_nodes = next_node;
1159 /* Construct the pass tree. The sequencing of passes is driven by
1160 the cgraph routines:
1162 cgraph_finalize_compilation_unit ()
1163 for each node N in the cgraph
1164 cgraph_analyze_function (N)
1165 cgraph_lower_function (N) -> all_lowering_passes
1167 If we are optimizing, cgraph_optimize is then invoked:
1169 cgraph_optimize ()
1170 ipa_passes () -> all_small_ipa_passes
1171 cgraph_expand_all_functions ()
1172 for each node N in the cgraph
1173 cgraph_expand_function (N)
1174 tree_rest_of_compilation (DECL (N)) -> all_passes
1177 void
1178 init_optimization_passes (void)
1180 struct opt_pass **p;
1182 #define NEXT_PASS(PASS) (p = next_pass_1 (p, &((PASS).pass)))
1184 /* All passes needed to lower the function into shape optimizers can
1185 operate on. These passes are always run first on the function, but
1186 backend might produce already lowered functions that are not processed
1187 by these passes. */
1188 p = &all_lowering_passes;
1189 NEXT_PASS (pass_warn_unused_result);
1190 NEXT_PASS (pass_diagnose_omp_blocks);
1191 NEXT_PASS (pass_diagnose_tm_blocks);
1192 NEXT_PASS (pass_mudflap_1);
1193 NEXT_PASS (pass_lower_omp);
1194 NEXT_PASS (pass_lower_cf);
1195 NEXT_PASS (pass_lower_tm);
1196 NEXT_PASS (pass_refactor_eh);
1197 NEXT_PASS (pass_lower_eh);
1198 NEXT_PASS (pass_build_cfg);
1199 NEXT_PASS (pass_warn_function_return);
1200 NEXT_PASS (pass_build_cgraph_edges);
1201 *p = NULL;
1203 /* Interprocedural optimization passes. */
1204 p = &all_small_ipa_passes;
1205 NEXT_PASS (pass_ipa_free_lang_data);
1206 NEXT_PASS (pass_ipa_function_and_variable_visibility);
1207 NEXT_PASS (pass_early_local_passes);
1209 struct opt_pass **p = &pass_early_local_passes.pass.sub;
1210 NEXT_PASS (pass_fixup_cfg);
1211 NEXT_PASS (pass_init_datastructures);
1212 NEXT_PASS (pass_expand_omp);
1214 NEXT_PASS (pass_referenced_vars);
1215 NEXT_PASS (pass_build_ssa);
1216 NEXT_PASS (pass_lower_vector);
1217 NEXT_PASS (pass_early_warn_uninitialized);
1218 NEXT_PASS (pass_rebuild_cgraph_edges);
1219 NEXT_PASS (pass_threadsafe_analyze);
1220 NEXT_PASS (pass_inline_parameters);
1221 NEXT_PASS (pass_early_inline);
1222 NEXT_PASS (pass_all_early_optimizations);
1224 struct opt_pass **p = &pass_all_early_optimizations.pass.sub;
1225 NEXT_PASS (pass_remove_cgraph_callee_edges);
1226 NEXT_PASS (pass_rename_ssa_copies);
1227 NEXT_PASS (pass_ccp);
1228 NEXT_PASS (pass_forwprop);
1229 /* pass_build_ealias is a dummy pass that ensures that we
1230 execute TODO_rebuild_alias at this point. Re-building
1231 alias information also rewrites no longer addressed
1232 locals into SSA form if possible. */
1233 NEXT_PASS (pass_build_ealias);
1234 NEXT_PASS (pass_sra_early);
1235 NEXT_PASS (pass_fre);
1236 NEXT_PASS (pass_copy_prop);
1237 NEXT_PASS (pass_merge_phi);
1238 NEXT_PASS (pass_cd_dce);
1239 NEXT_PASS (pass_early_ipa_sra);
1240 NEXT_PASS (pass_tail_recursion);
1241 NEXT_PASS (pass_convert_switch);
1242 NEXT_PASS (pass_cleanup_eh);
1243 NEXT_PASS (pass_profile);
1244 NEXT_PASS (pass_local_pure_const);
1245 /* Split functions creates parts that are not run through
1246 early optimizations again. It is thus good idea to do this
1247 late. */
1248 NEXT_PASS (pass_split_functions);
1250 NEXT_PASS (pass_release_ssa_names);
1251 NEXT_PASS (pass_rebuild_cgraph_edges);
1252 NEXT_PASS (pass_inline_parameters);
1254 NEXT_PASS (pass_ipa_auto_profile);
1255 NEXT_PASS (pass_ipa_tree_profile);
1257 struct opt_pass **p = &pass_ipa_tree_profile.pass.sub;
1258 NEXT_PASS (pass_feedback_split_functions);
1260 NEXT_PASS (pass_ipa_increase_alignment);
1261 NEXT_PASS (pass_ipa_matrix_reorg);
1262 NEXT_PASS (pass_ipa_multiversion_dispatch);
1264 struct opt_pass **p = &pass_ipa_multiversion_dispatch.pass.sub;
1265 NEXT_PASS (pass_tree_convert_builtin_dispatch);
1267 NEXT_PASS (pass_ipa_tm);
1268 NEXT_PASS (pass_ipa_lower_emutls);
1269 *p = NULL;
1271 p = &all_regular_ipa_passes;
1272 NEXT_PASS (pass_ipa_whole_program_visibility);
1273 NEXT_PASS (pass_ipa_profile);
1274 NEXT_PASS (pass_ipa_cp);
1275 NEXT_PASS (pass_ipa_cdtor_merge);
1276 NEXT_PASS (pass_ipa_inline);
1277 NEXT_PASS (pass_ipa_pure_const);
1278 NEXT_PASS (pass_ipa_reference);
1279 *p = NULL;
1281 p = &all_lto_gen_passes;
1282 NEXT_PASS (pass_ipa_lto_gimple_out);
1283 NEXT_PASS (pass_ipa_lto_finish_out); /* This must be the last LTO pass. */
1284 *p = NULL;
1286 /* Simple IPA passes executed after the regular passes. In WHOPR mode the
1287 passes are executed after partitioning and thus see just parts of the
1288 compiled unit. */
1289 p = &all_late_ipa_passes;
1290 NEXT_PASS (pass_ipa_pta);
1291 *p = NULL;
1292 /* These passes are run after IPA passes on every function that is being
1293 output to the assembler file. */
1294 p = &all_passes;
1295 NEXT_PASS (pass_direct_call_profile);
1296 NEXT_PASS (pass_fixup_cfg);
1297 NEXT_PASS (pass_lower_eh_dispatch);
1298 NEXT_PASS (pass_all_optimizations);
1300 struct opt_pass **p = &pass_all_optimizations.pass.sub;
1301 NEXT_PASS (pass_remove_cgraph_callee_edges);
1302 /* Initial scalar cleanups before alias computation.
1303 They ensure memory accesses are not indirect wherever possible. */
1304 NEXT_PASS (pass_strip_predict_hints);
1305 NEXT_PASS (pass_rename_ssa_copies);
1306 NEXT_PASS (pass_complete_unrolli);
1307 NEXT_PASS (pass_ccp);
1308 NEXT_PASS (pass_forwprop);
1309 /* pass_build_alias is a dummy pass that ensures that we
1310 execute TODO_rebuild_alias at this point. Re-building
1311 alias information also rewrites no longer addressed
1312 locals into SSA form if possible. */
1313 NEXT_PASS (pass_build_alias);
1314 NEXT_PASS (pass_return_slot);
1315 NEXT_PASS (pass_phiprop);
1316 NEXT_PASS (pass_fre);
1317 NEXT_PASS (pass_copy_prop);
1318 NEXT_PASS (pass_merge_phi);
1319 NEXT_PASS (pass_vrp);
1320 NEXT_PASS (pass_dce);
1321 NEXT_PASS (pass_call_cdce);
1322 NEXT_PASS (pass_cselim);
1323 NEXT_PASS (pass_tree_ifcombine);
1324 NEXT_PASS (pass_phiopt);
1325 NEXT_PASS (pass_tail_recursion);
1326 NEXT_PASS (pass_ch);
1327 NEXT_PASS (pass_stdarg);
1328 NEXT_PASS (pass_lower_complex);
1329 NEXT_PASS (pass_sra);
1330 NEXT_PASS (pass_rename_ssa_copies);
1331 /* The dom pass will also resolve all __builtin_constant_p calls
1332 that are still there to 0. This has to be done after some
1333 propagations have already run, but before some more dead code
1334 is removed, and this place fits nicely. Remember this when
1335 trying to move or duplicate pass_dominator somewhere earlier. */
1336 NEXT_PASS (pass_dominator);
1337 /* The only const/copy propagation opportunities left after
1338 DOM should be due to degenerate PHI nodes. So rather than
1339 run the full propagators, run a specialized pass which
1340 only examines PHIs to discover const/copy propagation
1341 opportunities. */
1342 NEXT_PASS (pass_phi_only_cprop);
1343 NEXT_PASS (pass_dse);
1344 NEXT_PASS (pass_reassoc);
1345 NEXT_PASS (pass_dce);
1346 NEXT_PASS (pass_forwprop);
1347 NEXT_PASS (pass_phiopt);
1348 NEXT_PASS (pass_object_sizes);
1349 NEXT_PASS (pass_strlen);
1350 NEXT_PASS (pass_ccp);
1351 NEXT_PASS (pass_copy_prop);
1352 NEXT_PASS (pass_cse_sincos);
1353 NEXT_PASS (pass_optimize_bswap);
1354 NEXT_PASS (pass_split_crit_edges);
1355 NEXT_PASS (pass_pre);
1356 NEXT_PASS (pass_sink_code);
1357 NEXT_PASS (pass_asan);
1358 NEXT_PASS (pass_tsan);
1359 NEXT_PASS (pass_tree_loop);
1361 struct opt_pass **p = &pass_tree_loop.pass.sub;
1362 NEXT_PASS (pass_tree_loop_init);
1363 NEXT_PASS (pass_lim);
1364 NEXT_PASS (pass_copy_prop);
1365 NEXT_PASS (pass_dce_loop);
1366 NEXT_PASS (pass_tree_unswitch);
1367 NEXT_PASS (pass_scev_cprop);
1368 NEXT_PASS (pass_record_bounds);
1369 NEXT_PASS (pass_check_data_deps);
1370 NEXT_PASS (pass_loop_distribution);
1371 NEXT_PASS (pass_copy_prop);
1372 NEXT_PASS (pass_graphite);
1374 struct opt_pass **p = &pass_graphite.pass.sub;
1375 NEXT_PASS (pass_graphite_transforms);
1376 NEXT_PASS (pass_lim);
1377 NEXT_PASS (pass_copy_prop);
1378 NEXT_PASS (pass_dce_loop);
1380 NEXT_PASS (pass_iv_canon);
1381 NEXT_PASS (pass_if_conversion);
1382 NEXT_PASS (pass_vectorize);
1384 struct opt_pass **p = &pass_vectorize.pass.sub;
1385 NEXT_PASS (pass_dce_loop);
1387 NEXT_PASS (pass_predcom);
1388 NEXT_PASS (pass_complete_unroll);
1389 NEXT_PASS (pass_slp_vectorize);
1390 NEXT_PASS (pass_parallelize_loops);
1391 NEXT_PASS (pass_loop_prefetch);
1392 NEXT_PASS (pass_iv_optimize);
1393 NEXT_PASS (pass_lim);
1394 NEXT_PASS (pass_tree_loop_done);
1396 NEXT_PASS (pass_lower_vector_ssa);
1397 NEXT_PASS (pass_cse_reciprocals);
1398 NEXT_PASS (pass_reassoc);
1399 NEXT_PASS (pass_vrp);
1400 NEXT_PASS (pass_dominator);
1401 /* The only const/copy propagation opportunities left after
1402 DOM should be due to degenerate PHI nodes. So rather than
1403 run the full propagators, run a specialized pass which
1404 only examines PHIs to discover const/copy propagation
1405 opportunities. */
1406 NEXT_PASS (pass_phi_only_cprop);
1407 NEXT_PASS (pass_cd_dce);
1408 NEXT_PASS (pass_tracer);
1410 /* FIXME: If DCE is not run before checking for uninitialized uses,
1411 we may get false warnings (e.g., testsuite/gcc.dg/uninit-5.c).
1412 However, this also causes us to misdiagnose cases that should be
1413 real warnings (e.g., testsuite/gcc.dg/pr18501.c).
1415 To fix the false positives in uninit-5.c, we would have to
1416 account for the predicates protecting the set and the use of each
1417 variable. Using a representation like Gated Single Assignment
1418 may help. */
1419 NEXT_PASS (pass_late_warn_uninitialized);
1420 NEXT_PASS (pass_dse);
1421 NEXT_PASS (pass_forwprop);
1422 NEXT_PASS (pass_phiopt);
1423 NEXT_PASS (pass_fold_builtins);
1424 NEXT_PASS (pass_optimize_widening_mul);
1425 NEXT_PASS (pass_tail_calls);
1426 NEXT_PASS (pass_rename_ssa_copies);
1427 NEXT_PASS (pass_uncprop);
1428 NEXT_PASS (pass_local_pure_const);
1430 NEXT_PASS (pass_tm_init);
1432 struct opt_pass **p = &pass_tm_init.pass.sub;
1433 NEXT_PASS (pass_tm_mark);
1434 NEXT_PASS (pass_tm_memopt);
1435 NEXT_PASS (pass_tm_edges);
1437 NEXT_PASS (pass_lower_complex_O0);
1438 NEXT_PASS (pass_cleanup_eh);
1439 NEXT_PASS (pass_lower_resx);
1440 NEXT_PASS (pass_nrv);
1441 NEXT_PASS (pass_mudflap_2);
1442 NEXT_PASS (pass_cleanup_cfg_post_optimizing);
1443 NEXT_PASS (pass_warn_function_noreturn);
1445 NEXT_PASS (pass_expand);
1447 NEXT_PASS (pass_rest_of_compilation);
1449 struct opt_pass **p = &pass_rest_of_compilation.pass.sub;
1450 NEXT_PASS (pass_init_function);
1451 NEXT_PASS (pass_jump);
1452 NEXT_PASS (pass_rtl_eh);
1453 NEXT_PASS (pass_initial_value_sets);
1454 NEXT_PASS (pass_unshare_all_rtl);
1455 NEXT_PASS (pass_instantiate_virtual_regs);
1456 NEXT_PASS (pass_into_cfg_layout_mode);
1457 NEXT_PASS (pass_jump2);
1458 NEXT_PASS (pass_lower_subreg);
1459 NEXT_PASS (pass_df_initialize_opt);
1460 NEXT_PASS (pass_cse);
1461 NEXT_PASS (pass_rtl_fwprop);
1462 NEXT_PASS (pass_rtl_cprop);
1463 NEXT_PASS (pass_rtl_pre);
1464 NEXT_PASS (pass_rtl_hoist);
1465 NEXT_PASS (pass_rtl_cprop);
1466 NEXT_PASS (pass_rtl_store_motion);
1467 NEXT_PASS (pass_cse_after_global_opts);
1468 NEXT_PASS (pass_rtl_ifcvt);
1469 NEXT_PASS (pass_reginfo_init);
1470 /* Perform loop optimizations. It might be better to do them a bit
1471 sooner, but we want the profile feedback to work more
1472 efficiently. */
1473 NEXT_PASS (pass_loop2);
1475 struct opt_pass **p = &pass_loop2.pass.sub;
1476 NEXT_PASS (pass_rtl_loop_init);
1477 NEXT_PASS (pass_rtl_move_loop_invariants);
1478 NEXT_PASS (pass_rtl_unswitch);
1479 NEXT_PASS (pass_rtl_unroll_and_peel_loops);
1480 NEXT_PASS (pass_rtl_doloop);
1481 NEXT_PASS (pass_rtl_loop_done);
1482 *p = NULL;
1484 NEXT_PASS (pass_simplify_got);
1485 NEXT_PASS (pass_web);
1486 NEXT_PASS (pass_rtl_cprop);
1487 NEXT_PASS (pass_cse2);
1488 NEXT_PASS (pass_rtl_dse1);
1489 NEXT_PASS (pass_rtl_fwprop_addr);
1490 NEXT_PASS (pass_inc_dec);
1491 NEXT_PASS (pass_initialize_regs);
1492 NEXT_PASS (pass_ud_rtl_dce);
1493 NEXT_PASS (pass_combine);
1494 NEXT_PASS (pass_if_after_combine);
1495 NEXT_PASS (pass_partition_blocks);
1496 NEXT_PASS (pass_regmove);
1497 NEXT_PASS (pass_outof_cfg_layout_mode);
1498 NEXT_PASS (pass_split_all_insns);
1499 NEXT_PASS (pass_lower_subreg2);
1500 NEXT_PASS (pass_df_initialize_no_opt);
1501 NEXT_PASS (pass_stack_ptr_mod);
1502 NEXT_PASS (pass_mode_switching);
1503 NEXT_PASS (pass_match_asm_constraints);
1504 NEXT_PASS (pass_sms);
1505 NEXT_PASS (pass_sched);
1506 NEXT_PASS (pass_ira);
1507 NEXT_PASS (pass_reload);
1508 NEXT_PASS (pass_postreload);
1510 struct opt_pass **p = &pass_postreload.pass.sub;
1511 NEXT_PASS (pass_postreload_cse);
1512 NEXT_PASS (pass_gcse2);
1513 NEXT_PASS (pass_split_after_reload);
1514 NEXT_PASS (pass_ree);
1515 NEXT_PASS (pass_compare_elim_after_reload);
1516 NEXT_PASS (pass_branch_target_load_optimize1);
1517 NEXT_PASS (pass_thread_prologue_and_epilogue);
1518 NEXT_PASS (pass_rtl_dse2);
1519 NEXT_PASS (pass_stack_adjustments);
1520 NEXT_PASS (pass_peephole2);
1521 NEXT_PASS (pass_if_after_reload);
1522 NEXT_PASS (pass_regrename);
1523 NEXT_PASS (pass_cprop_hardreg);
1524 NEXT_PASS (pass_fast_rtl_dce);
1525 NEXT_PASS (pass_reorder_blocks);
1526 NEXT_PASS (pass_branch_target_load_optimize2);
1527 NEXT_PASS (pass_leaf_regs);
1528 NEXT_PASS (pass_split_before_sched2);
1529 NEXT_PASS (pass_sched2);
1530 NEXT_PASS (pass_stack_regs);
1532 struct opt_pass **p = &pass_stack_regs.pass.sub;
1533 NEXT_PASS (pass_split_before_regstack);
1534 NEXT_PASS (pass_stack_regs_run);
1536 NEXT_PASS (pass_compute_alignments);
1537 NEXT_PASS (pass_duplicate_computed_gotos);
1538 NEXT_PASS (pass_variable_tracking);
1539 NEXT_PASS (pass_free_cfg);
1540 NEXT_PASS (pass_machine_reorg);
1541 NEXT_PASS (pass_cleanup_barriers);
1542 NEXT_PASS (pass_delay_slots);
1543 NEXT_PASS (pass_split_for_shorten_branches);
1544 NEXT_PASS (pass_convert_to_eh_region_ranges);
1545 NEXT_PASS (pass_shorten_branches);
1546 NEXT_PASS (pass_set_nothrow_function_flags);
1547 NEXT_PASS (pass_dwarf2_frame);
1548 NEXT_PASS (pass_final);
1550 NEXT_PASS (pass_df_finish);
1552 NEXT_PASS (pass_clean_state);
1553 *p = NULL;
1555 #undef NEXT_PASS
1557 /* Register the passes with the tree dump code. */
1558 register_dump_files (all_lowering_passes, PROP_gimple_any);
1559 register_dump_files (all_small_ipa_passes,
1560 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
1561 | PROP_cfg);
1562 register_dump_files (all_regular_ipa_passes,
1563 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
1564 | PROP_cfg);
1565 register_dump_files (all_lto_gen_passes,
1566 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
1567 | PROP_cfg);
1568 register_dump_files (all_late_ipa_passes,
1569 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
1570 | PROP_cfg);
1571 register_dump_files (all_passes,
1572 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
1573 | PROP_cfg);
1576 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1577 function CALLBACK for every function in the call graph. Otherwise,
1578 call CALLBACK on the current function. */
1580 static void
1581 do_per_function (void (*callback) (void *data), void *data)
1583 if (current_function_decl)
1584 callback (data);
1585 else
1587 struct cgraph_node *node;
1588 for (node = cgraph_nodes; node; node = node->next)
1589 if (node->analyzed && gimple_has_body_p (node->decl)
1590 && (!node->clone_of || node->decl != node->clone_of->decl))
1592 push_cfun (DECL_STRUCT_FUNCTION (node->decl));
1593 current_function_decl = node->decl;
1594 callback (data);
1595 if (!flag_wpa)
1597 free_dominance_info (CDI_DOMINATORS);
1598 free_dominance_info (CDI_POST_DOMINATORS);
1600 current_function_decl = NULL;
1601 pop_cfun ();
1602 ggc_collect ();
1607 /* Because inlining might remove no-longer reachable nodes, we need to
1608 keep the array visible to garbage collector to avoid reading collected
1609 out nodes. */
1610 static int nnodes;
1611 static GTY ((length ("nnodes"))) cgraph_node_ptr *order;
1613 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1614 function CALLBACK for every function in the call graph. Otherwise,
1615 call CALLBACK on the current function.
1616 This function is global so that plugins can use it. */
1617 void
1618 do_per_function_toporder (void (*callback) (void *data), void *data)
1620 int i;
1622 if (current_function_decl)
1623 callback (data);
1624 else
1626 gcc_assert (!order);
1627 order = ggc_alloc_vec_cgraph_node_ptr (cgraph_n_nodes);
1628 nnodes = ipa_reverse_postorder (order);
1629 for (i = nnodes - 1; i >= 0; i--)
1630 order[i]->process = 1;
1631 for (i = nnodes - 1; i >= 0; i--)
1633 struct cgraph_node *node = order[i];
1635 /* Allow possibly removed nodes to be garbage collected. */
1636 order[i] = NULL;
1637 node->process = 0;
1638 if (cgraph_function_with_gimple_body_p (node))
1640 push_cfun (DECL_STRUCT_FUNCTION (node->decl));
1641 current_function_decl = node->decl;
1642 callback (data);
1643 free_dominance_info (CDI_DOMINATORS);
1644 free_dominance_info (CDI_POST_DOMINATORS);
1645 current_function_decl = NULL;
1646 pop_cfun ();
1647 ggc_collect ();
1651 ggc_free (order);
1652 order = NULL;
1653 nnodes = 0;
1656 /* Helper function to perform function body dump. */
1658 static void
1659 execute_function_dump (void *data ATTRIBUTE_UNUSED)
1661 if (dump_file && current_function_decl)
1663 if (cfun->curr_properties & PROP_trees)
1664 dump_function_to_file (current_function_decl, dump_file, dump_flags);
1665 else
1667 if (dump_flags & TDF_SLIM)
1668 print_rtl_slim_with_bb (dump_file, get_insns (), dump_flags);
1669 else if ((cfun->curr_properties & PROP_cfg)
1670 && (dump_flags & TDF_BLOCKS))
1671 print_rtl_with_bb (dump_file, get_insns ());
1672 else
1673 print_rtl (dump_file, get_insns ());
1675 if ((cfun->curr_properties & PROP_cfg)
1676 && graph_dump_format != no_graph
1677 && (dump_flags & TDF_GRAPH))
1678 print_rtl_graph_with_bb (dump_file_name, get_insns ());
1681 /* Flush the file. If verification fails, we won't be able to
1682 close the file before aborting. */
1683 fflush (dump_file);
1687 /* Perform all TODO actions that ought to be done on each function. */
1689 static void
1690 execute_function_todo (void *data)
1692 unsigned int flags = (size_t)data;
1693 flags &= ~cfun->last_verified;
1694 if (!flags)
1695 return;
1697 /* Always cleanup the CFG before trying to update SSA. */
1698 if (flags & TODO_cleanup_cfg)
1700 bool cleanup = cleanup_tree_cfg ();
1702 if (cleanup && (cfun->curr_properties & PROP_ssa))
1703 flags |= TODO_remove_unused_locals;
1705 /* When cleanup_tree_cfg merges consecutive blocks, it may
1706 perform some simplistic propagation when removing single
1707 valued PHI nodes. This propagation may, in turn, cause the
1708 SSA form to become out-of-date (see PR 22037). So, even
1709 if the parent pass had not scheduled an SSA update, we may
1710 still need to do one. */
1711 if (!(flags & TODO_update_ssa_any) && need_ssa_update_p (cfun))
1712 flags |= TODO_update_ssa;
1715 if (flags & TODO_update_ssa_any)
1717 unsigned update_flags = flags & TODO_update_ssa_any;
1718 update_ssa (update_flags);
1719 cfun->last_verified &= ~TODO_verify_ssa;
1722 if (flags & TODO_rebuild_alias)
1724 execute_update_addresses_taken ();
1725 compute_may_aliases ();
1727 else if (optimize && (flags & TODO_update_address_taken))
1728 execute_update_addresses_taken ();
1730 if (flags & TODO_remove_unused_locals)
1731 remove_unused_locals ();
1733 if (flags & TODO_rebuild_frequencies)
1734 rebuild_frequencies ();
1736 if (flags & TODO_rebuild_cgraph_edges)
1737 rebuild_cgraph_edges ();
1739 /* If we've seen errors do not bother running any verifiers. */
1740 if (seen_error ())
1741 return;
1743 #if defined ENABLE_CHECKING
1744 if (flags & TODO_verify_ssa
1745 || (current_loops && loops_state_satisfies_p (LOOP_CLOSED_SSA)))
1747 verify_gimple_in_cfg (cfun);
1748 verify_ssa (true);
1750 else if (flags & TODO_verify_stmts)
1751 verify_gimple_in_cfg (cfun);
1752 if (flags & TODO_verify_flow)
1753 verify_flow_info ();
1754 if (current_loops && loops_state_satisfies_p (LOOP_CLOSED_SSA))
1755 verify_loop_closed_ssa (false);
1756 if (flags & TODO_verify_rtl_sharing)
1757 verify_rtl_sharing ();
1758 #endif
1760 cfun->last_verified = flags & TODO_verify_all;
1763 /* Perform all TODO actions. */
1764 static void
1765 execute_todo (unsigned int flags)
1767 #if defined ENABLE_CHECKING
1768 if (cfun
1769 && need_ssa_update_p (cfun))
1770 gcc_assert (flags & TODO_update_ssa_any);
1771 #endif
1773 timevar_push (TV_TODO);
1775 /* Inform the pass whether it is the first time it is run. */
1776 first_pass_instance = (flags & TODO_mark_first_instance) != 0;
1778 statistics_fini_pass ();
1780 do_per_function (execute_function_todo, (void *)(size_t) flags);
1782 /* Always remove functions just as before inlining: IPA passes might be
1783 interested to see bodies of extern inline functions that are not inlined
1784 to analyze side effects. The full removal is done just at the end
1785 of IPA pass queue. */
1786 if (flags & TODO_remove_functions)
1788 gcc_assert (!cfun);
1789 cgraph_remove_unreachable_nodes (true, dump_file);
1792 if ((flags & TODO_dump_cgraph) && dump_file && !current_function_decl)
1794 gcc_assert (!cfun);
1795 dump_cgraph (dump_file);
1796 /* Flush the file. If verification fails, we won't be able to
1797 close the file before aborting. */
1798 fflush (dump_file);
1801 if (flags & TODO_ggc_collect)
1802 ggc_collect ();
1804 /* Now that the dumping has been done, we can get rid of the optional
1805 df problems. */
1806 if (flags & TODO_df_finish)
1807 df_finish_pass ((flags & TODO_df_verify) != 0);
1809 timevar_pop (TV_TODO);
1812 /* Verify invariants that should hold between passes. This is a place
1813 to put simple sanity checks. */
1815 static void
1816 verify_interpass_invariants (void)
1818 gcc_checking_assert (!fold_deferring_overflow_warnings_p ());
1821 /* Clear the last verified flag. */
1823 static void
1824 clear_last_verified (void *data ATTRIBUTE_UNUSED)
1826 cfun->last_verified = 0;
1829 /* Helper function. Verify that the properties has been turn into the
1830 properties expected by the pass. */
1832 #ifdef ENABLE_CHECKING
1833 static void
1834 verify_curr_properties (void *data)
1836 unsigned int props = (size_t)data;
1837 gcc_assert ((cfun->curr_properties & props) == props);
1839 #endif
1841 /* Initialize pass dump file. */
1842 /* This is non-static so that the plugins can use it. */
1844 bool
1845 pass_init_dump_file (struct opt_pass *pass)
1847 /* If a dump file name is present, open it if enabled. */
1848 if (pass->static_pass_number != -1)
1850 bool initializing_dump = !dump_initialized_p (pass->static_pass_number);
1851 dump_file_name = get_dump_file_name (pass->static_pass_number);
1852 dump_file = dump_begin (pass->static_pass_number, &dump_flags);
1853 if (dump_file && current_function_decl)
1854 dump_function_header (dump_file, current_function_decl, dump_flags);
1855 return initializing_dump;
1857 else
1858 return false;
1861 /* Flush PASS dump file. */
1862 /* This is non-static so that plugins can use it. */
1864 void
1865 pass_fini_dump_file (struct opt_pass *pass)
1867 /* Flush and close dump file. */
1868 if (dump_file_name)
1870 free (CONST_CAST (char *, dump_file_name));
1871 dump_file_name = NULL;
1874 if (dump_file)
1876 dump_end (pass->static_pass_number, dump_file);
1877 dump_file = NULL;
1881 /* After executing the pass, apply expected changes to the function
1882 properties. */
1884 static void
1885 update_properties_after_pass (void *data)
1887 struct opt_pass *pass = (struct opt_pass *) data;
1888 cfun->curr_properties = (cfun->curr_properties | pass->properties_provided)
1889 & ~pass->properties_destroyed;
1892 /* Execute summary generation for all of the passes in IPA_PASS. */
1894 void
1895 execute_ipa_summary_passes (struct ipa_opt_pass_d *ipa_pass)
1897 while (ipa_pass)
1899 struct opt_pass *pass = &ipa_pass->pass;
1901 /* Execute all of the IPA_PASSes in the list. */
1902 if (ipa_pass->pass.type == IPA_PASS
1903 && (!pass->gate || pass->gate ())
1904 && ipa_pass->generate_summary)
1906 pass_init_dump_file (pass);
1908 /* If a timevar is present, start it. */
1909 if (pass->tv_id)
1910 timevar_push (pass->tv_id);
1912 ipa_pass->generate_summary ();
1914 /* Stop timevar. */
1915 if (pass->tv_id)
1916 timevar_pop (pass->tv_id);
1918 pass_fini_dump_file (pass);
1920 ipa_pass = (struct ipa_opt_pass_d *)ipa_pass->pass.next;
1924 /* Execute IPA_PASS function transform on NODE. */
1926 static void
1927 execute_one_ipa_transform_pass (struct cgraph_node *node,
1928 struct ipa_opt_pass_d *ipa_pass)
1930 struct opt_pass *pass = &ipa_pass->pass;
1931 unsigned int todo_after = 0;
1933 current_pass = pass;
1934 if (!ipa_pass->function_transform)
1935 return;
1937 /* Note that the folders should only create gimple expressions.
1938 This is a hack until the new folder is ready. */
1939 in_gimple_form = (cfun && (cfun->curr_properties & PROP_trees)) != 0;
1941 pass_init_dump_file (pass);
1943 /* Run pre-pass verification. */
1944 execute_todo (ipa_pass->function_transform_todo_flags_start);
1946 /* If a timevar is present, start it. */
1947 if (pass->tv_id != TV_NONE)
1948 timevar_push (pass->tv_id);
1950 /* Do it! */
1951 todo_after = ipa_pass->function_transform (node);
1953 /* Stop timevar. */
1954 if (pass->tv_id != TV_NONE)
1955 timevar_pop (pass->tv_id);
1957 /* Run post-pass cleanup and verification. */
1958 execute_todo (todo_after);
1959 verify_interpass_invariants ();
1961 do_per_function (execute_function_dump, NULL);
1962 pass_fini_dump_file (pass);
1964 current_pass = NULL;
1967 /* For the current function, execute all ipa transforms. */
1969 void
1970 execute_all_ipa_transforms (void)
1972 struct cgraph_node *node;
1973 if (!cfun)
1974 return;
1975 node = cgraph_get_node (current_function_decl);
1977 if (node->ipa_transforms_to_apply)
1979 unsigned int i;
1981 for (i = 0; i < VEC_length (ipa_opt_pass, node->ipa_transforms_to_apply);
1982 i++)
1983 execute_one_ipa_transform_pass (node,
1984 VEC_index (ipa_opt_pass,
1985 node->ipa_transforms_to_apply,
1986 i));
1987 VEC_free (ipa_opt_pass, heap, node->ipa_transforms_to_apply);
1988 node->ipa_transforms_to_apply = NULL;
1992 /* Callback for do_per_function to apply all IPA transforms. */
1994 static void
1995 apply_ipa_transforms (void *data)
1997 struct cgraph_node *node = cgraph_get_node (current_function_decl);
1998 if (!node->global.inlined_to && node->ipa_transforms_to_apply)
2000 *(bool *)data = true;
2001 execute_all_ipa_transforms();
2002 rebuild_cgraph_edges ();
2006 /* Check if PASS is explicitly disabled or enabled and return
2007 the gate status. FUNC is the function to be processed, and
2008 GATE_STATUS is the gate status determined by pass manager by
2009 default. */
2011 static bool
2012 override_gate_status (struct opt_pass *pass, tree func, bool gate_status)
2014 bool explicitly_enabled = false;
2015 bool explicitly_disabled = false;
2017 explicitly_enabled
2018 = is_pass_explicitly_enabled_or_disabled (pass, func,
2019 enabled_pass_uid_range_tab);
2020 explicitly_disabled
2021 = is_pass_explicitly_enabled_or_disabled (pass, func,
2022 disabled_pass_uid_range_tab);
2024 gate_status = !explicitly_disabled && (gate_status || explicitly_enabled);
2026 return gate_status;
2030 /* Execute PASS. */
2032 bool
2033 execute_one_pass (struct opt_pass *pass)
2035 bool initializing_dump;
2036 unsigned int todo_after = 0;
2038 bool gate_status;
2040 /* IPA passes are executed on whole program, so cfun should be NULL.
2041 Other passes need function context set. */
2042 if (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS)
2043 gcc_assert (!cfun && !current_function_decl);
2044 else
2045 gcc_assert (cfun && current_function_decl);
2047 current_pass = pass;
2049 /* Check whether gate check should be avoided.
2050 User controls the value of the gate through the parameter "gate_status". */
2051 gate_status = (pass->gate == NULL) ? true : pass->gate();
2052 gate_status = override_gate_status (pass, current_function_decl, gate_status);
2054 /* Override gate with plugin. */
2055 invoke_plugin_callbacks (PLUGIN_OVERRIDE_GATE, &gate_status);
2057 if (!gate_status)
2059 current_pass = NULL;
2060 return false;
2063 /* Pass execution event trigger: useful to identify passes being
2064 executed. */
2065 invoke_plugin_callbacks (PLUGIN_PASS_EXECUTION, pass);
2067 /* SIPLE IPA passes do not handle callgraphs with IPA transforms in it.
2068 Apply all trnasforms first. */
2069 if (pass->type == SIMPLE_IPA_PASS)
2071 bool applied = false;
2072 do_per_function (apply_ipa_transforms, (void *)&applied);
2073 if (applied)
2074 cgraph_remove_unreachable_nodes (true, dump_file);
2075 /* Restore current_pass. */
2076 current_pass = pass;
2079 if (!quiet_flag && !cfun)
2080 fprintf (stderr, " <%s>", pass->name ? pass->name : "");
2082 /* Note that the folders should only create gimple expressions.
2083 This is a hack until the new folder is ready. */
2084 in_gimple_form = (cfun && (cfun->curr_properties & PROP_trees)) != 0;
2086 initializing_dump = pass_init_dump_file (pass);
2088 /* Run pre-pass verification. */
2089 execute_todo (pass->todo_flags_start);
2091 #ifdef ENABLE_CHECKING
2092 do_per_function (verify_curr_properties,
2093 (void *)(size_t)pass->properties_required);
2094 #endif
2096 /* If a timevar is present, start it. */
2097 if (pass->tv_id != TV_NONE)
2098 timevar_push (pass->tv_id);
2100 /* Do it! */
2101 if (pass->execute)
2103 todo_after = pass->execute ();
2104 do_per_function (clear_last_verified, NULL);
2107 /* Stop timevar. */
2108 if (pass->tv_id != TV_NONE)
2109 timevar_pop (pass->tv_id);
2111 do_per_function (update_properties_after_pass, pass);
2113 if (initializing_dump
2114 && dump_file
2115 && graph_dump_format != no_graph
2116 && cfun
2117 && (cfun->curr_properties & (PROP_cfg | PROP_rtl))
2118 == (PROP_cfg | PROP_rtl))
2120 get_dump_file_info (pass->static_pass_number)->flags |= TDF_GRAPH;
2121 dump_flags |= TDF_GRAPH;
2122 clean_graph_dump_file (dump_file_name);
2125 /* Run post-pass cleanup and verification. */
2126 execute_todo (todo_after | pass->todo_flags_finish);
2127 verify_interpass_invariants ();
2128 do_per_function (execute_function_dump, NULL);
2129 if (pass->type == IPA_PASS)
2131 struct cgraph_node *node;
2132 FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node)
2133 VEC_safe_push (ipa_opt_pass, heap, node->ipa_transforms_to_apply,
2134 (struct ipa_opt_pass_d *)pass);
2137 if (!current_function_decl)
2138 cgraph_process_new_functions ();
2140 pass_fini_dump_file (pass);
2142 if (pass->type != SIMPLE_IPA_PASS && pass->type != IPA_PASS)
2143 gcc_assert (!(cfun->curr_properties & PROP_trees)
2144 || pass->type != RTL_PASS);
2146 current_pass = NULL;
2148 return true;
2151 void
2152 execute_pass_list (struct opt_pass *pass)
2156 gcc_assert (pass->type == GIMPLE_PASS
2157 || pass->type == RTL_PASS);
2158 if (execute_one_pass (pass) && pass->sub)
2159 execute_pass_list (pass->sub);
2160 pass = pass->next;
2162 while (pass);
2165 /* Same as execute_pass_list but assume that subpasses of IPA passes
2166 are local passes. If SET is not NULL, write out summaries of only
2167 those node in SET. */
2169 static void
2170 ipa_write_summaries_2 (struct opt_pass *pass, cgraph_node_set set,
2171 varpool_node_set vset,
2172 struct lto_out_decl_state *state)
2174 while (pass)
2176 struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *)pass;
2177 gcc_assert (!current_function_decl);
2178 gcc_assert (!cfun);
2179 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
2180 if (pass->type == IPA_PASS
2181 && ipa_pass->write_summary
2182 && (!pass->gate || pass->gate ()))
2184 /* If a timevar is present, start it. */
2185 if (pass->tv_id)
2186 timevar_push (pass->tv_id);
2188 pass_init_dump_file (pass);
2190 ipa_pass->write_summary (set,vset);
2192 pass_fini_dump_file (pass);
2194 /* If a timevar is present, start it. */
2195 if (pass->tv_id)
2196 timevar_pop (pass->tv_id);
2199 if (pass->sub && pass->sub->type != GIMPLE_PASS)
2200 ipa_write_summaries_2 (pass->sub, set, vset, state);
2202 pass = pass->next;
2206 /* Helper function of ipa_write_summaries. Creates and destroys the
2207 decl state and calls ipa_write_summaries_2 for all passes that have
2208 summaries. SET is the set of nodes to be written. */
2210 static void
2211 ipa_write_summaries_1 (cgraph_node_set set, varpool_node_set vset)
2213 struct lto_out_decl_state *state = lto_new_out_decl_state ();
2214 compute_ltrans_boundary (state, set, vset);
2216 lto_push_out_decl_state (state);
2218 gcc_assert (!flag_wpa);
2219 ipa_write_summaries_2 (all_regular_ipa_passes, set, vset, state);
2220 ipa_write_summaries_2 (all_lto_gen_passes, set, vset, state);
2222 gcc_assert (lto_get_out_decl_state () == state);
2223 lto_pop_out_decl_state ();
2224 lto_delete_out_decl_state (state);
2227 /* Write out summaries for all the nodes in the callgraph. */
2229 void
2230 ipa_write_summaries (void)
2232 cgraph_node_set set;
2233 varpool_node_set vset;
2234 struct cgraph_node **order;
2235 struct varpool_node *vnode;
2236 int i, order_pos;
2238 if (!flag_generate_lto || seen_error ())
2239 return;
2241 set = cgraph_node_set_new ();
2243 /* Create the callgraph set in the same order used in
2244 cgraph_expand_all_functions. This mostly facilitates debugging,
2245 since it causes the gimple file to be processed in the same order
2246 as the source code. */
2247 order = XCNEWVEC (struct cgraph_node *, cgraph_n_nodes);
2248 order_pos = ipa_reverse_postorder (order);
2249 gcc_assert (order_pos == cgraph_n_nodes);
2251 for (i = order_pos - 1; i >= 0; i--)
2253 struct cgraph_node *node = order[i];
2255 if (cgraph_function_with_gimple_body_p (node))
2257 /* When streaming out references to statements as part of some IPA
2258 pass summary, the statements need to have uids assigned and the
2259 following does that for all the IPA passes here. Naturally, this
2260 ordering then matches the one IPA-passes get in their stmt_fixup
2261 hooks. */
2263 push_cfun (DECL_STRUCT_FUNCTION (node->decl));
2264 renumber_gimple_stmt_uids ();
2265 pop_cfun ();
2267 if (node->analyzed)
2268 cgraph_node_set_add (set, node);
2270 vset = varpool_node_set_new ();
2272 for (vnode = varpool_nodes; vnode; vnode = vnode->next)
2273 if (vnode->needed && (!vnode->alias || vnode->alias_of))
2274 varpool_node_set_add (vset, vnode);
2276 ipa_write_summaries_1 (set, vset);
2278 free (order);
2279 free_cgraph_node_set (set);
2280 free_varpool_node_set (vset);
2283 /* Same as execute_pass_list but assume that subpasses of IPA passes
2284 are local passes. If SET is not NULL, write out optimization summaries of
2285 only those node in SET. */
2287 static void
2288 ipa_write_optimization_summaries_1 (struct opt_pass *pass, cgraph_node_set set,
2289 varpool_node_set vset,
2290 struct lto_out_decl_state *state)
2292 while (pass)
2294 struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *)pass;
2295 gcc_assert (!current_function_decl);
2296 gcc_assert (!cfun);
2297 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
2298 if (pass->type == IPA_PASS
2299 && ipa_pass->write_optimization_summary
2300 && (!pass->gate || pass->gate ()))
2302 /* If a timevar is present, start it. */
2303 if (pass->tv_id)
2304 timevar_push (pass->tv_id);
2306 pass_init_dump_file (pass);
2308 ipa_pass->write_optimization_summary (set, vset);
2310 pass_fini_dump_file (pass);
2312 /* If a timevar is present, start it. */
2313 if (pass->tv_id)
2314 timevar_pop (pass->tv_id);
2317 if (pass->sub && pass->sub->type != GIMPLE_PASS)
2318 ipa_write_optimization_summaries_1 (pass->sub, set, vset, state);
2320 pass = pass->next;
2324 /* Write all the optimization summaries for the cgraph nodes in SET. If SET is
2325 NULL, write out all summaries of all nodes. */
2327 void
2328 ipa_write_optimization_summaries (cgraph_node_set set, varpool_node_set vset)
2330 struct lto_out_decl_state *state = lto_new_out_decl_state ();
2331 cgraph_node_set_iterator csi;
2332 compute_ltrans_boundary (state, set, vset);
2334 lto_push_out_decl_state (state);
2335 for (csi = csi_start (set); !csi_end_p (csi); csi_next (&csi))
2337 struct cgraph_node *node = csi_node (csi);
2338 /* When streaming out references to statements as part of some IPA
2339 pass summary, the statements need to have uids assigned.
2341 For functions newly born at WPA stage we need to initialize
2342 the uids here. */
2343 if (node->analyzed
2344 && gimple_has_body_p (node->decl))
2346 push_cfun (DECL_STRUCT_FUNCTION (node->decl));
2347 renumber_gimple_stmt_uids ();
2348 pop_cfun ();
2352 gcc_assert (flag_wpa);
2353 ipa_write_optimization_summaries_1 (all_regular_ipa_passes, set, vset, state);
2354 ipa_write_optimization_summaries_1 (all_lto_gen_passes, set, vset, state);
2356 gcc_assert (lto_get_out_decl_state () == state);
2357 lto_pop_out_decl_state ();
2358 lto_delete_out_decl_state (state);
2361 /* Same as execute_pass_list but assume that subpasses of IPA passes
2362 are local passes. */
2364 static void
2365 ipa_read_summaries_1 (struct opt_pass *pass)
2367 while (pass)
2369 struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *) pass;
2371 gcc_assert (!current_function_decl);
2372 gcc_assert (!cfun);
2373 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
2375 if (pass->gate == NULL || pass->gate ())
2377 if (pass->type == IPA_PASS && ipa_pass->read_summary)
2379 /* If a timevar is present, start it. */
2380 if (pass->tv_id)
2381 timevar_push (pass->tv_id);
2383 pass_init_dump_file (pass);
2385 ipa_pass->read_summary ();
2387 pass_fini_dump_file (pass);
2389 /* Stop timevar. */
2390 if (pass->tv_id)
2391 timevar_pop (pass->tv_id);
2394 if (pass->sub && pass->sub->type != GIMPLE_PASS)
2395 ipa_read_summaries_1 (pass->sub);
2397 pass = pass->next;
2402 /* Read all the summaries for all_regular_ipa_passes and all_lto_gen_passes. */
2404 void
2405 ipa_read_summaries (void)
2407 ipa_read_summaries_1 (all_regular_ipa_passes);
2408 ipa_read_summaries_1 (all_lto_gen_passes);
2411 /* Same as execute_pass_list but assume that subpasses of IPA passes
2412 are local passes. */
2414 static void
2415 ipa_read_optimization_summaries_1 (struct opt_pass *pass)
2417 while (pass)
2419 struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *) pass;
2421 gcc_assert (!current_function_decl);
2422 gcc_assert (!cfun);
2423 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
2425 if (pass->gate == NULL || pass->gate ())
2427 if (pass->type == IPA_PASS && ipa_pass->read_optimization_summary)
2429 /* If a timevar is present, start it. */
2430 if (pass->tv_id)
2431 timevar_push (pass->tv_id);
2433 pass_init_dump_file (pass);
2435 ipa_pass->read_optimization_summary ();
2437 pass_fini_dump_file (pass);
2439 /* Stop timevar. */
2440 if (pass->tv_id)
2441 timevar_pop (pass->tv_id);
2444 if (pass->sub && pass->sub->type != GIMPLE_PASS)
2445 ipa_read_optimization_summaries_1 (pass->sub);
2447 pass = pass->next;
2451 /* Read all the summaries for all_regular_ipa_passes and all_lto_gen_passes. */
2453 void
2454 ipa_read_optimization_summaries (void)
2456 ipa_read_optimization_summaries_1 (all_regular_ipa_passes);
2457 ipa_read_optimization_summaries_1 (all_lto_gen_passes);
2460 /* Same as execute_pass_list but assume that subpasses of IPA passes
2461 are local passes. */
2462 void
2463 execute_ipa_pass_list (struct opt_pass *pass)
2467 gcc_assert (!current_function_decl);
2468 gcc_assert (!cfun);
2469 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
2470 if (execute_one_pass (pass) && pass->sub)
2472 if (pass->sub->type == GIMPLE_PASS)
2474 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_START, NULL);
2475 do_per_function_toporder ((void (*)(void *))execute_pass_list,
2476 pass->sub);
2477 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_END, NULL);
2479 else if (pass->sub->type == SIMPLE_IPA_PASS
2480 || pass->sub->type == IPA_PASS)
2481 execute_ipa_pass_list (pass->sub);
2482 else
2483 gcc_unreachable ();
2485 gcc_assert (!current_function_decl);
2486 cgraph_process_new_functions ();
2487 pass = pass->next;
2489 while (pass);
2492 /* Execute stmt fixup hooks of all passes in PASS for NODE and STMTS. */
2494 static void
2495 execute_ipa_stmt_fixups (struct opt_pass *pass,
2496 struct cgraph_node *node, gimple *stmts)
2498 while (pass)
2500 /* Execute all of the IPA_PASSes in the list. */
2501 if (pass->type == IPA_PASS
2502 && (!pass->gate || pass->gate ()))
2504 struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *) pass;
2506 if (ipa_pass->stmt_fixup)
2508 pass_init_dump_file (pass);
2509 /* If a timevar is present, start it. */
2510 if (pass->tv_id)
2511 timevar_push (pass->tv_id);
2513 ipa_pass->stmt_fixup (node, stmts);
2515 /* Stop timevar. */
2516 if (pass->tv_id)
2517 timevar_pop (pass->tv_id);
2518 pass_fini_dump_file (pass);
2520 if (pass->sub)
2521 execute_ipa_stmt_fixups (pass->sub, node, stmts);
2523 pass = pass->next;
2527 /* Execute stmt fixup hooks of all IPA passes for NODE and STMTS. */
2529 void
2530 execute_all_ipa_stmt_fixups (struct cgraph_node *node, gimple *stmts)
2532 execute_ipa_stmt_fixups (all_regular_ipa_passes, node, stmts);
2536 extern void debug_properties (unsigned int);
2537 extern void dump_properties (FILE *, unsigned int);
2539 DEBUG_FUNCTION void
2540 dump_properties (FILE *dump, unsigned int props)
2542 fprintf (dump, "Properties:\n");
2543 if (props & PROP_gimple_any)
2544 fprintf (dump, "PROP_gimple_any\n");
2545 if (props & PROP_gimple_lcf)
2546 fprintf (dump, "PROP_gimple_lcf\n");
2547 if (props & PROP_gimple_leh)
2548 fprintf (dump, "PROP_gimple_leh\n");
2549 if (props & PROP_cfg)
2550 fprintf (dump, "PROP_cfg\n");
2551 if (props & PROP_referenced_vars)
2552 fprintf (dump, "PROP_referenced_vars\n");
2553 if (props & PROP_ssa)
2554 fprintf (dump, "PROP_ssa\n");
2555 if (props & PROP_no_crit_edges)
2556 fprintf (dump, "PROP_no_crit_edges\n");
2557 if (props & PROP_rtl)
2558 fprintf (dump, "PROP_rtl\n");
2559 if (props & PROP_gimple_lomp)
2560 fprintf (dump, "PROP_gimple_lomp\n");
2561 if (props & PROP_gimple_lcx)
2562 fprintf (dump, "PROP_gimple_lcx\n");
2563 if (props & PROP_cfglayout)
2564 fprintf (dump, "PROP_cfglayout\n");
2567 DEBUG_FUNCTION void
2568 debug_properties (unsigned int props)
2570 dump_properties (stderr, props);
2573 /* Called by local passes to see if function is called by already processed nodes.
2574 Because we process nodes in topological order, this means that function is
2575 in recursive cycle or we introduced new direct calls. */
2576 bool
2577 function_called_by_processed_nodes_p (void)
2579 struct cgraph_edge *e;
2580 for (e = cgraph_get_node (current_function_decl)->callers;
2582 e = e->next_caller)
2584 if (e->caller->decl == current_function_decl)
2585 continue;
2586 if (!cgraph_function_with_gimple_body_p (e->caller))
2587 continue;
2588 if (TREE_ASM_WRITTEN (e->caller->decl))
2589 continue;
2590 if (!e->caller->process && !e->caller->global.inlined_to)
2591 break;
2593 if (dump_file && e)
2595 fprintf (dump_file, "Already processed call to:\n");
2596 dump_cgraph_node (dump_file, e->caller);
2598 return e != NULL;
2601 #include "gt-passes.h"