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