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