]>
Commit | Line | Data |
---|---|---|
2abae5f1 | 1 | /* Single entry single exit control flow regions. |
818ab71a | 2 | Copyright (C) 2008-2016 Free Software Foundation, Inc. |
2abae5f1 SP |
3 | Contributed by Jan Sjodin <jan.sjodin@amd.com> and |
4 | Sebastian Pop <sebastian.pop@amd.com>. | |
5 | ||
6 | This file is part of GCC. | |
7 | ||
8 | GCC is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 3, or (at your option) | |
11 | any later version. | |
12 | ||
13 | GCC is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with GCC; see the file COPYING3. If not see | |
20 | <http://www.gnu.org/licenses/>. */ | |
21 | ||
22 | #ifndef GCC_SESE_H | |
23 | #define GCC_SESE_H | |
24 | ||
1d198f09 | 25 | typedef hash_map<tree, tree> parameter_rename_map_t; |
65b016eb AK |
26 | typedef hash_map<basic_block, vec<basic_block> > bb_map_t; |
27 | typedef hash_map<tree, vec<tree> > rename_map_t; | |
28 | typedef struct ifsese_s *ifsese; | |
29 | /* First phi is the new codegenerated phi second one is original phi. */ | |
30 | typedef std::pair <gphi *, gphi *> phi_rename; | |
31 | /* First edge is the init edge and second is the back edge w.r.t. a loop. */ | |
32 | typedef std::pair<edge, edge> init_back_edge_pair_t; | |
33 | ||
2abae5f1 SP |
34 | /* A Single Entry, Single Exit region is a part of the CFG delimited |
35 | by two edges. */ | |
bafcb153 | 36 | struct sese_l |
2abae5f1 | 37 | { |
bafcb153 AK |
38 | sese_l (edge e, edge x) : entry (e), exit (x) {} |
39 | ||
bafcb153 AK |
40 | operator bool () const { return entry && exit; } |
41 | ||
bafcb153 AK |
42 | edge entry; |
43 | edge exit; | |
44 | }; | |
45 | ||
46 | /* Get the entry of an sese S. */ | |
47 | ||
48 | static inline basic_block | |
49 | get_entry_bb (sese_l &s) | |
50 | { | |
51 | return s.entry->dest; | |
52 | } | |
53 | ||
54 | /* Get the exit of an sese S. */ | |
55 | ||
56 | static inline basic_block | |
57 | get_exit_bb (sese_l &s) | |
58 | { | |
59 | return s.exit->src; | |
60 | } | |
61 | ||
65b016eb | 62 | /* Returns the index of V where ELEM can be found. -1 Otherwise. */ |
65b016eb AK |
63 | template<typename T> |
64 | int | |
65 | vec_find (const vec<T> &v, const T &elem) | |
66 | { | |
67 | int i; | |
68 | T t; | |
69 | FOR_EACH_VEC_ELT (v, i, t) | |
70 | if (elem == t) | |
71 | return i; | |
72 | return -1; | |
73 | } | |
74 | ||
bafcb153 AK |
75 | /* A helper structure for bookkeeping information about a scop in graphite. */ |
76 | typedef struct sese_info_t | |
77 | { | |
78 | /* The SESE region. */ | |
79 | sese_l region; | |
2abae5f1 SP |
80 | |
81 | /* Parameters used within the SCOP. */ | |
9771b263 | 82 | vec<tree> params; |
2abae5f1 | 83 | |
65b016eb AK |
84 | /* Maps an old name to one or more new names. When there are several new |
85 | names, one has to select the definition corresponding to the immediate | |
86 | dominator. */ | |
87 | rename_map_t *rename_map; | |
88 | ||
1d198f09 AK |
89 | /* Parameters to be renamed. */ |
90 | parameter_rename_map_t *parameter_rename_map; | |
91 | ||
91bf00a9 | 92 | /* Loops completely contained in this SESE. */ |
9771b263 | 93 | vec<loop_p> loop_nest; |
b0b5710c AK |
94 | |
95 | /* Basic blocks contained in this SESE. */ | |
96 | vec<basic_block> bbs; | |
2abae5f1 | 97 | |
65b016eb AK |
98 | /* Copied basic blocks indexed by the original bb. */ |
99 | bb_map_t *copied_bb_map; | |
100 | ||
101 | /* A vector of phi nodes to be updated when all arguments are available. The | |
102 | pair contains first the old_phi and second the new_phi. */ | |
103 | vec<phi_rename> incomplete_phis; | |
104 | ||
105 | /* The condition region generated for this sese. */ | |
106 | ifsese if_region; | |
107 | ||
108 | } *sese_info_p; | |
2abae5f1 | 109 | |
bafcb153 AK |
110 | extern sese_info_p new_sese_info (edge, edge); |
111 | extern void free_sese_info (sese_info_p); | |
112 | extern void sese_insert_phis_for_liveouts (sese_info_p, basic_block, edge, edge); | |
bafcb153 | 113 | extern struct loop *outermost_loop_in_sese (sese_l &, basic_block); |
1cb28772 | 114 | extern tree scalar_evolution_in_region (const sese_l &, loop_p, tree); |
2ecf4eca | 115 | extern bool scev_analyzable_p (tree, sese_l &); |
1cb28772 | 116 | extern bool invariant_in_sese_p_rec (tree, const sese_l &, bool *); |
2abae5f1 | 117 | |
2abae5f1 SP |
118 | /* The number of parameters in REGION. */ |
119 | ||
120 | static inline unsigned | |
bafcb153 | 121 | sese_nb_params (sese_info_p region) |
2abae5f1 | 122 | { |
65b016eb | 123 | return region->params.length (); |
2abae5f1 SP |
124 | } |
125 | ||
126 | /* Checks whether BB is contained in the region delimited by ENTRY and | |
127 | EXIT blocks. */ | |
128 | ||
129 | static inline bool | |
1cb28772 | 130 | bb_in_region (const_basic_block bb, const_basic_block entry, const_basic_block exit) |
2abae5f1 | 131 | { |
a6c764d0 MM |
132 | /* FIXME: PR67842. */ |
133 | #if 0 | |
134 | if (flag_checking) | |
135 | { | |
136 | edge e; | |
137 | edge_iterator ei; | |
138 | ||
139 | /* Check that there are no edges coming in the region: all the | |
140 | predecessors of EXIT are dominated by ENTRY. */ | |
141 | FOR_EACH_EDGE (e, ei, exit->preds) | |
142 | gcc_assert (dominated_by_p (CDI_DOMINATORS, e->src, entry)); | |
143 | } | |
2abae5f1 SP |
144 | #endif |
145 | ||
146 | return dominated_by_p (CDI_DOMINATORS, bb, entry) | |
147 | && !(dominated_by_p (CDI_DOMINATORS, bb, exit) | |
148 | && !dominated_by_p (CDI_DOMINATORS, entry, exit)); | |
149 | } | |
150 | ||
151 | /* Checks whether BB is contained in the region delimited by ENTRY and | |
152 | EXIT blocks. */ | |
153 | ||
154 | static inline bool | |
1cb28772 | 155 | bb_in_sese_p (basic_block bb, const sese_l &r) |
2abae5f1 | 156 | { |
bafcb153 | 157 | return bb_in_region (bb, r.entry->dest, r.exit->dest); |
2abae5f1 SP |
158 | } |
159 | ||
a30e5345 SP |
160 | /* Returns true when STMT is defined in REGION. */ |
161 | ||
162 | static inline bool | |
1cb28772 | 163 | stmt_in_sese_p (gimple *stmt, const sese_l &r) |
a30e5345 SP |
164 | { |
165 | basic_block bb = gimple_bb (stmt); | |
bafcb153 | 166 | return bb && bb_in_sese_p (bb, r); |
a30e5345 SP |
167 | } |
168 | ||
2abae5f1 SP |
169 | /* Returns true when NAME is defined in REGION. */ |
170 | ||
171 | static inline bool | |
1cb28772 | 172 | defined_in_sese_p (tree name, const sese_l &r) |
2abae5f1 | 173 | { |
bafcb153 | 174 | return stmt_in_sese_p (SSA_NAME_DEF_STMT (name), r); |
2abae5f1 SP |
175 | } |
176 | ||
177 | /* Returns true when LOOP is in REGION. */ | |
178 | ||
b8698a0f | 179 | static inline bool |
1cb28772 | 180 | loop_in_sese_p (struct loop *loop, const sese_l ®ion) |
2abae5f1 SP |
181 | { |
182 | return (bb_in_sese_p (loop->header, region) | |
183 | && bb_in_sese_p (loop->latch, region)); | |
184 | } | |
185 | ||
186 | /* Returns the loop depth of LOOP in REGION. The loop depth | |
187 | is the same as the normal loop depth, but limited by a region. | |
188 | ||
189 | Example: | |
190 | ||
191 | loop_0 | |
192 | loop_1 | |
193 | { | |
b8698a0f | 194 | S0 |
2abae5f1 SP |
195 | <- region start |
196 | S1 | |
197 | ||
198 | loop_2 | |
199 | S2 | |
200 | ||
201 | S3 | |
202 | <- region end | |
b8698a0f | 203 | } |
2abae5f1 SP |
204 | |
205 | loop_0 does not exist in the region -> invalid | |
206 | loop_1 exists, but is not completely contained in the region -> depth 0 | |
207 | loop_2 is completely contained -> depth 1 */ | |
208 | ||
209 | static inline unsigned int | |
bafcb153 | 210 | sese_loop_depth (sese_l ®ion, loop_p loop) |
2abae5f1 SP |
211 | { |
212 | unsigned int depth = 0; | |
213 | ||
2abae5f1 SP |
214 | while (loop_in_sese_p (loop, region)) |
215 | { | |
216 | depth++; | |
217 | loop = loop_outer (loop); | |
218 | } | |
219 | ||
220 | return depth; | |
221 | } | |
222 | ||
2abae5f1 SP |
223 | /* A single entry single exit specialized for conditions. */ |
224 | ||
225 | typedef struct ifsese_s { | |
bafcb153 AK |
226 | sese_info_p region; |
227 | sese_info_p true_region; | |
228 | sese_info_p false_region; | |
2abae5f1 SP |
229 | } *ifsese; |
230 | ||
bafcb153 AK |
231 | extern void if_region_set_false_region (ifsese, sese_info_p); |
232 | extern ifsese move_sese_in_condition (sese_info_p); | |
09b574dd | 233 | extern void set_ifsese_condition (ifsese, tree); |
2abae5f1 SP |
234 | extern edge get_true_edge_from_guard_bb (basic_block); |
235 | extern edge get_false_edge_from_guard_bb (basic_block); | |
236 | ||
237 | static inline edge | |
238 | if_region_entry (ifsese if_region) | |
239 | { | |
bafcb153 | 240 | return if_region->region->region.entry; |
2abae5f1 SP |
241 | } |
242 | ||
243 | static inline edge | |
244 | if_region_exit (ifsese if_region) | |
245 | { | |
bafcb153 | 246 | return if_region->region->region.exit; |
2abae5f1 SP |
247 | } |
248 | ||
249 | static inline basic_block | |
250 | if_region_get_condition_block (ifsese if_region) | |
251 | { | |
252 | return if_region_entry (if_region)->dest; | |
2abae5f1 SP |
253 | } |
254 | ||
2abae5f1 SP |
255 | /* Free and compute again all the dominators information. */ |
256 | ||
257 | static inline void | |
258 | recompute_all_dominators (void) | |
259 | { | |
260 | mark_irreducible_loops (); | |
261 | free_dominance_info (CDI_DOMINATORS); | |
2abae5f1 | 262 | calculate_dominance_info (CDI_DOMINATORS); |
7009b073 SP |
263 | |
264 | free_dominance_info (CDI_POST_DOMINATORS); | |
265 | calculate_dominance_info (CDI_POST_DOMINATORS); | |
2abae5f1 SP |
266 | } |
267 | ||
65b016eb AK |
268 | typedef std::pair <gimple *, tree> scalar_use; |
269 | ||
65ef70d6 | 270 | typedef struct gimple_poly_bb |
2abae5f1 SP |
271 | { |
272 | basic_block bb; | |
efa21390 | 273 | struct poly_bb *pbb; |
2abae5f1 SP |
274 | |
275 | /* Lists containing the restrictions of the conditional statements | |
276 | dominating this bb. This bb can only be executed, if all conditions | |
277 | are true. | |
b8698a0f | 278 | |
2abae5f1 | 279 | Example: |
b8698a0f | 280 | |
2abae5f1 SP |
281 | for (i = 0; i <= 20; i++) |
282 | { | |
283 | A | |
b8698a0f | 284 | |
2abae5f1 SP |
285 | if (2i <= 8) |
286 | B | |
287 | } | |
b8698a0f | 288 | |
2abae5f1 | 289 | So for B there is an additional condition (2i <= 8). |
b8698a0f | 290 | |
2abae5f1 SP |
291 | List of COND_EXPR and SWITCH_EXPR. A COND_EXPR is true only if the |
292 | corresponding element in CONDITION_CASES is not NULL_TREE. For a | |
293 | SWITCH_EXPR the corresponding element in CONDITION_CASES is a | |
294 | CASE_LABEL_EXPR. */ | |
355fe088 TS |
295 | vec<gimple *> conditions; |
296 | vec<gimple *> condition_cases; | |
9771b263 | 297 | vec<data_reference_p> data_refs; |
65b016eb AK |
298 | vec<scalar_use> read_scalar_refs; |
299 | vec<tree> write_scalar_refs; | |
65ef70d6 | 300 | } *gimple_poly_bb_p; |
2abae5f1 | 301 | |
efa21390 SP |
302 | #define GBB_BB(GBB) (GBB)->bb |
303 | #define GBB_PBB(GBB) (GBB)->pbb | |
304 | #define GBB_DATA_REFS(GBB) (GBB)->data_refs | |
305 | #define GBB_CONDITIONS(GBB) (GBB)->conditions | |
306 | #define GBB_CONDITION_CASES(GBB) (GBB)->condition_cases | |
2abae5f1 SP |
307 | |
308 | /* Return the innermost loop that contains the basic block GBB. */ | |
309 | ||
310 | static inline struct loop * | |
65ef70d6 | 311 | gbb_loop (gimple_poly_bb_p gbb) |
2abae5f1 SP |
312 | { |
313 | return GBB_BB (gbb)->loop_father; | |
314 | } | |
315 | ||
b8698a0f | 316 | /* Returns the gimple loop, that corresponds to the loop_iterator_INDEX. |
2abae5f1 SP |
317 | If there is no corresponding gimple loop, we return NULL. */ |
318 | ||
319 | static inline loop_p | |
bafcb153 | 320 | gbb_loop_at_index (gimple_poly_bb_p gbb, sese_l ®ion, int index) |
2abae5f1 SP |
321 | { |
322 | loop_p loop = gbb_loop (gbb); | |
323 | int depth = sese_loop_depth (region, loop); | |
324 | ||
325 | while (--depth > index) | |
326 | loop = loop_outer (loop); | |
327 | ||
bafcb153 | 328 | gcc_assert (loop_in_sese_p (loop, region)); |
2abae5f1 SP |
329 | |
330 | return loop; | |
331 | } | |
332 | ||
333 | /* The number of common loops in REGION for GBB1 and GBB2. */ | |
334 | ||
335 | static inline int | |
bafcb153 | 336 | nb_common_loops (sese_l ®ion, gimple_poly_bb_p gbb1, gimple_poly_bb_p gbb2) |
2abae5f1 SP |
337 | { |
338 | loop_p l1 = gbb_loop (gbb1); | |
339 | loop_p l2 = gbb_loop (gbb2); | |
340 | loop_p common = find_common_loop (l1, l2); | |
b8698a0f | 341 | |
2abae5f1 SP |
342 | return sese_loop_depth (region, common); |
343 | } | |
344 | ||
2abae5f1 | 345 | #endif |