* gfortran.dg/pr68251.f90: New test.
[official-gcc.git] / gcc / tree-vectorizer.h
blobfed80c81c3f3bf38923ed6cd6ed4961129dadc40
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 type of reduction. */
64 enum vect_reduction_type {
65 TREE_CODE_REDUCTION,
66 COND_REDUCTION
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 {
76 int count;
77 enum vect_cost_for_stmt kind;
78 gimple *stmt;
79 int misalign;
82 typedef vec<stmt_info_for_cost> stmt_vector_for_cost;
84 /************************************************************************
85 SLP
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. */
91 struct _slp_tree {
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. */
95 vec<gimple *> stmts;
96 /* Load permutation relative to the stores, NULL if there is no
97 permutation. */
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. */
107 bool two_operators;
111 /* SLP instance is a sequence of stmts in a loop that can be packed into
112 SIMD stmts. */
113 typedef struct _slp_instance {
114 /* The root of SLP tree. */
115 slp_tree root;
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. */
124 vec<slp_tree> loads;
125 } *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)
151 : dr (d),
152 offset (size_binop (PLUS_EXPR, DR_OFFSET (d), DR_INIT (d))),
153 seg_len (len) {}
155 data_reference_p dr;
156 tree offset;
157 tree seg_len;
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. */
176 struct vec_info {
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. */
186 vec<ddr_p> ddrs;
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;
197 struct _bb_vec_info;
199 template<>
200 template<>
201 inline bool
202 is_a_helper <_loop_vec_info *>::test (vec_info *i)
204 return i->kind == vec_info::loop;
207 template<>
208 template<>
209 inline bool
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. */
222 struct loop *loop;
224 /* The loop basic blocks. */
225 basic_block *bbs;
227 /* Number of latch executions. */
228 tree num_itersm1;
229 /* Number of iterations. */
230 tree num_iters;
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. */
237 unsigned int th;
239 /* Is the loop vectorizable? */
240 bool 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
255 unaligned_dr. */
256 int peeling_for_alignment;
258 /* The mask used to check the alignment of pointers or arrays. */
259 int ptr_mask;
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
295 this. */
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
305 fix it up. */
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:
319 #pragma omp simd
320 for (int i = 0; i < m; i++)
321 a[i] = a[i + k] * c;
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;
331 } *loop_vec_info;
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
340 cost model. */
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;
383 static inline bool
384 nested_in_vect_loop_p (struct loop *loop, gimple *stmt)
386 return (loop->inner
387 && (loop->inner == (gimple_bb (stmt))->loop_father));
390 typedef struct _bb_vec_info : public vec_info
392 basic_block bb;
393 gimple_stmt_iterator region_begin;
394 gimple_stmt_iterator region_end;
395 } *bb_vec_info;
397 #define BB_VINFO_BB(B) (B)->bb
398 #define BB_VINFO_GROUPED_STORES(B) (B)->grouped_stores
399 #define BB_VINFO_SLP_INSTANCES(B) (B)->slp_instances
400 #define BB_VINFO_DATAREFS(B) (B)->datarefs
401 #define BB_VINFO_DDRS(B) (B)->ddrs
402 #define BB_VINFO_TARGET_COST_DATA(B) (B)->target_cost_data
404 static inline bb_vec_info
405 vec_info_for_bb (basic_block bb)
407 return (bb_vec_info) bb->aux;
410 /*-----------------------------------------------------------------*/
411 /* Info on vectorized defs. */
412 /*-----------------------------------------------------------------*/
413 enum stmt_vec_info_type {
414 undef_vec_info_type = 0,
415 load_vec_info_type,
416 store_vec_info_type,
417 shift_vec_info_type,
418 op_vec_info_type,
419 call_vec_info_type,
420 call_simd_clone_vec_info_type,
421 assignment_vec_info_type,
422 condition_vec_info_type,
423 reduc_vec_info_type,
424 induc_vec_info_type,
425 type_promotion_vec_info_type,
426 type_demotion_vec_info_type,
427 type_conversion_vec_info_type,
428 loop_exit_ctrl_vec_info_type
431 /* Indicates whether/how a variable is used in the scope of loop/basic
432 block. */
433 enum vect_relevant {
434 vect_unused_in_scope = 0,
435 /* The def is in the inner loop, and the use is in the outer loop, and the
436 use is a reduction stmt. */
437 vect_used_in_outer_by_reduction,
438 /* The def is in the inner loop, and the use is in the outer loop (and is
439 not part of reduction). */
440 vect_used_in_outer,
442 /* defs that feed computations that end up (only) in a reduction. These
443 defs may be used by non-reduction stmts, but eventually, any
444 computations/values that are affected by these defs are used to compute
445 a reduction (i.e. don't get stored to memory, for example). We use this
446 to identify computations that we can change the order in which they are
447 computed. */
448 vect_used_by_reduction,
450 vect_used_in_scope
453 /* The type of vectorization that can be applied to the stmt: regular loop-based
454 vectorization; pure SLP - the stmt is a part of SLP instances and does not
455 have uses outside SLP instances; or hybrid SLP and loop-based - the stmt is
456 a part of SLP instance and also must be loop-based vectorized, since it has
457 uses outside SLP sequences.
459 In the loop context the meanings of pure and hybrid SLP are slightly
460 different. By saying that pure SLP is applied to the loop, we mean that we
461 exploit only intra-iteration parallelism in the loop; i.e., the loop can be
462 vectorized without doing any conceptual unrolling, cause we don't pack
463 together stmts from different iterations, only within a single iteration.
464 Loop hybrid SLP means that we exploit both intra-iteration and
465 inter-iteration parallelism (e.g., number of elements in the vector is 4
466 and the slp-group-size is 2, in which case we don't have enough parallelism
467 within an iteration, so we obtain the rest of the parallelism from subsequent
468 iterations by unrolling the loop by 2). */
469 enum slp_vect_type {
470 loop_vect = 0,
471 pure_slp,
472 hybrid
476 typedef struct data_reference *dr_p;
478 typedef struct _stmt_vec_info {
480 enum stmt_vec_info_type type;
482 /* Indicates whether this stmts is part of a computation whose result is
483 used outside the loop. */
484 bool live;
486 /* Stmt is part of some pattern (computation idiom) */
487 bool in_pattern_p;
489 /* The stmt to which this info struct refers to. */
490 gimple *stmt;
492 /* The vec_info with respect to which STMT is vectorized. */
493 vec_info *vinfo;
495 /* The vector type to be used for the LHS of this statement. */
496 tree vectype;
498 /* The vectorized version of the stmt. */
499 gimple *vectorized_stmt;
502 /** The following is relevant only for stmts that contain a non-scalar
503 data-ref (array/pointer/struct access). A GIMPLE stmt is expected to have
504 at most one such data-ref. **/
506 /* Information about the data-ref (access function, etc),
507 relative to the inner-most containing loop. */
508 struct data_reference *data_ref_info;
510 /* Information about the data-ref relative to this loop
511 nest (the loop that is being considered for vectorization). */
512 tree dr_base_address;
513 tree dr_init;
514 tree dr_offset;
515 tree dr_step;
516 tree dr_aligned_to;
518 /* For loop PHI nodes, the evolution part of it. This makes sure
519 this information is still available in vect_update_ivs_after_vectorizer
520 where we may not be able to re-analyze the PHI nodes evolution as
521 peeling for the prologue loop can make it unanalyzable. The evolution
522 part is still correct though. */
523 tree loop_phi_evolution_part;
525 /* Used for various bookkeeping purposes, generally holding a pointer to
526 some other stmt S that is in some way "related" to this stmt.
527 Current use of this field is:
528 If this stmt is part of a pattern (i.e. the field 'in_pattern_p' is
529 true): S is the "pattern stmt" that represents (and replaces) the
530 sequence of stmts that constitutes the pattern. Similarly, the
531 related_stmt of the "pattern stmt" points back to this stmt (which is
532 the last stmt in the original sequence of stmts that constitutes the
533 pattern). */
534 gimple *related_stmt;
536 /* Used to keep a sequence of def stmts of a pattern stmt if such exists. */
537 gimple_seq pattern_def_seq;
539 /* List of datarefs that are known to have the same alignment as the dataref
540 of this stmt. */
541 vec<dr_p> same_align_refs;
543 /* Selected SIMD clone's function info. First vector element
544 is SIMD clone's function decl, followed by a pair of trees (base + step)
545 for linear arguments (pair of NULLs for other arguments). */
546 vec<tree> simd_clone_info;
548 /* Classify the def of this stmt. */
549 enum vect_def_type def_type;
551 /* Whether the stmt is SLPed, loop-based vectorized, or both. */
552 enum slp_vect_type slp_type;
554 /* Interleaving and reduction chains info. */
555 /* First element in the group. */
556 gimple *first_element;
557 /* Pointer to the next element in the group. */
558 gimple *next_element;
559 /* For data-refs, in case that two or more stmts share data-ref, this is the
560 pointer to the previously detected stmt with the same dr. */
561 gimple *same_dr_stmt;
562 /* The size of the group. */
563 unsigned int size;
564 /* For stores, number of stores from this group seen. We vectorize the last
565 one. */
566 unsigned int store_count;
567 /* For loads only, the gap from the previous load. For consecutive loads, GAP
568 is 1. */
569 unsigned int gap;
571 /* The minimum negative dependence distance this stmt participates in
572 or zero if none. */
573 unsigned int min_neg_dist;
575 /* Not all stmts in the loop need to be vectorized. e.g, the increment
576 of the loop induction variable and computation of array indexes. relevant
577 indicates whether the stmt needs to be vectorized. */
578 enum vect_relevant relevant;
580 /* Is this statement vectorizable or should it be skipped in (partial)
581 vectorization. */
582 bool vectorizable;
584 /* For loads if this is a gather, for stores if this is a scatter. */
585 bool gather_scatter_p;
587 /* True if this is an access with loop-invariant stride. */
588 bool strided_p;
590 /* For both loads and stores. */
591 bool simd_lane_access_p;
593 /* For reduction loops, this is the type of reduction. */
594 enum vect_reduction_type v_reduc_type;
596 } *stmt_vec_info;
598 /* Access Functions. */
599 #define STMT_VINFO_TYPE(S) (S)->type
600 #define STMT_VINFO_STMT(S) (S)->stmt
601 inline loop_vec_info
602 STMT_VINFO_LOOP_VINFO (stmt_vec_info stmt_vinfo)
604 if (loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (stmt_vinfo->vinfo))
605 return loop_vinfo;
606 return NULL;
608 inline bb_vec_info
609 STMT_VINFO_BB_VINFO (stmt_vec_info stmt_vinfo)
611 if (bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (stmt_vinfo->vinfo))
612 return bb_vinfo;
613 return NULL;
615 #define STMT_VINFO_RELEVANT(S) (S)->relevant
616 #define STMT_VINFO_LIVE_P(S) (S)->live
617 #define STMT_VINFO_VECTYPE(S) (S)->vectype
618 #define STMT_VINFO_VEC_STMT(S) (S)->vectorized_stmt
619 #define STMT_VINFO_VECTORIZABLE(S) (S)->vectorizable
620 #define STMT_VINFO_DATA_REF(S) (S)->data_ref_info
621 #define STMT_VINFO_GATHER_SCATTER_P(S) (S)->gather_scatter_p
622 #define STMT_VINFO_STRIDED_P(S) (S)->strided_p
623 #define STMT_VINFO_SIMD_LANE_ACCESS_P(S) (S)->simd_lane_access_p
624 #define STMT_VINFO_VEC_REDUCTION_TYPE(S) (S)->v_reduc_type
626 #define STMT_VINFO_DR_BASE_ADDRESS(S) (S)->dr_base_address
627 #define STMT_VINFO_DR_INIT(S) (S)->dr_init
628 #define STMT_VINFO_DR_OFFSET(S) (S)->dr_offset
629 #define STMT_VINFO_DR_STEP(S) (S)->dr_step
630 #define STMT_VINFO_DR_ALIGNED_TO(S) (S)->dr_aligned_to
632 #define STMT_VINFO_IN_PATTERN_P(S) (S)->in_pattern_p
633 #define STMT_VINFO_RELATED_STMT(S) (S)->related_stmt
634 #define STMT_VINFO_PATTERN_DEF_SEQ(S) (S)->pattern_def_seq
635 #define STMT_VINFO_SAME_ALIGN_REFS(S) (S)->same_align_refs
636 #define STMT_VINFO_SIMD_CLONE_INFO(S) (S)->simd_clone_info
637 #define STMT_VINFO_DEF_TYPE(S) (S)->def_type
638 #define STMT_VINFO_GROUP_FIRST_ELEMENT(S) (S)->first_element
639 #define STMT_VINFO_GROUP_NEXT_ELEMENT(S) (S)->next_element
640 #define STMT_VINFO_GROUP_SIZE(S) (S)->size
641 #define STMT_VINFO_GROUP_STORE_COUNT(S) (S)->store_count
642 #define STMT_VINFO_GROUP_GAP(S) (S)->gap
643 #define STMT_VINFO_GROUP_SAME_DR_STMT(S) (S)->same_dr_stmt
644 #define STMT_VINFO_GROUPED_ACCESS(S) ((S)->first_element != NULL && (S)->data_ref_info)
645 #define STMT_VINFO_LOOP_PHI_EVOLUTION_PART(S) (S)->loop_phi_evolution_part
646 #define STMT_VINFO_MIN_NEG_DIST(S) (S)->min_neg_dist
648 #define GROUP_FIRST_ELEMENT(S) (S)->first_element
649 #define GROUP_NEXT_ELEMENT(S) (S)->next_element
650 #define GROUP_SIZE(S) (S)->size
651 #define GROUP_STORE_COUNT(S) (S)->store_count
652 #define GROUP_GAP(S) (S)->gap
653 #define GROUP_SAME_DR_STMT(S) (S)->same_dr_stmt
655 #define STMT_VINFO_RELEVANT_P(S) ((S)->relevant != vect_unused_in_scope)
657 #define HYBRID_SLP_STMT(S) ((S)->slp_type == hybrid)
658 #define PURE_SLP_STMT(S) ((S)->slp_type == pure_slp)
659 #define STMT_SLP_TYPE(S) (S)->slp_type
661 struct dataref_aux {
662 int misalignment;
663 /* If true the alignment of base_decl needs to be increased. */
664 bool base_misaligned;
665 /* If true we know the base is at least vector element alignment aligned. */
666 bool base_element_aligned;
667 tree base_decl;
670 #define DR_VECT_AUX(dr) ((dataref_aux *)(dr)->aux)
672 #define VECT_MAX_COST 1000
674 /* The maximum number of intermediate steps required in multi-step type
675 conversion. */
676 #define MAX_INTERM_CVT_STEPS 3
678 /* The maximum vectorization factor supported by any target (V64QI). */
679 #define MAX_VECTORIZATION_FACTOR 64
681 extern vec<stmt_vec_info> stmt_vec_info_vec;
683 void init_stmt_vec_info_vec (void);
684 void free_stmt_vec_info_vec (void);
686 /* Return a stmt_vec_info corresponding to STMT. */
688 static inline stmt_vec_info
689 vinfo_for_stmt (gimple *stmt)
691 unsigned int uid = gimple_uid (stmt);
692 if (uid == 0)
693 return NULL;
695 return stmt_vec_info_vec[uid - 1];
698 /* Set vectorizer information INFO for STMT. */
700 static inline void
701 set_vinfo_for_stmt (gimple *stmt, stmt_vec_info info)
703 unsigned int uid = gimple_uid (stmt);
704 if (uid == 0)
706 gcc_checking_assert (info);
707 uid = stmt_vec_info_vec.length () + 1;
708 gimple_set_uid (stmt, uid);
709 stmt_vec_info_vec.safe_push (info);
711 else
712 stmt_vec_info_vec[uid - 1] = info;
715 /* Return the earlier statement between STMT1 and STMT2. */
717 static inline gimple *
718 get_earlier_stmt (gimple *stmt1, gimple *stmt2)
720 unsigned int uid1, uid2;
722 if (stmt1 == NULL)
723 return stmt2;
725 if (stmt2 == NULL)
726 return stmt1;
728 uid1 = gimple_uid (stmt1);
729 uid2 = gimple_uid (stmt2);
731 if (uid1 == 0 || uid2 == 0)
732 return NULL;
734 gcc_checking_assert (uid1 <= stmt_vec_info_vec.length ()
735 && uid2 <= stmt_vec_info_vec.length ());
737 if (uid1 < uid2)
738 return stmt1;
739 else
740 return stmt2;
743 /* Return the later statement between STMT1 and STMT2. */
745 static inline gimple *
746 get_later_stmt (gimple *stmt1, gimple *stmt2)
748 unsigned int uid1, uid2;
750 if (stmt1 == NULL)
751 return stmt2;
753 if (stmt2 == NULL)
754 return stmt1;
756 uid1 = gimple_uid (stmt1);
757 uid2 = gimple_uid (stmt2);
759 if (uid1 == 0 || uid2 == 0)
760 return NULL;
762 gcc_assert (uid1 <= stmt_vec_info_vec.length ());
763 gcc_assert (uid2 <= stmt_vec_info_vec.length ());
765 if (uid1 > uid2)
766 return stmt1;
767 else
768 return stmt2;
771 /* Return TRUE if a statement represented by STMT_INFO is a part of a
772 pattern. */
774 static inline bool
775 is_pattern_stmt_p (stmt_vec_info stmt_info)
777 gimple *related_stmt;
778 stmt_vec_info related_stmt_info;
780 related_stmt = STMT_VINFO_RELATED_STMT (stmt_info);
781 if (related_stmt
782 && (related_stmt_info = vinfo_for_stmt (related_stmt))
783 && STMT_VINFO_IN_PATTERN_P (related_stmt_info))
784 return true;
786 return false;
789 /* Return true if BB is a loop header. */
791 static inline bool
792 is_loop_header_bb_p (basic_block bb)
794 if (bb == (bb->loop_father)->header)
795 return true;
796 gcc_checking_assert (EDGE_COUNT (bb->preds) == 1);
797 return false;
800 /* Return pow2 (X). */
802 static inline int
803 vect_pow2 (int x)
805 int i, res = 1;
807 for (i = 0; i < x; i++)
808 res *= 2;
810 return res;
813 /* Alias targetm.vectorize.builtin_vectorization_cost. */
815 static inline int
816 builtin_vectorization_cost (enum vect_cost_for_stmt type_of_cost,
817 tree vectype, int misalign)
819 return targetm.vectorize.builtin_vectorization_cost (type_of_cost,
820 vectype, misalign);
823 /* Get cost by calling cost target builtin. */
825 static inline
826 int vect_get_stmt_cost (enum vect_cost_for_stmt type_of_cost)
828 return builtin_vectorization_cost (type_of_cost, NULL, 0);
831 /* Alias targetm.vectorize.init_cost. */
833 static inline void *
834 init_cost (struct loop *loop_info)
836 return targetm.vectorize.init_cost (loop_info);
839 /* Alias targetm.vectorize.add_stmt_cost. */
841 static inline unsigned
842 add_stmt_cost (void *data, int count, enum vect_cost_for_stmt kind,
843 stmt_vec_info stmt_info, int misalign,
844 enum vect_cost_model_location where)
846 return targetm.vectorize.add_stmt_cost (data, count, kind,
847 stmt_info, misalign, where);
850 /* Alias targetm.vectorize.finish_cost. */
852 static inline void
853 finish_cost (void *data, unsigned *prologue_cost,
854 unsigned *body_cost, unsigned *epilogue_cost)
856 targetm.vectorize.finish_cost (data, prologue_cost, body_cost, epilogue_cost);
859 /* Alias targetm.vectorize.destroy_cost_data. */
861 static inline void
862 destroy_cost_data (void *data)
864 targetm.vectorize.destroy_cost_data (data);
867 /*-----------------------------------------------------------------*/
868 /* Info on data references alignment. */
869 /*-----------------------------------------------------------------*/
870 inline void
871 set_dr_misalignment (struct data_reference *dr, int val)
873 dataref_aux *data_aux = DR_VECT_AUX (dr);
875 if (!data_aux)
877 data_aux = XCNEW (dataref_aux);
878 dr->aux = data_aux;
881 data_aux->misalignment = val;
884 inline int
885 dr_misalignment (struct data_reference *dr)
887 return DR_VECT_AUX (dr)->misalignment;
890 /* Reflects actual alignment of first access in the vectorized loop,
891 taking into account peeling/versioning if applied. */
892 #define DR_MISALIGNMENT(DR) dr_misalignment (DR)
893 #define SET_DR_MISALIGNMENT(DR, VAL) set_dr_misalignment (DR, VAL)
895 /* Return TRUE if the data access is aligned, and FALSE otherwise. */
897 static inline bool
898 aligned_access_p (struct data_reference *data_ref_info)
900 return (DR_MISALIGNMENT (data_ref_info) == 0);
903 /* Return TRUE if the alignment of the data access is known, and FALSE
904 otherwise. */
906 static inline bool
907 known_alignment_for_access_p (struct data_reference *data_ref_info)
909 return (DR_MISALIGNMENT (data_ref_info) != -1);
913 /* Return true if the vect cost model is unlimited. */
914 static inline bool
915 unlimited_cost_model (loop_p loop)
917 if (loop != NULL && loop->force_vectorize
918 && flag_simd_cost_model != VECT_COST_MODEL_DEFAULT)
919 return flag_simd_cost_model == VECT_COST_MODEL_UNLIMITED;
920 return (flag_vect_cost_model == VECT_COST_MODEL_UNLIMITED);
923 /* Source location */
924 extern source_location vect_location;
926 /*-----------------------------------------------------------------*/
927 /* Function prototypes. */
928 /*-----------------------------------------------------------------*/
930 /* Simple loop peeling and versioning utilities for vectorizer's purposes -
931 in tree-vect-loop-manip.c. */
932 extern void slpeel_make_loop_iterate_ntimes (struct loop *, tree);
933 extern bool slpeel_can_duplicate_loop_p (const struct loop *, const_edge);
934 struct loop *slpeel_tree_duplicate_loop_to_edge_cfg (struct loop *,
935 struct loop *, edge);
936 extern void vect_loop_versioning (loop_vec_info, unsigned int, bool);
937 extern void vect_do_peeling_for_loop_bound (loop_vec_info, tree, tree,
938 unsigned int, bool);
939 extern void vect_do_peeling_for_alignment (loop_vec_info, tree,
940 unsigned int, bool);
941 extern source_location find_loop_location (struct loop *);
942 extern bool vect_can_advance_ivs_p (loop_vec_info);
944 /* In tree-vect-stmts.c. */
945 extern unsigned int current_vector_size;
946 extern tree get_vectype_for_scalar_type (tree);
947 extern tree get_same_sized_vectype (tree, tree);
948 extern bool vect_is_simple_use (tree, vec_info *, gimple **,
949 enum vect_def_type *);
950 extern bool vect_is_simple_use (tree, vec_info *, gimple **,
951 enum vect_def_type *, tree *);
952 extern bool supportable_widening_operation (enum tree_code, gimple *, tree,
953 tree, enum tree_code *,
954 enum tree_code *, int *,
955 vec<tree> *);
956 extern bool supportable_narrowing_operation (enum tree_code, tree, tree,
957 enum tree_code *,
958 int *, vec<tree> *);
959 extern stmt_vec_info new_stmt_vec_info (gimple *stmt, vec_info *);
960 extern void free_stmt_vec_info (gimple *stmt);
961 extern tree vectorizable_function (gcall *, tree, tree);
962 extern void vect_model_simple_cost (stmt_vec_info, int, enum vect_def_type *,
963 stmt_vector_for_cost *,
964 stmt_vector_for_cost *);
965 extern void vect_model_store_cost (stmt_vec_info, int, bool,
966 enum vect_def_type, slp_tree,
967 stmt_vector_for_cost *,
968 stmt_vector_for_cost *);
969 extern void vect_model_load_cost (stmt_vec_info, int, bool, slp_tree,
970 stmt_vector_for_cost *,
971 stmt_vector_for_cost *);
972 extern unsigned record_stmt_cost (stmt_vector_for_cost *, int,
973 enum vect_cost_for_stmt, stmt_vec_info,
974 int, enum vect_cost_model_location);
975 extern void vect_finish_stmt_generation (gimple *, gimple *,
976 gimple_stmt_iterator *);
977 extern bool vect_mark_stmts_to_be_vectorized (loop_vec_info);
978 extern tree vect_get_vec_def_for_operand (tree, gimple *);
979 extern tree vect_init_vector (gimple *, tree, tree,
980 gimple_stmt_iterator *);
981 extern tree vect_get_vec_def_for_stmt_copy (enum vect_def_type, tree);
982 extern bool vect_transform_stmt (gimple *, gimple_stmt_iterator *,
983 bool *, slp_tree, slp_instance);
984 extern void vect_remove_stores (gimple *);
985 extern bool vect_analyze_stmt (gimple *, bool *, slp_tree);
986 extern bool vectorizable_condition (gimple *, gimple_stmt_iterator *,
987 gimple **, tree, int, slp_tree);
988 extern void vect_get_load_cost (struct data_reference *, int, bool,
989 unsigned int *, unsigned int *,
990 stmt_vector_for_cost *,
991 stmt_vector_for_cost *, bool);
992 extern void vect_get_store_cost (struct data_reference *, int,
993 unsigned int *, stmt_vector_for_cost *);
994 extern bool vect_supportable_shift (enum tree_code, tree);
995 extern void vect_get_vec_defs (tree, tree, gimple *, vec<tree> *,
996 vec<tree> *, slp_tree, int);
997 extern tree vect_gen_perm_mask_any (tree, const unsigned char *);
998 extern tree vect_gen_perm_mask_checked (tree, const unsigned char *);
1000 /* In tree-vect-data-refs.c. */
1001 extern bool vect_can_force_dr_alignment_p (const_tree, unsigned int);
1002 extern enum dr_alignment_support vect_supportable_dr_alignment
1003 (struct data_reference *, bool);
1004 extern tree vect_get_smallest_scalar_type (gimple *, HOST_WIDE_INT *,
1005 HOST_WIDE_INT *);
1006 extern bool vect_analyze_data_ref_dependences (loop_vec_info, int *);
1007 extern bool vect_slp_analyze_data_ref_dependences (bb_vec_info);
1008 extern bool vect_enhance_data_refs_alignment (loop_vec_info);
1009 extern bool vect_analyze_data_refs_alignment (vec_info *);
1010 extern bool vect_verify_datarefs_alignment (vec_info *);
1011 extern bool vect_analyze_data_ref_accesses (vec_info *);
1012 extern bool vect_prune_runtime_alias_test_list (loop_vec_info);
1013 extern tree vect_check_gather_scatter (gimple *, loop_vec_info, tree *, tree *,
1014 int *);
1015 extern bool vect_analyze_data_refs (vec_info *, int *);
1016 extern tree vect_create_data_ref_ptr (gimple *, tree, struct loop *, tree,
1017 tree *, gimple_stmt_iterator *,
1018 gimple **, bool, bool *,
1019 tree = NULL_TREE);
1020 extern tree bump_vector_ptr (tree, gimple *, gimple_stmt_iterator *, gimple *,
1021 tree);
1022 extern tree vect_create_destination_var (tree, tree);
1023 extern bool vect_grouped_store_supported (tree, unsigned HOST_WIDE_INT);
1024 extern bool vect_store_lanes_supported (tree, unsigned HOST_WIDE_INT);
1025 extern bool vect_grouped_load_supported (tree, unsigned HOST_WIDE_INT);
1026 extern bool vect_load_lanes_supported (tree, unsigned HOST_WIDE_INT);
1027 extern void vect_permute_store_chain (vec<tree> ,unsigned int, gimple *,
1028 gimple_stmt_iterator *, vec<tree> *);
1029 extern tree vect_setup_realignment (gimple *, gimple_stmt_iterator *, tree *,
1030 enum dr_alignment_support, tree,
1031 struct loop **);
1032 extern void vect_transform_grouped_load (gimple *, vec<tree> , int,
1033 gimple_stmt_iterator *);
1034 extern void vect_record_grouped_load_vectors (gimple *, vec<tree> );
1035 extern tree vect_get_new_vect_var (tree, enum vect_var_kind, const char *);
1036 extern tree vect_get_new_ssa_name (tree, enum vect_var_kind,
1037 const char * = NULL);
1038 extern tree vect_create_addr_base_for_vector_ref (gimple *, gimple_seq *,
1039 tree, struct loop *,
1040 tree = NULL_TREE);
1042 /* In tree-vect-loop.c. */
1043 /* FORNOW: Used in tree-parloops.c. */
1044 extern void destroy_loop_vec_info (loop_vec_info, bool);
1045 extern gimple *vect_force_simple_reduction (loop_vec_info, gimple *, bool,
1046 bool *, bool);
1047 /* Drive for loop analysis stage. */
1048 extern loop_vec_info vect_analyze_loop (struct loop *);
1049 /* Drive for loop transformation stage. */
1050 extern void vect_transform_loop (loop_vec_info);
1051 extern loop_vec_info vect_analyze_loop_form (struct loop *);
1052 extern bool vectorizable_live_operation (gimple *, gimple_stmt_iterator *,
1053 gimple **);
1054 extern bool vectorizable_reduction (gimple *, gimple_stmt_iterator *,
1055 gimple **, slp_tree);
1056 extern bool vectorizable_induction (gimple *, gimple_stmt_iterator *, gimple **);
1057 extern tree get_initial_def_for_reduction (gimple *, tree, tree *);
1058 extern int vect_min_worthwhile_factor (enum tree_code);
1059 extern int vect_get_known_peeling_cost (loop_vec_info, int, int *,
1060 stmt_vector_for_cost *,
1061 stmt_vector_for_cost *,
1062 stmt_vector_for_cost *);
1064 /* In tree-vect-slp.c. */
1065 extern void vect_free_slp_instance (slp_instance);
1066 extern bool vect_transform_slp_perm_load (slp_tree, vec<tree> ,
1067 gimple_stmt_iterator *, int,
1068 slp_instance, bool);
1069 extern bool vect_slp_analyze_operations (vec<slp_instance> slp_instances,
1070 void *);
1071 extern bool vect_schedule_slp (vec_info *);
1072 extern bool vect_analyze_slp (vec_info *, unsigned);
1073 extern bool vect_make_slp_decision (loop_vec_info);
1074 extern void vect_detect_hybrid_slp (loop_vec_info);
1075 extern void vect_get_slp_defs (vec<tree> , slp_tree,
1076 vec<vec<tree> > *, int);
1077 extern bool vect_slp_bb (basic_block);
1078 extern gimple *vect_find_last_scalar_stmt_in_slp (slp_tree);
1080 /* In tree-vect-patterns.c. */
1081 /* Pattern recognition functions.
1082 Additional pattern recognition functions can (and will) be added
1083 in the future. */
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 *);
1091 bool vect_stmt_in_region_p (vec_info *, gimple *);
1093 #endif /* GCC_TREE_VECTORIZER_H */