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