]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/sese.h
a scalar depending on vdefs in the current region is not invariant
[thirdparty/gcc.git] / gcc / sese.h
CommitLineData
c6bb733d 1/* Single entry single exit control flow regions.
d353bf18 2 Copyright (C) 2008-2015 Free Software Foundation, Inc.
c6bb733d 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
fa4dba85 25typedef hash_map<tree, tree> parameter_rename_map_t;
26
c6bb733d 27/* A Single Entry, Single Exit region is a part of the CFG delimited
28 by two edges. */
f032380c 29struct sese_l
c6bb733d 30{
f032380c 31 sese_l (edge e, edge x) : entry (e), exit (x) {}
32
f032380c 33 operator bool () const { return entry && exit; }
34
f032380c 35 edge entry;
36 edge exit;
37};
38
39/* Get the entry of an sese S. */
40
41static inline basic_block
42get_entry_bb (sese_l &s)
43{
44 return s.entry->dest;
45}
46
47/* Get the exit of an sese S. */
48
49static inline basic_block
50get_exit_bb (sese_l &s)
51{
52 return s.exit->src;
53}
54
55/* A helper structure for bookkeeping information about a scop in graphite. */
56typedef struct sese_info_t
57{
58 /* The SESE region. */
59 sese_l region;
c6bb733d 60
61 /* Parameters used within the SCOP. */
f1f41a6c 62 vec<tree> params;
c6bb733d 63
fa4dba85 64 /* Parameters to be renamed. */
65 parameter_rename_map_t *parameter_rename_map;
66
e08f2b05 67 /* Loops completely contained in this SESE. */
c6bb733d 68 bitmap loops;
f1f41a6c 69 vec<loop_p> loop_nest;
0e526381 70
71 /* Basic blocks contained in this SESE. */
72 vec<basic_block> bbs;
f032380c 73} *sese_info_p;
c6bb733d 74
c6bb733d 75#define SESE_PARAMS(S) (S->params)
c6bb733d 76#define SESE_LOOPS(S) (S->loops)
77#define SESE_LOOP_NEST(S) (S->loop_nest)
c6bb733d 78
f032380c 79extern sese_info_p new_sese_info (edge, edge);
80extern void free_sese_info (sese_info_p);
81extern void sese_insert_phis_for_liveouts (sese_info_p, basic_block, edge, edge);
82extern void build_sese_loop_nests (sese_info_p);
83extern edge copy_bb_and_scalar_dependences (basic_block, sese_info_p, edge,
f1f41a6c 84 vec<tree> , bool *);
f032380c 85extern struct loop *outermost_loop_in_sese (sese_l &, basic_block);
86extern tree scalar_evolution_in_region (sese_l &, loop_p, tree);
13f421d5 87extern bool invariant_in_sese_p_rec (tree, sese_l &, bool *);
c6bb733d 88
89/* Check that SESE contains LOOP. */
90
91static inline bool
f032380c 92sese_contains_loop (sese_info_p sese, struct loop *loop)
c6bb733d 93{
94 return bitmap_bit_p (SESE_LOOPS (sese), loop->num);
95}
96
97/* The number of parameters in REGION. */
98
99static inline unsigned
f032380c 100sese_nb_params (sese_info_p region)
c6bb733d 101{
f1f41a6c 102 return SESE_PARAMS (region).length ();
c6bb733d 103}
104
105/* Checks whether BB is contained in the region delimited by ENTRY and
106 EXIT blocks. */
107
108static inline bool
109bb_in_region (basic_block bb, basic_block entry, basic_block exit)
110{
111#ifdef ENABLE_CHECKING
112 {
113 edge e;
114 edge_iterator ei;
115
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);
c6bb733d 120 }
121#endif
122
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));
126}
127
128/* Checks whether BB is contained in the region delimited by ENTRY and
129 EXIT blocks. */
130
131static inline bool
f032380c 132bb_in_sese_p (basic_block bb, sese_l &r)
c6bb733d 133{
f032380c 134 return bb_in_region (bb, r.entry->dest, r.exit->dest);
c6bb733d 135}
136
93514494 137/* Returns true when STMT is defined in REGION. */
138
139static inline bool
f032380c 140stmt_in_sese_p (gimple *stmt, sese_l &r)
93514494 141{
142 basic_block bb = gimple_bb (stmt);
f032380c 143 return bb && bb_in_sese_p (bb, r);
93514494 144}
145
c6bb733d 146/* Returns true when NAME is defined in REGION. */
147
148static inline bool
f032380c 149defined_in_sese_p (tree name, sese_l &r)
c6bb733d 150{
f032380c 151 return stmt_in_sese_p (SSA_NAME_DEF_STMT (name), r);
c6bb733d 152}
153
154/* Returns true when LOOP is in REGION. */
155
48e1416a 156static inline bool
f032380c 157loop_in_sese_p (struct loop *loop, sese_l &region)
c6bb733d 158{
159 return (bb_in_sese_p (loop->header, region)
160 && bb_in_sese_p (loop->latch, region));
161}
162
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.
165
166 Example:
167
168 loop_0
169 loop_1
170 {
48e1416a 171 S0
c6bb733d 172 <- region start
173 S1
174
175 loop_2
176 S2
177
178 S3
179 <- region end
48e1416a 180 }
c6bb733d 181
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 */
185
186static inline unsigned int
f032380c 187sese_loop_depth (sese_l &region, loop_p loop)
c6bb733d 188{
189 unsigned int depth = 0;
190
c6bb733d 191 while (loop_in_sese_p (loop, region))
192 {
193 depth++;
194 loop = loop_outer (loop);
195 }
196
197 return depth;
198}
199
c6bb733d 200/* A single entry single exit specialized for conditions. */
201
202typedef struct ifsese_s {
f032380c 203 sese_info_p region;
204 sese_info_p true_region;
205 sese_info_p false_region;
c6bb733d 206} *ifsese;
207
f032380c 208extern void if_region_set_false_region (ifsese, sese_info_p);
209extern ifsese move_sese_in_condition (sese_info_p);
c6bb733d 210extern edge get_true_edge_from_guard_bb (basic_block);
211extern edge get_false_edge_from_guard_bb (basic_block);
2487de19 212extern void set_ifsese_condition (ifsese, tree);
c6bb733d 213
214static inline edge
215if_region_entry (ifsese if_region)
216{
f032380c 217 return if_region->region->region.entry;
c6bb733d 218}
219
220static inline edge
221if_region_exit (ifsese if_region)
222{
f032380c 223 return if_region->region->region.exit;
c6bb733d 224}
225
226static inline basic_block
227if_region_get_condition_block (ifsese if_region)
228{
229 return if_region_entry (if_region)->dest;
c6bb733d 230}
231
c6bb733d 232/* Free and compute again all the dominators information. */
233
234static inline void
235recompute_all_dominators (void)
236{
237 mark_irreducible_loops ();
238 free_dominance_info (CDI_DOMINATORS);
c6bb733d 239 calculate_dominance_info (CDI_DOMINATORS);
7eb20e71 240
241 free_dominance_info (CDI_POST_DOMINATORS);
242 calculate_dominance_info (CDI_POST_DOMINATORS);
c6bb733d 243}
244
e0c0be18 245typedef struct gimple_poly_bb
c6bb733d 246{
247 basic_block bb;
8c6b3774 248 struct poly_bb *pbb;
c6bb733d 249
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.
48e1416a 253
c6bb733d 254 Example:
48e1416a 255
c6bb733d 256 for (i = 0; i <= 20; i++)
257 {
258 A
48e1416a 259
c6bb733d 260 if (2i <= 8)
261 B
262 }
48e1416a 263
c6bb733d 264 So for B there is an additional condition (2i <= 8).
48e1416a 265
c6bb733d 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. */
42acab1c 270 vec<gimple *> conditions;
271 vec<gimple *> condition_cases;
f1f41a6c 272 vec<data_reference_p> data_refs;
e0c0be18 273} *gimple_poly_bb_p;
c6bb733d 274
8c6b3774 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
c6bb733d 280
281/* Return the innermost loop that contains the basic block GBB. */
282
283static inline struct loop *
e0c0be18 284gbb_loop (gimple_poly_bb_p gbb)
c6bb733d 285{
286 return GBB_BB (gbb)->loop_father;
287}
288
48e1416a 289/* Returns the gimple loop, that corresponds to the loop_iterator_INDEX.
c6bb733d 290 If there is no corresponding gimple loop, we return NULL. */
291
292static inline loop_p
f032380c 293gbb_loop_at_index (gimple_poly_bb_p gbb, sese_l &region, int index)
c6bb733d 294{
295 loop_p loop = gbb_loop (gbb);
296 int depth = sese_loop_depth (region, loop);
297
298 while (--depth > index)
299 loop = loop_outer (loop);
300
f032380c 301 gcc_assert (loop_in_sese_p (loop, region));
c6bb733d 302
303 return loop;
304}
305
306/* The number of common loops in REGION for GBB1 and GBB2. */
307
308static inline int
f032380c 309nb_common_loops (sese_l &region, gimple_poly_bb_p gbb1, gimple_poly_bb_p gbb2)
c6bb733d 310{
311 loop_p l1 = gbb_loop (gbb1);
312 loop_p l2 = gbb_loop (gbb2);
313 loop_p common = find_common_loop (l1, l2);
48e1416a 314
c6bb733d 315 return sese_loop_depth (region, common);
316}
317
4ed27c8e 318/* Return true when DEF can be analyzed in REGION by the scalar
319 evolution analyzer. */
320
321static inline bool
f032380c 322scev_analyzable_p (tree def, sese_l &region)
4ed27c8e 323{
9f6a9eed 324 loop_p loop;
325 tree scev;
326 tree type = TREE_TYPE (def);
327
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;
337
338 loop = loop_containing_stmt (SSA_NAME_DEF_STMT (def));
339 scev = scalar_evolution_in_region (region, loop, def);
4ed27c8e 340
341 return !chrec_contains_undetermined (scev)
4934c3ba 342 && (TREE_CODE (scev) != SSA_NAME
343 || !defined_in_sese_p (scev, region))
32a6e336 344 && (tree_does_not_contain_chrecs (scev)
345 || evolution_function_is_affine_p (scev));
4ed27c8e 346}
347
c6bb733d 348#endif