2 Copyright (C) 2003, 2004, 2005 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, 59 Temple Place - Suite 330, 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. */
45 /* Defines type of operation: unary or binary. */
51 /* Define type of available alignment support. */
52 enum dr_alignment_support
{
53 dr_unaligned_unsupported
,
54 dr_unaligned_supported
,
55 dr_unaligned_software_pipeline
,
59 /* Define verbosity levels. */
60 enum verbosity_levels
{
62 REPORT_VECTORIZED_LOOPS
,
63 REPORT_UNVECTORIZED_LOOPS
,
65 REPORT_BAD_FORM_LOOPS
,
68 /* New verbosity levels should be added before this one. */
72 /*-----------------------------------------------------------------*/
73 /* Info on vectorized loops. */
74 /*-----------------------------------------------------------------*/
75 typedef struct _loop_vec_info
{
77 /* The loop to which this info struct refers to. */
80 /* The loop basic blocks. */
83 /* The loop exit_condition. */
86 /* Number of iterations. */
89 /* Is the loop vectorizable? */
92 /* Unrolling factor */
93 int vectorization_factor
;
95 /* Unknown DRs according to which loop was peeled. */
96 struct data_reference
*unaligned_dr
;
98 /* If true, loop is peeled.
99 unaligned_drs show in this case DRs used for peeling. */
100 bool do_peeling_for_alignment
;
102 /* All data references in the loop that are being written to. */
103 varray_type data_ref_writes
;
105 /* All data references in the loop that are being read from. */
106 varray_type data_ref_reads
;
108 /* The loop location in the source. */
109 LOC loop_line_number
;
112 /* Access Functions. */
113 #define LOOP_VINFO_LOOP(L) (L)->loop
114 #define LOOP_VINFO_BBS(L) (L)->bbs
115 #define LOOP_VINFO_EXIT_COND(L) (L)->exit_cond
116 #define LOOP_VINFO_NITERS(L) (L)->num_iters
117 #define LOOP_VINFO_VECTORIZABLE_P(L) (L)->vectorizable
118 #define LOOP_VINFO_VECT_FACTOR(L) (L)->vectorization_factor
119 #define LOOP_VINFO_DATAREF_WRITES(L) (L)->data_ref_writes
120 #define LOOP_VINFO_DATAREF_READS(L) (L)->data_ref_reads
121 #define LOOP_VINFO_INT_NITERS(L) (TREE_INT_CST_LOW ((L)->num_iters))
122 #define LOOP_DO_PEELING_FOR_ALIGNMENT(L) (L)->do_peeling_for_alignment
123 #define LOOP_VINFO_UNALIGNED_DR(L) (L)->unaligned_dr
124 #define LOOP_VINFO_LOC(L) (L)->loop_line_number
126 #define LOOP_LOC(L) LOOP_VINFO_LOC(L)
129 #define LOOP_VINFO_NITERS_KNOWN_P(L) \
130 (host_integerp ((L)->num_iters,0) \
131 && TREE_INT_CST_LOW ((L)->num_iters) > 0)
133 /*-----------------------------------------------------------------*/
134 /* Info on vectorized defs. */
135 /*-----------------------------------------------------------------*/
136 enum stmt_vec_info_type
{
137 undef_vec_info_type
= 0,
141 assignment_vec_info_type
144 typedef struct _stmt_vec_info
{
146 enum stmt_vec_info_type type
;
148 /* The stmt to which this info struct refers to. */
151 /* The loop_vec_info with respect to which STMT is vectorized. */
152 loop_vec_info loop_vinfo
;
154 /* Not all stmts in the loop need to be vectorized. e.g, the incrementation
155 of the loop induction variable and computation of array indexes. relevant
156 indicates whether the stmt needs to be vectorized. */
159 /* The vector type to be used. */
162 /* The vectorized version of the stmt. */
163 tree vectorized_stmt
;
166 /** The following is relevant only for stmts that contain a non-scalar
167 data-ref (array/pointer/struct access). A GIMPLE stmt is expected to have
168 at most one such data-ref. **/
170 /* Information about the data-ref (access function, etc). */
171 struct data_reference
*data_ref_info
;
173 /* Aliasing information. */
177 /** The following fields are used to store the information about
178 data-reference. {base_address + initial_offset} is the first location
179 accessed by data-ref in the loop, and step is the stride of data-ref in
184 data-ref a[j].b[i][j] a + 4B (a is int*)
187 initial_offset j_0*D_j + i_0*D_i + C 4
190 data-reference structure info:
192 access_fn <access_fns of indexes of b> (0, +, 1)
195 /* The above base_address, offset and step. */
200 /* Alignment information. Whether the base of the data-reference is aligned
203 /* Alignment information. The offset of the data-reference from its base
208 /* Access Functions. */
209 #define STMT_VINFO_TYPE(S) (S)->type
210 #define STMT_VINFO_STMT(S) (S)->stmt
211 #define STMT_VINFO_LOOP_VINFO(S) (S)->loop_vinfo
212 #define STMT_VINFO_RELEVANT_P(S) (S)->relevant
213 #define STMT_VINFO_VECTYPE(S) (S)->vectype
214 #define STMT_VINFO_VEC_STMT(S) (S)->vectorized_stmt
215 #define STMT_VINFO_DATA_REF(S) (S)->data_ref_info
216 #define STMT_VINFO_MEMTAG(S) (S)->memtag
217 #define STMT_VINFO_SUBVARS(S) (S)->subvars
218 #define STMT_VINFO_VECT_DR_BASE_ADDRESS(S)(S)->base_address
219 #define STMT_VINFO_VECT_INIT_OFFSET(S) (S)->initial_offset
220 #define STMT_VINFO_VECT_STEP(S) (S)->step
221 #define STMT_VINFO_VECT_BASE_ALIGNED_P(S) (S)->base_aligned_p
222 #define STMT_VINFO_VECT_MISALIGNMENT(S) (S)->misalignment
224 static inline void set_stmt_info (stmt_ann_t ann
, stmt_vec_info stmt_info
);
225 static inline stmt_vec_info
vinfo_for_stmt (tree stmt
);
228 set_stmt_info (stmt_ann_t ann
, stmt_vec_info stmt_info
)
231 ann
->common
.aux
= (char *) stmt_info
;
234 static inline stmt_vec_info
235 vinfo_for_stmt (tree stmt
)
237 stmt_ann_t ann
= stmt_ann (stmt
);
238 return ann
? (stmt_vec_info
) ann
->common
.aux
: NULL
;
241 /*-----------------------------------------------------------------*/
242 /* Info on data references alignment. */
243 /*-----------------------------------------------------------------*/
245 /* The misalignment of the memory access in bytes. */
246 #define DR_MISALIGNMENT(DR) (DR)->aux
249 aligned_access_p (struct data_reference
*data_ref_info
)
251 return (DR_MISALIGNMENT (data_ref_info
) == 0);
255 unknown_alignment_for_access_p (struct data_reference
*data_ref_info
)
257 return (DR_MISALIGNMENT (data_ref_info
) == -1);
260 /* Perform signed modulo, always returning a non-negative value. */
261 #define VECT_SMODULO(x,y) ((x) % (y) < 0 ? ((x) % (y) + (y)) : (x) % (y))
263 /* vect_dump will be set to stderr or dump_file if exist. */
264 extern FILE *vect_dump
;
265 extern enum verbosity_levels vect_verbosity_level
;
267 /*-----------------------------------------------------------------*/
268 /* Function prototypes. */
269 /*-----------------------------------------------------------------*/
271 /*************************************************************************
272 Simple Loop Peeling Utilities - in tree-vectorizer.c
273 *************************************************************************/
274 /* Entry point for peeling of simple loops.
275 Peel the first/last iterations of a loop.
276 It can be used outside of the vectorizer for loops that are simple enough
277 (see function documentation). In the vectorizer it is used to peel the
278 last few iterations when the loop bound is unknown or does not evenly
279 divide by the vectorization factor, and to peel the first few iterations
280 to force the alignment of data references in the loop. */
281 extern struct loop
*slpeel_tree_peel_loop_to_edge
282 (struct loop
*, struct loops
*, edge
, tree
, tree
, bool);
283 extern void slpeel_make_loop_iterate_ntimes (struct loop
*, tree
);
284 extern bool slpeel_can_duplicate_loop_p (struct loop
*, edge
);
285 #ifdef ENABLE_CHECKING
286 extern void slpeel_verify_cfg_after_peeling (struct loop
*, struct loop
*);
290 /*************************************************************************
291 General Vectorization Utilities
292 *************************************************************************/
293 /** In tree-vectorizer.c **/
294 extern tree
vect_strip_conversion (tree
);
295 extern tree
get_vectype_for_scalar_type (tree
);
296 extern bool vect_is_simple_use (tree
, loop_vec_info
, tree
*);
297 extern bool vect_is_simple_iv_evolution (unsigned, tree
, tree
*, tree
*);
298 extern bool vect_can_force_dr_alignment_p (tree
, unsigned int);
299 extern enum dr_alignment_support vect_supportable_dr_alignment
300 (struct data_reference
*);
301 /* Creation and deletion of loop and stmt info structs. */
302 extern loop_vec_info
new_loop_vec_info (struct loop
*loop
);
303 extern void destroy_loop_vec_info (loop_vec_info
);
304 extern stmt_vec_info
new_stmt_vec_info (tree stmt
, loop_vec_info
);
306 extern void vectorize_loops (struct loops
*);
308 /** In tree-vect-analyze.c **/
309 /* Driver for analysis stage. */
310 extern loop_vec_info
vect_analyze_loop (struct loop
*);
312 /** In tree-vect-transform.c **/
313 extern bool vectorizable_load (tree
, block_stmt_iterator
*, tree
*);
314 extern bool vectorizable_store (tree
, block_stmt_iterator
*, tree
*);
315 extern bool vectorizable_operation (tree
, block_stmt_iterator
*, tree
*);
316 extern bool vectorizable_assignment (tree
, block_stmt_iterator
*, tree
*);
317 /* Driver for transformation stage. */
318 extern void vect_transform_loop (loop_vec_info
, struct loops
*);
320 /*************************************************************************
321 Vectorization Debug Information - in tree-vectorizer.c
322 *************************************************************************/
323 extern bool vect_print_dump_info (enum verbosity_levels
, LOC
);
324 extern void vect_set_verbosity_level (const char *);
325 extern LOC
find_loop_location (struct loop
*);
327 #endif /* GCC_TREE_VECTORIZER_H */