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)
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/>. */
25 typedef hash_map
<tree
, tree
> parameter_rename_map_t
;
27 /* A Single Entry, Single Exit region is a part of the CFG delimited
31 sese_l (edge e
, edge x
) : entry (e
), exit (x
) {}
33 /* This is to push objects of sese_l in a vec. */
34 sese_l (int i
) : entry (NULL
), exit (NULL
) { gcc_assert (i
== 0); }
36 operator bool () const { return entry
&& exit
; }
39 operator= (const sese_l
&s
)
50 /* Get the entry of an sese S. */
52 static inline basic_block
53 get_entry_bb (sese_l
&s
)
58 /* Get the exit of an sese S. */
60 static inline basic_block
61 get_exit_bb (sese_l
&s
)
66 /* A helper structure for bookkeeping information about a scop in graphite. */
67 typedef struct sese_info_t
69 /* The SESE region. */
72 /* Parameters used within the SCOP. */
75 /* Parameters to be renamed. */
76 parameter_rename_map_t
*parameter_rename_map
;
78 /* Loops completely contained in this SESE. */
80 vec
<loop_p
> loop_nest
;
82 /* Basic blocks contained in this SESE. */
86 #define SESE_PARAMS(S) (S->params)
87 #define SESE_LOOPS(S) (S->loops)
88 #define SESE_LOOP_NEST(S) (S->loop_nest)
90 extern sese_info_p
new_sese_info (edge
, edge
);
91 extern void free_sese_info (sese_info_p
);
92 extern void sese_insert_phis_for_liveouts (sese_info_p
, basic_block
, edge
, edge
);
93 extern void build_sese_loop_nests (sese_info_p
);
94 extern edge
copy_bb_and_scalar_dependences (basic_block
, sese_info_p
, edge
,
96 extern struct loop
*outermost_loop_in_sese (sese_l
&, basic_block
);
97 extern tree
scalar_evolution_in_region (sese_l
&, loop_p
, tree
);
98 extern bool invariant_in_sese_p_rec (tree
, sese_l
&);
100 /* Check that SESE contains LOOP. */
103 sese_contains_loop (sese_info_p sese
, struct loop
*loop
)
105 return bitmap_bit_p (SESE_LOOPS (sese
), loop
->num
);
108 /* The number of parameters in REGION. */
110 static inline unsigned
111 sese_nb_params (sese_info_p region
)
113 return SESE_PARAMS (region
).length ();
116 /* Checks whether BB is contained in the region delimited by ENTRY and
120 bb_in_region (basic_block bb
, basic_block entry
, basic_block exit
)
122 #ifdef ENABLE_CHECKING
127 /* Check that there are no edges coming in the region: all the
128 predecessors of EXIT are dominated by ENTRY. */
129 FOR_EACH_EDGE (e
, ei
, exit
->preds
)
130 dominated_by_p (CDI_DOMINATORS
, e
->src
, entry
);
134 return dominated_by_p (CDI_DOMINATORS
, bb
, entry
)
135 && !(dominated_by_p (CDI_DOMINATORS
, bb
, exit
)
136 && !dominated_by_p (CDI_DOMINATORS
, entry
, exit
));
139 /* Checks whether BB is contained in the region delimited by ENTRY and
143 bb_in_sese_p (basic_block bb
, sese_l
&r
)
145 return bb_in_region (bb
, r
.entry
->dest
, r
.exit
->dest
);
148 /* Returns true when STMT is defined in REGION. */
151 stmt_in_sese_p (gimple
*stmt
, sese_l
&r
)
153 basic_block bb
= gimple_bb (stmt
);
154 return bb
&& bb_in_sese_p (bb
, r
);
157 /* Returns true when NAME is defined in REGION. */
160 defined_in_sese_p (tree name
, sese_l
&r
)
162 return stmt_in_sese_p (SSA_NAME_DEF_STMT (name
), r
);
165 /* Returns true when LOOP is in REGION. */
168 loop_in_sese_p (struct loop
*loop
, sese_l
®ion
)
170 return (bb_in_sese_p (loop
->header
, region
)
171 && bb_in_sese_p (loop
->latch
, region
));
174 /* Returns the loop depth of LOOP in REGION. The loop depth
175 is the same as the normal loop depth, but limited by a region.
193 loop_0 does not exist in the region -> invalid
194 loop_1 exists, but is not completely contained in the region -> depth 0
195 loop_2 is completely contained -> depth 1 */
197 static inline unsigned int
198 sese_loop_depth (sese_l
®ion
, loop_p loop
)
200 unsigned int depth
= 0;
202 while (loop_in_sese_p (loop
, region
))
205 loop
= loop_outer (loop
);
211 /* Splits BB to make a single entry single exit region. */
213 static inline sese_info_p
214 split_region_for_bb (basic_block bb
)
218 if (single_pred_p (bb
))
219 entry
= single_pred_edge (bb
);
222 entry
= split_block_after_labels (bb
);
223 bb
= single_succ (bb
);
226 if (single_succ_p (bb
))
227 exit
= single_succ_edge (bb
);
230 gimple_stmt_iterator gsi
= gsi_last_bb (bb
);
232 exit
= split_block (bb
, gsi_stmt (gsi
));
235 return new_sese_info (entry
, exit
);
240 /* A single entry single exit specialized for conditions. */
242 typedef struct ifsese_s
{
244 sese_info_p true_region
;
245 sese_info_p false_region
;
248 extern void if_region_set_false_region (ifsese
, sese_info_p
);
249 extern ifsese
move_sese_in_condition (sese_info_p
);
250 extern edge
get_true_edge_from_guard_bb (basic_block
);
251 extern edge
get_false_edge_from_guard_bb (basic_block
);
252 extern void set_ifsese_condition (ifsese
, tree
);
255 if_region_entry (ifsese if_region
)
257 return if_region
->region
->region
.entry
;
261 if_region_exit (ifsese if_region
)
263 return if_region
->region
->region
.exit
;
266 static inline basic_block
267 if_region_get_condition_block (ifsese if_region
)
269 return if_region_entry (if_region
)->dest
;
272 /* Free and compute again all the dominators information. */
275 recompute_all_dominators (void)
277 mark_irreducible_loops ();
278 free_dominance_info (CDI_DOMINATORS
);
279 calculate_dominance_info (CDI_DOMINATORS
);
281 free_dominance_info (CDI_POST_DOMINATORS
);
282 calculate_dominance_info (CDI_POST_DOMINATORS
);
285 typedef struct gimple_poly_bb
290 /* Lists containing the restrictions of the conditional statements
291 dominating this bb. This bb can only be executed, if all conditions
296 for (i = 0; i <= 20; i++)
304 So for B there is an additional condition (2i <= 8).
306 List of COND_EXPR and SWITCH_EXPR. A COND_EXPR is true only if the
307 corresponding element in CONDITION_CASES is not NULL_TREE. For a
308 SWITCH_EXPR the corresponding element in CONDITION_CASES is a
310 vec
<gimple
*> conditions
;
311 vec
<gimple
*> condition_cases
;
312 vec
<data_reference_p
> data_refs
;
315 #define GBB_BB(GBB) (GBB)->bb
316 #define GBB_PBB(GBB) (GBB)->pbb
317 #define GBB_DATA_REFS(GBB) (GBB)->data_refs
318 #define GBB_CONDITIONS(GBB) (GBB)->conditions
319 #define GBB_CONDITION_CASES(GBB) (GBB)->condition_cases
321 /* Return the innermost loop that contains the basic block GBB. */
323 static inline struct loop
*
324 gbb_loop (gimple_poly_bb_p gbb
)
326 return GBB_BB (gbb
)->loop_father
;
329 /* Returns the gimple loop, that corresponds to the loop_iterator_INDEX.
330 If there is no corresponding gimple loop, we return NULL. */
333 gbb_loop_at_index (gimple_poly_bb_p gbb
, sese_l
®ion
, int index
)
335 loop_p loop
= gbb_loop (gbb
);
336 int depth
= sese_loop_depth (region
, loop
);
338 while (--depth
> index
)
339 loop
= loop_outer (loop
);
341 gcc_assert (loop_in_sese_p (loop
, region
));
346 /* The number of common loops in REGION for GBB1 and GBB2. */
349 nb_common_loops (sese_l
®ion
, gimple_poly_bb_p gbb1
, gimple_poly_bb_p gbb2
)
351 loop_p l1
= gbb_loop (gbb1
);
352 loop_p l2
= gbb_loop (gbb2
);
353 loop_p common
= find_common_loop (l1
, l2
);
355 return sese_loop_depth (region
, common
);
358 /* Return true when DEF can be analyzed in REGION by the scalar
359 evolution analyzer. */
362 scev_analyzable_p (tree def
, sese_l
®ion
)
366 tree type
= TREE_TYPE (def
);
368 /* When Graphite generates code for a scev, the code generator
369 expresses the scev in function of a single induction variable.
370 This is unsafe for floating point computations, as it may replace
371 a floating point sum reduction with a multiplication. The
372 following test returns false for non integer types to avoid such
374 if (!INTEGRAL_TYPE_P (type
)
375 && !POINTER_TYPE_P (type
))
378 loop
= loop_containing_stmt (SSA_NAME_DEF_STMT (def
));
379 scev
= scalar_evolution_in_region (region
, loop
, def
);
381 return !chrec_contains_undetermined (scev
)
382 && (TREE_CODE (scev
) != SSA_NAME
383 || !defined_in_sese_p (scev
, region
))
384 && (tree_does_not_contain_chrecs (scev
)
385 || evolution_function_is_affine_p (scev
));