1 /* Loop optimizations over tree-ssa.
2 Copyright (C) 2003, 2005, 2006, 2007 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 GCC is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING. If not, write to the Free
18 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
23 #include "coretypes.h"
28 #include "hard-reg-set.h"
29 #include "basic-block.h"
31 #include "diagnostic.h"
32 #include "tree-flow.h"
33 #include "tree-dump.h"
34 #include "tree-pass.h"
38 #include "tree-inline.h"
39 #include "tree-scalar-evolution.h"
41 /* Initializes the loop structures. */
44 tree_loop_optimizer_init (void)
46 loop_optimizer_init (LOOPS_NORMAL
47 | LOOPS_HAVE_RECORDED_EXITS
);
48 rewrite_into_loop_closed_ssa (NULL
, TODO_update_ssa
);
51 /* The loop superpass. */
56 return flag_tree_loop_optimize
!= 0;
59 struct tree_opt_pass pass_tree_loop
=
62 gate_tree_loop
, /* gate */
66 0, /* static_pass_number */
67 TV_TREE_LOOP
, /* tv_id */
68 PROP_cfg
, /* properties_required */
69 0, /* properties_provided */
70 0, /* properties_destroyed */
71 TODO_ggc_collect
, /* todo_flags_start */
72 TODO_dump_func
| TODO_verify_ssa
| TODO_ggc_collect
, /* todo_flags_finish */
76 /* Loop optimizer initialization. */
79 tree_ssa_loop_init (void)
81 tree_loop_optimizer_init ();
82 if (number_of_loops () <= 1)
89 struct tree_opt_pass pass_tree_loop_init
=
91 "loopinit", /* name */
93 tree_ssa_loop_init
, /* execute */
96 0, /* static_pass_number */
97 TV_TREE_LOOP_INIT
, /* tv_id */
98 PROP_cfg
, /* properties_required */
99 0, /* properties_provided */
100 0, /* properties_destroyed */
101 0, /* todo_flags_start */
102 TODO_dump_func
| TODO_verify_loops
, /* todo_flags_finish */
106 /* Loop invariant motion pass. */
109 tree_ssa_loop_im (void)
111 if (number_of_loops () <= 1)
119 gate_tree_ssa_loop_im (void)
121 return flag_tree_loop_im
!= 0;
124 struct tree_opt_pass pass_lim
=
127 gate_tree_ssa_loop_im
, /* gate */
128 tree_ssa_loop_im
, /* execute */
131 0, /* static_pass_number */
133 PROP_cfg
, /* properties_required */
134 0, /* properties_provided */
135 0, /* properties_destroyed */
136 0, /* todo_flags_start */
137 TODO_dump_func
| TODO_verify_loops
, /* todo_flags_finish */
141 /* Loop unswitching pass. */
144 tree_ssa_loop_unswitch (void)
146 if (number_of_loops () <= 1)
149 return tree_ssa_unswitch_loops ();
153 gate_tree_ssa_loop_unswitch (void)
155 return flag_unswitch_loops
!= 0;
158 struct tree_opt_pass pass_tree_unswitch
=
160 "unswitch", /* name */
161 gate_tree_ssa_loop_unswitch
, /* gate */
162 tree_ssa_loop_unswitch
, /* execute */
165 0, /* static_pass_number */
166 TV_TREE_LOOP_UNSWITCH
, /* tv_id */
167 PROP_cfg
, /* properties_required */
168 0, /* properties_provided */
169 0, /* properties_destroyed */
170 0, /* todo_flags_start */
171 TODO_ggc_collect
| TODO_dump_func
172 | TODO_verify_loops
, /* todo_flags_finish */
176 /* Predictive commoning. */
179 run_tree_predictive_commoning (void)
184 tree_predictive_commoning ();
189 gate_tree_predictive_commoning (void)
191 return flag_predictive_commoning
!= 0;
194 struct tree_opt_pass pass_predcom
=
197 gate_tree_predictive_commoning
, /* gate */
198 run_tree_predictive_commoning
, /* execute */
201 0, /* static_pass_number */
202 TV_PREDCOM
, /* tv_id */
203 PROP_cfg
, /* properties_required */
204 0, /* properties_provided */
205 0, /* properties_destroyed */
206 0, /* todo_flags_start */
207 TODO_dump_func
| TODO_verify_loops
208 | TODO_update_ssa_only_virtuals
, /* todo_flags_finish */
212 /* Loop autovectorization. */
215 tree_vectorize (void)
217 return vectorize_loops ();
221 gate_tree_vectorize (void)
223 return flag_tree_vectorize
&& number_of_loops () > 1;
226 struct tree_opt_pass pass_vectorize
=
229 gate_tree_vectorize
, /* gate */
230 tree_vectorize
, /* execute */
233 0, /* static_pass_number */
234 TV_TREE_VECTORIZATION
, /* tv_id */
235 PROP_cfg
| PROP_ssa
, /* properties_required */
236 0, /* properties_provided */
237 0, /* properties_destroyed */
238 TODO_verify_loops
, /* todo_flags_start */
239 TODO_dump_func
| TODO_update_ssa
240 | TODO_ggc_collect
, /* todo_flags_finish */
244 /* Loop nest optimizations. */
247 tree_linear_transform (void)
249 if (number_of_loops () <= 1)
252 linear_transform_loops ();
257 gate_tree_linear_transform (void)
259 return flag_tree_loop_linear
!= 0;
262 struct tree_opt_pass pass_linear_transform
=
265 gate_tree_linear_transform
, /* gate */
266 tree_linear_transform
, /* execute */
269 0, /* static_pass_number */
270 TV_TREE_LINEAR_TRANSFORM
, /* tv_id */
271 PROP_cfg
| PROP_ssa
, /* properties_required */
272 0, /* properties_provided */
273 0, /* properties_destroyed */
274 0, /* todo_flags_start */
275 TODO_dump_func
| TODO_verify_loops
276 | TODO_ggc_collect
, /* todo_flags_finish */
280 /* Check the correctness of the data dependence analyzers. */
283 check_data_deps (void)
285 if (number_of_loops () <= 1)
288 tree_check_data_deps ();
293 gate_check_data_deps (void)
295 return flag_check_data_deps
!= 0;
298 struct tree_opt_pass pass_check_data_deps
=
301 gate_check_data_deps
, /* gate */
302 check_data_deps
, /* execute */
305 0, /* static_pass_number */
306 TV_CHECK_DATA_DEPS
, /* tv_id */
307 PROP_cfg
| PROP_ssa
, /* properties_required */
308 0, /* properties_provided */
309 0, /* properties_destroyed */
310 0, /* todo_flags_start */
311 TODO_dump_func
, /* todo_flags_finish */
315 /* Canonical induction variable creation pass. */
318 tree_ssa_loop_ivcanon (void)
320 if (number_of_loops () <= 1)
323 return canonicalize_induction_variables ();
327 gate_tree_ssa_loop_ivcanon (void)
329 return flag_tree_loop_ivcanon
!= 0;
332 struct tree_opt_pass pass_iv_canon
=
334 "ivcanon", /* name */
335 gate_tree_ssa_loop_ivcanon
, /* gate */
336 tree_ssa_loop_ivcanon
, /* execute */
339 0, /* static_pass_number */
340 TV_TREE_LOOP_IVCANON
, /* tv_id */
341 PROP_cfg
| PROP_ssa
, /* properties_required */
342 0, /* properties_provided */
343 0, /* properties_destroyed */
344 0, /* todo_flags_start */
345 TODO_dump_func
| TODO_verify_loops
, /* todo_flags_finish */
349 /* Propagation of constants using scev. */
352 gate_scev_const_prop (void)
354 return flag_tree_scev_cprop
;
357 struct tree_opt_pass pass_scev_cprop
=
360 gate_scev_const_prop
, /* gate */
361 scev_const_prop
, /* execute */
364 0, /* static_pass_number */
365 TV_SCEV_CONST
, /* tv_id */
366 PROP_cfg
| PROP_ssa
, /* properties_required */
367 0, /* properties_provided */
368 0, /* properties_destroyed */
369 0, /* todo_flags_start */
370 TODO_dump_func
| TODO_cleanup_cfg
371 | TODO_update_ssa_only_virtuals
,
372 /* todo_flags_finish */
376 /* Remove empty loops. */
379 tree_ssa_empty_loop (void)
381 if (number_of_loops () <= 1)
384 return remove_empty_loops ();
387 struct tree_opt_pass pass_empty_loop
=
391 tree_ssa_empty_loop
, /* execute */
394 0, /* static_pass_number */
395 TV_COMPLETE_UNROLL
, /* tv_id */
396 PROP_cfg
| PROP_ssa
, /* properties_required */
397 0, /* properties_provided */
398 0, /* properties_destroyed */
399 0, /* todo_flags_start */
400 TODO_dump_func
| TODO_verify_loops
401 | TODO_ggc_collect
, /* todo_flags_finish */
405 /* Record bounds on numbers of iterations of loops. */
408 tree_ssa_loop_bounds (void)
410 if (number_of_loops () <= 1)
413 estimate_numbers_of_iterations ();
418 struct tree_opt_pass pass_record_bounds
=
422 tree_ssa_loop_bounds
, /* execute */
425 0, /* static_pass_number */
426 TV_TREE_LOOP_BOUNDS
, /* tv_id */
427 PROP_cfg
| PROP_ssa
, /* properties_required */
428 0, /* properties_provided */
429 0, /* properties_destroyed */
430 0, /* todo_flags_start */
431 0, /* todo_flags_finish */
435 /* Complete unrolling of loops. */
438 tree_complete_unroll (void)
440 if (number_of_loops () <= 1)
443 return tree_unroll_loops_completely (flag_unroll_loops
449 gate_tree_complete_unroll (void)
454 struct tree_opt_pass pass_complete_unroll
=
456 "cunroll", /* name */
457 gate_tree_complete_unroll
, /* gate */
458 tree_complete_unroll
, /* execute */
461 0, /* static_pass_number */
462 TV_COMPLETE_UNROLL
, /* tv_id */
463 PROP_cfg
| PROP_ssa
, /* properties_required */
464 0, /* properties_provided */
465 0, /* properties_destroyed */
466 0, /* todo_flags_start */
467 TODO_dump_func
| TODO_verify_loops
468 | TODO_ggc_collect
, /* todo_flags_finish */
475 tree_ssa_loop_prefetch (void)
477 if (number_of_loops () <= 1)
480 return tree_ssa_prefetch_arrays ();
484 gate_tree_ssa_loop_prefetch (void)
486 return flag_prefetch_loop_arrays
!= 0;
489 struct tree_opt_pass pass_loop_prefetch
=
491 "aprefetch", /* name */
492 gate_tree_ssa_loop_prefetch
, /* gate */
493 tree_ssa_loop_prefetch
, /* execute */
496 0, /* static_pass_number */
497 TV_TREE_PREFETCH
, /* tv_id */
498 PROP_cfg
| PROP_ssa
, /* properties_required */
499 0, /* properties_provided */
500 0, /* properties_destroyed */
501 0, /* todo_flags_start */
502 TODO_dump_func
| TODO_verify_loops
, /* todo_flags_finish */
506 /* Induction variable optimizations. */
509 tree_ssa_loop_ivopts (void)
511 if (number_of_loops () <= 1)
514 tree_ssa_iv_optimize ();
519 gate_tree_ssa_loop_ivopts (void)
521 return flag_ivopts
!= 0;
524 struct tree_opt_pass pass_iv_optimize
=
527 gate_tree_ssa_loop_ivopts
, /* gate */
528 tree_ssa_loop_ivopts
, /* execute */
531 0, /* static_pass_number */
532 TV_TREE_LOOP_IVOPTS
, /* tv_id */
533 PROP_cfg
| PROP_ssa
, /* properties_required */
534 0, /* properties_provided */
535 0, /* properties_destroyed */
536 0, /* todo_flags_start */
537 TODO_dump_func
| TODO_verify_loops
538 | TODO_update_ssa
| TODO_ggc_collect
, /* todo_flags_finish */
542 /* Loop optimizer finalization. */
545 tree_ssa_loop_done (void)
547 free_numbers_of_iterations_estimates ();
549 loop_optimizer_finalize ();
553 struct tree_opt_pass pass_tree_loop_done
=
555 "loopdone", /* name */
557 tree_ssa_loop_done
, /* execute */
560 0, /* static_pass_number */
561 TV_TREE_LOOP_FINI
, /* tv_id */
562 PROP_cfg
, /* properties_required */
563 0, /* properties_provided */
564 0, /* properties_destroyed */
565 0, /* todo_flags_start */
566 TODO_cleanup_cfg
| TODO_dump_func
, /* todo_flags_finish */