Better function header dump
[official-gcc.git] / gcc / passes.c
blobd5189ca17d2b6faa424c5b021ea9dd687e937023
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 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 "ipa-utils.h"
77 #include "tree-pretty-print.h"
79 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
80 #include "dwarf2out.h"
81 #endif
83 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
84 #include "dbxout.h"
85 #endif
87 #ifdef SDB_DEBUGGING_INFO
88 #include "sdbout.h"
89 #endif
91 #ifdef XCOFF_DEBUGGING_INFO
92 #include "xcoffout.h" /* Needed for external data
93 declarations for e.g. AIX 4.x. */
94 #endif
96 /* This is used for debugging. It allows the current pass to printed
97 from anywhere in compilation.
98 The variable current_pass is also used for statistics and plugins. */
99 struct opt_pass *current_pass;
101 static void register_pass_name (struct opt_pass *, const char *);
103 /* Call from anywhere to find out what pass this is. Useful for
104 printing out debugging information deep inside an service
105 routine. */
106 void
107 print_current_pass (FILE *file)
109 if (current_pass)
110 fprintf (file, "current pass = %s (%d)\n",
111 current_pass->name, current_pass->static_pass_number);
112 else
113 fprintf (file, "no current pass.\n");
117 /* Call from the debugger to get the current pass name. */
118 DEBUG_FUNCTION void
119 debug_pass (void)
121 print_current_pass (stderr);
126 /* Global variables used to communicate with passes. */
127 int dump_flags;
128 bool in_gimple_form;
129 bool first_pass_instance;
132 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
133 and TYPE_DECL nodes.
135 This does nothing for local (non-static) variables, unless the
136 variable is a register variable with DECL_ASSEMBLER_NAME set. In
137 that case, or if the variable is not an automatic, it sets up the
138 RTL and outputs any assembler code (label definition, storage
139 allocation and initialization).
141 DECL is the declaration. TOP_LEVEL is nonzero
142 if this declaration is not within a function. */
144 void
145 rest_of_decl_compilation (tree decl,
146 int top_level,
147 int at_end)
149 /* We deferred calling assemble_alias so that we could collect
150 other attributes such as visibility. Emit the alias now. */
151 if (!in_lto_p)
153 tree alias;
154 alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
155 if (alias)
157 alias = TREE_VALUE (TREE_VALUE (alias));
158 alias = get_identifier (TREE_STRING_POINTER (alias));
159 assemble_alias (decl, alias);
163 /* Can't defer this, because it needs to happen before any
164 later function definitions are processed. */
165 if (DECL_ASSEMBLER_NAME_SET_P (decl) && DECL_REGISTER (decl))
166 make_decl_rtl (decl);
168 /* Forward declarations for nested functions are not "external",
169 but we need to treat them as if they were. */
170 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
171 || TREE_CODE (decl) == FUNCTION_DECL)
173 timevar_push (TV_VARCONST);
175 /* Don't output anything when a tentative file-scope definition
176 is seen. But at end of compilation, do output code for them.
178 We do output all variables and rely on
179 callgraph code to defer them except for forward declarations
180 (see gcc.c-torture/compile/920624-1.c) */
181 if ((at_end
182 || !DECL_DEFER_OUTPUT (decl)
183 || DECL_INITIAL (decl))
184 && !DECL_EXTERNAL (decl))
186 /* When reading LTO unit, we also read varpool, so do not
187 rebuild it. */
188 if (in_lto_p && !at_end)
190 else if (TREE_CODE (decl) != FUNCTION_DECL)
191 varpool_finalize_decl (decl);
194 #ifdef ASM_FINISH_DECLARE_OBJECT
195 if (decl == last_assemble_variable_decl)
197 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
198 top_level, at_end);
200 #endif
202 timevar_pop (TV_VARCONST);
204 else if (TREE_CODE (decl) == TYPE_DECL
205 /* Like in rest_of_type_compilation, avoid confusing the debug
206 information machinery when there are errors. */
207 && !seen_error ())
209 timevar_push (TV_SYMOUT);
210 debug_hooks->type_decl (decl, !top_level);
211 timevar_pop (TV_SYMOUT);
214 /* Let cgraph know about the existence of variables. */
215 if (in_lto_p && !at_end)
217 else if (TREE_CODE (decl) == VAR_DECL && !DECL_EXTERNAL (decl)
218 && TREE_STATIC (decl))
219 varpool_node (decl);
222 /* Called after finishing a record, union or enumeral type. */
224 void
225 rest_of_type_compilation (tree type, int toplev)
227 /* Avoid confusing the debug information machinery when there are
228 errors. */
229 if (seen_error ())
230 return;
232 timevar_push (TV_SYMOUT);
233 debug_hooks->type_decl (TYPE_STUB_DECL (type), !toplev);
234 timevar_pop (TV_SYMOUT);
239 void
240 finish_optimization_passes (void)
242 int i;
243 struct dump_file_info *dfi;
244 char *name;
246 timevar_push (TV_DUMP);
247 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
249 dump_file = dump_begin (pass_profile.pass.static_pass_number, NULL);
250 end_branch_prob ();
251 if (dump_file)
252 dump_end (pass_profile.pass.static_pass_number, dump_file);
255 if (optimize > 0)
257 dump_file = dump_begin (pass_combine.pass.static_pass_number, NULL);
258 if (dump_file)
260 dump_combine_total_stats (dump_file);
261 dump_end (pass_combine.pass.static_pass_number, dump_file);
265 /* Do whatever is necessary to finish printing the graphs. */
266 if (graph_dump_format != no_graph)
267 for (i = TDI_end; (dfi = get_dump_file_info (i)) != NULL; ++i)
268 if (dump_initialized_p (i)
269 && (dfi->flags & TDF_GRAPH) != 0
270 && (name = get_dump_file_name (i)) != NULL)
272 finish_graph_dump_file (name);
273 free (name);
276 timevar_pop (TV_DUMP);
279 static bool
280 gate_rest_of_compilation (void)
282 /* Early return if there were errors. We can run afoul of our
283 consistency checks, and there's not really much point in fixing them. */
284 return !(rtl_dump_and_exit || flag_syntax_only || seen_error ());
287 struct gimple_opt_pass pass_rest_of_compilation =
290 GIMPLE_PASS,
291 "*rest_of_compilation", /* name */
292 gate_rest_of_compilation, /* gate */
293 NULL, /* execute */
294 NULL, /* sub */
295 NULL, /* next */
296 0, /* static_pass_number */
297 TV_REST_OF_COMPILATION, /* tv_id */
298 PROP_rtl, /* properties_required */
299 0, /* properties_provided */
300 0, /* properties_destroyed */
301 0, /* todo_flags_start */
302 TODO_ggc_collect /* todo_flags_finish */
306 static bool
307 gate_postreload (void)
309 return reload_completed;
312 struct rtl_opt_pass pass_postreload =
315 RTL_PASS,
316 "*all-postreload", /* name */
317 gate_postreload, /* gate */
318 NULL, /* execute */
319 NULL, /* sub */
320 NULL, /* next */
321 0, /* static_pass_number */
322 TV_POSTRELOAD, /* tv_id */
323 PROP_rtl, /* properties_required */
324 0, /* properties_provided */
325 0, /* properties_destroyed */
326 0, /* todo_flags_start */
327 TODO_ggc_collect | TODO_verify_rtl_sharing /* todo_flags_finish */
333 /* The root of the compilation pass tree, once constructed. */
334 struct opt_pass *all_passes, *all_small_ipa_passes, *all_lowering_passes,
335 *all_regular_ipa_passes, *all_lto_gen_passes;
337 /* This is used by plugins, and should also be used in register_pass. */
338 #define DEF_PASS_LIST(LIST) &LIST,
339 struct opt_pass **gcc_pass_lists[] = { GCC_PASS_LISTS NULL };
340 #undef DEF_PASS_LIST
342 /* A map from static pass id to optimization pass. */
343 struct opt_pass **passes_by_id;
344 int passes_by_id_size;
346 /* Set the static pass number of pass PASS to ID and record that
347 in the mapping from static pass number to pass. */
349 static void
350 set_pass_for_id (int id, struct opt_pass *pass)
352 pass->static_pass_number = id;
353 if (passes_by_id_size <= id)
355 passes_by_id = XRESIZEVEC (struct opt_pass *, passes_by_id, id + 1);
356 memset (passes_by_id + passes_by_id_size, 0,
357 (id + 1 - passes_by_id_size) * sizeof (void *));
358 passes_by_id_size = id + 1;
360 passes_by_id[id] = pass;
363 /* Return the pass with the static pass number ID. */
365 struct opt_pass *
366 get_pass_for_id (int id)
368 if (id >= passes_by_id_size)
369 return NULL;
370 return passes_by_id[id];
373 /* Iterate over the pass tree allocating dump file numbers. We want
374 to do this depth first, and independent of whether the pass is
375 enabled or not. */
377 void
378 register_one_dump_file (struct opt_pass *pass)
380 char *dot_name, *flag_name, *glob_name;
381 const char *name, *full_name, *prefix;
382 char num[10];
383 int flags, id;
385 /* See below in next_pass_1. */
386 num[0] = '\0';
387 if (pass->static_pass_number != -1)
388 sprintf (num, "%d", ((int) pass->static_pass_number < 0
389 ? 1 : pass->static_pass_number));
391 /* The name is both used to identify the pass for the purposes of plugins,
392 and to specify dump file name and option.
393 The latter two might want something short which is not quite unique; for
394 that reason, we may have a disambiguating prefix, followed by a space
395 to mark the start of the following dump file name / option string. */
396 name = strchr (pass->name, ' ');
397 name = name ? name + 1 : pass->name;
398 dot_name = concat (".", name, num, NULL);
399 if (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS)
400 prefix = "ipa-", flags = TDF_IPA;
401 else if (pass->type == GIMPLE_PASS)
402 prefix = "tree-", flags = TDF_TREE;
403 else
404 prefix = "rtl-", flags = TDF_RTL;
406 flag_name = concat (prefix, name, num, NULL);
407 glob_name = concat (prefix, name, NULL);
408 id = dump_register (dot_name, flag_name, glob_name, flags);
409 set_pass_for_id (id, pass);
410 full_name = concat (prefix, pass->name, num, NULL);
411 register_pass_name (pass, full_name);
414 /* Recursive worker function for register_dump_files. */
416 static int
417 register_dump_files_1 (struct opt_pass *pass, int properties)
421 int new_properties = (properties | pass->properties_provided)
422 & ~pass->properties_destroyed;
424 if (pass->name && pass->name[0] != '*')
425 register_one_dump_file (pass);
427 if (pass->sub)
428 new_properties = register_dump_files_1 (pass->sub, new_properties);
430 /* If we have a gate, combine the properties that we could have with
431 and without the pass being examined. */
432 if (pass->gate)
433 properties &= new_properties;
434 else
435 properties = new_properties;
437 pass = pass->next;
439 while (pass);
441 return properties;
444 /* Register the dump files for the pipeline starting at PASS.
445 PROPERTIES reflects the properties that are guaranteed to be available at
446 the beginning of the pipeline. */
448 static void
449 register_dump_files (struct opt_pass *pass,int properties)
451 pass->properties_required |= properties;
452 register_dump_files_1 (pass, properties);
455 struct pass_registry
457 const char* unique_name;
458 struct opt_pass *pass;
461 /* Pass registry hash function. */
463 static hashval_t
464 passr_hash (const void *p)
466 const struct pass_registry *const s = (const struct pass_registry *const) p;
467 return htab_hash_string (s->unique_name);
470 /* Hash equal function */
472 static int
473 passr_eq (const void *p1, const void *p2)
475 const struct pass_registry *const s1 = (const struct pass_registry *const) p1;
476 const struct pass_registry *const s2 = (const struct pass_registry *const) p2;
478 return !strcmp (s1->unique_name, s2->unique_name);
481 static htab_t pass_name_tab = NULL;
483 /* Register PASS with NAME. */
485 static void
486 register_pass_name (struct opt_pass *pass, const char *name)
488 struct pass_registry **slot;
489 struct pass_registry pr;
491 if (!pass_name_tab)
492 pass_name_tab = htab_create (256, passr_hash, passr_eq, NULL);
494 pr.unique_name = name;
495 slot = (struct pass_registry **) htab_find_slot (pass_name_tab, &pr, INSERT);
496 if (!*slot)
498 struct pass_registry *new_pr;
500 new_pr = XCNEW (struct pass_registry);
501 new_pr->unique_name = xstrdup (name);
502 new_pr->pass = pass;
503 *slot = new_pr;
505 else
506 return; /* Ignore plugin passes. */
509 /* Returns the pass with NAME. */
511 static struct opt_pass *
512 get_pass_by_name (const char *name)
514 struct pass_registry **slot, pr;
516 gcc_assert (pass_name_tab);
517 pr.unique_name = name;
518 slot = (struct pass_registry **) htab_find_slot (pass_name_tab,
519 &pr, NO_INSERT);
521 if (!slot || !*slot)
522 return NULL;
524 return (*slot)->pass;
528 /* Range [start, last]. */
530 struct uid_range
532 unsigned int start;
533 unsigned int last;
534 struct uid_range *next;
537 typedef struct uid_range *uid_range_p;
539 DEF_VEC_P(uid_range_p);
540 DEF_VEC_ALLOC_P(uid_range_p, heap);
542 static VEC(uid_range_p, heap) *enabled_pass_uid_range_tab = NULL;
543 static VEC(uid_range_p, heap) *disabled_pass_uid_range_tab = NULL;
545 /* Parse option string for -fdisable- and -fenable-
546 The syntax of the options:
548 -fenable-<pass_name>
549 -fdisable-<pass_name>
551 -fenable-<pass_name>=s1:e1,s2:e2,...
552 -fdisable-<pass_name>=s1:e1,s2:e2,...
555 static void
556 enable_disable_pass (const char *arg, bool is_enable)
558 struct opt_pass *pass;
559 char *range_str, *phase_name;
560 char *argstr = xstrdup (arg);
561 VEC(uid_range_p, heap) **tab = 0;
563 range_str = strchr (argstr,'=');
564 if (range_str)
566 *range_str = '\0';
567 range_str++;
570 phase_name = argstr;
571 if (!*phase_name)
573 if (is_enable)
574 error ("unrecognized option -fenable");
575 else
576 error ("unrecognized option -fdisable");
577 free (argstr);
578 return;
580 pass = get_pass_by_name (phase_name);
581 if (!pass || pass->static_pass_number == -1)
583 if (is_enable)
584 error ("unknown pass %s specified in -fenable", phase_name);
585 else
586 error ("unknown pass %s specified in -fdisble", phase_name);
587 free (argstr);
588 return;
591 if (is_enable)
592 tab = &enabled_pass_uid_range_tab;
593 else
594 tab = &disabled_pass_uid_range_tab;
596 if ((unsigned) pass->static_pass_number >= VEC_length (uid_range_p, *tab))
597 VEC_safe_grow_cleared (uid_range_p, heap,
598 *tab, pass->static_pass_number + 1);
600 if (!range_str)
602 uid_range_p slot;
603 uid_range_p new_range = XCNEW (struct uid_range);
605 new_range->start = 0;
606 new_range->last = (unsigned)-1;
608 slot = VEC_index (uid_range_p, *tab, pass->static_pass_number);
609 new_range->next = slot;
610 VEC_replace (uid_range_p, *tab, pass->static_pass_number,
611 new_range);
612 if (is_enable)
613 inform (UNKNOWN_LOCATION, "enable pass %s for functions in the range "
614 "of [%u, %u]", phase_name, new_range->start, new_range->last);
615 else
616 inform (UNKNOWN_LOCATION, "disable pass %s for functions in the range "
617 "of [%u, %u]", phase_name, new_range->start, new_range->last);
619 else
621 char *next_range = NULL;
622 char *one_range = range_str;
623 char *end_val = NULL;
627 uid_range_p slot;
628 uid_range_p new_range;
629 char *invalid = NULL;
630 long start;
632 next_range = strchr (one_range, ',');
633 if (next_range)
635 *next_range = '\0';
636 next_range++;
639 end_val = strchr (one_range, ':');
640 if (end_val)
642 *end_val = '\0';
643 end_val++;
645 start = strtol (one_range, &invalid, 10);
646 if (*invalid || start < 0)
648 error ("Invalid range %s in option %s",
649 one_range,
650 is_enable ? "-fenable" : "-fdisable");
651 free (argstr);
652 return;
654 if (!end_val)
656 new_range = XCNEW (struct uid_range);
657 new_range->start = (unsigned) start;
658 new_range->last = (unsigned) start;
660 else
662 long last = strtol (end_val, &invalid, 10);
663 if (*invalid || last < start)
665 error ("Invalid range %s in option %s",
666 end_val,
667 is_enable ? "-fenable" : "-fdisable");
668 free (argstr);
669 return;
671 new_range = XCNEW (struct uid_range);
672 new_range->start = (unsigned) start;
673 new_range->last = (unsigned) last;
676 slot = VEC_index (uid_range_p, *tab, pass->static_pass_number);
677 new_range->next = slot;
678 VEC_replace (uid_range_p, *tab, pass->static_pass_number,
679 new_range);
681 if (is_enable)
682 inform (UNKNOWN_LOCATION,
683 "enable pass %s for functions in the range of [%u, %u]",
684 phase_name, new_range->start, new_range->last);
685 else
686 inform (UNKNOWN_LOCATION,
687 "disable pass %s for functions in the range of [%u, %u]",
688 phase_name, new_range->start, new_range->last);
690 one_range = next_range;
691 } while (next_range);
694 free (argstr);
697 /* Enable pass specified by ARG. */
699 void
700 enable_pass (const char *arg)
702 enable_disable_pass (arg, true);
705 /* Disable pass specified by ARG. */
707 void
708 disable_pass (const char *arg)
710 enable_disable_pass (arg, false);
713 /* Returns true if PASS is explicitly enabled/disabled for FUNC. */
715 static bool
716 is_pass_explicitly_enabled_or_disabled (struct opt_pass *pass,
717 tree func,
718 VEC(uid_range_p, heap) *tab)
720 uid_range_p slot, range;
721 int cgraph_uid;
723 if (!tab
724 || (unsigned) pass->static_pass_number >= VEC_length (uid_range_p, tab)
725 || pass->static_pass_number == -1)
726 return false;
728 slot = VEC_index (uid_range_p, tab, pass->static_pass_number);
729 if (!slot)
730 return false;
732 cgraph_uid = func ? cgraph_get_node (func)->uid : 0;
734 range = slot;
735 while (range)
737 if ((unsigned) cgraph_uid >= range->start
738 && (unsigned) cgraph_uid <= range->last)
739 return true;
740 range = range->next;
743 return false;
746 /* Look at the static_pass_number and duplicate the pass
747 if it is already added to a list. */
749 static struct opt_pass *
750 make_pass_instance (struct opt_pass *pass, bool track_duplicates)
752 /* A nonzero static_pass_number indicates that the
753 pass is already in the list. */
754 if (pass->static_pass_number)
756 struct opt_pass *new_pass;
758 if (pass->type == GIMPLE_PASS
759 || pass->type == RTL_PASS
760 || pass->type == SIMPLE_IPA_PASS)
762 new_pass = XNEW (struct opt_pass);
763 memcpy (new_pass, pass, sizeof (struct opt_pass));
765 else if (pass->type == IPA_PASS)
767 new_pass = (struct opt_pass *)XNEW (struct ipa_opt_pass_d);
768 memcpy (new_pass, pass, sizeof (struct ipa_opt_pass_d));
770 else
771 gcc_unreachable ();
773 new_pass->next = NULL;
775 new_pass->todo_flags_start &= ~TODO_mark_first_instance;
777 /* Indicate to register_dump_files that this pass has duplicates,
778 and so it should rename the dump file. The first instance will
779 be -1, and be number of duplicates = -static_pass_number - 1.
780 Subsequent instances will be > 0 and just the duplicate number. */
781 if ((pass->name && pass->name[0] != '*') || track_duplicates)
783 pass->static_pass_number -= 1;
784 new_pass->static_pass_number = -pass->static_pass_number;
786 return new_pass;
788 else
790 pass->todo_flags_start |= TODO_mark_first_instance;
791 pass->static_pass_number = -1;
793 invoke_plugin_callbacks (PLUGIN_NEW_PASS, pass);
795 return pass;
798 /* Add a pass to the pass list. Duplicate the pass if it's already
799 in the list. */
801 static struct opt_pass **
802 next_pass_1 (struct opt_pass **list, struct opt_pass *pass)
804 /* Every pass should have a name so that plugins can refer to them. */
805 gcc_assert (pass->name != NULL);
807 *list = make_pass_instance (pass, false);
809 return &(*list)->next;
812 /* List node for an inserted pass instance. We need to keep track of all
813 the newly-added pass instances (with 'added_pass_nodes' defined below)
814 so that we can register their dump files after pass-positioning is finished.
815 Registering dumping files needs to be post-processed or the
816 static_pass_number of the opt_pass object would be modified and mess up
817 the dump file names of future pass instances to be added. */
819 struct pass_list_node
821 struct opt_pass *pass;
822 struct pass_list_node *next;
825 static struct pass_list_node *added_pass_nodes = NULL;
826 static struct pass_list_node *prev_added_pass_node;
828 /* Insert the pass at the proper position. Return true if the pass
829 is successfully added.
831 NEW_PASS_INFO - new pass to be inserted
832 PASS_LIST - root of the pass list to insert the new pass to */
834 static bool
835 position_pass (struct register_pass_info *new_pass_info,
836 struct opt_pass **pass_list)
838 struct opt_pass *pass = *pass_list, *prev_pass = NULL;
839 bool success = false;
841 for ( ; pass; prev_pass = pass, pass = pass->next)
843 /* Check if the current pass is of the same type as the new pass and
844 matches the name and the instance number of the reference pass. */
845 if (pass->type == new_pass_info->pass->type
846 && pass->name
847 && !strcmp (pass->name, new_pass_info->reference_pass_name)
848 && ((new_pass_info->ref_pass_instance_number == 0)
849 || (new_pass_info->ref_pass_instance_number ==
850 pass->static_pass_number)
851 || (new_pass_info->ref_pass_instance_number == 1
852 && pass->todo_flags_start & TODO_mark_first_instance)))
854 struct opt_pass *new_pass;
855 struct pass_list_node *new_pass_node;
857 new_pass = make_pass_instance (new_pass_info->pass, true);
859 /* Insert the new pass instance based on the positioning op. */
860 switch (new_pass_info->pos_op)
862 case PASS_POS_INSERT_AFTER:
863 new_pass->next = pass->next;
864 pass->next = new_pass;
866 /* Skip newly inserted pass to avoid repeated
867 insertions in the case where the new pass and the
868 existing one have the same name. */
869 pass = new_pass;
870 break;
871 case PASS_POS_INSERT_BEFORE:
872 new_pass->next = pass;
873 if (prev_pass)
874 prev_pass->next = new_pass;
875 else
876 *pass_list = new_pass;
877 break;
878 case PASS_POS_REPLACE:
879 new_pass->next = pass->next;
880 if (prev_pass)
881 prev_pass->next = new_pass;
882 else
883 *pass_list = new_pass;
884 new_pass->sub = pass->sub;
885 new_pass->tv_id = pass->tv_id;
886 pass = new_pass;
887 break;
888 default:
889 error ("invalid pass positioning operation");
890 return false;
893 /* Save the newly added pass (instance) in the added_pass_nodes
894 list so that we can register its dump file later. Note that
895 we cannot register the dump file now because doing so will modify
896 the static_pass_number of the opt_pass object and therefore
897 mess up the dump file name of future instances. */
898 new_pass_node = XCNEW (struct pass_list_node);
899 new_pass_node->pass = new_pass;
900 if (!added_pass_nodes)
901 added_pass_nodes = new_pass_node;
902 else
903 prev_added_pass_node->next = new_pass_node;
904 prev_added_pass_node = new_pass_node;
906 success = true;
909 if (pass->sub && position_pass (new_pass_info, &pass->sub))
910 success = true;
913 return success;
916 /* Hooks a new pass into the pass lists.
918 PASS_INFO - pass information that specifies the opt_pass object,
919 reference pass, instance number, and how to position
920 the pass */
922 void
923 register_pass (struct register_pass_info *pass_info)
925 bool all_instances, success;
927 /* The checks below could fail in buggy plugins. Existing GCC
928 passes should never fail these checks, so we mention plugin in
929 the messages. */
930 if (!pass_info->pass)
931 fatal_error ("plugin cannot register a missing pass");
933 if (!pass_info->pass->name)
934 fatal_error ("plugin cannot register an unnamed pass");
936 if (!pass_info->reference_pass_name)
937 fatal_error
938 ("plugin cannot register pass %qs without reference pass name",
939 pass_info->pass->name);
941 /* Try to insert the new pass to the pass lists. We need to check
942 all five lists as the reference pass could be in one (or all) of
943 them. */
944 all_instances = pass_info->ref_pass_instance_number == 0;
945 success = position_pass (pass_info, &all_lowering_passes);
946 if (!success || all_instances)
947 success |= position_pass (pass_info, &all_small_ipa_passes);
948 if (!success || all_instances)
949 success |= position_pass (pass_info, &all_regular_ipa_passes);
950 if (!success || all_instances)
951 success |= position_pass (pass_info, &all_lto_gen_passes);
952 if (!success || all_instances)
953 success |= position_pass (pass_info, &all_passes);
954 if (!success)
955 fatal_error
956 ("pass %qs not found but is referenced by new pass %qs",
957 pass_info->reference_pass_name, pass_info->pass->name);
959 /* OK, we have successfully inserted the new pass. We need to register
960 the dump files for the newly added pass and its duplicates (if any).
961 Because the registration of plugin/backend passes happens after the
962 command-line options are parsed, the options that specify single
963 pass dumping (e.g. -fdump-tree-PASSNAME) cannot be used for new
964 passes. Therefore we currently can only enable dumping of
965 new passes when the 'dump-all' flags (e.g. -fdump-tree-all)
966 are specified. While doing so, we also delete the pass_list_node
967 objects created during pass positioning. */
968 while (added_pass_nodes)
970 struct pass_list_node *next_node = added_pass_nodes->next;
971 enum tree_dump_index tdi;
972 register_one_dump_file (added_pass_nodes->pass);
973 if (added_pass_nodes->pass->type == SIMPLE_IPA_PASS
974 || added_pass_nodes->pass->type == IPA_PASS)
975 tdi = TDI_ipa_all;
976 else if (added_pass_nodes->pass->type == GIMPLE_PASS)
977 tdi = TDI_tree_all;
978 else
979 tdi = TDI_rtl_all;
980 /* Check if dump-all flag is specified. */
981 if (get_dump_file_info (tdi)->state)
982 get_dump_file_info (added_pass_nodes->pass->static_pass_number)
983 ->state = get_dump_file_info (tdi)->state;
984 XDELETE (added_pass_nodes);
985 added_pass_nodes = next_node;
989 /* Construct the pass tree. The sequencing of passes is driven by
990 the cgraph routines:
992 cgraph_finalize_compilation_unit ()
993 for each node N in the cgraph
994 cgraph_analyze_function (N)
995 cgraph_lower_function (N) -> all_lowering_passes
997 If we are optimizing, cgraph_optimize is then invoked:
999 cgraph_optimize ()
1000 ipa_passes () -> all_small_ipa_passes
1001 cgraph_expand_all_functions ()
1002 for each node N in the cgraph
1003 cgraph_expand_function (N)
1004 tree_rest_of_compilation (DECL (N)) -> all_passes
1007 void
1008 init_optimization_passes (void)
1010 struct opt_pass **p;
1012 #define NEXT_PASS(PASS) (p = next_pass_1 (p, &((PASS).pass)))
1014 /* All passes needed to lower the function into shape optimizers can
1015 operate on. These passes are always run first on the function, but
1016 backend might produce already lowered functions that are not processed
1017 by these passes. */
1018 p = &all_lowering_passes;
1019 NEXT_PASS (pass_warn_unused_result);
1020 NEXT_PASS (pass_diagnose_omp_blocks);
1021 NEXT_PASS (pass_mudflap_1);
1022 NEXT_PASS (pass_lower_omp);
1023 NEXT_PASS (pass_lower_cf);
1024 NEXT_PASS (pass_refactor_eh);
1025 NEXT_PASS (pass_lower_eh);
1026 NEXT_PASS (pass_build_cfg);
1027 NEXT_PASS (pass_warn_function_return);
1028 NEXT_PASS (pass_build_cgraph_edges);
1029 *p = NULL;
1031 /* Interprocedural optimization passes. */
1032 p = &all_small_ipa_passes;
1033 NEXT_PASS (pass_ipa_free_lang_data);
1034 NEXT_PASS (pass_ipa_function_and_variable_visibility);
1035 NEXT_PASS (pass_early_local_passes);
1037 struct opt_pass **p = &pass_early_local_passes.pass.sub;
1038 NEXT_PASS (pass_fixup_cfg);
1039 NEXT_PASS (pass_init_datastructures);
1040 NEXT_PASS (pass_expand_omp);
1042 NEXT_PASS (pass_referenced_vars);
1043 NEXT_PASS (pass_build_ssa);
1044 NEXT_PASS (pass_lower_vector);
1045 NEXT_PASS (pass_early_warn_uninitialized);
1046 NEXT_PASS (pass_rebuild_cgraph_edges);
1047 NEXT_PASS (pass_inline_parameters);
1048 NEXT_PASS (pass_early_inline);
1049 NEXT_PASS (pass_all_early_optimizations);
1051 struct opt_pass **p = &pass_all_early_optimizations.pass.sub;
1052 NEXT_PASS (pass_remove_cgraph_callee_edges);
1053 NEXT_PASS (pass_rename_ssa_copies);
1054 NEXT_PASS (pass_ccp);
1055 NEXT_PASS (pass_forwprop);
1056 /* pass_build_ealias is a dummy pass that ensures that we
1057 execute TODO_rebuild_alias at this point. Re-building
1058 alias information also rewrites no longer addressed
1059 locals into SSA form if possible. */
1060 NEXT_PASS (pass_build_ealias);
1061 NEXT_PASS (pass_sra_early);
1062 NEXT_PASS (pass_fre);
1063 NEXT_PASS (pass_copy_prop);
1064 NEXT_PASS (pass_merge_phi);
1065 NEXT_PASS (pass_cd_dce);
1066 NEXT_PASS (pass_early_ipa_sra);
1067 NEXT_PASS (pass_tail_recursion);
1068 NEXT_PASS (pass_convert_switch);
1069 NEXT_PASS (pass_cleanup_eh);
1070 NEXT_PASS (pass_profile);
1071 NEXT_PASS (pass_local_pure_const);
1072 /* Split functions creates parts that are not run through
1073 early optimizations again. It is thus good idea to do this
1074 late. */
1075 NEXT_PASS (pass_split_functions);
1077 NEXT_PASS (pass_release_ssa_names);
1078 NEXT_PASS (pass_rebuild_cgraph_edges);
1079 NEXT_PASS (pass_inline_parameters);
1081 NEXT_PASS (pass_ipa_tree_profile);
1083 struct opt_pass **p = &pass_ipa_tree_profile.pass.sub;
1084 NEXT_PASS (pass_feedback_split_functions);
1086 NEXT_PASS (pass_ipa_increase_alignment);
1087 NEXT_PASS (pass_ipa_matrix_reorg);
1088 NEXT_PASS (pass_ipa_lower_emutls);
1089 *p = NULL;
1091 p = &all_regular_ipa_passes;
1092 NEXT_PASS (pass_ipa_whole_program_visibility);
1093 NEXT_PASS (pass_ipa_profile);
1094 NEXT_PASS (pass_ipa_cp);
1095 NEXT_PASS (pass_ipa_cdtor_merge);
1096 NEXT_PASS (pass_ipa_inline);
1097 NEXT_PASS (pass_ipa_pure_const);
1098 NEXT_PASS (pass_ipa_reference);
1099 NEXT_PASS (pass_ipa_pta);
1100 *p = NULL;
1102 p = &all_lto_gen_passes;
1103 NEXT_PASS (pass_ipa_lto_gimple_out);
1104 NEXT_PASS (pass_ipa_lto_finish_out); /* This must be the last LTO pass. */
1105 *p = NULL;
1107 /* These passes are run after IPA passes on every function that is being
1108 output to the assembler file. */
1109 p = &all_passes;
1110 NEXT_PASS (pass_lower_eh_dispatch);
1111 NEXT_PASS (pass_all_optimizations);
1113 struct opt_pass **p = &pass_all_optimizations.pass.sub;
1114 NEXT_PASS (pass_remove_cgraph_callee_edges);
1115 /* Initial scalar cleanups before alias computation.
1116 They ensure memory accesses are not indirect wherever possible. */
1117 NEXT_PASS (pass_strip_predict_hints);
1118 NEXT_PASS (pass_rename_ssa_copies);
1119 NEXT_PASS (pass_complete_unrolli);
1120 NEXT_PASS (pass_ccp);
1121 NEXT_PASS (pass_forwprop);
1122 NEXT_PASS (pass_call_cdce);
1123 /* pass_build_alias is a dummy pass that ensures that we
1124 execute TODO_rebuild_alias at this point. Re-building
1125 alias information also rewrites no longer addressed
1126 locals into SSA form if possible. */
1127 NEXT_PASS (pass_build_alias);
1128 NEXT_PASS (pass_return_slot);
1129 NEXT_PASS (pass_phiprop);
1130 NEXT_PASS (pass_fre);
1131 NEXT_PASS (pass_copy_prop);
1132 NEXT_PASS (pass_merge_phi);
1133 NEXT_PASS (pass_vrp);
1134 NEXT_PASS (pass_dce);
1135 NEXT_PASS (pass_cselim);
1136 NEXT_PASS (pass_tree_ifcombine);
1137 NEXT_PASS (pass_phiopt);
1138 NEXT_PASS (pass_tail_recursion);
1139 NEXT_PASS (pass_ch);
1140 NEXT_PASS (pass_stdarg);
1141 NEXT_PASS (pass_lower_complex);
1142 NEXT_PASS (pass_sra);
1143 NEXT_PASS (pass_rename_ssa_copies);
1144 /* The dom pass will also resolve all __builtin_constant_p calls
1145 that are still there to 0. This has to be done after some
1146 propagations have already run, but before some more dead code
1147 is removed, and this place fits nicely. Remember this when
1148 trying to move or duplicate pass_dominator somewhere earlier. */
1149 NEXT_PASS (pass_dominator);
1150 /* The only const/copy propagation opportunities left after
1151 DOM should be due to degenerate PHI nodes. So rather than
1152 run the full propagators, run a specialized pass which
1153 only examines PHIs to discover const/copy propagation
1154 opportunities. */
1155 NEXT_PASS (pass_phi_only_cprop);
1156 NEXT_PASS (pass_dse);
1157 NEXT_PASS (pass_reassoc);
1158 NEXT_PASS (pass_dce);
1159 NEXT_PASS (pass_forwprop);
1160 NEXT_PASS (pass_phiopt);
1161 NEXT_PASS (pass_object_sizes);
1162 NEXT_PASS (pass_ccp);
1163 NEXT_PASS (pass_copy_prop);
1164 NEXT_PASS (pass_cse_sincos);
1165 NEXT_PASS (pass_optimize_bswap);
1166 NEXT_PASS (pass_split_crit_edges);
1167 NEXT_PASS (pass_pre);
1168 NEXT_PASS (pass_sink_code);
1169 NEXT_PASS (pass_tree_loop);
1171 struct opt_pass **p = &pass_tree_loop.pass.sub;
1172 NEXT_PASS (pass_tree_loop_init);
1173 NEXT_PASS (pass_lim);
1174 NEXT_PASS (pass_copy_prop);
1175 NEXT_PASS (pass_dce_loop);
1176 NEXT_PASS (pass_tree_unswitch);
1177 NEXT_PASS (pass_scev_cprop);
1178 NEXT_PASS (pass_record_bounds);
1179 NEXT_PASS (pass_check_data_deps);
1180 NEXT_PASS (pass_loop_distribution);
1181 NEXT_PASS (pass_copy_prop);
1182 NEXT_PASS (pass_graphite);
1184 struct opt_pass **p = &pass_graphite.pass.sub;
1185 NEXT_PASS (pass_graphite_transforms);
1186 NEXT_PASS (pass_lim);
1187 NEXT_PASS (pass_copy_prop);
1188 NEXT_PASS (pass_dce_loop);
1190 NEXT_PASS (pass_iv_canon);
1191 NEXT_PASS (pass_if_conversion);
1192 NEXT_PASS (pass_vectorize);
1194 struct opt_pass **p = &pass_vectorize.pass.sub;
1195 NEXT_PASS (pass_lower_vector_ssa);
1196 NEXT_PASS (pass_dce_loop);
1198 NEXT_PASS (pass_predcom);
1199 NEXT_PASS (pass_complete_unroll);
1200 NEXT_PASS (pass_slp_vectorize);
1201 NEXT_PASS (pass_parallelize_loops);
1202 NEXT_PASS (pass_loop_prefetch);
1203 NEXT_PASS (pass_iv_optimize);
1204 NEXT_PASS (pass_tree_loop_done);
1206 NEXT_PASS (pass_cse_reciprocals);
1207 NEXT_PASS (pass_reassoc);
1208 NEXT_PASS (pass_vrp);
1209 NEXT_PASS (pass_dominator);
1210 /* The only const/copy propagation opportunities left after
1211 DOM should be due to degenerate PHI nodes. So rather than
1212 run the full propagators, run a specialized pass which
1213 only examines PHIs to discover const/copy propagation
1214 opportunities. */
1215 NEXT_PASS (pass_phi_only_cprop);
1216 NEXT_PASS (pass_cd_dce);
1217 NEXT_PASS (pass_tracer);
1219 /* FIXME: If DCE is not run before checking for uninitialized uses,
1220 we may get false warnings (e.g., testsuite/gcc.dg/uninit-5.c).
1221 However, this also causes us to misdiagnose cases that should be
1222 real warnings (e.g., testsuite/gcc.dg/pr18501.c).
1224 To fix the false positives in uninit-5.c, we would have to
1225 account for the predicates protecting the set and the use of each
1226 variable. Using a representation like Gated Single Assignment
1227 may help. */
1228 NEXT_PASS (pass_late_warn_uninitialized);
1229 NEXT_PASS (pass_dse);
1230 NEXT_PASS (pass_forwprop);
1231 NEXT_PASS (pass_phiopt);
1232 NEXT_PASS (pass_fold_builtins);
1233 NEXT_PASS (pass_optimize_widening_mul);
1234 NEXT_PASS (pass_tail_calls);
1235 NEXT_PASS (pass_rename_ssa_copies);
1236 NEXT_PASS (pass_uncprop);
1237 NEXT_PASS (pass_local_pure_const);
1239 NEXT_PASS (pass_lower_complex_O0);
1240 NEXT_PASS (pass_cleanup_eh);
1241 NEXT_PASS (pass_lower_resx);
1242 NEXT_PASS (pass_nrv);
1243 NEXT_PASS (pass_mudflap_2);
1244 NEXT_PASS (pass_cleanup_cfg_post_optimizing);
1245 NEXT_PASS (pass_warn_function_noreturn);
1247 NEXT_PASS (pass_expand);
1249 NEXT_PASS (pass_rest_of_compilation);
1251 struct opt_pass **p = &pass_rest_of_compilation.pass.sub;
1252 NEXT_PASS (pass_init_function);
1253 NEXT_PASS (pass_jump);
1254 NEXT_PASS (pass_rtl_eh);
1255 NEXT_PASS (pass_initial_value_sets);
1256 NEXT_PASS (pass_unshare_all_rtl);
1257 NEXT_PASS (pass_instantiate_virtual_regs);
1258 NEXT_PASS (pass_into_cfg_layout_mode);
1259 NEXT_PASS (pass_jump2);
1260 NEXT_PASS (pass_lower_subreg);
1261 NEXT_PASS (pass_df_initialize_opt);
1262 NEXT_PASS (pass_cse);
1263 NEXT_PASS (pass_rtl_fwprop);
1264 NEXT_PASS (pass_rtl_cprop);
1265 NEXT_PASS (pass_rtl_pre);
1266 NEXT_PASS (pass_rtl_hoist);
1267 NEXT_PASS (pass_rtl_cprop);
1268 NEXT_PASS (pass_rtl_store_motion);
1269 NEXT_PASS (pass_cse_after_global_opts);
1270 NEXT_PASS (pass_rtl_ifcvt);
1271 NEXT_PASS (pass_reginfo_init);
1272 /* Perform loop optimizations. It might be better to do them a bit
1273 sooner, but we want the profile feedback to work more
1274 efficiently. */
1275 NEXT_PASS (pass_loop2);
1277 struct opt_pass **p = &pass_loop2.pass.sub;
1278 NEXT_PASS (pass_rtl_loop_init);
1279 NEXT_PASS (pass_rtl_move_loop_invariants);
1280 NEXT_PASS (pass_rtl_unswitch);
1281 NEXT_PASS (pass_rtl_unroll_and_peel_loops);
1282 NEXT_PASS (pass_rtl_doloop);
1283 NEXT_PASS (pass_rtl_loop_done);
1284 *p = NULL;
1286 NEXT_PASS (pass_web);
1287 NEXT_PASS (pass_rtl_cprop);
1288 NEXT_PASS (pass_cse2);
1289 NEXT_PASS (pass_rtl_dse1);
1290 NEXT_PASS (pass_rtl_fwprop_addr);
1291 NEXT_PASS (pass_inc_dec);
1292 NEXT_PASS (pass_initialize_regs);
1293 NEXT_PASS (pass_ud_rtl_dce);
1294 NEXT_PASS (pass_combine);
1295 NEXT_PASS (pass_if_after_combine);
1296 NEXT_PASS (pass_partition_blocks);
1297 NEXT_PASS (pass_regmove);
1298 NEXT_PASS (pass_outof_cfg_layout_mode);
1299 NEXT_PASS (pass_split_all_insns);
1300 NEXT_PASS (pass_lower_subreg2);
1301 NEXT_PASS (pass_df_initialize_no_opt);
1302 NEXT_PASS (pass_stack_ptr_mod);
1303 NEXT_PASS (pass_mode_switching);
1304 NEXT_PASS (pass_match_asm_constraints);
1305 NEXT_PASS (pass_sms);
1306 NEXT_PASS (pass_sched);
1307 NEXT_PASS (pass_ira);
1308 NEXT_PASS (pass_postreload);
1310 struct opt_pass **p = &pass_postreload.pass.sub;
1311 NEXT_PASS (pass_postreload_cse);
1312 NEXT_PASS (pass_gcse2);
1313 NEXT_PASS (pass_split_after_reload);
1314 NEXT_PASS (pass_implicit_zee);
1315 NEXT_PASS (pass_compare_elim_after_reload);
1316 NEXT_PASS (pass_branch_target_load_optimize1);
1317 NEXT_PASS (pass_thread_prologue_and_epilogue);
1318 NEXT_PASS (pass_rtl_dse2);
1319 NEXT_PASS (pass_stack_adjustments);
1320 NEXT_PASS (pass_peephole2);
1321 NEXT_PASS (pass_if_after_reload);
1322 NEXT_PASS (pass_regrename);
1323 NEXT_PASS (pass_cprop_hardreg);
1324 NEXT_PASS (pass_fast_rtl_dce);
1325 NEXT_PASS (pass_reorder_blocks);
1326 NEXT_PASS (pass_branch_target_load_optimize2);
1327 NEXT_PASS (pass_leaf_regs);
1328 NEXT_PASS (pass_split_before_sched2);
1329 NEXT_PASS (pass_sched2);
1330 NEXT_PASS (pass_stack_regs);
1332 struct opt_pass **p = &pass_stack_regs.pass.sub;
1333 NEXT_PASS (pass_split_before_regstack);
1334 NEXT_PASS (pass_stack_regs_run);
1336 NEXT_PASS (pass_compute_alignments);
1337 NEXT_PASS (pass_duplicate_computed_gotos);
1338 NEXT_PASS (pass_variable_tracking);
1339 NEXT_PASS (pass_free_cfg);
1340 NEXT_PASS (pass_machine_reorg);
1341 NEXT_PASS (pass_cleanup_barriers);
1342 NEXT_PASS (pass_delay_slots);
1343 NEXT_PASS (pass_split_for_shorten_branches);
1344 NEXT_PASS (pass_convert_to_eh_region_ranges);
1345 NEXT_PASS (pass_shorten_branches);
1346 NEXT_PASS (pass_set_nothrow_function_flags);
1347 NEXT_PASS (pass_final);
1349 NEXT_PASS (pass_df_finish);
1351 NEXT_PASS (pass_clean_state);
1352 *p = NULL;
1354 #undef NEXT_PASS
1356 /* Register the passes with the tree dump code. */
1357 register_dump_files (all_lowering_passes, PROP_gimple_any);
1358 register_dump_files (all_small_ipa_passes,
1359 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
1360 | PROP_cfg);
1361 register_dump_files (all_regular_ipa_passes,
1362 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
1363 | PROP_cfg);
1364 register_dump_files (all_lto_gen_passes,
1365 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
1366 | PROP_cfg);
1367 register_dump_files (all_passes,
1368 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
1369 | PROP_cfg);
1372 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1373 function CALLBACK for every function in the call graph. Otherwise,
1374 call CALLBACK on the current function. */
1376 static void
1377 do_per_function (void (*callback) (void *data), void *data)
1379 if (current_function_decl)
1380 callback (data);
1381 else
1383 struct cgraph_node *node;
1384 for (node = cgraph_nodes; node; node = node->next)
1385 if (node->analyzed && gimple_has_body_p (node->decl)
1386 && (!node->clone_of || node->decl != node->clone_of->decl))
1388 push_cfun (DECL_STRUCT_FUNCTION (node->decl));
1389 current_function_decl = node->decl;
1390 callback (data);
1391 if (!flag_wpa)
1393 free_dominance_info (CDI_DOMINATORS);
1394 free_dominance_info (CDI_POST_DOMINATORS);
1396 current_function_decl = NULL;
1397 pop_cfun ();
1398 ggc_collect ();
1403 /* Because inlining might remove no-longer reachable nodes, we need to
1404 keep the array visible to garbage collector to avoid reading collected
1405 out nodes. */
1406 static int nnodes;
1407 static GTY ((length ("nnodes"))) cgraph_node_ptr *order;
1409 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1410 function CALLBACK for every function in the call graph. Otherwise,
1411 call CALLBACK on the current function.
1412 This function is global so that plugins can use it. */
1413 void
1414 do_per_function_toporder (void (*callback) (void *data), void *data)
1416 int i;
1418 if (current_function_decl)
1419 callback (data);
1420 else
1422 gcc_assert (!order);
1423 order = ggc_alloc_vec_cgraph_node_ptr (cgraph_n_nodes);
1424 nnodes = ipa_reverse_postorder (order);
1425 for (i = nnodes - 1; i >= 0; i--)
1426 order[i]->process = 1;
1427 for (i = nnodes - 1; i >= 0; i--)
1429 struct cgraph_node *node = order[i];
1431 /* Allow possibly removed nodes to be garbage collected. */
1432 order[i] = NULL;
1433 node->process = 0;
1434 if (cgraph_function_with_gimple_body_p (node))
1436 push_cfun (DECL_STRUCT_FUNCTION (node->decl));
1437 current_function_decl = node->decl;
1438 callback (data);
1439 free_dominance_info (CDI_DOMINATORS);
1440 free_dominance_info (CDI_POST_DOMINATORS);
1441 current_function_decl = NULL;
1442 pop_cfun ();
1443 ggc_collect ();
1447 ggc_free (order);
1448 order = NULL;
1449 nnodes = 0;
1452 /* Perform all TODO actions that ought to be done on each function. */
1454 static void
1455 execute_function_todo (void *data)
1457 unsigned int flags = (size_t)data;
1458 flags &= ~cfun->last_verified;
1459 if (!flags)
1460 return;
1462 /* Always cleanup the CFG before trying to update SSA. */
1463 if (flags & TODO_cleanup_cfg)
1465 bool cleanup = cleanup_tree_cfg ();
1467 if (cleanup && (cfun->curr_properties & PROP_ssa))
1468 flags |= TODO_remove_unused_locals;
1470 /* When cleanup_tree_cfg merges consecutive blocks, it may
1471 perform some simplistic propagation when removing single
1472 valued PHI nodes. This propagation may, in turn, cause the
1473 SSA form to become out-of-date (see PR 22037). So, even
1474 if the parent pass had not scheduled an SSA update, we may
1475 still need to do one. */
1476 if (!(flags & TODO_update_ssa_any) && need_ssa_update_p (cfun))
1477 flags |= TODO_update_ssa;
1480 if (flags & TODO_update_ssa_any)
1482 unsigned update_flags = flags & TODO_update_ssa_any;
1483 update_ssa (update_flags);
1484 cfun->last_verified &= ~TODO_verify_ssa;
1487 if (flags & TODO_rebuild_alias)
1489 execute_update_addresses_taken ();
1490 compute_may_aliases ();
1492 else if (optimize && (flags & TODO_update_address_taken))
1493 execute_update_addresses_taken ();
1495 if (flags & TODO_remove_unused_locals)
1496 remove_unused_locals ();
1498 if ((flags & TODO_dump_func) && dump_file && current_function_decl)
1500 if (cfun->curr_properties & PROP_trees)
1501 dump_function_to_file (current_function_decl, dump_file, dump_flags);
1502 else
1504 if (dump_flags & TDF_SLIM)
1505 print_rtl_slim_with_bb (dump_file, get_insns (), dump_flags);
1506 else if ((cfun->curr_properties & PROP_cfg)
1507 && (dump_flags & TDF_BLOCKS))
1508 print_rtl_with_bb (dump_file, get_insns ());
1509 else
1510 print_rtl (dump_file, get_insns ());
1512 if ((cfun->curr_properties & PROP_cfg)
1513 && graph_dump_format != no_graph
1514 && (dump_flags & TDF_GRAPH))
1515 print_rtl_graph_with_bb (dump_file_name, get_insns ());
1518 /* Flush the file. If verification fails, we won't be able to
1519 close the file before aborting. */
1520 fflush (dump_file);
1523 if (flags & TODO_rebuild_frequencies)
1524 rebuild_frequencies ();
1526 if (flags & TODO_rebuild_cgraph_edges)
1527 rebuild_cgraph_edges ();
1529 /* If we've seen errors do not bother running any verifiers. */
1530 if (seen_error ())
1531 return;
1533 #if defined ENABLE_CHECKING
1534 if (flags & TODO_verify_ssa
1535 || (current_loops && loops_state_satisfies_p (LOOP_CLOSED_SSA)))
1536 verify_ssa (true);
1537 if (flags & TODO_verify_flow)
1538 verify_flow_info ();
1539 if (flags & TODO_verify_stmts)
1540 verify_gimple_in_cfg (cfun);
1541 if (current_loops && loops_state_satisfies_p (LOOP_CLOSED_SSA))
1542 verify_loop_closed_ssa (false);
1543 if (flags & TODO_verify_rtl_sharing)
1544 verify_rtl_sharing ();
1545 #endif
1547 cfun->last_verified = flags & TODO_verify_all;
1550 /* Perform all TODO actions. */
1551 static void
1552 execute_todo (unsigned int flags)
1554 #if defined ENABLE_CHECKING
1555 if (cfun
1556 && need_ssa_update_p (cfun))
1557 gcc_assert (flags & TODO_update_ssa_any);
1558 #endif
1560 timevar_push (TV_TODO);
1562 /* Inform the pass whether it is the first time it is run. */
1563 first_pass_instance = (flags & TODO_mark_first_instance) != 0;
1565 statistics_fini_pass ();
1567 do_per_function (execute_function_todo, (void *)(size_t) flags);
1569 /* Always remove functions just as before inlining: IPA passes might be
1570 interested to see bodies of extern inline functions that are not inlined
1571 to analyze side effects. The full removal is done just at the end
1572 of IPA pass queue. */
1573 if (flags & TODO_remove_functions)
1575 gcc_assert (!cfun);
1576 cgraph_remove_unreachable_nodes (true, dump_file);
1579 if ((flags & TODO_dump_cgraph) && dump_file && !current_function_decl)
1581 gcc_assert (!cfun);
1582 dump_cgraph (dump_file);
1583 /* Flush the file. If verification fails, we won't be able to
1584 close the file before aborting. */
1585 fflush (dump_file);
1588 if (flags & TODO_ggc_collect)
1589 ggc_collect ();
1591 /* Now that the dumping has been done, we can get rid of the optional
1592 df problems. */
1593 if (flags & TODO_df_finish)
1594 df_finish_pass ((flags & TODO_df_verify) != 0);
1596 timevar_pop (TV_TODO);
1599 /* Verify invariants that should hold between passes. This is a place
1600 to put simple sanity checks. */
1602 static void
1603 verify_interpass_invariants (void)
1605 gcc_checking_assert (!fold_deferring_overflow_warnings_p ());
1608 /* Clear the last verified flag. */
1610 static void
1611 clear_last_verified (void *data ATTRIBUTE_UNUSED)
1613 cfun->last_verified = 0;
1616 /* Helper function. Verify that the properties has been turn into the
1617 properties expected by the pass. */
1619 #ifdef ENABLE_CHECKING
1620 static void
1621 verify_curr_properties (void *data)
1623 unsigned int props = (size_t)data;
1624 gcc_assert ((cfun->curr_properties & props) == props);
1626 #endif
1628 /* Initialize pass dump file. */
1629 /* This is non-static so that the plugins can use it. */
1631 bool
1632 pass_init_dump_file (struct opt_pass *pass)
1634 /* If a dump file name is present, open it if enabled. */
1635 if (pass->static_pass_number != -1)
1637 bool initializing_dump = !dump_initialized_p (pass->static_pass_number);
1638 dump_file_name = get_dump_file_name (pass->static_pass_number);
1639 dump_file = dump_begin (pass->static_pass_number, &dump_flags);
1640 if (dump_file && current_function_decl)
1641 dump_function_header (dump_file, current_function_decl);
1642 return initializing_dump;
1644 else
1645 return false;
1648 /* Flush PASS dump file. */
1649 /* This is non-static so that plugins can use it. */
1651 void
1652 pass_fini_dump_file (struct opt_pass *pass)
1654 /* Flush and close dump file. */
1655 if (dump_file_name)
1657 free (CONST_CAST (char *, dump_file_name));
1658 dump_file_name = NULL;
1661 if (dump_file)
1663 dump_end (pass->static_pass_number, dump_file);
1664 dump_file = NULL;
1668 /* After executing the pass, apply expected changes to the function
1669 properties. */
1671 static void
1672 update_properties_after_pass (void *data)
1674 struct opt_pass *pass = (struct opt_pass *) data;
1675 cfun->curr_properties = (cfun->curr_properties | pass->properties_provided)
1676 & ~pass->properties_destroyed;
1679 /* Execute summary generation for all of the passes in IPA_PASS. */
1681 void
1682 execute_ipa_summary_passes (struct ipa_opt_pass_d *ipa_pass)
1684 while (ipa_pass)
1686 struct opt_pass *pass = &ipa_pass->pass;
1688 /* Execute all of the IPA_PASSes in the list. */
1689 if (ipa_pass->pass.type == IPA_PASS
1690 && (!pass->gate || pass->gate ())
1691 && ipa_pass->generate_summary)
1693 pass_init_dump_file (pass);
1695 /* If a timevar is present, start it. */
1696 if (pass->tv_id)
1697 timevar_push (pass->tv_id);
1699 ipa_pass->generate_summary ();
1701 /* Stop timevar. */
1702 if (pass->tv_id)
1703 timevar_pop (pass->tv_id);
1705 pass_fini_dump_file (pass);
1707 ipa_pass = (struct ipa_opt_pass_d *)ipa_pass->pass.next;
1711 /* Execute IPA_PASS function transform on NODE. */
1713 static void
1714 execute_one_ipa_transform_pass (struct cgraph_node *node,
1715 struct ipa_opt_pass_d *ipa_pass)
1717 struct opt_pass *pass = &ipa_pass->pass;
1718 unsigned int todo_after = 0;
1720 current_pass = pass;
1721 if (!ipa_pass->function_transform)
1722 return;
1724 /* Note that the folders should only create gimple expressions.
1725 This is a hack until the new folder is ready. */
1726 in_gimple_form = (cfun && (cfun->curr_properties & PROP_trees)) != 0;
1728 pass_init_dump_file (pass);
1730 /* Run pre-pass verification. */
1731 execute_todo (ipa_pass->function_transform_todo_flags_start);
1733 /* If a timevar is present, start it. */
1734 if (pass->tv_id != TV_NONE)
1735 timevar_push (pass->tv_id);
1737 /* Do it! */
1738 todo_after = ipa_pass->function_transform (node);
1740 /* Stop timevar. */
1741 if (pass->tv_id != TV_NONE)
1742 timevar_pop (pass->tv_id);
1744 /* Run post-pass cleanup and verification. */
1745 execute_todo (todo_after);
1746 verify_interpass_invariants ();
1748 pass_fini_dump_file (pass);
1750 current_pass = NULL;
1753 /* For the current function, execute all ipa transforms. */
1755 void
1756 execute_all_ipa_transforms (void)
1758 struct cgraph_node *node;
1759 if (!cfun)
1760 return;
1761 node = cgraph_get_node (current_function_decl);
1763 if (node->ipa_transforms_to_apply)
1765 unsigned int i;
1767 for (i = 0; i < VEC_length (ipa_opt_pass, node->ipa_transforms_to_apply);
1768 i++)
1769 execute_one_ipa_transform_pass (node,
1770 VEC_index (ipa_opt_pass,
1771 node->ipa_transforms_to_apply,
1772 i));
1773 VEC_free (ipa_opt_pass, heap, node->ipa_transforms_to_apply);
1774 node->ipa_transforms_to_apply = NULL;
1778 /* Check if PASS is explicitly disabled or enabled and return
1779 the gate status. FUNC is the function to be processed, and
1780 GATE_STATUS is the gate status determined by pass manager by
1781 default. */
1783 static bool
1784 override_gate_status (struct opt_pass *pass, tree func, bool gate_status)
1786 bool explicitly_enabled = false;
1787 bool explicitly_disabled = false;
1789 explicitly_enabled
1790 = is_pass_explicitly_enabled_or_disabled (pass, func,
1791 enabled_pass_uid_range_tab);
1792 explicitly_disabled
1793 = is_pass_explicitly_enabled_or_disabled (pass, func,
1794 disabled_pass_uid_range_tab);
1796 gate_status = !explicitly_disabled && (gate_status || explicitly_enabled);
1798 return gate_status;
1802 /* Execute PASS. */
1804 bool
1805 execute_one_pass (struct opt_pass *pass)
1807 bool initializing_dump;
1808 unsigned int todo_after = 0;
1810 bool gate_status;
1812 /* IPA passes are executed on whole program, so cfun should be NULL.
1813 Other passes need function context set. */
1814 if (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS)
1815 gcc_assert (!cfun && !current_function_decl);
1816 else
1817 gcc_assert (cfun && current_function_decl);
1819 current_pass = pass;
1821 /* Check whether gate check should be avoided.
1822 User controls the value of the gate through the parameter "gate_status". */
1823 gate_status = (pass->gate == NULL) ? true : pass->gate();
1824 gate_status = override_gate_status (pass, current_function_decl, gate_status);
1826 /* Override gate with plugin. */
1827 invoke_plugin_callbacks (PLUGIN_OVERRIDE_GATE, &gate_status);
1829 if (!gate_status)
1831 current_pass = NULL;
1832 return false;
1835 /* Pass execution event trigger: useful to identify passes being
1836 executed. */
1837 invoke_plugin_callbacks (PLUGIN_PASS_EXECUTION, pass);
1839 if (!quiet_flag && !cfun)
1840 fprintf (stderr, " <%s>", pass->name ? pass->name : "");
1842 /* Note that the folders should only create gimple expressions.
1843 This is a hack until the new folder is ready. */
1844 in_gimple_form = (cfun && (cfun->curr_properties & PROP_trees)) != 0;
1846 initializing_dump = pass_init_dump_file (pass);
1848 /* Run pre-pass verification. */
1849 execute_todo (pass->todo_flags_start);
1851 #ifdef ENABLE_CHECKING
1852 do_per_function (verify_curr_properties,
1853 (void *)(size_t)pass->properties_required);
1854 #endif
1856 /* If a timevar is present, start it. */
1857 if (pass->tv_id != TV_NONE)
1858 timevar_push (pass->tv_id);
1860 /* Do it! */
1861 if (pass->execute)
1863 todo_after = pass->execute ();
1864 do_per_function (clear_last_verified, NULL);
1867 /* Stop timevar. */
1868 if (pass->tv_id != TV_NONE)
1869 timevar_pop (pass->tv_id);
1871 do_per_function (update_properties_after_pass, pass);
1873 if (initializing_dump
1874 && dump_file
1875 && graph_dump_format != no_graph
1876 && cfun
1877 && (cfun->curr_properties & (PROP_cfg | PROP_rtl))
1878 == (PROP_cfg | PROP_rtl))
1880 get_dump_file_info (pass->static_pass_number)->flags |= TDF_GRAPH;
1881 dump_flags |= TDF_GRAPH;
1882 clean_graph_dump_file (dump_file_name);
1885 /* Run post-pass cleanup and verification. */
1886 execute_todo (todo_after | pass->todo_flags_finish);
1887 verify_interpass_invariants ();
1888 if (pass->type == IPA_PASS)
1890 struct cgraph_node *node;
1891 FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node)
1892 VEC_safe_push (ipa_opt_pass, heap, node->ipa_transforms_to_apply,
1893 (struct ipa_opt_pass_d *)pass);
1896 if (!current_function_decl)
1897 cgraph_process_new_functions ();
1899 pass_fini_dump_file (pass);
1901 if (pass->type != SIMPLE_IPA_PASS && pass->type != IPA_PASS)
1902 gcc_assert (!(cfun->curr_properties & PROP_trees)
1903 || pass->type != RTL_PASS);
1905 current_pass = NULL;
1907 return true;
1910 void
1911 execute_pass_list (struct opt_pass *pass)
1915 gcc_assert (pass->type == GIMPLE_PASS
1916 || pass->type == RTL_PASS);
1917 if (execute_one_pass (pass) && pass->sub)
1918 execute_pass_list (pass->sub);
1919 pass = pass->next;
1921 while (pass);
1924 /* Same as execute_pass_list but assume that subpasses of IPA passes
1925 are local passes. If SET is not NULL, write out summaries of only
1926 those node in SET. */
1928 static void
1929 ipa_write_summaries_2 (struct opt_pass *pass, cgraph_node_set set,
1930 varpool_node_set vset,
1931 struct lto_out_decl_state *state)
1933 while (pass)
1935 struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *)pass;
1936 gcc_assert (!current_function_decl);
1937 gcc_assert (!cfun);
1938 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
1939 if (pass->type == IPA_PASS
1940 && ipa_pass->write_summary
1941 && (!pass->gate || pass->gate ()))
1943 /* If a timevar is present, start it. */
1944 if (pass->tv_id)
1945 timevar_push (pass->tv_id);
1947 pass_init_dump_file (pass);
1949 ipa_pass->write_summary (set,vset);
1951 pass_fini_dump_file (pass);
1953 /* If a timevar is present, start it. */
1954 if (pass->tv_id)
1955 timevar_pop (pass->tv_id);
1958 if (pass->sub && pass->sub->type != GIMPLE_PASS)
1959 ipa_write_summaries_2 (pass->sub, set, vset, state);
1961 pass = pass->next;
1965 /* Helper function of ipa_write_summaries. Creates and destroys the
1966 decl state and calls ipa_write_summaries_2 for all passes that have
1967 summaries. SET is the set of nodes to be written. */
1969 static void
1970 ipa_write_summaries_1 (cgraph_node_set set, varpool_node_set vset)
1972 struct lto_out_decl_state *state = lto_new_out_decl_state ();
1973 compute_ltrans_boundary (state, set, vset);
1975 lto_push_out_decl_state (state);
1977 gcc_assert (!flag_wpa);
1978 ipa_write_summaries_2 (all_regular_ipa_passes, set, vset, state);
1979 ipa_write_summaries_2 (all_lto_gen_passes, set, vset, state);
1981 gcc_assert (lto_get_out_decl_state () == state);
1982 lto_pop_out_decl_state ();
1983 lto_delete_out_decl_state (state);
1986 /* Write out summaries for all the nodes in the callgraph. */
1988 void
1989 ipa_write_summaries (void)
1991 cgraph_node_set set;
1992 varpool_node_set vset;
1993 struct cgraph_node **order;
1994 struct varpool_node *vnode;
1995 int i, order_pos;
1997 if (!flag_generate_lto || seen_error ())
1998 return;
2000 set = cgraph_node_set_new ();
2002 /* Create the callgraph set in the same order used in
2003 cgraph_expand_all_functions. This mostly facilitates debugging,
2004 since it causes the gimple file to be processed in the same order
2005 as the source code. */
2006 order = XCNEWVEC (struct cgraph_node *, cgraph_n_nodes);
2007 order_pos = ipa_reverse_postorder (order);
2008 gcc_assert (order_pos == cgraph_n_nodes);
2010 for (i = order_pos - 1; i >= 0; i--)
2012 struct cgraph_node *node = order[i];
2014 if (cgraph_function_with_gimple_body_p (node))
2016 /* When streaming out references to statements as part of some IPA
2017 pass summary, the statements need to have uids assigned and the
2018 following does that for all the IPA passes here. Naturally, this
2019 ordering then matches the one IPA-passes get in their stmt_fixup
2020 hooks. */
2022 push_cfun (DECL_STRUCT_FUNCTION (node->decl));
2023 renumber_gimple_stmt_uids ();
2024 pop_cfun ();
2026 if (node->analyzed)
2027 cgraph_node_set_add (set, node);
2029 vset = varpool_node_set_new ();
2031 for (vnode = varpool_nodes; vnode; vnode = vnode->next)
2032 if (vnode->needed && !vnode->alias)
2033 varpool_node_set_add (vset, vnode);
2035 ipa_write_summaries_1 (set, vset);
2037 free (order);
2038 free_cgraph_node_set (set);
2039 free_varpool_node_set (vset);
2042 /* Same as execute_pass_list but assume that subpasses of IPA passes
2043 are local passes. If SET is not NULL, write out optimization summaries of
2044 only those node in SET. */
2046 static void
2047 ipa_write_optimization_summaries_1 (struct opt_pass *pass, cgraph_node_set set,
2048 varpool_node_set vset,
2049 struct lto_out_decl_state *state)
2051 while (pass)
2053 struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *)pass;
2054 gcc_assert (!current_function_decl);
2055 gcc_assert (!cfun);
2056 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
2057 if (pass->type == IPA_PASS
2058 && ipa_pass->write_optimization_summary
2059 && (!pass->gate || pass->gate ()))
2061 /* If a timevar is present, start it. */
2062 if (pass->tv_id)
2063 timevar_push (pass->tv_id);
2065 pass_init_dump_file (pass);
2067 ipa_pass->write_optimization_summary (set, vset);
2069 pass_fini_dump_file (pass);
2071 /* If a timevar is present, start it. */
2072 if (pass->tv_id)
2073 timevar_pop (pass->tv_id);
2076 if (pass->sub && pass->sub->type != GIMPLE_PASS)
2077 ipa_write_optimization_summaries_1 (pass->sub, set, vset, state);
2079 pass = pass->next;
2083 /* Write all the optimization summaries for the cgraph nodes in SET. If SET is
2084 NULL, write out all summaries of all nodes. */
2086 void
2087 ipa_write_optimization_summaries (cgraph_node_set set, varpool_node_set vset)
2089 struct lto_out_decl_state *state = lto_new_out_decl_state ();
2090 cgraph_node_set_iterator csi;
2091 compute_ltrans_boundary (state, set, vset);
2093 lto_push_out_decl_state (state);
2094 for (csi = csi_start (set); !csi_end_p (csi); csi_next (&csi))
2096 struct cgraph_node *node = csi_node (csi);
2097 /* When streaming out references to statements as part of some IPA
2098 pass summary, the statements need to have uids assigned.
2100 For functions newly born at WPA stage we need to initialize
2101 the uids here. */
2102 if (node->analyzed
2103 && gimple_has_body_p (node->decl))
2105 push_cfun (DECL_STRUCT_FUNCTION (node->decl));
2106 renumber_gimple_stmt_uids ();
2107 pop_cfun ();
2111 gcc_assert (flag_wpa);
2112 ipa_write_optimization_summaries_1 (all_regular_ipa_passes, set, vset, state);
2113 ipa_write_optimization_summaries_1 (all_lto_gen_passes, set, vset, state);
2115 gcc_assert (lto_get_out_decl_state () == state);
2116 lto_pop_out_decl_state ();
2117 lto_delete_out_decl_state (state);
2120 /* Same as execute_pass_list but assume that subpasses of IPA passes
2121 are local passes. */
2123 static void
2124 ipa_read_summaries_1 (struct opt_pass *pass)
2126 while (pass)
2128 struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *) pass;
2130 gcc_assert (!current_function_decl);
2131 gcc_assert (!cfun);
2132 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
2134 if (pass->gate == NULL || pass->gate ())
2136 if (pass->type == IPA_PASS && ipa_pass->read_summary)
2138 /* If a timevar is present, start it. */
2139 if (pass->tv_id)
2140 timevar_push (pass->tv_id);
2142 pass_init_dump_file (pass);
2144 ipa_pass->read_summary ();
2146 pass_fini_dump_file (pass);
2148 /* Stop timevar. */
2149 if (pass->tv_id)
2150 timevar_pop (pass->tv_id);
2153 if (pass->sub && pass->sub->type != GIMPLE_PASS)
2154 ipa_read_summaries_1 (pass->sub);
2156 pass = pass->next;
2161 /* Read all the summaries for all_regular_ipa_passes and all_lto_gen_passes. */
2163 void
2164 ipa_read_summaries (void)
2166 ipa_read_summaries_1 (all_regular_ipa_passes);
2167 ipa_read_summaries_1 (all_lto_gen_passes);
2170 /* Same as execute_pass_list but assume that subpasses of IPA passes
2171 are local passes. */
2173 static void
2174 ipa_read_optimization_summaries_1 (struct opt_pass *pass)
2176 while (pass)
2178 struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *) pass;
2180 gcc_assert (!current_function_decl);
2181 gcc_assert (!cfun);
2182 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
2184 if (pass->gate == NULL || pass->gate ())
2186 if (pass->type == IPA_PASS && ipa_pass->read_optimization_summary)
2188 /* If a timevar is present, start it. */
2189 if (pass->tv_id)
2190 timevar_push (pass->tv_id);
2192 pass_init_dump_file (pass);
2194 ipa_pass->read_optimization_summary ();
2196 pass_fini_dump_file (pass);
2198 /* Stop timevar. */
2199 if (pass->tv_id)
2200 timevar_pop (pass->tv_id);
2203 if (pass->sub && pass->sub->type != GIMPLE_PASS)
2204 ipa_read_optimization_summaries_1 (pass->sub);
2206 pass = pass->next;
2210 /* Read all the summaries for all_regular_ipa_passes and all_lto_gen_passes. */
2212 void
2213 ipa_read_optimization_summaries (void)
2215 ipa_read_optimization_summaries_1 (all_regular_ipa_passes);
2216 ipa_read_optimization_summaries_1 (all_lto_gen_passes);
2219 /* Same as execute_pass_list but assume that subpasses of IPA passes
2220 are local passes. */
2221 void
2222 execute_ipa_pass_list (struct opt_pass *pass)
2226 gcc_assert (!current_function_decl);
2227 gcc_assert (!cfun);
2228 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
2229 if (execute_one_pass (pass) && pass->sub)
2231 if (pass->sub->type == GIMPLE_PASS)
2233 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_START, NULL);
2234 do_per_function_toporder ((void (*)(void *))execute_pass_list,
2235 pass->sub);
2236 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_END, NULL);
2238 else if (pass->sub->type == SIMPLE_IPA_PASS
2239 || pass->sub->type == IPA_PASS)
2240 execute_ipa_pass_list (pass->sub);
2241 else
2242 gcc_unreachable ();
2244 gcc_assert (!current_function_decl);
2245 cgraph_process_new_functions ();
2246 pass = pass->next;
2248 while (pass);
2251 /* Execute stmt fixup hooks of all passes in PASS for NODE and STMTS. */
2253 static void
2254 execute_ipa_stmt_fixups (struct opt_pass *pass,
2255 struct cgraph_node *node, gimple *stmts)
2257 while (pass)
2259 /* Execute all of the IPA_PASSes in the list. */
2260 if (pass->type == IPA_PASS
2261 && (!pass->gate || pass->gate ()))
2263 struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *) pass;
2265 if (ipa_pass->stmt_fixup)
2267 pass_init_dump_file (pass);
2268 /* If a timevar is present, start it. */
2269 if (pass->tv_id)
2270 timevar_push (pass->tv_id);
2272 ipa_pass->stmt_fixup (node, stmts);
2274 /* Stop timevar. */
2275 if (pass->tv_id)
2276 timevar_pop (pass->tv_id);
2277 pass_fini_dump_file (pass);
2279 if (pass->sub)
2280 execute_ipa_stmt_fixups (pass->sub, node, stmts);
2282 pass = pass->next;
2286 /* Execute stmt fixup hooks of all IPA passes for NODE and STMTS. */
2288 void
2289 execute_all_ipa_stmt_fixups (struct cgraph_node *node, gimple *stmts)
2291 execute_ipa_stmt_fixups (all_regular_ipa_passes, node, stmts);
2295 extern void debug_properties (unsigned int);
2296 extern void dump_properties (FILE *, unsigned int);
2298 DEBUG_FUNCTION void
2299 dump_properties (FILE *dump, unsigned int props)
2301 fprintf (dump, "Properties:\n");
2302 if (props & PROP_gimple_any)
2303 fprintf (dump, "PROP_gimple_any\n");
2304 if (props & PROP_gimple_lcf)
2305 fprintf (dump, "PROP_gimple_lcf\n");
2306 if (props & PROP_gimple_leh)
2307 fprintf (dump, "PROP_gimple_leh\n");
2308 if (props & PROP_cfg)
2309 fprintf (dump, "PROP_cfg\n");
2310 if (props & PROP_referenced_vars)
2311 fprintf (dump, "PROP_referenced_vars\n");
2312 if (props & PROP_ssa)
2313 fprintf (dump, "PROP_ssa\n");
2314 if (props & PROP_no_crit_edges)
2315 fprintf (dump, "PROP_no_crit_edges\n");
2316 if (props & PROP_rtl)
2317 fprintf (dump, "PROP_rtl\n");
2318 if (props & PROP_gimple_lomp)
2319 fprintf (dump, "PROP_gimple_lomp\n");
2320 if (props & PROP_gimple_lcx)
2321 fprintf (dump, "PROP_gimple_lcx\n");
2322 if (props & PROP_cfglayout)
2323 fprintf (dump, "PROP_cfglayout\n");
2326 DEBUG_FUNCTION void
2327 debug_properties (unsigned int props)
2329 dump_properties (stderr, props);
2332 /* Called by local passes to see if function is called by already processed nodes.
2333 Because we process nodes in topological order, this means that function is
2334 in recursive cycle or we introduced new direct calls. */
2335 bool
2336 function_called_by_processed_nodes_p (void)
2338 struct cgraph_edge *e;
2339 for (e = cgraph_get_node (current_function_decl)->callers;
2341 e = e->next_caller)
2343 if (e->caller->decl == current_function_decl)
2344 continue;
2345 if (!cgraph_function_with_gimple_body_p (e->caller))
2346 continue;
2347 if (TREE_ASM_WRITTEN (e->caller->decl))
2348 continue;
2349 if (!e->caller->process && !e->caller->global.inlined_to)
2350 break;
2352 if (dump_file && e)
2354 fprintf (dump_file, "Already processed call to:\n");
2355 dump_cgraph_node (dump_file, e->caller);
2357 return e != NULL;
2360 #include "gt-passes.h"