]>
Commit | Line | Data |
---|---|---|
79fe1b3b DN |
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 | ||
8c27b7d4 | 31 | /* Defines type of operation: unary or binary. */ |
79fe1b3b DN |
32 | enum operation_type { |
33 | unary_op = 1, | |
34 | binary_op | |
35 | }; | |
36 | ||
0dc0a70b DN |
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 | ||
79fe1b3b DN |
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 | ||
6cb38cd4 | 63 | /* The loop with respect to which STMT is vectorized. */ |
79fe1b3b DN |
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; | |
6775f1f3 IR |
87 | |
88 | /* Data reference base. This field holds the entire invariant part of the | |
89 | data-reference (with respect to the relevant loop), as opposed to the | |
90 | field DR_BASE of the STMT_VINFO_DATA_REF struct, which holds only the | |
91 | initial base; e.g: | |
92 | REF BR_BASE VECT_DR_BASE | |
93 | a[i] a a | |
94 | a[i][j] a a[i] */ | |
95 | tree vect_dr_base; | |
79fe1b3b DN |
96 | } *stmt_vec_info; |
97 | ||
98 | /* Access Functions. */ | |
6775f1f3 IR |
99 | #define STMT_VINFO_TYPE(S) (S)->type |
100 | #define STMT_VINFO_STMT(S) (S)->stmt | |
101 | #define STMT_VINFO_LOOP(S) (S)->loop | |
102 | #define STMT_VINFO_RELEVANT_P(S) (S)->relevant | |
103 | #define STMT_VINFO_VECTYPE(S) (S)->vectype | |
104 | #define STMT_VINFO_VEC_STMT(S) (S)->vectorized_stmt | |
105 | #define STMT_VINFO_DATA_REF(S) (S)->data_ref_info | |
106 | #define STMT_VINFO_MEMTAG(S) (S)->memtag | |
107 | #define STMT_VINFO_VECT_DR_BASE(S) (S)->vect_dr_base | |
79fe1b3b DN |
108 | |
109 | static inline void set_stmt_info (stmt_ann_t ann, stmt_vec_info stmt_info); | |
110 | static inline stmt_vec_info vinfo_for_stmt (tree stmt); | |
111 | ||
112 | static inline void | |
113 | set_stmt_info (stmt_ann_t ann, stmt_vec_info stmt_info) | |
114 | { | |
115 | if (ann) | |
116 | ann->common.aux = (char *) stmt_info; | |
117 | } | |
118 | ||
119 | static inline stmt_vec_info | |
120 | vinfo_for_stmt (tree stmt) | |
121 | { | |
122 | stmt_ann_t ann = stmt_ann (stmt); | |
123 | return ann ? (stmt_vec_info) ann->common.aux : NULL; | |
124 | } | |
125 | ||
126 | /*-----------------------------------------------------------------*/ | |
127 | /* Info on data references alignment. */ | |
128 | /*-----------------------------------------------------------------*/ | |
129 | ||
7ccf35ed | 130 | /* The misalignment of the memory access in bytes. */ |
79fe1b3b DN |
131 | #define DR_MISALIGNMENT(DR) (DR)->aux |
132 | ||
133 | static inline bool | |
134 | aligned_access_p (struct data_reference *data_ref_info) | |
135 | { | |
136 | return (DR_MISALIGNMENT (data_ref_info) == 0); | |
137 | } | |
138 | ||
139 | static inline bool | |
140 | unknown_alignment_for_access_p (struct data_reference *data_ref_info) | |
141 | { | |
142 | return (DR_MISALIGNMENT (data_ref_info) == -1); | |
143 | } | |
144 | ||
6775f1f3 IR |
145 | /* Perform signed modulo, always returning a non-negative value. */ |
146 | #define VECT_SMODULO(x,y) ((x) % (y) < 0 ? ((x) % (y) + (y)) : (x) % (y)) | |
147 | ||
79fe1b3b DN |
148 | |
149 | /*-----------------------------------------------------------------*/ | |
150 | /* Info on vectorized loops. */ | |
151 | /*-----------------------------------------------------------------*/ | |
152 | typedef struct _loop_vec_info { | |
153 | ||
154 | /* The loop to which this info struct refers to. */ | |
155 | struct loop *loop; | |
156 | ||
157 | /* The loop basic blocks. */ | |
158 | basic_block *bbs; | |
159 | ||
160 | /* The loop exit_condition. */ | |
161 | tree exit_cond; | |
162 | ||
a023975e OG |
163 | /* Number of iterations. */ |
164 | tree num_iters; | |
79fe1b3b DN |
165 | |
166 | /* Is the loop vectorizable? */ | |
167 | bool vectorizable; | |
168 | ||
169 | /* Unrolling factor */ | |
170 | int vectorization_factor; | |
171 | ||
a023975e | 172 | /* Unknown DRs according to which loop was peeled. */ |
0dc0a70b | 173 | struct data_reference *unaligned_dr; |
a023975e OG |
174 | |
175 | /* If true, loop is peeled. | |
176 | unaligned_drs show in this case DRs used for peeling. */ | |
177 | bool do_peeling_for_alignment; | |
178 | ||
79fe1b3b DN |
179 | /* All data references in the loop that are being written to. */ |
180 | varray_type data_ref_writes; | |
181 | ||
182 | /* All data references in the loop that are being read from. */ | |
183 | varray_type data_ref_reads; | |
184 | } *loop_vec_info; | |
185 | ||
186 | /* Access Functions. */ | |
187 | #define LOOP_VINFO_LOOP(L) (L)->loop | |
188 | #define LOOP_VINFO_BBS(L) (L)->bbs | |
189 | #define LOOP_VINFO_EXIT_COND(L) (L)->exit_cond | |
190 | #define LOOP_VINFO_NITERS(L) (L)->num_iters | |
191 | #define LOOP_VINFO_VECTORIZABLE_P(L) (L)->vectorizable | |
192 | #define LOOP_VINFO_VECT_FACTOR(L) (L)->vectorization_factor | |
193 | #define LOOP_VINFO_DATAREF_WRITES(L) (L)->data_ref_writes | |
194 | #define LOOP_VINFO_DATAREF_READS(L) (L)->data_ref_reads | |
a023975e OG |
195 | #define LOOP_VINFO_INT_NITERS(L) (TREE_INT_CST_LOW ((L)->num_iters)) |
196 | #define LOOP_DO_PEELING_FOR_ALIGNMENT(L) (L)->do_peeling_for_alignment | |
0dc0a70b | 197 | #define LOOP_VINFO_UNALIGNED_DR(L) (L)->unaligned_dr |
a023975e OG |
198 | |
199 | ||
200 | #define LOOP_VINFO_NITERS_KNOWN_P(L) \ | |
201 | (host_integerp ((L)->num_iters,0) \ | |
202 | && TREE_INT_CST_LOW ((L)->num_iters) > 0) | |
79fe1b3b DN |
203 | |
204 | /*-----------------------------------------------------------------*/ | |
205 | /* Function prototypes. */ | |
206 | /*-----------------------------------------------------------------*/ | |
207 | ||
208 | /* Main driver. */ | |
209 | extern void vectorize_loops (struct loops *); | |
210 | ||
211 | /* creation and deletion of loop and stmt info structs. */ | |
212 | extern loop_vec_info new_loop_vec_info (struct loop *loop); | |
213 | extern void destroy_loop_vec_info (loop_vec_info); | |
214 | extern stmt_vec_info new_stmt_vec_info (tree stmt, struct loop *loop); | |
215 | ||
216 | #endif /* GCC_TREE_VECTORIZER_H */ |