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