Remove trailing white spaces.
[gcc.git] / gcc / sese.h
1 /* Single entry single exit control flow regions.
2 Copyright (C) 2008, 2009 Free Software Foundation, Inc.
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
25 /* A Single Entry, Single Exit region is a part of the CFG delimited
26 by two edges. */
27 typedef struct sese_s
28 {
29 /* Single ENTRY and single EXIT from the SESE region. */
30 edge entry, exit;
31
32 /* Parameters used within the SCOP. */
33 VEC (tree, heap) *params;
34
35 /* Used to quickly retrieve the index of a parameter in PARAMS. */
36 htab_t params_index;
37
38 /* Store the names of the parameters that are passed to CLooG. */
39 char **params_names;
40
41 /* Loops completely contained in the SCOP. */
42 bitmap loops;
43 VEC (loop_p, heap) *loop_nest;
44
45 /* Are we allowed to add more params? This is for debugging purpose. We
46 can only add new params before generating the bb domains, otherwise they
47 become invalid. */
48 bool add_params;
49 } *sese;
50
51 #define SESE_ENTRY(S) (S->entry)
52 #define SESE_ENTRY_BB(S) (S->entry->dest)
53 #define SESE_EXIT(S) (S->exit)
54 #define SESE_EXIT_BB(S) (S->exit->dest)
55 #define SESE_PARAMS(S) (S->params)
56 #define SESE_PARAMS_INDEX(S) (S->params_index)
57 #define SESE_PARAMS_NAMES(S) (S->params_names)
58 #define SESE_LOOPS(S) (S->loops)
59 #define SESE_LOOP_NEST(S) (S->loop_nest)
60 #define SESE_ADD_PARAMS(S) (S->add_params)
61
62 extern sese new_sese (edge, edge);
63 extern void free_sese (sese);
64 extern void sese_insert_phis_for_liveouts (sese, basic_block, edge, edge);
65 extern void sese_adjust_liveout_phis (sese, htab_t, basic_block, edge, edge);
66 extern void build_sese_loop_nests (sese);
67 extern edge copy_bb_and_scalar_dependences (basic_block, sese, edge, htab_t);
68 extern struct loop *outermost_loop_in_sese (sese, basic_block);
69 extern void insert_loop_close_phis (htab_t, loop_p);
70 extern void insert_guard_phis (basic_block, edge, edge, htab_t, htab_t);
71 extern tree scalar_evolution_in_region (sese, loop_p, tree);
72
73 /* Check that SESE contains LOOP. */
74
75 static inline bool
76 sese_contains_loop (sese sese, struct loop *loop)
77 {
78 return bitmap_bit_p (SESE_LOOPS (sese), loop->num);
79 }
80
81 /* The number of parameters in REGION. */
82
83 static inline unsigned
84 sese_nb_params (sese region)
85 {
86 return VEC_length (tree, SESE_PARAMS (region));
87 }
88
89 /* Checks whether BB is contained in the region delimited by ENTRY and
90 EXIT blocks. */
91
92 static inline bool
93 bb_in_region (basic_block bb, basic_block entry, basic_block exit)
94 {
95 #ifdef ENABLE_CHECKING
96 {
97 edge e;
98 edge_iterator ei;
99
100 /* Check that there are no edges coming in the region: all the
101 predecessors of EXIT are dominated by ENTRY. */
102 FOR_EACH_EDGE (e, ei, exit->preds)
103 dominated_by_p (CDI_DOMINATORS, e->src, entry);
104
105 /* Check that there are no edges going out of the region: the
106 entry is post-dominated by the exit. FIXME: This cannot be
107 checked right now as the CDI_POST_DOMINATORS are needed. */
108 }
109 #endif
110
111 return dominated_by_p (CDI_DOMINATORS, bb, entry)
112 && !(dominated_by_p (CDI_DOMINATORS, bb, exit)
113 && !dominated_by_p (CDI_DOMINATORS, entry, exit));
114 }
115
116 /* Checks whether BB is contained in the region delimited by ENTRY and
117 EXIT blocks. */
118
119 static inline bool
120 bb_in_sese_p (basic_block bb, sese region)
121 {
122 basic_block entry = SESE_ENTRY_BB (region);
123 basic_block exit = SESE_EXIT_BB (region);
124
125 return bb_in_region (bb, entry, exit);
126 }
127
128 /* Returns true when NAME is defined in REGION. */
129
130 static inline bool
131 defined_in_sese_p (tree name, sese region)
132 {
133 gimple stmt = SSA_NAME_DEF_STMT (name);
134 basic_block bb = gimple_bb (stmt);
135
136 return bb && bb_in_sese_p (bb, region);
137 }
138
139 /* Returns true when LOOP is in REGION. */
140
141 static inline bool
142 loop_in_sese_p (struct loop *loop, sese region)
143 {
144 return (bb_in_sese_p (loop->header, region)
145 && bb_in_sese_p (loop->latch, region));
146 }
147
148 /* Returns the loop depth of LOOP in REGION. The loop depth
149 is the same as the normal loop depth, but limited by a region.
150
151 Example:
152
153 loop_0
154 loop_1
155 {
156 S0
157 <- region start
158 S1
159
160 loop_2
161 S2
162
163 S3
164 <- region end
165 }
166
167 loop_0 does not exist in the region -> invalid
168 loop_1 exists, but is not completely contained in the region -> depth 0
169 loop_2 is completely contained -> depth 1 */
170
171 static inline unsigned int
172 sese_loop_depth (sese region, loop_p loop)
173 {
174 unsigned int depth = 0;
175
176 gcc_assert ((!loop_in_sese_p (loop, region)
177 && (SESE_ENTRY_BB (region)->loop_father == loop
178 || SESE_EXIT (region)->src->loop_father == loop))
179 || loop_in_sese_p (loop, region));
180
181 while (loop_in_sese_p (loop, region))
182 {
183 depth++;
184 loop = loop_outer (loop);
185 }
186
187 return depth;
188 }
189
190 /* Splits BB to make a single entry single exit region. */
191
192 static inline sese
193 split_region_for_bb (basic_block bb)
194 {
195 edge entry, exit;
196
197 if (single_pred_p (bb))
198 entry = single_pred_edge (bb);
199 else
200 {
201 entry = split_block_after_labels (bb);
202 bb = single_succ (bb);
203 }
204
205 if (single_succ_p (bb))
206 exit = single_succ_edge (bb);
207 else
208 {
209 gimple_stmt_iterator gsi = gsi_last_bb (bb);
210 gsi_prev (&gsi);
211 exit = split_block (bb, gsi_stmt (gsi));
212 }
213
214 return new_sese (entry, exit);
215 }
216
217 /* Returns the block preceding the entry of a SESE. */
218
219 static inline basic_block
220 block_before_sese (sese sese)
221 {
222 return SESE_ENTRY (sese)->src;
223 }
224
225 /* Stores the INDEX in a vector for a given clast NAME. */
226
227 typedef struct clast_name_index {
228 int index;
229 const char *name;
230 } *clast_name_index_p;
231
232 /* Returns a pointer to a new element of type clast_name_index_p built
233 from NAME and INDEX. */
234
235 static inline clast_name_index_p
236 new_clast_name_index (const char *name, int index)
237 {
238 clast_name_index_p res = XNEW (struct clast_name_index);
239
240 res->name = name;
241 res->index = index;
242 return res;
243 }
244
245 /* For a given clast NAME, returns -1 if it does not correspond to any
246 parameter, or otherwise, returns the index in the PARAMS or
247 SCATTERING_DIMENSIONS vector. */
248
249 static inline int
250 clast_name_to_index (const char *name, htab_t index_table)
251 {
252 struct clast_name_index tmp;
253 PTR *slot;
254
255 tmp.name = name;
256 slot = htab_find_slot (index_table, &tmp, NO_INSERT);
257
258 if (slot && *slot)
259 return ((struct clast_name_index *) *slot)->index;
260
261 return -1;
262 }
263
264 /* Records in INDEX_TABLE the INDEX for NAME. */
265
266 static inline void
267 save_clast_name_index (htab_t index_table, const char *name, int index)
268 {
269 struct clast_name_index tmp;
270 PTR *slot;
271
272 tmp.name = name;
273 slot = htab_find_slot (index_table, &tmp, INSERT);
274
275 if (slot)
276 *slot = new_clast_name_index (name, index);
277 }
278
279 /* Print to stderr the element ELT. */
280
281 static inline void
282 debug_clast_name_index (clast_name_index_p elt)
283 {
284 fprintf (stderr, "(index = %d, name = %s)\n", elt->index, elt->name);
285 }
286
287 /* Helper function for debug_rename_map. */
288
289 static inline int
290 debug_clast_name_indexes_1 (void **slot, void *s ATTRIBUTE_UNUSED)
291 {
292 struct clast_name_index *entry = (struct clast_name_index *) *slot;
293 debug_clast_name_index (entry);
294 return 1;
295 }
296
297 /* Print to stderr all the elements of MAP. */
298
299 static inline void
300 debug_clast_name_indexes (htab_t map)
301 {
302 htab_traverse (map, debug_clast_name_indexes_1, NULL);
303 }
304
305 /* Computes a hash function for database element ELT. */
306
307 static inline hashval_t
308 clast_name_index_elt_info (const void *elt)
309 {
310 return htab_hash_pointer (((const struct clast_name_index *) elt)->name);
311 }
312
313 /* Compares database elements E1 and E2. */
314
315 static inline int
316 eq_clast_name_indexes (const void *e1, const void *e2)
317 {
318 const struct clast_name_index *elt1 = (const struct clast_name_index *) e1;
319 const struct clast_name_index *elt2 = (const struct clast_name_index *) e2;
320
321 return (elt1->name == elt2->name);
322 }
323
324 \f
325
326 /* A single entry single exit specialized for conditions. */
327
328 typedef struct ifsese_s {
329 sese region;
330 sese true_region;
331 sese false_region;
332 } *ifsese;
333
334 extern void if_region_set_false_region (ifsese, sese);
335 extern ifsese create_if_region_on_edge (edge, tree);
336 extern ifsese move_sese_in_condition (sese);
337 extern edge get_true_edge_from_guard_bb (basic_block);
338 extern edge get_false_edge_from_guard_bb (basic_block);
339
340 static inline edge
341 if_region_entry (ifsese if_region)
342 {
343 return SESE_ENTRY (if_region->region);
344 }
345
346 static inline edge
347 if_region_exit (ifsese if_region)
348 {
349 return SESE_EXIT (if_region->region);
350 }
351
352 static inline basic_block
353 if_region_get_condition_block (ifsese if_region)
354 {
355 return if_region_entry (if_region)->dest;
356 }
357
358 /* Structure containing the mapping between the old names and the new
359 names used after block copy in the new loop context. */
360 typedef struct rename_map_elt_s
361 {
362 tree old_name, expr;
363 } *rename_map_elt;
364
365 DEF_VEC_P(rename_map_elt);
366 DEF_VEC_ALLOC_P (rename_map_elt, heap);
367
368 extern void debug_rename_map (htab_t);
369 extern hashval_t rename_map_elt_info (const void *);
370 extern int eq_rename_map_elts (const void *, const void *);
371 extern void set_rename (htab_t, tree, tree);
372
373 /* Constructs a new SCEV_INFO_STR structure for VAR and INSTANTIATED_BELOW. */
374
375 static inline rename_map_elt
376 new_rename_map_elt (tree old_name, tree expr)
377 {
378 rename_map_elt res;
379
380 res = XNEW (struct rename_map_elt_s);
381 res->old_name = old_name;
382 res->expr = expr;
383
384 return res;
385 }
386
387 /* Structure containing the mapping between the CLooG's induction
388 variable and the type of the old induction variable. */
389 typedef struct ivtype_map_elt_s
390 {
391 tree type;
392 const char *cloog_iv;
393 } *ivtype_map_elt;
394
395 extern void debug_ivtype_map (htab_t);
396 extern hashval_t ivtype_map_elt_info (const void *);
397 extern int eq_ivtype_map_elts (const void *, const void *);
398
399 /* Constructs a new SCEV_INFO_STR structure for VAR and INSTANTIATED_BELOW. */
400
401 static inline ivtype_map_elt
402 new_ivtype_map_elt (const char *cloog_iv, tree type)
403 {
404 ivtype_map_elt res;
405
406 res = XNEW (struct ivtype_map_elt_s);
407 res->cloog_iv = cloog_iv;
408 res->type = type;
409
410 return res;
411 }
412
413 /* Free and compute again all the dominators information. */
414
415 static inline void
416 recompute_all_dominators (void)
417 {
418 mark_irreducible_loops ();
419 free_dominance_info (CDI_DOMINATORS);
420 free_dominance_info (CDI_POST_DOMINATORS);
421 calculate_dominance_info (CDI_DOMINATORS);
422 calculate_dominance_info (CDI_POST_DOMINATORS);
423 }
424
425 typedef struct gimple_bb
426 {
427 basic_block bb;
428
429 /* Lists containing the restrictions of the conditional statements
430 dominating this bb. This bb can only be executed, if all conditions
431 are true.
432
433 Example:
434
435 for (i = 0; i <= 20; i++)
436 {
437 A
438
439 if (2i <= 8)
440 B
441 }
442
443 So for B there is an additional condition (2i <= 8).
444
445 List of COND_EXPR and SWITCH_EXPR. A COND_EXPR is true only if the
446 corresponding element in CONDITION_CASES is not NULL_TREE. For a
447 SWITCH_EXPR the corresponding element in CONDITION_CASES is a
448 CASE_LABEL_EXPR. */
449 VEC (gimple, heap) *conditions;
450 VEC (gimple, heap) *condition_cases;
451 VEC (data_reference_p, heap) *data_refs;
452 htab_t cloog_iv_types;
453 } *gimple_bb_p;
454
455 #define GBB_BB(GBB) GBB->bb
456 #define GBB_DATA_REFS(GBB) GBB->data_refs
457 #define GBB_CONDITIONS(GBB) GBB->conditions
458 #define GBB_CONDITION_CASES(GBB) GBB->condition_cases
459 #define GBB_CLOOG_IV_TYPES(GBB) GBB->cloog_iv_types
460
461 /* Return the innermost loop that contains the basic block GBB. */
462
463 static inline struct loop *
464 gbb_loop (struct gimple_bb *gbb)
465 {
466 return GBB_BB (gbb)->loop_father;
467 }
468
469 /* Returns the gimple loop, that corresponds to the loop_iterator_INDEX.
470 If there is no corresponding gimple loop, we return NULL. */
471
472 static inline loop_p
473 gbb_loop_at_index (gimple_bb_p gbb, sese region, int index)
474 {
475 loop_p loop = gbb_loop (gbb);
476 int depth = sese_loop_depth (region, loop);
477
478 while (--depth > index)
479 loop = loop_outer (loop);
480
481 gcc_assert (sese_contains_loop (region, loop));
482
483 return loop;
484 }
485
486 /* The number of common loops in REGION for GBB1 and GBB2. */
487
488 static inline int
489 nb_common_loops (sese region, gimple_bb_p gbb1, gimple_bb_p gbb2)
490 {
491 loop_p l1 = gbb_loop (gbb1);
492 loop_p l2 = gbb_loop (gbb2);
493 loop_p common = find_common_loop (l1, l2);
494
495 return sese_loop_depth (region, common);
496 }
497
498 extern void print_gimple_bb (FILE *, gimple_bb_p, int, int);
499 extern void debug_gbb (gimple_bb_p, int);
500
501 #endif