OSDN Git Service

2007-02-05 Richard Guenther <rguenther@suse.de>
[pf3gnuchains/gcc-fork.git] / gcc / tree-vectorizer.h
1 /* Loop Vectorization
2    Copyright (C) 2003, 2004, 2005, 2006 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.  */
47 enum operation_type {
48   unary_op = 1,
49   binary_op,
50   ternary_op
51 };
52
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,
58   dr_aligned
59 };
60
61 /* Define type of def-use cross-iteration cycle.  */
62 enum vect_def_type {
63   vect_constant_def,
64   vect_invariant_def,
65   vect_loop_def,
66   vect_induction_def,
67   vect_reduction_def,
68   vect_unknown_def_type
69 };
70
71 /* Define verbosity levels.  */
72 enum verbosity_levels {
73   REPORT_NONE,
74   REPORT_VECTORIZED_LOOPS,
75   REPORT_UNVECTORIZED_LOOPS,
76   REPORT_ALIGNMENT,
77   REPORT_DR_DETAILS,
78   REPORT_BAD_FORM_LOOPS,
79   REPORT_OUTER_LOOPS,
80   REPORT_DETAILS,
81   /* New verbosity levels should be added before this one.  */
82   MAX_VERBOSITY_LEVEL
83 };
84
85 /*-----------------------------------------------------------------*/
86 /* Info on vectorized loops.                                       */
87 /*-----------------------------------------------------------------*/
88 typedef struct _loop_vec_info {
89
90   /* The loop to which this info struct refers to.  */
91   struct loop *loop;
92
93   /* The loop basic blocks.  */
94   basic_block *bbs;
95
96   /* The loop exit_condition.  */
97   tree exit_cond;
98
99   /* Number of iterations.  */
100   tree num_iters;
101
102   /* Is the loop vectorizable? */
103   bool vectorizable;
104
105   /* Unrolling factor  */
106   int vectorization_factor;
107
108   /* Unknown DRs according to which loop was peeled.  */
109   struct data_reference *unaligned_dr;
110
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
118                  unaligned_dr.  */
119   int peeling_for_alignment;
120
121   /* The mask used to check the alignment of pointers or arrays.  */
122   int ptr_mask;
123
124   /* All data references in the loop.  */
125   VEC (data_reference_p, heap) *datarefs;
126
127   /* All data dependences in the loop.  */
128   VEC (ddr_p, heap) *ddrs;
129
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;
133
134   /* The loop location in the source.  */
135   LOC loop_line_number;
136 } *loop_vec_info;
137
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
153
154 #define LOOP_VINFO_NITERS_KNOWN_P(L)                     \
155 (host_integerp ((L)->num_iters,0)                        \
156 && TREE_INT_CST_LOW ((L)->num_iters) > 0)
157
158 /*-----------------------------------------------------------------*/
159 /* Info on vectorized defs.                                        */
160 /*-----------------------------------------------------------------*/
161 enum stmt_vec_info_type {
162   undef_vec_info_type = 0,
163   load_vec_info_type,
164   store_vec_info_type,
165   op_vec_info_type,
166   call_vec_info_type,
167   assignment_vec_info_type,
168   condition_vec_info_type,
169   reduc_vec_info_type,
170   type_promotion_vec_info_type,
171   type_demotion_vec_info_type
172 };
173
174 /* Indicates whether/how a variable is used in the loop.  */
175 enum vect_relevant {
176   vect_unused_in_loop = 0,
177   vect_used_by_reduction,
178   vect_used_in_loop  
179 };
180
181 typedef struct data_reference *dr_p;
182 DEF_VEC_P(dr_p);
183 DEF_VEC_ALLOC_P(dr_p,heap);
184
185 typedef struct _stmt_vec_info {
186
187   enum stmt_vec_info_type type;
188
189   /* The stmt to which this info struct refers to.  */
190   tree stmt;
191
192   /* The loop_vec_info with respect to which STMT is vectorized.  */
193   loop_vec_info loop_vinfo;
194
195   /* Not all stmts in the loop need to be vectorized. e.g, the increment
196      of the loop induction variable and computation of array indexes. relevant
197      indicates whether the stmt needs to be vectorized.  */
198   enum vect_relevant relevant;
199
200   /* Indicates whether this stmts is part of a computation whose result is
201      used outside the loop.  */
202   bool live;
203
204   /* The vector type to be used.  */
205   tree vectype;
206
207   /* The vectorized version of the stmt.  */
208   tree vectorized_stmt;
209
210
211   /** The following is relevant only for stmts that contain a non-scalar
212      data-ref (array/pointer/struct access). A GIMPLE stmt is expected to have 
213      at most one such data-ref.  **/
214
215   /* Information about the data-ref (access function, etc).  */
216   struct data_reference *data_ref_info;
217
218   /* Stmt is part of some pattern (computation idiom)  */
219   bool in_pattern_p;
220
221   /* Used for various bookkeeping purposes, generally holding a pointer to 
222      some other stmt S that is in some way "related" to this stmt. 
223      Current use of this field is:
224         If this stmt is part of a pattern (i.e. the field 'in_pattern_p' is 
225         true): S is the "pattern stmt" that represents (and replaces) the 
226         sequence of stmts that constitutes the pattern.  Similarly, the 
227         related_stmt of the "pattern stmt" points back to this stmt (which is 
228         the last stmt in the original sequence of stmts that constitutes the 
229         pattern).  */
230   tree related_stmt;
231
232   /* List of datarefs that are known to have the same alignment as the dataref
233      of this stmt.  */
234   VEC(dr_p,heap) *same_align_refs;
235
236   /* Classify the def of this stmt.  */
237   enum vect_def_type def_type;
238
239   /* Interleaving info.  */
240   /* First data-ref in the interleaving group.  */
241   tree first_dr;
242   /* Pointer to the next data-ref in the group.  */
243   tree next_dr;
244   /* The size of the interleaving group.  */
245   unsigned int size;
246   /* For stores, number of stores from this group seen. We vectorize the last
247      one.  */
248   unsigned int store_count;
249   /* For loads only, the gap from the previous load. For consecutive loads, GAP
250      is 1.  */
251   unsigned int gap;
252   /* In case that two or more stmts share data-ref, this is the pointer to the
253      previously detected stmt with the same dr.  */
254   tree same_dr_stmt;
255   /* For loads only, if there is a store with the same location, this field is
256      TRUE.  */
257   bool read_write_dep;
258 } *stmt_vec_info;
259
260 /* Access Functions.  */
261 #define STMT_VINFO_TYPE(S)                 (S)->type
262 #define STMT_VINFO_STMT(S)                 (S)->stmt
263 #define STMT_VINFO_LOOP_VINFO(S)           (S)->loop_vinfo
264 #define STMT_VINFO_RELEVANT(S)             (S)->relevant
265 #define STMT_VINFO_LIVE_P(S)               (S)->live
266 #define STMT_VINFO_VECTYPE(S)              (S)->vectype
267 #define STMT_VINFO_VEC_STMT(S)             (S)->vectorized_stmt
268 #define STMT_VINFO_DATA_REF(S)             (S)->data_ref_info
269 #define STMT_VINFO_IN_PATTERN_P(S)         (S)->in_pattern_p
270 #define STMT_VINFO_RELATED_STMT(S)         (S)->related_stmt
271 #define STMT_VINFO_SAME_ALIGN_REFS(S)      (S)->same_align_refs
272 #define STMT_VINFO_DEF_TYPE(S)             (S)->def_type
273 #define STMT_VINFO_DR_GROUP_FIRST_DR(S)    (S)->first_dr
274 #define STMT_VINFO_DR_GROUP_NEXT_DR(S)     (S)->next_dr
275 #define STMT_VINFO_DR_GROUP_SIZE(S)        (S)->size
276 #define STMT_VINFO_DR_GROUP_STORE_COUNT(S) (S)->store_count
277 #define STMT_VINFO_DR_GROUP_GAP(S)         (S)->gap
278 #define STMT_VINFO_DR_GROUP_SAME_DR_STMT(S)(S)->same_dr_stmt
279 #define STMT_VINFO_DR_GROUP_READ_WRITE_DEPENDENCE(S)  (S)->read_write_dep
280
281 #define DR_GROUP_FIRST_DR(S)               (S)->first_dr
282 #define DR_GROUP_NEXT_DR(S)                (S)->next_dr
283 #define DR_GROUP_SIZE(S)                   (S)->size
284 #define DR_GROUP_STORE_COUNT(S)            (S)->store_count
285 #define DR_GROUP_GAP(S)                    (S)->gap
286 #define DR_GROUP_SAME_DR_STMT(S)           (S)->same_dr_stmt
287 #define DR_GROUP_READ_WRITE_DEPENDENCE(S)  (S)->read_write_dep
288
289 #define STMT_VINFO_RELEVANT_P(S)          ((S)->relevant != vect_unused_in_loop)
290
291 static inline void set_stmt_info (stmt_ann_t ann, stmt_vec_info stmt_info);
292 static inline stmt_vec_info vinfo_for_stmt (tree stmt);
293
294 static inline void
295 set_stmt_info (stmt_ann_t ann, stmt_vec_info stmt_info)
296 {
297   if (ann)
298     ann->common.aux = (char *) stmt_info;
299 }
300
301 static inline stmt_vec_info
302 vinfo_for_stmt (tree stmt)
303 {
304   stmt_ann_t ann = stmt_ann (stmt);
305   return ann ? (stmt_vec_info) ann->common.aux : NULL;
306 }
307
308 static inline bool
309 is_pattern_stmt_p (stmt_vec_info stmt_info)
310 {
311   tree related_stmt;
312   stmt_vec_info related_stmt_info;
313
314   related_stmt = STMT_VINFO_RELATED_STMT (stmt_info);
315   if (related_stmt
316       && (related_stmt_info = vinfo_for_stmt (related_stmt))
317       && STMT_VINFO_IN_PATTERN_P (related_stmt_info))
318     return true;
319
320   return false;
321 }
322
323 /*-----------------------------------------------------------------*/
324 /* Info on data references alignment.                              */
325 /*-----------------------------------------------------------------*/
326
327 /* Reflects actual alignment of first access in the vectorized loop,
328    taking into account peeling/versioning if applied.  */
329 #define DR_MISALIGNMENT(DR)   (DR)->aux
330
331 static inline bool
332 aligned_access_p (struct data_reference *data_ref_info)
333 {
334   return (DR_MISALIGNMENT (data_ref_info) == 0);
335 }
336
337 static inline bool
338 known_alignment_for_access_p (struct data_reference *data_ref_info)
339 {
340   return (DR_MISALIGNMENT (data_ref_info) != -1);
341 }
342
343 /* vect_dump will be set to stderr or dump_file if exist.  */
344 extern FILE *vect_dump;
345 extern enum verbosity_levels vect_verbosity_level;
346
347 /* Bitmap of virtual variables to be renamed.  */
348 extern bitmap vect_memsyms_to_rename;
349
350 /*-----------------------------------------------------------------*/
351 /* Function prototypes.                                            */
352 /*-----------------------------------------------------------------*/
353
354 /*************************************************************************
355   Simple Loop Peeling Utilities - in tree-vectorizer.c
356  *************************************************************************/
357 /* Entry point for peeling of simple loops.
358    Peel the first/last iterations of a loop.
359    It can be used outside of the vectorizer for loops that are simple enough
360    (see function documentation).  In the vectorizer it is used to peel the
361    last few iterations when the loop bound is unknown or does not evenly
362    divide by the vectorization factor, and to peel the first few iterations
363    to force the alignment of data references in the loop.  */
364 extern struct loop *slpeel_tree_peel_loop_to_edge 
365   (struct loop *, edge, tree, tree, bool, unsigned int);
366 extern void slpeel_make_loop_iterate_ntimes (struct loop *, tree);
367 extern bool slpeel_can_duplicate_loop_p (struct loop *, edge);
368 #ifdef ENABLE_CHECKING
369 extern void slpeel_verify_cfg_after_peeling (struct loop *, struct loop *);
370 #endif
371
372
373 /*************************************************************************
374   General Vectorization Utilities
375  *************************************************************************/
376 /** In tree-vectorizer.c **/
377 extern tree get_vectype_for_scalar_type (tree);
378 extern bool vect_is_simple_use (tree, loop_vec_info, tree *, tree *,
379                                 enum vect_def_type *);
380 extern bool vect_is_simple_iv_evolution (unsigned, tree, tree *, tree *);
381 extern tree vect_is_simple_reduction (struct loop *, tree);
382 extern bool vect_can_force_dr_alignment_p (tree, unsigned int);
383 extern enum dr_alignment_support vect_supportable_dr_alignment
384   (struct data_reference *);
385 extern bool reduction_code_for_scalar_code (enum tree_code, enum tree_code *);
386 extern bool supportable_widening_operation (enum tree_code, tree, tree,
387   tree *, tree *, enum tree_code *, enum tree_code *);
388 /* Creation and deletion of loop and stmt info structs.  */
389 extern loop_vec_info new_loop_vec_info (struct loop *loop);
390 extern void destroy_loop_vec_info (loop_vec_info);
391 extern stmt_vec_info new_stmt_vec_info (tree stmt, loop_vec_info);
392
393
394 /** In tree-vect-analyze.c  **/
395 /* Driver for analysis stage.  */
396 extern loop_vec_info vect_analyze_loop (struct loop *);
397
398
399 /** In tree-vect-patterns.c  **/
400 /* Pattern recognition functions.
401    Additional pattern recognition functions can (and will) be added
402    in the future.  */
403 typedef tree (* vect_recog_func_ptr) (tree, tree *, tree *);
404 #define NUM_PATTERNS 4
405 void vect_pattern_recog (loop_vec_info);
406
407
408 /** In tree-vect-transform.c  **/
409 extern bool vectorizable_load (tree, block_stmt_iterator *, tree *);
410 extern bool vectorizable_store (tree, block_stmt_iterator *, tree *);
411 extern bool vectorizable_operation (tree, block_stmt_iterator *, tree *);
412 extern bool vectorizable_type_promotion (tree, block_stmt_iterator *, tree *);
413 extern bool vectorizable_type_demotion (tree, block_stmt_iterator *, tree *);
414 extern bool vectorizable_assignment (tree, block_stmt_iterator *, tree *);
415 extern tree vectorizable_function (tree, tree, tree);
416 extern bool vectorizable_call (tree, block_stmt_iterator *, tree *);
417 extern bool vectorizable_condition (tree, block_stmt_iterator *, tree *);
418 extern bool vectorizable_live_operation (tree, block_stmt_iterator *, tree *);
419 extern bool vectorizable_reduction (tree, block_stmt_iterator *, tree *);
420 /* Driver for transformation stage.  */
421 extern void vect_transform_loop (loop_vec_info);
422
423 /*************************************************************************
424   Vectorization Debug Information - in tree-vectorizer.c
425  *************************************************************************/
426 extern bool vect_print_dump_info (enum verbosity_levels);
427 extern void vect_set_verbosity_level (const char *);
428 extern LOC find_loop_location (struct loop *);
429
430 #endif  /* GCC_TREE_VECTORIZER_H  */