* configure.ac (GCJ_JAVAC): Run false rather than no.
[official-gcc.git] / gcc / tree-ssa-loop.c
blob5534b6a515aeb9a421a491f8873e9bbf59e00a7f
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
10 later version.
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
15 for more details.
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/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "tree.h"
26 #include "tm_p.h"
27 #include "basic-block.h"
28 #include "output.h"
29 #include "tree-flow.h"
30 #include "tree-dump.h"
31 #include "tree-pass.h"
32 #include "timevar.h"
33 #include "cfgloop.h"
34 #include "flags.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. */
42 static bool
43 gate_tree_loop (void)
45 return flag_tree_loop_optimize != 0;
48 struct gimple_opt_pass pass_tree_loop =
51 GIMPLE_PASS,
52 "loop", /* name */
53 gate_tree_loop, /* gate */
54 NULL, /* execute */
55 NULL, /* sub */
56 NULL, /* next */
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. */
69 static unsigned int
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)
77 return 0;
79 scev_initialize ();
80 return 0;
83 struct gimple_opt_pass pass_tree_loop_init =
86 GIMPLE_PASS,
87 "loopinit", /* name */
88 NULL, /* gate */
89 tree_ssa_loop_init, /* execute */
90 NULL, /* sub */
91 NULL, /* next */
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. */
104 static unsigned int
105 tree_ssa_loop_im (void)
107 if (number_of_loops () <= 1)
108 return 0;
110 return tree_ssa_lim ();
113 static bool
114 gate_tree_ssa_loop_im (void)
116 return flag_tree_loop_im != 0;
119 struct gimple_opt_pass pass_lim =
122 GIMPLE_PASS,
123 "lim", /* name */
124 gate_tree_ssa_loop_im, /* gate */
125 tree_ssa_loop_im, /* execute */
126 NULL, /* sub */
127 NULL, /* next */
128 0, /* static_pass_number */
129 TV_LIM, /* tv_id */
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. */
140 static unsigned int
141 tree_ssa_loop_unswitch (void)
143 if (number_of_loops () <= 1)
144 return 0;
146 return tree_ssa_unswitch_loops ();
149 static bool
150 gate_tree_ssa_loop_unswitch (void)
152 return flag_unswitch_loops != 0;
155 struct gimple_opt_pass pass_tree_unswitch =
158 GIMPLE_PASS,
159 "unswitch", /* name */
160 gate_tree_ssa_loop_unswitch, /* gate */
161 tree_ssa_loop_unswitch, /* execute */
162 NULL, /* sub */
163 NULL, /* next */
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. */
176 static unsigned
177 run_tree_predictive_commoning (void)
179 if (!current_loops)
180 return 0;
182 tree_predictive_commoning ();
183 return 0;
186 static bool
187 gate_tree_predictive_commoning (void)
189 return flag_predictive_commoning != 0;
192 struct gimple_opt_pass pass_predcom =
195 GIMPLE_PASS,
196 "pcom", /* name */
197 gate_tree_predictive_commoning, /* gate */
198 run_tree_predictive_commoning, /* execute */
199 NULL, /* sub */
200 NULL, /* next */
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 */
207 TODO_dump_func
208 | TODO_update_ssa_only_virtuals /* todo_flags_finish */
212 /* Loop autovectorization. */
214 static unsigned int
215 tree_vectorize (void)
217 if (number_of_loops () <= 1)
218 return 0;
220 return vectorize_loops ();
223 static bool
224 gate_tree_vectorize (void)
226 return flag_tree_vectorize;
229 struct gimple_opt_pass pass_vectorize =
232 GIMPLE_PASS,
233 "vect", /* name */
234 gate_tree_vectorize, /* gate */
235 tree_vectorize, /* execute */
236 NULL, /* sub */
237 NULL, /* next */
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. */
251 static unsigned int
252 graphite_transforms (void)
254 if (!current_loops)
255 return 0;
257 graphite_transform_loops ();
259 return 0;
262 static bool
263 gate_graphite_transforms (void)
265 /* Enable -fgraphite pass if any one of the graphite optimization flags
266 is turned on. */
267 if (flag_loop_block
268 || flag_loop_interchange
269 || flag_tree_loop_linear
270 || flag_loop_strip_mine
271 || flag_graphite_identity
272 || flag_loop_parallelize_all
273 || flag_loop_flatten)
274 flag_graphite = 1;
276 /* Make flag_tree_loop_linear an alias of flag_loop_interchange. */
277 if (flag_tree_loop_linear)
278 flag_loop_interchange = flag_tree_loop_linear;
280 return flag_graphite != 0;
283 struct gimple_opt_pass pass_graphite =
286 GIMPLE_PASS,
287 "graphite0", /* name */
288 gate_graphite_transforms, /* gate */
289 NULL, /* execute */
290 NULL, /* sub */
291 NULL, /* next */
292 0, /* static_pass_number */
293 TV_GRAPHITE, /* tv_id */
294 PROP_cfg | PROP_ssa, /* properties_required */
295 0, /* properties_provided */
296 0, /* properties_destroyed */
297 0, /* todo_flags_start */
298 0 /* todo_flags_finish */
302 struct gimple_opt_pass pass_graphite_transforms =
305 GIMPLE_PASS,
306 "graphite", /* name */
307 gate_graphite_transforms, /* gate */
308 graphite_transforms, /* execute */
309 NULL, /* sub */
310 NULL, /* next */
311 0, /* static_pass_number */
312 TV_GRAPHITE_TRANSFORMS, /* tv_id */
313 PROP_cfg | PROP_ssa, /* properties_required */
314 0, /* properties_provided */
315 0, /* properties_destroyed */
316 0, /* todo_flags_start */
317 0 /* todo_flags_finish */
321 /* Check the correctness of the data dependence analyzers. */
323 static unsigned int
324 check_data_deps (void)
326 if (number_of_loops () <= 1)
327 return 0;
329 tree_check_data_deps ();
330 return 0;
333 static bool
334 gate_check_data_deps (void)
336 return flag_check_data_deps != 0;
339 struct gimple_opt_pass pass_check_data_deps =
342 GIMPLE_PASS,
343 "ckdd", /* name */
344 gate_check_data_deps, /* gate */
345 check_data_deps, /* execute */
346 NULL, /* sub */
347 NULL, /* next */
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 TODO_dump_func /* todo_flags_finish */
358 /* Canonical induction variable creation pass. */
360 static unsigned int
361 tree_ssa_loop_ivcanon (void)
363 if (number_of_loops () <= 1)
364 return 0;
366 return canonicalize_induction_variables ();
369 static bool
370 gate_tree_ssa_loop_ivcanon (void)
372 return flag_tree_loop_ivcanon != 0;
375 struct gimple_opt_pass pass_iv_canon =
378 GIMPLE_PASS,
379 "ivcanon", /* name */
380 gate_tree_ssa_loop_ivcanon, /* gate */
381 tree_ssa_loop_ivcanon, /* execute */
382 NULL, /* sub */
383 NULL, /* next */
384 0, /* static_pass_number */
385 TV_TREE_LOOP_IVCANON, /* tv_id */
386 PROP_cfg | PROP_ssa, /* properties_required */
387 0, /* properties_provided */
388 0, /* properties_destroyed */
389 0, /* todo_flags_start */
390 TODO_dump_func /* todo_flags_finish */
394 /* Propagation of constants using scev. */
396 static bool
397 gate_scev_const_prop (void)
399 return flag_tree_scev_cprop;
402 struct gimple_opt_pass pass_scev_cprop =
405 GIMPLE_PASS,
406 "sccp", /* name */
407 gate_scev_const_prop, /* gate */
408 scev_const_prop, /* execute */
409 NULL, /* sub */
410 NULL, /* next */
411 0, /* static_pass_number */
412 TV_SCEV_CONST, /* tv_id */
413 PROP_cfg | PROP_ssa, /* properties_required */
414 0, /* properties_provided */
415 0, /* properties_destroyed */
416 0, /* todo_flags_start */
417 TODO_dump_func | TODO_cleanup_cfg
418 | TODO_update_ssa_only_virtuals
419 /* todo_flags_finish */
423 /* Record bounds on numbers of iterations of loops. */
425 static unsigned int
426 tree_ssa_loop_bounds (void)
428 if (number_of_loops () <= 1)
429 return 0;
431 estimate_numbers_of_iterations (true);
432 scev_reset ();
433 return 0;
436 struct gimple_opt_pass pass_record_bounds =
439 GIMPLE_PASS,
440 "*record_bounds", /* name */
441 NULL, /* gate */
442 tree_ssa_loop_bounds, /* execute */
443 NULL, /* sub */
444 NULL, /* next */
445 0, /* static_pass_number */
446 TV_TREE_LOOP_BOUNDS, /* tv_id */
447 PROP_cfg | PROP_ssa, /* properties_required */
448 0, /* properties_provided */
449 0, /* properties_destroyed */
450 0, /* todo_flags_start */
451 0 /* todo_flags_finish */
455 /* Complete unrolling of loops. */
457 static unsigned int
458 tree_complete_unroll (void)
460 if (number_of_loops () <= 1)
461 return 0;
463 return tree_unroll_loops_completely (flag_unroll_loops
464 || flag_peel_loops
465 || optimize >= 3, true);
468 static bool
469 gate_tree_complete_unroll (void)
471 return true;
474 struct gimple_opt_pass pass_complete_unroll =
477 GIMPLE_PASS,
478 "cunroll", /* name */
479 gate_tree_complete_unroll, /* gate */
480 tree_complete_unroll, /* execute */
481 NULL, /* sub */
482 NULL, /* next */
483 0, /* static_pass_number */
484 TV_COMPLETE_UNROLL, /* tv_id */
485 PROP_cfg | PROP_ssa, /* properties_required */
486 0, /* properties_provided */
487 0, /* properties_destroyed */
488 0, /* todo_flags_start */
489 TODO_dump_func
490 | TODO_ggc_collect /* todo_flags_finish */
494 /* Complete unrolling of inner loops. */
496 static unsigned int
497 tree_complete_unroll_inner (void)
499 unsigned ret = 0;
501 loop_optimizer_init (LOOPS_NORMAL
502 | LOOPS_HAVE_RECORDED_EXITS);
503 if (number_of_loops () > 1)
505 scev_initialize ();
506 ret = tree_unroll_loops_completely (optimize >= 3, false);
507 free_numbers_of_iterations_estimates ();
508 scev_finalize ();
510 loop_optimizer_finalize ();
512 return ret;
515 static bool
516 gate_tree_complete_unroll_inner (void)
518 return optimize >= 2;
521 struct gimple_opt_pass pass_complete_unrolli =
524 GIMPLE_PASS,
525 "cunrolli", /* name */
526 gate_tree_complete_unroll_inner, /* gate */
527 tree_complete_unroll_inner, /* execute */
528 NULL, /* sub */
529 NULL, /* next */
530 0, /* static_pass_number */
531 TV_COMPLETE_UNROLL, /* tv_id */
532 PROP_cfg | PROP_ssa, /* properties_required */
533 0, /* properties_provided */
534 0, /* properties_destroyed */
535 0, /* todo_flags_start */
536 TODO_dump_func
537 | TODO_ggc_collect /* todo_flags_finish */
541 /* Parallelization. */
543 static bool
544 gate_tree_parallelize_loops (void)
546 return flag_tree_parallelize_loops > 1;
549 static unsigned
550 tree_parallelize_loops (void)
552 if (number_of_loops () <= 1)
553 return 0;
555 if (parallelize_loops ())
556 return TODO_cleanup_cfg | TODO_rebuild_alias;
557 return 0;
560 struct gimple_opt_pass pass_parallelize_loops =
563 GIMPLE_PASS,
564 "parloops", /* name */
565 gate_tree_parallelize_loops, /* gate */
566 tree_parallelize_loops, /* execute */
567 NULL, /* sub */
568 NULL, /* next */
569 0, /* static_pass_number */
570 TV_TREE_PARALLELIZE_LOOPS, /* tv_id */
571 PROP_cfg | PROP_ssa, /* properties_required */
572 0, /* properties_provided */
573 0, /* properties_destroyed */
574 0, /* todo_flags_start */
575 TODO_dump_func /* todo_flags_finish */
579 /* Prefetching. */
581 static unsigned int
582 tree_ssa_loop_prefetch (void)
584 if (number_of_loops () <= 1)
585 return 0;
587 return tree_ssa_prefetch_arrays ();
590 static bool
591 gate_tree_ssa_loop_prefetch (void)
593 return flag_prefetch_loop_arrays > 0;
596 struct gimple_opt_pass pass_loop_prefetch =
599 GIMPLE_PASS,
600 "aprefetch", /* name */
601 gate_tree_ssa_loop_prefetch, /* gate */
602 tree_ssa_loop_prefetch, /* execute */
603 NULL, /* sub */
604 NULL, /* next */
605 0, /* static_pass_number */
606 TV_TREE_PREFETCH, /* tv_id */
607 PROP_cfg | PROP_ssa, /* properties_required */
608 0, /* properties_provided */
609 0, /* properties_destroyed */
610 0, /* todo_flags_start */
611 TODO_dump_func /* todo_flags_finish */
615 /* Induction variable optimizations. */
617 static unsigned int
618 tree_ssa_loop_ivopts (void)
620 if (number_of_loops () <= 1)
621 return 0;
623 tree_ssa_iv_optimize ();
624 return 0;
627 static bool
628 gate_tree_ssa_loop_ivopts (void)
630 return flag_ivopts != 0;
633 struct gimple_opt_pass pass_iv_optimize =
636 GIMPLE_PASS,
637 "ivopts", /* name */
638 gate_tree_ssa_loop_ivopts, /* gate */
639 tree_ssa_loop_ivopts, /* execute */
640 NULL, /* sub */
641 NULL, /* next */
642 0, /* static_pass_number */
643 TV_TREE_LOOP_IVOPTS, /* tv_id */
644 PROP_cfg | PROP_ssa, /* properties_required */
645 0, /* properties_provided */
646 0, /* properties_destroyed */
647 0, /* todo_flags_start */
648 TODO_dump_func | TODO_update_ssa | TODO_ggc_collect /* todo_flags_finish */
652 /* Loop optimizer finalization. */
654 static unsigned int
655 tree_ssa_loop_done (void)
657 free_numbers_of_iterations_estimates ();
658 scev_finalize ();
659 loop_optimizer_finalize ();
660 return 0;
663 struct gimple_opt_pass pass_tree_loop_done =
666 GIMPLE_PASS,
667 "loopdone", /* name */
668 NULL, /* gate */
669 tree_ssa_loop_done, /* execute */
670 NULL, /* sub */
671 NULL, /* next */
672 0, /* static_pass_number */
673 TV_TREE_LOOP_FINI, /* tv_id */
674 PROP_cfg, /* properties_required */
675 0, /* properties_provided */
676 0, /* properties_destroyed */
677 0, /* todo_flags_start */
678 TODO_cleanup_cfg | TODO_dump_func /* todo_flags_finish */