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