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