1 /* Loop optimizations over tree-ssa.
2 Copyright (C) 2003, 2005 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 2, 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 COPYING. If not, write to the Free
18 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
23 #include "coretypes.h"
28 #include "hard-reg-set.h"
29 #include "basic-block.h"
31 #include "diagnostic.h"
32 #include "tree-flow.h"
33 #include "tree-dump.h"
34 #include "tree-pass.h"
38 #include "tree-inline.h"
39 #include "tree-scalar-evolution.h"
41 /* Initializes the loop structures. */
44 tree_loop_optimizer_init (void)
46 loop_optimizer_init (LOOPS_NORMAL
47 | LOOPS_HAVE_RECORDED_EXITS);
51 rewrite_into_loop_closed_ssa (NULL, TODO_update_ssa);
54 /* The loop superpass. */
59 return flag_tree_loop_optimize != 0;
62 struct tree_opt_pass pass_tree_loop =
65 gate_tree_loop, /* gate */
69 0, /* static_pass_number */
70 TV_TREE_LOOP, /* tv_id */
71 PROP_cfg, /* properties_required */
72 0, /* properties_provided */
73 0, /* properties_destroyed */
74 TODO_ggc_collect, /* todo_flags_start */
75 TODO_dump_func | TODO_verify_ssa | TODO_ggc_collect, /* todo_flags_finish */
79 /* Loop optimizer initialization. */
82 tree_ssa_loop_init (void)
84 tree_loop_optimizer_init ();
92 struct tree_opt_pass pass_tree_loop_init =
94 "loopinit", /* name */
96 tree_ssa_loop_init, /* execute */
99 0, /* static_pass_number */
100 TV_TREE_LOOP_INIT, /* tv_id */
101 PROP_cfg, /* properties_required */
102 0, /* properties_provided */
103 0, /* properties_destroyed */
104 0, /* todo_flags_start */
105 TODO_dump_func | TODO_verify_loops, /* todo_flags_finish */
109 /* Loop invariant motion pass. */
112 tree_ssa_loop_im (void)
122 gate_tree_ssa_loop_im (void)
124 return flag_tree_loop_im != 0;
127 struct tree_opt_pass pass_lim =
130 gate_tree_ssa_loop_im, /* gate */
131 tree_ssa_loop_im, /* execute */
134 0, /* static_pass_number */
136 PROP_cfg, /* properties_required */
137 0, /* properties_provided */
138 0, /* properties_destroyed */
139 0, /* todo_flags_start */
140 TODO_dump_func | TODO_verify_loops, /* todo_flags_finish */
144 /* Loop unswitching pass. */
147 tree_ssa_loop_unswitch (void)
152 return tree_ssa_unswitch_loops ();
156 gate_tree_ssa_loop_unswitch (void)
158 return flag_unswitch_loops != 0;
161 struct tree_opt_pass pass_tree_unswitch =
163 "unswitch", /* name */
164 gate_tree_ssa_loop_unswitch, /* gate */
165 tree_ssa_loop_unswitch, /* execute */
168 0, /* static_pass_number */
169 TV_TREE_LOOP_UNSWITCH, /* tv_id */
170 PROP_cfg, /* properties_required */
171 0, /* properties_provided */
172 0, /* properties_destroyed */
173 0, /* todo_flags_start */
174 TODO_dump_func | TODO_verify_loops, /* todo_flags_finish */
178 /* Loop autovectorization. */
181 tree_vectorize (void)
183 return vectorize_loops ();
187 gate_tree_vectorize (void)
189 return flag_tree_vectorize && current_loops;
192 struct tree_opt_pass pass_vectorize =
195 gate_tree_vectorize, /* gate */
196 tree_vectorize, /* execute */
199 0, /* static_pass_number */
200 TV_TREE_VECTORIZATION, /* tv_id */
201 PROP_cfg | PROP_ssa, /* properties_required */
202 0, /* properties_provided */
203 0, /* properties_destroyed */
204 TODO_verify_loops, /* todo_flags_start */
205 TODO_dump_func | TODO_update_ssa, /* todo_flags_finish */
209 /* Loop nest optimizations. */
212 tree_linear_transform (void)
217 linear_transform_loops ();
222 gate_tree_linear_transform (void)
224 return flag_tree_loop_linear != 0;
227 struct tree_opt_pass pass_linear_transform =
230 gate_tree_linear_transform, /* gate */
231 tree_linear_transform, /* execute */
234 0, /* static_pass_number */
235 TV_TREE_LINEAR_TRANSFORM, /* tv_id */
236 PROP_cfg | PROP_ssa, /* properties_required */
237 0, /* properties_provided */
238 0, /* properties_destroyed */
239 0, /* todo_flags_start */
240 TODO_dump_func | TODO_verify_loops, /* todo_flags_finish */
244 /* Canonical induction variable creation pass. */
247 tree_ssa_loop_ivcanon (void)
252 return canonicalize_induction_variables ();
256 gate_tree_ssa_loop_ivcanon (void)
258 return flag_tree_loop_ivcanon != 0;
261 struct tree_opt_pass pass_iv_canon =
263 "ivcanon", /* name */
264 gate_tree_ssa_loop_ivcanon, /* gate */
265 tree_ssa_loop_ivcanon, /* execute */
268 0, /* static_pass_number */
269 TV_TREE_LOOP_IVCANON, /* tv_id */
270 PROP_cfg | PROP_ssa, /* properties_required */
271 0, /* properties_provided */
272 0, /* properties_destroyed */
273 0, /* todo_flags_start */
274 TODO_dump_func | TODO_verify_loops, /* todo_flags_finish */
278 /* Propagation of constants using scev. */
281 gate_scev_const_prop (void)
286 struct tree_opt_pass pass_scev_cprop =
289 gate_scev_const_prop, /* gate */
290 scev_const_prop, /* execute */
293 0, /* static_pass_number */
294 TV_SCEV_CONST, /* tv_id */
295 PROP_cfg | PROP_ssa, /* properties_required */
296 0, /* properties_provided */
297 0, /* properties_destroyed */
298 0, /* todo_flags_start */
299 TODO_dump_func | TODO_cleanup_cfg
300 | TODO_update_ssa_only_virtuals,
301 /* todo_flags_finish */
305 /* Remove empty loops. */
308 tree_ssa_empty_loop (void)
313 return remove_empty_loops ();
316 struct tree_opt_pass pass_empty_loop =
320 tree_ssa_empty_loop, /* execute */
323 0, /* static_pass_number */
324 TV_COMPLETE_UNROLL, /* tv_id */
325 PROP_cfg | PROP_ssa, /* properties_required */
326 0, /* properties_provided */
327 0, /* properties_destroyed */
328 0, /* todo_flags_start */
329 TODO_dump_func | TODO_verify_loops, /* todo_flags_finish */
333 /* Record bounds on numbers of iterations of loops. */
336 tree_ssa_loop_bounds (void)
341 estimate_numbers_of_iterations ();
346 struct tree_opt_pass pass_record_bounds =
350 tree_ssa_loop_bounds, /* execute */
353 0, /* static_pass_number */
354 TV_TREE_LOOP_BOUNDS, /* tv_id */
355 PROP_cfg | PROP_ssa, /* properties_required */
356 0, /* properties_provided */
357 0, /* properties_destroyed */
358 0, /* todo_flags_start */
359 0, /* todo_flags_finish */
363 /* Complete unrolling of loops. */
366 tree_complete_unroll (void)
371 return tree_unroll_loops_completely (flag_unroll_loops
377 gate_tree_complete_unroll (void)
382 struct tree_opt_pass pass_complete_unroll =
384 "cunroll", /* name */
385 gate_tree_complete_unroll, /* gate */
386 tree_complete_unroll, /* execute */
389 0, /* static_pass_number */
390 TV_COMPLETE_UNROLL, /* tv_id */
391 PROP_cfg | PROP_ssa, /* properties_required */
392 0, /* properties_provided */
393 0, /* properties_destroyed */
394 0, /* todo_flags_start */
395 TODO_dump_func | TODO_verify_loops, /* todo_flags_finish */
402 tree_ssa_loop_prefetch (void)
407 return tree_ssa_prefetch_arrays ();
411 gate_tree_ssa_loop_prefetch (void)
413 return flag_prefetch_loop_arrays != 0;
416 struct tree_opt_pass pass_loop_prefetch =
418 "aprefetch", /* name */
419 gate_tree_ssa_loop_prefetch, /* gate */
420 tree_ssa_loop_prefetch, /* execute */
423 0, /* static_pass_number */
424 TV_TREE_PREFETCH, /* tv_id */
425 PROP_cfg | PROP_ssa, /* properties_required */
426 0, /* properties_provided */
427 0, /* properties_destroyed */
428 0, /* todo_flags_start */
429 TODO_dump_func | TODO_verify_loops, /* todo_flags_finish */
433 /* Induction variable optimizations. */
436 tree_ssa_loop_ivopts (void)
441 tree_ssa_iv_optimize ();
446 gate_tree_ssa_loop_ivopts (void)
448 return flag_ivopts != 0;
451 struct tree_opt_pass pass_iv_optimize =
454 gate_tree_ssa_loop_ivopts, /* gate */
455 tree_ssa_loop_ivopts, /* execute */
458 0, /* static_pass_number */
459 TV_TREE_LOOP_IVOPTS, /* tv_id */
460 PROP_cfg | PROP_ssa, /* properties_required */
461 0, /* properties_provided */
462 0, /* properties_destroyed */
463 0, /* todo_flags_start */
466 | TODO_update_ssa, /* todo_flags_finish */
470 /* Loop optimizer finalization. */
473 tree_ssa_loop_done (void)
478 free_numbers_of_iterations_estimates ();
480 loop_optimizer_finalize ();
484 struct tree_opt_pass pass_tree_loop_done =
486 "loopdone", /* name */
488 tree_ssa_loop_done, /* execute */
491 0, /* static_pass_number */
492 TV_TREE_LOOP_FINI, /* tv_id */
493 PROP_cfg, /* properties_required */
494 0, /* properties_provided */
495 0, /* properties_destroyed */
496 0, /* todo_flags_start */
497 TODO_cleanup_cfg | TODO_dump_func, /* todo_flags_finish */