2010-11-11 Jakub Jelinek <jakub@redhat.com>
[official-gcc.git] / gcc / tree-vectorizer.h
blobf2a5889ebad15f19016f285d48445a12fa982f8c
1 /* Vectorizer
2 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
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"
27 typedef source_location LOC;
28 #define UNKNOWN_LOC UNKNOWN_LOCATION
29 #define EXPR_LOC(e) EXPR_LOCATION(e)
30 #define LOC_FILE(l) LOCATION_FILE (l)
31 #define LOC_LINE(l) LOCATION_LINE (l)
33 /* Used for naming of new temporaries. */
34 enum vect_var_kind {
35 vect_simple_var,
36 vect_pointer_var,
37 vect_scalar_var
40 /* Defines type of operation. */
41 enum operation_type {
42 unary_op = 1,
43 binary_op,
44 ternary_op
47 /* Define type of available alignment support. */
48 enum dr_alignment_support {
49 dr_unaligned_unsupported,
50 dr_unaligned_supported,
51 dr_explicit_realign,
52 dr_explicit_realign_optimized,
53 dr_aligned
56 /* Define type of def-use cross-iteration cycle. */
57 enum vect_def_type {
58 vect_uninitialized_def = 0,
59 vect_constant_def = 1,
60 vect_external_def,
61 vect_internal_def,
62 vect_induction_def,
63 vect_reduction_def,
64 vect_double_reduction_def,
65 vect_nested_cycle,
66 vect_unknown_def_type
69 #define VECTORIZABLE_CYCLE_DEF(D) (((D) == vect_reduction_def) \
70 || ((D) == vect_double_reduction_def) \
71 || ((D) == vect_nested_cycle))
73 /* Define verbosity levels. */
74 enum verbosity_levels {
75 REPORT_NONE,
76 REPORT_VECTORIZED_LOCATIONS,
77 REPORT_UNVECTORIZED_LOCATIONS,
78 REPORT_COST,
79 REPORT_ALIGNMENT,
80 REPORT_DR_DETAILS,
81 REPORT_BAD_FORM_LOOPS,
82 REPORT_OUTER_LOOPS,
83 REPORT_SLP,
84 REPORT_DETAILS,
85 /* New verbosity levels should be added before this one. */
86 MAX_VERBOSITY_LEVEL
89 /************************************************************************
90 SLP
91 ************************************************************************/
93 /* A computation tree of an SLP instance. Each node corresponds to a group of
94 stmts to be packed in a SIMD stmt. */
95 typedef struct _slp_tree {
96 /* Only binary and unary operations are supported. LEFT child corresponds to
97 the first operand and RIGHT child to the second if the operation is
98 binary. */
99 struct _slp_tree *left;
100 struct _slp_tree *right;
101 /* A group of scalar stmts to be vectorized together. */
102 VEC (gimple, heap) *stmts;
103 /* Vectorized stmt/s. */
104 VEC (gimple, heap) *vec_stmts;
105 /* Number of vector stmts that are created to replace the group of scalar
106 stmts. It is calculated during the transformation phase as the number of
107 scalar elements in one scalar iteration (GROUP_SIZE) multiplied by VF
108 divided by vector size. */
109 unsigned int vec_stmts_size;
110 /* Vectorization costs associated with SLP node. */
111 struct
113 int outside_of_loop; /* Statements generated outside loop. */
114 int inside_of_loop; /* Statements generated inside loop. */
115 } cost;
116 } *slp_tree;
118 DEF_VEC_P(slp_tree);
119 DEF_VEC_ALLOC_P(slp_tree, heap);
121 /* SLP instance is a sequence of stmts in a loop that can be packed into
122 SIMD stmts. */
123 typedef struct _slp_instance {
124 /* The root of SLP tree. */
125 slp_tree root;
127 /* Size of groups of scalar stmts that will be replaced by SIMD stmt/s. */
128 unsigned int group_size;
130 /* The unrolling factor required to vectorized this SLP instance. */
131 unsigned int unrolling_factor;
133 /* Vectorization costs associated with SLP instance. */
134 struct
136 int outside_of_loop; /* Statements generated outside loop. */
137 int inside_of_loop; /* Statements generated inside loop. */
138 } cost;
140 /* Loads permutation relatively to the stores, NULL if there is no
141 permutation. */
142 VEC (int, heap) *load_permutation;
144 /* The group of nodes that contain loads of this SLP instance. */
145 VEC (slp_tree, heap) *loads;
147 /* The first scalar load of the instance. The created vector loads will be
148 inserted before this statement. */
149 gimple first_load;
150 } *slp_instance;
152 DEF_VEC_P(slp_instance);
153 DEF_VEC_ALLOC_P(slp_instance, heap);
155 /* Access Functions. */
156 #define SLP_INSTANCE_TREE(S) (S)->root
157 #define SLP_INSTANCE_GROUP_SIZE(S) (S)->group_size
158 #define SLP_INSTANCE_UNROLLING_FACTOR(S) (S)->unrolling_factor
159 #define SLP_INSTANCE_OUTSIDE_OF_LOOP_COST(S) (S)->cost.outside_of_loop
160 #define SLP_INSTANCE_INSIDE_OF_LOOP_COST(S) (S)->cost.inside_of_loop
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_LEFT(S) (S)->left
166 #define SLP_TREE_RIGHT(S) (S)->right
167 #define SLP_TREE_SCALAR_STMTS(S) (S)->stmts
168 #define SLP_TREE_VEC_STMTS(S) (S)->vec_stmts
169 #define SLP_TREE_NUMBER_OF_VEC_STMTS(S) (S)->vec_stmts_size
170 #define SLP_TREE_OUTSIDE_OF_LOOP_COST(S) (S)->cost.outside_of_loop
171 #define SLP_TREE_INSIDE_OF_LOOP_COST(S) (S)->cost.inside_of_loop
174 typedef struct _vect_peel_info
176 int npeel;
177 struct data_reference *dr;
178 unsigned int count;
179 } *vect_peel_info;
181 typedef struct _vect_peel_extended_info
183 struct _vect_peel_info peel_info;
184 unsigned int inside_cost;
185 unsigned int outside_cost;
186 } *vect_peel_extended_info;
188 /*-----------------------------------------------------------------*/
189 /* Info on vectorized loops. */
190 /*-----------------------------------------------------------------*/
191 typedef struct _loop_vec_info {
193 /* The loop to which this info struct refers to. */
194 struct loop *loop;
196 /* The loop basic blocks. */
197 basic_block *bbs;
199 /* Number of iterations. */
200 tree num_iters;
201 tree num_iters_unchanged;
203 /* Minimum number of iterations below which vectorization is expected to
204 not be profitable (as estimated by the cost model).
205 -1 indicates that vectorization will not be profitable.
206 FORNOW: This field is an int. Will be a tree in the future, to represent
207 values unknown at compile time. */
208 int min_profitable_iters;
210 /* Is the loop vectorizable? */
211 bool vectorizable;
213 /* Unrolling factor */
214 int vectorization_factor;
216 /* The loop location in the source. */
217 LOC loop_line_number;
219 /* Unknown DRs according to which loop was peeled. */
220 struct data_reference *unaligned_dr;
222 /* peeling_for_alignment indicates whether peeling for alignment will take
223 place, and what the peeling factor should be:
224 peeling_for_alignment = X means:
225 If X=0: Peeling for alignment will not be applied.
226 If X>0: Peel first X iterations.
227 If X=-1: Generate a runtime test to calculate the number of iterations
228 to be peeled, using the dataref recorded in the field
229 unaligned_dr. */
230 int peeling_for_alignment;
232 /* The mask used to check the alignment of pointers or arrays. */
233 int ptr_mask;
235 /* All data references in the loop. */
236 VEC (data_reference_p, heap) *datarefs;
238 /* All data dependences in the loop. */
239 VEC (ddr_p, heap) *ddrs;
241 /* Data Dependence Relations defining address ranges that are candidates
242 for a run-time aliasing check. */
243 VEC (ddr_p, heap) *may_alias_ddrs;
245 /* Statements in the loop that have data references that are candidates for a
246 runtime (loop versioning) misalignment check. */
247 VEC(gimple,heap) *may_misalign_stmts;
249 /* All interleaving chains of stores in the loop, represented by the first
250 stmt in the chain. */
251 VEC(gimple, heap) *strided_stores;
253 /* All SLP instances in the loop. This is a subset of the set of STRIDED_STORES
254 of the loop. */
255 VEC(slp_instance, heap) *slp_instances;
257 /* The unrolling factor needed to SLP the loop. In case of that pure SLP is
258 applied to the loop, i.e., no unrolling is needed, this is 1. */
259 unsigned slp_unrolling_factor;
261 /* Reduction cycles detected in the loop. Used in loop-aware SLP. */
262 VEC (gimple, heap) *reductions;
264 /* Hash table used to choose the best peeling option. */
265 htab_t peeling_htab;
267 } *loop_vec_info;
269 /* Access Functions. */
270 #define LOOP_VINFO_LOOP(L) (L)->loop
271 #define LOOP_VINFO_BBS(L) (L)->bbs
272 #define LOOP_VINFO_NITERS(L) (L)->num_iters
273 /* Since LOOP_VINFO_NITERS can change after prologue peeling
274 retain total unchanged scalar loop iterations for cost model. */
275 #define LOOP_VINFO_NITERS_UNCHANGED(L) (L)->num_iters_unchanged
276 #define LOOP_VINFO_COST_MODEL_MIN_ITERS(L) (L)->min_profitable_iters
277 #define LOOP_VINFO_VECTORIZABLE_P(L) (L)->vectorizable
278 #define LOOP_VINFO_VECT_FACTOR(L) (L)->vectorization_factor
279 #define LOOP_VINFO_PTR_MASK(L) (L)->ptr_mask
280 #define LOOP_VINFO_DATAREFS(L) (L)->datarefs
281 #define LOOP_VINFO_DDRS(L) (L)->ddrs
282 #define LOOP_VINFO_INT_NITERS(L) (TREE_INT_CST_LOW ((L)->num_iters))
283 #define LOOP_PEELING_FOR_ALIGNMENT(L) (L)->peeling_for_alignment
284 #define LOOP_VINFO_UNALIGNED_DR(L) (L)->unaligned_dr
285 #define LOOP_VINFO_MAY_MISALIGN_STMTS(L) (L)->may_misalign_stmts
286 #define LOOP_VINFO_LOC(L) (L)->loop_line_number
287 #define LOOP_VINFO_MAY_ALIAS_DDRS(L) (L)->may_alias_ddrs
288 #define LOOP_VINFO_STRIDED_STORES(L) (L)->strided_stores
289 #define LOOP_VINFO_SLP_INSTANCES(L) (L)->slp_instances
290 #define LOOP_VINFO_SLP_UNROLLING_FACTOR(L) (L)->slp_unrolling_factor
291 #define LOOP_VINFO_REDUCTIONS(L) (L)->reductions
292 #define LOOP_VINFO_PEELING_HTAB(L) (L)->peeling_htab
294 #define LOOP_REQUIRES_VERSIONING_FOR_ALIGNMENT(L) \
295 VEC_length (gimple, (L)->may_misalign_stmts) > 0
296 #define LOOP_REQUIRES_VERSIONING_FOR_ALIAS(L) \
297 VEC_length (ddr_p, (L)->may_alias_ddrs) > 0
299 #define NITERS_KNOWN_P(n) \
300 (host_integerp ((n),0) \
301 && TREE_INT_CST_LOW ((n)) > 0)
303 #define LOOP_VINFO_NITERS_KNOWN_P(L) \
304 NITERS_KNOWN_P((L)->num_iters)
306 static inline loop_vec_info
307 loop_vec_info_for_loop (struct loop *loop)
309 return (loop_vec_info) loop->aux;
312 static inline bool
313 nested_in_vect_loop_p (struct loop *loop, gimple stmt)
315 return (loop->inner
316 && (loop->inner == (gimple_bb (stmt))->loop_father));
319 typedef struct _bb_vec_info {
321 basic_block bb;
322 /* All interleaving chains of stores in the basic block, represented by the
323 first stmt in the chain. */
324 VEC(gimple, heap) *strided_stores;
326 /* All SLP instances in the basic block. This is a subset of the set of
327 STRIDED_STORES of the basic block. */
328 VEC(slp_instance, heap) *slp_instances;
330 /* All data references in the basic block. */
331 VEC (data_reference_p, heap) *datarefs;
333 /* All data dependences in the basic block. */
334 VEC (ddr_p, heap) *ddrs;
335 } *bb_vec_info;
337 #define BB_VINFO_BB(B) (B)->bb
338 #define BB_VINFO_STRIDED_STORES(B) (B)->strided_stores
339 #define BB_VINFO_SLP_INSTANCES(B) (B)->slp_instances
340 #define BB_VINFO_DATAREFS(B) (B)->datarefs
341 #define BB_VINFO_DDRS(B) (B)->ddrs
343 static inline bb_vec_info
344 vec_info_for_bb (basic_block bb)
346 return (bb_vec_info) bb->aux;
349 /*-----------------------------------------------------------------*/
350 /* Info on vectorized defs. */
351 /*-----------------------------------------------------------------*/
352 enum stmt_vec_info_type {
353 undef_vec_info_type = 0,
354 load_vec_info_type,
355 store_vec_info_type,
356 shift_vec_info_type,
357 op_vec_info_type,
358 call_vec_info_type,
359 assignment_vec_info_type,
360 condition_vec_info_type,
361 reduc_vec_info_type,
362 induc_vec_info_type,
363 type_promotion_vec_info_type,
364 type_demotion_vec_info_type,
365 type_conversion_vec_info_type,
366 loop_exit_ctrl_vec_info_type
369 /* Indicates whether/how a variable is used in the scope of loop/basic
370 block. */
371 enum vect_relevant {
372 vect_unused_in_scope = 0,
373 /* The def is in the inner loop, and the use is in the outer loop, and the
374 use is a reduction stmt. */
375 vect_used_in_outer_by_reduction,
376 /* The def is in the inner loop, and the use is in the outer loop (and is
377 not part of reduction). */
378 vect_used_in_outer,
380 /* defs that feed computations that end up (only) in a reduction. These
381 defs may be used by non-reduction stmts, but eventually, any
382 computations/values that are affected by these defs are used to compute
383 a reduction (i.e. don't get stored to memory, for example). We use this
384 to identify computations that we can change the order in which they are
385 computed. */
386 vect_used_by_reduction,
388 vect_used_in_scope
391 /* The type of vectorization that can be applied to the stmt: regular loop-based
392 vectorization; pure SLP - the stmt is a part of SLP instances and does not
393 have uses outside SLP instances; or hybrid SLP and loop-based - the stmt is
394 a part of SLP instance and also must be loop-based vectorized, since it has
395 uses outside SLP sequences.
397 In the loop context the meanings of pure and hybrid SLP are slightly
398 different. By saying that pure SLP is applied to the loop, we mean that we
399 exploit only intra-iteration parallelism in the loop; i.e., the loop can be
400 vectorized without doing any conceptual unrolling, cause we don't pack
401 together stmts from different iterations, only within a single iteration.
402 Loop hybrid SLP means that we exploit both intra-iteration and
403 inter-iteration parallelism (e.g., number of elements in the vector is 4
404 and the slp-group-size is 2, in which case we don't have enough parallelism
405 within an iteration, so we obtain the rest of the parallelism from subsequent
406 iterations by unrolling the loop by 2). */
407 enum slp_vect_type {
408 loop_vect = 0,
409 pure_slp,
410 hybrid
414 typedef struct data_reference *dr_p;
415 DEF_VEC_P(dr_p);
416 DEF_VEC_ALLOC_P(dr_p,heap);
418 typedef struct _stmt_vec_info {
420 enum stmt_vec_info_type type;
422 /* Indicates whether this stmts is part of a computation whose result is
423 used outside the loop. */
424 bool live;
426 /* Stmt is part of some pattern (computation idiom) */
427 bool in_pattern_p;
429 /* For loads only, if there is a store with the same location, this field is
430 TRUE. */
431 bool read_write_dep;
433 /* The stmt to which this info struct refers to. */
434 gimple stmt;
436 /* The loop_vec_info with respect to which STMT is vectorized. */
437 loop_vec_info loop_vinfo;
439 /* The vector type to be used for the LHS of this statement. */
440 tree vectype;
442 /* The vectorized version of the stmt. */
443 gimple vectorized_stmt;
446 /** The following is relevant only for stmts that contain a non-scalar
447 data-ref (array/pointer/struct access). A GIMPLE stmt is expected to have
448 at most one such data-ref. **/
450 /* Information about the data-ref (access function, etc),
451 relative to the inner-most containing loop. */
452 struct data_reference *data_ref_info;
454 /* Information about the data-ref relative to this loop
455 nest (the loop that is being considered for vectorization). */
456 tree dr_base_address;
457 tree dr_init;
458 tree dr_offset;
459 tree dr_step;
460 tree dr_aligned_to;
462 /* Used for various bookkeeping purposes, generally holding a pointer to
463 some other stmt S that is in some way "related" to this stmt.
464 Current use of this field is:
465 If this stmt is part of a pattern (i.e. the field 'in_pattern_p' is
466 true): S is the "pattern stmt" that represents (and replaces) the
467 sequence of stmts that constitutes the pattern. Similarly, the
468 related_stmt of the "pattern stmt" points back to this stmt (which is
469 the last stmt in the original sequence of stmts that constitutes the
470 pattern). */
471 gimple related_stmt;
473 /* List of datarefs that are known to have the same alignment as the dataref
474 of this stmt. */
475 VEC(dr_p,heap) *same_align_refs;
477 /* Classify the def of this stmt. */
478 enum vect_def_type def_type;
480 /* Whether the stmt is SLPed, loop-based vectorized, or both. */
481 enum slp_vect_type slp_type;
483 /* Interleaving info. */
484 /* First data-ref in the interleaving group. */
485 gimple first_dr;
486 /* Pointer to the next data-ref in the group. */
487 gimple next_dr;
488 /* In case that two or more stmts share data-ref, this is the pointer to the
489 previously detected stmt with the same dr. */
490 gimple same_dr_stmt;
491 /* The size of the interleaving group. */
492 unsigned int size;
493 /* For stores, number of stores from this group seen. We vectorize the last
494 one. */
495 unsigned int store_count;
496 /* For loads only, the gap from the previous load. For consecutive loads, GAP
497 is 1. */
498 unsigned int gap;
500 /* Not all stmts in the loop need to be vectorized. e.g, the increment
501 of the loop induction variable and computation of array indexes. relevant
502 indicates whether the stmt needs to be vectorized. */
503 enum vect_relevant relevant;
505 /* Vectorization costs associated with statement. */
506 struct
508 int outside_of_loop; /* Statements generated outside loop. */
509 int inside_of_loop; /* Statements generated inside loop. */
510 } cost;
512 /* The bb_vec_info with respect to which STMT is vectorized. */
513 bb_vec_info bb_vinfo;
515 /* Is this statement vectorizable or should it be skipped in (partial)
516 vectorization. */
517 bool vectorizable;
518 } *stmt_vec_info;
520 /* Access Functions. */
521 #define STMT_VINFO_TYPE(S) (S)->type
522 #define STMT_VINFO_STMT(S) (S)->stmt
523 #define STMT_VINFO_LOOP_VINFO(S) (S)->loop_vinfo
524 #define STMT_VINFO_BB_VINFO(S) (S)->bb_vinfo
525 #define STMT_VINFO_RELEVANT(S) (S)->relevant
526 #define STMT_VINFO_LIVE_P(S) (S)->live
527 #define STMT_VINFO_VECTYPE(S) (S)->vectype
528 #define STMT_VINFO_VEC_STMT(S) (S)->vectorized_stmt
529 #define STMT_VINFO_VECTORIZABLE(S) (S)->vectorizable
530 #define STMT_VINFO_DATA_REF(S) (S)->data_ref_info
532 #define STMT_VINFO_DR_BASE_ADDRESS(S) (S)->dr_base_address
533 #define STMT_VINFO_DR_INIT(S) (S)->dr_init
534 #define STMT_VINFO_DR_OFFSET(S) (S)->dr_offset
535 #define STMT_VINFO_DR_STEP(S) (S)->dr_step
536 #define STMT_VINFO_DR_ALIGNED_TO(S) (S)->dr_aligned_to
538 #define STMT_VINFO_IN_PATTERN_P(S) (S)->in_pattern_p
539 #define STMT_VINFO_RELATED_STMT(S) (S)->related_stmt
540 #define STMT_VINFO_SAME_ALIGN_REFS(S) (S)->same_align_refs
541 #define STMT_VINFO_DEF_TYPE(S) (S)->def_type
542 #define STMT_VINFO_DR_GROUP_FIRST_DR(S) (S)->first_dr
543 #define STMT_VINFO_DR_GROUP_NEXT_DR(S) (S)->next_dr
544 #define STMT_VINFO_DR_GROUP_SIZE(S) (S)->size
545 #define STMT_VINFO_DR_GROUP_STORE_COUNT(S) (S)->store_count
546 #define STMT_VINFO_DR_GROUP_GAP(S) (S)->gap
547 #define STMT_VINFO_DR_GROUP_SAME_DR_STMT(S)(S)->same_dr_stmt
548 #define STMT_VINFO_DR_GROUP_READ_WRITE_DEPENDENCE(S) (S)->read_write_dep
549 #define STMT_VINFO_STRIDED_ACCESS(S) ((S)->first_dr != NULL)
551 #define DR_GROUP_FIRST_DR(S) (S)->first_dr
552 #define DR_GROUP_NEXT_DR(S) (S)->next_dr
553 #define DR_GROUP_SIZE(S) (S)->size
554 #define DR_GROUP_STORE_COUNT(S) (S)->store_count
555 #define DR_GROUP_GAP(S) (S)->gap
556 #define DR_GROUP_SAME_DR_STMT(S) (S)->same_dr_stmt
557 #define DR_GROUP_READ_WRITE_DEPENDENCE(S) (S)->read_write_dep
559 #define STMT_VINFO_RELEVANT_P(S) ((S)->relevant != vect_unused_in_scope)
560 #define STMT_VINFO_OUTSIDE_OF_LOOP_COST(S) (S)->cost.outside_of_loop
561 #define STMT_VINFO_INSIDE_OF_LOOP_COST(S) (S)->cost.inside_of_loop
563 #define HYBRID_SLP_STMT(S) ((S)->slp_type == hybrid)
564 #define PURE_SLP_STMT(S) ((S)->slp_type == pure_slp)
565 #define STMT_SLP_TYPE(S) (S)->slp_type
567 #define VECT_MAX_COST 1000
569 /* The maximum number of intermediate steps required in multi-step type
570 conversion. */
571 #define MAX_INTERM_CVT_STEPS 3
573 /* The maximum vectorization factor supported by any target (V32QI). */
574 #define MAX_VECTORIZATION_FACTOR 32
576 /* Avoid GTY(()) on stmt_vec_info. */
577 typedef void *vec_void_p;
578 DEF_VEC_P (vec_void_p);
579 DEF_VEC_ALLOC_P (vec_void_p, heap);
581 extern VEC(vec_void_p,heap) *stmt_vec_info_vec;
583 void init_stmt_vec_info_vec (void);
584 void free_stmt_vec_info_vec (void);
586 /* Return a stmt_vec_info corresponding to STMT. */
588 static inline stmt_vec_info
589 vinfo_for_stmt (gimple stmt)
591 unsigned int uid = gimple_uid (stmt);
592 if (uid == 0)
593 return NULL;
595 return (stmt_vec_info) VEC_index (vec_void_p, stmt_vec_info_vec, uid - 1);
598 /* Set vectorizer information INFO for STMT. */
600 static inline void
601 set_vinfo_for_stmt (gimple stmt, stmt_vec_info info)
603 unsigned int uid = gimple_uid (stmt);
604 if (uid == 0)
606 gcc_checking_assert (info);
607 uid = VEC_length (vec_void_p, stmt_vec_info_vec) + 1;
608 gimple_set_uid (stmt, uid);
609 VEC_safe_push (vec_void_p, heap, stmt_vec_info_vec, (vec_void_p) info);
611 else
612 VEC_replace (vec_void_p, stmt_vec_info_vec, uid - 1, (vec_void_p) info);
615 /* Return the earlier statement between STMT1 and STMT2. */
617 static inline gimple
618 get_earlier_stmt (gimple stmt1, gimple stmt2)
620 unsigned int uid1, uid2;
622 if (stmt1 == NULL)
623 return stmt2;
625 if (stmt2 == NULL)
626 return stmt1;
628 uid1 = gimple_uid (stmt1);
629 uid2 = gimple_uid (stmt2);
631 if (uid1 == 0 || uid2 == 0)
632 return NULL;
634 gcc_checking_assert (uid1 <= VEC_length (vec_void_p, stmt_vec_info_vec)
635 && uid2 <= VEC_length (vec_void_p, stmt_vec_info_vec));
637 if (uid1 < uid2)
638 return stmt1;
639 else
640 return stmt2;
643 /* Return the later statement between STMT1 and STMT2. */
645 static inline gimple
646 get_later_stmt (gimple stmt1, gimple stmt2)
648 unsigned int uid1, uid2;
650 if (stmt1 == NULL)
651 return stmt2;
653 if (stmt2 == NULL)
654 return stmt1;
656 uid1 = gimple_uid (stmt1);
657 uid2 = gimple_uid (stmt2);
659 if (uid1 == 0 || uid2 == 0)
660 return NULL;
662 gcc_assert (uid1 <= VEC_length (vec_void_p, stmt_vec_info_vec));
663 gcc_assert (uid2 <= VEC_length (vec_void_p, stmt_vec_info_vec));
665 if (uid1 > uid2)
666 return stmt1;
667 else
668 return stmt2;
671 /* Return TRUE if a statement represented by STMT_INFO is a part of a
672 pattern. */
674 static inline bool
675 is_pattern_stmt_p (stmt_vec_info stmt_info)
677 gimple related_stmt;
678 stmt_vec_info related_stmt_info;
680 related_stmt = STMT_VINFO_RELATED_STMT (stmt_info);
681 if (related_stmt
682 && (related_stmt_info = vinfo_for_stmt (related_stmt))
683 && STMT_VINFO_IN_PATTERN_P (related_stmt_info))
684 return true;
686 return false;
689 /* Return true if BB is a loop header. */
691 static inline bool
692 is_loop_header_bb_p (basic_block bb)
694 if (bb == (bb->loop_father)->header)
695 return true;
696 gcc_checking_assert (EDGE_COUNT (bb->preds) == 1);
697 return false;
700 /* Set inside loop vectorization cost. */
702 static inline void
703 stmt_vinfo_set_inside_of_loop_cost (stmt_vec_info stmt_info, slp_tree slp_node,
704 int cost)
706 if (slp_node)
707 SLP_TREE_INSIDE_OF_LOOP_COST (slp_node) = cost;
708 else
709 STMT_VINFO_INSIDE_OF_LOOP_COST (stmt_info) = cost;
712 /* Set inside loop vectorization cost. */
714 static inline void
715 stmt_vinfo_set_outside_of_loop_cost (stmt_vec_info stmt_info, slp_tree slp_node,
716 int cost)
718 if (slp_node)
719 SLP_TREE_OUTSIDE_OF_LOOP_COST (slp_node) = cost;
720 else
721 STMT_VINFO_OUTSIDE_OF_LOOP_COST (stmt_info) = cost;
724 /* Return pow2 (X). */
726 static inline int
727 vect_pow2 (int x)
729 int i, res = 1;
731 for (i = 0; i < x; i++)
732 res *= 2;
734 return res;
737 /*-----------------------------------------------------------------*/
738 /* Info on data references alignment. */
739 /*-----------------------------------------------------------------*/
741 /* Reflects actual alignment of first access in the vectorized loop,
742 taking into account peeling/versioning if applied. */
743 #define DR_MISALIGNMENT(DR) ((int) (size_t) (DR)->aux)
744 #define SET_DR_MISALIGNMENT(DR, VAL) ((DR)->aux = (void *) (size_t) (VAL))
746 /* Return TRUE if the data access is aligned, and FALSE otherwise. */
748 static inline bool
749 aligned_access_p (struct data_reference *data_ref_info)
751 return (DR_MISALIGNMENT (data_ref_info) == 0);
754 /* Return TRUE if the alignment of the data access is known, and FALSE
755 otherwise. */
757 static inline bool
758 known_alignment_for_access_p (struct data_reference *data_ref_info)
760 return (DR_MISALIGNMENT (data_ref_info) != -1);
763 /* vect_dump will be set to stderr or dump_file if exist. */
764 extern FILE *vect_dump;
765 extern LOC vect_loop_location;
767 /*-----------------------------------------------------------------*/
768 /* Function prototypes. */
769 /*-----------------------------------------------------------------*/
771 /* Simple loop peeling and versioning utilities for vectorizer's purposes -
772 in tree-vect-loop-manip.c. */
773 extern void slpeel_make_loop_iterate_ntimes (struct loop *, tree);
774 extern bool slpeel_can_duplicate_loop_p (const struct loop *, const_edge);
775 extern void vect_loop_versioning (loop_vec_info, bool, tree *, gimple_seq *);
776 extern void vect_do_peeling_for_loop_bound (loop_vec_info, tree *,
777 tree, gimple_seq);
778 extern void vect_do_peeling_for_alignment (loop_vec_info);
779 extern LOC find_loop_location (struct loop *);
780 extern bool vect_can_advance_ivs_p (loop_vec_info);
782 /* In tree-vect-stmts.c. */
783 extern unsigned int current_vector_size;
784 extern tree get_vectype_for_scalar_type (tree);
785 extern tree get_same_sized_vectype (tree, tree);
786 extern bool vect_is_simple_use (tree, loop_vec_info, bb_vec_info, gimple *,
787 tree *, enum vect_def_type *);
788 extern bool vect_is_simple_use_1 (tree, loop_vec_info, bb_vec_info, gimple *,
789 tree *, enum vect_def_type *, tree *);
790 extern bool supportable_widening_operation (enum tree_code, gimple, tree, tree,
791 tree *, tree *, enum tree_code *,
792 enum tree_code *, int *,
793 VEC (tree, heap) **);
794 extern bool supportable_narrowing_operation (enum tree_code, tree, tree,
795 enum tree_code *,
796 int *, VEC (tree, heap) **);
797 extern stmt_vec_info new_stmt_vec_info (gimple stmt, loop_vec_info,
798 bb_vec_info);
799 extern void free_stmt_vec_info (gimple stmt);
800 extern tree vectorizable_function (gimple, tree, tree);
801 extern void vect_model_simple_cost (stmt_vec_info, int, enum vect_def_type *,
802 slp_tree);
803 extern void vect_model_store_cost (stmt_vec_info, int, enum vect_def_type,
804 slp_tree);
805 extern void vect_model_load_cost (stmt_vec_info, int, slp_tree);
806 extern void vect_finish_stmt_generation (gimple, gimple,
807 gimple_stmt_iterator *);
808 extern bool vect_mark_stmts_to_be_vectorized (loop_vec_info);
809 extern int cost_for_stmt (gimple);
810 extern tree vect_get_vec_def_for_operand (tree, gimple, tree *);
811 extern tree vect_init_vector (gimple, tree, tree,
812 gimple_stmt_iterator *);
813 extern tree vect_get_vec_def_for_stmt_copy (enum vect_def_type, tree);
814 extern bool vect_transform_stmt (gimple, gimple_stmt_iterator *,
815 bool *, slp_tree, slp_instance);
816 extern void vect_remove_stores (gimple);
817 extern bool vect_analyze_stmt (gimple, bool *, slp_tree);
818 extern bool vectorizable_condition (gimple, gimple_stmt_iterator *, gimple *,
819 tree, int);
820 extern void vect_get_load_cost (struct data_reference *, int, bool,
821 unsigned int *, unsigned int *);
822 extern void vect_get_store_cost (struct data_reference *, int, unsigned int *);
824 /* In tree-vect-data-refs.c. */
825 extern bool vect_can_force_dr_alignment_p (const_tree, unsigned int);
826 extern enum dr_alignment_support vect_supportable_dr_alignment
827 (struct data_reference *, bool);
828 extern tree vect_get_smallest_scalar_type (gimple, HOST_WIDE_INT *,
829 HOST_WIDE_INT *);
830 extern bool vect_analyze_data_ref_dependences (loop_vec_info, bb_vec_info,
831 int *, bool *);
832 extern bool vect_enhance_data_refs_alignment (loop_vec_info);
833 extern bool vect_analyze_data_refs_alignment (loop_vec_info, bb_vec_info);
834 extern bool vect_verify_datarefs_alignment (loop_vec_info, bb_vec_info);
835 extern bool vect_analyze_data_ref_accesses (loop_vec_info, bb_vec_info);
836 extern bool vect_prune_runtime_alias_test_list (loop_vec_info);
837 extern bool vect_analyze_data_refs (loop_vec_info, bb_vec_info, int *);
838 extern tree vect_create_data_ref_ptr (gimple, struct loop *, tree, tree *,
839 gimple *, bool, bool *);
840 extern tree bump_vector_ptr (tree, gimple, gimple_stmt_iterator *, gimple, tree);
841 extern tree vect_create_destination_var (tree, tree);
842 extern bool vect_strided_store_supported (tree);
843 extern bool vect_strided_load_supported (tree);
844 extern bool vect_permute_store_chain (VEC(tree,heap) *,unsigned int, gimple,
845 gimple_stmt_iterator *, VEC(tree,heap) **);
846 extern tree vect_setup_realignment (gimple, gimple_stmt_iterator *, tree *,
847 enum dr_alignment_support, tree,
848 struct loop **);
849 extern bool vect_permute_load_chain (VEC(tree,heap) *,unsigned int, gimple,
850 gimple_stmt_iterator *, VEC(tree,heap) **);
851 extern bool vect_transform_strided_load (gimple, VEC(tree,heap) *, int,
852 gimple_stmt_iterator *);
853 extern int vect_get_place_in_interleaving_chain (gimple, gimple);
854 extern tree vect_get_new_vect_var (tree, enum vect_var_kind, const char *);
855 extern tree vect_create_addr_base_for_vector_ref (gimple, gimple_seq *,
856 tree, struct loop *);
858 /* In tree-vect-loop.c. */
859 /* FORNOW: Used in tree-parloops.c. */
860 extern void destroy_loop_vec_info (loop_vec_info, bool);
861 extern gimple vect_force_simple_reduction (loop_vec_info, gimple, bool, bool *);
862 /* Drive for loop analysis stage. */
863 extern loop_vec_info vect_analyze_loop (struct loop *);
864 /* Drive for loop transformation stage. */
865 extern void vect_transform_loop (loop_vec_info);
866 extern loop_vec_info vect_analyze_loop_form (struct loop *);
867 extern bool vectorizable_live_operation (gimple, gimple_stmt_iterator *,
868 gimple *);
869 extern bool vectorizable_reduction (gimple, gimple_stmt_iterator *, gimple *,
870 slp_tree);
871 extern bool vectorizable_induction (gimple, gimple_stmt_iterator *, gimple *);
872 extern int vect_estimate_min_profitable_iters (loop_vec_info);
873 extern tree get_initial_def_for_reduction (gimple, tree, tree *);
874 extern int vect_min_worthwhile_factor (enum tree_code);
875 extern int vect_get_known_peeling_cost (loop_vec_info, int, int *, int);
876 extern int vect_get_single_scalar_iteraion_cost (loop_vec_info);
878 /* In tree-vect-slp.c. */
879 extern void vect_free_slp_instance (slp_instance);
880 extern bool vect_transform_slp_perm_load (gimple, VEC (tree, heap) *,
881 gimple_stmt_iterator *, int,
882 slp_instance, bool);
883 extern bool vect_schedule_slp (loop_vec_info, bb_vec_info);
884 extern void vect_update_slp_costs_according_to_vf (loop_vec_info);
885 extern bool vect_analyze_slp (loop_vec_info, bb_vec_info);
886 extern void vect_make_slp_decision (loop_vec_info);
887 extern void vect_detect_hybrid_slp (loop_vec_info);
888 extern void vect_get_slp_defs (tree, tree, slp_tree, VEC (tree,heap) **,
889 VEC (tree,heap) **, int);
890 extern LOC find_bb_location (basic_block);
891 extern bb_vec_info vect_slp_analyze_bb (basic_block);
892 extern void vect_slp_transform_bb (basic_block);
894 /* In tree-vect-patterns.c. */
895 /* Pattern recognition functions.
896 Additional pattern recognition functions can (and will) be added
897 in the future. */
898 typedef gimple (* vect_recog_func_ptr) (gimple, tree *, tree *);
899 #define NUM_PATTERNS 4
900 void vect_pattern_recog (loop_vec_info);
902 /* In tree-vectorizer.c. */
903 unsigned vectorize_loops (void);
904 /* Vectorization debug information */
905 extern bool vect_print_dump_info (enum verbosity_levels);
907 #endif /* GCC_TREE_VECTORIZER_H */