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