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