gcc/
[official-gcc.git] / gcc / tree-vectorizer.h
blob0796cc19fcd8190957679ce2204e1cd35519c6b3
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"
26 #include "hash-table.h"
28 /* Used for naming of new temporaries. */
29 enum vect_var_kind {
30 vect_simple_var,
31 vect_pointer_var,
32 vect_scalar_var
35 /* Defines type of operation. */
36 enum operation_type {
37 unary_op = 1,
38 binary_op,
39 ternary_op
42 /* Define type of available alignment support. */
43 enum dr_alignment_support {
44 dr_unaligned_unsupported,
45 dr_unaligned_supported,
46 dr_explicit_realign,
47 dr_explicit_realign_optimized,
48 dr_aligned
51 /* Define type of def-use cross-iteration cycle. */
52 enum vect_def_type {
53 vect_uninitialized_def = 0,
54 vect_constant_def = 1,
55 vect_external_def,
56 vect_internal_def,
57 vect_induction_def,
58 vect_reduction_def,
59 vect_double_reduction_def,
60 vect_nested_cycle,
61 vect_unknown_def_type
64 #define VECTORIZABLE_CYCLE_DEF(D) (((D) == vect_reduction_def) \
65 || ((D) == vect_double_reduction_def) \
66 || ((D) == vect_nested_cycle))
68 /* Structure to encapsulate information about a group of like
69 instructions to be presented to the target cost model. */
70 typedef struct _stmt_info_for_cost {
71 int count;
72 enum vect_cost_for_stmt kind;
73 gimple stmt;
74 int misalign;
75 } stmt_info_for_cost;
78 typedef vec<stmt_info_for_cost> stmt_vector_for_cost;
80 static inline void
81 add_stmt_info_to_vec (stmt_vector_for_cost *stmt_cost_vec, int count,
82 enum vect_cost_for_stmt kind, gimple stmt, int misalign)
84 stmt_info_for_cost si;
85 si.count = count;
86 si.kind = kind;
87 si.stmt = stmt;
88 si.misalign = misalign;
89 stmt_cost_vec->safe_push (si);
92 /************************************************************************
93 SLP
94 ************************************************************************/
95 typedef struct _slp_tree *slp_tree;
97 /* A computation tree of an SLP instance. Each node corresponds to a group of
98 stmts to be packed in a SIMD stmt. */
99 struct _slp_tree {
100 /* Nodes that contain def-stmts of this node statements operands. */
101 vec<slp_tree> children;
102 /* A group of scalar stmts to be vectorized together. */
103 vec<gimple> stmts;
104 /* Load permutation relative to the stores, NULL if there is no
105 permutation. */
106 vec<unsigned> load_permutation;
107 /* Vectorized stmt/s. */
108 vec<gimple> vec_stmts;
109 /* Number of vector stmts that are created to replace the group of scalar
110 stmts. It is calculated during the transformation phase as the number of
111 scalar elements in one scalar iteration (GROUP_SIZE) multiplied by VF
112 divided by vector size. */
113 unsigned int vec_stmts_size;
117 /* SLP instance is a sequence of stmts in a loop that can be packed into
118 SIMD stmts. */
119 typedef struct _slp_instance {
120 /* The root of SLP tree. */
121 slp_tree root;
123 /* Size of groups of scalar stmts that will be replaced by SIMD stmt/s. */
124 unsigned int group_size;
126 /* The unrolling factor required to vectorized this SLP instance. */
127 unsigned int unrolling_factor;
129 /* Vectorization costs associated with SLP instance. */
130 stmt_vector_for_cost body_cost_vec;
132 /* The group of nodes that contain loads of this SLP instance. */
133 vec<slp_tree> loads;
134 } *slp_instance;
137 /* Access Functions. */
138 #define SLP_INSTANCE_TREE(S) (S)->root
139 #define SLP_INSTANCE_GROUP_SIZE(S) (S)->group_size
140 #define SLP_INSTANCE_UNROLLING_FACTOR(S) (S)->unrolling_factor
141 #define SLP_INSTANCE_BODY_COST_VEC(S) (S)->body_cost_vec
142 #define SLP_INSTANCE_LOADS(S) (S)->loads
144 #define SLP_TREE_CHILDREN(S) (S)->children
145 #define SLP_TREE_SCALAR_STMTS(S) (S)->stmts
146 #define SLP_TREE_VEC_STMTS(S) (S)->vec_stmts
147 #define SLP_TREE_NUMBER_OF_VEC_STMTS(S) (S)->vec_stmts_size
148 #define SLP_TREE_LOAD_PERMUTATION(S) (S)->load_permutation
150 /* This structure is used in creation of an SLP tree. Each instance
151 corresponds to the same operand in a group of scalar stmts in an SLP
152 node. */
153 typedef struct _slp_oprnd_info
155 /* Def-stmts for the operands. */
156 vec<gimple> def_stmts;
157 /* Information about the first statement, its vector def-type, type, the
158 operand itself in case it's constant, and an indication if it's a pattern
159 stmt. */
160 enum vect_def_type first_dt;
161 tree first_op_type;
162 bool first_pattern;
163 } *slp_oprnd_info;
167 /* This struct is used to store the information of a data reference,
168 including the data ref itself, the access offset (calculated by summing its
169 offset and init) and the segment length for aliasing checks.
170 This is used to merge alias checks. */
172 struct dr_with_seg_len
174 dr_with_seg_len (data_reference_p d, tree len)
175 : dr (d),
176 offset (size_binop (PLUS_EXPR, DR_OFFSET (d), DR_INIT (d))),
177 seg_len (len) {}
179 data_reference_p dr;
180 tree offset;
181 tree seg_len;
184 /* This struct contains two dr_with_seg_len objects with aliasing data
185 refs. Two comparisons are generated from them. */
187 struct dr_with_seg_len_pair_t
189 dr_with_seg_len_pair_t (const dr_with_seg_len& d1,
190 const dr_with_seg_len& d2)
191 : first (d1), second (d2) {}
193 dr_with_seg_len first;
194 dr_with_seg_len second;
198 typedef struct _vect_peel_info
200 int npeel;
201 struct data_reference *dr;
202 unsigned int count;
203 } *vect_peel_info;
205 typedef struct _vect_peel_extended_info
207 struct _vect_peel_info peel_info;
208 unsigned int inside_cost;
209 unsigned int outside_cost;
210 stmt_vector_for_cost body_cost_vec;
211 } *vect_peel_extended_info;
214 /* Peeling hashtable helpers. */
216 struct peel_info_hasher : typed_free_remove <_vect_peel_info>
218 typedef _vect_peel_info *value_type;
219 typedef _vect_peel_info *compare_type;
220 static inline hashval_t hash (const _vect_peel_info *);
221 static inline bool equal (const _vect_peel_info *, const _vect_peel_info *);
224 inline hashval_t
225 peel_info_hasher::hash (const _vect_peel_info *peel_info)
227 return (hashval_t) peel_info->npeel;
230 inline bool
231 peel_info_hasher::equal (const _vect_peel_info *a, const _vect_peel_info *b)
233 return (a->npeel == b->npeel);
237 /*-----------------------------------------------------------------*/
238 /* Info on vectorized loops. */
239 /*-----------------------------------------------------------------*/
240 typedef struct _loop_vec_info {
242 /* The loop to which this info struct refers to. */
243 struct loop *loop;
245 /* The loop basic blocks. */
246 basic_block *bbs;
248 /* Number of latch executions. */
249 tree num_itersm1;
250 /* Number of iterations. */
251 tree num_iters;
252 /* Number of iterations of the original loop. */
253 tree num_iters_unchanged;
255 /* Minimum number of iterations below which vectorization is expected to
256 not be profitable (as estimated by the cost model).
257 -1 indicates that vectorization will not be profitable.
258 FORNOW: This field is an int. Will be a tree in the future, to represent
259 values unknown at compile time. */
260 int min_profitable_iters;
262 /* Threshold of number of iterations below which vectorzation will not be
263 performed. It is calculated from MIN_PROFITABLE_ITERS and
264 PARAM_MIN_VECT_LOOP_BOUND. */
265 unsigned int th;
267 /* Is the loop vectorizable? */
268 bool vectorizable;
270 /* Unrolling factor */
271 int vectorization_factor;
273 /* Unknown DRs according to which loop was peeled. */
274 struct data_reference *unaligned_dr;
276 /* peeling_for_alignment indicates whether peeling for alignment will take
277 place, and what the peeling factor should be:
278 peeling_for_alignment = X means:
279 If X=0: Peeling for alignment will not be applied.
280 If X>0: Peel first X iterations.
281 If X=-1: Generate a runtime test to calculate the number of iterations
282 to be peeled, using the dataref recorded in the field
283 unaligned_dr. */
284 int peeling_for_alignment;
286 /* The mask used to check the alignment of pointers or arrays. */
287 int ptr_mask;
289 /* The loop nest in which the data dependences are computed. */
290 vec<loop_p> loop_nest;
292 /* All data references in the loop. */
293 vec<data_reference_p> datarefs;
295 /* All data dependences in the loop. */
296 vec<ddr_p> ddrs;
298 /* Data Dependence Relations defining address ranges that are candidates
299 for a run-time aliasing check. */
300 vec<ddr_p> may_alias_ddrs;
302 /* Data Dependence Relations defining address ranges together with segment
303 lengths from which the run-time aliasing check is built. */
304 vec<dr_with_seg_len_pair_t> comp_alias_ddrs;
306 /* Statements in the loop that have data references that are candidates for a
307 runtime (loop versioning) misalignment check. */
308 vec<gimple> may_misalign_stmts;
310 /* All interleaving chains of stores in the loop, represented by the first
311 stmt in the chain. */
312 vec<gimple> grouped_stores;
314 /* All SLP instances in the loop. This is a subset of the set of GROUP_STORES
315 of the loop. */
316 vec<slp_instance> slp_instances;
318 /* The unrolling factor needed to SLP the loop. In case of that pure SLP is
319 applied to the loop, i.e., no unrolling is needed, this is 1. */
320 unsigned slp_unrolling_factor;
322 /* Reduction cycles detected in the loop. Used in loop-aware SLP. */
323 vec<gimple> reductions;
325 /* All reduction chains in the loop, represented by the first
326 stmt in the chain. */
327 vec<gimple> reduction_chains;
329 /* Hash table used to choose the best peeling option. */
330 hash_table<peel_info_hasher> *peeling_htab;
332 /* Cost data used by the target cost model. */
333 void *target_cost_data;
335 /* When we have grouped data accesses with gaps, we may introduce invalid
336 memory accesses. We peel the last iteration of the loop to prevent
337 this. */
338 bool peeling_for_gaps;
340 /* When the number of iterations is not a multiple of the vector size
341 we need to peel off iterations at the end to form an epilogue loop. */
342 bool peeling_for_niter;
344 /* Reductions are canonicalized so that the last operand is the reduction
345 operand. If this places a constant into RHS1, this decanonicalizes
346 GIMPLE for other phases, so we must track when this has occurred and
347 fix it up. */
348 bool operands_swapped;
350 /* True if there are no loop carried data dependencies in the loop.
351 If loop->safelen <= 1, then this is always true, either the loop
352 didn't have any loop carried data dependencies, or the loop is being
353 vectorized guarded with some runtime alias checks, or couldn't
354 be vectorized at all, but then this field shouldn't be used.
355 For loop->safelen >= 2, the user has asserted that there are no
356 backward dependencies, but there still could be loop carried forward
357 dependencies in such loops. This flag will be false if normal
358 vectorizer data dependency analysis would fail or require versioning
359 for alias, but because of loop->safelen >= 2 it has been vectorized
360 even without versioning for alias. E.g. in:
361 #pragma omp simd
362 for (int i = 0; i < m; i++)
363 a[i] = a[i + k] * c;
364 (or #pragma simd or #pragma ivdep) we can vectorize this and it will
365 DTRT even for k > 0 && k < m, but without safelen we would not
366 vectorize this, so this field would be false. */
367 bool no_data_dependencies;
369 /* If if-conversion versioned this loop before conversion, this is the
370 loop version without if-conversion. */
371 struct loop *scalar_loop;
373 } *loop_vec_info;
375 /* Access Functions. */
376 #define LOOP_VINFO_LOOP(L) (L)->loop
377 #define LOOP_VINFO_BBS(L) (L)->bbs
378 #define LOOP_VINFO_NITERSM1(L) (L)->num_itersm1
379 #define LOOP_VINFO_NITERS(L) (L)->num_iters
380 /* Since LOOP_VINFO_NITERS and LOOP_VINFO_NITERSM1 can change after
381 prologue peeling retain total unchanged scalar loop iterations for
382 cost model. */
383 #define LOOP_VINFO_NITERS_UNCHANGED(L) (L)->num_iters_unchanged
384 #define LOOP_VINFO_COST_MODEL_MIN_ITERS(L) (L)->min_profitable_iters
385 #define LOOP_VINFO_COST_MODEL_THRESHOLD(L) (L)->th
386 #define LOOP_VINFO_VECTORIZABLE_P(L) (L)->vectorizable
387 #define LOOP_VINFO_VECT_FACTOR(L) (L)->vectorization_factor
388 #define LOOP_VINFO_PTR_MASK(L) (L)->ptr_mask
389 #define LOOP_VINFO_LOOP_NEST(L) (L)->loop_nest
390 #define LOOP_VINFO_DATAREFS(L) (L)->datarefs
391 #define LOOP_VINFO_DDRS(L) (L)->ddrs
392 #define LOOP_VINFO_INT_NITERS(L) (TREE_INT_CST_LOW ((L)->num_iters))
393 #define LOOP_VINFO_PEELING_FOR_ALIGNMENT(L) (L)->peeling_for_alignment
394 #define LOOP_VINFO_UNALIGNED_DR(L) (L)->unaligned_dr
395 #define LOOP_VINFO_MAY_MISALIGN_STMTS(L) (L)->may_misalign_stmts
396 #define LOOP_VINFO_MAY_ALIAS_DDRS(L) (L)->may_alias_ddrs
397 #define LOOP_VINFO_COMP_ALIAS_DDRS(L) (L)->comp_alias_ddrs
398 #define LOOP_VINFO_GROUPED_STORES(L) (L)->grouped_stores
399 #define LOOP_VINFO_SLP_INSTANCES(L) (L)->slp_instances
400 #define LOOP_VINFO_SLP_UNROLLING_FACTOR(L) (L)->slp_unrolling_factor
401 #define LOOP_VINFO_REDUCTIONS(L) (L)->reductions
402 #define LOOP_VINFO_REDUCTION_CHAINS(L) (L)->reduction_chains
403 #define LOOP_VINFO_PEELING_HTAB(L) (L)->peeling_htab
404 #define LOOP_VINFO_TARGET_COST_DATA(L) (L)->target_cost_data
405 #define LOOP_VINFO_PEELING_FOR_GAPS(L) (L)->peeling_for_gaps
406 #define LOOP_VINFO_OPERANDS_SWAPPED(L) (L)->operands_swapped
407 #define LOOP_VINFO_PEELING_FOR_NITER(L) (L)->peeling_for_niter
408 #define LOOP_VINFO_NO_DATA_DEPENDENCIES(L) (L)->no_data_dependencies
409 #define LOOP_VINFO_SCALAR_LOOP(L) (L)->scalar_loop
411 #define LOOP_REQUIRES_VERSIONING_FOR_ALIGNMENT(L) \
412 ((L)->may_misalign_stmts.length () > 0)
413 #define LOOP_REQUIRES_VERSIONING_FOR_ALIAS(L) \
414 ((L)->may_alias_ddrs.length () > 0)
416 #define LOOP_VINFO_NITERS_KNOWN_P(L) \
417 (tree_fits_shwi_p ((L)->num_iters) && tree_to_shwi ((L)->num_iters) > 0)
419 static inline loop_vec_info
420 loop_vec_info_for_loop (struct loop *loop)
422 return (loop_vec_info) loop->aux;
425 static inline bool
426 nested_in_vect_loop_p (struct loop *loop, gimple stmt)
428 return (loop->inner
429 && (loop->inner == (gimple_bb (stmt))->loop_father));
432 typedef struct _bb_vec_info {
434 basic_block bb;
435 /* All interleaving chains of stores in the basic block, represented by the
436 first stmt in the chain. */
437 vec<gimple> grouped_stores;
439 /* All SLP instances in the basic block. This is a subset of the set of
440 GROUP_STORES of the basic block. */
441 vec<slp_instance> slp_instances;
443 /* All data references in the basic block. */
444 vec<data_reference_p> datarefs;
446 /* All data dependences in the basic block. */
447 vec<ddr_p> ddrs;
449 /* Cost data used by the target cost model. */
450 void *target_cost_data;
452 } *bb_vec_info;
454 #define BB_VINFO_BB(B) (B)->bb
455 #define BB_VINFO_GROUPED_STORES(B) (B)->grouped_stores
456 #define BB_VINFO_SLP_INSTANCES(B) (B)->slp_instances
457 #define BB_VINFO_DATAREFS(B) (B)->datarefs
458 #define BB_VINFO_DDRS(B) (B)->ddrs
459 #define BB_VINFO_TARGET_COST_DATA(B) (B)->target_cost_data
461 static inline bb_vec_info
462 vec_info_for_bb (basic_block bb)
464 return (bb_vec_info) bb->aux;
467 /*-----------------------------------------------------------------*/
468 /* Info on vectorized defs. */
469 /*-----------------------------------------------------------------*/
470 enum stmt_vec_info_type {
471 undef_vec_info_type = 0,
472 load_vec_info_type,
473 store_vec_info_type,
474 shift_vec_info_type,
475 op_vec_info_type,
476 call_vec_info_type,
477 call_simd_clone_vec_info_type,
478 assignment_vec_info_type,
479 condition_vec_info_type,
480 reduc_vec_info_type,
481 induc_vec_info_type,
482 type_promotion_vec_info_type,
483 type_demotion_vec_info_type,
484 type_conversion_vec_info_type,
485 loop_exit_ctrl_vec_info_type
488 /* Indicates whether/how a variable is used in the scope of loop/basic
489 block. */
490 enum vect_relevant {
491 vect_unused_in_scope = 0,
492 /* The def is in the inner loop, and the use is in the outer loop, and the
493 use is a reduction stmt. */
494 vect_used_in_outer_by_reduction,
495 /* The def is in the inner loop, and the use is in the outer loop (and is
496 not part of reduction). */
497 vect_used_in_outer,
499 /* defs that feed computations that end up (only) in a reduction. These
500 defs may be used by non-reduction stmts, but eventually, any
501 computations/values that are affected by these defs are used to compute
502 a reduction (i.e. don't get stored to memory, for example). We use this
503 to identify computations that we can change the order in which they are
504 computed. */
505 vect_used_by_reduction,
507 vect_used_in_scope
510 /* The type of vectorization that can be applied to the stmt: regular loop-based
511 vectorization; pure SLP - the stmt is a part of SLP instances and does not
512 have uses outside SLP instances; or hybrid SLP and loop-based - the stmt is
513 a part of SLP instance and also must be loop-based vectorized, since it has
514 uses outside SLP sequences.
516 In the loop context the meanings of pure and hybrid SLP are slightly
517 different. By saying that pure SLP is applied to the loop, we mean that we
518 exploit only intra-iteration parallelism in the loop; i.e., the loop can be
519 vectorized without doing any conceptual unrolling, cause we don't pack
520 together stmts from different iterations, only within a single iteration.
521 Loop hybrid SLP means that we exploit both intra-iteration and
522 inter-iteration parallelism (e.g., number of elements in the vector is 4
523 and the slp-group-size is 2, in which case we don't have enough parallelism
524 within an iteration, so we obtain the rest of the parallelism from subsequent
525 iterations by unrolling the loop by 2). */
526 enum slp_vect_type {
527 loop_vect = 0,
528 pure_slp,
529 hybrid
533 typedef struct data_reference *dr_p;
535 typedef struct _stmt_vec_info {
537 enum stmt_vec_info_type type;
539 /* Indicates whether this stmts is part of a computation whose result is
540 used outside the loop. */
541 bool live;
543 /* Stmt is part of some pattern (computation idiom) */
544 bool in_pattern_p;
546 /* The stmt to which this info struct refers to. */
547 gimple stmt;
549 /* The loop_vec_info with respect to which STMT is vectorized. */
550 loop_vec_info loop_vinfo;
552 /* The vector type to be used for the LHS of this statement. */
553 tree vectype;
555 /* The vectorized version of the stmt. */
556 gimple vectorized_stmt;
559 /** The following is relevant only for stmts that contain a non-scalar
560 data-ref (array/pointer/struct access). A GIMPLE stmt is expected to have
561 at most one such data-ref. **/
563 /* Information about the data-ref (access function, etc),
564 relative to the inner-most containing loop. */
565 struct data_reference *data_ref_info;
567 /* Information about the data-ref relative to this loop
568 nest (the loop that is being considered for vectorization). */
569 tree dr_base_address;
570 tree dr_init;
571 tree dr_offset;
572 tree dr_step;
573 tree dr_aligned_to;
575 /* For loop PHI nodes, the evolution part of it. This makes sure
576 this information is still available in vect_update_ivs_after_vectorizer
577 where we may not be able to re-analyze the PHI nodes evolution as
578 peeling for the prologue loop can make it unanalyzable. The evolution
579 part is still correct though. */
580 tree loop_phi_evolution_part;
582 /* Used for various bookkeeping purposes, generally holding a pointer to
583 some other stmt S that is in some way "related" to this stmt.
584 Current use of this field is:
585 If this stmt is part of a pattern (i.e. the field 'in_pattern_p' is
586 true): S is the "pattern stmt" that represents (and replaces) the
587 sequence of stmts that constitutes the pattern. Similarly, the
588 related_stmt of the "pattern stmt" points back to this stmt (which is
589 the last stmt in the original sequence of stmts that constitutes the
590 pattern). */
591 gimple related_stmt;
593 /* Used to keep a sequence of def stmts of a pattern stmt if such exists. */
594 gimple_seq pattern_def_seq;
596 /* List of datarefs that are known to have the same alignment as the dataref
597 of this stmt. */
598 vec<dr_p> same_align_refs;
600 /* Selected SIMD clone's function info. First vector element
601 is SIMD clone's function decl, followed by a pair of trees (base + step)
602 for linear arguments (pair of NULLs for other arguments). */
603 vec<tree> simd_clone_info;
605 /* Classify the def of this stmt. */
606 enum vect_def_type def_type;
608 /* Whether the stmt is SLPed, loop-based vectorized, or both. */
609 enum slp_vect_type slp_type;
611 /* Interleaving and reduction chains info. */
612 /* First element in the group. */
613 gimple first_element;
614 /* Pointer to the next element in the group. */
615 gimple next_element;
616 /* For data-refs, in case that two or more stmts share data-ref, this is the
617 pointer to the previously detected stmt with the same dr. */
618 gimple same_dr_stmt;
619 /* The size of the group. */
620 unsigned int size;
621 /* For stores, number of stores from this group seen. We vectorize the last
622 one. */
623 unsigned int store_count;
624 /* For loads only, the gap from the previous load. For consecutive loads, GAP
625 is 1. */
626 unsigned int gap;
628 /* The minimum negative dependence distance this stmt participates in
629 or zero if none. */
630 unsigned int min_neg_dist;
632 /* Not all stmts in the loop need to be vectorized. e.g, the increment
633 of the loop induction variable and computation of array indexes. relevant
634 indicates whether the stmt needs to be vectorized. */
635 enum vect_relevant relevant;
637 /* The bb_vec_info with respect to which STMT is vectorized. */
638 bb_vec_info bb_vinfo;
640 /* Is this statement vectorizable or should it be skipped in (partial)
641 vectorization. */
642 bool vectorizable;
644 /* For loads only, true if this is a gather load. */
645 bool gather_p;
646 bool stride_load_p;
648 /* For both loads and stores. */
649 bool simd_lane_access_p;
650 } *stmt_vec_info;
652 /* Access Functions. */
653 #define STMT_VINFO_TYPE(S) (S)->type
654 #define STMT_VINFO_STMT(S) (S)->stmt
655 #define STMT_VINFO_LOOP_VINFO(S) (S)->loop_vinfo
656 #define STMT_VINFO_BB_VINFO(S) (S)->bb_vinfo
657 #define STMT_VINFO_RELEVANT(S) (S)->relevant
658 #define STMT_VINFO_LIVE_P(S) (S)->live
659 #define STMT_VINFO_VECTYPE(S) (S)->vectype
660 #define STMT_VINFO_VEC_STMT(S) (S)->vectorized_stmt
661 #define STMT_VINFO_VECTORIZABLE(S) (S)->vectorizable
662 #define STMT_VINFO_DATA_REF(S) (S)->data_ref_info
663 #define STMT_VINFO_GATHER_P(S) (S)->gather_p
664 #define STMT_VINFO_STRIDE_LOAD_P(S) (S)->stride_load_p
665 #define STMT_VINFO_SIMD_LANE_ACCESS_P(S) (S)->simd_lane_access_p
667 #define STMT_VINFO_DR_BASE_ADDRESS(S) (S)->dr_base_address
668 #define STMT_VINFO_DR_INIT(S) (S)->dr_init
669 #define STMT_VINFO_DR_OFFSET(S) (S)->dr_offset
670 #define STMT_VINFO_DR_STEP(S) (S)->dr_step
671 #define STMT_VINFO_DR_ALIGNED_TO(S) (S)->dr_aligned_to
673 #define STMT_VINFO_IN_PATTERN_P(S) (S)->in_pattern_p
674 #define STMT_VINFO_RELATED_STMT(S) (S)->related_stmt
675 #define STMT_VINFO_PATTERN_DEF_SEQ(S) (S)->pattern_def_seq
676 #define STMT_VINFO_SAME_ALIGN_REFS(S) (S)->same_align_refs
677 #define STMT_VINFO_SIMD_CLONE_INFO(S) (S)->simd_clone_info
678 #define STMT_VINFO_DEF_TYPE(S) (S)->def_type
679 #define STMT_VINFO_GROUP_FIRST_ELEMENT(S) (S)->first_element
680 #define STMT_VINFO_GROUP_NEXT_ELEMENT(S) (S)->next_element
681 #define STMT_VINFO_GROUP_SIZE(S) (S)->size
682 #define STMT_VINFO_GROUP_STORE_COUNT(S) (S)->store_count
683 #define STMT_VINFO_GROUP_GAP(S) (S)->gap
684 #define STMT_VINFO_GROUP_SAME_DR_STMT(S) (S)->same_dr_stmt
685 #define STMT_VINFO_GROUPED_ACCESS(S) ((S)->first_element != NULL && (S)->data_ref_info)
686 #define STMT_VINFO_LOOP_PHI_EVOLUTION_PART(S) (S)->loop_phi_evolution_part
687 #define STMT_VINFO_MIN_NEG_DIST(S) (S)->min_neg_dist
689 #define GROUP_FIRST_ELEMENT(S) (S)->first_element
690 #define GROUP_NEXT_ELEMENT(S) (S)->next_element
691 #define GROUP_SIZE(S) (S)->size
692 #define GROUP_STORE_COUNT(S) (S)->store_count
693 #define GROUP_GAP(S) (S)->gap
694 #define GROUP_SAME_DR_STMT(S) (S)->same_dr_stmt
696 #define STMT_VINFO_RELEVANT_P(S) ((S)->relevant != vect_unused_in_scope)
698 #define HYBRID_SLP_STMT(S) ((S)->slp_type == hybrid)
699 #define PURE_SLP_STMT(S) ((S)->slp_type == pure_slp)
700 #define STMT_SLP_TYPE(S) (S)->slp_type
702 struct dataref_aux {
703 tree base_decl;
704 bool base_misaligned;
705 int misalignment;
708 #define VECT_MAX_COST 1000
710 /* The maximum number of intermediate steps required in multi-step type
711 conversion. */
712 #define MAX_INTERM_CVT_STEPS 3
714 /* The maximum vectorization factor supported by any target (V64QI). */
715 #define MAX_VECTORIZATION_FACTOR 64
717 /* Avoid GTY(()) on stmt_vec_info. */
718 typedef void *vec_void_p;
720 extern vec<vec_void_p> stmt_vec_info_vec;
722 void init_stmt_vec_info_vec (void);
723 void free_stmt_vec_info_vec (void);
725 /* Return a stmt_vec_info corresponding to STMT. */
727 static inline stmt_vec_info
728 vinfo_for_stmt (gimple stmt)
730 unsigned int uid = gimple_uid (stmt);
731 if (uid == 0)
732 return NULL;
734 return (stmt_vec_info) stmt_vec_info_vec[uid - 1];
737 /* Set vectorizer information INFO for STMT. */
739 static inline void
740 set_vinfo_for_stmt (gimple stmt, stmt_vec_info info)
742 unsigned int uid = gimple_uid (stmt);
743 if (uid == 0)
745 gcc_checking_assert (info);
746 uid = stmt_vec_info_vec.length () + 1;
747 gimple_set_uid (stmt, uid);
748 stmt_vec_info_vec.safe_push ((vec_void_p) info);
750 else
751 stmt_vec_info_vec[uid - 1] = (vec_void_p) info;
754 /* Return the earlier statement between STMT1 and STMT2. */
756 static inline gimple
757 get_earlier_stmt (gimple stmt1, gimple stmt2)
759 unsigned int uid1, uid2;
761 if (stmt1 == NULL)
762 return stmt2;
764 if (stmt2 == NULL)
765 return stmt1;
767 uid1 = gimple_uid (stmt1);
768 uid2 = gimple_uid (stmt2);
770 if (uid1 == 0 || uid2 == 0)
771 return NULL;
773 gcc_checking_assert (uid1 <= stmt_vec_info_vec.length ()
774 && uid2 <= stmt_vec_info_vec.length ());
776 if (uid1 < uid2)
777 return stmt1;
778 else
779 return stmt2;
782 /* Return the later statement between STMT1 and STMT2. */
784 static inline gimple
785 get_later_stmt (gimple stmt1, gimple stmt2)
787 unsigned int uid1, uid2;
789 if (stmt1 == NULL)
790 return stmt2;
792 if (stmt2 == NULL)
793 return stmt1;
795 uid1 = gimple_uid (stmt1);
796 uid2 = gimple_uid (stmt2);
798 if (uid1 == 0 || uid2 == 0)
799 return NULL;
801 gcc_assert (uid1 <= stmt_vec_info_vec.length ());
802 gcc_assert (uid2 <= stmt_vec_info_vec.length ());
804 if (uid1 > uid2)
805 return stmt1;
806 else
807 return stmt2;
810 /* Return TRUE if a statement represented by STMT_INFO is a part of a
811 pattern. */
813 static inline bool
814 is_pattern_stmt_p (stmt_vec_info stmt_info)
816 gimple related_stmt;
817 stmt_vec_info related_stmt_info;
819 related_stmt = STMT_VINFO_RELATED_STMT (stmt_info);
820 if (related_stmt
821 && (related_stmt_info = vinfo_for_stmt (related_stmt))
822 && STMT_VINFO_IN_PATTERN_P (related_stmt_info))
823 return true;
825 return false;
828 /* Return true if BB is a loop header. */
830 static inline bool
831 is_loop_header_bb_p (basic_block bb)
833 if (bb == (bb->loop_father)->header)
834 return true;
835 gcc_checking_assert (EDGE_COUNT (bb->preds) == 1);
836 return false;
839 /* Return pow2 (X). */
841 static inline int
842 vect_pow2 (int x)
844 int i, res = 1;
846 for (i = 0; i < x; i++)
847 res *= 2;
849 return res;
852 /* Alias targetm.vectorize.builtin_vectorization_cost. */
854 static inline int
855 builtin_vectorization_cost (enum vect_cost_for_stmt type_of_cost,
856 tree vectype, int misalign)
858 return targetm.vectorize.builtin_vectorization_cost (type_of_cost,
859 vectype, misalign);
862 /* Get cost by calling cost target builtin. */
864 static inline
865 int vect_get_stmt_cost (enum vect_cost_for_stmt type_of_cost)
867 return builtin_vectorization_cost (type_of_cost, NULL, 0);
870 /* Alias targetm.vectorize.init_cost. */
872 static inline void *
873 init_cost (struct loop *loop_info)
875 return targetm.vectorize.init_cost (loop_info);
878 /* Alias targetm.vectorize.add_stmt_cost. */
880 static inline unsigned
881 add_stmt_cost (void *data, int count, enum vect_cost_for_stmt kind,
882 stmt_vec_info stmt_info, int misalign,
883 enum vect_cost_model_location where)
885 return targetm.vectorize.add_stmt_cost (data, count, kind,
886 stmt_info, misalign, where);
889 /* Alias targetm.vectorize.finish_cost. */
891 static inline void
892 finish_cost (void *data, unsigned *prologue_cost,
893 unsigned *body_cost, unsigned *epilogue_cost)
895 targetm.vectorize.finish_cost (data, prologue_cost, body_cost, epilogue_cost);
898 /* Alias targetm.vectorize.destroy_cost_data. */
900 static inline void
901 destroy_cost_data (void *data)
903 targetm.vectorize.destroy_cost_data (data);
907 /*-----------------------------------------------------------------*/
908 /* Info on data references alignment. */
909 /*-----------------------------------------------------------------*/
910 inline void
911 set_dr_misalignment (struct data_reference *dr, int val)
913 dataref_aux *data_aux = (dataref_aux *) dr->aux;
915 if (!data_aux)
917 data_aux = XCNEW (dataref_aux);
918 dr->aux = data_aux;
921 data_aux->misalignment = val;
924 inline int
925 dr_misalignment (struct data_reference *dr)
927 gcc_assert (dr->aux);
928 return ((dataref_aux *) dr->aux)->misalignment;
931 /* Reflects actual alignment of first access in the vectorized loop,
932 taking into account peeling/versioning if applied. */
933 #define DR_MISALIGNMENT(DR) dr_misalignment (DR)
934 #define SET_DR_MISALIGNMENT(DR, VAL) set_dr_misalignment (DR, VAL)
936 /* Return TRUE if the data access is aligned, and FALSE otherwise. */
938 static inline bool
939 aligned_access_p (struct data_reference *data_ref_info)
941 return (DR_MISALIGNMENT (data_ref_info) == 0);
944 /* Return TRUE if the alignment of the data access is known, and FALSE
945 otherwise. */
947 static inline bool
948 known_alignment_for_access_p (struct data_reference *data_ref_info)
950 return (DR_MISALIGNMENT (data_ref_info) != -1);
954 /* Return true if the vect cost model is unlimited. */
955 static inline bool
956 unlimited_cost_model (loop_p loop)
958 if (loop != NULL && loop->force_vectorize
959 && flag_simd_cost_model != VECT_COST_MODEL_DEFAULT)
960 return flag_simd_cost_model == VECT_COST_MODEL_UNLIMITED;
961 return (flag_vect_cost_model == VECT_COST_MODEL_UNLIMITED);
964 /* Source location */
965 extern source_location vect_location;
967 /*-----------------------------------------------------------------*/
968 /* Function prototypes. */
969 /*-----------------------------------------------------------------*/
971 /* Simple loop peeling and versioning utilities for vectorizer's purposes -
972 in tree-vect-loop-manip.c. */
973 extern void slpeel_make_loop_iterate_ntimes (struct loop *, tree);
974 extern bool slpeel_can_duplicate_loop_p (const struct loop *, const_edge);
975 struct loop *slpeel_tree_duplicate_loop_to_edge_cfg (struct loop *,
976 struct loop *, edge);
977 extern void vect_loop_versioning (loop_vec_info, unsigned int, bool);
978 extern void vect_do_peeling_for_loop_bound (loop_vec_info, tree, tree,
979 unsigned int, bool);
980 extern void vect_do_peeling_for_alignment (loop_vec_info, tree,
981 unsigned int, bool);
982 extern source_location find_loop_location (struct loop *);
983 extern bool vect_can_advance_ivs_p (loop_vec_info);
985 /* In tree-vect-stmts.c. */
986 extern unsigned int current_vector_size;
987 extern tree get_vectype_for_scalar_type (tree);
988 extern tree get_same_sized_vectype (tree, tree);
989 extern bool vect_is_simple_use (tree, gimple, loop_vec_info,
990 bb_vec_info, gimple *,
991 tree *, enum vect_def_type *);
992 extern bool vect_is_simple_use_1 (tree, gimple, loop_vec_info,
993 bb_vec_info, gimple *,
994 tree *, enum vect_def_type *, tree *);
995 extern bool supportable_widening_operation (enum tree_code, gimple, tree, tree,
996 enum tree_code *, enum tree_code *,
997 int *, vec<tree> *);
998 extern bool supportable_narrowing_operation (enum tree_code, tree, tree,
999 enum tree_code *,
1000 int *, vec<tree> *);
1001 extern stmt_vec_info new_stmt_vec_info (gimple stmt, loop_vec_info,
1002 bb_vec_info);
1003 extern void free_stmt_vec_info (gimple stmt);
1004 extern tree vectorizable_function (gcall *, tree, tree);
1005 extern void vect_model_simple_cost (stmt_vec_info, int, enum vect_def_type *,
1006 stmt_vector_for_cost *,
1007 stmt_vector_for_cost *);
1008 extern void vect_model_store_cost (stmt_vec_info, int, bool,
1009 enum vect_def_type, slp_tree,
1010 stmt_vector_for_cost *,
1011 stmt_vector_for_cost *);
1012 extern void vect_model_load_cost (stmt_vec_info, int, bool, slp_tree,
1013 stmt_vector_for_cost *,
1014 stmt_vector_for_cost *);
1015 extern unsigned record_stmt_cost (stmt_vector_for_cost *, int,
1016 enum vect_cost_for_stmt, stmt_vec_info,
1017 int, enum vect_cost_model_location);
1018 extern void vect_finish_stmt_generation (gimple, gimple,
1019 gimple_stmt_iterator *);
1020 extern bool vect_mark_stmts_to_be_vectorized (loop_vec_info);
1021 extern tree vect_get_vec_def_for_operand (tree, gimple, tree *);
1022 extern tree vect_init_vector (gimple, tree, tree,
1023 gimple_stmt_iterator *);
1024 extern tree vect_get_vec_def_for_stmt_copy (enum vect_def_type, tree);
1025 extern bool vect_transform_stmt (gimple, gimple_stmt_iterator *,
1026 bool *, slp_tree, slp_instance);
1027 extern void vect_remove_stores (gimple);
1028 extern bool vect_analyze_stmt (gimple, bool *, slp_tree);
1029 extern bool vectorizable_condition (gimple, gimple_stmt_iterator *, gimple *,
1030 tree, int, slp_tree);
1031 extern void vect_get_load_cost (struct data_reference *, int, bool,
1032 unsigned int *, unsigned int *,
1033 stmt_vector_for_cost *,
1034 stmt_vector_for_cost *, bool);
1035 extern void vect_get_store_cost (struct data_reference *, int,
1036 unsigned int *, stmt_vector_for_cost *);
1037 extern bool vect_supportable_shift (enum tree_code, tree);
1038 extern void vect_get_vec_defs (tree, tree, gimple, vec<tree> *,
1039 vec<tree> *, slp_tree, int);
1040 extern tree vect_gen_perm_mask_any (tree, const unsigned char *);
1041 extern tree vect_gen_perm_mask_checked (tree, const unsigned char *);
1043 /* In tree-vect-data-refs.c. */
1044 extern bool vect_can_force_dr_alignment_p (const_tree, unsigned int);
1045 extern enum dr_alignment_support vect_supportable_dr_alignment
1046 (struct data_reference *, bool);
1047 extern tree vect_get_smallest_scalar_type (gimple, HOST_WIDE_INT *,
1048 HOST_WIDE_INT *);
1049 extern bool vect_analyze_data_ref_dependences (loop_vec_info, int *);
1050 extern bool vect_slp_analyze_data_ref_dependences (bb_vec_info);
1051 extern bool vect_enhance_data_refs_alignment (loop_vec_info);
1052 extern bool vect_analyze_data_refs_alignment (loop_vec_info, bb_vec_info);
1053 extern bool vect_verify_datarefs_alignment (loop_vec_info, bb_vec_info);
1054 extern bool vect_analyze_data_ref_accesses (loop_vec_info, bb_vec_info);
1055 extern bool vect_prune_runtime_alias_test_list (loop_vec_info);
1056 extern tree vect_check_gather (gimple, loop_vec_info, tree *, tree *,
1057 int *);
1058 extern bool vect_analyze_data_refs (loop_vec_info, bb_vec_info, int *,
1059 unsigned *);
1060 extern tree vect_create_data_ref_ptr (gimple, tree, struct loop *, tree,
1061 tree *, gimple_stmt_iterator *,
1062 gimple *, bool, bool *,
1063 tree = NULL_TREE);
1064 extern tree bump_vector_ptr (tree, gimple, gimple_stmt_iterator *, gimple, tree);
1065 extern tree vect_create_destination_var (tree, tree);
1066 extern bool vect_grouped_store_supported (tree, unsigned HOST_WIDE_INT);
1067 extern bool vect_store_lanes_supported (tree, unsigned HOST_WIDE_INT);
1068 extern bool vect_grouped_load_supported (tree, unsigned HOST_WIDE_INT);
1069 extern bool vect_load_lanes_supported (tree, unsigned HOST_WIDE_INT);
1070 extern void vect_permute_store_chain (vec<tree> ,unsigned int, gimple,
1071 gimple_stmt_iterator *, vec<tree> *);
1072 extern tree vect_setup_realignment (gimple, gimple_stmt_iterator *, tree *,
1073 enum dr_alignment_support, tree,
1074 struct loop **);
1075 extern void vect_transform_grouped_load (gimple, vec<tree> , int,
1076 gimple_stmt_iterator *);
1077 extern void vect_record_grouped_load_vectors (gimple, vec<tree> );
1078 extern tree vect_get_new_vect_var (tree, enum vect_var_kind, const char *);
1079 extern tree vect_create_addr_base_for_vector_ref (gimple, gimple_seq *,
1080 tree, struct loop *,
1081 tree = NULL_TREE);
1083 /* In tree-vect-loop.c. */
1084 /* FORNOW: Used in tree-parloops.c. */
1085 extern void destroy_loop_vec_info (loop_vec_info, bool);
1086 extern gimple vect_force_simple_reduction (loop_vec_info, gimple, bool, bool *);
1087 /* Drive for loop analysis stage. */
1088 extern loop_vec_info vect_analyze_loop (struct loop *);
1089 /* Drive for loop transformation stage. */
1090 extern void vect_transform_loop (loop_vec_info);
1091 extern loop_vec_info vect_analyze_loop_form (struct loop *);
1092 extern bool vectorizable_live_operation (gimple, gimple_stmt_iterator *,
1093 gimple *);
1094 extern bool vectorizable_reduction (gimple, gimple_stmt_iterator *, gimple *,
1095 slp_tree);
1096 extern bool vectorizable_induction (gimple, gimple_stmt_iterator *, gimple *);
1097 extern tree get_initial_def_for_reduction (gimple, tree, tree *);
1098 extern int vect_min_worthwhile_factor (enum tree_code);
1099 extern int vect_get_known_peeling_cost (loop_vec_info, int, int *,
1100 stmt_vector_for_cost *,
1101 stmt_vector_for_cost *,
1102 stmt_vector_for_cost *);
1103 extern int vect_get_single_scalar_iteration_cost (loop_vec_info,
1104 stmt_vector_for_cost *);
1106 /* In tree-vect-slp.c. */
1107 extern void vect_free_slp_instance (slp_instance);
1108 extern bool vect_transform_slp_perm_load (slp_tree, vec<tree> ,
1109 gimple_stmt_iterator *, int,
1110 slp_instance, bool);
1111 extern bool vect_schedule_slp (loop_vec_info, bb_vec_info);
1112 extern void vect_update_slp_costs_according_to_vf (loop_vec_info);
1113 extern bool vect_analyze_slp (loop_vec_info, bb_vec_info, unsigned);
1114 extern bool vect_make_slp_decision (loop_vec_info);
1115 extern void vect_detect_hybrid_slp (loop_vec_info);
1116 extern void vect_get_slp_defs (vec<tree> , slp_tree,
1117 vec<vec<tree> > *, int);
1119 extern source_location find_bb_location (basic_block);
1120 extern bb_vec_info vect_slp_analyze_bb (basic_block);
1121 extern void vect_slp_transform_bb (basic_block);
1123 /* In tree-vect-patterns.c. */
1124 /* Pattern recognition functions.
1125 Additional pattern recognition functions can (and will) be added
1126 in the future. */
1127 typedef gimple (* vect_recog_func_ptr) (vec<gimple> *, tree *, tree *);
1128 #define NUM_PATTERNS 12
1129 void vect_pattern_recog (loop_vec_info, bb_vec_info);
1131 /* In tree-vectorizer.c. */
1132 unsigned vectorize_loops (void);
1133 void vect_destroy_datarefs (loop_vec_info, bb_vec_info);
1135 #endif /* GCC_TREE_VECTORIZER_H */