]>
Commit | Line | Data |
---|---|---|
2abae5f1 | 1 | /* Single entry single exit control flow regions. |
5624e564 | 2 | Copyright (C) 2008-2015 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 | ||
74032f47 AK |
25 | typedef hash_map<tree, tree> parameter_rename_map_t; |
26 | ||
2abae5f1 SP |
27 | /* A Single Entry, Single Exit region is a part of the CFG delimited |
28 | by two edges. */ | |
29 | typedef struct sese_s | |
30 | { | |
31 | /* Single ENTRY and single EXIT from the SESE region. */ | |
32 | edge entry, exit; | |
33 | ||
34 | /* Parameters used within the SCOP. */ | |
9771b263 | 35 | vec<tree> params; |
2abae5f1 | 36 | |
74032f47 AK |
37 | /* Parameters to be renamed. */ |
38 | parameter_rename_map_t *parameter_rename_map; | |
39 | ||
2abae5f1 SP |
40 | /* Loops completely contained in the SCOP. */ |
41 | bitmap loops; | |
9771b263 | 42 | vec<loop_p> loop_nest; |
2abae5f1 SP |
43 | |
44 | /* Are we allowed to add more params? This is for debugging purpose. We | |
45 | can only add new params before generating the bb domains, otherwise they | |
46 | become invalid. */ | |
47 | bool add_params; | |
48 | } *sese; | |
49 | ||
50 | #define SESE_ENTRY(S) (S->entry) | |
51 | #define SESE_ENTRY_BB(S) (S->entry->dest) | |
52 | #define SESE_EXIT(S) (S->exit) | |
53 | #define SESE_EXIT_BB(S) (S->exit->dest) | |
54 | #define SESE_PARAMS(S) (S->params) | |
2abae5f1 SP |
55 | #define SESE_LOOPS(S) (S->loops) |
56 | #define SESE_LOOP_NEST(S) (S->loop_nest) | |
57 | #define SESE_ADD_PARAMS(S) (S->add_params) | |
58 | ||
59 | extern sese new_sese (edge, edge); | |
60 | extern void free_sese (sese); | |
61 | extern void sese_insert_phis_for_liveouts (sese, basic_block, edge, edge); | |
2abae5f1 | 62 | extern void build_sese_loop_nests (sese); |
2e286fd2 | 63 | extern edge copy_bb_and_scalar_dependences (basic_block, sese, edge, |
9771b263 | 64 | vec<tree> , bool *); |
2abae5f1 | 65 | extern struct loop *outermost_loop_in_sese (sese, basic_block); |
2abae5f1 | 66 | extern tree scalar_evolution_in_region (sese, loop_p, tree); |
d5b5a232 | 67 | extern bool invariant_in_sese_p_rec (tree, sese); |
2abae5f1 SP |
68 | |
69 | /* Check that SESE contains LOOP. */ | |
70 | ||
71 | static inline bool | |
72 | sese_contains_loop (sese sese, struct loop *loop) | |
73 | { | |
74 | return bitmap_bit_p (SESE_LOOPS (sese), loop->num); | |
75 | } | |
76 | ||
77 | /* The number of parameters in REGION. */ | |
78 | ||
79 | static inline unsigned | |
80 | sese_nb_params (sese region) | |
81 | { | |
9771b263 | 82 | return SESE_PARAMS (region).length (); |
2abae5f1 SP |
83 | } |
84 | ||
85 | /* Checks whether BB is contained in the region delimited by ENTRY and | |
86 | EXIT blocks. */ | |
87 | ||
88 | static inline bool | |
89 | bb_in_region (basic_block bb, basic_block entry, basic_block exit) | |
90 | { | |
91 | #ifdef ENABLE_CHECKING | |
92 | { | |
93 | edge e; | |
94 | edge_iterator ei; | |
95 | ||
96 | /* Check that there are no edges coming in the region: all the | |
97 | predecessors of EXIT are dominated by ENTRY. */ | |
98 | FOR_EACH_EDGE (e, ei, exit->preds) | |
99 | dominated_by_p (CDI_DOMINATORS, e->src, entry); | |
2abae5f1 SP |
100 | } |
101 | #endif | |
102 | ||
103 | return dominated_by_p (CDI_DOMINATORS, bb, entry) | |
104 | && !(dominated_by_p (CDI_DOMINATORS, bb, exit) | |
105 | && !dominated_by_p (CDI_DOMINATORS, entry, exit)); | |
106 | } | |
107 | ||
108 | /* Checks whether BB is contained in the region delimited by ENTRY and | |
109 | EXIT blocks. */ | |
110 | ||
111 | static inline bool | |
112 | bb_in_sese_p (basic_block bb, sese region) | |
113 | { | |
114 | basic_block entry = SESE_ENTRY_BB (region); | |
115 | basic_block exit = SESE_EXIT_BB (region); | |
116 | ||
117 | return bb_in_region (bb, entry, exit); | |
118 | } | |
119 | ||
a30e5345 SP |
120 | /* Returns true when STMT is defined in REGION. */ |
121 | ||
122 | static inline bool | |
355fe088 | 123 | stmt_in_sese_p (gimple *stmt, sese region) |
a30e5345 SP |
124 | { |
125 | basic_block bb = gimple_bb (stmt); | |
126 | return bb && bb_in_sese_p (bb, region); | |
127 | } | |
128 | ||
2abae5f1 SP |
129 | /* Returns true when NAME is defined in REGION. */ |
130 | ||
131 | static inline bool | |
132 | defined_in_sese_p (tree name, sese region) | |
133 | { | |
355fe088 | 134 | gimple *stmt = SSA_NAME_DEF_STMT (name); |
a30e5345 | 135 | return stmt_in_sese_p (stmt, region); |
2abae5f1 SP |
136 | } |
137 | ||
138 | /* Returns true when LOOP is in REGION. */ | |
139 | ||
b8698a0f | 140 | static inline bool |
2abae5f1 SP |
141 | loop_in_sese_p (struct loop *loop, sese region) |
142 | { | |
143 | return (bb_in_sese_p (loop->header, region) | |
144 | && bb_in_sese_p (loop->latch, region)); | |
145 | } | |
146 | ||
147 | /* Returns the loop depth of LOOP in REGION. The loop depth | |
148 | is the same as the normal loop depth, but limited by a region. | |
149 | ||
150 | Example: | |
151 | ||
152 | loop_0 | |
153 | loop_1 | |
154 | { | |
b8698a0f | 155 | S0 |
2abae5f1 SP |
156 | <- region start |
157 | S1 | |
158 | ||
159 | loop_2 | |
160 | S2 | |
161 | ||
162 | S3 | |
163 | <- region end | |
b8698a0f | 164 | } |
2abae5f1 SP |
165 | |
166 | loop_0 does not exist in the region -> invalid | |
167 | loop_1 exists, but is not completely contained in the region -> depth 0 | |
168 | loop_2 is completely contained -> depth 1 */ | |
169 | ||
170 | static inline unsigned int | |
171 | sese_loop_depth (sese region, loop_p loop) | |
172 | { | |
173 | unsigned int depth = 0; | |
174 | ||
175 | gcc_assert ((!loop_in_sese_p (loop, region) | |
176 | && (SESE_ENTRY_BB (region)->loop_father == loop | |
177 | || SESE_EXIT (region)->src->loop_father == loop)) | |
178 | || loop_in_sese_p (loop, region)); | |
179 | ||
180 | while (loop_in_sese_p (loop, region)) | |
181 | { | |
182 | depth++; | |
183 | loop = loop_outer (loop); | |
184 | } | |
185 | ||
186 | return depth; | |
187 | } | |
188 | ||
a0dd1440 SP |
189 | /* Splits BB to make a single entry single exit region. */ |
190 | ||
191 | static inline sese | |
192 | split_region_for_bb (basic_block bb) | |
193 | { | |
194 | edge entry, exit; | |
195 | ||
196 | if (single_pred_p (bb)) | |
197 | entry = single_pred_edge (bb); | |
198 | else | |
199 | { | |
200 | entry = split_block_after_labels (bb); | |
201 | bb = single_succ (bb); | |
202 | } | |
203 | ||
204 | if (single_succ_p (bb)) | |
205 | exit = single_succ_edge (bb); | |
206 | else | |
207 | { | |
208 | gimple_stmt_iterator gsi = gsi_last_bb (bb); | |
209 | gsi_prev (&gsi); | |
210 | exit = split_block (bb, gsi_stmt (gsi)); | |
211 | } | |
212 | ||
213 | return new_sese (entry, exit); | |
214 | } | |
215 | ||
2abae5f1 SP |
216 | /* Returns the block preceding the entry of a SESE. */ |
217 | ||
218 | static inline basic_block | |
219 | block_before_sese (sese sese) | |
220 | { | |
221 | return SESE_ENTRY (sese)->src; | |
222 | } | |
223 | ||
2abae5f1 SP |
224 | \f |
225 | ||
226 | /* A single entry single exit specialized for conditions. */ | |
227 | ||
228 | typedef struct ifsese_s { | |
229 | sese region; | |
230 | sese true_region; | |
231 | sese false_region; | |
232 | } *ifsese; | |
233 | ||
234 | extern void if_region_set_false_region (ifsese, sese); | |
2abae5f1 SP |
235 | extern ifsese move_sese_in_condition (sese); |
236 | extern edge get_true_edge_from_guard_bb (basic_block); | |
237 | extern edge get_false_edge_from_guard_bb (basic_block); | |
3c7c0158 | 238 | extern void set_ifsese_condition (ifsese, tree); |
2abae5f1 SP |
239 | |
240 | static inline edge | |
241 | if_region_entry (ifsese if_region) | |
242 | { | |
243 | return SESE_ENTRY (if_region->region); | |
244 | } | |
245 | ||
246 | static inline edge | |
247 | if_region_exit (ifsese if_region) | |
248 | { | |
249 | return SESE_EXIT (if_region->region); | |
250 | } | |
251 | ||
252 | static inline basic_block | |
253 | if_region_get_condition_block (ifsese if_region) | |
254 | { | |
255 | return if_region_entry (if_region)->dest; | |
2abae5f1 SP |
256 | } |
257 | ||
2abae5f1 SP |
258 | /* Free and compute again all the dominators information. */ |
259 | ||
260 | static inline void | |
261 | recompute_all_dominators (void) | |
262 | { | |
263 | mark_irreducible_loops (); | |
264 | free_dominance_info (CDI_DOMINATORS); | |
2abae5f1 | 265 | calculate_dominance_info (CDI_DOMINATORS); |
2abae5f1 SP |
266 | } |
267 | ||
268 | typedef struct gimple_bb | |
269 | { | |
270 | basic_block bb; | |
efa21390 | 271 | struct poly_bb *pbb; |
2abae5f1 SP |
272 | |
273 | /* Lists containing the restrictions of the conditional statements | |
274 | dominating this bb. This bb can only be executed, if all conditions | |
275 | are true. | |
b8698a0f | 276 | |
2abae5f1 | 277 | Example: |
b8698a0f | 278 | |
2abae5f1 SP |
279 | for (i = 0; i <= 20; i++) |
280 | { | |
281 | A | |
b8698a0f | 282 | |
2abae5f1 SP |
283 | if (2i <= 8) |
284 | B | |
285 | } | |
b8698a0f | 286 | |
2abae5f1 | 287 | So for B there is an additional condition (2i <= 8). |
b8698a0f | 288 | |
2abae5f1 SP |
289 | List of COND_EXPR and SWITCH_EXPR. A COND_EXPR is true only if the |
290 | corresponding element in CONDITION_CASES is not NULL_TREE. For a | |
291 | SWITCH_EXPR the corresponding element in CONDITION_CASES is a | |
292 | CASE_LABEL_EXPR. */ | |
355fe088 TS |
293 | vec<gimple *> conditions; |
294 | vec<gimple *> condition_cases; | |
9771b263 | 295 | vec<data_reference_p> data_refs; |
2abae5f1 SP |
296 | } *gimple_bb_p; |
297 | ||
efa21390 SP |
298 | #define GBB_BB(GBB) (GBB)->bb |
299 | #define GBB_PBB(GBB) (GBB)->pbb | |
300 | #define GBB_DATA_REFS(GBB) (GBB)->data_refs | |
301 | #define GBB_CONDITIONS(GBB) (GBB)->conditions | |
302 | #define GBB_CONDITION_CASES(GBB) (GBB)->condition_cases | |
2abae5f1 SP |
303 | |
304 | /* Return the innermost loop that contains the basic block GBB. */ | |
305 | ||
306 | static inline struct loop * | |
307 | gbb_loop (struct gimple_bb *gbb) | |
308 | { | |
309 | return GBB_BB (gbb)->loop_father; | |
310 | } | |
311 | ||
b8698a0f | 312 | /* Returns the gimple loop, that corresponds to the loop_iterator_INDEX. |
2abae5f1 SP |
313 | If there is no corresponding gimple loop, we return NULL. */ |
314 | ||
315 | static inline loop_p | |
316 | gbb_loop_at_index (gimple_bb_p gbb, sese region, int index) | |
317 | { | |
318 | loop_p loop = gbb_loop (gbb); | |
319 | int depth = sese_loop_depth (region, loop); | |
320 | ||
321 | while (--depth > index) | |
322 | loop = loop_outer (loop); | |
323 | ||
324 | gcc_assert (sese_contains_loop (region, loop)); | |
325 | ||
326 | return loop; | |
327 | } | |
328 | ||
329 | /* The number of common loops in REGION for GBB1 and GBB2. */ | |
330 | ||
331 | static inline int | |
332 | nb_common_loops (sese region, gimple_bb_p gbb1, gimple_bb_p gbb2) | |
333 | { | |
334 | loop_p l1 = gbb_loop (gbb1); | |
335 | loop_p l2 = gbb_loop (gbb2); | |
336 | loop_p common = find_common_loop (l1, l2); | |
b8698a0f | 337 | |
2abae5f1 SP |
338 | return sese_loop_depth (region, common); |
339 | } | |
340 | ||
2e286fd2 SP |
341 | /* Return true when DEF can be analyzed in REGION by the scalar |
342 | evolution analyzer. */ | |
343 | ||
344 | static inline bool | |
345 | scev_analyzable_p (tree def, sese region) | |
346 | { | |
8ba78f92 SP |
347 | loop_p loop; |
348 | tree scev; | |
349 | tree type = TREE_TYPE (def); | |
350 | ||
351 | /* When Graphite generates code for a scev, the code generator | |
352 | expresses the scev in function of a single induction variable. | |
353 | This is unsafe for floating point computations, as it may replace | |
354 | a floating point sum reduction with a multiplication. The | |
355 | following test returns false for non integer types to avoid such | |
356 | problems. */ | |
357 | if (!INTEGRAL_TYPE_P (type) | |
358 | && !POINTER_TYPE_P (type)) | |
359 | return false; | |
360 | ||
361 | loop = loop_containing_stmt (SSA_NAME_DEF_STMT (def)); | |
362 | scev = scalar_evolution_in_region (region, loop, def); | |
2e286fd2 SP |
363 | |
364 | return !chrec_contains_undetermined (scev) | |
9be8ba7e SP |
365 | && (TREE_CODE (scev) != SSA_NAME |
366 | || !defined_in_sese_p (scev, region)) | |
f36fc876 SP |
367 | && (tree_does_not_contain_chrecs (scev) |
368 | || evolution_function_is_affine_p (scev)); | |
2e286fd2 SP |
369 | } |
370 | ||
2abae5f1 | 371 | #endif |