2 Copyright (C) 2003, 2004 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 /*-----------------------------------------------------------------*/
60 /* Info on vectorized loops. */
61 /*-----------------------------------------------------------------*/
62 typedef struct _loop_vec_info
{
64 /* The loop to which this info struct refers to. */
67 /* The loop basic blocks. */
70 /* The loop exit_condition. */
73 /* Number of iterations. */
76 /* Is the loop vectorizable? */
79 /* Unrolling factor */
80 int vectorization_factor
;
82 /* Unknown DRs according to which loop was peeled. */
83 struct data_reference
*unaligned_dr
;
85 /* If true, loop is peeled.
86 unaligned_drs show in this case DRs used for peeling. */
87 bool do_peeling_for_alignment
;
89 /* All data references in the loop that are being written to. */
90 varray_type data_ref_writes
;
92 /* All data references in the loop that are being read from. */
93 varray_type data_ref_reads
;
95 /* The loop location in the source. */
99 /* Access Functions. */
100 #define LOOP_VINFO_LOOP(L) (L)->loop
101 #define LOOP_VINFO_BBS(L) (L)->bbs
102 #define LOOP_VINFO_EXIT_COND(L) (L)->exit_cond
103 #define LOOP_VINFO_NITERS(L) (L)->num_iters
104 #define LOOP_VINFO_VECTORIZABLE_P(L) (L)->vectorizable
105 #define LOOP_VINFO_VECT_FACTOR(L) (L)->vectorization_factor
106 #define LOOP_VINFO_DATAREF_WRITES(L) (L)->data_ref_writes
107 #define LOOP_VINFO_DATAREF_READS(L) (L)->data_ref_reads
108 #define LOOP_VINFO_INT_NITERS(L) (TREE_INT_CST_LOW ((L)->num_iters))
109 #define LOOP_DO_PEELING_FOR_ALIGNMENT(L) (L)->do_peeling_for_alignment
110 #define LOOP_VINFO_UNALIGNED_DR(L) (L)->unaligned_dr
111 #define LOOP_VINFO_LOC(L) (L)->loop_line_number
113 #define LOOP_LOC(L) LOOP_VINFO_LOC(L)
116 #define LOOP_VINFO_NITERS_KNOWN_P(L) \
117 (host_integerp ((L)->num_iters,0) \
118 && TREE_INT_CST_LOW ((L)->num_iters) > 0)
120 /*-----------------------------------------------------------------*/
121 /* Info on vectorized defs. */
122 /*-----------------------------------------------------------------*/
123 enum stmt_vec_info_type
{
124 undef_vec_info_type
= 0,
128 assignment_vec_info_type
131 typedef struct _stmt_vec_info
{
133 enum stmt_vec_info_type type
;
135 /* The stmt to which this info struct refers to. */
138 /* The loop_vec_info with respect to which STMT is vectorized. */
139 loop_vec_info loop_vinfo
;
141 /* Not all stmts in the loop need to be vectorized. e.g, the incrementation
142 of the loop induction variable and computation of array indexes. relevant
143 indicates whether the stmt needs to be vectorized. */
146 /* The vector type to be used. */
149 /* The vectorized version of the stmt. */
150 tree vectorized_stmt
;
153 /** The following is relevant only for stmts that contain a non-scalar
154 data-ref (array/pointer/struct access). A GIMPLE stmt is expected to have
155 at most one such data-ref. **/
157 /* Information about the data-ref (access function, etc). */
158 struct data_reference
*data_ref_info
;
160 /* Aliasing information. */
163 /** The following fields are used to store the information about
164 data-reference. {base + initial_offset} is the first location accessed by
165 data-ref in the loop, and step is the stride of data-ref in the loop;
169 data-ref a[j].b[i][j] a + 4B (a is int*)
172 initial_offset j_0*D_j + i_0*D_i + C 4
176 /* The above base, offset and step. */
181 /* Alignment information. Whether the base of the data-reference is aligned
184 /* Alignment information. The offset of the data-reference from its base
189 /* Access Functions. */
190 #define STMT_VINFO_TYPE(S) (S)->type
191 #define STMT_VINFO_STMT(S) (S)->stmt
192 #define STMT_VINFO_LOOP_VINFO(S) (S)->loop_vinfo
193 #define STMT_VINFO_RELEVANT_P(S) (S)->relevant
194 #define STMT_VINFO_VECTYPE(S) (S)->vectype
195 #define STMT_VINFO_VEC_STMT(S) (S)->vectorized_stmt
196 #define STMT_VINFO_DATA_REF(S) (S)->data_ref_info
197 #define STMT_VINFO_MEMTAG(S) (S)->memtag
198 #define STMT_VINFO_VECT_DR_BASE(S) (S)->base
199 #define STMT_VINFO_VECT_INIT_OFFSET(S) (S)->initial_offset
200 #define STMT_VINFO_VECT_STEP(S) (S)->step
201 #define STMT_VINFO_VECT_BASE_ALIGNED_P(S) (S)->base_aligned_p
202 #define STMT_VINFO_VECT_MISALIGNMENT(S) (S)->misalignment
204 static inline void set_stmt_info (stmt_ann_t ann
, stmt_vec_info stmt_info
);
205 static inline stmt_vec_info
vinfo_for_stmt (tree stmt
);
208 set_stmt_info (stmt_ann_t ann
, stmt_vec_info stmt_info
)
211 ann
->common
.aux
= (char *) stmt_info
;
214 static inline stmt_vec_info
215 vinfo_for_stmt (tree stmt
)
217 stmt_ann_t ann
= stmt_ann (stmt
);
218 return ann
? (stmt_vec_info
) ann
->common
.aux
: NULL
;
221 /*-----------------------------------------------------------------*/
222 /* Info on data references alignment. */
223 /*-----------------------------------------------------------------*/
225 /* The misalignment of the memory access in bytes. */
226 #define DR_MISALIGNMENT(DR) (DR)->aux
229 aligned_access_p (struct data_reference
*data_ref_info
)
231 return (DR_MISALIGNMENT (data_ref_info
) == 0);
235 unknown_alignment_for_access_p (struct data_reference
*data_ref_info
)
237 return (DR_MISALIGNMENT (data_ref_info
) == -1);
240 /* Perform signed modulo, always returning a non-negative value. */
241 #define VECT_SMODULO(x,y) ((x) % (y) < 0 ? ((x) % (y) + (y)) : (x) % (y))
244 /*-----------------------------------------------------------------*/
245 /* Function prototypes. */
246 /*-----------------------------------------------------------------*/
249 extern void vectorize_loops (struct loops
*);
251 /* creation and deletion of loop and stmt info structs. */
252 extern loop_vec_info
new_loop_vec_info (struct loop
*loop
);
253 extern void destroy_loop_vec_info (loop_vec_info
);
254 extern stmt_vec_info
new_stmt_vec_info (tree stmt
, loop_vec_info
);
256 #endif /* GCC_TREE_VECTORIZER_H */