]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/passes.c
Merge from transactional-memory branch.
[thirdparty/gcc.git] / gcc / passes.c
CommitLineData
f6db1481
RH
1/* Top level of GCC compilers (cc1, cc1plus, etc.)
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
8b57bfeb
JJ
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
4 2011 Free Software Foundation, Inc.
f6db1481
RH
5
6This file is part of GCC.
7
8GCC is free software; you can redistribute it and/or modify it under
9the terms of the GNU General Public License as published by the Free
9dcd6f09 10Software Foundation; either version 3, or (at your option) any later
f6db1481
RH
11version.
12
13GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14WARRANTY; without even the implied warranty of MERCHANTABILITY or
15FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16for more details.
17
18You should have received a copy of the GNU General Public License
9dcd6f09
NC
19along with GCC; see the file COPYING3. If not see
20<http://www.gnu.org/licenses/>. */
f6db1481
RH
21
22/* This is the top level of cc1/c++.
23 It parses command args, opens files, invokes the various passes
24 in the proper order, and counts the time used by each.
25 Error messages and low-level interface to malloc also handled here. */
26
27#include "config.h"
f6db1481
RH
28#include "system.h"
29#include "coretypes.h"
30#include "tm.h"
f6db1481
RH
31#include "line-map.h"
32#include "input.h"
33#include "tree.h"
34#include "rtl.h"
35#include "tm_p.h"
36#include "flags.h"
37#include "insn-attr.h"
38#include "insn-config.h"
39#include "insn-flags.h"
40#include "hard-reg-set.h"
41#include "recog.h"
42#include "output.h"
43#include "except.h"
44#include "function.h"
45#include "toplev.h"
46#include "expr.h"
47#include "basic-block.h"
48#include "intl.h"
49#include "ggc.h"
50#include "graph.h"
f6db1481
RH
51#include "regs.h"
52#include "timevar.h"
1da2ed5f 53#include "diagnostic-core.h"
f6db1481
RH
54#include "params.h"
55#include "reload.h"
56#include "dwarf2asm.h"
57#include "integrate.h"
f6db1481
RH
58#include "debug.h"
59#include "target.h"
60#include "langhooks.h"
61#include "cfglayout.h"
62#include "cfgloop.h"
63#include "hosthooks.h"
64#include "cgraph.h"
65#include "opts.h"
66#include "coverage.h"
67#include "value-prof.h"
ef330312
PB
68#include "tree-inline.h"
69#include "tree-flow.h"
2f8e398b 70#include "tree-pass.h"
9f8628ba 71#include "tree-dump.h"
6fb5fa3c 72#include "df.h"
45a80bb9 73#include "predict.h"
d7f09764 74#include "lto-streamer.h"
090fa0ab 75#include "plugin.h"
af8bca3c 76#include "ipa-utils.h"
ea6cf778 77#include "tree-pretty-print.h"
f6db1481
RH
78
79#if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
80#include "dwarf2out.h"
81#endif
82
97b0ade3 83#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
f6db1481
RH
84#include "dbxout.h"
85#endif
86
87#ifdef SDB_DEBUGGING_INFO
88#include "sdbout.h"
89#endif
90
91#ifdef XCOFF_DEBUGGING_INFO
92#include "xcoffout.h" /* Needed for external data
93 declarations for e.g. AIX 4.x. */
94#endif
95
6fb5fa3c 96/* This is used for debugging. It allows the current pass to printed
090fa0ab
GF
97 from anywhere in compilation.
98 The variable current_pass is also used for statistics and plugins. */
8ddbbcae 99struct opt_pass *current_pass;
6fb5fa3c 100
226c52aa
XDL
101static void register_pass_name (struct opt_pass *, const char *);
102
6fb5fa3c
DB
103/* Call from anywhere to find out what pass this is. Useful for
104 printing out debugging information deep inside an service
105 routine. */
106void
107print_current_pass (FILE *file)
108{
109 if (current_pass)
b8698a0f 110 fprintf (file, "current pass = %s (%d)\n",
6fb5fa3c
DB
111 current_pass->name, current_pass->static_pass_number);
112 else
113 fprintf (file, "no current pass.\n");
114}
115
116
117/* Call from the debugger to get the current pass name. */
24e47c76 118DEBUG_FUNCTION void
6fb5fa3c
DB
119debug_pass (void)
120{
121 print_current_pass (stderr);
b8698a0f 122}
6fb5fa3c
DB
123
124
125
ef330312
PB
126/* Global variables used to communicate with passes. */
127int dump_flags;
128bool in_gimple_form;
b02b9b53 129bool first_pass_instance;
f6db1481 130
f6db1481
RH
131
132/* This is called from various places for FUNCTION_DECL, VAR_DECL,
133 and TYPE_DECL nodes.
134
135 This does nothing for local (non-static) variables, unless the
0e6df31e
GK
136 variable is a register variable with DECL_ASSEMBLER_NAME set. In
137 that case, or if the variable is not an automatic, it sets up the
138 RTL and outputs any assembler code (label definition, storage
139 allocation and initialization).
f6db1481 140
0e6df31e 141 DECL is the declaration. TOP_LEVEL is nonzero
f6db1481
RH
142 if this declaration is not within a function. */
143
144void
145rest_of_decl_compilation (tree decl,
f6db1481
RH
146 int top_level,
147 int at_end)
148{
149 /* We deferred calling assemble_alias so that we could collect
150 other attributes such as visibility. Emit the alias now. */
6e701822 151 if (!in_lto_p)
f6db1481
RH
152 {
153 tree alias;
154 alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
155 if (alias)
156 {
157 alias = TREE_VALUE (TREE_VALUE (alias));
158 alias = get_identifier (TREE_STRING_POINTER (alias));
159 assemble_alias (decl, alias);
160 }
161 }
162
0e6df31e
GK
163 /* Can't defer this, because it needs to happen before any
164 later function definitions are processed. */
820cc88f 165 if (DECL_ASSEMBLER_NAME_SET_P (decl) && DECL_REGISTER (decl))
0e6df31e
GK
166 make_decl_rtl (decl);
167
f6db1481
RH
168 /* Forward declarations for nested functions are not "external",
169 but we need to treat them as if they were. */
170 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
171 || TREE_CODE (decl) == FUNCTION_DECL)
172 {
173 timevar_push (TV_VARCONST);
174
f6db1481
RH
175 /* Don't output anything when a tentative file-scope definition
176 is seen. But at end of compilation, do output code for them.
177
7e8b322a 178 We do output all variables and rely on
f6db1481
RH
179 callgraph code to defer them except for forward declarations
180 (see gcc.c-torture/compile/920624-1.c) */
181 if ((at_end
182 || !DECL_DEFER_OUTPUT (decl)
cd9c7bd2 183 || DECL_INITIAL (decl))
f6db1481
RH
184 && !DECL_EXTERNAL (decl))
185 {
2942c502
JH
186 /* When reading LTO unit, we also read varpool, so do not
187 rebuild it. */
188 if (in_lto_p && !at_end)
189 ;
190 else if (TREE_CODE (decl) != FUNCTION_DECL)
8a4a83ed 191 varpool_finalize_decl (decl);
f6db1481
RH
192 }
193
194#ifdef ASM_FINISH_DECLARE_OBJECT
195 if (decl == last_assemble_variable_decl)
196 {
197 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
198 top_level, at_end);
199 }
200#endif
201
202 timevar_pop (TV_VARCONST);
203 }
ef11c839
SB
204 else if (TREE_CODE (decl) == TYPE_DECL
205 /* Like in rest_of_type_compilation, avoid confusing the debug
206 information machinery when there are errors. */
1da2ed5f 207 && !seen_error ())
f6db1481
RH
208 {
209 timevar_push (TV_SYMOUT);
210 debug_hooks->type_decl (decl, !top_level);
211 timevar_pop (TV_SYMOUT);
212 }
e4d5432a 213
aabcd309 214 /* Let cgraph know about the existence of variables. */
2942c502
JH
215 if (in_lto_p && !at_end)
216 ;
a482b1f5
JH
217 else if (TREE_CODE (decl) == VAR_DECL && !DECL_EXTERNAL (decl)
218 && TREE_STATIC (decl))
8a4a83ed 219 varpool_node (decl);
f6db1481
RH
220}
221
222/* Called after finishing a record, union or enumeral type. */
223
224void
225rest_of_type_compilation (tree type, int toplev)
226{
227 /* Avoid confusing the debug information machinery when there are
228 errors. */
1da2ed5f 229 if (seen_error ())
f6db1481
RH
230 return;
231
232 timevar_push (TV_SYMOUT);
233 debug_hooks->type_decl (TYPE_STUB_DECL (type), !toplev);
234 timevar_pop (TV_SYMOUT);
235}
236
ef330312 237\f
f6db1481 238
ef330312
PB
239void
240finish_optimization_passes (void)
f6db1481 241{
09639a83 242 int i;
ef330312
PB
243 struct dump_file_info *dfi;
244 char *name;
f6db1481 245
ef330312
PB
246 timevar_push (TV_DUMP);
247 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
f6db1481 248 {
8ddbbcae 249 dump_file = dump_begin (pass_profile.pass.static_pass_number, NULL);
ef330312
PB
250 end_branch_prob ();
251 if (dump_file)
8ddbbcae 252 dump_end (pass_profile.pass.static_pass_number, dump_file);
f6db1481 253 }
f6db1481 254
ef330312 255 if (optimize > 0)
f6db1481 256 {
8ddbbcae 257 dump_file = dump_begin (pass_combine.pass.static_pass_number, NULL);
ef330312 258 if (dump_file)
f6db1481 259 {
ef330312 260 dump_combine_total_stats (dump_file);
8ddbbcae 261 dump_end (pass_combine.pass.static_pass_number, dump_file);
f6db1481
RH
262 }
263 }
264
ef330312
PB
265 /* Do whatever is necessary to finish printing the graphs. */
266 if (graph_dump_format != no_graph)
267 for (i = TDI_end; (dfi = get_dump_file_info (i)) != NULL; ++i)
268 if (dump_initialized_p (i)
5e34206b 269 && (dfi->flags & TDF_GRAPH) != 0
ef330312 270 && (name = get_dump_file_name (i)) != NULL)
5e34206b
JJ
271 {
272 finish_graph_dump_file (name);
273 free (name);
274 }
f6db1481 275
ef330312 276 timevar_pop (TV_DUMP);
f6db1481 277}
f6db1481 278
ef330312
PB
279static bool
280gate_rest_of_compilation (void)
f6db1481 281{
ef330312
PB
282 /* Early return if there were errors. We can run afoul of our
283 consistency checks, and there's not really much point in fixing them. */
1da2ed5f 284 return !(rtl_dump_and_exit || flag_syntax_only || seen_error ());
f6db1481
RH
285}
286
8ddbbcae 287struct gimple_opt_pass pass_rest_of_compilation =
f6db1481 288{
8ddbbcae
JH
289 {
290 GIMPLE_PASS,
cf400ddb 291 "*rest_of_compilation", /* name */
ef330312
PB
292 gate_rest_of_compilation, /* gate */
293 NULL, /* execute */
294 NULL, /* sub */
295 NULL, /* next */
296 0, /* static_pass_number */
297 TV_REST_OF_COMPILATION, /* tv_id */
298 PROP_rtl, /* properties_required */
299 0, /* properties_provided */
300 0, /* properties_destroyed */
301 0, /* todo_flags_start */
8ddbbcae
JH
302 TODO_ggc_collect /* todo_flags_finish */
303 }
ef330312 304};
f6db1481 305
ef330312
PB
306static bool
307gate_postreload (void)
308{
309 return reload_completed;
f6db1481
RH
310}
311
8ddbbcae 312struct rtl_opt_pass pass_postreload =
f6db1481 313{
8ddbbcae
JH
314 {
315 RTL_PASS,
e0a42b0f 316 "*all-postreload", /* name */
ef330312
PB
317 gate_postreload, /* gate */
318 NULL, /* execute */
319 NULL, /* sub */
320 NULL, /* next */
321 0, /* static_pass_number */
a222c01a 322 TV_POSTRELOAD, /* tv_id */
ef330312
PB
323 PROP_rtl, /* properties_required */
324 0, /* properties_provided */
325 0, /* properties_destroyed */
326 0, /* todo_flags_start */
8ddbbcae
JH
327 TODO_ggc_collect | TODO_verify_rtl_sharing /* todo_flags_finish */
328 }
ef330312 329};
f6db1481 330
97b0ade3 331
f6db1481 332
ef330312 333/* The root of the compilation pass tree, once constructed. */
d7f09764 334struct opt_pass *all_passes, *all_small_ipa_passes, *all_lowering_passes,
febb1302 335 *all_regular_ipa_passes, *all_late_ipa_passes, *all_lto_gen_passes;
f6db1481 336
2a5e9d16
JR
337/* This is used by plugins, and should also be used in register_pass. */
338#define DEF_PASS_LIST(LIST) &LIST,
339struct opt_pass **gcc_pass_lists[] = { GCC_PASS_LISTS NULL };
340#undef DEF_PASS_LIST
341
9fe0cb7d
RG
342/* A map from static pass id to optimization pass. */
343struct opt_pass **passes_by_id;
344int passes_by_id_size;
345
346/* Set the static pass number of pass PASS to ID and record that
347 in the mapping from static pass number to pass. */
348
349static void
350set_pass_for_id (int id, struct opt_pass *pass)
351{
352 pass->static_pass_number = id;
353 if (passes_by_id_size <= id)
354 {
d3bfe4de 355 passes_by_id = XRESIZEVEC (struct opt_pass *, passes_by_id, id + 1);
9fe0cb7d
RG
356 memset (passes_by_id + passes_by_id_size, 0,
357 (id + 1 - passes_by_id_size) * sizeof (void *));
358 passes_by_id_size = id + 1;
359 }
360 passes_by_id[id] = pass;
361}
362
363/* Return the pass with the static pass number ID. */
364
365struct opt_pass *
366get_pass_for_id (int id)
367{
368 if (id >= passes_by_id_size)
369 return NULL;
370 return passes_by_id[id];
371}
372
ef330312
PB
373/* Iterate over the pass tree allocating dump file numbers. We want
374 to do this depth first, and independent of whether the pass is
375 enabled or not. */
f6db1481 376
68a607d8 377void
9e016eba 378register_one_dump_file (struct opt_pass *pass)
ef330312
PB
379{
380 char *dot_name, *flag_name, *glob_name;
226c52aa 381 const char *name, *full_name, *prefix;
ef330312 382 char num[10];
9fe0cb7d 383 int flags, id;
f6db1481 384
ef330312
PB
385 /* See below in next_pass_1. */
386 num[0] = '\0';
387 if (pass->static_pass_number != -1)
388 sprintf (num, "%d", ((int) pass->static_pass_number < 0
389 ? 1 : pass->static_pass_number));
f6db1481 390
e0a42b0f
ZC
391 /* The name is both used to identify the pass for the purposes of plugins,
392 and to specify dump file name and option.
393 The latter two might want something short which is not quite unique; for
394 that reason, we may have a disambiguating prefix, followed by a space
395 to mark the start of the following dump file name / option string. */
396 name = strchr (pass->name, ' ');
397 name = name ? name + 1 : pass->name;
398 dot_name = concat (".", name, num, NULL);
17653c00 399 if (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS)
bbbe4e7b 400 prefix = "ipa-", flags = TDF_IPA;
9e016eba 401 else if (pass->type == GIMPLE_PASS)
bbbe4e7b 402 prefix = "tree-", flags = TDF_TREE;
f6db1481 403 else
bbbe4e7b
PB
404 prefix = "rtl-", flags = TDF_RTL;
405
e0a42b0f
ZC
406 flag_name = concat (prefix, name, num, NULL);
407 glob_name = concat (prefix, name, NULL);
9fe0cb7d
RG
408 id = dump_register (dot_name, flag_name, glob_name, flags);
409 set_pass_for_id (id, pass);
226c52aa
XDL
410 full_name = concat (prefix, pass->name, num, NULL);
411 register_pass_name (pass, full_name);
97b0ade3
PB
412}
413
bbbe4e7b
PB
414/* Recursive worker function for register_dump_files. */
415
b8698a0f 416static int
9e016eba 417register_dump_files_1 (struct opt_pass *pass, int properties)
97b0ade3 418{
ef330312
PB
419 do
420 {
bbbe4e7b
PB
421 int new_properties = (properties | pass->properties_provided)
422 & ~pass->properties_destroyed;
f6db1481 423
8e352cd3 424 if (pass->name && pass->name[0] != '*')
9e016eba 425 register_one_dump_file (pass);
f6db1481 426
ef330312 427 if (pass->sub)
9e016eba 428 new_properties = register_dump_files_1 (pass->sub, new_properties);
f6db1481 429
ef330312
PB
430 /* If we have a gate, combine the properties that we could have with
431 and without the pass being examined. */
432 if (pass->gate)
433 properties &= new_properties;
434 else
435 properties = new_properties;
f6db1481 436
ef330312 437 pass = pass->next;
f6db1481 438 }
ef330312 439 while (pass);
f6db1481 440
ef330312 441 return properties;
f6db1481 442}
f9957958 443
b8698a0f 444/* Register the dump files for the pipeline starting at PASS.
9e016eba
JH
445 PROPERTIES reflects the properties that are guaranteed to be available at
446 the beginning of the pipeline. */
bbbe4e7b 447
b8698a0f 448static void
9e016eba 449register_dump_files (struct opt_pass *pass,int properties)
bbbe4e7b
PB
450{
451 pass->properties_required |= properties;
9e016eba 452 register_dump_files_1 (pass, properties);
bbbe4e7b
PB
453}
454
226c52aa
XDL
455struct pass_registry
456{
457 const char* unique_name;
458 struct opt_pass *pass;
459};
460
461/* Pass registry hash function. */
462
463static hashval_t
464passr_hash (const void *p)
465{
466 const struct pass_registry *const s = (const struct pass_registry *const) p;
467 return htab_hash_string (s->unique_name);
468}
469
470/* Hash equal function */
471
472static int
473passr_eq (const void *p1, const void *p2)
474{
475 const struct pass_registry *const s1 = (const struct pass_registry *const) p1;
476 const struct pass_registry *const s2 = (const struct pass_registry *const) p2;
477
478 return !strcmp (s1->unique_name, s2->unique_name);
479}
480
deced1e2 481static htab_t name_to_pass_map = NULL;
226c52aa
XDL
482
483/* Register PASS with NAME. */
484
485static void
486register_pass_name (struct opt_pass *pass, const char *name)
487{
488 struct pass_registry **slot;
489 struct pass_registry pr;
490
deced1e2
XDL
491 if (!name_to_pass_map)
492 name_to_pass_map = htab_create (256, passr_hash, passr_eq, NULL);
226c52aa
XDL
493
494 pr.unique_name = name;
deced1e2 495 slot = (struct pass_registry **) htab_find_slot (name_to_pass_map, &pr, INSERT);
226c52aa
XDL
496 if (!*slot)
497 {
498 struct pass_registry *new_pr;
499
500 new_pr = XCNEW (struct pass_registry);
501 new_pr->unique_name = xstrdup (name);
502 new_pr->pass = pass;
503 *slot = new_pr;
504 }
505 else
506 return; /* Ignore plugin passes. */
507}
508
deced1e2
XDL
509/* Map from pass id to canonicalized pass name. */
510
511typedef const char *char_ptr;
512DEF_VEC_P(char_ptr);
513DEF_VEC_ALLOC_P(char_ptr, heap);
514static VEC(char_ptr, heap) *pass_tab = NULL;
515
516/* Callback function for traversing NAME_TO_PASS_MAP. */
517
518static int
519pass_traverse (void **slot, void *data ATTRIBUTE_UNUSED)
520{
521 struct pass_registry **p = (struct pass_registry **)slot;
522 struct opt_pass *pass = (*p)->pass;
523
524 gcc_assert (pass->static_pass_number > 0);
525 gcc_assert (pass_tab);
526
527 VEC_replace (char_ptr, pass_tab, pass->static_pass_number,
528 (*p)->unique_name);
529
530 return 1;
531}
532
533/* The function traverses NAME_TO_PASS_MAP and creates a pass info
534 table for dumping purpose. */
535
536static void
537create_pass_tab (void)
538{
539 if (!flag_dump_passes)
540 return;
541
542 VEC_safe_grow_cleared (char_ptr, heap,
543 pass_tab, passes_by_id_size + 1);
544 htab_traverse (name_to_pass_map, pass_traverse, NULL);
545}
546
547static bool override_gate_status (struct opt_pass *, tree, bool);
548
549/* Dump the instantiated name for PASS. IS_ON indicates if PASS
550 is turned on or not. */
551
552static void
553dump_one_pass (struct opt_pass *pass, int pass_indent)
554{
555 int indent = 3 * pass_indent;
556 const char *pn;
557 bool is_on, is_really_on;
558
559 is_on = (pass->gate == NULL) ? true : pass->gate();
560 is_really_on = override_gate_status (pass, current_function_decl, is_on);
561
562 if (pass->static_pass_number <= 0)
563 pn = pass->name;
564 else
565 pn = VEC_index (char_ptr, pass_tab, pass->static_pass_number);
566
567 fprintf (stderr, "%*s%-40s%*s:%s%s\n", indent, " ", pn,
568 (15 - indent < 0 ? 0 : 15 - indent), " ",
569 is_on ? " ON" : " OFF",
570 ((!is_on) == (!is_really_on) ? ""
571 : (is_really_on ? " (FORCED_ON)" : " (FORCED_OFF)")));
572}
573
574/* Dump pass list PASS with indentation INDENT. */
575
576static void
577dump_pass_list (struct opt_pass *pass, int indent)
578{
579 do
580 {
581 dump_one_pass (pass, indent);
582 if (pass->sub)
583 dump_pass_list (pass->sub, indent + 1);
584 pass = pass->next;
585 }
586 while (pass);
587}
588
589/* Dump all optimization passes. */
590
591void
592dump_passes (void)
593{
594 struct cgraph_node *n, *node = NULL;
595 tree save_fndecl = current_function_decl;
596
597 create_pass_tab();
598
599 n = cgraph_nodes;
600 while (n)
601 {
602 if (DECL_STRUCT_FUNCTION (n->decl))
603 {
604 node = n;
605 break;
606 }
607 n = n->next;
608 }
609
610 if (!node)
611 return;
612
613 push_cfun (DECL_STRUCT_FUNCTION (node->decl));
614 current_function_decl = node->decl;
615
616 dump_pass_list (all_lowering_passes, 1);
617 dump_pass_list (all_small_ipa_passes, 1);
618 dump_pass_list (all_regular_ipa_passes, 1);
619 dump_pass_list (all_lto_gen_passes, 1);
febb1302 620 dump_pass_list (all_late_ipa_passes, 1);
deced1e2
XDL
621 dump_pass_list (all_passes, 1);
622
623 pop_cfun ();
624 current_function_decl = save_fndecl;
625}
626
627
226c52aa
XDL
628/* Returns the pass with NAME. */
629
630static struct opt_pass *
631get_pass_by_name (const char *name)
632{
633 struct pass_registry **slot, pr;
634
226c52aa 635 pr.unique_name = name;
deced1e2 636 slot = (struct pass_registry **) htab_find_slot (name_to_pass_map,
226c52aa
XDL
637 &pr, NO_INSERT);
638
639 if (!slot || !*slot)
640 return NULL;
641
642 return (*slot)->pass;
643}
644
645
646/* Range [start, last]. */
647
648struct uid_range
649{
650 unsigned int start;
651 unsigned int last;
bb5b1f5e 652 const char *assem_name;
226c52aa
XDL
653 struct uid_range *next;
654};
655
656typedef struct uid_range *uid_range_p;
657
658DEF_VEC_P(uid_range_p);
659DEF_VEC_ALLOC_P(uid_range_p, heap);
660
661static VEC(uid_range_p, heap) *enabled_pass_uid_range_tab = NULL;
662static VEC(uid_range_p, heap) *disabled_pass_uid_range_tab = NULL;
663
bb5b1f5e 664
226c52aa
XDL
665/* Parse option string for -fdisable- and -fenable-
666 The syntax of the options:
667
668 -fenable-<pass_name>
669 -fdisable-<pass_name>
670
671 -fenable-<pass_name>=s1:e1,s2:e2,...
672 -fdisable-<pass_name>=s1:e1,s2:e2,...
673*/
674
675static void
676enable_disable_pass (const char *arg, bool is_enable)
677{
678 struct opt_pass *pass;
679 char *range_str, *phase_name;
680 char *argstr = xstrdup (arg);
681 VEC(uid_range_p, heap) **tab = 0;
682
683 range_str = strchr (argstr,'=');
684 if (range_str)
685 {
686 *range_str = '\0';
687 range_str++;
688 }
689
690 phase_name = argstr;
691 if (!*phase_name)
692 {
693 if (is_enable)
694 error ("unrecognized option -fenable");
695 else
696 error ("unrecognized option -fdisable");
697 free (argstr);
698 return;
699 }
700 pass = get_pass_by_name (phase_name);
701 if (!pass || pass->static_pass_number == -1)
702 {
703 if (is_enable)
704 error ("unknown pass %s specified in -fenable", phase_name);
705 else
706 error ("unknown pass %s specified in -fdisble", phase_name);
707 free (argstr);
708 return;
709 }
710
711 if (is_enable)
712 tab = &enabled_pass_uid_range_tab;
713 else
714 tab = &disabled_pass_uid_range_tab;
715
716 if ((unsigned) pass->static_pass_number >= VEC_length (uid_range_p, *tab))
717 VEC_safe_grow_cleared (uid_range_p, heap,
718 *tab, pass->static_pass_number + 1);
719
720 if (!range_str)
721 {
722 uid_range_p slot;
723 uid_range_p new_range = XCNEW (struct uid_range);
724
725 new_range->start = 0;
726 new_range->last = (unsigned)-1;
727
728 slot = VEC_index (uid_range_p, *tab, pass->static_pass_number);
729 new_range->next = slot;
730 VEC_replace (uid_range_p, *tab, pass->static_pass_number,
731 new_range);
732 if (is_enable)
733 inform (UNKNOWN_LOCATION, "enable pass %s for functions in the range "
734 "of [%u, %u]", phase_name, new_range->start, new_range->last);
735 else
736 inform (UNKNOWN_LOCATION, "disable pass %s for functions in the range "
737 "of [%u, %u]", phase_name, new_range->start, new_range->last);
738 }
739 else
740 {
741 char *next_range = NULL;
742 char *one_range = range_str;
743 char *end_val = NULL;
744
745 do
746 {
747 uid_range_p slot;
748 uid_range_p new_range;
749 char *invalid = NULL;
750 long start;
bb5b1f5e 751 char *func_name = NULL;
226c52aa
XDL
752
753 next_range = strchr (one_range, ',');
754 if (next_range)
755 {
756 *next_range = '\0';
757 next_range++;
758 }
759
760 end_val = strchr (one_range, ':');
761 if (end_val)
762 {
763 *end_val = '\0';
764 end_val++;
765 }
766 start = strtol (one_range, &invalid, 10);
767 if (*invalid || start < 0)
768 {
bb5b1f5e
XDL
769 if (end_val || (one_range[0] >= '0'
770 && one_range[0] <= '9'))
771 {
772 error ("Invalid range %s in option %s",
773 one_range,
774 is_enable ? "-fenable" : "-fdisable");
775 free (argstr);
776 return;
777 }
778 func_name = one_range;
226c52aa
XDL
779 }
780 if (!end_val)
781 {
782 new_range = XCNEW (struct uid_range);
bb5b1f5e
XDL
783 if (!func_name)
784 {
785 new_range->start = (unsigned) start;
786 new_range->last = (unsigned) start;
787 }
788 else
789 {
790 new_range->start = (unsigned) -1;
791 new_range->last = (unsigned) -1;
792 new_range->assem_name = xstrdup (func_name);
793 }
226c52aa
XDL
794 }
795 else
796 {
797 long last = strtol (end_val, &invalid, 10);
798 if (*invalid || last < start)
799 {
800 error ("Invalid range %s in option %s",
801 end_val,
802 is_enable ? "-fenable" : "-fdisable");
803 free (argstr);
804 return;
805 }
806 new_range = XCNEW (struct uid_range);
807 new_range->start = (unsigned) start;
808 new_range->last = (unsigned) last;
809 }
810
811 slot = VEC_index (uid_range_p, *tab, pass->static_pass_number);
812 new_range->next = slot;
813 VEC_replace (uid_range_p, *tab, pass->static_pass_number,
814 new_range);
226c52aa 815 if (is_enable)
bb5b1f5e
XDL
816 {
817 if (new_range->assem_name)
818 inform (UNKNOWN_LOCATION,
819 "enable pass %s for function %s",
820 phase_name, new_range->assem_name);
821 else
822 inform (UNKNOWN_LOCATION,
823 "enable pass %s for functions in the range of [%u, %u]",
824 phase_name, new_range->start, new_range->last);
825 }
226c52aa 826 else
bb5b1f5e
XDL
827 {
828 if (new_range->assem_name)
829 inform (UNKNOWN_LOCATION,
830 "disable pass %s for function %s",
831 phase_name, new_range->assem_name);
832 else
833 inform (UNKNOWN_LOCATION,
834 "disable pass %s for functions in the range of [%u, %u]",
835 phase_name, new_range->start, new_range->last);
836 }
226c52aa
XDL
837
838 one_range = next_range;
839 } while (next_range);
840 }
841
842 free (argstr);
843}
844
845/* Enable pass specified by ARG. */
846
847void
848enable_pass (const char *arg)
849{
850 enable_disable_pass (arg, true);
851}
852
853/* Disable pass specified by ARG. */
854
855void
856disable_pass (const char *arg)
857{
858 enable_disable_pass (arg, false);
859}
860
861/* Returns true if PASS is explicitly enabled/disabled for FUNC. */
862
863static bool
864is_pass_explicitly_enabled_or_disabled (struct opt_pass *pass,
865 tree func,
866 VEC(uid_range_p, heap) *tab)
867{
868 uid_range_p slot, range;
869 int cgraph_uid;
bb5b1f5e 870 const char *aname = NULL;
226c52aa
XDL
871
872 if (!tab
873 || (unsigned) pass->static_pass_number >= VEC_length (uid_range_p, tab)
874 || pass->static_pass_number == -1)
875 return false;
876
877 slot = VEC_index (uid_range_p, tab, pass->static_pass_number);
878 if (!slot)
879 return false;
880
881 cgraph_uid = func ? cgraph_get_node (func)->uid : 0;
bb5b1f5e
XDL
882 if (func && DECL_ASSEMBLER_NAME_SET_P (func))
883 aname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func));
226c52aa
XDL
884
885 range = slot;
886 while (range)
887 {
888 if ((unsigned) cgraph_uid >= range->start
889 && (unsigned) cgraph_uid <= range->last)
890 return true;
bb5b1f5e
XDL
891 if (range->assem_name && aname
892 && !strcmp (range->assem_name, aname))
893 return true;
226c52aa
XDL
894 range = range->next;
895 }
896
897 return false;
898}
899
b80b0fd9
ST
900/* Look at the static_pass_number and duplicate the pass
901 if it is already added to a list. */
f9957958 902
b80b0fd9
ST
903static struct opt_pass *
904make_pass_instance (struct opt_pass *pass, bool track_duplicates)
f6db1481 905{
ef330312
PB
906 /* A nonzero static_pass_number indicates that the
907 pass is already in the list. */
908 if (pass->static_pass_number)
909 {
82d6e6fc 910 struct opt_pass *new_pass;
f6db1481 911
63a00e0d
DS
912 if (pass->type == GIMPLE_PASS
913 || pass->type == RTL_PASS
914 || pass->type == SIMPLE_IPA_PASS)
915 {
916 new_pass = XNEW (struct opt_pass);
917 memcpy (new_pass, pass, sizeof (struct opt_pass));
918 }
919 else if (pass->type == IPA_PASS)
920 {
921 new_pass = (struct opt_pass *)XNEW (struct ipa_opt_pass_d);
922 memcpy (new_pass, pass, sizeof (struct ipa_opt_pass_d));
923 }
924 else
925 gcc_unreachable ();
926
82d6e6fc 927 new_pass->next = NULL;
f6db1481 928
82d6e6fc 929 new_pass->todo_flags_start &= ~TODO_mark_first_instance;
b02b9b53 930
ef330312
PB
931 /* Indicate to register_dump_files that this pass has duplicates,
932 and so it should rename the dump file. The first instance will
933 be -1, and be number of duplicates = -static_pass_number - 1.
934 Subsequent instances will be > 0 and just the duplicate number. */
e0a42b0f 935 if ((pass->name && pass->name[0] != '*') || track_duplicates)
ef330312
PB
936 {
937 pass->static_pass_number -= 1;
82d6e6fc 938 new_pass->static_pass_number = -pass->static_pass_number;
ef330312 939 }
b80b0fd9 940 return new_pass;
ef330312
PB
941 }
942 else
943 {
b02b9b53 944 pass->todo_flags_start |= TODO_mark_first_instance;
ef330312 945 pass->static_pass_number = -1;
090fa0ab
GF
946
947 invoke_plugin_callbacks (PLUGIN_NEW_PASS, pass);
b8698a0f
L
948 }
949 return pass;
b80b0fd9
ST
950}
951
952/* Add a pass to the pass list. Duplicate the pass if it's already
953 in the list. */
954
955static struct opt_pass **
956next_pass_1 (struct opt_pass **list, struct opt_pass *pass)
957{
e0a42b0f
ZC
958 /* Every pass should have a name so that plugins can refer to them. */
959 gcc_assert (pass->name != NULL);
960
b80b0fd9 961 *list = make_pass_instance (pass, false);
b8698a0f 962
ef330312 963 return &(*list)->next;
f6db1481
RH
964}
965
b80b0fd9
ST
966/* List node for an inserted pass instance. We need to keep track of all
967 the newly-added pass instances (with 'added_pass_nodes' defined below)
968 so that we can register their dump files after pass-positioning is finished.
969 Registering dumping files needs to be post-processed or the
970 static_pass_number of the opt_pass object would be modified and mess up
971 the dump file names of future pass instances to be added. */
972
973struct pass_list_node
974{
975 struct opt_pass *pass;
976 struct pass_list_node *next;
977};
978
979static struct pass_list_node *added_pass_nodes = NULL;
980static struct pass_list_node *prev_added_pass_node;
981
b8698a0f 982/* Insert the pass at the proper position. Return true if the pass
b80b0fd9
ST
983 is successfully added.
984
985 NEW_PASS_INFO - new pass to be inserted
986 PASS_LIST - root of the pass list to insert the new pass to */
987
988static bool
989position_pass (struct register_pass_info *new_pass_info,
990 struct opt_pass **pass_list)
991{
992 struct opt_pass *pass = *pass_list, *prev_pass = NULL;
993 bool success = false;
994
995 for ( ; pass; prev_pass = pass, pass = pass->next)
996 {
997 /* Check if the current pass is of the same type as the new pass and
998 matches the name and the instance number of the reference pass. */
999 if (pass->type == new_pass_info->pass->type
1000 && pass->name
1001 && !strcmp (pass->name, new_pass_info->reference_pass_name)
1002 && ((new_pass_info->ref_pass_instance_number == 0)
1003 || (new_pass_info->ref_pass_instance_number ==
1004 pass->static_pass_number)
1005 || (new_pass_info->ref_pass_instance_number == 1
1006 && pass->todo_flags_start & TODO_mark_first_instance)))
1007 {
1008 struct opt_pass *new_pass;
1009 struct pass_list_node *new_pass_node;
1010
1011 new_pass = make_pass_instance (new_pass_info->pass, true);
b8698a0f 1012
b80b0fd9
ST
1013 /* Insert the new pass instance based on the positioning op. */
1014 switch (new_pass_info->pos_op)
1015 {
1016 case PASS_POS_INSERT_AFTER:
1017 new_pass->next = pass->next;
1018 pass->next = new_pass;
1019
1020 /* Skip newly inserted pass to avoid repeated
1021 insertions in the case where the new pass and the
1022 existing one have the same name. */
b8698a0f 1023 pass = new_pass;
b80b0fd9
ST
1024 break;
1025 case PASS_POS_INSERT_BEFORE:
1026 new_pass->next = pass;
1027 if (prev_pass)
1028 prev_pass->next = new_pass;
1029 else
1030 *pass_list = new_pass;
1031 break;
1032 case PASS_POS_REPLACE:
1033 new_pass->next = pass->next;
1034 if (prev_pass)
1035 prev_pass->next = new_pass;
1036 else
1037 *pass_list = new_pass;
1038 new_pass->sub = pass->sub;
1039 new_pass->tv_id = pass->tv_id;
1040 pass = new_pass;
1041 break;
1042 default:
d8a07487 1043 error ("invalid pass positioning operation");
b80b0fd9
ST
1044 return false;
1045 }
1046
1047 /* Save the newly added pass (instance) in the added_pass_nodes
1048 list so that we can register its dump file later. Note that
1049 we cannot register the dump file now because doing so will modify
1050 the static_pass_number of the opt_pass object and therefore
1051 mess up the dump file name of future instances. */
1052 new_pass_node = XCNEW (struct pass_list_node);
1053 new_pass_node->pass = new_pass;
1054 if (!added_pass_nodes)
1055 added_pass_nodes = new_pass_node;
1056 else
1057 prev_added_pass_node->next = new_pass_node;
1058 prev_added_pass_node = new_pass_node;
1059
1060 success = true;
1061 }
1062
1063 if (pass->sub && position_pass (new_pass_info, &pass->sub))
1064 success = true;
1065 }
1066
1067 return success;
1068}
1069
1070/* Hooks a new pass into the pass lists.
1071
1072 PASS_INFO - pass information that specifies the opt_pass object,
1073 reference pass, instance number, and how to position
1074 the pass */
1075
1076void
1077register_pass (struct register_pass_info *pass_info)
1078{
669887fc
DS
1079 bool all_instances, success;
1080
b9e467a2
BS
1081 /* The checks below could fail in buggy plugins. Existing GCC
1082 passes should never fail these checks, so we mention plugin in
1083 the messages. */
b80b0fd9 1084 if (!pass_info->pass)
b9e467a2
BS
1085 fatal_error ("plugin cannot register a missing pass");
1086
1087 if (!pass_info->pass->name)
1088 fatal_error ("plugin cannot register an unnamed pass");
b80b0fd9
ST
1089
1090 if (!pass_info->reference_pass_name)
b9e467a2
BS
1091 fatal_error
1092 ("plugin cannot register pass %qs without reference pass name",
1093 pass_info->pass->name);
b80b0fd9 1094
b9e467a2 1095 /* Try to insert the new pass to the pass lists. We need to check
669887fc 1096 all five lists as the reference pass could be in one (or all) of
b9e467a2 1097 them. */
669887fc
DS
1098 all_instances = pass_info->ref_pass_instance_number == 0;
1099 success = position_pass (pass_info, &all_lowering_passes);
1100 if (!success || all_instances)
1101 success |= position_pass (pass_info, &all_small_ipa_passes);
1102 if (!success || all_instances)
1103 success |= position_pass (pass_info, &all_regular_ipa_passes);
1104 if (!success || all_instances)
1105 success |= position_pass (pass_info, &all_lto_gen_passes);
febb1302
JH
1106 if (!success || all_instances)
1107 success |= position_pass (pass_info, &all_late_ipa_passes);
669887fc
DS
1108 if (!success || all_instances)
1109 success |= position_pass (pass_info, &all_passes);
1110 if (!success)
b9e467a2
BS
1111 fatal_error
1112 ("pass %qs not found but is referenced by new pass %qs",
1113 pass_info->reference_pass_name, pass_info->pass->name);
669887fc
DS
1114
1115 /* OK, we have successfully inserted the new pass. We need to register
1116 the dump files for the newly added pass and its duplicates (if any).
1117 Because the registration of plugin/backend passes happens after the
1118 command-line options are parsed, the options that specify single
1119 pass dumping (e.g. -fdump-tree-PASSNAME) cannot be used for new
1120 passes. Therefore we currently can only enable dumping of
1121 new passes when the 'dump-all' flags (e.g. -fdump-tree-all)
1122 are specified. While doing so, we also delete the pass_list_node
1123 objects created during pass positioning. */
1124 while (added_pass_nodes)
b80b0fd9 1125 {
669887fc
DS
1126 struct pass_list_node *next_node = added_pass_nodes->next;
1127 enum tree_dump_index tdi;
1128 register_one_dump_file (added_pass_nodes->pass);
1129 if (added_pass_nodes->pass->type == SIMPLE_IPA_PASS
1130 || added_pass_nodes->pass->type == IPA_PASS)
1131 tdi = TDI_ipa_all;
1132 else if (added_pass_nodes->pass->type == GIMPLE_PASS)
1133 tdi = TDI_tree_all;
1134 else
1135 tdi = TDI_rtl_all;
1136 /* Check if dump-all flag is specified. */
1137 if (get_dump_file_info (tdi)->state)
1138 get_dump_file_info (added_pass_nodes->pass->static_pass_number)
1139 ->state = get_dump_file_info (tdi)->state;
1140 XDELETE (added_pass_nodes);
1141 added_pass_nodes = next_node;
b80b0fd9
ST
1142 }
1143}
6fb5fa3c 1144
dd97d271
DN
1145/* Construct the pass tree. The sequencing of passes is driven by
1146 the cgraph routines:
1147
1148 cgraph_finalize_compilation_unit ()
1149 for each node N in the cgraph
1150 cgraph_analyze_function (N)
1151 cgraph_lower_function (N) -> all_lowering_passes
1152
1153 If we are optimizing, cgraph_optimize is then invoked:
1154
1155 cgraph_optimize ()
d7f09764 1156 ipa_passes () -> all_small_ipa_passes
dd97d271
DN
1157 cgraph_expand_all_functions ()
1158 for each node N in the cgraph
1159 cgraph_expand_function (N)
e89d6010 1160 tree_rest_of_compilation (DECL (N)) -> all_passes
dd97d271 1161*/
97b0ade3 1162
ef330312
PB
1163void
1164init_optimization_passes (void)
1165{
8ddbbcae 1166 struct opt_pass **p;
ef330312 1167
8ddbbcae 1168#define NEXT_PASS(PASS) (p = next_pass_1 (p, &((PASS).pass)))
873aa8f5 1169
f1bd2543
JH
1170 /* All passes needed to lower the function into shape optimizers can
1171 operate on. These passes are always run first on the function, but
1172 backend might produce already lowered functions that are not processed
1173 by these passes. */
ef330312 1174 p = &all_lowering_passes;
a406865a
RG
1175 NEXT_PASS (pass_warn_unused_result);
1176 NEXT_PASS (pass_diagnose_omp_blocks);
0a35513e 1177 NEXT_PASS (pass_diagnose_tm_blocks);
ef330312 1178 NEXT_PASS (pass_mudflap_1);
953ff289 1179 NEXT_PASS (pass_lower_omp);
ef330312 1180 NEXT_PASS (pass_lower_cf);
0a35513e 1181 NEXT_PASS (pass_lower_tm);
a24549d4 1182 NEXT_PASS (pass_refactor_eh);
ef330312
PB
1183 NEXT_PASS (pass_lower_eh);
1184 NEXT_PASS (pass_build_cfg);
ef330312 1185 NEXT_PASS (pass_warn_function_return);
2dee695b 1186 NEXT_PASS (pass_build_cgraph_edges);
ef330312
PB
1187 *p = NULL;
1188
7e8b322a 1189 /* Interprocedural optimization passes. */
d7f09764 1190 p = &all_small_ipa_passes;
b6050cb7 1191 NEXT_PASS (pass_ipa_free_lang_data);
f1bd2543 1192 NEXT_PASS (pass_ipa_function_and_variable_visibility);
f1bd2543
JH
1193 NEXT_PASS (pass_early_local_passes);
1194 {
8ddbbcae 1195 struct opt_pass **p = &pass_early_local_passes.pass.sub;
6f1873a1 1196 NEXT_PASS (pass_fixup_cfg);
f1bd2543
JH
1197 NEXT_PASS (pass_init_datastructures);
1198 NEXT_PASS (pass_expand_omp);
c72321c9
JH
1199
1200 NEXT_PASS (pass_referenced_vars);
c72321c9 1201 NEXT_PASS (pass_build_ssa);
47853c73 1202 NEXT_PASS (pass_lower_vector);
2dc74010 1203 NEXT_PASS (pass_early_warn_uninitialized);
d7f09764 1204 NEXT_PASS (pass_rebuild_cgraph_edges);
bb7e6d55 1205 NEXT_PASS (pass_inline_parameters);
d7f09764 1206 NEXT_PASS (pass_early_inline);
f1bd2543
JH
1207 NEXT_PASS (pass_all_early_optimizations);
1208 {
8ddbbcae 1209 struct opt_pass **p = &pass_all_early_optimizations.pass.sub;
133f9369 1210 NEXT_PASS (pass_remove_cgraph_callee_edges);
f1bd2543
JH
1211 NEXT_PASS (pass_rename_ssa_copies);
1212 NEXT_PASS (pass_ccp);
1213 NEXT_PASS (pass_forwprop);
6b8ed145
RG
1214 /* pass_build_ealias is a dummy pass that ensures that we
1215 execute TODO_rebuild_alias at this point. Re-building
1216 alias information also rewrites no longer addressed
1217 locals into SSA form if possible. */
1218 NEXT_PASS (pass_build_ealias);
029f45bd 1219 NEXT_PASS (pass_sra_early);
605896f5 1220 NEXT_PASS (pass_fre);
f1bd2543
JH
1221 NEXT_PASS (pass_copy_prop);
1222 NEXT_PASS (pass_merge_phi);
11b08ee9 1223 NEXT_PASS (pass_cd_dce);
07ffa034 1224 NEXT_PASS (pass_early_ipa_sra);
f1bd2543 1225 NEXT_PASS (pass_tail_recursion);
b6e99746 1226 NEXT_PASS (pass_convert_switch);
a8da523f 1227 NEXT_PASS (pass_cleanup_eh);
45a80bb9 1228 NEXT_PASS (pass_profile);
33977f81 1229 NEXT_PASS (pass_local_pure_const);
3e485f62
JH
1230 /* Split functions creates parts that are not run through
1231 early optimizations again. It is thus good idea to do this
1232 late. */
1233 NEXT_PASS (pass_split_functions);
f1bd2543 1234 }
c72321c9 1235 NEXT_PASS (pass_release_ssa_names);
f1bd2543 1236 NEXT_PASS (pass_rebuild_cgraph_edges);
b91bc349 1237 NEXT_PASS (pass_inline_parameters);
f1bd2543 1238 }
4d3814a5 1239 NEXT_PASS (pass_ipa_tree_profile);
cf9712cc
JH
1240 {
1241 struct opt_pass **p = &pass_ipa_tree_profile.pass.sub;
1242 NEXT_PASS (pass_feedback_split_functions);
1243 }
f1bd2543 1244 NEXT_PASS (pass_ipa_increase_alignment);
43d861a5 1245 NEXT_PASS (pass_ipa_matrix_reorg);
0a35513e 1246 NEXT_PASS (pass_ipa_tm);
8b84c596 1247 NEXT_PASS (pass_ipa_lower_emutls);
d7f09764
DN
1248 *p = NULL;
1249
1250 p = &all_regular_ipa_passes;
b20996ff 1251 NEXT_PASS (pass_ipa_whole_program_visibility);
e65bb9be 1252 NEXT_PASS (pass_ipa_profile);
f1bd2543 1253 NEXT_PASS (pass_ipa_cp);
9e97ff61 1254 NEXT_PASS (pass_ipa_cdtor_merge);
f1bd2543 1255 NEXT_PASS (pass_ipa_inline);
b8698a0f 1256 NEXT_PASS (pass_ipa_pure_const);
514f01ad 1257 NEXT_PASS (pass_ipa_reference);
d7f09764
DN
1258 *p = NULL;
1259
1260 p = &all_lto_gen_passes;
1261 NEXT_PASS (pass_ipa_lto_gimple_out);
d7f09764 1262 NEXT_PASS (pass_ipa_lto_finish_out); /* This must be the last LTO pass. */
7a388ee4
JH
1263 *p = NULL;
1264
febb1302
JH
1265 /* Simple IPA passes executed after the regular passes. In WHOPR mode the
1266 passes are executed after partitioning and thus see just parts of the
1267 compiled unit. */
1268 p = &all_late_ipa_passes;
1269 NEXT_PASS (pass_ipa_pta);
1270 *p = NULL;
b3f7d793
DN
1271 /* These passes are run after IPA passes on every function that is being
1272 output to the assembler file. */
ef330312 1273 p = &all_passes;
febb1302 1274 NEXT_PASS (pass_fixup_cfg);
1d65f45c 1275 NEXT_PASS (pass_lower_eh_dispatch);
ef330312 1276 NEXT_PASS (pass_all_optimizations);
f1bd2543 1277 {
8ddbbcae 1278 struct opt_pass **p = &pass_all_optimizations.pass.sub;
133f9369 1279 NEXT_PASS (pass_remove_cgraph_callee_edges);
11b08ee9
RG
1280 /* Initial scalar cleanups before alias computation.
1281 They ensure memory accesses are not indirect wherever possible. */
7299cb99 1282 NEXT_PASS (pass_strip_predict_hints);
f1bd2543 1283 NEXT_PASS (pass_rename_ssa_copies);
d6e840ee 1284 NEXT_PASS (pass_complete_unrolli);
f1bd2543 1285 NEXT_PASS (pass_ccp);
e2081a1d 1286 NEXT_PASS (pass_forwprop);
11b08ee9
RG
1287 NEXT_PASS (pass_call_cdce);
1288 /* pass_build_alias is a dummy pass that ensures that we
1289 execute TODO_rebuild_alias at this point. Re-building
1290 alias information also rewrites no longer addressed
1291 locals into SSA form if possible. */
1292 NEXT_PASS (pass_build_alias);
1293 NEXT_PASS (pass_return_slot);
3b48ccbc 1294 NEXT_PASS (pass_phiprop);
f1bd2543 1295 NEXT_PASS (pass_fre);
f1bd2543
JH
1296 NEXT_PASS (pass_copy_prop);
1297 NEXT_PASS (pass_merge_phi);
1298 NEXT_PASS (pass_vrp);
1299 NEXT_PASS (pass_dce);
a5828d1e 1300 NEXT_PASS (pass_cselim);
18d08014 1301 NEXT_PASS (pass_tree_ifcombine);
f1bd2543 1302 NEXT_PASS (pass_phiopt);
f1bd2543 1303 NEXT_PASS (pass_tail_recursion);
f1bd2543
JH
1304 NEXT_PASS (pass_ch);
1305 NEXT_PASS (pass_stdarg);
1306 NEXT_PASS (pass_lower_complex);
1307 NEXT_PASS (pass_sra);
f1bd2543 1308 NEXT_PASS (pass_rename_ssa_copies);
44e10129
MM
1309 /* The dom pass will also resolve all __builtin_constant_p calls
1310 that are still there to 0. This has to be done after some
1311 propagations have already run, but before some more dead code
1312 is removed, and this place fits nicely. Remember this when
1313 trying to move or duplicate pass_dominator somewhere earlier. */
f1bd2543 1314 NEXT_PASS (pass_dominator);
f1bd2543
JH
1315 /* The only const/copy propagation opportunities left after
1316 DOM should be due to degenerate PHI nodes. So rather than
1317 run the full propagators, run a specialized pass which
1318 only examines PHIs to discover const/copy propagation
1319 opportunities. */
1320 NEXT_PASS (pass_phi_only_cprop);
25c6036a 1321 NEXT_PASS (pass_dse);
f1bd2543
JH
1322 NEXT_PASS (pass_reassoc);
1323 NEXT_PASS (pass_dce);
f1bd2543
JH
1324 NEXT_PASS (pass_forwprop);
1325 NEXT_PASS (pass_phiopt);
1326 NEXT_PASS (pass_object_sizes);
8b57bfeb 1327 NEXT_PASS (pass_strlen);
a4b8a65f 1328 NEXT_PASS (pass_ccp);
324d2217 1329 NEXT_PASS (pass_copy_prop);
f1bd2543 1330 NEXT_PASS (pass_cse_sincos);
03bd2f1a 1331 NEXT_PASS (pass_optimize_bswap);
f1bd2543
JH
1332 NEXT_PASS (pass_split_crit_edges);
1333 NEXT_PASS (pass_pre);
f1bd2543
JH
1334 NEXT_PASS (pass_sink_code);
1335 NEXT_PASS (pass_tree_loop);
1336 {
8ddbbcae 1337 struct opt_pass **p = &pass_tree_loop.pass.sub;
f1bd2543 1338 NEXT_PASS (pass_tree_loop_init);
c86a3947 1339 NEXT_PASS (pass_lim);
f1bd2543 1340 NEXT_PASS (pass_copy_prop);
bbc8a8dc 1341 NEXT_PASS (pass_dce_loop);
f1bd2543
JH
1342 NEXT_PASS (pass_tree_unswitch);
1343 NEXT_PASS (pass_scev_cprop);
f1bd2543 1344 NEXT_PASS (pass_record_bounds);
3d8864c0 1345 NEXT_PASS (pass_check_data_deps);
dea61d92 1346 NEXT_PASS (pass_loop_distribution);
d4332d00
SP
1347 NEXT_PASS (pass_copy_prop);
1348 NEXT_PASS (pass_graphite);
204b560f 1349 {
d4332d00 1350 struct opt_pass **p = &pass_graphite.pass.sub;
d4332d00 1351 NEXT_PASS (pass_graphite_transforms);
9dac82c4 1352 NEXT_PASS (pass_lim);
caaf41d0 1353 NEXT_PASS (pass_copy_prop);
204b560f 1354 NEXT_PASS (pass_dce_loop);
204b560f 1355 }
f1bd2543
JH
1356 NEXT_PASS (pass_iv_canon);
1357 NEXT_PASS (pass_if_conversion);
1358 NEXT_PASS (pass_vectorize);
1359 {
8ddbbcae 1360 struct opt_pass **p = &pass_vectorize.pass.sub;
f1bd2543
JH
1361 NEXT_PASS (pass_dce_loop);
1362 }
6a753d5f 1363 NEXT_PASS (pass_predcom);
f1bd2543 1364 NEXT_PASS (pass_complete_unroll);
a70d6342 1365 NEXT_PASS (pass_slp_vectorize);
5f40b3cb 1366 NEXT_PASS (pass_parallelize_loops);
f1bd2543
JH
1367 NEXT_PASS (pass_loop_prefetch);
1368 NEXT_PASS (pass_iv_optimize);
d3b7e946 1369 NEXT_PASS (pass_lim);
f1bd2543
JH
1370 NEXT_PASS (pass_tree_loop_done);
1371 }
f90e8e2e 1372 NEXT_PASS (pass_lower_vector_ssa);
f1bd2543
JH
1373 NEXT_PASS (pass_cse_reciprocals);
1374 NEXT_PASS (pass_reassoc);
1375 NEXT_PASS (pass_vrp);
1376 NEXT_PASS (pass_dominator);
f1bd2543
JH
1377 /* The only const/copy propagation opportunities left after
1378 DOM should be due to degenerate PHI nodes. So rather than
1379 run the full propagators, run a specialized pass which
1380 only examines PHIs to discover const/copy propagation
1381 opportunities. */
1382 NEXT_PASS (pass_phi_only_cprop);
f1bd2543 1383 NEXT_PASS (pass_cd_dce);
232abc3f 1384 NEXT_PASS (pass_tracer);
f1bd2543
JH
1385
1386 /* FIXME: If DCE is not run before checking for uninitialized uses,
1387 we may get false warnings (e.g., testsuite/gcc.dg/uninit-5.c).
1388 However, this also causes us to misdiagnose cases that should be
1389 real warnings (e.g., testsuite/gcc.dg/pr18501.c).
b8698a0f 1390
f1bd2543
JH
1391 To fix the false positives in uninit-5.c, we would have to
1392 account for the predicates protecting the set and the use of each
1393 variable. Using a representation like Gated Single Assignment
1394 may help. */
1395 NEXT_PASS (pass_late_warn_uninitialized);
1396 NEXT_PASS (pass_dse);
1397 NEXT_PASS (pass_forwprop);
1398 NEXT_PASS (pass_phiopt);
44e10129 1399 NEXT_PASS (pass_fold_builtins);
5b58b39b 1400 NEXT_PASS (pass_optimize_widening_mul);
f1bd2543
JH
1401 NEXT_PASS (pass_tail_calls);
1402 NEXT_PASS (pass_rename_ssa_copies);
1403 NEXT_PASS (pass_uncprop);
33977f81 1404 NEXT_PASS (pass_local_pure_const);
f1bd2543 1405 }
0a35513e
AH
1406 NEXT_PASS (pass_tm_init);
1407 {
1408 struct opt_pass **p = &pass_tm_init.pass.sub;
1409 NEXT_PASS (pass_tm_mark);
1410 NEXT_PASS (pass_tm_memopt);
1411 NEXT_PASS (pass_tm_edges);
1412 }
688a482d 1413 NEXT_PASS (pass_lower_complex_O0);
6d07ad98 1414 NEXT_PASS (pass_cleanup_eh);
1d65f45c 1415 NEXT_PASS (pass_lower_resx);
c72321c9 1416 NEXT_PASS (pass_nrv);
4e3825db 1417 NEXT_PASS (pass_mudflap_2);
c72321c9 1418 NEXT_PASS (pass_cleanup_cfg_post_optimizing);
ef330312 1419 NEXT_PASS (pass_warn_function_noreturn);
726a989a 1420
ef330312 1421 NEXT_PASS (pass_expand);
4e3825db 1422
ef330312 1423 NEXT_PASS (pass_rest_of_compilation);
f1bd2543 1424 {
8ddbbcae 1425 struct opt_pass **p = &pass_rest_of_compilation.pass.sub;
f1bd2543
JH
1426 NEXT_PASS (pass_init_function);
1427 NEXT_PASS (pass_jump);
f1bd2543
JH
1428 NEXT_PASS (pass_rtl_eh);
1429 NEXT_PASS (pass_initial_value_sets);
1430 NEXT_PASS (pass_unshare_all_rtl);
7114321e 1431 NEXT_PASS (pass_instantiate_virtual_regs);
45dbce1b 1432 NEXT_PASS (pass_into_cfg_layout_mode);
f1bd2543
JH
1433 NEXT_PASS (pass_jump2);
1434 NEXT_PASS (pass_lower_subreg);
6fb5fa3c 1435 NEXT_PASS (pass_df_initialize_opt);
f1bd2543
JH
1436 NEXT_PASS (pass_cse);
1437 NEXT_PASS (pass_rtl_fwprop);
5f39ad47
SB
1438 NEXT_PASS (pass_rtl_cprop);
1439 NEXT_PASS (pass_rtl_pre);
1440 NEXT_PASS (pass_rtl_hoist);
1441 NEXT_PASS (pass_rtl_cprop);
1442 NEXT_PASS (pass_rtl_store_motion);
1443 NEXT_PASS (pass_cse_after_global_opts);
f1bd2543 1444 NEXT_PASS (pass_rtl_ifcvt);
1833192f 1445 NEXT_PASS (pass_reginfo_init);
f1bd2543
JH
1446 /* Perform loop optimizations. It might be better to do them a bit
1447 sooner, but we want the profile feedback to work more
1448 efficiently. */
1449 NEXT_PASS (pass_loop2);
1450 {
8ddbbcae 1451 struct opt_pass **p = &pass_loop2.pass.sub;
f1bd2543
JH
1452 NEXT_PASS (pass_rtl_loop_init);
1453 NEXT_PASS (pass_rtl_move_loop_invariants);
1454 NEXT_PASS (pass_rtl_unswitch);
1455 NEXT_PASS (pass_rtl_unroll_and_peel_loops);
1456 NEXT_PASS (pass_rtl_doloop);
1457 NEXT_PASS (pass_rtl_loop_done);
1458 *p = NULL;
1459 }
1460 NEXT_PASS (pass_web);
5f39ad47 1461 NEXT_PASS (pass_rtl_cprop);
f1bd2543 1462 NEXT_PASS (pass_cse2);
6fb5fa3c 1463 NEXT_PASS (pass_rtl_dse1);
f1bd2543 1464 NEXT_PASS (pass_rtl_fwprop_addr);
6fb5fa3c
DB
1465 NEXT_PASS (pass_inc_dec);
1466 NEXT_PASS (pass_initialize_regs);
6fb5fa3c 1467 NEXT_PASS (pass_ud_rtl_dce);
f1bd2543
JH
1468 NEXT_PASS (pass_combine);
1469 NEXT_PASS (pass_if_after_combine);
1470 NEXT_PASS (pass_partition_blocks);
1471 NEXT_PASS (pass_regmove);
d25aa7ab 1472 NEXT_PASS (pass_outof_cfg_layout_mode);
f1bd2543
JH
1473 NEXT_PASS (pass_split_all_insns);
1474 NEXT_PASS (pass_lower_subreg2);
6fb5fa3c
DB
1475 NEXT_PASS (pass_df_initialize_no_opt);
1476 NEXT_PASS (pass_stack_ptr_mod);
f1bd2543 1477 NEXT_PASS (pass_mode_switching);
d8d72314 1478 NEXT_PASS (pass_match_asm_constraints);
f1bd2543 1479 NEXT_PASS (pass_sms);
ce18efcb 1480 NEXT_PASS (pass_sched);
058e97ec 1481 NEXT_PASS (pass_ira);
f1bd2543
JH
1482 NEXT_PASS (pass_postreload);
1483 {
8ddbbcae 1484 struct opt_pass **p = &pass_postreload.pass.sub;
f1bd2543
JH
1485 NEXT_PASS (pass_postreload_cse);
1486 NEXT_PASS (pass_gcse2);
6fb5fa3c 1487 NEXT_PASS (pass_split_after_reload);
87a0ebfd 1488 NEXT_PASS (pass_implicit_zee);
e692f276 1489 NEXT_PASS (pass_compare_elim_after_reload);
6fb5fa3c
DB
1490 NEXT_PASS (pass_branch_target_load_optimize1);
1491 NEXT_PASS (pass_thread_prologue_and_epilogue);
1492 NEXT_PASS (pass_rtl_dse2);
f1bd2543
JH
1493 NEXT_PASS (pass_stack_adjustments);
1494 NEXT_PASS (pass_peephole2);
1495 NEXT_PASS (pass_if_after_reload);
1496 NEXT_PASS (pass_regrename);
6fb5fa3c
DB
1497 NEXT_PASS (pass_cprop_hardreg);
1498 NEXT_PASS (pass_fast_rtl_dce);
f1bd2543 1499 NEXT_PASS (pass_reorder_blocks);
6fb5fa3c 1500 NEXT_PASS (pass_branch_target_load_optimize2);
f1bd2543 1501 NEXT_PASS (pass_leaf_regs);
6fb5fa3c 1502 NEXT_PASS (pass_split_before_sched2);
f1bd2543 1503 NEXT_PASS (pass_sched2);
f1bd2543 1504 NEXT_PASS (pass_stack_regs);
6fb5fa3c 1505 {
8ddbbcae 1506 struct opt_pass **p = &pass_stack_regs.pass.sub;
6fb5fa3c
DB
1507 NEXT_PASS (pass_split_before_regstack);
1508 NEXT_PASS (pass_stack_regs_run);
1509 }
f1bd2543
JH
1510 NEXT_PASS (pass_compute_alignments);
1511 NEXT_PASS (pass_duplicate_computed_gotos);
1512 NEXT_PASS (pass_variable_tracking);
1513 NEXT_PASS (pass_free_cfg);
1514 NEXT_PASS (pass_machine_reorg);
1515 NEXT_PASS (pass_cleanup_barriers);
1516 NEXT_PASS (pass_delay_slots);
1517 NEXT_PASS (pass_split_for_shorten_branches);
1518 NEXT_PASS (pass_convert_to_eh_region_ranges);
1519 NEXT_PASS (pass_shorten_branches);
1520 NEXT_PASS (pass_set_nothrow_function_flags);
7644b3c7 1521 NEXT_PASS (pass_dwarf2_frame);
f1bd2543
JH
1522 NEXT_PASS (pass_final);
1523 }
0b738568 1524 NEXT_PASS (pass_df_finish);
f1bd2543 1525 }
ef330312
PB
1526 NEXT_PASS (pass_clean_state);
1527 *p = NULL;
1528
ef330312
PB
1529#undef NEXT_PASS
1530
1531 /* Register the passes with the tree dump code. */
9e016eba 1532 register_dump_files (all_lowering_passes, PROP_gimple_any);
b8698a0f 1533 register_dump_files (all_small_ipa_passes,
d7f09764
DN
1534 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
1535 | PROP_cfg);
b8698a0f 1536 register_dump_files (all_regular_ipa_passes,
d7f09764
DN
1537 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
1538 | PROP_cfg);
b8698a0f 1539 register_dump_files (all_lto_gen_passes,
bbbe4e7b
PB
1540 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
1541 | PROP_cfg);
febb1302
JH
1542 register_dump_files (all_late_ipa_passes,
1543 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
1544 | PROP_cfg);
b8698a0f 1545 register_dump_files (all_passes,
bbbe4e7b
PB
1546 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
1547 | PROP_cfg);
ef330312
PB
1548}
1549
a5093353
JH
1550/* If we are in IPA mode (i.e., current_function_decl is NULL), call
1551 function CALLBACK for every function in the call graph. Otherwise,
b8698a0f 1552 call CALLBACK on the current function. */
bbbe4e7b 1553
ef330312 1554static void
a5093353 1555do_per_function (void (*callback) (void *data), void *data)
ef330312 1556{
a5093353
JH
1557 if (current_function_decl)
1558 callback (data);
1559 else
1560 {
1561 struct cgraph_node *node;
1562 for (node = cgraph_nodes; node; node = node->next)
21ecdec5
JH
1563 if (node->analyzed && gimple_has_body_p (node->decl)
1564 && (!node->clone_of || node->decl != node->clone_of->decl))
a5093353
JH
1565 {
1566 push_cfun (DECL_STRUCT_FUNCTION (node->decl));
1567 current_function_decl = node->decl;
1568 callback (data);
d7f09764
DN
1569 if (!flag_wpa)
1570 {
1571 free_dominance_info (CDI_DOMINATORS);
1572 free_dominance_info (CDI_POST_DOMINATORS);
1573 }
a5093353
JH
1574 current_function_decl = NULL;
1575 pop_cfun ();
1576 ggc_collect ();
1577 }
1578 }
1579}
1580
873aa8f5
JH
1581/* Because inlining might remove no-longer reachable nodes, we need to
1582 keep the array visible to garbage collector to avoid reading collected
1583 out nodes. */
1584static int nnodes;
a9429e29 1585static GTY ((length ("nnodes"))) cgraph_node_ptr *order;
873aa8f5
JH
1586
1587/* If we are in IPA mode (i.e., current_function_decl is NULL), call
1588 function CALLBACK for every function in the call graph. Otherwise,
090fa0ab
GF
1589 call CALLBACK on the current function.
1590 This function is global so that plugins can use it. */
1591void
873aa8f5
JH
1592do_per_function_toporder (void (*callback) (void *data), void *data)
1593{
1594 int i;
1595
1596 if (current_function_decl)
1597 callback (data);
1598 else
1599 {
1600 gcc_assert (!order);
a9429e29 1601 order = ggc_alloc_vec_cgraph_node_ptr (cgraph_n_nodes);
af8bca3c 1602 nnodes = ipa_reverse_postorder (order);
257eb6e3
JH
1603 for (i = nnodes - 1; i >= 0; i--)
1604 order[i]->process = 1;
873aa8f5
JH
1605 for (i = nnodes - 1; i >= 0; i--)
1606 {
1607 struct cgraph_node *node = order[i];
1608
1609 /* Allow possibly removed nodes to be garbage collected. */
1610 order[i] = NULL;
257eb6e3 1611 node->process = 0;
c47d0034 1612 if (cgraph_function_with_gimple_body_p (node))
873aa8f5
JH
1613 {
1614 push_cfun (DECL_STRUCT_FUNCTION (node->decl));
1615 current_function_decl = node->decl;
1616 callback (data);
1617 free_dominance_info (CDI_DOMINATORS);
1618 free_dominance_info (CDI_POST_DOMINATORS);
1619 current_function_decl = NULL;
1620 pop_cfun ();
1621 ggc_collect ();
1622 }
1623 }
1624 }
1625 ggc_free (order);
1626 order = NULL;
1627 nnodes = 0;
1628}
1629
22c5fa5f
DL
1630/* Helper function to perform function body dump. */
1631
1632static void
1633execute_function_dump (void *data ATTRIBUTE_UNUSED)
1634{
1635 if (dump_file && current_function_decl)
1636 {
1637 if (cfun->curr_properties & PROP_trees)
1638 dump_function_to_file (current_function_decl, dump_file, dump_flags);
1639 else
1640 {
1641 if (dump_flags & TDF_SLIM)
1642 print_rtl_slim_with_bb (dump_file, get_insns (), dump_flags);
1643 else if ((cfun->curr_properties & PROP_cfg)
1644 && (dump_flags & TDF_BLOCKS))
1645 print_rtl_with_bb (dump_file, get_insns ());
1646 else
1647 print_rtl (dump_file, get_insns ());
1648
1649 if ((cfun->curr_properties & PROP_cfg)
1650 && graph_dump_format != no_graph
1651 && (dump_flags & TDF_GRAPH))
1652 print_rtl_graph_with_bb (dump_file_name, get_insns ());
1653 }
1654
1655 /* Flush the file. If verification fails, we won't be able to
1656 close the file before aborting. */
1657 fflush (dump_file);
1658 }
1659}
1660
a5093353 1661/* Perform all TODO actions that ought to be done on each function. */
ef330312 1662
a5093353
JH
1663static void
1664execute_function_todo (void *data)
1665{
1666 unsigned int flags = (size_t)data;
a5093353 1667 flags &= ~cfun->last_verified;
bbbe4e7b
PB
1668 if (!flags)
1669 return;
9fe0cb7d 1670
1994bfea 1671 /* Always cleanup the CFG before trying to update SSA. */
ef330312
PB
1672 if (flags & TODO_cleanup_cfg)
1673 {
592c303d 1674 bool cleanup = cleanup_tree_cfg ();
c4f548b8 1675
1994bfea
JH
1676 if (cleanup && (cfun->curr_properties & PROP_ssa))
1677 flags |= TODO_remove_unused_locals;
b8698a0f 1678
c4f548b8
DN
1679 /* When cleanup_tree_cfg merges consecutive blocks, it may
1680 perform some simplistic propagation when removing single
1681 valued PHI nodes. This propagation may, in turn, cause the
1682 SSA form to become out-of-date (see PR 22037). So, even
1683 if the parent pass had not scheduled an SSA update, we may
1684 still need to do one. */
5006671f 1685 if (!(flags & TODO_update_ssa_any) && need_ssa_update_p (cfun))
c4f548b8 1686 flags |= TODO_update_ssa;
ef330312 1687 }
f6db1481 1688
563cb6be
DN
1689 if (flags & TODO_update_ssa_any)
1690 {
1691 unsigned update_flags = flags & TODO_update_ssa_any;
1692 update_ssa (update_flags);
a5093353 1693 cfun->last_verified &= ~TODO_verify_ssa;
563cb6be 1694 }
b8698a0f 1695
7b0e48fb
DB
1696 if (flags & TODO_rebuild_alias)
1697 {
f61c8291 1698 execute_update_addresses_taken ();
7b0e48fb 1699 compute_may_aliases ();
7b0e48fb 1700 }
f61c8291
EB
1701 else if (optimize && (flags & TODO_update_address_taken))
1702 execute_update_addresses_taken ();
b8698a0f 1703
3f519b35
RG
1704 if (flags & TODO_remove_unused_locals)
1705 remove_unused_locals ();
1706
45a80bb9 1707 if (flags & TODO_rebuild_frequencies)
b35366ce 1708 rebuild_frequencies ();
45a80bb9 1709
cf9712cc
JH
1710 if (flags & TODO_rebuild_cgraph_edges)
1711 rebuild_cgraph_edges ();
1712
c9d6130e
RG
1713 /* If we've seen errors do not bother running any verifiers. */
1714 if (seen_error ())
1715 return;
1716
a5093353 1717#if defined ENABLE_CHECKING
a3b9e73c
SP
1718 if (flags & TODO_verify_ssa
1719 || (current_loops && loops_state_satisfies_p (LOOP_CLOSED_SSA)))
a5093353
JH
1720 verify_ssa (true);
1721 if (flags & TODO_verify_flow)
1722 verify_flow_info ();
1723 if (flags & TODO_verify_stmts)
34019e28 1724 verify_gimple_in_cfg (cfun);
98b6e9dd 1725 if (current_loops && loops_state_satisfies_p (LOOP_CLOSED_SSA))
a3b9e73c 1726 verify_loop_closed_ssa (false);
a36b8a1e
JH
1727 if (flags & TODO_verify_rtl_sharing)
1728 verify_rtl_sharing ();
a5093353
JH
1729#endif
1730
1731 cfun->last_verified = flags & TODO_verify_all;
1732}
1733
1734/* Perform all TODO actions. */
1735static void
1736execute_todo (unsigned int flags)
1737{
1738#if defined ENABLE_CHECKING
5006671f
RG
1739 if (cfun
1740 && need_ssa_update_p (cfun))
a5093353
JH
1741 gcc_assert (flags & TODO_update_ssa_any);
1742#endif
1743
a222c01a
MM
1744 timevar_push (TV_TODO);
1745
b02b9b53
ZD
1746 /* Inform the pass whether it is the first time it is run. */
1747 first_pass_instance = (flags & TODO_mark_first_instance) != 0;
1748
0d6a035d
JH
1749 statistics_fini_pass ();
1750
a5093353
JH
1751 do_per_function (execute_function_todo, (void *)(size_t) flags);
1752
f4b3ca72
JH
1753 /* Always remove functions just as before inlining: IPA passes might be
1754 interested to see bodies of extern inline functions that are not inlined
1755 to analyze side effects. The full removal is done just at the end
1756 of IPA pass queue. */
1757 if (flags & TODO_remove_functions)
a12f79f5
JH
1758 {
1759 gcc_assert (!cfun);
1760 cgraph_remove_unreachable_nodes (true, dump_file);
1761 }
f4b3ca72 1762
726a989a 1763 if ((flags & TODO_dump_cgraph) && dump_file && !current_function_decl)
ef330312 1764 {
a12f79f5 1765 gcc_assert (!cfun);
ef330312
PB
1766 dump_cgraph (dump_file);
1767 /* Flush the file. If verification fails, we won't be able to
1768 close the file before aborting. */
1769 fflush (dump_file);
1770 }
f6db1481 1771
ef330312 1772 if (flags & TODO_ggc_collect)
726a989a 1773 ggc_collect ();
6fb5fa3c 1774
b8698a0f 1775 /* Now that the dumping has been done, we can get rid of the optional
6fb5fa3c
DB
1776 df problems. */
1777 if (flags & TODO_df_finish)
0d475361 1778 df_finish_pass ((flags & TODO_df_verify) != 0);
a222c01a
MM
1779
1780 timevar_pop (TV_TODO);
a5093353 1781}
97b0ade3 1782
6ac01510
ILT
1783/* Verify invariants that should hold between passes. This is a place
1784 to put simple sanity checks. */
1785
1786static void
1787verify_interpass_invariants (void)
1788{
77a74ed7 1789 gcc_checking_assert (!fold_deferring_overflow_warnings_p ());
6ac01510
ILT
1790}
1791
a5093353
JH
1792/* Clear the last verified flag. */
1793
1794static void
1795clear_last_verified (void *data ATTRIBUTE_UNUSED)
1796{
1797 cfun->last_verified = 0;
1798}
1799
1800/* Helper function. Verify that the properties has been turn into the
1801 properties expected by the pass. */
bbbe4e7b 1802
582fd9ce 1803#ifdef ENABLE_CHECKING
a5093353
JH
1804static void
1805verify_curr_properties (void *data)
1806{
1807 unsigned int props = (size_t)data;
1808 gcc_assert ((cfun->curr_properties & props) == props);
1809}
582fd9ce 1810#endif
a5093353 1811
17653c00 1812/* Initialize pass dump file. */
090fa0ab 1813/* This is non-static so that the plugins can use it. */
17653c00 1814
090fa0ab 1815bool
17653c00
JH
1816pass_init_dump_file (struct opt_pass *pass)
1817{
1818 /* If a dump file name is present, open it if enabled. */
1819 if (pass->static_pass_number != -1)
1820 {
1821 bool initializing_dump = !dump_initialized_p (pass->static_pass_number);
1822 dump_file_name = get_dump_file_name (pass->static_pass_number);
1823 dump_file = dump_begin (pass->static_pass_number, &dump_flags);
1824 if (dump_file && current_function_decl)
6d8402ac 1825 dump_function_header (dump_file, current_function_decl, dump_flags);
17653c00
JH
1826 return initializing_dump;
1827 }
1828 else
1829 return false;
1830}
1831
1832/* Flush PASS dump file. */
090fa0ab 1833/* This is non-static so that plugins can use it. */
17653c00 1834
090fa0ab 1835void
17653c00
JH
1836pass_fini_dump_file (struct opt_pass *pass)
1837{
1838 /* Flush and close dump file. */
1839 if (dump_file_name)
1840 {
1841 free (CONST_CAST (char *, dump_file_name));
1842 dump_file_name = NULL;
1843 }
1844
1845 if (dump_file)
1846 {
1847 dump_end (pass->static_pass_number, dump_file);
1848 dump_file = NULL;
1849 }
1850}
1851
a5093353
JH
1852/* After executing the pass, apply expected changes to the function
1853 properties. */
17653c00 1854
a5093353
JH
1855static void
1856update_properties_after_pass (void *data)
1857{
d3bfe4de 1858 struct opt_pass *pass = (struct opt_pass *) data;
a5093353
JH
1859 cfun->curr_properties = (cfun->curr_properties | pass->properties_provided)
1860 & ~pass->properties_destroyed;
f6db1481
RH
1861}
1862
1920df6c 1863/* Execute summary generation for all of the passes in IPA_PASS. */
17653c00 1864
d7f09764 1865void
7e5487a2 1866execute_ipa_summary_passes (struct ipa_opt_pass_d *ipa_pass)
17653c00 1867{
1920df6c 1868 while (ipa_pass)
17653c00
JH
1869 {
1870 struct opt_pass *pass = &ipa_pass->pass;
1920df6c
KZ
1871
1872 /* Execute all of the IPA_PASSes in the list. */
b8698a0f 1873 if (ipa_pass->pass.type == IPA_PASS
d7f09764
DN
1874 && (!pass->gate || pass->gate ())
1875 && ipa_pass->generate_summary)
17653c00
JH
1876 {
1877 pass_init_dump_file (pass);
d7f09764
DN
1878
1879 /* If a timevar is present, start it. */
1880 if (pass->tv_id)
1881 timevar_push (pass->tv_id);
1882
1920df6c 1883 ipa_pass->generate_summary ();
d7f09764
DN
1884
1885 /* Stop timevar. */
1886 if (pass->tv_id)
1887 timevar_pop (pass->tv_id);
1888
17653c00
JH
1889 pass_fini_dump_file (pass);
1890 }
7e5487a2 1891 ipa_pass = (struct ipa_opt_pass_d *)ipa_pass->pass.next;
17653c00
JH
1892 }
1893}
1894
1895/* Execute IPA_PASS function transform on NODE. */
1896
1897static void
1898execute_one_ipa_transform_pass (struct cgraph_node *node,
7e5487a2 1899 struct ipa_opt_pass_d *ipa_pass)
17653c00
JH
1900{
1901 struct opt_pass *pass = &ipa_pass->pass;
1902 unsigned int todo_after = 0;
1903
1904 current_pass = pass;
1905 if (!ipa_pass->function_transform)
1906 return;
1907
1908 /* Note that the folders should only create gimple expressions.
1909 This is a hack until the new folder is ready. */
1910 in_gimple_form = (cfun && (cfun->curr_properties & PROP_trees)) != 0;
1911
1912 pass_init_dump_file (pass);
1913
1914 /* Run pre-pass verification. */
a12f79f5 1915 execute_todo (ipa_pass->function_transform_todo_flags_start);
17653c00
JH
1916
1917 /* If a timevar is present, start it. */
7072a650 1918 if (pass->tv_id != TV_NONE)
17653c00
JH
1919 timevar_push (pass->tv_id);
1920
1921 /* Do it! */
1922 todo_after = ipa_pass->function_transform (node);
1923
1924 /* Stop timevar. */
7072a650 1925 if (pass->tv_id != TV_NONE)
17653c00
JH
1926 timevar_pop (pass->tv_id);
1927
1928 /* Run post-pass cleanup and verification. */
1929 execute_todo (todo_after);
1930 verify_interpass_invariants ();
1931
22c5fa5f 1932 do_per_function (execute_function_dump, NULL);
17653c00
JH
1933 pass_fini_dump_file (pass);
1934
1935 current_pass = NULL;
17653c00
JH
1936}
1937
d7f09764 1938/* For the current function, execute all ipa transforms. */
9e016eba 1939
d7f09764
DN
1940void
1941execute_all_ipa_transforms (void)
1942{
0e3776db
JH
1943 struct cgraph_node *node;
1944 if (!cfun)
1945 return;
581985d7 1946 node = cgraph_get_node (current_function_decl);
bc58d7e1 1947
0e3776db 1948 if (node->ipa_transforms_to_apply)
17653c00
JH
1949 {
1950 unsigned int i;
17653c00 1951
0e3776db 1952 for (i = 0; i < VEC_length (ipa_opt_pass, node->ipa_transforms_to_apply);
17653c00
JH
1953 i++)
1954 execute_one_ipa_transform_pass (node,
d7f09764 1955 VEC_index (ipa_opt_pass,
0e3776db 1956 node->ipa_transforms_to_apply,
17653c00 1957 i));
0e3776db
JH
1958 VEC_free (ipa_opt_pass, heap, node->ipa_transforms_to_apply);
1959 node->ipa_transforms_to_apply = NULL;
17653c00 1960 }
d7f09764
DN
1961}
1962
febb1302
JH
1963/* Callback for do_per_function to apply all IPA transforms. */
1964
1965static void
1966apply_ipa_transforms (void *data)
1967{
1968 struct cgraph_node *node = cgraph_get_node (current_function_decl);
1969 if (!node->global.inlined_to && node->ipa_transforms_to_apply)
1970 {
1971 *(bool *)data = true;
1972 execute_all_ipa_transforms();
1973 rebuild_cgraph_edges ();
1974 }
1975}
1976
226c52aa
XDL
1977/* Check if PASS is explicitly disabled or enabled and return
1978 the gate status. FUNC is the function to be processed, and
1979 GATE_STATUS is the gate status determined by pass manager by
1980 default. */
1981
1982static bool
1983override_gate_status (struct opt_pass *pass, tree func, bool gate_status)
1984{
1985 bool explicitly_enabled = false;
1986 bool explicitly_disabled = false;
1987
1988 explicitly_enabled
1989 = is_pass_explicitly_enabled_or_disabled (pass, func,
1990 enabled_pass_uid_range_tab);
1991 explicitly_disabled
1992 = is_pass_explicitly_enabled_or_disabled (pass, func,
1993 disabled_pass_uid_range_tab);
1994
1995 gate_status = !explicitly_disabled && (gate_status || explicitly_enabled);
1996
1997 return gate_status;
1998}
1999
2000
d7f09764
DN
2001/* Execute PASS. */
2002
090fa0ab 2003bool
d7f09764
DN
2004execute_one_pass (struct opt_pass *pass)
2005{
2006 bool initializing_dump;
2007 unsigned int todo_after = 0;
2008
090fa0ab
GF
2009 bool gate_status;
2010
d7f09764
DN
2011 /* IPA passes are executed on whole program, so cfun should be NULL.
2012 Other passes need function context set. */
2013 if (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS)
2014 gcc_assert (!cfun && !current_function_decl);
2015 else
2016 gcc_assert (cfun && current_function_decl);
17653c00 2017
6fb5fa3c 2018 current_pass = pass;
726a989a 2019
090fa0ab
GF
2020 /* Check whether gate check should be avoided.
2021 User controls the value of the gate through the parameter "gate_status". */
2022 gate_status = (pass->gate == NULL) ? true : pass->gate();
226c52aa 2023 gate_status = override_gate_status (pass, current_function_decl, gate_status);
090fa0ab
GF
2024
2025 /* Override gate with plugin. */
2026 invoke_plugin_callbacks (PLUGIN_OVERRIDE_GATE, &gate_status);
2027
2028 if (!gate_status)
2029 {
2030 current_pass = NULL;
2031 return false;
2032 }
2033
2034 /* Pass execution event trigger: useful to identify passes being
2035 executed. */
2036 invoke_plugin_callbacks (PLUGIN_PASS_EXECUTION, pass);
f6db1481 2037
febb1302
JH
2038 /* SIPLE IPA passes do not handle callgraphs with IPA transforms in it.
2039 Apply all trnasforms first. */
2040 if (pass->type == SIMPLE_IPA_PASS)
2041 {
2042 bool applied = false;
2043 do_per_function (apply_ipa_transforms, (void *)&applied);
2044 if (applied)
2045 cgraph_remove_unreachable_nodes (true, dump_file);
1c86160a
RG
2046 /* Restore current_pass. */
2047 current_pass = pass;
febb1302
JH
2048 }
2049
b9cafe60 2050 if (!quiet_flag && !cfun)
873aa8f5
JH
2051 fprintf (stderr, " <%s>", pass->name ? pass->name : "");
2052
ef330312
PB
2053 /* Note that the folders should only create gimple expressions.
2054 This is a hack until the new folder is ready. */
a5093353 2055 in_gimple_form = (cfun && (cfun->curr_properties & PROP_trees)) != 0;
f6db1481 2056
5006671f
RG
2057 initializing_dump = pass_init_dump_file (pass);
2058
ef330312 2059 /* Run pre-pass verification. */
bbbe4e7b
PB
2060 execute_todo (pass->todo_flags_start);
2061
a5093353
JH
2062#ifdef ENABLE_CHECKING
2063 do_per_function (verify_curr_properties,
2064 (void *)(size_t)pass->properties_required);
2065#endif
f6db1481 2066
ef330312 2067 /* If a timevar is present, start it. */
7072a650 2068 if (pass->tv_id != TV_NONE)
ef330312 2069 timevar_push (pass->tv_id);
f6db1481 2070
ef330312
PB
2071 /* Do it! */
2072 if (pass->execute)
bbbe4e7b 2073 {
c2924966 2074 todo_after = pass->execute ();
a5093353 2075 do_per_function (clear_last_verified, NULL);
bbbe4e7b 2076 }
f6db1481 2077
ef330312 2078 /* Stop timevar. */
7072a650 2079 if (pass->tv_id != TV_NONE)
ef330312 2080 timevar_pop (pass->tv_id);
f6db1481 2081
a5093353 2082 do_per_function (update_properties_after_pass, pass);
bbbe4e7b
PB
2083
2084 if (initializing_dump
2085 && dump_file
2086 && graph_dump_format != no_graph
6f1fe305 2087 && cfun
a5093353
JH
2088 && (cfun->curr_properties & (PROP_cfg | PROP_rtl))
2089 == (PROP_cfg | PROP_rtl))
bbbe4e7b
PB
2090 {
2091 get_dump_file_info (pass->static_pass_number)->flags |= TDF_GRAPH;
2092 dump_flags |= TDF_GRAPH;
2093 clean_graph_dump_file (dump_file_name);
2094 }
2095
ef330312 2096 /* Run post-pass cleanup and verification. */
c2924966 2097 execute_todo (todo_after | pass->todo_flags_finish);
6ac01510 2098 verify_interpass_invariants ();
22c5fa5f 2099 do_per_function (execute_function_dump, NULL);
17653c00 2100 if (pass->type == IPA_PASS)
0e3776db
JH
2101 {
2102 struct cgraph_node *node;
c47d0034
JH
2103 FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node)
2104 VEC_safe_push (ipa_opt_pass, heap, node->ipa_transforms_to_apply,
2105 (struct ipa_opt_pass_d *)pass);
0e3776db 2106 }
f6db1481 2107
f45e0ad1
JH
2108 if (!current_function_decl)
2109 cgraph_process_new_functions ();
2110
17653c00 2111 pass_fini_dump_file (pass);
f6db1481 2112
17653c00 2113 if (pass->type != SIMPLE_IPA_PASS && pass->type != IPA_PASS)
e3b5732b
JH
2114 gcc_assert (!(cfun->curr_properties & PROP_trees)
2115 || pass->type != RTL_PASS);
2116
6fb5fa3c 2117 current_pass = NULL;
91851351 2118
ef330312 2119 return true;
f6db1481
RH
2120}
2121
ef330312 2122void
8ddbbcae 2123execute_pass_list (struct opt_pass *pass)
f6db1481 2124{
ef330312 2125 do
f6db1481 2126 {
9e016eba
JH
2127 gcc_assert (pass->type == GIMPLE_PASS
2128 || pass->type == RTL_PASS);
ef330312
PB
2129 if (execute_one_pass (pass) && pass->sub)
2130 execute_pass_list (pass->sub);
2131 pass = pass->next;
f6db1481 2132 }
ef330312 2133 while (pass);
f6db1481
RH
2134}
2135
ef330312 2136/* Same as execute_pass_list but assume that subpasses of IPA passes
d7f09764
DN
2137 are local passes. If SET is not NULL, write out summaries of only
2138 those node in SET. */
2139
2140static void
2141ipa_write_summaries_2 (struct opt_pass *pass, cgraph_node_set set,
2942c502 2142 varpool_node_set vset,
d7f09764
DN
2143 struct lto_out_decl_state *state)
2144{
2145 while (pass)
2146 {
2147 struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *)pass;
2148 gcc_assert (!current_function_decl);
2149 gcc_assert (!cfun);
2150 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
2151 if (pass->type == IPA_PASS
2152 && ipa_pass->write_summary
2153 && (!pass->gate || pass->gate ()))
2154 {
2155 /* If a timevar is present, start it. */
2156 if (pass->tv_id)
2157 timevar_push (pass->tv_id);
2158
f59292da
JH
2159 pass_init_dump_file (pass);
2160
2942c502 2161 ipa_pass->write_summary (set,vset);
d7f09764 2162
f59292da
JH
2163 pass_fini_dump_file (pass);
2164
d7f09764
DN
2165 /* If a timevar is present, start it. */
2166 if (pass->tv_id)
2167 timevar_pop (pass->tv_id);
2168 }
2169
2170 if (pass->sub && pass->sub->type != GIMPLE_PASS)
2942c502 2171 ipa_write_summaries_2 (pass->sub, set, vset, state);
d7f09764
DN
2172
2173 pass = pass->next;
2174 }
2175}
2176
2177/* Helper function of ipa_write_summaries. Creates and destroys the
2178 decl state and calls ipa_write_summaries_2 for all passes that have
2179 summaries. SET is the set of nodes to be written. */
2180
2181static void
2942c502 2182ipa_write_summaries_1 (cgraph_node_set set, varpool_node_set vset)
d7f09764
DN
2183{
2184 struct lto_out_decl_state *state = lto_new_out_decl_state ();
f3380641 2185 compute_ltrans_boundary (state, set, vset);
5c4f225f 2186
d7f09764
DN
2187 lto_push_out_decl_state (state);
2188
e792884f 2189 gcc_assert (!flag_wpa);
2942c502
JH
2190 ipa_write_summaries_2 (all_regular_ipa_passes, set, vset, state);
2191 ipa_write_summaries_2 (all_lto_gen_passes, set, vset, state);
d7f09764
DN
2192
2193 gcc_assert (lto_get_out_decl_state () == state);
2194 lto_pop_out_decl_state ();
2195 lto_delete_out_decl_state (state);
2196}
2197
2198/* Write out summaries for all the nodes in the callgraph. */
2199
ef330312 2200void
d7f09764 2201ipa_write_summaries (void)
f6db1481 2202{
d7f09764 2203 cgraph_node_set set;
2942c502 2204 varpool_node_set vset;
d7f09764 2205 struct cgraph_node **order;
2942c502 2206 struct varpool_node *vnode;
d7f09764 2207 int i, order_pos;
b8698a0f 2208
1da2ed5f 2209 if (!flag_generate_lto || seen_error ())
d7f09764
DN
2210 return;
2211
d7f09764
DN
2212 set = cgraph_node_set_new ();
2213
2214 /* Create the callgraph set in the same order used in
2215 cgraph_expand_all_functions. This mostly facilitates debugging,
2216 since it causes the gimple file to be processed in the same order
2217 as the source code. */
2218 order = XCNEWVEC (struct cgraph_node *, cgraph_n_nodes);
af8bca3c 2219 order_pos = ipa_reverse_postorder (order);
d7f09764
DN
2220 gcc_assert (order_pos == cgraph_n_nodes);
2221
2222 for (i = order_pos - 1; i >= 0; i--)
8b220502
MJ
2223 {
2224 struct cgraph_node *node = order[i];
2225
c47d0034 2226 if (cgraph_function_with_gimple_body_p (node))
8b220502
MJ
2227 {
2228 /* When streaming out references to statements as part of some IPA
2229 pass summary, the statements need to have uids assigned and the
2230 following does that for all the IPA passes here. Naturally, this
2231 ordering then matches the one IPA-passes get in their stmt_fixup
2232 hooks. */
2233
2234 push_cfun (DECL_STRUCT_FUNCTION (node->decl));
2235 renumber_gimple_stmt_uids ();
2236 pop_cfun ();
2237 }
9b3cf76a 2238 if (node->analyzed)
c47d0034 2239 cgraph_node_set_add (set, node);
8b220502 2240 }
2942c502 2241 vset = varpool_node_set_new ();
d7f09764 2242
2942c502 2243 for (vnode = varpool_nodes; vnode; vnode = vnode->next)
3bd72190 2244 if (vnode->needed && (!vnode->alias || vnode->alias_of))
2942c502
JH
2245 varpool_node_set_add (vset, vnode);
2246
2247 ipa_write_summaries_1 (set, vset);
d7f09764
DN
2248
2249 free (order);
1cb1a99f
JH
2250 free_cgraph_node_set (set);
2251 free_varpool_node_set (vset);
d7f09764
DN
2252}
2253
e792884f
JH
2254/* Same as execute_pass_list but assume that subpasses of IPA passes
2255 are local passes. If SET is not NULL, write out optimization summaries of
2256 only those node in SET. */
d7f09764 2257
e792884f
JH
2258static void
2259ipa_write_optimization_summaries_1 (struct opt_pass *pass, cgraph_node_set set,
2942c502 2260 varpool_node_set vset,
e792884f
JH
2261 struct lto_out_decl_state *state)
2262{
2263 while (pass)
2264 {
2265 struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *)pass;
2266 gcc_assert (!current_function_decl);
2267 gcc_assert (!cfun);
2268 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
2269 if (pass->type == IPA_PASS
2270 && ipa_pass->write_optimization_summary
2271 && (!pass->gate || pass->gate ()))
2272 {
2273 /* If a timevar is present, start it. */
2274 if (pass->tv_id)
2275 timevar_push (pass->tv_id);
2276
f59292da
JH
2277 pass_init_dump_file (pass);
2278
2942c502 2279 ipa_pass->write_optimization_summary (set, vset);
e792884f 2280
f59292da
JH
2281 pass_fini_dump_file (pass);
2282
e792884f
JH
2283 /* If a timevar is present, start it. */
2284 if (pass->tv_id)
2285 timevar_pop (pass->tv_id);
2286 }
2287
2288 if (pass->sub && pass->sub->type != GIMPLE_PASS)
2942c502 2289 ipa_write_optimization_summaries_1 (pass->sub, set, vset, state);
e792884f
JH
2290
2291 pass = pass->next;
2292 }
2293}
2294
2295/* Write all the optimization summaries for the cgraph nodes in SET. If SET is
d7f09764
DN
2296 NULL, write out all summaries of all nodes. */
2297
2298void
2942c502 2299ipa_write_optimization_summaries (cgraph_node_set set, varpool_node_set vset)
d7f09764 2300{
e792884f 2301 struct lto_out_decl_state *state = lto_new_out_decl_state ();
f1395d4a 2302 cgraph_node_set_iterator csi;
f3380641
JH
2303 compute_ltrans_boundary (state, set, vset);
2304
e792884f 2305 lto_push_out_decl_state (state);
f1395d4a
JH
2306 for (csi = csi_start (set); !csi_end_p (csi); csi_next (&csi))
2307 {
2308 struct cgraph_node *node = csi_node (csi);
2309 /* When streaming out references to statements as part of some IPA
2310 pass summary, the statements need to have uids assigned.
2311
2312 For functions newly born at WPA stage we need to initialize
2313 the uids here. */
2314 if (node->analyzed
2315 && gimple_has_body_p (node->decl))
2316 {
2317 push_cfun (DECL_STRUCT_FUNCTION (node->decl));
2318 renumber_gimple_stmt_uids ();
2319 pop_cfun ();
2320 }
2321 }
e792884f
JH
2322
2323 gcc_assert (flag_wpa);
2942c502
JH
2324 ipa_write_optimization_summaries_1 (all_regular_ipa_passes, set, vset, state);
2325 ipa_write_optimization_summaries_1 (all_lto_gen_passes, set, vset, state);
e792884f
JH
2326
2327 gcc_assert (lto_get_out_decl_state () == state);
2328 lto_pop_out_decl_state ();
2329 lto_delete_out_decl_state (state);
d7f09764
DN
2330}
2331
2332/* Same as execute_pass_list but assume that subpasses of IPA passes
2333 are local passes. */
2334
2335static void
2336ipa_read_summaries_1 (struct opt_pass *pass)
2337{
2338 while (pass)
f6db1481 2339 {
d7f09764
DN
2340 struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *) pass;
2341
a5093353
JH
2342 gcc_assert (!current_function_decl);
2343 gcc_assert (!cfun);
17653c00 2344 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
d7f09764
DN
2345
2346 if (pass->gate == NULL || pass->gate ())
17653c00 2347 {
d7f09764 2348 if (pass->type == IPA_PASS && ipa_pass->read_summary)
17653c00 2349 {
d7f09764
DN
2350 /* If a timevar is present, start it. */
2351 if (pass->tv_id)
2352 timevar_push (pass->tv_id);
2353
f59292da
JH
2354 pass_init_dump_file (pass);
2355
d7f09764
DN
2356 ipa_pass->read_summary ();
2357
f59292da
JH
2358 pass_fini_dump_file (pass);
2359
d7f09764
DN
2360 /* Stop timevar. */
2361 if (pass->tv_id)
2362 timevar_pop (pass->tv_id);
17653c00 2363 }
d7f09764
DN
2364
2365 if (pass->sub && pass->sub->type != GIMPLE_PASS)
2366 ipa_read_summaries_1 (pass->sub);
17653c00 2367 }
d7f09764
DN
2368 pass = pass->next;
2369 }
2370}
2371
2372
2373/* Read all the summaries for all_regular_ipa_passes and all_lto_gen_passes. */
2374
2375void
2376ipa_read_summaries (void)
2377{
e792884f 2378 ipa_read_summaries_1 (all_regular_ipa_passes);
d7f09764
DN
2379 ipa_read_summaries_1 (all_lto_gen_passes);
2380}
2381
e792884f
JH
2382/* Same as execute_pass_list but assume that subpasses of IPA passes
2383 are local passes. */
2384
2385static void
2386ipa_read_optimization_summaries_1 (struct opt_pass *pass)
2387{
2388 while (pass)
2389 {
2390 struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *) pass;
2391
2392 gcc_assert (!current_function_decl);
2393 gcc_assert (!cfun);
2394 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
2395
2396 if (pass->gate == NULL || pass->gate ())
2397 {
2398 if (pass->type == IPA_PASS && ipa_pass->read_optimization_summary)
2399 {
2400 /* If a timevar is present, start it. */
2401 if (pass->tv_id)
2402 timevar_push (pass->tv_id);
2403
f59292da
JH
2404 pass_init_dump_file (pass);
2405
e792884f
JH
2406 ipa_pass->read_optimization_summary ();
2407
f59292da
JH
2408 pass_fini_dump_file (pass);
2409
e792884f
JH
2410 /* Stop timevar. */
2411 if (pass->tv_id)
2412 timevar_pop (pass->tv_id);
2413 }
2414
2415 if (pass->sub && pass->sub->type != GIMPLE_PASS)
2416 ipa_read_optimization_summaries_1 (pass->sub);
2417 }
2418 pass = pass->next;
2419 }
2420}
2421
2422/* Read all the summaries for all_regular_ipa_passes and all_lto_gen_passes. */
2423
2424void
2425ipa_read_optimization_summaries (void)
2426{
2427 ipa_read_optimization_summaries_1 (all_regular_ipa_passes);
2428 ipa_read_optimization_summaries_1 (all_lto_gen_passes);
2429}
2430
d7f09764
DN
2431/* Same as execute_pass_list but assume that subpasses of IPA passes
2432 are local passes. */
2433void
2434execute_ipa_pass_list (struct opt_pass *pass)
2435{
2436 do
2437 {
2438 gcc_assert (!current_function_decl);
2439 gcc_assert (!cfun);
2440 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
ef330312 2441 if (execute_one_pass (pass) && pass->sub)
9e016eba
JH
2442 {
2443 if (pass->sub->type == GIMPLE_PASS)
090fa0ab
GF
2444 {
2445 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_START, NULL);
2446 do_per_function_toporder ((void (*)(void *))execute_pass_list,
2447 pass->sub);
2448 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_END, NULL);
2449 }
17653c00
JH
2450 else if (pass->sub->type == SIMPLE_IPA_PASS
2451 || pass->sub->type == IPA_PASS)
9e016eba
JH
2452 execute_ipa_pass_list (pass->sub);
2453 else
2454 gcc_unreachable ();
2455 }
d7f09764
DN
2456 gcc_assert (!current_function_decl);
2457 cgraph_process_new_functions ();
ef330312 2458 pass = pass->next;
f6db1481 2459 }
ef330312 2460 while (pass);
97b0ade3 2461}
9fe0cb7d 2462
2c5721d9
MJ
2463/* Execute stmt fixup hooks of all passes in PASS for NODE and STMTS. */
2464
2465static void
2466execute_ipa_stmt_fixups (struct opt_pass *pass,
2467 struct cgraph_node *node, gimple *stmts)
2468{
2469 while (pass)
2470 {
2471 /* Execute all of the IPA_PASSes in the list. */
2472 if (pass->type == IPA_PASS
2473 && (!pass->gate || pass->gate ()))
2474 {
2475 struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *) pass;
2476
2477 if (ipa_pass->stmt_fixup)
2478 {
2479 pass_init_dump_file (pass);
2480 /* If a timevar is present, start it. */
2481 if (pass->tv_id)
2482 timevar_push (pass->tv_id);
2483
2484 ipa_pass->stmt_fixup (node, stmts);
2485
2486 /* Stop timevar. */
2487 if (pass->tv_id)
2488 timevar_pop (pass->tv_id);
2489 pass_fini_dump_file (pass);
2490 }
2491 if (pass->sub)
2492 execute_ipa_stmt_fixups (pass->sub, node, stmts);
2493 }
2494 pass = pass->next;
2495 }
2496}
2497
2498/* Execute stmt fixup hooks of all IPA passes for NODE and STMTS. */
2499
2500void
2501execute_all_ipa_stmt_fixups (struct cgraph_node *node, gimple *stmts)
2502{
2503 execute_ipa_stmt_fixups (all_regular_ipa_passes, node, stmts);
2504}
2505
2506
d7f09764
DN
2507extern void debug_properties (unsigned int);
2508extern void dump_properties (FILE *, unsigned int);
2509
24e47c76 2510DEBUG_FUNCTION void
d7f09764
DN
2511dump_properties (FILE *dump, unsigned int props)
2512{
2513 fprintf (dump, "Properties:\n");
2514 if (props & PROP_gimple_any)
2515 fprintf (dump, "PROP_gimple_any\n");
2516 if (props & PROP_gimple_lcf)
2517 fprintf (dump, "PROP_gimple_lcf\n");
2518 if (props & PROP_gimple_leh)
2519 fprintf (dump, "PROP_gimple_leh\n");
2520 if (props & PROP_cfg)
2521 fprintf (dump, "PROP_cfg\n");
2522 if (props & PROP_referenced_vars)
2523 fprintf (dump, "PROP_referenced_vars\n");
2524 if (props & PROP_ssa)
2525 fprintf (dump, "PROP_ssa\n");
2526 if (props & PROP_no_crit_edges)
2527 fprintf (dump, "PROP_no_crit_edges\n");
2528 if (props & PROP_rtl)
2529 fprintf (dump, "PROP_rtl\n");
2530 if (props & PROP_gimple_lomp)
2531 fprintf (dump, "PROP_gimple_lomp\n");
688a482d
RG
2532 if (props & PROP_gimple_lcx)
2533 fprintf (dump, "PROP_gimple_lcx\n");
24e47c76
JH
2534 if (props & PROP_cfglayout)
2535 fprintf (dump, "PROP_cfglayout\n");
d7f09764
DN
2536}
2537
24e47c76 2538DEBUG_FUNCTION void
d7f09764
DN
2539debug_properties (unsigned int props)
2540{
2541 dump_properties (stderr, props);
2542}
2543
33977f81
JH
2544/* Called by local passes to see if function is called by already processed nodes.
2545 Because we process nodes in topological order, this means that function is
2546 in recursive cycle or we introduced new direct calls. */
2547bool
2548function_called_by_processed_nodes_p (void)
2549{
2550 struct cgraph_edge *e;
581985d7
MJ
2551 for (e = cgraph_get_node (current_function_decl)->callers;
2552 e;
2553 e = e->next_caller)
33977f81
JH
2554 {
2555 if (e->caller->decl == current_function_decl)
2556 continue;
c47d0034 2557 if (!cgraph_function_with_gimple_body_p (e->caller))
33977f81
JH
2558 continue;
2559 if (TREE_ASM_WRITTEN (e->caller->decl))
2560 continue;
2561 if (!e->caller->process && !e->caller->global.inlined_to)
2562 break;
2563 }
2564 if (dump_file && e)
2565 {
2566 fprintf (dump_file, "Already processed call to:\n");
2567 dump_cgraph_node (dump_file, e->caller);
2568 }
2569 return e != NULL;
2570}
2571
873aa8f5 2572#include "gt-passes.h"