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