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 /* The loop tree currently optimized. */
43 struct loops *current_loops = NULL;
45 /* Initializes the loop structures. DUMP is the file to that the details
46 about the analysis should be dumped. */
49 tree_loop_optimizer_init (FILE *dump)
51 struct loops *loops = loop_optimizer_init (dump);
56 rewrite_into_loop_closed_ssa (NULL, TODO_update_ssa);
61 /* The loop superpass. */
66 return flag_tree_loop_optimize != 0;
69 struct tree_opt_pass pass_tree_loop =
72 gate_tree_loop, /* gate */
76 0, /* static_pass_number */
77 TV_TREE_LOOP, /* tv_id */
78 PROP_cfg, /* properties_required */
79 0, /* properties_provided */
80 0, /* properties_destroyed */
81 TODO_ggc_collect, /* todo_flags_start */
82 TODO_dump_func | TODO_verify_ssa | TODO_ggc_collect, /* todo_flags_finish */
86 /* Loop optimizer initialization. */
89 tree_ssa_loop_init (void)
91 current_loops = tree_loop_optimizer_init (dump_file);
95 /* Find the loops that are exited just through a single edge. */
96 mark_single_exit_loops (current_loops);
98 scev_initialize (current_loops);
101 struct tree_opt_pass pass_tree_loop_init =
103 "loopinit", /* name */
105 tree_ssa_loop_init, /* execute */
108 0, /* static_pass_number */
109 TV_TREE_LOOP_INIT, /* tv_id */
110 PROP_cfg, /* properties_required */
111 0, /* properties_provided */
112 0, /* properties_destroyed */
113 0, /* todo_flags_start */
114 TODO_dump_func | TODO_verify_loops, /* todo_flags_finish */
118 /* Loop invariant motion pass. */
121 tree_ssa_loop_im (void)
126 tree_ssa_lim (current_loops);
130 gate_tree_ssa_loop_im (void)
132 return flag_tree_loop_im != 0;
135 struct tree_opt_pass pass_lim =
138 gate_tree_ssa_loop_im, /* gate */
139 tree_ssa_loop_im, /* execute */
142 0, /* static_pass_number */
144 PROP_cfg, /* properties_required */
145 0, /* properties_provided */
146 0, /* properties_destroyed */
147 0, /* todo_flags_start */
148 TODO_dump_func | TODO_verify_loops, /* todo_flags_finish */
152 /* Loop unswitching pass. */
155 tree_ssa_loop_unswitch (void)
160 tree_ssa_unswitch_loops (current_loops);
164 gate_tree_ssa_loop_unswitch (void)
166 return flag_unswitch_loops != 0;
169 struct tree_opt_pass pass_tree_unswitch =
171 "unswitch", /* name */
172 gate_tree_ssa_loop_unswitch, /* gate */
173 tree_ssa_loop_unswitch, /* execute */
176 0, /* static_pass_number */
177 TV_TREE_LOOP_UNSWITCH, /* tv_id */
178 PROP_cfg, /* properties_required */
179 0, /* properties_provided */
180 0, /* properties_destroyed */
181 0, /* todo_flags_start */
182 TODO_dump_func | TODO_verify_loops, /* todo_flags_finish */
186 /* Loop autovectorization. */
189 tree_vectorize (void)
191 vectorize_loops (current_loops);
195 gate_tree_vectorize (void)
197 return flag_tree_vectorize && current_loops;
200 struct tree_opt_pass pass_vectorize =
203 gate_tree_vectorize, /* gate */
204 tree_vectorize, /* execute */
207 0, /* static_pass_number */
208 TV_TREE_VECTORIZATION, /* tv_id */
209 PROP_cfg | PROP_ssa, /* properties_required */
210 0, /* properties_provided */
211 0, /* properties_destroyed */
212 TODO_verify_loops, /* todo_flags_start */
213 TODO_dump_func | TODO_update_ssa, /* todo_flags_finish */
217 /* Loop nest optimizations. */
220 tree_linear_transform (void)
225 linear_transform_loops (current_loops);
229 gate_tree_linear_transform (void)
231 return flag_tree_loop_linear != 0;
234 struct tree_opt_pass pass_linear_transform =
237 gate_tree_linear_transform, /* gate */
238 tree_linear_transform, /* execute */
241 0, /* static_pass_number */
242 TV_TREE_LINEAR_TRANSFORM, /* tv_id */
243 PROP_cfg | PROP_ssa, /* properties_required */
244 0, /* properties_provided */
245 0, /* properties_destroyed */
246 0, /* todo_flags_start */
247 TODO_dump_func | TODO_verify_loops, /* todo_flags_finish */
251 /* Canonical induction variable creation pass. */
254 tree_ssa_loop_ivcanon (void)
259 canonicalize_induction_variables (current_loops);
263 gate_tree_ssa_loop_ivcanon (void)
265 return flag_tree_loop_ivcanon != 0;
268 struct tree_opt_pass pass_iv_canon =
270 "ivcanon", /* name */
271 gate_tree_ssa_loop_ivcanon, /* gate */
272 tree_ssa_loop_ivcanon, /* execute */
275 0, /* static_pass_number */
276 TV_TREE_LOOP_IVCANON, /* tv_id */
277 PROP_cfg | PROP_ssa, /* properties_required */
278 0, /* properties_provided */
279 0, /* properties_destroyed */
280 0, /* todo_flags_start */
281 TODO_dump_func | TODO_verify_loops, /* todo_flags_finish */
285 /* Propagation of constants using scev. */
288 gate_scev_const_prop (void)
293 struct tree_opt_pass pass_scev_cprop =
296 gate_scev_const_prop, /* gate */
297 scev_const_prop, /* execute */
300 0, /* static_pass_number */
301 TV_SCEV_CONST, /* tv_id */
302 PROP_cfg | PROP_ssa, /* properties_required */
303 0, /* properties_provided */
304 0, /* properties_destroyed */
305 0, /* todo_flags_start */
306 TODO_dump_func | TODO_cleanup_cfg
307 | TODO_update_ssa_only_virtuals,
308 /* todo_flags_finish */
312 /* Remove empty loops. */
315 tree_ssa_empty_loop (void)
320 remove_empty_loops (current_loops);
323 struct tree_opt_pass pass_empty_loop =
327 tree_ssa_empty_loop, /* execute */
330 0, /* static_pass_number */
331 TV_COMPLETE_UNROLL, /* tv_id */
332 PROP_cfg | PROP_ssa, /* properties_required */
333 0, /* properties_provided */
334 0, /* properties_destroyed */
335 0, /* todo_flags_start */
336 TODO_dump_func | TODO_verify_loops, /* todo_flags_finish */
340 /* Record bounds on numbers of iterations of loops. */
343 tree_ssa_loop_bounds (void)
348 estimate_numbers_of_iterations (current_loops);
352 struct tree_opt_pass pass_record_bounds =
356 tree_ssa_loop_bounds, /* execute */
359 0, /* static_pass_number */
360 TV_TREE_LOOP_BOUNDS, /* tv_id */
361 PROP_cfg | PROP_ssa, /* properties_required */
362 0, /* properties_provided */
363 0, /* properties_destroyed */
364 0, /* todo_flags_start */
365 0, /* todo_flags_finish */
369 /* Complete unrolling of loops. */
372 tree_complete_unroll (void)
377 tree_unroll_loops_completely (current_loops,
384 gate_tree_complete_unroll (void)
389 struct tree_opt_pass pass_complete_unroll =
391 "cunroll", /* name */
392 gate_tree_complete_unroll, /* gate */
393 tree_complete_unroll, /* execute */
396 0, /* static_pass_number */
397 TV_COMPLETE_UNROLL, /* tv_id */
398 PROP_cfg | PROP_ssa, /* properties_required */
399 0, /* properties_provided */
400 0, /* properties_destroyed */
401 0, /* todo_flags_start */
402 TODO_dump_func | TODO_verify_loops, /* todo_flags_finish */
406 /* Induction variable optimizations. */
409 tree_ssa_loop_ivopts (void)
414 tree_ssa_iv_optimize (current_loops);
418 gate_tree_ssa_loop_ivopts (void)
420 return flag_ivopts != 0;
423 struct tree_opt_pass pass_iv_optimize =
426 gate_tree_ssa_loop_ivopts, /* gate */
427 tree_ssa_loop_ivopts, /* execute */
430 0, /* static_pass_number */
431 TV_TREE_LOOP_IVOPTS, /* tv_id */
432 PROP_cfg | PROP_ssa, /* properties_required */
433 0, /* properties_provided */
434 0, /* properties_destroyed */
435 0, /* todo_flags_start */
436 TODO_dump_func | TODO_verify_loops, /* todo_flags_finish */
440 /* Loop optimizer finalization. */
443 tree_ssa_loop_done (void)
448 free_numbers_of_iterations_estimates (current_loops);
450 loop_optimizer_finalize (current_loops,
451 (dump_flags & TDF_DETAILS ? dump_file : NULL));
452 current_loops = NULL;
455 struct tree_opt_pass pass_tree_loop_done =
457 "loopdone", /* name */
459 tree_ssa_loop_done, /* execute */
462 0, /* static_pass_number */
463 TV_TREE_LOOP_FINI, /* tv_id */
464 PROP_cfg, /* properties_required */
465 0, /* properties_provided */
466 0, /* properties_destroyed */
467 0, /* todo_flags_start */
468 TODO_cleanup_cfg | TODO_dump_func, /* todo_flags_finish */