lto-symtab.c (lto_symtab_merge_cgraph_nodes_1): Rename to ...
[gcc.git] / gcc / passes.c
1 /* Top level of GCC compilers (cc1, cc1plus, etc.)
2 Copyright (C) 1987-2013 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
10
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
19
20 /* This is the top level of cc1/c++.
21 It parses command args, opens files, invokes the various passes
22 in the proper order, and counts the time used by each.
23 Error messages and low-level interface to malloc also handled here. */
24
25 #include "config.h"
26 #include "system.h"
27 #include "coretypes.h"
28 #include "tm.h"
29 #include "line-map.h"
30 #include "hash-table.h"
31 #include "input.h"
32 #include "tree.h"
33 #include "rtl.h"
34 #include "tm_p.h"
35 #include "flags.h"
36 #include "insn-attr.h"
37 #include "insn-config.h"
38 #include "insn-flags.h"
39 #include "hard-reg-set.h"
40 #include "recog.h"
41 #include "output.h"
42 #include "except.h"
43 #include "function.h"
44 #include "toplev.h"
45 #include "expr.h"
46 #include "basic-block.h"
47 #include "intl.h"
48 #include "ggc.h"
49 #include "graph.h"
50 #include "regs.h"
51 #include "diagnostic-core.h"
52 #include "params.h"
53 #include "reload.h"
54 #include "debug.h"
55 #include "target.h"
56 #include "langhooks.h"
57 #include "cfgloop.h"
58 #include "hosthooks.h"
59 #include "cgraph.h"
60 #include "opts.h"
61 #include "coverage.h"
62 #include "value-prof.h"
63 #include "tree-inline.h"
64 #include "tree-flow.h"
65 #include "tree-pass.h"
66 #include "tree-dump.h"
67 #include "df.h"
68 #include "predict.h"
69 #include "lto-streamer.h"
70 #include "plugin.h"
71 #include "ipa-utils.h"
72 #include "tree-pretty-print.h" /* for dump_function_header */
73
74 /* This is used for debugging. It allows the current pass to printed
75 from anywhere in compilation.
76 The variable current_pass is also used for statistics and plugins. */
77 struct opt_pass *current_pass;
78
79 static void register_pass_name (struct opt_pass *, const char *);
80
81 /* Call from anywhere to find out what pass this is. Useful for
82 printing out debugging information deep inside an service
83 routine. */
84 void
85 print_current_pass (FILE *file)
86 {
87 if (current_pass)
88 fprintf (file, "current pass = %s (%d)\n",
89 current_pass->name, current_pass->static_pass_number);
90 else
91 fprintf (file, "no current pass.\n");
92 }
93
94
95 /* Call from the debugger to get the current pass name. */
96 DEBUG_FUNCTION void
97 debug_pass (void)
98 {
99 print_current_pass (stderr);
100 }
101
102
103
104 /* Global variables used to communicate with passes. */
105 bool in_gimple_form;
106 bool first_pass_instance;
107
108
109 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
110 and TYPE_DECL nodes.
111
112 This does nothing for local (non-static) variables, unless the
113 variable is a register variable with DECL_ASSEMBLER_NAME set. In
114 that case, or if the variable is not an automatic, it sets up the
115 RTL and outputs any assembler code (label definition, storage
116 allocation and initialization).
117
118 DECL is the declaration. TOP_LEVEL is nonzero
119 if this declaration is not within a function. */
120
121 void
122 rest_of_decl_compilation (tree decl,
123 int top_level,
124 int at_end)
125 {
126 /* We deferred calling assemble_alias so that we could collect
127 other attributes such as visibility. Emit the alias now. */
128 if (!in_lto_p)
129 {
130 tree alias;
131 alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
132 if (alias)
133 {
134 alias = TREE_VALUE (TREE_VALUE (alias));
135 alias = get_identifier (TREE_STRING_POINTER (alias));
136 /* A quirk of the initial implementation of aliases required that the
137 user add "extern" to all of them. Which is silly, but now
138 historical. Do note that the symbol is in fact locally defined. */
139 if (!lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))
140 DECL_EXTERNAL (decl) = 0;
141 assemble_alias (decl, alias);
142 }
143 }
144
145 /* Can't defer this, because it needs to happen before any
146 later function definitions are processed. */
147 if (DECL_ASSEMBLER_NAME_SET_P (decl) && DECL_REGISTER (decl))
148 make_decl_rtl (decl);
149
150 /* Forward declarations for nested functions are not "external",
151 but we need to treat them as if they were. */
152 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
153 || TREE_CODE (decl) == FUNCTION_DECL)
154 {
155 timevar_push (TV_VARCONST);
156
157 /* Don't output anything when a tentative file-scope definition
158 is seen. But at end of compilation, do output code for them.
159
160 We do output all variables and rely on
161 callgraph code to defer them except for forward declarations
162 (see gcc.c-torture/compile/920624-1.c) */
163 if ((at_end
164 || !DECL_DEFER_OUTPUT (decl)
165 || DECL_INITIAL (decl))
166 && (TREE_CODE (decl) != VAR_DECL || !DECL_HAS_VALUE_EXPR_P (decl))
167 && !DECL_EXTERNAL (decl))
168 {
169 /* When reading LTO unit, we also read varpool, so do not
170 rebuild it. */
171 if (in_lto_p && !at_end)
172 ;
173 else if (TREE_CODE (decl) != FUNCTION_DECL)
174 varpool_finalize_decl (decl);
175 }
176
177 #ifdef ASM_FINISH_DECLARE_OBJECT
178 if (decl == last_assemble_variable_decl)
179 {
180 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
181 top_level, at_end);
182 }
183 #endif
184
185 timevar_pop (TV_VARCONST);
186 }
187 else if (TREE_CODE (decl) == TYPE_DECL
188 /* Like in rest_of_type_compilation, avoid confusing the debug
189 information machinery when there are errors. */
190 && !seen_error ())
191 {
192 timevar_push (TV_SYMOUT);
193 debug_hooks->type_decl (decl, !top_level);
194 timevar_pop (TV_SYMOUT);
195 }
196
197 /* Let cgraph know about the existence of variables. */
198 if (in_lto_p && !at_end)
199 ;
200 else if (TREE_CODE (decl) == VAR_DECL && !DECL_EXTERNAL (decl)
201 && TREE_STATIC (decl))
202 varpool_node_for_decl (decl);
203 }
204
205 /* Called after finishing a record, union or enumeral type. */
206
207 void
208 rest_of_type_compilation (tree type, int toplev)
209 {
210 /* Avoid confusing the debug information machinery when there are
211 errors. */
212 if (seen_error ())
213 return;
214
215 timevar_push (TV_SYMOUT);
216 debug_hooks->type_decl (TYPE_STUB_DECL (type), !toplev);
217 timevar_pop (TV_SYMOUT);
218 }
219
220 \f
221
222 void
223 finish_optimization_passes (void)
224 {
225 int i;
226 struct dump_file_info *dfi;
227 char *name;
228
229 timevar_push (TV_DUMP);
230 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
231 {
232 dump_start (pass_profile.pass.static_pass_number, NULL);
233 end_branch_prob ();
234 dump_finish (pass_profile.pass.static_pass_number);
235 }
236
237 if (optimize > 0)
238 {
239 dump_start (pass_profile.pass.static_pass_number, NULL);
240 print_combine_total_stats ();
241 dump_finish (pass_profile.pass.static_pass_number);
242 }
243
244 /* Do whatever is necessary to finish printing the graphs. */
245 for (i = TDI_end; (dfi = get_dump_file_info (i)) != NULL; ++i)
246 if (dump_initialized_p (i)
247 && (dfi->pflags & TDF_GRAPH) != 0
248 && (name = get_dump_file_name (i)) != NULL)
249 {
250 finish_graph_dump_file (name);
251 free (name);
252 }
253
254 timevar_pop (TV_DUMP);
255 }
256
257 static unsigned int
258 execute_all_early_local_passes (void)
259 {
260 /* Once this pass (and its sub-passes) are complete, all functions
261 will be in SSA form. Technically this state change is happening
262 a tad early, since the sub-passes have not yet run, but since
263 none of the sub-passes are IPA passes and do not create new
264 functions, this is ok. We're setting this value for the benefit
265 of IPA passes that follow. */
266 if (cgraph_state < CGRAPH_STATE_IPA_SSA)
267 cgraph_state = CGRAPH_STATE_IPA_SSA;
268 return 0;
269 }
270
271 /* Gate: execute, or not, all of the non-trivial optimizations. */
272
273 static bool
274 gate_all_early_local_passes (void)
275 {
276 /* Don't bother doing anything if the program has errors. */
277 return (!seen_error () && !in_lto_p);
278 }
279
280 struct simple_ipa_opt_pass pass_early_local_passes =
281 {
282 {
283 SIMPLE_IPA_PASS,
284 "early_local_cleanups", /* name */
285 OPTGROUP_NONE, /* optinfo_flags */
286 gate_all_early_local_passes, /* gate */
287 execute_all_early_local_passes, /* execute */
288 NULL, /* sub */
289 NULL, /* next */
290 0, /* static_pass_number */
291 TV_EARLY_LOCAL, /* tv_id */
292 0, /* properties_required */
293 0, /* properties_provided */
294 0, /* properties_destroyed */
295 0, /* todo_flags_start */
296 TODO_remove_functions /* todo_flags_finish */
297 }
298 };
299
300 /* Gate: execute, or not, all of the non-trivial optimizations. */
301
302 static bool
303 gate_all_early_optimizations (void)
304 {
305 return (optimize >= 1
306 /* Don't bother doing anything if the program has errors. */
307 && !seen_error ());
308 }
309
310 static struct gimple_opt_pass pass_all_early_optimizations =
311 {
312 {
313 GIMPLE_PASS,
314 "early_optimizations", /* name */
315 OPTGROUP_NONE, /* optinfo_flags */
316 gate_all_early_optimizations, /* gate */
317 NULL, /* execute */
318 NULL, /* sub */
319 NULL, /* next */
320 0, /* static_pass_number */
321 TV_NONE, /* tv_id */
322 0, /* properties_required */
323 0, /* properties_provided */
324 0, /* properties_destroyed */
325 0, /* todo_flags_start */
326 0 /* todo_flags_finish */
327 }
328 };
329
330 /* Gate: execute, or not, all of the non-trivial optimizations. */
331
332 static bool
333 gate_all_optimizations (void)
334 {
335 return optimize >= 1 && !optimize_debug;
336 }
337
338 static struct gimple_opt_pass pass_all_optimizations =
339 {
340 {
341 GIMPLE_PASS,
342 "*all_optimizations", /* name */
343 OPTGROUP_NONE, /* optinfo_flags */
344 gate_all_optimizations, /* gate */
345 NULL, /* execute */
346 NULL, /* sub */
347 NULL, /* next */
348 0, /* static_pass_number */
349 TV_OPTIMIZE, /* tv_id */
350 0, /* properties_required */
351 0, /* properties_provided */
352 0, /* properties_destroyed */
353 0, /* todo_flags_start */
354 0 /* todo_flags_finish */
355 }
356 };
357
358 /* Gate: execute, or not, all of the non-trivial optimizations. */
359
360 static bool
361 gate_all_optimizations_g (void)
362 {
363 return optimize >= 1 && optimize_debug;
364 }
365
366 static struct gimple_opt_pass pass_all_optimizations_g =
367 {
368 {
369 GIMPLE_PASS,
370 "*all_optimizations_g", /* name */
371 OPTGROUP_NONE, /* optinfo_flags */
372 gate_all_optimizations_g, /* gate */
373 NULL, /* execute */
374 NULL, /* sub */
375 NULL, /* next */
376 0, /* static_pass_number */
377 TV_OPTIMIZE, /* tv_id */
378 0, /* properties_required */
379 0, /* properties_provided */
380 0, /* properties_destroyed */
381 0, /* todo_flags_start */
382 0 /* todo_flags_finish */
383 }
384 };
385
386 static bool
387 gate_rest_of_compilation (void)
388 {
389 /* Early return if there were errors. We can run afoul of our
390 consistency checks, and there's not really much point in fixing them. */
391 return !(rtl_dump_and_exit || flag_syntax_only || seen_error ());
392 }
393
394 static struct rtl_opt_pass pass_rest_of_compilation =
395 {
396 {
397 RTL_PASS,
398 "*rest_of_compilation", /* name */
399 OPTGROUP_NONE, /* optinfo_flags */
400 gate_rest_of_compilation, /* gate */
401 NULL, /* execute */
402 NULL, /* sub */
403 NULL, /* next */
404 0, /* static_pass_number */
405 TV_REST_OF_COMPILATION, /* tv_id */
406 PROP_rtl, /* properties_required */
407 0, /* properties_provided */
408 0, /* properties_destroyed */
409 0, /* todo_flags_start */
410 0 /* todo_flags_finish */
411 }
412 };
413
414 static bool
415 gate_postreload (void)
416 {
417 return reload_completed;
418 }
419
420 static struct rtl_opt_pass pass_postreload =
421 {
422 {
423 RTL_PASS,
424 "*all-postreload", /* name */
425 OPTGROUP_NONE, /* optinfo_flags */
426 gate_postreload, /* gate */
427 NULL, /* execute */
428 NULL, /* sub */
429 NULL, /* next */
430 0, /* static_pass_number */
431 TV_POSTRELOAD, /* tv_id */
432 PROP_rtl, /* properties_required */
433 0, /* properties_provided */
434 0, /* properties_destroyed */
435 0, /* todo_flags_start */
436 TODO_verify_rtl_sharing /* todo_flags_finish */
437 }
438 };
439
440
441
442 /* The root of the compilation pass tree, once constructed. */
443 struct opt_pass *all_passes, *all_small_ipa_passes, *all_lowering_passes,
444 *all_regular_ipa_passes, *all_late_ipa_passes, *all_lto_gen_passes;
445
446 /* This is used by plugins, and should also be used in register_pass. */
447 #define DEF_PASS_LIST(LIST) &LIST,
448 struct opt_pass **gcc_pass_lists[] = { GCC_PASS_LISTS NULL };
449 #undef DEF_PASS_LIST
450
451 /* A map from static pass id to optimization pass. */
452 struct opt_pass **passes_by_id;
453 int passes_by_id_size;
454
455 /* Set the static pass number of pass PASS to ID and record that
456 in the mapping from static pass number to pass. */
457
458 static void
459 set_pass_for_id (int id, struct opt_pass *pass)
460 {
461 pass->static_pass_number = id;
462 if (passes_by_id_size <= id)
463 {
464 passes_by_id = XRESIZEVEC (struct opt_pass *, passes_by_id, id + 1);
465 memset (passes_by_id + passes_by_id_size, 0,
466 (id + 1 - passes_by_id_size) * sizeof (void *));
467 passes_by_id_size = id + 1;
468 }
469 passes_by_id[id] = pass;
470 }
471
472 /* Return the pass with the static pass number ID. */
473
474 struct opt_pass *
475 get_pass_for_id (int id)
476 {
477 if (id >= passes_by_id_size)
478 return NULL;
479 return passes_by_id[id];
480 }
481
482 /* Iterate over the pass tree allocating dump file numbers. We want
483 to do this depth first, and independent of whether the pass is
484 enabled or not. */
485
486 void
487 register_one_dump_file (struct opt_pass *pass)
488 {
489 char *dot_name, *flag_name, *glob_name;
490 const char *name, *full_name, *prefix;
491 char num[10];
492 int flags, id;
493 int optgroup_flags = OPTGROUP_NONE;
494
495 /* See below in next_pass_1. */
496 num[0] = '\0';
497 if (pass->static_pass_number != -1)
498 sprintf (num, "%d", ((int) pass->static_pass_number < 0
499 ? 1 : pass->static_pass_number));
500
501 /* The name is both used to identify the pass for the purposes of plugins,
502 and to specify dump file name and option.
503 The latter two might want something short which is not quite unique; for
504 that reason, we may have a disambiguating prefix, followed by a space
505 to mark the start of the following dump file name / option string. */
506 name = strchr (pass->name, ' ');
507 name = name ? name + 1 : pass->name;
508 dot_name = concat (".", name, num, NULL);
509 if (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS)
510 {
511 prefix = "ipa-";
512 flags = TDF_IPA;
513 optgroup_flags |= OPTGROUP_IPA;
514 }
515 else if (pass->type == GIMPLE_PASS)
516 {
517 prefix = "tree-";
518 flags = TDF_TREE;
519 }
520 else
521 {
522 prefix = "rtl-";
523 flags = TDF_RTL;
524 }
525
526 flag_name = concat (prefix, name, num, NULL);
527 glob_name = concat (prefix, name, NULL);
528 optgroup_flags |= pass->optinfo_flags;
529 id = dump_register (dot_name, flag_name, glob_name, flags, optgroup_flags);
530 set_pass_for_id (id, pass);
531 full_name = concat (prefix, pass->name, num, NULL);
532 register_pass_name (pass, full_name);
533 free (CONST_CAST (char *, full_name));
534 }
535
536 /* Recursive worker function for register_dump_files. */
537
538 static int
539 register_dump_files_1 (struct opt_pass *pass, int properties)
540 {
541 do
542 {
543 int new_properties = (properties | pass->properties_provided)
544 & ~pass->properties_destroyed;
545
546 if (pass->name && pass->name[0] != '*')
547 register_one_dump_file (pass);
548
549 if (pass->sub)
550 new_properties = register_dump_files_1 (pass->sub, new_properties);
551
552 /* If we have a gate, combine the properties that we could have with
553 and without the pass being examined. */
554 if (pass->gate)
555 properties &= new_properties;
556 else
557 properties = new_properties;
558
559 pass = pass->next;
560 }
561 while (pass);
562
563 return properties;
564 }
565
566 /* Register the dump files for the pipeline starting at PASS.
567 PROPERTIES reflects the properties that are guaranteed to be available at
568 the beginning of the pipeline. */
569
570 static void
571 register_dump_files (struct opt_pass *pass,int properties)
572 {
573 pass->properties_required |= properties;
574 register_dump_files_1 (pass, properties);
575 }
576
577 struct pass_registry
578 {
579 const char* unique_name;
580 struct opt_pass *pass;
581 };
582
583 /* Helper for pass_registry hash table. */
584
585 struct pass_registry_hasher : typed_noop_remove <pass_registry>
586 {
587 typedef pass_registry value_type;
588 typedef pass_registry compare_type;
589 static inline hashval_t hash (const value_type *);
590 static inline bool equal (const value_type *, const compare_type *);
591 };
592
593 /* Pass registry hash function. */
594
595 inline hashval_t
596 pass_registry_hasher::hash (const value_type *s)
597 {
598 return htab_hash_string (s->unique_name);
599 }
600
601 /* Hash equal function */
602
603 inline bool
604 pass_registry_hasher::equal (const value_type *s1, const compare_type *s2)
605 {
606 return !strcmp (s1->unique_name, s2->unique_name);
607 }
608
609 static hash_table <pass_registry_hasher> name_to_pass_map;
610
611 /* Register PASS with NAME. */
612
613 static void
614 register_pass_name (struct opt_pass *pass, const char *name)
615 {
616 struct pass_registry **slot;
617 struct pass_registry pr;
618
619 if (!name_to_pass_map.is_created ())
620 name_to_pass_map.create (256);
621
622 pr.unique_name = name;
623 slot = name_to_pass_map.find_slot (&pr, INSERT);
624 if (!*slot)
625 {
626 struct pass_registry *new_pr;
627
628 new_pr = XCNEW (struct pass_registry);
629 new_pr->unique_name = xstrdup (name);
630 new_pr->pass = pass;
631 *slot = new_pr;
632 }
633 else
634 return; /* Ignore plugin passes. */
635 }
636
637 /* Map from pass id to canonicalized pass name. */
638
639 typedef const char *char_ptr;
640 static vec<char_ptr> pass_tab = vNULL;
641
642 /* Callback function for traversing NAME_TO_PASS_MAP. */
643
644 int
645 passes_pass_traverse (pass_registry **p, void *data ATTRIBUTE_UNUSED)
646 {
647 struct opt_pass *pass = (*p)->pass;
648
649 gcc_assert (pass->static_pass_number > 0);
650 gcc_assert (pass_tab.exists ());
651
652 pass_tab[pass->static_pass_number] = (*p)->unique_name;
653
654 return 1;
655 }
656
657 /* The function traverses NAME_TO_PASS_MAP and creates a pass info
658 table for dumping purpose. */
659
660 static void
661 create_pass_tab (void)
662 {
663 if (!flag_dump_passes)
664 return;
665
666 pass_tab.safe_grow_cleared (passes_by_id_size + 1);
667 name_to_pass_map.traverse <void *, passes_pass_traverse> (NULL);
668 }
669
670 static bool override_gate_status (struct opt_pass *, tree, bool);
671
672 /* Dump the instantiated name for PASS. IS_ON indicates if PASS
673 is turned on or not. */
674
675 static void
676 dump_one_pass (struct opt_pass *pass, int pass_indent)
677 {
678 int indent = 3 * pass_indent;
679 const char *pn;
680 bool is_on, is_really_on;
681
682 is_on = (pass->gate == NULL) ? true : pass->gate();
683 is_really_on = override_gate_status (pass, current_function_decl, is_on);
684
685 if (pass->static_pass_number <= 0)
686 pn = pass->name;
687 else
688 pn = pass_tab[pass->static_pass_number];
689
690 fprintf (stderr, "%*s%-40s%*s:%s%s\n", indent, " ", pn,
691 (15 - indent < 0 ? 0 : 15 - indent), " ",
692 is_on ? " ON" : " OFF",
693 ((!is_on) == (!is_really_on) ? ""
694 : (is_really_on ? " (FORCED_ON)" : " (FORCED_OFF)")));
695 }
696
697 /* Dump pass list PASS with indentation INDENT. */
698
699 static void
700 dump_pass_list (struct opt_pass *pass, int indent)
701 {
702 do
703 {
704 dump_one_pass (pass, indent);
705 if (pass->sub)
706 dump_pass_list (pass->sub, indent + 1);
707 pass = pass->next;
708 }
709 while (pass);
710 }
711
712 /* Dump all optimization passes. */
713
714 void
715 dump_passes (void)
716 {
717 struct cgraph_node *n, *node = NULL;
718
719 create_pass_tab();
720
721 FOR_EACH_FUNCTION (n)
722 if (DECL_STRUCT_FUNCTION (n->symbol.decl))
723 {
724 node = n;
725 break;
726 }
727
728 if (!node)
729 return;
730
731 push_cfun (DECL_STRUCT_FUNCTION (node->symbol.decl));
732
733 dump_pass_list (all_lowering_passes, 1);
734 dump_pass_list (all_small_ipa_passes, 1);
735 dump_pass_list (all_regular_ipa_passes, 1);
736 dump_pass_list (all_lto_gen_passes, 1);
737 dump_pass_list (all_late_ipa_passes, 1);
738 dump_pass_list (all_passes, 1);
739
740 pop_cfun ();
741 }
742
743
744 /* Returns the pass with NAME. */
745
746 static struct opt_pass *
747 get_pass_by_name (const char *name)
748 {
749 struct pass_registry **slot, pr;
750
751 pr.unique_name = name;
752 slot = name_to_pass_map.find_slot (&pr, NO_INSERT);
753
754 if (!slot || !*slot)
755 return NULL;
756
757 return (*slot)->pass;
758 }
759
760
761 /* Range [start, last]. */
762
763 struct uid_range
764 {
765 unsigned int start;
766 unsigned int last;
767 const char *assem_name;
768 struct uid_range *next;
769 };
770
771 typedef struct uid_range *uid_range_p;
772
773
774 static vec<uid_range_p>
775 enabled_pass_uid_range_tab = vNULL;
776 static vec<uid_range_p>
777 disabled_pass_uid_range_tab = vNULL;
778
779
780 /* Parse option string for -fdisable- and -fenable-
781 The syntax of the options:
782
783 -fenable-<pass_name>
784 -fdisable-<pass_name>
785
786 -fenable-<pass_name>=s1:e1,s2:e2,...
787 -fdisable-<pass_name>=s1:e1,s2:e2,...
788 */
789
790 static void
791 enable_disable_pass (const char *arg, bool is_enable)
792 {
793 struct opt_pass *pass;
794 char *range_str, *phase_name;
795 char *argstr = xstrdup (arg);
796 vec<uid_range_p> *tab = 0;
797
798 range_str = strchr (argstr,'=');
799 if (range_str)
800 {
801 *range_str = '\0';
802 range_str++;
803 }
804
805 phase_name = argstr;
806 if (!*phase_name)
807 {
808 if (is_enable)
809 error ("unrecognized option -fenable");
810 else
811 error ("unrecognized option -fdisable");
812 free (argstr);
813 return;
814 }
815 pass = get_pass_by_name (phase_name);
816 if (!pass || pass->static_pass_number == -1)
817 {
818 if (is_enable)
819 error ("unknown pass %s specified in -fenable", phase_name);
820 else
821 error ("unknown pass %s specified in -fdisable", phase_name);
822 free (argstr);
823 return;
824 }
825
826 if (is_enable)
827 tab = &enabled_pass_uid_range_tab;
828 else
829 tab = &disabled_pass_uid_range_tab;
830
831 if ((unsigned) pass->static_pass_number >= tab->length ())
832 tab->safe_grow_cleared (pass->static_pass_number + 1);
833
834 if (!range_str)
835 {
836 uid_range_p slot;
837 uid_range_p new_range = XCNEW (struct uid_range);
838
839 new_range->start = 0;
840 new_range->last = (unsigned)-1;
841
842 slot = (*tab)[pass->static_pass_number];
843 new_range->next = slot;
844 (*tab)[pass->static_pass_number] = new_range;
845 if (is_enable)
846 inform (UNKNOWN_LOCATION, "enable pass %s for functions in the range "
847 "of [%u, %u]", phase_name, new_range->start, new_range->last);
848 else
849 inform (UNKNOWN_LOCATION, "disable pass %s for functions in the range "
850 "of [%u, %u]", phase_name, new_range->start, new_range->last);
851 }
852 else
853 {
854 char *next_range = NULL;
855 char *one_range = range_str;
856 char *end_val = NULL;
857
858 do
859 {
860 uid_range_p slot;
861 uid_range_p new_range;
862 char *invalid = NULL;
863 long start;
864 char *func_name = NULL;
865
866 next_range = strchr (one_range, ',');
867 if (next_range)
868 {
869 *next_range = '\0';
870 next_range++;
871 }
872
873 end_val = strchr (one_range, ':');
874 if (end_val)
875 {
876 *end_val = '\0';
877 end_val++;
878 }
879 start = strtol (one_range, &invalid, 10);
880 if (*invalid || start < 0)
881 {
882 if (end_val || (one_range[0] >= '0'
883 && one_range[0] <= '9'))
884 {
885 error ("Invalid range %s in option %s",
886 one_range,
887 is_enable ? "-fenable" : "-fdisable");
888 free (argstr);
889 return;
890 }
891 func_name = one_range;
892 }
893 if (!end_val)
894 {
895 new_range = XCNEW (struct uid_range);
896 if (!func_name)
897 {
898 new_range->start = (unsigned) start;
899 new_range->last = (unsigned) start;
900 }
901 else
902 {
903 new_range->start = (unsigned) -1;
904 new_range->last = (unsigned) -1;
905 new_range->assem_name = xstrdup (func_name);
906 }
907 }
908 else
909 {
910 long last = strtol (end_val, &invalid, 10);
911 if (*invalid || last < start)
912 {
913 error ("Invalid range %s in option %s",
914 end_val,
915 is_enable ? "-fenable" : "-fdisable");
916 free (argstr);
917 return;
918 }
919 new_range = XCNEW (struct uid_range);
920 new_range->start = (unsigned) start;
921 new_range->last = (unsigned) last;
922 }
923
924 slot = (*tab)[pass->static_pass_number];
925 new_range->next = slot;
926 (*tab)[pass->static_pass_number] = new_range;
927 if (is_enable)
928 {
929 if (new_range->assem_name)
930 inform (UNKNOWN_LOCATION,
931 "enable pass %s for function %s",
932 phase_name, new_range->assem_name);
933 else
934 inform (UNKNOWN_LOCATION,
935 "enable pass %s for functions in the range of [%u, %u]",
936 phase_name, new_range->start, new_range->last);
937 }
938 else
939 {
940 if (new_range->assem_name)
941 inform (UNKNOWN_LOCATION,
942 "disable pass %s for function %s",
943 phase_name, new_range->assem_name);
944 else
945 inform (UNKNOWN_LOCATION,
946 "disable pass %s for functions in the range of [%u, %u]",
947 phase_name, new_range->start, new_range->last);
948 }
949
950 one_range = next_range;
951 } while (next_range);
952 }
953
954 free (argstr);
955 }
956
957 /* Enable pass specified by ARG. */
958
959 void
960 enable_pass (const char *arg)
961 {
962 enable_disable_pass (arg, true);
963 }
964
965 /* Disable pass specified by ARG. */
966
967 void
968 disable_pass (const char *arg)
969 {
970 enable_disable_pass (arg, false);
971 }
972
973 /* Returns true if PASS is explicitly enabled/disabled for FUNC. */
974
975 static bool
976 is_pass_explicitly_enabled_or_disabled (struct opt_pass *pass,
977 tree func,
978 vec<uid_range_p> tab)
979 {
980 uid_range_p slot, range;
981 int cgraph_uid;
982 const char *aname = NULL;
983
984 if (!tab.exists ()
985 || (unsigned) pass->static_pass_number >= tab.length ()
986 || pass->static_pass_number == -1)
987 return false;
988
989 slot = tab[pass->static_pass_number];
990 if (!slot)
991 return false;
992
993 cgraph_uid = func ? cgraph_get_node (func)->uid : 0;
994 if (func && DECL_ASSEMBLER_NAME_SET_P (func))
995 aname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func));
996
997 range = slot;
998 while (range)
999 {
1000 if ((unsigned) cgraph_uid >= range->start
1001 && (unsigned) cgraph_uid <= range->last)
1002 return true;
1003 if (range->assem_name && aname
1004 && !strcmp (range->assem_name, aname))
1005 return true;
1006 range = range->next;
1007 }
1008
1009 return false;
1010 }
1011
1012 /* Look at the static_pass_number and duplicate the pass
1013 if it is already added to a list. */
1014
1015 static struct opt_pass *
1016 make_pass_instance (struct opt_pass *pass, bool track_duplicates)
1017 {
1018 /* A nonzero static_pass_number indicates that the
1019 pass is already in the list. */
1020 if (pass->static_pass_number)
1021 {
1022 struct opt_pass *new_pass;
1023
1024 if (pass->type == GIMPLE_PASS
1025 || pass->type == RTL_PASS
1026 || pass->type == SIMPLE_IPA_PASS)
1027 {
1028 new_pass = XNEW (struct opt_pass);
1029 memcpy (new_pass, pass, sizeof (struct opt_pass));
1030 }
1031 else if (pass->type == IPA_PASS)
1032 {
1033 new_pass = (struct opt_pass *)XNEW (struct ipa_opt_pass_d);
1034 memcpy (new_pass, pass, sizeof (struct ipa_opt_pass_d));
1035 }
1036 else
1037 gcc_unreachable ();
1038
1039 new_pass->next = NULL;
1040
1041 new_pass->todo_flags_start &= ~TODO_mark_first_instance;
1042
1043 /* Indicate to register_dump_files that this pass has duplicates,
1044 and so it should rename the dump file. The first instance will
1045 be -1, and be number of duplicates = -static_pass_number - 1.
1046 Subsequent instances will be > 0 and just the duplicate number. */
1047 if ((pass->name && pass->name[0] != '*') || track_duplicates)
1048 {
1049 pass->static_pass_number -= 1;
1050 new_pass->static_pass_number = -pass->static_pass_number;
1051 }
1052 return new_pass;
1053 }
1054 else
1055 {
1056 pass->todo_flags_start |= TODO_mark_first_instance;
1057 pass->static_pass_number = -1;
1058
1059 invoke_plugin_callbacks (PLUGIN_NEW_PASS, pass);
1060 }
1061 return pass;
1062 }
1063
1064 /* Add a pass to the pass list. Duplicate the pass if it's already
1065 in the list. */
1066
1067 static struct opt_pass **
1068 next_pass_1 (struct opt_pass **list, struct opt_pass *pass)
1069 {
1070 /* Every pass should have a name so that plugins can refer to them. */
1071 gcc_assert (pass->name != NULL);
1072
1073 *list = make_pass_instance (pass, false);
1074
1075 return &(*list)->next;
1076 }
1077
1078 /* List node for an inserted pass instance. We need to keep track of all
1079 the newly-added pass instances (with 'added_pass_nodes' defined below)
1080 so that we can register their dump files after pass-positioning is finished.
1081 Registering dumping files needs to be post-processed or the
1082 static_pass_number of the opt_pass object would be modified and mess up
1083 the dump file names of future pass instances to be added. */
1084
1085 struct pass_list_node
1086 {
1087 struct opt_pass *pass;
1088 struct pass_list_node *next;
1089 };
1090
1091 static struct pass_list_node *added_pass_nodes = NULL;
1092 static struct pass_list_node *prev_added_pass_node;
1093
1094 /* Insert the pass at the proper position. Return true if the pass
1095 is successfully added.
1096
1097 NEW_PASS_INFO - new pass to be inserted
1098 PASS_LIST - root of the pass list to insert the new pass to */
1099
1100 static bool
1101 position_pass (struct register_pass_info *new_pass_info,
1102 struct opt_pass **pass_list)
1103 {
1104 struct opt_pass *pass = *pass_list, *prev_pass = NULL;
1105 bool success = false;
1106
1107 for ( ; pass; prev_pass = pass, pass = pass->next)
1108 {
1109 /* Check if the current pass is of the same type as the new pass and
1110 matches the name and the instance number of the reference pass. */
1111 if (pass->type == new_pass_info->pass->type
1112 && pass->name
1113 && !strcmp (pass->name, new_pass_info->reference_pass_name)
1114 && ((new_pass_info->ref_pass_instance_number == 0)
1115 || (new_pass_info->ref_pass_instance_number ==
1116 pass->static_pass_number)
1117 || (new_pass_info->ref_pass_instance_number == 1
1118 && pass->todo_flags_start & TODO_mark_first_instance)))
1119 {
1120 struct opt_pass *new_pass;
1121 struct pass_list_node *new_pass_node;
1122
1123 new_pass = make_pass_instance (new_pass_info->pass, true);
1124
1125 /* Insert the new pass instance based on the positioning op. */
1126 switch (new_pass_info->pos_op)
1127 {
1128 case PASS_POS_INSERT_AFTER:
1129 new_pass->next = pass->next;
1130 pass->next = new_pass;
1131
1132 /* Skip newly inserted pass to avoid repeated
1133 insertions in the case where the new pass and the
1134 existing one have the same name. */
1135 pass = new_pass;
1136 break;
1137 case PASS_POS_INSERT_BEFORE:
1138 new_pass->next = pass;
1139 if (prev_pass)
1140 prev_pass->next = new_pass;
1141 else
1142 *pass_list = new_pass;
1143 break;
1144 case PASS_POS_REPLACE:
1145 new_pass->next = pass->next;
1146 if (prev_pass)
1147 prev_pass->next = new_pass;
1148 else
1149 *pass_list = new_pass;
1150 new_pass->sub = pass->sub;
1151 new_pass->tv_id = pass->tv_id;
1152 pass = new_pass;
1153 break;
1154 default:
1155 error ("invalid pass positioning operation");
1156 return false;
1157 }
1158
1159 /* Save the newly added pass (instance) in the added_pass_nodes
1160 list so that we can register its dump file later. Note that
1161 we cannot register the dump file now because doing so will modify
1162 the static_pass_number of the opt_pass object and therefore
1163 mess up the dump file name of future instances. */
1164 new_pass_node = XCNEW (struct pass_list_node);
1165 new_pass_node->pass = new_pass;
1166 if (!added_pass_nodes)
1167 added_pass_nodes = new_pass_node;
1168 else
1169 prev_added_pass_node->next = new_pass_node;
1170 prev_added_pass_node = new_pass_node;
1171
1172 success = true;
1173 }
1174
1175 if (pass->sub && position_pass (new_pass_info, &pass->sub))
1176 success = true;
1177 }
1178
1179 return success;
1180 }
1181
1182 /* Hooks a new pass into the pass lists.
1183
1184 PASS_INFO - pass information that specifies the opt_pass object,
1185 reference pass, instance number, and how to position
1186 the pass */
1187
1188 void
1189 register_pass (struct register_pass_info *pass_info)
1190 {
1191 bool all_instances, success;
1192
1193 /* The checks below could fail in buggy plugins. Existing GCC
1194 passes should never fail these checks, so we mention plugin in
1195 the messages. */
1196 if (!pass_info->pass)
1197 fatal_error ("plugin cannot register a missing pass");
1198
1199 if (!pass_info->pass->name)
1200 fatal_error ("plugin cannot register an unnamed pass");
1201
1202 if (!pass_info->reference_pass_name)
1203 fatal_error
1204 ("plugin cannot register pass %qs without reference pass name",
1205 pass_info->pass->name);
1206
1207 /* Try to insert the new pass to the pass lists. We need to check
1208 all five lists as the reference pass could be in one (or all) of
1209 them. */
1210 all_instances = pass_info->ref_pass_instance_number == 0;
1211 success = position_pass (pass_info, &all_lowering_passes);
1212 if (!success || all_instances)
1213 success |= position_pass (pass_info, &all_small_ipa_passes);
1214 if (!success || all_instances)
1215 success |= position_pass (pass_info, &all_regular_ipa_passes);
1216 if (!success || all_instances)
1217 success |= position_pass (pass_info, &all_lto_gen_passes);
1218 if (!success || all_instances)
1219 success |= position_pass (pass_info, &all_late_ipa_passes);
1220 if (!success || all_instances)
1221 success |= position_pass (pass_info, &all_passes);
1222 if (!success)
1223 fatal_error
1224 ("pass %qs not found but is referenced by new pass %qs",
1225 pass_info->reference_pass_name, pass_info->pass->name);
1226
1227 /* OK, we have successfully inserted the new pass. We need to register
1228 the dump files for the newly added pass and its duplicates (if any).
1229 Because the registration of plugin/backend passes happens after the
1230 command-line options are parsed, the options that specify single
1231 pass dumping (e.g. -fdump-tree-PASSNAME) cannot be used for new
1232 passes. Therefore we currently can only enable dumping of
1233 new passes when the 'dump-all' flags (e.g. -fdump-tree-all)
1234 are specified. While doing so, we also delete the pass_list_node
1235 objects created during pass positioning. */
1236 while (added_pass_nodes)
1237 {
1238 struct pass_list_node *next_node = added_pass_nodes->next;
1239 enum tree_dump_index tdi;
1240 register_one_dump_file (added_pass_nodes->pass);
1241 if (added_pass_nodes->pass->type == SIMPLE_IPA_PASS
1242 || added_pass_nodes->pass->type == IPA_PASS)
1243 tdi = TDI_ipa_all;
1244 else if (added_pass_nodes->pass->type == GIMPLE_PASS)
1245 tdi = TDI_tree_all;
1246 else
1247 tdi = TDI_rtl_all;
1248 /* Check if dump-all flag is specified. */
1249 if (get_dump_file_info (tdi)->pstate)
1250 get_dump_file_info (added_pass_nodes->pass->static_pass_number)
1251 ->pstate = get_dump_file_info (tdi)->pstate;
1252 XDELETE (added_pass_nodes);
1253 added_pass_nodes = next_node;
1254 }
1255 }
1256
1257 /* Construct the pass tree. The sequencing of passes is driven by
1258 the cgraph routines:
1259
1260 finalize_compilation_unit ()
1261 for each node N in the cgraph
1262 cgraph_analyze_function (N)
1263 cgraph_lower_function (N) -> all_lowering_passes
1264
1265 If we are optimizing, compile is then invoked:
1266
1267 compile ()
1268 ipa_passes () -> all_small_ipa_passes
1269 -> Analysis of all_regular_ipa_passes
1270 * possible LTO streaming at copmilation time *
1271 -> Execution of all_regular_ipa_passes
1272 * possible LTO streaming at link time *
1273 -> all_late_ipa_passes
1274 expand_all_functions ()
1275 for each node N in the cgraph
1276 expand_function (N) -> Transformation of all_regular_ipa_passes
1277 -> all_passes
1278 */
1279
1280 void
1281 init_optimization_passes (void)
1282 {
1283 struct opt_pass **p;
1284
1285 #define NEXT_PASS(PASS) (p = next_pass_1 (p, &((PASS).pass)))
1286
1287 /* All passes needed to lower the function into shape optimizers can
1288 operate on. These passes are always run first on the function, but
1289 backend might produce already lowered functions that are not processed
1290 by these passes. */
1291 p = &all_lowering_passes;
1292 NEXT_PASS (pass_warn_unused_result);
1293 NEXT_PASS (pass_diagnose_omp_blocks);
1294 NEXT_PASS (pass_diagnose_tm_blocks);
1295 NEXT_PASS (pass_mudflap_1);
1296 NEXT_PASS (pass_lower_omp);
1297 NEXT_PASS (pass_lower_cf);
1298 NEXT_PASS (pass_lower_tm);
1299 NEXT_PASS (pass_refactor_eh);
1300 NEXT_PASS (pass_lower_eh);
1301 NEXT_PASS (pass_build_cfg);
1302 NEXT_PASS (pass_warn_function_return);
1303 NEXT_PASS (pass_expand_omp);
1304 NEXT_PASS (pass_build_cgraph_edges);
1305 *p = NULL;
1306
1307 /* Interprocedural optimization passes. */
1308 p = &all_small_ipa_passes;
1309 NEXT_PASS (pass_ipa_free_lang_data);
1310 NEXT_PASS (pass_ipa_function_and_variable_visibility);
1311 NEXT_PASS (pass_early_local_passes);
1312 {
1313 struct opt_pass **p = &pass_early_local_passes.pass.sub;
1314 NEXT_PASS (pass_fixup_cfg);
1315 NEXT_PASS (pass_init_datastructures);
1316
1317 NEXT_PASS (pass_build_ssa);
1318 NEXT_PASS (pass_early_warn_uninitialized);
1319 NEXT_PASS (pass_rebuild_cgraph_edges);
1320 NEXT_PASS (pass_inline_parameters);
1321 NEXT_PASS (pass_early_inline);
1322 NEXT_PASS (pass_all_early_optimizations);
1323 {
1324 struct opt_pass **p = &pass_all_early_optimizations.pass.sub;
1325 NEXT_PASS (pass_remove_cgraph_callee_edges);
1326 NEXT_PASS (pass_rename_ssa_copies);
1327 NEXT_PASS (pass_ccp);
1328 /* After CCP we rewrite no longer addressed locals into SSA
1329 form if possible. */
1330 NEXT_PASS (pass_forwprop);
1331 /* pass_build_ealias is a dummy pass that ensures that we
1332 execute TODO_rebuild_alias at this point. */
1333 NEXT_PASS (pass_build_ealias);
1334 NEXT_PASS (pass_sra_early);
1335 NEXT_PASS (pass_fre);
1336 NEXT_PASS (pass_copy_prop);
1337 NEXT_PASS (pass_merge_phi);
1338 NEXT_PASS (pass_cd_dce);
1339 NEXT_PASS (pass_early_ipa_sra);
1340 NEXT_PASS (pass_tail_recursion);
1341 NEXT_PASS (pass_convert_switch);
1342 NEXT_PASS (pass_cleanup_eh);
1343 NEXT_PASS (pass_profile);
1344 NEXT_PASS (pass_local_pure_const);
1345 /* Split functions creates parts that are not run through
1346 early optimizations again. It is thus good idea to do this
1347 late. */
1348 NEXT_PASS (pass_split_functions);
1349 }
1350 NEXT_PASS (pass_release_ssa_names);
1351 NEXT_PASS (pass_rebuild_cgraph_edges);
1352 NEXT_PASS (pass_inline_parameters);
1353 }
1354 NEXT_PASS (pass_ipa_free_inline_summary);
1355 NEXT_PASS (pass_ipa_tree_profile);
1356 {
1357 struct opt_pass **p = &pass_ipa_tree_profile.pass.sub;
1358 NEXT_PASS (pass_feedback_split_functions);
1359 }
1360 NEXT_PASS (pass_ipa_increase_alignment);
1361 NEXT_PASS (pass_ipa_tm);
1362 NEXT_PASS (pass_ipa_lower_emutls);
1363 *p = NULL;
1364
1365 p = &all_regular_ipa_passes;
1366 NEXT_PASS (pass_ipa_whole_program_visibility);
1367 NEXT_PASS (pass_ipa_profile);
1368 NEXT_PASS (pass_ipa_cp);
1369 NEXT_PASS (pass_ipa_cdtor_merge);
1370 NEXT_PASS (pass_ipa_inline);
1371 NEXT_PASS (pass_ipa_pure_const);
1372 NEXT_PASS (pass_ipa_reference);
1373 *p = NULL;
1374
1375 p = &all_lto_gen_passes;
1376 NEXT_PASS (pass_ipa_lto_gimple_out);
1377 NEXT_PASS (pass_ipa_lto_finish_out); /* This must be the last LTO pass. */
1378 *p = NULL;
1379
1380 /* Simple IPA passes executed after the regular passes. In WHOPR mode the
1381 passes are executed after partitioning and thus see just parts of the
1382 compiled unit. */
1383 p = &all_late_ipa_passes;
1384 NEXT_PASS (pass_ipa_pta);
1385 *p = NULL;
1386
1387 /* These passes are run after IPA passes on every function that is being
1388 output to the assembler file. */
1389 p = &all_passes;
1390 NEXT_PASS (pass_fixup_cfg);
1391 NEXT_PASS (pass_lower_eh_dispatch);
1392 NEXT_PASS (pass_all_optimizations);
1393 {
1394 struct opt_pass **p = &pass_all_optimizations.pass.sub;
1395 NEXT_PASS (pass_remove_cgraph_callee_edges);
1396 /* Initial scalar cleanups before alias computation.
1397 They ensure memory accesses are not indirect wherever possible. */
1398 NEXT_PASS (pass_strip_predict_hints);
1399 NEXT_PASS (pass_rename_ssa_copies);
1400 NEXT_PASS (pass_copy_prop);
1401 NEXT_PASS (pass_complete_unrolli);
1402 NEXT_PASS (pass_ccp);
1403 /* After CCP we rewrite no longer addressed locals into SSA
1404 form if possible. */
1405 NEXT_PASS (pass_phiprop);
1406 NEXT_PASS (pass_forwprop);
1407 /* pass_build_alias is a dummy pass that ensures that we
1408 execute TODO_rebuild_alias at this point. */
1409 NEXT_PASS (pass_build_alias);
1410 NEXT_PASS (pass_return_slot);
1411 NEXT_PASS (pass_fre);
1412 NEXT_PASS (pass_copy_prop);
1413 NEXT_PASS (pass_merge_phi);
1414 NEXT_PASS (pass_vrp);
1415 NEXT_PASS (pass_dce);
1416 NEXT_PASS (pass_call_cdce);
1417 NEXT_PASS (pass_cselim);
1418 NEXT_PASS (pass_tree_ifcombine);
1419 NEXT_PASS (pass_phiopt);
1420 NEXT_PASS (pass_tail_recursion);
1421 NEXT_PASS (pass_ch);
1422 NEXT_PASS (pass_stdarg);
1423 NEXT_PASS (pass_lower_complex);
1424 NEXT_PASS (pass_sra);
1425 NEXT_PASS (pass_rename_ssa_copies);
1426 /* The dom pass will also resolve all __builtin_constant_p calls
1427 that are still there to 0. This has to be done after some
1428 propagations have already run, but before some more dead code
1429 is removed, and this place fits nicely. Remember this when
1430 trying to move or duplicate pass_dominator somewhere earlier. */
1431 NEXT_PASS (pass_dominator);
1432 /* The only const/copy propagation opportunities left after
1433 DOM should be due to degenerate PHI nodes. So rather than
1434 run the full propagators, run a specialized pass which
1435 only examines PHIs to discover const/copy propagation
1436 opportunities. */
1437 NEXT_PASS (pass_phi_only_cprop);
1438 NEXT_PASS (pass_dse);
1439 NEXT_PASS (pass_reassoc);
1440 NEXT_PASS (pass_dce);
1441 NEXT_PASS (pass_forwprop);
1442 NEXT_PASS (pass_phiopt);
1443 NEXT_PASS (pass_object_sizes);
1444 NEXT_PASS (pass_strlen);
1445 NEXT_PASS (pass_ccp);
1446 /* After CCP we rewrite no longer addressed locals into SSA
1447 form if possible. */
1448 NEXT_PASS (pass_copy_prop);
1449 NEXT_PASS (pass_cse_sincos);
1450 NEXT_PASS (pass_optimize_bswap);
1451 NEXT_PASS (pass_split_crit_edges);
1452 NEXT_PASS (pass_pre);
1453 NEXT_PASS (pass_sink_code);
1454 NEXT_PASS (pass_asan);
1455 NEXT_PASS (pass_tsan);
1456 NEXT_PASS (pass_tree_loop);
1457 {
1458 struct opt_pass **p = &pass_tree_loop.pass.sub;
1459 NEXT_PASS (pass_tree_loop_init);
1460 NEXT_PASS (pass_lim);
1461 NEXT_PASS (pass_copy_prop);
1462 NEXT_PASS (pass_dce_loop);
1463 NEXT_PASS (pass_tree_unswitch);
1464 NEXT_PASS (pass_scev_cprop);
1465 NEXT_PASS (pass_record_bounds);
1466 NEXT_PASS (pass_check_data_deps);
1467 NEXT_PASS (pass_loop_distribution);
1468 NEXT_PASS (pass_copy_prop);
1469 NEXT_PASS (pass_graphite);
1470 {
1471 struct opt_pass **p = &pass_graphite.pass.sub;
1472 NEXT_PASS (pass_graphite_transforms);
1473 NEXT_PASS (pass_lim);
1474 NEXT_PASS (pass_copy_prop);
1475 NEXT_PASS (pass_dce_loop);
1476 }
1477 NEXT_PASS (pass_iv_canon);
1478 NEXT_PASS (pass_parallelize_loops);
1479 NEXT_PASS (pass_if_conversion);
1480 NEXT_PASS (pass_vectorize);
1481 {
1482 struct opt_pass **p = &pass_vectorize.pass.sub;
1483 NEXT_PASS (pass_dce_loop);
1484 }
1485 NEXT_PASS (pass_predcom);
1486 NEXT_PASS (pass_complete_unroll);
1487 NEXT_PASS (pass_slp_vectorize);
1488 NEXT_PASS (pass_loop_prefetch);
1489 NEXT_PASS (pass_iv_optimize);
1490 NEXT_PASS (pass_lim);
1491 NEXT_PASS (pass_tree_loop_done);
1492 }
1493 NEXT_PASS (pass_lower_vector_ssa);
1494 NEXT_PASS (pass_cse_reciprocals);
1495 NEXT_PASS (pass_reassoc);
1496 NEXT_PASS (pass_strength_reduction);
1497 NEXT_PASS (pass_dominator);
1498 /* The only const/copy propagation opportunities left after
1499 DOM should be due to degenerate PHI nodes. So rather than
1500 run the full propagators, run a specialized pass which
1501 only examines PHIs to discover const/copy propagation
1502 opportunities. */
1503 NEXT_PASS (pass_phi_only_cprop);
1504 NEXT_PASS (pass_vrp);
1505 NEXT_PASS (pass_cd_dce);
1506 NEXT_PASS (pass_tracer);
1507
1508 /* FIXME: If DCE is not run before checking for uninitialized uses,
1509 we may get false warnings (e.g., testsuite/gcc.dg/uninit-5.c).
1510 However, this also causes us to misdiagnose cases that should be
1511 real warnings (e.g., testsuite/gcc.dg/pr18501.c).
1512
1513 To fix the false positives in uninit-5.c, we would have to
1514 account for the predicates protecting the set and the use of each
1515 variable. Using a representation like Gated Single Assignment
1516 may help. */
1517 NEXT_PASS (pass_late_warn_uninitialized);
1518 NEXT_PASS (pass_dse);
1519 NEXT_PASS (pass_forwprop);
1520 NEXT_PASS (pass_phiopt);
1521 NEXT_PASS (pass_fold_builtins);
1522 NEXT_PASS (pass_optimize_widening_mul);
1523 NEXT_PASS (pass_tail_calls);
1524 NEXT_PASS (pass_rename_ssa_copies);
1525 NEXT_PASS (pass_uncprop);
1526 NEXT_PASS (pass_local_pure_const);
1527 }
1528 NEXT_PASS (pass_all_optimizations_g);
1529 {
1530 struct opt_pass **p = &pass_all_optimizations_g.pass.sub;
1531 NEXT_PASS (pass_remove_cgraph_callee_edges);
1532 NEXT_PASS (pass_strip_predict_hints);
1533 /* Lower remaining pieces of GIMPLE. */
1534 NEXT_PASS (pass_lower_complex);
1535 NEXT_PASS (pass_lower_vector_ssa);
1536 /* Perform simple scalar cleanup which is constant/copy propagation. */
1537 NEXT_PASS (pass_ccp);
1538 NEXT_PASS (pass_object_sizes);
1539 /* Copy propagation also copy-propagates constants, this is necessary
1540 to forward object-size results properly. */
1541 NEXT_PASS (pass_copy_prop);
1542 NEXT_PASS (pass_asan);
1543 NEXT_PASS (pass_tsan);
1544 NEXT_PASS (pass_rename_ssa_copies);
1545 NEXT_PASS (pass_dce);
1546 /* Fold remaining builtins. */
1547 NEXT_PASS (pass_fold_builtins);
1548 /* ??? We do want some kind of loop invariant motion, but we possibly
1549 need to adjust LIM to be more friendly towards preserving accurate
1550 debug information here. */
1551 NEXT_PASS (pass_late_warn_uninitialized);
1552 NEXT_PASS (pass_uncprop);
1553 NEXT_PASS (pass_local_pure_const);
1554 }
1555 NEXT_PASS (pass_tm_init);
1556 {
1557 struct opt_pass **p = &pass_tm_init.pass.sub;
1558 NEXT_PASS (pass_tm_mark);
1559 NEXT_PASS (pass_tm_memopt);
1560 NEXT_PASS (pass_tm_edges);
1561 }
1562 NEXT_PASS (pass_lower_vector);
1563 NEXT_PASS (pass_lower_complex_O0);
1564 NEXT_PASS (pass_asan_O0);
1565 NEXT_PASS (pass_tsan_O0);
1566 NEXT_PASS (pass_cleanup_eh);
1567 NEXT_PASS (pass_lower_resx);
1568 NEXT_PASS (pass_nrv);
1569 NEXT_PASS (pass_mudflap_2);
1570 NEXT_PASS (pass_cleanup_cfg_post_optimizing);
1571 NEXT_PASS (pass_warn_function_noreturn);
1572
1573 NEXT_PASS (pass_expand);
1574
1575 NEXT_PASS (pass_rest_of_compilation);
1576 {
1577 struct opt_pass **p = &pass_rest_of_compilation.pass.sub;
1578 NEXT_PASS (pass_instantiate_virtual_regs);
1579 NEXT_PASS (pass_into_cfg_layout_mode);
1580 NEXT_PASS (pass_jump);
1581 NEXT_PASS (pass_lower_subreg);
1582 NEXT_PASS (pass_df_initialize_opt);
1583 NEXT_PASS (pass_cse);
1584 NEXT_PASS (pass_rtl_fwprop);
1585 NEXT_PASS (pass_rtl_cprop);
1586 NEXT_PASS (pass_rtl_pre);
1587 NEXT_PASS (pass_rtl_hoist);
1588 NEXT_PASS (pass_rtl_cprop);
1589 NEXT_PASS (pass_rtl_store_motion);
1590 NEXT_PASS (pass_cse_after_global_opts);
1591 NEXT_PASS (pass_rtl_ifcvt);
1592 NEXT_PASS (pass_reginfo_init);
1593 /* Perform loop optimizations. It might be better to do them a bit
1594 sooner, but we want the profile feedback to work more
1595 efficiently. */
1596 NEXT_PASS (pass_loop2);
1597 {
1598 struct opt_pass **p = &pass_loop2.pass.sub;
1599 NEXT_PASS (pass_rtl_loop_init);
1600 NEXT_PASS (pass_rtl_move_loop_invariants);
1601 NEXT_PASS (pass_rtl_unswitch);
1602 NEXT_PASS (pass_rtl_unroll_and_peel_loops);
1603 NEXT_PASS (pass_rtl_doloop);
1604 NEXT_PASS (pass_rtl_loop_done);
1605 *p = NULL;
1606 }
1607 NEXT_PASS (pass_web);
1608 NEXT_PASS (pass_rtl_cprop);
1609 NEXT_PASS (pass_cse2);
1610 NEXT_PASS (pass_rtl_dse1);
1611 NEXT_PASS (pass_rtl_fwprop_addr);
1612 NEXT_PASS (pass_inc_dec);
1613 NEXT_PASS (pass_initialize_regs);
1614 NEXT_PASS (pass_ud_rtl_dce);
1615 NEXT_PASS (pass_combine);
1616 NEXT_PASS (pass_if_after_combine);
1617 NEXT_PASS (pass_partition_blocks);
1618 NEXT_PASS (pass_regmove);
1619 NEXT_PASS (pass_outof_cfg_layout_mode);
1620 NEXT_PASS (pass_split_all_insns);
1621 NEXT_PASS (pass_lower_subreg2);
1622 NEXT_PASS (pass_df_initialize_no_opt);
1623 NEXT_PASS (pass_stack_ptr_mod);
1624 NEXT_PASS (pass_mode_switching);
1625 NEXT_PASS (pass_match_asm_constraints);
1626 NEXT_PASS (pass_sms);
1627 NEXT_PASS (pass_sched);
1628 NEXT_PASS (pass_ira);
1629 NEXT_PASS (pass_reload);
1630 NEXT_PASS (pass_postreload);
1631 {
1632 struct opt_pass **p = &pass_postreload.pass.sub;
1633 NEXT_PASS (pass_postreload_cse);
1634 NEXT_PASS (pass_gcse2);
1635 NEXT_PASS (pass_split_after_reload);
1636 NEXT_PASS (pass_ree);
1637 NEXT_PASS (pass_compare_elim_after_reload);
1638 NEXT_PASS (pass_branch_target_load_optimize1);
1639 NEXT_PASS (pass_thread_prologue_and_epilogue);
1640 NEXT_PASS (pass_rtl_dse2);
1641 NEXT_PASS (pass_stack_adjustments);
1642 NEXT_PASS (pass_jump2);
1643 NEXT_PASS (pass_peephole2);
1644 NEXT_PASS (pass_if_after_reload);
1645 NEXT_PASS (pass_regrename);
1646 NEXT_PASS (pass_cprop_hardreg);
1647 NEXT_PASS (pass_fast_rtl_dce);
1648 NEXT_PASS (pass_reorder_blocks);
1649 NEXT_PASS (pass_branch_target_load_optimize2);
1650 NEXT_PASS (pass_leaf_regs);
1651 NEXT_PASS (pass_split_before_sched2);
1652 NEXT_PASS (pass_sched2);
1653 NEXT_PASS (pass_stack_regs);
1654 {
1655 struct opt_pass **p = &pass_stack_regs.pass.sub;
1656 NEXT_PASS (pass_split_before_regstack);
1657 NEXT_PASS (pass_stack_regs_run);
1658 }
1659 NEXT_PASS (pass_compute_alignments);
1660 NEXT_PASS (pass_duplicate_computed_gotos);
1661 NEXT_PASS (pass_variable_tracking);
1662 NEXT_PASS (pass_free_cfg);
1663 NEXT_PASS (pass_machine_reorg);
1664 NEXT_PASS (pass_cleanup_barriers);
1665 NEXT_PASS (pass_delay_slots);
1666 NEXT_PASS (pass_split_for_shorten_branches);
1667 NEXT_PASS (pass_convert_to_eh_region_ranges);
1668 NEXT_PASS (pass_shorten_branches);
1669 NEXT_PASS (pass_set_nothrow_function_flags);
1670 NEXT_PASS (pass_dwarf2_frame);
1671 NEXT_PASS (pass_final);
1672 }
1673 NEXT_PASS (pass_df_finish);
1674 }
1675 NEXT_PASS (pass_clean_state);
1676 *p = NULL;
1677
1678 #undef NEXT_PASS
1679
1680 /* Register the passes with the tree dump code. */
1681 register_dump_files (all_lowering_passes, PROP_gimple_any);
1682 register_dump_files (all_small_ipa_passes,
1683 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
1684 | PROP_cfg);
1685 register_dump_files (all_regular_ipa_passes,
1686 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
1687 | PROP_cfg);
1688 register_dump_files (all_lto_gen_passes,
1689 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
1690 | PROP_cfg);
1691 register_dump_files (all_late_ipa_passes,
1692 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
1693 | PROP_cfg);
1694 register_dump_files (all_passes,
1695 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
1696 | PROP_cfg);
1697 }
1698
1699 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1700 function CALLBACK for every function in the call graph. Otherwise,
1701 call CALLBACK on the current function. */
1702
1703 static void
1704 do_per_function (void (*callback) (void *data), void *data)
1705 {
1706 if (current_function_decl)
1707 callback (data);
1708 else
1709 {
1710 struct cgraph_node *node;
1711 FOR_EACH_DEFINED_FUNCTION (node)
1712 if (gimple_has_body_p (node->symbol.decl)
1713 && (!node->clone_of || node->symbol.decl != node->clone_of->symbol.decl))
1714 {
1715 push_cfun (DECL_STRUCT_FUNCTION (node->symbol.decl));
1716 callback (data);
1717 if (!flag_wpa)
1718 {
1719 free_dominance_info (CDI_DOMINATORS);
1720 free_dominance_info (CDI_POST_DOMINATORS);
1721 }
1722 pop_cfun ();
1723 ggc_collect ();
1724 }
1725 }
1726 }
1727
1728 /* Because inlining might remove no-longer reachable nodes, we need to
1729 keep the array visible to garbage collector to avoid reading collected
1730 out nodes. */
1731 static int nnodes;
1732 static GTY ((length ("nnodes"))) cgraph_node_ptr *order;
1733
1734 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1735 function CALLBACK for every function in the call graph. Otherwise,
1736 call CALLBACK on the current function.
1737 This function is global so that plugins can use it. */
1738 void
1739 do_per_function_toporder (void (*callback) (void *data), void *data)
1740 {
1741 int i;
1742
1743 if (current_function_decl)
1744 callback (data);
1745 else
1746 {
1747 gcc_assert (!order);
1748 order = ggc_alloc_vec_cgraph_node_ptr (cgraph_n_nodes);
1749 nnodes = ipa_reverse_postorder (order);
1750 for (i = nnodes - 1; i >= 0; i--)
1751 order[i]->process = 1;
1752 for (i = nnodes - 1; i >= 0; i--)
1753 {
1754 struct cgraph_node *node = order[i];
1755
1756 /* Allow possibly removed nodes to be garbage collected. */
1757 order[i] = NULL;
1758 node->process = 0;
1759 if (cgraph_function_with_gimple_body_p (node))
1760 {
1761 push_cfun (DECL_STRUCT_FUNCTION (node->symbol.decl));
1762 callback (data);
1763 free_dominance_info (CDI_DOMINATORS);
1764 free_dominance_info (CDI_POST_DOMINATORS);
1765 pop_cfun ();
1766 ggc_collect ();
1767 }
1768 }
1769 }
1770 ggc_free (order);
1771 order = NULL;
1772 nnodes = 0;
1773 }
1774
1775 /* Helper function to perform function body dump. */
1776
1777 static void
1778 execute_function_dump (void *data ATTRIBUTE_UNUSED)
1779 {
1780 if (dump_file && current_function_decl)
1781 {
1782 if (cfun->curr_properties & PROP_trees)
1783 dump_function_to_file (current_function_decl, dump_file, dump_flags);
1784 else
1785 print_rtl_with_bb (dump_file, get_insns (), dump_flags);
1786
1787 /* Flush the file. If verification fails, we won't be able to
1788 close the file before aborting. */
1789 fflush (dump_file);
1790
1791 if ((cfun->curr_properties & PROP_cfg)
1792 && (dump_flags & TDF_GRAPH))
1793 print_graph_cfg (dump_file_name, cfun);
1794 }
1795 }
1796
1797 static struct profile_record *profile_record;
1798
1799 /* Do profile consistency book-keeping for the pass with static number INDEX.
1800 If SUBPASS is zero, we run _before_ the pass, and if SUBPASS is one, then
1801 we run _after_ the pass. RUN is true if the pass really runs, or FALSE
1802 if we are only book-keeping on passes that may have selectively disabled
1803 themselves on a given function. */
1804 static void
1805 check_profile_consistency (int index, int subpass, bool run)
1806 {
1807 if (index == -1)
1808 return;
1809 if (!profile_record)
1810 profile_record = XCNEWVEC (struct profile_record,
1811 passes_by_id_size);
1812 gcc_assert (index < passes_by_id_size && index >= 0);
1813 gcc_assert (subpass < 2);
1814 profile_record[index].run |= run;
1815 account_profile_record (&profile_record[index], subpass);
1816 }
1817
1818 /* Output profile consistency. */
1819
1820 void
1821 dump_profile_report (void)
1822 {
1823 int i, j;
1824 int last_freq_in = 0, last_count_in = 0, last_freq_out = 0, last_count_out = 0;
1825 gcov_type last_time = 0, last_size = 0;
1826 double rel_time_change, rel_size_change;
1827 int last_reported = 0;
1828
1829 if (!profile_record)
1830 return;
1831 fprintf (stderr, "\nProfile consistency report:\n\n");
1832 fprintf (stderr, "Pass name |mismatch in |mismated out|Overall\n");
1833 fprintf (stderr, " |freq count |freq count |size time\n");
1834
1835 for (i = 0; i < passes_by_id_size; i++)
1836 for (j = 0 ; j < 2; j++)
1837 if (profile_record[i].run)
1838 {
1839 if (last_time)
1840 rel_time_change = (profile_record[i].time[j]
1841 - (double)last_time) * 100 / (double)last_time;
1842 else
1843 rel_time_change = 0;
1844 if (last_size)
1845 rel_size_change = (profile_record[i].size[j]
1846 - (double)last_size) * 100 / (double)last_size;
1847 else
1848 rel_size_change = 0;
1849
1850 if (profile_record[i].num_mismatched_freq_in[j] != last_freq_in
1851 || profile_record[i].num_mismatched_freq_out[j] != last_freq_out
1852 || profile_record[i].num_mismatched_count_in[j] != last_count_in
1853 || profile_record[i].num_mismatched_count_out[j] != last_count_out
1854 || rel_time_change || rel_size_change)
1855 {
1856 last_reported = i;
1857 fprintf (stderr, "%-20s %s",
1858 passes_by_id [i]->name,
1859 j ? "(after TODO)" : " ");
1860 if (profile_record[i].num_mismatched_freq_in[j] != last_freq_in)
1861 fprintf (stderr, "| %+5i",
1862 profile_record[i].num_mismatched_freq_in[j]
1863 - last_freq_in);
1864 else
1865 fprintf (stderr, "| ");
1866 if (profile_record[i].num_mismatched_count_in[j] != last_count_in)
1867 fprintf (stderr, " %+5i",
1868 profile_record[i].num_mismatched_count_in[j]
1869 - last_count_in);
1870 else
1871 fprintf (stderr, " ");
1872 if (profile_record[i].num_mismatched_freq_out[j] != last_freq_out)
1873 fprintf (stderr, "| %+5i",
1874 profile_record[i].num_mismatched_freq_out[j]
1875 - last_freq_out);
1876 else
1877 fprintf (stderr, "| ");
1878 if (profile_record[i].num_mismatched_count_out[j] != last_count_out)
1879 fprintf (stderr, " %+5i",
1880 profile_record[i].num_mismatched_count_out[j]
1881 - last_count_out);
1882 else
1883 fprintf (stderr, " ");
1884
1885 /* Size/time units change across gimple and RTL. */
1886 if (i == pass_expand.pass.static_pass_number)
1887 fprintf (stderr, "|----------");
1888 else
1889 {
1890 if (rel_size_change)
1891 fprintf (stderr, "| %+8.4f%%", rel_size_change);
1892 else
1893 fprintf (stderr, "| ");
1894 if (rel_time_change)
1895 fprintf (stderr, " %+8.4f%%", rel_time_change);
1896 }
1897 fprintf (stderr, "\n");
1898 last_freq_in = profile_record[i].num_mismatched_freq_in[j];
1899 last_freq_out = profile_record[i].num_mismatched_freq_out[j];
1900 last_count_in = profile_record[i].num_mismatched_count_in[j];
1901 last_count_out = profile_record[i].num_mismatched_count_out[j];
1902 }
1903 else if (j && last_reported != i)
1904 {
1905 last_reported = i;
1906 fprintf (stderr, "%-20s ------------| | |\n",
1907 passes_by_id [i]->name);
1908 }
1909 last_time = profile_record[i].time[j];
1910 last_size = profile_record[i].size[j];
1911 }
1912 }
1913
1914 /* Perform all TODO actions that ought to be done on each function. */
1915
1916 static void
1917 execute_function_todo (void *data)
1918 {
1919 unsigned int flags = (size_t)data;
1920 flags &= ~cfun->last_verified;
1921 if (!flags)
1922 return;
1923
1924 /* Always cleanup the CFG before trying to update SSA. */
1925 if (flags & TODO_cleanup_cfg)
1926 {
1927 cleanup_tree_cfg ();
1928
1929 /* When cleanup_tree_cfg merges consecutive blocks, it may
1930 perform some simplistic propagation when removing single
1931 valued PHI nodes. This propagation may, in turn, cause the
1932 SSA form to become out-of-date (see PR 22037). So, even
1933 if the parent pass had not scheduled an SSA update, we may
1934 still need to do one. */
1935 if (!(flags & TODO_update_ssa_any) && need_ssa_update_p (cfun))
1936 flags |= TODO_update_ssa;
1937 }
1938
1939 if (flags & TODO_update_ssa_any)
1940 {
1941 unsigned update_flags = flags & TODO_update_ssa_any;
1942 update_ssa (update_flags);
1943 cfun->last_verified &= ~TODO_verify_ssa;
1944 }
1945
1946 if (flag_tree_pta && (flags & TODO_rebuild_alias))
1947 compute_may_aliases ();
1948
1949 if (optimize && (flags & TODO_update_address_taken))
1950 execute_update_addresses_taken ();
1951
1952 if (flags & TODO_remove_unused_locals)
1953 remove_unused_locals ();
1954
1955 if (flags & TODO_rebuild_frequencies)
1956 rebuild_frequencies ();
1957
1958 if (flags & TODO_rebuild_cgraph_edges)
1959 rebuild_cgraph_edges ();
1960
1961 /* If we've seen errors do not bother running any verifiers. */
1962 if (seen_error ())
1963 return;
1964
1965 #if defined ENABLE_CHECKING
1966 if (flags & TODO_verify_ssa
1967 || (current_loops && loops_state_satisfies_p (LOOP_CLOSED_SSA)))
1968 {
1969 verify_gimple_in_cfg (cfun);
1970 verify_ssa (true);
1971 }
1972 else if (flags & TODO_verify_stmts)
1973 verify_gimple_in_cfg (cfun);
1974 if (flags & TODO_verify_flow)
1975 verify_flow_info ();
1976 if (current_loops && loops_state_satisfies_p (LOOP_CLOSED_SSA))
1977 verify_loop_closed_ssa (false);
1978 if (flags & TODO_verify_rtl_sharing)
1979 verify_rtl_sharing ();
1980 #endif
1981
1982 cfun->last_verified = flags & TODO_verify_all;
1983 }
1984
1985 /* Perform all TODO actions. */
1986 static void
1987 execute_todo (unsigned int flags)
1988 {
1989 #if defined ENABLE_CHECKING
1990 if (cfun
1991 && need_ssa_update_p (cfun))
1992 gcc_assert (flags & TODO_update_ssa_any);
1993 #endif
1994
1995 timevar_push (TV_TODO);
1996
1997 /* Inform the pass whether it is the first time it is run. */
1998 first_pass_instance = (flags & TODO_mark_first_instance) != 0;
1999
2000 statistics_fini_pass ();
2001
2002 do_per_function (execute_function_todo, (void *)(size_t) flags);
2003
2004 /* Always remove functions just as before inlining: IPA passes might be
2005 interested to see bodies of extern inline functions that are not inlined
2006 to analyze side effects. The full removal is done just at the end
2007 of IPA pass queue. */
2008 if (flags & TODO_remove_functions)
2009 {
2010 gcc_assert (!cfun);
2011 symtab_remove_unreachable_nodes (true, dump_file);
2012 }
2013
2014 if ((flags & TODO_dump_symtab) && dump_file && !current_function_decl)
2015 {
2016 gcc_assert (!cfun);
2017 dump_symtab (dump_file);
2018 /* Flush the file. If verification fails, we won't be able to
2019 close the file before aborting. */
2020 fflush (dump_file);
2021 }
2022
2023 /* Now that the dumping has been done, we can get rid of the optional
2024 df problems. */
2025 if (flags & TODO_df_finish)
2026 df_finish_pass ((flags & TODO_df_verify) != 0);
2027
2028 timevar_pop (TV_TODO);
2029 }
2030
2031 /* Verify invariants that should hold between passes. This is a place
2032 to put simple sanity checks. */
2033
2034 static void
2035 verify_interpass_invariants (void)
2036 {
2037 gcc_checking_assert (!fold_deferring_overflow_warnings_p ());
2038 }
2039
2040 /* Clear the last verified flag. */
2041
2042 static void
2043 clear_last_verified (void *data ATTRIBUTE_UNUSED)
2044 {
2045 cfun->last_verified = 0;
2046 }
2047
2048 /* Helper function. Verify that the properties has been turn into the
2049 properties expected by the pass. */
2050
2051 #ifdef ENABLE_CHECKING
2052 static void
2053 verify_curr_properties (void *data)
2054 {
2055 unsigned int props = (size_t)data;
2056 gcc_assert ((cfun->curr_properties & props) == props);
2057 }
2058 #endif
2059
2060 /* Initialize pass dump file. */
2061 /* This is non-static so that the plugins can use it. */
2062
2063 bool
2064 pass_init_dump_file (struct opt_pass *pass)
2065 {
2066 /* If a dump file name is present, open it if enabled. */
2067 if (pass->static_pass_number != -1)
2068 {
2069 timevar_push (TV_DUMP);
2070 bool initializing_dump = !dump_initialized_p (pass->static_pass_number);
2071 dump_file_name = get_dump_file_name (pass->static_pass_number);
2072 dump_start (pass->static_pass_number, &dump_flags);
2073 if (dump_file && current_function_decl)
2074 dump_function_header (dump_file, current_function_decl, dump_flags);
2075 if (initializing_dump
2076 && dump_file && (dump_flags & TDF_GRAPH)
2077 && cfun && (cfun->curr_properties & PROP_cfg))
2078 clean_graph_dump_file (dump_file_name);
2079 timevar_pop (TV_DUMP);
2080 return initializing_dump;
2081 }
2082 else
2083 return false;
2084 }
2085
2086 /* Flush PASS dump file. */
2087 /* This is non-static so that plugins can use it. */
2088
2089 void
2090 pass_fini_dump_file (struct opt_pass *pass)
2091 {
2092 timevar_push (TV_DUMP);
2093
2094 /* Flush and close dump file. */
2095 if (dump_file_name)
2096 {
2097 free (CONST_CAST (char *, dump_file_name));
2098 dump_file_name = NULL;
2099 }
2100
2101 dump_finish (pass->static_pass_number);
2102 timevar_pop (TV_DUMP);
2103 }
2104
2105 /* After executing the pass, apply expected changes to the function
2106 properties. */
2107
2108 static void
2109 update_properties_after_pass (void *data)
2110 {
2111 struct opt_pass *pass = (struct opt_pass *) data;
2112 cfun->curr_properties = (cfun->curr_properties | pass->properties_provided)
2113 & ~pass->properties_destroyed;
2114 }
2115
2116 /* Execute summary generation for all of the passes in IPA_PASS. */
2117
2118 void
2119 execute_ipa_summary_passes (struct ipa_opt_pass_d *ipa_pass)
2120 {
2121 while (ipa_pass)
2122 {
2123 struct opt_pass *pass = &ipa_pass->pass;
2124
2125 /* Execute all of the IPA_PASSes in the list. */
2126 if (ipa_pass->pass.type == IPA_PASS
2127 && (!pass->gate || pass->gate ())
2128 && ipa_pass->generate_summary)
2129 {
2130 pass_init_dump_file (pass);
2131
2132 /* If a timevar is present, start it. */
2133 if (pass->tv_id)
2134 timevar_push (pass->tv_id);
2135
2136 ipa_pass->generate_summary ();
2137
2138 /* Stop timevar. */
2139 if (pass->tv_id)
2140 timevar_pop (pass->tv_id);
2141
2142 pass_fini_dump_file (pass);
2143 }
2144 ipa_pass = (struct ipa_opt_pass_d *)ipa_pass->pass.next;
2145 }
2146 }
2147
2148 /* Execute IPA_PASS function transform on NODE. */
2149
2150 static void
2151 execute_one_ipa_transform_pass (struct cgraph_node *node,
2152 struct ipa_opt_pass_d *ipa_pass)
2153 {
2154 struct opt_pass *pass = &ipa_pass->pass;
2155 unsigned int todo_after = 0;
2156
2157 current_pass = pass;
2158 if (!ipa_pass->function_transform)
2159 return;
2160
2161 /* Note that the folders should only create gimple expressions.
2162 This is a hack until the new folder is ready. */
2163 in_gimple_form = (cfun && (cfun->curr_properties & PROP_trees)) != 0;
2164
2165 pass_init_dump_file (pass);
2166
2167 /* Run pre-pass verification. */
2168 execute_todo (ipa_pass->function_transform_todo_flags_start);
2169
2170 /* If a timevar is present, start it. */
2171 if (pass->tv_id != TV_NONE)
2172 timevar_push (pass->tv_id);
2173
2174 /* Do it! */
2175 todo_after = ipa_pass->function_transform (node);
2176
2177 /* Stop timevar. */
2178 if (pass->tv_id != TV_NONE)
2179 timevar_pop (pass->tv_id);
2180
2181 if (profile_report && cfun && (cfun->curr_properties & PROP_cfg))
2182 check_profile_consistency (pass->static_pass_number, 0, true);
2183
2184 /* Run post-pass cleanup and verification. */
2185 execute_todo (todo_after);
2186 verify_interpass_invariants ();
2187 if (profile_report && cfun && (cfun->curr_properties & PROP_cfg))
2188 check_profile_consistency (pass->static_pass_number, 1, true);
2189
2190 do_per_function (execute_function_dump, NULL);
2191 pass_fini_dump_file (pass);
2192
2193 current_pass = NULL;
2194
2195 /* Signal this is a suitable GC collection point. */
2196 if (!(todo_after & TODO_do_not_ggc_collect))
2197 ggc_collect ();
2198 }
2199
2200 /* For the current function, execute all ipa transforms. */
2201
2202 void
2203 execute_all_ipa_transforms (void)
2204 {
2205 struct cgraph_node *node;
2206 if (!cfun)
2207 return;
2208 node = cgraph_get_node (current_function_decl);
2209
2210 if (node->ipa_transforms_to_apply.exists ())
2211 {
2212 unsigned int i;
2213
2214 for (i = 0; i < node->ipa_transforms_to_apply.length (); i++)
2215 execute_one_ipa_transform_pass (node, node->ipa_transforms_to_apply[i]);
2216 node->ipa_transforms_to_apply.release ();
2217 }
2218 }
2219
2220 /* Callback for do_per_function to apply all IPA transforms. */
2221
2222 static void
2223 apply_ipa_transforms (void *data)
2224 {
2225 struct cgraph_node *node = cgraph_get_node (current_function_decl);
2226 if (!node->global.inlined_to && node->ipa_transforms_to_apply.exists ())
2227 {
2228 *(bool *)data = true;
2229 execute_all_ipa_transforms();
2230 rebuild_cgraph_edges ();
2231 }
2232 }
2233
2234 /* Check if PASS is explicitly disabled or enabled and return
2235 the gate status. FUNC is the function to be processed, and
2236 GATE_STATUS is the gate status determined by pass manager by
2237 default. */
2238
2239 static bool
2240 override_gate_status (struct opt_pass *pass, tree func, bool gate_status)
2241 {
2242 bool explicitly_enabled = false;
2243 bool explicitly_disabled = false;
2244
2245 explicitly_enabled
2246 = is_pass_explicitly_enabled_or_disabled (pass, func,
2247 enabled_pass_uid_range_tab);
2248 explicitly_disabled
2249 = is_pass_explicitly_enabled_or_disabled (pass, func,
2250 disabled_pass_uid_range_tab);
2251
2252 gate_status = !explicitly_disabled && (gate_status || explicitly_enabled);
2253
2254 return gate_status;
2255 }
2256
2257
2258 /* Execute PASS. */
2259
2260 bool
2261 execute_one_pass (struct opt_pass *pass)
2262 {
2263 unsigned int todo_after = 0;
2264
2265 bool gate_status;
2266
2267 /* IPA passes are executed on whole program, so cfun should be NULL.
2268 Other passes need function context set. */
2269 if (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS)
2270 gcc_assert (!cfun && !current_function_decl);
2271 else
2272 gcc_assert (cfun && current_function_decl);
2273
2274 current_pass = pass;
2275
2276 /* Check whether gate check should be avoided.
2277 User controls the value of the gate through the parameter "gate_status". */
2278 gate_status = (pass->gate == NULL) ? true : pass->gate();
2279 gate_status = override_gate_status (pass, current_function_decl, gate_status);
2280
2281 /* Override gate with plugin. */
2282 invoke_plugin_callbacks (PLUGIN_OVERRIDE_GATE, &gate_status);
2283
2284 if (!gate_status)
2285 {
2286 /* Run so passes selectively disabling themselves on a given function
2287 are not miscounted. */
2288 if (profile_report && cfun && (cfun->curr_properties & PROP_cfg))
2289 {
2290 check_profile_consistency (pass->static_pass_number, 0, false);
2291 check_profile_consistency (pass->static_pass_number, 1, false);
2292 }
2293 current_pass = NULL;
2294 return false;
2295 }
2296
2297 /* Pass execution event trigger: useful to identify passes being
2298 executed. */
2299 invoke_plugin_callbacks (PLUGIN_PASS_EXECUTION, pass);
2300
2301 /* SIPLE IPA passes do not handle callgraphs with IPA transforms in it.
2302 Apply all trnasforms first. */
2303 if (pass->type == SIMPLE_IPA_PASS)
2304 {
2305 bool applied = false;
2306 do_per_function (apply_ipa_transforms, (void *)&applied);
2307 if (applied)
2308 symtab_remove_unreachable_nodes (true, dump_file);
2309 /* Restore current_pass. */
2310 current_pass = pass;
2311 }
2312
2313 if (!quiet_flag && !cfun)
2314 fprintf (stderr, " <%s>", pass->name ? pass->name : "");
2315
2316 /* Note that the folders should only create gimple expressions.
2317 This is a hack until the new folder is ready. */
2318 in_gimple_form = (cfun && (cfun->curr_properties & PROP_trees)) != 0;
2319
2320 pass_init_dump_file (pass);
2321
2322 /* Run pre-pass verification. */
2323 execute_todo (pass->todo_flags_start);
2324
2325 #ifdef ENABLE_CHECKING
2326 do_per_function (verify_curr_properties,
2327 (void *)(size_t)pass->properties_required);
2328 #endif
2329
2330 /* If a timevar is present, start it. */
2331 if (pass->tv_id != TV_NONE)
2332 timevar_push (pass->tv_id);
2333
2334 /* Do it! */
2335 if (pass->execute)
2336 {
2337 todo_after = pass->execute ();
2338 do_per_function (clear_last_verified, NULL);
2339 }
2340
2341 /* Stop timevar. */
2342 if (pass->tv_id != TV_NONE)
2343 timevar_pop (pass->tv_id);
2344
2345 do_per_function (update_properties_after_pass, pass);
2346
2347 if (profile_report && cfun && (cfun->curr_properties & PROP_cfg))
2348 check_profile_consistency (pass->static_pass_number, 0, true);
2349
2350 /* Run post-pass cleanup and verification. */
2351 execute_todo (todo_after | pass->todo_flags_finish);
2352 if (profile_report && cfun && (cfun->curr_properties & PROP_cfg))
2353 check_profile_consistency (pass->static_pass_number, 1, true);
2354
2355 verify_interpass_invariants ();
2356 do_per_function (execute_function_dump, NULL);
2357 if (pass->type == IPA_PASS)
2358 {
2359 struct cgraph_node *node;
2360 FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node)
2361 node->ipa_transforms_to_apply.safe_push ((struct ipa_opt_pass_d *)pass);
2362 }
2363
2364 if (!current_function_decl)
2365 cgraph_process_new_functions ();
2366
2367 pass_fini_dump_file (pass);
2368
2369 if (pass->type != SIMPLE_IPA_PASS && pass->type != IPA_PASS)
2370 gcc_assert (!(cfun->curr_properties & PROP_trees)
2371 || pass->type != RTL_PASS);
2372
2373 current_pass = NULL;
2374
2375 /* Signal this is a suitable GC collection point. */
2376 if (!((todo_after | pass->todo_flags_finish) & TODO_do_not_ggc_collect))
2377 ggc_collect ();
2378
2379 return true;
2380 }
2381
2382 void
2383 execute_pass_list (struct opt_pass *pass)
2384 {
2385 do
2386 {
2387 gcc_assert (pass->type == GIMPLE_PASS
2388 || pass->type == RTL_PASS);
2389 if (execute_one_pass (pass) && pass->sub)
2390 execute_pass_list (pass->sub);
2391 pass = pass->next;
2392 }
2393 while (pass);
2394 }
2395
2396 /* Same as execute_pass_list but assume that subpasses of IPA passes
2397 are local passes. If SET is not NULL, write out summaries of only
2398 those node in SET. */
2399
2400 static void
2401 ipa_write_summaries_2 (struct opt_pass *pass, struct lto_out_decl_state *state)
2402 {
2403 while (pass)
2404 {
2405 struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *)pass;
2406 gcc_assert (!current_function_decl);
2407 gcc_assert (!cfun);
2408 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
2409 if (pass->type == IPA_PASS
2410 && ipa_pass->write_summary
2411 && (!pass->gate || pass->gate ()))
2412 {
2413 /* If a timevar is present, start it. */
2414 if (pass->tv_id)
2415 timevar_push (pass->tv_id);
2416
2417 pass_init_dump_file (pass);
2418
2419 ipa_pass->write_summary ();
2420
2421 pass_fini_dump_file (pass);
2422
2423 /* If a timevar is present, start it. */
2424 if (pass->tv_id)
2425 timevar_pop (pass->tv_id);
2426 }
2427
2428 if (pass->sub && pass->sub->type != GIMPLE_PASS)
2429 ipa_write_summaries_2 (pass->sub, state);
2430
2431 pass = pass->next;
2432 }
2433 }
2434
2435 /* Helper function of ipa_write_summaries. Creates and destroys the
2436 decl state and calls ipa_write_summaries_2 for all passes that have
2437 summaries. SET is the set of nodes to be written. */
2438
2439 static void
2440 ipa_write_summaries_1 (lto_symtab_encoder_t encoder)
2441 {
2442 struct lto_out_decl_state *state = lto_new_out_decl_state ();
2443 state->symtab_node_encoder = encoder;
2444
2445 lto_push_out_decl_state (state);
2446
2447 gcc_assert (!flag_wpa);
2448 ipa_write_summaries_2 (all_regular_ipa_passes, state);
2449 ipa_write_summaries_2 (all_lto_gen_passes, state);
2450
2451 gcc_assert (lto_get_out_decl_state () == state);
2452 lto_pop_out_decl_state ();
2453 lto_delete_out_decl_state (state);
2454 }
2455
2456 /* Write out summaries for all the nodes in the callgraph. */
2457
2458 void
2459 ipa_write_summaries (void)
2460 {
2461 lto_symtab_encoder_t encoder;
2462 int i, order_pos;
2463 struct varpool_node *vnode;
2464 struct cgraph_node *node;
2465 struct cgraph_node **order;
2466
2467 if (!flag_generate_lto || seen_error ())
2468 return;
2469
2470 encoder = lto_symtab_encoder_new (false);
2471
2472 /* Create the callgraph set in the same order used in
2473 cgraph_expand_all_functions. This mostly facilitates debugging,
2474 since it causes the gimple file to be processed in the same order
2475 as the source code. */
2476 order = XCNEWVEC (struct cgraph_node *, cgraph_n_nodes);
2477 order_pos = ipa_reverse_postorder (order);
2478 gcc_assert (order_pos == cgraph_n_nodes);
2479
2480 for (i = order_pos - 1; i >= 0; i--)
2481 {
2482 struct cgraph_node *node = order[i];
2483
2484 if (cgraph_function_with_gimple_body_p (node))
2485 {
2486 /* When streaming out references to statements as part of some IPA
2487 pass summary, the statements need to have uids assigned and the
2488 following does that for all the IPA passes here. Naturally, this
2489 ordering then matches the one IPA-passes get in their stmt_fixup
2490 hooks. */
2491
2492 push_cfun (DECL_STRUCT_FUNCTION (node->symbol.decl));
2493 renumber_gimple_stmt_uids ();
2494 pop_cfun ();
2495 }
2496 if (node->symbol.definition)
2497 lto_set_symtab_encoder_in_partition (encoder, (symtab_node)node);
2498 }
2499
2500 FOR_EACH_DEFINED_FUNCTION (node)
2501 if (node->symbol.alias)
2502 lto_set_symtab_encoder_in_partition (encoder, (symtab_node)node);
2503 FOR_EACH_DEFINED_VARIABLE (vnode)
2504 lto_set_symtab_encoder_in_partition (encoder, (symtab_node)vnode);
2505
2506 ipa_write_summaries_1 (compute_ltrans_boundary (encoder));
2507
2508 free (order);
2509 }
2510
2511 /* Same as execute_pass_list but assume that subpasses of IPA passes
2512 are local passes. If SET is not NULL, write out optimization summaries of
2513 only those node in SET. */
2514
2515 static void
2516 ipa_write_optimization_summaries_1 (struct opt_pass *pass, struct lto_out_decl_state *state)
2517 {
2518 while (pass)
2519 {
2520 struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *)pass;
2521 gcc_assert (!current_function_decl);
2522 gcc_assert (!cfun);
2523 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
2524 if (pass->type == IPA_PASS
2525 && ipa_pass->write_optimization_summary
2526 && (!pass->gate || pass->gate ()))
2527 {
2528 /* If a timevar is present, start it. */
2529 if (pass->tv_id)
2530 timevar_push (pass->tv_id);
2531
2532 pass_init_dump_file (pass);
2533
2534 ipa_pass->write_optimization_summary ();
2535
2536 pass_fini_dump_file (pass);
2537
2538 /* If a timevar is present, start it. */
2539 if (pass->tv_id)
2540 timevar_pop (pass->tv_id);
2541 }
2542
2543 if (pass->sub && pass->sub->type != GIMPLE_PASS)
2544 ipa_write_optimization_summaries_1 (pass->sub, state);
2545
2546 pass = pass->next;
2547 }
2548 }
2549
2550 /* Write all the optimization summaries for the cgraph nodes in SET. If SET is
2551 NULL, write out all summaries of all nodes. */
2552
2553 void
2554 ipa_write_optimization_summaries (lto_symtab_encoder_t encoder)
2555 {
2556 struct lto_out_decl_state *state = lto_new_out_decl_state ();
2557 lto_symtab_encoder_iterator lsei;
2558 state->symtab_node_encoder = encoder;
2559
2560 lto_push_out_decl_state (state);
2561 for (lsei = lsei_start_function_in_partition (encoder);
2562 !lsei_end_p (lsei); lsei_next_function_in_partition (&lsei))
2563 {
2564 struct cgraph_node *node = lsei_cgraph_node (lsei);
2565 /* When streaming out references to statements as part of some IPA
2566 pass summary, the statements need to have uids assigned.
2567
2568 For functions newly born at WPA stage we need to initialize
2569 the uids here. */
2570 if (node->symbol.definition
2571 && gimple_has_body_p (node->symbol.decl))
2572 {
2573 push_cfun (DECL_STRUCT_FUNCTION (node->symbol.decl));
2574 renumber_gimple_stmt_uids ();
2575 pop_cfun ();
2576 }
2577 }
2578
2579 gcc_assert (flag_wpa);
2580 ipa_write_optimization_summaries_1 (all_regular_ipa_passes, state);
2581 ipa_write_optimization_summaries_1 (all_lto_gen_passes, state);
2582
2583 gcc_assert (lto_get_out_decl_state () == state);
2584 lto_pop_out_decl_state ();
2585 lto_delete_out_decl_state (state);
2586 }
2587
2588 /* Same as execute_pass_list but assume that subpasses of IPA passes
2589 are local passes. */
2590
2591 static void
2592 ipa_read_summaries_1 (struct opt_pass *pass)
2593 {
2594 while (pass)
2595 {
2596 struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *) pass;
2597
2598 gcc_assert (!current_function_decl);
2599 gcc_assert (!cfun);
2600 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
2601
2602 if (pass->gate == NULL || pass->gate ())
2603 {
2604 if (pass->type == IPA_PASS && ipa_pass->read_summary)
2605 {
2606 /* If a timevar is present, start it. */
2607 if (pass->tv_id)
2608 timevar_push (pass->tv_id);
2609
2610 pass_init_dump_file (pass);
2611
2612 ipa_pass->read_summary ();
2613
2614 pass_fini_dump_file (pass);
2615
2616 /* Stop timevar. */
2617 if (pass->tv_id)
2618 timevar_pop (pass->tv_id);
2619 }
2620
2621 if (pass->sub && pass->sub->type != GIMPLE_PASS)
2622 ipa_read_summaries_1 (pass->sub);
2623 }
2624 pass = pass->next;
2625 }
2626 }
2627
2628
2629 /* Read all the summaries for all_regular_ipa_passes and all_lto_gen_passes. */
2630
2631 void
2632 ipa_read_summaries (void)
2633 {
2634 ipa_read_summaries_1 (all_regular_ipa_passes);
2635 ipa_read_summaries_1 (all_lto_gen_passes);
2636 }
2637
2638 /* Same as execute_pass_list but assume that subpasses of IPA passes
2639 are local passes. */
2640
2641 static void
2642 ipa_read_optimization_summaries_1 (struct opt_pass *pass)
2643 {
2644 while (pass)
2645 {
2646 struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *) pass;
2647
2648 gcc_assert (!current_function_decl);
2649 gcc_assert (!cfun);
2650 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
2651
2652 if (pass->gate == NULL || pass->gate ())
2653 {
2654 if (pass->type == IPA_PASS && ipa_pass->read_optimization_summary)
2655 {
2656 /* If a timevar is present, start it. */
2657 if (pass->tv_id)
2658 timevar_push (pass->tv_id);
2659
2660 pass_init_dump_file (pass);
2661
2662 ipa_pass->read_optimization_summary ();
2663
2664 pass_fini_dump_file (pass);
2665
2666 /* Stop timevar. */
2667 if (pass->tv_id)
2668 timevar_pop (pass->tv_id);
2669 }
2670
2671 if (pass->sub && pass->sub->type != GIMPLE_PASS)
2672 ipa_read_optimization_summaries_1 (pass->sub);
2673 }
2674 pass = pass->next;
2675 }
2676 }
2677
2678 /* Read all the summaries for all_regular_ipa_passes and all_lto_gen_passes. */
2679
2680 void
2681 ipa_read_optimization_summaries (void)
2682 {
2683 ipa_read_optimization_summaries_1 (all_regular_ipa_passes);
2684 ipa_read_optimization_summaries_1 (all_lto_gen_passes);
2685 }
2686
2687 /* Same as execute_pass_list but assume that subpasses of IPA passes
2688 are local passes. */
2689 void
2690 execute_ipa_pass_list (struct opt_pass *pass)
2691 {
2692 do
2693 {
2694 gcc_assert (!current_function_decl);
2695 gcc_assert (!cfun);
2696 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
2697 if (execute_one_pass (pass) && pass->sub)
2698 {
2699 if (pass->sub->type == GIMPLE_PASS)
2700 {
2701 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_START, NULL);
2702 do_per_function_toporder ((void (*)(void *))execute_pass_list,
2703 pass->sub);
2704 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_END, NULL);
2705 }
2706 else if (pass->sub->type == SIMPLE_IPA_PASS
2707 || pass->sub->type == IPA_PASS)
2708 execute_ipa_pass_list (pass->sub);
2709 else
2710 gcc_unreachable ();
2711 }
2712 gcc_assert (!current_function_decl);
2713 cgraph_process_new_functions ();
2714 pass = pass->next;
2715 }
2716 while (pass);
2717 }
2718
2719 /* Execute stmt fixup hooks of all passes in PASS for NODE and STMTS. */
2720
2721 static void
2722 execute_ipa_stmt_fixups (struct opt_pass *pass,
2723 struct cgraph_node *node, gimple *stmts)
2724 {
2725 while (pass)
2726 {
2727 /* Execute all of the IPA_PASSes in the list. */
2728 if (pass->type == IPA_PASS
2729 && (!pass->gate || pass->gate ()))
2730 {
2731 struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *) pass;
2732
2733 if (ipa_pass->stmt_fixup)
2734 {
2735 pass_init_dump_file (pass);
2736 /* If a timevar is present, start it. */
2737 if (pass->tv_id)
2738 timevar_push (pass->tv_id);
2739
2740 ipa_pass->stmt_fixup (node, stmts);
2741
2742 /* Stop timevar. */
2743 if (pass->tv_id)
2744 timevar_pop (pass->tv_id);
2745 pass_fini_dump_file (pass);
2746 }
2747 if (pass->sub)
2748 execute_ipa_stmt_fixups (pass->sub, node, stmts);
2749 }
2750 pass = pass->next;
2751 }
2752 }
2753
2754 /* Execute stmt fixup hooks of all IPA passes for NODE and STMTS. */
2755
2756 void
2757 execute_all_ipa_stmt_fixups (struct cgraph_node *node, gimple *stmts)
2758 {
2759 execute_ipa_stmt_fixups (all_regular_ipa_passes, node, stmts);
2760 }
2761
2762
2763 extern void debug_properties (unsigned int);
2764 extern void dump_properties (FILE *, unsigned int);
2765
2766 DEBUG_FUNCTION void
2767 dump_properties (FILE *dump, unsigned int props)
2768 {
2769 fprintf (dump, "Properties:\n");
2770 if (props & PROP_gimple_any)
2771 fprintf (dump, "PROP_gimple_any\n");
2772 if (props & PROP_gimple_lcf)
2773 fprintf (dump, "PROP_gimple_lcf\n");
2774 if (props & PROP_gimple_leh)
2775 fprintf (dump, "PROP_gimple_leh\n");
2776 if (props & PROP_cfg)
2777 fprintf (dump, "PROP_cfg\n");
2778 if (props & PROP_ssa)
2779 fprintf (dump, "PROP_ssa\n");
2780 if (props & PROP_no_crit_edges)
2781 fprintf (dump, "PROP_no_crit_edges\n");
2782 if (props & PROP_rtl)
2783 fprintf (dump, "PROP_rtl\n");
2784 if (props & PROP_gimple_lomp)
2785 fprintf (dump, "PROP_gimple_lomp\n");
2786 if (props & PROP_gimple_lcx)
2787 fprintf (dump, "PROP_gimple_lcx\n");
2788 if (props & PROP_gimple_lvec)
2789 fprintf (dump, "PROP_gimple_lvec\n");
2790 if (props & PROP_cfglayout)
2791 fprintf (dump, "PROP_cfglayout\n");
2792 }
2793
2794 DEBUG_FUNCTION void
2795 debug_properties (unsigned int props)
2796 {
2797 dump_properties (stderr, props);
2798 }
2799
2800 /* Called by local passes to see if function is called by already processed nodes.
2801 Because we process nodes in topological order, this means that function is
2802 in recursive cycle or we introduced new direct calls. */
2803 bool
2804 function_called_by_processed_nodes_p (void)
2805 {
2806 struct cgraph_edge *e;
2807 for (e = cgraph_get_node (current_function_decl)->callers;
2808 e;
2809 e = e->next_caller)
2810 {
2811 if (e->caller->symbol.decl == current_function_decl)
2812 continue;
2813 if (!cgraph_function_with_gimple_body_p (e->caller))
2814 continue;
2815 if (TREE_ASM_WRITTEN (e->caller->symbol.decl))
2816 continue;
2817 if (!e->caller->process && !e->caller->global.inlined_to)
2818 break;
2819 }
2820 if (dump_file && e)
2821 {
2822 fprintf (dump_file, "Already processed call to:\n");
2823 dump_cgraph_node (dump_file, e->caller);
2824 }
2825 return e != NULL;
2826 }
2827
2828 #include "gt-passes.h"