1 /* Loop optimizations over tree-ssa.
2 Copyright (C) 2003, 2005, 2006, 2007, 2008, 2009, 2010
3 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3, or (at your option) any
12 GCC is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
23 #include "coretypes.h"
27 #include "basic-block.h"
28 #include "tree-flow.h"
29 #include "tree-pass.h"
32 #include "tree-inline.h"
33 #include "tree-scalar-evolution.h"
34 #include "diagnostic-core.h"
35 #include "tree-vectorizer.h"
37 /* The loop superpass. */
42 return flag_tree_loop_optimize
!= 0;
45 struct gimple_opt_pass pass_tree_loop
=
50 OPTGROUP_LOOP
, /* optinfo_flags */
51 gate_tree_loop
, /* gate */
55 0, /* static_pass_number */
56 TV_TREE_LOOP
, /* tv_id */
57 PROP_cfg
, /* properties_required */
58 0, /* properties_provided */
59 0, /* properties_destroyed */
60 TODO_ggc_collect
, /* todo_flags_start */
61 TODO_verify_ssa
| TODO_ggc_collect
/* todo_flags_finish */
65 /* Loop optimizer initialization. */
68 tree_ssa_loop_init (void)
70 loop_optimizer_init (LOOPS_NORMAL
71 | LOOPS_HAVE_RECORDED_EXITS
);
72 rewrite_into_loop_closed_ssa (NULL
, TODO_update_ssa
);
74 if (number_of_loops () <= 1)
81 struct gimple_opt_pass pass_tree_loop_init
=
85 "loopinit", /* name */
86 OPTGROUP_LOOP
, /* optinfo_flags */
88 tree_ssa_loop_init
, /* execute */
91 0, /* static_pass_number */
93 PROP_cfg
, /* properties_required */
94 PROP_loops
, /* properties_provided */
95 0, /* properties_destroyed */
96 0, /* todo_flags_start */
97 0 /* todo_flags_finish */
101 /* Loop invariant motion pass. */
104 tree_ssa_loop_im (void)
106 if (number_of_loops () <= 1)
109 return tree_ssa_lim ();
113 gate_tree_ssa_loop_im (void)
115 return flag_tree_loop_im
!= 0;
118 struct gimple_opt_pass pass_lim
=
123 OPTGROUP_LOOP
, /* optinfo_flags */
124 gate_tree_ssa_loop_im
, /* gate */
125 tree_ssa_loop_im
, /* execute */
128 0, /* static_pass_number */
130 PROP_cfg
, /* properties_required */
131 0, /* properties_provided */
132 0, /* properties_destroyed */
133 0, /* todo_flags_start */
134 0 /* todo_flags_finish */
138 /* Loop unswitching pass. */
141 tree_ssa_loop_unswitch (void)
143 if (number_of_loops () <= 1)
146 return tree_ssa_unswitch_loops ();
150 gate_tree_ssa_loop_unswitch (void)
152 return flag_unswitch_loops
!= 0;
155 struct gimple_opt_pass pass_tree_unswitch
=
159 "unswitch", /* name */
160 OPTGROUP_LOOP
, /* optinfo_flags */
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_flags_finish */
175 /* Predictive commoning. */
178 run_tree_predictive_commoning (void)
183 return tree_predictive_commoning ();
187 gate_tree_predictive_commoning (void)
189 return flag_predictive_commoning
!= 0;
192 struct gimple_opt_pass pass_predcom
=
197 OPTGROUP_LOOP
, /* optinfo_flags */
198 gate_tree_predictive_commoning
, /* gate */
199 run_tree_predictive_commoning
, /* execute */
202 0, /* static_pass_number */
203 TV_PREDCOM
, /* tv_id */
204 PROP_cfg
, /* properties_required */
205 0, /* properties_provided */
206 0, /* properties_destroyed */
207 0, /* todo_flags_start */
208 TODO_update_ssa_only_virtuals
/* todo_flags_finish */
212 /* Loop autovectorization. */
215 tree_vectorize (void)
217 if (number_of_loops () <= 1)
220 return vectorize_loops ();
224 gate_tree_vectorize (void)
226 return flag_tree_vectorize
;
229 struct gimple_opt_pass pass_vectorize
=
235 | OPTGROUP_VEC
, /* optinfo_flags */
236 gate_tree_vectorize
, /* gate */
237 tree_vectorize
, /* execute */
240 0, /* static_pass_number */
241 TV_TREE_VECTORIZATION
, /* tv_id */
242 PROP_cfg
| PROP_ssa
, /* properties_required */
243 0, /* properties_provided */
244 0, /* properties_destroyed */
245 0, /* todo_flags_start */
247 | TODO_ggc_collect
/* todo_flags_finish */
251 /* GRAPHITE optimizations. */
254 graphite_transforms (void)
259 graphite_transform_loops ();
265 gate_graphite_transforms (void)
267 /* Enable -fgraphite pass if any one of the graphite optimization flags
270 || flag_loop_interchange
271 || flag_loop_strip_mine
272 || flag_graphite_identity
273 || flag_loop_parallelize_all
274 || flag_loop_optimize_isl
)
277 return flag_graphite
!= 0;
280 struct gimple_opt_pass pass_graphite
=
284 "graphite0", /* name */
285 OPTGROUP_LOOP
, /* optinfo_flags */
286 gate_graphite_transforms
, /* gate */
290 0, /* static_pass_number */
291 TV_GRAPHITE
, /* tv_id */
292 PROP_cfg
| PROP_ssa
, /* properties_required */
293 0, /* properties_provided */
294 0, /* properties_destroyed */
295 0, /* todo_flags_start */
296 0 /* todo_flags_finish */
300 struct gimple_opt_pass pass_graphite_transforms
=
304 "graphite", /* name */
305 OPTGROUP_LOOP
, /* optinfo_flags */
306 gate_graphite_transforms
, /* gate */
307 graphite_transforms
, /* execute */
310 0, /* static_pass_number */
311 TV_GRAPHITE_TRANSFORMS
, /* tv_id */
312 PROP_cfg
| PROP_ssa
, /* properties_required */
313 0, /* properties_provided */
314 0, /* properties_destroyed */
315 0, /* todo_flags_start */
316 0 /* todo_flags_finish */
320 /* Check the correctness of the data dependence analyzers. */
323 check_data_deps (void)
325 if (number_of_loops () <= 1)
328 tree_check_data_deps ();
333 gate_check_data_deps (void)
335 return flag_check_data_deps
!= 0;
338 struct gimple_opt_pass pass_check_data_deps
=
343 OPTGROUP_LOOP
, /* optinfo_flags */
344 gate_check_data_deps
, /* gate */
345 check_data_deps
, /* execute */
348 0, /* static_pass_number */
349 TV_CHECK_DATA_DEPS
, /* tv_id */
350 PROP_cfg
| PROP_ssa
, /* properties_required */
351 0, /* properties_provided */
352 0, /* properties_destroyed */
353 0, /* todo_flags_start */
354 0 /* todo_flags_finish */
358 /* Canonical induction variable creation pass. */
361 tree_ssa_loop_ivcanon (void)
363 if (number_of_loops () <= 1)
366 return canonicalize_induction_variables ();
370 gate_tree_ssa_loop_ivcanon (void)
372 return flag_tree_loop_ivcanon
!= 0;
375 struct gimple_opt_pass pass_iv_canon
=
379 "ivcanon", /* name */
380 OPTGROUP_LOOP
, /* optinfo_flags */
381 gate_tree_ssa_loop_ivcanon
, /* gate */
382 tree_ssa_loop_ivcanon
, /* execute */
385 0, /* static_pass_number */
386 TV_TREE_LOOP_IVCANON
, /* tv_id */
387 PROP_cfg
| PROP_ssa
, /* properties_required */
388 0, /* properties_provided */
389 0, /* properties_destroyed */
390 0, /* todo_flags_start */
391 0 /* todo_flags_finish */
395 /* Propagation of constants using scev. */
398 gate_scev_const_prop (void)
400 return flag_tree_scev_cprop
;
403 struct gimple_opt_pass pass_scev_cprop
=
408 OPTGROUP_LOOP
, /* optinfo_flags */
409 gate_scev_const_prop
, /* gate */
410 scev_const_prop
, /* execute */
413 0, /* static_pass_number */
414 TV_SCEV_CONST
, /* tv_id */
415 PROP_cfg
| PROP_ssa
, /* properties_required */
416 0, /* properties_provided */
417 0, /* properties_destroyed */
418 0, /* todo_flags_start */
420 | TODO_update_ssa_only_virtuals
421 /* todo_flags_finish */
425 /* Record bounds on numbers of iterations of loops. */
428 tree_ssa_loop_bounds (void)
430 if (number_of_loops () <= 1)
433 estimate_numbers_of_iterations ();
438 struct gimple_opt_pass pass_record_bounds
=
442 "*record_bounds", /* name */
443 OPTGROUP_NONE
, /* optinfo_flags */
445 tree_ssa_loop_bounds
, /* execute */
448 0, /* static_pass_number */
449 TV_TREE_LOOP_BOUNDS
, /* tv_id */
450 PROP_cfg
| PROP_ssa
, /* properties_required */
451 0, /* properties_provided */
452 0, /* properties_destroyed */
453 0, /* todo_flags_start */
454 0 /* todo_flags_finish */
458 /* Complete unrolling of loops. */
461 tree_complete_unroll (void)
463 if (number_of_loops () <= 1)
466 return tree_unroll_loops_completely (flag_unroll_loops
468 || optimize
>= 3, true);
472 gate_tree_complete_unroll (void)
477 struct gimple_opt_pass pass_complete_unroll
=
481 "cunroll", /* name */
482 OPTGROUP_LOOP
, /* optinfo_flags */
483 gate_tree_complete_unroll
, /* gate */
484 tree_complete_unroll
, /* execute */
487 0, /* static_pass_number */
488 TV_COMPLETE_UNROLL
, /* tv_id */
489 PROP_cfg
| PROP_ssa
, /* properties_required */
490 0, /* properties_provided */
491 0, /* properties_destroyed */
492 0, /* todo_flags_start */
493 TODO_ggc_collect
/* todo_flags_finish */
497 /* Complete unrolling of inner loops. */
500 tree_complete_unroll_inner (void)
504 loop_optimizer_init (LOOPS_NORMAL
505 | LOOPS_HAVE_RECORDED_EXITS
);
506 if (number_of_loops () > 1)
509 ret
= tree_unroll_loops_completely (optimize
>= 3, false);
510 free_numbers_of_iterations_estimates ();
513 loop_optimizer_finalize ();
519 gate_tree_complete_unroll_inner (void)
521 return optimize
>= 2;
524 struct gimple_opt_pass pass_complete_unrolli
=
528 "cunrolli", /* name */
529 OPTGROUP_LOOP
, /* optinfo_flags */
530 gate_tree_complete_unroll_inner
, /* gate */
531 tree_complete_unroll_inner
, /* execute */
534 0, /* static_pass_number */
535 TV_COMPLETE_UNROLL
, /* tv_id */
536 PROP_cfg
| PROP_ssa
, /* properties_required */
537 0, /* properties_provided */
538 0, /* properties_destroyed */
539 0, /* todo_flags_start */
541 | TODO_ggc_collect
/* todo_flags_finish */
545 /* Parallelization. */
548 gate_tree_parallelize_loops (void)
550 return flag_tree_parallelize_loops
> 1;
554 tree_parallelize_loops (void)
556 if (number_of_loops () <= 1)
559 if (parallelize_loops ())
560 return TODO_cleanup_cfg
| TODO_rebuild_alias
;
564 struct gimple_opt_pass pass_parallelize_loops
=
568 "parloops", /* name */
569 OPTGROUP_LOOP
, /* optinfo_flags */
570 gate_tree_parallelize_loops
, /* gate */
571 tree_parallelize_loops
, /* execute */
574 0, /* static_pass_number */
575 TV_TREE_PARALLELIZE_LOOPS
, /* tv_id */
576 PROP_cfg
| PROP_ssa
, /* properties_required */
577 0, /* properties_provided */
578 0, /* properties_destroyed */
579 0, /* todo_flags_start */
580 0 /* todo_flags_finish */
587 tree_ssa_loop_prefetch (void)
589 if (number_of_loops () <= 1)
592 return tree_ssa_prefetch_arrays ();
596 gate_tree_ssa_loop_prefetch (void)
598 return flag_prefetch_loop_arrays
> 0;
601 struct gimple_opt_pass pass_loop_prefetch
=
605 "aprefetch", /* name */
606 OPTGROUP_LOOP
, /* optinfo_flags */
607 gate_tree_ssa_loop_prefetch
, /* gate */
608 tree_ssa_loop_prefetch
, /* execute */
611 0, /* static_pass_number */
612 TV_TREE_PREFETCH
, /* tv_id */
613 PROP_cfg
| PROP_ssa
, /* properties_required */
614 0, /* properties_provided */
615 0, /* properties_destroyed */
616 0, /* todo_flags_start */
617 0 /* todo_flags_finish */
621 /* Induction variable optimizations. */
624 tree_ssa_loop_ivopts (void)
626 if (number_of_loops () <= 1)
629 tree_ssa_iv_optimize ();
634 gate_tree_ssa_loop_ivopts (void)
636 return flag_ivopts
!= 0;
639 struct gimple_opt_pass pass_iv_optimize
=
644 OPTGROUP_LOOP
, /* optinfo_flags */
645 gate_tree_ssa_loop_ivopts
, /* gate */
646 tree_ssa_loop_ivopts
, /* execute */
649 0, /* static_pass_number */
650 TV_TREE_LOOP_IVOPTS
, /* tv_id */
651 PROP_cfg
| PROP_ssa
, /* properties_required */
652 0, /* properties_provided */
653 0, /* properties_destroyed */
654 0, /* todo_flags_start */
655 TODO_update_ssa
| TODO_ggc_collect
/* todo_flags_finish */
659 /* Loop optimizer finalization. */
662 tree_ssa_loop_done (void)
664 free_numbers_of_iterations_estimates ();
666 loop_optimizer_finalize ();
670 struct gimple_opt_pass pass_tree_loop_done
=
674 "loopdone", /* name */
675 OPTGROUP_LOOP
, /* optinfo_flags */
677 tree_ssa_loop_done
, /* execute */
680 0, /* static_pass_number */
682 PROP_cfg
, /* properties_required */
683 0, /* properties_provided */
684 0, /* properties_destroyed */
685 0, /* todo_flags_start */
687 | TODO_verify_flow
/* todo_flags_finish */