1 /* Loop optimizations over tree-ssa.
2 Copyright (C) 2003, 2005, 2006, 2007, 2008 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 #include "tree-vectorizer.h"
42 /* The loop superpass. */
47 return flag_tree_loop_optimize != 0;
50 struct gimple_opt_pass pass_tree_loop =
55 gate_tree_loop, /* gate */
59 0, /* static_pass_number */
60 TV_TREE_LOOP, /* tv_id */
61 PROP_cfg, /* properties_required */
62 0, /* properties_provided */
63 0, /* properties_destroyed */
64 TODO_ggc_collect, /* todo_flags_start */
65 TODO_dump_func | TODO_verify_ssa | TODO_ggc_collect /* todo_flags_finish */
69 /* Loop optimizer initialization. */
72 tree_ssa_loop_init (void)
74 loop_optimizer_init (LOOPS_NORMAL
75 | LOOPS_HAVE_RECORDED_EXITS);
76 rewrite_into_loop_closed_ssa (NULL, TODO_update_ssa);
78 if (number_of_loops () <= 1)
85 struct gimple_opt_pass pass_tree_loop_init =
89 "loopinit", /* name */
91 tree_ssa_loop_init, /* execute */
94 0, /* static_pass_number */
95 TV_TREE_LOOP_INIT, /* tv_id */
96 PROP_cfg, /* properties_required */
97 0, /* properties_provided */
98 0, /* properties_destroyed */
99 0, /* todo_flags_start */
100 TODO_dump_func /* todo_flags_finish */
104 /* Loop invariant motion pass. */
107 tree_ssa_loop_im (void)
109 if (number_of_loops () <= 1)
117 gate_tree_ssa_loop_im (void)
119 return flag_tree_loop_im != 0;
122 struct gimple_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_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 gimple_opt_pass pass_tree_unswitch =
162 "unswitch", /* name */
163 gate_tree_ssa_loop_unswitch, /* gate */
164 tree_ssa_loop_unswitch, /* execute */
167 0, /* static_pass_number */
168 TV_TREE_LOOP_UNSWITCH, /* tv_id */
169 PROP_cfg, /* properties_required */
170 0, /* properties_provided */
171 0, /* properties_destroyed */
172 0, /* todo_flags_start */
173 TODO_ggc_collect | TODO_dump_func /* todo_flags_finish */
177 /* Predictive commoning. */
180 run_tree_predictive_commoning (void)
185 tree_predictive_commoning ();
190 gate_tree_predictive_commoning (void)
192 return flag_predictive_commoning != 0;
195 struct gimple_opt_pass pass_predcom =
200 gate_tree_predictive_commoning, /* gate */
201 run_tree_predictive_commoning, /* execute */
204 0, /* static_pass_number */
205 TV_PREDCOM, /* tv_id */
206 PROP_cfg, /* properties_required */
207 0, /* properties_provided */
208 0, /* properties_destroyed */
209 0, /* todo_flags_start */
211 | TODO_update_ssa_only_virtuals /* todo_flags_finish */
215 /* Loop autovectorization. */
218 tree_vectorize (void)
220 if (number_of_loops () <= 1)
223 return vectorize_loops ();
227 gate_tree_vectorize (void)
229 return flag_tree_vectorize;
232 struct gimple_opt_pass pass_vectorize =
237 gate_tree_vectorize, /* gate */
238 tree_vectorize, /* execute */
241 0, /* static_pass_number */
242 TV_TREE_VECTORIZATION, /* tv_id */
243 PROP_cfg | PROP_ssa, /* properties_required */
244 0, /* properties_provided */
245 0, /* properties_destroyed */
246 0, /* todo_flags_start */
247 TODO_dump_func | TODO_update_ssa
248 | TODO_ggc_collect /* todo_flags_finish */
252 /* Loop nest optimizations. */
255 tree_linear_transform (void)
257 if (number_of_loops () <= 1)
260 linear_transform_loops ();
265 gate_tree_linear_transform (void)
267 return flag_tree_loop_linear != 0;
270 struct gimple_opt_pass pass_linear_transform =
275 gate_tree_linear_transform, /* gate */
276 tree_linear_transform, /* execute */
279 0, /* static_pass_number */
280 TV_TREE_LINEAR_TRANSFORM, /* tv_id */
281 PROP_cfg | PROP_ssa, /* properties_required */
282 0, /* properties_provided */
283 0, /* properties_destroyed */
284 0, /* todo_flags_start */
286 | TODO_update_ssa_only_virtuals
287 | TODO_ggc_collect /* todo_flags_finish */
291 /* GRAPHITE optimizations. */
294 graphite_transforms (void)
299 graphite_transform_loops ();
305 gate_graphite_transforms (void)
307 /* Enable -fgraphite pass if any one of the graphite optimization flags
309 if (flag_loop_block || flag_loop_interchange || flag_loop_strip_mine
310 || flag_graphite_identity || flag_loop_parallelize_all)
313 return flag_graphite != 0;
316 struct gimple_opt_pass pass_graphite_transforms =
320 "graphite", /* name */
321 gate_graphite_transforms, /* gate */
322 graphite_transforms, /* execute */
325 0, /* static_pass_number */
326 TV_GRAPHITE_TRANSFORMS, /* tv_id */
327 PROP_cfg | PROP_ssa, /* properties_required */
328 0, /* properties_provided */
329 0, /* properties_destroyed */
330 0, /* todo_flags_start */
331 0 /* todo_flags_finish */
335 /* Check the correctness of the data dependence analyzers. */
338 check_data_deps (void)
340 if (number_of_loops () <= 1)
343 tree_check_data_deps ();
348 gate_check_data_deps (void)
350 return flag_check_data_deps != 0;
353 struct gimple_opt_pass pass_check_data_deps =
358 gate_check_data_deps, /* gate */
359 check_data_deps, /* execute */
362 0, /* static_pass_number */
363 TV_CHECK_DATA_DEPS, /* tv_id */
364 PROP_cfg | PROP_ssa, /* properties_required */
365 0, /* properties_provided */
366 0, /* properties_destroyed */
367 0, /* todo_flags_start */
368 TODO_dump_func /* todo_flags_finish */
372 /* Canonical induction variable creation pass. */
375 tree_ssa_loop_ivcanon (void)
377 if (number_of_loops () <= 1)
380 return canonicalize_induction_variables ();
384 gate_tree_ssa_loop_ivcanon (void)
386 return flag_tree_loop_ivcanon != 0;
389 struct gimple_opt_pass pass_iv_canon =
393 "ivcanon", /* name */
394 gate_tree_ssa_loop_ivcanon, /* gate */
395 tree_ssa_loop_ivcanon, /* execute */
398 0, /* static_pass_number */
399 TV_TREE_LOOP_IVCANON, /* tv_id */
400 PROP_cfg | PROP_ssa, /* properties_required */
401 0, /* properties_provided */
402 0, /* properties_destroyed */
403 0, /* todo_flags_start */
404 TODO_dump_func /* todo_flags_finish */
408 /* Propagation of constants using scev. */
411 gate_scev_const_prop (void)
413 return flag_tree_scev_cprop;
416 struct gimple_opt_pass pass_scev_cprop =
421 gate_scev_const_prop, /* gate */
422 scev_const_prop, /* execute */
425 0, /* static_pass_number */
426 TV_SCEV_CONST, /* tv_id */
427 PROP_cfg | PROP_ssa, /* properties_required */
428 0, /* properties_provided */
429 0, /* properties_destroyed */
430 0, /* todo_flags_start */
431 TODO_dump_func | TODO_cleanup_cfg
432 | TODO_update_ssa_only_virtuals
433 /* todo_flags_finish */
437 /* Record bounds on numbers of iterations of loops. */
440 tree_ssa_loop_bounds (void)
442 if (number_of_loops () <= 1)
445 estimate_numbers_of_iterations ();
450 struct gimple_opt_pass pass_record_bounds =
454 "*record_bounds", /* name */
456 tree_ssa_loop_bounds, /* execute */
459 0, /* static_pass_number */
460 TV_TREE_LOOP_BOUNDS, /* tv_id */
461 PROP_cfg | PROP_ssa, /* properties_required */
462 0, /* properties_provided */
463 0, /* properties_destroyed */
464 0, /* todo_flags_start */
465 0 /* todo_flags_finish */
469 /* Complete unrolling of loops. */
472 tree_complete_unroll (void)
474 if (number_of_loops () <= 1)
477 return tree_unroll_loops_completely (flag_unroll_loops
479 || optimize >= 3, true);
483 gate_tree_complete_unroll (void)
488 struct gimple_opt_pass pass_complete_unroll =
492 "cunroll", /* name */
493 gate_tree_complete_unroll, /* gate */
494 tree_complete_unroll, /* execute */
497 0, /* static_pass_number */
498 TV_COMPLETE_UNROLL, /* tv_id */
499 PROP_cfg | PROP_ssa, /* properties_required */
500 0, /* properties_provided */
501 0, /* properties_destroyed */
502 0, /* todo_flags_start */
504 | TODO_ggc_collect /* todo_flags_finish */
508 /* Complete unrolling of inner loops. */
511 tree_complete_unroll_inner (void)
515 loop_optimizer_init (LOOPS_NORMAL
516 | LOOPS_HAVE_RECORDED_EXITS);
517 if (number_of_loops () > 1)
520 ret = tree_unroll_loops_completely (optimize >= 3, false);
521 free_numbers_of_iterations_estimates ();
524 loop_optimizer_finalize ();
530 gate_tree_complete_unroll_inner (void)
532 return optimize >= 2;
535 struct gimple_opt_pass pass_complete_unrolli =
539 "cunrolli", /* name */
540 gate_tree_complete_unroll_inner, /* gate */
541 tree_complete_unroll_inner, /* execute */
544 0, /* static_pass_number */
545 TV_COMPLETE_UNROLL, /* tv_id */
546 PROP_cfg | PROP_ssa, /* properties_required */
547 0, /* properties_provided */
548 0, /* properties_destroyed */
549 0, /* todo_flags_start */
551 | TODO_ggc_collect /* todo_flags_finish */
555 /* Parallelization. */
558 gate_tree_parallelize_loops (void)
560 return flag_tree_parallelize_loops > 1;
564 tree_parallelize_loops (void)
566 if (number_of_loops () <= 1)
569 if (parallelize_loops ())
570 return TODO_cleanup_cfg | TODO_rebuild_alias;
574 struct gimple_opt_pass pass_parallelize_loops =
578 "parloops", /* name */
579 gate_tree_parallelize_loops, /* gate */
580 tree_parallelize_loops, /* execute */
583 0, /* static_pass_number */
584 TV_TREE_PARALLELIZE_LOOPS, /* tv_id */
585 PROP_cfg | PROP_ssa, /* properties_required */
586 0, /* properties_provided */
587 0, /* properties_destroyed */
588 0, /* todo_flags_start */
589 TODO_dump_func /* todo_flags_finish */
596 tree_ssa_loop_prefetch (void)
598 if (number_of_loops () <= 1)
601 return tree_ssa_prefetch_arrays ();
605 gate_tree_ssa_loop_prefetch (void)
607 return flag_prefetch_loop_arrays != 0;
610 struct gimple_opt_pass pass_loop_prefetch =
614 "aprefetch", /* name */
615 gate_tree_ssa_loop_prefetch, /* gate */
616 tree_ssa_loop_prefetch, /* execute */
619 0, /* static_pass_number */
620 TV_TREE_PREFETCH, /* tv_id */
621 PROP_cfg | PROP_ssa, /* properties_required */
622 0, /* properties_provided */
623 0, /* properties_destroyed */
624 0, /* todo_flags_start */
625 TODO_dump_func /* todo_flags_finish */
629 /* Induction variable optimizations. */
632 tree_ssa_loop_ivopts (void)
634 if (number_of_loops () <= 1)
637 tree_ssa_iv_optimize ();
642 gate_tree_ssa_loop_ivopts (void)
644 return flag_ivopts != 0;
647 struct gimple_opt_pass pass_iv_optimize =
652 gate_tree_ssa_loop_ivopts, /* gate */
653 tree_ssa_loop_ivopts, /* execute */
656 0, /* static_pass_number */
657 TV_TREE_LOOP_IVOPTS, /* tv_id */
658 PROP_cfg | PROP_ssa, /* properties_required */
659 0, /* properties_provided */
660 0, /* properties_destroyed */
661 0, /* todo_flags_start */
662 TODO_dump_func | TODO_update_ssa | TODO_ggc_collect /* todo_flags_finish */
666 /* Loop optimizer finalization. */
669 tree_ssa_loop_done (void)
671 free_numbers_of_iterations_estimates ();
673 loop_optimizer_finalize ();
677 struct gimple_opt_pass pass_tree_loop_done =
681 "loopdone", /* name */
683 tree_ssa_loop_done, /* execute */
686 0, /* static_pass_number */
687 TV_TREE_LOOP_FINI, /* tv_id */
688 PROP_cfg, /* properties_required */
689 0, /* properties_provided */
690 0, /* properties_destroyed */
691 0, /* todo_flags_start */
692 TODO_cleanup_cfg | TODO_dump_func /* todo_flags_finish */