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