2012-07-06 Tom de Vries <tom@codesourcery.com>
[official-gcc.git] / gcc / tree-vectorizer.h
blob4c5ea36017d1e407e64c30acdcb7a6827051728a
1 /* Vectorizer
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
11 version.
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
16 for more details.
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"
26 #include "target.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 /************************************************************************
75 SLP
76 ************************************************************************/
77 typedef void *slp_void_p;
78 DEF_VEC_P (slp_void_p);
79 DEF_VEC_ALLOC_P (slp_void_p, heap);
81 /* A computation tree of an SLP instance. Each node corresponds to a group of
82 stmts to be packed in a SIMD stmt. */
83 typedef struct _slp_tree {
84 /* Nodes that contain def-stmts of this node statements operands. */
85 VEC (slp_void_p, heap) *children;
86 /* A group of scalar stmts to be vectorized together. */
87 VEC (gimple, heap) *stmts;
88 /* Vectorized stmt/s. */
89 VEC (gimple, heap) *vec_stmts;
90 /* Number of vector stmts that are created to replace the group of scalar
91 stmts. It is calculated during the transformation phase as the number of
92 scalar elements in one scalar iteration (GROUP_SIZE) multiplied by VF
93 divided by vector size. */
94 unsigned int vec_stmts_size;
95 /* Vectorization costs associated with SLP node. */
96 struct
98 int outside_of_loop; /* Statements generated outside loop. */
99 int inside_of_loop; /* Statements generated inside loop. */
100 } cost;
101 } *slp_tree;
103 DEF_VEC_P(slp_tree);
104 DEF_VEC_ALLOC_P(slp_tree, heap);
106 /* SLP instance is a sequence of stmts in a loop that can be packed into
107 SIMD stmts. */
108 typedef struct _slp_instance {
109 /* The root of SLP tree. */
110 slp_tree root;
112 /* Size of groups of scalar stmts that will be replaced by SIMD stmt/s. */
113 unsigned int group_size;
115 /* The unrolling factor required to vectorized this SLP instance. */
116 unsigned int unrolling_factor;
118 /* Vectorization costs associated with SLP instance. */
119 struct
121 int outside_of_loop; /* Statements generated outside loop. */
122 int inside_of_loop; /* Statements generated inside loop. */
123 } cost;
125 /* Loads permutation relatively to the stores, NULL if there is no
126 permutation. */
127 VEC (int, heap) *load_permutation;
129 /* The group of nodes that contain loads of this SLP instance. */
130 VEC (slp_tree, heap) *loads;
132 /* The first scalar load of the instance. The created vector loads will be
133 inserted before this statement. */
134 gimple first_load;
135 } *slp_instance;
137 DEF_VEC_P(slp_instance);
138 DEF_VEC_ALLOC_P(slp_instance, heap);
140 /* Access Functions. */
141 #define SLP_INSTANCE_TREE(S) (S)->root
142 #define SLP_INSTANCE_GROUP_SIZE(S) (S)->group_size
143 #define SLP_INSTANCE_UNROLLING_FACTOR(S) (S)->unrolling_factor
144 #define SLP_INSTANCE_OUTSIDE_OF_LOOP_COST(S) (S)->cost.outside_of_loop
145 #define SLP_INSTANCE_INSIDE_OF_LOOP_COST(S) (S)->cost.inside_of_loop
146 #define SLP_INSTANCE_LOAD_PERMUTATION(S) (S)->load_permutation
147 #define SLP_INSTANCE_LOADS(S) (S)->loads
148 #define SLP_INSTANCE_FIRST_LOAD_STMT(S) (S)->first_load
150 #define SLP_TREE_CHILDREN(S) (S)->children
151 #define SLP_TREE_SCALAR_STMTS(S) (S)->stmts
152 #define SLP_TREE_VEC_STMTS(S) (S)->vec_stmts
153 #define SLP_TREE_NUMBER_OF_VEC_STMTS(S) (S)->vec_stmts_size
154 #define SLP_TREE_OUTSIDE_OF_LOOP_COST(S) (S)->cost.outside_of_loop
155 #define SLP_TREE_INSIDE_OF_LOOP_COST(S) (S)->cost.inside_of_loop
157 /* This structure is used in creation of an SLP tree. Each instance
158 corresponds to the same operand in a group of scalar stmts in an SLP
159 node. */
160 typedef struct _slp_oprnd_info
162 /* Def-stmts for the operands. */
163 VEC (gimple, heap) *def_stmts;
164 /* Information about the first statement, its vector def-type, type, the
165 operand itself in case it's constant, and an indication if it's a pattern
166 stmt. */
167 enum vect_def_type first_dt;
168 tree first_def_type;
169 tree first_const_oprnd;
170 bool first_pattern;
171 } *slp_oprnd_info;
173 DEF_VEC_P(slp_oprnd_info);
174 DEF_VEC_ALLOC_P(slp_oprnd_info, heap);
177 typedef struct _vect_peel_info
179 int npeel;
180 struct data_reference *dr;
181 unsigned int count;
182 } *vect_peel_info;
184 typedef struct _vect_peel_extended_info
186 struct _vect_peel_info peel_info;
187 unsigned int inside_cost;
188 unsigned int outside_cost;
189 } *vect_peel_extended_info;
191 /*-----------------------------------------------------------------*/
192 /* Info on vectorized loops. */
193 /*-----------------------------------------------------------------*/
194 typedef struct _loop_vec_info {
196 /* The loop to which this info struct refers to. */
197 struct loop *loop;
199 /* The loop basic blocks. */
200 basic_block *bbs;
202 /* Number of iterations. */
203 tree num_iters;
204 tree num_iters_unchanged;
206 /* Minimum number of iterations below which vectorization is expected to
207 not be profitable (as estimated by the cost model).
208 -1 indicates that vectorization will not be profitable.
209 FORNOW: This field is an int. Will be a tree in the future, to represent
210 values unknown at compile time. */
211 int min_profitable_iters;
213 /* Is the loop vectorizable? */
214 bool vectorizable;
216 /* Unrolling factor */
217 int vectorization_factor;
219 /* The loop location in the source. */
220 LOC loop_line_number;
222 /* Unknown DRs according to which loop was peeled. */
223 struct data_reference *unaligned_dr;
225 /* peeling_for_alignment indicates whether peeling for alignment will take
226 place, and what the peeling factor should be:
227 peeling_for_alignment = X means:
228 If X=0: Peeling for alignment will not be applied.
229 If X>0: Peel first X iterations.
230 If X=-1: Generate a runtime test to calculate the number of iterations
231 to be peeled, using the dataref recorded in the field
232 unaligned_dr. */
233 int peeling_for_alignment;
235 /* The mask used to check the alignment of pointers or arrays. */
236 int ptr_mask;
238 /* The loop nest in which the data dependences are computed. */
239 VEC (loop_p, heap) *loop_nest;
241 /* All data references in the loop. */
242 VEC (data_reference_p, heap) *datarefs;
244 /* All data dependences in the loop. */
245 VEC (ddr_p, heap) *ddrs;
247 /* Data Dependence Relations defining address ranges that are candidates
248 for a run-time aliasing check. */
249 VEC (ddr_p, heap) *may_alias_ddrs;
251 /* Statements in the loop that have data references that are candidates for a
252 runtime (loop versioning) misalignment check. */
253 VEC(gimple,heap) *may_misalign_stmts;
255 /* All interleaving chains of stores in the loop, represented by the first
256 stmt in the chain. */
257 VEC(gimple, heap) *grouped_stores;
259 /* All SLP instances in the loop. This is a subset of the set of GROUP_STORES
260 of the loop. */
261 VEC(slp_instance, heap) *slp_instances;
263 /* The unrolling factor needed to SLP the loop. In case of that pure SLP is
264 applied to the loop, i.e., no unrolling is needed, this is 1. */
265 unsigned slp_unrolling_factor;
267 /* Reduction cycles detected in the loop. Used in loop-aware SLP. */
268 VEC (gimple, heap) *reductions;
270 /* All reduction chains in the loop, represented by the first
271 stmt in the chain. */
272 VEC (gimple, heap) *reduction_chains;
274 /* Hash table used to choose the best peeling option. */
275 htab_t peeling_htab;
277 /* When we have grouped data accesses with gaps, we may introduce invalid
278 memory accesses. We peel the last iteration of the loop to prevent
279 this. */
280 bool peeling_for_gaps;
282 } *loop_vec_info;
284 /* Access Functions. */
285 #define LOOP_VINFO_LOOP(L) (L)->loop
286 #define LOOP_VINFO_BBS(L) (L)->bbs
287 #define LOOP_VINFO_NITERS(L) (L)->num_iters
288 /* Since LOOP_VINFO_NITERS can change after prologue peeling
289 retain total unchanged scalar loop iterations for cost model. */
290 #define LOOP_VINFO_NITERS_UNCHANGED(L) (L)->num_iters_unchanged
291 #define LOOP_VINFO_COST_MODEL_MIN_ITERS(L) (L)->min_profitable_iters
292 #define LOOP_VINFO_VECTORIZABLE_P(L) (L)->vectorizable
293 #define LOOP_VINFO_VECT_FACTOR(L) (L)->vectorization_factor
294 #define LOOP_VINFO_PTR_MASK(L) (L)->ptr_mask
295 #define LOOP_VINFO_LOOP_NEST(L) (L)->loop_nest
296 #define LOOP_VINFO_DATAREFS(L) (L)->datarefs
297 #define LOOP_VINFO_DDRS(L) (L)->ddrs
298 #define LOOP_VINFO_INT_NITERS(L) (TREE_INT_CST_LOW ((L)->num_iters))
299 #define LOOP_PEELING_FOR_ALIGNMENT(L) (L)->peeling_for_alignment
300 #define LOOP_VINFO_UNALIGNED_DR(L) (L)->unaligned_dr
301 #define LOOP_VINFO_MAY_MISALIGN_STMTS(L) (L)->may_misalign_stmts
302 #define LOOP_VINFO_LOC(L) (L)->loop_line_number
303 #define LOOP_VINFO_MAY_ALIAS_DDRS(L) (L)->may_alias_ddrs
304 #define LOOP_VINFO_GROUPED_STORES(L) (L)->grouped_stores
305 #define LOOP_VINFO_SLP_INSTANCES(L) (L)->slp_instances
306 #define LOOP_VINFO_SLP_UNROLLING_FACTOR(L) (L)->slp_unrolling_factor
307 #define LOOP_VINFO_REDUCTIONS(L) (L)->reductions
308 #define LOOP_VINFO_REDUCTION_CHAINS(L) (L)->reduction_chains
309 #define LOOP_VINFO_PEELING_HTAB(L) (L)->peeling_htab
310 #define LOOP_VINFO_PEELING_FOR_GAPS(L) (L)->peeling_for_gaps
312 #define LOOP_REQUIRES_VERSIONING_FOR_ALIGNMENT(L) \
313 VEC_length (gimple, (L)->may_misalign_stmts) > 0
314 #define LOOP_REQUIRES_VERSIONING_FOR_ALIAS(L) \
315 VEC_length (ddr_p, (L)->may_alias_ddrs) > 0
317 #define NITERS_KNOWN_P(n) \
318 (host_integerp ((n),0) \
319 && TREE_INT_CST_LOW ((n)) > 0)
321 #define LOOP_VINFO_NITERS_KNOWN_P(L) \
322 NITERS_KNOWN_P((L)->num_iters)
324 static inline loop_vec_info
325 loop_vec_info_for_loop (struct loop *loop)
327 return (loop_vec_info) loop->aux;
330 static inline bool
331 nested_in_vect_loop_p (struct loop *loop, gimple stmt)
333 return (loop->inner
334 && (loop->inner == (gimple_bb (stmt))->loop_father));
337 typedef struct _bb_vec_info {
339 basic_block bb;
340 /* All interleaving chains of stores in the basic block, represented by the
341 first stmt in the chain. */
342 VEC(gimple, heap) *grouped_stores;
344 /* All SLP instances in the basic block. This is a subset of the set of
345 GROUP_STORES of the basic block. */
346 VEC(slp_instance, heap) *slp_instances;
348 /* All data references in the basic block. */
349 VEC (data_reference_p, heap) *datarefs;
351 /* All data dependences in the basic block. */
352 VEC (ddr_p, heap) *ddrs;
353 } *bb_vec_info;
355 #define BB_VINFO_BB(B) (B)->bb
356 #define BB_VINFO_GROUPED_STORES(B) (B)->grouped_stores
357 #define BB_VINFO_SLP_INSTANCES(B) (B)->slp_instances
358 #define BB_VINFO_DATAREFS(B) (B)->datarefs
359 #define BB_VINFO_DDRS(B) (B)->ddrs
361 static inline bb_vec_info
362 vec_info_for_bb (basic_block bb)
364 return (bb_vec_info) bb->aux;
367 /*-----------------------------------------------------------------*/
368 /* Info on vectorized defs. */
369 /*-----------------------------------------------------------------*/
370 enum stmt_vec_info_type {
371 undef_vec_info_type = 0,
372 load_vec_info_type,
373 store_vec_info_type,
374 shift_vec_info_type,
375 op_vec_info_type,
376 call_vec_info_type,
377 assignment_vec_info_type,
378 condition_vec_info_type,
379 reduc_vec_info_type,
380 induc_vec_info_type,
381 type_promotion_vec_info_type,
382 type_demotion_vec_info_type,
383 type_conversion_vec_info_type,
384 loop_exit_ctrl_vec_info_type
387 /* Indicates whether/how a variable is used in the scope of loop/basic
388 block. */
389 enum vect_relevant {
390 vect_unused_in_scope = 0,
391 /* The def is in the inner loop, and the use is in the outer loop, and the
392 use is a reduction stmt. */
393 vect_used_in_outer_by_reduction,
394 /* The def is in the inner loop, and the use is in the outer loop (and is
395 not part of reduction). */
396 vect_used_in_outer,
398 /* defs that feed computations that end up (only) in a reduction. These
399 defs may be used by non-reduction stmts, but eventually, any
400 computations/values that are affected by these defs are used to compute
401 a reduction (i.e. don't get stored to memory, for example). We use this
402 to identify computations that we can change the order in which they are
403 computed. */
404 vect_used_by_reduction,
406 vect_used_in_scope
409 /* The type of vectorization that can be applied to the stmt: regular loop-based
410 vectorization; pure SLP - the stmt is a part of SLP instances and does not
411 have uses outside SLP instances; or hybrid SLP and loop-based - the stmt is
412 a part of SLP instance and also must be loop-based vectorized, since it has
413 uses outside SLP sequences.
415 In the loop context the meanings of pure and hybrid SLP are slightly
416 different. By saying that pure SLP is applied to the loop, we mean that we
417 exploit only intra-iteration parallelism in the loop; i.e., the loop can be
418 vectorized without doing any conceptual unrolling, cause we don't pack
419 together stmts from different iterations, only within a single iteration.
420 Loop hybrid SLP means that we exploit both intra-iteration and
421 inter-iteration parallelism (e.g., number of elements in the vector is 4
422 and the slp-group-size is 2, in which case we don't have enough parallelism
423 within an iteration, so we obtain the rest of the parallelism from subsequent
424 iterations by unrolling the loop by 2). */
425 enum slp_vect_type {
426 loop_vect = 0,
427 pure_slp,
428 hybrid
432 typedef struct data_reference *dr_p;
433 DEF_VEC_P(dr_p);
434 DEF_VEC_ALLOC_P(dr_p,heap);
436 typedef struct _stmt_vec_info {
438 enum stmt_vec_info_type type;
440 /* Indicates whether this stmts is part of a computation whose result is
441 used outside the loop. */
442 bool live;
444 /* Stmt is part of some pattern (computation idiom) */
445 bool in_pattern_p;
447 /* For loads only, if there is a store with the same location, this field is
448 TRUE. */
449 bool read_write_dep;
451 /* The stmt to which this info struct refers to. */
452 gimple stmt;
454 /* The loop_vec_info with respect to which STMT is vectorized. */
455 loop_vec_info loop_vinfo;
457 /* The vector type to be used for the LHS of this statement. */
458 tree vectype;
460 /* The vectorized version of the stmt. */
461 gimple vectorized_stmt;
464 /** The following is relevant only for stmts that contain a non-scalar
465 data-ref (array/pointer/struct access). A GIMPLE stmt is expected to have
466 at most one such data-ref. **/
468 /* Information about the data-ref (access function, etc),
469 relative to the inner-most containing loop. */
470 struct data_reference *data_ref_info;
472 /* Information about the data-ref relative to this loop
473 nest (the loop that is being considered for vectorization). */
474 tree dr_base_address;
475 tree dr_init;
476 tree dr_offset;
477 tree dr_step;
478 tree dr_aligned_to;
480 /* For loop PHI nodes, the evolution part of it. This makes sure
481 this information is still available in vect_update_ivs_after_vectorizer
482 where we may not be able to re-analyze the PHI nodes evolution as
483 peeling for the prologue loop can make it unanalyzable. The evolution
484 part is still correct though. */
485 tree loop_phi_evolution_part;
487 /* Used for various bookkeeping purposes, generally holding a pointer to
488 some other stmt S that is in some way "related" to this stmt.
489 Current use of this field is:
490 If this stmt is part of a pattern (i.e. the field 'in_pattern_p' is
491 true): S is the "pattern stmt" that represents (and replaces) the
492 sequence of stmts that constitutes the pattern. Similarly, the
493 related_stmt of the "pattern stmt" points back to this stmt (which is
494 the last stmt in the original sequence of stmts that constitutes the
495 pattern). */
496 gimple related_stmt;
498 /* Used to keep a sequence of def stmts of a pattern stmt if such exists. */
499 gimple_seq pattern_def_seq;
501 /* List of datarefs that are known to have the same alignment as the dataref
502 of this stmt. */
503 VEC(dr_p,heap) *same_align_refs;
505 /* Classify the def of this stmt. */
506 enum vect_def_type def_type;
508 /* Whether the stmt is SLPed, loop-based vectorized, or both. */
509 enum slp_vect_type slp_type;
511 /* Interleaving and reduction chains info. */
512 /* First element in the group. */
513 gimple first_element;
514 /* Pointer to the next element in the group. */
515 gimple next_element;
516 /* For data-refs, in case that two or more stmts share data-ref, this is the
517 pointer to the previously detected stmt with the same dr. */
518 gimple same_dr_stmt;
519 /* The size of the group. */
520 unsigned int size;
521 /* For stores, number of stores from this group seen. We vectorize the last
522 one. */
523 unsigned int store_count;
524 /* For loads only, the gap from the previous load. For consecutive loads, GAP
525 is 1. */
526 unsigned int gap;
528 /* Not all stmts in the loop need to be vectorized. e.g, the increment
529 of the loop induction variable and computation of array indexes. relevant
530 indicates whether the stmt needs to be vectorized. */
531 enum vect_relevant relevant;
533 /* Vectorization costs associated with statement. */
534 struct
536 int outside_of_loop; /* Statements generated outside loop. */
537 int inside_of_loop; /* Statements generated inside loop. */
538 } cost;
540 /* The bb_vec_info with respect to which STMT is vectorized. */
541 bb_vec_info bb_vinfo;
543 /* Is this statement vectorizable or should it be skipped in (partial)
544 vectorization. */
545 bool vectorizable;
547 /* For loads only, true if this is a gather load. */
548 bool gather_p;
549 bool stride_load_p;
550 } *stmt_vec_info;
552 /* Access Functions. */
553 #define STMT_VINFO_TYPE(S) (S)->type
554 #define STMT_VINFO_STMT(S) (S)->stmt
555 #define STMT_VINFO_LOOP_VINFO(S) (S)->loop_vinfo
556 #define STMT_VINFO_BB_VINFO(S) (S)->bb_vinfo
557 #define STMT_VINFO_RELEVANT(S) (S)->relevant
558 #define STMT_VINFO_LIVE_P(S) (S)->live
559 #define STMT_VINFO_VECTYPE(S) (S)->vectype
560 #define STMT_VINFO_VEC_STMT(S) (S)->vectorized_stmt
561 #define STMT_VINFO_VECTORIZABLE(S) (S)->vectorizable
562 #define STMT_VINFO_DATA_REF(S) (S)->data_ref_info
563 #define STMT_VINFO_GATHER_P(S) (S)->gather_p
564 #define STMT_VINFO_STRIDE_LOAD_P(S) (S)->stride_load_p
566 #define STMT_VINFO_DR_BASE_ADDRESS(S) (S)->dr_base_address
567 #define STMT_VINFO_DR_INIT(S) (S)->dr_init
568 #define STMT_VINFO_DR_OFFSET(S) (S)->dr_offset
569 #define STMT_VINFO_DR_STEP(S) (S)->dr_step
570 #define STMT_VINFO_DR_ALIGNED_TO(S) (S)->dr_aligned_to
572 #define STMT_VINFO_IN_PATTERN_P(S) (S)->in_pattern_p
573 #define STMT_VINFO_RELATED_STMT(S) (S)->related_stmt
574 #define STMT_VINFO_PATTERN_DEF_SEQ(S) (S)->pattern_def_seq
575 #define STMT_VINFO_SAME_ALIGN_REFS(S) (S)->same_align_refs
576 #define STMT_VINFO_DEF_TYPE(S) (S)->def_type
577 #define STMT_VINFO_GROUP_FIRST_ELEMENT(S) (S)->first_element
578 #define STMT_VINFO_GROUP_NEXT_ELEMENT(S) (S)->next_element
579 #define STMT_VINFO_GROUP_SIZE(S) (S)->size
580 #define STMT_VINFO_GROUP_STORE_COUNT(S) (S)->store_count
581 #define STMT_VINFO_GROUP_GAP(S) (S)->gap
582 #define STMT_VINFO_GROUP_SAME_DR_STMT(S) (S)->same_dr_stmt
583 #define STMT_VINFO_GROUP_READ_WRITE_DEPENDENCE(S) (S)->read_write_dep
584 #define STMT_VINFO_GROUPED_ACCESS(S) ((S)->first_element != NULL && (S)->data_ref_info)
585 #define STMT_VINFO_LOOP_PHI_EVOLUTION_PART(S) (S)->loop_phi_evolution_part
587 #define GROUP_FIRST_ELEMENT(S) (S)->first_element
588 #define GROUP_NEXT_ELEMENT(S) (S)->next_element
589 #define GROUP_SIZE(S) (S)->size
590 #define GROUP_STORE_COUNT(S) (S)->store_count
591 #define GROUP_GAP(S) (S)->gap
592 #define GROUP_SAME_DR_STMT(S) (S)->same_dr_stmt
593 #define GROUP_READ_WRITE_DEPENDENCE(S) (S)->read_write_dep
595 #define STMT_VINFO_RELEVANT_P(S) ((S)->relevant != vect_unused_in_scope)
596 #define STMT_VINFO_OUTSIDE_OF_LOOP_COST(S) (S)->cost.outside_of_loop
597 #define STMT_VINFO_INSIDE_OF_LOOP_COST(S) (S)->cost.inside_of_loop
599 #define HYBRID_SLP_STMT(S) ((S)->slp_type == hybrid)
600 #define PURE_SLP_STMT(S) ((S)->slp_type == pure_slp)
601 #define STMT_SLP_TYPE(S) (S)->slp_type
603 #define VECT_MAX_COST 1000
605 /* The maximum number of intermediate steps required in multi-step type
606 conversion. */
607 #define MAX_INTERM_CVT_STEPS 3
609 /* The maximum vectorization factor supported by any target (V32QI). */
610 #define MAX_VECTORIZATION_FACTOR 32
612 /* Avoid GTY(()) on stmt_vec_info. */
613 typedef void *vec_void_p;
614 DEF_VEC_P (vec_void_p);
615 DEF_VEC_ALLOC_P (vec_void_p, heap);
617 extern VEC(vec_void_p,heap) *stmt_vec_info_vec;
619 void init_stmt_vec_info_vec (void);
620 void free_stmt_vec_info_vec (void);
622 /* Return a stmt_vec_info corresponding to STMT. */
624 static inline stmt_vec_info
625 vinfo_for_stmt (gimple stmt)
627 unsigned int uid = gimple_uid (stmt);
628 if (uid == 0)
629 return NULL;
631 return (stmt_vec_info) VEC_index (vec_void_p, stmt_vec_info_vec, uid - 1);
634 /* Set vectorizer information INFO for STMT. */
636 static inline void
637 set_vinfo_for_stmt (gimple stmt, stmt_vec_info info)
639 unsigned int uid = gimple_uid (stmt);
640 if (uid == 0)
642 gcc_checking_assert (info);
643 uid = VEC_length (vec_void_p, stmt_vec_info_vec) + 1;
644 gimple_set_uid (stmt, uid);
645 VEC_safe_push (vec_void_p, heap, stmt_vec_info_vec, (vec_void_p) info);
647 else
648 VEC_replace (vec_void_p, stmt_vec_info_vec, uid - 1, (vec_void_p) info);
651 /* Return the earlier statement between STMT1 and STMT2. */
653 static inline gimple
654 get_earlier_stmt (gimple stmt1, gimple stmt2)
656 unsigned int uid1, uid2;
658 if (stmt1 == NULL)
659 return stmt2;
661 if (stmt2 == NULL)
662 return stmt1;
664 uid1 = gimple_uid (stmt1);
665 uid2 = gimple_uid (stmt2);
667 if (uid1 == 0 || uid2 == 0)
668 return NULL;
670 gcc_checking_assert (uid1 <= VEC_length (vec_void_p, stmt_vec_info_vec)
671 && uid2 <= VEC_length (vec_void_p, stmt_vec_info_vec));
673 if (uid1 < uid2)
674 return stmt1;
675 else
676 return stmt2;
679 /* Return the later statement between STMT1 and STMT2. */
681 static inline gimple
682 get_later_stmt (gimple stmt1, gimple stmt2)
684 unsigned int uid1, uid2;
686 if (stmt1 == NULL)
687 return stmt2;
689 if (stmt2 == NULL)
690 return stmt1;
692 uid1 = gimple_uid (stmt1);
693 uid2 = gimple_uid (stmt2);
695 if (uid1 == 0 || uid2 == 0)
696 return NULL;
698 gcc_assert (uid1 <= VEC_length (vec_void_p, stmt_vec_info_vec));
699 gcc_assert (uid2 <= VEC_length (vec_void_p, stmt_vec_info_vec));
701 if (uid1 > uid2)
702 return stmt1;
703 else
704 return stmt2;
707 /* Return TRUE if a statement represented by STMT_INFO is a part of a
708 pattern. */
710 static inline bool
711 is_pattern_stmt_p (stmt_vec_info stmt_info)
713 gimple related_stmt;
714 stmt_vec_info related_stmt_info;
716 related_stmt = STMT_VINFO_RELATED_STMT (stmt_info);
717 if (related_stmt
718 && (related_stmt_info = vinfo_for_stmt (related_stmt))
719 && STMT_VINFO_IN_PATTERN_P (related_stmt_info))
720 return true;
722 return false;
725 /* Return true if BB is a loop header. */
727 static inline bool
728 is_loop_header_bb_p (basic_block bb)
730 if (bb == (bb->loop_father)->header)
731 return true;
732 gcc_checking_assert (EDGE_COUNT (bb->preds) == 1);
733 return false;
736 /* Set inside loop vectorization cost. */
738 static inline void
739 stmt_vinfo_set_inside_of_loop_cost (stmt_vec_info stmt_info, slp_tree slp_node,
740 int cost)
742 if (slp_node)
743 SLP_TREE_INSIDE_OF_LOOP_COST (slp_node) = cost;
744 else
745 STMT_VINFO_INSIDE_OF_LOOP_COST (stmt_info) = cost;
748 /* Set inside loop vectorization cost. */
750 static inline void
751 stmt_vinfo_set_outside_of_loop_cost (stmt_vec_info stmt_info, slp_tree slp_node,
752 int cost)
754 if (slp_node)
755 SLP_TREE_OUTSIDE_OF_LOOP_COST (slp_node) = cost;
756 else
757 STMT_VINFO_OUTSIDE_OF_LOOP_COST (stmt_info) = cost;
760 /* Return pow2 (X). */
762 static inline int
763 vect_pow2 (int x)
765 int i, res = 1;
767 for (i = 0; i < x; i++)
768 res *= 2;
770 return res;
773 /* Get cost by calling cost target builtin. */
775 static inline
776 int vect_get_stmt_cost (enum vect_cost_for_stmt type_of_cost)
778 tree dummy_type = NULL;
779 int dummy = 0;
781 return targetm.vectorize.builtin_vectorization_cost (type_of_cost,
782 dummy_type, dummy);
785 /*-----------------------------------------------------------------*/
786 /* Info on data references alignment. */
787 /*-----------------------------------------------------------------*/
789 /* Reflects actual alignment of first access in the vectorized loop,
790 taking into account peeling/versioning if applied. */
791 #define DR_MISALIGNMENT(DR) ((int) (size_t) (DR)->aux)
792 #define SET_DR_MISALIGNMENT(DR, VAL) ((DR)->aux = (void *) (size_t) (VAL))
794 /* Return TRUE if the data access is aligned, and FALSE otherwise. */
796 static inline bool
797 aligned_access_p (struct data_reference *data_ref_info)
799 return (DR_MISALIGNMENT (data_ref_info) == 0);
802 /* Return TRUE if the alignment of the data access is known, and FALSE
803 otherwise. */
805 static inline bool
806 known_alignment_for_access_p (struct data_reference *data_ref_info)
808 return (DR_MISALIGNMENT (data_ref_info) != -1);
811 /* vect_dump will be set to stderr or dump_file if exist. */
812 extern FILE *vect_dump;
813 extern LOC vect_loop_location;
815 /*-----------------------------------------------------------------*/
816 /* Function prototypes. */
817 /*-----------------------------------------------------------------*/
819 /* Simple loop peeling and versioning utilities for vectorizer's purposes -
820 in tree-vect-loop-manip.c. */
821 extern void slpeel_make_loop_iterate_ntimes (struct loop *, tree);
822 extern bool slpeel_can_duplicate_loop_p (const struct loop *, const_edge);
823 extern void vect_loop_versioning (loop_vec_info, unsigned int, bool);
824 extern void vect_do_peeling_for_loop_bound (loop_vec_info, tree *,
825 unsigned int, bool);
826 extern void vect_do_peeling_for_alignment (loop_vec_info, unsigned int, bool);
827 extern LOC find_loop_location (struct loop *);
828 extern bool vect_can_advance_ivs_p (loop_vec_info);
830 /* In tree-vect-stmts.c. */
831 extern unsigned int current_vector_size;
832 extern tree get_vectype_for_scalar_type (tree);
833 extern tree get_same_sized_vectype (tree, tree);
834 extern bool vect_is_simple_use (tree, gimple, loop_vec_info,
835 bb_vec_info, gimple *,
836 tree *, enum vect_def_type *);
837 extern bool vect_is_simple_use_1 (tree, gimple, loop_vec_info,
838 bb_vec_info, gimple *,
839 tree *, enum vect_def_type *, tree *);
840 extern bool supportable_widening_operation (enum tree_code, gimple, tree, tree,
841 tree *, tree *, enum tree_code *,
842 enum tree_code *, int *,
843 VEC (tree, heap) **);
844 extern bool supportable_narrowing_operation (enum tree_code, tree, tree,
845 enum tree_code *,
846 int *, VEC (tree, heap) **);
847 extern stmt_vec_info new_stmt_vec_info (gimple stmt, loop_vec_info,
848 bb_vec_info);
849 extern void free_stmt_vec_info (gimple stmt);
850 extern tree vectorizable_function (gimple, tree, tree);
851 extern void vect_model_simple_cost (stmt_vec_info, int, enum vect_def_type *,
852 slp_tree);
853 extern void vect_model_store_cost (stmt_vec_info, int, bool,
854 enum vect_def_type, slp_tree);
855 extern void vect_model_load_cost (stmt_vec_info, int, bool, slp_tree);
856 extern void vect_finish_stmt_generation (gimple, gimple,
857 gimple_stmt_iterator *);
858 extern bool vect_mark_stmts_to_be_vectorized (loop_vec_info);
859 extern tree vect_get_vec_def_for_operand (tree, gimple, tree *);
860 extern tree vect_init_vector (gimple, tree, tree,
861 gimple_stmt_iterator *);
862 extern tree vect_get_vec_def_for_stmt_copy (enum vect_def_type, tree);
863 extern bool vect_transform_stmt (gimple, gimple_stmt_iterator *,
864 bool *, slp_tree, slp_instance);
865 extern void vect_remove_stores (gimple);
866 extern bool vect_analyze_stmt (gimple, bool *, slp_tree);
867 extern bool vectorizable_condition (gimple, gimple_stmt_iterator *, gimple *,
868 tree, int, slp_tree);
869 extern void vect_get_load_cost (struct data_reference *, int, bool,
870 unsigned int *, unsigned int *);
871 extern void vect_get_store_cost (struct data_reference *, int, unsigned int *);
872 extern bool vect_supportable_shift (enum tree_code, tree);
873 extern void vect_get_vec_defs (tree, tree, gimple, VEC (tree, heap) **,
874 VEC (tree, heap) **, slp_tree, int);
875 extern tree vect_gen_perm_mask (tree, unsigned char *);
877 /* In tree-vect-data-refs.c. */
878 extern bool vect_can_force_dr_alignment_p (const_tree, unsigned int);
879 extern enum dr_alignment_support vect_supportable_dr_alignment
880 (struct data_reference *, bool);
881 extern tree vect_get_smallest_scalar_type (gimple, HOST_WIDE_INT *,
882 HOST_WIDE_INT *);
883 extern bool vect_analyze_data_ref_dependences (loop_vec_info, bb_vec_info,
884 int *);
885 extern bool vect_enhance_data_refs_alignment (loop_vec_info);
886 extern bool vect_analyze_data_refs_alignment (loop_vec_info, bb_vec_info);
887 extern bool vect_verify_datarefs_alignment (loop_vec_info, bb_vec_info);
888 extern bool vect_analyze_data_ref_accesses (loop_vec_info, bb_vec_info);
889 extern bool vect_prune_runtime_alias_test_list (loop_vec_info);
890 extern tree vect_check_gather (gimple, loop_vec_info, tree *, tree *,
891 int *);
892 extern bool vect_check_strided_load (gimple, loop_vec_info, tree *, tree *);
893 extern bool vect_analyze_data_refs (loop_vec_info, bb_vec_info, int *);
894 extern tree vect_create_data_ref_ptr (gimple, tree, struct loop *, tree,
895 tree *, gimple_stmt_iterator *,
896 gimple *, bool, bool *);
897 extern tree bump_vector_ptr (tree, gimple, gimple_stmt_iterator *, gimple, tree);
898 extern tree vect_create_destination_var (tree, tree);
899 extern bool vect_grouped_store_supported (tree, unsigned HOST_WIDE_INT);
900 extern bool vect_store_lanes_supported (tree, unsigned HOST_WIDE_INT);
901 extern bool vect_grouped_load_supported (tree, unsigned HOST_WIDE_INT);
902 extern bool vect_load_lanes_supported (tree, unsigned HOST_WIDE_INT);
903 extern void vect_permute_store_chain (VEC(tree,heap) *,unsigned int, gimple,
904 gimple_stmt_iterator *, VEC(tree,heap) **);
905 extern tree vect_setup_realignment (gimple, gimple_stmt_iterator *, tree *,
906 enum dr_alignment_support, tree,
907 struct loop **);
908 extern void vect_transform_grouped_load (gimple, VEC(tree,heap) *, int,
909 gimple_stmt_iterator *);
910 extern void vect_record_grouped_load_vectors (gimple, VEC(tree,heap) *);
911 extern int vect_get_place_in_interleaving_chain (gimple, gimple);
912 extern tree vect_get_new_vect_var (tree, enum vect_var_kind, const char *);
913 extern tree vect_create_addr_base_for_vector_ref (gimple, gimple_seq *,
914 tree, struct loop *);
916 /* In tree-vect-loop.c. */
917 /* FORNOW: Used in tree-parloops.c. */
918 extern void destroy_loop_vec_info (loop_vec_info, bool);
919 extern gimple vect_force_simple_reduction (loop_vec_info, gimple, bool, bool *);
920 /* Drive for loop analysis stage. */
921 extern loop_vec_info vect_analyze_loop (struct loop *);
922 /* Drive for loop transformation stage. */
923 extern void vect_transform_loop (loop_vec_info);
924 extern loop_vec_info vect_analyze_loop_form (struct loop *);
925 extern bool vectorizable_live_operation (gimple, gimple_stmt_iterator *,
926 gimple *);
927 extern bool vectorizable_reduction (gimple, gimple_stmt_iterator *, gimple *,
928 slp_tree);
929 extern bool vectorizable_induction (gimple, gimple_stmt_iterator *, gimple *);
930 extern int vect_estimate_min_profitable_iters (loop_vec_info);
931 extern tree get_initial_def_for_reduction (gimple, tree, tree *);
932 extern int vect_min_worthwhile_factor (enum tree_code);
933 extern int vect_get_known_peeling_cost (loop_vec_info, int, int *, int);
934 extern int vect_get_single_scalar_iteration_cost (loop_vec_info);
936 /* In tree-vect-slp.c. */
937 extern void vect_free_slp_instance (slp_instance);
938 extern bool vect_transform_slp_perm_load (gimple, VEC (tree, heap) *,
939 gimple_stmt_iterator *, int,
940 slp_instance, bool);
941 extern bool vect_schedule_slp (loop_vec_info, bb_vec_info);
942 extern void vect_update_slp_costs_according_to_vf (loop_vec_info);
943 extern bool vect_analyze_slp (loop_vec_info, bb_vec_info);
944 extern bool vect_make_slp_decision (loop_vec_info);
945 extern void vect_detect_hybrid_slp (loop_vec_info);
946 extern void vect_get_slp_defs (VEC (tree, heap) *, slp_tree,
947 VEC (slp_void_p, heap) **, int);
949 extern LOC find_bb_location (basic_block);
950 extern bb_vec_info vect_slp_analyze_bb (basic_block);
951 extern void vect_slp_transform_bb (basic_block);
953 /* In tree-vect-patterns.c. */
954 /* Pattern recognition functions.
955 Additional pattern recognition functions can (and will) be added
956 in the future. */
957 typedef gimple (* vect_recog_func_ptr) (VEC (gimple, heap) **, tree *, tree *);
958 #define NUM_PATTERNS 10
959 void vect_pattern_recog (loop_vec_info, bb_vec_info);
961 /* In tree-vectorizer.c. */
962 unsigned vectorize_loops (void);
963 /* Vectorization debug information */
964 extern bool vect_print_dump_info (enum vect_verbosity_levels);
966 #endif /* GCC_TREE_VECTORIZER_H */