1 /* Loop optimizations over tree-ssa.
2 Copyright (C) 2003 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, 59 Temple Place - Suite 330, 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;
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 /* Creation of preheaders may create redundant phi nodes if the loop is
57 entered by more than one edge, but the initial value of the induction
58 variable is the same on all of them. */
59 kill_redundant_phi_nodes ();
60 rewrite_into_ssa (false);
61 bitmap_clear (vars_to_rename);
63 rewrite_into_loop_closed_ssa ();
64 #ifdef ENABLE_CHECKING
65 verify_loop_closed_ssa ();
71 /* The loop superpass. */
76 return flag_tree_loop_optimize != 0;
79 struct tree_opt_pass pass_loop =
86 0, /* static_pass_number */
87 TV_TREE_LOOP, /* tv_id */
88 PROP_cfg, /* properties_required */
89 0, /* properties_provided */
90 0, /* properties_destroyed */
91 TODO_ggc_collect, /* todo_flags_start */
92 TODO_dump_func | TODO_verify_ssa | TODO_ggc_collect /* todo_flags_finish */
95 /* Loop optimizer initialization. */
98 tree_ssa_loop_init (void)
100 current_loops = tree_loop_optimizer_init (dump_file);
104 /* Find the loops that are exited just through a single edge. */
105 mark_single_exit_loops (current_loops);
107 scev_initialize (current_loops);
110 struct tree_opt_pass pass_loop_init =
112 "loopinit", /* name */
114 tree_ssa_loop_init, /* execute */
117 0, /* static_pass_number */
119 PROP_cfg, /* properties_required */
120 0, /* properties_provided */
121 0, /* properties_destroyed */
122 0, /* todo_flags_start */
123 TODO_dump_func /* todo_flags_finish */
126 /* Loop invariant motion pass. */
129 tree_ssa_loop_im (void)
134 tree_ssa_lim (current_loops);
138 gate_tree_ssa_loop_im (void)
140 return flag_tree_loop_im != 0;
143 struct tree_opt_pass pass_lim =
146 gate_tree_ssa_loop_im, /* gate */
147 tree_ssa_loop_im, /* execute */
150 0, /* static_pass_number */
152 PROP_cfg, /* properties_required */
153 0, /* properties_provided */
154 0, /* properties_destroyed */
155 0, /* todo_flags_start */
156 TODO_dump_func /* todo_flags_finish */
159 /* Loop autovectorization. */
162 tree_vectorize (void)
167 bitmap_clear (vars_to_rename);
168 vectorize_loops (current_loops);
172 gate_tree_vectorize (void)
174 return flag_tree_vectorize != 0;
177 struct tree_opt_pass pass_vectorize =
180 gate_tree_vectorize, /* gate */
181 tree_vectorize, /* execute */
184 0, /* static_pass_number */
185 TV_TREE_VECTORIZATION, /* tv_id */
186 PROP_cfg | PROP_ssa, /* properties_required */
187 0, /* properties_provided */
188 0, /* properties_destroyed */
189 0, /* todo_flags_start */
190 TODO_dump_func /* todo_flags_finish */
193 /* Canonical induction variable creation pass. */
196 tree_ssa_loop_ivcanon (void)
201 canonicalize_induction_variables (current_loops);
205 gate_tree_ssa_loop_ivcanon (void)
207 return flag_tree_loop_ivcanon != 0;
210 struct tree_opt_pass pass_iv_canon =
212 "ivcanon", /* name */
213 gate_tree_ssa_loop_ivcanon, /* gate */
214 tree_ssa_loop_ivcanon, /* execute */
217 0, /* static_pass_number */
218 TV_TREE_LOOP_IVCANON, /* tv_id */
219 PROP_cfg | PROP_ssa, /* properties_required */
220 0, /* properties_provided */
221 0, /* properties_destroyed */
222 0, /* todo_flags_start */
223 TODO_dump_func /* todo_flags_finish */
226 /* Complete unrolling of loops. */
229 tree_complete_unroll (void)
234 tree_unroll_loops_completely (current_loops);
238 gate_tree_complete_unroll (void)
240 return flag_unroll_loops != 0;
243 struct tree_opt_pass pass_complete_unroll =
245 "cunroll", /* name */
246 gate_tree_complete_unroll, /* gate */
247 tree_complete_unroll, /* execute */
250 0, /* static_pass_number */
251 TV_COMPLETE_UNROLL, /* tv_id */
252 PROP_cfg | PROP_ssa, /* properties_required */
253 0, /* properties_provided */
254 0, /* properties_destroyed */
255 0, /* todo_flags_start */
256 TODO_dump_func /* todo_flags_finish */
259 /* Induction variable optimizations. */
262 tree_ssa_loop_ivopts (void)
267 tree_ssa_iv_optimize (current_loops);
271 gate_tree_ssa_loop_ivopts (void)
273 return flag_ivopts != 0;
276 struct tree_opt_pass pass_iv_optimize =
279 gate_tree_ssa_loop_ivopts, /* gate */
280 tree_ssa_loop_ivopts, /* execute */
283 0, /* static_pass_number */
284 TV_TREE_LOOP_IVOPTS, /* tv_id */
285 PROP_cfg | PROP_ssa, /* properties_required */
286 0, /* properties_provided */
287 0, /* properties_destroyed */
288 0, /* todo_flags_start */
289 TODO_dump_func /* todo_flags_finish */
292 /* Loop optimizer finalization. */
295 tree_ssa_loop_done (void)
300 #ifdef ENABLE_CHECKING
301 verify_loop_closed_ssa ();
304 free_numbers_of_iterations_estimates (current_loops);
306 loop_optimizer_finalize (current_loops,
307 (dump_flags & TDF_DETAILS ? dump_file : NULL));
308 current_loops = NULL;
312 struct tree_opt_pass pass_loop_done =
314 "loopdone", /* name */
316 tree_ssa_loop_done, /* execute */
319 0, /* static_pass_number */
321 PROP_cfg, /* properties_required */
322 0, /* properties_provided */
323 0, /* properties_destroyed */
324 0, /* todo_flags_start */
325 TODO_dump_func /* todo_flags_finish */