2 Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
3 Contributed by Dorit Naishlos <dorit@il.ibm.com>
5 This file is part of GCC.
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 2, or (at your option) any later
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
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
22 #ifndef GCC_TREE_VECTORIZER_H
23 #define GCC_TREE_VECTORIZER_H
25 #ifdef USE_MAPPED_LOCATION
26 typedef source_location LOC
;
27 #define UNKNOWN_LOC UNKNOWN_LOCATION
28 #define EXPR_LOC(e) EXPR_LOCATION(e)
29 #define LOC_FILE(l) LOCATION_FILE (l)
30 #define LOC_LINE(l) LOCATION_LINE (l)
32 typedef source_locus LOC
;
33 #define UNKNOWN_LOC NULL
34 #define EXPR_LOC(e) EXPR_LOCUS(e)
35 #define LOC_FILE(l) (l)->file
36 #define LOC_LINE(l) (l)->line
39 /* Used for naming of new temporaries. */
46 /* Defines type of operation. */
53 /* Define type of available alignment support. */
54 enum dr_alignment_support
{
55 dr_unaligned_unsupported
,
56 dr_unaligned_supported
,
57 dr_unaligned_software_pipeline
,
61 /* Define type of def-use cross-iteration cycle. */
71 /* Define verbosity levels. */
72 enum verbosity_levels
{
74 REPORT_VECTORIZED_LOOPS
,
75 REPORT_UNVECTORIZED_LOOPS
,
78 REPORT_BAD_FORM_LOOPS
,
81 /* New verbosity levels should be added before this one. */
85 /*-----------------------------------------------------------------*/
86 /* Info on vectorized loops. */
87 /*-----------------------------------------------------------------*/
88 typedef struct _loop_vec_info
{
90 /* The loop to which this info struct refers to. */
93 /* The loop basic blocks. */
96 /* The loop exit_condition. */
99 /* Number of iterations. */
102 /* Is the loop vectorizable? */
105 /* Unrolling factor */
106 int vectorization_factor
;
108 /* Unknown DRs according to which loop was peeled. */
109 struct data_reference
*unaligned_dr
;
111 /* peeling_for_alignment indicates whether peeling for alignment will take
112 place, and what the peeling factor should be:
113 peeling_for_alignment = X means:
114 If X=0: Peeling for alignment will not be applied.
115 If X>0: Peel first X iterations.
116 If X=-1: Generate a runtime test to calculate the number of iterations
117 to be peeled, using the dataref recorded in the field
119 int peeling_for_alignment
;
121 /* The mask used to check the alignment of pointers or arrays. */
124 /* All data references in the loop. */
125 VEC (data_reference_p
, heap
) *datarefs
;
127 /* All data dependences in the loop. */
128 VEC (ddr_p
, heap
) *ddrs
;
130 /* Statements in the loop that have data references that are candidates for a
131 runtime (loop versioning) misalignment check. */
132 VEC(tree
,heap
) *may_misalign_stmts
;
134 /* The loop location in the source. */
135 LOC loop_line_number
;
138 /* Access Functions. */
139 #define LOOP_VINFO_LOOP(L) (L)->loop
140 #define LOOP_VINFO_BBS(L) (L)->bbs
141 #define LOOP_VINFO_EXIT_COND(L) (L)->exit_cond
142 #define LOOP_VINFO_NITERS(L) (L)->num_iters
143 #define LOOP_VINFO_VECTORIZABLE_P(L) (L)->vectorizable
144 #define LOOP_VINFO_VECT_FACTOR(L) (L)->vectorization_factor
145 #define LOOP_VINFO_PTR_MASK(L) (L)->ptr_mask
146 #define LOOP_VINFO_DATAREFS(L) (L)->datarefs
147 #define LOOP_VINFO_DDRS(L) (L)->ddrs
148 #define LOOP_VINFO_INT_NITERS(L) (TREE_INT_CST_LOW ((L)->num_iters))
149 #define LOOP_PEELING_FOR_ALIGNMENT(L) (L)->peeling_for_alignment
150 #define LOOP_VINFO_UNALIGNED_DR(L) (L)->unaligned_dr
151 #define LOOP_VINFO_MAY_MISALIGN_STMTS(L) (L)->may_misalign_stmts
152 #define LOOP_VINFO_LOC(L) (L)->loop_line_number
154 #define LOOP_VINFO_NITERS_KNOWN_P(L) \
155 (host_integerp ((L)->num_iters,0) \
156 && TREE_INT_CST_LOW ((L)->num_iters) > 0)
158 /*-----------------------------------------------------------------*/
159 /* Info on vectorized defs. */
160 /*-----------------------------------------------------------------*/
161 enum stmt_vec_info_type
{
162 undef_vec_info_type
= 0,
166 assignment_vec_info_type
,
167 condition_vec_info_type
,
169 type_promotion_vec_info_type
,
170 type_demotion_vec_info_type
173 /* Indicates whether/how a variable is used in the loop. */
175 vect_unused_in_loop
= 0,
176 vect_used_by_reduction
,
180 typedef struct data_reference
*dr_p
;
182 DEF_VEC_ALLOC_P(dr_p
,heap
);
184 typedef struct _stmt_vec_info
{
186 enum stmt_vec_info_type type
;
188 /* The stmt to which this info struct refers to. */
191 /* The loop_vec_info with respect to which STMT is vectorized. */
192 loop_vec_info loop_vinfo
;
194 /* Not all stmts in the loop need to be vectorized. e.g, the increment
195 of the loop induction variable and computation of array indexes. relevant
196 indicates whether the stmt needs to be vectorized. */
197 enum vect_relevant relevant
;
199 /* Indicates whether this stmts is part of a computation whose result is
200 used outside the loop. */
203 /* The vector type to be used. */
206 /* The vectorized version of the stmt. */
207 tree vectorized_stmt
;
210 /** The following is relevant only for stmts that contain a non-scalar
211 data-ref (array/pointer/struct access). A GIMPLE stmt is expected to have
212 at most one such data-ref. **/
214 /* Information about the data-ref (access function, etc). */
215 struct data_reference
*data_ref_info
;
217 /* Stmt is part of some pattern (computation idiom) */
220 /* Used for various bookkeeping purposes, generally holding a pointer to
221 some other stmt S that is in some way "related" to this stmt.
222 Current use of this field is:
223 If this stmt is part of a pattern (i.e. the field 'in_pattern_p' is
224 true): S is the "pattern stmt" that represents (and replaces) the
225 sequence of stmts that constitutes the pattern. Similarly, the
226 related_stmt of the "pattern stmt" points back to this stmt (which is
227 the last stmt in the original sequence of stmts that constitutes the
231 /* List of datarefs that are known to have the same alignment as the dataref
233 VEC(dr_p
,heap
) *same_align_refs
;
235 /* Classify the def of this stmt. */
236 enum vect_def_type def_type
;
240 /* Access Functions. */
241 #define STMT_VINFO_TYPE(S) (S)->type
242 #define STMT_VINFO_STMT(S) (S)->stmt
243 #define STMT_VINFO_LOOP_VINFO(S) (S)->loop_vinfo
244 #define STMT_VINFO_RELEVANT(S) (S)->relevant
245 #define STMT_VINFO_LIVE_P(S) (S)->live
246 #define STMT_VINFO_VECTYPE(S) (S)->vectype
247 #define STMT_VINFO_VEC_STMT(S) (S)->vectorized_stmt
248 #define STMT_VINFO_DATA_REF(S) (S)->data_ref_info
249 #define STMT_VINFO_IN_PATTERN_P(S) (S)->in_pattern_p
250 #define STMT_VINFO_RELATED_STMT(S) (S)->related_stmt
251 #define STMT_VINFO_SAME_ALIGN_REFS(S) (S)->same_align_refs
252 #define STMT_VINFO_DEF_TYPE(S) (S)->def_type
254 #define STMT_VINFO_RELEVANT_P(S) ((S)->relevant != vect_unused_in_loop)
256 static inline void set_stmt_info (stmt_ann_t ann
, stmt_vec_info stmt_info
);
257 static inline stmt_vec_info
vinfo_for_stmt (tree stmt
);
260 set_stmt_info (stmt_ann_t ann
, stmt_vec_info stmt_info
)
263 ann
->common
.aux
= (char *) stmt_info
;
266 static inline stmt_vec_info
267 vinfo_for_stmt (tree stmt
)
269 stmt_ann_t ann
= stmt_ann (stmt
);
270 return ann
? (stmt_vec_info
) ann
->common
.aux
: NULL
;
273 /*-----------------------------------------------------------------*/
274 /* Info on data references alignment. */
275 /*-----------------------------------------------------------------*/
277 /* Reflects actual alignment of first access in the vectorized loop,
278 taking into account peeling/versioning if applied. */
279 #define DR_MISALIGNMENT(DR) (DR)->aux
282 aligned_access_p (struct data_reference
*data_ref_info
)
284 return (DR_MISALIGNMENT (data_ref_info
) == 0);
288 known_alignment_for_access_p (struct data_reference
*data_ref_info
)
290 return (DR_MISALIGNMENT (data_ref_info
) != -1);
293 /* Perform signed modulo, always returning a non-negative value. */
294 #define VECT_SMODULO(x,y) ((x) % (y) < 0 ? ((x) % (y) + (y)) : (x) % (y))
296 /* vect_dump will be set to stderr or dump_file if exist. */
297 extern FILE *vect_dump
;
298 extern enum verbosity_levels vect_verbosity_level
;
300 /* Number of loops, at the beginning of vectorization. */
301 extern unsigned int vect_loops_num
;
303 /* Bitmap of virtual variables to be renamed. */
304 extern bitmap vect_vnames_to_rename
;
306 /*-----------------------------------------------------------------*/
307 /* Function prototypes. */
308 /*-----------------------------------------------------------------*/
310 /*************************************************************************
311 Simple Loop Peeling Utilities - in tree-vectorizer.c
312 *************************************************************************/
313 /* Entry point for peeling of simple loops.
314 Peel the first/last iterations of a loop.
315 It can be used outside of the vectorizer for loops that are simple enough
316 (see function documentation). In the vectorizer it is used to peel the
317 last few iterations when the loop bound is unknown or does not evenly
318 divide by the vectorization factor, and to peel the first few iterations
319 to force the alignment of data references in the loop. */
320 extern struct loop
*slpeel_tree_peel_loop_to_edge
321 (struct loop
*, struct loops
*, edge
, tree
, tree
, bool);
322 extern void slpeel_make_loop_iterate_ntimes (struct loop
*, tree
);
323 extern bool slpeel_can_duplicate_loop_p (struct loop
*, edge
);
324 #ifdef ENABLE_CHECKING
325 extern void slpeel_verify_cfg_after_peeling (struct loop
*, struct loop
*);
329 /*************************************************************************
330 General Vectorization Utilities
331 *************************************************************************/
332 /** In tree-vectorizer.c **/
333 extern tree
get_vectype_for_scalar_type (tree
);
334 extern bool vect_is_simple_use (tree
, loop_vec_info
, tree
*, tree
*,
335 enum vect_def_type
*);
336 extern bool vect_is_simple_iv_evolution (unsigned, tree
, tree
*, tree
*);
337 extern tree
vect_is_simple_reduction (struct loop
*, tree
);
338 extern bool vect_can_force_dr_alignment_p (tree
, unsigned int);
339 extern enum dr_alignment_support vect_supportable_dr_alignment
340 (struct data_reference
*);
341 extern bool reduction_code_for_scalar_code (enum tree_code
, enum tree_code
*);
342 extern bool supportable_widening_operation (enum tree_code
, tree
, tree
,
343 tree
*, tree
*, enum tree_code
*, enum tree_code
*);
344 /* Creation and deletion of loop and stmt info structs. */
345 extern loop_vec_info
new_loop_vec_info (struct loop
*loop
);
346 extern void destroy_loop_vec_info (loop_vec_info
);
347 extern stmt_vec_info
new_stmt_vec_info (tree stmt
, loop_vec_info
);
350 /** In tree-vect-analyze.c **/
351 /* Driver for analysis stage. */
352 extern loop_vec_info
vect_analyze_loop (struct loop
*);
355 /** In tree-vect-patterns.c **/
356 /* Pattern recognition functions.
357 Additional pattern recognition functions can (and will) be added
359 typedef tree (* vect_recog_func_ptr
) (tree
, tree
*, tree
*);
360 #define NUM_PATTERNS 3
361 void vect_pattern_recog (loop_vec_info
);
364 /** In tree-vect-transform.c **/
365 extern bool vectorizable_load (tree
, block_stmt_iterator
*, tree
*);
366 extern bool vectorizable_store (tree
, block_stmt_iterator
*, tree
*);
367 extern bool vectorizable_operation (tree
, block_stmt_iterator
*, tree
*);
368 extern bool vectorizable_type_promotion (tree
, block_stmt_iterator
*, tree
*);
369 extern bool vectorizable_type_demotion (tree
, block_stmt_iterator
*, tree
*);
370 extern bool vectorizable_assignment (tree
, block_stmt_iterator
*, tree
*);
371 extern bool vectorizable_condition (tree
, block_stmt_iterator
*, tree
*);
372 extern bool vectorizable_live_operation (tree
, block_stmt_iterator
*, tree
*);
373 extern bool vectorizable_reduction (tree
, block_stmt_iterator
*, tree
*);
374 /* Driver for transformation stage. */
375 extern void vect_transform_loop (loop_vec_info
, struct loops
*);
377 /*************************************************************************
378 Vectorization Debug Information - in tree-vectorizer.c
379 *************************************************************************/
380 extern bool vect_print_dump_info (enum verbosity_levels
);
381 extern void vect_set_verbosity_level (const char *);
382 extern LOC
find_loop_location (struct loop
*);
384 #endif /* GCC_TREE_VECTORIZER_H */