Remove trailing white spaces.
[official-gcc.git] / gcc / sese.h
blobc126a6964f8f09b640f087ce47b7510927eb167a
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 tree scalar_evolution_in_region (sese, loop_p, tree);
73 /* Check that SESE contains LOOP. */
75 static inline bool
76 sese_contains_loop (sese sese, struct loop *loop)
78 return bitmap_bit_p (SESE_LOOPS (sese), loop->num);
81 /* The number of parameters in REGION. */
83 static inline unsigned
84 sese_nb_params (sese region)
86 return VEC_length (tree, SESE_PARAMS (region));
89 /* Checks whether BB is contained in the region delimited by ENTRY and
90 EXIT blocks. */
92 static inline bool
93 bb_in_region (basic_block bb, basic_block entry, basic_block exit)
95 #ifdef ENABLE_CHECKING
97 edge e;
98 edge_iterator ei;
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);
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. */
109 #endif
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));
116 /* Checks whether BB is contained in the region delimited by ENTRY and
117 EXIT blocks. */
119 static inline bool
120 bb_in_sese_p (basic_block bb, sese region)
122 basic_block entry = SESE_ENTRY_BB (region);
123 basic_block exit = SESE_EXIT_BB (region);
125 return bb_in_region (bb, entry, exit);
128 /* Returns true when NAME is defined in REGION. */
130 static inline bool
131 defined_in_sese_p (tree name, sese region)
133 gimple stmt = SSA_NAME_DEF_STMT (name);
134 basic_block bb = gimple_bb (stmt);
136 return bb && bb_in_sese_p (bb, region);
139 /* Returns true when LOOP is in REGION. */
141 static inline bool
142 loop_in_sese_p (struct loop *loop, sese region)
144 return (bb_in_sese_p (loop->header, region)
145 && bb_in_sese_p (loop->latch, region));
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.
151 Example:
153 loop_0
154 loop_1
157 <- region start
160 loop_2
164 <- region end
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 */
171 static inline unsigned int
172 sese_loop_depth (sese region, loop_p loop)
174 unsigned int depth = 0;
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));
181 while (loop_in_sese_p (loop, region))
183 depth++;
184 loop = loop_outer (loop);
187 return depth;
190 /* Splits BB to make a single entry single exit region. */
192 static inline sese
193 split_region_for_bb (basic_block bb)
195 edge entry, exit;
197 if (single_pred_p (bb))
198 entry = single_pred_edge (bb);
199 else
201 entry = split_block_after_labels (bb);
202 bb = single_succ (bb);
205 if (single_succ_p (bb))
206 exit = single_succ_edge (bb);
207 else
209 gimple_stmt_iterator gsi = gsi_last_bb (bb);
210 gsi_prev (&gsi);
211 exit = split_block (bb, gsi_stmt (gsi));
214 return new_sese (entry, exit);
217 /* Returns the block preceding the entry of a SESE. */
219 static inline basic_block
220 block_before_sese (sese sese)
222 return SESE_ENTRY (sese)->src;
225 /* Stores the INDEX in a vector for a given clast NAME. */
227 typedef struct clast_name_index {
228 int index;
229 const char *name;
230 } *clast_name_index_p;
232 /* Returns a pointer to a new element of type clast_name_index_p built
233 from NAME and INDEX. */
235 static inline clast_name_index_p
236 new_clast_name_index (const char *name, int index)
238 clast_name_index_p res = XNEW (struct clast_name_index);
240 res->name = name;
241 res->index = index;
242 return res;
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. */
249 static inline int
250 clast_name_to_index (const char *name, htab_t index_table)
252 struct clast_name_index tmp;
253 PTR *slot;
255 tmp.name = name;
256 slot = htab_find_slot (index_table, &tmp, NO_INSERT);
258 if (slot && *slot)
259 return ((struct clast_name_index *) *slot)->index;
261 return -1;
264 /* Records in INDEX_TABLE the INDEX for NAME. */
266 static inline void
267 save_clast_name_index (htab_t index_table, const char *name, int index)
269 struct clast_name_index tmp;
270 PTR *slot;
272 tmp.name = name;
273 slot = htab_find_slot (index_table, &tmp, INSERT);
275 if (slot)
276 *slot = new_clast_name_index (name, index);
279 /* Print to stderr the element ELT. */
281 static inline void
282 debug_clast_name_index (clast_name_index_p elt)
284 fprintf (stderr, "(index = %d, name = %s)\n", elt->index, elt->name);
287 /* Helper function for debug_rename_map. */
289 static inline int
290 debug_clast_name_indexes_1 (void **slot, void *s ATTRIBUTE_UNUSED)
292 struct clast_name_index *entry = (struct clast_name_index *) *slot;
293 debug_clast_name_index (entry);
294 return 1;
297 /* Print to stderr all the elements of MAP. */
299 static inline void
300 debug_clast_name_indexes (htab_t map)
302 htab_traverse (map, debug_clast_name_indexes_1, NULL);
305 /* Computes a hash function for database element ELT. */
307 static inline hashval_t
308 clast_name_index_elt_info (const void *elt)
310 return htab_hash_pointer (((const struct clast_name_index *) elt)->name);
313 /* Compares database elements E1 and E2. */
315 static inline int
316 eq_clast_name_indexes (const void *e1, const void *e2)
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;
321 return (elt1->name == elt2->name);
326 /* A single entry single exit specialized for conditions. */
328 typedef struct ifsese_s {
329 sese region;
330 sese true_region;
331 sese false_region;
332 } *ifsese;
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);
340 static inline edge
341 if_region_entry (ifsese if_region)
343 return SESE_ENTRY (if_region->region);
346 static inline edge
347 if_region_exit (ifsese if_region)
349 return SESE_EXIT (if_region->region);
352 static inline basic_block
353 if_region_get_condition_block (ifsese if_region)
355 return if_region_entry (if_region)->dest;
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
362 tree old_name, expr;
363 } *rename_map_elt;
365 DEF_VEC_P(rename_map_elt);
366 DEF_VEC_ALLOC_P (rename_map_elt, heap);
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);
373 /* Constructs a new SCEV_INFO_STR structure for VAR and INSTANTIATED_BELOW. */
375 static inline rename_map_elt
376 new_rename_map_elt (tree old_name, tree expr)
378 rename_map_elt res;
380 res = XNEW (struct rename_map_elt_s);
381 res->old_name = old_name;
382 res->expr = expr;
384 return res;
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
391 tree type;
392 const char *cloog_iv;
393 } *ivtype_map_elt;
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 *);
399 /* Constructs a new SCEV_INFO_STR structure for VAR and INSTANTIATED_BELOW. */
401 static inline ivtype_map_elt
402 new_ivtype_map_elt (const char *cloog_iv, tree type)
404 ivtype_map_elt res;
406 res = XNEW (struct ivtype_map_elt_s);
407 res->cloog_iv = cloog_iv;
408 res->type = type;
410 return res;
413 /* Free and compute again all the dominators information. */
415 static inline void
416 recompute_all_dominators (void)
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);
425 typedef struct gimple_bb
427 basic_block bb;
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.
433 Example:
435 for (i = 0; i <= 20; i++)
439 if (2i <= 8)
443 So for B there is an additional condition (2i <= 8).
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;
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
461 /* Return the innermost loop that contains the basic block GBB. */
463 static inline struct loop *
464 gbb_loop (struct gimple_bb *gbb)
466 return GBB_BB (gbb)->loop_father;
469 /* Returns the gimple loop, that corresponds to the loop_iterator_INDEX.
470 If there is no corresponding gimple loop, we return NULL. */
472 static inline loop_p
473 gbb_loop_at_index (gimple_bb_p gbb, sese region, int index)
475 loop_p loop = gbb_loop (gbb);
476 int depth = sese_loop_depth (region, loop);
478 while (--depth > index)
479 loop = loop_outer (loop);
481 gcc_assert (sese_contains_loop (region, loop));
483 return loop;
486 /* The number of common loops in REGION for GBB1 and GBB2. */
488 static inline int
489 nb_common_loops (sese region, gimple_bb_p gbb1, gimple_bb_p gbb2)
491 loop_p l1 = gbb_loop (gbb1);
492 loop_p l2 = gbb_loop (gbb2);
493 loop_p common = find_common_loop (l1, l2);
495 return sese_loop_depth (region, common);
498 extern void print_gimple_bb (FILE *, gimple_bb_p, int, int);
499 extern void debug_gbb (gimple_bb_p, int);
501 #endif