[PR67828] don't unswitch on default defs of non-parms
[official-gcc.git] / gcc / tree-vectorizer.h
blob39f92728e95e7b85dff97c7ce0d4d4d8119b0e30
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 struct stmt_info_for_cost {
70 int count;
71 enum vect_cost_for_stmt kind;
72 gimple *stmt;
73 int misalign;
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 : free_ptr_hash <_vect_peel_info>
217 static inline hashval_t hash (const _vect_peel_info *);
218 static inline bool equal (const _vect_peel_info *, const _vect_peel_info *);
221 inline hashval_t
222 peel_info_hasher::hash (const _vect_peel_info *peel_info)
224 return (hashval_t) peel_info->npeel;
227 inline bool
228 peel_info_hasher::equal (const _vect_peel_info *a, const _vect_peel_info *b)
230 return (a->npeel == b->npeel);
233 /* Vectorizer state common between loop and basic-block vectorization. */
234 struct vec_info {
235 enum { bb, loop } kind;
237 /* All SLP instances. */
238 vec<slp_instance> slp_instances;
240 /* All data references. */
241 vec<data_reference_p> datarefs;
243 /* All data dependences. */
244 vec<ddr_p> ddrs;
246 /* All interleaving chains of stores, represented by the first
247 stmt in the chain. */
248 vec<gimple *> grouped_stores;
250 /* Cost data used by the target cost model. */
251 void *target_cost_data;
254 struct _loop_vec_info;
255 struct _bb_vec_info;
257 template<>
258 template<>
259 inline bool
260 is_a_helper <_loop_vec_info *>::test (vec_info *i)
262 return i->kind == vec_info::loop;
265 template<>
266 template<>
267 inline bool
268 is_a_helper <_bb_vec_info *>::test (vec_info *i)
270 return i->kind == vec_info::bb;
274 /*-----------------------------------------------------------------*/
275 /* Info on vectorized loops. */
276 /*-----------------------------------------------------------------*/
277 typedef struct _loop_vec_info : public vec_info {
279 /* The loop to which this info struct refers to. */
280 struct loop *loop;
282 /* The loop basic blocks. */
283 basic_block *bbs;
285 /* Number of latch executions. */
286 tree num_itersm1;
287 /* Number of iterations. */
288 tree num_iters;
289 /* Number of iterations of the original loop. */
290 tree num_iters_unchanged;
292 /* Minimum number of iterations below which vectorization is expected to
293 not be profitable (as estimated by the cost model).
294 -1 indicates that vectorization will not be profitable.
295 FORNOW: This field is an int. Will be a tree in the future, to represent
296 values unknown at compile time. */
297 int min_profitable_iters;
299 /* Threshold of number of iterations below which vectorzation will not be
300 performed. It is calculated from MIN_PROFITABLE_ITERS and
301 PARAM_MIN_VECT_LOOP_BOUND. */
302 unsigned int th;
304 /* Is the loop vectorizable? */
305 bool vectorizable;
307 /* Unrolling factor */
308 int vectorization_factor;
310 /* Unknown DRs according to which loop was peeled. */
311 struct data_reference *unaligned_dr;
313 /* peeling_for_alignment indicates whether peeling for alignment will take
314 place, and what the peeling factor should be:
315 peeling_for_alignment = X means:
316 If X=0: Peeling for alignment will not be applied.
317 If X>0: Peel first X iterations.
318 If X=-1: Generate a runtime test to calculate the number of iterations
319 to be peeled, using the dataref recorded in the field
320 unaligned_dr. */
321 int peeling_for_alignment;
323 /* The mask used to check the alignment of pointers or arrays. */
324 int ptr_mask;
326 /* The loop nest in which the data dependences are computed. */
327 vec<loop_p> loop_nest;
329 /* Data Dependence Relations defining address ranges that are candidates
330 for a run-time aliasing check. */
331 vec<ddr_p> may_alias_ddrs;
333 /* Data Dependence Relations defining address ranges together with segment
334 lengths from which the run-time aliasing check is built. */
335 vec<dr_with_seg_len_pair_t> comp_alias_ddrs;
337 /* Statements in the loop that have data references that are candidates for a
338 runtime (loop versioning) misalignment check. */
339 vec<gimple *> may_misalign_stmts;
341 /* The unrolling factor needed to SLP the loop. In case of that pure SLP is
342 applied to the loop, i.e., no unrolling is needed, this is 1. */
343 unsigned slp_unrolling_factor;
345 /* Reduction cycles detected in the loop. Used in loop-aware SLP. */
346 vec<gimple *> reductions;
348 /* All reduction chains in the loop, represented by the first
349 stmt in the chain. */
350 vec<gimple *> reduction_chains;
352 /* Hash table used to choose the best peeling option. */
353 hash_table<peel_info_hasher> *peeling_htab;
355 /* Cost vector for a single scalar iteration. */
356 vec<stmt_info_for_cost> scalar_cost_vec;
358 /* Cost of a single scalar iteration. */
359 int single_scalar_iteration_cost;
361 /* When we have grouped data accesses with gaps, we may introduce invalid
362 memory accesses. We peel the last iteration of the loop to prevent
363 this. */
364 bool peeling_for_gaps;
366 /* When the number of iterations is not a multiple of the vector size
367 we need to peel off iterations at the end to form an epilogue loop. */
368 bool peeling_for_niter;
370 /* Reductions are canonicalized so that the last operand is the reduction
371 operand. If this places a constant into RHS1, this decanonicalizes
372 GIMPLE for other phases, so we must track when this has occurred and
373 fix it up. */
374 bool operands_swapped;
376 /* True if there are no loop carried data dependencies in the loop.
377 If loop->safelen <= 1, then this is always true, either the loop
378 didn't have any loop carried data dependencies, or the loop is being
379 vectorized guarded with some runtime alias checks, or couldn't
380 be vectorized at all, but then this field shouldn't be used.
381 For loop->safelen >= 2, the user has asserted that there are no
382 backward dependencies, but there still could be loop carried forward
383 dependencies in such loops. This flag will be false if normal
384 vectorizer data dependency analysis would fail or require versioning
385 for alias, but because of loop->safelen >= 2 it has been vectorized
386 even without versioning for alias. E.g. in:
387 #pragma omp simd
388 for (int i = 0; i < m; i++)
389 a[i] = a[i + k] * c;
390 (or #pragma simd or #pragma ivdep) we can vectorize this and it will
391 DTRT even for k > 0 && k < m, but without safelen we would not
392 vectorize this, so this field would be false. */
393 bool no_data_dependencies;
395 /* If if-conversion versioned this loop before conversion, this is the
396 loop version without if-conversion. */
397 struct loop *scalar_loop;
399 } *loop_vec_info;
401 /* Access Functions. */
402 #define LOOP_VINFO_LOOP(L) (L)->loop
403 #define LOOP_VINFO_BBS(L) (L)->bbs
404 #define LOOP_VINFO_NITERSM1(L) (L)->num_itersm1
405 #define LOOP_VINFO_NITERS(L) (L)->num_iters
406 /* Since LOOP_VINFO_NITERS and LOOP_VINFO_NITERSM1 can change after
407 prologue peeling retain total unchanged scalar loop iterations for
408 cost model. */
409 #define LOOP_VINFO_NITERS_UNCHANGED(L) (L)->num_iters_unchanged
410 #define LOOP_VINFO_COST_MODEL_MIN_ITERS(L) (L)->min_profitable_iters
411 #define LOOP_VINFO_COST_MODEL_THRESHOLD(L) (L)->th
412 #define LOOP_VINFO_VECTORIZABLE_P(L) (L)->vectorizable
413 #define LOOP_VINFO_VECT_FACTOR(L) (L)->vectorization_factor
414 #define LOOP_VINFO_PTR_MASK(L) (L)->ptr_mask
415 #define LOOP_VINFO_LOOP_NEST(L) (L)->loop_nest
416 #define LOOP_VINFO_DATAREFS(L) (L)->datarefs
417 #define LOOP_VINFO_DDRS(L) (L)->ddrs
418 #define LOOP_VINFO_INT_NITERS(L) (TREE_INT_CST_LOW ((L)->num_iters))
419 #define LOOP_VINFO_PEELING_FOR_ALIGNMENT(L) (L)->peeling_for_alignment
420 #define LOOP_VINFO_UNALIGNED_DR(L) (L)->unaligned_dr
421 #define LOOP_VINFO_MAY_MISALIGN_STMTS(L) (L)->may_misalign_stmts
422 #define LOOP_VINFO_MAY_ALIAS_DDRS(L) (L)->may_alias_ddrs
423 #define LOOP_VINFO_COMP_ALIAS_DDRS(L) (L)->comp_alias_ddrs
424 #define LOOP_VINFO_GROUPED_STORES(L) (L)->grouped_stores
425 #define LOOP_VINFO_SLP_INSTANCES(L) (L)->slp_instances
426 #define LOOP_VINFO_SLP_UNROLLING_FACTOR(L) (L)->slp_unrolling_factor
427 #define LOOP_VINFO_REDUCTIONS(L) (L)->reductions
428 #define LOOP_VINFO_REDUCTION_CHAINS(L) (L)->reduction_chains
429 #define LOOP_VINFO_PEELING_HTAB(L) (L)->peeling_htab
430 #define LOOP_VINFO_TARGET_COST_DATA(L) (L)->target_cost_data
431 #define LOOP_VINFO_PEELING_FOR_GAPS(L) (L)->peeling_for_gaps
432 #define LOOP_VINFO_OPERANDS_SWAPPED(L) (L)->operands_swapped
433 #define LOOP_VINFO_PEELING_FOR_NITER(L) (L)->peeling_for_niter
434 #define LOOP_VINFO_NO_DATA_DEPENDENCIES(L) (L)->no_data_dependencies
435 #define LOOP_VINFO_SCALAR_LOOP(L) (L)->scalar_loop
436 #define LOOP_VINFO_SCALAR_ITERATION_COST(L) (L)->scalar_cost_vec
437 #define LOOP_VINFO_SINGLE_SCALAR_ITERATION_COST(L) (L)->single_scalar_iteration_cost
439 #define LOOP_REQUIRES_VERSIONING_FOR_ALIGNMENT(L) \
440 ((L)->may_misalign_stmts.length () > 0)
441 #define LOOP_REQUIRES_VERSIONING_FOR_ALIAS(L) \
442 ((L)->may_alias_ddrs.length () > 0)
444 #define LOOP_VINFO_NITERS_KNOWN_P(L) \
445 (tree_fits_shwi_p ((L)->num_iters) && tree_to_shwi ((L)->num_iters) > 0)
447 static inline loop_vec_info
448 loop_vec_info_for_loop (struct loop *loop)
450 return (loop_vec_info) loop->aux;
453 static inline bool
454 nested_in_vect_loop_p (struct loop *loop, gimple *stmt)
456 return (loop->inner
457 && (loop->inner == (gimple_bb (stmt))->loop_father));
460 typedef struct _bb_vec_info : public vec_info
462 basic_block bb;
463 } *bb_vec_info;
465 #define BB_VINFO_BB(B) (B)->bb
466 #define BB_VINFO_GROUPED_STORES(B) (B)->grouped_stores
467 #define BB_VINFO_SLP_INSTANCES(B) (B)->slp_instances
468 #define BB_VINFO_DATAREFS(B) (B)->datarefs
469 #define BB_VINFO_DDRS(B) (B)->ddrs
470 #define BB_VINFO_TARGET_COST_DATA(B) (B)->target_cost_data
472 static inline bb_vec_info
473 vec_info_for_bb (basic_block bb)
475 return (bb_vec_info) bb->aux;
478 /*-----------------------------------------------------------------*/
479 /* Info on vectorized defs. */
480 /*-----------------------------------------------------------------*/
481 enum stmt_vec_info_type {
482 undef_vec_info_type = 0,
483 load_vec_info_type,
484 store_vec_info_type,
485 shift_vec_info_type,
486 op_vec_info_type,
487 call_vec_info_type,
488 call_simd_clone_vec_info_type,
489 assignment_vec_info_type,
490 condition_vec_info_type,
491 reduc_vec_info_type,
492 induc_vec_info_type,
493 type_promotion_vec_info_type,
494 type_demotion_vec_info_type,
495 type_conversion_vec_info_type,
496 loop_exit_ctrl_vec_info_type
499 /* Indicates whether/how a variable is used in the scope of loop/basic
500 block. */
501 enum vect_relevant {
502 vect_unused_in_scope = 0,
503 /* The def is in the inner loop, and the use is in the outer loop, and the
504 use is a reduction stmt. */
505 vect_used_in_outer_by_reduction,
506 /* The def is in the inner loop, and the use is in the outer loop (and is
507 not part of reduction). */
508 vect_used_in_outer,
510 /* defs that feed computations that end up (only) in a reduction. These
511 defs may be used by non-reduction stmts, but eventually, any
512 computations/values that are affected by these defs are used to compute
513 a reduction (i.e. don't get stored to memory, for example). We use this
514 to identify computations that we can change the order in which they are
515 computed. */
516 vect_used_by_reduction,
518 vect_used_in_scope
521 /* The type of vectorization that can be applied to the stmt: regular loop-based
522 vectorization; pure SLP - the stmt is a part of SLP instances and does not
523 have uses outside SLP instances; or hybrid SLP and loop-based - the stmt is
524 a part of SLP instance and also must be loop-based vectorized, since it has
525 uses outside SLP sequences.
527 In the loop context the meanings of pure and hybrid SLP are slightly
528 different. By saying that pure SLP is applied to the loop, we mean that we
529 exploit only intra-iteration parallelism in the loop; i.e., the loop can be
530 vectorized without doing any conceptual unrolling, cause we don't pack
531 together stmts from different iterations, only within a single iteration.
532 Loop hybrid SLP means that we exploit both intra-iteration and
533 inter-iteration parallelism (e.g., number of elements in the vector is 4
534 and the slp-group-size is 2, in which case we don't have enough parallelism
535 within an iteration, so we obtain the rest of the parallelism from subsequent
536 iterations by unrolling the loop by 2). */
537 enum slp_vect_type {
538 loop_vect = 0,
539 pure_slp,
540 hybrid
544 typedef struct data_reference *dr_p;
546 typedef struct _stmt_vec_info {
548 enum stmt_vec_info_type type;
550 /* Indicates whether this stmts is part of a computation whose result is
551 used outside the loop. */
552 bool live;
554 /* Stmt is part of some pattern (computation idiom) */
555 bool in_pattern_p;
557 /* The stmt to which this info struct refers to. */
558 gimple *stmt;
560 /* The vec_info with respect to which STMT is vectorized. */
561 vec_info *vinfo;
563 /* The vector type to be used for the LHS of this statement. */
564 tree vectype;
566 /* The vectorized version of the stmt. */
567 gimple *vectorized_stmt;
570 /** The following is relevant only for stmts that contain a non-scalar
571 data-ref (array/pointer/struct access). A GIMPLE stmt is expected to have
572 at most one such data-ref. **/
574 /* Information about the data-ref (access function, etc),
575 relative to the inner-most containing loop. */
576 struct data_reference *data_ref_info;
578 /* Information about the data-ref relative to this loop
579 nest (the loop that is being considered for vectorization). */
580 tree dr_base_address;
581 tree dr_init;
582 tree dr_offset;
583 tree dr_step;
584 tree dr_aligned_to;
586 /* For loop PHI nodes, the evolution part of it. This makes sure
587 this information is still available in vect_update_ivs_after_vectorizer
588 where we may not be able to re-analyze the PHI nodes evolution as
589 peeling for the prologue loop can make it unanalyzable. The evolution
590 part is still correct though. */
591 tree loop_phi_evolution_part;
593 /* Used for various bookkeeping purposes, generally holding a pointer to
594 some other stmt S that is in some way "related" to this stmt.
595 Current use of this field is:
596 If this stmt is part of a pattern (i.e. the field 'in_pattern_p' is
597 true): S is the "pattern stmt" that represents (and replaces) the
598 sequence of stmts that constitutes the pattern. Similarly, the
599 related_stmt of the "pattern stmt" points back to this stmt (which is
600 the last stmt in the original sequence of stmts that constitutes the
601 pattern). */
602 gimple *related_stmt;
604 /* Used to keep a sequence of def stmts of a pattern stmt if such exists. */
605 gimple_seq pattern_def_seq;
607 /* List of datarefs that are known to have the same alignment as the dataref
608 of this stmt. */
609 vec<dr_p> same_align_refs;
611 /* Selected SIMD clone's function info. First vector element
612 is SIMD clone's function decl, followed by a pair of trees (base + step)
613 for linear arguments (pair of NULLs for other arguments). */
614 vec<tree> simd_clone_info;
616 /* Classify the def of this stmt. */
617 enum vect_def_type def_type;
619 /* Whether the stmt is SLPed, loop-based vectorized, or both. */
620 enum slp_vect_type slp_type;
622 /* Interleaving and reduction chains info. */
623 /* First element in the group. */
624 gimple *first_element;
625 /* Pointer to the next element in the group. */
626 gimple *next_element;
627 /* For data-refs, in case that two or more stmts share data-ref, this is the
628 pointer to the previously detected stmt with the same dr. */
629 gimple *same_dr_stmt;
630 /* The size of the group. */
631 unsigned int size;
632 /* For stores, number of stores from this group seen. We vectorize the last
633 one. */
634 unsigned int store_count;
635 /* For loads only, the gap from the previous load. For consecutive loads, GAP
636 is 1. */
637 unsigned int gap;
639 /* The minimum negative dependence distance this stmt participates in
640 or zero if none. */
641 unsigned int min_neg_dist;
643 /* Not all stmts in the loop need to be vectorized. e.g, the increment
644 of the loop induction variable and computation of array indexes. relevant
645 indicates whether the stmt needs to be vectorized. */
646 enum vect_relevant relevant;
648 /* Is this statement vectorizable or should it be skipped in (partial)
649 vectorization. */
650 bool vectorizable;
652 /* For loads if this is a gather, for stores if this is a scatter. */
653 bool gather_scatter_p;
655 /* True if this is an access with loop-invariant stride. */
656 bool strided_p;
658 /* For both loads and stores. */
659 bool simd_lane_access_p;
660 } *stmt_vec_info;
662 /* Access Functions. */
663 #define STMT_VINFO_TYPE(S) (S)->type
664 #define STMT_VINFO_STMT(S) (S)->stmt
665 inline loop_vec_info
666 STMT_VINFO_LOOP_VINFO (stmt_vec_info stmt_vinfo)
668 if (loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (stmt_vinfo->vinfo))
669 return loop_vinfo;
670 return NULL;
672 inline bb_vec_info
673 STMT_VINFO_BB_VINFO (stmt_vec_info stmt_vinfo)
675 if (bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (stmt_vinfo->vinfo))
676 return bb_vinfo;
677 return NULL;
679 #define STMT_VINFO_RELEVANT(S) (S)->relevant
680 #define STMT_VINFO_LIVE_P(S) (S)->live
681 #define STMT_VINFO_VECTYPE(S) (S)->vectype
682 #define STMT_VINFO_VEC_STMT(S) (S)->vectorized_stmt
683 #define STMT_VINFO_VECTORIZABLE(S) (S)->vectorizable
684 #define STMT_VINFO_DATA_REF(S) (S)->data_ref_info
685 #define STMT_VINFO_GATHER_SCATTER_P(S) (S)->gather_scatter_p
686 #define STMT_VINFO_STRIDED_P(S) (S)->strided_p
687 #define STMT_VINFO_SIMD_LANE_ACCESS_P(S) (S)->simd_lane_access_p
689 #define STMT_VINFO_DR_BASE_ADDRESS(S) (S)->dr_base_address
690 #define STMT_VINFO_DR_INIT(S) (S)->dr_init
691 #define STMT_VINFO_DR_OFFSET(S) (S)->dr_offset
692 #define STMT_VINFO_DR_STEP(S) (S)->dr_step
693 #define STMT_VINFO_DR_ALIGNED_TO(S) (S)->dr_aligned_to
695 #define STMT_VINFO_IN_PATTERN_P(S) (S)->in_pattern_p
696 #define STMT_VINFO_RELATED_STMT(S) (S)->related_stmt
697 #define STMT_VINFO_PATTERN_DEF_SEQ(S) (S)->pattern_def_seq
698 #define STMT_VINFO_SAME_ALIGN_REFS(S) (S)->same_align_refs
699 #define STMT_VINFO_SIMD_CLONE_INFO(S) (S)->simd_clone_info
700 #define STMT_VINFO_DEF_TYPE(S) (S)->def_type
701 #define STMT_VINFO_GROUP_FIRST_ELEMENT(S) (S)->first_element
702 #define STMT_VINFO_GROUP_NEXT_ELEMENT(S) (S)->next_element
703 #define STMT_VINFO_GROUP_SIZE(S) (S)->size
704 #define STMT_VINFO_GROUP_STORE_COUNT(S) (S)->store_count
705 #define STMT_VINFO_GROUP_GAP(S) (S)->gap
706 #define STMT_VINFO_GROUP_SAME_DR_STMT(S) (S)->same_dr_stmt
707 #define STMT_VINFO_GROUPED_ACCESS(S) ((S)->first_element != NULL && (S)->data_ref_info)
708 #define STMT_VINFO_LOOP_PHI_EVOLUTION_PART(S) (S)->loop_phi_evolution_part
709 #define STMT_VINFO_MIN_NEG_DIST(S) (S)->min_neg_dist
711 #define GROUP_FIRST_ELEMENT(S) (S)->first_element
712 #define GROUP_NEXT_ELEMENT(S) (S)->next_element
713 #define GROUP_SIZE(S) (S)->size
714 #define GROUP_STORE_COUNT(S) (S)->store_count
715 #define GROUP_GAP(S) (S)->gap
716 #define GROUP_SAME_DR_STMT(S) (S)->same_dr_stmt
718 #define STMT_VINFO_RELEVANT_P(S) ((S)->relevant != vect_unused_in_scope)
720 #define HYBRID_SLP_STMT(S) ((S)->slp_type == hybrid)
721 #define PURE_SLP_STMT(S) ((S)->slp_type == pure_slp)
722 #define STMT_SLP_TYPE(S) (S)->slp_type
724 struct dataref_aux {
725 int misalignment;
726 /* If true the alignment of base_decl needs to be increased. */
727 bool base_misaligned;
728 /* If true we know the base is at least vector element alignment aligned. */
729 bool base_element_aligned;
730 tree base_decl;
733 #define DR_VECT_AUX(dr) ((dataref_aux *)(dr)->aux)
735 #define VECT_MAX_COST 1000
737 /* The maximum number of intermediate steps required in multi-step type
738 conversion. */
739 #define MAX_INTERM_CVT_STEPS 3
741 /* The maximum vectorization factor supported by any target (V64QI). */
742 #define MAX_VECTORIZATION_FACTOR 64
744 extern vec<stmt_vec_info> stmt_vec_info_vec;
746 void init_stmt_vec_info_vec (void);
747 void free_stmt_vec_info_vec (void);
749 /* Return a stmt_vec_info corresponding to STMT. */
751 static inline stmt_vec_info
752 vinfo_for_stmt (gimple *stmt)
754 unsigned int uid = gimple_uid (stmt);
755 if (uid == 0)
756 return NULL;
758 return stmt_vec_info_vec[uid - 1];
761 /* Set vectorizer information INFO for STMT. */
763 static inline void
764 set_vinfo_for_stmt (gimple *stmt, stmt_vec_info info)
766 unsigned int uid = gimple_uid (stmt);
767 if (uid == 0)
769 gcc_checking_assert (info);
770 uid = stmt_vec_info_vec.length () + 1;
771 gimple_set_uid (stmt, uid);
772 stmt_vec_info_vec.safe_push (info);
774 else
775 stmt_vec_info_vec[uid - 1] = info;
778 /* Return the earlier statement between STMT1 and STMT2. */
780 static inline gimple *
781 get_earlier_stmt (gimple *stmt1, gimple *stmt2)
783 unsigned int uid1, uid2;
785 if (stmt1 == NULL)
786 return stmt2;
788 if (stmt2 == NULL)
789 return stmt1;
791 uid1 = gimple_uid (stmt1);
792 uid2 = gimple_uid (stmt2);
794 if (uid1 == 0 || uid2 == 0)
795 return NULL;
797 gcc_checking_assert (uid1 <= stmt_vec_info_vec.length ()
798 && uid2 <= stmt_vec_info_vec.length ());
800 if (uid1 < uid2)
801 return stmt1;
802 else
803 return stmt2;
806 /* Return the later statement between STMT1 and STMT2. */
808 static inline gimple *
809 get_later_stmt (gimple *stmt1, gimple *stmt2)
811 unsigned int uid1, uid2;
813 if (stmt1 == NULL)
814 return stmt2;
816 if (stmt2 == NULL)
817 return stmt1;
819 uid1 = gimple_uid (stmt1);
820 uid2 = gimple_uid (stmt2);
822 if (uid1 == 0 || uid2 == 0)
823 return NULL;
825 gcc_assert (uid1 <= stmt_vec_info_vec.length ());
826 gcc_assert (uid2 <= stmt_vec_info_vec.length ());
828 if (uid1 > uid2)
829 return stmt1;
830 else
831 return stmt2;
834 /* Return TRUE if a statement represented by STMT_INFO is a part of a
835 pattern. */
837 static inline bool
838 is_pattern_stmt_p (stmt_vec_info stmt_info)
840 gimple *related_stmt;
841 stmt_vec_info related_stmt_info;
843 related_stmt = STMT_VINFO_RELATED_STMT (stmt_info);
844 if (related_stmt
845 && (related_stmt_info = vinfo_for_stmt (related_stmt))
846 && STMT_VINFO_IN_PATTERN_P (related_stmt_info))
847 return true;
849 return false;
852 /* Return true if BB is a loop header. */
854 static inline bool
855 is_loop_header_bb_p (basic_block bb)
857 if (bb == (bb->loop_father)->header)
858 return true;
859 gcc_checking_assert (EDGE_COUNT (bb->preds) == 1);
860 return false;
863 /* Return pow2 (X). */
865 static inline int
866 vect_pow2 (int x)
868 int i, res = 1;
870 for (i = 0; i < x; i++)
871 res *= 2;
873 return res;
876 /* Alias targetm.vectorize.builtin_vectorization_cost. */
878 static inline int
879 builtin_vectorization_cost (enum vect_cost_for_stmt type_of_cost,
880 tree vectype, int misalign)
882 return targetm.vectorize.builtin_vectorization_cost (type_of_cost,
883 vectype, misalign);
886 /* Get cost by calling cost target builtin. */
888 static inline
889 int vect_get_stmt_cost (enum vect_cost_for_stmt type_of_cost)
891 return builtin_vectorization_cost (type_of_cost, NULL, 0);
894 /* Alias targetm.vectorize.init_cost. */
896 static inline void *
897 init_cost (struct loop *loop_info)
899 return targetm.vectorize.init_cost (loop_info);
902 /* Alias targetm.vectorize.add_stmt_cost. */
904 static inline unsigned
905 add_stmt_cost (void *data, int count, enum vect_cost_for_stmt kind,
906 stmt_vec_info stmt_info, int misalign,
907 enum vect_cost_model_location where)
909 return targetm.vectorize.add_stmt_cost (data, count, kind,
910 stmt_info, misalign, where);
913 /* Alias targetm.vectorize.finish_cost. */
915 static inline void
916 finish_cost (void *data, unsigned *prologue_cost,
917 unsigned *body_cost, unsigned *epilogue_cost)
919 targetm.vectorize.finish_cost (data, prologue_cost, body_cost, epilogue_cost);
922 /* Alias targetm.vectorize.destroy_cost_data. */
924 static inline void
925 destroy_cost_data (void *data)
927 targetm.vectorize.destroy_cost_data (data);
930 /*-----------------------------------------------------------------*/
931 /* Info on data references alignment. */
932 /*-----------------------------------------------------------------*/
933 inline void
934 set_dr_misalignment (struct data_reference *dr, int val)
936 dataref_aux *data_aux = DR_VECT_AUX (dr);
938 if (!data_aux)
940 data_aux = XCNEW (dataref_aux);
941 dr->aux = data_aux;
944 data_aux->misalignment = val;
947 inline int
948 dr_misalignment (struct data_reference *dr)
950 return DR_VECT_AUX (dr)->misalignment;
953 /* Reflects actual alignment of first access in the vectorized loop,
954 taking into account peeling/versioning if applied. */
955 #define DR_MISALIGNMENT(DR) dr_misalignment (DR)
956 #define SET_DR_MISALIGNMENT(DR, VAL) set_dr_misalignment (DR, VAL)
958 /* Return TRUE if the data access is aligned, and FALSE otherwise. */
960 static inline bool
961 aligned_access_p (struct data_reference *data_ref_info)
963 return (DR_MISALIGNMENT (data_ref_info) == 0);
966 /* Return TRUE if the alignment of the data access is known, and FALSE
967 otherwise. */
969 static inline bool
970 known_alignment_for_access_p (struct data_reference *data_ref_info)
972 return (DR_MISALIGNMENT (data_ref_info) != -1);
976 /* Return true if the vect cost model is unlimited. */
977 static inline bool
978 unlimited_cost_model (loop_p loop)
980 if (loop != NULL && loop->force_vectorize
981 && flag_simd_cost_model != VECT_COST_MODEL_DEFAULT)
982 return flag_simd_cost_model == VECT_COST_MODEL_UNLIMITED;
983 return (flag_vect_cost_model == VECT_COST_MODEL_UNLIMITED);
986 /* Source location */
987 extern source_location vect_location;
989 /*-----------------------------------------------------------------*/
990 /* Function prototypes. */
991 /*-----------------------------------------------------------------*/
993 /* Simple loop peeling and versioning utilities for vectorizer's purposes -
994 in tree-vect-loop-manip.c. */
995 extern void slpeel_make_loop_iterate_ntimes (struct loop *, tree);
996 extern bool slpeel_can_duplicate_loop_p (const struct loop *, const_edge);
997 struct loop *slpeel_tree_duplicate_loop_to_edge_cfg (struct loop *,
998 struct loop *, edge);
999 extern void vect_loop_versioning (loop_vec_info, unsigned int, bool);
1000 extern void vect_do_peeling_for_loop_bound (loop_vec_info, tree, tree,
1001 unsigned int, bool);
1002 extern void vect_do_peeling_for_alignment (loop_vec_info, tree,
1003 unsigned int, bool);
1004 extern source_location find_loop_location (struct loop *);
1005 extern bool vect_can_advance_ivs_p (loop_vec_info);
1007 /* In tree-vect-stmts.c. */
1008 extern unsigned int current_vector_size;
1009 extern tree get_vectype_for_scalar_type (tree);
1010 extern tree get_same_sized_vectype (tree, tree);
1011 extern bool vect_is_simple_use (tree, gimple *, vec_info *, gimple **,
1012 tree *, enum vect_def_type *);
1013 extern bool vect_is_simple_use_1 (tree, gimple *, vec_info *, gimple **,
1014 tree *, enum vect_def_type *, tree *);
1015 extern bool supportable_widening_operation (enum tree_code, gimple *, tree,
1016 tree, enum tree_code *,
1017 enum tree_code *, int *,
1018 vec<tree> *);
1019 extern bool supportable_narrowing_operation (enum tree_code, tree, tree,
1020 enum tree_code *,
1021 int *, vec<tree> *);
1022 extern stmt_vec_info new_stmt_vec_info (gimple *stmt, vec_info *);
1023 extern void free_stmt_vec_info (gimple *stmt);
1024 extern tree vectorizable_function (gcall *, tree, tree);
1025 extern void vect_model_simple_cost (stmt_vec_info, int, enum vect_def_type *,
1026 stmt_vector_for_cost *,
1027 stmt_vector_for_cost *);
1028 extern void vect_model_store_cost (stmt_vec_info, int, bool,
1029 enum vect_def_type, slp_tree,
1030 stmt_vector_for_cost *,
1031 stmt_vector_for_cost *);
1032 extern void vect_model_load_cost (stmt_vec_info, int, bool, slp_tree,
1033 stmt_vector_for_cost *,
1034 stmt_vector_for_cost *);
1035 extern unsigned record_stmt_cost (stmt_vector_for_cost *, int,
1036 enum vect_cost_for_stmt, stmt_vec_info,
1037 int, enum vect_cost_model_location);
1038 extern void vect_finish_stmt_generation (gimple *, gimple *,
1039 gimple_stmt_iterator *);
1040 extern bool vect_mark_stmts_to_be_vectorized (loop_vec_info);
1041 extern tree vect_get_vec_def_for_operand (tree, gimple *, tree *);
1042 extern tree vect_init_vector (gimple *, tree, tree,
1043 gimple_stmt_iterator *);
1044 extern tree vect_get_vec_def_for_stmt_copy (enum vect_def_type, tree);
1045 extern bool vect_transform_stmt (gimple *, gimple_stmt_iterator *,
1046 bool *, slp_tree, slp_instance);
1047 extern void vect_remove_stores (gimple *);
1048 extern bool vect_analyze_stmt (gimple *, bool *, slp_tree);
1049 extern bool vectorizable_condition (gimple *, gimple_stmt_iterator *,
1050 gimple **, tree, int, slp_tree);
1051 extern void vect_get_load_cost (struct data_reference *, int, bool,
1052 unsigned int *, unsigned int *,
1053 stmt_vector_for_cost *,
1054 stmt_vector_for_cost *, bool);
1055 extern void vect_get_store_cost (struct data_reference *, int,
1056 unsigned int *, stmt_vector_for_cost *);
1057 extern bool vect_supportable_shift (enum tree_code, tree);
1058 extern void vect_get_vec_defs (tree, tree, gimple *, vec<tree> *,
1059 vec<tree> *, slp_tree, int);
1060 extern tree vect_gen_perm_mask_any (tree, const unsigned char *);
1061 extern tree vect_gen_perm_mask_checked (tree, const unsigned char *);
1063 /* In tree-vect-data-refs.c. */
1064 extern bool vect_can_force_dr_alignment_p (const_tree, unsigned int);
1065 extern enum dr_alignment_support vect_supportable_dr_alignment
1066 (struct data_reference *, bool);
1067 extern tree vect_get_smallest_scalar_type (gimple *, HOST_WIDE_INT *,
1068 HOST_WIDE_INT *);
1069 extern bool vect_analyze_data_ref_dependences (loop_vec_info, int *);
1070 extern bool vect_slp_analyze_data_ref_dependences (bb_vec_info);
1071 extern bool vect_enhance_data_refs_alignment (loop_vec_info);
1072 extern bool vect_analyze_data_refs_alignment (vec_info *);
1073 extern bool vect_verify_datarefs_alignment (vec_info *);
1074 extern bool vect_analyze_data_ref_accesses (vec_info *);
1075 extern bool vect_prune_runtime_alias_test_list (loop_vec_info);
1076 extern tree vect_check_gather_scatter (gimple *, loop_vec_info, tree *, tree *,
1077 int *);
1078 extern bool vect_analyze_data_refs (vec_info *, int *, unsigned *);
1079 extern tree vect_create_data_ref_ptr (gimple *, tree, struct loop *, tree,
1080 tree *, gimple_stmt_iterator *,
1081 gimple **, bool, bool *,
1082 tree = NULL_TREE);
1083 extern tree bump_vector_ptr (tree, gimple *, gimple_stmt_iterator *, gimple *,
1084 tree);
1085 extern tree vect_create_destination_var (tree, tree);
1086 extern bool vect_grouped_store_supported (tree, unsigned HOST_WIDE_INT);
1087 extern bool vect_store_lanes_supported (tree, unsigned HOST_WIDE_INT);
1088 extern bool vect_grouped_load_supported (tree, unsigned HOST_WIDE_INT);
1089 extern bool vect_load_lanes_supported (tree, unsigned HOST_WIDE_INT);
1090 extern void vect_permute_store_chain (vec<tree> ,unsigned int, gimple *,
1091 gimple_stmt_iterator *, vec<tree> *);
1092 extern tree vect_setup_realignment (gimple *, gimple_stmt_iterator *, tree *,
1093 enum dr_alignment_support, tree,
1094 struct loop **);
1095 extern void vect_transform_grouped_load (gimple *, vec<tree> , int,
1096 gimple_stmt_iterator *);
1097 extern void vect_record_grouped_load_vectors (gimple *, vec<tree> );
1098 extern tree vect_get_new_vect_var (tree, enum vect_var_kind, const char *);
1099 extern tree vect_create_addr_base_for_vector_ref (gimple *, gimple_seq *,
1100 tree, struct loop *,
1101 tree = NULL_TREE);
1103 /* In tree-vect-loop.c. */
1104 /* FORNOW: Used in tree-parloops.c. */
1105 extern void destroy_loop_vec_info (loop_vec_info, bool);
1106 extern gimple *vect_force_simple_reduction (loop_vec_info, gimple *, bool,
1107 bool *, bool);
1108 /* Drive for loop analysis stage. */
1109 extern loop_vec_info vect_analyze_loop (struct loop *);
1110 /* Drive for loop transformation stage. */
1111 extern void vect_transform_loop (loop_vec_info);
1112 extern loop_vec_info vect_analyze_loop_form (struct loop *);
1113 extern bool vectorizable_live_operation (gimple *, gimple_stmt_iterator *,
1114 gimple **);
1115 extern bool vectorizable_reduction (gimple *, gimple_stmt_iterator *,
1116 gimple **, slp_tree);
1117 extern bool vectorizable_induction (gimple *, gimple_stmt_iterator *, gimple **);
1118 extern tree get_initial_def_for_reduction (gimple *, tree, tree *);
1119 extern int vect_min_worthwhile_factor (enum tree_code);
1120 extern int vect_get_known_peeling_cost (loop_vec_info, int, int *,
1121 stmt_vector_for_cost *,
1122 stmt_vector_for_cost *,
1123 stmt_vector_for_cost *);
1125 /* In tree-vect-slp.c. */
1126 extern void vect_free_slp_instance (slp_instance);
1127 extern bool vect_transform_slp_perm_load (slp_tree, vec<tree> ,
1128 gimple_stmt_iterator *, int,
1129 slp_instance, bool);
1130 extern bool vect_slp_analyze_operations (vec<slp_instance> slp_instances,
1131 void *);
1132 extern bool vect_schedule_slp (vec_info *);
1133 extern bool vect_analyze_slp (vec_info *, unsigned);
1134 extern bool vect_make_slp_decision (loop_vec_info);
1135 extern void vect_detect_hybrid_slp (loop_vec_info);
1136 extern void vect_get_slp_defs (vec<tree> , slp_tree,
1137 vec<vec<tree> > *, int);
1139 extern source_location find_bb_location (basic_block);
1140 extern bb_vec_info vect_slp_analyze_bb (basic_block);
1141 extern void vect_slp_transform_bb (basic_block);
1143 /* In tree-vect-patterns.c. */
1144 /* Pattern recognition functions.
1145 Additional pattern recognition functions can (and will) be added
1146 in the future. */
1147 typedef gimple *(* vect_recog_func_ptr) (vec<gimple *> *, tree *, tree *);
1148 #define NUM_PATTERNS 13
1149 void vect_pattern_recog (vec_info *);
1151 /* In tree-vectorizer.c. */
1152 unsigned vectorize_loops (void);
1153 void vect_destroy_datarefs (vec_info *);
1155 #endif /* GCC_TREE_VECTORIZER_H */