PR c++/16115
[official-gcc.git] / gcc / tree-ssa-loop.c
blob816be1526af7203ce58ebcf00af3e10e56af875f
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
9 later version.
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
14 for more details.
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
19 02111-1307, USA. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "tree.h"
26 #include "rtl.h"
27 #include "tm_p.h"
28 #include "hard-reg-set.h"
29 #include "basic-block.h"
30 #include "output.h"
31 #include "diagnostic.h"
32 #include "basic-block.h"
33 #include "tree-flow.h"
34 #include "tree-dump.h"
35 #include "tree-pass.h"
36 #include "timevar.h"
37 #include "cfgloop.h"
38 #include "flags.h"
39 #include "tree-inline.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. */
48 static struct loops *
49 tree_loop_optimizer_init (FILE *dump)
51 struct loops *loops = loop_optimizer_init (dump);
53 if (!loops)
54 return NULL;
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 return loops;
66 /* The loop superpass. */
68 static bool
69 gate_loop (void)
71 return flag_tree_loop_optimize != 0;
74 struct tree_opt_pass pass_loop =
76 "loop", /* name */
77 gate_loop, /* gate */
78 NULL, /* execute */
79 NULL, /* sub */
80 NULL, /* next */
81 0, /* static_pass_number */
82 TV_TREE_LOOP, /* tv_id */
83 PROP_cfg, /* properties_required */
84 0, /* properties_provided */
85 0, /* properties_destroyed */
86 TODO_ggc_collect, /* todo_flags_start */
87 TODO_dump_func | TODO_verify_ssa | TODO_ggc_collect /* todo_flags_finish */
90 /* Loop optimizer initialization. */
92 static void
93 tree_ssa_loop_init (void)
95 current_loops = tree_loop_optimizer_init (dump_file);
98 struct tree_opt_pass pass_loop_init =
100 "loopinit", /* name */
101 NULL, /* gate */
102 tree_ssa_loop_init, /* execute */
103 NULL, /* sub */
104 NULL, /* next */
105 0, /* static_pass_number */
106 0, /* tv_id */
107 PROP_cfg, /* properties_required */
108 0, /* properties_provided */
109 0, /* properties_destroyed */
110 0, /* todo_flags_start */
111 0 /* todo_flags_finish */
114 /* Loop invariant motion pass. */
116 static void
117 tree_ssa_loop_im (void)
119 if (!current_loops)
120 return;
122 tree_ssa_lim (current_loops);
125 static bool
126 gate_tree_ssa_loop_im (void)
128 return flag_tree_lim != 0;
131 struct tree_opt_pass pass_lim =
133 "lim", /* name */
134 gate_tree_ssa_loop_im, /* gate */
135 tree_ssa_loop_im, /* execute */
136 NULL, /* sub */
137 NULL, /* next */
138 0, /* static_pass_number */
139 TV_LIM, /* tv_id */
140 PROP_cfg, /* properties_required */
141 0, /* properties_provided */
142 0, /* properties_destroyed */
143 0, /* todo_flags_start */
144 TODO_dump_func /* todo_flags_finish */
147 /* Loop optimizer finalization. */
149 static void
150 tree_ssa_loop_done (void)
152 if (!current_loops)
153 return;
155 loop_optimizer_finalize (current_loops,
156 (dump_flags & TDF_DETAILS ? dump_file : NULL));
157 current_loops = NULL;
158 cleanup_tree_cfg ();
161 struct tree_opt_pass pass_loop_done =
163 "loopdone", /* name */
164 NULL, /* gate */
165 tree_ssa_loop_done, /* execute */
166 NULL, /* sub */
167 NULL, /* next */
168 0, /* static_pass_number */
169 0, /* tv_id */
170 PROP_cfg, /* properties_required */
171 0, /* properties_provided */
172 0, /* properties_destroyed */
173 0, /* todo_flags_start */
174 0 /* todo_flags_finish */