2 Copyright (C) 2003-2017 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
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
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"
27 /* Used for naming of new temporaries. */
35 /* Defines type of operation. */
42 /* Define type of available alignment support. */
43 enum dr_alignment_support
{
44 dr_unaligned_unsupported
,
45 dr_unaligned_supported
,
47 dr_explicit_realign_optimized
,
51 /* Define type of def-use cross-iteration cycle. */
53 vect_uninitialized_def
= 0,
54 vect_constant_def
= 1,
59 vect_double_reduction_def
,
64 /* Define type of reduction. */
65 enum vect_reduction_type
{
68 INTEGER_INDUC_COND_REDUCTION
,
72 #define VECTORIZABLE_CYCLE_DEF(D) (((D) == vect_reduction_def) \
73 || ((D) == vect_double_reduction_def) \
74 || ((D) == vect_nested_cycle))
76 /* Structure to encapsulate information about a group of like
77 instructions to be presented to the target cost model. */
78 struct stmt_info_for_cost
{
80 enum vect_cost_for_stmt kind
;
85 typedef vec
<stmt_info_for_cost
> stmt_vector_for_cost
;
87 /************************************************************************
89 ************************************************************************/
90 typedef struct _slp_tree
*slp_tree
;
92 /* A computation tree of an SLP instance. Each node corresponds to a group of
93 stmts to be packed in a SIMD stmt. */
95 /* Nodes that contain def-stmts of this node statements operands. */
96 vec
<slp_tree
> children
;
97 /* A group of scalar stmts to be vectorized together. */
99 /* Load permutation relative to the stores, NULL if there is no
101 vec
<unsigned> load_permutation
;
102 /* Vectorized stmt/s. */
103 vec
<gimple
*> vec_stmts
;
104 /* Number of vector stmts that are created to replace the group of scalar
105 stmts. It is calculated during the transformation phase as the number of
106 scalar elements in one scalar iteration (GROUP_SIZE) multiplied by VF
107 divided by vector size. */
108 unsigned int vec_stmts_size
;
109 /* Whether the scalar computations use two different operators. */
111 /* The DEF type of this node. */
112 enum vect_def_type def_type
;
116 /* SLP instance is a sequence of stmts in a loop that can be packed into
118 typedef struct _slp_instance
{
119 /* The root of SLP tree. */
122 /* Size of groups of scalar stmts that will be replaced by SIMD stmt/s. */
123 unsigned int group_size
;
125 /* The unrolling factor required to vectorized this SLP instance. */
126 unsigned int unrolling_factor
;
128 /* The group of nodes that contain loads of this SLP instance. */
133 /* Access Functions. */
134 #define SLP_INSTANCE_TREE(S) (S)->root
135 #define SLP_INSTANCE_GROUP_SIZE(S) (S)->group_size
136 #define SLP_INSTANCE_UNROLLING_FACTOR(S) (S)->unrolling_factor
137 #define SLP_INSTANCE_LOADS(S) (S)->loads
139 #define SLP_TREE_CHILDREN(S) (S)->children
140 #define SLP_TREE_SCALAR_STMTS(S) (S)->stmts
141 #define SLP_TREE_VEC_STMTS(S) (S)->vec_stmts
142 #define SLP_TREE_NUMBER_OF_VEC_STMTS(S) (S)->vec_stmts_size
143 #define SLP_TREE_LOAD_PERMUTATION(S) (S)->load_permutation
144 #define SLP_TREE_TWO_OPERATORS(S) (S)->two_operators
145 #define SLP_TREE_DEF_TYPE(S) (S)->def_type
149 /* This struct is used to store the information of a data reference,
150 including the data ref itself and the segment length for aliasing
151 checks. This is used to merge alias checks. */
153 struct dr_with_seg_len
155 dr_with_seg_len (data_reference_p d
, tree len
)
156 : dr (d
), seg_len (len
) {}
162 /* This struct contains two dr_with_seg_len objects with aliasing data
163 refs. Two comparisons are generated from them. */
165 struct dr_with_seg_len_pair_t
167 dr_with_seg_len_pair_t (const dr_with_seg_len
& d1
,
168 const dr_with_seg_len
& d2
)
169 : first (d1
), second (d2
) {}
171 dr_with_seg_len first
;
172 dr_with_seg_len second
;
177 /* Vectorizer state common between loop and basic-block vectorization. */
179 enum { bb
, loop
} kind
;
181 /* All SLP instances. */
182 vec
<slp_instance
> slp_instances
;
184 /* All data references. */
185 vec
<data_reference_p
> datarefs
;
187 /* All data dependences. */
190 /* All interleaving chains of stores, represented by the first
191 stmt in the chain. */
192 vec
<gimple
*> grouped_stores
;
194 /* Cost data used by the target cost model. */
195 void *target_cost_data
;
198 struct _loop_vec_info
;
204 is_a_helper
<_loop_vec_info
*>::test (vec_info
*i
)
206 return i
->kind
== vec_info::loop
;
212 is_a_helper
<_bb_vec_info
*>::test (vec_info
*i
)
214 return i
->kind
== vec_info::bb
;
218 /*-----------------------------------------------------------------*/
219 /* Info on vectorized loops. */
220 /*-----------------------------------------------------------------*/
221 typedef struct _loop_vec_info
: public vec_info
{
223 /* The loop to which this info struct refers to. */
226 /* The loop basic blocks. */
229 /* Number of latch executions. */
231 /* Number of iterations. */
233 /* Number of iterations of the original loop. */
234 tree num_iters_unchanged
;
235 /* Condition under which this loop is analyzed and versioned. */
236 tree num_iters_assumptions
;
238 /* Threshold of number of iterations below which vectorzation will not be
239 performed. It is calculated from MIN_PROFITABLE_ITERS and
240 PARAM_MIN_VECT_LOOP_BOUND. */
243 /* Is the loop vectorizable? */
246 /* Unrolling factor */
247 int vectorization_factor
;
249 /* Unknown DRs according to which loop was peeled. */
250 struct data_reference
*unaligned_dr
;
252 /* peeling_for_alignment indicates whether peeling for alignment will take
253 place, and what the peeling factor should be:
254 peeling_for_alignment = X means:
255 If X=0: Peeling for alignment will not be applied.
256 If X>0: Peel first X iterations.
257 If X=-1: Generate a runtime test to calculate the number of iterations
258 to be peeled, using the dataref recorded in the field
260 int peeling_for_alignment
;
262 /* The mask used to check the alignment of pointers or arrays. */
265 /* The loop nest in which the data dependences are computed. */
266 vec
<loop_p
> loop_nest
;
268 /* Data Dependence Relations defining address ranges that are candidates
269 for a run-time aliasing check. */
270 vec
<ddr_p
> may_alias_ddrs
;
272 /* Data Dependence Relations defining address ranges together with segment
273 lengths from which the run-time aliasing check is built. */
274 vec
<dr_with_seg_len_pair_t
> comp_alias_ddrs
;
276 /* Statements in the loop that have data references that are candidates for a
277 runtime (loop versioning) misalignment check. */
278 vec
<gimple
*> may_misalign_stmts
;
280 /* The unrolling factor needed to SLP the loop. In case of that pure SLP is
281 applied to the loop, i.e., no unrolling is needed, this is 1. */
282 unsigned slp_unrolling_factor
;
284 /* Reduction cycles detected in the loop. Used in loop-aware SLP. */
285 vec
<gimple
*> reductions
;
287 /* All reduction chains in the loop, represented by the first
288 stmt in the chain. */
289 vec
<gimple
*> reduction_chains
;
291 /* Cost vector for a single scalar iteration. */
292 vec
<stmt_info_for_cost
> scalar_cost_vec
;
294 /* Cost of a single scalar iteration. */
295 int single_scalar_iteration_cost
;
297 /* When we have grouped data accesses with gaps, we may introduce invalid
298 memory accesses. We peel the last iteration of the loop to prevent
300 bool peeling_for_gaps
;
302 /* When the number of iterations is not a multiple of the vector size
303 we need to peel off iterations at the end to form an epilogue loop. */
304 bool peeling_for_niter
;
306 /* Reductions are canonicalized so that the last operand is the reduction
307 operand. If this places a constant into RHS1, this decanonicalizes
308 GIMPLE for other phases, so we must track when this has occurred and
310 bool operands_swapped
;
312 /* True if there are no loop carried data dependencies in the loop.
313 If loop->safelen <= 1, then this is always true, either the loop
314 didn't have any loop carried data dependencies, or the loop is being
315 vectorized guarded with some runtime alias checks, or couldn't
316 be vectorized at all, but then this field shouldn't be used.
317 For loop->safelen >= 2, the user has asserted that there are no
318 backward dependencies, but there still could be loop carried forward
319 dependencies in such loops. This flag will be false if normal
320 vectorizer data dependency analysis would fail or require versioning
321 for alias, but because of loop->safelen >= 2 it has been vectorized
322 even without versioning for alias. E.g. in:
324 for (int i = 0; i < m; i++)
326 (or #pragma simd or #pragma ivdep) we can vectorize this and it will
327 DTRT even for k > 0 && k < m, but without safelen we would not
328 vectorize this, so this field would be false. */
329 bool no_data_dependencies
;
331 /* If if-conversion versioned this loop before conversion, this is the
332 loop version without if-conversion. */
333 struct loop
*scalar_loop
;
335 /* Mark loops having masked stores. */
338 /* For loops being epilogues of already vectorized loops
339 this points to the original vectorized loop. Otherwise NULL. */
340 _loop_vec_info
*orig_loop_info
;
344 /* Access Functions. */
345 #define LOOP_VINFO_LOOP(L) (L)->loop
346 #define LOOP_VINFO_BBS(L) (L)->bbs
347 #define LOOP_VINFO_NITERSM1(L) (L)->num_itersm1
348 #define LOOP_VINFO_NITERS(L) (L)->num_iters
349 /* Since LOOP_VINFO_NITERS and LOOP_VINFO_NITERSM1 can change after
350 prologue peeling retain total unchanged scalar loop iterations for
352 #define LOOP_VINFO_NITERS_UNCHANGED(L) (L)->num_iters_unchanged
353 #define LOOP_VINFO_NITERS_ASSUMPTIONS(L) (L)->num_iters_assumptions
354 #define LOOP_VINFO_COST_MODEL_THRESHOLD(L) (L)->th
355 #define LOOP_VINFO_VECTORIZABLE_P(L) (L)->vectorizable
356 #define LOOP_VINFO_VECT_FACTOR(L) (L)->vectorization_factor
357 #define LOOP_VINFO_PTR_MASK(L) (L)->ptr_mask
358 #define LOOP_VINFO_LOOP_NEST(L) (L)->loop_nest
359 #define LOOP_VINFO_DATAREFS(L) (L)->datarefs
360 #define LOOP_VINFO_DDRS(L) (L)->ddrs
361 #define LOOP_VINFO_INT_NITERS(L) (TREE_INT_CST_LOW ((L)->num_iters))
362 #define LOOP_VINFO_PEELING_FOR_ALIGNMENT(L) (L)->peeling_for_alignment
363 #define LOOP_VINFO_UNALIGNED_DR(L) (L)->unaligned_dr
364 #define LOOP_VINFO_MAY_MISALIGN_STMTS(L) (L)->may_misalign_stmts
365 #define LOOP_VINFO_MAY_ALIAS_DDRS(L) (L)->may_alias_ddrs
366 #define LOOP_VINFO_COMP_ALIAS_DDRS(L) (L)->comp_alias_ddrs
367 #define LOOP_VINFO_GROUPED_STORES(L) (L)->grouped_stores
368 #define LOOP_VINFO_SLP_INSTANCES(L) (L)->slp_instances
369 #define LOOP_VINFO_SLP_UNROLLING_FACTOR(L) (L)->slp_unrolling_factor
370 #define LOOP_VINFO_REDUCTIONS(L) (L)->reductions
371 #define LOOP_VINFO_REDUCTION_CHAINS(L) (L)->reduction_chains
372 #define LOOP_VINFO_TARGET_COST_DATA(L) (L)->target_cost_data
373 #define LOOP_VINFO_PEELING_FOR_GAPS(L) (L)->peeling_for_gaps
374 #define LOOP_VINFO_OPERANDS_SWAPPED(L) (L)->operands_swapped
375 #define LOOP_VINFO_PEELING_FOR_NITER(L) (L)->peeling_for_niter
376 #define LOOP_VINFO_NO_DATA_DEPENDENCIES(L) (L)->no_data_dependencies
377 #define LOOP_VINFO_SCALAR_LOOP(L) (L)->scalar_loop
378 #define LOOP_VINFO_HAS_MASK_STORE(L) (L)->has_mask_store
379 #define LOOP_VINFO_SCALAR_ITERATION_COST(L) (L)->scalar_cost_vec
380 #define LOOP_VINFO_SINGLE_SCALAR_ITERATION_COST(L) (L)->single_scalar_iteration_cost
381 #define LOOP_VINFO_ORIG_LOOP_INFO(L) (L)->orig_loop_info
383 #define LOOP_REQUIRES_VERSIONING_FOR_ALIGNMENT(L) \
384 ((L)->may_misalign_stmts.length () > 0)
385 #define LOOP_REQUIRES_VERSIONING_FOR_ALIAS(L) \
386 ((L)->may_alias_ddrs.length () > 0)
387 #define LOOP_REQUIRES_VERSIONING_FOR_NITERS(L) \
388 (LOOP_VINFO_NITERS_ASSUMPTIONS (L))
389 #define LOOP_REQUIRES_VERSIONING(L) \
390 (LOOP_REQUIRES_VERSIONING_FOR_ALIGNMENT (L) \
391 || LOOP_REQUIRES_VERSIONING_FOR_ALIAS (L) \
392 || LOOP_REQUIRES_VERSIONING_FOR_NITERS (L))
394 #define LOOP_VINFO_NITERS_KNOWN_P(L) \
395 (tree_fits_shwi_p ((L)->num_iters) && tree_to_shwi ((L)->num_iters) > 0)
397 #define LOOP_VINFO_EPILOGUE_P(L) \
398 (LOOP_VINFO_ORIG_LOOP_INFO (L) != NULL)
400 #define LOOP_VINFO_ORIG_VECT_FACTOR(L) \
401 (LOOP_VINFO_VECT_FACTOR (LOOP_VINFO_ORIG_LOOP_INFO (L)))
403 static inline loop_vec_info
404 loop_vec_info_for_loop (struct loop
*loop
)
406 return (loop_vec_info
) loop
->aux
;
410 nested_in_vect_loop_p (struct loop
*loop
, gimple
*stmt
)
413 && (loop
->inner
== (gimple_bb (stmt
))->loop_father
));
416 typedef struct _bb_vec_info
: public vec_info
419 gimple_stmt_iterator region_begin
;
420 gimple_stmt_iterator region_end
;
423 #define BB_VINFO_BB(B) (B)->bb
424 #define BB_VINFO_GROUPED_STORES(B) (B)->grouped_stores
425 #define BB_VINFO_SLP_INSTANCES(B) (B)->slp_instances
426 #define BB_VINFO_DATAREFS(B) (B)->datarefs
427 #define BB_VINFO_DDRS(B) (B)->ddrs
428 #define BB_VINFO_TARGET_COST_DATA(B) (B)->target_cost_data
430 static inline bb_vec_info
431 vec_info_for_bb (basic_block bb
)
433 return (bb_vec_info
) bb
->aux
;
436 /*-----------------------------------------------------------------*/
437 /* Info on vectorized defs. */
438 /*-----------------------------------------------------------------*/
439 enum stmt_vec_info_type
{
440 undef_vec_info_type
= 0,
446 call_simd_clone_vec_info_type
,
447 assignment_vec_info_type
,
448 condition_vec_info_type
,
449 comparison_vec_info_type
,
452 type_promotion_vec_info_type
,
453 type_demotion_vec_info_type
,
454 type_conversion_vec_info_type
,
455 loop_exit_ctrl_vec_info_type
458 /* Indicates whether/how a variable is used in the scope of loop/basic
461 vect_unused_in_scope
= 0,
463 /* The def is only used outside the loop. */
465 /* The def is in the inner loop, and the use is in the outer loop, and the
466 use is a reduction stmt. */
467 vect_used_in_outer_by_reduction
,
468 /* The def is in the inner loop, and the use is in the outer loop (and is
469 not part of reduction). */
472 /* defs that feed computations that end up (only) in a reduction. These
473 defs may be used by non-reduction stmts, but eventually, any
474 computations/values that are affected by these defs are used to compute
475 a reduction (i.e. don't get stored to memory, for example). We use this
476 to identify computations that we can change the order in which they are
478 vect_used_by_reduction
,
483 /* The type of vectorization that can be applied to the stmt: regular loop-based
484 vectorization; pure SLP - the stmt is a part of SLP instances and does not
485 have uses outside SLP instances; or hybrid SLP and loop-based - the stmt is
486 a part of SLP instance and also must be loop-based vectorized, since it has
487 uses outside SLP sequences.
489 In the loop context the meanings of pure and hybrid SLP are slightly
490 different. By saying that pure SLP is applied to the loop, we mean that we
491 exploit only intra-iteration parallelism in the loop; i.e., the loop can be
492 vectorized without doing any conceptual unrolling, cause we don't pack
493 together stmts from different iterations, only within a single iteration.
494 Loop hybrid SLP means that we exploit both intra-iteration and
495 inter-iteration parallelism (e.g., number of elements in the vector is 4
496 and the slp-group-size is 2, in which case we don't have enough parallelism
497 within an iteration, so we obtain the rest of the parallelism from subsequent
498 iterations by unrolling the loop by 2). */
505 /* Describes how we're going to vectorize an individual load or store,
506 or a group of loads or stores. */
507 enum vect_memory_access_type
{
508 /* An access to an invariant address. This is used only for loads. */
511 /* A simple contiguous access. */
514 /* A contiguous access that goes down in memory rather than up,
515 with no additional permutation. This is used only for stores
517 VMAT_CONTIGUOUS_DOWN
,
519 /* A simple contiguous access in which the elements need to be permuted
520 after loading or before storing. Only used for loop vectorization;
521 SLP uses separate permutes. */
522 VMAT_CONTIGUOUS_PERMUTE
,
524 /* A simple contiguous access in which the elements need to be reversed
525 after loading or before storing. */
526 VMAT_CONTIGUOUS_REVERSE
,
528 /* An access that uses IFN_LOAD_LANES or IFN_STORE_LANES. */
529 VMAT_LOAD_STORE_LANES
,
531 /* An access in which each scalar element is loaded or stored
535 /* A hybrid of VMAT_CONTIGUOUS and VMAT_ELEMENTWISE, used for grouped
536 SLP accesses. Each unrolled iteration uses a contiguous load
537 or store for the whole group, but the groups from separate iterations
538 are combined in the same way as for VMAT_ELEMENTWISE. */
541 /* The access uses gather loads or scatter stores. */
545 typedef struct data_reference
*dr_p
;
547 typedef struct _stmt_vec_info
{
549 enum stmt_vec_info_type type
;
551 /* Indicates whether this stmts is part of a computation whose result is
552 used outside the loop. */
555 /* Stmt is part of some pattern (computation idiom) */
558 /* The stmt to which this info struct refers to. */
561 /* The vec_info with respect to which STMT is vectorized. */
564 /* The vector type to be used for the LHS of this statement. */
567 /* The vectorized version of the stmt. */
568 gimple
*vectorized_stmt
;
571 /** The following is relevant only for stmts that contain a non-scalar
572 data-ref (array/pointer/struct access). A GIMPLE stmt is expected to have
573 at most one such data-ref. **/
575 /* Information about the data-ref (access function, etc),
576 relative to the inner-most containing loop. */
577 struct data_reference
*data_ref_info
;
579 /* Information about the data-ref relative to this loop
580 nest (the loop that is being considered for vectorization). */
581 tree dr_base_address
;
587 /* For loop PHI nodes, the base and evolution part of it. This makes sure
588 this information is still available in vect_update_ivs_after_vectorizer
589 where we may not be able to re-analyze the PHI nodes evolution as
590 peeling for the prologue loop can make it unanalyzable. The evolution
591 part is still correct after peeling, but the base may have changed from
593 tree loop_phi_evolution_base_unchanged
;
594 tree loop_phi_evolution_part
;
596 /* Used for various bookkeeping purposes, generally holding a pointer to
597 some other stmt S that is in some way "related" to this stmt.
598 Current use of this field is:
599 If this stmt is part of a pattern (i.e. the field 'in_pattern_p' is
600 true): S is the "pattern stmt" that represents (and replaces) the
601 sequence of stmts that constitutes the pattern. Similarly, the
602 related_stmt of the "pattern stmt" points back to this stmt (which is
603 the last stmt in the original sequence of stmts that constitutes the
605 gimple
*related_stmt
;
607 /* Used to keep a sequence of def stmts of a pattern stmt if such exists. */
608 gimple_seq pattern_def_seq
;
610 /* List of datarefs that are known to have the same alignment as the dataref
612 vec
<dr_p
> same_align_refs
;
614 /* Selected SIMD clone's function info. First vector element
615 is SIMD clone's function decl, followed by a pair of trees (base + step)
616 for linear arguments (pair of NULLs for other arguments). */
617 vec
<tree
> simd_clone_info
;
619 /* Classify the def of this stmt. */
620 enum vect_def_type def_type
;
622 /* Whether the stmt is SLPed, loop-based vectorized, or both. */
623 enum slp_vect_type slp_type
;
625 /* Interleaving and reduction chains info. */
626 /* First element in the group. */
627 gimple
*first_element
;
628 /* Pointer to the next element in the group. */
629 gimple
*next_element
;
630 /* For data-refs, in case that two or more stmts share data-ref, this is the
631 pointer to the previously detected stmt with the same dr. */
632 gimple
*same_dr_stmt
;
633 /* The size of the group. */
635 /* For stores, number of stores from this group seen. We vectorize the last
637 unsigned int store_count
;
638 /* For loads only, the gap from the previous load. For consecutive loads, GAP
642 /* The minimum negative dependence distance this stmt participates in
644 unsigned int min_neg_dist
;
646 /* Not all stmts in the loop need to be vectorized. e.g, the increment
647 of the loop induction variable and computation of array indexes. relevant
648 indicates whether the stmt needs to be vectorized. */
649 enum vect_relevant relevant
;
651 /* Is this statement vectorizable or should it be skipped in (partial)
655 /* For loads if this is a gather, for stores if this is a scatter. */
656 bool gather_scatter_p
;
658 /* True if this is an access with loop-invariant stride. */
661 /* Classifies how the load or store is going to be implemented
662 for loop vectorization. */
663 vect_memory_access_type memory_access_type
;
665 /* For both loads and stores. */
666 bool simd_lane_access_p
;
668 /* For reduction loops, this is the type of reduction. */
669 enum vect_reduction_type v_reduc_type
;
671 /* For CONST_COND_REDUCTION, record the reduc code. */
672 enum tree_code const_cond_reduc_code
;
674 /* The number of scalar stmt references from active SLP instances. */
675 unsigned int num_slp_uses
;
678 /* Information about a gather/scatter call. */
679 struct gather_scatter_info
{
680 /* The FUNCTION_DECL for the built-in gather/scatter function. */
683 /* The loop-invariant base value. */
686 /* The original scalar offset, which is a non-loop-invariant SSA_NAME. */
689 /* Each offset element should be multiplied by this amount before
690 being added to the base. */
693 /* The definition type for the vectorized offset. */
694 enum vect_def_type offset_dt
;
696 /* The type of the vectorized offset. */
700 /* Access Functions. */
701 #define STMT_VINFO_TYPE(S) (S)->type
702 #define STMT_VINFO_STMT(S) (S)->stmt
704 STMT_VINFO_LOOP_VINFO (stmt_vec_info stmt_vinfo
)
706 if (loop_vec_info loop_vinfo
= dyn_cast
<loop_vec_info
> (stmt_vinfo
->vinfo
))
711 STMT_VINFO_BB_VINFO (stmt_vec_info stmt_vinfo
)
713 if (bb_vec_info bb_vinfo
= dyn_cast
<bb_vec_info
> (stmt_vinfo
->vinfo
))
717 #define STMT_VINFO_RELEVANT(S) (S)->relevant
718 #define STMT_VINFO_LIVE_P(S) (S)->live
719 #define STMT_VINFO_VECTYPE(S) (S)->vectype
720 #define STMT_VINFO_VEC_STMT(S) (S)->vectorized_stmt
721 #define STMT_VINFO_VECTORIZABLE(S) (S)->vectorizable
722 #define STMT_VINFO_DATA_REF(S) (S)->data_ref_info
723 #define STMT_VINFO_GATHER_SCATTER_P(S) (S)->gather_scatter_p
724 #define STMT_VINFO_STRIDED_P(S) (S)->strided_p
725 #define STMT_VINFO_MEMORY_ACCESS_TYPE(S) (S)->memory_access_type
726 #define STMT_VINFO_SIMD_LANE_ACCESS_P(S) (S)->simd_lane_access_p
727 #define STMT_VINFO_VEC_REDUCTION_TYPE(S) (S)->v_reduc_type
728 #define STMT_VINFO_VEC_CONST_COND_REDUC_CODE(S) (S)->const_cond_reduc_code
730 #define STMT_VINFO_DR_BASE_ADDRESS(S) (S)->dr_base_address
731 #define STMT_VINFO_DR_INIT(S) (S)->dr_init
732 #define STMT_VINFO_DR_OFFSET(S) (S)->dr_offset
733 #define STMT_VINFO_DR_STEP(S) (S)->dr_step
734 #define STMT_VINFO_DR_ALIGNED_TO(S) (S)->dr_aligned_to
736 #define STMT_VINFO_IN_PATTERN_P(S) (S)->in_pattern_p
737 #define STMT_VINFO_RELATED_STMT(S) (S)->related_stmt
738 #define STMT_VINFO_PATTERN_DEF_SEQ(S) (S)->pattern_def_seq
739 #define STMT_VINFO_SAME_ALIGN_REFS(S) (S)->same_align_refs
740 #define STMT_VINFO_SIMD_CLONE_INFO(S) (S)->simd_clone_info
741 #define STMT_VINFO_DEF_TYPE(S) (S)->def_type
742 #define STMT_VINFO_GROUP_FIRST_ELEMENT(S) (S)->first_element
743 #define STMT_VINFO_GROUP_NEXT_ELEMENT(S) (S)->next_element
744 #define STMT_VINFO_GROUP_SIZE(S) (S)->size
745 #define STMT_VINFO_GROUP_STORE_COUNT(S) (S)->store_count
746 #define STMT_VINFO_GROUP_GAP(S) (S)->gap
747 #define STMT_VINFO_GROUP_SAME_DR_STMT(S) (S)->same_dr_stmt
748 #define STMT_VINFO_GROUPED_ACCESS(S) ((S)->first_element != NULL && (S)->data_ref_info)
749 #define STMT_VINFO_LOOP_PHI_EVOLUTION_BASE_UNCHANGED(S) (S)->loop_phi_evolution_base_unchanged
750 #define STMT_VINFO_LOOP_PHI_EVOLUTION_PART(S) (S)->loop_phi_evolution_part
751 #define STMT_VINFO_MIN_NEG_DIST(S) (S)->min_neg_dist
752 #define STMT_VINFO_NUM_SLP_USES(S) (S)->num_slp_uses
754 #define GROUP_FIRST_ELEMENT(S) (S)->first_element
755 #define GROUP_NEXT_ELEMENT(S) (S)->next_element
756 #define GROUP_SIZE(S) (S)->size
757 #define GROUP_STORE_COUNT(S) (S)->store_count
758 #define GROUP_GAP(S) (S)->gap
759 #define GROUP_SAME_DR_STMT(S) (S)->same_dr_stmt
761 #define STMT_VINFO_RELEVANT_P(S) ((S)->relevant != vect_unused_in_scope)
763 #define HYBRID_SLP_STMT(S) ((S)->slp_type == hybrid)
764 #define PURE_SLP_STMT(S) ((S)->slp_type == pure_slp)
765 #define STMT_SLP_TYPE(S) (S)->slp_type
769 /* If true the alignment of base_decl needs to be increased. */
770 bool base_misaligned
;
771 /* If true we know the base is at least vector element alignment aligned. */
772 bool base_element_aligned
;
776 #define DR_VECT_AUX(dr) ((dataref_aux *)(dr)->aux)
778 #define VECT_MAX_COST 1000
780 /* The maximum number of intermediate steps required in multi-step type
782 #define MAX_INTERM_CVT_STEPS 3
784 /* The maximum vectorization factor supported by any target (V64QI). */
785 #define MAX_VECTORIZATION_FACTOR 64
787 extern vec
<stmt_vec_info
> stmt_vec_info_vec
;
789 void init_stmt_vec_info_vec (void);
790 void free_stmt_vec_info_vec (void);
792 /* Return a stmt_vec_info corresponding to STMT. */
794 static inline stmt_vec_info
795 vinfo_for_stmt (gimple
*stmt
)
797 unsigned int uid
= gimple_uid (stmt
);
801 return stmt_vec_info_vec
[uid
- 1];
804 /* Set vectorizer information INFO for STMT. */
807 set_vinfo_for_stmt (gimple
*stmt
, stmt_vec_info info
)
809 unsigned int uid
= gimple_uid (stmt
);
812 gcc_checking_assert (info
);
813 uid
= stmt_vec_info_vec
.length () + 1;
814 gimple_set_uid (stmt
, uid
);
815 stmt_vec_info_vec
.safe_push (info
);
819 gcc_checking_assert (info
== NULL
);
820 stmt_vec_info_vec
[uid
- 1] = info
;
824 /* Return the earlier statement between STMT1 and STMT2. */
826 static inline gimple
*
827 get_earlier_stmt (gimple
*stmt1
, gimple
*stmt2
)
829 unsigned int uid1
, uid2
;
837 uid1
= gimple_uid (stmt1
);
838 uid2
= gimple_uid (stmt2
);
840 if (uid1
== 0 || uid2
== 0)
843 gcc_checking_assert (uid1
<= stmt_vec_info_vec
.length ()
844 && uid2
<= stmt_vec_info_vec
.length ());
852 /* Return the later statement between STMT1 and STMT2. */
854 static inline gimple
*
855 get_later_stmt (gimple
*stmt1
, gimple
*stmt2
)
857 unsigned int uid1
, uid2
;
865 uid1
= gimple_uid (stmt1
);
866 uid2
= gimple_uid (stmt2
);
868 if (uid1
== 0 || uid2
== 0)
871 gcc_assert (uid1
<= stmt_vec_info_vec
.length ());
872 gcc_assert (uid2
<= stmt_vec_info_vec
.length ());
880 /* Return TRUE if a statement represented by STMT_INFO is a part of a
884 is_pattern_stmt_p (stmt_vec_info stmt_info
)
886 gimple
*related_stmt
;
887 stmt_vec_info related_stmt_info
;
889 related_stmt
= STMT_VINFO_RELATED_STMT (stmt_info
);
891 && (related_stmt_info
= vinfo_for_stmt (related_stmt
))
892 && STMT_VINFO_IN_PATTERN_P (related_stmt_info
))
898 /* Return true if BB is a loop header. */
901 is_loop_header_bb_p (basic_block bb
)
903 if (bb
== (bb
->loop_father
)->header
)
905 gcc_checking_assert (EDGE_COUNT (bb
->preds
) == 1);
909 /* Return pow2 (X). */
916 for (i
= 0; i
< x
; i
++)
922 /* Alias targetm.vectorize.builtin_vectorization_cost. */
925 builtin_vectorization_cost (enum vect_cost_for_stmt type_of_cost
,
926 tree vectype
, int misalign
)
928 return targetm
.vectorize
.builtin_vectorization_cost (type_of_cost
,
932 /* Get cost by calling cost target builtin. */
935 int vect_get_stmt_cost (enum vect_cost_for_stmt type_of_cost
)
937 return builtin_vectorization_cost (type_of_cost
, NULL
, 0);
940 /* Alias targetm.vectorize.init_cost. */
943 init_cost (struct loop
*loop_info
)
945 return targetm
.vectorize
.init_cost (loop_info
);
948 /* Alias targetm.vectorize.add_stmt_cost. */
950 static inline unsigned
951 add_stmt_cost (void *data
, int count
, enum vect_cost_for_stmt kind
,
952 stmt_vec_info stmt_info
, int misalign
,
953 enum vect_cost_model_location where
)
955 return targetm
.vectorize
.add_stmt_cost (data
, count
, kind
,
956 stmt_info
, misalign
, where
);
959 /* Alias targetm.vectorize.finish_cost. */
962 finish_cost (void *data
, unsigned *prologue_cost
,
963 unsigned *body_cost
, unsigned *epilogue_cost
)
965 targetm
.vectorize
.finish_cost (data
, prologue_cost
, body_cost
, epilogue_cost
);
968 /* Alias targetm.vectorize.destroy_cost_data. */
971 destroy_cost_data (void *data
)
973 targetm
.vectorize
.destroy_cost_data (data
);
976 /*-----------------------------------------------------------------*/
977 /* Info on data references alignment. */
978 /*-----------------------------------------------------------------*/
980 set_dr_misalignment (struct data_reference
*dr
, int val
)
982 dataref_aux
*data_aux
= DR_VECT_AUX (dr
);
986 data_aux
= XCNEW (dataref_aux
);
990 data_aux
->misalignment
= val
;
994 dr_misalignment (struct data_reference
*dr
)
996 return DR_VECT_AUX (dr
)->misalignment
;
999 /* Reflects actual alignment of first access in the vectorized loop,
1000 taking into account peeling/versioning if applied. */
1001 #define DR_MISALIGNMENT(DR) dr_misalignment (DR)
1002 #define SET_DR_MISALIGNMENT(DR, VAL) set_dr_misalignment (DR, VAL)
1004 /* Return TRUE if the data access is aligned, and FALSE otherwise. */
1007 aligned_access_p (struct data_reference
*data_ref_info
)
1009 return (DR_MISALIGNMENT (data_ref_info
) == 0);
1012 /* Return TRUE if the alignment of the data access is known, and FALSE
1016 known_alignment_for_access_p (struct data_reference
*data_ref_info
)
1018 return (DR_MISALIGNMENT (data_ref_info
) != -1);
1022 /* Return true if the vect cost model is unlimited. */
1024 unlimited_cost_model (loop_p loop
)
1026 if (loop
!= NULL
&& loop
->force_vectorize
1027 && flag_simd_cost_model
!= VECT_COST_MODEL_DEFAULT
)
1028 return flag_simd_cost_model
== VECT_COST_MODEL_UNLIMITED
;
1029 return (flag_vect_cost_model
== VECT_COST_MODEL_UNLIMITED
);
1032 /* Source location */
1033 extern source_location vect_location
;
1035 /*-----------------------------------------------------------------*/
1036 /* Function prototypes. */
1037 /*-----------------------------------------------------------------*/
1039 /* Simple loop peeling and versioning utilities for vectorizer's purposes -
1040 in tree-vect-loop-manip.c. */
1041 extern void slpeel_make_loop_iterate_ntimes (struct loop
*, tree
);
1042 extern bool slpeel_can_duplicate_loop_p (const struct loop
*, const_edge
);
1043 struct loop
*slpeel_tree_duplicate_loop_to_edge_cfg (struct loop
*,
1044 struct loop
*, edge
);
1045 extern void vect_loop_versioning (loop_vec_info
, unsigned int, bool);
1046 extern struct loop
*vect_do_peeling (loop_vec_info
, tree
, tree
,
1047 tree
*, int, bool, bool);
1048 extern source_location
find_loop_location (struct loop
*);
1049 extern bool vect_can_advance_ivs_p (loop_vec_info
);
1051 /* In tree-vect-stmts.c. */
1052 extern unsigned int current_vector_size
;
1053 extern tree
get_vectype_for_scalar_type (tree
);
1054 extern tree
get_mask_type_for_scalar_type (tree
);
1055 extern tree
get_same_sized_vectype (tree
, tree
);
1056 extern bool vect_is_simple_use (tree
, vec_info
*, gimple
**,
1057 enum vect_def_type
*);
1058 extern bool vect_is_simple_use (tree
, vec_info
*, gimple
**,
1059 enum vect_def_type
*, tree
*);
1060 extern bool supportable_widening_operation (enum tree_code
, gimple
*, tree
,
1061 tree
, enum tree_code
*,
1062 enum tree_code
*, int *,
1064 extern bool supportable_narrowing_operation (enum tree_code
, tree
, tree
,
1066 int *, vec
<tree
> *);
1067 extern stmt_vec_info
new_stmt_vec_info (gimple
*stmt
, vec_info
*);
1068 extern void free_stmt_vec_info (gimple
*stmt
);
1069 extern void vect_model_simple_cost (stmt_vec_info
, int, enum vect_def_type
*,
1070 stmt_vector_for_cost
*,
1071 stmt_vector_for_cost
*);
1072 extern void vect_model_store_cost (stmt_vec_info
, int, vect_memory_access_type
,
1073 enum vect_def_type
, slp_tree
,
1074 stmt_vector_for_cost
*,
1075 stmt_vector_for_cost
*);
1076 extern void vect_model_load_cost (stmt_vec_info
, int, vect_memory_access_type
,
1077 slp_tree
, stmt_vector_for_cost
*,
1078 stmt_vector_for_cost
*);
1079 extern unsigned record_stmt_cost (stmt_vector_for_cost
*, int,
1080 enum vect_cost_for_stmt
, stmt_vec_info
,
1081 int, enum vect_cost_model_location
);
1082 extern void vect_finish_stmt_generation (gimple
*, gimple
*,
1083 gimple_stmt_iterator
*);
1084 extern bool vect_mark_stmts_to_be_vectorized (loop_vec_info
);
1085 extern tree
vect_get_vec_def_for_operand_1 (gimple
*, enum vect_def_type
);
1086 extern tree
vect_get_vec_def_for_operand (tree
, gimple
*, tree
= NULL
);
1087 extern tree
vect_init_vector (gimple
*, tree
, tree
,
1088 gimple_stmt_iterator
*);
1089 extern tree
vect_get_vec_def_for_stmt_copy (enum vect_def_type
, tree
);
1090 extern bool vect_transform_stmt (gimple
*, gimple_stmt_iterator
*,
1091 bool *, slp_tree
, slp_instance
);
1092 extern void vect_remove_stores (gimple
*);
1093 extern bool vect_analyze_stmt (gimple
*, bool *, slp_tree
);
1094 extern bool vectorizable_condition (gimple
*, gimple_stmt_iterator
*,
1095 gimple
**, tree
, int, slp_tree
);
1096 extern void vect_get_load_cost (struct data_reference
*, int, bool,
1097 unsigned int *, unsigned int *,
1098 stmt_vector_for_cost
*,
1099 stmt_vector_for_cost
*, bool);
1100 extern void vect_get_store_cost (struct data_reference
*, int,
1101 unsigned int *, stmt_vector_for_cost
*);
1102 extern bool vect_supportable_shift (enum tree_code
, tree
);
1103 extern void vect_get_vec_defs (tree
, tree
, gimple
*, vec
<tree
> *,
1104 vec
<tree
> *, slp_tree
, int);
1105 extern tree
vect_gen_perm_mask_any (tree
, const unsigned char *);
1106 extern tree
vect_gen_perm_mask_checked (tree
, const unsigned char *);
1107 extern void optimize_mask_stores (struct loop
*);
1109 /* In tree-vect-data-refs.c. */
1110 extern bool vect_can_force_dr_alignment_p (const_tree
, unsigned int);
1111 extern enum dr_alignment_support vect_supportable_dr_alignment
1112 (struct data_reference
*, bool);
1113 extern tree
vect_get_smallest_scalar_type (gimple
*, HOST_WIDE_INT
*,
1115 extern bool vect_analyze_data_ref_dependences (loop_vec_info
, int *);
1116 extern bool vect_slp_analyze_instance_dependence (slp_instance
);
1117 extern bool vect_enhance_data_refs_alignment (loop_vec_info
);
1118 extern bool vect_analyze_data_refs_alignment (loop_vec_info
);
1119 extern bool vect_verify_datarefs_alignment (loop_vec_info
);
1120 extern bool vect_slp_analyze_and_verify_instance_alignment (slp_instance
);
1121 extern bool vect_analyze_data_ref_accesses (vec_info
*);
1122 extern bool vect_prune_runtime_alias_test_list (loop_vec_info
);
1123 extern bool vect_check_gather_scatter (gimple
*, loop_vec_info
,
1124 gather_scatter_info
*);
1125 extern bool vect_analyze_data_refs (vec_info
*, int *);
1126 extern tree
vect_create_data_ref_ptr (gimple
*, tree
, struct loop
*, tree
,
1127 tree
*, gimple_stmt_iterator
*,
1128 gimple
**, bool, bool *,
1130 extern tree
bump_vector_ptr (tree
, gimple
*, gimple_stmt_iterator
*, gimple
*,
1132 extern tree
vect_create_destination_var (tree
, tree
);
1133 extern bool vect_grouped_store_supported (tree
, unsigned HOST_WIDE_INT
);
1134 extern bool vect_store_lanes_supported (tree
, unsigned HOST_WIDE_INT
);
1135 extern bool vect_grouped_load_supported (tree
, bool, unsigned HOST_WIDE_INT
);
1136 extern bool vect_load_lanes_supported (tree
, unsigned HOST_WIDE_INT
);
1137 extern void vect_permute_store_chain (vec
<tree
> ,unsigned int, gimple
*,
1138 gimple_stmt_iterator
*, vec
<tree
> *);
1139 extern tree
vect_setup_realignment (gimple
*, gimple_stmt_iterator
*, tree
*,
1140 enum dr_alignment_support
, tree
,
1142 extern void vect_transform_grouped_load (gimple
*, vec
<tree
> , int,
1143 gimple_stmt_iterator
*);
1144 extern void vect_record_grouped_load_vectors (gimple
*, vec
<tree
> );
1145 extern tree
vect_get_new_vect_var (tree
, enum vect_var_kind
, const char *);
1146 extern tree
vect_get_new_ssa_name (tree
, enum vect_var_kind
,
1147 const char * = NULL
);
1148 extern tree
vect_create_addr_base_for_vector_ref (gimple
*, gimple_seq
*,
1149 tree
, struct loop
*,
1152 /* In tree-vect-loop.c. */
1153 /* FORNOW: Used in tree-parloops.c. */
1154 extern void destroy_loop_vec_info (loop_vec_info
, bool);
1155 extern gimple
*vect_force_simple_reduction (loop_vec_info
, gimple
*, bool,
1157 /* Drive for loop analysis stage. */
1158 extern loop_vec_info
vect_analyze_loop (struct loop
*, loop_vec_info
);
1159 extern tree
vect_build_loop_niters (loop_vec_info
);
1160 extern void vect_gen_vector_loop_niters (loop_vec_info
, tree
, tree
*, bool);
1161 /* Drive for loop transformation stage. */
1162 extern struct loop
*vect_transform_loop (loop_vec_info
);
1163 extern loop_vec_info
vect_analyze_loop_form (struct loop
*);
1164 extern bool vectorizable_live_operation (gimple
*, gimple_stmt_iterator
*,
1165 slp_tree
, int, gimple
**);
1166 extern bool vectorizable_reduction (gimple
*, gimple_stmt_iterator
*,
1167 gimple
**, slp_tree
);
1168 extern bool vectorizable_induction (gimple
*, gimple_stmt_iterator
*, gimple
**);
1169 extern tree
get_initial_def_for_reduction (gimple
*, tree
, tree
*);
1170 extern int vect_min_worthwhile_factor (enum tree_code
);
1171 extern int vect_get_known_peeling_cost (loop_vec_info
, int, int *,
1172 stmt_vector_for_cost
*,
1173 stmt_vector_for_cost
*,
1174 stmt_vector_for_cost
*);
1176 /* In tree-vect-slp.c. */
1177 extern void vect_free_slp_instance (slp_instance
);
1178 extern bool vect_transform_slp_perm_load (slp_tree
, vec
<tree
> ,
1179 gimple_stmt_iterator
*, int,
1180 slp_instance
, bool, unsigned *);
1181 extern bool vect_slp_analyze_operations (vec
<slp_instance
> slp_instances
,
1183 extern bool vect_schedule_slp (vec_info
*);
1184 extern bool vect_analyze_slp (vec_info
*, unsigned);
1185 extern bool vect_make_slp_decision (loop_vec_info
);
1186 extern void vect_detect_hybrid_slp (loop_vec_info
);
1187 extern void vect_get_slp_defs (vec
<tree
> , slp_tree
,
1188 vec
<vec
<tree
> > *, int);
1189 extern bool vect_slp_bb (basic_block
);
1190 extern gimple
*vect_find_last_scalar_stmt_in_slp (slp_tree
);
1191 extern bool is_simple_and_all_uses_invariant (gimple
*, loop_vec_info
);
1193 /* In tree-vect-patterns.c. */
1194 /* Pattern recognition functions.
1195 Additional pattern recognition functions can (and will) be added
1197 typedef gimple
*(* vect_recog_func_ptr
) (vec
<gimple
*> *, tree
*, tree
*);
1198 #define NUM_PATTERNS 14
1199 void vect_pattern_recog (vec_info
*);
1201 /* In tree-vectorizer.c. */
1202 unsigned vectorize_loops (void);
1203 void vect_destroy_datarefs (vec_info
*);
1204 bool vect_stmt_in_region_p (vec_info
*, gimple
*);
1205 void vect_free_loop_info_assumptions (struct loop
*);
1207 #endif /* GCC_TREE_VECTORIZER_H */