]>
Commit | Line | Data |
---|---|---|
a49a878f | 1 | /* Top level of GCC compilers (cc1, cc1plus, etc.) |
2 | Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, | |
7cf0dbf3 | 3 | 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 |
1a6a0f2a | 4 | Free Software Foundation, Inc. |
a49a878f | 5 | |
6 | This file is part of GCC. | |
7 | ||
8 | GCC is free software; you can redistribute it and/or modify it under | |
9 | the terms of the GNU General Public License as published by the Free | |
8c4c00c1 | 10 | Software Foundation; either version 3, or (at your option) any later |
a49a878f | 11 | version. |
12 | ||
13 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
14 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 | for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
8c4c00c1 | 19 | along with GCC; see the file COPYING3. If not see |
20 | <http://www.gnu.org/licenses/>. */ | |
a49a878f | 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" | |
a49a878f | 28 | #include "system.h" |
29 | #include "coretypes.h" | |
30 | #include "tm.h" | |
a49a878f | 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" | |
a49a878f | 51 | #include "regs.h" |
52 | #include "timevar.h" | |
852f689e | 53 | #include "diagnostic-core.h" |
a49a878f | 54 | #include "params.h" |
55 | #include "reload.h" | |
56 | #include "dwarf2asm.h" | |
57 | #include "integrate.h" | |
a49a878f | 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" | |
77fce4cd | 68 | #include "tree-inline.h" |
69 | #include "tree-flow.h" | |
5290ebdb | 70 | #include "tree-pass.h" |
0f9005dd | 71 | #include "tree-dump.h" |
3072d30e | 72 | #include "df.h" |
4ae20857 | 73 | #include "predict.h" |
7bfefa9d | 74 | #include "lto-streamer.h" |
c9036234 | 75 | #include "plugin.h" |
a49a878f | 76 | |
77 | #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO) | |
78 | #include "dwarf2out.h" | |
79 | #endif | |
80 | ||
da2f1613 | 81 | #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO) |
a49a878f | 82 | #include "dbxout.h" |
83 | #endif | |
84 | ||
85 | #ifdef SDB_DEBUGGING_INFO | |
86 | #include "sdbout.h" | |
87 | #endif | |
88 | ||
89 | #ifdef XCOFF_DEBUGGING_INFO | |
90 | #include "xcoffout.h" /* Needed for external data | |
91 | declarations for e.g. AIX 4.x. */ | |
92 | #endif | |
93 | ||
3072d30e | 94 | /* This is used for debugging. It allows the current pass to printed |
c9036234 | 95 | from anywhere in compilation. |
96 | The variable current_pass is also used for statistics and plugins. */ | |
20099e35 | 97 | struct opt_pass *current_pass; |
3072d30e | 98 | |
99 | /* Call from anywhere to find out what pass this is. Useful for | |
100 | printing out debugging information deep inside an service | |
101 | routine. */ | |
102 | void | |
103 | print_current_pass (FILE *file) | |
104 | { | |
105 | if (current_pass) | |
48e1416a | 106 | fprintf (file, "current pass = %s (%d)\n", |
3072d30e | 107 | current_pass->name, current_pass->static_pass_number); |
108 | else | |
109 | fprintf (file, "no current pass.\n"); | |
110 | } | |
111 | ||
112 | ||
113 | /* Call from the debugger to get the current pass name. */ | |
4b987fac | 114 | DEBUG_FUNCTION void |
3072d30e | 115 | debug_pass (void) |
116 | { | |
117 | print_current_pass (stderr); | |
48e1416a | 118 | } |
3072d30e | 119 | |
120 | ||
121 | ||
77fce4cd | 122 | /* Global variables used to communicate with passes. */ |
123 | int dump_flags; | |
124 | bool in_gimple_form; | |
7e0311ae | 125 | bool first_pass_instance; |
a49a878f | 126 | |
a49a878f | 127 | |
128 | /* This is called from various places for FUNCTION_DECL, VAR_DECL, | |
129 | and TYPE_DECL nodes. | |
130 | ||
131 | This does nothing for local (non-static) variables, unless the | |
b2c4af5e | 132 | variable is a register variable with DECL_ASSEMBLER_NAME set. In |
133 | that case, or if the variable is not an automatic, it sets up the | |
134 | RTL and outputs any assembler code (label definition, storage | |
135 | allocation and initialization). | |
a49a878f | 136 | |
b2c4af5e | 137 | DECL is the declaration. TOP_LEVEL is nonzero |
a49a878f | 138 | if this declaration is not within a function. */ |
139 | ||
140 | void | |
141 | rest_of_decl_compilation (tree decl, | |
a49a878f | 142 | int top_level, |
143 | int at_end) | |
144 | { | |
145 | /* We deferred calling assemble_alias so that we could collect | |
146 | other attributes such as visibility. Emit the alias now. */ | |
147 | { | |
148 | tree alias; | |
149 | alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl)); | |
150 | if (alias) | |
151 | { | |
152 | alias = TREE_VALUE (TREE_VALUE (alias)); | |
153 | alias = get_identifier (TREE_STRING_POINTER (alias)); | |
154 | assemble_alias (decl, alias); | |
155 | } | |
156 | } | |
157 | ||
b2c4af5e | 158 | /* Can't defer this, because it needs to happen before any |
159 | later function definitions are processed. */ | |
5ded8c6f | 160 | if (DECL_ASSEMBLER_NAME_SET_P (decl) && DECL_REGISTER (decl)) |
b2c4af5e | 161 | make_decl_rtl (decl); |
162 | ||
a49a878f | 163 | /* Forward declarations for nested functions are not "external", |
164 | but we need to treat them as if they were. */ | |
165 | if (TREE_STATIC (decl) || DECL_EXTERNAL (decl) | |
166 | || TREE_CODE (decl) == FUNCTION_DECL) | |
167 | { | |
168 | timevar_push (TV_VARCONST); | |
169 | ||
a49a878f | 170 | /* Don't output anything when a tentative file-scope definition |
171 | is seen. But at end of compilation, do output code for them. | |
172 | ||
6329636b | 173 | We do output all variables and rely on |
a49a878f | 174 | callgraph code to defer them except for forward declarations |
175 | (see gcc.c-torture/compile/920624-1.c) */ | |
176 | if ((at_end | |
177 | || !DECL_DEFER_OUTPUT (decl) | |
c1dcd13c | 178 | || DECL_INITIAL (decl)) |
a49a878f | 179 | && !DECL_EXTERNAL (decl)) |
180 | { | |
0cddb138 | 181 | /* When reading LTO unit, we also read varpool, so do not |
182 | rebuild it. */ | |
183 | if (in_lto_p && !at_end) | |
184 | ; | |
185 | else if (TREE_CODE (decl) != FUNCTION_DECL) | |
1d416bd7 | 186 | varpool_finalize_decl (decl); |
a49a878f | 187 | } |
188 | ||
189 | #ifdef ASM_FINISH_DECLARE_OBJECT | |
190 | if (decl == last_assemble_variable_decl) | |
191 | { | |
192 | ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl, | |
193 | top_level, at_end); | |
194 | } | |
195 | #endif | |
196 | ||
197 | timevar_pop (TV_VARCONST); | |
198 | } | |
76512af6 | 199 | else if (TREE_CODE (decl) == TYPE_DECL |
200 | /* Like in rest_of_type_compilation, avoid confusing the debug | |
201 | information machinery when there are errors. */ | |
852f689e | 202 | && !seen_error ()) |
a49a878f | 203 | { |
204 | timevar_push (TV_SYMOUT); | |
205 | debug_hooks->type_decl (decl, !top_level); | |
206 | timevar_pop (TV_SYMOUT); | |
207 | } | |
d7401838 | 208 | |
06b27565 | 209 | /* Let cgraph know about the existence of variables. */ |
0cddb138 | 210 | if (in_lto_p && !at_end) |
211 | ; | |
79ee0029 | 212 | else if (TREE_CODE (decl) == VAR_DECL && !DECL_EXTERNAL (decl) |
213 | && TREE_STATIC (decl)) | |
1d416bd7 | 214 | varpool_node (decl); |
a49a878f | 215 | } |
216 | ||
217 | /* Called after finishing a record, union or enumeral type. */ | |
218 | ||
219 | void | |
220 | rest_of_type_compilation (tree type, int toplev) | |
221 | { | |
222 | /* Avoid confusing the debug information machinery when there are | |
223 | errors. */ | |
852f689e | 224 | if (seen_error ()) |
a49a878f | 225 | return; |
226 | ||
227 | timevar_push (TV_SYMOUT); | |
228 | debug_hooks->type_decl (TYPE_STUB_DECL (type), !toplev); | |
229 | timevar_pop (TV_SYMOUT); | |
230 | } | |
231 | ||
77fce4cd | 232 | \f |
a49a878f | 233 | |
77fce4cd | 234 | void |
235 | finish_optimization_passes (void) | |
a49a878f | 236 | { |
9f1b7d17 | 237 | int i; |
77fce4cd | 238 | struct dump_file_info *dfi; |
239 | char *name; | |
a49a878f | 240 | |
77fce4cd | 241 | timevar_push (TV_DUMP); |
242 | if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities) | |
a49a878f | 243 | { |
20099e35 | 244 | dump_file = dump_begin (pass_profile.pass.static_pass_number, NULL); |
77fce4cd | 245 | end_branch_prob (); |
246 | if (dump_file) | |
20099e35 | 247 | dump_end (pass_profile.pass.static_pass_number, dump_file); |
a49a878f | 248 | } |
a49a878f | 249 | |
77fce4cd | 250 | if (optimize > 0) |
a49a878f | 251 | { |
20099e35 | 252 | dump_file = dump_begin (pass_combine.pass.static_pass_number, NULL); |
77fce4cd | 253 | if (dump_file) |
a49a878f | 254 | { |
77fce4cd | 255 | dump_combine_total_stats (dump_file); |
20099e35 | 256 | dump_end (pass_combine.pass.static_pass_number, dump_file); |
a49a878f | 257 | } |
258 | } | |
259 | ||
77fce4cd | 260 | /* Do whatever is necessary to finish printing the graphs. */ |
261 | if (graph_dump_format != no_graph) | |
262 | for (i = TDI_end; (dfi = get_dump_file_info (i)) != NULL; ++i) | |
263 | if (dump_initialized_p (i) | |
5f0ef107 | 264 | && (dfi->flags & TDF_GRAPH) != 0 |
77fce4cd | 265 | && (name = get_dump_file_name (i)) != NULL) |
5f0ef107 | 266 | { |
267 | finish_graph_dump_file (name); | |
268 | free (name); | |
269 | } | |
a49a878f | 270 | |
77fce4cd | 271 | timevar_pop (TV_DUMP); |
a49a878f | 272 | } |
a49a878f | 273 | |
77fce4cd | 274 | static bool |
275 | gate_rest_of_compilation (void) | |
a49a878f | 276 | { |
77fce4cd | 277 | /* Early return if there were errors. We can run afoul of our |
278 | consistency checks, and there's not really much point in fixing them. */ | |
852f689e | 279 | return !(rtl_dump_and_exit || flag_syntax_only || seen_error ()); |
a49a878f | 280 | } |
281 | ||
20099e35 | 282 | struct gimple_opt_pass pass_rest_of_compilation = |
a49a878f | 283 | { |
20099e35 | 284 | { |
285 | GIMPLE_PASS, | |
21486db3 | 286 | "*rest_of_compilation", /* name */ |
77fce4cd | 287 | gate_rest_of_compilation, /* gate */ |
288 | NULL, /* execute */ | |
289 | NULL, /* sub */ | |
290 | NULL, /* next */ | |
291 | 0, /* static_pass_number */ | |
292 | TV_REST_OF_COMPILATION, /* tv_id */ | |
293 | PROP_rtl, /* properties_required */ | |
294 | 0, /* properties_provided */ | |
295 | 0, /* properties_destroyed */ | |
296 | 0, /* todo_flags_start */ | |
20099e35 | 297 | TODO_ggc_collect /* todo_flags_finish */ |
298 | } | |
77fce4cd | 299 | }; |
a49a878f | 300 | |
77fce4cd | 301 | static bool |
302 | gate_postreload (void) | |
303 | { | |
304 | return reload_completed; | |
a49a878f | 305 | } |
306 | ||
20099e35 | 307 | struct rtl_opt_pass pass_postreload = |
a49a878f | 308 | { |
20099e35 | 309 | { |
310 | RTL_PASS, | |
0c297edc | 311 | "*all-postreload", /* name */ |
77fce4cd | 312 | gate_postreload, /* gate */ |
313 | NULL, /* execute */ | |
314 | NULL, /* sub */ | |
315 | NULL, /* next */ | |
316 | 0, /* static_pass_number */ | |
4b366dd3 | 317 | TV_POSTRELOAD, /* tv_id */ |
77fce4cd | 318 | PROP_rtl, /* properties_required */ |
319 | 0, /* properties_provided */ | |
320 | 0, /* properties_destroyed */ | |
321 | 0, /* todo_flags_start */ | |
20099e35 | 322 | TODO_ggc_collect | TODO_verify_rtl_sharing /* todo_flags_finish */ |
323 | } | |
77fce4cd | 324 | }; |
a49a878f | 325 | |
da2f1613 | 326 | |
a49a878f | 327 | |
77fce4cd | 328 | /* The root of the compilation pass tree, once constructed. */ |
7bfefa9d | 329 | struct opt_pass *all_passes, *all_small_ipa_passes, *all_lowering_passes, |
330 | *all_regular_ipa_passes, *all_lto_gen_passes; | |
a49a878f | 331 | |
c34d1545 | 332 | /* This is used by plugins, and should also be used in register_pass. */ |
333 | #define DEF_PASS_LIST(LIST) &LIST, | |
334 | struct opt_pass **gcc_pass_lists[] = { GCC_PASS_LISTS NULL }; | |
335 | #undef DEF_PASS_LIST | |
336 | ||
9659d177 | 337 | /* A map from static pass id to optimization pass. */ |
338 | struct opt_pass **passes_by_id; | |
339 | int passes_by_id_size; | |
340 | ||
341 | /* Set the static pass number of pass PASS to ID and record that | |
342 | in the mapping from static pass number to pass. */ | |
343 | ||
344 | static void | |
345 | set_pass_for_id (int id, struct opt_pass *pass) | |
346 | { | |
347 | pass->static_pass_number = id; | |
348 | if (passes_by_id_size <= id) | |
349 | { | |
4077bf7a | 350 | passes_by_id = XRESIZEVEC (struct opt_pass *, passes_by_id, id + 1); |
9659d177 | 351 | memset (passes_by_id + passes_by_id_size, 0, |
352 | (id + 1 - passes_by_id_size) * sizeof (void *)); | |
353 | passes_by_id_size = id + 1; | |
354 | } | |
355 | passes_by_id[id] = pass; | |
356 | } | |
357 | ||
358 | /* Return the pass with the static pass number ID. */ | |
359 | ||
360 | struct opt_pass * | |
361 | get_pass_for_id (int id) | |
362 | { | |
363 | if (id >= passes_by_id_size) | |
364 | return NULL; | |
365 | return passes_by_id[id]; | |
366 | } | |
367 | ||
77fce4cd | 368 | /* Iterate over the pass tree allocating dump file numbers. We want |
369 | to do this depth first, and independent of whether the pass is | |
370 | enabled or not. */ | |
a49a878f | 371 | |
9227b6fc | 372 | void |
5d48fdb4 | 373 | register_one_dump_file (struct opt_pass *pass) |
77fce4cd | 374 | { |
375 | char *dot_name, *flag_name, *glob_name; | |
0c297edc | 376 | const char *name, *prefix; |
77fce4cd | 377 | char num[10]; |
9659d177 | 378 | int flags, id; |
a49a878f | 379 | |
77fce4cd | 380 | /* See below in next_pass_1. */ |
381 | num[0] = '\0'; | |
382 | if (pass->static_pass_number != -1) | |
383 | sprintf (num, "%d", ((int) pass->static_pass_number < 0 | |
384 | ? 1 : pass->static_pass_number)); | |
a49a878f | 385 | |
0c297edc | 386 | /* The name is both used to identify the pass for the purposes of plugins, |
387 | and to specify dump file name and option. | |
388 | The latter two might want something short which is not quite unique; for | |
389 | that reason, we may have a disambiguating prefix, followed by a space | |
390 | to mark the start of the following dump file name / option string. */ | |
391 | name = strchr (pass->name, ' '); | |
392 | name = name ? name + 1 : pass->name; | |
393 | dot_name = concat (".", name, num, NULL); | |
68e3904e | 394 | if (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS) |
6354626c | 395 | prefix = "ipa-", flags = TDF_IPA; |
5d48fdb4 | 396 | else if (pass->type == GIMPLE_PASS) |
6354626c | 397 | prefix = "tree-", flags = TDF_TREE; |
a49a878f | 398 | else |
6354626c | 399 | prefix = "rtl-", flags = TDF_RTL; |
400 | ||
0c297edc | 401 | flag_name = concat (prefix, name, num, NULL); |
402 | glob_name = concat (prefix, name, NULL); | |
9659d177 | 403 | id = dump_register (dot_name, flag_name, glob_name, flags); |
404 | set_pass_for_id (id, pass); | |
da2f1613 | 405 | } |
406 | ||
6354626c | 407 | /* Recursive worker function for register_dump_files. */ |
408 | ||
48e1416a | 409 | static int |
5d48fdb4 | 410 | register_dump_files_1 (struct opt_pass *pass, int properties) |
da2f1613 | 411 | { |
77fce4cd | 412 | do |
413 | { | |
6354626c | 414 | int new_properties = (properties | pass->properties_provided) |
415 | & ~pass->properties_destroyed; | |
a49a878f | 416 | |
9478582c | 417 | if (pass->name && pass->name[0] != '*') |
5d48fdb4 | 418 | register_one_dump_file (pass); |
a49a878f | 419 | |
77fce4cd | 420 | if (pass->sub) |
5d48fdb4 | 421 | new_properties = register_dump_files_1 (pass->sub, new_properties); |
a49a878f | 422 | |
77fce4cd | 423 | /* If we have a gate, combine the properties that we could have with |
424 | and without the pass being examined. */ | |
425 | if (pass->gate) | |
426 | properties &= new_properties; | |
427 | else | |
428 | properties = new_properties; | |
a49a878f | 429 | |
77fce4cd | 430 | pass = pass->next; |
a49a878f | 431 | } |
77fce4cd | 432 | while (pass); |
a49a878f | 433 | |
77fce4cd | 434 | return properties; |
a49a878f | 435 | } |
839f8415 | 436 | |
48e1416a | 437 | /* Register the dump files for the pipeline starting at PASS. |
5d48fdb4 | 438 | PROPERTIES reflects the properties that are guaranteed to be available at |
439 | the beginning of the pipeline. */ | |
6354626c | 440 | |
48e1416a | 441 | static void |
5d48fdb4 | 442 | register_dump_files (struct opt_pass *pass,int properties) |
6354626c | 443 | { |
444 | pass->properties_required |= properties; | |
5d48fdb4 | 445 | register_dump_files_1 (pass, properties); |
6354626c | 446 | } |
447 | ||
3efe62a1 | 448 | /* Look at the static_pass_number and duplicate the pass |
449 | if it is already added to a list. */ | |
839f8415 | 450 | |
3efe62a1 | 451 | static struct opt_pass * |
452 | make_pass_instance (struct opt_pass *pass, bool track_duplicates) | |
a49a878f | 453 | { |
77fce4cd | 454 | /* A nonzero static_pass_number indicates that the |
455 | pass is already in the list. */ | |
456 | if (pass->static_pass_number) | |
457 | { | |
f4e36c33 | 458 | struct opt_pass *new_pass; |
a49a878f | 459 | |
ea2c6784 | 460 | if (pass->type == GIMPLE_PASS |
461 | || pass->type == RTL_PASS | |
462 | || pass->type == SIMPLE_IPA_PASS) | |
463 | { | |
464 | new_pass = XNEW (struct opt_pass); | |
465 | memcpy (new_pass, pass, sizeof (struct opt_pass)); | |
466 | } | |
467 | else if (pass->type == IPA_PASS) | |
468 | { | |
469 | new_pass = (struct opt_pass *)XNEW (struct ipa_opt_pass_d); | |
470 | memcpy (new_pass, pass, sizeof (struct ipa_opt_pass_d)); | |
471 | } | |
472 | else | |
473 | gcc_unreachable (); | |
474 | ||
f4e36c33 | 475 | new_pass->next = NULL; |
a49a878f | 476 | |
f4e36c33 | 477 | new_pass->todo_flags_start &= ~TODO_mark_first_instance; |
7e0311ae | 478 | |
77fce4cd | 479 | /* Indicate to register_dump_files that this pass has duplicates, |
480 | and so it should rename the dump file. The first instance will | |
481 | be -1, and be number of duplicates = -static_pass_number - 1. | |
482 | Subsequent instances will be > 0 and just the duplicate number. */ | |
0c297edc | 483 | if ((pass->name && pass->name[0] != '*') || track_duplicates) |
77fce4cd | 484 | { |
485 | pass->static_pass_number -= 1; | |
f4e36c33 | 486 | new_pass->static_pass_number = -pass->static_pass_number; |
77fce4cd | 487 | } |
3efe62a1 | 488 | return new_pass; |
77fce4cd | 489 | } |
490 | else | |
491 | { | |
7e0311ae | 492 | pass->todo_flags_start |= TODO_mark_first_instance; |
77fce4cd | 493 | pass->static_pass_number = -1; |
c9036234 | 494 | |
495 | invoke_plugin_callbacks (PLUGIN_NEW_PASS, pass); | |
48e1416a | 496 | } |
497 | return pass; | |
3efe62a1 | 498 | } |
499 | ||
500 | /* Add a pass to the pass list. Duplicate the pass if it's already | |
501 | in the list. */ | |
502 | ||
503 | static struct opt_pass ** | |
504 | next_pass_1 (struct opt_pass **list, struct opt_pass *pass) | |
505 | { | |
0c297edc | 506 | /* Every pass should have a name so that plugins can refer to them. */ |
507 | gcc_assert (pass->name != NULL); | |
508 | ||
3efe62a1 | 509 | *list = make_pass_instance (pass, false); |
48e1416a | 510 | |
77fce4cd | 511 | return &(*list)->next; |
a49a878f | 512 | } |
513 | ||
3efe62a1 | 514 | /* List node for an inserted pass instance. We need to keep track of all |
515 | the newly-added pass instances (with 'added_pass_nodes' defined below) | |
516 | so that we can register their dump files after pass-positioning is finished. | |
517 | Registering dumping files needs to be post-processed or the | |
518 | static_pass_number of the opt_pass object would be modified and mess up | |
519 | the dump file names of future pass instances to be added. */ | |
520 | ||
521 | struct pass_list_node | |
522 | { | |
523 | struct opt_pass *pass; | |
524 | struct pass_list_node *next; | |
525 | }; | |
526 | ||
527 | static struct pass_list_node *added_pass_nodes = NULL; | |
528 | static struct pass_list_node *prev_added_pass_node; | |
529 | ||
48e1416a | 530 | /* Insert the pass at the proper position. Return true if the pass |
3efe62a1 | 531 | is successfully added. |
532 | ||
533 | NEW_PASS_INFO - new pass to be inserted | |
534 | PASS_LIST - root of the pass list to insert the new pass to */ | |
535 | ||
536 | static bool | |
537 | position_pass (struct register_pass_info *new_pass_info, | |
538 | struct opt_pass **pass_list) | |
539 | { | |
540 | struct opt_pass *pass = *pass_list, *prev_pass = NULL; | |
541 | bool success = false; | |
542 | ||
543 | for ( ; pass; prev_pass = pass, pass = pass->next) | |
544 | { | |
545 | /* Check if the current pass is of the same type as the new pass and | |
546 | matches the name and the instance number of the reference pass. */ | |
547 | if (pass->type == new_pass_info->pass->type | |
548 | && pass->name | |
549 | && !strcmp (pass->name, new_pass_info->reference_pass_name) | |
550 | && ((new_pass_info->ref_pass_instance_number == 0) | |
551 | || (new_pass_info->ref_pass_instance_number == | |
552 | pass->static_pass_number) | |
553 | || (new_pass_info->ref_pass_instance_number == 1 | |
554 | && pass->todo_flags_start & TODO_mark_first_instance))) | |
555 | { | |
556 | struct opt_pass *new_pass; | |
557 | struct pass_list_node *new_pass_node; | |
558 | ||
559 | new_pass = make_pass_instance (new_pass_info->pass, true); | |
48e1416a | 560 | |
3efe62a1 | 561 | /* Insert the new pass instance based on the positioning op. */ |
562 | switch (new_pass_info->pos_op) | |
563 | { | |
564 | case PASS_POS_INSERT_AFTER: | |
565 | new_pass->next = pass->next; | |
566 | pass->next = new_pass; | |
567 | ||
568 | /* Skip newly inserted pass to avoid repeated | |
569 | insertions in the case where the new pass and the | |
570 | existing one have the same name. */ | |
48e1416a | 571 | pass = new_pass; |
3efe62a1 | 572 | break; |
573 | case PASS_POS_INSERT_BEFORE: | |
574 | new_pass->next = pass; | |
575 | if (prev_pass) | |
576 | prev_pass->next = new_pass; | |
577 | else | |
578 | *pass_list = new_pass; | |
579 | break; | |
580 | case PASS_POS_REPLACE: | |
581 | new_pass->next = pass->next; | |
582 | if (prev_pass) | |
583 | prev_pass->next = new_pass; | |
584 | else | |
585 | *pass_list = new_pass; | |
586 | new_pass->sub = pass->sub; | |
587 | new_pass->tv_id = pass->tv_id; | |
588 | pass = new_pass; | |
589 | break; | |
590 | default: | |
bf776685 | 591 | error ("invalid pass positioning operation"); |
3efe62a1 | 592 | return false; |
593 | } | |
594 | ||
595 | /* Save the newly added pass (instance) in the added_pass_nodes | |
596 | list so that we can register its dump file later. Note that | |
597 | we cannot register the dump file now because doing so will modify | |
598 | the static_pass_number of the opt_pass object and therefore | |
599 | mess up the dump file name of future instances. */ | |
600 | new_pass_node = XCNEW (struct pass_list_node); | |
601 | new_pass_node->pass = new_pass; | |
602 | if (!added_pass_nodes) | |
603 | added_pass_nodes = new_pass_node; | |
604 | else | |
605 | prev_added_pass_node->next = new_pass_node; | |
606 | prev_added_pass_node = new_pass_node; | |
607 | ||
608 | success = true; | |
609 | } | |
610 | ||
611 | if (pass->sub && position_pass (new_pass_info, &pass->sub)) | |
612 | success = true; | |
613 | } | |
614 | ||
615 | return success; | |
616 | } | |
617 | ||
618 | /* Hooks a new pass into the pass lists. | |
619 | ||
620 | PASS_INFO - pass information that specifies the opt_pass object, | |
621 | reference pass, instance number, and how to position | |
622 | the pass */ | |
623 | ||
624 | void | |
625 | register_pass (struct register_pass_info *pass_info) | |
626 | { | |
c21d7f23 | 627 | bool all_instances, success; |
628 | ||
0de338e5 | 629 | /* The checks below could fail in buggy plugins. Existing GCC |
630 | passes should never fail these checks, so we mention plugin in | |
631 | the messages. */ | |
3efe62a1 | 632 | if (!pass_info->pass) |
0de338e5 | 633 | fatal_error ("plugin cannot register a missing pass"); |
634 | ||
635 | if (!pass_info->pass->name) | |
636 | fatal_error ("plugin cannot register an unnamed pass"); | |
3efe62a1 | 637 | |
638 | if (!pass_info->reference_pass_name) | |
0de338e5 | 639 | fatal_error |
640 | ("plugin cannot register pass %qs without reference pass name", | |
641 | pass_info->pass->name); | |
3efe62a1 | 642 | |
0de338e5 | 643 | /* Try to insert the new pass to the pass lists. We need to check |
c21d7f23 | 644 | all five lists as the reference pass could be in one (or all) of |
0de338e5 | 645 | them. */ |
c21d7f23 | 646 | all_instances = pass_info->ref_pass_instance_number == 0; |
647 | success = position_pass (pass_info, &all_lowering_passes); | |
648 | if (!success || all_instances) | |
649 | success |= position_pass (pass_info, &all_small_ipa_passes); | |
650 | if (!success || all_instances) | |
651 | success |= position_pass (pass_info, &all_regular_ipa_passes); | |
652 | if (!success || all_instances) | |
653 | success |= position_pass (pass_info, &all_lto_gen_passes); | |
654 | if (!success || all_instances) | |
655 | success |= position_pass (pass_info, &all_passes); | |
656 | if (!success) | |
0de338e5 | 657 | fatal_error |
658 | ("pass %qs not found but is referenced by new pass %qs", | |
659 | pass_info->reference_pass_name, pass_info->pass->name); | |
c21d7f23 | 660 | |
661 | /* OK, we have successfully inserted the new pass. We need to register | |
662 | the dump files for the newly added pass and its duplicates (if any). | |
663 | Because the registration of plugin/backend passes happens after the | |
664 | command-line options are parsed, the options that specify single | |
665 | pass dumping (e.g. -fdump-tree-PASSNAME) cannot be used for new | |
666 | passes. Therefore we currently can only enable dumping of | |
667 | new passes when the 'dump-all' flags (e.g. -fdump-tree-all) | |
668 | are specified. While doing so, we also delete the pass_list_node | |
669 | objects created during pass positioning. */ | |
670 | while (added_pass_nodes) | |
3efe62a1 | 671 | { |
c21d7f23 | 672 | struct pass_list_node *next_node = added_pass_nodes->next; |
673 | enum tree_dump_index tdi; | |
674 | register_one_dump_file (added_pass_nodes->pass); | |
675 | if (added_pass_nodes->pass->type == SIMPLE_IPA_PASS | |
676 | || added_pass_nodes->pass->type == IPA_PASS) | |
677 | tdi = TDI_ipa_all; | |
678 | else if (added_pass_nodes->pass->type == GIMPLE_PASS) | |
679 | tdi = TDI_tree_all; | |
680 | else | |
681 | tdi = TDI_rtl_all; | |
682 | /* Check if dump-all flag is specified. */ | |
683 | if (get_dump_file_info (tdi)->state) | |
684 | get_dump_file_info (added_pass_nodes->pass->static_pass_number) | |
685 | ->state = get_dump_file_info (tdi)->state; | |
686 | XDELETE (added_pass_nodes); | |
687 | added_pass_nodes = next_node; | |
3efe62a1 | 688 | } |
689 | } | |
3072d30e | 690 | |
ae6ad54a | 691 | /* Construct the pass tree. The sequencing of passes is driven by |
692 | the cgraph routines: | |
693 | ||
694 | cgraph_finalize_compilation_unit () | |
695 | for each node N in the cgraph | |
696 | cgraph_analyze_function (N) | |
697 | cgraph_lower_function (N) -> all_lowering_passes | |
698 | ||
699 | If we are optimizing, cgraph_optimize is then invoked: | |
700 | ||
701 | cgraph_optimize () | |
7bfefa9d | 702 | ipa_passes () -> all_small_ipa_passes |
ae6ad54a | 703 | cgraph_expand_all_functions () |
704 | for each node N in the cgraph | |
705 | cgraph_expand_function (N) | |
84e10000 | 706 | tree_rest_of_compilation (DECL (N)) -> all_passes |
ae6ad54a | 707 | */ |
da2f1613 | 708 | |
77fce4cd | 709 | void |
710 | init_optimization_passes (void) | |
711 | { | |
20099e35 | 712 | struct opt_pass **p; |
77fce4cd | 713 | |
20099e35 | 714 | #define NEXT_PASS(PASS) (p = next_pass_1 (p, &((PASS).pass))) |
09a2e412 | 715 | |
fdd35027 | 716 | /* All passes needed to lower the function into shape optimizers can |
717 | operate on. These passes are always run first on the function, but | |
718 | backend might produce already lowered functions that are not processed | |
719 | by these passes. */ | |
77fce4cd | 720 | p = &all_lowering_passes; |
bfec3452 | 721 | NEXT_PASS (pass_warn_unused_result); |
722 | NEXT_PASS (pass_diagnose_omp_blocks); | |
77fce4cd | 723 | NEXT_PASS (pass_mudflap_1); |
1e8e9920 | 724 | NEXT_PASS (pass_lower_omp); |
77fce4cd | 725 | NEXT_PASS (pass_lower_cf); |
4888ab9a | 726 | NEXT_PASS (pass_refactor_eh); |
77fce4cd | 727 | NEXT_PASS (pass_lower_eh); |
728 | NEXT_PASS (pass_build_cfg); | |
77fce4cd | 729 | NEXT_PASS (pass_warn_function_return); |
e7c352d1 | 730 | NEXT_PASS (pass_build_cgraph_edges); |
09a2e412 | 731 | NEXT_PASS (pass_inline_parameters); |
77fce4cd | 732 | *p = NULL; |
733 | ||
6329636b | 734 | /* Interprocedural optimization passes. */ |
7bfefa9d | 735 | p = &all_small_ipa_passes; |
4d07b54f | 736 | NEXT_PASS (pass_ipa_free_lang_data); |
fdd35027 | 737 | NEXT_PASS (pass_ipa_function_and_variable_visibility); |
fdd35027 | 738 | NEXT_PASS (pass_early_local_passes); |
739 | { | |
20099e35 | 740 | struct opt_pass **p = &pass_early_local_passes.pass.sub; |
6cb239e5 | 741 | NEXT_PASS (pass_fixup_cfg); |
fdd35027 | 742 | NEXT_PASS (pass_init_datastructures); |
743 | NEXT_PASS (pass_expand_omp); | |
bff4202c | 744 | |
745 | NEXT_PASS (pass_referenced_vars); | |
bff4202c | 746 | NEXT_PASS (pass_build_ssa); |
2fee2038 | 747 | NEXT_PASS (pass_lower_vector); |
ea18e2e5 | 748 | NEXT_PASS (pass_early_warn_uninitialized); |
7bfefa9d | 749 | /* Note that it is not strictly necessary to schedule an early |
750 | inline pass here. However, some test cases (e.g., | |
751 | g++.dg/other/p334435.C g++.dg/other/i386-1.C) expect extern | |
752 | inline functions to be inlined even at -O0. This does not | |
753 | happen during the first early inline pass. */ | |
754 | NEXT_PASS (pass_rebuild_cgraph_edges); | |
755 | NEXT_PASS (pass_early_inline); | |
fdd35027 | 756 | NEXT_PASS (pass_all_early_optimizations); |
757 | { | |
20099e35 | 758 | struct opt_pass **p = &pass_all_early_optimizations.pass.sub; |
ba3a7ba0 | 759 | NEXT_PASS (pass_remove_cgraph_callee_edges); |
fdd35027 | 760 | NEXT_PASS (pass_rename_ssa_copies); |
761 | NEXT_PASS (pass_ccp); | |
762 | NEXT_PASS (pass_forwprop); | |
7f81b5ee | 763 | /* pass_build_ealias is a dummy pass that ensures that we |
764 | execute TODO_rebuild_alias at this point. Re-building | |
765 | alias information also rewrites no longer addressed | |
766 | locals into SSA form if possible. */ | |
767 | NEXT_PASS (pass_build_ealias); | |
1f0a4df8 | 768 | NEXT_PASS (pass_sra_early); |
fdd35027 | 769 | NEXT_PASS (pass_copy_prop); |
770 | NEXT_PASS (pass_merge_phi); | |
43bba217 | 771 | NEXT_PASS (pass_cd_dce); |
2f29eac3 | 772 | NEXT_PASS (pass_early_ipa_sra); |
fdd35027 | 773 | NEXT_PASS (pass_tail_recursion); |
a347af29 | 774 | NEXT_PASS (pass_convert_switch); |
4c5fcca6 | 775 | NEXT_PASS (pass_cleanup_eh); |
4ae20857 | 776 | NEXT_PASS (pass_profile); |
b5cebd44 | 777 | NEXT_PASS (pass_local_pure_const); |
2862cf88 | 778 | /* Split functions creates parts that are not run through |
779 | early optimizations again. It is thus good idea to do this | |
780 | late. */ | |
781 | NEXT_PASS (pass_split_functions); | |
fdd35027 | 782 | } |
bff4202c | 783 | NEXT_PASS (pass_release_ssa_names); |
fdd35027 | 784 | NEXT_PASS (pass_rebuild_cgraph_edges); |
64f6c8c9 | 785 | NEXT_PASS (pass_inline_parameters); |
fdd35027 | 786 | } |
85344eeb | 787 | NEXT_PASS (pass_ipa_tree_profile); |
fdd35027 | 788 | NEXT_PASS (pass_ipa_increase_alignment); |
604cde73 | 789 | NEXT_PASS (pass_ipa_matrix_reorg); |
cffbbb9d | 790 | NEXT_PASS (pass_ipa_lower_emutls); |
7bfefa9d | 791 | *p = NULL; |
792 | ||
793 | p = &all_regular_ipa_passes; | |
59dd4830 | 794 | NEXT_PASS (pass_ipa_whole_program_visibility); |
4e2db0ad | 795 | NEXT_PASS (pass_ipa_profile); |
fdd35027 | 796 | NEXT_PASS (pass_ipa_cp); |
a53e7471 | 797 | NEXT_PASS (pass_ipa_cdtor_merge); |
fdd35027 | 798 | NEXT_PASS (pass_ipa_inline); |
48e1416a | 799 | NEXT_PASS (pass_ipa_pure_const); |
a5231069 | 800 | NEXT_PASS (pass_ipa_reference); |
fdd35027 | 801 | NEXT_PASS (pass_ipa_type_escape); |
802 | NEXT_PASS (pass_ipa_pta); | |
7bfefa9d | 803 | NEXT_PASS (pass_ipa_struct_reorg); |
804 | *p = NULL; | |
805 | ||
806 | p = &all_lto_gen_passes; | |
807 | NEXT_PASS (pass_ipa_lto_gimple_out); | |
7bfefa9d | 808 | NEXT_PASS (pass_ipa_lto_finish_out); /* This must be the last LTO pass. */ |
f517b36e | 809 | *p = NULL; |
810 | ||
48a12060 | 811 | /* These passes are run after IPA passes on every function that is being |
812 | output to the assembler file. */ | |
77fce4cd | 813 | p = &all_passes; |
e38def9c | 814 | NEXT_PASS (pass_lower_eh_dispatch); |
77fce4cd | 815 | NEXT_PASS (pass_all_optimizations); |
fdd35027 | 816 | { |
20099e35 | 817 | struct opt_pass **p = &pass_all_optimizations.pass.sub; |
ba3a7ba0 | 818 | NEXT_PASS (pass_remove_cgraph_callee_edges); |
43bba217 | 819 | /* Initial scalar cleanups before alias computation. |
820 | They ensure memory accesses are not indirect wherever possible. */ | |
1add270f | 821 | NEXT_PASS (pass_strip_predict_hints); |
fdd35027 | 822 | NEXT_PASS (pass_rename_ssa_copies); |
d88fd237 | 823 | NEXT_PASS (pass_complete_unrolli); |
fdd35027 | 824 | NEXT_PASS (pass_ccp); |
ac4b41a4 | 825 | NEXT_PASS (pass_forwprop); |
43bba217 | 826 | NEXT_PASS (pass_call_cdce); |
827 | /* pass_build_alias is a dummy pass that ensures that we | |
828 | execute TODO_rebuild_alias at this point. Re-building | |
829 | alias information also rewrites no longer addressed | |
830 | locals into SSA form if possible. */ | |
831 | NEXT_PASS (pass_build_alias); | |
832 | NEXT_PASS (pass_return_slot); | |
37361b38 | 833 | NEXT_PASS (pass_phiprop); |
fdd35027 | 834 | NEXT_PASS (pass_fre); |
fdd35027 | 835 | NEXT_PASS (pass_copy_prop); |
836 | NEXT_PASS (pass_merge_phi); | |
837 | NEXT_PASS (pass_vrp); | |
838 | NEXT_PASS (pass_dce); | |
e6d0e152 | 839 | NEXT_PASS (pass_cselim); |
8530c7be | 840 | NEXT_PASS (pass_tree_ifcombine); |
fdd35027 | 841 | NEXT_PASS (pass_phiopt); |
fdd35027 | 842 | NEXT_PASS (pass_tail_recursion); |
fdd35027 | 843 | NEXT_PASS (pass_ch); |
844 | NEXT_PASS (pass_stdarg); | |
845 | NEXT_PASS (pass_lower_complex); | |
846 | NEXT_PASS (pass_sra); | |
fdd35027 | 847 | NEXT_PASS (pass_rename_ssa_copies); |
a65c4d64 | 848 | /* The dom pass will also resolve all __builtin_constant_p calls |
849 | that are still there to 0. This has to be done after some | |
850 | propagations have already run, but before some more dead code | |
851 | is removed, and this place fits nicely. Remember this when | |
852 | trying to move or duplicate pass_dominator somewhere earlier. */ | |
fdd35027 | 853 | NEXT_PASS (pass_dominator); |
fdd35027 | 854 | /* The only const/copy propagation opportunities left after |
855 | DOM should be due to degenerate PHI nodes. So rather than | |
856 | run the full propagators, run a specialized pass which | |
857 | only examines PHIs to discover const/copy propagation | |
858 | opportunities. */ | |
859 | NEXT_PASS (pass_phi_only_cprop); | |
dddf5036 | 860 | NEXT_PASS (pass_dse); |
fdd35027 | 861 | NEXT_PASS (pass_reassoc); |
862 | NEXT_PASS (pass_dce); | |
fdd35027 | 863 | NEXT_PASS (pass_forwprop); |
864 | NEXT_PASS (pass_phiopt); | |
865 | NEXT_PASS (pass_object_sizes); | |
f70980f2 | 866 | NEXT_PASS (pass_ccp); |
317d3b82 | 867 | NEXT_PASS (pass_copy_prop); |
fdd35027 | 868 | NEXT_PASS (pass_cse_sincos); |
84cc784c | 869 | NEXT_PASS (pass_optimize_bswap); |
fdd35027 | 870 | NEXT_PASS (pass_split_crit_edges); |
871 | NEXT_PASS (pass_pre); | |
fdd35027 | 872 | NEXT_PASS (pass_sink_code); |
873 | NEXT_PASS (pass_tree_loop); | |
874 | { | |
20099e35 | 875 | struct opt_pass **p = &pass_tree_loop.pass.sub; |
fdd35027 | 876 | NEXT_PASS (pass_tree_loop_init); |
69f0b410 | 877 | NEXT_PASS (pass_lim); |
fdd35027 | 878 | NEXT_PASS (pass_copy_prop); |
ad4a85ad | 879 | NEXT_PASS (pass_dce_loop); |
fdd35027 | 880 | NEXT_PASS (pass_tree_unswitch); |
881 | NEXT_PASS (pass_scev_cprop); | |
fdd35027 | 882 | NEXT_PASS (pass_record_bounds); |
355572cc | 883 | NEXT_PASS (pass_check_data_deps); |
801c5610 | 884 | NEXT_PASS (pass_loop_distribution); |
fdd35027 | 885 | NEXT_PASS (pass_linear_transform); |
b90bb125 | 886 | NEXT_PASS (pass_copy_prop); |
887 | NEXT_PASS (pass_graphite); | |
26c166eb | 888 | { |
b90bb125 | 889 | struct opt_pass **p = &pass_graphite.pass.sub; |
b90bb125 | 890 | NEXT_PASS (pass_graphite_transforms); |
a751953f | 891 | NEXT_PASS (pass_copy_prop); |
26c166eb | 892 | NEXT_PASS (pass_dce_loop); |
893 | NEXT_PASS (pass_lim); | |
894 | } | |
fdd35027 | 895 | NEXT_PASS (pass_iv_canon); |
896 | NEXT_PASS (pass_if_conversion); | |
897 | NEXT_PASS (pass_vectorize); | |
898 | { | |
20099e35 | 899 | struct opt_pass **p = &pass_vectorize.pass.sub; |
fdd35027 | 900 | NEXT_PASS (pass_lower_vector_ssa); |
901 | NEXT_PASS (pass_dce_loop); | |
902 | } | |
b50b1b69 | 903 | NEXT_PASS (pass_predcom); |
fdd35027 | 904 | NEXT_PASS (pass_complete_unroll); |
37545e54 | 905 | NEXT_PASS (pass_slp_vectorize); |
28c92cbb | 906 | NEXT_PASS (pass_parallelize_loops); |
fdd35027 | 907 | NEXT_PASS (pass_loop_prefetch); |
908 | NEXT_PASS (pass_iv_optimize); | |
909 | NEXT_PASS (pass_tree_loop_done); | |
910 | } | |
911 | NEXT_PASS (pass_cse_reciprocals); | |
912 | NEXT_PASS (pass_reassoc); | |
913 | NEXT_PASS (pass_vrp); | |
914 | NEXT_PASS (pass_dominator); | |
fdd35027 | 915 | /* The only const/copy propagation opportunities left after |
916 | DOM should be due to degenerate PHI nodes. So rather than | |
917 | run the full propagators, run a specialized pass which | |
918 | only examines PHIs to discover const/copy propagation | |
919 | opportunities. */ | |
920 | NEXT_PASS (pass_phi_only_cprop); | |
fdd35027 | 921 | NEXT_PASS (pass_cd_dce); |
3ddccd57 | 922 | NEXT_PASS (pass_tracer); |
fdd35027 | 923 | |
924 | /* FIXME: If DCE is not run before checking for uninitialized uses, | |
925 | we may get false warnings (e.g., testsuite/gcc.dg/uninit-5.c). | |
926 | However, this also causes us to misdiagnose cases that should be | |
927 | real warnings (e.g., testsuite/gcc.dg/pr18501.c). | |
48e1416a | 928 | |
fdd35027 | 929 | To fix the false positives in uninit-5.c, we would have to |
930 | account for the predicates protecting the set and the use of each | |
931 | variable. Using a representation like Gated Single Assignment | |
932 | may help. */ | |
933 | NEXT_PASS (pass_late_warn_uninitialized); | |
934 | NEXT_PASS (pass_dse); | |
935 | NEXT_PASS (pass_forwprop); | |
936 | NEXT_PASS (pass_phiopt); | |
a65c4d64 | 937 | NEXT_PASS (pass_fold_builtins); |
62be004c | 938 | NEXT_PASS (pass_optimize_widening_mul); |
fdd35027 | 939 | NEXT_PASS (pass_tail_calls); |
940 | NEXT_PASS (pass_rename_ssa_copies); | |
941 | NEXT_PASS (pass_uncprop); | |
b5cebd44 | 942 | NEXT_PASS (pass_local_pure_const); |
fdd35027 | 943 | } |
7b76dcb9 | 944 | NEXT_PASS (pass_lower_complex_O0); |
48d5ef93 | 945 | NEXT_PASS (pass_cleanup_eh); |
e38def9c | 946 | NEXT_PASS (pass_lower_resx); |
bff4202c | 947 | NEXT_PASS (pass_nrv); |
a8dd994c | 948 | NEXT_PASS (pass_mudflap_2); |
bff4202c | 949 | NEXT_PASS (pass_cleanup_cfg_post_optimizing); |
77fce4cd | 950 | NEXT_PASS (pass_warn_function_noreturn); |
75a70cf9 | 951 | |
77fce4cd | 952 | NEXT_PASS (pass_expand); |
a8dd994c | 953 | |
77fce4cd | 954 | NEXT_PASS (pass_rest_of_compilation); |
fdd35027 | 955 | { |
20099e35 | 956 | struct opt_pass **p = &pass_rest_of_compilation.pass.sub; |
fdd35027 | 957 | NEXT_PASS (pass_init_function); |
958 | NEXT_PASS (pass_jump); | |
fdd35027 | 959 | NEXT_PASS (pass_rtl_eh); |
960 | NEXT_PASS (pass_initial_value_sets); | |
961 | NEXT_PASS (pass_unshare_all_rtl); | |
962 | NEXT_PASS (pass_instantiate_virtual_regs); | |
154480b1 | 963 | NEXT_PASS (pass_into_cfg_layout_mode); |
fdd35027 | 964 | NEXT_PASS (pass_jump2); |
965 | NEXT_PASS (pass_lower_subreg); | |
3072d30e | 966 | NEXT_PASS (pass_df_initialize_opt); |
fdd35027 | 967 | NEXT_PASS (pass_cse); |
968 | NEXT_PASS (pass_rtl_fwprop); | |
d743aba2 | 969 | NEXT_PASS (pass_rtl_cprop); |
970 | NEXT_PASS (pass_rtl_pre); | |
971 | NEXT_PASS (pass_rtl_hoist); | |
972 | NEXT_PASS (pass_rtl_cprop); | |
973 | NEXT_PASS (pass_rtl_store_motion); | |
974 | NEXT_PASS (pass_cse_after_global_opts); | |
fdd35027 | 975 | NEXT_PASS (pass_rtl_ifcvt); |
e8eed2f8 | 976 | NEXT_PASS (pass_reginfo_init); |
fdd35027 | 977 | /* Perform loop optimizations. It might be better to do them a bit |
978 | sooner, but we want the profile feedback to work more | |
979 | efficiently. */ | |
980 | NEXT_PASS (pass_loop2); | |
981 | { | |
20099e35 | 982 | struct opt_pass **p = &pass_loop2.pass.sub; |
fdd35027 | 983 | NEXT_PASS (pass_rtl_loop_init); |
984 | NEXT_PASS (pass_rtl_move_loop_invariants); | |
985 | NEXT_PASS (pass_rtl_unswitch); | |
986 | NEXT_PASS (pass_rtl_unroll_and_peel_loops); | |
987 | NEXT_PASS (pass_rtl_doloop); | |
988 | NEXT_PASS (pass_rtl_loop_done); | |
989 | *p = NULL; | |
990 | } | |
991 | NEXT_PASS (pass_web); | |
d743aba2 | 992 | NEXT_PASS (pass_rtl_cprop); |
fdd35027 | 993 | NEXT_PASS (pass_cse2); |
3072d30e | 994 | NEXT_PASS (pass_rtl_dse1); |
fdd35027 | 995 | NEXT_PASS (pass_rtl_fwprop_addr); |
3072d30e | 996 | NEXT_PASS (pass_inc_dec); |
997 | NEXT_PASS (pass_initialize_regs); | |
3072d30e | 998 | NEXT_PASS (pass_ud_rtl_dce); |
fdd35027 | 999 | NEXT_PASS (pass_combine); |
1000 | NEXT_PASS (pass_if_after_combine); | |
1001 | NEXT_PASS (pass_partition_blocks); | |
1002 | NEXT_PASS (pass_regmove); | |
ee4d588d | 1003 | NEXT_PASS (pass_outof_cfg_layout_mode); |
fdd35027 | 1004 | NEXT_PASS (pass_split_all_insns); |
1005 | NEXT_PASS (pass_lower_subreg2); | |
3072d30e | 1006 | NEXT_PASS (pass_df_initialize_no_opt); |
1007 | NEXT_PASS (pass_stack_ptr_mod); | |
fdd35027 | 1008 | NEXT_PASS (pass_mode_switching); |
9dc6d5bb | 1009 | NEXT_PASS (pass_match_asm_constraints); |
fdd35027 | 1010 | NEXT_PASS (pass_sms); |
a7dcf969 | 1011 | NEXT_PASS (pass_sched); |
47dd2e78 | 1012 | NEXT_PASS (pass_ira); |
fdd35027 | 1013 | NEXT_PASS (pass_postreload); |
1014 | { | |
20099e35 | 1015 | struct opt_pass **p = &pass_postreload.pass.sub; |
fdd35027 | 1016 | NEXT_PASS (pass_postreload_cse); |
1017 | NEXT_PASS (pass_gcse2); | |
3072d30e | 1018 | NEXT_PASS (pass_split_after_reload); |
a5b022e7 | 1019 | NEXT_PASS (pass_implicit_zee); |
3072d30e | 1020 | NEXT_PASS (pass_branch_target_load_optimize1); |
1021 | NEXT_PASS (pass_thread_prologue_and_epilogue); | |
1022 | NEXT_PASS (pass_rtl_dse2); | |
fdd35027 | 1023 | NEXT_PASS (pass_stack_adjustments); |
1024 | NEXT_PASS (pass_peephole2); | |
1025 | NEXT_PASS (pass_if_after_reload); | |
1026 | NEXT_PASS (pass_regrename); | |
3072d30e | 1027 | NEXT_PASS (pass_cprop_hardreg); |
1028 | NEXT_PASS (pass_fast_rtl_dce); | |
fdd35027 | 1029 | NEXT_PASS (pass_reorder_blocks); |
3072d30e | 1030 | NEXT_PASS (pass_branch_target_load_optimize2); |
fdd35027 | 1031 | NEXT_PASS (pass_leaf_regs); |
3072d30e | 1032 | NEXT_PASS (pass_split_before_sched2); |
fdd35027 | 1033 | NEXT_PASS (pass_sched2); |
fdd35027 | 1034 | NEXT_PASS (pass_stack_regs); |
3072d30e | 1035 | { |
20099e35 | 1036 | struct opt_pass **p = &pass_stack_regs.pass.sub; |
3072d30e | 1037 | NEXT_PASS (pass_split_before_regstack); |
1038 | NEXT_PASS (pass_stack_regs_run); | |
1039 | } | |
fdd35027 | 1040 | NEXT_PASS (pass_compute_alignments); |
1041 | NEXT_PASS (pass_duplicate_computed_gotos); | |
1042 | NEXT_PASS (pass_variable_tracking); | |
1043 | NEXT_PASS (pass_free_cfg); | |
1044 | NEXT_PASS (pass_machine_reorg); | |
1045 | NEXT_PASS (pass_cleanup_barriers); | |
1046 | NEXT_PASS (pass_delay_slots); | |
1047 | NEXT_PASS (pass_split_for_shorten_branches); | |
1048 | NEXT_PASS (pass_convert_to_eh_region_ranges); | |
1049 | NEXT_PASS (pass_shorten_branches); | |
1050 | NEXT_PASS (pass_set_nothrow_function_flags); | |
1051 | NEXT_PASS (pass_final); | |
1052 | } | |
829545fe | 1053 | NEXT_PASS (pass_df_finish); |
fdd35027 | 1054 | } |
77fce4cd | 1055 | NEXT_PASS (pass_clean_state); |
1056 | *p = NULL; | |
1057 | ||
77fce4cd | 1058 | #undef NEXT_PASS |
1059 | ||
1060 | /* Register the passes with the tree dump code. */ | |
5d48fdb4 | 1061 | register_dump_files (all_lowering_passes, PROP_gimple_any); |
48e1416a | 1062 | register_dump_files (all_small_ipa_passes, |
7bfefa9d | 1063 | PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh |
1064 | | PROP_cfg); | |
48e1416a | 1065 | register_dump_files (all_regular_ipa_passes, |
7bfefa9d | 1066 | PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh |
1067 | | PROP_cfg); | |
48e1416a | 1068 | register_dump_files (all_lto_gen_passes, |
6354626c | 1069 | PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh |
1070 | | PROP_cfg); | |
48e1416a | 1071 | register_dump_files (all_passes, |
6354626c | 1072 | PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh |
1073 | | PROP_cfg); | |
77fce4cd | 1074 | } |
1075 | ||
80f94d49 | 1076 | /* If we are in IPA mode (i.e., current_function_decl is NULL), call |
1077 | function CALLBACK for every function in the call graph. Otherwise, | |
48e1416a | 1078 | call CALLBACK on the current function. */ |
6354626c | 1079 | |
77fce4cd | 1080 | static void |
80f94d49 | 1081 | do_per_function (void (*callback) (void *data), void *data) |
77fce4cd | 1082 | { |
80f94d49 | 1083 | if (current_function_decl) |
1084 | callback (data); | |
1085 | else | |
1086 | { | |
1087 | struct cgraph_node *node; | |
1088 | for (node = cgraph_nodes; node; node = node->next) | |
7fe9b425 | 1089 | if (node->analyzed && gimple_has_body_p (node->decl) |
1090 | && (!node->clone_of || node->decl != node->clone_of->decl)) | |
80f94d49 | 1091 | { |
1092 | push_cfun (DECL_STRUCT_FUNCTION (node->decl)); | |
1093 | current_function_decl = node->decl; | |
1094 | callback (data); | |
7bfefa9d | 1095 | if (!flag_wpa) |
1096 | { | |
1097 | free_dominance_info (CDI_DOMINATORS); | |
1098 | free_dominance_info (CDI_POST_DOMINATORS); | |
1099 | } | |
80f94d49 | 1100 | current_function_decl = NULL; |
1101 | pop_cfun (); | |
1102 | ggc_collect (); | |
1103 | } | |
1104 | } | |
1105 | } | |
1106 | ||
09a2e412 | 1107 | /* Because inlining might remove no-longer reachable nodes, we need to |
1108 | keep the array visible to garbage collector to avoid reading collected | |
1109 | out nodes. */ | |
1110 | static int nnodes; | |
ba72912a | 1111 | static GTY ((length ("nnodes"))) cgraph_node_ptr *order; |
09a2e412 | 1112 | |
1113 | /* If we are in IPA mode (i.e., current_function_decl is NULL), call | |
1114 | function CALLBACK for every function in the call graph. Otherwise, | |
c9036234 | 1115 | call CALLBACK on the current function. |
1116 | This function is global so that plugins can use it. */ | |
1117 | void | |
09a2e412 | 1118 | do_per_function_toporder (void (*callback) (void *data), void *data) |
1119 | { | |
1120 | int i; | |
1121 | ||
1122 | if (current_function_decl) | |
1123 | callback (data); | |
1124 | else | |
1125 | { | |
1126 | gcc_assert (!order); | |
ba72912a | 1127 | order = ggc_alloc_vec_cgraph_node_ptr (cgraph_n_nodes); |
09a2e412 | 1128 | nnodes = cgraph_postorder (order); |
09fc9532 | 1129 | for (i = nnodes - 1; i >= 0; i--) |
1130 | order[i]->process = 1; | |
09a2e412 | 1131 | for (i = nnodes - 1; i >= 0; i--) |
1132 | { | |
1133 | struct cgraph_node *node = order[i]; | |
1134 | ||
1135 | /* Allow possibly removed nodes to be garbage collected. */ | |
1136 | order[i] = NULL; | |
09fc9532 | 1137 | node->process = 0; |
59dd4830 | 1138 | if (node->analyzed) |
09a2e412 | 1139 | { |
1140 | push_cfun (DECL_STRUCT_FUNCTION (node->decl)); | |
1141 | current_function_decl = node->decl; | |
1142 | callback (data); | |
1143 | free_dominance_info (CDI_DOMINATORS); | |
1144 | free_dominance_info (CDI_POST_DOMINATORS); | |
1145 | current_function_decl = NULL; | |
1146 | pop_cfun (); | |
1147 | ggc_collect (); | |
1148 | } | |
1149 | } | |
1150 | } | |
1151 | ggc_free (order); | |
1152 | order = NULL; | |
1153 | nnodes = 0; | |
1154 | } | |
1155 | ||
80f94d49 | 1156 | /* Perform all TODO actions that ought to be done on each function. */ |
77fce4cd | 1157 | |
80f94d49 | 1158 | static void |
1159 | execute_function_todo (void *data) | |
1160 | { | |
1161 | unsigned int flags = (size_t)data; | |
80f94d49 | 1162 | flags &= ~cfun->last_verified; |
6354626c | 1163 | if (!flags) |
1164 | return; | |
9659d177 | 1165 | |
6fa78c7b | 1166 | /* Always cleanup the CFG before trying to update SSA. */ |
77fce4cd | 1167 | if (flags & TODO_cleanup_cfg) |
1168 | { | |
eb2a640e | 1169 | bool cleanup = cleanup_tree_cfg (); |
ae79515f | 1170 | |
6fa78c7b | 1171 | if (cleanup && (cfun->curr_properties & PROP_ssa)) |
1172 | flags |= TODO_remove_unused_locals; | |
48e1416a | 1173 | |
ae79515f | 1174 | /* When cleanup_tree_cfg merges consecutive blocks, it may |
1175 | perform some simplistic propagation when removing single | |
1176 | valued PHI nodes. This propagation may, in turn, cause the | |
1177 | SSA form to become out-of-date (see PR 22037). So, even | |
1178 | if the parent pass had not scheduled an SSA update, we may | |
1179 | still need to do one. */ | |
dd277d48 | 1180 | if (!(flags & TODO_update_ssa_any) && need_ssa_update_p (cfun)) |
ae79515f | 1181 | flags |= TODO_update_ssa; |
77fce4cd | 1182 | } |
a49a878f | 1183 | |
91be5bb8 | 1184 | if (flags & TODO_update_ssa_any) |
1185 | { | |
1186 | unsigned update_flags = flags & TODO_update_ssa_any; | |
1187 | update_ssa (update_flags); | |
80f94d49 | 1188 | cfun->last_verified &= ~TODO_verify_ssa; |
91be5bb8 | 1189 | } |
48e1416a | 1190 | |
b1b7c0c4 | 1191 | if (flags & TODO_rebuild_alias) |
1192 | { | |
5ea2e42f | 1193 | execute_update_addresses_taken (); |
b1b7c0c4 | 1194 | compute_may_aliases (); |
b1b7c0c4 | 1195 | } |
5ea2e42f | 1196 | else if (optimize && (flags & TODO_update_address_taken)) |
1197 | execute_update_addresses_taken (); | |
48e1416a | 1198 | |
db22d3cc | 1199 | if (flags & TODO_remove_unused_locals) |
1200 | remove_unused_locals (); | |
1201 | ||
75a70cf9 | 1202 | if ((flags & TODO_dump_func) && dump_file && current_function_decl) |
77fce4cd | 1203 | { |
80f94d49 | 1204 | if (cfun->curr_properties & PROP_trees) |
75a70cf9 | 1205 | dump_function_to_file (current_function_decl, dump_file, dump_flags); |
75ab26dc | 1206 | else |
5f0ef107 | 1207 | { |
75ab26dc | 1208 | if (dump_flags & TDF_SLIM) |
1209 | print_rtl_slim_with_bb (dump_file, get_insns (), dump_flags); | |
80f94d49 | 1210 | else if ((cfun->curr_properties & PROP_cfg) |
1211 | && (dump_flags & TDF_BLOCKS)) | |
75ab26dc | 1212 | print_rtl_with_bb (dump_file, get_insns ()); |
1213 | else | |
1214 | print_rtl (dump_file, get_insns ()); | |
1215 | ||
75a70cf9 | 1216 | if ((cfun->curr_properties & PROP_cfg) |
75ab26dc | 1217 | && graph_dump_format != no_graph |
5f0ef107 | 1218 | && (dump_flags & TDF_GRAPH)) |
1219 | print_rtl_graph_with_bb (dump_file_name, get_insns ()); | |
1220 | } | |
77fce4cd | 1221 | |
1222 | /* Flush the file. If verification fails, we won't be able to | |
1223 | close the file before aborting. */ | |
1224 | fflush (dump_file); | |
1225 | } | |
80f94d49 | 1226 | |
4ae20857 | 1227 | if (flags & TODO_rebuild_frequencies) |
555e8b05 | 1228 | rebuild_frequencies (); |
4ae20857 | 1229 | |
e1250294 | 1230 | /* If we've seen errors do not bother running any verifiers. */ |
1231 | if (seen_error ()) | |
1232 | return; | |
1233 | ||
80f94d49 | 1234 | #if defined ENABLE_CHECKING |
ca77c6ec | 1235 | if (flags & TODO_verify_ssa |
1236 | || (current_loops && loops_state_satisfies_p (LOOP_CLOSED_SSA))) | |
80f94d49 | 1237 | verify_ssa (true); |
1238 | if (flags & TODO_verify_flow) | |
1239 | verify_flow_info (); | |
1240 | if (flags & TODO_verify_stmts) | |
1241 | verify_stmts (); | |
a29ec3eb | 1242 | if (current_loops && loops_state_satisfies_p (LOOP_CLOSED_SSA)) |
ca77c6ec | 1243 | verify_loop_closed_ssa (false); |
0806b508 | 1244 | if (flags & TODO_verify_rtl_sharing) |
1245 | verify_rtl_sharing (); | |
80f94d49 | 1246 | #endif |
1247 | ||
1248 | cfun->last_verified = flags & TODO_verify_all; | |
1249 | } | |
1250 | ||
1251 | /* Perform all TODO actions. */ | |
1252 | static void | |
1253 | execute_todo (unsigned int flags) | |
1254 | { | |
1255 | #if defined ENABLE_CHECKING | |
dd277d48 | 1256 | if (cfun |
1257 | && need_ssa_update_p (cfun)) | |
80f94d49 | 1258 | gcc_assert (flags & TODO_update_ssa_any); |
1259 | #endif | |
1260 | ||
4b366dd3 | 1261 | timevar_push (TV_TODO); |
1262 | ||
7e0311ae | 1263 | /* Inform the pass whether it is the first time it is run. */ |
1264 | first_pass_instance = (flags & TODO_mark_first_instance) != 0; | |
1265 | ||
8e50b5dd | 1266 | statistics_fini_pass (); |
1267 | ||
80f94d49 | 1268 | do_per_function (execute_function_todo, (void *)(size_t) flags); |
1269 | ||
f37a5008 | 1270 | /* Always remove functions just as before inlining: IPA passes might be |
1271 | interested to see bodies of extern inline functions that are not inlined | |
1272 | to analyze side effects. The full removal is done just at the end | |
1273 | of IPA pass queue. */ | |
1274 | if (flags & TODO_remove_functions) | |
fba7ae09 | 1275 | { |
1276 | gcc_assert (!cfun); | |
1277 | cgraph_remove_unreachable_nodes (true, dump_file); | |
1278 | } | |
f37a5008 | 1279 | |
75a70cf9 | 1280 | if ((flags & TODO_dump_cgraph) && dump_file && !current_function_decl) |
77fce4cd | 1281 | { |
fba7ae09 | 1282 | gcc_assert (!cfun); |
77fce4cd | 1283 | dump_cgraph (dump_file); |
1284 | /* Flush the file. If verification fails, we won't be able to | |
1285 | close the file before aborting. */ | |
1286 | fflush (dump_file); | |
1287 | } | |
a49a878f | 1288 | |
77fce4cd | 1289 | if (flags & TODO_ggc_collect) |
75a70cf9 | 1290 | ggc_collect (); |
3072d30e | 1291 | |
48e1416a | 1292 | /* Now that the dumping has been done, we can get rid of the optional |
3072d30e | 1293 | df problems. */ |
1294 | if (flags & TODO_df_finish) | |
314966f4 | 1295 | df_finish_pass ((flags & TODO_df_verify) != 0); |
4b366dd3 | 1296 | |
1297 | timevar_pop (TV_TODO); | |
80f94d49 | 1298 | } |
da2f1613 | 1299 | |
add6ee5e | 1300 | /* Verify invariants that should hold between passes. This is a place |
1301 | to put simple sanity checks. */ | |
1302 | ||
1303 | static void | |
1304 | verify_interpass_invariants (void) | |
1305 | { | |
1b4345f7 | 1306 | gcc_checking_assert (!fold_deferring_overflow_warnings_p ()); |
add6ee5e | 1307 | } |
1308 | ||
80f94d49 | 1309 | /* Clear the last verified flag. */ |
1310 | ||
1311 | static void | |
1312 | clear_last_verified (void *data ATTRIBUTE_UNUSED) | |
1313 | { | |
1314 | cfun->last_verified = 0; | |
1315 | } | |
1316 | ||
1317 | /* Helper function. Verify that the properties has been turn into the | |
1318 | properties expected by the pass. */ | |
6354626c | 1319 | |
14c14128 | 1320 | #ifdef ENABLE_CHECKING |
80f94d49 | 1321 | static void |
1322 | verify_curr_properties (void *data) | |
1323 | { | |
1324 | unsigned int props = (size_t)data; | |
1325 | gcc_assert ((cfun->curr_properties & props) == props); | |
1326 | } | |
14c14128 | 1327 | #endif |
80f94d49 | 1328 | |
68e3904e | 1329 | /* Initialize pass dump file. */ |
c9036234 | 1330 | /* This is non-static so that the plugins can use it. */ |
68e3904e | 1331 | |
c9036234 | 1332 | bool |
68e3904e | 1333 | pass_init_dump_file (struct opt_pass *pass) |
1334 | { | |
1335 | /* If a dump file name is present, open it if enabled. */ | |
1336 | if (pass->static_pass_number != -1) | |
1337 | { | |
1338 | bool initializing_dump = !dump_initialized_p (pass->static_pass_number); | |
1339 | dump_file_name = get_dump_file_name (pass->static_pass_number); | |
1340 | dump_file = dump_begin (pass->static_pass_number, &dump_flags); | |
1341 | if (dump_file && current_function_decl) | |
1342 | { | |
1343 | const char *dname, *aname; | |
125b6d78 | 1344 | struct cgraph_node *node = cgraph_node (current_function_decl); |
68e3904e | 1345 | dname = lang_hooks.decl_printable_name (current_function_decl, 2); |
1346 | aname = (IDENTIFIER_POINTER | |
1347 | (DECL_ASSEMBLER_NAME (current_function_decl))); | |
0300832e | 1348 | fprintf (dump_file, "\n;; Function %s (%s)%s\n\n", dname, aname, |
125b6d78 | 1349 | node->frequency == NODE_FREQUENCY_HOT |
68e3904e | 1350 | ? " (hot)" |
125b6d78 | 1351 | : node->frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED |
68e3904e | 1352 | ? " (unlikely executed)" |
125b6d78 | 1353 | : node->frequency == NODE_FREQUENCY_EXECUTED_ONCE |
1354 | ? " (executed once)" | |
68e3904e | 1355 | : ""); |
1356 | } | |
1357 | return initializing_dump; | |
1358 | } | |
1359 | else | |
1360 | return false; | |
1361 | } | |
1362 | ||
1363 | /* Flush PASS dump file. */ | |
c9036234 | 1364 | /* This is non-static so that plugins can use it. */ |
68e3904e | 1365 | |
c9036234 | 1366 | void |
68e3904e | 1367 | pass_fini_dump_file (struct opt_pass *pass) |
1368 | { | |
1369 | /* Flush and close dump file. */ | |
1370 | if (dump_file_name) | |
1371 | { | |
1372 | free (CONST_CAST (char *, dump_file_name)); | |
1373 | dump_file_name = NULL; | |
1374 | } | |
1375 | ||
1376 | if (dump_file) | |
1377 | { | |
1378 | dump_end (pass->static_pass_number, dump_file); | |
1379 | dump_file = NULL; | |
1380 | } | |
1381 | } | |
1382 | ||
80f94d49 | 1383 | /* After executing the pass, apply expected changes to the function |
1384 | properties. */ | |
68e3904e | 1385 | |
80f94d49 | 1386 | static void |
1387 | update_properties_after_pass (void *data) | |
1388 | { | |
4077bf7a | 1389 | struct opt_pass *pass = (struct opt_pass *) data; |
80f94d49 | 1390 | cfun->curr_properties = (cfun->curr_properties | pass->properties_provided) |
1391 | & ~pass->properties_destroyed; | |
a49a878f | 1392 | } |
1393 | ||
9c1bff7a | 1394 | /* Execute summary generation for all of the passes in IPA_PASS. */ |
68e3904e | 1395 | |
7bfefa9d | 1396 | void |
26dbec0a | 1397 | execute_ipa_summary_passes (struct ipa_opt_pass_d *ipa_pass) |
68e3904e | 1398 | { |
9c1bff7a | 1399 | while (ipa_pass) |
68e3904e | 1400 | { |
1401 | struct opt_pass *pass = &ipa_pass->pass; | |
9c1bff7a | 1402 | |
1403 | /* Execute all of the IPA_PASSes in the list. */ | |
48e1416a | 1404 | if (ipa_pass->pass.type == IPA_PASS |
7bfefa9d | 1405 | && (!pass->gate || pass->gate ()) |
1406 | && ipa_pass->generate_summary) | |
68e3904e | 1407 | { |
1408 | pass_init_dump_file (pass); | |
7bfefa9d | 1409 | |
1410 | /* If a timevar is present, start it. */ | |
1411 | if (pass->tv_id) | |
1412 | timevar_push (pass->tv_id); | |
1413 | ||
9c1bff7a | 1414 | ipa_pass->generate_summary (); |
7bfefa9d | 1415 | |
1416 | /* Stop timevar. */ | |
1417 | if (pass->tv_id) | |
1418 | timevar_pop (pass->tv_id); | |
1419 | ||
68e3904e | 1420 | pass_fini_dump_file (pass); |
1421 | } | |
26dbec0a | 1422 | ipa_pass = (struct ipa_opt_pass_d *)ipa_pass->pass.next; |
68e3904e | 1423 | } |
1424 | } | |
1425 | ||
1426 | /* Execute IPA_PASS function transform on NODE. */ | |
1427 | ||
1428 | static void | |
1429 | execute_one_ipa_transform_pass (struct cgraph_node *node, | |
26dbec0a | 1430 | struct ipa_opt_pass_d *ipa_pass) |
68e3904e | 1431 | { |
1432 | struct opt_pass *pass = &ipa_pass->pass; | |
1433 | unsigned int todo_after = 0; | |
1434 | ||
1435 | current_pass = pass; | |
1436 | if (!ipa_pass->function_transform) | |
1437 | return; | |
1438 | ||
1439 | /* Note that the folders should only create gimple expressions. | |
1440 | This is a hack until the new folder is ready. */ | |
1441 | in_gimple_form = (cfun && (cfun->curr_properties & PROP_trees)) != 0; | |
1442 | ||
1443 | pass_init_dump_file (pass); | |
1444 | ||
1445 | /* Run pre-pass verification. */ | |
fba7ae09 | 1446 | execute_todo (ipa_pass->function_transform_todo_flags_start); |
68e3904e | 1447 | |
1448 | /* If a timevar is present, start it. */ | |
0b1615c1 | 1449 | if (pass->tv_id != TV_NONE) |
68e3904e | 1450 | timevar_push (pass->tv_id); |
1451 | ||
1452 | /* Do it! */ | |
1453 | todo_after = ipa_pass->function_transform (node); | |
1454 | ||
1455 | /* Stop timevar. */ | |
0b1615c1 | 1456 | if (pass->tv_id != TV_NONE) |
68e3904e | 1457 | timevar_pop (pass->tv_id); |
1458 | ||
1459 | /* Run post-pass cleanup and verification. */ | |
1460 | execute_todo (todo_after); | |
1461 | verify_interpass_invariants (); | |
1462 | ||
1463 | pass_fini_dump_file (pass); | |
1464 | ||
1465 | current_pass = NULL; | |
68e3904e | 1466 | } |
1467 | ||
7bfefa9d | 1468 | /* For the current function, execute all ipa transforms. */ |
5d48fdb4 | 1469 | |
7bfefa9d | 1470 | void |
1471 | execute_all_ipa_transforms (void) | |
1472 | { | |
6d1cc52c | 1473 | struct cgraph_node *node; |
1474 | if (!cfun) | |
1475 | return; | |
1476 | node = cgraph_node (current_function_decl); | |
5a2aecd6 | 1477 | |
6d1cc52c | 1478 | if (node->ipa_transforms_to_apply) |
68e3904e | 1479 | { |
1480 | unsigned int i; | |
68e3904e | 1481 | |
6d1cc52c | 1482 | for (i = 0; i < VEC_length (ipa_opt_pass, node->ipa_transforms_to_apply); |
68e3904e | 1483 | i++) |
1484 | execute_one_ipa_transform_pass (node, | |
7bfefa9d | 1485 | VEC_index (ipa_opt_pass, |
6d1cc52c | 1486 | node->ipa_transforms_to_apply, |
68e3904e | 1487 | i)); |
6d1cc52c | 1488 | VEC_free (ipa_opt_pass, heap, node->ipa_transforms_to_apply); |
1489 | node->ipa_transforms_to_apply = NULL; | |
68e3904e | 1490 | } |
7bfefa9d | 1491 | } |
1492 | ||
1493 | /* Execute PASS. */ | |
1494 | ||
c9036234 | 1495 | bool |
7bfefa9d | 1496 | execute_one_pass (struct opt_pass *pass) |
1497 | { | |
1498 | bool initializing_dump; | |
1499 | unsigned int todo_after = 0; | |
1500 | ||
c9036234 | 1501 | bool gate_status; |
1502 | ||
7bfefa9d | 1503 | /* IPA passes are executed on whole program, so cfun should be NULL. |
1504 | Other passes need function context set. */ | |
1505 | if (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS) | |
1506 | gcc_assert (!cfun && !current_function_decl); | |
1507 | else | |
1508 | gcc_assert (cfun && current_function_decl); | |
68e3904e | 1509 | |
3072d30e | 1510 | current_pass = pass; |
75a70cf9 | 1511 | |
c9036234 | 1512 | /* Check whether gate check should be avoided. |
1513 | User controls the value of the gate through the parameter "gate_status". */ | |
1514 | gate_status = (pass->gate == NULL) ? true : pass->gate(); | |
1515 | ||
1516 | /* Override gate with plugin. */ | |
1517 | invoke_plugin_callbacks (PLUGIN_OVERRIDE_GATE, &gate_status); | |
1518 | ||
1519 | if (!gate_status) | |
1520 | { | |
1521 | current_pass = NULL; | |
1522 | return false; | |
1523 | } | |
1524 | ||
1525 | /* Pass execution event trigger: useful to identify passes being | |
1526 | executed. */ | |
1527 | invoke_plugin_callbacks (PLUGIN_PASS_EXECUTION, pass); | |
a49a878f | 1528 | |
fa0ccb6b | 1529 | if (!quiet_flag && !cfun) |
09a2e412 | 1530 | fprintf (stderr, " <%s>", pass->name ? pass->name : ""); |
1531 | ||
77fce4cd | 1532 | /* Note that the folders should only create gimple expressions. |
1533 | This is a hack until the new folder is ready. */ | |
80f94d49 | 1534 | in_gimple_form = (cfun && (cfun->curr_properties & PROP_trees)) != 0; |
a49a878f | 1535 | |
dd277d48 | 1536 | initializing_dump = pass_init_dump_file (pass); |
1537 | ||
77fce4cd | 1538 | /* Run pre-pass verification. */ |
6354626c | 1539 | execute_todo (pass->todo_flags_start); |
1540 | ||
80f94d49 | 1541 | #ifdef ENABLE_CHECKING |
1542 | do_per_function (verify_curr_properties, | |
1543 | (void *)(size_t)pass->properties_required); | |
1544 | #endif | |
a49a878f | 1545 | |
77fce4cd | 1546 | /* If a timevar is present, start it. */ |
0b1615c1 | 1547 | if (pass->tv_id != TV_NONE) |
77fce4cd | 1548 | timevar_push (pass->tv_id); |
a49a878f | 1549 | |
77fce4cd | 1550 | /* Do it! */ |
1551 | if (pass->execute) | |
6354626c | 1552 | { |
2a1990e9 | 1553 | todo_after = pass->execute (); |
80f94d49 | 1554 | do_per_function (clear_last_verified, NULL); |
6354626c | 1555 | } |
a49a878f | 1556 | |
77fce4cd | 1557 | /* Stop timevar. */ |
0b1615c1 | 1558 | if (pass->tv_id != TV_NONE) |
77fce4cd | 1559 | timevar_pop (pass->tv_id); |
a49a878f | 1560 | |
80f94d49 | 1561 | do_per_function (update_properties_after_pass, pass); |
6354626c | 1562 | |
1563 | if (initializing_dump | |
1564 | && dump_file | |
1565 | && graph_dump_format != no_graph | |
d885a412 | 1566 | && cfun |
80f94d49 | 1567 | && (cfun->curr_properties & (PROP_cfg | PROP_rtl)) |
1568 | == (PROP_cfg | PROP_rtl)) | |
6354626c | 1569 | { |
1570 | get_dump_file_info (pass->static_pass_number)->flags |= TDF_GRAPH; | |
1571 | dump_flags |= TDF_GRAPH; | |
1572 | clean_graph_dump_file (dump_file_name); | |
1573 | } | |
1574 | ||
77fce4cd | 1575 | /* Run post-pass cleanup and verification. */ |
2a1990e9 | 1576 | execute_todo (todo_after | pass->todo_flags_finish); |
add6ee5e | 1577 | verify_interpass_invariants (); |
68e3904e | 1578 | if (pass->type == IPA_PASS) |
6d1cc52c | 1579 | { |
1580 | struct cgraph_node *node; | |
1581 | for (node = cgraph_nodes; node; node = node->next) | |
1582 | if (node->analyzed) | |
1583 | VEC_safe_push (ipa_opt_pass, heap, node->ipa_transforms_to_apply, | |
1584 | (struct ipa_opt_pass_d *)pass); | |
1585 | } | |
a49a878f | 1586 | |
523c1122 | 1587 | if (!current_function_decl) |
1588 | cgraph_process_new_functions (); | |
1589 | ||
68e3904e | 1590 | pass_fini_dump_file (pass); |
a49a878f | 1591 | |
68e3904e | 1592 | if (pass->type != SIMPLE_IPA_PASS && pass->type != IPA_PASS) |
18d50ae6 | 1593 | gcc_assert (!(cfun->curr_properties & PROP_trees) |
1594 | || pass->type != RTL_PASS); | |
1595 | ||
3072d30e | 1596 | current_pass = NULL; |
159787b7 | 1597 | |
77fce4cd | 1598 | return true; |
a49a878f | 1599 | } |
1600 | ||
77fce4cd | 1601 | void |
20099e35 | 1602 | execute_pass_list (struct opt_pass *pass) |
a49a878f | 1603 | { |
77fce4cd | 1604 | do |
a49a878f | 1605 | { |
5d48fdb4 | 1606 | gcc_assert (pass->type == GIMPLE_PASS |
1607 | || pass->type == RTL_PASS); | |
77fce4cd | 1608 | if (execute_one_pass (pass) && pass->sub) |
1609 | execute_pass_list (pass->sub); | |
1610 | pass = pass->next; | |
a49a878f | 1611 | } |
77fce4cd | 1612 | while (pass); |
a49a878f | 1613 | } |
1614 | ||
77fce4cd | 1615 | /* Same as execute_pass_list but assume that subpasses of IPA passes |
7bfefa9d | 1616 | are local passes. If SET is not NULL, write out summaries of only |
1617 | those node in SET. */ | |
1618 | ||
1619 | static void | |
1620 | ipa_write_summaries_2 (struct opt_pass *pass, cgraph_node_set set, | |
0cddb138 | 1621 | varpool_node_set vset, |
7bfefa9d | 1622 | struct lto_out_decl_state *state) |
1623 | { | |
1624 | while (pass) | |
1625 | { | |
1626 | struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *)pass; | |
1627 | gcc_assert (!current_function_decl); | |
1628 | gcc_assert (!cfun); | |
1629 | gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS); | |
1630 | if (pass->type == IPA_PASS | |
1631 | && ipa_pass->write_summary | |
1632 | && (!pass->gate || pass->gate ())) | |
1633 | { | |
1634 | /* If a timevar is present, start it. */ | |
1635 | if (pass->tv_id) | |
1636 | timevar_push (pass->tv_id); | |
1637 | ||
2da8af1f | 1638 | pass_init_dump_file (pass); |
1639 | ||
0cddb138 | 1640 | ipa_pass->write_summary (set,vset); |
7bfefa9d | 1641 | |
2da8af1f | 1642 | pass_fini_dump_file (pass); |
1643 | ||
7bfefa9d | 1644 | /* If a timevar is present, start it. */ |
1645 | if (pass->tv_id) | |
1646 | timevar_pop (pass->tv_id); | |
1647 | } | |
1648 | ||
1649 | if (pass->sub && pass->sub->type != GIMPLE_PASS) | |
0cddb138 | 1650 | ipa_write_summaries_2 (pass->sub, set, vset, state); |
7bfefa9d | 1651 | |
1652 | pass = pass->next; | |
1653 | } | |
1654 | } | |
1655 | ||
1656 | /* Helper function of ipa_write_summaries. Creates and destroys the | |
1657 | decl state and calls ipa_write_summaries_2 for all passes that have | |
1658 | summaries. SET is the set of nodes to be written. */ | |
1659 | ||
1660 | static void | |
0cddb138 | 1661 | ipa_write_summaries_1 (cgraph_node_set set, varpool_node_set vset) |
7bfefa9d | 1662 | { |
1663 | struct lto_out_decl_state *state = lto_new_out_decl_state (); | |
d97be713 | 1664 | compute_ltrans_boundary (state, set, vset); |
a33890d0 | 1665 | |
7bfefa9d | 1666 | lto_push_out_decl_state (state); |
1667 | ||
ddc90d88 | 1668 | gcc_assert (!flag_wpa); |
0cddb138 | 1669 | ipa_write_summaries_2 (all_regular_ipa_passes, set, vset, state); |
1670 | ipa_write_summaries_2 (all_lto_gen_passes, set, vset, state); | |
7bfefa9d | 1671 | |
1672 | gcc_assert (lto_get_out_decl_state () == state); | |
1673 | lto_pop_out_decl_state (); | |
1674 | lto_delete_out_decl_state (state); | |
1675 | } | |
1676 | ||
1677 | /* Write out summaries for all the nodes in the callgraph. */ | |
1678 | ||
77fce4cd | 1679 | void |
7bfefa9d | 1680 | ipa_write_summaries (void) |
a49a878f | 1681 | { |
7bfefa9d | 1682 | cgraph_node_set set; |
0cddb138 | 1683 | varpool_node_set vset; |
7bfefa9d | 1684 | struct cgraph_node **order; |
0cddb138 | 1685 | struct varpool_node *vnode; |
7bfefa9d | 1686 | int i, order_pos; |
48e1416a | 1687 | |
852f689e | 1688 | if (!flag_generate_lto || seen_error ()) |
7bfefa9d | 1689 | return; |
1690 | ||
7bfefa9d | 1691 | set = cgraph_node_set_new (); |
1692 | ||
1693 | /* Create the callgraph set in the same order used in | |
1694 | cgraph_expand_all_functions. This mostly facilitates debugging, | |
1695 | since it causes the gimple file to be processed in the same order | |
1696 | as the source code. */ | |
1697 | order = XCNEWVEC (struct cgraph_node *, cgraph_n_nodes); | |
1698 | order_pos = cgraph_postorder (order); | |
1699 | gcc_assert (order_pos == cgraph_n_nodes); | |
1700 | ||
1701 | for (i = order_pos - 1; i >= 0; i--) | |
8e78b58c | 1702 | { |
1703 | struct cgraph_node *node = order[i]; | |
1704 | ||
1705 | if (node->analyzed) | |
1706 | { | |
1707 | /* When streaming out references to statements as part of some IPA | |
1708 | pass summary, the statements need to have uids assigned and the | |
1709 | following does that for all the IPA passes here. Naturally, this | |
1710 | ordering then matches the one IPA-passes get in their stmt_fixup | |
1711 | hooks. */ | |
1712 | ||
1713 | push_cfun (DECL_STRUCT_FUNCTION (node->decl)); | |
1714 | renumber_gimple_stmt_uids (); | |
1715 | pop_cfun (); | |
1716 | } | |
7c1a227e | 1717 | if (node->analyzed) |
0cddb138 | 1718 | cgraph_node_set_add (set, node); |
8e78b58c | 1719 | } |
0cddb138 | 1720 | vset = varpool_node_set_new (); |
7bfefa9d | 1721 | |
0cddb138 | 1722 | for (vnode = varpool_nodes; vnode; vnode = vnode->next) |
1723 | if (vnode->needed && !vnode->alias) | |
1724 | varpool_node_set_add (vset, vnode); | |
1725 | ||
1726 | ipa_write_summaries_1 (set, vset); | |
7bfefa9d | 1727 | |
1728 | free (order); | |
1729 | ggc_free (set); | |
0cddb138 | 1730 | ggc_free (vset); |
7bfefa9d | 1731 | } |
1732 | ||
ddc90d88 | 1733 | /* Same as execute_pass_list but assume that subpasses of IPA passes |
1734 | are local passes. If SET is not NULL, write out optimization summaries of | |
1735 | only those node in SET. */ | |
7bfefa9d | 1736 | |
ddc90d88 | 1737 | static void |
1738 | ipa_write_optimization_summaries_1 (struct opt_pass *pass, cgraph_node_set set, | |
0cddb138 | 1739 | varpool_node_set vset, |
ddc90d88 | 1740 | struct lto_out_decl_state *state) |
1741 | { | |
1742 | while (pass) | |
1743 | { | |
1744 | struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *)pass; | |
1745 | gcc_assert (!current_function_decl); | |
1746 | gcc_assert (!cfun); | |
1747 | gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS); | |
1748 | if (pass->type == IPA_PASS | |
1749 | && ipa_pass->write_optimization_summary | |
1750 | && (!pass->gate || pass->gate ())) | |
1751 | { | |
1752 | /* If a timevar is present, start it. */ | |
1753 | if (pass->tv_id) | |
1754 | timevar_push (pass->tv_id); | |
1755 | ||
2da8af1f | 1756 | pass_init_dump_file (pass); |
1757 | ||
0cddb138 | 1758 | ipa_pass->write_optimization_summary (set, vset); |
ddc90d88 | 1759 | |
2da8af1f | 1760 | pass_fini_dump_file (pass); |
1761 | ||
ddc90d88 | 1762 | /* If a timevar is present, start it. */ |
1763 | if (pass->tv_id) | |
1764 | timevar_pop (pass->tv_id); | |
1765 | } | |
1766 | ||
1767 | if (pass->sub && pass->sub->type != GIMPLE_PASS) | |
0cddb138 | 1768 | ipa_write_optimization_summaries_1 (pass->sub, set, vset, state); |
ddc90d88 | 1769 | |
1770 | pass = pass->next; | |
1771 | } | |
1772 | } | |
1773 | ||
1774 | /* Write all the optimization summaries for the cgraph nodes in SET. If SET is | |
7bfefa9d | 1775 | NULL, write out all summaries of all nodes. */ |
1776 | ||
1777 | void | |
0cddb138 | 1778 | ipa_write_optimization_summaries (cgraph_node_set set, varpool_node_set vset) |
7bfefa9d | 1779 | { |
ddc90d88 | 1780 | struct lto_out_decl_state *state = lto_new_out_decl_state (); |
c5cc4842 | 1781 | cgraph_node_set_iterator csi; |
d97be713 | 1782 | compute_ltrans_boundary (state, set, vset); |
1783 | ||
ddc90d88 | 1784 | lto_push_out_decl_state (state); |
c5cc4842 | 1785 | for (csi = csi_start (set); !csi_end_p (csi); csi_next (&csi)) |
1786 | { | |
1787 | struct cgraph_node *node = csi_node (csi); | |
1788 | /* When streaming out references to statements as part of some IPA | |
1789 | pass summary, the statements need to have uids assigned. | |
1790 | ||
1791 | For functions newly born at WPA stage we need to initialize | |
1792 | the uids here. */ | |
1793 | if (node->analyzed | |
1794 | && gimple_has_body_p (node->decl)) | |
1795 | { | |
1796 | push_cfun (DECL_STRUCT_FUNCTION (node->decl)); | |
1797 | renumber_gimple_stmt_uids (); | |
1798 | pop_cfun (); | |
1799 | } | |
1800 | } | |
ddc90d88 | 1801 | |
1802 | gcc_assert (flag_wpa); | |
0cddb138 | 1803 | ipa_write_optimization_summaries_1 (all_regular_ipa_passes, set, vset, state); |
1804 | ipa_write_optimization_summaries_1 (all_lto_gen_passes, set, vset, state); | |
ddc90d88 | 1805 | |
1806 | gcc_assert (lto_get_out_decl_state () == state); | |
1807 | lto_pop_out_decl_state (); | |
1808 | lto_delete_out_decl_state (state); | |
7bfefa9d | 1809 | } |
1810 | ||
1811 | /* Same as execute_pass_list but assume that subpasses of IPA passes | |
1812 | are local passes. */ | |
1813 | ||
1814 | static void | |
1815 | ipa_read_summaries_1 (struct opt_pass *pass) | |
1816 | { | |
1817 | while (pass) | |
a49a878f | 1818 | { |
7bfefa9d | 1819 | struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *) pass; |
1820 | ||
80f94d49 | 1821 | gcc_assert (!current_function_decl); |
1822 | gcc_assert (!cfun); | |
68e3904e | 1823 | gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS); |
7bfefa9d | 1824 | |
1825 | if (pass->gate == NULL || pass->gate ()) | |
68e3904e | 1826 | { |
7bfefa9d | 1827 | if (pass->type == IPA_PASS && ipa_pass->read_summary) |
68e3904e | 1828 | { |
7bfefa9d | 1829 | /* If a timevar is present, start it. */ |
1830 | if (pass->tv_id) | |
1831 | timevar_push (pass->tv_id); | |
1832 | ||
2da8af1f | 1833 | pass_init_dump_file (pass); |
1834 | ||
7bfefa9d | 1835 | ipa_pass->read_summary (); |
1836 | ||
2da8af1f | 1837 | pass_fini_dump_file (pass); |
1838 | ||
7bfefa9d | 1839 | /* Stop timevar. */ |
1840 | if (pass->tv_id) | |
1841 | timevar_pop (pass->tv_id); | |
68e3904e | 1842 | } |
7bfefa9d | 1843 | |
1844 | if (pass->sub && pass->sub->type != GIMPLE_PASS) | |
1845 | ipa_read_summaries_1 (pass->sub); | |
68e3904e | 1846 | } |
7bfefa9d | 1847 | pass = pass->next; |
1848 | } | |
1849 | } | |
1850 | ||
1851 | ||
1852 | /* Read all the summaries for all_regular_ipa_passes and all_lto_gen_passes. */ | |
1853 | ||
1854 | void | |
1855 | ipa_read_summaries (void) | |
1856 | { | |
ddc90d88 | 1857 | ipa_read_summaries_1 (all_regular_ipa_passes); |
7bfefa9d | 1858 | ipa_read_summaries_1 (all_lto_gen_passes); |
1859 | } | |
1860 | ||
ddc90d88 | 1861 | /* Same as execute_pass_list but assume that subpasses of IPA passes |
1862 | are local passes. */ | |
1863 | ||
1864 | static void | |
1865 | ipa_read_optimization_summaries_1 (struct opt_pass *pass) | |
1866 | { | |
1867 | while (pass) | |
1868 | { | |
1869 | struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *) pass; | |
1870 | ||
1871 | gcc_assert (!current_function_decl); | |
1872 | gcc_assert (!cfun); | |
1873 | gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS); | |
1874 | ||
1875 | if (pass->gate == NULL || pass->gate ()) | |
1876 | { | |
1877 | if (pass->type == IPA_PASS && ipa_pass->read_optimization_summary) | |
1878 | { | |
1879 | /* If a timevar is present, start it. */ | |
1880 | if (pass->tv_id) | |
1881 | timevar_push (pass->tv_id); | |
1882 | ||
2da8af1f | 1883 | pass_init_dump_file (pass); |
1884 | ||
ddc90d88 | 1885 | ipa_pass->read_optimization_summary (); |
1886 | ||
2da8af1f | 1887 | pass_fini_dump_file (pass); |
1888 | ||
ddc90d88 | 1889 | /* Stop timevar. */ |
1890 | if (pass->tv_id) | |
1891 | timevar_pop (pass->tv_id); | |
1892 | } | |
1893 | ||
1894 | if (pass->sub && pass->sub->type != GIMPLE_PASS) | |
1895 | ipa_read_optimization_summaries_1 (pass->sub); | |
1896 | } | |
1897 | pass = pass->next; | |
1898 | } | |
1899 | } | |
1900 | ||
1901 | /* Read all the summaries for all_regular_ipa_passes and all_lto_gen_passes. */ | |
1902 | ||
1903 | void | |
1904 | ipa_read_optimization_summaries (void) | |
1905 | { | |
1906 | ipa_read_optimization_summaries_1 (all_regular_ipa_passes); | |
1907 | ipa_read_optimization_summaries_1 (all_lto_gen_passes); | |
1908 | } | |
1909 | ||
7bfefa9d | 1910 | /* Same as execute_pass_list but assume that subpasses of IPA passes |
1911 | are local passes. */ | |
1912 | void | |
1913 | execute_ipa_pass_list (struct opt_pass *pass) | |
1914 | { | |
1915 | do | |
1916 | { | |
1917 | gcc_assert (!current_function_decl); | |
1918 | gcc_assert (!cfun); | |
1919 | gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS); | |
77fce4cd | 1920 | if (execute_one_pass (pass) && pass->sub) |
5d48fdb4 | 1921 | { |
1922 | if (pass->sub->type == GIMPLE_PASS) | |
c9036234 | 1923 | { |
1924 | invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_START, NULL); | |
1925 | do_per_function_toporder ((void (*)(void *))execute_pass_list, | |
1926 | pass->sub); | |
1927 | invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_END, NULL); | |
1928 | } | |
68e3904e | 1929 | else if (pass->sub->type == SIMPLE_IPA_PASS |
1930 | || pass->sub->type == IPA_PASS) | |
5d48fdb4 | 1931 | execute_ipa_pass_list (pass->sub); |
1932 | else | |
1933 | gcc_unreachable (); | |
1934 | } | |
7bfefa9d | 1935 | gcc_assert (!current_function_decl); |
1936 | cgraph_process_new_functions (); | |
77fce4cd | 1937 | pass = pass->next; |
a49a878f | 1938 | } |
77fce4cd | 1939 | while (pass); |
da2f1613 | 1940 | } |
9659d177 | 1941 | |
90464c8b | 1942 | /* Execute stmt fixup hooks of all passes in PASS for NODE and STMTS. */ |
1943 | ||
1944 | static void | |
1945 | execute_ipa_stmt_fixups (struct opt_pass *pass, | |
1946 | struct cgraph_node *node, gimple *stmts) | |
1947 | { | |
1948 | while (pass) | |
1949 | { | |
1950 | /* Execute all of the IPA_PASSes in the list. */ | |
1951 | if (pass->type == IPA_PASS | |
1952 | && (!pass->gate || pass->gate ())) | |
1953 | { | |
1954 | struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *) pass; | |
1955 | ||
1956 | if (ipa_pass->stmt_fixup) | |
1957 | { | |
1958 | pass_init_dump_file (pass); | |
1959 | /* If a timevar is present, start it. */ | |
1960 | if (pass->tv_id) | |
1961 | timevar_push (pass->tv_id); | |
1962 | ||
1963 | ipa_pass->stmt_fixup (node, stmts); | |
1964 | ||
1965 | /* Stop timevar. */ | |
1966 | if (pass->tv_id) | |
1967 | timevar_pop (pass->tv_id); | |
1968 | pass_fini_dump_file (pass); | |
1969 | } | |
1970 | if (pass->sub) | |
1971 | execute_ipa_stmt_fixups (pass->sub, node, stmts); | |
1972 | } | |
1973 | pass = pass->next; | |
1974 | } | |
1975 | } | |
1976 | ||
1977 | /* Execute stmt fixup hooks of all IPA passes for NODE and STMTS. */ | |
1978 | ||
1979 | void | |
1980 | execute_all_ipa_stmt_fixups (struct cgraph_node *node, gimple *stmts) | |
1981 | { | |
1982 | execute_ipa_stmt_fixups (all_regular_ipa_passes, node, stmts); | |
1983 | } | |
1984 | ||
1985 | ||
7bfefa9d | 1986 | extern void debug_properties (unsigned int); |
1987 | extern void dump_properties (FILE *, unsigned int); | |
1988 | ||
4b987fac | 1989 | DEBUG_FUNCTION void |
7bfefa9d | 1990 | dump_properties (FILE *dump, unsigned int props) |
1991 | { | |
1992 | fprintf (dump, "Properties:\n"); | |
1993 | if (props & PROP_gimple_any) | |
1994 | fprintf (dump, "PROP_gimple_any\n"); | |
1995 | if (props & PROP_gimple_lcf) | |
1996 | fprintf (dump, "PROP_gimple_lcf\n"); | |
1997 | if (props & PROP_gimple_leh) | |
1998 | fprintf (dump, "PROP_gimple_leh\n"); | |
1999 | if (props & PROP_cfg) | |
2000 | fprintf (dump, "PROP_cfg\n"); | |
2001 | if (props & PROP_referenced_vars) | |
2002 | fprintf (dump, "PROP_referenced_vars\n"); | |
2003 | if (props & PROP_ssa) | |
2004 | fprintf (dump, "PROP_ssa\n"); | |
2005 | if (props & PROP_no_crit_edges) | |
2006 | fprintf (dump, "PROP_no_crit_edges\n"); | |
2007 | if (props & PROP_rtl) | |
2008 | fprintf (dump, "PROP_rtl\n"); | |
2009 | if (props & PROP_gimple_lomp) | |
2010 | fprintf (dump, "PROP_gimple_lomp\n"); | |
7b76dcb9 | 2011 | if (props & PROP_gimple_lcx) |
2012 | fprintf (dump, "PROP_gimple_lcx\n"); | |
4b987fac | 2013 | if (props & PROP_cfglayout) |
2014 | fprintf (dump, "PROP_cfglayout\n"); | |
7bfefa9d | 2015 | } |
2016 | ||
4b987fac | 2017 | DEBUG_FUNCTION void |
7bfefa9d | 2018 | debug_properties (unsigned int props) |
2019 | { | |
2020 | dump_properties (stderr, props); | |
2021 | } | |
2022 | ||
b5cebd44 | 2023 | /* Called by local passes to see if function is called by already processed nodes. |
2024 | Because we process nodes in topological order, this means that function is | |
2025 | in recursive cycle or we introduced new direct calls. */ | |
2026 | bool | |
2027 | function_called_by_processed_nodes_p (void) | |
2028 | { | |
2029 | struct cgraph_edge *e; | |
2030 | for (e = cgraph_node (current_function_decl)->callers; e; e = e->next_caller) | |
2031 | { | |
2032 | if (e->caller->decl == current_function_decl) | |
2033 | continue; | |
59dd4830 | 2034 | if (!e->caller->analyzed) |
b5cebd44 | 2035 | continue; |
2036 | if (TREE_ASM_WRITTEN (e->caller->decl)) | |
2037 | continue; | |
2038 | if (!e->caller->process && !e->caller->global.inlined_to) | |
2039 | break; | |
2040 | } | |
2041 | if (dump_file && e) | |
2042 | { | |
2043 | fprintf (dump_file, "Already processed call to:\n"); | |
2044 | dump_cgraph_node (dump_file, e->caller); | |
2045 | } | |
2046 | return e != NULL; | |
2047 | } | |
2048 | ||
09a2e412 | 2049 | #include "gt-passes.h" |