OSDN Git Service

87d3138bcaa0efd69ca410843b2c6dc4c341731f
[pf3gnuchains/gcc-fork.git] / gcc / tree-vectorizer.h
1 /* Loop Vectorization
2    Copyright (C) 2003, 2004, 2005 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, 51 Franklin Street, Fifth Floor, Boston, MA
20 02110-1301, 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   vect_scalar_var
44 };
45
46 /* Defines type of operation: unary or binary.  */
47 enum operation_type {
48   unary_op = 1,
49   binary_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_BAD_FORM_LOOPS,
77   REPORT_OUTER_LOOPS,
78   REPORT_DETAILS,
79   /* New verbosity levels should be added before this one.  */
80   MAX_VERBOSITY_LEVEL
81 };
82
83 /*-----------------------------------------------------------------*/
84 /* Info on vectorized loops.                                       */
85 /*-----------------------------------------------------------------*/
86 typedef struct _loop_vec_info {
87
88   /* The loop to which this info struct refers to.  */
89   struct loop *loop;
90
91   /* The loop basic blocks.  */
92   basic_block *bbs;
93
94   /* The loop exit_condition.  */
95   tree exit_cond;
96
97   /* Number of iterations.  */
98   tree num_iters;
99
100   /* Is the loop vectorizable? */
101   bool vectorizable;
102
103   /* Unrolling factor  */
104   int vectorization_factor;
105
106   /* Unknown DRs according to which loop was peeled.  */
107   struct data_reference *unaligned_dr;
108
109   /* peeling_for_alignment indicates whether peeling for alignment will take
110      place, and what the peeling factor should be:
111      peeling_for_alignment = X means:
112         If X=0: Peeling for alignment will not be applied.
113         If X>0: Peel first X iterations.
114         If X=-1: Generate a runtime test to calculate the number of iterations
115                  to be peeled, using the dataref recorded in the field
116                  unaligned_dr.  */
117   int peeling_for_alignment;
118
119   /* All data references in the loop that are being written to.  */
120   varray_type data_ref_writes;
121
122   /* All data references in the loop that are being read from.  */
123   varray_type data_ref_reads;
124
125 } *loop_vec_info;
126
127 /* Access Functions.  */
128 #define LOOP_VINFO_LOOP(L)           (L)->loop
129 #define LOOP_VINFO_BBS(L)            (L)->bbs
130 #define LOOP_VINFO_EXIT_COND(L)      (L)->exit_cond
131 #define LOOP_VINFO_NITERS(L)         (L)->num_iters
132 #define LOOP_VINFO_VECTORIZABLE_P(L) (L)->vectorizable
133 #define LOOP_VINFO_VECT_FACTOR(L)    (L)->vectorization_factor
134 #define LOOP_VINFO_DATAREF_WRITES(L) (L)->data_ref_writes
135 #define LOOP_VINFO_DATAREF_READS(L)  (L)->data_ref_reads
136 #define LOOP_VINFO_INT_NITERS(L) (TREE_INT_CST_LOW ((L)->num_iters))
137 #define LOOP_PEELING_FOR_ALIGNMENT(L) (L)->peeling_for_alignment
138 #define LOOP_VINFO_UNALIGNED_DR(L) (L)->unaligned_dr
139
140
141 #define LOOP_VINFO_NITERS_KNOWN_P(L)                     \
142 (host_integerp ((L)->num_iters,0)                        \
143 && TREE_INT_CST_LOW ((L)->num_iters) > 0)
144
145 /*-----------------------------------------------------------------*/
146 /* Info on vectorized defs.                                        */
147 /*-----------------------------------------------------------------*/
148 enum stmt_vec_info_type {
149   undef_vec_info_type = 0,
150   load_vec_info_type,
151   store_vec_info_type,
152   op_vec_info_type,
153   assignment_vec_info_type,
154   condition_vec_info_type,
155   reduc_vec_info_type
156 };
157
158 typedef struct data_reference *dr_p;
159 DEF_VEC_P(dr_p);
160 DEF_VEC_ALLOC_P(dr_p,heap);
161
162 typedef struct _stmt_vec_info {
163
164   enum stmt_vec_info_type type;
165
166   /* The stmt to which this info struct refers to.  */
167   tree stmt;
168
169   /* The loop_vec_info with respect to which STMT is vectorized.  */
170   loop_vec_info loop_vinfo;
171
172   /* Not all stmts in the loop need to be vectorized. e.g, the incrementation
173      of the loop induction variable and computation of array indexes. relevant
174      indicates whether the stmt needs to be vectorized.  */
175   bool relevant;
176
177   /* Indicates whether this stmts is part of a computation whose result is
178      used outside the loop.  */
179   bool live;
180
181   /* The vector type to be used.  */
182   tree vectype;
183
184   /* The vectorized version of the stmt.  */
185   tree vectorized_stmt;
186
187
188   /** The following is relevant only for stmts that contain a non-scalar
189      data-ref (array/pointer/struct access). A GIMPLE stmt is expected to have 
190      at most one such data-ref.  **/
191
192   /* Information about the data-ref (access function, etc).  */
193   struct data_reference *data_ref_info;
194
195   /* Aliasing information.  This field represents the symbol that
196      should be aliased by a pointer holding the address of this data
197      reference.  If the original data reference was a pointer
198      dereference, then this field contains the memory tag that should
199      be used by the new vector-pointer.  */
200   tree memtag;
201   struct ptr_info_def *ptr_info;
202   subvar_t subvars;
203
204   /** The following fields are used to store the information about 
205       data-reference. {base_address + initial_offset} is the first location 
206       accessed by data-ref in the loop, and step is the stride of data-ref in 
207       the loop in bytes;
208       e.g.:
209     
210                        Example 1                      Example 2
211       data-ref         a[j].b[i][j]                   a + 4B (a is int*)
212       
213       base_address     &a                             a
214       initial_offset   j_0*D_j + i_0*D_i + C          4
215       step             D_j                            4
216
217       data-reference structure info:
218       base_name        a                              NULL
219       access_fn        <access_fns of indexes of b>   (0, +, 1)
220
221   **/
222   /* The above base_address, offset and step.  */
223   tree base_address;
224   tree initial_offset;
225   tree step;
226
227   /* Alignment information. Whether the base of the data-reference is aligned 
228      to vectype.  */
229   bool base_aligned_p;
230   /* Alignment information. The offset of the data-reference from its base 
231      in bytes.  */
232   tree misalignment;
233
234   /* List of datarefs that are known to have the same alignment as the dataref
235      of this stmt.  */
236   VEC(dr_p,heap) *same_align_refs;
237
238   /* Classify the def of this stmt.  */
239   enum vect_def_type def_type;
240
241 } *stmt_vec_info;
242
243 /* Access Functions.  */
244 #define STMT_VINFO_TYPE(S)                (S)->type
245 #define STMT_VINFO_STMT(S)                (S)->stmt
246 #define STMT_VINFO_LOOP_VINFO(S)          (S)->loop_vinfo
247 #define STMT_VINFO_RELEVANT_P(S)          (S)->relevant
248 #define STMT_VINFO_LIVE_P(S)              (S)->live
249 #define STMT_VINFO_VECTYPE(S)             (S)->vectype
250 #define STMT_VINFO_VEC_STMT(S)            (S)->vectorized_stmt
251 #define STMT_VINFO_DATA_REF(S)            (S)->data_ref_info
252 #define STMT_VINFO_MEMTAG(S)              (S)->memtag
253 #define STMT_VINFO_PTR_INFO(S)            (S)->ptr_info
254 #define STMT_VINFO_SUBVARS(S)             (S)->subvars
255 #define STMT_VINFO_VECT_DR_BASE_ADDRESS(S)(S)->base_address
256 #define STMT_VINFO_VECT_INIT_OFFSET(S)    (S)->initial_offset
257 #define STMT_VINFO_VECT_STEP(S)           (S)->step
258 #define STMT_VINFO_VECT_BASE_ALIGNED_P(S) (S)->base_aligned_p
259 #define STMT_VINFO_VECT_MISALIGNMENT(S)   (S)->misalignment
260 #define STMT_VINFO_SAME_ALIGN_REFS(S)     (S)->same_align_refs
261 #define STMT_VINFO_DEF_TYPE(S)            (S)->def_type
262
263 static inline void set_stmt_info (tree_ann_t ann, stmt_vec_info stmt_info);
264 static inline stmt_vec_info vinfo_for_stmt (tree stmt);
265
266 static inline void
267 set_stmt_info (tree_ann_t ann, stmt_vec_info stmt_info)
268 {
269   if (ann)
270     ann->common.aux = (char *) stmt_info;
271 }
272
273 static inline stmt_vec_info
274 vinfo_for_stmt (tree stmt)
275 {
276   tree_ann_t ann = tree_ann (stmt);
277   return ann ? (stmt_vec_info) ann->common.aux : NULL;
278 }
279
280 /*-----------------------------------------------------------------*/
281 /* Info on data references alignment.                              */
282 /*-----------------------------------------------------------------*/
283
284 /* Reflects actual alignment of first access in the vectorized loop,
285    taking into account peeling/versioning if applied.  */
286 #define DR_MISALIGNMENT(DR)   (DR)->aux
287
288 static inline bool
289 aligned_access_p (struct data_reference *data_ref_info)
290 {
291   return (DR_MISALIGNMENT (data_ref_info) == 0);
292 }
293
294 static inline bool
295 known_alignment_for_access_p (struct data_reference *data_ref_info)
296 {
297   return (DR_MISALIGNMENT (data_ref_info) != -1);
298 }
299
300 /* Perform signed modulo, always returning a non-negative value.  */
301 #define VECT_SMODULO(x,y) ((x) % (y) < 0 ? ((x) % (y) + (y)) : (x) % (y))
302
303 /* vect_dump will be set to stderr or dump_file if exist.  */
304 extern FILE *vect_dump;
305 extern enum verbosity_levels vect_verbosity_level;
306
307 /* Number of loops, at the beginning of vectorization.  */
308 extern unsigned int vect_loops_num;
309
310 /*-----------------------------------------------------------------*/
311 /* Function prototypes.                                            */
312 /*-----------------------------------------------------------------*/
313
314 /*************************************************************************
315   Simple Loop Peeling Utilities - in tree-vectorizer.c
316  *************************************************************************/
317 /* Entry point for peeling of simple loops.
318    Peel the first/last iterations of a loop.
319    It can be used outside of the vectorizer for loops that are simple enough
320    (see function documentation).  In the vectorizer it is used to peel the
321    last few iterations when the loop bound is unknown or does not evenly
322    divide by the vectorization factor, and to peel the first few iterations
323    to force the alignment of data references in the loop.  */
324 extern struct loop *slpeel_tree_peel_loop_to_edge 
325   (struct loop *, struct loops *, edge, tree, tree, bool);
326 extern void slpeel_make_loop_iterate_ntimes (struct loop *, tree);
327 extern bool slpeel_can_duplicate_loop_p (struct loop *, edge);
328 #ifdef ENABLE_CHECKING
329 extern void slpeel_verify_cfg_after_peeling (struct loop *, struct loop *);
330 #endif
331
332
333 /*************************************************************************
334   General Vectorization Utilities
335  *************************************************************************/
336 /** In tree-vectorizer.c **/
337 extern tree vect_strip_conversion (tree);
338 extern tree get_vectype_for_scalar_type (tree);
339 extern bool vect_is_simple_use (tree, loop_vec_info, tree *, tree *,
340                                 enum vect_def_type *);
341 extern bool vect_is_simple_iv_evolution (unsigned, tree, tree *, tree *);
342 extern tree vect_is_simple_reduction (struct loop *, tree);
343 extern bool vect_can_force_dr_alignment_p (tree, unsigned int);
344 extern enum dr_alignment_support vect_supportable_dr_alignment
345   (struct data_reference *);
346 extern bool reduction_code_for_scalar_code (enum tree_code, enum tree_code *);
347
348 /* Creation and deletion of loop and stmt info structs.  */
349 extern loop_vec_info new_loop_vec_info (struct loop *loop);
350 extern void destroy_loop_vec_info (loop_vec_info);
351 extern stmt_vec_info new_stmt_vec_info (tree stmt, loop_vec_info);
352 /* Main driver.  */
353 extern void vectorize_loops (struct loops *);
354
355 /** In tree-vect-analyze.c  **/
356 /* Driver for analysis stage.  */
357 extern loop_vec_info vect_analyze_loop (struct loop *);
358
359 /** In tree-vect-transform.c  **/
360 extern bool vectorizable_load (tree, block_stmt_iterator *, tree *);
361 extern bool vectorizable_store (tree, block_stmt_iterator *, tree *);
362 extern bool vectorizable_operation (tree, block_stmt_iterator *, tree *);
363 extern bool vectorizable_assignment (tree, block_stmt_iterator *, tree *);
364 extern bool vectorizable_condition (tree, block_stmt_iterator *, tree *);
365 extern bool vectorizable_live_operation (tree, block_stmt_iterator *, tree *);
366 extern bool vectorizable_reduction (tree, block_stmt_iterator *, tree *);
367 /* Driver for transformation stage.  */
368 extern void vect_transform_loop (loop_vec_info, struct loops *);
369
370 /*************************************************************************
371   Vectorization Debug Information - in tree-vectorizer.c
372  *************************************************************************/
373 extern bool vect_print_dump_info (enum verbosity_levels);
374 extern void vect_set_verbosity_level (const char *);
375 extern LOC find_loop_location (struct loop *);
376
377 #endif  /* GCC_TREE_VECTORIZER_H  */