OSDN Git Service

* doc/invoke.texi (ftree-vectorizer-verbose): New.
[pf3gnuchains/gcc-fork.git] / gcc / tree-vectorizer.h
1 /* Loop Vectorization
2    Copyright (C) 2003, 2004 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 2, 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 COPYING.  If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.  */
21
22 #ifndef GCC_TREE_VECTORIZER_H
23 #define GCC_TREE_VECTORIZER_H
24
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)
31 #else
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
37 #endif
38
39 /* Used for naming of new temporaries.  */
40 enum vect_var_kind {
41   vect_simple_var,
42   vect_pointer_var
43 };
44
45 /* Defines type of operation: unary or binary.  */
46 enum operation_type {
47   unary_op = 1,
48   binary_op
49 };
50
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,
56   dr_aligned
57 };
58
59 /* Define verbosity levels.  */
60 enum verbosity_levels {
61   REPORT_NONE,
62   REPORT_VECTORIZED_LOOPS,
63   REPORT_UNVECTORIZED_LOOPS,
64   REPORT_ALIGNMENT,
65   REPORT_BAD_FORM_LOOPS,
66   REPORT_OUTER_LOOPS,
67   REPORT_DETAILS,
68   /* New verbosity levels should be added before this one.  */
69   MAX_VERBOSITY_LEVEL
70 };
71
72 /*-----------------------------------------------------------------*/
73 /* Info on vectorized loops.                                       */
74 /*-----------------------------------------------------------------*/
75 typedef struct _loop_vec_info {
76
77   /* The loop to which this info struct refers to.  */
78   struct loop *loop;
79
80   /* The loop basic blocks.  */
81   basic_block *bbs;
82
83   /* The loop exit_condition.  */
84   tree exit_cond;
85
86   /* Number of iterations.  */
87   tree num_iters;
88
89   /* Is the loop vectorizable? */
90   bool vectorizable;
91
92   /* Unrolling factor  */
93   int vectorization_factor;
94
95   /* Unknown DRs according to which loop was peeled.  */
96   struct data_reference *unaligned_dr;
97
98   /* If true, loop is peeled.
99    unaligned_drs show in this case DRs used for peeling.  */
100   bool do_peeling_for_alignment;
101
102   /* All data references in the loop that are being written to.  */
103   varray_type data_ref_writes;
104
105   /* All data references in the loop that are being read from.  */
106   varray_type data_ref_reads;
107
108   /* The loop location in the source.  */
109   LOC loop_line_number;
110 } *loop_vec_info;
111
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
125
126 #define LOOP_LOC(L)    LOOP_VINFO_LOC(L)
127
128
129 #define LOOP_VINFO_NITERS_KNOWN_P(L)                     \
130 (host_integerp ((L)->num_iters,0)                        \
131 && TREE_INT_CST_LOW ((L)->num_iters) > 0)
132
133 /*-----------------------------------------------------------------*/
134 /* Info on vectorized defs.                                        */
135 /*-----------------------------------------------------------------*/
136 enum stmt_vec_info_type {
137   undef_vec_info_type = 0,
138   load_vec_info_type,
139   store_vec_info_type,
140   op_vec_info_type,
141   assignment_vec_info_type
142 };
143
144 typedef struct _stmt_vec_info {
145
146   enum stmt_vec_info_type type;
147
148   /* The stmt to which this info struct refers to.  */
149   tree stmt;
150
151   /* The loop_vec_info with respect to which STMT is vectorized.  */
152   loop_vec_info loop_vinfo;
153
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.  */
157   bool relevant;
158
159   /* The vector type to be used.  */
160   tree vectype;
161
162   /* The vectorized version of the stmt.  */
163   tree vectorized_stmt;
164
165
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.  **/
169
170   /* Information about the data-ref (access function, etc).  */
171   struct data_reference *data_ref_info;
172
173   /* Aliasing information.  */
174   tree memtag;
175
176   /** The following fields are used to store the information about 
177       data-reference. {base + initial_offset} is the first location accessed by
178       data-ref in the loop, and step is the stride of data-ref in the loop;
179       e.g.:
180     
181                        Example 1                      Example 2
182       data-ref         a[j].b[i][j]                   a + 4B (a is int*)
183
184       base             a                              a
185       initial_offset   j_0*D_j + i_0*D_i + C          4
186       step             D_j                            4
187
188   **/
189   /* The above base, offset and step.  */
190   tree base;
191   tree initial_offset;
192   tree step;
193
194   /* Alignment information. Whether the base of the data-reference is aligned 
195      to vectype.  */
196   bool base_aligned_p;
197   /* Alignment information. The offset of the data-reference from its base 
198      in bytes.  */
199   tree misalignment;
200 } *stmt_vec_info;
201
202 /* Access Functions.  */
203 #define STMT_VINFO_TYPE(S)                (S)->type
204 #define STMT_VINFO_STMT(S)                (S)->stmt
205 #define STMT_VINFO_LOOP_VINFO(S)          (S)->loop_vinfo
206 #define STMT_VINFO_RELEVANT_P(S)          (S)->relevant
207 #define STMT_VINFO_VECTYPE(S)             (S)->vectype
208 #define STMT_VINFO_VEC_STMT(S)            (S)->vectorized_stmt
209 #define STMT_VINFO_DATA_REF(S)            (S)->data_ref_info
210 #define STMT_VINFO_MEMTAG(S)              (S)->memtag
211 #define STMT_VINFO_VECT_DR_BASE(S)        (S)->base
212 #define STMT_VINFO_VECT_INIT_OFFSET(S)    (S)->initial_offset
213 #define STMT_VINFO_VECT_STEP(S)           (S)->step
214 #define STMT_VINFO_VECT_BASE_ALIGNED_P(S) (S)->base_aligned_p
215 #define STMT_VINFO_VECT_MISALIGNMENT(S)   (S)->misalignment
216
217 static inline void set_stmt_info (stmt_ann_t ann, stmt_vec_info stmt_info);
218 static inline stmt_vec_info vinfo_for_stmt (tree stmt);
219
220 static inline void
221 set_stmt_info (stmt_ann_t ann, stmt_vec_info stmt_info)
222 {
223   if (ann)
224     ann->common.aux = (char *) stmt_info;
225 }
226
227 static inline stmt_vec_info
228 vinfo_for_stmt (tree stmt)
229 {
230   stmt_ann_t ann = stmt_ann (stmt);
231   return ann ? (stmt_vec_info) ann->common.aux : NULL;
232 }
233
234 /*-----------------------------------------------------------------*/
235 /* Info on data references alignment.                              */
236 /*-----------------------------------------------------------------*/
237
238 /* The misalignment of the memory access in bytes.  */
239 #define DR_MISALIGNMENT(DR)   (DR)->aux
240
241 static inline bool
242 aligned_access_p (struct data_reference *data_ref_info)
243 {
244   return (DR_MISALIGNMENT (data_ref_info) == 0);
245 }
246
247 static inline bool
248 unknown_alignment_for_access_p (struct data_reference *data_ref_info)
249 {
250   return (DR_MISALIGNMENT (data_ref_info) == -1);
251 }
252
253 /* Perform signed modulo, always returning a non-negative value.  */
254 #define VECT_SMODULO(x,y) ((x) % (y) < 0 ? ((x) % (y) + (y)) : (x) % (y))
255
256
257 /*-----------------------------------------------------------------*/
258 /* Function prototypes.                                            */
259 /*-----------------------------------------------------------------*/
260
261 /* Main driver.  */
262 extern void vectorize_loops (struct loops *);
263
264 /* creation and deletion of loop and stmt info structs.  */
265 extern loop_vec_info new_loop_vec_info (struct loop *loop);
266 extern void destroy_loop_vec_info (loop_vec_info);
267 extern stmt_vec_info new_stmt_vec_info (tree stmt, loop_vec_info);
268
269 #endif  /* GCC_TREE_VECTORIZER_H  */