* gcc.dg/c11-complex-1.c: Use dg-add-options ieee.
[official-gcc.git] / gcc / tree-vectorizer.h
bloba6c5b596e9b6a97c213cee6c86c1a4d24f2a578e
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 typedef source_location LOC;
29 #define UNKNOWN_LOC UNKNOWN_LOCATION
30 #define EXPR_LOC(e) EXPR_LOCATION (e)
31 #define LOC_FILE(l) LOCATION_FILE (l)
32 #define LOC_LINE(l) LOCATION_LINE (l)
34 /* Used for naming of new temporaries. */
35 enum vect_var_kind {
36 vect_simple_var,
37 vect_pointer_var,
38 vect_scalar_var
41 /* Defines type of operation. */
42 enum operation_type {
43 unary_op = 1,
44 binary_op,
45 ternary_op
48 /* Define type of available alignment support. */
49 enum dr_alignment_support {
50 dr_unaligned_unsupported,
51 dr_unaligned_supported,
52 dr_explicit_realign,
53 dr_explicit_realign_optimized,
54 dr_aligned
57 /* Define type of def-use cross-iteration cycle. */
58 enum vect_def_type {
59 vect_uninitialized_def = 0,
60 vect_constant_def = 1,
61 vect_external_def,
62 vect_internal_def,
63 vect_induction_def,
64 vect_reduction_def,
65 vect_double_reduction_def,
66 vect_nested_cycle,
67 vect_unknown_def_type
70 #define VECTORIZABLE_CYCLE_DEF(D) (((D) == vect_reduction_def) \
71 || ((D) == vect_double_reduction_def) \
72 || ((D) == vect_nested_cycle))
74 /* Structure to encapsulate information about a group of like
75 instructions to be presented to the target cost model. */
76 typedef struct _stmt_info_for_cost {
77 int count;
78 enum vect_cost_for_stmt kind;
79 gimple stmt;
80 int misalign;
81 } stmt_info_for_cost;
84 typedef vec<stmt_info_for_cost> stmt_vector_for_cost;
86 static inline void
87 add_stmt_info_to_vec (stmt_vector_for_cost *stmt_cost_vec, int count,
88 enum vect_cost_for_stmt kind, gimple stmt, int misalign)
90 stmt_info_for_cost si;
91 si.count = count;
92 si.kind = kind;
93 si.stmt = stmt;
94 si.misalign = misalign;
95 stmt_cost_vec->safe_push (si);
98 /************************************************************************
99 SLP
100 ************************************************************************/
101 typedef struct _slp_tree *slp_tree;
103 /* A computation tree of an SLP instance. Each node corresponds to a group of
104 stmts to be packed in a SIMD stmt. */
105 struct _slp_tree {
106 /* Nodes that contain def-stmts of this node statements operands. */
107 vec<slp_tree> children;
108 /* A group of scalar stmts to be vectorized together. */
109 vec<gimple> stmts;
110 /* Load permutation relative to the stores, NULL if there is no
111 permutation. */
112 vec<unsigned> load_permutation;
113 /* Vectorized stmt/s. */
114 vec<gimple> vec_stmts;
115 /* Number of vector stmts that are created to replace the group of scalar
116 stmts. It is calculated during the transformation phase as the number of
117 scalar elements in one scalar iteration (GROUP_SIZE) multiplied by VF
118 divided by vector size. */
119 unsigned int vec_stmts_size;
123 /* SLP instance is a sequence of stmts in a loop that can be packed into
124 SIMD stmts. */
125 typedef struct _slp_instance {
126 /* The root of SLP tree. */
127 slp_tree root;
129 /* Size of groups of scalar stmts that will be replaced by SIMD stmt/s. */
130 unsigned int group_size;
132 /* The unrolling factor required to vectorized this SLP instance. */
133 unsigned int unrolling_factor;
135 /* Vectorization costs associated with SLP instance. */
136 stmt_vector_for_cost body_cost_vec;
138 /* The group of nodes that contain loads of this SLP instance. */
139 vec<slp_tree> loads;
141 /* The first scalar load of the instance. The created vector loads will be
142 inserted before this statement. */
143 gimple first_load;
144 } *slp_instance;
147 /* Access Functions. */
148 #define SLP_INSTANCE_TREE(S) (S)->root
149 #define SLP_INSTANCE_GROUP_SIZE(S) (S)->group_size
150 #define SLP_INSTANCE_UNROLLING_FACTOR(S) (S)->unrolling_factor
151 #define SLP_INSTANCE_BODY_COST_VEC(S) (S)->body_cost_vec
152 #define SLP_INSTANCE_LOADS(S) (S)->loads
153 #define SLP_INSTANCE_FIRST_LOAD_STMT(S) (S)->first_load
155 #define SLP_TREE_CHILDREN(S) (S)->children
156 #define SLP_TREE_SCALAR_STMTS(S) (S)->stmts
157 #define SLP_TREE_VEC_STMTS(S) (S)->vec_stmts
158 #define SLP_TREE_NUMBER_OF_VEC_STMTS(S) (S)->vec_stmts_size
159 #define SLP_TREE_LOAD_PERMUTATION(S) (S)->load_permutation
161 /* This structure is used in creation of an SLP tree. Each instance
162 corresponds to the same operand in a group of scalar stmts in an SLP
163 node. */
164 typedef struct _slp_oprnd_info
166 /* Def-stmts for the operands. */
167 vec<gimple> def_stmts;
168 /* Information about the first statement, its vector def-type, type, the
169 operand itself in case it's constant, and an indication if it's a pattern
170 stmt. */
171 enum vect_def_type first_dt;
172 tree first_op_type;
173 bool first_pattern;
174 } *slp_oprnd_info;
178 /* This struct is used to store the information of a data reference,
179 including the data ref itself, the access offset (calculated by summing its
180 offset and init) and the segment length for aliasing checks.
181 This is used to merge alias checks. */
183 struct dr_with_seg_len
185 dr_with_seg_len (data_reference_p d, tree len)
186 : dr (d),
187 offset (size_binop (PLUS_EXPR, DR_OFFSET (d), DR_INIT (d))),
188 seg_len (len) {}
190 data_reference_p dr;
191 tree offset;
192 tree seg_len;
195 /* This struct contains two dr_with_seg_len objects with aliasing data
196 refs. Two comparisons are generated from them. */
198 struct dr_with_seg_len_pair_t
200 dr_with_seg_len_pair_t (const dr_with_seg_len& d1,
201 const dr_with_seg_len& d2)
202 : first (d1), second (d2) {}
204 dr_with_seg_len first;
205 dr_with_seg_len second;
209 typedef struct _vect_peel_info
211 int npeel;
212 struct data_reference *dr;
213 unsigned int count;
214 } *vect_peel_info;
216 typedef struct _vect_peel_extended_info
218 struct _vect_peel_info peel_info;
219 unsigned int inside_cost;
220 unsigned int outside_cost;
221 stmt_vector_for_cost body_cost_vec;
222 } *vect_peel_extended_info;
225 /* Peeling hashtable helpers. */
227 struct peel_info_hasher : typed_free_remove <_vect_peel_info>
229 typedef _vect_peel_info value_type;
230 typedef _vect_peel_info compare_type;
231 static inline hashval_t hash (const value_type *);
232 static inline bool equal (const value_type *, const compare_type *);
235 inline hashval_t
236 peel_info_hasher::hash (const value_type *peel_info)
238 return (hashval_t) peel_info->npeel;
241 inline bool
242 peel_info_hasher::equal (const value_type *a, const compare_type *b)
244 return (a->npeel == b->npeel);
248 /*-----------------------------------------------------------------*/
249 /* Info on vectorized loops. */
250 /*-----------------------------------------------------------------*/
251 typedef struct _loop_vec_info {
253 /* The loop to which this info struct refers to. */
254 struct loop *loop;
256 /* The loop basic blocks. */
257 basic_block *bbs;
259 /* Number of iterations. */
260 tree num_iters;
261 tree num_iters_unchanged;
263 /* Minimum number of iterations below which vectorization is expected to
264 not be profitable (as estimated by the cost model).
265 -1 indicates that vectorization will not be profitable.
266 FORNOW: This field is an int. Will be a tree in the future, to represent
267 values unknown at compile time. */
268 int min_profitable_iters;
270 /* Is the loop vectorizable? */
271 bool vectorizable;
273 /* Unrolling factor */
274 int vectorization_factor;
276 /* The loop location in the source. */
277 LOC loop_line_number;
279 /* Unknown DRs according to which loop was peeled. */
280 struct data_reference *unaligned_dr;
282 /* peeling_for_alignment indicates whether peeling for alignment will take
283 place, and what the peeling factor should be:
284 peeling_for_alignment = X means:
285 If X=0: Peeling for alignment will not be applied.
286 If X>0: Peel first X iterations.
287 If X=-1: Generate a runtime test to calculate the number of iterations
288 to be peeled, using the dataref recorded in the field
289 unaligned_dr. */
290 int peeling_for_alignment;
292 /* The mask used to check the alignment of pointers or arrays. */
293 int ptr_mask;
295 /* The loop nest in which the data dependences are computed. */
296 vec<loop_p> loop_nest;
298 /* All data references in the loop. */
299 vec<data_reference_p> datarefs;
301 /* All data dependences in the loop. */
302 vec<ddr_p> ddrs;
304 /* Data Dependence Relations defining address ranges that are candidates
305 for a run-time aliasing check. */
306 vec<ddr_p> may_alias_ddrs;
308 /* Data Dependence Relations defining address ranges together with segment
309 lengths from which the run-time aliasing check is built. */
310 vec<dr_with_seg_len_pair_t> comp_alias_ddrs;
312 /* Statements in the loop that have data references that are candidates for a
313 runtime (loop versioning) misalignment check. */
314 vec<gimple> may_misalign_stmts;
316 /* All interleaving chains of stores in the loop, represented by the first
317 stmt in the chain. */
318 vec<gimple> grouped_stores;
320 /* All SLP instances in the loop. This is a subset of the set of GROUP_STORES
321 of the loop. */
322 vec<slp_instance> slp_instances;
324 /* The unrolling factor needed to SLP the loop. In case of that pure SLP is
325 applied to the loop, i.e., no unrolling is needed, this is 1. */
326 unsigned slp_unrolling_factor;
328 /* Reduction cycles detected in the loop. Used in loop-aware SLP. */
329 vec<gimple> reductions;
331 /* All reduction chains in the loop, represented by the first
332 stmt in the chain. */
333 vec<gimple> reduction_chains;
335 /* Hash table used to choose the best peeling option. */
336 hash_table <peel_info_hasher> peeling_htab;
338 /* Cost data used by the target cost model. */
339 void *target_cost_data;
341 /* When we have grouped data accesses with gaps, we may introduce invalid
342 memory accesses. We peel the last iteration of the loop to prevent
343 this. */
344 bool peeling_for_gaps;
346 /* Reductions are canonicalized so that the last operand is the reduction
347 operand. If this places a constant into RHS1, this decanonicalizes
348 GIMPLE for other phases, so we must track when this has occurred and
349 fix it up. */
350 bool operands_swapped;
352 } *loop_vec_info;
354 /* Access Functions. */
355 #define LOOP_VINFO_LOOP(L) (L)->loop
356 #define LOOP_VINFO_BBS(L) (L)->bbs
357 #define LOOP_VINFO_NITERS(L) (L)->num_iters
358 /* Since LOOP_VINFO_NITERS can change after prologue peeling
359 retain total unchanged scalar loop iterations for cost model. */
360 #define LOOP_VINFO_NITERS_UNCHANGED(L) (L)->num_iters_unchanged
361 #define LOOP_VINFO_COST_MODEL_MIN_ITERS(L) (L)->min_profitable_iters
362 #define LOOP_VINFO_VECTORIZABLE_P(L) (L)->vectorizable
363 #define LOOP_VINFO_VECT_FACTOR(L) (L)->vectorization_factor
364 #define LOOP_VINFO_PTR_MASK(L) (L)->ptr_mask
365 #define LOOP_VINFO_LOOP_NEST(L) (L)->loop_nest
366 #define LOOP_VINFO_DATAREFS(L) (L)->datarefs
367 #define LOOP_VINFO_DDRS(L) (L)->ddrs
368 #define LOOP_VINFO_INT_NITERS(L) (TREE_INT_CST_LOW ((L)->num_iters))
369 #define LOOP_PEELING_FOR_ALIGNMENT(L) (L)->peeling_for_alignment
370 #define LOOP_VINFO_UNALIGNED_DR(L) (L)->unaligned_dr
371 #define LOOP_VINFO_MAY_MISALIGN_STMTS(L) (L)->may_misalign_stmts
372 #define LOOP_VINFO_LOC(L) (L)->loop_line_number
373 #define LOOP_VINFO_MAY_ALIAS_DDRS(L) (L)->may_alias_ddrs
374 #define LOOP_VINFO_COMP_ALIAS_DDRS(L) (L)->comp_alias_ddrs
375 #define LOOP_VINFO_GROUPED_STORES(L) (L)->grouped_stores
376 #define LOOP_VINFO_SLP_INSTANCES(L) (L)->slp_instances
377 #define LOOP_VINFO_SLP_UNROLLING_FACTOR(L) (L)->slp_unrolling_factor
378 #define LOOP_VINFO_REDUCTIONS(L) (L)->reductions
379 #define LOOP_VINFO_REDUCTION_CHAINS(L) (L)->reduction_chains
380 #define LOOP_VINFO_PEELING_HTAB(L) (L)->peeling_htab
381 #define LOOP_VINFO_TARGET_COST_DATA(L) (L)->target_cost_data
382 #define LOOP_VINFO_PEELING_FOR_GAPS(L) (L)->peeling_for_gaps
383 #define LOOP_VINFO_OPERANDS_SWAPPED(L) (L)->operands_swapped
385 #define LOOP_REQUIRES_VERSIONING_FOR_ALIGNMENT(L) \
386 (L)->may_misalign_stmts.length () > 0
387 #define LOOP_REQUIRES_VERSIONING_FOR_ALIAS(L) \
388 (L)->may_alias_ddrs.length () > 0
390 #define NITERS_KNOWN_P(n) \
391 (tree_fits_shwi_p ((n)) \
392 && TREE_INT_CST_LOW ((n)) > 0)
394 #define LOOP_VINFO_NITERS_KNOWN_P(L) \
395 NITERS_KNOWN_P ((L)->num_iters)
397 static inline loop_vec_info
398 loop_vec_info_for_loop (struct loop *loop)
400 return (loop_vec_info) loop->aux;
403 static inline bool
404 nested_in_vect_loop_p (struct loop *loop, gimple stmt)
406 return (loop->inner
407 && (loop->inner == (gimple_bb (stmt))->loop_father));
410 typedef struct _bb_vec_info {
412 basic_block bb;
413 /* All interleaving chains of stores in the basic block, represented by the
414 first stmt in the chain. */
415 vec<gimple> grouped_stores;
417 /* All SLP instances in the basic block. This is a subset of the set of
418 GROUP_STORES of the basic block. */
419 vec<slp_instance> slp_instances;
421 /* All data references in the basic block. */
422 vec<data_reference_p> datarefs;
424 /* All data dependences in the basic block. */
425 vec<ddr_p> ddrs;
427 /* Cost data used by the target cost model. */
428 void *target_cost_data;
430 } *bb_vec_info;
432 #define BB_VINFO_BB(B) (B)->bb
433 #define BB_VINFO_GROUPED_STORES(B) (B)->grouped_stores
434 #define BB_VINFO_SLP_INSTANCES(B) (B)->slp_instances
435 #define BB_VINFO_DATAREFS(B) (B)->datarefs
436 #define BB_VINFO_DDRS(B) (B)->ddrs
437 #define BB_VINFO_TARGET_COST_DATA(B) (B)->target_cost_data
439 static inline bb_vec_info
440 vec_info_for_bb (basic_block bb)
442 return (bb_vec_info) bb->aux;
445 /*-----------------------------------------------------------------*/
446 /* Info on vectorized defs. */
447 /*-----------------------------------------------------------------*/
448 enum stmt_vec_info_type {
449 undef_vec_info_type = 0,
450 load_vec_info_type,
451 store_vec_info_type,
452 shift_vec_info_type,
453 op_vec_info_type,
454 call_vec_info_type,
455 assignment_vec_info_type,
456 condition_vec_info_type,
457 reduc_vec_info_type,
458 induc_vec_info_type,
459 type_promotion_vec_info_type,
460 type_demotion_vec_info_type,
461 type_conversion_vec_info_type,
462 loop_exit_ctrl_vec_info_type
465 /* Indicates whether/how a variable is used in the scope of loop/basic
466 block. */
467 enum vect_relevant {
468 vect_unused_in_scope = 0,
469 /* The def is in the inner loop, and the use is in the outer loop, and the
470 use is a reduction stmt. */
471 vect_used_in_outer_by_reduction,
472 /* The def is in the inner loop, and the use is in the outer loop (and is
473 not part of reduction). */
474 vect_used_in_outer,
476 /* defs that feed computations that end up (only) in a reduction. These
477 defs may be used by non-reduction stmts, but eventually, any
478 computations/values that are affected by these defs are used to compute
479 a reduction (i.e. don't get stored to memory, for example). We use this
480 to identify computations that we can change the order in which they are
481 computed. */
482 vect_used_by_reduction,
484 vect_used_in_scope
487 /* The type of vectorization that can be applied to the stmt: regular loop-based
488 vectorization; pure SLP - the stmt is a part of SLP instances and does not
489 have uses outside SLP instances; or hybrid SLP and loop-based - the stmt is
490 a part of SLP instance and also must be loop-based vectorized, since it has
491 uses outside SLP sequences.
493 In the loop context the meanings of pure and hybrid SLP are slightly
494 different. By saying that pure SLP is applied to the loop, we mean that we
495 exploit only intra-iteration parallelism in the loop; i.e., the loop can be
496 vectorized without doing any conceptual unrolling, cause we don't pack
497 together stmts from different iterations, only within a single iteration.
498 Loop hybrid SLP means that we exploit both intra-iteration and
499 inter-iteration parallelism (e.g., number of elements in the vector is 4
500 and the slp-group-size is 2, in which case we don't have enough parallelism
501 within an iteration, so we obtain the rest of the parallelism from subsequent
502 iterations by unrolling the loop by 2). */
503 enum slp_vect_type {
504 loop_vect = 0,
505 pure_slp,
506 hybrid
510 typedef struct data_reference *dr_p;
512 typedef struct _stmt_vec_info {
514 enum stmt_vec_info_type type;
516 /* Indicates whether this stmts is part of a computation whose result is
517 used outside the loop. */
518 bool live;
520 /* Stmt is part of some pattern (computation idiom) */
521 bool in_pattern_p;
523 /* The stmt to which this info struct refers to. */
524 gimple stmt;
526 /* The loop_vec_info with respect to which STMT is vectorized. */
527 loop_vec_info loop_vinfo;
529 /* The vector type to be used for the LHS of this statement. */
530 tree vectype;
532 /* The vectorized version of the stmt. */
533 gimple vectorized_stmt;
536 /** The following is relevant only for stmts that contain a non-scalar
537 data-ref (array/pointer/struct access). A GIMPLE stmt is expected to have
538 at most one such data-ref. **/
540 /* Information about the data-ref (access function, etc),
541 relative to the inner-most containing loop. */
542 struct data_reference *data_ref_info;
544 /* Information about the data-ref relative to this loop
545 nest (the loop that is being considered for vectorization). */
546 tree dr_base_address;
547 tree dr_init;
548 tree dr_offset;
549 tree dr_step;
550 tree dr_aligned_to;
552 /* For loop PHI nodes, the evolution part of it. This makes sure
553 this information is still available in vect_update_ivs_after_vectorizer
554 where we may not be able to re-analyze the PHI nodes evolution as
555 peeling for the prologue loop can make it unanalyzable. The evolution
556 part is still correct though. */
557 tree loop_phi_evolution_part;
559 /* Used for various bookkeeping purposes, generally holding a pointer to
560 some other stmt S that is in some way "related" to this stmt.
561 Current use of this field is:
562 If this stmt is part of a pattern (i.e. the field 'in_pattern_p' is
563 true): S is the "pattern stmt" that represents (and replaces) the
564 sequence of stmts that constitutes the pattern. Similarly, the
565 related_stmt of the "pattern stmt" points back to this stmt (which is
566 the last stmt in the original sequence of stmts that constitutes the
567 pattern). */
568 gimple related_stmt;
570 /* Used to keep a sequence of def stmts of a pattern stmt if such exists. */
571 gimple_seq pattern_def_seq;
573 /* List of datarefs that are known to have the same alignment as the dataref
574 of this stmt. */
575 vec<dr_p> same_align_refs;
577 /* Classify the def of this stmt. */
578 enum vect_def_type def_type;
580 /* Whether the stmt is SLPed, loop-based vectorized, or both. */
581 enum slp_vect_type slp_type;
583 /* Interleaving and reduction chains info. */
584 /* First element in the group. */
585 gimple first_element;
586 /* Pointer to the next element in the group. */
587 gimple next_element;
588 /* For data-refs, in case that two or more stmts share data-ref, this is the
589 pointer to the previously detected stmt with the same dr. */
590 gimple same_dr_stmt;
591 /* The size of the group. */
592 unsigned int size;
593 /* For stores, number of stores from this group seen. We vectorize the last
594 one. */
595 unsigned int store_count;
596 /* For loads only, the gap from the previous load. For consecutive loads, GAP
597 is 1. */
598 unsigned int gap;
600 /* Not all stmts in the loop need to be vectorized. e.g, the increment
601 of the loop induction variable and computation of array indexes. relevant
602 indicates whether the stmt needs to be vectorized. */
603 enum vect_relevant relevant;
605 /* The bb_vec_info with respect to which STMT is vectorized. */
606 bb_vec_info bb_vinfo;
608 /* Is this statement vectorizable or should it be skipped in (partial)
609 vectorization. */
610 bool vectorizable;
612 /* For loads only, true if this is a gather load. */
613 bool gather_p;
614 bool stride_load_p;
616 /* For both loads and stores. */
617 bool simd_lane_access_p;
618 } *stmt_vec_info;
620 /* Access Functions. */
621 #define STMT_VINFO_TYPE(S) (S)->type
622 #define STMT_VINFO_STMT(S) (S)->stmt
623 #define STMT_VINFO_LOOP_VINFO(S) (S)->loop_vinfo
624 #define STMT_VINFO_BB_VINFO(S) (S)->bb_vinfo
625 #define STMT_VINFO_RELEVANT(S) (S)->relevant
626 #define STMT_VINFO_LIVE_P(S) (S)->live
627 #define STMT_VINFO_VECTYPE(S) (S)->vectype
628 #define STMT_VINFO_VEC_STMT(S) (S)->vectorized_stmt
629 #define STMT_VINFO_VECTORIZABLE(S) (S)->vectorizable
630 #define STMT_VINFO_DATA_REF(S) (S)->data_ref_info
631 #define STMT_VINFO_GATHER_P(S) (S)->gather_p
632 #define STMT_VINFO_STRIDE_LOAD_P(S) (S)->stride_load_p
633 #define STMT_VINFO_SIMD_LANE_ACCESS_P(S) (S)->simd_lane_access_p
635 #define STMT_VINFO_DR_BASE_ADDRESS(S) (S)->dr_base_address
636 #define STMT_VINFO_DR_INIT(S) (S)->dr_init
637 #define STMT_VINFO_DR_OFFSET(S) (S)->dr_offset
638 #define STMT_VINFO_DR_STEP(S) (S)->dr_step
639 #define STMT_VINFO_DR_ALIGNED_TO(S) (S)->dr_aligned_to
641 #define STMT_VINFO_IN_PATTERN_P(S) (S)->in_pattern_p
642 #define STMT_VINFO_RELATED_STMT(S) (S)->related_stmt
643 #define STMT_VINFO_PATTERN_DEF_SEQ(S) (S)->pattern_def_seq
644 #define STMT_VINFO_SAME_ALIGN_REFS(S) (S)->same_align_refs
645 #define STMT_VINFO_DEF_TYPE(S) (S)->def_type
646 #define STMT_VINFO_GROUP_FIRST_ELEMENT(S) (S)->first_element
647 #define STMT_VINFO_GROUP_NEXT_ELEMENT(S) (S)->next_element
648 #define STMT_VINFO_GROUP_SIZE(S) (S)->size
649 #define STMT_VINFO_GROUP_STORE_COUNT(S) (S)->store_count
650 #define STMT_VINFO_GROUP_GAP(S) (S)->gap
651 #define STMT_VINFO_GROUP_SAME_DR_STMT(S) (S)->same_dr_stmt
652 #define STMT_VINFO_GROUPED_ACCESS(S) ((S)->first_element != NULL && (S)->data_ref_info)
653 #define STMT_VINFO_LOOP_PHI_EVOLUTION_PART(S) (S)->loop_phi_evolution_part
655 #define GROUP_FIRST_ELEMENT(S) (S)->first_element
656 #define GROUP_NEXT_ELEMENT(S) (S)->next_element
657 #define GROUP_SIZE(S) (S)->size
658 #define GROUP_STORE_COUNT(S) (S)->store_count
659 #define GROUP_GAP(S) (S)->gap
660 #define GROUP_SAME_DR_STMT(S) (S)->same_dr_stmt
662 #define STMT_VINFO_RELEVANT_P(S) ((S)->relevant != vect_unused_in_scope)
664 #define HYBRID_SLP_STMT(S) ((S)->slp_type == hybrid)
665 #define PURE_SLP_STMT(S) ((S)->slp_type == pure_slp)
666 #define STMT_SLP_TYPE(S) (S)->slp_type
668 struct dataref_aux {
669 tree base_decl;
670 bool base_misaligned;
671 int misalignment;
674 #define VECT_MAX_COST 1000
676 /* The maximum number of intermediate steps required in multi-step type
677 conversion. */
678 #define MAX_INTERM_CVT_STEPS 3
680 /* The maximum vectorization factor supported by any target (V32QI). */
681 #define MAX_VECTORIZATION_FACTOR 32
683 /* Avoid GTY(()) on stmt_vec_info. */
684 typedef void *vec_void_p;
686 extern vec<vec_void_p> stmt_vec_info_vec;
688 void init_stmt_vec_info_vec (void);
689 void free_stmt_vec_info_vec (void);
691 /* Return a stmt_vec_info corresponding to STMT. */
693 static inline stmt_vec_info
694 vinfo_for_stmt (gimple stmt)
696 unsigned int uid = gimple_uid (stmt);
697 if (uid == 0)
698 return NULL;
700 return (stmt_vec_info) stmt_vec_info_vec[uid - 1];
703 /* Set vectorizer information INFO for STMT. */
705 static inline void
706 set_vinfo_for_stmt (gimple stmt, stmt_vec_info info)
708 unsigned int uid = gimple_uid (stmt);
709 if (uid == 0)
711 gcc_checking_assert (info);
712 uid = stmt_vec_info_vec.length () + 1;
713 gimple_set_uid (stmt, uid);
714 stmt_vec_info_vec.safe_push ((vec_void_p) info);
716 else
717 stmt_vec_info_vec[uid - 1] = (vec_void_p) info;
720 /* Return the earlier statement between STMT1 and STMT2. */
722 static inline gimple
723 get_earlier_stmt (gimple stmt1, gimple stmt2)
725 unsigned int uid1, uid2;
727 if (stmt1 == NULL)
728 return stmt2;
730 if (stmt2 == NULL)
731 return stmt1;
733 uid1 = gimple_uid (stmt1);
734 uid2 = gimple_uid (stmt2);
736 if (uid1 == 0 || uid2 == 0)
737 return NULL;
739 gcc_checking_assert (uid1 <= stmt_vec_info_vec.length ()
740 && uid2 <= stmt_vec_info_vec.length ());
742 if (uid1 < uid2)
743 return stmt1;
744 else
745 return stmt2;
748 /* Return the later statement between STMT1 and STMT2. */
750 static inline gimple
751 get_later_stmt (gimple stmt1, gimple stmt2)
753 unsigned int uid1, uid2;
755 if (stmt1 == NULL)
756 return stmt2;
758 if (stmt2 == NULL)
759 return stmt1;
761 uid1 = gimple_uid (stmt1);
762 uid2 = gimple_uid (stmt2);
764 if (uid1 == 0 || uid2 == 0)
765 return NULL;
767 gcc_assert (uid1 <= stmt_vec_info_vec.length ());
768 gcc_assert (uid2 <= stmt_vec_info_vec.length ());
770 if (uid1 > uid2)
771 return stmt1;
772 else
773 return stmt2;
776 /* Return TRUE if a statement represented by STMT_INFO is a part of a
777 pattern. */
779 static inline bool
780 is_pattern_stmt_p (stmt_vec_info stmt_info)
782 gimple related_stmt;
783 stmt_vec_info related_stmt_info;
785 related_stmt = STMT_VINFO_RELATED_STMT (stmt_info);
786 if (related_stmt
787 && (related_stmt_info = vinfo_for_stmt (related_stmt))
788 && STMT_VINFO_IN_PATTERN_P (related_stmt_info))
789 return true;
791 return false;
794 /* Return true if BB is a loop header. */
796 static inline bool
797 is_loop_header_bb_p (basic_block bb)
799 if (bb == (bb->loop_father)->header)
800 return true;
801 gcc_checking_assert (EDGE_COUNT (bb->preds) == 1);
802 return false;
805 /* Return pow2 (X). */
807 static inline int
808 vect_pow2 (int x)
810 int i, res = 1;
812 for (i = 0; i < x; i++)
813 res *= 2;
815 return res;
818 /* Alias targetm.vectorize.builtin_vectorization_cost. */
820 static inline int
821 builtin_vectorization_cost (enum vect_cost_for_stmt type_of_cost,
822 tree vectype, int misalign)
824 return targetm.vectorize.builtin_vectorization_cost (type_of_cost,
825 vectype, misalign);
828 /* Get cost by calling cost target builtin. */
830 static inline
831 int vect_get_stmt_cost (enum vect_cost_for_stmt type_of_cost)
833 return builtin_vectorization_cost (type_of_cost, NULL, 0);
836 /* Alias targetm.vectorize.init_cost. */
838 static inline void *
839 init_cost (struct loop *loop_info)
841 return targetm.vectorize.init_cost (loop_info);
844 /* Alias targetm.vectorize.add_stmt_cost. */
846 static inline unsigned
847 add_stmt_cost (void *data, int count, enum vect_cost_for_stmt kind,
848 stmt_vec_info stmt_info, int misalign,
849 enum vect_cost_model_location where)
851 return targetm.vectorize.add_stmt_cost (data, count, kind,
852 stmt_info, misalign, where);
855 /* Alias targetm.vectorize.finish_cost. */
857 static inline void
858 finish_cost (void *data, unsigned *prologue_cost,
859 unsigned *body_cost, unsigned *epilogue_cost)
861 targetm.vectorize.finish_cost (data, prologue_cost, body_cost, epilogue_cost);
864 /* Alias targetm.vectorize.destroy_cost_data. */
866 static inline void
867 destroy_cost_data (void *data)
869 targetm.vectorize.destroy_cost_data (data);
873 /*-----------------------------------------------------------------*/
874 /* Info on data references alignment. */
875 /*-----------------------------------------------------------------*/
876 inline void
877 set_dr_misalignment (struct data_reference *dr, int val)
879 dataref_aux *data_aux = (dataref_aux *) dr->aux;
881 if (!data_aux)
883 data_aux = XCNEW (dataref_aux);
884 dr->aux = data_aux;
887 data_aux->misalignment = val;
890 inline int
891 dr_misalignment (struct data_reference *dr)
893 gcc_assert (dr->aux);
894 return ((dataref_aux *) dr->aux)->misalignment;
897 /* Reflects actual alignment of first access in the vectorized loop,
898 taking into account peeling/versioning if applied. */
899 #define DR_MISALIGNMENT(DR) dr_misalignment (DR)
900 #define SET_DR_MISALIGNMENT(DR, VAL) set_dr_misalignment (DR, VAL)
902 /* Return TRUE if the data access is aligned, and FALSE otherwise. */
904 static inline bool
905 aligned_access_p (struct data_reference *data_ref_info)
907 return (DR_MISALIGNMENT (data_ref_info) == 0);
910 /* Return TRUE if the alignment of the data access is known, and FALSE
911 otherwise. */
913 static inline bool
914 known_alignment_for_access_p (struct data_reference *data_ref_info)
916 return (DR_MISALIGNMENT (data_ref_info) != -1);
920 /* Return true if the vect cost model is unlimited. */
921 static inline bool
922 unlimited_cost_model ()
924 return flag_vect_cost_model == VECT_COST_MODEL_UNLIMITED;
927 /* Source location */
928 extern LOC vect_location;
930 /*-----------------------------------------------------------------*/
931 /* Function prototypes. */
932 /*-----------------------------------------------------------------*/
934 /* Simple loop peeling and versioning utilities for vectorizer's purposes -
935 in tree-vect-loop-manip.c. */
936 extern void slpeel_make_loop_iterate_ntimes (struct loop *, tree);
937 extern bool slpeel_can_duplicate_loop_p (const struct loop *, const_edge);
938 struct loop *slpeel_tree_duplicate_loop_to_edge_cfg (struct loop *, edge);
939 extern void vect_loop_versioning (loop_vec_info, unsigned int, bool);
940 extern void vect_generate_tmps_on_preheader (loop_vec_info, tree *, tree *,
941 tree *, gimple_seq);
942 extern void vect_do_peeling_for_loop_bound (loop_vec_info, tree *,
943 unsigned int, bool);
944 extern void vect_do_peeling_for_alignment (loop_vec_info, unsigned int, bool);
945 extern LOC find_loop_location (struct loop *);
946 extern bool vect_can_advance_ivs_p (loop_vec_info);
948 /* In tree-vect-stmts.c. */
949 extern unsigned int current_vector_size;
950 extern tree get_vectype_for_scalar_type (tree);
951 extern tree get_same_sized_vectype (tree, tree);
952 extern bool vect_is_simple_use (tree, gimple, loop_vec_info,
953 bb_vec_info, gimple *,
954 tree *, enum vect_def_type *);
955 extern bool vect_is_simple_use_1 (tree, gimple, loop_vec_info,
956 bb_vec_info, gimple *,
957 tree *, enum vect_def_type *, tree *);
958 extern bool supportable_widening_operation (enum tree_code, gimple, tree, tree,
959 enum tree_code *, enum tree_code *,
960 int *, vec<tree> *);
961 extern bool supportable_narrowing_operation (enum tree_code, tree, tree,
962 enum tree_code *,
963 int *, vec<tree> *);
964 extern stmt_vec_info new_stmt_vec_info (gimple stmt, loop_vec_info,
965 bb_vec_info);
966 extern void free_stmt_vec_info (gimple stmt);
967 extern tree vectorizable_function (gimple, tree, tree);
968 extern void vect_model_simple_cost (stmt_vec_info, int, enum vect_def_type *,
969 stmt_vector_for_cost *,
970 stmt_vector_for_cost *);
971 extern void vect_model_store_cost (stmt_vec_info, int, bool,
972 enum vect_def_type, slp_tree,
973 stmt_vector_for_cost *,
974 stmt_vector_for_cost *);
975 extern void vect_model_load_cost (stmt_vec_info, int, bool, slp_tree,
976 stmt_vector_for_cost *,
977 stmt_vector_for_cost *);
978 extern unsigned record_stmt_cost (stmt_vector_for_cost *, int,
979 enum vect_cost_for_stmt, stmt_vec_info,
980 int, enum vect_cost_model_location);
981 extern void vect_finish_stmt_generation (gimple, gimple,
982 gimple_stmt_iterator *);
983 extern bool vect_mark_stmts_to_be_vectorized (loop_vec_info);
984 extern tree vect_get_vec_def_for_operand (tree, gimple, tree *);
985 extern tree vect_init_vector (gimple, tree, tree,
986 gimple_stmt_iterator *);
987 extern tree vect_get_vec_def_for_stmt_copy (enum vect_def_type, tree);
988 extern bool vect_transform_stmt (gimple, gimple_stmt_iterator *,
989 bool *, slp_tree, slp_instance);
990 extern void vect_remove_stores (gimple);
991 extern bool vect_analyze_stmt (gimple, bool *, slp_tree);
992 extern bool vectorizable_condition (gimple, gimple_stmt_iterator *, gimple *,
993 tree, int, slp_tree);
994 extern void vect_get_load_cost (struct data_reference *, int, bool,
995 unsigned int *, unsigned int *,
996 stmt_vector_for_cost *,
997 stmt_vector_for_cost *, bool);
998 extern void vect_get_store_cost (struct data_reference *, int,
999 unsigned int *, stmt_vector_for_cost *);
1000 extern bool vect_supportable_shift (enum tree_code, tree);
1001 extern void vect_get_vec_defs (tree, tree, gimple, vec<tree> *,
1002 vec<tree> *, slp_tree, int);
1003 extern tree vect_gen_perm_mask (tree, unsigned char *);
1005 /* In tree-vect-data-refs.c. */
1006 extern bool vect_can_force_dr_alignment_p (const_tree, unsigned int);
1007 extern enum dr_alignment_support vect_supportable_dr_alignment
1008 (struct data_reference *, bool);
1009 extern tree vect_get_smallest_scalar_type (gimple, HOST_WIDE_INT *,
1010 HOST_WIDE_INT *);
1011 extern bool vect_analyze_data_ref_dependences (loop_vec_info, int *);
1012 extern bool vect_slp_analyze_data_ref_dependences (bb_vec_info);
1013 extern bool vect_enhance_data_refs_alignment (loop_vec_info);
1014 extern bool vect_analyze_data_refs_alignment (loop_vec_info, bb_vec_info);
1015 extern bool vect_verify_datarefs_alignment (loop_vec_info, bb_vec_info);
1016 extern bool vect_analyze_data_ref_accesses (loop_vec_info, bb_vec_info);
1017 extern bool vect_prune_runtime_alias_test_list (loop_vec_info);
1018 extern tree vect_check_gather (gimple, loop_vec_info, tree *, tree *,
1019 int *);
1020 extern bool vect_analyze_data_refs (loop_vec_info, bb_vec_info, int *);
1021 extern tree vect_create_data_ref_ptr (gimple, tree, struct loop *, tree,
1022 tree *, gimple_stmt_iterator *,
1023 gimple *, bool, bool *);
1024 extern tree bump_vector_ptr (tree, gimple, gimple_stmt_iterator *, gimple, tree);
1025 extern tree vect_create_destination_var (tree, tree);
1026 extern bool vect_grouped_store_supported (tree, unsigned HOST_WIDE_INT);
1027 extern bool vect_store_lanes_supported (tree, unsigned HOST_WIDE_INT);
1028 extern bool vect_grouped_load_supported (tree, unsigned HOST_WIDE_INT);
1029 extern bool vect_load_lanes_supported (tree, unsigned HOST_WIDE_INT);
1030 extern void vect_permute_store_chain (vec<tree> ,unsigned int, gimple,
1031 gimple_stmt_iterator *, vec<tree> *);
1032 extern tree vect_setup_realignment (gimple, gimple_stmt_iterator *, tree *,
1033 enum dr_alignment_support, tree,
1034 struct loop **);
1035 extern void vect_transform_grouped_load (gimple, vec<tree> , int,
1036 gimple_stmt_iterator *);
1037 extern void vect_record_grouped_load_vectors (gimple, vec<tree> );
1038 extern tree vect_get_new_vect_var (tree, enum vect_var_kind, const char *);
1039 extern tree vect_create_addr_base_for_vector_ref (gimple, gimple_seq *,
1040 tree, struct loop *);
1042 /* In tree-vect-loop.c. */
1043 /* FORNOW: Used in tree-parloops.c. */
1044 extern void destroy_loop_vec_info (loop_vec_info, bool);
1045 extern gimple vect_force_simple_reduction (loop_vec_info, gimple, bool, bool *);
1046 /* Drive for loop analysis stage. */
1047 extern loop_vec_info vect_analyze_loop (struct loop *);
1048 /* Drive for loop transformation stage. */
1049 extern void vect_transform_loop (loop_vec_info);
1050 extern loop_vec_info vect_analyze_loop_form (struct loop *);
1051 extern bool vectorizable_live_operation (gimple, gimple_stmt_iterator *,
1052 gimple *);
1053 extern bool vectorizable_reduction (gimple, gimple_stmt_iterator *, gimple *,
1054 slp_tree);
1055 extern bool vectorizable_induction (gimple, gimple_stmt_iterator *, gimple *);
1056 extern tree get_initial_def_for_reduction (gimple, tree, tree *);
1057 extern int vect_min_worthwhile_factor (enum tree_code);
1058 extern int vect_get_known_peeling_cost (loop_vec_info, int, int *, int,
1059 stmt_vector_for_cost *,
1060 stmt_vector_for_cost *);
1061 extern int vect_get_single_scalar_iteration_cost (loop_vec_info);
1063 /* In tree-vect-slp.c. */
1064 extern void vect_free_slp_instance (slp_instance);
1065 extern bool vect_transform_slp_perm_load (slp_tree, vec<tree> ,
1066 gimple_stmt_iterator *, int,
1067 slp_instance, bool);
1068 extern bool vect_schedule_slp (loop_vec_info, bb_vec_info);
1069 extern void vect_update_slp_costs_according_to_vf (loop_vec_info);
1070 extern bool vect_analyze_slp (loop_vec_info, bb_vec_info);
1071 extern bool vect_make_slp_decision (loop_vec_info);
1072 extern void vect_detect_hybrid_slp (loop_vec_info);
1073 extern void vect_get_slp_defs (vec<tree> , slp_tree,
1074 vec<vec<tree> > *, int);
1076 extern LOC find_bb_location (basic_block);
1077 extern bb_vec_info vect_slp_analyze_bb (basic_block);
1078 extern void vect_slp_transform_bb (basic_block);
1080 /* In tree-vect-patterns.c. */
1081 /* Pattern recognition functions.
1082 Additional pattern recognition functions can (and will) be added
1083 in the future. */
1084 typedef gimple (* vect_recog_func_ptr) (vec<gimple> *, tree *, tree *);
1085 #define NUM_PATTERNS 11
1086 void vect_pattern_recog (loop_vec_info, bb_vec_info);
1088 /* In tree-vectorizer.c. */
1089 unsigned vectorize_loops (void);
1090 void vect_destroy_datarefs (loop_vec_info, bb_vec_info);
1092 #endif /* GCC_TREE_VECTORIZER_H */