Fix for ICE with -g on testcase with incomplete types.
[official-gcc.git] / gcc / sese.h
blobd2ad9bde04b88145f5a329c0bd79f2d3d87cbfce
1 /* Single entry single exit control flow regions.
2 Copyright (C) 2008-2015 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 typedef hash_map<tree, tree> parameter_rename_map_t;
27 /* A Single Entry, Single Exit region is a part of the CFG delimited
28 by two edges. */
29 struct sese_l
31 sese_l (edge e, edge x) : entry (e), exit (x) {}
33 operator bool () const { return entry && exit; }
35 edge entry;
36 edge exit;
39 /* Get the entry of an sese S. */
41 static inline basic_block
42 get_entry_bb (sese_l &s)
44 return s.entry->dest;
47 /* Get the exit of an sese S. */
49 static inline basic_block
50 get_exit_bb (sese_l &s)
52 return s.exit->src;
55 /* A helper structure for bookkeeping information about a scop in graphite. */
56 typedef struct sese_info_t
58 /* The SESE region. */
59 sese_l region;
61 /* Parameters used within the SCOP. */
62 vec<tree> params;
64 /* Parameters to be renamed. */
65 parameter_rename_map_t *parameter_rename_map;
67 /* Loops completely contained in this SESE. */
68 bitmap loops;
69 vec<loop_p> loop_nest;
71 /* Basic blocks contained in this SESE. */
72 vec<basic_block> bbs;
73 } *sese_info_p;
75 #define SESE_PARAMS(S) (S->params)
76 #define SESE_LOOPS(S) (S->loops)
77 #define SESE_LOOP_NEST(S) (S->loop_nest)
79 extern sese_info_p new_sese_info (edge, edge);
80 extern void free_sese_info (sese_info_p);
81 extern void sese_insert_phis_for_liveouts (sese_info_p, basic_block, edge, edge);
82 extern void build_sese_loop_nests (sese_info_p);
83 extern edge copy_bb_and_scalar_dependences (basic_block, sese_info_p, edge,
84 vec<tree> , bool *);
85 extern struct loop *outermost_loop_in_sese (sese_l &, basic_block);
86 extern tree scalar_evolution_in_region (sese_l &, loop_p, tree);
87 extern bool invariant_in_sese_p_rec (tree, sese_l &, bool *);
89 /* Check that SESE contains LOOP. */
91 static inline bool
92 sese_contains_loop (sese_info_p sese, struct loop *loop)
94 return bitmap_bit_p (SESE_LOOPS (sese), loop->num);
97 /* The number of parameters in REGION. */
99 static inline unsigned
100 sese_nb_params (sese_info_p region)
102 return SESE_PARAMS (region).length ();
105 /* Checks whether BB is contained in the region delimited by ENTRY and
106 EXIT blocks. */
108 static inline bool
109 bb_in_region (basic_block bb, basic_block entry, basic_block exit)
111 #ifdef ENABLE_CHECKING
113 edge e;
114 edge_iterator ei;
116 /* Check that there are no edges coming in the region: all the
117 predecessors of EXIT are dominated by ENTRY. */
118 FOR_EACH_EDGE (e, ei, exit->preds)
119 dominated_by_p (CDI_DOMINATORS, e->src, entry);
121 #endif
123 return dominated_by_p (CDI_DOMINATORS, bb, entry)
124 && !(dominated_by_p (CDI_DOMINATORS, bb, exit)
125 && !dominated_by_p (CDI_DOMINATORS, entry, exit));
128 /* Checks whether BB is contained in the region delimited by ENTRY and
129 EXIT blocks. */
131 static inline bool
132 bb_in_sese_p (basic_block bb, sese_l &r)
134 return bb_in_region (bb, r.entry->dest, r.exit->dest);
137 /* Returns true when STMT is defined in REGION. */
139 static inline bool
140 stmt_in_sese_p (gimple *stmt, sese_l &r)
142 basic_block bb = gimple_bb (stmt);
143 return bb && bb_in_sese_p (bb, r);
146 /* Returns true when NAME is defined in REGION. */
148 static inline bool
149 defined_in_sese_p (tree name, sese_l &r)
151 return stmt_in_sese_p (SSA_NAME_DEF_STMT (name), r);
154 /* Returns true when LOOP is in REGION. */
156 static inline bool
157 loop_in_sese_p (struct loop *loop, sese_l &region)
159 return (bb_in_sese_p (loop->header, region)
160 && bb_in_sese_p (loop->latch, region));
163 /* Returns the loop depth of LOOP in REGION. The loop depth
164 is the same as the normal loop depth, but limited by a region.
166 Example:
168 loop_0
169 loop_1
172 <- region start
175 loop_2
179 <- region end
182 loop_0 does not exist in the region -> invalid
183 loop_1 exists, but is not completely contained in the region -> depth 0
184 loop_2 is completely contained -> depth 1 */
186 static inline unsigned int
187 sese_loop_depth (sese_l &region, loop_p loop)
189 unsigned int depth = 0;
191 while (loop_in_sese_p (loop, region))
193 depth++;
194 loop = loop_outer (loop);
197 return depth;
200 /* A single entry single exit specialized for conditions. */
202 typedef struct ifsese_s {
203 sese_info_p region;
204 sese_info_p true_region;
205 sese_info_p false_region;
206 } *ifsese;
208 extern void if_region_set_false_region (ifsese, sese_info_p);
209 extern ifsese move_sese_in_condition (sese_info_p);
210 extern edge get_true_edge_from_guard_bb (basic_block);
211 extern edge get_false_edge_from_guard_bb (basic_block);
212 extern void set_ifsese_condition (ifsese, tree);
214 static inline edge
215 if_region_entry (ifsese if_region)
217 return if_region->region->region.entry;
220 static inline edge
221 if_region_exit (ifsese if_region)
223 return if_region->region->region.exit;
226 static inline basic_block
227 if_region_get_condition_block (ifsese if_region)
229 return if_region_entry (if_region)->dest;
232 /* Free and compute again all the dominators information. */
234 static inline void
235 recompute_all_dominators (void)
237 mark_irreducible_loops ();
238 free_dominance_info (CDI_DOMINATORS);
239 calculate_dominance_info (CDI_DOMINATORS);
241 free_dominance_info (CDI_POST_DOMINATORS);
242 calculate_dominance_info (CDI_POST_DOMINATORS);
245 typedef struct gimple_poly_bb
247 basic_block bb;
248 struct poly_bb *pbb;
250 /* Lists containing the restrictions of the conditional statements
251 dominating this bb. This bb can only be executed, if all conditions
252 are true.
254 Example:
256 for (i = 0; i <= 20; i++)
260 if (2i <= 8)
264 So for B there is an additional condition (2i <= 8).
266 List of COND_EXPR and SWITCH_EXPR. A COND_EXPR is true only if the
267 corresponding element in CONDITION_CASES is not NULL_TREE. For a
268 SWITCH_EXPR the corresponding element in CONDITION_CASES is a
269 CASE_LABEL_EXPR. */
270 vec<gimple *> conditions;
271 vec<gimple *> condition_cases;
272 vec<data_reference_p> data_refs;
273 } *gimple_poly_bb_p;
275 #define GBB_BB(GBB) (GBB)->bb
276 #define GBB_PBB(GBB) (GBB)->pbb
277 #define GBB_DATA_REFS(GBB) (GBB)->data_refs
278 #define GBB_CONDITIONS(GBB) (GBB)->conditions
279 #define GBB_CONDITION_CASES(GBB) (GBB)->condition_cases
281 /* Return the innermost loop that contains the basic block GBB. */
283 static inline struct loop *
284 gbb_loop (gimple_poly_bb_p gbb)
286 return GBB_BB (gbb)->loop_father;
289 /* Returns the gimple loop, that corresponds to the loop_iterator_INDEX.
290 If there is no corresponding gimple loop, we return NULL. */
292 static inline loop_p
293 gbb_loop_at_index (gimple_poly_bb_p gbb, sese_l &region, int index)
295 loop_p loop = gbb_loop (gbb);
296 int depth = sese_loop_depth (region, loop);
298 while (--depth > index)
299 loop = loop_outer (loop);
301 gcc_assert (loop_in_sese_p (loop, region));
303 return loop;
306 /* The number of common loops in REGION for GBB1 and GBB2. */
308 static inline int
309 nb_common_loops (sese_l &region, gimple_poly_bb_p gbb1, gimple_poly_bb_p gbb2)
311 loop_p l1 = gbb_loop (gbb1);
312 loop_p l2 = gbb_loop (gbb2);
313 loop_p common = find_common_loop (l1, l2);
315 return sese_loop_depth (region, common);
318 /* Return true when DEF can be analyzed in REGION by the scalar
319 evolution analyzer. */
321 static inline bool
322 scev_analyzable_p (tree def, sese_l &region)
324 loop_p loop;
325 tree scev;
326 tree type = TREE_TYPE (def);
328 /* When Graphite generates code for a scev, the code generator
329 expresses the scev in function of a single induction variable.
330 This is unsafe for floating point computations, as it may replace
331 a floating point sum reduction with a multiplication. The
332 following test returns false for non integer types to avoid such
333 problems. */
334 if (!INTEGRAL_TYPE_P (type)
335 && !POINTER_TYPE_P (type))
336 return false;
338 loop = loop_containing_stmt (SSA_NAME_DEF_STMT (def));
339 scev = scalar_evolution_in_region (region, loop, def);
341 return !chrec_contains_undetermined (scev)
342 && (TREE_CODE (scev) != SSA_NAME
343 || !defined_in_sese_p (scev, region))
344 && (tree_does_not_contain_chrecs (scev)
345 || evolution_function_is_affine_p (scev));
348 #endif