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