2013-11-21 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / tree-vectorizer.h
blob23c4d88beb338acfa15512071d66176bd02e4f4d
1 /* Vectorizer
2 Copyright (C) 2003-2013 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;
135 /* The first scalar load of the instance. The created vector loads will be
136 inserted before this statement. */
137 gimple first_load;
138 } *slp_instance;
141 /* Access Functions. */
142 #define SLP_INSTANCE_TREE(S) (S)->root
143 #define SLP_INSTANCE_GROUP_SIZE(S) (S)->group_size
144 #define SLP_INSTANCE_UNROLLING_FACTOR(S) (S)->unrolling_factor
145 #define SLP_INSTANCE_BODY_COST_VEC(S) (S)->body_cost_vec
146 #define SLP_INSTANCE_LOADS(S) (S)->loads
147 #define SLP_INSTANCE_FIRST_LOAD_STMT(S) (S)->first_load
149 #define SLP_TREE_CHILDREN(S) (S)->children
150 #define SLP_TREE_SCALAR_STMTS(S) (S)->stmts
151 #define SLP_TREE_VEC_STMTS(S) (S)->vec_stmts
152 #define SLP_TREE_NUMBER_OF_VEC_STMTS(S) (S)->vec_stmts_size
153 #define SLP_TREE_LOAD_PERMUTATION(S) (S)->load_permutation
155 /* This structure is used in creation of an SLP tree. Each instance
156 corresponds to the same operand in a group of scalar stmts in an SLP
157 node. */
158 typedef struct _slp_oprnd_info
160 /* Def-stmts for the operands. */
161 vec<gimple> def_stmts;
162 /* Information about the first statement, its vector def-type, type, the
163 operand itself in case it's constant, and an indication if it's a pattern
164 stmt. */
165 enum vect_def_type first_dt;
166 tree first_op_type;
167 bool first_pattern;
168 } *slp_oprnd_info;
172 /* This struct is used to store the information of a data reference,
173 including the data ref itself, the access offset (calculated by summing its
174 offset and init) and the segment length for aliasing checks.
175 This is used to merge alias checks. */
177 struct dr_with_seg_len
179 dr_with_seg_len (data_reference_p d, tree len)
180 : dr (d),
181 offset (size_binop (PLUS_EXPR, DR_OFFSET (d), DR_INIT (d))),
182 seg_len (len) {}
184 data_reference_p dr;
185 tree offset;
186 tree seg_len;
189 /* This struct contains two dr_with_seg_len objects with aliasing data
190 refs. Two comparisons are generated from them. */
192 struct dr_with_seg_len_pair_t
194 dr_with_seg_len_pair_t (const dr_with_seg_len& d1,
195 const dr_with_seg_len& d2)
196 : first (d1), second (d2) {}
198 dr_with_seg_len first;
199 dr_with_seg_len second;
203 typedef struct _vect_peel_info
205 int npeel;
206 struct data_reference *dr;
207 unsigned int count;
208 } *vect_peel_info;
210 typedef struct _vect_peel_extended_info
212 struct _vect_peel_info peel_info;
213 unsigned int inside_cost;
214 unsigned int outside_cost;
215 stmt_vector_for_cost body_cost_vec;
216 } *vect_peel_extended_info;
219 /* Peeling hashtable helpers. */
221 struct peel_info_hasher : typed_free_remove <_vect_peel_info>
223 typedef _vect_peel_info value_type;
224 typedef _vect_peel_info compare_type;
225 static inline hashval_t hash (const value_type *);
226 static inline bool equal (const value_type *, const compare_type *);
229 inline hashval_t
230 peel_info_hasher::hash (const value_type *peel_info)
232 return (hashval_t) peel_info->npeel;
235 inline bool
236 peel_info_hasher::equal (const value_type *a, const compare_type *b)
238 return (a->npeel == b->npeel);
242 /*-----------------------------------------------------------------*/
243 /* Info on vectorized loops. */
244 /*-----------------------------------------------------------------*/
245 typedef struct _loop_vec_info {
247 /* The loop to which this info struct refers to. */
248 struct loop *loop;
250 /* The loop basic blocks. */
251 basic_block *bbs;
253 /* Number of iterations. */
254 tree num_iters;
255 tree num_iters_unchanged;
257 /* Minimum number of iterations below which vectorization is expected to
258 not be profitable (as estimated by the cost model).
259 -1 indicates that vectorization will not be profitable.
260 FORNOW: This field is an int. Will be a tree in the future, to represent
261 values unknown at compile time. */
262 int min_profitable_iters;
264 /* Is the loop vectorizable? */
265 bool vectorizable;
267 /* Unrolling factor */
268 int vectorization_factor;
270 /* Unknown DRs according to which loop was peeled. */
271 struct data_reference *unaligned_dr;
273 /* peeling_for_alignment indicates whether peeling for alignment will take
274 place, and what the peeling factor should be:
275 peeling_for_alignment = X means:
276 If X=0: Peeling for alignment will not be applied.
277 If X>0: Peel first X iterations.
278 If X=-1: Generate a runtime test to calculate the number of iterations
279 to be peeled, using the dataref recorded in the field
280 unaligned_dr. */
281 int peeling_for_alignment;
283 /* The mask used to check the alignment of pointers or arrays. */
284 int ptr_mask;
286 /* The loop nest in which the data dependences are computed. */
287 vec<loop_p> loop_nest;
289 /* All data references in the loop. */
290 vec<data_reference_p> datarefs;
292 /* All data dependences in the loop. */
293 vec<ddr_p> ddrs;
295 /* Data Dependence Relations defining address ranges that are candidates
296 for a run-time aliasing check. */
297 vec<ddr_p> may_alias_ddrs;
299 /* Data Dependence Relations defining address ranges together with segment
300 lengths from which the run-time aliasing check is built. */
301 vec<dr_with_seg_len_pair_t> comp_alias_ddrs;
303 /* Statements in the loop that have data references that are candidates for a
304 runtime (loop versioning) misalignment check. */
305 vec<gimple> may_misalign_stmts;
307 /* All interleaving chains of stores in the loop, represented by the first
308 stmt in the chain. */
309 vec<gimple> grouped_stores;
311 /* All SLP instances in the loop. This is a subset of the set of GROUP_STORES
312 of the loop. */
313 vec<slp_instance> slp_instances;
315 /* The unrolling factor needed to SLP the loop. In case of that pure SLP is
316 applied to the loop, i.e., no unrolling is needed, this is 1. */
317 unsigned slp_unrolling_factor;
319 /* Reduction cycles detected in the loop. Used in loop-aware SLP. */
320 vec<gimple> reductions;
322 /* All reduction chains in the loop, represented by the first
323 stmt in the chain. */
324 vec<gimple> reduction_chains;
326 /* Hash table used to choose the best peeling option. */
327 hash_table <peel_info_hasher> peeling_htab;
329 /* Cost data used by the target cost model. */
330 void *target_cost_data;
332 /* When we have grouped data accesses with gaps, we may introduce invalid
333 memory accesses. We peel the last iteration of the loop to prevent
334 this. */
335 bool peeling_for_gaps;
337 /* When the number of iterations is not a multiple of the vector size
338 we need to peel off iterations at the end to form an epilogue loop. */
339 bool peeling_for_niter;
341 /* Reductions are canonicalized so that the last operand is the reduction
342 operand. If this places a constant into RHS1, this decanonicalizes
343 GIMPLE for other phases, so we must track when this has occurred and
344 fix it up. */
345 bool operands_swapped;
347 } *loop_vec_info;
349 /* Access Functions. */
350 #define LOOP_VINFO_LOOP(L) (L)->loop
351 #define LOOP_VINFO_BBS(L) (L)->bbs
352 #define LOOP_VINFO_NITERS(L) (L)->num_iters
353 /* Since LOOP_VINFO_NITERS can change after prologue peeling
354 retain total unchanged scalar loop iterations for cost model. */
355 #define LOOP_VINFO_NITERS_UNCHANGED(L) (L)->num_iters_unchanged
356 #define LOOP_VINFO_COST_MODEL_MIN_ITERS(L) (L)->min_profitable_iters
357 #define LOOP_VINFO_VECTORIZABLE_P(L) (L)->vectorizable
358 #define LOOP_VINFO_VECT_FACTOR(L) (L)->vectorization_factor
359 #define LOOP_VINFO_PTR_MASK(L) (L)->ptr_mask
360 #define LOOP_VINFO_LOOP_NEST(L) (L)->loop_nest
361 #define LOOP_VINFO_DATAREFS(L) (L)->datarefs
362 #define LOOP_VINFO_DDRS(L) (L)->ddrs
363 #define LOOP_VINFO_INT_NITERS(L) (TREE_INT_CST_LOW ((L)->num_iters))
364 #define LOOP_PEELING_FOR_ALIGNMENT(L) (L)->peeling_for_alignment
365 #define LOOP_VINFO_UNALIGNED_DR(L) (L)->unaligned_dr
366 #define LOOP_VINFO_MAY_MISALIGN_STMTS(L) (L)->may_misalign_stmts
367 #define LOOP_VINFO_MAY_ALIAS_DDRS(L) (L)->may_alias_ddrs
368 #define LOOP_VINFO_COMP_ALIAS_DDRS(L) (L)->comp_alias_ddrs
369 #define LOOP_VINFO_GROUPED_STORES(L) (L)->grouped_stores
370 #define LOOP_VINFO_SLP_INSTANCES(L) (L)->slp_instances
371 #define LOOP_VINFO_SLP_UNROLLING_FACTOR(L) (L)->slp_unrolling_factor
372 #define LOOP_VINFO_REDUCTIONS(L) (L)->reductions
373 #define LOOP_VINFO_REDUCTION_CHAINS(L) (L)->reduction_chains
374 #define LOOP_VINFO_PEELING_HTAB(L) (L)->peeling_htab
375 #define LOOP_VINFO_TARGET_COST_DATA(L) (L)->target_cost_data
376 #define LOOP_VINFO_PEELING_FOR_GAPS(L) (L)->peeling_for_gaps
377 #define LOOP_VINFO_OPERANDS_SWAPPED(L) (L)->operands_swapped
379 #define LOOP_REQUIRES_VERSIONING_FOR_ALIGNMENT(L) \
380 (L)->may_misalign_stmts.length () > 0
381 #define LOOP_REQUIRES_VERSIONING_FOR_ALIAS(L) \
382 (L)->may_alias_ddrs.length () > 0
384 #define NITERS_KNOWN_P(n) \
385 (tree_fits_shwi_p ((n)) \
386 && tree_to_shwi ((n)) > 0)
388 #define LOOP_VINFO_NITERS_KNOWN_P(L) \
389 NITERS_KNOWN_P ((L)->num_iters)
391 static inline loop_vec_info
392 loop_vec_info_for_loop (struct loop *loop)
394 return (loop_vec_info) loop->aux;
397 static inline bool
398 nested_in_vect_loop_p (struct loop *loop, gimple stmt)
400 return (loop->inner
401 && (loop->inner == (gimple_bb (stmt))->loop_father));
404 typedef struct _bb_vec_info {
406 basic_block bb;
407 /* All interleaving chains of stores in the basic block, represented by the
408 first stmt in the chain. */
409 vec<gimple> grouped_stores;
411 /* All SLP instances in the basic block. This is a subset of the set of
412 GROUP_STORES of the basic block. */
413 vec<slp_instance> slp_instances;
415 /* All data references in the basic block. */
416 vec<data_reference_p> datarefs;
418 /* All data dependences in the basic block. */
419 vec<ddr_p> ddrs;
421 /* Cost data used by the target cost model. */
422 void *target_cost_data;
424 } *bb_vec_info;
426 #define BB_VINFO_BB(B) (B)->bb
427 #define BB_VINFO_GROUPED_STORES(B) (B)->grouped_stores
428 #define BB_VINFO_SLP_INSTANCES(B) (B)->slp_instances
429 #define BB_VINFO_DATAREFS(B) (B)->datarefs
430 #define BB_VINFO_DDRS(B) (B)->ddrs
431 #define BB_VINFO_TARGET_COST_DATA(B) (B)->target_cost_data
433 static inline bb_vec_info
434 vec_info_for_bb (basic_block bb)
436 return (bb_vec_info) bb->aux;
439 /*-----------------------------------------------------------------*/
440 /* Info on vectorized defs. */
441 /*-----------------------------------------------------------------*/
442 enum stmt_vec_info_type {
443 undef_vec_info_type = 0,
444 load_vec_info_type,
445 store_vec_info_type,
446 shift_vec_info_type,
447 op_vec_info_type,
448 call_vec_info_type,
449 assignment_vec_info_type,
450 condition_vec_info_type,
451 reduc_vec_info_type,
452 induc_vec_info_type,
453 type_promotion_vec_info_type,
454 type_demotion_vec_info_type,
455 type_conversion_vec_info_type,
456 loop_exit_ctrl_vec_info_type
459 /* Indicates whether/how a variable is used in the scope of loop/basic
460 block. */
461 enum vect_relevant {
462 vect_unused_in_scope = 0,
463 /* The def is in the inner loop, and the use is in the outer loop, and the
464 use is a reduction stmt. */
465 vect_used_in_outer_by_reduction,
466 /* The def is in the inner loop, and the use is in the outer loop (and is
467 not part of reduction). */
468 vect_used_in_outer,
470 /* defs that feed computations that end up (only) in a reduction. These
471 defs may be used by non-reduction stmts, but eventually, any
472 computations/values that are affected by these defs are used to compute
473 a reduction (i.e. don't get stored to memory, for example). We use this
474 to identify computations that we can change the order in which they are
475 computed. */
476 vect_used_by_reduction,
478 vect_used_in_scope
481 /* The type of vectorization that can be applied to the stmt: regular loop-based
482 vectorization; pure SLP - the stmt is a part of SLP instances and does not
483 have uses outside SLP instances; or hybrid SLP and loop-based - the stmt is
484 a part of SLP instance and also must be loop-based vectorized, since it has
485 uses outside SLP sequences.
487 In the loop context the meanings of pure and hybrid SLP are slightly
488 different. By saying that pure SLP is applied to the loop, we mean that we
489 exploit only intra-iteration parallelism in the loop; i.e., the loop can be
490 vectorized without doing any conceptual unrolling, cause we don't pack
491 together stmts from different iterations, only within a single iteration.
492 Loop hybrid SLP means that we exploit both intra-iteration and
493 inter-iteration parallelism (e.g., number of elements in the vector is 4
494 and the slp-group-size is 2, in which case we don't have enough parallelism
495 within an iteration, so we obtain the rest of the parallelism from subsequent
496 iterations by unrolling the loop by 2). */
497 enum slp_vect_type {
498 loop_vect = 0,
499 pure_slp,
500 hybrid
504 typedef struct data_reference *dr_p;
506 typedef struct _stmt_vec_info {
508 enum stmt_vec_info_type type;
510 /* Indicates whether this stmts is part of a computation whose result is
511 used outside the loop. */
512 bool live;
514 /* Stmt is part of some pattern (computation idiom) */
515 bool in_pattern_p;
517 /* The stmt to which this info struct refers to. */
518 gimple stmt;
520 /* The loop_vec_info with respect to which STMT is vectorized. */
521 loop_vec_info loop_vinfo;
523 /* The vector type to be used for the LHS of this statement. */
524 tree vectype;
526 /* The vectorized version of the stmt. */
527 gimple vectorized_stmt;
530 /** The following is relevant only for stmts that contain a non-scalar
531 data-ref (array/pointer/struct access). A GIMPLE stmt is expected to have
532 at most one such data-ref. **/
534 /* Information about the data-ref (access function, etc),
535 relative to the inner-most containing loop. */
536 struct data_reference *data_ref_info;
538 /* Information about the data-ref relative to this loop
539 nest (the loop that is being considered for vectorization). */
540 tree dr_base_address;
541 tree dr_init;
542 tree dr_offset;
543 tree dr_step;
544 tree dr_aligned_to;
546 /* For loop PHI nodes, the evolution part of it. This makes sure
547 this information is still available in vect_update_ivs_after_vectorizer
548 where we may not be able to re-analyze the PHI nodes evolution as
549 peeling for the prologue loop can make it unanalyzable. The evolution
550 part is still correct though. */
551 tree loop_phi_evolution_part;
553 /* Used for various bookkeeping purposes, generally holding a pointer to
554 some other stmt S that is in some way "related" to this stmt.
555 Current use of this field is:
556 If this stmt is part of a pattern (i.e. the field 'in_pattern_p' is
557 true): S is the "pattern stmt" that represents (and replaces) the
558 sequence of stmts that constitutes the pattern. Similarly, the
559 related_stmt of the "pattern stmt" points back to this stmt (which is
560 the last stmt in the original sequence of stmts that constitutes the
561 pattern). */
562 gimple related_stmt;
564 /* Used to keep a sequence of def stmts of a pattern stmt if such exists. */
565 gimple_seq pattern_def_seq;
567 /* List of datarefs that are known to have the same alignment as the dataref
568 of this stmt. */
569 vec<dr_p> same_align_refs;
571 /* Classify the def of this stmt. */
572 enum vect_def_type def_type;
574 /* Whether the stmt is SLPed, loop-based vectorized, or both. */
575 enum slp_vect_type slp_type;
577 /* Interleaving and reduction chains info. */
578 /* First element in the group. */
579 gimple first_element;
580 /* Pointer to the next element in the group. */
581 gimple next_element;
582 /* For data-refs, in case that two or more stmts share data-ref, this is the
583 pointer to the previously detected stmt with the same dr. */
584 gimple same_dr_stmt;
585 /* The size of the group. */
586 unsigned int size;
587 /* For stores, number of stores from this group seen. We vectorize the last
588 one. */
589 unsigned int store_count;
590 /* For loads only, the gap from the previous load. For consecutive loads, GAP
591 is 1. */
592 unsigned int gap;
594 /* Not all stmts in the loop need to be vectorized. e.g, the increment
595 of the loop induction variable and computation of array indexes. relevant
596 indicates whether the stmt needs to be vectorized. */
597 enum vect_relevant relevant;
599 /* The bb_vec_info with respect to which STMT is vectorized. */
600 bb_vec_info bb_vinfo;
602 /* Is this statement vectorizable or should it be skipped in (partial)
603 vectorization. */
604 bool vectorizable;
606 /* For loads only, true if this is a gather load. */
607 bool gather_p;
608 bool stride_load_p;
610 /* For both loads and stores. */
611 bool simd_lane_access_p;
612 } *stmt_vec_info;
614 /* Access Functions. */
615 #define STMT_VINFO_TYPE(S) (S)->type
616 #define STMT_VINFO_STMT(S) (S)->stmt
617 #define STMT_VINFO_LOOP_VINFO(S) (S)->loop_vinfo
618 #define STMT_VINFO_BB_VINFO(S) (S)->bb_vinfo
619 #define STMT_VINFO_RELEVANT(S) (S)->relevant
620 #define STMT_VINFO_LIVE_P(S) (S)->live
621 #define STMT_VINFO_VECTYPE(S) (S)->vectype
622 #define STMT_VINFO_VEC_STMT(S) (S)->vectorized_stmt
623 #define STMT_VINFO_VECTORIZABLE(S) (S)->vectorizable
624 #define STMT_VINFO_DATA_REF(S) (S)->data_ref_info
625 #define STMT_VINFO_GATHER_P(S) (S)->gather_p
626 #define STMT_VINFO_STRIDE_LOAD_P(S) (S)->stride_load_p
627 #define STMT_VINFO_SIMD_LANE_ACCESS_P(S) (S)->simd_lane_access_p
629 #define STMT_VINFO_DR_BASE_ADDRESS(S) (S)->dr_base_address
630 #define STMT_VINFO_DR_INIT(S) (S)->dr_init
631 #define STMT_VINFO_DR_OFFSET(S) (S)->dr_offset
632 #define STMT_VINFO_DR_STEP(S) (S)->dr_step
633 #define STMT_VINFO_DR_ALIGNED_TO(S) (S)->dr_aligned_to
635 #define STMT_VINFO_IN_PATTERN_P(S) (S)->in_pattern_p
636 #define STMT_VINFO_RELATED_STMT(S) (S)->related_stmt
637 #define STMT_VINFO_PATTERN_DEF_SEQ(S) (S)->pattern_def_seq
638 #define STMT_VINFO_SAME_ALIGN_REFS(S) (S)->same_align_refs
639 #define STMT_VINFO_DEF_TYPE(S) (S)->def_type
640 #define STMT_VINFO_GROUP_FIRST_ELEMENT(S) (S)->first_element
641 #define STMT_VINFO_GROUP_NEXT_ELEMENT(S) (S)->next_element
642 #define STMT_VINFO_GROUP_SIZE(S) (S)->size
643 #define STMT_VINFO_GROUP_STORE_COUNT(S) (S)->store_count
644 #define STMT_VINFO_GROUP_GAP(S) (S)->gap
645 #define STMT_VINFO_GROUP_SAME_DR_STMT(S) (S)->same_dr_stmt
646 #define STMT_VINFO_GROUPED_ACCESS(S) ((S)->first_element != NULL && (S)->data_ref_info)
647 #define STMT_VINFO_LOOP_PHI_EVOLUTION_PART(S) (S)->loop_phi_evolution_part
649 #define GROUP_FIRST_ELEMENT(S) (S)->first_element
650 #define GROUP_NEXT_ELEMENT(S) (S)->next_element
651 #define GROUP_SIZE(S) (S)->size
652 #define GROUP_STORE_COUNT(S) (S)->store_count
653 #define GROUP_GAP(S) (S)->gap
654 #define GROUP_SAME_DR_STMT(S) (S)->same_dr_stmt
656 #define STMT_VINFO_RELEVANT_P(S) ((S)->relevant != vect_unused_in_scope)
658 #define HYBRID_SLP_STMT(S) ((S)->slp_type == hybrid)
659 #define PURE_SLP_STMT(S) ((S)->slp_type == pure_slp)
660 #define STMT_SLP_TYPE(S) (S)->slp_type
662 struct dataref_aux {
663 tree base_decl;
664 bool base_misaligned;
665 int misalignment;
668 #define VECT_MAX_COST 1000
670 /* The maximum number of intermediate steps required in multi-step type
671 conversion. */
672 #define MAX_INTERM_CVT_STEPS 3
674 /* The maximum vectorization factor supported by any target (V32QI). */
675 #define MAX_VECTORIZATION_FACTOR 32
677 /* Avoid GTY(()) on stmt_vec_info. */
678 typedef void *vec_void_p;
680 extern vec<vec_void_p> stmt_vec_info_vec;
682 void init_stmt_vec_info_vec (void);
683 void free_stmt_vec_info_vec (void);
685 /* Return a stmt_vec_info corresponding to STMT. */
687 static inline stmt_vec_info
688 vinfo_for_stmt (gimple stmt)
690 unsigned int uid = gimple_uid (stmt);
691 if (uid == 0)
692 return NULL;
694 return (stmt_vec_info) stmt_vec_info_vec[uid - 1];
697 /* Set vectorizer information INFO for STMT. */
699 static inline void
700 set_vinfo_for_stmt (gimple stmt, stmt_vec_info info)
702 unsigned int uid = gimple_uid (stmt);
703 if (uid == 0)
705 gcc_checking_assert (info);
706 uid = stmt_vec_info_vec.length () + 1;
707 gimple_set_uid (stmt, uid);
708 stmt_vec_info_vec.safe_push ((vec_void_p) info);
710 else
711 stmt_vec_info_vec[uid - 1] = (vec_void_p) info;
714 /* Return the earlier statement between STMT1 and STMT2. */
716 static inline gimple
717 get_earlier_stmt (gimple stmt1, gimple stmt2)
719 unsigned int uid1, uid2;
721 if (stmt1 == NULL)
722 return stmt2;
724 if (stmt2 == NULL)
725 return stmt1;
727 uid1 = gimple_uid (stmt1);
728 uid2 = gimple_uid (stmt2);
730 if (uid1 == 0 || uid2 == 0)
731 return NULL;
733 gcc_checking_assert (uid1 <= stmt_vec_info_vec.length ()
734 && uid2 <= stmt_vec_info_vec.length ());
736 if (uid1 < uid2)
737 return stmt1;
738 else
739 return stmt2;
742 /* Return the later statement between STMT1 and STMT2. */
744 static inline gimple
745 get_later_stmt (gimple stmt1, gimple stmt2)
747 unsigned int uid1, uid2;
749 if (stmt1 == NULL)
750 return stmt2;
752 if (stmt2 == NULL)
753 return stmt1;
755 uid1 = gimple_uid (stmt1);
756 uid2 = gimple_uid (stmt2);
758 if (uid1 == 0 || uid2 == 0)
759 return NULL;
761 gcc_assert (uid1 <= stmt_vec_info_vec.length ());
762 gcc_assert (uid2 <= stmt_vec_info_vec.length ());
764 if (uid1 > uid2)
765 return stmt1;
766 else
767 return stmt2;
770 /* Return TRUE if a statement represented by STMT_INFO is a part of a
771 pattern. */
773 static inline bool
774 is_pattern_stmt_p (stmt_vec_info stmt_info)
776 gimple related_stmt;
777 stmt_vec_info related_stmt_info;
779 related_stmt = STMT_VINFO_RELATED_STMT (stmt_info);
780 if (related_stmt
781 && (related_stmt_info = vinfo_for_stmt (related_stmt))
782 && STMT_VINFO_IN_PATTERN_P (related_stmt_info))
783 return true;
785 return false;
788 /* Return true if BB is a loop header. */
790 static inline bool
791 is_loop_header_bb_p (basic_block bb)
793 if (bb == (bb->loop_father)->header)
794 return true;
795 gcc_checking_assert (EDGE_COUNT (bb->preds) == 1);
796 return false;
799 /* Return pow2 (X). */
801 static inline int
802 vect_pow2 (int x)
804 int i, res = 1;
806 for (i = 0; i < x; i++)
807 res *= 2;
809 return res;
812 /* Alias targetm.vectorize.builtin_vectorization_cost. */
814 static inline int
815 builtin_vectorization_cost (enum vect_cost_for_stmt type_of_cost,
816 tree vectype, int misalign)
818 return targetm.vectorize.builtin_vectorization_cost (type_of_cost,
819 vectype, misalign);
822 /* Get cost by calling cost target builtin. */
824 static inline
825 int vect_get_stmt_cost (enum vect_cost_for_stmt type_of_cost)
827 return builtin_vectorization_cost (type_of_cost, NULL, 0);
830 /* Alias targetm.vectorize.init_cost. */
832 static inline void *
833 init_cost (struct loop *loop_info)
835 return targetm.vectorize.init_cost (loop_info);
838 /* Alias targetm.vectorize.add_stmt_cost. */
840 static inline unsigned
841 add_stmt_cost (void *data, int count, enum vect_cost_for_stmt kind,
842 stmt_vec_info stmt_info, int misalign,
843 enum vect_cost_model_location where)
845 return targetm.vectorize.add_stmt_cost (data, count, kind,
846 stmt_info, misalign, where);
849 /* Alias targetm.vectorize.finish_cost. */
851 static inline void
852 finish_cost (void *data, unsigned *prologue_cost,
853 unsigned *body_cost, unsigned *epilogue_cost)
855 targetm.vectorize.finish_cost (data, prologue_cost, body_cost, epilogue_cost);
858 /* Alias targetm.vectorize.destroy_cost_data. */
860 static inline void
861 destroy_cost_data (void *data)
863 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 = (dataref_aux *) dr->aux;
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 gcc_assert (dr->aux);
888 return ((dataref_aux *) dr->aux)->misalignment;
891 /* Reflects actual alignment of first access in the vectorized loop,
892 taking into account peeling/versioning if applied. */
893 #define DR_MISALIGNMENT(DR) dr_misalignment (DR)
894 #define SET_DR_MISALIGNMENT(DR, VAL) set_dr_misalignment (DR, VAL)
896 /* Return TRUE if the data access is aligned, and FALSE otherwise. */
898 static inline bool
899 aligned_access_p (struct data_reference *data_ref_info)
901 return (DR_MISALIGNMENT (data_ref_info) == 0);
904 /* Return TRUE if the alignment of the data access is known, and FALSE
905 otherwise. */
907 static inline bool
908 known_alignment_for_access_p (struct data_reference *data_ref_info)
910 return (DR_MISALIGNMENT (data_ref_info) != -1);
914 /* Return true if the vect cost model is unlimited. */
915 static inline bool
916 unlimited_cost_model ()
918 return flag_vect_cost_model == VECT_COST_MODEL_UNLIMITED;
921 /* Source location */
922 extern source_location vect_location;
924 /*-----------------------------------------------------------------*/
925 /* Function prototypes. */
926 /*-----------------------------------------------------------------*/
928 /* Simple loop peeling and versioning utilities for vectorizer's purposes -
929 in tree-vect-loop-manip.c. */
930 extern void slpeel_make_loop_iterate_ntimes (struct loop *, tree);
931 extern bool slpeel_can_duplicate_loop_p (const struct loop *, const_edge);
932 struct loop *slpeel_tree_duplicate_loop_to_edge_cfg (struct loop *, edge);
933 extern void vect_loop_versioning (loop_vec_info, unsigned int, bool);
934 extern void vect_do_peeling_for_loop_bound (loop_vec_info, tree, tree,
935 unsigned int, bool);
936 extern void vect_do_peeling_for_alignment (loop_vec_info, tree,
937 unsigned int, bool);
938 extern source_location find_loop_location (struct loop *);
939 extern bool vect_can_advance_ivs_p (loop_vec_info);
941 /* In tree-vect-stmts.c. */
942 extern unsigned int current_vector_size;
943 extern tree get_vectype_for_scalar_type (tree);
944 extern tree get_same_sized_vectype (tree, tree);
945 extern bool vect_is_simple_use (tree, gimple, loop_vec_info,
946 bb_vec_info, gimple *,
947 tree *, enum vect_def_type *);
948 extern bool vect_is_simple_use_1 (tree, gimple, loop_vec_info,
949 bb_vec_info, gimple *,
950 tree *, enum vect_def_type *, tree *);
951 extern bool supportable_widening_operation (enum tree_code, gimple, tree, tree,
952 enum tree_code *, enum tree_code *,
953 int *, vec<tree> *);
954 extern bool supportable_narrowing_operation (enum tree_code, tree, tree,
955 enum tree_code *,
956 int *, vec<tree> *);
957 extern stmt_vec_info new_stmt_vec_info (gimple stmt, loop_vec_info,
958 bb_vec_info);
959 extern void free_stmt_vec_info (gimple stmt);
960 extern tree vectorizable_function (gimple, tree, tree);
961 extern void vect_model_simple_cost (stmt_vec_info, int, enum vect_def_type *,
962 stmt_vector_for_cost *,
963 stmt_vector_for_cost *);
964 extern void vect_model_store_cost (stmt_vec_info, int, bool,
965 enum vect_def_type, slp_tree,
966 stmt_vector_for_cost *,
967 stmt_vector_for_cost *);
968 extern void vect_model_load_cost (stmt_vec_info, int, bool, slp_tree,
969 stmt_vector_for_cost *,
970 stmt_vector_for_cost *);
971 extern unsigned record_stmt_cost (stmt_vector_for_cost *, int,
972 enum vect_cost_for_stmt, stmt_vec_info,
973 int, enum vect_cost_model_location);
974 extern void vect_finish_stmt_generation (gimple, gimple,
975 gimple_stmt_iterator *);
976 extern bool vect_mark_stmts_to_be_vectorized (loop_vec_info);
977 extern tree vect_get_vec_def_for_operand (tree, gimple, tree *);
978 extern tree vect_init_vector (gimple, tree, tree,
979 gimple_stmt_iterator *);
980 extern tree vect_get_vec_def_for_stmt_copy (enum vect_def_type, tree);
981 extern bool vect_transform_stmt (gimple, gimple_stmt_iterator *,
982 bool *, slp_tree, slp_instance);
983 extern void vect_remove_stores (gimple);
984 extern bool vect_analyze_stmt (gimple, bool *, slp_tree);
985 extern bool vectorizable_condition (gimple, gimple_stmt_iterator *, gimple *,
986 tree, int, slp_tree);
987 extern void vect_get_load_cost (struct data_reference *, int, bool,
988 unsigned int *, unsigned int *,
989 stmt_vector_for_cost *,
990 stmt_vector_for_cost *, bool);
991 extern void vect_get_store_cost (struct data_reference *, int,
992 unsigned int *, stmt_vector_for_cost *);
993 extern bool vect_supportable_shift (enum tree_code, tree);
994 extern void vect_get_vec_defs (tree, tree, gimple, vec<tree> *,
995 vec<tree> *, slp_tree, int);
996 extern tree vect_gen_perm_mask (tree, unsigned char *);
998 /* In tree-vect-data-refs.c. */
999 extern bool vect_can_force_dr_alignment_p (const_tree, unsigned int);
1000 extern enum dr_alignment_support vect_supportable_dr_alignment
1001 (struct data_reference *, bool);
1002 extern tree vect_get_smallest_scalar_type (gimple, HOST_WIDE_INT *,
1003 HOST_WIDE_INT *);
1004 extern bool vect_analyze_data_ref_dependences (loop_vec_info, int *);
1005 extern bool vect_slp_analyze_data_ref_dependences (bb_vec_info);
1006 extern bool vect_enhance_data_refs_alignment (loop_vec_info);
1007 extern bool vect_analyze_data_refs_alignment (loop_vec_info, bb_vec_info);
1008 extern bool vect_verify_datarefs_alignment (loop_vec_info, bb_vec_info);
1009 extern bool vect_analyze_data_ref_accesses (loop_vec_info, bb_vec_info);
1010 extern bool vect_prune_runtime_alias_test_list (loop_vec_info);
1011 extern tree vect_check_gather (gimple, loop_vec_info, tree *, tree *,
1012 int *);
1013 extern bool vect_analyze_data_refs (loop_vec_info, bb_vec_info, int *);
1014 extern tree vect_create_data_ref_ptr (gimple, tree, struct loop *, tree,
1015 tree *, gimple_stmt_iterator *,
1016 gimple *, bool, bool *);
1017 extern tree bump_vector_ptr (tree, gimple, gimple_stmt_iterator *, gimple, tree);
1018 extern tree vect_create_destination_var (tree, tree);
1019 extern bool vect_grouped_store_supported (tree, unsigned HOST_WIDE_INT);
1020 extern bool vect_store_lanes_supported (tree, unsigned HOST_WIDE_INT);
1021 extern bool vect_grouped_load_supported (tree, unsigned HOST_WIDE_INT);
1022 extern bool vect_load_lanes_supported (tree, unsigned HOST_WIDE_INT);
1023 extern void vect_permute_store_chain (vec<tree> ,unsigned int, gimple,
1024 gimple_stmt_iterator *, vec<tree> *);
1025 extern tree vect_setup_realignment (gimple, gimple_stmt_iterator *, tree *,
1026 enum dr_alignment_support, tree,
1027 struct loop **);
1028 extern void vect_transform_grouped_load (gimple, vec<tree> , int,
1029 gimple_stmt_iterator *);
1030 extern void vect_record_grouped_load_vectors (gimple, vec<tree> );
1031 extern tree vect_get_new_vect_var (tree, enum vect_var_kind, const char *);
1032 extern tree vect_create_addr_base_for_vector_ref (gimple, gimple_seq *,
1033 tree, struct loop *);
1035 /* In tree-vect-loop.c. */
1036 /* FORNOW: Used in tree-parloops.c. */
1037 extern void destroy_loop_vec_info (loop_vec_info, bool);
1038 extern gimple vect_force_simple_reduction (loop_vec_info, gimple, bool, bool *);
1039 /* Drive for loop analysis stage. */
1040 extern loop_vec_info vect_analyze_loop (struct loop *);
1041 /* Drive for loop transformation stage. */
1042 extern void vect_transform_loop (loop_vec_info);
1043 extern loop_vec_info vect_analyze_loop_form (struct loop *);
1044 extern bool vectorizable_live_operation (gimple, gimple_stmt_iterator *,
1045 gimple *);
1046 extern bool vectorizable_reduction (gimple, gimple_stmt_iterator *, gimple *,
1047 slp_tree);
1048 extern bool vectorizable_induction (gimple, gimple_stmt_iterator *, gimple *);
1049 extern tree get_initial_def_for_reduction (gimple, tree, tree *);
1050 extern int vect_min_worthwhile_factor (enum tree_code);
1051 extern int vect_get_known_peeling_cost (loop_vec_info, int, int *, int,
1052 stmt_vector_for_cost *,
1053 stmt_vector_for_cost *);
1054 extern int vect_get_single_scalar_iteration_cost (loop_vec_info);
1056 /* In tree-vect-slp.c. */
1057 extern void vect_free_slp_instance (slp_instance);
1058 extern bool vect_transform_slp_perm_load (slp_tree, vec<tree> ,
1059 gimple_stmt_iterator *, int,
1060 slp_instance, bool);
1061 extern bool vect_schedule_slp (loop_vec_info, bb_vec_info);
1062 extern void vect_update_slp_costs_according_to_vf (loop_vec_info);
1063 extern bool vect_analyze_slp (loop_vec_info, bb_vec_info);
1064 extern bool vect_make_slp_decision (loop_vec_info);
1065 extern void vect_detect_hybrid_slp (loop_vec_info);
1066 extern void vect_get_slp_defs (vec<tree> , slp_tree,
1067 vec<vec<tree> > *, int);
1069 extern source_location find_bb_location (basic_block);
1070 extern bb_vec_info vect_slp_analyze_bb (basic_block);
1071 extern void vect_slp_transform_bb (basic_block);
1073 /* In tree-vect-patterns.c. */
1074 /* Pattern recognition functions.
1075 Additional pattern recognition functions can (and will) be added
1076 in the future. */
1077 typedef gimple (* vect_recog_func_ptr) (vec<gimple> *, tree *, tree *);
1078 #define NUM_PATTERNS 11
1079 void vect_pattern_recog (loop_vec_info, bb_vec_info);
1081 /* In tree-vectorizer.c. */
1082 unsigned vectorize_loops (void);
1083 void vect_destroy_datarefs (loop_vec_info, bb_vec_info);
1085 #endif /* GCC_TREE_VECTORIZER_H */