Mercurial > hg > CbC > CbC_gcc
comparison gcc/tree-optimize.c @ 55:77e2b8dfacca gcc-4.4.5
update it from 4.4.3 to 4.5.0
author | ryoma <e075725@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 12 Feb 2010 23:39:51 +0900 |
parents | a06113de4d67 |
children | b7f97abdc517 |
comparison
equal
deleted
inserted
replaced
52:c156f1bd5cd9 | 55:77e2b8dfacca |
---|---|
1 /* Top-level control of tree optimizations. | 1 /* Top-level control of tree optimizations. |
2 Copyright 2001, 2002, 2003, 2004, 2005, 2007, 2008 | 2 Copyright 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009 |
3 Free Software Foundation, Inc. | 3 Free Software Foundation, Inc. |
4 Contributed by Diego Novillo <dnovillo@redhat.com> | 4 Contributed by Diego Novillo <dnovillo@redhat.com> |
5 | 5 |
6 This file is part of GCC. | 6 This file is part of GCC. |
7 | 7 |
47 #include "ggc.h" | 47 #include "ggc.h" |
48 #include "cgraph.h" | 48 #include "cgraph.h" |
49 #include "graph.h" | 49 #include "graph.h" |
50 #include "cfgloop.h" | 50 #include "cfgloop.h" |
51 #include "except.h" | 51 #include "except.h" |
52 #include "plugin.h" | |
52 | 53 |
53 | 54 |
54 /* Gate: execute, or not, all of the non-trivial optimizations. */ | 55 /* Gate: execute, or not, all of the non-trivial optimizations. */ |
55 | 56 |
56 static bool | 57 static bool |
57 gate_all_optimizations (void) | 58 gate_all_optimizations (void) |
58 { | 59 { |
59 return (optimize >= 1 | 60 return (optimize >= 1 |
60 /* Don't bother doing anything if the program has errors. | 61 /* Don't bother doing anything if the program has errors. |
61 We have to pass down the queue if we already went into SSA */ | 62 We have to pass down the queue if we already went into SSA */ |
62 && (!(errorcount || sorrycount) || gimple_in_ssa_p (cfun))); | 63 && (!(errorcount || sorrycount) || gimple_in_ssa_p (cfun))); |
63 } | 64 } |
64 | 65 |
65 struct gimple_opt_pass pass_all_optimizations = | 66 struct gimple_opt_pass pass_all_optimizations = |
66 { | 67 { |
67 { | 68 { |
68 GIMPLE_PASS, | 69 GIMPLE_PASS, |
69 NULL, /* name */ | 70 "*all_optimizations", /* name */ |
70 gate_all_optimizations, /* gate */ | 71 gate_all_optimizations, /* gate */ |
71 NULL, /* execute */ | 72 NULL, /* execute */ |
72 NULL, /* sub */ | 73 NULL, /* sub */ |
73 NULL, /* next */ | 74 NULL, /* next */ |
74 0, /* static_pass_number */ | 75 0, /* static_pass_number */ |
75 0, /* tv_id */ | 76 TV_NONE, /* tv_id */ |
76 0, /* properties_required */ | 77 0, /* properties_required */ |
77 0, /* properties_provided */ | 78 0, /* properties_provided */ |
78 0, /* properties_destroyed */ | 79 0, /* properties_destroyed */ |
79 0, /* todo_flags_start */ | 80 0, /* todo_flags_start */ |
80 0 /* todo_flags_finish */ | 81 0 /* todo_flags_finish */ |
85 | 86 |
86 static bool | 87 static bool |
87 gate_all_early_local_passes (void) | 88 gate_all_early_local_passes (void) |
88 { | 89 { |
89 /* Don't bother doing anything if the program has errors. */ | 90 /* Don't bother doing anything if the program has errors. */ |
90 return (!errorcount && !sorrycount); | 91 return (!errorcount && !sorrycount && !in_lto_p); |
91 } | 92 } |
92 | 93 |
93 struct simple_ipa_opt_pass pass_early_local_passes = | 94 struct simple_ipa_opt_pass pass_early_local_passes = |
94 { | 95 { |
95 { | 96 { |
98 gate_all_early_local_passes, /* gate */ | 99 gate_all_early_local_passes, /* gate */ |
99 NULL, /* execute */ | 100 NULL, /* execute */ |
100 NULL, /* sub */ | 101 NULL, /* sub */ |
101 NULL, /* next */ | 102 NULL, /* next */ |
102 0, /* static_pass_number */ | 103 0, /* static_pass_number */ |
103 0, /* tv_id */ | 104 TV_NONE, /* tv_id */ |
104 0, /* properties_required */ | 105 0, /* properties_required */ |
105 0, /* properties_provided */ | 106 0, /* properties_provided */ |
106 0, /* properties_destroyed */ | 107 0, /* properties_destroyed */ |
107 0, /* todo_flags_start */ | 108 0, /* todo_flags_start */ |
108 TODO_remove_functions /* todo_flags_finish */ | 109 TODO_remove_functions /* todo_flags_finish */ |
139 gate_all_early_optimizations, /* gate */ | 140 gate_all_early_optimizations, /* gate */ |
140 execute_early_local_optimizations, /* execute */ | 141 execute_early_local_optimizations, /* execute */ |
141 NULL, /* sub */ | 142 NULL, /* sub */ |
142 NULL, /* next */ | 143 NULL, /* next */ |
143 0, /* static_pass_number */ | 144 0, /* static_pass_number */ |
144 0, /* tv_id */ | 145 TV_NONE, /* tv_id */ |
145 0, /* properties_required */ | 146 0, /* properties_required */ |
146 0, /* properties_provided */ | 147 0, /* properties_provided */ |
147 0, /* properties_destroyed */ | 148 0, /* properties_destroyed */ |
148 0, /* todo_flags_start */ | 149 0, /* todo_flags_start */ |
149 0 /* todo_flags_finish */ | 150 0 /* todo_flags_finish */ |
170 NULL, /* gate */ | 171 NULL, /* gate */ |
171 execute_cleanup_cfg_pre_ipa, /* execute */ | 172 execute_cleanup_cfg_pre_ipa, /* execute */ |
172 NULL, /* sub */ | 173 NULL, /* sub */ |
173 NULL, /* next */ | 174 NULL, /* next */ |
174 0, /* static_pass_number */ | 175 0, /* static_pass_number */ |
175 0, /* tv_id */ | 176 TV_NONE, /* tv_id */ |
176 PROP_cfg, /* properties_required */ | 177 PROP_cfg, /* properties_required */ |
177 0, /* properties_provided */ | 178 0, /* properties_provided */ |
178 0, /* properties_destroyed */ | 179 0, /* properties_destroyed */ |
179 0, /* todo_flags_start */ | 180 0, /* todo_flags_start */ |
180 TODO_dump_func /* todo_flags_finish */ | 181 TODO_dump_func /* todo_flags_finish */ |
199 | 200 |
200 struct gimple_opt_pass pass_cleanup_cfg_post_optimizing = | 201 struct gimple_opt_pass pass_cleanup_cfg_post_optimizing = |
201 { | 202 { |
202 { | 203 { |
203 GIMPLE_PASS, | 204 GIMPLE_PASS, |
204 "final_cleanup", /* name */ | 205 "optimized", /* name */ |
205 NULL, /* gate */ | 206 NULL, /* gate */ |
206 execute_cleanup_cfg_post_optimizing, /* execute */ | 207 execute_cleanup_cfg_post_optimizing, /* execute */ |
207 NULL, /* sub */ | 208 NULL, /* sub */ |
208 NULL, /* next */ | 209 NULL, /* next */ |
209 0, /* static_pass_number */ | 210 0, /* static_pass_number */ |
210 0, /* tv_id */ | 211 TV_NONE, /* tv_id */ |
211 PROP_cfg, /* properties_required */ | 212 PROP_cfg, /* properties_required */ |
212 0, /* properties_provided */ | 213 0, /* properties_provided */ |
213 0, /* properties_destroyed */ | 214 0, /* properties_destroyed */ |
214 0, /* todo_flags_start */ | 215 0, /* todo_flags_start */ |
215 TODO_dump_func /* todo_flags_finish */ | 216 TODO_dump_func /* todo_flags_finish */ |
217 | TODO_remove_unused_locals | |
216 } | 218 } |
217 }; | 219 }; |
218 | 220 |
219 /* Pass: do the actions required to finish with tree-ssa optimization | 221 /* Pass: do the actions required to finish with tree-ssa optimization |
220 passes. */ | 222 passes. */ |
221 | 223 |
222 static unsigned int | 224 unsigned int |
223 execute_free_datastructures (void) | 225 execute_free_datastructures (void) |
224 { | 226 { |
225 free_dominance_info (CDI_DOMINATORS); | 227 free_dominance_info (CDI_DOMINATORS); |
226 free_dominance_info (CDI_POST_DOMINATORS); | 228 free_dominance_info (CDI_POST_DOMINATORS); |
227 | 229 |
228 /* Remove the ssa structures. */ | |
229 if (cfun->gimple_df) | |
230 delete_tree_ssa (); | |
231 return 0; | |
232 } | |
233 | |
234 struct gimple_opt_pass pass_free_datastructures = | |
235 { | |
236 { | |
237 GIMPLE_PASS, | |
238 NULL, /* name */ | |
239 NULL, /* gate */ | |
240 execute_free_datastructures, /* execute */ | |
241 NULL, /* sub */ | |
242 NULL, /* next */ | |
243 0, /* static_pass_number */ | |
244 0, /* tv_id */ | |
245 PROP_cfg, /* properties_required */ | |
246 0, /* properties_provided */ | |
247 0, /* properties_destroyed */ | |
248 0, /* todo_flags_start */ | |
249 0 /* todo_flags_finish */ | |
250 } | |
251 }; | |
252 /* Pass: free cfg annotations. */ | |
253 | |
254 static unsigned int | |
255 execute_free_cfg_annotations (void) | |
256 { | |
257 /* And get rid of annotations we no longer need. */ | 230 /* And get rid of annotations we no longer need. */ |
258 delete_tree_cfg_annotations (); | 231 delete_tree_cfg_annotations (); |
259 | 232 |
260 return 0; | 233 return 0; |
261 } | 234 } |
262 | |
263 struct gimple_opt_pass pass_free_cfg_annotations = | |
264 { | |
265 { | |
266 GIMPLE_PASS, | |
267 NULL, /* name */ | |
268 NULL, /* gate */ | |
269 execute_free_cfg_annotations, /* execute */ | |
270 NULL, /* sub */ | |
271 NULL, /* next */ | |
272 0, /* static_pass_number */ | |
273 0, /* tv_id */ | |
274 PROP_cfg, /* properties_required */ | |
275 0, /* properties_provided */ | |
276 0, /* properties_destroyed */ | |
277 0, /* todo_flags_start */ | |
278 0 /* todo_flags_finish */ | |
279 } | |
280 }; | |
281 | 235 |
282 /* Pass: fixup_cfg. IPA passes, compilation of earlier functions or inlining | 236 /* Pass: fixup_cfg. IPA passes, compilation of earlier functions or inlining |
283 might have changed some properties, such as marked functions nothrow. | 237 might have changed some properties, such as marked functions nothrow. |
284 Remove redundant edges and basic blocks, and create new ones if necessary. | 238 Remove redundant edges and basic blocks, and create new ones if necessary. |
285 | 239 |
290 execute_fixup_cfg (void) | 244 execute_fixup_cfg (void) |
291 { | 245 { |
292 basic_block bb; | 246 basic_block bb; |
293 gimple_stmt_iterator gsi; | 247 gimple_stmt_iterator gsi; |
294 int todo = gimple_in_ssa_p (cfun) ? TODO_verify_ssa : 0; | 248 int todo = gimple_in_ssa_p (cfun) ? TODO_verify_ssa : 0; |
295 | 249 gcov_type count_scale; |
296 cfun->after_inlining = true; | 250 edge e; |
297 cfun->always_inline_functions_inlined = true; | 251 edge_iterator ei; |
298 | 252 |
299 if (cfun->eh) | 253 if (ENTRY_BLOCK_PTR->count) |
300 FOR_EACH_BB (bb) | 254 count_scale = (cgraph_node (current_function_decl)->count * REG_BR_PROB_BASE |
301 { | 255 + ENTRY_BLOCK_PTR->count / 2) / ENTRY_BLOCK_PTR->count; |
302 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) | 256 else |
303 { | 257 count_scale = REG_BR_PROB_BASE; |
304 gimple stmt = gsi_stmt (gsi); | 258 |
305 tree decl = is_gimple_call (stmt) | 259 ENTRY_BLOCK_PTR->count = cgraph_node (current_function_decl)->count; |
306 ? gimple_call_fndecl (stmt) | 260 EXIT_BLOCK_PTR->count = (EXIT_BLOCK_PTR->count * count_scale |
307 : NULL; | 261 + REG_BR_PROB_BASE / 2) / REG_BR_PROB_BASE; |
308 | 262 |
309 if (decl | 263 FOR_EACH_BB (bb) |
310 && gimple_call_flags (stmt) & (ECF_CONST | 264 { |
311 | ECF_PURE | 265 bb->count = (bb->count * count_scale |
312 | ECF_LOOPING_CONST_OR_PURE)) | 266 + REG_BR_PROB_BASE / 2) / REG_BR_PROB_BASE; |
313 { | 267 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) |
314 if (gimple_in_ssa_p (cfun)) | 268 { |
315 { | 269 gimple stmt = gsi_stmt (gsi); |
316 todo |= TODO_update_ssa | TODO_cleanup_cfg; | 270 tree decl = is_gimple_call (stmt) |
317 update_stmt (stmt); | 271 ? gimple_call_fndecl (stmt) |
318 } | 272 : NULL; |
319 } | 273 |
320 | 274 if (decl |
321 if (!stmt_could_throw_p (stmt) && lookup_stmt_eh_region (stmt)) | 275 && gimple_call_flags (stmt) & (ECF_CONST |
322 remove_stmt_from_eh_region (stmt); | 276 | ECF_PURE |
323 } | 277 | ECF_LOOPING_CONST_OR_PURE)) |
324 | 278 { |
325 if (gimple_purge_dead_eh_edges (bb)) | 279 if (gimple_in_ssa_p (cfun)) |
326 todo |= TODO_cleanup_cfg; | 280 { |
327 } | 281 todo |= TODO_update_ssa | TODO_cleanup_cfg; |
282 mark_symbols_for_renaming (stmt); | |
283 update_stmt (stmt); | |
284 } | |
285 } | |
286 | |
287 maybe_clean_eh_stmt (stmt); | |
288 } | |
289 | |
290 if (gimple_purge_dead_eh_edges (bb)) | |
291 todo |= TODO_cleanup_cfg; | |
292 FOR_EACH_EDGE (e, ei, bb->succs) | |
293 e->count = (e->count * count_scale | |
294 + REG_BR_PROB_BASE / 2) / REG_BR_PROB_BASE; | |
295 } | |
296 if (count_scale != REG_BR_PROB_BASE) | |
297 compute_function_frequency (); | |
328 | 298 |
329 /* Dump a textual representation of the flowgraph. */ | 299 /* Dump a textual representation of the flowgraph. */ |
330 if (dump_file) | 300 if (dump_file) |
331 gimple_dump_cfg (dump_file, dump_flags); | 301 gimple_dump_cfg (dump_file, dump_flags); |
332 | 302 |
333 return todo; | 303 return todo; |
334 } | 304 } |
335 | 305 |
306 struct gimple_opt_pass pass_fixup_cfg = | |
307 { | |
308 { | |
309 GIMPLE_PASS, | |
310 "*free_cfg_annotations", /* name */ | |
311 NULL, /* gate */ | |
312 execute_fixup_cfg, /* execute */ | |
313 NULL, /* sub */ | |
314 NULL, /* next */ | |
315 0, /* static_pass_number */ | |
316 TV_NONE, /* tv_id */ | |
317 PROP_cfg, /* properties_required */ | |
318 0, /* properties_provided */ | |
319 0, /* properties_destroyed */ | |
320 0, /* todo_flags_start */ | |
321 0 /* todo_flags_finish */ | |
322 } | |
323 }; | |
324 | |
336 /* Do the actions required to initialize internal data structures used | 325 /* Do the actions required to initialize internal data structures used |
337 in tree-ssa optimization passes. */ | 326 in tree-ssa optimization passes. */ |
338 | 327 |
339 static unsigned int | 328 static unsigned int |
340 execute_init_datastructures (void) | 329 execute_init_datastructures (void) |
346 | 335 |
347 struct gimple_opt_pass pass_init_datastructures = | 336 struct gimple_opt_pass pass_init_datastructures = |
348 { | 337 { |
349 { | 338 { |
350 GIMPLE_PASS, | 339 GIMPLE_PASS, |
351 NULL, /* name */ | 340 "*init_datastructures", /* name */ |
352 NULL, /* gate */ | 341 NULL, /* gate */ |
353 execute_init_datastructures, /* execute */ | 342 execute_init_datastructures, /* execute */ |
354 NULL, /* sub */ | 343 NULL, /* sub */ |
355 NULL, /* next */ | 344 NULL, /* next */ |
356 0, /* static_pass_number */ | 345 0, /* static_pass_number */ |
357 0, /* tv_id */ | 346 TV_NONE, /* tv_id */ |
358 PROP_cfg, /* properties_required */ | 347 PROP_cfg, /* properties_required */ |
359 0, /* properties_provided */ | 348 0, /* properties_provided */ |
360 0, /* properties_destroyed */ | 349 0, /* properties_destroyed */ |
361 0, /* todo_flags_start */ | 350 0, /* todo_flags_start */ |
362 0 /* todo_flags_finish */ | 351 0 /* todo_flags_finish */ |
388 | 377 |
389 void | 378 void |
390 tree_rest_of_compilation (tree fndecl) | 379 tree_rest_of_compilation (tree fndecl) |
391 { | 380 { |
392 location_t saved_loc; | 381 location_t saved_loc; |
393 struct cgraph_node *node; | |
394 | 382 |
395 timevar_push (TV_EXPAND); | 383 timevar_push (TV_EXPAND); |
396 | 384 |
397 gcc_assert (cgraph_global_info_ready); | 385 gcc_assert (cgraph_global_info_ready); |
398 | |
399 node = cgraph_node (fndecl); | |
400 | 386 |
401 /* Initialize the default bitmap obstack. */ | 387 /* Initialize the default bitmap obstack. */ |
402 bitmap_obstack_initialize (NULL); | 388 bitmap_obstack_initialize (NULL); |
403 | 389 |
404 /* Initialize the RTL code for the function. */ | 390 /* Initialize the RTL code for the function. */ |
410 /* Even though we're inside a function body, we still don't want to | 396 /* Even though we're inside a function body, we still don't want to |
411 call expand_expr to calculate the size of a variable-sized array. | 397 call expand_expr to calculate the size of a variable-sized array. |
412 We haven't necessarily assigned RTL to all variables yet, so it's | 398 We haven't necessarily assigned RTL to all variables yet, so it's |
413 not safe to try to expand expressions involving them. */ | 399 not safe to try to expand expressions involving them. */ |
414 cfun->dont_save_pending_sizes_p = 1; | 400 cfun->dont_save_pending_sizes_p = 1; |
415 | 401 |
416 gimple_register_cfg_hooks (); | 402 gimple_register_cfg_hooks (); |
417 | 403 |
418 bitmap_obstack_initialize (®_obstack); /* FIXME, only at RTL generation*/ | 404 bitmap_obstack_initialize (®_obstack); /* FIXME, only at RTL generation*/ |
405 | |
406 execute_all_ipa_transforms (); | |
407 | |
419 /* Perform all tree transforms and optimizations. */ | 408 /* Perform all tree transforms and optimizations. */ |
409 | |
410 /* Signal the start of passes. */ | |
411 invoke_plugin_callbacks (PLUGIN_ALL_PASSES_START, NULL); | |
412 | |
420 execute_pass_list (all_passes); | 413 execute_pass_list (all_passes); |
421 | 414 |
415 /* Signal the end of passes. */ | |
416 invoke_plugin_callbacks (PLUGIN_ALL_PASSES_END, NULL); | |
417 | |
422 bitmap_obstack_release (®_obstack); | 418 bitmap_obstack_release (®_obstack); |
423 | 419 |
424 /* Release the default bitmap obstack. */ | 420 /* Release the default bitmap obstack. */ |
425 bitmap_obstack_release (NULL); | 421 bitmap_obstack_release (NULL); |
426 | 422 |
427 set_cfun (NULL); | 423 set_cfun (NULL); |
428 | 424 |
429 /* If requested, warn about function definitions where the function will | 425 /* If requested, warn about function definitions where the function will |
430 return a value (usually of some struct or union type) which itself will | 426 return a value (usually of some struct or union type) which itself will |
431 take up a lot of stack space. */ | 427 take up a lot of stack space. */ |