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