Create branch to syn ICI 2.0 with gcc mainline.
[official-gcc.git] / gcc / sese.h
blobace63ba671967354f8e6328fca7d7f5bf2b60f1d
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>.
6 This file is part of GCC.
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.
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.
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/>. */
22 #ifndef GCC_SESE_H
23 #define GCC_SESE_H
25 /* A Single Entry, Single Exit region is a part of the CFG delimited
26 by two edges. */
27 typedef struct sese_s
29 /* Single ENTRY and single EXIT from the SESE region. */
30 edge entry, exit;
32 /* Parameters used within the SCOP. */
33 VEC (tree, heap) *params;
35 /* Used to quickly retrieve the index of a parameter in PARAMS. */
36 htab_t params_index;
38 /* Store the names of the parameters that are passed to CLooG. */
39 char **params_names;
41 /* Loops completely contained in the SCOP. */
42 bitmap loops;
43 VEC (loop_p, heap) *loop_nest;
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;
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)
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 void sese_reset_aux_in_loops (sese);
72 extern tree scalar_evolution_in_region (sese, loop_p, tree);
74 /* Check that SESE contains LOOP. */
76 static inline bool
77 sese_contains_loop (sese sese, struct loop *loop)
79 return bitmap_bit_p (SESE_LOOPS (sese), loop->num);
82 /* The number of parameters in REGION. */
84 static inline unsigned
85 sese_nb_params (sese region)
87 return VEC_length (tree, SESE_PARAMS (region));
90 /* Checks whether BB is contained in the region delimited by ENTRY and
91 EXIT blocks. */
93 static inline bool
94 bb_in_region (basic_block bb, basic_block entry, basic_block exit)
96 #ifdef ENABLE_CHECKING
98 edge e;
99 edge_iterator ei;
101 /* Check that there are no edges coming in the region: all the
102 predecessors of EXIT are dominated by ENTRY. */
103 FOR_EACH_EDGE (e, ei, exit->preds)
104 dominated_by_p (CDI_DOMINATORS, e->src, entry);
106 /* Check that there are no edges going out of the region: the
107 entry is post-dominated by the exit. FIXME: This cannot be
108 checked right now as the CDI_POST_DOMINATORS are needed. */
110 #endif
112 return dominated_by_p (CDI_DOMINATORS, bb, entry)
113 && !(dominated_by_p (CDI_DOMINATORS, bb, exit)
114 && !dominated_by_p (CDI_DOMINATORS, entry, exit));
117 /* Checks whether BB is contained in the region delimited by ENTRY and
118 EXIT blocks. */
120 static inline bool
121 bb_in_sese_p (basic_block bb, sese region)
123 basic_block entry = SESE_ENTRY_BB (region);
124 basic_block exit = SESE_EXIT_BB (region);
126 return bb_in_region (bb, entry, exit);
129 /* Returns true when NAME is defined in REGION. */
131 static inline bool
132 defined_in_sese_p (tree name, sese region)
134 gimple stmt = SSA_NAME_DEF_STMT (name);
135 basic_block bb = gimple_bb (stmt);
137 return bb && bb_in_sese_p (bb, region);
140 /* Returns true when LOOP is in REGION. */
142 static inline bool
143 loop_in_sese_p (struct loop *loop, sese region)
145 return (bb_in_sese_p (loop->header, region)
146 && bb_in_sese_p (loop->latch, region));
149 /* Returns the loop depth of LOOP in REGION. The loop depth
150 is the same as the normal loop depth, but limited by a region.
152 Example:
154 loop_0
155 loop_1
158 <- region start
161 loop_2
165 <- region end
168 loop_0 does not exist in the region -> invalid
169 loop_1 exists, but is not completely contained in the region -> depth 0
170 loop_2 is completely contained -> depth 1 */
172 static inline unsigned int
173 sese_loop_depth (sese region, loop_p loop)
175 unsigned int depth = 0;
177 gcc_assert ((!loop_in_sese_p (loop, region)
178 && (SESE_ENTRY_BB (region)->loop_father == loop
179 || SESE_EXIT (region)->src->loop_father == loop))
180 || loop_in_sese_p (loop, region));
182 while (loop_in_sese_p (loop, region))
184 depth++;
185 loop = loop_outer (loop);
188 return depth;
191 /* Returns the block preceding the entry of a SESE. */
193 static inline basic_block
194 block_before_sese (sese sese)
196 return SESE_ENTRY (sese)->src;
199 /* Stores the INDEX in a vector for a given clast NAME. */
201 typedef struct clast_name_index {
202 int index;
203 const char *name;
204 } *clast_name_index_p;
206 /* Returns a pointer to a new element of type clast_name_index_p built
207 from NAME and INDEX. */
209 static inline clast_name_index_p
210 new_clast_name_index (const char *name, int index)
212 clast_name_index_p res = XNEW (struct clast_name_index);
214 res->name = name;
215 res->index = index;
216 return res;
219 /* For a given clast NAME, returns -1 if it does not correspond to any
220 parameter, or otherwise, returns the index in the PARAMS or
221 SCATTERING_DIMENSIONS vector. */
223 static inline int
224 clast_name_to_index (const char *name, htab_t index_table)
226 struct clast_name_index tmp;
227 PTR *slot;
229 tmp.name = name;
230 slot = htab_find_slot (index_table, &tmp, NO_INSERT);
232 if (slot && *slot)
233 return ((struct clast_name_index *) *slot)->index;
235 return -1;
238 /* Records in INDEX_TABLE the INDEX for NAME. */
240 static inline void
241 save_clast_name_index (htab_t index_table, const char *name, int index)
243 struct clast_name_index tmp;
244 PTR *slot;
246 tmp.name = name;
247 slot = htab_find_slot (index_table, &tmp, INSERT);
249 if (slot)
250 *slot = new_clast_name_index (name, index);
253 /* Print to stderr the element ELT. */
255 static inline void
256 debug_clast_name_index (clast_name_index_p elt)
258 fprintf (stderr, "(index = %d, name = %s)\n", elt->index, elt->name);
261 /* Helper function for debug_rename_map. */
263 static inline int
264 debug_clast_name_indexes_1 (void **slot, void *s ATTRIBUTE_UNUSED)
266 struct clast_name_index *entry = (struct clast_name_index *) *slot;
267 debug_clast_name_index (entry);
268 return 1;
271 /* Print to stderr all the elements of MAP. */
273 static inline void
274 debug_clast_name_indexes (htab_t map)
276 htab_traverse (map, debug_clast_name_indexes_1, NULL);
279 /* Computes a hash function for database element ELT. */
281 static inline hashval_t
282 clast_name_index_elt_info (const void *elt)
284 return htab_hash_pointer (((const struct clast_name_index *) elt)->name);
287 /* Compares database elements E1 and E2. */
289 static inline int
290 eq_clast_name_indexes (const void *e1, const void *e2)
292 const struct clast_name_index *elt1 = (const struct clast_name_index *) e1;
293 const struct clast_name_index *elt2 = (const struct clast_name_index *) e2;
295 return (elt1->name == elt2->name);
300 /* A single entry single exit specialized for conditions. */
302 typedef struct ifsese_s {
303 sese region;
304 sese true_region;
305 sese false_region;
306 } *ifsese;
308 extern void if_region_set_false_region (ifsese, sese);
309 extern ifsese create_if_region_on_edge (edge, tree);
310 extern ifsese move_sese_in_condition (sese);
311 extern edge get_true_edge_from_guard_bb (basic_block);
312 extern edge get_false_edge_from_guard_bb (basic_block);
314 static inline edge
315 if_region_entry (ifsese if_region)
317 return SESE_ENTRY (if_region->region);
320 static inline edge
321 if_region_exit (ifsese if_region)
323 return SESE_EXIT (if_region->region);
326 static inline basic_block
327 if_region_get_condition_block (ifsese if_region)
329 return if_region_entry (if_region)->dest;
332 /* Structure containing the mapping between the old names and the new
333 names used after block copy in the new loop context. */
334 typedef struct rename_map_elt_s
336 tree old_name, expr;
337 } *rename_map_elt;
339 DEF_VEC_P(rename_map_elt);
340 DEF_VEC_ALLOC_P (rename_map_elt, heap);
342 extern void debug_rename_map (htab_t);
343 extern hashval_t rename_map_elt_info (const void *);
344 extern int eq_rename_map_elts (const void *, const void *);
345 extern void set_rename (htab_t, tree, tree);
347 /* Constructs a new SCEV_INFO_STR structure for VAR and INSTANTIATED_BELOW. */
349 static inline rename_map_elt
350 new_rename_map_elt (tree old_name, tree expr)
352 rename_map_elt res;
354 res = XNEW (struct rename_map_elt_s);
355 res->old_name = old_name;
356 res->expr = expr;
358 return res;
361 /* Structure containing the mapping between the CLooG's induction
362 variable and the type of the old induction variable. */
363 typedef struct ivtype_map_elt_s
365 tree type;
366 const char *cloog_iv;
367 } *ivtype_map_elt;
369 extern void debug_ivtype_map (htab_t);
370 extern hashval_t ivtype_map_elt_info (const void *);
371 extern int eq_ivtype_map_elts (const void *, const void *);
373 /* Constructs a new SCEV_INFO_STR structure for VAR and INSTANTIATED_BELOW. */
375 static inline ivtype_map_elt
376 new_ivtype_map_elt (const char *cloog_iv, tree type)
378 ivtype_map_elt res;
380 res = XNEW (struct ivtype_map_elt_s);
381 res->cloog_iv = cloog_iv;
382 res->type = type;
384 return res;
387 /* Free and compute again all the dominators information. */
389 static inline void
390 recompute_all_dominators (void)
392 mark_irreducible_loops ();
393 free_dominance_info (CDI_DOMINATORS);
394 free_dominance_info (CDI_POST_DOMINATORS);
395 calculate_dominance_info (CDI_DOMINATORS);
396 calculate_dominance_info (CDI_POST_DOMINATORS);
399 typedef struct gimple_bb
401 basic_block bb;
403 /* Lists containing the restrictions of the conditional statements
404 dominating this bb. This bb can only be executed, if all conditions
405 are true.
407 Example:
409 for (i = 0; i <= 20; i++)
413 if (2i <= 8)
417 So for B there is an additional condition (2i <= 8).
419 List of COND_EXPR and SWITCH_EXPR. A COND_EXPR is true only if the
420 corresponding element in CONDITION_CASES is not NULL_TREE. For a
421 SWITCH_EXPR the corresponding element in CONDITION_CASES is a
422 CASE_LABEL_EXPR. */
423 VEC (gimple, heap) *conditions;
424 VEC (gimple, heap) *condition_cases;
425 VEC (data_reference_p, heap) *data_refs;
426 htab_t cloog_iv_types;
427 } *gimple_bb_p;
429 #define GBB_BB(GBB) GBB->bb
430 #define GBB_DATA_REFS(GBB) GBB->data_refs
431 #define GBB_CONDITIONS(GBB) GBB->conditions
432 #define GBB_CONDITION_CASES(GBB) GBB->condition_cases
433 #define GBB_CLOOG_IV_TYPES(GBB) GBB->cloog_iv_types
435 /* Return the innermost loop that contains the basic block GBB. */
437 static inline struct loop *
438 gbb_loop (struct gimple_bb *gbb)
440 return GBB_BB (gbb)->loop_father;
443 /* Returns the gimple loop, that corresponds to the loop_iterator_INDEX.
444 If there is no corresponding gimple loop, we return NULL. */
446 static inline loop_p
447 gbb_loop_at_index (gimple_bb_p gbb, sese region, int index)
449 loop_p loop = gbb_loop (gbb);
450 int depth = sese_loop_depth (region, loop);
452 while (--depth > index)
453 loop = loop_outer (loop);
455 gcc_assert (sese_contains_loop (region, loop));
457 return loop;
460 /* The number of common loops in REGION for GBB1 and GBB2. */
462 static inline int
463 nb_common_loops (sese region, gimple_bb_p gbb1, gimple_bb_p gbb2)
465 loop_p l1 = gbb_loop (gbb1);
466 loop_p l2 = gbb_loop (gbb2);
467 loop_p common = find_common_loop (l1, l2);
469 return sese_loop_depth (region, common);
472 extern void print_gimple_bb (FILE *, gimple_bb_p, int, int);
473 extern void debug_gbb (gimple_bb_p, int);
475 #endif