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