OSDN Git Service

* ifcvt.c (find_if_case_1): Reinstate 2005-01-04 change, now that
[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 /* Used for naming of new temporaries.  */
26 enum vect_var_kind {
27   vect_simple_var,
28   vect_pointer_var
29 };
30
31 /* Defines type of operation: unary or binary.  */
32 enum operation_type {
33   unary_op = 1,
34   binary_op
35 };
36
37 /* Define type of available alignment support.  */
38 enum dr_alignment_support {
39   dr_unaligned_unsupported,
40   dr_unaligned_supported,
41   dr_unaligned_software_pipeline,
42   dr_aligned
43 };
44
45 /*-----------------------------------------------------------------*/
46 /* Info on vectorized defs.                                        */
47 /*-----------------------------------------------------------------*/
48 enum stmt_vec_info_type {
49   undef_vec_info_type = 0,
50   load_vec_info_type,
51   store_vec_info_type,
52   op_vec_info_type,
53   assignment_vec_info_type
54 };
55
56 typedef struct _stmt_vec_info {
57
58   enum stmt_vec_info_type type;
59
60   /* The stmt to which this info struct refers to.  */
61   tree stmt;
62
63   /* The loop with respect to which STMT is vectorized.  */
64   struct loop *loop;
65
66   /* Not all stmts in the loop need to be vectorized. e.g, the incrementation
67      of the loop induction variable and computation of array indexes. relevant
68      indicates whether the stmt needs to be vectorized.  */
69   bool relevant;
70
71   /* The vector type to be used.  */
72   tree vectype;
73
74   /* The vectorized version of the stmt.  */
75   tree vectorized_stmt;
76
77
78   /** The following is relevant only for stmts that contain a non-scalar
79      data-ref (array/pointer/struct access). A GIMPLE stmt is expected to have 
80      at most one such data-ref.  **/
81
82   /* Information about the data-ref (access function, etc).  */
83   struct data_reference *data_ref_info;
84
85   /* Aliasing information.  */
86   tree memtag;
87
88   /** The following fields are used to store the information about 
89       data-reference. {base + initial_offset} is the first location accessed by
90       data-ref in the loop, and step is the stride of data-ref in the loop;
91       e.g.:
92     
93                        Example 1                      Example 2
94       data-ref         a[j].b[i][j]                   a + 4B (a is int*)
95
96       base             a                              a
97       initial_offset   j_0*D_j + i_0*D_i + C          4
98       step             D_j                            4
99
100   **/
101   /* The above base, offset and step.  */
102   tree base;
103   tree initial_offset;
104   tree step;
105
106   /* Alignment information. Whether the base of the data-reference is aligned 
107      to vectype.  */
108   bool base_aligned_p;
109   /* Alignment information. The offset of the data-reference from its base 
110      in bytes.  */
111   tree misalignment;
112 } *stmt_vec_info;
113
114 /* Access Functions.  */
115 #define STMT_VINFO_TYPE(S)                (S)->type
116 #define STMT_VINFO_STMT(S)                (S)->stmt
117 #define STMT_VINFO_LOOP(S)                (S)->loop
118 #define STMT_VINFO_RELEVANT_P(S)          (S)->relevant
119 #define STMT_VINFO_VECTYPE(S)             (S)->vectype
120 #define STMT_VINFO_VEC_STMT(S)            (S)->vectorized_stmt
121 #define STMT_VINFO_DATA_REF(S)            (S)->data_ref_info
122 #define STMT_VINFO_MEMTAG(S)              (S)->memtag
123 #define STMT_VINFO_VECT_DR_BASE(S)        (S)->base
124 #define STMT_VINFO_VECT_INIT_OFFSET(S)    (S)->initial_offset
125 #define STMT_VINFO_VECT_STEP(S)           (S)->step
126 #define STMT_VINFO_VECT_BASE_ALIGNED_P(S) (S)->base_aligned_p
127 #define STMT_VINFO_VECT_MISALIGNMENT(S)   (S)->misalignment
128
129 static inline void set_stmt_info (stmt_ann_t ann, stmt_vec_info stmt_info);
130 static inline stmt_vec_info vinfo_for_stmt (tree stmt);
131
132 static inline void
133 set_stmt_info (stmt_ann_t ann, stmt_vec_info stmt_info)
134 {
135   if (ann)
136     ann->common.aux = (char *) stmt_info;
137 }
138
139 static inline stmt_vec_info
140 vinfo_for_stmt (tree stmt)
141 {
142   stmt_ann_t ann = stmt_ann (stmt);
143   return ann ? (stmt_vec_info) ann->common.aux : NULL;
144 }
145
146 /*-----------------------------------------------------------------*/
147 /* Info on data references alignment.                              */
148 /*-----------------------------------------------------------------*/
149
150 /* The misalignment of the memory access in bytes.  */
151 #define DR_MISALIGNMENT(DR)   (DR)->aux
152
153 static inline bool
154 aligned_access_p (struct data_reference *data_ref_info)
155 {
156   return (DR_MISALIGNMENT (data_ref_info) == 0);
157 }
158
159 static inline bool
160 unknown_alignment_for_access_p (struct data_reference *data_ref_info)
161 {
162   return (DR_MISALIGNMENT (data_ref_info) == -1);
163 }
164
165 /* Perform signed modulo, always returning a non-negative value.  */
166 #define VECT_SMODULO(x,y) ((x) % (y) < 0 ? ((x) % (y) + (y)) : (x) % (y))
167
168
169 /*-----------------------------------------------------------------*/
170 /* Info on vectorized loops.                                       */
171 /*-----------------------------------------------------------------*/
172 typedef struct _loop_vec_info {
173
174   /* The loop to which this info struct refers to.  */
175   struct loop *loop;
176
177   /* The loop basic blocks.  */
178   basic_block *bbs;
179
180   /* The loop exit_condition.  */
181   tree exit_cond;
182
183   /* Number of iterations.  */
184   tree num_iters;
185
186   /* Is the loop vectorizable? */
187   bool vectorizable;
188
189   /* Unrolling factor  */
190   int vectorization_factor;
191
192   /* Unknown DRs according to which loop was peeled.  */
193   struct data_reference *unaligned_dr;
194
195   /* If true, loop is peeled.
196    unaligned_drs show in this case DRs used for peeling.  */
197   bool do_peeling_for_alignment;
198
199   /* All data references in the loop that are being written to.  */
200   varray_type data_ref_writes;
201
202   /* All data references in the loop that are being read from.  */
203   varray_type data_ref_reads;
204 } *loop_vec_info;
205
206 /* Access Functions.  */
207 #define LOOP_VINFO_LOOP(L)           (L)->loop
208 #define LOOP_VINFO_BBS(L)            (L)->bbs
209 #define LOOP_VINFO_EXIT_COND(L)      (L)->exit_cond
210 #define LOOP_VINFO_NITERS(L)         (L)->num_iters
211 #define LOOP_VINFO_VECTORIZABLE_P(L) (L)->vectorizable
212 #define LOOP_VINFO_VECT_FACTOR(L)    (L)->vectorization_factor
213 #define LOOP_VINFO_DATAREF_WRITES(L) (L)->data_ref_writes
214 #define LOOP_VINFO_DATAREF_READS(L)  (L)->data_ref_reads
215 #define LOOP_VINFO_INT_NITERS(L) (TREE_INT_CST_LOW ((L)->num_iters))       
216 #define LOOP_DO_PEELING_FOR_ALIGNMENT(L) (L)->do_peeling_for_alignment
217 #define LOOP_VINFO_UNALIGNED_DR(L)       (L)->unaligned_dr
218   
219
220 #define LOOP_VINFO_NITERS_KNOWN_P(L)                     \
221 (host_integerp ((L)->num_iters,0)                        \
222 && TREE_INT_CST_LOW ((L)->num_iters) > 0)      
223
224 /*-----------------------------------------------------------------*/
225 /* Function prototypes.                                            */
226 /*-----------------------------------------------------------------*/
227
228 /* Main driver.  */
229 extern void vectorize_loops (struct loops *);
230
231 /* creation and deletion of loop and stmt info structs.  */
232 extern loop_vec_info new_loop_vec_info (struct loop *loop);
233 extern void destroy_loop_vec_info (loop_vec_info);
234 extern stmt_vec_info new_stmt_vec_info (tree stmt, struct loop *loop);
235
236 #endif  /* GCC_TREE_VECTORIZER_H  */