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 3, 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 COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
22 #include "coretypes.h"
27 #include "hard-reg-set.h"
28 #include "basic-block.h"
30 #include "diagnostic.h"
31 #include "tree-flow.h"
32 #include "tree-dump.h"
33 #include "tree-pass.h"
37 #include "tree-inline.h"
38 #include "tree-scalar-evolution.h"
40 /* Initializes the loop structures. */
43 tree_loop_optimizer_init (void)
45 loop_optimizer_init (LOOPS_NORMAL
46 | LOOPS_HAVE_RECORDED_EXITS
);
47 rewrite_into_loop_closed_ssa (NULL
, TODO_update_ssa
);
50 /* The loop superpass. */
55 return flag_tree_loop_optimize
!= 0;
58 struct tree_opt_pass pass_tree_loop
=
61 gate_tree_loop
, /* gate */
65 0, /* static_pass_number */
66 TV_TREE_LOOP
, /* tv_id */
67 PROP_cfg
, /* properties_required */
68 0, /* properties_provided */
69 0, /* properties_destroyed */
70 TODO_ggc_collect
, /* todo_flags_start */
71 TODO_dump_func
| TODO_verify_ssa
| TODO_ggc_collect
, /* todo_flags_finish */
75 /* Loop optimizer initialization. */
78 tree_ssa_loop_init (void)
80 tree_loop_optimizer_init ();
81 if (number_of_loops () <= 1)
88 struct tree_opt_pass pass_tree_loop_init
=
90 "loopinit", /* name */
92 tree_ssa_loop_init
, /* execute */
95 0, /* static_pass_number */
96 TV_TREE_LOOP_INIT
, /* tv_id */
97 PROP_cfg
, /* properties_required */
98 0, /* properties_provided */
99 0, /* properties_destroyed */
100 0, /* todo_flags_start */
101 TODO_dump_func
| TODO_verify_loops
, /* todo_flags_finish */
105 /* Loop invariant motion pass. */
108 tree_ssa_loop_im (void)
110 if (number_of_loops () <= 1)
118 gate_tree_ssa_loop_im (void)
120 return flag_tree_loop_im
!= 0;
123 struct tree_opt_pass pass_lim
=
126 gate_tree_ssa_loop_im
, /* gate */
127 tree_ssa_loop_im
, /* execute */
130 0, /* static_pass_number */
132 PROP_cfg
, /* properties_required */
133 0, /* properties_provided */
134 0, /* properties_destroyed */
135 0, /* todo_flags_start */
136 TODO_dump_func
| TODO_verify_loops
, /* todo_flags_finish */
140 /* Loop unswitching pass. */
143 tree_ssa_loop_unswitch (void)
145 if (number_of_loops () <= 1)
148 return tree_ssa_unswitch_loops ();
152 gate_tree_ssa_loop_unswitch (void)
154 return flag_unswitch_loops
!= 0;
157 struct tree_opt_pass pass_tree_unswitch
=
159 "unswitch", /* name */
160 gate_tree_ssa_loop_unswitch
, /* gate */
161 tree_ssa_loop_unswitch
, /* execute */
164 0, /* static_pass_number */
165 TV_TREE_LOOP_UNSWITCH
, /* tv_id */
166 PROP_cfg
, /* properties_required */
167 0, /* properties_provided */
168 0, /* properties_destroyed */
169 0, /* todo_flags_start */
170 TODO_ggc_collect
| TODO_dump_func
171 | TODO_verify_loops
, /* todo_flags_finish */
175 /* Predictive commoning. */
178 run_tree_predictive_commoning (void)
183 tree_predictive_commoning ();
188 gate_tree_predictive_commoning (void)
190 return flag_predictive_commoning
!= 0;
193 struct tree_opt_pass pass_predcom
=
196 gate_tree_predictive_commoning
, /* gate */
197 run_tree_predictive_commoning
, /* execute */
200 0, /* static_pass_number */
201 TV_PREDCOM
, /* tv_id */
202 PROP_cfg
, /* properties_required */
203 0, /* properties_provided */
204 0, /* properties_destroyed */
205 0, /* todo_flags_start */
206 TODO_dump_func
| TODO_verify_loops
207 | TODO_update_ssa_only_virtuals
, /* todo_flags_finish */
211 /* Loop autovectorization. */
214 tree_vectorize (void)
216 return vectorize_loops ();
220 gate_tree_vectorize (void)
222 return flag_tree_vectorize
&& number_of_loops () > 1;
225 struct tree_opt_pass pass_vectorize
=
228 gate_tree_vectorize
, /* gate */
229 tree_vectorize
, /* execute */
232 0, /* static_pass_number */
233 TV_TREE_VECTORIZATION
, /* tv_id */
234 PROP_cfg
| PROP_ssa
, /* properties_required */
235 0, /* properties_provided */
236 0, /* properties_destroyed */
237 TODO_verify_loops
, /* todo_flags_start */
238 TODO_dump_func
| TODO_update_ssa
239 | TODO_ggc_collect
, /* todo_flags_finish */
243 /* Loop nest optimizations. */
246 tree_linear_transform (void)
248 if (number_of_loops () <= 1)
251 linear_transform_loops ();
256 gate_tree_linear_transform (void)
258 return flag_tree_loop_linear
!= 0;
261 struct tree_opt_pass pass_linear_transform
=
264 gate_tree_linear_transform
, /* gate */
265 tree_linear_transform
, /* execute */
268 0, /* static_pass_number */
269 TV_TREE_LINEAR_TRANSFORM
, /* tv_id */
270 PROP_cfg
| PROP_ssa
, /* properties_required */
271 0, /* properties_provided */
272 0, /* properties_destroyed */
273 0, /* todo_flags_start */
274 TODO_dump_func
| TODO_verify_loops
275 | TODO_ggc_collect
, /* todo_flags_finish */
279 /* Check the correctness of the data dependence analyzers. */
282 check_data_deps (void)
284 if (number_of_loops () <= 1)
287 tree_check_data_deps ();
292 gate_check_data_deps (void)
294 return flag_check_data_deps
!= 0;
297 struct tree_opt_pass pass_check_data_deps
=
300 gate_check_data_deps
, /* gate */
301 check_data_deps
, /* execute */
304 0, /* static_pass_number */
305 TV_CHECK_DATA_DEPS
, /* tv_id */
306 PROP_cfg
| PROP_ssa
, /* properties_required */
307 0, /* properties_provided */
308 0, /* properties_destroyed */
309 0, /* todo_flags_start */
310 TODO_dump_func
, /* todo_flags_finish */
314 /* Canonical induction variable creation pass. */
317 tree_ssa_loop_ivcanon (void)
319 if (number_of_loops () <= 1)
322 return canonicalize_induction_variables ();
326 gate_tree_ssa_loop_ivcanon (void)
328 return flag_tree_loop_ivcanon
!= 0;
331 struct tree_opt_pass pass_iv_canon
=
333 "ivcanon", /* name */
334 gate_tree_ssa_loop_ivcanon
, /* gate */
335 tree_ssa_loop_ivcanon
, /* execute */
338 0, /* static_pass_number */
339 TV_TREE_LOOP_IVCANON
, /* tv_id */
340 PROP_cfg
| PROP_ssa
, /* properties_required */
341 0, /* properties_provided */
342 0, /* properties_destroyed */
343 0, /* todo_flags_start */
344 TODO_dump_func
| TODO_verify_loops
, /* todo_flags_finish */
348 /* Propagation of constants using scev. */
351 gate_scev_const_prop (void)
353 return flag_tree_scev_cprop
;
356 struct tree_opt_pass pass_scev_cprop
=
359 gate_scev_const_prop
, /* gate */
360 scev_const_prop
, /* execute */
363 0, /* static_pass_number */
364 TV_SCEV_CONST
, /* tv_id */
365 PROP_cfg
| PROP_ssa
, /* properties_required */
366 0, /* properties_provided */
367 0, /* properties_destroyed */
368 0, /* todo_flags_start */
369 TODO_dump_func
| TODO_cleanup_cfg
370 | TODO_update_ssa_only_virtuals
,
371 /* todo_flags_finish */
375 /* Remove empty loops. */
378 tree_ssa_empty_loop (void)
380 if (number_of_loops () <= 1)
383 return remove_empty_loops ();
386 struct tree_opt_pass pass_empty_loop
=
390 tree_ssa_empty_loop
, /* execute */
393 0, /* static_pass_number */
394 TV_COMPLETE_UNROLL
, /* tv_id */
395 PROP_cfg
| PROP_ssa
, /* properties_required */
396 0, /* properties_provided */
397 0, /* properties_destroyed */
398 0, /* todo_flags_start */
399 TODO_dump_func
| TODO_verify_loops
400 | TODO_ggc_collect
, /* todo_flags_finish */
404 /* Record bounds on numbers of iterations of loops. */
407 tree_ssa_loop_bounds (void)
409 if (number_of_loops () <= 1)
412 estimate_numbers_of_iterations ();
417 struct tree_opt_pass pass_record_bounds
=
421 tree_ssa_loop_bounds
, /* execute */
424 0, /* static_pass_number */
425 TV_TREE_LOOP_BOUNDS
, /* tv_id */
426 PROP_cfg
| PROP_ssa
, /* properties_required */
427 0, /* properties_provided */
428 0, /* properties_destroyed */
429 0, /* todo_flags_start */
430 0, /* todo_flags_finish */
434 /* Complete unrolling of loops. */
437 tree_complete_unroll (void)
439 if (number_of_loops () <= 1)
442 return tree_unroll_loops_completely (flag_unroll_loops
448 gate_tree_complete_unroll (void)
453 struct tree_opt_pass pass_complete_unroll
=
455 "cunroll", /* name */
456 gate_tree_complete_unroll
, /* gate */
457 tree_complete_unroll
, /* execute */
460 0, /* static_pass_number */
461 TV_COMPLETE_UNROLL
, /* tv_id */
462 PROP_cfg
| PROP_ssa
, /* properties_required */
463 0, /* properties_provided */
464 0, /* properties_destroyed */
465 0, /* todo_flags_start */
466 TODO_dump_func
| TODO_verify_loops
467 | TODO_ggc_collect
, /* todo_flags_finish */
471 /* Parallelization. */
474 gate_tree_parallelize_loops (void)
476 return flag_tree_parallelize_loops
!= 1;
480 tree_parallelize_loops (void)
482 if (number_of_loops () <= 1)
485 if (parallelize_loops ())
486 return TODO_cleanup_cfg
| TODO_rebuild_alias
;
490 struct tree_opt_pass pass_parallelize_loops
=
492 "parloops", /* name */
493 gate_tree_parallelize_loops
, /* gate */
494 tree_parallelize_loops
, /* execute */
497 0, /* static_pass_number */
498 TV_TREE_PARALLELIZE_LOOPS
, /* tv_id */
499 PROP_cfg
| PROP_ssa
, /* properties_required */
500 0, /* properties_provided */
501 0, /* properties_destroyed */
502 0, /* todo_flags_start */
503 TODO_dump_func
| TODO_verify_loops
, /* todo_flags_finish */
510 tree_ssa_loop_prefetch (void)
512 if (number_of_loops () <= 1)
515 return tree_ssa_prefetch_arrays ();
519 gate_tree_ssa_loop_prefetch (void)
521 return flag_prefetch_loop_arrays
!= 0;
524 struct tree_opt_pass pass_loop_prefetch
=
526 "aprefetch", /* name */
527 gate_tree_ssa_loop_prefetch
, /* gate */
528 tree_ssa_loop_prefetch
, /* execute */
531 0, /* static_pass_number */
532 TV_TREE_PREFETCH
, /* 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
, /* todo_flags_finish */
541 /* Induction variable optimizations. */
544 tree_ssa_loop_ivopts (void)
546 if (number_of_loops () <= 1)
549 tree_ssa_iv_optimize ();
554 gate_tree_ssa_loop_ivopts (void)
556 return flag_ivopts
!= 0;
559 struct tree_opt_pass pass_iv_optimize
=
562 gate_tree_ssa_loop_ivopts
, /* gate */
563 tree_ssa_loop_ivopts
, /* execute */
566 0, /* static_pass_number */
567 TV_TREE_LOOP_IVOPTS
, /* tv_id */
568 PROP_cfg
| PROP_ssa
, /* properties_required */
569 0, /* properties_provided */
570 0, /* properties_destroyed */
571 0, /* todo_flags_start */
572 TODO_dump_func
| TODO_verify_loops
573 | TODO_update_ssa
| TODO_ggc_collect
, /* todo_flags_finish */
577 /* Loop optimizer finalization. */
580 tree_ssa_loop_done (void)
582 free_numbers_of_iterations_estimates ();
584 loop_optimizer_finalize ();
588 struct tree_opt_pass pass_tree_loop_done
=
590 "loopdone", /* name */
592 tree_ssa_loop_done
, /* execute */
595 0, /* static_pass_number */
596 TV_TREE_LOOP_FINI
, /* tv_id */
597 PROP_cfg
, /* properties_required */
598 0, /* properties_provided */
599 0, /* properties_destroyed */
600 0, /* todo_flags_start */
601 TODO_cleanup_cfg
| TODO_dump_func
, /* todo_flags_finish */