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