PR target/66563
[official-gcc.git] / gcc / tree-vectorizer.h
blobd3e788b878536c4156f841dec2156c1ff7792f63
1 /* Vectorizer
2 Copyright (C) 2003-2015 Free Software Foundation, Inc.
3 Contributed by Dorit Naishlos <dorit@il.ibm.com>
5 This file is part of GCC.
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 3, or (at your option) any later
10 version.
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.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #ifndef GCC_TREE_VECTORIZER_H
22 #define GCC_TREE_VECTORIZER_H
24 #include "tree-data-ref.h"
25 #include "target.h"
27 /* Used for naming of new temporaries. */
28 enum vect_var_kind {
29 vect_simple_var,
30 vect_pointer_var,
31 vect_scalar_var
34 /* Defines type of operation. */
35 enum operation_type {
36 unary_op = 1,
37 binary_op,
38 ternary_op
41 /* Define type of available alignment support. */
42 enum dr_alignment_support {
43 dr_unaligned_unsupported,
44 dr_unaligned_supported,
45 dr_explicit_realign,
46 dr_explicit_realign_optimized,
47 dr_aligned
50 /* Define type of def-use cross-iteration cycle. */
51 enum vect_def_type {
52 vect_uninitialized_def = 0,
53 vect_constant_def = 1,
54 vect_external_def,
55 vect_internal_def,
56 vect_induction_def,
57 vect_reduction_def,
58 vect_double_reduction_def,
59 vect_nested_cycle,
60 vect_unknown_def_type
63 #define VECTORIZABLE_CYCLE_DEF(D) (((D) == vect_reduction_def) \
64 || ((D) == vect_double_reduction_def) \
65 || ((D) == vect_nested_cycle))
67 /* Structure to encapsulate information about a group of like
68 instructions to be presented to the target cost model. */
69 typedef struct _stmt_info_for_cost {
70 int count;
71 enum vect_cost_for_stmt kind;
72 gimple stmt;
73 int misalign;
74 } stmt_info_for_cost;
77 typedef vec<stmt_info_for_cost> stmt_vector_for_cost;
79 static inline void
80 add_stmt_info_to_vec (stmt_vector_for_cost *stmt_cost_vec, int count,
81 enum vect_cost_for_stmt kind, gimple stmt, int misalign)
83 stmt_info_for_cost si;
84 si.count = count;
85 si.kind = kind;
86 si.stmt = stmt;
87 si.misalign = misalign;
88 stmt_cost_vec->safe_push (si);
91 /************************************************************************
92 SLP
93 ************************************************************************/
94 typedef struct _slp_tree *slp_tree;
96 /* A computation tree of an SLP instance. Each node corresponds to a group of
97 stmts to be packed in a SIMD stmt. */
98 struct _slp_tree {
99 /* Nodes that contain def-stmts of this node statements operands. */
100 vec<slp_tree> children;
101 /* A group of scalar stmts to be vectorized together. */
102 vec<gimple> stmts;
103 /* Load permutation relative to the stores, NULL if there is no
104 permutation. */
105 vec<unsigned> load_permutation;
106 /* Vectorized stmt/s. */
107 vec<gimple> vec_stmts;
108 /* Number of vector stmts that are created to replace the group of scalar
109 stmts. It is calculated during the transformation phase as the number of
110 scalar elements in one scalar iteration (GROUP_SIZE) multiplied by VF
111 divided by vector size. */
112 unsigned int vec_stmts_size;
113 /* Whether the scalar computations use two different operators. */
114 bool two_operators;
118 /* SLP instance is a sequence of stmts in a loop that can be packed into
119 SIMD stmts. */
120 typedef struct _slp_instance {
121 /* The root of SLP tree. */
122 slp_tree root;
124 /* Size of groups of scalar stmts that will be replaced by SIMD stmt/s. */
125 unsigned int group_size;
127 /* The unrolling factor required to vectorized this SLP instance. */
128 unsigned int unrolling_factor;
130 /* The group of nodes that contain loads of this SLP instance. */
131 vec<slp_tree> loads;
132 } *slp_instance;
135 /* Access Functions. */
136 #define SLP_INSTANCE_TREE(S) (S)->root
137 #define SLP_INSTANCE_GROUP_SIZE(S) (S)->group_size
138 #define SLP_INSTANCE_UNROLLING_FACTOR(S) (S)->unrolling_factor
139 #define SLP_INSTANCE_LOADS(S) (S)->loads
141 #define SLP_TREE_CHILDREN(S) (S)->children
142 #define SLP_TREE_SCALAR_STMTS(S) (S)->stmts
143 #define SLP_TREE_VEC_STMTS(S) (S)->vec_stmts
144 #define SLP_TREE_NUMBER_OF_VEC_STMTS(S) (S)->vec_stmts_size
145 #define SLP_TREE_LOAD_PERMUTATION(S) (S)->load_permutation
146 #define SLP_TREE_TWO_OPERATORS(S) (S)->two_operators
148 /* This structure is used in creation of an SLP tree. Each instance
149 corresponds to the same operand in a group of scalar stmts in an SLP
150 node. */
151 typedef struct _slp_oprnd_info
153 /* Def-stmts for the operands. */
154 vec<gimple> def_stmts;
155 /* Information about the first statement, its vector def-type, type, the
156 operand itself in case it's constant, and an indication if it's a pattern
157 stmt. */
158 enum vect_def_type first_dt;
159 tree first_op_type;
160 bool first_pattern;
161 bool second_pattern;
162 } *slp_oprnd_info;
166 /* This struct is used to store the information of a data reference,
167 including the data ref itself, the access offset (calculated by summing its
168 offset and init) and the segment length for aliasing checks.
169 This is used to merge alias checks. */
171 struct dr_with_seg_len
173 dr_with_seg_len (data_reference_p d, tree len)
174 : dr (d),
175 offset (size_binop (PLUS_EXPR, DR_OFFSET (d), DR_INIT (d))),
176 seg_len (len) {}
178 data_reference_p dr;
179 tree offset;
180 tree seg_len;
183 /* This struct contains two dr_with_seg_len objects with aliasing data
184 refs. Two comparisons are generated from them. */
186 struct dr_with_seg_len_pair_t
188 dr_with_seg_len_pair_t (const dr_with_seg_len& d1,
189 const dr_with_seg_len& d2)
190 : first (d1), second (d2) {}
192 dr_with_seg_len first;
193 dr_with_seg_len second;
197 typedef struct _vect_peel_info
199 int npeel;
200 struct data_reference *dr;
201 unsigned int count;
202 } *vect_peel_info;
204 typedef struct _vect_peel_extended_info
206 struct _vect_peel_info peel_info;
207 unsigned int inside_cost;
208 unsigned int outside_cost;
209 stmt_vector_for_cost body_cost_vec;
210 } *vect_peel_extended_info;
213 /* Peeling hashtable helpers. */
215 struct peel_info_hasher : typed_free_remove <_vect_peel_info>
217 typedef _vect_peel_info *value_type;
218 typedef _vect_peel_info *compare_type;
219 static inline hashval_t hash (const _vect_peel_info *);
220 static inline bool equal (const _vect_peel_info *, const _vect_peel_info *);
223 inline hashval_t
224 peel_info_hasher::hash (const _vect_peel_info *peel_info)
226 return (hashval_t) peel_info->npeel;
229 inline bool
230 peel_info_hasher::equal (const _vect_peel_info *a, const _vect_peel_info *b)
232 return (a->npeel == b->npeel);
236 /*-----------------------------------------------------------------*/
237 /* Info on vectorized loops. */
238 /*-----------------------------------------------------------------*/
239 typedef struct _loop_vec_info {
241 /* The loop to which this info struct refers to. */
242 struct loop *loop;
244 /* The loop basic blocks. */
245 basic_block *bbs;
247 /* Number of latch executions. */
248 tree num_itersm1;
249 /* Number of iterations. */
250 tree num_iters;
251 /* Number of iterations of the original loop. */
252 tree num_iters_unchanged;
254 /* Minimum number of iterations below which vectorization is expected to
255 not be profitable (as estimated by the cost model).
256 -1 indicates that vectorization will not be profitable.
257 FORNOW: This field is an int. Will be a tree in the future, to represent
258 values unknown at compile time. */
259 int min_profitable_iters;
261 /* Threshold of number of iterations below which vectorzation will not be
262 performed. It is calculated from MIN_PROFITABLE_ITERS and
263 PARAM_MIN_VECT_LOOP_BOUND. */
264 unsigned int th;
266 /* Is the loop vectorizable? */
267 bool vectorizable;
269 /* Unrolling factor */
270 int vectorization_factor;
272 /* Unknown DRs according to which loop was peeled. */
273 struct data_reference *unaligned_dr;
275 /* peeling_for_alignment indicates whether peeling for alignment will take
276 place, and what the peeling factor should be:
277 peeling_for_alignment = X means:
278 If X=0: Peeling for alignment will not be applied.
279 If X>0: Peel first X iterations.
280 If X=-1: Generate a runtime test to calculate the number of iterations
281 to be peeled, using the dataref recorded in the field
282 unaligned_dr. */
283 int peeling_for_alignment;
285 /* The mask used to check the alignment of pointers or arrays. */
286 int ptr_mask;
288 /* The loop nest in which the data dependences are computed. */
289 vec<loop_p> loop_nest;
291 /* All data references in the loop. */
292 vec<data_reference_p> datarefs;
294 /* All data dependences in the loop. */
295 vec<ddr_p> ddrs;
297 /* Data Dependence Relations defining address ranges that are candidates
298 for a run-time aliasing check. */
299 vec<ddr_p> may_alias_ddrs;
301 /* Data Dependence Relations defining address ranges together with segment
302 lengths from which the run-time aliasing check is built. */
303 vec<dr_with_seg_len_pair_t> comp_alias_ddrs;
305 /* Statements in the loop that have data references that are candidates for a
306 runtime (loop versioning) misalignment check. */
307 vec<gimple> may_misalign_stmts;
309 /* All interleaving chains of stores in the loop, represented by the first
310 stmt in the chain. */
311 vec<gimple> grouped_stores;
313 /* All SLP instances in the loop. This is a subset of the set of GROUP_STORES
314 of the loop. */
315 vec<slp_instance> slp_instances;
317 /* The unrolling factor needed to SLP the loop. In case of that pure SLP is
318 applied to the loop, i.e., no unrolling is needed, this is 1. */
319 unsigned slp_unrolling_factor;
321 /* Reduction cycles detected in the loop. Used in loop-aware SLP. */
322 vec<gimple> reductions;
324 /* All reduction chains in the loop, represented by the first
325 stmt in the chain. */
326 vec<gimple> reduction_chains;
328 /* Hash table used to choose the best peeling option. */
329 hash_table<peel_info_hasher> *peeling_htab;
331 /* Cost vector for a single scalar iteration. */
332 vec<stmt_info_for_cost> scalar_cost_vec;
334 /* Cost of a single scalar iteration. */
335 int single_scalar_iteration_cost;
337 /* Cost data used by the target cost model. */
338 void *target_cost_data;
340 /* When we have grouped data accesses with gaps, we may introduce invalid
341 memory accesses. We peel the last iteration of the loop to prevent
342 this. */
343 bool peeling_for_gaps;
345 /* When the number of iterations is not a multiple of the vector size
346 we need to peel off iterations at the end to form an epilogue loop. */
347 bool peeling_for_niter;
349 /* Reductions are canonicalized so that the last operand is the reduction
350 operand. If this places a constant into RHS1, this decanonicalizes
351 GIMPLE for other phases, so we must track when this has occurred and
352 fix it up. */
353 bool operands_swapped;
355 /* True if there are no loop carried data dependencies in the loop.
356 If loop->safelen <= 1, then this is always true, either the loop
357 didn't have any loop carried data dependencies, or the loop is being
358 vectorized guarded with some runtime alias checks, or couldn't
359 be vectorized at all, but then this field shouldn't be used.
360 For loop->safelen >= 2, the user has asserted that there are no
361 backward dependencies, but there still could be loop carried forward
362 dependencies in such loops. This flag will be false if normal
363 vectorizer data dependency analysis would fail or require versioning
364 for alias, but because of loop->safelen >= 2 it has been vectorized
365 even without versioning for alias. E.g. in:
366 #pragma omp simd
367 for (int i = 0; i < m; i++)
368 a[i] = a[i + k] * c;
369 (or #pragma simd or #pragma ivdep) we can vectorize this and it will
370 DTRT even for k > 0 && k < m, but without safelen we would not
371 vectorize this, so this field would be false. */
372 bool no_data_dependencies;
374 /* If if-conversion versioned this loop before conversion, this is the
375 loop version without if-conversion. */
376 struct loop *scalar_loop;
378 } *loop_vec_info;
380 /* Access Functions. */
381 #define LOOP_VINFO_LOOP(L) (L)->loop
382 #define LOOP_VINFO_BBS(L) (L)->bbs
383 #define LOOP_VINFO_NITERSM1(L) (L)->num_itersm1
384 #define LOOP_VINFO_NITERS(L) (L)->num_iters
385 /* Since LOOP_VINFO_NITERS and LOOP_VINFO_NITERSM1 can change after
386 prologue peeling retain total unchanged scalar loop iterations for
387 cost model. */
388 #define LOOP_VINFO_NITERS_UNCHANGED(L) (L)->num_iters_unchanged
389 #define LOOP_VINFO_COST_MODEL_MIN_ITERS(L) (L)->min_profitable_iters
390 #define LOOP_VINFO_COST_MODEL_THRESHOLD(L) (L)->th
391 #define LOOP_VINFO_VECTORIZABLE_P(L) (L)->vectorizable
392 #define LOOP_VINFO_VECT_FACTOR(L) (L)->vectorization_factor
393 #define LOOP_VINFO_PTR_MASK(L) (L)->ptr_mask
394 #define LOOP_VINFO_LOOP_NEST(L) (L)->loop_nest
395 #define LOOP_VINFO_DATAREFS(L) (L)->datarefs
396 #define LOOP_VINFO_DDRS(L) (L)->ddrs
397 #define LOOP_VINFO_INT_NITERS(L) (TREE_INT_CST_LOW ((L)->num_iters))
398 #define LOOP_VINFO_PEELING_FOR_ALIGNMENT(L) (L)->peeling_for_alignment
399 #define LOOP_VINFO_UNALIGNED_DR(L) (L)->unaligned_dr
400 #define LOOP_VINFO_MAY_MISALIGN_STMTS(L) (L)->may_misalign_stmts
401 #define LOOP_VINFO_MAY_ALIAS_DDRS(L) (L)->may_alias_ddrs
402 #define LOOP_VINFO_COMP_ALIAS_DDRS(L) (L)->comp_alias_ddrs
403 #define LOOP_VINFO_GROUPED_STORES(L) (L)->grouped_stores
404 #define LOOP_VINFO_SLP_INSTANCES(L) (L)->slp_instances
405 #define LOOP_VINFO_SLP_UNROLLING_FACTOR(L) (L)->slp_unrolling_factor
406 #define LOOP_VINFO_REDUCTIONS(L) (L)->reductions
407 #define LOOP_VINFO_REDUCTION_CHAINS(L) (L)->reduction_chains
408 #define LOOP_VINFO_PEELING_HTAB(L) (L)->peeling_htab
409 #define LOOP_VINFO_TARGET_COST_DATA(L) (L)->target_cost_data
410 #define LOOP_VINFO_PEELING_FOR_GAPS(L) (L)->peeling_for_gaps
411 #define LOOP_VINFO_OPERANDS_SWAPPED(L) (L)->operands_swapped
412 #define LOOP_VINFO_PEELING_FOR_NITER(L) (L)->peeling_for_niter
413 #define LOOP_VINFO_NO_DATA_DEPENDENCIES(L) (L)->no_data_dependencies
414 #define LOOP_VINFO_SCALAR_LOOP(L) (L)->scalar_loop
415 #define LOOP_VINFO_SCALAR_ITERATION_COST(L) (L)->scalar_cost_vec
416 #define LOOP_VINFO_SINGLE_SCALAR_ITERATION_COST(L) (L)->single_scalar_iteration_cost
418 #define LOOP_REQUIRES_VERSIONING_FOR_ALIGNMENT(L) \
419 ((L)->may_misalign_stmts.length () > 0)
420 #define LOOP_REQUIRES_VERSIONING_FOR_ALIAS(L) \
421 ((L)->may_alias_ddrs.length () > 0)
423 #define LOOP_VINFO_NITERS_KNOWN_P(L) \
424 (tree_fits_shwi_p ((L)->num_iters) && tree_to_shwi ((L)->num_iters) > 0)
426 static inline loop_vec_info
427 loop_vec_info_for_loop (struct loop *loop)
429 return (loop_vec_info) loop->aux;
432 static inline bool
433 nested_in_vect_loop_p (struct loop *loop, gimple stmt)
435 return (loop->inner
436 && (loop->inner == (gimple_bb (stmt))->loop_father));
439 typedef struct _bb_vec_info {
441 basic_block bb;
442 /* All interleaving chains of stores in the basic block, represented by the
443 first stmt in the chain. */
444 vec<gimple> grouped_stores;
446 /* All SLP instances in the basic block. This is a subset of the set of
447 GROUP_STORES of the basic block. */
448 vec<slp_instance> slp_instances;
450 /* All data references in the basic block. */
451 vec<data_reference_p> datarefs;
453 /* All data dependences in the basic block. */
454 vec<ddr_p> ddrs;
456 /* Cost data used by the target cost model. */
457 void *target_cost_data;
459 } *bb_vec_info;
461 #define BB_VINFO_BB(B) (B)->bb
462 #define BB_VINFO_GROUPED_STORES(B) (B)->grouped_stores
463 #define BB_VINFO_SLP_INSTANCES(B) (B)->slp_instances
464 #define BB_VINFO_DATAREFS(B) (B)->datarefs
465 #define BB_VINFO_DDRS(B) (B)->ddrs
466 #define BB_VINFO_TARGET_COST_DATA(B) (B)->target_cost_data
468 static inline bb_vec_info
469 vec_info_for_bb (basic_block bb)
471 return (bb_vec_info) bb->aux;
474 /*-----------------------------------------------------------------*/
475 /* Info on vectorized defs. */
476 /*-----------------------------------------------------------------*/
477 enum stmt_vec_info_type {
478 undef_vec_info_type = 0,
479 load_vec_info_type,
480 store_vec_info_type,
481 shift_vec_info_type,
482 op_vec_info_type,
483 call_vec_info_type,
484 call_simd_clone_vec_info_type,
485 assignment_vec_info_type,
486 condition_vec_info_type,
487 reduc_vec_info_type,
488 induc_vec_info_type,
489 type_promotion_vec_info_type,
490 type_demotion_vec_info_type,
491 type_conversion_vec_info_type,
492 loop_exit_ctrl_vec_info_type
495 /* Indicates whether/how a variable is used in the scope of loop/basic
496 block. */
497 enum vect_relevant {
498 vect_unused_in_scope = 0,
499 /* The def is in the inner loop, and the use is in the outer loop, and the
500 use is a reduction stmt. */
501 vect_used_in_outer_by_reduction,
502 /* The def is in the inner loop, and the use is in the outer loop (and is
503 not part of reduction). */
504 vect_used_in_outer,
506 /* defs that feed computations that end up (only) in a reduction. These
507 defs may be used by non-reduction stmts, but eventually, any
508 computations/values that are affected by these defs are used to compute
509 a reduction (i.e. don't get stored to memory, for example). We use this
510 to identify computations that we can change the order in which they are
511 computed. */
512 vect_used_by_reduction,
514 vect_used_in_scope
517 /* The type of vectorization that can be applied to the stmt: regular loop-based
518 vectorization; pure SLP - the stmt is a part of SLP instances and does not
519 have uses outside SLP instances; or hybrid SLP and loop-based - the stmt is
520 a part of SLP instance and also must be loop-based vectorized, since it has
521 uses outside SLP sequences.
523 In the loop context the meanings of pure and hybrid SLP are slightly
524 different. By saying that pure SLP is applied to the loop, we mean that we
525 exploit only intra-iteration parallelism in the loop; i.e., the loop can be
526 vectorized without doing any conceptual unrolling, cause we don't pack
527 together stmts from different iterations, only within a single iteration.
528 Loop hybrid SLP means that we exploit both intra-iteration and
529 inter-iteration parallelism (e.g., number of elements in the vector is 4
530 and the slp-group-size is 2, in which case we don't have enough parallelism
531 within an iteration, so we obtain the rest of the parallelism from subsequent
532 iterations by unrolling the loop by 2). */
533 enum slp_vect_type {
534 loop_vect = 0,
535 pure_slp,
536 hybrid
540 typedef struct data_reference *dr_p;
542 typedef struct _stmt_vec_info {
544 enum stmt_vec_info_type type;
546 /* Indicates whether this stmts is part of a computation whose result is
547 used outside the loop. */
548 bool live;
550 /* Stmt is part of some pattern (computation idiom) */
551 bool in_pattern_p;
553 /* The stmt to which this info struct refers to. */
554 gimple stmt;
556 /* The loop_vec_info with respect to which STMT is vectorized. */
557 loop_vec_info loop_vinfo;
559 /* The vector type to be used for the LHS of this statement. */
560 tree vectype;
562 /* The vectorized version of the stmt. */
563 gimple vectorized_stmt;
566 /** The following is relevant only for stmts that contain a non-scalar
567 data-ref (array/pointer/struct access). A GIMPLE stmt is expected to have
568 at most one such data-ref. **/
570 /* Information about the data-ref (access function, etc),
571 relative to the inner-most containing loop. */
572 struct data_reference *data_ref_info;
574 /* Information about the data-ref relative to this loop
575 nest (the loop that is being considered for vectorization). */
576 tree dr_base_address;
577 tree dr_init;
578 tree dr_offset;
579 tree dr_step;
580 tree dr_aligned_to;
582 /* For loop PHI nodes, the evolution part of it. This makes sure
583 this information is still available in vect_update_ivs_after_vectorizer
584 where we may not be able to re-analyze the PHI nodes evolution as
585 peeling for the prologue loop can make it unanalyzable. The evolution
586 part is still correct though. */
587 tree loop_phi_evolution_part;
589 /* Used for various bookkeeping purposes, generally holding a pointer to
590 some other stmt S that is in some way "related" to this stmt.
591 Current use of this field is:
592 If this stmt is part of a pattern (i.e. the field 'in_pattern_p' is
593 true): S is the "pattern stmt" that represents (and replaces) the
594 sequence of stmts that constitutes the pattern. Similarly, the
595 related_stmt of the "pattern stmt" points back to this stmt (which is
596 the last stmt in the original sequence of stmts that constitutes the
597 pattern). */
598 gimple related_stmt;
600 /* Used to keep a sequence of def stmts of a pattern stmt if such exists. */
601 gimple_seq pattern_def_seq;
603 /* List of datarefs that are known to have the same alignment as the dataref
604 of this stmt. */
605 vec<dr_p> same_align_refs;
607 /* Selected SIMD clone's function info. First vector element
608 is SIMD clone's function decl, followed by a pair of trees (base + step)
609 for linear arguments (pair of NULLs for other arguments). */
610 vec<tree> simd_clone_info;
612 /* Classify the def of this stmt. */
613 enum vect_def_type def_type;
615 /* Whether the stmt is SLPed, loop-based vectorized, or both. */
616 enum slp_vect_type slp_type;
618 /* Interleaving and reduction chains info. */
619 /* First element in the group. */
620 gimple first_element;
621 /* Pointer to the next element in the group. */
622 gimple next_element;
623 /* For data-refs, in case that two or more stmts share data-ref, this is the
624 pointer to the previously detected stmt with the same dr. */
625 gimple same_dr_stmt;
626 /* The size of the group. */
627 unsigned int size;
628 /* For stores, number of stores from this group seen. We vectorize the last
629 one. */
630 unsigned int store_count;
631 /* For loads only, the gap from the previous load. For consecutive loads, GAP
632 is 1. */
633 unsigned int gap;
635 /* The minimum negative dependence distance this stmt participates in
636 or zero if none. */
637 unsigned int min_neg_dist;
639 /* Not all stmts in the loop need to be vectorized. e.g, the increment
640 of the loop induction variable and computation of array indexes. relevant
641 indicates whether the stmt needs to be vectorized. */
642 enum vect_relevant relevant;
644 /* The bb_vec_info with respect to which STMT is vectorized. */
645 bb_vec_info bb_vinfo;
647 /* Is this statement vectorizable or should it be skipped in (partial)
648 vectorization. */
649 bool vectorizable;
651 /* For loads only, true if this is a gather load. */
652 bool gather_p;
654 /* True if this is an access with loop-invariant stride. */
655 bool strided_p;
657 /* For both loads and stores. */
658 bool simd_lane_access_p;
659 } *stmt_vec_info;
661 /* Access Functions. */
662 #define STMT_VINFO_TYPE(S) (S)->type
663 #define STMT_VINFO_STMT(S) (S)->stmt
664 #define STMT_VINFO_LOOP_VINFO(S) (S)->loop_vinfo
665 #define STMT_VINFO_BB_VINFO(S) (S)->bb_vinfo
666 #define STMT_VINFO_RELEVANT(S) (S)->relevant
667 #define STMT_VINFO_LIVE_P(S) (S)->live
668 #define STMT_VINFO_VECTYPE(S) (S)->vectype
669 #define STMT_VINFO_VEC_STMT(S) (S)->vectorized_stmt
670 #define STMT_VINFO_VECTORIZABLE(S) (S)->vectorizable
671 #define STMT_VINFO_DATA_REF(S) (S)->data_ref_info
672 #define STMT_VINFO_GATHER_P(S) (S)->gather_p
673 #define STMT_VINFO_STRIDED_P(S) (S)->strided_p
674 #define STMT_VINFO_SIMD_LANE_ACCESS_P(S) (S)->simd_lane_access_p
676 #define STMT_VINFO_DR_BASE_ADDRESS(S) (S)->dr_base_address
677 #define STMT_VINFO_DR_INIT(S) (S)->dr_init
678 #define STMT_VINFO_DR_OFFSET(S) (S)->dr_offset
679 #define STMT_VINFO_DR_STEP(S) (S)->dr_step
680 #define STMT_VINFO_DR_ALIGNED_TO(S) (S)->dr_aligned_to
682 #define STMT_VINFO_IN_PATTERN_P(S) (S)->in_pattern_p
683 #define STMT_VINFO_RELATED_STMT(S) (S)->related_stmt
684 #define STMT_VINFO_PATTERN_DEF_SEQ(S) (S)->pattern_def_seq
685 #define STMT_VINFO_SAME_ALIGN_REFS(S) (S)->same_align_refs
686 #define STMT_VINFO_SIMD_CLONE_INFO(S) (S)->simd_clone_info
687 #define STMT_VINFO_DEF_TYPE(S) (S)->def_type
688 #define STMT_VINFO_GROUP_FIRST_ELEMENT(S) (S)->first_element
689 #define STMT_VINFO_GROUP_NEXT_ELEMENT(S) (S)->next_element
690 #define STMT_VINFO_GROUP_SIZE(S) (S)->size
691 #define STMT_VINFO_GROUP_STORE_COUNT(S) (S)->store_count
692 #define STMT_VINFO_GROUP_GAP(S) (S)->gap
693 #define STMT_VINFO_GROUP_SAME_DR_STMT(S) (S)->same_dr_stmt
694 #define STMT_VINFO_GROUPED_ACCESS(S) ((S)->first_element != NULL && (S)->data_ref_info)
695 #define STMT_VINFO_LOOP_PHI_EVOLUTION_PART(S) (S)->loop_phi_evolution_part
696 #define STMT_VINFO_MIN_NEG_DIST(S) (S)->min_neg_dist
698 #define GROUP_FIRST_ELEMENT(S) (S)->first_element
699 #define GROUP_NEXT_ELEMENT(S) (S)->next_element
700 #define GROUP_SIZE(S) (S)->size
701 #define GROUP_STORE_COUNT(S) (S)->store_count
702 #define GROUP_GAP(S) (S)->gap
703 #define GROUP_SAME_DR_STMT(S) (S)->same_dr_stmt
705 #define STMT_VINFO_RELEVANT_P(S) ((S)->relevant != vect_unused_in_scope)
707 #define HYBRID_SLP_STMT(S) ((S)->slp_type == hybrid)
708 #define PURE_SLP_STMT(S) ((S)->slp_type == pure_slp)
709 #define STMT_SLP_TYPE(S) (S)->slp_type
711 struct dataref_aux {
712 tree base_decl;
713 bool base_misaligned;
714 int misalignment;
717 #define VECT_MAX_COST 1000
719 /* The maximum number of intermediate steps required in multi-step type
720 conversion. */
721 #define MAX_INTERM_CVT_STEPS 3
723 /* The maximum vectorization factor supported by any target (V64QI). */
724 #define MAX_VECTORIZATION_FACTOR 64
726 /* Avoid GTY(()) on stmt_vec_info. */
727 typedef void *vec_void_p;
729 extern vec<vec_void_p> stmt_vec_info_vec;
731 void init_stmt_vec_info_vec (void);
732 void free_stmt_vec_info_vec (void);
734 /* Return a stmt_vec_info corresponding to STMT. */
736 static inline stmt_vec_info
737 vinfo_for_stmt (gimple stmt)
739 unsigned int uid = gimple_uid (stmt);
740 if (uid == 0)
741 return NULL;
743 return (stmt_vec_info) stmt_vec_info_vec[uid - 1];
746 /* Set vectorizer information INFO for STMT. */
748 static inline void
749 set_vinfo_for_stmt (gimple stmt, stmt_vec_info info)
751 unsigned int uid = gimple_uid (stmt);
752 if (uid == 0)
754 gcc_checking_assert (info);
755 uid = stmt_vec_info_vec.length () + 1;
756 gimple_set_uid (stmt, uid);
757 stmt_vec_info_vec.safe_push ((vec_void_p) info);
759 else
760 stmt_vec_info_vec[uid - 1] = (vec_void_p) info;
763 /* Return the earlier statement between STMT1 and STMT2. */
765 static inline gimple
766 get_earlier_stmt (gimple stmt1, gimple stmt2)
768 unsigned int uid1, uid2;
770 if (stmt1 == NULL)
771 return stmt2;
773 if (stmt2 == NULL)
774 return stmt1;
776 uid1 = gimple_uid (stmt1);
777 uid2 = gimple_uid (stmt2);
779 if (uid1 == 0 || uid2 == 0)
780 return NULL;
782 gcc_checking_assert (uid1 <= stmt_vec_info_vec.length ()
783 && uid2 <= stmt_vec_info_vec.length ());
785 if (uid1 < uid2)
786 return stmt1;
787 else
788 return stmt2;
791 /* Return the later statement between STMT1 and STMT2. */
793 static inline gimple
794 get_later_stmt (gimple stmt1, gimple stmt2)
796 unsigned int uid1, uid2;
798 if (stmt1 == NULL)
799 return stmt2;
801 if (stmt2 == NULL)
802 return stmt1;
804 uid1 = gimple_uid (stmt1);
805 uid2 = gimple_uid (stmt2);
807 if (uid1 == 0 || uid2 == 0)
808 return NULL;
810 gcc_assert (uid1 <= stmt_vec_info_vec.length ());
811 gcc_assert (uid2 <= stmt_vec_info_vec.length ());
813 if (uid1 > uid2)
814 return stmt1;
815 else
816 return stmt2;
819 /* Return TRUE if a statement represented by STMT_INFO is a part of a
820 pattern. */
822 static inline bool
823 is_pattern_stmt_p (stmt_vec_info stmt_info)
825 gimple related_stmt;
826 stmt_vec_info related_stmt_info;
828 related_stmt = STMT_VINFO_RELATED_STMT (stmt_info);
829 if (related_stmt
830 && (related_stmt_info = vinfo_for_stmt (related_stmt))
831 && STMT_VINFO_IN_PATTERN_P (related_stmt_info))
832 return true;
834 return false;
837 /* Return true if BB is a loop header. */
839 static inline bool
840 is_loop_header_bb_p (basic_block bb)
842 if (bb == (bb->loop_father)->header)
843 return true;
844 gcc_checking_assert (EDGE_COUNT (bb->preds) == 1);
845 return false;
848 /* Return pow2 (X). */
850 static inline int
851 vect_pow2 (int x)
853 int i, res = 1;
855 for (i = 0; i < x; i++)
856 res *= 2;
858 return res;
861 /* Alias targetm.vectorize.builtin_vectorization_cost. */
863 static inline int
864 builtin_vectorization_cost (enum vect_cost_for_stmt type_of_cost,
865 tree vectype, int misalign)
867 return targetm.vectorize.builtin_vectorization_cost (type_of_cost,
868 vectype, misalign);
871 /* Get cost by calling cost target builtin. */
873 static inline
874 int vect_get_stmt_cost (enum vect_cost_for_stmt type_of_cost)
876 return builtin_vectorization_cost (type_of_cost, NULL, 0);
879 /* Alias targetm.vectorize.init_cost. */
881 static inline void *
882 init_cost (struct loop *loop_info)
884 return targetm.vectorize.init_cost (loop_info);
887 /* Alias targetm.vectorize.add_stmt_cost. */
889 static inline unsigned
890 add_stmt_cost (void *data, int count, enum vect_cost_for_stmt kind,
891 stmt_vec_info stmt_info, int misalign,
892 enum vect_cost_model_location where)
894 return targetm.vectorize.add_stmt_cost (data, count, kind,
895 stmt_info, misalign, where);
898 /* Alias targetm.vectorize.finish_cost. */
900 static inline void
901 finish_cost (void *data, unsigned *prologue_cost,
902 unsigned *body_cost, unsigned *epilogue_cost)
904 targetm.vectorize.finish_cost (data, prologue_cost, body_cost, epilogue_cost);
907 /* Alias targetm.vectorize.destroy_cost_data. */
909 static inline void
910 destroy_cost_data (void *data)
912 targetm.vectorize.destroy_cost_data (data);
916 /*-----------------------------------------------------------------*/
917 /* Info on data references alignment. */
918 /*-----------------------------------------------------------------*/
919 inline void
920 set_dr_misalignment (struct data_reference *dr, int val)
922 dataref_aux *data_aux = (dataref_aux *) dr->aux;
924 if (!data_aux)
926 data_aux = XCNEW (dataref_aux);
927 dr->aux = data_aux;
930 data_aux->misalignment = val;
933 inline int
934 dr_misalignment (struct data_reference *dr)
936 gcc_assert (dr->aux);
937 return ((dataref_aux *) dr->aux)->misalignment;
940 /* Reflects actual alignment of first access in the vectorized loop,
941 taking into account peeling/versioning if applied. */
942 #define DR_MISALIGNMENT(DR) dr_misalignment (DR)
943 #define SET_DR_MISALIGNMENT(DR, VAL) set_dr_misalignment (DR, VAL)
945 /* Return TRUE if the data access is aligned, and FALSE otherwise. */
947 static inline bool
948 aligned_access_p (struct data_reference *data_ref_info)
950 return (DR_MISALIGNMENT (data_ref_info) == 0);
953 /* Return TRUE if the alignment of the data access is known, and FALSE
954 otherwise. */
956 static inline bool
957 known_alignment_for_access_p (struct data_reference *data_ref_info)
959 return (DR_MISALIGNMENT (data_ref_info) != -1);
963 /* Return true if the vect cost model is unlimited. */
964 static inline bool
965 unlimited_cost_model (loop_p loop)
967 if (loop != NULL && loop->force_vectorize
968 && flag_simd_cost_model != VECT_COST_MODEL_DEFAULT)
969 return flag_simd_cost_model == VECT_COST_MODEL_UNLIMITED;
970 return (flag_vect_cost_model == VECT_COST_MODEL_UNLIMITED);
973 /* Source location */
974 extern source_location vect_location;
976 /*-----------------------------------------------------------------*/
977 /* Function prototypes. */
978 /*-----------------------------------------------------------------*/
980 /* Simple loop peeling and versioning utilities for vectorizer's purposes -
981 in tree-vect-loop-manip.c. */
982 extern void slpeel_make_loop_iterate_ntimes (struct loop *, tree);
983 extern bool slpeel_can_duplicate_loop_p (const struct loop *, const_edge);
984 struct loop *slpeel_tree_duplicate_loop_to_edge_cfg (struct loop *,
985 struct loop *, edge);
986 extern void vect_loop_versioning (loop_vec_info, unsigned int, bool);
987 extern void vect_do_peeling_for_loop_bound (loop_vec_info, tree, tree,
988 unsigned int, bool);
989 extern void vect_do_peeling_for_alignment (loop_vec_info, tree,
990 unsigned int, bool);
991 extern source_location find_loop_location (struct loop *);
992 extern bool vect_can_advance_ivs_p (loop_vec_info);
994 /* In tree-vect-stmts.c. */
995 extern unsigned int current_vector_size;
996 extern tree get_vectype_for_scalar_type (tree);
997 extern tree get_same_sized_vectype (tree, tree);
998 extern bool vect_is_simple_use (tree, gimple, loop_vec_info,
999 bb_vec_info, gimple *,
1000 tree *, enum vect_def_type *);
1001 extern bool vect_is_simple_use_1 (tree, gimple, loop_vec_info,
1002 bb_vec_info, gimple *,
1003 tree *, enum vect_def_type *, tree *);
1004 extern bool supportable_widening_operation (enum tree_code, gimple, tree, tree,
1005 enum tree_code *, enum tree_code *,
1006 int *, vec<tree> *);
1007 extern bool supportable_narrowing_operation (enum tree_code, tree, tree,
1008 enum tree_code *,
1009 int *, vec<tree> *);
1010 extern stmt_vec_info new_stmt_vec_info (gimple stmt, loop_vec_info,
1011 bb_vec_info);
1012 extern void free_stmt_vec_info (gimple stmt);
1013 extern tree vectorizable_function (gcall *, tree, tree);
1014 extern void vect_model_simple_cost (stmt_vec_info, int, enum vect_def_type *,
1015 stmt_vector_for_cost *,
1016 stmt_vector_for_cost *);
1017 extern void vect_model_store_cost (stmt_vec_info, int, bool,
1018 enum vect_def_type, slp_tree,
1019 stmt_vector_for_cost *,
1020 stmt_vector_for_cost *);
1021 extern void vect_model_load_cost (stmt_vec_info, int, bool, slp_tree,
1022 stmt_vector_for_cost *,
1023 stmt_vector_for_cost *);
1024 extern unsigned record_stmt_cost (stmt_vector_for_cost *, int,
1025 enum vect_cost_for_stmt, stmt_vec_info,
1026 int, enum vect_cost_model_location);
1027 extern void vect_finish_stmt_generation (gimple, gimple,
1028 gimple_stmt_iterator *);
1029 extern bool vect_mark_stmts_to_be_vectorized (loop_vec_info);
1030 extern tree vect_get_vec_def_for_operand (tree, gimple, tree *);
1031 extern tree vect_init_vector (gimple, tree, tree,
1032 gimple_stmt_iterator *);
1033 extern tree vect_get_vec_def_for_stmt_copy (enum vect_def_type, tree);
1034 extern bool vect_transform_stmt (gimple, gimple_stmt_iterator *,
1035 bool *, slp_tree, slp_instance);
1036 extern void vect_remove_stores (gimple);
1037 extern bool vect_analyze_stmt (gimple, bool *, slp_tree);
1038 extern bool vectorizable_condition (gimple, gimple_stmt_iterator *, gimple *,
1039 tree, int, slp_tree);
1040 extern void vect_get_load_cost (struct data_reference *, int, bool,
1041 unsigned int *, unsigned int *,
1042 stmt_vector_for_cost *,
1043 stmt_vector_for_cost *, bool);
1044 extern void vect_get_store_cost (struct data_reference *, int,
1045 unsigned int *, stmt_vector_for_cost *);
1046 extern bool vect_supportable_shift (enum tree_code, tree);
1047 extern void vect_get_vec_defs (tree, tree, gimple, vec<tree> *,
1048 vec<tree> *, slp_tree, int);
1049 extern tree vect_gen_perm_mask_any (tree, const unsigned char *);
1050 extern tree vect_gen_perm_mask_checked (tree, const unsigned char *);
1052 /* In tree-vect-data-refs.c. */
1053 extern bool vect_can_force_dr_alignment_p (const_tree, unsigned int);
1054 extern enum dr_alignment_support vect_supportable_dr_alignment
1055 (struct data_reference *, bool);
1056 extern tree vect_get_smallest_scalar_type (gimple, HOST_WIDE_INT *,
1057 HOST_WIDE_INT *);
1058 extern bool vect_analyze_data_ref_dependences (loop_vec_info, int *);
1059 extern bool vect_slp_analyze_data_ref_dependences (bb_vec_info);
1060 extern bool vect_enhance_data_refs_alignment (loop_vec_info);
1061 extern bool vect_analyze_data_refs_alignment (loop_vec_info, bb_vec_info);
1062 extern bool vect_verify_datarefs_alignment (loop_vec_info, bb_vec_info);
1063 extern bool vect_analyze_data_ref_accesses (loop_vec_info, bb_vec_info);
1064 extern bool vect_prune_runtime_alias_test_list (loop_vec_info);
1065 extern tree vect_check_gather (gimple, loop_vec_info, tree *, tree *,
1066 int *);
1067 extern bool vect_analyze_data_refs (loop_vec_info, bb_vec_info, int *,
1068 unsigned *);
1069 extern tree vect_create_data_ref_ptr (gimple, tree, struct loop *, tree,
1070 tree *, gimple_stmt_iterator *,
1071 gimple *, bool, bool *,
1072 tree = NULL_TREE);
1073 extern tree bump_vector_ptr (tree, gimple, gimple_stmt_iterator *, gimple, tree);
1074 extern tree vect_create_destination_var (tree, tree);
1075 extern bool vect_grouped_store_supported (tree, unsigned HOST_WIDE_INT);
1076 extern bool vect_store_lanes_supported (tree, unsigned HOST_WIDE_INT);
1077 extern bool vect_grouped_load_supported (tree, unsigned HOST_WIDE_INT);
1078 extern bool vect_load_lanes_supported (tree, unsigned HOST_WIDE_INT);
1079 extern void vect_permute_store_chain (vec<tree> ,unsigned int, gimple,
1080 gimple_stmt_iterator *, vec<tree> *);
1081 extern tree vect_setup_realignment (gimple, gimple_stmt_iterator *, tree *,
1082 enum dr_alignment_support, tree,
1083 struct loop **);
1084 extern void vect_transform_grouped_load (gimple, vec<tree> , int,
1085 gimple_stmt_iterator *);
1086 extern void vect_record_grouped_load_vectors (gimple, vec<tree> );
1087 extern tree vect_get_new_vect_var (tree, enum vect_var_kind, const char *);
1088 extern tree vect_create_addr_base_for_vector_ref (gimple, gimple_seq *,
1089 tree, struct loop *,
1090 tree = NULL_TREE);
1092 /* In tree-vect-loop.c. */
1093 /* FORNOW: Used in tree-parloops.c. */
1094 extern void destroy_loop_vec_info (loop_vec_info, bool);
1095 extern gimple vect_force_simple_reduction (loop_vec_info, gimple, bool, bool *);
1096 /* Drive for loop analysis stage. */
1097 extern loop_vec_info vect_analyze_loop (struct loop *);
1098 /* Drive for loop transformation stage. */
1099 extern void vect_transform_loop (loop_vec_info);
1100 extern loop_vec_info vect_analyze_loop_form (struct loop *);
1101 extern bool vectorizable_live_operation (gimple, gimple_stmt_iterator *,
1102 gimple *);
1103 extern bool vectorizable_reduction (gimple, gimple_stmt_iterator *, gimple *,
1104 slp_tree);
1105 extern bool vectorizable_induction (gimple, gimple_stmt_iterator *, gimple *);
1106 extern tree get_initial_def_for_reduction (gimple, tree, tree *);
1107 extern int vect_min_worthwhile_factor (enum tree_code);
1108 extern int vect_get_known_peeling_cost (loop_vec_info, int, int *,
1109 stmt_vector_for_cost *,
1110 stmt_vector_for_cost *,
1111 stmt_vector_for_cost *);
1113 /* In tree-vect-slp.c. */
1114 extern void vect_free_slp_instance (slp_instance);
1115 extern bool vect_transform_slp_perm_load (slp_tree, vec<tree> ,
1116 gimple_stmt_iterator *, int,
1117 slp_instance, bool);
1118 extern bool vect_slp_analyze_operations (vec<slp_instance> slp_instances,
1119 void *);
1120 extern bool vect_schedule_slp (loop_vec_info, bb_vec_info);
1121 extern bool vect_analyze_slp (loop_vec_info, bb_vec_info, unsigned);
1122 extern bool vect_make_slp_decision (loop_vec_info);
1123 extern void vect_detect_hybrid_slp (loop_vec_info);
1124 extern void vect_get_slp_defs (vec<tree> , slp_tree,
1125 vec<vec<tree> > *, int);
1127 extern source_location find_bb_location (basic_block);
1128 extern bb_vec_info vect_slp_analyze_bb (basic_block);
1129 extern void vect_slp_transform_bb (basic_block);
1131 /* In tree-vect-patterns.c. */
1132 /* Pattern recognition functions.
1133 Additional pattern recognition functions can (and will) be added
1134 in the future. */
1135 typedef gimple (* vect_recog_func_ptr) (vec<gimple> *, tree *, tree *);
1136 #define NUM_PATTERNS 12
1137 void vect_pattern_recog (loop_vec_info, bb_vec_info);
1139 /* In tree-vectorizer.c. */
1140 unsigned vectorize_loops (void);
1141 void vect_destroy_datarefs (loop_vec_info, bb_vec_info);
1143 #endif /* GCC_TREE_VECTORIZER_H */