]>
Commit | Line | Data |
---|---|---|
ac534736 | 1 | /* Top-level control of tree optimizations. |
ad616de1 | 2 | Copyright 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. |
6de9cd9a | 3 | Contributed by Diego Novillo <dnovillo@redhat.com> |
4985cde3 RH |
4 | |
5 | This file is part of GCC. | |
6 | ||
7 | GCC is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2, or (at your option) | |
10 | any later version. | |
11 | ||
12 | GCC is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GCC; see the file COPYING. If not, write to | |
19 | the Free Software Foundation, 59 Temple Place - Suite 330, | |
20 | Boston, MA 02111-1307, USA. */ | |
21 | ||
22 | #include "config.h" | |
23 | #include "system.h" | |
24 | #include "coretypes.h" | |
6de9cd9a | 25 | #include "tm.h" |
4985cde3 | 26 | #include "tree.h" |
6de9cd9a DN |
27 | #include "rtl.h" |
28 | #include "tm_p.h" | |
29 | #include "hard-reg-set.h" | |
30 | #include "basic-block.h" | |
31 | #include "output.h" | |
32 | #include "expr.h" | |
33 | #include "diagnostic.h" | |
34 | #include "basic-block.h" | |
4985cde3 | 35 | #include "flags.h" |
6de9cd9a DN |
36 | #include "tree-flow.h" |
37 | #include "tree-dump.h" | |
4985cde3 | 38 | #include "timevar.h" |
4985cde3 | 39 | #include "function.h" |
6de9cd9a DN |
40 | #include "langhooks.h" |
41 | #include "toplev.h" | |
42 | #include "flags.h" | |
43 | #include "cgraph.h" | |
44 | #include "tree-inline.h" | |
45 | #include "tree-mudflap.h" | |
46 | #include "tree-pass.h" | |
4985cde3 | 47 | #include "ggc.h" |
6de9cd9a | 48 | #include "cgraph.h" |
9f8628ba | 49 | #include "graph.h" |
2b271002 | 50 | #include "cfgloop.h" |
6de9cd9a DN |
51 | |
52 | ||
53 | /* Global variables used to communicate with passes. */ | |
54 | int dump_flags; | |
6de9cd9a DN |
55 | bool in_gimple_form; |
56 | ||
57 | /* The root of the compilation pass tree, once constructed. */ | |
b4861090 | 58 | static struct tree_opt_pass *all_passes, *all_ipa_passes; |
6de9cd9a | 59 | |
84936f6f | 60 | /* Pass: dump the gimplified, inlined, functions. */ |
6de9cd9a DN |
61 | |
62 | static struct tree_opt_pass pass_gimple = | |
63 | { | |
64 | "gimple", /* name */ | |
65 | NULL, /* gate */ | |
84936f6f | 66 | NULL, /* execute */ |
6de9cd9a DN |
67 | NULL, /* sub */ |
68 | NULL, /* next */ | |
69 | 0, /* static_pass_number */ | |
70 | 0, /* tv_id */ | |
71 | 0, /* properties_required */ | |
72 | PROP_gimple_any, /* properties_provided */ | |
73 | 0, /* properties_destroyed */ | |
74 | 0, /* todo_flags_start */ | |
9f8628ba PB |
75 | TODO_dump_func, /* todo_flags_finish */ |
76 | 0 /* letter */ | |
6de9cd9a DN |
77 | }; |
78 | ||
6de9cd9a DN |
79 | /* Gate: execute, or not, all of the non-trivial optimizations. */ |
80 | ||
81 | static bool | |
82 | gate_all_optimizations (void) | |
83 | { | |
84 | return (optimize >= 1 | |
85 | /* Don't bother doing anything if the program has errors. */ | |
86 | && !(errorcount || sorrycount)); | |
87 | } | |
88 | ||
89 | static struct tree_opt_pass pass_all_optimizations = | |
90 | { | |
91 | NULL, /* name */ | |
92 | gate_all_optimizations, /* gate */ | |
93 | NULL, /* execute */ | |
94 | NULL, /* sub */ | |
95 | NULL, /* next */ | |
96 | 0, /* static_pass_number */ | |
97 | 0, /* tv_id */ | |
98 | 0, /* properties_required */ | |
99 | 0, /* properties_provided */ | |
100 | 0, /* properties_destroyed */ | |
101 | 0, /* todo_flags_start */ | |
9f8628ba PB |
102 | 0, /* todo_flags_finish */ |
103 | 0 /* letter */ | |
6de9cd9a DN |
104 | }; |
105 | ||
165b54c3 SB |
106 | /* Pass: cleanup the CFG just before expanding trees to RTL. |
107 | This is just a round of label cleanups and case node grouping | |
108 | because after the tree optimizers have run such cleanups may | |
109 | be necessary. */ | |
110 | ||
111 | static void | |
112 | execute_cleanup_cfg_post_optimizing (void) | |
113 | { | |
114 | cleanup_tree_cfg (); | |
115 | cleanup_dead_labels (); | |
116 | group_case_labels (); | |
117 | } | |
118 | ||
119 | static struct tree_opt_pass pass_cleanup_cfg_post_optimizing = | |
120 | { | |
edfaf675 | 121 | "final_cleanup", /* name */ |
165b54c3 SB |
122 | NULL, /* gate */ |
123 | execute_cleanup_cfg_post_optimizing, /* execute */ | |
124 | NULL, /* sub */ | |
125 | NULL, /* next */ | |
126 | 0, /* static_pass_number */ | |
127 | 0, /* tv_id */ | |
128 | PROP_cfg, /* properties_required */ | |
129 | 0, /* properties_provided */ | |
130 | 0, /* properties_destroyed */ | |
131 | 0, /* todo_flags_start */ | |
edfaf675 | 132 | TODO_dump_func, /* todo_flags_finish */ |
9f8628ba | 133 | 0 /* letter */ |
165b54c3 SB |
134 | }; |
135 | ||
6de9cd9a DN |
136 | /* Pass: do the actions required to finish with tree-ssa optimization |
137 | passes. */ | |
138 | ||
139 | static void | |
242229bb | 140 | execute_free_datastructures (void) |
6de9cd9a | 141 | { |
6de9cd9a DN |
142 | tree *chain; |
143 | ||
144 | /* ??? This isn't the right place for this. Worse, it got computed | |
145 | more or less at random in various passes. */ | |
146 | free_dominance_info (CDI_DOMINATORS); | |
147 | ||
148 | /* Emit gotos for implicit jumps. */ | |
149 | disband_implicit_edges (); | |
150 | ||
151 | /* Remove the ssa structures. Do it here since this includes statement | |
152 | annotations that need to be intact during disband_implicit_edges. */ | |
153 | delete_tree_ssa (); | |
154 | ||
155 | /* Re-chain the statements from the blocks. */ | |
156 | chain = &DECL_SAVED_TREE (current_function_decl); | |
157 | *chain = alloc_stmt_list (); | |
6de9cd9a | 158 | |
242229bb JH |
159 | /* And get rid of annotations we no longer need. */ |
160 | delete_tree_cfg_annotations (); | |
6de9cd9a DN |
161 | } |
162 | ||
242229bb | 163 | static struct tree_opt_pass pass_free_datastructures = |
6de9cd9a DN |
164 | { |
165 | NULL, /* name */ | |
166 | NULL, /* gate */ | |
242229bb | 167 | execute_free_datastructures, /* execute */ |
6de9cd9a DN |
168 | NULL, /* sub */ |
169 | NULL, /* next */ | |
170 | 0, /* static_pass_number */ | |
171 | 0, /* tv_id */ | |
172 | PROP_cfg, /* properties_required */ | |
173 | 0, /* properties_provided */ | |
242229bb | 174 | 0, /* properties_destroyed */ |
6de9cd9a | 175 | 0, /* todo_flags_start */ |
9f8628ba PB |
176 | 0, /* todo_flags_finish */ |
177 | 0 /* letter */ | |
6de9cd9a DN |
178 | }; |
179 | ||
33c94679 DN |
180 | |
181 | /* Do the actions required to initialize internal data structures used | |
182 | in tree-ssa optimization passes. */ | |
183 | ||
184 | static void | |
185 | execute_init_datastructures (void) | |
186 | { | |
187 | /* Allocate hash tables, arrays and other structures. */ | |
188 | init_tree_ssa (); | |
189 | } | |
190 | ||
191 | static struct tree_opt_pass pass_init_datastructures = | |
192 | { | |
193 | NULL, /* name */ | |
194 | NULL, /* gate */ | |
195 | execute_init_datastructures, /* execute */ | |
196 | NULL, /* sub */ | |
197 | NULL, /* next */ | |
198 | 0, /* static_pass_number */ | |
199 | 0, /* tv_id */ | |
200 | PROP_cfg, /* properties_required */ | |
201 | 0, /* properties_provided */ | |
202 | 0, /* properties_destroyed */ | |
203 | 0, /* todo_flags_start */ | |
9f8628ba PB |
204 | 0, /* todo_flags_finish */ |
205 | 0 /* letter */ | |
33c94679 DN |
206 | }; |
207 | ||
6de9cd9a DN |
208 | /* Iterate over the pass tree allocating dump file numbers. We want |
209 | to do this depth first, and independent of whether the pass is | |
210 | enabled or not. */ | |
211 | ||
212 | static void | |
b4861090 | 213 | register_one_dump_file (struct tree_opt_pass *pass, bool ipa, int n) |
6de9cd9a | 214 | { |
f46fe224 | 215 | char *dot_name, *flag_name, *glob_name; |
6de9cd9a DN |
216 | char num[10]; |
217 | ||
b3fade83 | 218 | /* See below in next_pass_1. */ |
6de9cd9a | 219 | num[0] = '\0'; |
b3fade83 | 220 | if (pass->static_pass_number != -1) |
6de9cd9a DN |
221 | sprintf (num, "%d", ((int) pass->static_pass_number < 0 |
222 | ? 1 : pass->static_pass_number)); | |
223 | ||
224 | dot_name = concat (".", pass->name, num, NULL); | |
b4861090 JH |
225 | if (ipa) |
226 | { | |
227 | flag_name = concat ("ipa-", pass->name, num, NULL); | |
228 | glob_name = concat ("ipa-", pass->name, NULL); | |
229 | /* First IPA dump is cgraph that is dumped via separate channels. */ | |
230 | pass->static_pass_number = dump_register (dot_name, flag_name, glob_name, | |
231 | TDF_IPA, n + 1, 0); | |
232 | } | |
233 | else if (pass->properties_provided & PROP_trees) | |
9f8628ba PB |
234 | { |
235 | flag_name = concat ("tree-", pass->name, num, NULL); | |
f46fe224 DB |
236 | glob_name = concat ("tree-", pass->name, NULL); |
237 | pass->static_pass_number = dump_register (dot_name, flag_name, glob_name, | |
9f8628ba PB |
238 | TDF_TREE, n + TDI_tree_all, 0); |
239 | } | |
240 | else | |
241 | { | |
242 | flag_name = concat ("rtl-", pass->name, num, NULL); | |
f46fe224 DB |
243 | glob_name = concat ("rtl-", pass->name, NULL); |
244 | pass->static_pass_number = dump_register (dot_name, flag_name, glob_name, | |
9f8628ba PB |
245 | TDF_RTL, n, pass->letter); |
246 | } | |
6de9cd9a DN |
247 | } |
248 | ||
2f8e398b | 249 | static int |
b4861090 | 250 | register_dump_files (struct tree_opt_pass *pass, bool ipa, int properties) |
6de9cd9a | 251 | { |
9f8628ba | 252 | static int n = 0; |
6de9cd9a DN |
253 | do |
254 | { | |
9f8628ba PB |
255 | int new_properties; |
256 | int pass_number; | |
2f8e398b PB |
257 | |
258 | pass->properties_required = properties; | |
9f8628ba | 259 | new_properties = |
2f8e398b PB |
260 | (properties | pass->properties_provided) & ~pass->properties_destroyed; |
261 | ||
9f8628ba PB |
262 | /* Reset the counter when we reach RTL-based passes. */ |
263 | if ((pass->properties_provided ^ pass->properties_required) & PROP_rtl) | |
264 | n = 0; | |
265 | ||
266 | pass_number = n; | |
267 | if (pass->name) | |
268 | n++; | |
269 | ||
6de9cd9a | 270 | if (pass->sub) |
b4861090 | 271 | new_properties = register_dump_files (pass->sub, ipa, new_properties); |
9f8628ba PB |
272 | |
273 | /* If we have a gate, combine the properties that we could have with | |
274 | and without the pass being examined. */ | |
275 | if (pass->gate) | |
276 | properties &= new_properties; | |
277 | else | |
278 | properties = new_properties; | |
279 | ||
280 | pass->properties_provided = properties; | |
281 | if (pass->name) | |
b4861090 | 282 | register_one_dump_file (pass, ipa, pass_number); |
9f8628ba | 283 | |
6de9cd9a DN |
284 | pass = pass->next; |
285 | } | |
286 | while (pass); | |
2f8e398b PB |
287 | |
288 | return properties; | |
6de9cd9a DN |
289 | } |
290 | ||
b3fade83 BB |
291 | /* Add a pass to the pass list. Duplicate the pass if it's already |
292 | in the list. */ | |
6de9cd9a | 293 | |
b3fade83 BB |
294 | static struct tree_opt_pass ** |
295 | next_pass_1 (struct tree_opt_pass **list, struct tree_opt_pass *pass) | |
6de9cd9a | 296 | { |
6de9cd9a | 297 | |
8e3c61c5 | 298 | /* A nonzero static_pass_number indicates that the |
8c27b7d4 | 299 | pass is already in the list. */ |
b3fade83 | 300 | if (pass->static_pass_number) |
6de9cd9a | 301 | { |
b3fade83 BB |
302 | struct tree_opt_pass *new; |
303 | ||
304 | new = xmalloc (sizeof (*new)); | |
305 | memcpy (new, pass, sizeof (*new)); | |
306 | ||
307 | /* Indicate to register_dump_files that this pass has duplicates, | |
308 | and so it should rename the dump file. The first instance will | |
309 | be -1, and be number of duplicates = -static_pass_number - 1. | |
310 | Subsequent instances will be > 0 and just the duplicate number. */ | |
311 | if (pass->name) | |
312 | { | |
313 | pass->static_pass_number -= 1; | |
314 | new->static_pass_number = -pass->static_pass_number; | |
315 | } | |
316 | ||
317 | *list = new; | |
6de9cd9a | 318 | } |
b3fade83 BB |
319 | else |
320 | { | |
321 | pass->static_pass_number = -1; | |
322 | *list = pass; | |
323 | } | |
324 | ||
325 | return &(*list)->next; | |
326 | ||
6de9cd9a DN |
327 | } |
328 | ||
329 | /* Construct the pass tree. */ | |
330 | ||
331 | void | |
332 | init_tree_optimization_passes (void) | |
333 | { | |
334 | struct tree_opt_pass **p; | |
335 | ||
b3fade83 | 336 | #define NEXT_PASS(PASS) (p = next_pass_1 (p, &PASS)) |
b4861090 JH |
337 | /* Intraprocedural optimization passes. */ |
338 | p = &all_ipa_passes; | |
339 | NEXT_PASS (pass_ipa_inline); | |
340 | *p = NULL; | |
6de9cd9a DN |
341 | |
342 | p = &all_passes; | |
343 | NEXT_PASS (pass_gimple); | |
344 | NEXT_PASS (pass_remove_useless_stmts); | |
345 | NEXT_PASS (pass_mudflap_1); | |
346 | NEXT_PASS (pass_lower_cf); | |
347 | NEXT_PASS (pass_lower_eh); | |
242229bb | 348 | NEXT_PASS (pass_build_cfg); |
26277d41 | 349 | NEXT_PASS (pass_pre_expand); |
242229bb | 350 | NEXT_PASS (pass_tree_profile); |
33c94679 | 351 | NEXT_PASS (pass_init_datastructures); |
6de9cd9a | 352 | NEXT_PASS (pass_all_optimizations); |
55e99d52 | 353 | NEXT_PASS (pass_warn_function_return); |
6de9cd9a | 354 | NEXT_PASS (pass_mudflap_2); |
242229bb | 355 | NEXT_PASS (pass_free_datastructures); |
2f8e398b PB |
356 | NEXT_PASS (pass_expand); |
357 | NEXT_PASS (pass_rest_of_compilation); | |
6de9cd9a DN |
358 | *p = NULL; |
359 | ||
360 | p = &pass_all_optimizations.sub; | |
6de9cd9a | 361 | NEXT_PASS (pass_referenced_vars); |
c75ab022 | 362 | NEXT_PASS (pass_create_structure_vars); |
6de9cd9a | 363 | NEXT_PASS (pass_build_ssa); |
c1b763fa | 364 | NEXT_PASS (pass_may_alias); |
6de9cd9a DN |
365 | NEXT_PASS (pass_rename_ssa_copies); |
366 | NEXT_PASS (pass_early_warn_uninitialized); | |
367 | NEXT_PASS (pass_dce); | |
368 | NEXT_PASS (pass_dominator); | |
0bca51f0 | 369 | NEXT_PASS (pass_copy_prop); |
b3fade83 | 370 | NEXT_PASS (pass_dce); |
0d21c2a2 | 371 | NEXT_PASS (pass_forwprop); |
0bca51f0 | 372 | NEXT_PASS (pass_vrp); |
23ab2e4e | 373 | NEXT_PASS (pass_merge_phi); |
6de9cd9a DN |
374 | NEXT_PASS (pass_phiopt); |
375 | NEXT_PASS (pass_may_alias); | |
376 | NEXT_PASS (pass_tail_recursion); | |
377 | NEXT_PASS (pass_ch); | |
6de9cd9a | 378 | NEXT_PASS (pass_profile); |
9d30f3c1 | 379 | NEXT_PASS (pass_stdarg); |
6de9cd9a | 380 | NEXT_PASS (pass_sra); |
3bd09563 DN |
381 | /* FIXME: SRA may generate arbitrary gimple code, exposing new |
382 | aliased and call-clobbered variables. As mentioned below, | |
383 | pass_may_alias should be a TODO item. */ | |
384 | NEXT_PASS (pass_may_alias); | |
b3fade83 BB |
385 | NEXT_PASS (pass_rename_ssa_copies); |
386 | NEXT_PASS (pass_dominator); | |
0bca51f0 | 387 | NEXT_PASS (pass_copy_prop); |
b3fade83 | 388 | NEXT_PASS (pass_dce); |
6de9cd9a | 389 | NEXT_PASS (pass_dse); |
b3fade83 BB |
390 | NEXT_PASS (pass_may_alias); |
391 | NEXT_PASS (pass_forwprop); | |
392 | NEXT_PASS (pass_phiopt); | |
0bca51f0 DN |
393 | NEXT_PASS (pass_store_ccp); |
394 | NEXT_PASS (pass_store_copy_prop); | |
6de9cd9a | 395 | NEXT_PASS (pass_fold_builtins); |
209e170c AP |
396 | /* FIXME: May alias should a TODO but for 4.0.0, |
397 | we add may_alias right after fold builtins | |
398 | which can create arbitrary GIMPLE. */ | |
399 | NEXT_PASS (pass_may_alias); | |
6de9cd9a DN |
400 | NEXT_PASS (pass_split_crit_edges); |
401 | NEXT_PASS (pass_pre); | |
fa555252 | 402 | NEXT_PASS (pass_sink_code); |
c66b6c66 | 403 | NEXT_PASS (pass_loop); |
b3fade83 | 404 | NEXT_PASS (pass_dominator); |
0bca51f0 | 405 | NEXT_PASS (pass_copy_prop); |
75983038 DN |
406 | /* FIXME: If DCE is not run before checking for uninitialized uses, |
407 | we may get false warnings (e.g., testsuite/gcc.dg/uninit-5.c). | |
408 | However, this also causes us to misdiagnose cases that should be | |
409 | real warnings (e.g., testsuite/gcc.dg/pr18501.c). | |
410 | ||
411 | To fix the false positives in uninit-5.c, we would have to | |
412 | account for the predicates protecting the set and the use of each | |
413 | variable. Using a representation like Gated Single Assignment | |
414 | may help. */ | |
415 | NEXT_PASS (pass_late_warn_uninitialized); | |
6de9cd9a | 416 | NEXT_PASS (pass_cd_dce); |
b3fade83 BB |
417 | NEXT_PASS (pass_dse); |
418 | NEXT_PASS (pass_forwprop); | |
419 | NEXT_PASS (pass_phiopt); | |
6de9cd9a | 420 | NEXT_PASS (pass_tail_calls); |
85840349 | 421 | NEXT_PASS (pass_rename_ssa_copies); |
fef0657c | 422 | NEXT_PASS (pass_uncprop); |
6de9cd9a DN |
423 | NEXT_PASS (pass_del_ssa); |
424 | NEXT_PASS (pass_nrv); | |
425 | NEXT_PASS (pass_remove_useless_vars); | |
1eb3331e | 426 | NEXT_PASS (pass_mark_used_blocks); |
165b54c3 | 427 | NEXT_PASS (pass_cleanup_cfg_post_optimizing); |
6de9cd9a DN |
428 | *p = NULL; |
429 | ||
c66b6c66 ZD |
430 | p = &pass_loop.sub; |
431 | NEXT_PASS (pass_loop_init); | |
0bca51f0 | 432 | NEXT_PASS (pass_copy_prop); |
a7e5372d | 433 | NEXT_PASS (pass_lim); |
92fc4a2f | 434 | NEXT_PASS (pass_unswitch); |
f3cd574f | 435 | NEXT_PASS (pass_record_bounds); |
464f49d8 DB |
436 | NEXT_PASS (pass_linear_transform); |
437 | NEXT_PASS (pass_iv_canon); | |
40923b20 | 438 | NEXT_PASS (pass_if_conversion); |
79fe1b3b | 439 | NEXT_PASS (pass_vectorize); |
82b85a85 | 440 | NEXT_PASS (pass_complete_unroll); |
8b11a64c | 441 | NEXT_PASS (pass_iv_optimize); |
c66b6c66 ZD |
442 | NEXT_PASS (pass_loop_done); |
443 | *p = NULL; | |
444 | ||
6de9cd9a | 445 | #undef NEXT_PASS |
6de9cd9a | 446 | |
b4861090 JH |
447 | register_dump_files (all_passes, false, PROP_gimple_any |
448 | | PROP_gimple_lcf | |
449 | | PROP_gimple_leh | |
450 | | PROP_cfg); | |
451 | register_dump_files (all_ipa_passes, true, PROP_gimple_any | |
452 | | PROP_gimple_lcf | |
453 | | PROP_gimple_leh | |
454 | | PROP_cfg); | |
6de9cd9a DN |
455 | } |
456 | ||
6de9cd9a DN |
457 | static unsigned int last_verified; |
458 | ||
459 | static void | |
f430bae8 | 460 | execute_todo (struct tree_opt_pass *pass, unsigned int flags, bool use_required) |
6de9cd9a | 461 | { |
f430bae8 AM |
462 | int properties |
463 | = use_required ? pass->properties_required : pass->properties_provided; | |
464 | ||
0bca51f0 DN |
465 | #if defined ENABLE_CHECKING |
466 | if (need_ssa_update_p ()) | |
467 | gcc_assert (flags & TODO_update_ssa_any); | |
468 | #endif | |
469 | ||
470 | if (flags & TODO_update_ssa_any) | |
52328bf6 | 471 | { |
0bca51f0 DN |
472 | unsigned update_flags = flags & TODO_update_ssa_any; |
473 | update_ssa (update_flags); | |
52328bf6 | 474 | } |
6de9cd9a | 475 | |
88a40e67 | 476 | if (flags & TODO_cleanup_cfg) |
2b271002 ZD |
477 | { |
478 | if (current_loops) | |
479 | cleanup_tree_cfg_loop (); | |
480 | else | |
481 | cleanup_tree_cfg (); | |
482 | } | |
88a40e67 | 483 | |
b4861090 JH |
484 | if ((flags & TODO_dump_func) |
485 | && dump_file && current_function_decl) | |
2aaf3dd5 | 486 | { |
9f8628ba PB |
487 | if (properties & PROP_trees) |
488 | dump_function_to_file (current_function_decl, | |
489 | dump_file, dump_flags); | |
490 | else if (properties & PROP_cfg) | |
491 | print_rtl_with_bb (dump_file, get_insns ()); | |
492 | else | |
493 | print_rtl (dump_file, get_insns ()); | |
2aaf3dd5 DN |
494 | |
495 | /* Flush the file. If verification fails, we won't be able to | |
496 | close the file before aborting. */ | |
497 | fflush (dump_file); | |
498 | } | |
b4861090 JH |
499 | if ((flags & TODO_dump_cgraph) |
500 | && dump_file && !current_function_decl) | |
501 | { | |
502 | dump_cgraph (dump_file); | |
503 | /* Flush the file. If verification fails, we won't be able to | |
504 | close the file before aborting. */ | |
505 | fflush (dump_file); | |
506 | } | |
6de9cd9a DN |
507 | |
508 | if (flags & TODO_ggc_collect) | |
f430bae8 AM |
509 | { |
510 | ggc_collect (); | |
511 | } | |
6de9cd9a | 512 | |
0bca51f0 | 513 | #if defined ENABLE_CHECKING |
f430bae8 AM |
514 | if ((pass->properties_required & PROP_ssa) |
515 | && !(pass->properties_destroyed & PROP_ssa)) | |
0bca51f0 | 516 | verify_ssa (true); |
6de9cd9a DN |
517 | if (flags & TODO_verify_flow) |
518 | verify_flow_info (); | |
519 | if (flags & TODO_verify_stmts) | |
520 | verify_stmts (); | |
0bca51f0 DN |
521 | if (flags & TODO_verify_loops) |
522 | verify_loop_closed_ssa (); | |
6de9cd9a DN |
523 | #endif |
524 | } | |
525 | ||
526 | static bool | |
527 | execute_one_pass (struct tree_opt_pass *pass) | |
528 | { | |
529 | unsigned int todo; | |
530 | ||
531 | /* See if we're supposed to run this pass. */ | |
532 | if (pass->gate && !pass->gate ()) | |
533 | return false; | |
534 | ||
2f8e398b PB |
535 | /* Note that the folders should only create gimple expressions. |
536 | This is a hack until the new folder is ready. */ | |
537 | in_gimple_form = (pass->properties_provided & PROP_trees) != 0; | |
6de9cd9a DN |
538 | |
539 | /* Run pre-pass verification. */ | |
540 | todo = pass->todo_flags_start & ~last_verified; | |
541 | if (todo) | |
f430bae8 | 542 | execute_todo (pass, todo, true); |
6de9cd9a DN |
543 | |
544 | /* If a dump file name is present, open it if enabled. */ | |
b3fade83 | 545 | if (pass->static_pass_number != -1) |
6de9cd9a | 546 | { |
9f8628ba PB |
547 | bool initializing_dump = !dump_initialized_p (pass->static_pass_number); |
548 | dump_file_name = get_dump_file_name (pass->static_pass_number); | |
6de9cd9a | 549 | dump_file = dump_begin (pass->static_pass_number, &dump_flags); |
b4861090 | 550 | if (dump_file && current_function_decl) |
6de9cd9a DN |
551 | { |
552 | const char *dname, *aname; | |
673fda6b | 553 | dname = lang_hooks.decl_printable_name (current_function_decl, 2); |
6de9cd9a DN |
554 | aname = (IDENTIFIER_POINTER |
555 | (DECL_ASSEMBLER_NAME (current_function_decl))); | |
b4861090 JH |
556 | fprintf (dump_file, "\n;; Function %s (%s)%s\n\n", dname, aname, |
557 | cfun->function_frequency == FUNCTION_FREQUENCY_HOT | |
558 | ? " (hot)" | |
559 | : cfun->function_frequency == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED | |
560 | ? " (unlikely executed)" | |
561 | : ""); | |
6de9cd9a | 562 | } |
9f8628ba PB |
563 | |
564 | if (initializing_dump | |
565 | && graph_dump_format != no_graph | |
566 | && (pass->properties_provided & (PROP_cfg | PROP_rtl)) | |
567 | == (PROP_cfg | PROP_rtl)) | |
568 | clean_graph_dump_file (dump_file_name); | |
6de9cd9a DN |
569 | } |
570 | ||
571 | /* If a timevar is present, start it. */ | |
572 | if (pass->tv_id) | |
573 | timevar_push (pass->tv_id); | |
574 | ||
6de9cd9a DN |
575 | /* Do it! */ |
576 | if (pass->execute) | |
577 | pass->execute (); | |
4985cde3 | 578 | |
e26ce7ed DN |
579 | /* Stop timevar. */ |
580 | if (pass->tv_id) | |
581 | timevar_pop (pass->tv_id); | |
582 | ||
9f8628ba PB |
583 | if (dump_file |
584 | && (pass->properties_provided & (PROP_cfg | PROP_rtl)) | |
585 | == (PROP_cfg | PROP_rtl)) | |
b7211528 | 586 | print_rtl_with_bb (dump_file, get_insns ()); |
9f8628ba | 587 | |
6de9cd9a DN |
588 | /* Run post-pass cleanup and verification. */ |
589 | todo = pass->todo_flags_finish; | |
590 | last_verified = todo & TODO_verify_all; | |
591 | if (todo) | |
f430bae8 | 592 | execute_todo (pass, todo, false); |
6de9cd9a | 593 | |
e26ce7ed | 594 | /* Flush and close dump file. */ |
9f8628ba PB |
595 | if (dump_file_name) |
596 | { | |
597 | free ((char *) dump_file_name); | |
598 | dump_file_name = NULL; | |
599 | } | |
6de9cd9a DN |
600 | if (dump_file) |
601 | { | |
602 | dump_end (pass->static_pass_number, dump_file); | |
603 | dump_file = NULL; | |
604 | } | |
605 | ||
606 | return true; | |
607 | } | |
608 | ||
609 | static void | |
610 | execute_pass_list (struct tree_opt_pass *pass) | |
611 | { | |
612 | do | |
613 | { | |
614 | if (execute_one_pass (pass) && pass->sub) | |
615 | execute_pass_list (pass->sub); | |
616 | pass = pass->next; | |
617 | } | |
618 | while (pass); | |
619 | } | |
b4861090 JH |
620 | |
621 | /* Execute all IPA passes. */ | |
622 | void | |
623 | ipa_passes (void) | |
624 | { | |
625 | execute_pass_list (all_ipa_passes); | |
626 | } | |
2c459e74 JH |
627 | \f |
628 | ||
454ff5cb | 629 | /* Update recursively all inlined_to pointers of functions |
2c459e74 JH |
630 | inlined into NODE to INLINED_TO. */ |
631 | static void | |
632 | update_inlined_to_pointers (struct cgraph_node *node, | |
633 | struct cgraph_node *inlined_to) | |
634 | { | |
635 | struct cgraph_edge *e; | |
636 | for (e = node->callees; e; e = e->next_callee) | |
637 | { | |
638 | if (e->callee->global.inlined_to) | |
639 | { | |
640 | e->callee->global.inlined_to = inlined_to; | |
d21bede3 | 641 | update_inlined_to_pointers (e->callee, inlined_to); |
2c459e74 JH |
642 | } |
643 | } | |
644 | } | |
6de9cd9a DN |
645 | |
646 | \f | |
4985cde3 RH |
647 | /* For functions-as-trees languages, this performs all optimization and |
648 | compilation for FNDECL. */ | |
649 | ||
650 | void | |
0f0377f6 | 651 | tree_rest_of_compilation (tree fndecl) |
4985cde3 | 652 | { |
5d4854c8 | 653 | location_t saved_loc; |
6de9cd9a | 654 | struct cgraph_node *saved_node = NULL, *node; |
5d4854c8 | 655 | |
4985cde3 RH |
656 | timevar_push (TV_EXPAND); |
657 | ||
1e128c5f | 658 | gcc_assert (!flag_unit_at_a_time || cgraph_global_info_ready); |
4985cde3 | 659 | |
4985cde3 RH |
660 | /* Initialize the RTL code for the function. */ |
661 | current_function_decl = fndecl; | |
5d4854c8 | 662 | saved_loc = input_location; |
f31686a3 | 663 | input_location = DECL_SOURCE_LOCATION (fndecl); |
4985cde3 RH |
664 | init_function_start (fndecl); |
665 | ||
4985cde3 RH |
666 | /* Even though we're inside a function body, we still don't want to |
667 | call expand_expr to calculate the size of a variable-sized array. | |
668 | We haven't necessarily assigned RTL to all variables yet, so it's | |
669 | not safe to try to expand expressions involving them. */ | |
4985cde3 RH |
670 | cfun->x_dont_save_pending_sizes_p = 1; |
671 | ||
18c6ada9 JH |
672 | node = cgraph_node (fndecl); |
673 | ||
674 | /* We might need the body of this function so that we can expand | |
675 | it inline somewhere else. This means not lowering some constructs | |
676 | such as exception handling. */ | |
677 | if (cgraph_preserve_function_body_p (fndecl)) | |
678 | { | |
679 | if (!flag_unit_at_a_time) | |
680 | { | |
681 | struct cgraph_edge *e; | |
682 | ||
683 | saved_node = cgraph_clone_node (node); | |
684 | for (e = saved_node->callees; e; e = e->next_callee) | |
685 | if (!e->inline_failed) | |
686 | cgraph_clone_inlined_nodes (e, true); | |
687 | } | |
1a837f77 RK |
688 | cfun->saved_static_chain_decl = cfun->static_chain_decl; |
689 | cfun->saved_tree = save_body (fndecl, &cfun->saved_args, | |
690 | &cfun->saved_static_chain_decl); | |
18c6ada9 JH |
691 | } |
692 | ||
693 | if (flag_inline_trees) | |
694 | { | |
695 | struct cgraph_edge *e; | |
696 | for (e = node->callees; e; e = e->next_callee) | |
697 | if (!e->inline_failed || warn_inline) | |
698 | break; | |
699 | if (e) | |
700 | { | |
701 | timevar_push (TV_INTEGRATION); | |
702 | optimize_inline_calls (fndecl); | |
703 | timevar_pop (TV_INTEGRATION); | |
704 | } | |
705 | } | |
cd9c7bd2 JH |
706 | /* We are not going to maintain the cgraph edges up to date. |
707 | Kill it so it won't confuse us. */ | |
708 | while (node->callees) | |
709 | { | |
710 | /* In non-unit-at-a-time we must mark all referenced functions as needed. | |
711 | */ | |
712 | if (node->callees->callee->analyzed && !flag_unit_at_a_time) | |
713 | cgraph_mark_needed_node (node->callees->callee); | |
714 | cgraph_remove_edge (node->callees); | |
715 | } | |
18c6ada9 | 716 | |
89480522 JH |
717 | /* We are not going to maintain the cgraph edges up to date. |
718 | Kill it so it won't confuse us. */ | |
2563c224 | 719 | cgraph_node_remove_callees (node); |
89480522 | 720 | |
5f240ec4 | 721 | |
7932a3db NS |
722 | /* Initialize the default bitmap obstack. */ |
723 | bitmap_obstack_initialize (NULL); | |
724 | bitmap_obstack_initialize (®_obstack); /* FIXME, only at RTL generation*/ | |
725 | ||
2f8e398b PB |
726 | /* Perform all tree transforms and optimizations. */ |
727 | execute_pass_list (all_passes); | |
7932a3db NS |
728 | |
729 | bitmap_obstack_release (®_obstack); | |
4985cde3 | 730 | |
7932a3db NS |
731 | /* Release the default bitmap obstack. */ |
732 | bitmap_obstack_release (NULL); | |
733 | ||
6de9cd9a DN |
734 | /* Restore original body if still needed. */ |
735 | if (cfun->saved_tree) | |
736 | { | |
737 | DECL_SAVED_TREE (fndecl) = cfun->saved_tree; | |
738 | DECL_ARGUMENTS (fndecl) = cfun->saved_args; | |
1a837f77 | 739 | cfun->static_chain_decl = cfun->saved_static_chain_decl; |
18c6ada9 | 740 | |
6de9cd9a DN |
741 | /* When not in unit-at-a-time mode, we must preserve out of line copy |
742 | representing node before inlining. Restore original outgoing edges | |
743 | using clone we created earlier. */ | |
744 | if (!flag_unit_at_a_time) | |
745 | { | |
746 | struct cgraph_edge *e; | |
0eac5feb | 747 | |
2563c224 | 748 | cgraph_node_remove_callees (node); |
6de9cd9a DN |
749 | node->callees = saved_node->callees; |
750 | saved_node->callees = NULL; | |
d21bede3 | 751 | update_inlined_to_pointers (node, node); |
89480522 | 752 | for (e = node->callees; e; e = e->next_callee) |
d21bede3 | 753 | e->caller = node; |
6de9cd9a DN |
754 | cgraph_remove_node (saved_node); |
755 | } | |
756 | } | |
757 | else | |
758 | DECL_SAVED_TREE (fndecl) = NULL; | |
759 | cfun = 0; | |
4985cde3 RH |
760 | |
761 | /* If requested, warn about function definitions where the function will | |
762 | return a value (usually of some struct or union type) which itself will | |
763 | take up a lot of stack space. */ | |
764 | if (warn_larger_than && !DECL_EXTERNAL (fndecl) && TREE_TYPE (fndecl)) | |
765 | { | |
766 | tree ret_type = TREE_TYPE (TREE_TYPE (fndecl)); | |
767 | ||
768 | if (ret_type && TYPE_SIZE_UNIT (ret_type) | |
769 | && TREE_CODE (TYPE_SIZE_UNIT (ret_type)) == INTEGER_CST | |
770 | && 0 < compare_tree_int (TYPE_SIZE_UNIT (ret_type), | |
771 | larger_than_size)) | |
772 | { | |
4985cde3 RH |
773 | unsigned int size_as_int |
774 | = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (ret_type)); | |
775 | ||
776 | if (compare_tree_int (TYPE_SIZE_UNIT (ret_type), size_as_int) == 0) | |
7a6336aa | 777 | warning ("%Jsize of return value of %qD is %u bytes", |
ddd2d57e | 778 | fndecl, fndecl, size_as_int); |
4985cde3 | 779 | else |
7a6336aa | 780 | warning ("%Jsize of return value of %qD is larger than %wd bytes", |
ddd2d57e | 781 | fndecl, fndecl, larger_than_size); |
4985cde3 RH |
782 | } |
783 | } | |
784 | ||
0f0377f6 | 785 | if (!flag_inline_trees) |
4985cde3 | 786 | { |
d173e685 | 787 | DECL_SAVED_TREE (fndecl) = NULL; |
6de9cd9a DN |
788 | if (DECL_STRUCT_FUNCTION (fndecl) == 0 |
789 | && !cgraph_node (fndecl)->origin) | |
d173e685 JH |
790 | { |
791 | /* Stop pointing to the local nodes about to be freed. | |
792 | But DECL_INITIAL must remain nonzero so we know this | |
793 | was an actual function definition. | |
794 | For a nested function, this is done in c_pop_function_context. | |
795 | If rest_of_compilation set this to 0, leave it 0. */ | |
796 | if (DECL_INITIAL (fndecl) != 0) | |
797 | DECL_INITIAL (fndecl) = error_mark_node; | |
d173e685 | 798 | } |
4985cde3 RH |
799 | } |
800 | ||
5d4854c8 RH |
801 | input_location = saved_loc; |
802 | ||
6de9cd9a | 803 | ggc_collect (); |
4985cde3 RH |
804 | timevar_pop (TV_EXPAND); |
805 | } |