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