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