1 |
38 |
julius |
/* Loop Vectorization
|
2 |
|
|
Copyright (C) 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
|
3 |
|
|
Contributed by Dorit Naishlos <dorit@il.ibm.com>
|
4 |
|
|
|
5 |
|
|
This file is part of GCC.
|
6 |
|
|
|
7 |
|
|
GCC is free software; you can redistribute it and/or modify it under
|
8 |
|
|
the terms of the GNU General Public License as published by the Free
|
9 |
|
|
Software Foundation; either version 3, or (at your option) any later
|
10 |
|
|
version.
|
11 |
|
|
|
12 |
|
|
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
|
13 |
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
14 |
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
15 |
|
|
for more details.
|
16 |
|
|
|
17 |
|
|
You should have received a copy of the GNU General Public License
|
18 |
|
|
along with GCC; see the file COPYING3. If not see
|
19 |
|
|
<http://www.gnu.org/licenses/>. */
|
20 |
|
|
|
21 |
|
|
#ifndef GCC_TREE_VECTORIZER_H
|
22 |
|
|
#define GCC_TREE_VECTORIZER_H
|
23 |
|
|
|
24 |
|
|
#ifdef USE_MAPPED_LOCATION
|
25 |
|
|
typedef source_location LOC;
|
26 |
|
|
#define UNKNOWN_LOC UNKNOWN_LOCATION
|
27 |
|
|
#define EXPR_LOC(e) EXPR_LOCATION(e)
|
28 |
|
|
#define LOC_FILE(l) LOCATION_FILE (l)
|
29 |
|
|
#define LOC_LINE(l) LOCATION_LINE (l)
|
30 |
|
|
#else
|
31 |
|
|
typedef source_locus LOC;
|
32 |
|
|
#define UNKNOWN_LOC NULL
|
33 |
|
|
#define EXPR_LOC(e) EXPR_LOCUS(e)
|
34 |
|
|
#define LOC_FILE(l) (l)->file
|
35 |
|
|
#define LOC_LINE(l) (l)->line
|
36 |
|
|
#endif
|
37 |
|
|
|
38 |
|
|
/* Used for naming of new temporaries. */
|
39 |
|
|
enum vect_var_kind {
|
40 |
|
|
vect_simple_var,
|
41 |
|
|
vect_pointer_var,
|
42 |
|
|
vect_scalar_var
|
43 |
|
|
};
|
44 |
|
|
|
45 |
|
|
/* Defines type of operation. */
|
46 |
|
|
enum operation_type {
|
47 |
|
|
unary_op = 1,
|
48 |
|
|
binary_op,
|
49 |
|
|
ternary_op
|
50 |
|
|
};
|
51 |
|
|
|
52 |
|
|
/* Define type of available alignment support. */
|
53 |
|
|
enum dr_alignment_support {
|
54 |
|
|
dr_unaligned_unsupported,
|
55 |
|
|
dr_unaligned_supported,
|
56 |
|
|
dr_unaligned_software_pipeline,
|
57 |
|
|
dr_aligned
|
58 |
|
|
};
|
59 |
|
|
|
60 |
|
|
/* Define type of def-use cross-iteration cycle. */
|
61 |
|
|
enum vect_def_type {
|
62 |
|
|
vect_constant_def,
|
63 |
|
|
vect_invariant_def,
|
64 |
|
|
vect_loop_def,
|
65 |
|
|
vect_induction_def,
|
66 |
|
|
vect_reduction_def,
|
67 |
|
|
vect_unknown_def_type
|
68 |
|
|
};
|
69 |
|
|
|
70 |
|
|
/* Define verbosity levels. */
|
71 |
|
|
enum verbosity_levels {
|
72 |
|
|
REPORT_NONE,
|
73 |
|
|
REPORT_VECTORIZED_LOOPS,
|
74 |
|
|
REPORT_UNVECTORIZED_LOOPS,
|
75 |
|
|
REPORT_ALIGNMENT,
|
76 |
|
|
REPORT_DR_DETAILS,
|
77 |
|
|
REPORT_BAD_FORM_LOOPS,
|
78 |
|
|
REPORT_OUTER_LOOPS,
|
79 |
|
|
REPORT_DETAILS,
|
80 |
|
|
/* New verbosity levels should be added before this one. */
|
81 |
|
|
MAX_VERBOSITY_LEVEL
|
82 |
|
|
};
|
83 |
|
|
|
84 |
|
|
/*-----------------------------------------------------------------*/
|
85 |
|
|
/* Info on vectorized loops. */
|
86 |
|
|
/*-----------------------------------------------------------------*/
|
87 |
|
|
typedef struct _loop_vec_info {
|
88 |
|
|
|
89 |
|
|
/* The loop to which this info struct refers to. */
|
90 |
|
|
struct loop *loop;
|
91 |
|
|
|
92 |
|
|
/* The loop basic blocks. */
|
93 |
|
|
basic_block *bbs;
|
94 |
|
|
|
95 |
|
|
/* The loop exit_condition. */
|
96 |
|
|
tree exit_cond;
|
97 |
|
|
|
98 |
|
|
/* Number of iterations. */
|
99 |
|
|
tree num_iters;
|
100 |
|
|
|
101 |
|
|
/* Is the loop vectorizable? */
|
102 |
|
|
bool vectorizable;
|
103 |
|
|
|
104 |
|
|
/* Unrolling factor */
|
105 |
|
|
int vectorization_factor;
|
106 |
|
|
|
107 |
|
|
/* Unknown DRs according to which loop was peeled. */
|
108 |
|
|
struct data_reference *unaligned_dr;
|
109 |
|
|
|
110 |
|
|
/* peeling_for_alignment indicates whether peeling for alignment will take
|
111 |
|
|
place, and what the peeling factor should be:
|
112 |
|
|
peeling_for_alignment = X means:
|
113 |
|
|
If X=0: Peeling for alignment will not be applied.
|
114 |
|
|
If X>0: Peel first X iterations.
|
115 |
|
|
If X=-1: Generate a runtime test to calculate the number of iterations
|
116 |
|
|
to be peeled, using the dataref recorded in the field
|
117 |
|
|
unaligned_dr. */
|
118 |
|
|
int peeling_for_alignment;
|
119 |
|
|
|
120 |
|
|
/* The mask used to check the alignment of pointers or arrays. */
|
121 |
|
|
int ptr_mask;
|
122 |
|
|
|
123 |
|
|
/* All data references in the loop. */
|
124 |
|
|
VEC (data_reference_p, heap) *datarefs;
|
125 |
|
|
|
126 |
|
|
/* All data dependences in the loop. */
|
127 |
|
|
VEC (ddr_p, heap) *ddrs;
|
128 |
|
|
|
129 |
|
|
/* Statements in the loop that have data references that are candidates for a
|
130 |
|
|
runtime (loop versioning) misalignment check. */
|
131 |
|
|
VEC(tree,heap) *may_misalign_stmts;
|
132 |
|
|
|
133 |
|
|
/* The loop location in the source. */
|
134 |
|
|
LOC loop_line_number;
|
135 |
|
|
} *loop_vec_info;
|
136 |
|
|
|
137 |
|
|
/* Access Functions. */
|
138 |
|
|
#define LOOP_VINFO_LOOP(L) (L)->loop
|
139 |
|
|
#define LOOP_VINFO_BBS(L) (L)->bbs
|
140 |
|
|
#define LOOP_VINFO_EXIT_COND(L) (L)->exit_cond
|
141 |
|
|
#define LOOP_VINFO_NITERS(L) (L)->num_iters
|
142 |
|
|
#define LOOP_VINFO_VECTORIZABLE_P(L) (L)->vectorizable
|
143 |
|
|
#define LOOP_VINFO_VECT_FACTOR(L) (L)->vectorization_factor
|
144 |
|
|
#define LOOP_VINFO_PTR_MASK(L) (L)->ptr_mask
|
145 |
|
|
#define LOOP_VINFO_DATAREFS(L) (L)->datarefs
|
146 |
|
|
#define LOOP_VINFO_DDRS(L) (L)->ddrs
|
147 |
|
|
#define LOOP_VINFO_INT_NITERS(L) (TREE_INT_CST_LOW ((L)->num_iters))
|
148 |
|
|
#define LOOP_PEELING_FOR_ALIGNMENT(L) (L)->peeling_for_alignment
|
149 |
|
|
#define LOOP_VINFO_UNALIGNED_DR(L) (L)->unaligned_dr
|
150 |
|
|
#define LOOP_VINFO_MAY_MISALIGN_STMTS(L) (L)->may_misalign_stmts
|
151 |
|
|
#define LOOP_VINFO_LOC(L) (L)->loop_line_number
|
152 |
|
|
|
153 |
|
|
#define LOOP_VINFO_NITERS_KNOWN_P(L) \
|
154 |
|
|
(host_integerp ((L)->num_iters,0) \
|
155 |
|
|
&& TREE_INT_CST_LOW ((L)->num_iters) > 0)
|
156 |
|
|
|
157 |
|
|
/*-----------------------------------------------------------------*/
|
158 |
|
|
/* Info on vectorized defs. */
|
159 |
|
|
/*-----------------------------------------------------------------*/
|
160 |
|
|
enum stmt_vec_info_type {
|
161 |
|
|
undef_vec_info_type = 0,
|
162 |
|
|
load_vec_info_type,
|
163 |
|
|
store_vec_info_type,
|
164 |
|
|
op_vec_info_type,
|
165 |
|
|
assignment_vec_info_type,
|
166 |
|
|
condition_vec_info_type,
|
167 |
|
|
reduc_vec_info_type
|
168 |
|
|
};
|
169 |
|
|
|
170 |
|
|
typedef struct data_reference *dr_p;
|
171 |
|
|
DEF_VEC_P(dr_p);
|
172 |
|
|
DEF_VEC_ALLOC_P(dr_p,heap);
|
173 |
|
|
|
174 |
|
|
typedef struct _stmt_vec_info {
|
175 |
|
|
|
176 |
|
|
enum stmt_vec_info_type type;
|
177 |
|
|
|
178 |
|
|
/* The stmt to which this info struct refers to. */
|
179 |
|
|
tree stmt;
|
180 |
|
|
|
181 |
|
|
/* The loop_vec_info with respect to which STMT is vectorized. */
|
182 |
|
|
loop_vec_info loop_vinfo;
|
183 |
|
|
|
184 |
|
|
/* Not all stmts in the loop need to be vectorized. e.g, the incrementation
|
185 |
|
|
of the loop induction variable and computation of array indexes. relevant
|
186 |
|
|
indicates whether the stmt needs to be vectorized. */
|
187 |
|
|
bool relevant;
|
188 |
|
|
|
189 |
|
|
/* Indicates whether this stmts is part of a computation whose result is
|
190 |
|
|
used outside the loop. */
|
191 |
|
|
bool live;
|
192 |
|
|
|
193 |
|
|
/* The vector type to be used. */
|
194 |
|
|
tree vectype;
|
195 |
|
|
|
196 |
|
|
/* The vectorized version of the stmt. */
|
197 |
|
|
tree vectorized_stmt;
|
198 |
|
|
|
199 |
|
|
|
200 |
|
|
/** The following is relevant only for stmts that contain a non-scalar
|
201 |
|
|
data-ref (array/pointer/struct access). A GIMPLE stmt is expected to have
|
202 |
|
|
at most one such data-ref. **/
|
203 |
|
|
|
204 |
|
|
/* Information about the data-ref (access function, etc). */
|
205 |
|
|
struct data_reference *data_ref_info;
|
206 |
|
|
|
207 |
|
|
/* Stmt is part of some pattern (computation idiom) */
|
208 |
|
|
bool in_pattern_p;
|
209 |
|
|
|
210 |
|
|
/* Used for various bookkeeping purposes, generally holding a pointer to
|
211 |
|
|
some other stmt S that is in some way "related" to this stmt.
|
212 |
|
|
Current use of this field is:
|
213 |
|
|
If this stmt is part of a pattern (i.e. the field 'in_pattern_p' is
|
214 |
|
|
true): S is the "pattern stmt" that represents (and replaces) the
|
215 |
|
|
sequence of stmts that constitutes the pattern. Similarly, the
|
216 |
|
|
related_stmt of the "pattern stmt" points back to this stmt (which is
|
217 |
|
|
the last stmt in the original sequence of stmts that constitutes the
|
218 |
|
|
pattern). */
|
219 |
|
|
tree related_stmt;
|
220 |
|
|
|
221 |
|
|
/* List of datarefs that are known to have the same alignment as the dataref
|
222 |
|
|
of this stmt. */
|
223 |
|
|
VEC(dr_p,heap) *same_align_refs;
|
224 |
|
|
|
225 |
|
|
/* Classify the def of this stmt. */
|
226 |
|
|
enum vect_def_type def_type;
|
227 |
|
|
|
228 |
|
|
} *stmt_vec_info;
|
229 |
|
|
|
230 |
|
|
/* Access Functions. */
|
231 |
|
|
#define STMT_VINFO_TYPE(S) (S)->type
|
232 |
|
|
#define STMT_VINFO_STMT(S) (S)->stmt
|
233 |
|
|
#define STMT_VINFO_LOOP_VINFO(S) (S)->loop_vinfo
|
234 |
|
|
#define STMT_VINFO_RELEVANT_P(S) (S)->relevant
|
235 |
|
|
#define STMT_VINFO_LIVE_P(S) (S)->live
|
236 |
|
|
#define STMT_VINFO_VECTYPE(S) (S)->vectype
|
237 |
|
|
#define STMT_VINFO_VEC_STMT(S) (S)->vectorized_stmt
|
238 |
|
|
#define STMT_VINFO_DATA_REF(S) (S)->data_ref_info
|
239 |
|
|
#define STMT_VINFO_IN_PATTERN_P(S) (S)->in_pattern_p
|
240 |
|
|
#define STMT_VINFO_RELATED_STMT(S) (S)->related_stmt
|
241 |
|
|
#define STMT_VINFO_SAME_ALIGN_REFS(S) (S)->same_align_refs
|
242 |
|
|
#define STMT_VINFO_DEF_TYPE(S) (S)->def_type
|
243 |
|
|
|
244 |
|
|
static inline void set_stmt_info (stmt_ann_t ann, stmt_vec_info stmt_info);
|
245 |
|
|
static inline stmt_vec_info vinfo_for_stmt (tree stmt);
|
246 |
|
|
|
247 |
|
|
static inline void
|
248 |
|
|
set_stmt_info (stmt_ann_t ann, stmt_vec_info stmt_info)
|
249 |
|
|
{
|
250 |
|
|
if (ann)
|
251 |
|
|
ann->common.aux = (char *) stmt_info;
|
252 |
|
|
}
|
253 |
|
|
|
254 |
|
|
static inline stmt_vec_info
|
255 |
|
|
vinfo_for_stmt (tree stmt)
|
256 |
|
|
{
|
257 |
|
|
stmt_ann_t ann = stmt_ann (stmt);
|
258 |
|
|
return ann ? (stmt_vec_info) ann->common.aux : NULL;
|
259 |
|
|
}
|
260 |
|
|
|
261 |
|
|
/*-----------------------------------------------------------------*/
|
262 |
|
|
/* Info on data references alignment. */
|
263 |
|
|
/*-----------------------------------------------------------------*/
|
264 |
|
|
|
265 |
|
|
/* Reflects actual alignment of first access in the vectorized loop,
|
266 |
|
|
taking into account peeling/versioning if applied. */
|
267 |
|
|
#define DR_MISALIGNMENT(DR) (DR)->aux
|
268 |
|
|
|
269 |
|
|
static inline bool
|
270 |
|
|
aligned_access_p (struct data_reference *data_ref_info)
|
271 |
|
|
{
|
272 |
|
|
return (DR_MISALIGNMENT (data_ref_info) == 0);
|
273 |
|
|
}
|
274 |
|
|
|
275 |
|
|
static inline bool
|
276 |
|
|
known_alignment_for_access_p (struct data_reference *data_ref_info)
|
277 |
|
|
{
|
278 |
|
|
return (DR_MISALIGNMENT (data_ref_info) != -1);
|
279 |
|
|
}
|
280 |
|
|
|
281 |
|
|
/* Perform signed modulo, always returning a non-negative value. */
|
282 |
|
|
#define VECT_SMODULO(x,y) ((x) % (y) < 0 ? ((x) % (y) + (y)) : (x) % (y))
|
283 |
|
|
|
284 |
|
|
/* vect_dump will be set to stderr or dump_file if exist. */
|
285 |
|
|
extern FILE *vect_dump;
|
286 |
|
|
extern enum verbosity_levels vect_verbosity_level;
|
287 |
|
|
|
288 |
|
|
/* Number of loops, at the beginning of vectorization. */
|
289 |
|
|
extern unsigned int vect_loops_num;
|
290 |
|
|
|
291 |
|
|
/* Bitmap of virtual variables to be renamed. */
|
292 |
|
|
extern bitmap vect_vnames_to_rename;
|
293 |
|
|
|
294 |
|
|
/*-----------------------------------------------------------------*/
|
295 |
|
|
/* Function prototypes. */
|
296 |
|
|
/*-----------------------------------------------------------------*/
|
297 |
|
|
|
298 |
|
|
/*************************************************************************
|
299 |
|
|
Simple Loop Peeling Utilities - in tree-vectorizer.c
|
300 |
|
|
*************************************************************************/
|
301 |
|
|
/* Entry point for peeling of simple loops.
|
302 |
|
|
Peel the first/last iterations of a loop.
|
303 |
|
|
It can be used outside of the vectorizer for loops that are simple enough
|
304 |
|
|
(see function documentation). In the vectorizer it is used to peel the
|
305 |
|
|
last few iterations when the loop bound is unknown or does not evenly
|
306 |
|
|
divide by the vectorization factor, and to peel the first few iterations
|
307 |
|
|
to force the alignment of data references in the loop. */
|
308 |
|
|
extern struct loop *slpeel_tree_peel_loop_to_edge
|
309 |
|
|
(struct loop *, struct loops *, edge, tree, tree, bool);
|
310 |
|
|
extern void slpeel_make_loop_iterate_ntimes (struct loop *, tree);
|
311 |
|
|
extern bool slpeel_can_duplicate_loop_p (struct loop *, edge);
|
312 |
|
|
#ifdef ENABLE_CHECKING
|
313 |
|
|
extern void slpeel_verify_cfg_after_peeling (struct loop *, struct loop *);
|
314 |
|
|
#endif
|
315 |
|
|
|
316 |
|
|
|
317 |
|
|
/*************************************************************************
|
318 |
|
|
General Vectorization Utilities
|
319 |
|
|
*************************************************************************/
|
320 |
|
|
/** In tree-vectorizer.c **/
|
321 |
|
|
extern tree get_vectype_for_scalar_type (tree);
|
322 |
|
|
extern bool vect_is_simple_use (tree, loop_vec_info, tree *, tree *,
|
323 |
|
|
enum vect_def_type *);
|
324 |
|
|
extern bool vect_is_simple_iv_evolution (unsigned, tree, tree *, tree *);
|
325 |
|
|
extern tree vect_is_simple_reduction (struct loop *, tree);
|
326 |
|
|
extern bool vect_can_force_dr_alignment_p (tree, unsigned int);
|
327 |
|
|
extern enum dr_alignment_support vect_supportable_dr_alignment
|
328 |
|
|
(struct data_reference *);
|
329 |
|
|
extern bool reduction_code_for_scalar_code (enum tree_code, enum tree_code *);
|
330 |
|
|
/* Creation and deletion of loop and stmt info structs. */
|
331 |
|
|
extern loop_vec_info new_loop_vec_info (struct loop *loop);
|
332 |
|
|
extern void destroy_loop_vec_info (loop_vec_info);
|
333 |
|
|
extern stmt_vec_info new_stmt_vec_info (tree stmt, loop_vec_info);
|
334 |
|
|
/* Main driver. */
|
335 |
|
|
extern void vectorize_loops (struct loops *);
|
336 |
|
|
|
337 |
|
|
|
338 |
|
|
/** In tree-vect-analyze.c **/
|
339 |
|
|
/* Driver for analysis stage. */
|
340 |
|
|
extern loop_vec_info vect_analyze_loop (struct loop *);
|
341 |
|
|
|
342 |
|
|
|
343 |
|
|
/** In tree-vect-patterns.c **/
|
344 |
|
|
/* Pattern recognition functions.
|
345 |
|
|
Additional pattern recognition functions can (and will) be added
|
346 |
|
|
in the future. */
|
347 |
|
|
typedef tree (* vect_recog_func_ptr) (tree, tree *, tree *);
|
348 |
|
|
#define NUM_PATTERNS 3
|
349 |
|
|
void vect_pattern_recog (loop_vec_info);
|
350 |
|
|
|
351 |
|
|
|
352 |
|
|
/** In tree-vect-transform.c **/
|
353 |
|
|
extern bool vectorizable_load (tree, block_stmt_iterator *, tree *);
|
354 |
|
|
extern bool vectorizable_store (tree, block_stmt_iterator *, tree *);
|
355 |
|
|
extern bool vectorizable_operation (tree, block_stmt_iterator *, tree *);
|
356 |
|
|
extern bool vectorizable_assignment (tree, block_stmt_iterator *, tree *);
|
357 |
|
|
extern bool vectorizable_condition (tree, block_stmt_iterator *, tree *);
|
358 |
|
|
extern bool vectorizable_live_operation (tree, block_stmt_iterator *, tree *);
|
359 |
|
|
extern bool vectorizable_reduction (tree, block_stmt_iterator *, tree *);
|
360 |
|
|
/* Driver for transformation stage. */
|
361 |
|
|
extern void vect_transform_loop (loop_vec_info, struct loops *);
|
362 |
|
|
|
363 |
|
|
/*************************************************************************
|
364 |
|
|
Vectorization Debug Information - in tree-vectorizer.c
|
365 |
|
|
*************************************************************************/
|
366 |
|
|
extern bool vect_print_dump_info (enum verbosity_levels);
|
367 |
|
|
extern void vect_set_verbosity_level (const char *);
|
368 |
|
|
extern LOC find_loop_location (struct loop *);
|
369 |
|
|
|
370 |
|
|
#endif /* GCC_TREE_VECTORIZER_H */
|