tree-vectorizer.h revision 1.8 1 1.1 mrg /* Vectorizer
2 1.8 mrg Copyright (C) 2003-2017 Free Software Foundation, Inc.
3 1.1 mrg Contributed by Dorit Naishlos <dorit (at) il.ibm.com>
4 1.1 mrg
5 1.1 mrg This file is part of GCC.
6 1.1 mrg
7 1.1 mrg GCC is free software; you can redistribute it and/or modify it under
8 1.1 mrg the terms of the GNU General Public License as published by the Free
9 1.1 mrg Software Foundation; either version 3, or (at your option) any later
10 1.1 mrg version.
11 1.1 mrg
12 1.1 mrg GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 1.1 mrg WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 1.1 mrg FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 1.1 mrg for more details.
16 1.1 mrg
17 1.1 mrg You should have received a copy of the GNU General Public License
18 1.1 mrg along with GCC; see the file COPYING3. If not see
19 1.1 mrg <http://www.gnu.org/licenses/>. */
20 1.1 mrg
21 1.1 mrg #ifndef GCC_TREE_VECTORIZER_H
22 1.1 mrg #define GCC_TREE_VECTORIZER_H
23 1.1 mrg
24 1.1 mrg #include "tree-data-ref.h"
25 1.3 mrg #include "target.h"
26 1.1 mrg
27 1.1 mrg /* Used for naming of new temporaries. */
28 1.1 mrg enum vect_var_kind {
29 1.1 mrg vect_simple_var,
30 1.1 mrg vect_pointer_var,
31 1.6 mrg vect_scalar_var,
32 1.6 mrg vect_mask_var
33 1.1 mrg };
34 1.1 mrg
35 1.1 mrg /* Defines type of operation. */
36 1.1 mrg enum operation_type {
37 1.1 mrg unary_op = 1,
38 1.1 mrg binary_op,
39 1.1 mrg ternary_op
40 1.1 mrg };
41 1.1 mrg
42 1.1 mrg /* Define type of available alignment support. */
43 1.1 mrg enum dr_alignment_support {
44 1.1 mrg dr_unaligned_unsupported,
45 1.1 mrg dr_unaligned_supported,
46 1.1 mrg dr_explicit_realign,
47 1.1 mrg dr_explicit_realign_optimized,
48 1.1 mrg dr_aligned
49 1.1 mrg };
50 1.1 mrg
51 1.1 mrg /* Define type of def-use cross-iteration cycle. */
52 1.1 mrg enum vect_def_type {
53 1.1 mrg vect_uninitialized_def = 0,
54 1.1 mrg vect_constant_def = 1,
55 1.1 mrg vect_external_def,
56 1.1 mrg vect_internal_def,
57 1.1 mrg vect_induction_def,
58 1.1 mrg vect_reduction_def,
59 1.1 mrg vect_double_reduction_def,
60 1.1 mrg vect_nested_cycle,
61 1.1 mrg vect_unknown_def_type
62 1.1 mrg };
63 1.1 mrg
64 1.6 mrg /* Define type of reduction. */
65 1.6 mrg enum vect_reduction_type {
66 1.6 mrg TREE_CODE_REDUCTION,
67 1.6 mrg COND_REDUCTION,
68 1.8 mrg INTEGER_INDUC_COND_REDUCTION,
69 1.8 mrg CONST_COND_REDUCTION
70 1.6 mrg };
71 1.6 mrg
72 1.1 mrg #define VECTORIZABLE_CYCLE_DEF(D) (((D) == vect_reduction_def) \
73 1.1 mrg || ((D) == vect_double_reduction_def) \
74 1.1 mrg || ((D) == vect_nested_cycle))
75 1.1 mrg
76 1.3 mrg /* Structure to encapsulate information about a group of like
77 1.3 mrg instructions to be presented to the target cost model. */
78 1.6 mrg struct stmt_info_for_cost {
79 1.3 mrg int count;
80 1.3 mrg enum vect_cost_for_stmt kind;
81 1.6 mrg gimple *stmt;
82 1.3 mrg int misalign;
83 1.6 mrg };
84 1.3 mrg
85 1.3 mrg typedef vec<stmt_info_for_cost> stmt_vector_for_cost;
86 1.3 mrg
87 1.1 mrg /************************************************************************
88 1.1 mrg SLP
89 1.1 mrg ************************************************************************/
90 1.5 mrg typedef struct _slp_tree *slp_tree;
91 1.1 mrg
92 1.3 mrg /* A computation tree of an SLP instance. Each node corresponds to a group of
93 1.1 mrg stmts to be packed in a SIMD stmt. */
94 1.5 mrg struct _slp_tree {
95 1.3 mrg /* Nodes that contain def-stmts of this node statements operands. */
96 1.5 mrg vec<slp_tree> children;
97 1.1 mrg /* A group of scalar stmts to be vectorized together. */
98 1.6 mrg vec<gimple *> stmts;
99 1.5 mrg /* Load permutation relative to the stores, NULL if there is no
100 1.5 mrg permutation. */
101 1.5 mrg vec<unsigned> load_permutation;
102 1.1 mrg /* Vectorized stmt/s. */
103 1.6 mrg vec<gimple *> vec_stmts;
104 1.1 mrg /* Number of vector stmts that are created to replace the group of scalar
105 1.1 mrg stmts. It is calculated during the transformation phase as the number of
106 1.1 mrg scalar elements in one scalar iteration (GROUP_SIZE) multiplied by VF
107 1.1 mrg divided by vector size. */
108 1.1 mrg unsigned int vec_stmts_size;
109 1.6 mrg /* Whether the scalar computations use two different operators. */
110 1.6 mrg bool two_operators;
111 1.6 mrg /* The DEF type of this node. */
112 1.6 mrg enum vect_def_type def_type;
113 1.5 mrg };
114 1.1 mrg
115 1.1 mrg
116 1.1 mrg /* SLP instance is a sequence of stmts in a loop that can be packed into
117 1.1 mrg SIMD stmts. */
118 1.1 mrg typedef struct _slp_instance {
119 1.1 mrg /* The root of SLP tree. */
120 1.1 mrg slp_tree root;
121 1.1 mrg
122 1.1 mrg /* Size of groups of scalar stmts that will be replaced by SIMD stmt/s. */
123 1.1 mrg unsigned int group_size;
124 1.1 mrg
125 1.1 mrg /* The unrolling factor required to vectorized this SLP instance. */
126 1.1 mrg unsigned int unrolling_factor;
127 1.1 mrg
128 1.1 mrg /* The group of nodes that contain loads of this SLP instance. */
129 1.3 mrg vec<slp_tree> loads;
130 1.1 mrg } *slp_instance;
131 1.1 mrg
132 1.1 mrg
133 1.1 mrg /* Access Functions. */
134 1.1 mrg #define SLP_INSTANCE_TREE(S) (S)->root
135 1.1 mrg #define SLP_INSTANCE_GROUP_SIZE(S) (S)->group_size
136 1.1 mrg #define SLP_INSTANCE_UNROLLING_FACTOR(S) (S)->unrolling_factor
137 1.1 mrg #define SLP_INSTANCE_LOADS(S) (S)->loads
138 1.1 mrg
139 1.3 mrg #define SLP_TREE_CHILDREN(S) (S)->children
140 1.1 mrg #define SLP_TREE_SCALAR_STMTS(S) (S)->stmts
141 1.1 mrg #define SLP_TREE_VEC_STMTS(S) (S)->vec_stmts
142 1.1 mrg #define SLP_TREE_NUMBER_OF_VEC_STMTS(S) (S)->vec_stmts_size
143 1.5 mrg #define SLP_TREE_LOAD_PERMUTATION(S) (S)->load_permutation
144 1.6 mrg #define SLP_TREE_TWO_OPERATORS(S) (S)->two_operators
145 1.6 mrg #define SLP_TREE_DEF_TYPE(S) (S)->def_type
146 1.3 mrg
147 1.3 mrg
148 1.3 mrg
149 1.5 mrg /* This struct is used to store the information of a data reference,
150 1.8 mrg including the data ref itself and the segment length for aliasing
151 1.8 mrg checks. This is used to merge alias checks. */
152 1.5 mrg
153 1.5 mrg struct dr_with_seg_len
154 1.5 mrg {
155 1.5 mrg dr_with_seg_len (data_reference_p d, tree len)
156 1.8 mrg : dr (d), seg_len (len) {}
157 1.5 mrg
158 1.5 mrg data_reference_p dr;
159 1.5 mrg tree seg_len;
160 1.5 mrg };
161 1.5 mrg
162 1.5 mrg /* This struct contains two dr_with_seg_len objects with aliasing data
163 1.5 mrg refs. Two comparisons are generated from them. */
164 1.5 mrg
165 1.5 mrg struct dr_with_seg_len_pair_t
166 1.5 mrg {
167 1.5 mrg dr_with_seg_len_pair_t (const dr_with_seg_len& d1,
168 1.5 mrg const dr_with_seg_len& d2)
169 1.5 mrg : first (d1), second (d2) {}
170 1.5 mrg
171 1.5 mrg dr_with_seg_len first;
172 1.5 mrg dr_with_seg_len second;
173 1.5 mrg };
174 1.5 mrg
175 1.5 mrg
176 1.3 mrg
177 1.6 mrg /* Vectorizer state common between loop and basic-block vectorization. */
178 1.6 mrg struct vec_info {
179 1.6 mrg enum { bb, loop } kind;
180 1.6 mrg
181 1.6 mrg /* All SLP instances. */
182 1.6 mrg vec<slp_instance> slp_instances;
183 1.6 mrg
184 1.6 mrg /* All data references. */
185 1.6 mrg vec<data_reference_p> datarefs;
186 1.1 mrg
187 1.6 mrg /* All data dependences. */
188 1.6 mrg vec<ddr_p> ddrs;
189 1.5 mrg
190 1.6 mrg /* All interleaving chains of stores, represented by the first
191 1.6 mrg stmt in the chain. */
192 1.6 mrg vec<gimple *> grouped_stores;
193 1.5 mrg
194 1.6 mrg /* Cost data used by the target cost model. */
195 1.6 mrg void *target_cost_data;
196 1.5 mrg };
197 1.5 mrg
198 1.6 mrg struct _loop_vec_info;
199 1.6 mrg struct _bb_vec_info;
200 1.6 mrg
201 1.6 mrg template<>
202 1.6 mrg template<>
203 1.6 mrg inline bool
204 1.6 mrg is_a_helper <_loop_vec_info *>::test (vec_info *i)
205 1.5 mrg {
206 1.6 mrg return i->kind == vec_info::loop;
207 1.5 mrg }
208 1.5 mrg
209 1.6 mrg template<>
210 1.6 mrg template<>
211 1.5 mrg inline bool
212 1.6 mrg is_a_helper <_bb_vec_info *>::test (vec_info *i)
213 1.5 mrg {
214 1.6 mrg return i->kind == vec_info::bb;
215 1.5 mrg }
216 1.5 mrg
217 1.5 mrg
218 1.1 mrg /*-----------------------------------------------------------------*/
219 1.1 mrg /* Info on vectorized loops. */
220 1.1 mrg /*-----------------------------------------------------------------*/
221 1.6 mrg typedef struct _loop_vec_info : public vec_info {
222 1.1 mrg
223 1.1 mrg /* The loop to which this info struct refers to. */
224 1.1 mrg struct loop *loop;
225 1.1 mrg
226 1.1 mrg /* The loop basic blocks. */
227 1.1 mrg basic_block *bbs;
228 1.1 mrg
229 1.5 mrg /* Number of latch executions. */
230 1.5 mrg tree num_itersm1;
231 1.1 mrg /* Number of iterations. */
232 1.1 mrg tree num_iters;
233 1.5 mrg /* Number of iterations of the original loop. */
234 1.1 mrg tree num_iters_unchanged;
235 1.8 mrg /* Condition under which this loop is analyzed and versioned. */
236 1.8 mrg tree num_iters_assumptions;
237 1.1 mrg
238 1.5 mrg /* Threshold of number of iterations below which vectorzation will not be
239 1.5 mrg performed. It is calculated from MIN_PROFITABLE_ITERS and
240 1.5 mrg PARAM_MIN_VECT_LOOP_BOUND. */
241 1.5 mrg unsigned int th;
242 1.5 mrg
243 1.1 mrg /* Unrolling factor */
244 1.1 mrg int vectorization_factor;
245 1.1 mrg
246 1.1 mrg /* Unknown DRs according to which loop was peeled. */
247 1.1 mrg struct data_reference *unaligned_dr;
248 1.1 mrg
249 1.1 mrg /* peeling_for_alignment indicates whether peeling for alignment will take
250 1.1 mrg place, and what the peeling factor should be:
251 1.1 mrg peeling_for_alignment = X means:
252 1.1 mrg If X=0: Peeling for alignment will not be applied.
253 1.1 mrg If X>0: Peel first X iterations.
254 1.1 mrg If X=-1: Generate a runtime test to calculate the number of iterations
255 1.1 mrg to be peeled, using the dataref recorded in the field
256 1.1 mrg unaligned_dr. */
257 1.1 mrg int peeling_for_alignment;
258 1.1 mrg
259 1.1 mrg /* The mask used to check the alignment of pointers or arrays. */
260 1.1 mrg int ptr_mask;
261 1.1 mrg
262 1.3 mrg /* The loop nest in which the data dependences are computed. */
263 1.3 mrg vec<loop_p> loop_nest;
264 1.3 mrg
265 1.1 mrg /* Data Dependence Relations defining address ranges that are candidates
266 1.1 mrg for a run-time aliasing check. */
267 1.3 mrg vec<ddr_p> may_alias_ddrs;
268 1.1 mrg
269 1.5 mrg /* Data Dependence Relations defining address ranges together with segment
270 1.5 mrg lengths from which the run-time aliasing check is built. */
271 1.5 mrg vec<dr_with_seg_len_pair_t> comp_alias_ddrs;
272 1.5 mrg
273 1.1 mrg /* Statements in the loop that have data references that are candidates for a
274 1.1 mrg runtime (loop versioning) misalignment check. */
275 1.6 mrg vec<gimple *> may_misalign_stmts;
276 1.1 mrg
277 1.3 mrg /* Reduction cycles detected in the loop. Used in loop-aware SLP. */
278 1.6 mrg vec<gimple *> reductions;
279 1.3 mrg
280 1.3 mrg /* All reduction chains in the loop, represented by the first
281 1.3 mrg stmt in the chain. */
282 1.6 mrg vec<gimple *> reduction_chains;
283 1.3 mrg
284 1.6 mrg /* Cost vector for a single scalar iteration. */
285 1.6 mrg vec<stmt_info_for_cost> scalar_cost_vec;
286 1.3 mrg
287 1.8 mrg /* The unrolling factor needed to SLP the loop. In case of that pure SLP is
288 1.8 mrg applied to the loop, i.e., no unrolling is needed, this is 1. */
289 1.8 mrg unsigned slp_unrolling_factor;
290 1.8 mrg
291 1.6 mrg /* Cost of a single scalar iteration. */
292 1.6 mrg int single_scalar_iteration_cost;
293 1.3 mrg
294 1.8 mrg /* Is the loop vectorizable? */
295 1.8 mrg bool vectorizable;
296 1.8 mrg
297 1.3 mrg /* When we have grouped data accesses with gaps, we may introduce invalid
298 1.1 mrg memory accesses. We peel the last iteration of the loop to prevent
299 1.1 mrg this. */
300 1.1 mrg bool peeling_for_gaps;
301 1.1 mrg
302 1.5 mrg /* When the number of iterations is not a multiple of the vector size
303 1.5 mrg we need to peel off iterations at the end to form an epilogue loop. */
304 1.5 mrg bool peeling_for_niter;
305 1.5 mrg
306 1.3 mrg /* Reductions are canonicalized so that the last operand is the reduction
307 1.3 mrg operand. If this places a constant into RHS1, this decanonicalizes
308 1.3 mrg GIMPLE for other phases, so we must track when this has occurred and
309 1.3 mrg fix it up. */
310 1.3 mrg bool operands_swapped;
311 1.3 mrg
312 1.5 mrg /* True if there are no loop carried data dependencies in the loop.
313 1.5 mrg If loop->safelen <= 1, then this is always true, either the loop
314 1.5 mrg didn't have any loop carried data dependencies, or the loop is being
315 1.5 mrg vectorized guarded with some runtime alias checks, or couldn't
316 1.5 mrg be vectorized at all, but then this field shouldn't be used.
317 1.5 mrg For loop->safelen >= 2, the user has asserted that there are no
318 1.5 mrg backward dependencies, but there still could be loop carried forward
319 1.5 mrg dependencies in such loops. This flag will be false if normal
320 1.5 mrg vectorizer data dependency analysis would fail or require versioning
321 1.5 mrg for alias, but because of loop->safelen >= 2 it has been vectorized
322 1.5 mrg even without versioning for alias. E.g. in:
323 1.5 mrg #pragma omp simd
324 1.5 mrg for (int i = 0; i < m; i++)
325 1.5 mrg a[i] = a[i + k] * c;
326 1.5 mrg (or #pragma simd or #pragma ivdep) we can vectorize this and it will
327 1.5 mrg DTRT even for k > 0 && k < m, but without safelen we would not
328 1.5 mrg vectorize this, so this field would be false. */
329 1.5 mrg bool no_data_dependencies;
330 1.5 mrg
331 1.8 mrg /* Mark loops having masked stores. */
332 1.8 mrg bool has_mask_store;
333 1.8 mrg
334 1.5 mrg /* If if-conversion versioned this loop before conversion, this is the
335 1.5 mrg loop version without if-conversion. */
336 1.5 mrg struct loop *scalar_loop;
337 1.5 mrg
338 1.8 mrg /* For loops being epilogues of already vectorized loops
339 1.8 mrg this points to the original vectorized loop. Otherwise NULL. */
340 1.8 mrg _loop_vec_info *orig_loop_info;
341 1.6 mrg
342 1.1 mrg } *loop_vec_info;
343 1.1 mrg
344 1.1 mrg /* Access Functions. */
345 1.1 mrg #define LOOP_VINFO_LOOP(L) (L)->loop
346 1.1 mrg #define LOOP_VINFO_BBS(L) (L)->bbs
347 1.5 mrg #define LOOP_VINFO_NITERSM1(L) (L)->num_itersm1
348 1.1 mrg #define LOOP_VINFO_NITERS(L) (L)->num_iters
349 1.5 mrg /* Since LOOP_VINFO_NITERS and LOOP_VINFO_NITERSM1 can change after
350 1.5 mrg prologue peeling retain total unchanged scalar loop iterations for
351 1.5 mrg cost model. */
352 1.1 mrg #define LOOP_VINFO_NITERS_UNCHANGED(L) (L)->num_iters_unchanged
353 1.8 mrg #define LOOP_VINFO_NITERS_ASSUMPTIONS(L) (L)->num_iters_assumptions
354 1.5 mrg #define LOOP_VINFO_COST_MODEL_THRESHOLD(L) (L)->th
355 1.1 mrg #define LOOP_VINFO_VECTORIZABLE_P(L) (L)->vectorizable
356 1.1 mrg #define LOOP_VINFO_VECT_FACTOR(L) (L)->vectorization_factor
357 1.1 mrg #define LOOP_VINFO_PTR_MASK(L) (L)->ptr_mask
358 1.3 mrg #define LOOP_VINFO_LOOP_NEST(L) (L)->loop_nest
359 1.1 mrg #define LOOP_VINFO_DATAREFS(L) (L)->datarefs
360 1.1 mrg #define LOOP_VINFO_DDRS(L) (L)->ddrs
361 1.1 mrg #define LOOP_VINFO_INT_NITERS(L) (TREE_INT_CST_LOW ((L)->num_iters))
362 1.5 mrg #define LOOP_VINFO_PEELING_FOR_ALIGNMENT(L) (L)->peeling_for_alignment
363 1.1 mrg #define LOOP_VINFO_UNALIGNED_DR(L) (L)->unaligned_dr
364 1.1 mrg #define LOOP_VINFO_MAY_MISALIGN_STMTS(L) (L)->may_misalign_stmts
365 1.1 mrg #define LOOP_VINFO_MAY_ALIAS_DDRS(L) (L)->may_alias_ddrs
366 1.5 mrg #define LOOP_VINFO_COMP_ALIAS_DDRS(L) (L)->comp_alias_ddrs
367 1.3 mrg #define LOOP_VINFO_GROUPED_STORES(L) (L)->grouped_stores
368 1.1 mrg #define LOOP_VINFO_SLP_INSTANCES(L) (L)->slp_instances
369 1.1 mrg #define LOOP_VINFO_SLP_UNROLLING_FACTOR(L) (L)->slp_unrolling_factor
370 1.3 mrg #define LOOP_VINFO_REDUCTIONS(L) (L)->reductions
371 1.3 mrg #define LOOP_VINFO_REDUCTION_CHAINS(L) (L)->reduction_chains
372 1.3 mrg #define LOOP_VINFO_TARGET_COST_DATA(L) (L)->target_cost_data
373 1.1 mrg #define LOOP_VINFO_PEELING_FOR_GAPS(L) (L)->peeling_for_gaps
374 1.3 mrg #define LOOP_VINFO_OPERANDS_SWAPPED(L) (L)->operands_swapped
375 1.5 mrg #define LOOP_VINFO_PEELING_FOR_NITER(L) (L)->peeling_for_niter
376 1.5 mrg #define LOOP_VINFO_NO_DATA_DEPENDENCIES(L) (L)->no_data_dependencies
377 1.5 mrg #define LOOP_VINFO_SCALAR_LOOP(L) (L)->scalar_loop
378 1.6 mrg #define LOOP_VINFO_HAS_MASK_STORE(L) (L)->has_mask_store
379 1.6 mrg #define LOOP_VINFO_SCALAR_ITERATION_COST(L) (L)->scalar_cost_vec
380 1.6 mrg #define LOOP_VINFO_SINGLE_SCALAR_ITERATION_COST(L) (L)->single_scalar_iteration_cost
381 1.8 mrg #define LOOP_VINFO_ORIG_LOOP_INFO(L) (L)->orig_loop_info
382 1.1 mrg
383 1.8 mrg #define LOOP_REQUIRES_VERSIONING_FOR_ALIGNMENT(L) \
384 1.5 mrg ((L)->may_misalign_stmts.length () > 0)
385 1.8 mrg #define LOOP_REQUIRES_VERSIONING_FOR_ALIAS(L) \
386 1.5 mrg ((L)->may_alias_ddrs.length () > 0)
387 1.8 mrg #define LOOP_REQUIRES_VERSIONING_FOR_NITERS(L) \
388 1.8 mrg (LOOP_VINFO_NITERS_ASSUMPTIONS (L))
389 1.8 mrg #define LOOP_REQUIRES_VERSIONING(L) \
390 1.8 mrg (LOOP_REQUIRES_VERSIONING_FOR_ALIGNMENT (L) \
391 1.8 mrg || LOOP_REQUIRES_VERSIONING_FOR_ALIAS (L) \
392 1.8 mrg || LOOP_REQUIRES_VERSIONING_FOR_NITERS (L))
393 1.1 mrg
394 1.1 mrg #define LOOP_VINFO_NITERS_KNOWN_P(L) \
395 1.5 mrg (tree_fits_shwi_p ((L)->num_iters) && tree_to_shwi ((L)->num_iters) > 0)
396 1.1 mrg
397 1.8 mrg #define LOOP_VINFO_EPILOGUE_P(L) \
398 1.8 mrg (LOOP_VINFO_ORIG_LOOP_INFO (L) != NULL)
399 1.8 mrg
400 1.8 mrg #define LOOP_VINFO_ORIG_VECT_FACTOR(L) \
401 1.8 mrg (LOOP_VINFO_VECT_FACTOR (LOOP_VINFO_ORIG_LOOP_INFO (L)))
402 1.8 mrg
403 1.1 mrg static inline loop_vec_info
404 1.1 mrg loop_vec_info_for_loop (struct loop *loop)
405 1.1 mrg {
406 1.1 mrg return (loop_vec_info) loop->aux;
407 1.1 mrg }
408 1.1 mrg
409 1.1 mrg static inline bool
410 1.6 mrg nested_in_vect_loop_p (struct loop *loop, gimple *stmt)
411 1.1 mrg {
412 1.1 mrg return (loop->inner
413 1.1 mrg && (loop->inner == (gimple_bb (stmt))->loop_father));
414 1.1 mrg }
415 1.1 mrg
416 1.6 mrg typedef struct _bb_vec_info : public vec_info
417 1.6 mrg {
418 1.1 mrg basic_block bb;
419 1.6 mrg gimple_stmt_iterator region_begin;
420 1.6 mrg gimple_stmt_iterator region_end;
421 1.1 mrg } *bb_vec_info;
422 1.1 mrg
423 1.3 mrg #define BB_VINFO_BB(B) (B)->bb
424 1.3 mrg #define BB_VINFO_GROUPED_STORES(B) (B)->grouped_stores
425 1.3 mrg #define BB_VINFO_SLP_INSTANCES(B) (B)->slp_instances
426 1.3 mrg #define BB_VINFO_DATAREFS(B) (B)->datarefs
427 1.3 mrg #define BB_VINFO_DDRS(B) (B)->ddrs
428 1.3 mrg #define BB_VINFO_TARGET_COST_DATA(B) (B)->target_cost_data
429 1.1 mrg
430 1.1 mrg static inline bb_vec_info
431 1.1 mrg vec_info_for_bb (basic_block bb)
432 1.1 mrg {
433 1.1 mrg return (bb_vec_info) bb->aux;
434 1.1 mrg }
435 1.1 mrg
436 1.1 mrg /*-----------------------------------------------------------------*/
437 1.1 mrg /* Info on vectorized defs. */
438 1.1 mrg /*-----------------------------------------------------------------*/
439 1.1 mrg enum stmt_vec_info_type {
440 1.1 mrg undef_vec_info_type = 0,
441 1.1 mrg load_vec_info_type,
442 1.1 mrg store_vec_info_type,
443 1.1 mrg shift_vec_info_type,
444 1.1 mrg op_vec_info_type,
445 1.1 mrg call_vec_info_type,
446 1.5 mrg call_simd_clone_vec_info_type,
447 1.1 mrg assignment_vec_info_type,
448 1.1 mrg condition_vec_info_type,
449 1.6 mrg comparison_vec_info_type,
450 1.1 mrg reduc_vec_info_type,
451 1.1 mrg induc_vec_info_type,
452 1.1 mrg type_promotion_vec_info_type,
453 1.1 mrg type_demotion_vec_info_type,
454 1.1 mrg type_conversion_vec_info_type,
455 1.1 mrg loop_exit_ctrl_vec_info_type
456 1.1 mrg };
457 1.1 mrg
458 1.1 mrg /* Indicates whether/how a variable is used in the scope of loop/basic
459 1.1 mrg block. */
460 1.1 mrg enum vect_relevant {
461 1.1 mrg vect_unused_in_scope = 0,
462 1.8 mrg
463 1.8 mrg /* The def is only used outside the loop. */
464 1.8 mrg vect_used_only_live,
465 1.1 mrg /* The def is in the inner loop, and the use is in the outer loop, and the
466 1.1 mrg use is a reduction stmt. */
467 1.1 mrg vect_used_in_outer_by_reduction,
468 1.1 mrg /* The def is in the inner loop, and the use is in the outer loop (and is
469 1.1 mrg not part of reduction). */
470 1.1 mrg vect_used_in_outer,
471 1.1 mrg
472 1.1 mrg /* defs that feed computations that end up (only) in a reduction. These
473 1.1 mrg defs may be used by non-reduction stmts, but eventually, any
474 1.1 mrg computations/values that are affected by these defs are used to compute
475 1.1 mrg a reduction (i.e. don't get stored to memory, for example). We use this
476 1.1 mrg to identify computations that we can change the order in which they are
477 1.1 mrg computed. */
478 1.1 mrg vect_used_by_reduction,
479 1.1 mrg
480 1.1 mrg vect_used_in_scope
481 1.1 mrg };
482 1.1 mrg
483 1.1 mrg /* The type of vectorization that can be applied to the stmt: regular loop-based
484 1.1 mrg vectorization; pure SLP - the stmt is a part of SLP instances and does not
485 1.1 mrg have uses outside SLP instances; or hybrid SLP and loop-based - the stmt is
486 1.1 mrg a part of SLP instance and also must be loop-based vectorized, since it has
487 1.1 mrg uses outside SLP sequences.
488 1.1 mrg
489 1.1 mrg In the loop context the meanings of pure and hybrid SLP are slightly
490 1.1 mrg different. By saying that pure SLP is applied to the loop, we mean that we
491 1.1 mrg exploit only intra-iteration parallelism in the loop; i.e., the loop can be
492 1.1 mrg vectorized without doing any conceptual unrolling, cause we don't pack
493 1.1 mrg together stmts from different iterations, only within a single iteration.
494 1.1 mrg Loop hybrid SLP means that we exploit both intra-iteration and
495 1.1 mrg inter-iteration parallelism (e.g., number of elements in the vector is 4
496 1.1 mrg and the slp-group-size is 2, in which case we don't have enough parallelism
497 1.1 mrg within an iteration, so we obtain the rest of the parallelism from subsequent
498 1.1 mrg iterations by unrolling the loop by 2). */
499 1.1 mrg enum slp_vect_type {
500 1.1 mrg loop_vect = 0,
501 1.1 mrg pure_slp,
502 1.1 mrg hybrid
503 1.1 mrg };
504 1.1 mrg
505 1.8 mrg /* Describes how we're going to vectorize an individual load or store,
506 1.8 mrg or a group of loads or stores. */
507 1.8 mrg enum vect_memory_access_type {
508 1.8 mrg /* An access to an invariant address. This is used only for loads. */
509 1.8 mrg VMAT_INVARIANT,
510 1.8 mrg
511 1.8 mrg /* A simple contiguous access. */
512 1.8 mrg VMAT_CONTIGUOUS,
513 1.8 mrg
514 1.8 mrg /* A contiguous access that goes down in memory rather than up,
515 1.8 mrg with no additional permutation. This is used only for stores
516 1.8 mrg of invariants. */
517 1.8 mrg VMAT_CONTIGUOUS_DOWN,
518 1.8 mrg
519 1.8 mrg /* A simple contiguous access in which the elements need to be permuted
520 1.8 mrg after loading or before storing. Only used for loop vectorization;
521 1.8 mrg SLP uses separate permutes. */
522 1.8 mrg VMAT_CONTIGUOUS_PERMUTE,
523 1.8 mrg
524 1.8 mrg /* A simple contiguous access in which the elements need to be reversed
525 1.8 mrg after loading or before storing. */
526 1.8 mrg VMAT_CONTIGUOUS_REVERSE,
527 1.8 mrg
528 1.8 mrg /* An access that uses IFN_LOAD_LANES or IFN_STORE_LANES. */
529 1.8 mrg VMAT_LOAD_STORE_LANES,
530 1.8 mrg
531 1.8 mrg /* An access in which each scalar element is loaded or stored
532 1.8 mrg individually. */
533 1.8 mrg VMAT_ELEMENTWISE,
534 1.8 mrg
535 1.8 mrg /* A hybrid of VMAT_CONTIGUOUS and VMAT_ELEMENTWISE, used for grouped
536 1.8 mrg SLP accesses. Each unrolled iteration uses a contiguous load
537 1.8 mrg or store for the whole group, but the groups from separate iterations
538 1.8 mrg are combined in the same way as for VMAT_ELEMENTWISE. */
539 1.8 mrg VMAT_STRIDED_SLP,
540 1.8 mrg
541 1.8 mrg /* The access uses gather loads or scatter stores. */
542 1.8 mrg VMAT_GATHER_SCATTER
543 1.8 mrg };
544 1.1 mrg
545 1.1 mrg typedef struct data_reference *dr_p;
546 1.1 mrg
547 1.1 mrg typedef struct _stmt_vec_info {
548 1.1 mrg
549 1.1 mrg enum stmt_vec_info_type type;
550 1.1 mrg
551 1.3 mrg /* Indicates whether this stmts is part of a computation whose result is
552 1.3 mrg used outside the loop. */
553 1.3 mrg bool live;
554 1.3 mrg
555 1.3 mrg /* Stmt is part of some pattern (computation idiom) */
556 1.3 mrg bool in_pattern_p;
557 1.3 mrg
558 1.8 mrg /* Is this statement vectorizable or should it be skipped in (partial)
559 1.8 mrg vectorization. */
560 1.8 mrg bool vectorizable;
561 1.8 mrg
562 1.1 mrg /* The stmt to which this info struct refers to. */
563 1.6 mrg gimple *stmt;
564 1.1 mrg
565 1.6 mrg /* The vec_info with respect to which STMT is vectorized. */
566 1.6 mrg vec_info *vinfo;
567 1.1 mrg
568 1.3 mrg /* The vector type to be used for the LHS of this statement. */
569 1.1 mrg tree vectype;
570 1.1 mrg
571 1.1 mrg /* The vectorized version of the stmt. */
572 1.6 mrg gimple *vectorized_stmt;
573 1.1 mrg
574 1.1 mrg
575 1.1 mrg /** The following is relevant only for stmts that contain a non-scalar
576 1.1 mrg data-ref (array/pointer/struct access). A GIMPLE stmt is expected to have
577 1.1 mrg at most one such data-ref. **/
578 1.1 mrg
579 1.1 mrg /* Information about the data-ref (access function, etc),
580 1.1 mrg relative to the inner-most containing loop. */
581 1.1 mrg struct data_reference *data_ref_info;
582 1.1 mrg
583 1.1 mrg /* Information about the data-ref relative to this loop
584 1.1 mrg nest (the loop that is being considered for vectorization). */
585 1.1 mrg tree dr_base_address;
586 1.1 mrg tree dr_init;
587 1.1 mrg tree dr_offset;
588 1.1 mrg tree dr_step;
589 1.1 mrg tree dr_aligned_to;
590 1.1 mrg
591 1.6 mrg /* For loop PHI nodes, the base and evolution part of it. This makes sure
592 1.3 mrg this information is still available in vect_update_ivs_after_vectorizer
593 1.3 mrg where we may not be able to re-analyze the PHI nodes evolution as
594 1.3 mrg peeling for the prologue loop can make it unanalyzable. The evolution
595 1.6 mrg part is still correct after peeling, but the base may have changed from
596 1.6 mrg the version here. */
597 1.6 mrg tree loop_phi_evolution_base_unchanged;
598 1.3 mrg tree loop_phi_evolution_part;
599 1.1 mrg
600 1.1 mrg /* Used for various bookkeeping purposes, generally holding a pointer to
601 1.1 mrg some other stmt S that is in some way "related" to this stmt.
602 1.1 mrg Current use of this field is:
603 1.1 mrg If this stmt is part of a pattern (i.e. the field 'in_pattern_p' is
604 1.1 mrg true): S is the "pattern stmt" that represents (and replaces) the
605 1.1 mrg sequence of stmts that constitutes the pattern. Similarly, the
606 1.1 mrg related_stmt of the "pattern stmt" points back to this stmt (which is
607 1.1 mrg the last stmt in the original sequence of stmts that constitutes the
608 1.1 mrg pattern). */
609 1.6 mrg gimple *related_stmt;
610 1.1 mrg
611 1.3 mrg /* Used to keep a sequence of def stmts of a pattern stmt if such exists. */
612 1.3 mrg gimple_seq pattern_def_seq;
613 1.3 mrg
614 1.1 mrg /* List of datarefs that are known to have the same alignment as the dataref
615 1.1 mrg of this stmt. */
616 1.3 mrg vec<dr_p> same_align_refs;
617 1.1 mrg
618 1.5 mrg /* Selected SIMD clone's function info. First vector element
619 1.5 mrg is SIMD clone's function decl, followed by a pair of trees (base + step)
620 1.5 mrg for linear arguments (pair of NULLs for other arguments). */
621 1.5 mrg vec<tree> simd_clone_info;
622 1.5 mrg
623 1.1 mrg /* Classify the def of this stmt. */
624 1.1 mrg enum vect_def_type def_type;
625 1.1 mrg
626 1.3 mrg /* Whether the stmt is SLPed, loop-based vectorized, or both. */
627 1.3 mrg enum slp_vect_type slp_type;
628 1.3 mrg
629 1.3 mrg /* Interleaving and reduction chains info. */
630 1.3 mrg /* First element in the group. */
631 1.6 mrg gimple *first_element;
632 1.3 mrg /* Pointer to the next element in the group. */
633 1.6 mrg gimple *next_element;
634 1.3 mrg /* For data-refs, in case that two or more stmts share data-ref, this is the
635 1.3 mrg pointer to the previously detected stmt with the same dr. */
636 1.6 mrg gimple *same_dr_stmt;
637 1.3 mrg /* The size of the group. */
638 1.1 mrg unsigned int size;
639 1.1 mrg /* For stores, number of stores from this group seen. We vectorize the last
640 1.1 mrg one. */
641 1.1 mrg unsigned int store_count;
642 1.1 mrg /* For loads only, the gap from the previous load. For consecutive loads, GAP
643 1.1 mrg is 1. */
644 1.1 mrg unsigned int gap;
645 1.1 mrg
646 1.3 mrg /* The minimum negative dependence distance this stmt participates in
647 1.3 mrg or zero if none. */
648 1.3 mrg unsigned int min_neg_dist;
649 1.1 mrg
650 1.3 mrg /* Not all stmts in the loop need to be vectorized. e.g, the increment
651 1.3 mrg of the loop induction variable and computation of array indexes. relevant
652 1.3 mrg indicates whether the stmt needs to be vectorized. */
653 1.3 mrg enum vect_relevant relevant;
654 1.1 mrg
655 1.6 mrg /* For loads if this is a gather, for stores if this is a scatter. */
656 1.6 mrg bool gather_scatter_p;
657 1.6 mrg
658 1.6 mrg /* True if this is an access with loop-invariant stride. */
659 1.6 mrg bool strided_p;
660 1.5 mrg
661 1.5 mrg /* For both loads and stores. */
662 1.5 mrg bool simd_lane_access_p;
663 1.6 mrg
664 1.8 mrg /* Classifies how the load or store is going to be implemented
665 1.8 mrg for loop vectorization. */
666 1.8 mrg vect_memory_access_type memory_access_type;
667 1.8 mrg
668 1.6 mrg /* For reduction loops, this is the type of reduction. */
669 1.6 mrg enum vect_reduction_type v_reduc_type;
670 1.6 mrg
671 1.8 mrg /* For CONST_COND_REDUCTION, record the reduc code. */
672 1.8 mrg enum tree_code const_cond_reduc_code;
673 1.8 mrg
674 1.6 mrg /* The number of scalar stmt references from active SLP instances. */
675 1.6 mrg unsigned int num_slp_uses;
676 1.1 mrg } *stmt_vec_info;
677 1.1 mrg
678 1.8 mrg /* Information about a gather/scatter call. */
679 1.8 mrg struct gather_scatter_info {
680 1.8 mrg /* The FUNCTION_DECL for the built-in gather/scatter function. */
681 1.8 mrg tree decl;
682 1.8 mrg
683 1.8 mrg /* The loop-invariant base value. */
684 1.8 mrg tree base;
685 1.8 mrg
686 1.8 mrg /* The original scalar offset, which is a non-loop-invariant SSA_NAME. */
687 1.8 mrg tree offset;
688 1.8 mrg
689 1.8 mrg /* Each offset element should be multiplied by this amount before
690 1.8 mrg being added to the base. */
691 1.8 mrg int scale;
692 1.8 mrg
693 1.8 mrg /* The definition type for the vectorized offset. */
694 1.8 mrg enum vect_def_type offset_dt;
695 1.8 mrg
696 1.8 mrg /* The type of the vectorized offset. */
697 1.8 mrg tree offset_vectype;
698 1.8 mrg };
699 1.8 mrg
700 1.1 mrg /* Access Functions. */
701 1.1 mrg #define STMT_VINFO_TYPE(S) (S)->type
702 1.1 mrg #define STMT_VINFO_STMT(S) (S)->stmt
703 1.6 mrg inline loop_vec_info
704 1.6 mrg STMT_VINFO_LOOP_VINFO (stmt_vec_info stmt_vinfo)
705 1.6 mrg {
706 1.6 mrg if (loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (stmt_vinfo->vinfo))
707 1.6 mrg return loop_vinfo;
708 1.6 mrg return NULL;
709 1.6 mrg }
710 1.6 mrg inline bb_vec_info
711 1.6 mrg STMT_VINFO_BB_VINFO (stmt_vec_info stmt_vinfo)
712 1.6 mrg {
713 1.6 mrg if (bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (stmt_vinfo->vinfo))
714 1.6 mrg return bb_vinfo;
715 1.6 mrg return NULL;
716 1.6 mrg }
717 1.1 mrg #define STMT_VINFO_RELEVANT(S) (S)->relevant
718 1.1 mrg #define STMT_VINFO_LIVE_P(S) (S)->live
719 1.1 mrg #define STMT_VINFO_VECTYPE(S) (S)->vectype
720 1.1 mrg #define STMT_VINFO_VEC_STMT(S) (S)->vectorized_stmt
721 1.3 mrg #define STMT_VINFO_VECTORIZABLE(S) (S)->vectorizable
722 1.1 mrg #define STMT_VINFO_DATA_REF(S) (S)->data_ref_info
723 1.6 mrg #define STMT_VINFO_GATHER_SCATTER_P(S) (S)->gather_scatter_p
724 1.6 mrg #define STMT_VINFO_STRIDED_P(S) (S)->strided_p
725 1.8 mrg #define STMT_VINFO_MEMORY_ACCESS_TYPE(S) (S)->memory_access_type
726 1.5 mrg #define STMT_VINFO_SIMD_LANE_ACCESS_P(S) (S)->simd_lane_access_p
727 1.6 mrg #define STMT_VINFO_VEC_REDUCTION_TYPE(S) (S)->v_reduc_type
728 1.8 mrg #define STMT_VINFO_VEC_CONST_COND_REDUC_CODE(S) (S)->const_cond_reduc_code
729 1.1 mrg
730 1.1 mrg #define STMT_VINFO_DR_BASE_ADDRESS(S) (S)->dr_base_address
731 1.1 mrg #define STMT_VINFO_DR_INIT(S) (S)->dr_init
732 1.1 mrg #define STMT_VINFO_DR_OFFSET(S) (S)->dr_offset
733 1.1 mrg #define STMT_VINFO_DR_STEP(S) (S)->dr_step
734 1.1 mrg #define STMT_VINFO_DR_ALIGNED_TO(S) (S)->dr_aligned_to
735 1.1 mrg
736 1.1 mrg #define STMT_VINFO_IN_PATTERN_P(S) (S)->in_pattern_p
737 1.1 mrg #define STMT_VINFO_RELATED_STMT(S) (S)->related_stmt
738 1.3 mrg #define STMT_VINFO_PATTERN_DEF_SEQ(S) (S)->pattern_def_seq
739 1.1 mrg #define STMT_VINFO_SAME_ALIGN_REFS(S) (S)->same_align_refs
740 1.5 mrg #define STMT_VINFO_SIMD_CLONE_INFO(S) (S)->simd_clone_info
741 1.1 mrg #define STMT_VINFO_DEF_TYPE(S) (S)->def_type
742 1.3 mrg #define STMT_VINFO_GROUP_FIRST_ELEMENT(S) (S)->first_element
743 1.3 mrg #define STMT_VINFO_GROUP_NEXT_ELEMENT(S) (S)->next_element
744 1.3 mrg #define STMT_VINFO_GROUP_SIZE(S) (S)->size
745 1.3 mrg #define STMT_VINFO_GROUP_STORE_COUNT(S) (S)->store_count
746 1.3 mrg #define STMT_VINFO_GROUP_GAP(S) (S)->gap
747 1.3 mrg #define STMT_VINFO_GROUP_SAME_DR_STMT(S) (S)->same_dr_stmt
748 1.3 mrg #define STMT_VINFO_GROUPED_ACCESS(S) ((S)->first_element != NULL && (S)->data_ref_info)
749 1.6 mrg #define STMT_VINFO_LOOP_PHI_EVOLUTION_BASE_UNCHANGED(S) (S)->loop_phi_evolution_base_unchanged
750 1.3 mrg #define STMT_VINFO_LOOP_PHI_EVOLUTION_PART(S) (S)->loop_phi_evolution_part
751 1.3 mrg #define STMT_VINFO_MIN_NEG_DIST(S) (S)->min_neg_dist
752 1.6 mrg #define STMT_VINFO_NUM_SLP_USES(S) (S)->num_slp_uses
753 1.3 mrg
754 1.3 mrg #define GROUP_FIRST_ELEMENT(S) (S)->first_element
755 1.3 mrg #define GROUP_NEXT_ELEMENT(S) (S)->next_element
756 1.3 mrg #define GROUP_SIZE(S) (S)->size
757 1.3 mrg #define GROUP_STORE_COUNT(S) (S)->store_count
758 1.3 mrg #define GROUP_GAP(S) (S)->gap
759 1.3 mrg #define GROUP_SAME_DR_STMT(S) (S)->same_dr_stmt
760 1.1 mrg
761 1.1 mrg #define STMT_VINFO_RELEVANT_P(S) ((S)->relevant != vect_unused_in_scope)
762 1.1 mrg
763 1.1 mrg #define HYBRID_SLP_STMT(S) ((S)->slp_type == hybrid)
764 1.1 mrg #define PURE_SLP_STMT(S) ((S)->slp_type == pure_slp)
765 1.1 mrg #define STMT_SLP_TYPE(S) (S)->slp_type
766 1.1 mrg
767 1.5 mrg struct dataref_aux {
768 1.5 mrg int misalignment;
769 1.5 mrg /* If true the alignment of base_decl needs to be increased. */
770 1.5 mrg bool base_misaligned;
771 1.5 mrg /* If true we know the base is at least vector element alignment aligned. */
772 1.5 mrg bool base_element_aligned;
773 1.5 mrg tree base_decl;
774 1.5 mrg };
775 1.5 mrg
776 1.5 mrg #define DR_VECT_AUX(dr) ((dataref_aux *)(dr)->aux)
777 1.5 mrg
778 1.3 mrg #define VECT_MAX_COST 1000
779 1.1 mrg
780 1.1 mrg /* The maximum number of intermediate steps required in multi-step type
781 1.1 mrg conversion. */
782 1.1 mrg #define MAX_INTERM_CVT_STEPS 3
783 1.1 mrg
784 1.5 mrg /* The maximum vectorization factor supported by any target (V64QI). */
785 1.5 mrg #define MAX_VECTORIZATION_FACTOR 64
786 1.3 mrg
787 1.8 mrg /* Nonzero if TYPE represents a (scalar) boolean type or type
788 1.8 mrg in the middle-end compatible with it (unsigned precision 1 integral
789 1.8 mrg types). Used to determine which types should be vectorized as
790 1.8 mrg VECTOR_BOOLEAN_TYPE_P. */
791 1.8 mrg
792 1.8 mrg #define VECT_SCALAR_BOOLEAN_TYPE_P(TYPE) \
793 1.8 mrg (TREE_CODE (TYPE) == BOOLEAN_TYPE \
794 1.8 mrg || ((TREE_CODE (TYPE) == INTEGER_TYPE \
795 1.8 mrg || TREE_CODE (TYPE) == ENUMERAL_TYPE) \
796 1.8 mrg && TYPE_PRECISION (TYPE) == 1 \
797 1.8 mrg && TYPE_UNSIGNED (TYPE)))
798 1.8 mrg
799 1.6 mrg extern vec<stmt_vec_info> stmt_vec_info_vec;
800 1.1 mrg
801 1.1 mrg void init_stmt_vec_info_vec (void);
802 1.1 mrg void free_stmt_vec_info_vec (void);
803 1.1 mrg
804 1.3 mrg /* Return a stmt_vec_info corresponding to STMT. */
805 1.3 mrg
806 1.1 mrg static inline stmt_vec_info
807 1.6 mrg vinfo_for_stmt (gimple *stmt)
808 1.1 mrg {
809 1.1 mrg unsigned int uid = gimple_uid (stmt);
810 1.1 mrg if (uid == 0)
811 1.1 mrg return NULL;
812 1.1 mrg
813 1.6 mrg return stmt_vec_info_vec[uid - 1];
814 1.1 mrg }
815 1.1 mrg
816 1.3 mrg /* Set vectorizer information INFO for STMT. */
817 1.3 mrg
818 1.1 mrg static inline void
819 1.6 mrg set_vinfo_for_stmt (gimple *stmt, stmt_vec_info info)
820 1.1 mrg {
821 1.1 mrg unsigned int uid = gimple_uid (stmt);
822 1.1 mrg if (uid == 0)
823 1.1 mrg {
824 1.3 mrg gcc_checking_assert (info);
825 1.3 mrg uid = stmt_vec_info_vec.length () + 1;
826 1.1 mrg gimple_set_uid (stmt, uid);
827 1.6 mrg stmt_vec_info_vec.safe_push (info);
828 1.1 mrg }
829 1.1 mrg else
830 1.6 mrg {
831 1.6 mrg gcc_checking_assert (info == NULL);
832 1.6 mrg stmt_vec_info_vec[uid - 1] = info;
833 1.6 mrg }
834 1.1 mrg }
835 1.1 mrg
836 1.8 mrg /* Return TRUE if a statement represented by STMT_INFO is a part of a
837 1.8 mrg pattern. */
838 1.3 mrg
839 1.8 mrg static inline bool
840 1.8 mrg is_pattern_stmt_p (stmt_vec_info stmt_info)
841 1.1 mrg {
842 1.8 mrg gimple *related_stmt;
843 1.8 mrg stmt_vec_info related_stmt_info;
844 1.1 mrg
845 1.8 mrg related_stmt = STMT_VINFO_RELATED_STMT (stmt_info);
846 1.8 mrg if (related_stmt
847 1.8 mrg && (related_stmt_info = vinfo_for_stmt (related_stmt))
848 1.8 mrg && STMT_VINFO_IN_PATTERN_P (related_stmt_info))
849 1.8 mrg return true;
850 1.1 mrg
851 1.8 mrg return false;
852 1.1 mrg }
853 1.1 mrg
854 1.3 mrg /* Return the later statement between STMT1 and STMT2. */
855 1.3 mrg
856 1.6 mrg static inline gimple *
857 1.6 mrg get_later_stmt (gimple *stmt1, gimple *stmt2)
858 1.3 mrg {
859 1.3 mrg unsigned int uid1, uid2;
860 1.3 mrg
861 1.3 mrg if (stmt1 == NULL)
862 1.3 mrg return stmt2;
863 1.3 mrg
864 1.3 mrg if (stmt2 == NULL)
865 1.3 mrg return stmt1;
866 1.3 mrg
867 1.8 mrg stmt_vec_info stmt_info1 = vinfo_for_stmt (stmt1);
868 1.8 mrg stmt_vec_info stmt_info2 = vinfo_for_stmt (stmt2);
869 1.8 mrg uid1 = gimple_uid (is_pattern_stmt_p (stmt_info1)
870 1.8 mrg ? STMT_VINFO_RELATED_STMT (stmt_info1) : stmt1);
871 1.8 mrg uid2 = gimple_uid (is_pattern_stmt_p (stmt_info2)
872 1.8 mrg ? STMT_VINFO_RELATED_STMT (stmt_info2) : stmt2);
873 1.3 mrg
874 1.3 mrg if (uid1 == 0 || uid2 == 0)
875 1.3 mrg return NULL;
876 1.3 mrg
877 1.3 mrg gcc_assert (uid1 <= stmt_vec_info_vec.length ());
878 1.3 mrg gcc_assert (uid2 <= stmt_vec_info_vec.length ());
879 1.3 mrg
880 1.3 mrg if (uid1 > uid2)
881 1.3 mrg return stmt1;
882 1.3 mrg else
883 1.3 mrg return stmt2;
884 1.3 mrg }
885 1.3 mrg
886 1.3 mrg /* Return true if BB is a loop header. */
887 1.3 mrg
888 1.1 mrg static inline bool
889 1.1 mrg is_loop_header_bb_p (basic_block bb)
890 1.1 mrg {
891 1.1 mrg if (bb == (bb->loop_father)->header)
892 1.1 mrg return true;
893 1.3 mrg gcc_checking_assert (EDGE_COUNT (bb->preds) == 1);
894 1.1 mrg return false;
895 1.1 mrg }
896 1.1 mrg
897 1.3 mrg /* Return pow2 (X). */
898 1.1 mrg
899 1.1 mrg static inline int
900 1.1 mrg vect_pow2 (int x)
901 1.1 mrg {
902 1.1 mrg int i, res = 1;
903 1.1 mrg
904 1.1 mrg for (i = 0; i < x; i++)
905 1.1 mrg res *= 2;
906 1.1 mrg
907 1.1 mrg return res;
908 1.1 mrg }
909 1.1 mrg
910 1.3 mrg /* Alias targetm.vectorize.builtin_vectorization_cost. */
911 1.3 mrg
912 1.3 mrg static inline int
913 1.3 mrg builtin_vectorization_cost (enum vect_cost_for_stmt type_of_cost,
914 1.3 mrg tree vectype, int misalign)
915 1.3 mrg {
916 1.3 mrg return targetm.vectorize.builtin_vectorization_cost (type_of_cost,
917 1.3 mrg vectype, misalign);
918 1.3 mrg }
919 1.3 mrg
920 1.3 mrg /* Get cost by calling cost target builtin. */
921 1.3 mrg
922 1.3 mrg static inline
923 1.3 mrg int vect_get_stmt_cost (enum vect_cost_for_stmt type_of_cost)
924 1.3 mrg {
925 1.3 mrg return builtin_vectorization_cost (type_of_cost, NULL, 0);
926 1.3 mrg }
927 1.3 mrg
928 1.3 mrg /* Alias targetm.vectorize.init_cost. */
929 1.3 mrg
930 1.3 mrg static inline void *
931 1.3 mrg init_cost (struct loop *loop_info)
932 1.3 mrg {
933 1.3 mrg return targetm.vectorize.init_cost (loop_info);
934 1.3 mrg }
935 1.3 mrg
936 1.3 mrg /* Alias targetm.vectorize.add_stmt_cost. */
937 1.3 mrg
938 1.3 mrg static inline unsigned
939 1.3 mrg add_stmt_cost (void *data, int count, enum vect_cost_for_stmt kind,
940 1.3 mrg stmt_vec_info stmt_info, int misalign,
941 1.3 mrg enum vect_cost_model_location where)
942 1.3 mrg {
943 1.3 mrg return targetm.vectorize.add_stmt_cost (data, count, kind,
944 1.3 mrg stmt_info, misalign, where);
945 1.3 mrg }
946 1.3 mrg
947 1.3 mrg /* Alias targetm.vectorize.finish_cost. */
948 1.3 mrg
949 1.3 mrg static inline void
950 1.3 mrg finish_cost (void *data, unsigned *prologue_cost,
951 1.3 mrg unsigned *body_cost, unsigned *epilogue_cost)
952 1.3 mrg {
953 1.3 mrg targetm.vectorize.finish_cost (data, prologue_cost, body_cost, epilogue_cost);
954 1.3 mrg }
955 1.3 mrg
956 1.3 mrg /* Alias targetm.vectorize.destroy_cost_data. */
957 1.3 mrg
958 1.3 mrg static inline void
959 1.3 mrg destroy_cost_data (void *data)
960 1.3 mrg {
961 1.3 mrg targetm.vectorize.destroy_cost_data (data);
962 1.3 mrg }
963 1.3 mrg
964 1.1 mrg /*-----------------------------------------------------------------*/
965 1.1 mrg /* Info on data references alignment. */
966 1.1 mrg /*-----------------------------------------------------------------*/
967 1.5 mrg inline void
968 1.5 mrg set_dr_misalignment (struct data_reference *dr, int val)
969 1.5 mrg {
970 1.5 mrg dataref_aux *data_aux = DR_VECT_AUX (dr);
971 1.5 mrg
972 1.5 mrg if (!data_aux)
973 1.5 mrg {
974 1.5 mrg data_aux = XCNEW (dataref_aux);
975 1.5 mrg dr->aux = data_aux;
976 1.5 mrg }
977 1.5 mrg
978 1.5 mrg data_aux->misalignment = val;
979 1.5 mrg }
980 1.5 mrg
981 1.5 mrg inline int
982 1.5 mrg dr_misalignment (struct data_reference *dr)
983 1.5 mrg {
984 1.5 mrg return DR_VECT_AUX (dr)->misalignment;
985 1.5 mrg }
986 1.1 mrg
987 1.1 mrg /* Reflects actual alignment of first access in the vectorized loop,
988 1.1 mrg taking into account peeling/versioning if applied. */
989 1.5 mrg #define DR_MISALIGNMENT(DR) dr_misalignment (DR)
990 1.5 mrg #define SET_DR_MISALIGNMENT(DR, VAL) set_dr_misalignment (DR, VAL)
991 1.1 mrg
992 1.3 mrg /* Return TRUE if the data access is aligned, and FALSE otherwise. */
993 1.3 mrg
994 1.1 mrg static inline bool
995 1.1 mrg aligned_access_p (struct data_reference *data_ref_info)
996 1.1 mrg {
997 1.1 mrg return (DR_MISALIGNMENT (data_ref_info) == 0);
998 1.1 mrg }
999 1.1 mrg
1000 1.3 mrg /* Return TRUE if the alignment of the data access is known, and FALSE
1001 1.3 mrg otherwise. */
1002 1.3 mrg
1003 1.1 mrg static inline bool
1004 1.1 mrg known_alignment_for_access_p (struct data_reference *data_ref_info)
1005 1.1 mrg {
1006 1.1 mrg return (DR_MISALIGNMENT (data_ref_info) != -1);
1007 1.1 mrg }
1008 1.1 mrg
1009 1.5 mrg
1010 1.5 mrg /* Return true if the vect cost model is unlimited. */
1011 1.5 mrg static inline bool
1012 1.5 mrg unlimited_cost_model (loop_p loop)
1013 1.5 mrg {
1014 1.5 mrg if (loop != NULL && loop->force_vectorize
1015 1.5 mrg && flag_simd_cost_model != VECT_COST_MODEL_DEFAULT)
1016 1.5 mrg return flag_simd_cost_model == VECT_COST_MODEL_UNLIMITED;
1017 1.5 mrg return (flag_vect_cost_model == VECT_COST_MODEL_UNLIMITED);
1018 1.5 mrg }
1019 1.5 mrg
1020 1.3 mrg /* Source location */
1021 1.5 mrg extern source_location vect_location;
1022 1.1 mrg
1023 1.1 mrg /*-----------------------------------------------------------------*/
1024 1.1 mrg /* Function prototypes. */
1025 1.1 mrg /*-----------------------------------------------------------------*/
1026 1.1 mrg
1027 1.1 mrg /* Simple loop peeling and versioning utilities for vectorizer's purposes -
1028 1.1 mrg in tree-vect-loop-manip.c. */
1029 1.1 mrg extern void slpeel_make_loop_iterate_ntimes (struct loop *, tree);
1030 1.1 mrg extern bool slpeel_can_duplicate_loop_p (const struct loop *, const_edge);
1031 1.5 mrg struct loop *slpeel_tree_duplicate_loop_to_edge_cfg (struct loop *,
1032 1.5 mrg struct loop *, edge);
1033 1.3 mrg extern void vect_loop_versioning (loop_vec_info, unsigned int, bool);
1034 1.8 mrg extern struct loop *vect_do_peeling (loop_vec_info, tree, tree,
1035 1.8 mrg tree *, int, bool, bool);
1036 1.5 mrg extern source_location find_loop_location (struct loop *);
1037 1.1 mrg extern bool vect_can_advance_ivs_p (loop_vec_info);
1038 1.1 mrg
1039 1.1 mrg /* In tree-vect-stmts.c. */
1040 1.3 mrg extern unsigned int current_vector_size;
1041 1.1 mrg extern tree get_vectype_for_scalar_type (tree);
1042 1.6 mrg extern tree get_mask_type_for_scalar_type (tree);
1043 1.3 mrg extern tree get_same_sized_vectype (tree, tree);
1044 1.6 mrg extern bool vect_is_simple_use (tree, vec_info *, gimple **,
1045 1.6 mrg enum vect_def_type *);
1046 1.6 mrg extern bool vect_is_simple_use (tree, vec_info *, gimple **,
1047 1.6 mrg enum vect_def_type *, tree *);
1048 1.6 mrg extern bool supportable_widening_operation (enum tree_code, gimple *, tree,
1049 1.6 mrg tree, enum tree_code *,
1050 1.6 mrg enum tree_code *, int *,
1051 1.6 mrg vec<tree> *);
1052 1.3 mrg extern bool supportable_narrowing_operation (enum tree_code, tree, tree,
1053 1.3 mrg enum tree_code *,
1054 1.3 mrg int *, vec<tree> *);
1055 1.6 mrg extern stmt_vec_info new_stmt_vec_info (gimple *stmt, vec_info *);
1056 1.6 mrg extern void free_stmt_vec_info (gimple *stmt);
1057 1.1 mrg extern void vect_model_simple_cost (stmt_vec_info, int, enum vect_def_type *,
1058 1.3 mrg stmt_vector_for_cost *,
1059 1.3 mrg stmt_vector_for_cost *);
1060 1.8 mrg extern void vect_model_store_cost (stmt_vec_info, int, vect_memory_access_type,
1061 1.3 mrg enum vect_def_type, slp_tree,
1062 1.3 mrg stmt_vector_for_cost *,
1063 1.3 mrg stmt_vector_for_cost *);
1064 1.8 mrg extern void vect_model_load_cost (stmt_vec_info, int, vect_memory_access_type,
1065 1.8 mrg slp_tree, stmt_vector_for_cost *,
1066 1.3 mrg stmt_vector_for_cost *);
1067 1.3 mrg extern unsigned record_stmt_cost (stmt_vector_for_cost *, int,
1068 1.3 mrg enum vect_cost_for_stmt, stmt_vec_info,
1069 1.3 mrg int, enum vect_cost_model_location);
1070 1.6 mrg extern void vect_finish_stmt_generation (gimple *, gimple *,
1071 1.1 mrg gimple_stmt_iterator *);
1072 1.1 mrg extern bool vect_mark_stmts_to_be_vectorized (loop_vec_info);
1073 1.8 mrg extern tree vect_get_vec_def_for_operand_1 (gimple *, enum vect_def_type);
1074 1.6 mrg extern tree vect_get_vec_def_for_operand (tree, gimple *, tree = NULL);
1075 1.6 mrg extern tree vect_init_vector (gimple *, tree, tree,
1076 1.1 mrg gimple_stmt_iterator *);
1077 1.1 mrg extern tree vect_get_vec_def_for_stmt_copy (enum vect_def_type, tree);
1078 1.6 mrg extern bool vect_transform_stmt (gimple *, gimple_stmt_iterator *,
1079 1.1 mrg bool *, slp_tree, slp_instance);
1080 1.6 mrg extern void vect_remove_stores (gimple *);
1081 1.6 mrg extern bool vect_analyze_stmt (gimple *, bool *, slp_tree);
1082 1.6 mrg extern bool vectorizable_condition (gimple *, gimple_stmt_iterator *,
1083 1.6 mrg gimple **, tree, int, slp_tree);
1084 1.3 mrg extern void vect_get_load_cost (struct data_reference *, int, bool,
1085 1.3 mrg unsigned int *, unsigned int *,
1086 1.3 mrg stmt_vector_for_cost *,
1087 1.3 mrg stmt_vector_for_cost *, bool);
1088 1.3 mrg extern void vect_get_store_cost (struct data_reference *, int,
1089 1.3 mrg unsigned int *, stmt_vector_for_cost *);
1090 1.3 mrg extern bool vect_supportable_shift (enum tree_code, tree);
1091 1.6 mrg extern void vect_get_vec_defs (tree, tree, gimple *, vec<tree> *,
1092 1.3 mrg vec<tree> *, slp_tree, int);
1093 1.5 mrg extern tree vect_gen_perm_mask_any (tree, const unsigned char *);
1094 1.5 mrg extern tree vect_gen_perm_mask_checked (tree, const unsigned char *);
1095 1.6 mrg extern void optimize_mask_stores (struct loop*);
1096 1.1 mrg
1097 1.1 mrg /* In tree-vect-data-refs.c. */
1098 1.1 mrg extern bool vect_can_force_dr_alignment_p (const_tree, unsigned int);
1099 1.1 mrg extern enum dr_alignment_support vect_supportable_dr_alignment
1100 1.3 mrg (struct data_reference *, bool);
1101 1.6 mrg extern tree vect_get_smallest_scalar_type (gimple *, HOST_WIDE_INT *,
1102 1.1 mrg HOST_WIDE_INT *);
1103 1.5 mrg extern bool vect_analyze_data_ref_dependences (loop_vec_info, int *);
1104 1.6 mrg extern bool vect_slp_analyze_instance_dependence (slp_instance);
1105 1.1 mrg extern bool vect_enhance_data_refs_alignment (loop_vec_info);
1106 1.6 mrg extern bool vect_analyze_data_refs_alignment (loop_vec_info);
1107 1.6 mrg extern bool vect_verify_datarefs_alignment (loop_vec_info);
1108 1.6 mrg extern bool vect_slp_analyze_and_verify_instance_alignment (slp_instance);
1109 1.6 mrg extern bool vect_analyze_data_ref_accesses (vec_info *);
1110 1.1 mrg extern bool vect_prune_runtime_alias_test_list (loop_vec_info);
1111 1.8 mrg extern bool vect_check_gather_scatter (gimple *, loop_vec_info,
1112 1.8 mrg gather_scatter_info *);
1113 1.6 mrg extern bool vect_analyze_data_refs (vec_info *, int *);
1114 1.6 mrg extern tree vect_create_data_ref_ptr (gimple *, tree, struct loop *, tree,
1115 1.3 mrg tree *, gimple_stmt_iterator *,
1116 1.6 mrg gimple **, bool, bool *,
1117 1.3 mrg tree = NULL_TREE);
1118 1.6 mrg extern tree bump_vector_ptr (tree, gimple *, gimple_stmt_iterator *, gimple *,
1119 1.6 mrg tree);
1120 1.1 mrg extern tree vect_create_destination_var (tree, tree);
1121 1.3 mrg extern bool vect_grouped_store_supported (tree, unsigned HOST_WIDE_INT);
1122 1.3 mrg extern bool vect_store_lanes_supported (tree, unsigned HOST_WIDE_INT);
1123 1.8 mrg extern bool vect_grouped_load_supported (tree, bool, unsigned HOST_WIDE_INT);
1124 1.3 mrg extern bool vect_load_lanes_supported (tree, unsigned HOST_WIDE_INT);
1125 1.6 mrg extern void vect_permute_store_chain (vec<tree> ,unsigned int, gimple *,
1126 1.3 mrg gimple_stmt_iterator *, vec<tree> *);
1127 1.6 mrg extern tree vect_setup_realignment (gimple *, gimple_stmt_iterator *, tree *,
1128 1.1 mrg enum dr_alignment_support, tree,
1129 1.1 mrg struct loop **);
1130 1.6 mrg extern void vect_transform_grouped_load (gimple *, vec<tree> , int,
1131 1.1 mrg gimple_stmt_iterator *);
1132 1.6 mrg extern void vect_record_grouped_load_vectors (gimple *, vec<tree> );
1133 1.1 mrg extern tree vect_get_new_vect_var (tree, enum vect_var_kind, const char *);
1134 1.6 mrg extern tree vect_get_new_ssa_name (tree, enum vect_var_kind,
1135 1.6 mrg const char * = NULL);
1136 1.6 mrg extern tree vect_create_addr_base_for_vector_ref (gimple *, gimple_seq *,
1137 1.3 mrg tree, struct loop *,
1138 1.3 mrg tree = NULL_TREE);
1139 1.1 mrg
1140 1.1 mrg /* In tree-vect-loop.c. */
1141 1.1 mrg /* FORNOW: Used in tree-parloops.c. */
1142 1.1 mrg extern void destroy_loop_vec_info (loop_vec_info, bool);
1143 1.6 mrg extern gimple *vect_force_simple_reduction (loop_vec_info, gimple *, bool,
1144 1.6 mrg bool *, bool);
1145 1.1 mrg /* Drive for loop analysis stage. */
1146 1.8 mrg extern loop_vec_info vect_analyze_loop (struct loop *, loop_vec_info);
1147 1.8 mrg extern tree vect_build_loop_niters (loop_vec_info);
1148 1.8 mrg extern void vect_gen_vector_loop_niters (loop_vec_info, tree, tree *, bool);
1149 1.1 mrg /* Drive for loop transformation stage. */
1150 1.8 mrg extern struct loop *vect_transform_loop (loop_vec_info);
1151 1.1 mrg extern loop_vec_info vect_analyze_loop_form (struct loop *);
1152 1.6 mrg extern bool vectorizable_live_operation (gimple *, gimple_stmt_iterator *,
1153 1.8 mrg slp_tree, int, gimple **);
1154 1.6 mrg extern bool vectorizable_reduction (gimple *, gimple_stmt_iterator *,
1155 1.6 mrg gimple **, slp_tree);
1156 1.6 mrg extern bool vectorizable_induction (gimple *, gimple_stmt_iterator *, gimple **);
1157 1.6 mrg extern tree get_initial_def_for_reduction (gimple *, tree, tree *);
1158 1.1 mrg extern int vect_min_worthwhile_factor (enum tree_code);
1159 1.5 mrg extern int vect_get_known_peeling_cost (loop_vec_info, int, int *,
1160 1.5 mrg stmt_vector_for_cost *,
1161 1.3 mrg stmt_vector_for_cost *,
1162 1.3 mrg stmt_vector_for_cost *);
1163 1.1 mrg
1164 1.1 mrg /* In tree-vect-slp.c. */
1165 1.1 mrg extern void vect_free_slp_instance (slp_instance);
1166 1.5 mrg extern bool vect_transform_slp_perm_load (slp_tree, vec<tree> ,
1167 1.1 mrg gimple_stmt_iterator *, int,
1168 1.8 mrg slp_instance, bool, unsigned *);
1169 1.6 mrg extern bool vect_slp_analyze_operations (vec<slp_instance> slp_instances,
1170 1.6 mrg void *);
1171 1.6 mrg extern bool vect_schedule_slp (vec_info *);
1172 1.6 mrg extern bool vect_analyze_slp (vec_info *, unsigned);
1173 1.3 mrg extern bool vect_make_slp_decision (loop_vec_info);
1174 1.1 mrg extern void vect_detect_hybrid_slp (loop_vec_info);
1175 1.3 mrg extern void vect_get_slp_defs (vec<tree> , slp_tree,
1176 1.3 mrg vec<vec<tree> > *, int);
1177 1.6 mrg extern bool vect_slp_bb (basic_block);
1178 1.6 mrg extern gimple *vect_find_last_scalar_stmt_in_slp (slp_tree);
1179 1.8 mrg extern bool is_simple_and_all_uses_invariant (gimple *, loop_vec_info);
1180 1.1 mrg
1181 1.1 mrg /* In tree-vect-patterns.c. */
1182 1.1 mrg /* Pattern recognition functions.
1183 1.1 mrg Additional pattern recognition functions can (and will) be added
1184 1.1 mrg in the future. */
1185 1.6 mrg typedef gimple *(* vect_recog_func_ptr) (vec<gimple *> *, tree *, tree *);
1186 1.6 mrg #define NUM_PATTERNS 14
1187 1.6 mrg void vect_pattern_recog (vec_info *);
1188 1.1 mrg
1189 1.1 mrg /* In tree-vectorizer.c. */
1190 1.1 mrg unsigned vectorize_loops (void);
1191 1.6 mrg void vect_destroy_datarefs (vec_info *);
1192 1.6 mrg bool vect_stmt_in_region_p (vec_info *, gimple *);
1193 1.8 mrg void vect_free_loop_info_assumptions (struct loop *);
1194 1.1 mrg
1195 1.1 mrg #endif /* GCC_TREE_VECTORIZER_H */
1196