]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/sese.h
Fix failing test-case
[thirdparty/gcc.git] / gcc / sese.h
CommitLineData
2abae5f1 1/* Single entry single exit control flow regions.
cbe34bb5 2 Copyright (C) 2008-2017 Free Software Foundation, Inc.
2abae5f1
SP
3 Contributed by Jan Sjodin <jan.sjodin@amd.com> and
4 Sebastian Pop <sebastian.pop@amd.com>.
5
6This file is part of GCC.
7
8GCC is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 3, or (at your option)
11any later version.
12
13GCC is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along 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
65b016eb
AK
25typedef hash_map<basic_block, vec<basic_block> > bb_map_t;
26typedef hash_map<tree, vec<tree> > rename_map_t;
27typedef struct ifsese_s *ifsese;
28/* First phi is the new codegenerated phi second one is original phi. */
29typedef std::pair <gphi *, gphi *> phi_rename;
30/* First edge is the init edge and second is the back edge w.r.t. a loop. */
31typedef std::pair<edge, edge> init_back_edge_pair_t;
32
2abae5f1
SP
33/* A Single Entry, Single Exit region is a part of the CFG delimited
34 by two edges. */
bafcb153 35struct sese_l
2abae5f1 36{
bafcb153
AK
37 sese_l (edge e, edge x) : entry (e), exit (x) {}
38
bafcb153
AK
39 operator bool () const { return entry && exit; }
40
bafcb153
AK
41 edge entry;
42 edge exit;
43};
44
adba512d
AK
45void print_edge (FILE *file, const_edge e);
46void print_sese (FILE *file, const sese_l &s);
47void dump_edge (const_edge e);
48void dump_sese (const sese_l &);
49
bafcb153
AK
50/* Get the entry of an sese S. */
51
52static inline basic_block
53get_entry_bb (sese_l &s)
54{
55 return s.entry->dest;
56}
57
58/* Get the exit of an sese S. */
59
60static inline basic_block
61get_exit_bb (sese_l &s)
62{
63 return s.exit->src;
64}
65
65b016eb 66/* Returns the index of V where ELEM can be found. -1 Otherwise. */
65b016eb
AK
67template<typename T>
68int
69vec_find (const vec<T> &v, const T &elem)
70{
71 int i;
72 T t;
73 FOR_EACH_VEC_ELT (v, i, t)
74 if (elem == t)
75 return i;
76 return -1;
77}
78
bafcb153
AK
79/* A helper structure for bookkeeping information about a scop in graphite. */
80typedef struct sese_info_t
81{
82 /* The SESE region. */
83 sese_l region;
2abae5f1 84
bd8d431f
RB
85 /* Liveout vars. */
86 bitmap liveout;
87
88 /* Liveout in debug stmts. */
89 bitmap debug_liveout;
90
2abae5f1 91 /* Parameters used within the SCOP. */
9771b263 92 vec<tree> params;
2abae5f1 93
65b016eb
AK
94 /* Maps an old name to one or more new names. When there are several new
95 names, one has to select the definition corresponding to the immediate
96 dominator. */
97 rename_map_t *rename_map;
98
b0b5710c
AK
99 /* Basic blocks contained in this SESE. */
100 vec<basic_block> bbs;
2abae5f1 101
65b016eb
AK
102 /* A vector of phi nodes to be updated when all arguments are available. The
103 pair contains first the old_phi and second the new_phi. */
104 vec<phi_rename> incomplete_phis;
105
106 /* The condition region generated for this sese. */
107 ifsese if_region;
108
109} *sese_info_p;
2abae5f1 110
bafcb153
AK
111extern sese_info_p new_sese_info (edge, edge);
112extern void free_sese_info (sese_info_p);
113extern void sese_insert_phis_for_liveouts (sese_info_p, basic_block, edge, edge);
bafcb153 114extern struct loop *outermost_loop_in_sese (sese_l &, basic_block);
1cb28772 115extern tree scalar_evolution_in_region (const sese_l &, loop_p, tree);
2ecf4eca 116extern bool scev_analyzable_p (tree, sese_l &);
1cb28772 117extern bool invariant_in_sese_p_rec (tree, const sese_l &, bool *);
bd8d431f
RB
118extern void sese_build_liveouts (sese_info_p);
119extern bool sese_trivially_empty_bb_p (basic_block);
2abae5f1 120
2abae5f1
SP
121/* The number of parameters in REGION. */
122
123static inline unsigned
bafcb153 124sese_nb_params (sese_info_p region)
2abae5f1 125{
65b016eb 126 return region->params.length ();
2abae5f1
SP
127}
128
129/* Checks whether BB is contained in the region delimited by ENTRY and
130 EXIT blocks. */
131
132static inline bool
1cb28772 133bb_in_region (const_basic_block bb, const_basic_block entry, const_basic_block exit)
2abae5f1 134{
a6c764d0
MM
135 /* FIXME: PR67842. */
136#if 0
137 if (flag_checking)
138 {
139 edge e;
140 edge_iterator ei;
141
142 /* Check that there are no edges coming in the region: all the
143 predecessors of EXIT are dominated by ENTRY. */
144 FOR_EACH_EDGE (e, ei, exit->preds)
145 gcc_assert (dominated_by_p (CDI_DOMINATORS, e->src, entry));
146 }
2abae5f1
SP
147#endif
148
149 return dominated_by_p (CDI_DOMINATORS, bb, entry)
150 && !(dominated_by_p (CDI_DOMINATORS, bb, exit)
151 && !dominated_by_p (CDI_DOMINATORS, entry, exit));
152}
153
154/* Checks whether BB is contained in the region delimited by ENTRY and
155 EXIT blocks. */
156
157static inline bool
1cb28772 158bb_in_sese_p (basic_block bb, const sese_l &r)
2abae5f1 159{
bafcb153 160 return bb_in_region (bb, r.entry->dest, r.exit->dest);
2abae5f1
SP
161}
162
a30e5345
SP
163/* Returns true when STMT is defined in REGION. */
164
165static inline bool
1cb28772 166stmt_in_sese_p (gimple *stmt, const sese_l &r)
a30e5345
SP
167{
168 basic_block bb = gimple_bb (stmt);
bafcb153 169 return bb && bb_in_sese_p (bb, r);
a30e5345
SP
170}
171
2abae5f1
SP
172/* Returns true when NAME is defined in REGION. */
173
174static inline bool
1cb28772 175defined_in_sese_p (tree name, const sese_l &r)
2abae5f1 176{
bafcb153 177 return stmt_in_sese_p (SSA_NAME_DEF_STMT (name), r);
2abae5f1
SP
178}
179
180/* Returns true when LOOP is in REGION. */
181
b8698a0f 182static inline bool
1cb28772 183loop_in_sese_p (struct loop *loop, const sese_l &region)
2abae5f1
SP
184{
185 return (bb_in_sese_p (loop->header, region)
186 && bb_in_sese_p (loop->latch, region));
187}
188
189/* Returns the loop depth of LOOP in REGION. The loop depth
190 is the same as the normal loop depth, but limited by a region.
191
192 Example:
193
194 loop_0
195 loop_1
196 {
b8698a0f 197 S0
2abae5f1
SP
198 <- region start
199 S1
200
201 loop_2
202 S2
203
204 S3
205 <- region end
b8698a0f 206 }
2abae5f1
SP
207
208 loop_0 does not exist in the region -> invalid
209 loop_1 exists, but is not completely contained in the region -> depth 0
210 loop_2 is completely contained -> depth 1 */
211
212static inline unsigned int
adba512d 213sese_loop_depth (const sese_l &region, loop_p loop)
2abae5f1
SP
214{
215 unsigned int depth = 0;
216
2abae5f1
SP
217 while (loop_in_sese_p (loop, region))
218 {
219 depth++;
220 loop = loop_outer (loop);
221 }
222
223 return depth;
224}
225
2abae5f1
SP
226/* A single entry single exit specialized for conditions. */
227
228typedef struct ifsese_s {
bafcb153
AK
229 sese_info_p region;
230 sese_info_p true_region;
231 sese_info_p false_region;
2abae5f1
SP
232} *ifsese;
233
bafcb153 234extern ifsese move_sese_in_condition (sese_info_p);
09b574dd 235extern void set_ifsese_condition (ifsese, tree);
2abae5f1
SP
236extern edge get_true_edge_from_guard_bb (basic_block);
237extern edge get_false_edge_from_guard_bb (basic_block);
238
239static inline edge
240if_region_entry (ifsese if_region)
241{
bafcb153 242 return if_region->region->region.entry;
2abae5f1
SP
243}
244
245static inline edge
246if_region_exit (ifsese if_region)
247{
bafcb153 248 return if_region->region->region.exit;
2abae5f1
SP
249}
250
251static inline basic_block
252if_region_get_condition_block (ifsese if_region)
253{
254 return if_region_entry (if_region)->dest;
2abae5f1
SP
255}
256
2abae5f1
SP
257/* Free and compute again all the dominators information. */
258
259static inline void
260recompute_all_dominators (void)
261{
262 mark_irreducible_loops ();
263 free_dominance_info (CDI_DOMINATORS);
2abae5f1 264 calculate_dominance_info (CDI_DOMINATORS);
7009b073
SP
265
266 free_dominance_info (CDI_POST_DOMINATORS);
267 calculate_dominance_info (CDI_POST_DOMINATORS);
2abae5f1
SP
268}
269
65b016eb
AK
270typedef std::pair <gimple *, tree> scalar_use;
271
65ef70d6 272typedef struct gimple_poly_bb
2abae5f1
SP
273{
274 basic_block bb;
efa21390 275 struct poly_bb *pbb;
2abae5f1
SP
276
277 /* Lists containing the restrictions of the conditional statements
278 dominating this bb. This bb can only be executed, if all conditions
279 are true.
b8698a0f 280
2abae5f1 281 Example:
b8698a0f 282
2abae5f1
SP
283 for (i = 0; i <= 20; i++)
284 {
285 A
b8698a0f 286
2abae5f1
SP
287 if (2i <= 8)
288 B
289 }
b8698a0f 290
2abae5f1 291 So for B there is an additional condition (2i <= 8).
b8698a0f 292
2abae5f1
SP
293 List of COND_EXPR and SWITCH_EXPR. A COND_EXPR is true only if the
294 corresponding element in CONDITION_CASES is not NULL_TREE. For a
295 SWITCH_EXPR the corresponding element in CONDITION_CASES is a
296 CASE_LABEL_EXPR. */
355fe088
TS
297 vec<gimple *> conditions;
298 vec<gimple *> condition_cases;
9771b263 299 vec<data_reference_p> data_refs;
65b016eb
AK
300 vec<scalar_use> read_scalar_refs;
301 vec<tree> write_scalar_refs;
65ef70d6 302} *gimple_poly_bb_p;
2abae5f1 303
efa21390
SP
304#define GBB_BB(GBB) (GBB)->bb
305#define GBB_PBB(GBB) (GBB)->pbb
306#define GBB_DATA_REFS(GBB) (GBB)->data_refs
307#define GBB_CONDITIONS(GBB) (GBB)->conditions
308#define GBB_CONDITION_CASES(GBB) (GBB)->condition_cases
2abae5f1
SP
309
310/* Return the innermost loop that contains the basic block GBB. */
311
312static inline struct loop *
65ef70d6 313gbb_loop (gimple_poly_bb_p gbb)
2abae5f1
SP
314{
315 return GBB_BB (gbb)->loop_father;
316}
317
b8698a0f 318/* Returns the gimple loop, that corresponds to the loop_iterator_INDEX.
2abae5f1
SP
319 If there is no corresponding gimple loop, we return NULL. */
320
321static inline loop_p
bafcb153 322gbb_loop_at_index (gimple_poly_bb_p gbb, sese_l &region, int index)
2abae5f1
SP
323{
324 loop_p loop = gbb_loop (gbb);
325 int depth = sese_loop_depth (region, loop);
326
327 while (--depth > index)
328 loop = loop_outer (loop);
329
a68f286c
RB
330 gcc_assert (loop_in_sese_p (loop, region));
331
2abae5f1
SP
332 return loop;
333}
334
335/* The number of common loops in REGION for GBB1 and GBB2. */
336
337static inline int
bafcb153 338nb_common_loops (sese_l &region, gimple_poly_bb_p gbb1, gimple_poly_bb_p gbb2)
2abae5f1
SP
339{
340 loop_p l1 = gbb_loop (gbb1);
341 loop_p l2 = gbb_loop (gbb2);
342 loop_p common = find_common_loop (l1, l2);
b8698a0f 343
2abae5f1
SP
344 return sese_loop_depth (region, common);
345}
346
2abae5f1 347#endif