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
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. */
34 /* Defines type of operation. */
41 /* Define type of available alignment support. */
42 enum dr_alignment_support
{
43 dr_unaligned_unsupported
,
44 dr_unaligned_supported
,
46 dr_explicit_realign_optimized
,
50 /* Define type of def-use cross-iteration cycle. */
52 vect_uninitialized_def
= 0,
53 vect_constant_def
= 1,
58 vect_double_reduction_def
,
63 /* Define type of reduction. */
64 enum vect_reduction_type
{
69 #define VECTORIZABLE_CYCLE_DEF(D) (((D) == vect_reduction_def) \
70 || ((D) == vect_double_reduction_def) \
71 || ((D) == vect_nested_cycle))
73 /* Structure to encapsulate information about a group of like
74 instructions to be presented to the target cost model. */
75 struct stmt_info_for_cost
{
77 enum vect_cost_for_stmt kind
;
82 typedef vec
<stmt_info_for_cost
> stmt_vector_for_cost
;
84 /************************************************************************
86 ************************************************************************/
87 typedef struct _slp_tree
*slp_tree
;
89 /* A computation tree of an SLP instance. Each node corresponds to a group of
90 stmts to be packed in a SIMD stmt. */
92 /* Nodes that contain def-stmts of this node statements operands. */
93 vec
<slp_tree
> children
;
94 /* A group of scalar stmts to be vectorized together. */
96 /* Load permutation relative to the stores, NULL if there is no
98 vec
<unsigned> load_permutation
;
99 /* Vectorized stmt/s. */
100 vec
<gimple
*> vec_stmts
;
101 /* Number of vector stmts that are created to replace the group of scalar
102 stmts. It is calculated during the transformation phase as the number of
103 scalar elements in one scalar iteration (GROUP_SIZE) multiplied by VF
104 divided by vector size. */
105 unsigned int vec_stmts_size
;
106 /* Whether the scalar computations use two different operators. */
111 /* SLP instance is a sequence of stmts in a loop that can be packed into
113 typedef struct _slp_instance
{
114 /* The root of SLP tree. */
117 /* Size of groups of scalar stmts that will be replaced by SIMD stmt/s. */
118 unsigned int group_size
;
120 /* The unrolling factor required to vectorized this SLP instance. */
121 unsigned int unrolling_factor
;
123 /* The group of nodes that contain loads of this SLP instance. */
128 /* Access Functions. */
129 #define SLP_INSTANCE_TREE(S) (S)->root
130 #define SLP_INSTANCE_GROUP_SIZE(S) (S)->group_size
131 #define SLP_INSTANCE_UNROLLING_FACTOR(S) (S)->unrolling_factor
132 #define SLP_INSTANCE_LOADS(S) (S)->loads
134 #define SLP_TREE_CHILDREN(S) (S)->children
135 #define SLP_TREE_SCALAR_STMTS(S) (S)->stmts
136 #define SLP_TREE_VEC_STMTS(S) (S)->vec_stmts
137 #define SLP_TREE_NUMBER_OF_VEC_STMTS(S) (S)->vec_stmts_size
138 #define SLP_TREE_LOAD_PERMUTATION(S) (S)->load_permutation
139 #define SLP_TREE_TWO_OPERATORS(S) (S)->two_operators
143 /* This struct is used to store the information of a data reference,
144 including the data ref itself, the access offset (calculated by summing its
145 offset and init) and the segment length for aliasing checks.
146 This is used to merge alias checks. */
148 struct dr_with_seg_len
150 dr_with_seg_len (data_reference_p d
, tree len
)
152 offset (size_binop (PLUS_EXPR
, DR_OFFSET (d
), DR_INIT (d
))),
160 /* This struct contains two dr_with_seg_len objects with aliasing data
161 refs. Two comparisons are generated from them. */
163 struct dr_with_seg_len_pair_t
165 dr_with_seg_len_pair_t (const dr_with_seg_len
& d1
,
166 const dr_with_seg_len
& d2
)
167 : first (d1
), second (d2
) {}
169 dr_with_seg_len first
;
170 dr_with_seg_len second
;
175 /* Vectorizer state common between loop and basic-block vectorization. */
177 enum { bb
, loop
} kind
;
179 /* All SLP instances. */
180 vec
<slp_instance
> slp_instances
;
182 /* All data references. */
183 vec
<data_reference_p
> datarefs
;
185 /* All data dependences. */
188 /* All interleaving chains of stores, represented by the first
189 stmt in the chain. */
190 vec
<gimple
*> grouped_stores
;
192 /* Cost data used by the target cost model. */
193 void *target_cost_data
;
196 struct _loop_vec_info
;
202 is_a_helper
<_loop_vec_info
*>::test (vec_info
*i
)
204 return i
->kind
== vec_info::loop
;
210 is_a_helper
<_bb_vec_info
*>::test (vec_info
*i
)
212 return i
->kind
== vec_info::bb
;
216 /*-----------------------------------------------------------------*/
217 /* Info on vectorized loops. */
218 /*-----------------------------------------------------------------*/
219 typedef struct _loop_vec_info
: public vec_info
{
221 /* The loop to which this info struct refers to. */
224 /* The loop basic blocks. */
227 /* Number of latch executions. */
229 /* Number of iterations. */
231 /* Number of iterations of the original loop. */
232 tree num_iters_unchanged
;
234 /* Threshold of number of iterations below which vectorzation will not be
235 performed. It is calculated from MIN_PROFITABLE_ITERS and
236 PARAM_MIN_VECT_LOOP_BOUND. */
239 /* Is the loop vectorizable? */
242 /* Unrolling factor */
243 int vectorization_factor
;
245 /* Unknown DRs according to which loop was peeled. */
246 struct data_reference
*unaligned_dr
;
248 /* peeling_for_alignment indicates whether peeling for alignment will take
249 place, and what the peeling factor should be:
250 peeling_for_alignment = X means:
251 If X=0: Peeling for alignment will not be applied.
252 If X>0: Peel first X iterations.
253 If X=-1: Generate a runtime test to calculate the number of iterations
254 to be peeled, using the dataref recorded in the field
256 int peeling_for_alignment
;
258 /* The mask used to check the alignment of pointers or arrays. */
261 /* The loop nest in which the data dependences are computed. */
262 vec
<loop_p
> loop_nest
;
264 /* Data Dependence Relations defining address ranges that are candidates
265 for a run-time aliasing check. */
266 vec
<ddr_p
> may_alias_ddrs
;
268 /* Data Dependence Relations defining address ranges together with segment
269 lengths from which the run-time aliasing check is built. */
270 vec
<dr_with_seg_len_pair_t
> comp_alias_ddrs
;
272 /* Statements in the loop that have data references that are candidates for a
273 runtime (loop versioning) misalignment check. */
274 vec
<gimple
*> may_misalign_stmts
;
276 /* The unrolling factor needed to SLP the loop. In case of that pure SLP is
277 applied to the loop, i.e., no unrolling is needed, this is 1. */
278 unsigned slp_unrolling_factor
;
280 /* Reduction cycles detected in the loop. Used in loop-aware SLP. */
281 vec
<gimple
*> reductions
;
283 /* All reduction chains in the loop, represented by the first
284 stmt in the chain. */
285 vec
<gimple
*> reduction_chains
;
287 /* Cost vector for a single scalar iteration. */
288 vec
<stmt_info_for_cost
> scalar_cost_vec
;
290 /* Cost of a single scalar iteration. */
291 int single_scalar_iteration_cost
;
293 /* When we have grouped data accesses with gaps, we may introduce invalid
294 memory accesses. We peel the last iteration of the loop to prevent
296 bool peeling_for_gaps
;
298 /* When the number of iterations is not a multiple of the vector size
299 we need to peel off iterations at the end to form an epilogue loop. */
300 bool peeling_for_niter
;
302 /* Reductions are canonicalized so that the last operand is the reduction
303 operand. If this places a constant into RHS1, this decanonicalizes
304 GIMPLE for other phases, so we must track when this has occurred and
306 bool operands_swapped
;
308 /* True if there are no loop carried data dependencies in the loop.
309 If loop->safelen <= 1, then this is always true, either the loop
310 didn't have any loop carried data dependencies, or the loop is being
311 vectorized guarded with some runtime alias checks, or couldn't
312 be vectorized at all, but then this field shouldn't be used.
313 For loop->safelen >= 2, the user has asserted that there are no
314 backward dependencies, but there still could be loop carried forward
315 dependencies in such loops. This flag will be false if normal
316 vectorizer data dependency analysis would fail or require versioning
317 for alias, but because of loop->safelen >= 2 it has been vectorized
318 even without versioning for alias. E.g. in:
320 for (int i = 0; i < m; i++)
322 (or #pragma simd or #pragma ivdep) we can vectorize this and it will
323 DTRT even for k > 0 && k < m, but without safelen we would not
324 vectorize this, so this field would be false. */
325 bool no_data_dependencies
;
327 /* If if-conversion versioned this loop before conversion, this is the
328 loop version without if-conversion. */
329 struct loop
*scalar_loop
;
333 /* Access Functions. */
334 #define LOOP_VINFO_LOOP(L) (L)->loop
335 #define LOOP_VINFO_BBS(L) (L)->bbs
336 #define LOOP_VINFO_NITERSM1(L) (L)->num_itersm1
337 #define LOOP_VINFO_NITERS(L) (L)->num_iters
338 /* Since LOOP_VINFO_NITERS and LOOP_VINFO_NITERSM1 can change after
339 prologue peeling retain total unchanged scalar loop iterations for
341 #define LOOP_VINFO_NITERS_UNCHANGED(L) (L)->num_iters_unchanged
342 #define LOOP_VINFO_COST_MODEL_THRESHOLD(L) (L)->th
343 #define LOOP_VINFO_VECTORIZABLE_P(L) (L)->vectorizable
344 #define LOOP_VINFO_VECT_FACTOR(L) (L)->vectorization_factor
345 #define LOOP_VINFO_PTR_MASK(L) (L)->ptr_mask
346 #define LOOP_VINFO_LOOP_NEST(L) (L)->loop_nest
347 #define LOOP_VINFO_DATAREFS(L) (L)->datarefs
348 #define LOOP_VINFO_DDRS(L) (L)->ddrs
349 #define LOOP_VINFO_INT_NITERS(L) (TREE_INT_CST_LOW ((L)->num_iters))
350 #define LOOP_VINFO_PEELING_FOR_ALIGNMENT(L) (L)->peeling_for_alignment
351 #define LOOP_VINFO_UNALIGNED_DR(L) (L)->unaligned_dr
352 #define LOOP_VINFO_MAY_MISALIGN_STMTS(L) (L)->may_misalign_stmts
353 #define LOOP_VINFO_MAY_ALIAS_DDRS(L) (L)->may_alias_ddrs
354 #define LOOP_VINFO_COMP_ALIAS_DDRS(L) (L)->comp_alias_ddrs
355 #define LOOP_VINFO_GROUPED_STORES(L) (L)->grouped_stores
356 #define LOOP_VINFO_SLP_INSTANCES(L) (L)->slp_instances
357 #define LOOP_VINFO_SLP_UNROLLING_FACTOR(L) (L)->slp_unrolling_factor
358 #define LOOP_VINFO_REDUCTIONS(L) (L)->reductions
359 #define LOOP_VINFO_REDUCTION_CHAINS(L) (L)->reduction_chains
360 #define LOOP_VINFO_TARGET_COST_DATA(L) (L)->target_cost_data
361 #define LOOP_VINFO_PEELING_FOR_GAPS(L) (L)->peeling_for_gaps
362 #define LOOP_VINFO_OPERANDS_SWAPPED(L) (L)->operands_swapped
363 #define LOOP_VINFO_PEELING_FOR_NITER(L) (L)->peeling_for_niter
364 #define LOOP_VINFO_NO_DATA_DEPENDENCIES(L) (L)->no_data_dependencies
365 #define LOOP_VINFO_SCALAR_LOOP(L) (L)->scalar_loop
366 #define LOOP_VINFO_SCALAR_ITERATION_COST(L) (L)->scalar_cost_vec
367 #define LOOP_VINFO_SINGLE_SCALAR_ITERATION_COST(L) (L)->single_scalar_iteration_cost
369 #define LOOP_REQUIRES_VERSIONING_FOR_ALIGNMENT(L) \
370 ((L)->may_misalign_stmts.length () > 0)
371 #define LOOP_REQUIRES_VERSIONING_FOR_ALIAS(L) \
372 ((L)->may_alias_ddrs.length () > 0)
374 #define LOOP_VINFO_NITERS_KNOWN_P(L) \
375 (tree_fits_shwi_p ((L)->num_iters) && tree_to_shwi ((L)->num_iters) > 0)
377 static inline loop_vec_info
378 loop_vec_info_for_loop (struct loop
*loop
)
380 return (loop_vec_info
) loop
->aux
;
384 nested_in_vect_loop_p (struct loop
*loop
, gimple
*stmt
)
387 && (loop
->inner
== (gimple_bb (stmt
))->loop_father
));
390 typedef struct _bb_vec_info
: public vec_info
395 #define BB_VINFO_BB(B) (B)->bb
396 #define BB_VINFO_GROUPED_STORES(B) (B)->grouped_stores
397 #define BB_VINFO_SLP_INSTANCES(B) (B)->slp_instances
398 #define BB_VINFO_DATAREFS(B) (B)->datarefs
399 #define BB_VINFO_DDRS(B) (B)->ddrs
400 #define BB_VINFO_TARGET_COST_DATA(B) (B)->target_cost_data
402 static inline bb_vec_info
403 vec_info_for_bb (basic_block bb
)
405 return (bb_vec_info
) bb
->aux
;
408 /*-----------------------------------------------------------------*/
409 /* Info on vectorized defs. */
410 /*-----------------------------------------------------------------*/
411 enum stmt_vec_info_type
{
412 undef_vec_info_type
= 0,
418 call_simd_clone_vec_info_type
,
419 assignment_vec_info_type
,
420 condition_vec_info_type
,
423 type_promotion_vec_info_type
,
424 type_demotion_vec_info_type
,
425 type_conversion_vec_info_type
,
426 loop_exit_ctrl_vec_info_type
429 /* Indicates whether/how a variable is used in the scope of loop/basic
432 vect_unused_in_scope
= 0,
433 /* The def is in the inner loop, and the use is in the outer loop, and the
434 use is a reduction stmt. */
435 vect_used_in_outer_by_reduction
,
436 /* The def is in the inner loop, and the use is in the outer loop (and is
437 not part of reduction). */
440 /* defs that feed computations that end up (only) in a reduction. These
441 defs may be used by non-reduction stmts, but eventually, any
442 computations/values that are affected by these defs are used to compute
443 a reduction (i.e. don't get stored to memory, for example). We use this
444 to identify computations that we can change the order in which they are
446 vect_used_by_reduction
,
451 /* The type of vectorization that can be applied to the stmt: regular loop-based
452 vectorization; pure SLP - the stmt is a part of SLP instances and does not
453 have uses outside SLP instances; or hybrid SLP and loop-based - the stmt is
454 a part of SLP instance and also must be loop-based vectorized, since it has
455 uses outside SLP sequences.
457 In the loop context the meanings of pure and hybrid SLP are slightly
458 different. By saying that pure SLP is applied to the loop, we mean that we
459 exploit only intra-iteration parallelism in the loop; i.e., the loop can be
460 vectorized without doing any conceptual unrolling, cause we don't pack
461 together stmts from different iterations, only within a single iteration.
462 Loop hybrid SLP means that we exploit both intra-iteration and
463 inter-iteration parallelism (e.g., number of elements in the vector is 4
464 and the slp-group-size is 2, in which case we don't have enough parallelism
465 within an iteration, so we obtain the rest of the parallelism from subsequent
466 iterations by unrolling the loop by 2). */
474 typedef struct data_reference
*dr_p
;
476 typedef struct _stmt_vec_info
{
478 enum stmt_vec_info_type type
;
480 /* Indicates whether this stmts is part of a computation whose result is
481 used outside the loop. */
484 /* Stmt is part of some pattern (computation idiom) */
487 /* The stmt to which this info struct refers to. */
490 /* The vec_info with respect to which STMT is vectorized. */
493 /* The vector type to be used for the LHS of this statement. */
496 /* The vectorized version of the stmt. */
497 gimple
*vectorized_stmt
;
500 /** The following is relevant only for stmts that contain a non-scalar
501 data-ref (array/pointer/struct access). A GIMPLE stmt is expected to have
502 at most one such data-ref. **/
504 /* Information about the data-ref (access function, etc),
505 relative to the inner-most containing loop. */
506 struct data_reference
*data_ref_info
;
508 /* Information about the data-ref relative to this loop
509 nest (the loop that is being considered for vectorization). */
510 tree dr_base_address
;
516 /* For loop PHI nodes, the evolution part of it. This makes sure
517 this information is still available in vect_update_ivs_after_vectorizer
518 where we may not be able to re-analyze the PHI nodes evolution as
519 peeling for the prologue loop can make it unanalyzable. The evolution
520 part is still correct though. */
521 tree loop_phi_evolution_part
;
523 /* Used for various bookkeeping purposes, generally holding a pointer to
524 some other stmt S that is in some way "related" to this stmt.
525 Current use of this field is:
526 If this stmt is part of a pattern (i.e. the field 'in_pattern_p' is
527 true): S is the "pattern stmt" that represents (and replaces) the
528 sequence of stmts that constitutes the pattern. Similarly, the
529 related_stmt of the "pattern stmt" points back to this stmt (which is
530 the last stmt in the original sequence of stmts that constitutes the
532 gimple
*related_stmt
;
534 /* Used to keep a sequence of def stmts of a pattern stmt if such exists. */
535 gimple_seq pattern_def_seq
;
537 /* List of datarefs that are known to have the same alignment as the dataref
539 vec
<dr_p
> same_align_refs
;
541 /* Selected SIMD clone's function info. First vector element
542 is SIMD clone's function decl, followed by a pair of trees (base + step)
543 for linear arguments (pair of NULLs for other arguments). */
544 vec
<tree
> simd_clone_info
;
546 /* Classify the def of this stmt. */
547 enum vect_def_type def_type
;
549 /* Whether the stmt is SLPed, loop-based vectorized, or both. */
550 enum slp_vect_type slp_type
;
552 /* Interleaving and reduction chains info. */
553 /* First element in the group. */
554 gimple
*first_element
;
555 /* Pointer to the next element in the group. */
556 gimple
*next_element
;
557 /* For data-refs, in case that two or more stmts share data-ref, this is the
558 pointer to the previously detected stmt with the same dr. */
559 gimple
*same_dr_stmt
;
560 /* The size of the group. */
562 /* For stores, number of stores from this group seen. We vectorize the last
564 unsigned int store_count
;
565 /* For loads only, the gap from the previous load. For consecutive loads, GAP
569 /* The minimum negative dependence distance this stmt participates in
571 unsigned int min_neg_dist
;
573 /* Not all stmts in the loop need to be vectorized. e.g, the increment
574 of the loop induction variable and computation of array indexes. relevant
575 indicates whether the stmt needs to be vectorized. */
576 enum vect_relevant relevant
;
578 /* Is this statement vectorizable or should it be skipped in (partial)
582 /* For loads if this is a gather, for stores if this is a scatter. */
583 bool gather_scatter_p
;
585 /* True if this is an access with loop-invariant stride. */
588 /* For both loads and stores. */
589 bool simd_lane_access_p
;
591 /* For reduction loops, this is the type of reduction. */
592 enum vect_reduction_type v_reduc_type
;
596 /* Access Functions. */
597 #define STMT_VINFO_TYPE(S) (S)->type
598 #define STMT_VINFO_STMT(S) (S)->stmt
600 STMT_VINFO_LOOP_VINFO (stmt_vec_info stmt_vinfo
)
602 if (loop_vec_info loop_vinfo
= dyn_cast
<loop_vec_info
> (stmt_vinfo
->vinfo
))
607 STMT_VINFO_BB_VINFO (stmt_vec_info stmt_vinfo
)
609 if (bb_vec_info bb_vinfo
= dyn_cast
<bb_vec_info
> (stmt_vinfo
->vinfo
))
613 #define STMT_VINFO_RELEVANT(S) (S)->relevant
614 #define STMT_VINFO_LIVE_P(S) (S)->live
615 #define STMT_VINFO_VECTYPE(S) (S)->vectype
616 #define STMT_VINFO_VEC_STMT(S) (S)->vectorized_stmt
617 #define STMT_VINFO_VECTORIZABLE(S) (S)->vectorizable
618 #define STMT_VINFO_DATA_REF(S) (S)->data_ref_info
619 #define STMT_VINFO_GATHER_SCATTER_P(S) (S)->gather_scatter_p
620 #define STMT_VINFO_STRIDED_P(S) (S)->strided_p
621 #define STMT_VINFO_SIMD_LANE_ACCESS_P(S) (S)->simd_lane_access_p
622 #define STMT_VINFO_VEC_REDUCTION_TYPE(S) (S)->v_reduc_type
624 #define STMT_VINFO_DR_BASE_ADDRESS(S) (S)->dr_base_address
625 #define STMT_VINFO_DR_INIT(S) (S)->dr_init
626 #define STMT_VINFO_DR_OFFSET(S) (S)->dr_offset
627 #define STMT_VINFO_DR_STEP(S) (S)->dr_step
628 #define STMT_VINFO_DR_ALIGNED_TO(S) (S)->dr_aligned_to
630 #define STMT_VINFO_IN_PATTERN_P(S) (S)->in_pattern_p
631 #define STMT_VINFO_RELATED_STMT(S) (S)->related_stmt
632 #define STMT_VINFO_PATTERN_DEF_SEQ(S) (S)->pattern_def_seq
633 #define STMT_VINFO_SAME_ALIGN_REFS(S) (S)->same_align_refs
634 #define STMT_VINFO_SIMD_CLONE_INFO(S) (S)->simd_clone_info
635 #define STMT_VINFO_DEF_TYPE(S) (S)->def_type
636 #define STMT_VINFO_GROUP_FIRST_ELEMENT(S) (S)->first_element
637 #define STMT_VINFO_GROUP_NEXT_ELEMENT(S) (S)->next_element
638 #define STMT_VINFO_GROUP_SIZE(S) (S)->size
639 #define STMT_VINFO_GROUP_STORE_COUNT(S) (S)->store_count
640 #define STMT_VINFO_GROUP_GAP(S) (S)->gap
641 #define STMT_VINFO_GROUP_SAME_DR_STMT(S) (S)->same_dr_stmt
642 #define STMT_VINFO_GROUPED_ACCESS(S) ((S)->first_element != NULL && (S)->data_ref_info)
643 #define STMT_VINFO_LOOP_PHI_EVOLUTION_PART(S) (S)->loop_phi_evolution_part
644 #define STMT_VINFO_MIN_NEG_DIST(S) (S)->min_neg_dist
646 #define GROUP_FIRST_ELEMENT(S) (S)->first_element
647 #define GROUP_NEXT_ELEMENT(S) (S)->next_element
648 #define GROUP_SIZE(S) (S)->size
649 #define GROUP_STORE_COUNT(S) (S)->store_count
650 #define GROUP_GAP(S) (S)->gap
651 #define GROUP_SAME_DR_STMT(S) (S)->same_dr_stmt
653 #define STMT_VINFO_RELEVANT_P(S) ((S)->relevant != vect_unused_in_scope)
655 #define HYBRID_SLP_STMT(S) ((S)->slp_type == hybrid)
656 #define PURE_SLP_STMT(S) ((S)->slp_type == pure_slp)
657 #define STMT_SLP_TYPE(S) (S)->slp_type
661 /* If true the alignment of base_decl needs to be increased. */
662 bool base_misaligned
;
663 /* If true we know the base is at least vector element alignment aligned. */
664 bool base_element_aligned
;
668 #define DR_VECT_AUX(dr) ((dataref_aux *)(dr)->aux)
670 #define VECT_MAX_COST 1000
672 /* The maximum number of intermediate steps required in multi-step type
674 #define MAX_INTERM_CVT_STEPS 3
676 /* The maximum vectorization factor supported by any target (V64QI). */
677 #define MAX_VECTORIZATION_FACTOR 64
679 extern vec
<stmt_vec_info
> stmt_vec_info_vec
;
681 void init_stmt_vec_info_vec (void);
682 void free_stmt_vec_info_vec (void);
684 /* Return a stmt_vec_info corresponding to STMT. */
686 static inline stmt_vec_info
687 vinfo_for_stmt (gimple
*stmt
)
689 unsigned int uid
= gimple_uid (stmt
);
693 return stmt_vec_info_vec
[uid
- 1];
696 /* Set vectorizer information INFO for STMT. */
699 set_vinfo_for_stmt (gimple
*stmt
, stmt_vec_info info
)
701 unsigned int uid
= gimple_uid (stmt
);
704 gcc_checking_assert (info
);
705 uid
= stmt_vec_info_vec
.length () + 1;
706 gimple_set_uid (stmt
, uid
);
707 stmt_vec_info_vec
.safe_push (info
);
710 stmt_vec_info_vec
[uid
- 1] = info
;
713 /* Return the earlier statement between STMT1 and STMT2. */
715 static inline gimple
*
716 get_earlier_stmt (gimple
*stmt1
, gimple
*stmt2
)
718 unsigned int uid1
, uid2
;
726 uid1
= gimple_uid (stmt1
);
727 uid2
= gimple_uid (stmt2
);
729 if (uid1
== 0 || uid2
== 0)
732 gcc_checking_assert (uid1
<= stmt_vec_info_vec
.length ()
733 && uid2
<= stmt_vec_info_vec
.length ());
741 /* Return the later statement between STMT1 and STMT2. */
743 static inline gimple
*
744 get_later_stmt (gimple
*stmt1
, gimple
*stmt2
)
746 unsigned int uid1
, uid2
;
754 uid1
= gimple_uid (stmt1
);
755 uid2
= gimple_uid (stmt2
);
757 if (uid1
== 0 || uid2
== 0)
760 gcc_assert (uid1
<= stmt_vec_info_vec
.length ());
761 gcc_assert (uid2
<= stmt_vec_info_vec
.length ());
769 /* Return TRUE if a statement represented by STMT_INFO is a part of a
773 is_pattern_stmt_p (stmt_vec_info stmt_info
)
775 gimple
*related_stmt
;
776 stmt_vec_info related_stmt_info
;
778 related_stmt
= STMT_VINFO_RELATED_STMT (stmt_info
);
780 && (related_stmt_info
= vinfo_for_stmt (related_stmt
))
781 && STMT_VINFO_IN_PATTERN_P (related_stmt_info
))
787 /* Return true if BB is a loop header. */
790 is_loop_header_bb_p (basic_block bb
)
792 if (bb
== (bb
->loop_father
)->header
)
794 gcc_checking_assert (EDGE_COUNT (bb
->preds
) == 1);
798 /* Return pow2 (X). */
805 for (i
= 0; i
< x
; i
++)
811 /* Alias targetm.vectorize.builtin_vectorization_cost. */
814 builtin_vectorization_cost (enum vect_cost_for_stmt type_of_cost
,
815 tree vectype
, int misalign
)
817 return targetm
.vectorize
.builtin_vectorization_cost (type_of_cost
,
821 /* Get cost by calling cost target builtin. */
824 int vect_get_stmt_cost (enum vect_cost_for_stmt type_of_cost
)
826 return builtin_vectorization_cost (type_of_cost
, NULL
, 0);
829 /* Alias targetm.vectorize.init_cost. */
832 init_cost (struct loop
*loop_info
)
834 return targetm
.vectorize
.init_cost (loop_info
);
837 /* Alias targetm.vectorize.add_stmt_cost. */
839 static inline unsigned
840 add_stmt_cost (void *data
, int count
, enum vect_cost_for_stmt kind
,
841 stmt_vec_info stmt_info
, int misalign
,
842 enum vect_cost_model_location where
)
844 return targetm
.vectorize
.add_stmt_cost (data
, count
, kind
,
845 stmt_info
, misalign
, where
);
848 /* Alias targetm.vectorize.finish_cost. */
851 finish_cost (void *data
, unsigned *prologue_cost
,
852 unsigned *body_cost
, unsigned *epilogue_cost
)
854 targetm
.vectorize
.finish_cost (data
, prologue_cost
, body_cost
, epilogue_cost
);
857 /* Alias targetm.vectorize.destroy_cost_data. */
860 destroy_cost_data (void *data
)
862 targetm
.vectorize
.destroy_cost_data (data
);
865 /*-----------------------------------------------------------------*/
866 /* Info on data references alignment. */
867 /*-----------------------------------------------------------------*/
869 set_dr_misalignment (struct data_reference
*dr
, int val
)
871 dataref_aux
*data_aux
= DR_VECT_AUX (dr
);
875 data_aux
= XCNEW (dataref_aux
);
879 data_aux
->misalignment
= val
;
883 dr_misalignment (struct data_reference
*dr
)
885 return DR_VECT_AUX (dr
)->misalignment
;
888 /* Reflects actual alignment of first access in the vectorized loop,
889 taking into account peeling/versioning if applied. */
890 #define DR_MISALIGNMENT(DR) dr_misalignment (DR)
891 #define SET_DR_MISALIGNMENT(DR, VAL) set_dr_misalignment (DR, VAL)
893 /* Return TRUE if the data access is aligned, and FALSE otherwise. */
896 aligned_access_p (struct data_reference
*data_ref_info
)
898 return (DR_MISALIGNMENT (data_ref_info
) == 0);
901 /* Return TRUE if the alignment of the data access is known, and FALSE
905 known_alignment_for_access_p (struct data_reference
*data_ref_info
)
907 return (DR_MISALIGNMENT (data_ref_info
) != -1);
911 /* Return true if the vect cost model is unlimited. */
913 unlimited_cost_model (loop_p loop
)
915 if (loop
!= NULL
&& loop
->force_vectorize
916 && flag_simd_cost_model
!= VECT_COST_MODEL_DEFAULT
)
917 return flag_simd_cost_model
== VECT_COST_MODEL_UNLIMITED
;
918 return (flag_vect_cost_model
== VECT_COST_MODEL_UNLIMITED
);
921 /* Source location */
922 extern source_location vect_location
;
924 /*-----------------------------------------------------------------*/
925 /* Function prototypes. */
926 /*-----------------------------------------------------------------*/
928 /* Simple loop peeling and versioning utilities for vectorizer's purposes -
929 in tree-vect-loop-manip.c. */
930 extern void slpeel_make_loop_iterate_ntimes (struct loop
*, tree
);
931 extern bool slpeel_can_duplicate_loop_p (const struct loop
*, const_edge
);
932 struct loop
*slpeel_tree_duplicate_loop_to_edge_cfg (struct loop
*,
933 struct loop
*, edge
);
934 extern void vect_loop_versioning (loop_vec_info
, unsigned int, bool);
935 extern void vect_do_peeling_for_loop_bound (loop_vec_info
, tree
, tree
,
937 extern void vect_do_peeling_for_alignment (loop_vec_info
, tree
,
939 extern source_location
find_loop_location (struct loop
*);
940 extern bool vect_can_advance_ivs_p (loop_vec_info
);
942 /* In tree-vect-stmts.c. */
943 extern unsigned int current_vector_size
;
944 extern tree
get_vectype_for_scalar_type (tree
);
945 extern tree
get_same_sized_vectype (tree
, tree
);
946 extern bool vect_is_simple_use (tree
, vec_info
*, gimple
**,
947 enum vect_def_type
*);
948 extern bool vect_is_simple_use (tree
, vec_info
*, gimple
**,
949 enum vect_def_type
*, tree
*);
950 extern bool supportable_widening_operation (enum tree_code
, gimple
*, tree
,
951 tree
, enum tree_code
*,
952 enum tree_code
*, int *,
954 extern bool supportable_narrowing_operation (enum tree_code
, tree
, tree
,
957 extern stmt_vec_info
new_stmt_vec_info (gimple
*stmt
, vec_info
*);
958 extern void free_stmt_vec_info (gimple
*stmt
);
959 extern tree
vectorizable_function (gcall
*, tree
, tree
);
960 extern void vect_model_simple_cost (stmt_vec_info
, int, enum vect_def_type
*,
961 stmt_vector_for_cost
*,
962 stmt_vector_for_cost
*);
963 extern void vect_model_store_cost (stmt_vec_info
, int, bool,
964 enum vect_def_type
, slp_tree
,
965 stmt_vector_for_cost
*,
966 stmt_vector_for_cost
*);
967 extern void vect_model_load_cost (stmt_vec_info
, int, bool, slp_tree
,
968 stmt_vector_for_cost
*,
969 stmt_vector_for_cost
*);
970 extern unsigned record_stmt_cost (stmt_vector_for_cost
*, int,
971 enum vect_cost_for_stmt
, stmt_vec_info
,
972 int, enum vect_cost_model_location
);
973 extern void vect_finish_stmt_generation (gimple
*, gimple
*,
974 gimple_stmt_iterator
*);
975 extern bool vect_mark_stmts_to_be_vectorized (loop_vec_info
);
976 extern tree
vect_get_vec_def_for_operand (tree
, gimple
*);
977 extern tree
vect_init_vector (gimple
*, tree
, tree
,
978 gimple_stmt_iterator
*);
979 extern tree
vect_get_vec_def_for_stmt_copy (enum vect_def_type
, tree
);
980 extern bool vect_transform_stmt (gimple
*, gimple_stmt_iterator
*,
981 bool *, slp_tree
, slp_instance
);
982 extern void vect_remove_stores (gimple
*);
983 extern bool vect_analyze_stmt (gimple
*, bool *, slp_tree
);
984 extern bool vectorizable_condition (gimple
*, gimple_stmt_iterator
*,
985 gimple
**, tree
, int, slp_tree
);
986 extern void vect_get_load_cost (struct data_reference
*, int, bool,
987 unsigned int *, unsigned int *,
988 stmt_vector_for_cost
*,
989 stmt_vector_for_cost
*, bool);
990 extern void vect_get_store_cost (struct data_reference
*, int,
991 unsigned int *, stmt_vector_for_cost
*);
992 extern bool vect_supportable_shift (enum tree_code
, tree
);
993 extern void vect_get_vec_defs (tree
, tree
, gimple
*, vec
<tree
> *,
994 vec
<tree
> *, slp_tree
, int);
995 extern tree
vect_gen_perm_mask_any (tree
, const unsigned char *);
996 extern tree
vect_gen_perm_mask_checked (tree
, const unsigned char *);
998 /* In tree-vect-data-refs.c. */
999 extern bool vect_can_force_dr_alignment_p (const_tree
, unsigned int);
1000 extern enum dr_alignment_support vect_supportable_dr_alignment
1001 (struct data_reference
*, bool);
1002 extern tree
vect_get_smallest_scalar_type (gimple
*, HOST_WIDE_INT
*,
1004 extern bool vect_analyze_data_ref_dependences (loop_vec_info
, int *);
1005 extern bool vect_slp_analyze_data_ref_dependences (bb_vec_info
);
1006 extern bool vect_enhance_data_refs_alignment (loop_vec_info
);
1007 extern bool vect_analyze_data_refs_alignment (vec_info
*);
1008 extern bool vect_verify_datarefs_alignment (vec_info
*);
1009 extern bool vect_analyze_data_ref_accesses (vec_info
*);
1010 extern bool vect_prune_runtime_alias_test_list (loop_vec_info
);
1011 extern tree
vect_check_gather_scatter (gimple
*, loop_vec_info
, tree
*, tree
*,
1013 extern bool vect_analyze_data_refs (vec_info
*, int *, unsigned *);
1014 extern tree
vect_create_data_ref_ptr (gimple
*, tree
, struct loop
*, tree
,
1015 tree
*, gimple_stmt_iterator
*,
1016 gimple
**, bool, bool *,
1018 extern tree
bump_vector_ptr (tree
, gimple
*, gimple_stmt_iterator
*, gimple
*,
1020 extern tree
vect_create_destination_var (tree
, tree
);
1021 extern bool vect_grouped_store_supported (tree
, unsigned HOST_WIDE_INT
);
1022 extern bool vect_store_lanes_supported (tree
, unsigned HOST_WIDE_INT
);
1023 extern bool vect_grouped_load_supported (tree
, unsigned HOST_WIDE_INT
);
1024 extern bool vect_load_lanes_supported (tree
, unsigned HOST_WIDE_INT
);
1025 extern void vect_permute_store_chain (vec
<tree
> ,unsigned int, gimple
*,
1026 gimple_stmt_iterator
*, vec
<tree
> *);
1027 extern tree
vect_setup_realignment (gimple
*, gimple_stmt_iterator
*, tree
*,
1028 enum dr_alignment_support
, tree
,
1030 extern void vect_transform_grouped_load (gimple
*, vec
<tree
> , int,
1031 gimple_stmt_iterator
*);
1032 extern void vect_record_grouped_load_vectors (gimple
*, vec
<tree
> );
1033 extern tree
vect_get_new_vect_var (tree
, enum vect_var_kind
, const char *);
1034 extern tree
vect_get_new_ssa_name (tree
, enum vect_var_kind
,
1035 const char * = NULL
);
1036 extern tree
vect_create_addr_base_for_vector_ref (gimple
*, gimple_seq
*,
1037 tree
, struct loop
*,
1040 /* In tree-vect-loop.c. */
1041 /* FORNOW: Used in tree-parloops.c. */
1042 extern void destroy_loop_vec_info (loop_vec_info
, bool);
1043 extern gimple
*vect_force_simple_reduction (loop_vec_info
, gimple
*, bool,
1045 /* Drive for loop analysis stage. */
1046 extern loop_vec_info
vect_analyze_loop (struct loop
*);
1047 /* Drive for loop transformation stage. */
1048 extern void vect_transform_loop (loop_vec_info
);
1049 extern loop_vec_info
vect_analyze_loop_form (struct loop
*);
1050 extern bool vectorizable_live_operation (gimple
*, gimple_stmt_iterator
*,
1052 extern bool vectorizable_reduction (gimple
*, gimple_stmt_iterator
*,
1053 gimple
**, slp_tree
);
1054 extern bool vectorizable_induction (gimple
*, gimple_stmt_iterator
*, gimple
**);
1055 extern tree
get_initial_def_for_reduction (gimple
*, tree
, tree
*);
1056 extern int vect_min_worthwhile_factor (enum tree_code
);
1057 extern int vect_get_known_peeling_cost (loop_vec_info
, int, int *,
1058 stmt_vector_for_cost
*,
1059 stmt_vector_for_cost
*,
1060 stmt_vector_for_cost
*);
1062 /* In tree-vect-slp.c. */
1063 extern void vect_free_slp_instance (slp_instance
);
1064 extern bool vect_transform_slp_perm_load (slp_tree
, vec
<tree
> ,
1065 gimple_stmt_iterator
*, int,
1066 slp_instance
, bool);
1067 extern bool vect_slp_analyze_operations (vec
<slp_instance
> slp_instances
,
1069 extern bool vect_schedule_slp (vec_info
*);
1070 extern bool vect_analyze_slp (vec_info
*, unsigned);
1071 extern bool vect_make_slp_decision (loop_vec_info
);
1072 extern void vect_detect_hybrid_slp (loop_vec_info
);
1073 extern void vect_get_slp_defs (vec
<tree
> , slp_tree
,
1074 vec
<vec
<tree
> > *, int);
1076 extern source_location
find_bb_location (basic_block
);
1077 extern bb_vec_info
vect_slp_analyze_bb (basic_block
);
1078 extern void vect_slp_transform_bb (basic_block
);
1080 /* In tree-vect-patterns.c. */
1081 /* Pattern recognition functions.
1082 Additional pattern recognition functions can (and will) be added
1084 typedef gimple
*(* vect_recog_func_ptr
) (vec
<gimple
*> *, tree
*, tree
*);
1085 #define NUM_PATTERNS 13
1086 void vect_pattern_recog (vec_info
*);
1088 /* In tree-vectorizer.c. */
1089 unsigned vectorize_loops (void);
1090 void vect_destroy_datarefs (vec_info
*);
1092 #endif /* GCC_TREE_VECTORIZER_H */