2 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 Free Software Foundation, Inc.
4 Contributed by Dorit Naishlos <dorit@il.ibm.com>
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 #ifndef GCC_TREE_VECTORIZER_H
23 #define GCC_TREE_VECTORIZER_H
25 #include "tree-data-ref.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. */
41 /* Defines type of operation. */
48 /* Define type of available alignment support. */
49 enum dr_alignment_support
{
50 dr_unaligned_unsupported
,
51 dr_unaligned_supported
,
53 dr_explicit_realign_optimized
,
57 /* Define type of def-use cross-iteration cycle. */
59 vect_uninitialized_def
= 0,
60 vect_constant_def
= 1,
65 vect_double_reduction_def
,
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
{
78 enum vect_cost_for_stmt kind
;
83 DEF_VEC_O (stmt_info_for_cost
);
84 DEF_VEC_ALLOC_O (stmt_info_for_cost
, heap
);
86 typedef VEC(stmt_info_for_cost
, heap
) *stmt_vector_for_cost
;
89 add_stmt_info_to_vec (stmt_vector_for_cost
*stmt_cost_vec
, int count
,
90 enum vect_cost_for_stmt kind
, gimple stmt
, int misalign
)
92 stmt_info_for_cost si
;
96 si
.misalign
= misalign
;
97 VEC_safe_push (stmt_info_for_cost
, heap
, *stmt_cost_vec
, si
);
100 /************************************************************************
102 ************************************************************************/
103 typedef void *slp_void_p
;
104 DEF_VEC_P (slp_void_p
);
105 DEF_VEC_ALLOC_P (slp_void_p
, heap
);
107 /* A computation tree of an SLP instance. Each node corresponds to a group of
108 stmts to be packed in a SIMD stmt. */
109 typedef struct _slp_tree
{
110 /* Nodes that contain def-stmts of this node statements operands. */
111 VEC (slp_void_p
, heap
) *children
;
112 /* A group of scalar stmts to be vectorized together. */
113 VEC (gimple
, heap
) *stmts
;
114 /* Vectorized stmt/s. */
115 VEC (gimple
, heap
) *vec_stmts
;
116 /* Number of vector stmts that are created to replace the group of scalar
117 stmts. It is calculated during the transformation phase as the number of
118 scalar elements in one scalar iteration (GROUP_SIZE) multiplied by VF
119 divided by vector size. */
120 unsigned int vec_stmts_size
;
124 DEF_VEC_ALLOC_P(slp_tree
, heap
);
126 /* SLP instance is a sequence of stmts in a loop that can be packed into
128 typedef struct _slp_instance
{
129 /* The root of SLP tree. */
132 /* Size of groups of scalar stmts that will be replaced by SIMD stmt/s. */
133 unsigned int group_size
;
135 /* The unrolling factor required to vectorized this SLP instance. */
136 unsigned int unrolling_factor
;
138 /* Vectorization costs associated with SLP instance. */
139 stmt_vector_for_cost body_cost_vec
;
141 /* Loads permutation relatively to the stores, NULL if there is no
143 VEC (int, heap
) *load_permutation
;
145 /* The group of nodes that contain loads of this SLP instance. */
146 VEC (slp_tree
, heap
) *loads
;
148 /* The first scalar load of the instance. The created vector loads will be
149 inserted before this statement. */
153 DEF_VEC_P(slp_instance
);
154 DEF_VEC_ALLOC_P(slp_instance
, heap
);
156 /* Access Functions. */
157 #define SLP_INSTANCE_TREE(S) (S)->root
158 #define SLP_INSTANCE_GROUP_SIZE(S) (S)->group_size
159 #define SLP_INSTANCE_UNROLLING_FACTOR(S) (S)->unrolling_factor
160 #define SLP_INSTANCE_BODY_COST_VEC(S) (S)->body_cost_vec
161 #define SLP_INSTANCE_LOAD_PERMUTATION(S) (S)->load_permutation
162 #define SLP_INSTANCE_LOADS(S) (S)->loads
163 #define SLP_INSTANCE_FIRST_LOAD_STMT(S) (S)->first_load
165 #define SLP_TREE_CHILDREN(S) (S)->children
166 #define SLP_TREE_SCALAR_STMTS(S) (S)->stmts
167 #define SLP_TREE_VEC_STMTS(S) (S)->vec_stmts
168 #define SLP_TREE_NUMBER_OF_VEC_STMTS(S) (S)->vec_stmts_size
170 /* This structure is used in creation of an SLP tree. Each instance
171 corresponds to the same operand in a group of scalar stmts in an SLP
173 typedef struct _slp_oprnd_info
175 /* Def-stmts for the operands. */
176 VEC (gimple
, heap
) *def_stmts
;
177 /* Information about the first statement, its vector def-type, type, the
178 operand itself in case it's constant, and an indication if it's a pattern
180 enum vect_def_type first_dt
;
182 tree first_const_oprnd
;
186 DEF_VEC_P(slp_oprnd_info
);
187 DEF_VEC_ALLOC_P(slp_oprnd_info
, heap
);
190 typedef struct _vect_peel_info
193 struct data_reference
*dr
;
197 typedef struct _vect_peel_extended_info
199 struct _vect_peel_info peel_info
;
200 unsigned int inside_cost
;
201 unsigned int outside_cost
;
202 stmt_vector_for_cost body_cost_vec
;
203 } *vect_peel_extended_info
;
205 /*-----------------------------------------------------------------*/
206 /* Info on vectorized loops. */
207 /*-----------------------------------------------------------------*/
208 typedef struct _loop_vec_info
{
210 /* The loop to which this info struct refers to. */
213 /* The loop basic blocks. */
216 /* Number of iterations. */
218 tree num_iters_unchanged
;
220 /* Minimum number of iterations below which vectorization is expected to
221 not be profitable (as estimated by the cost model).
222 -1 indicates that vectorization will not be profitable.
223 FORNOW: This field is an int. Will be a tree in the future, to represent
224 values unknown at compile time. */
225 int min_profitable_iters
;
227 /* Is the loop vectorizable? */
230 /* Unrolling factor */
231 int vectorization_factor
;
233 /* The loop location in the source. */
234 LOC loop_line_number
;
236 /* Unknown DRs according to which loop was peeled. */
237 struct data_reference
*unaligned_dr
;
239 /* peeling_for_alignment indicates whether peeling for alignment will take
240 place, and what the peeling factor should be:
241 peeling_for_alignment = X means:
242 If X=0: Peeling for alignment will not be applied.
243 If X>0: Peel first X iterations.
244 If X=-1: Generate a runtime test to calculate the number of iterations
245 to be peeled, using the dataref recorded in the field
247 int peeling_for_alignment
;
249 /* The mask used to check the alignment of pointers or arrays. */
252 /* The loop nest in which the data dependences are computed. */
253 VEC (loop_p
, heap
) *loop_nest
;
255 /* All data references in the loop. */
256 VEC (data_reference_p
, heap
) *datarefs
;
258 /* All data dependences in the loop. */
259 VEC (ddr_p
, heap
) *ddrs
;
261 /* Data Dependence Relations defining address ranges that are candidates
262 for a run-time aliasing check. */
263 VEC (ddr_p
, heap
) *may_alias_ddrs
;
265 /* Statements in the loop that have data references that are candidates for a
266 runtime (loop versioning) misalignment check. */
267 VEC(gimple
,heap
) *may_misalign_stmts
;
269 /* All interleaving chains of stores in the loop, represented by the first
270 stmt in the chain. */
271 VEC(gimple
, heap
) *grouped_stores
;
273 /* All SLP instances in the loop. This is a subset of the set of GROUP_STORES
275 VEC(slp_instance
, heap
) *slp_instances
;
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
, heap
) *reductions
;
284 /* All reduction chains in the loop, represented by the first
285 stmt in the chain. */
286 VEC (gimple
, heap
) *reduction_chains
;
288 /* Hash table used to choose the best peeling option. */
291 /* Cost data used by the target cost model. */
292 void *target_cost_data
;
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
297 bool peeling_for_gaps
;
299 /* Reductions are canonicalized so that the last operand is the reduction
300 operand. If this places a constant into RHS1, this decanonicalizes
301 GIMPLE for other phases, so we must track when this has occurred and
303 bool operands_swapped
;
307 /* Access Functions. */
308 #define LOOP_VINFO_LOOP(L) (L)->loop
309 #define LOOP_VINFO_BBS(L) (L)->bbs
310 #define LOOP_VINFO_NITERS(L) (L)->num_iters
311 /* Since LOOP_VINFO_NITERS can change after prologue peeling
312 retain total unchanged scalar loop iterations for cost model. */
313 #define LOOP_VINFO_NITERS_UNCHANGED(L) (L)->num_iters_unchanged
314 #define LOOP_VINFO_COST_MODEL_MIN_ITERS(L) (L)->min_profitable_iters
315 #define LOOP_VINFO_VECTORIZABLE_P(L) (L)->vectorizable
316 #define LOOP_VINFO_VECT_FACTOR(L) (L)->vectorization_factor
317 #define LOOP_VINFO_PTR_MASK(L) (L)->ptr_mask
318 #define LOOP_VINFO_LOOP_NEST(L) (L)->loop_nest
319 #define LOOP_VINFO_DATAREFS(L) (L)->datarefs
320 #define LOOP_VINFO_DDRS(L) (L)->ddrs
321 #define LOOP_VINFO_INT_NITERS(L) (TREE_INT_CST_LOW ((L)->num_iters))
322 #define LOOP_PEELING_FOR_ALIGNMENT(L) (L)->peeling_for_alignment
323 #define LOOP_VINFO_UNALIGNED_DR(L) (L)->unaligned_dr
324 #define LOOP_VINFO_MAY_MISALIGN_STMTS(L) (L)->may_misalign_stmts
325 #define LOOP_VINFO_LOC(L) (L)->loop_line_number
326 #define LOOP_VINFO_MAY_ALIAS_DDRS(L) (L)->may_alias_ddrs
327 #define LOOP_VINFO_GROUPED_STORES(L) (L)->grouped_stores
328 #define LOOP_VINFO_SLP_INSTANCES(L) (L)->slp_instances
329 #define LOOP_VINFO_SLP_UNROLLING_FACTOR(L) (L)->slp_unrolling_factor
330 #define LOOP_VINFO_REDUCTIONS(L) (L)->reductions
331 #define LOOP_VINFO_REDUCTION_CHAINS(L) (L)->reduction_chains
332 #define LOOP_VINFO_PEELING_HTAB(L) (L)->peeling_htab
333 #define LOOP_VINFO_TARGET_COST_DATA(L) (L)->target_cost_data
334 #define LOOP_VINFO_PEELING_FOR_GAPS(L) (L)->peeling_for_gaps
335 #define LOOP_VINFO_OPERANDS_SWAPPED(L) (L)->operands_swapped
337 #define LOOP_REQUIRES_VERSIONING_FOR_ALIGNMENT(L) \
338 VEC_length (gimple, (L)->may_misalign_stmts) > 0
339 #define LOOP_REQUIRES_VERSIONING_FOR_ALIAS(L) \
340 VEC_length (ddr_p, (L)->may_alias_ddrs) > 0
342 #define NITERS_KNOWN_P(n) \
343 (host_integerp ((n),0) \
344 && TREE_INT_CST_LOW ((n)) > 0)
346 #define LOOP_VINFO_NITERS_KNOWN_P(L) \
347 NITERS_KNOWN_P((L)->num_iters)
349 static inline loop_vec_info
350 loop_vec_info_for_loop (struct loop
*loop
)
352 return (loop_vec_info
) loop
->aux
;
356 nested_in_vect_loop_p (struct loop
*loop
, gimple stmt
)
359 && (loop
->inner
== (gimple_bb (stmt
))->loop_father
));
362 typedef struct _bb_vec_info
{
365 /* All interleaving chains of stores in the basic block, represented by the
366 first stmt in the chain. */
367 VEC(gimple
, heap
) *grouped_stores
;
369 /* All SLP instances in the basic block. This is a subset of the set of
370 GROUP_STORES of the basic block. */
371 VEC(slp_instance
, heap
) *slp_instances
;
373 /* All data references in the basic block. */
374 VEC (data_reference_p
, heap
) *datarefs
;
376 /* All data dependences in the basic block. */
377 VEC (ddr_p
, heap
) *ddrs
;
379 /* Cost data used by the target cost model. */
380 void *target_cost_data
;
384 #define BB_VINFO_BB(B) (B)->bb
385 #define BB_VINFO_GROUPED_STORES(B) (B)->grouped_stores
386 #define BB_VINFO_SLP_INSTANCES(B) (B)->slp_instances
387 #define BB_VINFO_DATAREFS(B) (B)->datarefs
388 #define BB_VINFO_DDRS(B) (B)->ddrs
389 #define BB_VINFO_TARGET_COST_DATA(B) (B)->target_cost_data
391 static inline bb_vec_info
392 vec_info_for_bb (basic_block bb
)
394 return (bb_vec_info
) bb
->aux
;
397 /*-----------------------------------------------------------------*/
398 /* Info on vectorized defs. */
399 /*-----------------------------------------------------------------*/
400 enum stmt_vec_info_type
{
401 undef_vec_info_type
= 0,
407 assignment_vec_info_type
,
408 condition_vec_info_type
,
411 type_promotion_vec_info_type
,
412 type_demotion_vec_info_type
,
413 type_conversion_vec_info_type
,
414 loop_exit_ctrl_vec_info_type
417 /* Indicates whether/how a variable is used in the scope of loop/basic
420 vect_unused_in_scope
= 0,
421 /* The def is in the inner loop, and the use is in the outer loop, and the
422 use is a reduction stmt. */
423 vect_used_in_outer_by_reduction
,
424 /* The def is in the inner loop, and the use is in the outer loop (and is
425 not part of reduction). */
428 /* defs that feed computations that end up (only) in a reduction. These
429 defs may be used by non-reduction stmts, but eventually, any
430 computations/values that are affected by these defs are used to compute
431 a reduction (i.e. don't get stored to memory, for example). We use this
432 to identify computations that we can change the order in which they are
434 vect_used_by_reduction
,
439 /* The type of vectorization that can be applied to the stmt: regular loop-based
440 vectorization; pure SLP - the stmt is a part of SLP instances and does not
441 have uses outside SLP instances; or hybrid SLP and loop-based - the stmt is
442 a part of SLP instance and also must be loop-based vectorized, since it has
443 uses outside SLP sequences.
445 In the loop context the meanings of pure and hybrid SLP are slightly
446 different. By saying that pure SLP is applied to the loop, we mean that we
447 exploit only intra-iteration parallelism in the loop; i.e., the loop can be
448 vectorized without doing any conceptual unrolling, cause we don't pack
449 together stmts from different iterations, only within a single iteration.
450 Loop hybrid SLP means that we exploit both intra-iteration and
451 inter-iteration parallelism (e.g., number of elements in the vector is 4
452 and the slp-group-size is 2, in which case we don't have enough parallelism
453 within an iteration, so we obtain the rest of the parallelism from subsequent
454 iterations by unrolling the loop by 2). */
462 typedef struct data_reference
*dr_p
;
464 DEF_VEC_ALLOC_P(dr_p
,heap
);
466 typedef struct _stmt_vec_info
{
468 enum stmt_vec_info_type type
;
470 /* Indicates whether this stmts is part of a computation whose result is
471 used outside the loop. */
474 /* Stmt is part of some pattern (computation idiom) */
477 /* For loads only, if there is a store with the same location, this field is
481 /* The stmt to which this info struct refers to. */
484 /* The loop_vec_info with respect to which STMT is vectorized. */
485 loop_vec_info loop_vinfo
;
487 /* The vector type to be used for the LHS of this statement. */
490 /* The vectorized version of the stmt. */
491 gimple vectorized_stmt
;
494 /** The following is relevant only for stmts that contain a non-scalar
495 data-ref (array/pointer/struct access). A GIMPLE stmt is expected to have
496 at most one such data-ref. **/
498 /* Information about the data-ref (access function, etc),
499 relative to the inner-most containing loop. */
500 struct data_reference
*data_ref_info
;
502 /* Information about the data-ref relative to this loop
503 nest (the loop that is being considered for vectorization). */
504 tree dr_base_address
;
510 /* For loop PHI nodes, the evolution part of it. This makes sure
511 this information is still available in vect_update_ivs_after_vectorizer
512 where we may not be able to re-analyze the PHI nodes evolution as
513 peeling for the prologue loop can make it unanalyzable. The evolution
514 part is still correct though. */
515 tree loop_phi_evolution_part
;
517 /* Used for various bookkeeping purposes, generally holding a pointer to
518 some other stmt S that is in some way "related" to this stmt.
519 Current use of this field is:
520 If this stmt is part of a pattern (i.e. the field 'in_pattern_p' is
521 true): S is the "pattern stmt" that represents (and replaces) the
522 sequence of stmts that constitutes the pattern. Similarly, the
523 related_stmt of the "pattern stmt" points back to this stmt (which is
524 the last stmt in the original sequence of stmts that constitutes the
528 /* Used to keep a sequence of def stmts of a pattern stmt if such exists. */
529 gimple_seq pattern_def_seq
;
531 /* List of datarefs that are known to have the same alignment as the dataref
533 VEC(dr_p
,heap
) *same_align_refs
;
535 /* Classify the def of this stmt. */
536 enum vect_def_type def_type
;
538 /* Whether the stmt is SLPed, loop-based vectorized, or both. */
539 enum slp_vect_type slp_type
;
541 /* Interleaving and reduction chains info. */
542 /* First element in the group. */
543 gimple first_element
;
544 /* Pointer to the next element in the group. */
546 /* For data-refs, in case that two or more stmts share data-ref, this is the
547 pointer to the previously detected stmt with the same dr. */
549 /* The size of the group. */
551 /* For stores, number of stores from this group seen. We vectorize the last
553 unsigned int store_count
;
554 /* For loads only, the gap from the previous load. For consecutive loads, GAP
558 /* Not all stmts in the loop need to be vectorized. e.g, the increment
559 of the loop induction variable and computation of array indexes. relevant
560 indicates whether the stmt needs to be vectorized. */
561 enum vect_relevant relevant
;
563 /* The bb_vec_info with respect to which STMT is vectorized. */
564 bb_vec_info bb_vinfo
;
566 /* Is this statement vectorizable or should it be skipped in (partial)
570 /* For loads only, true if this is a gather load. */
575 /* Access Functions. */
576 #define STMT_VINFO_TYPE(S) (S)->type
577 #define STMT_VINFO_STMT(S) (S)->stmt
578 #define STMT_VINFO_LOOP_VINFO(S) (S)->loop_vinfo
579 #define STMT_VINFO_BB_VINFO(S) (S)->bb_vinfo
580 #define STMT_VINFO_RELEVANT(S) (S)->relevant
581 #define STMT_VINFO_LIVE_P(S) (S)->live
582 #define STMT_VINFO_VECTYPE(S) (S)->vectype
583 #define STMT_VINFO_VEC_STMT(S) (S)->vectorized_stmt
584 #define STMT_VINFO_VECTORIZABLE(S) (S)->vectorizable
585 #define STMT_VINFO_DATA_REF(S) (S)->data_ref_info
586 #define STMT_VINFO_GATHER_P(S) (S)->gather_p
587 #define STMT_VINFO_STRIDE_LOAD_P(S) (S)->stride_load_p
589 #define STMT_VINFO_DR_BASE_ADDRESS(S) (S)->dr_base_address
590 #define STMT_VINFO_DR_INIT(S) (S)->dr_init
591 #define STMT_VINFO_DR_OFFSET(S) (S)->dr_offset
592 #define STMT_VINFO_DR_STEP(S) (S)->dr_step
593 #define STMT_VINFO_DR_ALIGNED_TO(S) (S)->dr_aligned_to
595 #define STMT_VINFO_IN_PATTERN_P(S) (S)->in_pattern_p
596 #define STMT_VINFO_RELATED_STMT(S) (S)->related_stmt
597 #define STMT_VINFO_PATTERN_DEF_SEQ(S) (S)->pattern_def_seq
598 #define STMT_VINFO_SAME_ALIGN_REFS(S) (S)->same_align_refs
599 #define STMT_VINFO_DEF_TYPE(S) (S)->def_type
600 #define STMT_VINFO_GROUP_FIRST_ELEMENT(S) (S)->first_element
601 #define STMT_VINFO_GROUP_NEXT_ELEMENT(S) (S)->next_element
602 #define STMT_VINFO_GROUP_SIZE(S) (S)->size
603 #define STMT_VINFO_GROUP_STORE_COUNT(S) (S)->store_count
604 #define STMT_VINFO_GROUP_GAP(S) (S)->gap
605 #define STMT_VINFO_GROUP_SAME_DR_STMT(S) (S)->same_dr_stmt
606 #define STMT_VINFO_GROUP_READ_WRITE_DEPENDENCE(S) (S)->read_write_dep
607 #define STMT_VINFO_GROUPED_ACCESS(S) ((S)->first_element != NULL && (S)->data_ref_info)
608 #define STMT_VINFO_LOOP_PHI_EVOLUTION_PART(S) (S)->loop_phi_evolution_part
610 #define GROUP_FIRST_ELEMENT(S) (S)->first_element
611 #define GROUP_NEXT_ELEMENT(S) (S)->next_element
612 #define GROUP_SIZE(S) (S)->size
613 #define GROUP_STORE_COUNT(S) (S)->store_count
614 #define GROUP_GAP(S) (S)->gap
615 #define GROUP_SAME_DR_STMT(S) (S)->same_dr_stmt
616 #define GROUP_READ_WRITE_DEPENDENCE(S) (S)->read_write_dep
618 #define STMT_VINFO_RELEVANT_P(S) ((S)->relevant != vect_unused_in_scope)
620 #define HYBRID_SLP_STMT(S) ((S)->slp_type == hybrid)
621 #define PURE_SLP_STMT(S) ((S)->slp_type == pure_slp)
622 #define STMT_SLP_TYPE(S) (S)->slp_type
624 #define VECT_MAX_COST 1000
626 /* The maximum number of intermediate steps required in multi-step type
628 #define MAX_INTERM_CVT_STEPS 3
630 /* The maximum vectorization factor supported by any target (V32QI). */
631 #define MAX_VECTORIZATION_FACTOR 32
633 /* Avoid GTY(()) on stmt_vec_info. */
634 typedef void *vec_void_p
;
635 DEF_VEC_P (vec_void_p
);
636 DEF_VEC_ALLOC_P (vec_void_p
, heap
);
638 extern VEC(vec_void_p
,heap
) *stmt_vec_info_vec
;
640 void init_stmt_vec_info_vec (void);
641 void free_stmt_vec_info_vec (void);
643 /* Return a stmt_vec_info corresponding to STMT. */
645 static inline stmt_vec_info
646 vinfo_for_stmt (gimple stmt
)
648 unsigned int uid
= gimple_uid (stmt
);
652 return (stmt_vec_info
) VEC_index (vec_void_p
, stmt_vec_info_vec
, uid
- 1);
655 /* Set vectorizer information INFO for STMT. */
658 set_vinfo_for_stmt (gimple stmt
, stmt_vec_info info
)
660 unsigned int uid
= gimple_uid (stmt
);
663 gcc_checking_assert (info
);
664 uid
= VEC_length (vec_void_p
, stmt_vec_info_vec
) + 1;
665 gimple_set_uid (stmt
, uid
);
666 VEC_safe_push (vec_void_p
, heap
, stmt_vec_info_vec
, (vec_void_p
) info
);
669 VEC_replace (vec_void_p
, stmt_vec_info_vec
, uid
- 1, (vec_void_p
) info
);
672 /* Return the earlier statement between STMT1 and STMT2. */
675 get_earlier_stmt (gimple stmt1
, gimple stmt2
)
677 unsigned int uid1
, uid2
;
685 uid1
= gimple_uid (stmt1
);
686 uid2
= gimple_uid (stmt2
);
688 if (uid1
== 0 || uid2
== 0)
691 gcc_checking_assert (uid1
<= VEC_length (vec_void_p
, stmt_vec_info_vec
)
692 && uid2
<= VEC_length (vec_void_p
, stmt_vec_info_vec
));
700 /* Return the later statement between STMT1 and STMT2. */
703 get_later_stmt (gimple stmt1
, gimple stmt2
)
705 unsigned int uid1
, uid2
;
713 uid1
= gimple_uid (stmt1
);
714 uid2
= gimple_uid (stmt2
);
716 if (uid1
== 0 || uid2
== 0)
719 gcc_assert (uid1
<= VEC_length (vec_void_p
, stmt_vec_info_vec
));
720 gcc_assert (uid2
<= VEC_length (vec_void_p
, stmt_vec_info_vec
));
728 /* Return TRUE if a statement represented by STMT_INFO is a part of a
732 is_pattern_stmt_p (stmt_vec_info stmt_info
)
735 stmt_vec_info related_stmt_info
;
737 related_stmt
= STMT_VINFO_RELATED_STMT (stmt_info
);
739 && (related_stmt_info
= vinfo_for_stmt (related_stmt
))
740 && STMT_VINFO_IN_PATTERN_P (related_stmt_info
))
746 /* Return true if BB is a loop header. */
749 is_loop_header_bb_p (basic_block bb
)
751 if (bb
== (bb
->loop_father
)->header
)
753 gcc_checking_assert (EDGE_COUNT (bb
->preds
) == 1);
757 /* Return pow2 (X). */
764 for (i
= 0; i
< x
; i
++)
770 /* Alias targetm.vectorize.builtin_vectorization_cost. */
773 builtin_vectorization_cost (enum vect_cost_for_stmt type_of_cost
,
774 tree vectype
, int misalign
)
776 return targetm
.vectorize
.builtin_vectorization_cost (type_of_cost
,
780 /* Get cost by calling cost target builtin. */
783 int vect_get_stmt_cost (enum vect_cost_for_stmt type_of_cost
)
785 return builtin_vectorization_cost (type_of_cost
, NULL
, 0);
788 /* Alias targetm.vectorize.init_cost. */
791 init_cost (struct loop
*loop_info
)
793 return targetm
.vectorize
.init_cost (loop_info
);
796 /* Alias targetm.vectorize.add_stmt_cost. */
798 static inline unsigned
799 add_stmt_cost (void *data
, int count
, enum vect_cost_for_stmt kind
,
800 stmt_vec_info stmt_info
, int misalign
,
801 enum vect_cost_model_location where
)
803 return targetm
.vectorize
.add_stmt_cost (data
, count
, kind
,
804 stmt_info
, misalign
, where
);
807 /* Alias targetm.vectorize.finish_cost. */
810 finish_cost (void *data
, unsigned *prologue_cost
,
811 unsigned *body_cost
, unsigned *epilogue_cost
)
813 targetm
.vectorize
.finish_cost (data
, prologue_cost
, body_cost
, epilogue_cost
);
816 /* Alias targetm.vectorize.destroy_cost_data. */
819 destroy_cost_data (void *data
)
821 targetm
.vectorize
.destroy_cost_data (data
);
825 /*-----------------------------------------------------------------*/
826 /* Info on data references alignment. */
827 /*-----------------------------------------------------------------*/
829 /* Reflects actual alignment of first access in the vectorized loop,
830 taking into account peeling/versioning if applied. */
831 #define DR_MISALIGNMENT(DR) ((int) (size_t) (DR)->aux)
832 #define SET_DR_MISALIGNMENT(DR, VAL) ((DR)->aux = (void *) (size_t) (VAL))
834 /* Return TRUE if the data access is aligned, and FALSE otherwise. */
837 aligned_access_p (struct data_reference
*data_ref_info
)
839 return (DR_MISALIGNMENT (data_ref_info
) == 0);
842 /* Return TRUE if the alignment of the data access is known, and FALSE
846 known_alignment_for_access_p (struct data_reference
*data_ref_info
)
848 return (DR_MISALIGNMENT (data_ref_info
) != -1);
851 /* vect_dump will be set to stderr or dump_file if exist. */
852 extern FILE *vect_dump
;
853 extern LOC vect_loop_location
;
855 /*-----------------------------------------------------------------*/
856 /* Function prototypes. */
857 /*-----------------------------------------------------------------*/
859 /* Simple loop peeling and versioning utilities for vectorizer's purposes -
860 in tree-vect-loop-manip.c. */
861 extern void slpeel_make_loop_iterate_ntimes (struct loop
*, tree
);
862 extern bool slpeel_can_duplicate_loop_p (const struct loop
*, const_edge
);
863 extern void vect_loop_versioning (loop_vec_info
, unsigned int, bool);
864 extern void vect_do_peeling_for_loop_bound (loop_vec_info
, tree
*,
866 extern void vect_do_peeling_for_alignment (loop_vec_info
, unsigned int, bool);
867 extern LOC
find_loop_location (struct loop
*);
868 extern bool vect_can_advance_ivs_p (loop_vec_info
);
870 /* In tree-vect-stmts.c. */
871 extern unsigned int current_vector_size
;
872 extern tree
get_vectype_for_scalar_type (tree
);
873 extern tree
get_same_sized_vectype (tree
, tree
);
874 extern bool vect_is_simple_use (tree
, gimple
, loop_vec_info
,
875 bb_vec_info
, gimple
*,
876 tree
*, enum vect_def_type
*);
877 extern bool vect_is_simple_use_1 (tree
, gimple
, loop_vec_info
,
878 bb_vec_info
, gimple
*,
879 tree
*, enum vect_def_type
*, tree
*);
880 extern bool supportable_widening_operation (enum tree_code
, gimple
, tree
, tree
,
881 enum tree_code
*, enum tree_code
*,
882 int *, VEC (tree
, heap
) **);
883 extern bool supportable_narrowing_operation (enum tree_code
, tree
, tree
,
885 int *, VEC (tree
, heap
) **);
886 extern stmt_vec_info
new_stmt_vec_info (gimple stmt
, loop_vec_info
,
888 extern void free_stmt_vec_info (gimple stmt
);
889 extern tree
vectorizable_function (gimple
, tree
, tree
);
890 extern void vect_model_simple_cost (stmt_vec_info
, int, enum vect_def_type
*,
891 stmt_vector_for_cost
*,
892 stmt_vector_for_cost
*);
893 extern void vect_model_store_cost (stmt_vec_info
, int, bool,
894 enum vect_def_type
, slp_tree
,
895 stmt_vector_for_cost
*,
896 stmt_vector_for_cost
*);
897 extern void vect_model_load_cost (stmt_vec_info
, int, bool, slp_tree
,
898 stmt_vector_for_cost
*,
899 stmt_vector_for_cost
*);
900 extern unsigned record_stmt_cost (stmt_vector_for_cost
*, int,
901 enum vect_cost_for_stmt
, stmt_vec_info
,
902 int, enum vect_cost_model_location
);
903 extern void vect_finish_stmt_generation (gimple
, gimple
,
904 gimple_stmt_iterator
*);
905 extern bool vect_mark_stmts_to_be_vectorized (loop_vec_info
);
906 extern tree
vect_get_vec_def_for_operand (tree
, gimple
, tree
*);
907 extern tree
vect_init_vector (gimple
, tree
, tree
,
908 gimple_stmt_iterator
*);
909 extern tree
vect_get_vec_def_for_stmt_copy (enum vect_def_type
, tree
);
910 extern bool vect_transform_stmt (gimple
, gimple_stmt_iterator
*,
911 bool *, slp_tree
, slp_instance
);
912 extern void vect_remove_stores (gimple
);
913 extern bool vect_analyze_stmt (gimple
, bool *, slp_tree
);
914 extern bool vectorizable_condition (gimple
, gimple_stmt_iterator
*, gimple
*,
915 tree
, int, slp_tree
);
916 extern void vect_get_load_cost (struct data_reference
*, int, bool,
917 unsigned int *, unsigned int *,
918 stmt_vector_for_cost
*,
919 stmt_vector_for_cost
*, bool);
920 extern void vect_get_store_cost (struct data_reference
*, int,
921 unsigned int *, stmt_vector_for_cost
*);
922 extern bool vect_supportable_shift (enum tree_code
, tree
);
923 extern void vect_get_vec_defs (tree
, tree
, gimple
, VEC (tree
, heap
) **,
924 VEC (tree
, heap
) **, slp_tree
, int);
925 extern tree
vect_gen_perm_mask (tree
, unsigned char *);
927 /* In tree-vect-data-refs.c. */
928 extern bool vect_can_force_dr_alignment_p (const_tree
, unsigned int);
929 extern enum dr_alignment_support vect_supportable_dr_alignment
930 (struct data_reference
*, bool);
931 extern tree
vect_get_smallest_scalar_type (gimple
, HOST_WIDE_INT
*,
933 extern bool vect_analyze_data_ref_dependences (loop_vec_info
, bb_vec_info
,
935 extern bool vect_enhance_data_refs_alignment (loop_vec_info
);
936 extern bool vect_analyze_data_refs_alignment (loop_vec_info
, bb_vec_info
);
937 extern bool vect_verify_datarefs_alignment (loop_vec_info
, bb_vec_info
);
938 extern bool vect_analyze_data_ref_accesses (loop_vec_info
, bb_vec_info
);
939 extern bool vect_prune_runtime_alias_test_list (loop_vec_info
);
940 extern tree
vect_check_gather (gimple
, loop_vec_info
, tree
*, tree
*,
942 extern bool vect_check_strided_load (gimple
, loop_vec_info
, tree
*, tree
*);
943 extern bool vect_analyze_data_refs (loop_vec_info
, bb_vec_info
, int *);
944 extern tree
vect_create_data_ref_ptr (gimple
, tree
, struct loop
*, tree
,
945 tree
*, gimple_stmt_iterator
*,
946 gimple
*, bool, bool *);
947 extern tree
bump_vector_ptr (tree
, gimple
, gimple_stmt_iterator
*, gimple
, tree
);
948 extern tree
vect_create_destination_var (tree
, tree
);
949 extern bool vect_grouped_store_supported (tree
, unsigned HOST_WIDE_INT
);
950 extern bool vect_store_lanes_supported (tree
, unsigned HOST_WIDE_INT
);
951 extern bool vect_grouped_load_supported (tree
, unsigned HOST_WIDE_INT
);
952 extern bool vect_load_lanes_supported (tree
, unsigned HOST_WIDE_INT
);
953 extern void vect_permute_store_chain (VEC(tree
,heap
) *,unsigned int, gimple
,
954 gimple_stmt_iterator
*, VEC(tree
,heap
) **);
955 extern tree
vect_setup_realignment (gimple
, gimple_stmt_iterator
*, tree
*,
956 enum dr_alignment_support
, tree
,
958 extern void vect_transform_grouped_load (gimple
, VEC(tree
,heap
) *, int,
959 gimple_stmt_iterator
*);
960 extern void vect_record_grouped_load_vectors (gimple
, VEC(tree
,heap
) *);
961 extern int vect_get_place_in_interleaving_chain (gimple
, gimple
);
962 extern tree
vect_get_new_vect_var (tree
, enum vect_var_kind
, const char *);
963 extern tree
vect_create_addr_base_for_vector_ref (gimple
, gimple_seq
*,
964 tree
, struct loop
*);
966 /* In tree-vect-loop.c. */
967 /* FORNOW: Used in tree-parloops.c. */
968 extern void destroy_loop_vec_info (loop_vec_info
, bool);
969 extern gimple
vect_force_simple_reduction (loop_vec_info
, gimple
, bool, bool *);
970 /* Drive for loop analysis stage. */
971 extern loop_vec_info
vect_analyze_loop (struct loop
*);
972 /* Drive for loop transformation stage. */
973 extern void vect_transform_loop (loop_vec_info
);
974 extern loop_vec_info
vect_analyze_loop_form (struct loop
*);
975 extern bool vectorizable_live_operation (gimple
, gimple_stmt_iterator
*,
977 extern bool vectorizable_reduction (gimple
, gimple_stmt_iterator
*, gimple
*,
979 extern bool vectorizable_induction (gimple
, gimple_stmt_iterator
*, gimple
*);
980 extern int vect_estimate_min_profitable_iters (loop_vec_info
);
981 extern tree
get_initial_def_for_reduction (gimple
, tree
, tree
*);
982 extern int vect_min_worthwhile_factor (enum tree_code
);
983 extern int vect_get_known_peeling_cost (loop_vec_info
, int, int *, int,
984 stmt_vector_for_cost
*,
985 stmt_vector_for_cost
*);
986 extern int vect_get_single_scalar_iteration_cost (loop_vec_info
);
988 /* In tree-vect-slp.c. */
989 extern void vect_free_slp_instance (slp_instance
);
990 extern bool vect_transform_slp_perm_load (gimple
, VEC (tree
, heap
) *,
991 gimple_stmt_iterator
*, int,
993 extern bool vect_schedule_slp (loop_vec_info
, bb_vec_info
);
994 extern void vect_update_slp_costs_according_to_vf (loop_vec_info
);
995 extern bool vect_analyze_slp (loop_vec_info
, bb_vec_info
);
996 extern bool vect_make_slp_decision (loop_vec_info
);
997 extern void vect_detect_hybrid_slp (loop_vec_info
);
998 extern void vect_get_slp_defs (VEC (tree
, heap
) *, slp_tree
,
999 VEC (slp_void_p
, heap
) **, int);
1001 extern LOC
find_bb_location (basic_block
);
1002 extern bb_vec_info
vect_slp_analyze_bb (basic_block
);
1003 extern void vect_slp_transform_bb (basic_block
);
1005 /* In tree-vect-patterns.c. */
1006 /* Pattern recognition functions.
1007 Additional pattern recognition functions can (and will) be added
1009 typedef gimple (* vect_recog_func_ptr
) (VEC (gimple
, heap
) **, tree
*, tree
*);
1010 #define NUM_PATTERNS 10
1011 void vect_pattern_recog (loop_vec_info
, bb_vec_info
);
1013 /* In tree-vectorizer.c. */
1014 unsigned vectorize_loops (void);
1015 /* Vectorization debug information */
1016 extern bool vect_print_dump_info (enum vect_verbosity_levels
);
1018 #endif /* GCC_TREE_VECTORIZER_H */