[RS6000] push_secondary_reload ICE
[official-gcc.git] / gcc / tree-vectorizer.h
blob2cfb72a6fa3ac17100fdf7086f96e96e4145147a
1 /* Vectorizer
2 Copyright (C) 2003-2016 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,
32 vect_mask_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 type of reduction. */
65 enum vect_reduction_type {
66 TREE_CODE_REDUCTION,
67 COND_REDUCTION,
68 INTEGER_INDUC_COND_REDUCTION
71 #define VECTORIZABLE_CYCLE_DEF(D) (((D) == vect_reduction_def) \
72 || ((D) == vect_double_reduction_def) \
73 || ((D) == vect_nested_cycle))
75 /* Structure to encapsulate information about a group of like
76 instructions to be presented to the target cost model. */
77 struct stmt_info_for_cost {
78 int count;
79 enum vect_cost_for_stmt kind;
80 gimple *stmt;
81 int misalign;
84 typedef vec<stmt_info_for_cost> stmt_vector_for_cost;
86 /************************************************************************
87 SLP
88 ************************************************************************/
89 typedef struct _slp_tree *slp_tree;
91 /* A computation tree of an SLP instance. Each node corresponds to a group of
92 stmts to be packed in a SIMD stmt. */
93 struct _slp_tree {
94 /* Nodes that contain def-stmts of this node statements operands. */
95 vec<slp_tree> children;
96 /* A group of scalar stmts to be vectorized together. */
97 vec<gimple *> stmts;
98 /* Load permutation relative to the stores, NULL if there is no
99 permutation. */
100 vec<unsigned> load_permutation;
101 /* Vectorized stmt/s. */
102 vec<gimple *> vec_stmts;
103 /* Number of vector stmts that are created to replace the group of scalar
104 stmts. It is calculated during the transformation phase as the number of
105 scalar elements in one scalar iteration (GROUP_SIZE) multiplied by VF
106 divided by vector size. */
107 unsigned int vec_stmts_size;
108 /* Whether the scalar computations use two different operators. */
109 bool two_operators;
110 /* The DEF type of this node. */
111 enum vect_def_type def_type;
115 /* SLP instance is a sequence of stmts in a loop that can be packed into
116 SIMD stmts. */
117 typedef struct _slp_instance {
118 /* The root of SLP tree. */
119 slp_tree root;
121 /* Size of groups of scalar stmts that will be replaced by SIMD stmt/s. */
122 unsigned int group_size;
124 /* The unrolling factor required to vectorized this SLP instance. */
125 unsigned int unrolling_factor;
127 /* The group of nodes that contain loads of this SLP instance. */
128 vec<slp_tree> loads;
129 } *slp_instance;
132 /* Access Functions. */
133 #define SLP_INSTANCE_TREE(S) (S)->root
134 #define SLP_INSTANCE_GROUP_SIZE(S) (S)->group_size
135 #define SLP_INSTANCE_UNROLLING_FACTOR(S) (S)->unrolling_factor
136 #define SLP_INSTANCE_LOADS(S) (S)->loads
138 #define SLP_TREE_CHILDREN(S) (S)->children
139 #define SLP_TREE_SCALAR_STMTS(S) (S)->stmts
140 #define SLP_TREE_VEC_STMTS(S) (S)->vec_stmts
141 #define SLP_TREE_NUMBER_OF_VEC_STMTS(S) (S)->vec_stmts_size
142 #define SLP_TREE_LOAD_PERMUTATION(S) (S)->load_permutation
143 #define SLP_TREE_TWO_OPERATORS(S) (S)->two_operators
144 #define SLP_TREE_DEF_TYPE(S) (S)->def_type
148 /* This struct is used to store the information of a data reference,
149 including the data ref itself and the segment length for aliasing
150 checks. This is used to merge alias checks. */
152 struct dr_with_seg_len
154 dr_with_seg_len (data_reference_p d, tree len)
155 : dr (d), seg_len (len) {}
157 data_reference_p dr;
158 tree seg_len;
161 /* This struct contains two dr_with_seg_len objects with aliasing data
162 refs. Two comparisons are generated from them. */
164 struct dr_with_seg_len_pair_t
166 dr_with_seg_len_pair_t (const dr_with_seg_len& d1,
167 const dr_with_seg_len& d2)
168 : first (d1), second (d2) {}
170 dr_with_seg_len first;
171 dr_with_seg_len second;
176 /* Vectorizer state common between loop and basic-block vectorization. */
177 struct vec_info {
178 enum { bb, loop } kind;
180 /* All SLP instances. */
181 vec<slp_instance> slp_instances;
183 /* All data references. */
184 vec<data_reference_p> datarefs;
186 /* All data dependences. */
187 vec<ddr_p> ddrs;
189 /* All interleaving chains of stores, represented by the first
190 stmt in the chain. */
191 vec<gimple *> grouped_stores;
193 /* Cost data used by the target cost model. */
194 void *target_cost_data;
197 struct _loop_vec_info;
198 struct _bb_vec_info;
200 template<>
201 template<>
202 inline bool
203 is_a_helper <_loop_vec_info *>::test (vec_info *i)
205 return i->kind == vec_info::loop;
208 template<>
209 template<>
210 inline bool
211 is_a_helper <_bb_vec_info *>::test (vec_info *i)
213 return i->kind == vec_info::bb;
217 /*-----------------------------------------------------------------*/
218 /* Info on vectorized loops. */
219 /*-----------------------------------------------------------------*/
220 typedef struct _loop_vec_info : public vec_info {
222 /* The loop to which this info struct refers to. */
223 struct loop *loop;
225 /* The loop basic blocks. */
226 basic_block *bbs;
228 /* Number of latch executions. */
229 tree num_itersm1;
230 /* Number of iterations. */
231 tree num_iters;
232 /* Number of iterations of the original loop. */
233 tree num_iters_unchanged;
235 /* Threshold of number of iterations below which vectorzation will not be
236 performed. It is calculated from MIN_PROFITABLE_ITERS and
237 PARAM_MIN_VECT_LOOP_BOUND. */
238 unsigned int th;
240 /* Is the loop vectorizable? */
241 bool vectorizable;
243 /* Unrolling factor */
244 int vectorization_factor;
246 /* Unknown DRs according to which loop was peeled. */
247 struct data_reference *unaligned_dr;
249 /* peeling_for_alignment indicates whether peeling for alignment will take
250 place, and what the peeling factor should be:
251 peeling_for_alignment = X means:
252 If X=0: Peeling for alignment will not be applied.
253 If X>0: Peel first X iterations.
254 If X=-1: Generate a runtime test to calculate the number of iterations
255 to be peeled, using the dataref recorded in the field
256 unaligned_dr. */
257 int peeling_for_alignment;
259 /* The mask used to check the alignment of pointers or arrays. */
260 int ptr_mask;
262 /* The loop nest in which the data dependences are computed. */
263 vec<loop_p> loop_nest;
265 /* Data Dependence Relations defining address ranges that are candidates
266 for a run-time aliasing check. */
267 vec<ddr_p> may_alias_ddrs;
269 /* Data Dependence Relations defining address ranges together with segment
270 lengths from which the run-time aliasing check is built. */
271 vec<dr_with_seg_len_pair_t> comp_alias_ddrs;
273 /* Statements in the loop that have data references that are candidates for a
274 runtime (loop versioning) misalignment check. */
275 vec<gimple *> may_misalign_stmts;
277 /* The unrolling factor needed to SLP the loop. In case of that pure SLP is
278 applied to the loop, i.e., no unrolling is needed, this is 1. */
279 unsigned slp_unrolling_factor;
281 /* Reduction cycles detected in the loop. Used in loop-aware SLP. */
282 vec<gimple *> reductions;
284 /* All reduction chains in the loop, represented by the first
285 stmt in the chain. */
286 vec<gimple *> reduction_chains;
288 /* Cost vector for a single scalar iteration. */
289 vec<stmt_info_for_cost> scalar_cost_vec;
291 /* Cost of a single scalar iteration. */
292 int single_scalar_iteration_cost;
294 /* When we have grouped data accesses with gaps, we may introduce invalid
295 memory accesses. We peel the last iteration of the loop to prevent
296 this. */
297 bool peeling_for_gaps;
299 /* When the number of iterations is not a multiple of the vector size
300 we need to peel off iterations at the end to form an epilogue loop. */
301 bool peeling_for_niter;
303 /* Reductions are canonicalized so that the last operand is the reduction
304 operand. If this places a constant into RHS1, this decanonicalizes
305 GIMPLE for other phases, so we must track when this has occurred and
306 fix it up. */
307 bool operands_swapped;
309 /* True if there are no loop carried data dependencies in the loop.
310 If loop->safelen <= 1, then this is always true, either the loop
311 didn't have any loop carried data dependencies, or the loop is being
312 vectorized guarded with some runtime alias checks, or couldn't
313 be vectorized at all, but then this field shouldn't be used.
314 For loop->safelen >= 2, the user has asserted that there are no
315 backward dependencies, but there still could be loop carried forward
316 dependencies in such loops. This flag will be false if normal
317 vectorizer data dependency analysis would fail or require versioning
318 for alias, but because of loop->safelen >= 2 it has been vectorized
319 even without versioning for alias. E.g. in:
320 #pragma omp simd
321 for (int i = 0; i < m; i++)
322 a[i] = a[i + k] * c;
323 (or #pragma simd or #pragma ivdep) we can vectorize this and it will
324 DTRT even for k > 0 && k < m, but without safelen we would not
325 vectorize this, so this field would be false. */
326 bool no_data_dependencies;
328 /* If if-conversion versioned this loop before conversion, this is the
329 loop version without if-conversion. */
330 struct loop *scalar_loop;
332 /* Mark loops having masked stores. */
333 bool has_mask_store;
335 } *loop_vec_info;
337 /* Access Functions. */
338 #define LOOP_VINFO_LOOP(L) (L)->loop
339 #define LOOP_VINFO_BBS(L) (L)->bbs
340 #define LOOP_VINFO_NITERSM1(L) (L)->num_itersm1
341 #define LOOP_VINFO_NITERS(L) (L)->num_iters
342 /* Since LOOP_VINFO_NITERS and LOOP_VINFO_NITERSM1 can change after
343 prologue peeling retain total unchanged scalar loop iterations for
344 cost model. */
345 #define LOOP_VINFO_NITERS_UNCHANGED(L) (L)->num_iters_unchanged
346 #define LOOP_VINFO_COST_MODEL_THRESHOLD(L) (L)->th
347 #define LOOP_VINFO_VECTORIZABLE_P(L) (L)->vectorizable
348 #define LOOP_VINFO_VECT_FACTOR(L) (L)->vectorization_factor
349 #define LOOP_VINFO_PTR_MASK(L) (L)->ptr_mask
350 #define LOOP_VINFO_LOOP_NEST(L) (L)->loop_nest
351 #define LOOP_VINFO_DATAREFS(L) (L)->datarefs
352 #define LOOP_VINFO_DDRS(L) (L)->ddrs
353 #define LOOP_VINFO_INT_NITERS(L) (TREE_INT_CST_LOW ((L)->num_iters))
354 #define LOOP_VINFO_PEELING_FOR_ALIGNMENT(L) (L)->peeling_for_alignment
355 #define LOOP_VINFO_UNALIGNED_DR(L) (L)->unaligned_dr
356 #define LOOP_VINFO_MAY_MISALIGN_STMTS(L) (L)->may_misalign_stmts
357 #define LOOP_VINFO_MAY_ALIAS_DDRS(L) (L)->may_alias_ddrs
358 #define LOOP_VINFO_COMP_ALIAS_DDRS(L) (L)->comp_alias_ddrs
359 #define LOOP_VINFO_GROUPED_STORES(L) (L)->grouped_stores
360 #define LOOP_VINFO_SLP_INSTANCES(L) (L)->slp_instances
361 #define LOOP_VINFO_SLP_UNROLLING_FACTOR(L) (L)->slp_unrolling_factor
362 #define LOOP_VINFO_REDUCTIONS(L) (L)->reductions
363 #define LOOP_VINFO_REDUCTION_CHAINS(L) (L)->reduction_chains
364 #define LOOP_VINFO_TARGET_COST_DATA(L) (L)->target_cost_data
365 #define LOOP_VINFO_PEELING_FOR_GAPS(L) (L)->peeling_for_gaps
366 #define LOOP_VINFO_OPERANDS_SWAPPED(L) (L)->operands_swapped
367 #define LOOP_VINFO_PEELING_FOR_NITER(L) (L)->peeling_for_niter
368 #define LOOP_VINFO_NO_DATA_DEPENDENCIES(L) (L)->no_data_dependencies
369 #define LOOP_VINFO_SCALAR_LOOP(L) (L)->scalar_loop
370 #define LOOP_VINFO_HAS_MASK_STORE(L) (L)->has_mask_store
371 #define LOOP_VINFO_SCALAR_ITERATION_COST(L) (L)->scalar_cost_vec
372 #define LOOP_VINFO_SINGLE_SCALAR_ITERATION_COST(L) (L)->single_scalar_iteration_cost
374 #define LOOP_REQUIRES_VERSIONING_FOR_ALIGNMENT(L) \
375 ((L)->may_misalign_stmts.length () > 0)
376 #define LOOP_REQUIRES_VERSIONING_FOR_ALIAS(L) \
377 ((L)->may_alias_ddrs.length () > 0)
379 #define LOOP_VINFO_NITERS_KNOWN_P(L) \
380 (tree_fits_shwi_p ((L)->num_iters) && tree_to_shwi ((L)->num_iters) > 0)
382 static inline loop_vec_info
383 loop_vec_info_for_loop (struct loop *loop)
385 return (loop_vec_info) loop->aux;
388 static inline bool
389 nested_in_vect_loop_p (struct loop *loop, gimple *stmt)
391 return (loop->inner
392 && (loop->inner == (gimple_bb (stmt))->loop_father));
395 typedef struct _bb_vec_info : public vec_info
397 basic_block bb;
398 gimple_stmt_iterator region_begin;
399 gimple_stmt_iterator region_end;
400 } *bb_vec_info;
402 #define BB_VINFO_BB(B) (B)->bb
403 #define BB_VINFO_GROUPED_STORES(B) (B)->grouped_stores
404 #define BB_VINFO_SLP_INSTANCES(B) (B)->slp_instances
405 #define BB_VINFO_DATAREFS(B) (B)->datarefs
406 #define BB_VINFO_DDRS(B) (B)->ddrs
407 #define BB_VINFO_TARGET_COST_DATA(B) (B)->target_cost_data
409 static inline bb_vec_info
410 vec_info_for_bb (basic_block bb)
412 return (bb_vec_info) bb->aux;
415 /*-----------------------------------------------------------------*/
416 /* Info on vectorized defs. */
417 /*-----------------------------------------------------------------*/
418 enum stmt_vec_info_type {
419 undef_vec_info_type = 0,
420 load_vec_info_type,
421 store_vec_info_type,
422 shift_vec_info_type,
423 op_vec_info_type,
424 call_vec_info_type,
425 call_simd_clone_vec_info_type,
426 assignment_vec_info_type,
427 condition_vec_info_type,
428 comparison_vec_info_type,
429 reduc_vec_info_type,
430 induc_vec_info_type,
431 type_promotion_vec_info_type,
432 type_demotion_vec_info_type,
433 type_conversion_vec_info_type,
434 loop_exit_ctrl_vec_info_type
437 /* Indicates whether/how a variable is used in the scope of loop/basic
438 block. */
439 enum vect_relevant {
440 vect_unused_in_scope = 0,
442 /* The def is only used outside the loop. */
443 vect_used_only_live,
444 /* The def is in the inner loop, and the use is in the outer loop, and the
445 use is a reduction stmt. */
446 vect_used_in_outer_by_reduction,
447 /* The def is in the inner loop, and the use is in the outer loop (and is
448 not part of reduction). */
449 vect_used_in_outer,
451 /* defs that feed computations that end up (only) in a reduction. These
452 defs may be used by non-reduction stmts, but eventually, any
453 computations/values that are affected by these defs are used to compute
454 a reduction (i.e. don't get stored to memory, for example). We use this
455 to identify computations that we can change the order in which they are
456 computed. */
457 vect_used_by_reduction,
459 vect_used_in_scope
462 /* The type of vectorization that can be applied to the stmt: regular loop-based
463 vectorization; pure SLP - the stmt is a part of SLP instances and does not
464 have uses outside SLP instances; or hybrid SLP and loop-based - the stmt is
465 a part of SLP instance and also must be loop-based vectorized, since it has
466 uses outside SLP sequences.
468 In the loop context the meanings of pure and hybrid SLP are slightly
469 different. By saying that pure SLP is applied to the loop, we mean that we
470 exploit only intra-iteration parallelism in the loop; i.e., the loop can be
471 vectorized without doing any conceptual unrolling, cause we don't pack
472 together stmts from different iterations, only within a single iteration.
473 Loop hybrid SLP means that we exploit both intra-iteration and
474 inter-iteration parallelism (e.g., number of elements in the vector is 4
475 and the slp-group-size is 2, in which case we don't have enough parallelism
476 within an iteration, so we obtain the rest of the parallelism from subsequent
477 iterations by unrolling the loop by 2). */
478 enum slp_vect_type {
479 loop_vect = 0,
480 pure_slp,
481 hybrid
484 /* Describes how we're going to vectorize an individual load or store,
485 or a group of loads or stores. */
486 enum vect_memory_access_type {
487 /* An access to an invariant address. This is used only for loads. */
488 VMAT_INVARIANT,
490 /* A simple contiguous access. */
491 VMAT_CONTIGUOUS,
493 /* A contiguous access that goes down in memory rather than up,
494 with no additional permutation. This is used only for stores
495 of invariants. */
496 VMAT_CONTIGUOUS_DOWN,
498 /* A simple contiguous access in which the elements need to be permuted
499 after loading or before storing. Only used for loop vectorization;
500 SLP uses separate permutes. */
501 VMAT_CONTIGUOUS_PERMUTE,
503 /* A simple contiguous access in which the elements need to be reversed
504 after loading or before storing. */
505 VMAT_CONTIGUOUS_REVERSE,
507 /* An access that uses IFN_LOAD_LANES or IFN_STORE_LANES. */
508 VMAT_LOAD_STORE_LANES,
510 /* An access in which each scalar element is loaded or stored
511 individually. */
512 VMAT_ELEMENTWISE,
514 /* A hybrid of VMAT_CONTIGUOUS and VMAT_ELEMENTWISE, used for grouped
515 SLP accesses. Each unrolled iteration uses a contiguous load
516 or store for the whole group, but the groups from separate iterations
517 are combined in the same way as for VMAT_ELEMENTWISE. */
518 VMAT_STRIDED_SLP,
520 /* The access uses gather loads or scatter stores. */
521 VMAT_GATHER_SCATTER
524 typedef struct data_reference *dr_p;
526 typedef struct _stmt_vec_info {
528 enum stmt_vec_info_type type;
530 /* Indicates whether this stmts is part of a computation whose result is
531 used outside the loop. */
532 bool live;
534 /* Stmt is part of some pattern (computation idiom) */
535 bool in_pattern_p;
537 /* The stmt to which this info struct refers to. */
538 gimple *stmt;
540 /* The vec_info with respect to which STMT is vectorized. */
541 vec_info *vinfo;
543 /* The vector type to be used for the LHS of this statement. */
544 tree vectype;
546 /* The vectorized version of the stmt. */
547 gimple *vectorized_stmt;
550 /** The following is relevant only for stmts that contain a non-scalar
551 data-ref (array/pointer/struct access). A GIMPLE stmt is expected to have
552 at most one such data-ref. **/
554 /* Information about the data-ref (access function, etc),
555 relative to the inner-most containing loop. */
556 struct data_reference *data_ref_info;
558 /* Information about the data-ref relative to this loop
559 nest (the loop that is being considered for vectorization). */
560 tree dr_base_address;
561 tree dr_init;
562 tree dr_offset;
563 tree dr_step;
564 tree dr_aligned_to;
566 /* For loop PHI nodes, the base and evolution part of it. This makes sure
567 this information is still available in vect_update_ivs_after_vectorizer
568 where we may not be able to re-analyze the PHI nodes evolution as
569 peeling for the prologue loop can make it unanalyzable. The evolution
570 part is still correct after peeling, but the base may have changed from
571 the version here. */
572 tree loop_phi_evolution_base_unchanged;
573 tree loop_phi_evolution_part;
575 /* Used for various bookkeeping purposes, generally holding a pointer to
576 some other stmt S that is in some way "related" to this stmt.
577 Current use of this field is:
578 If this stmt is part of a pattern (i.e. the field 'in_pattern_p' is
579 true): S is the "pattern stmt" that represents (and replaces) the
580 sequence of stmts that constitutes the pattern. Similarly, the
581 related_stmt of the "pattern stmt" points back to this stmt (which is
582 the last stmt in the original sequence of stmts that constitutes the
583 pattern). */
584 gimple *related_stmt;
586 /* Used to keep a sequence of def stmts of a pattern stmt if such exists. */
587 gimple_seq pattern_def_seq;
589 /* List of datarefs that are known to have the same alignment as the dataref
590 of this stmt. */
591 vec<dr_p> same_align_refs;
593 /* Selected SIMD clone's function info. First vector element
594 is SIMD clone's function decl, followed by a pair of trees (base + step)
595 for linear arguments (pair of NULLs for other arguments). */
596 vec<tree> simd_clone_info;
598 /* Classify the def of this stmt. */
599 enum vect_def_type def_type;
601 /* Whether the stmt is SLPed, loop-based vectorized, or both. */
602 enum slp_vect_type slp_type;
604 /* Interleaving and reduction chains info. */
605 /* First element in the group. */
606 gimple *first_element;
607 /* Pointer to the next element in the group. */
608 gimple *next_element;
609 /* For data-refs, in case that two or more stmts share data-ref, this is the
610 pointer to the previously detected stmt with the same dr. */
611 gimple *same_dr_stmt;
612 /* The size of the group. */
613 unsigned int size;
614 /* For stores, number of stores from this group seen. We vectorize the last
615 one. */
616 unsigned int store_count;
617 /* For loads only, the gap from the previous load. For consecutive loads, GAP
618 is 1. */
619 unsigned int gap;
621 /* The minimum negative dependence distance this stmt participates in
622 or zero if none. */
623 unsigned int min_neg_dist;
625 /* Not all stmts in the loop need to be vectorized. e.g, the increment
626 of the loop induction variable and computation of array indexes. relevant
627 indicates whether the stmt needs to be vectorized. */
628 enum vect_relevant relevant;
630 /* Is this statement vectorizable or should it be skipped in (partial)
631 vectorization. */
632 bool vectorizable;
634 /* For loads if this is a gather, for stores if this is a scatter. */
635 bool gather_scatter_p;
637 /* True if this is an access with loop-invariant stride. */
638 bool strided_p;
640 /* Classifies how the load or store is going to be implemented
641 for loop vectorization. */
642 vect_memory_access_type memory_access_type;
644 /* For both loads and stores. */
645 bool simd_lane_access_p;
647 /* For reduction loops, this is the type of reduction. */
648 enum vect_reduction_type v_reduc_type;
650 /* The number of scalar stmt references from active SLP instances. */
651 unsigned int num_slp_uses;
652 } *stmt_vec_info;
654 /* Information about a gather/scatter call. */
655 struct gather_scatter_info {
656 /* The FUNCTION_DECL for the built-in gather/scatter function. */
657 tree decl;
659 /* The loop-invariant base value. */
660 tree base;
662 /* The original scalar offset, which is a non-loop-invariant SSA_NAME. */
663 tree offset;
665 /* Each offset element should be multiplied by this amount before
666 being added to the base. */
667 int scale;
669 /* The definition type for the vectorized offset. */
670 enum vect_def_type offset_dt;
672 /* The type of the vectorized offset. */
673 tree offset_vectype;
676 /* Access Functions. */
677 #define STMT_VINFO_TYPE(S) (S)->type
678 #define STMT_VINFO_STMT(S) (S)->stmt
679 inline loop_vec_info
680 STMT_VINFO_LOOP_VINFO (stmt_vec_info stmt_vinfo)
682 if (loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (stmt_vinfo->vinfo))
683 return loop_vinfo;
684 return NULL;
686 inline bb_vec_info
687 STMT_VINFO_BB_VINFO (stmt_vec_info stmt_vinfo)
689 if (bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (stmt_vinfo->vinfo))
690 return bb_vinfo;
691 return NULL;
693 #define STMT_VINFO_RELEVANT(S) (S)->relevant
694 #define STMT_VINFO_LIVE_P(S) (S)->live
695 #define STMT_VINFO_VECTYPE(S) (S)->vectype
696 #define STMT_VINFO_VEC_STMT(S) (S)->vectorized_stmt
697 #define STMT_VINFO_VECTORIZABLE(S) (S)->vectorizable
698 #define STMT_VINFO_DATA_REF(S) (S)->data_ref_info
699 #define STMT_VINFO_GATHER_SCATTER_P(S) (S)->gather_scatter_p
700 #define STMT_VINFO_STRIDED_P(S) (S)->strided_p
701 #define STMT_VINFO_MEMORY_ACCESS_TYPE(S) (S)->memory_access_type
702 #define STMT_VINFO_SIMD_LANE_ACCESS_P(S) (S)->simd_lane_access_p
703 #define STMT_VINFO_VEC_REDUCTION_TYPE(S) (S)->v_reduc_type
705 #define STMT_VINFO_DR_BASE_ADDRESS(S) (S)->dr_base_address
706 #define STMT_VINFO_DR_INIT(S) (S)->dr_init
707 #define STMT_VINFO_DR_OFFSET(S) (S)->dr_offset
708 #define STMT_VINFO_DR_STEP(S) (S)->dr_step
709 #define STMT_VINFO_DR_ALIGNED_TO(S) (S)->dr_aligned_to
711 #define STMT_VINFO_IN_PATTERN_P(S) (S)->in_pattern_p
712 #define STMT_VINFO_RELATED_STMT(S) (S)->related_stmt
713 #define STMT_VINFO_PATTERN_DEF_SEQ(S) (S)->pattern_def_seq
714 #define STMT_VINFO_SAME_ALIGN_REFS(S) (S)->same_align_refs
715 #define STMT_VINFO_SIMD_CLONE_INFO(S) (S)->simd_clone_info
716 #define STMT_VINFO_DEF_TYPE(S) (S)->def_type
717 #define STMT_VINFO_GROUP_FIRST_ELEMENT(S) (S)->first_element
718 #define STMT_VINFO_GROUP_NEXT_ELEMENT(S) (S)->next_element
719 #define STMT_VINFO_GROUP_SIZE(S) (S)->size
720 #define STMT_VINFO_GROUP_STORE_COUNT(S) (S)->store_count
721 #define STMT_VINFO_GROUP_GAP(S) (S)->gap
722 #define STMT_VINFO_GROUP_SAME_DR_STMT(S) (S)->same_dr_stmt
723 #define STMT_VINFO_GROUPED_ACCESS(S) ((S)->first_element != NULL && (S)->data_ref_info)
724 #define STMT_VINFO_LOOP_PHI_EVOLUTION_BASE_UNCHANGED(S) (S)->loop_phi_evolution_base_unchanged
725 #define STMT_VINFO_LOOP_PHI_EVOLUTION_PART(S) (S)->loop_phi_evolution_part
726 #define STMT_VINFO_MIN_NEG_DIST(S) (S)->min_neg_dist
727 #define STMT_VINFO_NUM_SLP_USES(S) (S)->num_slp_uses
729 #define GROUP_FIRST_ELEMENT(S) (S)->first_element
730 #define GROUP_NEXT_ELEMENT(S) (S)->next_element
731 #define GROUP_SIZE(S) (S)->size
732 #define GROUP_STORE_COUNT(S) (S)->store_count
733 #define GROUP_GAP(S) (S)->gap
734 #define GROUP_SAME_DR_STMT(S) (S)->same_dr_stmt
736 #define STMT_VINFO_RELEVANT_P(S) ((S)->relevant != vect_unused_in_scope)
738 #define HYBRID_SLP_STMT(S) ((S)->slp_type == hybrid)
739 #define PURE_SLP_STMT(S) ((S)->slp_type == pure_slp)
740 #define STMT_SLP_TYPE(S) (S)->slp_type
742 struct dataref_aux {
743 int misalignment;
744 /* If true the alignment of base_decl needs to be increased. */
745 bool base_misaligned;
746 /* If true we know the base is at least vector element alignment aligned. */
747 bool base_element_aligned;
748 tree base_decl;
751 #define DR_VECT_AUX(dr) ((dataref_aux *)(dr)->aux)
753 #define VECT_MAX_COST 1000
755 /* The maximum number of intermediate steps required in multi-step type
756 conversion. */
757 #define MAX_INTERM_CVT_STEPS 3
759 /* The maximum vectorization factor supported by any target (V64QI). */
760 #define MAX_VECTORIZATION_FACTOR 64
762 extern vec<stmt_vec_info> stmt_vec_info_vec;
764 void init_stmt_vec_info_vec (void);
765 void free_stmt_vec_info_vec (void);
767 /* Return a stmt_vec_info corresponding to STMT. */
769 static inline stmt_vec_info
770 vinfo_for_stmt (gimple *stmt)
772 unsigned int uid = gimple_uid (stmt);
773 if (uid == 0)
774 return NULL;
776 return stmt_vec_info_vec[uid - 1];
779 /* Set vectorizer information INFO for STMT. */
781 static inline void
782 set_vinfo_for_stmt (gimple *stmt, stmt_vec_info info)
784 unsigned int uid = gimple_uid (stmt);
785 if (uid == 0)
787 gcc_checking_assert (info);
788 uid = stmt_vec_info_vec.length () + 1;
789 gimple_set_uid (stmt, uid);
790 stmt_vec_info_vec.safe_push (info);
792 else
794 gcc_checking_assert (info == NULL);
795 stmt_vec_info_vec[uid - 1] = info;
799 /* Return the earlier statement between STMT1 and STMT2. */
801 static inline gimple *
802 get_earlier_stmt (gimple *stmt1, gimple *stmt2)
804 unsigned int uid1, uid2;
806 if (stmt1 == NULL)
807 return stmt2;
809 if (stmt2 == NULL)
810 return stmt1;
812 uid1 = gimple_uid (stmt1);
813 uid2 = gimple_uid (stmt2);
815 if (uid1 == 0 || uid2 == 0)
816 return NULL;
818 gcc_checking_assert (uid1 <= stmt_vec_info_vec.length ()
819 && uid2 <= stmt_vec_info_vec.length ());
821 if (uid1 < uid2)
822 return stmt1;
823 else
824 return stmt2;
827 /* Return the later statement between STMT1 and STMT2. */
829 static inline gimple *
830 get_later_stmt (gimple *stmt1, gimple *stmt2)
832 unsigned int uid1, uid2;
834 if (stmt1 == NULL)
835 return stmt2;
837 if (stmt2 == NULL)
838 return stmt1;
840 uid1 = gimple_uid (stmt1);
841 uid2 = gimple_uid (stmt2);
843 if (uid1 == 0 || uid2 == 0)
844 return NULL;
846 gcc_assert (uid1 <= stmt_vec_info_vec.length ());
847 gcc_assert (uid2 <= stmt_vec_info_vec.length ());
849 if (uid1 > uid2)
850 return stmt1;
851 else
852 return stmt2;
855 /* Return TRUE if a statement represented by STMT_INFO is a part of a
856 pattern. */
858 static inline bool
859 is_pattern_stmt_p (stmt_vec_info stmt_info)
861 gimple *related_stmt;
862 stmt_vec_info related_stmt_info;
864 related_stmt = STMT_VINFO_RELATED_STMT (stmt_info);
865 if (related_stmt
866 && (related_stmt_info = vinfo_for_stmt (related_stmt))
867 && STMT_VINFO_IN_PATTERN_P (related_stmt_info))
868 return true;
870 return false;
873 /* Return true if BB is a loop header. */
875 static inline bool
876 is_loop_header_bb_p (basic_block bb)
878 if (bb == (bb->loop_father)->header)
879 return true;
880 gcc_checking_assert (EDGE_COUNT (bb->preds) == 1);
881 return false;
884 /* Return pow2 (X). */
886 static inline int
887 vect_pow2 (int x)
889 int i, res = 1;
891 for (i = 0; i < x; i++)
892 res *= 2;
894 return res;
897 /* Alias targetm.vectorize.builtin_vectorization_cost. */
899 static inline int
900 builtin_vectorization_cost (enum vect_cost_for_stmt type_of_cost,
901 tree vectype, int misalign)
903 return targetm.vectorize.builtin_vectorization_cost (type_of_cost,
904 vectype, misalign);
907 /* Get cost by calling cost target builtin. */
909 static inline
910 int vect_get_stmt_cost (enum vect_cost_for_stmt type_of_cost)
912 return builtin_vectorization_cost (type_of_cost, NULL, 0);
915 /* Alias targetm.vectorize.init_cost. */
917 static inline void *
918 init_cost (struct loop *loop_info)
920 return targetm.vectorize.init_cost (loop_info);
923 /* Alias targetm.vectorize.add_stmt_cost. */
925 static inline unsigned
926 add_stmt_cost (void *data, int count, enum vect_cost_for_stmt kind,
927 stmt_vec_info stmt_info, int misalign,
928 enum vect_cost_model_location where)
930 return targetm.vectorize.add_stmt_cost (data, count, kind,
931 stmt_info, misalign, where);
934 /* Alias targetm.vectorize.finish_cost. */
936 static inline void
937 finish_cost (void *data, unsigned *prologue_cost,
938 unsigned *body_cost, unsigned *epilogue_cost)
940 targetm.vectorize.finish_cost (data, prologue_cost, body_cost, epilogue_cost);
943 /* Alias targetm.vectorize.destroy_cost_data. */
945 static inline void
946 destroy_cost_data (void *data)
948 targetm.vectorize.destroy_cost_data (data);
951 /*-----------------------------------------------------------------*/
952 /* Info on data references alignment. */
953 /*-----------------------------------------------------------------*/
954 inline void
955 set_dr_misalignment (struct data_reference *dr, int val)
957 dataref_aux *data_aux = DR_VECT_AUX (dr);
959 if (!data_aux)
961 data_aux = XCNEW (dataref_aux);
962 dr->aux = data_aux;
965 data_aux->misalignment = val;
968 inline int
969 dr_misalignment (struct data_reference *dr)
971 return DR_VECT_AUX (dr)->misalignment;
974 /* Reflects actual alignment of first access in the vectorized loop,
975 taking into account peeling/versioning if applied. */
976 #define DR_MISALIGNMENT(DR) dr_misalignment (DR)
977 #define SET_DR_MISALIGNMENT(DR, VAL) set_dr_misalignment (DR, VAL)
979 /* Return TRUE if the data access is aligned, and FALSE otherwise. */
981 static inline bool
982 aligned_access_p (struct data_reference *data_ref_info)
984 return (DR_MISALIGNMENT (data_ref_info) == 0);
987 /* Return TRUE if the alignment of the data access is known, and FALSE
988 otherwise. */
990 static inline bool
991 known_alignment_for_access_p (struct data_reference *data_ref_info)
993 return (DR_MISALIGNMENT (data_ref_info) != -1);
997 /* Return true if the vect cost model is unlimited. */
998 static inline bool
999 unlimited_cost_model (loop_p loop)
1001 if (loop != NULL && loop->force_vectorize
1002 && flag_simd_cost_model != VECT_COST_MODEL_DEFAULT)
1003 return flag_simd_cost_model == VECT_COST_MODEL_UNLIMITED;
1004 return (flag_vect_cost_model == VECT_COST_MODEL_UNLIMITED);
1007 /* Source location */
1008 extern source_location vect_location;
1010 /*-----------------------------------------------------------------*/
1011 /* Function prototypes. */
1012 /*-----------------------------------------------------------------*/
1014 /* Simple loop peeling and versioning utilities for vectorizer's purposes -
1015 in tree-vect-loop-manip.c. */
1016 extern void slpeel_make_loop_iterate_ntimes (struct loop *, tree);
1017 extern bool slpeel_can_duplicate_loop_p (const struct loop *, const_edge);
1018 struct loop *slpeel_tree_duplicate_loop_to_edge_cfg (struct loop *,
1019 struct loop *, edge);
1020 extern void vect_loop_versioning (loop_vec_info, unsigned int, bool);
1021 extern void vect_do_peeling_for_loop_bound (loop_vec_info, tree, tree,
1022 unsigned int, bool);
1023 extern void vect_do_peeling_for_alignment (loop_vec_info, tree,
1024 unsigned int, bool);
1025 extern source_location find_loop_location (struct loop *);
1026 extern bool vect_can_advance_ivs_p (loop_vec_info);
1028 /* In tree-vect-stmts.c. */
1029 extern unsigned int current_vector_size;
1030 extern tree get_vectype_for_scalar_type (tree);
1031 extern tree get_mask_type_for_scalar_type (tree);
1032 extern tree get_same_sized_vectype (tree, tree);
1033 extern bool vect_is_simple_use (tree, vec_info *, gimple **,
1034 enum vect_def_type *);
1035 extern bool vect_is_simple_use (tree, vec_info *, gimple **,
1036 enum vect_def_type *, tree *);
1037 extern bool supportable_widening_operation (enum tree_code, gimple *, tree,
1038 tree, enum tree_code *,
1039 enum tree_code *, int *,
1040 vec<tree> *);
1041 extern bool supportable_narrowing_operation (enum tree_code, tree, tree,
1042 enum tree_code *,
1043 int *, vec<tree> *);
1044 extern stmt_vec_info new_stmt_vec_info (gimple *stmt, vec_info *);
1045 extern void free_stmt_vec_info (gimple *stmt);
1046 extern void vect_model_simple_cost (stmt_vec_info, int, enum vect_def_type *,
1047 stmt_vector_for_cost *,
1048 stmt_vector_for_cost *);
1049 extern void vect_model_store_cost (stmt_vec_info, int, vect_memory_access_type,
1050 enum vect_def_type, slp_tree,
1051 stmt_vector_for_cost *,
1052 stmt_vector_for_cost *);
1053 extern void vect_model_load_cost (stmt_vec_info, int, vect_memory_access_type,
1054 slp_tree, stmt_vector_for_cost *,
1055 stmt_vector_for_cost *);
1056 extern unsigned record_stmt_cost (stmt_vector_for_cost *, int,
1057 enum vect_cost_for_stmt, stmt_vec_info,
1058 int, enum vect_cost_model_location);
1059 extern void vect_finish_stmt_generation (gimple *, gimple *,
1060 gimple_stmt_iterator *);
1061 extern bool vect_mark_stmts_to_be_vectorized (loop_vec_info);
1062 extern tree vect_get_vec_def_for_operand_1 (gimple *, enum vect_def_type);
1063 extern tree vect_get_vec_def_for_operand (tree, gimple *, tree = NULL);
1064 extern tree vect_init_vector (gimple *, tree, tree,
1065 gimple_stmt_iterator *);
1066 extern tree vect_get_vec_def_for_stmt_copy (enum vect_def_type, tree);
1067 extern bool vect_transform_stmt (gimple *, gimple_stmt_iterator *,
1068 bool *, slp_tree, slp_instance);
1069 extern void vect_remove_stores (gimple *);
1070 extern bool vect_analyze_stmt (gimple *, bool *, slp_tree);
1071 extern bool vectorizable_condition (gimple *, gimple_stmt_iterator *,
1072 gimple **, tree, int, slp_tree);
1073 extern void vect_get_load_cost (struct data_reference *, int, bool,
1074 unsigned int *, unsigned int *,
1075 stmt_vector_for_cost *,
1076 stmt_vector_for_cost *, bool);
1077 extern void vect_get_store_cost (struct data_reference *, int,
1078 unsigned int *, stmt_vector_for_cost *);
1079 extern bool vect_supportable_shift (enum tree_code, tree);
1080 extern void vect_get_vec_defs (tree, tree, gimple *, vec<tree> *,
1081 vec<tree> *, slp_tree, int);
1082 extern tree vect_gen_perm_mask_any (tree, const unsigned char *);
1083 extern tree vect_gen_perm_mask_checked (tree, const unsigned char *);
1084 extern void optimize_mask_stores (struct loop*);
1086 /* In tree-vect-data-refs.c. */
1087 extern bool vect_can_force_dr_alignment_p (const_tree, unsigned int);
1088 extern enum dr_alignment_support vect_supportable_dr_alignment
1089 (struct data_reference *, bool);
1090 extern tree vect_get_smallest_scalar_type (gimple *, HOST_WIDE_INT *,
1091 HOST_WIDE_INT *);
1092 extern bool vect_analyze_data_ref_dependences (loop_vec_info, int *);
1093 extern bool vect_slp_analyze_instance_dependence (slp_instance);
1094 extern bool vect_enhance_data_refs_alignment (loop_vec_info);
1095 extern bool vect_analyze_data_refs_alignment (loop_vec_info);
1096 extern bool vect_verify_datarefs_alignment (loop_vec_info);
1097 extern bool vect_slp_analyze_and_verify_instance_alignment (slp_instance);
1098 extern bool vect_analyze_data_ref_accesses (vec_info *);
1099 extern bool vect_prune_runtime_alias_test_list (loop_vec_info);
1100 extern bool vect_check_gather_scatter (gimple *, loop_vec_info,
1101 gather_scatter_info *);
1102 extern bool vect_analyze_data_refs (vec_info *, int *);
1103 extern tree vect_create_data_ref_ptr (gimple *, tree, struct loop *, tree,
1104 tree *, gimple_stmt_iterator *,
1105 gimple **, bool, bool *,
1106 tree = NULL_TREE);
1107 extern tree bump_vector_ptr (tree, gimple *, gimple_stmt_iterator *, gimple *,
1108 tree);
1109 extern tree vect_create_destination_var (tree, tree);
1110 extern bool vect_grouped_store_supported (tree, unsigned HOST_WIDE_INT);
1111 extern bool vect_store_lanes_supported (tree, unsigned HOST_WIDE_INT);
1112 extern bool vect_grouped_load_supported (tree, bool, unsigned HOST_WIDE_INT);
1113 extern bool vect_load_lanes_supported (tree, unsigned HOST_WIDE_INT);
1114 extern void vect_permute_store_chain (vec<tree> ,unsigned int, gimple *,
1115 gimple_stmt_iterator *, vec<tree> *);
1116 extern tree vect_setup_realignment (gimple *, gimple_stmt_iterator *, tree *,
1117 enum dr_alignment_support, tree,
1118 struct loop **);
1119 extern void vect_transform_grouped_load (gimple *, vec<tree> , int,
1120 gimple_stmt_iterator *);
1121 extern void vect_record_grouped_load_vectors (gimple *, vec<tree> );
1122 extern tree vect_get_new_vect_var (tree, enum vect_var_kind, const char *);
1123 extern tree vect_get_new_ssa_name (tree, enum vect_var_kind,
1124 const char * = NULL);
1125 extern tree vect_create_addr_base_for_vector_ref (gimple *, gimple_seq *,
1126 tree, struct loop *,
1127 tree = NULL_TREE);
1129 /* In tree-vect-loop.c. */
1130 /* FORNOW: Used in tree-parloops.c. */
1131 extern void destroy_loop_vec_info (loop_vec_info, bool);
1132 extern gimple *vect_force_simple_reduction (loop_vec_info, gimple *, bool,
1133 bool *, bool);
1134 /* Drive for loop analysis stage. */
1135 extern loop_vec_info vect_analyze_loop (struct loop *);
1136 /* Drive for loop transformation stage. */
1137 extern void vect_transform_loop (loop_vec_info);
1138 extern loop_vec_info vect_analyze_loop_form (struct loop *);
1139 extern bool vectorizable_live_operation (gimple *, gimple_stmt_iterator *,
1140 slp_tree, int, gimple **);
1141 extern bool vectorizable_reduction (gimple *, gimple_stmt_iterator *,
1142 gimple **, slp_tree);
1143 extern bool vectorizable_induction (gimple *, gimple_stmt_iterator *, gimple **);
1144 extern tree get_initial_def_for_reduction (gimple *, tree, tree *);
1145 extern int vect_min_worthwhile_factor (enum tree_code);
1146 extern int vect_get_known_peeling_cost (loop_vec_info, int, int *,
1147 stmt_vector_for_cost *,
1148 stmt_vector_for_cost *,
1149 stmt_vector_for_cost *);
1151 /* In tree-vect-slp.c. */
1152 extern void vect_free_slp_instance (slp_instance);
1153 extern bool vect_transform_slp_perm_load (slp_tree, vec<tree> ,
1154 gimple_stmt_iterator *, int,
1155 slp_instance, bool);
1156 extern bool vect_slp_analyze_operations (vec<slp_instance> slp_instances,
1157 void *);
1158 extern bool vect_schedule_slp (vec_info *);
1159 extern bool vect_analyze_slp (vec_info *, unsigned);
1160 extern bool vect_make_slp_decision (loop_vec_info);
1161 extern void vect_detect_hybrid_slp (loop_vec_info);
1162 extern void vect_get_slp_defs (vec<tree> , slp_tree,
1163 vec<vec<tree> > *, int);
1164 extern bool vect_slp_bb (basic_block);
1165 extern gimple *vect_find_last_scalar_stmt_in_slp (slp_tree);
1166 extern bool is_simple_and_all_uses_invariant (gimple *, loop_vec_info);
1168 /* In tree-vect-patterns.c. */
1169 /* Pattern recognition functions.
1170 Additional pattern recognition functions can (and will) be added
1171 in the future. */
1172 typedef gimple *(* vect_recog_func_ptr) (vec<gimple *> *, tree *, tree *);
1173 #define NUM_PATTERNS 14
1174 void vect_pattern_recog (vec_info *);
1176 /* In tree-vectorizer.c. */
1177 unsigned vectorize_loops (void);
1178 void vect_destroy_datarefs (vec_info *);
1179 bool vect_stmt_in_region_p (vec_info *, gimple *);
1181 #endif /* GCC_TREE_VECTORIZER_H */