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_dump_func | 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 TODO_dump_func /* 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 TODO_dump_func /* 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_dump_func /* todo_flags_finish */
174 /* Predictive commoning. */
177 run_tree_predictive_commoning (void)
182 tree_predictive_commoning ();
187 gate_tree_predictive_commoning (void)
189 return flag_predictive_commoning != 0;
192 struct gimple_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 */
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 =
234 gate_tree_vectorize, /* gate */
235 tree_vectorize, /* execute */
238 0, /* static_pass_number */
239 TV_TREE_VECTORIZATION, /* tv_id */
240 PROP_cfg | PROP_ssa, /* properties_required */
241 0, /* properties_provided */
242 0, /* properties_destroyed */
243 0, /* todo_flags_start */
244 TODO_dump_func | TODO_update_ssa
245 | TODO_ggc_collect /* todo_flags_finish */
249 /* GRAPHITE optimizations. */
252 graphite_transforms (void)
257 graphite_transform_loops ();
263 gate_graphite_transforms (void)
265 /* Enable -fgraphite pass if any one of the graphite optimization flags
268 || flag_loop_interchange
269 || flag_loop_strip_mine
270 || flag_graphite_identity
271 || flag_loop_parallelize_all
272 || flag_loop_flatten)
275 return flag_graphite != 0;
278 struct gimple_opt_pass pass_graphite =
282 "graphite0", /* name */
283 gate_graphite_transforms, /* gate */
287 0, /* static_pass_number */
288 TV_GRAPHITE, /* tv_id */
289 PROP_cfg | PROP_ssa, /* properties_required */
290 0, /* properties_provided */
291 0, /* properties_destroyed */
292 0, /* todo_flags_start */
293 0 /* todo_flags_finish */
297 struct gimple_opt_pass pass_graphite_transforms =
301 "graphite", /* name */
302 gate_graphite_transforms, /* gate */
303 graphite_transforms, /* execute */
306 0, /* static_pass_number */
307 TV_GRAPHITE_TRANSFORMS, /* tv_id */
308 PROP_cfg | PROP_ssa, /* properties_required */
309 0, /* properties_provided */
310 0, /* properties_destroyed */
311 0, /* todo_flags_start */
312 TODO_dump_func /* todo_flags_finish */
316 /* Check the correctness of the data dependence analyzers. */
319 check_data_deps (void)
321 if (number_of_loops () <= 1)
324 tree_check_data_deps ();
329 gate_check_data_deps (void)
331 return flag_check_data_deps != 0;
334 struct gimple_opt_pass pass_check_data_deps =
339 gate_check_data_deps, /* gate */
340 check_data_deps, /* execute */
343 0, /* static_pass_number */
344 TV_CHECK_DATA_DEPS, /* tv_id */
345 PROP_cfg | PROP_ssa, /* properties_required */
346 0, /* properties_provided */
347 0, /* properties_destroyed */
348 0, /* todo_flags_start */
349 TODO_dump_func /* todo_flags_finish */
353 /* Canonical induction variable creation pass. */
356 tree_ssa_loop_ivcanon (void)
358 if (number_of_loops () <= 1)
361 return canonicalize_induction_variables ();
365 gate_tree_ssa_loop_ivcanon (void)
367 return flag_tree_loop_ivcanon != 0;
370 struct gimple_opt_pass pass_iv_canon =
374 "ivcanon", /* name */
375 gate_tree_ssa_loop_ivcanon, /* gate */
376 tree_ssa_loop_ivcanon, /* execute */
379 0, /* static_pass_number */
380 TV_TREE_LOOP_IVCANON, /* tv_id */
381 PROP_cfg | PROP_ssa, /* properties_required */
382 0, /* properties_provided */
383 0, /* properties_destroyed */
384 0, /* todo_flags_start */
385 TODO_dump_func /* todo_flags_finish */
389 /* Propagation of constants using scev. */
392 gate_scev_const_prop (void)
394 return flag_tree_scev_cprop;
397 struct gimple_opt_pass pass_scev_cprop =
402 gate_scev_const_prop, /* gate */
403 scev_const_prop, /* execute */
406 0, /* static_pass_number */
407 TV_SCEV_CONST, /* tv_id */
408 PROP_cfg | PROP_ssa, /* properties_required */
409 0, /* properties_provided */
410 0, /* properties_destroyed */
411 0, /* todo_flags_start */
412 TODO_dump_func | TODO_cleanup_cfg
413 | TODO_update_ssa_only_virtuals
414 /* todo_flags_finish */
418 /* Record bounds on numbers of iterations of loops. */
421 tree_ssa_loop_bounds (void)
423 if (number_of_loops () <= 1)
426 estimate_numbers_of_iterations (true);
431 struct gimple_opt_pass pass_record_bounds =
435 "*record_bounds", /* name */
437 tree_ssa_loop_bounds, /* execute */
440 0, /* static_pass_number */
441 TV_TREE_LOOP_BOUNDS, /* tv_id */
442 PROP_cfg | PROP_ssa, /* properties_required */
443 0, /* properties_provided */
444 0, /* properties_destroyed */
445 0, /* todo_flags_start */
446 0 /* todo_flags_finish */
450 /* Complete unrolling of loops. */
453 tree_complete_unroll (void)
455 if (number_of_loops () <= 1)
458 return tree_unroll_loops_completely (flag_unroll_loops
460 || optimize >= 3, true);
464 gate_tree_complete_unroll (void)
469 struct gimple_opt_pass pass_complete_unroll =
473 "cunroll", /* name */
474 gate_tree_complete_unroll, /* gate */
475 tree_complete_unroll, /* execute */
478 0, /* static_pass_number */
479 TV_COMPLETE_UNROLL, /* tv_id */
480 PROP_cfg | PROP_ssa, /* properties_required */
481 0, /* properties_provided */
482 0, /* properties_destroyed */
483 0, /* todo_flags_start */
485 | TODO_ggc_collect /* todo_flags_finish */
489 /* Complete unrolling of inner loops. */
492 tree_complete_unroll_inner (void)
496 loop_optimizer_init (LOOPS_NORMAL
497 | LOOPS_HAVE_RECORDED_EXITS);
498 if (number_of_loops () > 1)
501 ret = tree_unroll_loops_completely (optimize >= 3, false);
502 free_numbers_of_iterations_estimates ();
505 loop_optimizer_finalize ();
511 gate_tree_complete_unroll_inner (void)
513 return optimize >= 2;
516 struct gimple_opt_pass pass_complete_unrolli =
520 "cunrolli", /* name */
521 gate_tree_complete_unroll_inner, /* gate */
522 tree_complete_unroll_inner, /* execute */
525 0, /* static_pass_number */
526 TV_COMPLETE_UNROLL, /* tv_id */
527 PROP_cfg | PROP_ssa, /* properties_required */
528 0, /* properties_provided */
529 0, /* properties_destroyed */
530 0, /* todo_flags_start */
533 | TODO_ggc_collect /* todo_flags_finish */
537 /* Parallelization. */
540 gate_tree_parallelize_loops (void)
542 return flag_tree_parallelize_loops > 1;
546 tree_parallelize_loops (void)
548 if (number_of_loops () <= 1)
551 if (parallelize_loops ())
552 return TODO_cleanup_cfg | TODO_rebuild_alias;
556 struct gimple_opt_pass pass_parallelize_loops =
560 "parloops", /* name */
561 gate_tree_parallelize_loops, /* gate */
562 tree_parallelize_loops, /* execute */
565 0, /* static_pass_number */
566 TV_TREE_PARALLELIZE_LOOPS, /* tv_id */
567 PROP_cfg | PROP_ssa, /* properties_required */
568 0, /* properties_provided */
569 0, /* properties_destroyed */
570 0, /* todo_flags_start */
571 TODO_dump_func /* todo_flags_finish */
578 tree_ssa_loop_prefetch (void)
580 if (number_of_loops () <= 1)
583 return tree_ssa_prefetch_arrays ();
587 gate_tree_ssa_loop_prefetch (void)
589 return flag_prefetch_loop_arrays > 0;
592 struct gimple_opt_pass pass_loop_prefetch =
596 "aprefetch", /* name */
597 gate_tree_ssa_loop_prefetch, /* gate */
598 tree_ssa_loop_prefetch, /* execute */
601 0, /* static_pass_number */
602 TV_TREE_PREFETCH, /* tv_id */
603 PROP_cfg | PROP_ssa, /* properties_required */
604 0, /* properties_provided */
605 0, /* properties_destroyed */
606 0, /* todo_flags_start */
607 TODO_dump_func /* todo_flags_finish */
611 /* Induction variable optimizations. */
614 tree_ssa_loop_ivopts (void)
616 if (number_of_loops () <= 1)
619 tree_ssa_iv_optimize ();
624 gate_tree_ssa_loop_ivopts (void)
626 return flag_ivopts != 0;
629 struct gimple_opt_pass pass_iv_optimize =
634 gate_tree_ssa_loop_ivopts, /* gate */
635 tree_ssa_loop_ivopts, /* execute */
638 0, /* static_pass_number */
639 TV_TREE_LOOP_IVOPTS, /* tv_id */
640 PROP_cfg | PROP_ssa, /* properties_required */
641 0, /* properties_provided */
642 0, /* properties_destroyed */
643 0, /* todo_flags_start */
644 TODO_dump_func | TODO_update_ssa | TODO_ggc_collect /* todo_flags_finish */
648 /* Loop optimizer finalization. */
651 tree_ssa_loop_done (void)
653 free_numbers_of_iterations_estimates ();
655 loop_optimizer_finalize ();
659 struct gimple_opt_pass pass_tree_loop_done =
663 "loopdone", /* name */
665 tree_ssa_loop_done, /* execute */
668 0, /* static_pass_number */
669 TV_TREE_LOOP_FINI, /* tv_id */
670 PROP_cfg, /* properties_required */
671 0, /* properties_provided */
672 0, /* properties_destroyed */
673 0, /* todo_flags_start */
676 | TODO_dump_func /* todo_flags_finish */