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"
29 #include "tree-flow.h"
30 #include "tree-dump.h"
31 #include "tree-pass.h"
35 #include "tree-inline.h"
36 #include "tree-scalar-evolution.h"
37 #include "diagnostic-core.h"
38 #include "tree-vectorizer.h"
40 /* The loop superpass. */
45 return flag_tree_loop_optimize
!= 0;
48 struct gimple_opt_pass pass_tree_loop
=
53 gate_tree_loop
, /* gate */
57 0, /* static_pass_number */
58 TV_TREE_LOOP
, /* tv_id */
59 PROP_cfg
, /* properties_required */
60 0, /* properties_provided */
61 0, /* properties_destroyed */
62 TODO_ggc_collect
, /* todo_flags_start */
63 TODO_verify_ssa
| TODO_ggc_collect
/* todo_flags_finish */
67 /* Loop optimizer initialization. */
70 tree_ssa_loop_init (void)
72 loop_optimizer_init (LOOPS_NORMAL
73 | LOOPS_HAVE_RECORDED_EXITS
);
74 rewrite_into_loop_closed_ssa (NULL
, TODO_update_ssa
);
76 if (number_of_loops () <= 1)
83 struct gimple_opt_pass pass_tree_loop_init
=
87 "loopinit", /* name */
89 tree_ssa_loop_init
, /* execute */
92 0, /* static_pass_number */
93 TV_TREE_LOOP_INIT
, /* tv_id */
94 PROP_cfg
, /* properties_required */
95 0, /* properties_provided */
96 0, /* properties_destroyed */
97 0, /* todo_flags_start */
98 0 /* todo_flags_finish */
102 /* Loop invariant motion pass. */
105 tree_ssa_loop_im (void)
107 if (number_of_loops () <= 1)
110 return tree_ssa_lim ();
114 gate_tree_ssa_loop_im (void)
116 return flag_tree_loop_im
!= 0;
119 struct gimple_opt_pass pass_lim
=
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 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_flags_finish */
174 /* Predictive commoning. */
177 run_tree_predictive_commoning (void)
182 return tree_predictive_commoning ();
186 gate_tree_predictive_commoning (void)
188 return flag_predictive_commoning
!= 0;
191 struct gimple_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_update_ssa_only_virtuals
/* todo_flags_finish */
210 /* Loop autovectorization. */
213 tree_vectorize (void)
215 if (number_of_loops () <= 1)
218 return vectorize_loops ();
222 gate_tree_vectorize (void)
224 return flag_tree_vectorize
;
227 struct gimple_opt_pass pass_vectorize
=
232 gate_tree_vectorize
, /* gate */
233 tree_vectorize
, /* execute */
236 0, /* static_pass_number */
237 TV_TREE_VECTORIZATION
, /* tv_id */
238 PROP_cfg
| PROP_ssa
, /* properties_required */
239 0, /* properties_provided */
240 0, /* properties_destroyed */
241 0, /* todo_flags_start */
243 | TODO_ggc_collect
/* todo_flags_finish */
247 /* GRAPHITE optimizations. */
250 graphite_transforms (void)
255 graphite_transform_loops ();
261 gate_graphite_transforms (void)
263 /* Enable -fgraphite pass if any one of the graphite optimization flags
266 || flag_loop_interchange
267 || flag_loop_strip_mine
268 || flag_graphite_identity
269 || flag_loop_parallelize_all
270 || flag_loop_flatten
)
273 return flag_graphite
!= 0;
276 struct gimple_opt_pass pass_graphite
=
280 "graphite0", /* name */
281 gate_graphite_transforms
, /* gate */
285 0, /* static_pass_number */
286 TV_GRAPHITE
, /* tv_id */
287 PROP_cfg
| PROP_ssa
, /* properties_required */
288 0, /* properties_provided */
289 0, /* properties_destroyed */
290 0, /* todo_flags_start */
291 0 /* todo_flags_finish */
295 struct gimple_opt_pass pass_graphite_transforms
=
299 "graphite", /* name */
300 gate_graphite_transforms
, /* gate */
301 graphite_transforms
, /* execute */
304 0, /* static_pass_number */
305 TV_GRAPHITE_TRANSFORMS
, /* tv_id */
306 PROP_cfg
| PROP_ssa
, /* properties_required */
307 0, /* properties_provided */
308 0, /* properties_destroyed */
309 0, /* todo_flags_start */
310 0 /* todo_flags_finish */
314 /* Check the correctness of the data dependence analyzers. */
317 check_data_deps (void)
319 if (number_of_loops () <= 1)
322 tree_check_data_deps ();
327 gate_check_data_deps (void)
329 return flag_check_data_deps
!= 0;
332 struct gimple_opt_pass pass_check_data_deps
=
337 gate_check_data_deps
, /* gate */
338 check_data_deps
, /* execute */
341 0, /* static_pass_number */
342 TV_CHECK_DATA_DEPS
, /* tv_id */
343 PROP_cfg
| PROP_ssa
, /* properties_required */
344 0, /* properties_provided */
345 0, /* properties_destroyed */
346 0, /* todo_flags_start */
347 0 /* todo_flags_finish */
351 /* Canonical induction variable creation pass. */
354 tree_ssa_loop_ivcanon (void)
356 if (number_of_loops () <= 1)
359 return canonicalize_induction_variables ();
363 gate_tree_ssa_loop_ivcanon (void)
365 return flag_tree_loop_ivcanon
!= 0;
368 struct gimple_opt_pass pass_iv_canon
=
372 "ivcanon", /* name */
373 gate_tree_ssa_loop_ivcanon
, /* gate */
374 tree_ssa_loop_ivcanon
, /* execute */
377 0, /* static_pass_number */
378 TV_TREE_LOOP_IVCANON
, /* tv_id */
379 PROP_cfg
| PROP_ssa
, /* properties_required */
380 0, /* properties_provided */
381 0, /* properties_destroyed */
382 0, /* todo_flags_start */
383 0 /* todo_flags_finish */
387 /* Propagation of constants using scev. */
390 gate_scev_const_prop (void)
392 return flag_tree_scev_cprop
;
395 struct gimple_opt_pass pass_scev_cprop
=
400 gate_scev_const_prop
, /* gate */
401 scev_const_prop
, /* execute */
404 0, /* static_pass_number */
405 TV_SCEV_CONST
, /* tv_id */
406 PROP_cfg
| PROP_ssa
, /* properties_required */
407 0, /* properties_provided */
408 0, /* properties_destroyed */
409 0, /* todo_flags_start */
411 | TODO_update_ssa_only_virtuals
412 /* todo_flags_finish */
416 /* Record bounds on numbers of iterations of loops. */
419 tree_ssa_loop_bounds (void)
421 if (number_of_loops () <= 1)
424 estimate_numbers_of_iterations (true);
429 struct gimple_opt_pass pass_record_bounds
=
433 "*record_bounds", /* name */
435 tree_ssa_loop_bounds
, /* execute */
438 0, /* static_pass_number */
439 TV_TREE_LOOP_BOUNDS
, /* tv_id */
440 PROP_cfg
| PROP_ssa
, /* properties_required */
441 0, /* properties_provided */
442 0, /* properties_destroyed */
443 0, /* todo_flags_start */
444 0 /* todo_flags_finish */
448 /* Complete unrolling of loops. */
451 tree_complete_unroll (void)
453 if (number_of_loops () <= 1)
456 return tree_unroll_loops_completely (flag_unroll_loops
458 || optimize
>= 3, true);
462 gate_tree_complete_unroll (void)
467 struct gimple_opt_pass pass_complete_unroll
=
471 "cunroll", /* name */
472 gate_tree_complete_unroll
, /* gate */
473 tree_complete_unroll
, /* execute */
476 0, /* static_pass_number */
477 TV_COMPLETE_UNROLL
, /* tv_id */
478 PROP_cfg
| PROP_ssa
, /* properties_required */
479 0, /* properties_provided */
480 0, /* properties_destroyed */
481 0, /* todo_flags_start */
482 TODO_ggc_collect
/* todo_flags_finish */
486 /* Complete unrolling of inner loops. */
489 tree_complete_unroll_inner (void)
493 loop_optimizer_init (LOOPS_NORMAL
494 | LOOPS_HAVE_RECORDED_EXITS
);
495 if (number_of_loops () > 1)
498 ret
= tree_unroll_loops_completely (optimize
>= 3, false);
499 free_numbers_of_iterations_estimates ();
502 loop_optimizer_finalize ();
508 gate_tree_complete_unroll_inner (void)
510 return optimize
>= 2;
513 struct gimple_opt_pass pass_complete_unrolli
=
517 "cunrolli", /* name */
518 gate_tree_complete_unroll_inner
, /* gate */
519 tree_complete_unroll_inner
, /* execute */
522 0, /* static_pass_number */
523 TV_COMPLETE_UNROLL
, /* tv_id */
524 PROP_cfg
| PROP_ssa
, /* properties_required */
525 0, /* properties_provided */
526 0, /* properties_destroyed */
527 0, /* todo_flags_start */
529 | TODO_ggc_collect
/* todo_flags_finish */
533 /* Parallelization. */
536 gate_tree_parallelize_loops (void)
538 return flag_tree_parallelize_loops
> 1;
542 tree_parallelize_loops (void)
544 if (number_of_loops () <= 1)
547 if (parallelize_loops ())
548 return TODO_cleanup_cfg
| TODO_rebuild_alias
;
552 struct gimple_opt_pass pass_parallelize_loops
=
556 "parloops", /* name */
557 gate_tree_parallelize_loops
, /* gate */
558 tree_parallelize_loops
, /* execute */
561 0, /* static_pass_number */
562 TV_TREE_PARALLELIZE_LOOPS
, /* tv_id */
563 PROP_cfg
| PROP_ssa
, /* properties_required */
564 0, /* properties_provided */
565 0, /* properties_destroyed */
566 0, /* todo_flags_start */
567 0 /* todo_flags_finish */
574 tree_ssa_loop_prefetch (void)
576 if (number_of_loops () <= 1)
579 return tree_ssa_prefetch_arrays ();
583 gate_tree_ssa_loop_prefetch (void)
585 return flag_prefetch_loop_arrays
> 0;
588 struct gimple_opt_pass pass_loop_prefetch
=
592 "aprefetch", /* name */
593 gate_tree_ssa_loop_prefetch
, /* gate */
594 tree_ssa_loop_prefetch
, /* execute */
597 0, /* static_pass_number */
598 TV_TREE_PREFETCH
, /* tv_id */
599 PROP_cfg
| PROP_ssa
, /* properties_required */
600 0, /* properties_provided */
601 0, /* properties_destroyed */
602 0, /* todo_flags_start */
603 0 /* todo_flags_finish */
607 /* Induction variable optimizations. */
610 tree_ssa_loop_ivopts (void)
612 if (number_of_loops () <= 1)
615 tree_ssa_iv_optimize ();
620 gate_tree_ssa_loop_ivopts (void)
622 return flag_ivopts
!= 0;
625 struct gimple_opt_pass pass_iv_optimize
=
630 gate_tree_ssa_loop_ivopts
, /* gate */
631 tree_ssa_loop_ivopts
, /* execute */
634 0, /* static_pass_number */
635 TV_TREE_LOOP_IVOPTS
, /* tv_id */
636 PROP_cfg
| PROP_ssa
, /* properties_required */
637 0, /* properties_provided */
638 0, /* properties_destroyed */
639 0, /* todo_flags_start */
640 TODO_update_ssa
| TODO_ggc_collect
/* todo_flags_finish */
644 /* Loop optimizer finalization. */
647 tree_ssa_loop_done (void)
649 free_numbers_of_iterations_estimates ();
651 loop_optimizer_finalize ();
655 struct gimple_opt_pass pass_tree_loop_done
=
659 "loopdone", /* name */
661 tree_ssa_loop_done
, /* execute */
664 0, /* static_pass_number */
665 TV_TREE_LOOP_FINI
, /* tv_id */
666 PROP_cfg
, /* properties_required */
667 0, /* properties_provided */
668 0, /* properties_destroyed */
669 0, /* todo_flags_start */
671 | TODO_verify_flow
/* todo_flags_finish */