expmed.c (expand_divmod): Always use a comparison for a division by a large unsigned...
[official-gcc.git] / gcc / tree-vectorizer.h
blob1f3247d1a7550a4ed1c77dc00b71a87bd349abb7
1 /* Vectorizer
2 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free
3 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_constant_def = 1,
59 vect_invariant_def,
60 vect_loop_def,
61 vect_induction_def,
62 vect_reduction_def,
63 vect_unknown_def_type
66 /* Define verbosity levels. */
67 enum verbosity_levels {
68 REPORT_NONE,
69 REPORT_VECTORIZED_LOOPS,
70 REPORT_UNVECTORIZED_LOOPS,
71 REPORT_COST,
72 REPORT_ALIGNMENT,
73 REPORT_DR_DETAILS,
74 REPORT_BAD_FORM_LOOPS,
75 REPORT_OUTER_LOOPS,
76 REPORT_SLP,
77 REPORT_DETAILS,
78 /* New verbosity levels should be added before this one. */
79 MAX_VERBOSITY_LEVEL
82 /************************************************************************
83 SLP
84 ************************************************************************/
86 /* A computation tree of an SLP instance. Each node corresponds to a group of
87 stmts to be packed in a SIMD stmt. */
88 typedef struct _slp_tree {
89 /* Only binary and unary operations are supported. LEFT child corresponds to
90 the first operand and RIGHT child to the second if the operation is
91 binary. */
92 struct _slp_tree *left;
93 struct _slp_tree *right;
94 /* A group of scalar stmts to be vectorized together. */
95 VEC (gimple, heap) *stmts;
96 /* Vectorized stmt/s. */
97 VEC (gimple, heap) *vec_stmts;
98 /* Number of vector stmts that are created to replace the group of scalar
99 stmts. It is calculated during the transformation phase as the number of
100 scalar elements in one scalar iteration (GROUP_SIZE) multiplied by VF
101 divided by vector size. */
102 unsigned int vec_stmts_size;
103 /* Vectorization costs associated with SLP node. */
104 struct
106 int outside_of_loop; /* Statements generated outside loop. */
107 int inside_of_loop; /* Statements generated inside loop. */
108 } cost;
109 } *slp_tree;
111 DEF_VEC_P(slp_tree);
112 DEF_VEC_ALLOC_P(slp_tree, heap);
114 /* SLP instance is a sequence of stmts in a loop that can be packed into
115 SIMD stmts. */
116 typedef struct _slp_instance {
117 /* The root of SLP tree. */
118 slp_tree root;
120 /* Size of groups of scalar stmts that will be replaced by SIMD stmt/s. */
121 unsigned int group_size;
123 /* The unrolling factor required to vectorized this SLP instance. */
124 unsigned int unrolling_factor;
126 /* Vectorization costs associated with SLP instance. */
127 struct
129 int outside_of_loop; /* Statements generated outside loop. */
130 int inside_of_loop; /* Statements generated inside loop. */
131 } cost;
133 /* Loads permutation relatively to the stores, NULL if there is no
134 permutation. */
135 VEC (int, heap) *load_permutation;
137 /* The group of nodes that contain loads of this SLP instance. */
138 VEC (slp_tree, heap) *loads;
140 /* The first scalar load of the instance. The created vector loads will be
141 inserted before this statement. */
142 gimple first_load;
143 } *slp_instance;
145 DEF_VEC_P(slp_instance);
146 DEF_VEC_ALLOC_P(slp_instance, heap);
148 /* Access Functions. */
149 #define SLP_INSTANCE_TREE(S) (S)->root
150 #define SLP_INSTANCE_GROUP_SIZE(S) (S)->group_size
151 #define SLP_INSTANCE_UNROLLING_FACTOR(S) (S)->unrolling_factor
152 #define SLP_INSTANCE_OUTSIDE_OF_LOOP_COST(S) (S)->cost.outside_of_loop
153 #define SLP_INSTANCE_INSIDE_OF_LOOP_COST(S) (S)->cost.inside_of_loop
154 #define SLP_INSTANCE_LOAD_PERMUTATION(S) (S)->load_permutation
155 #define SLP_INSTANCE_LOADS(S) (S)->loads
156 #define SLP_INSTANCE_FIRST_LOAD_STMT(S) (S)->first_load
158 #define SLP_TREE_LEFT(S) (S)->left
159 #define SLP_TREE_RIGHT(S) (S)->right
160 #define SLP_TREE_SCALAR_STMTS(S) (S)->stmts
161 #define SLP_TREE_VEC_STMTS(S) (S)->vec_stmts
162 #define SLP_TREE_NUMBER_OF_VEC_STMTS(S) (S)->vec_stmts_size
163 #define SLP_TREE_OUTSIDE_OF_LOOP_COST(S) (S)->cost.outside_of_loop
164 #define SLP_TREE_INSIDE_OF_LOOP_COST(S) (S)->cost.inside_of_loop
166 /*-----------------------------------------------------------------*/
167 /* Info on vectorized loops. */
168 /*-----------------------------------------------------------------*/
169 typedef struct _loop_vec_info {
171 /* The loop to which this info struct refers to. */
172 struct loop *loop;
174 /* The loop basic blocks. */
175 basic_block *bbs;
177 /* Number of iterations. */
178 tree num_iters;
179 tree num_iters_unchanged;
181 /* Minimum number of iterations below which vectorization is expected to
182 not be profitable (as estimated by the cost model).
183 -1 indicates that vectorization will not be profitable.
184 FORNOW: This field is an int. Will be a tree in the future, to represent
185 values unknown at compile time. */
186 int min_profitable_iters;
188 /* Is the loop vectorizable? */
189 bool vectorizable;
191 /* Unrolling factor */
192 int vectorization_factor;
194 /* Unknown DRs according to which loop was peeled. */
195 struct data_reference *unaligned_dr;
197 /* peeling_for_alignment indicates whether peeling for alignment will take
198 place, and what the peeling factor should be:
199 peeling_for_alignment = X means:
200 If X=0: Peeling for alignment will not be applied.
201 If X>0: Peel first X iterations.
202 If X=-1: Generate a runtime test to calculate the number of iterations
203 to be peeled, using the dataref recorded in the field
204 unaligned_dr. */
205 int peeling_for_alignment;
207 /* The mask used to check the alignment of pointers or arrays. */
208 int ptr_mask;
210 /* All data references in the loop. */
211 VEC (data_reference_p, heap) *datarefs;
213 /* All data dependences in the loop. */
214 VEC (ddr_p, heap) *ddrs;
216 /* Data Dependence Relations defining address ranges that are candidates
217 for a run-time aliasing check. */
218 VEC (ddr_p, heap) *may_alias_ddrs;
220 /* Statements in the loop that have data references that are candidates for a
221 runtime (loop versioning) misalignment check. */
222 VEC(gimple,heap) *may_misalign_stmts;
224 /* The loop location in the source. */
225 LOC loop_line_number;
227 /* All interleaving chains of stores in the loop, represented by the first
228 stmt in the chain. */
229 VEC(gimple, heap) *strided_stores;
231 /* All SLP instances in the loop. This is a subset of the set of STRIDED_STORES
232 of the loop. */
233 VEC(slp_instance, heap) *slp_instances;
235 /* The unrolling factor needed to SLP the loop. In case of that pure SLP is
236 applied to the loop, i.e., no unrolling is needed, this is 1. */
237 unsigned slp_unrolling_factor;
238 } *loop_vec_info;
240 /* Access Functions. */
241 #define LOOP_VINFO_LOOP(L) (L)->loop
242 #define LOOP_VINFO_BBS(L) (L)->bbs
243 #define LOOP_VINFO_NITERS(L) (L)->num_iters
244 /* Since LOOP_VINFO_NITERS can change after prologue peeling
245 retain total unchanged scalar loop iterations for cost model. */
246 #define LOOP_VINFO_NITERS_UNCHANGED(L) (L)->num_iters_unchanged
247 #define LOOP_VINFO_COST_MODEL_MIN_ITERS(L) (L)->min_profitable_iters
248 #define LOOP_VINFO_VECTORIZABLE_P(L) (L)->vectorizable
249 #define LOOP_VINFO_VECT_FACTOR(L) (L)->vectorization_factor
250 #define LOOP_VINFO_PTR_MASK(L) (L)->ptr_mask
251 #define LOOP_VINFO_DATAREFS(L) (L)->datarefs
252 #define LOOP_VINFO_DDRS(L) (L)->ddrs
253 #define LOOP_VINFO_INT_NITERS(L) (TREE_INT_CST_LOW ((L)->num_iters))
254 #define LOOP_PEELING_FOR_ALIGNMENT(L) (L)->peeling_for_alignment
255 #define LOOP_VINFO_UNALIGNED_DR(L) (L)->unaligned_dr
256 #define LOOP_VINFO_MAY_MISALIGN_STMTS(L) (L)->may_misalign_stmts
257 #define LOOP_VINFO_LOC(L) (L)->loop_line_number
258 #define LOOP_VINFO_MAY_ALIAS_DDRS(L) (L)->may_alias_ddrs
259 #define LOOP_VINFO_STRIDED_STORES(L) (L)->strided_stores
260 #define LOOP_VINFO_SLP_INSTANCES(L) (L)->slp_instances
261 #define LOOP_VINFO_SLP_UNROLLING_FACTOR(L) (L)->slp_unrolling_factor
263 #define NITERS_KNOWN_P(n) \
264 (host_integerp ((n),0) \
265 && TREE_INT_CST_LOW ((n)) > 0)
267 #define LOOP_VINFO_NITERS_KNOWN_P(L) \
268 NITERS_KNOWN_P((L)->num_iters)
270 static inline loop_vec_info
271 loop_vec_info_for_loop (struct loop *loop)
273 return (loop_vec_info) loop->aux;
276 static inline bool
277 nested_in_vect_loop_p (struct loop *loop, gimple stmt)
279 return (loop->inner
280 && (loop->inner == (gimple_bb (stmt))->loop_father));
283 /*-----------------------------------------------------------------*/
284 /* Info on vectorized defs. */
285 /*-----------------------------------------------------------------*/
286 enum stmt_vec_info_type {
287 undef_vec_info_type = 0,
288 load_vec_info_type,
289 store_vec_info_type,
290 op_vec_info_type,
291 call_vec_info_type,
292 assignment_vec_info_type,
293 condition_vec_info_type,
294 reduc_vec_info_type,
295 induc_vec_info_type,
296 type_promotion_vec_info_type,
297 type_demotion_vec_info_type,
298 type_conversion_vec_info_type,
299 loop_exit_ctrl_vec_info_type
302 /* Indicates whether/how a variable is used in the loop. */
303 enum vect_relevant {
304 vect_unused_in_loop = 0,
305 vect_used_in_outer_by_reduction,
306 vect_used_in_outer,
308 /* defs that feed computations that end up (only) in a reduction. These
309 defs may be used by non-reduction stmts, but eventually, any
310 computations/values that are affected by these defs are used to compute
311 a reduction (i.e. don't get stored to memory, for example). We use this
312 to identify computations that we can change the order in which they are
313 computed. */
314 vect_used_by_reduction,
316 vect_used_in_loop
319 /* The type of vectorization that can be applied to the stmt: regular loop-based
320 vectorization; pure SLP - the stmt is a part of SLP instances and does not
321 have uses outside SLP instances; or hybrid SLP and loop-based - the stmt is
322 a part of SLP instance and also must be loop-based vectorized, since it has
323 uses outside SLP sequences.
325 In the loop context the meanings of pure and hybrid SLP are slightly
326 different. By saying that pure SLP is applied to the loop, we mean that we
327 exploit only intra-iteration parallelism in the loop; i.e., the loop can be
328 vectorized without doing any conceptual unrolling, cause we don't pack
329 together stmts from different iterations, only within a single iteration.
330 Loop hybrid SLP means that we exploit both intra-iteration and
331 inter-iteration parallelism (e.g., number of elements in the vector is 4
332 and the slp-group-size is 2, in which case we don't have enough parallelism
333 within an iteration, so we obtain the rest of the parallelism from subsequent
334 iterations by unrolling the loop by 2). */
335 enum slp_vect_type {
336 loop_vect = 0,
337 pure_slp,
338 hybrid
342 typedef struct data_reference *dr_p;
343 DEF_VEC_P(dr_p);
344 DEF_VEC_ALLOC_P(dr_p,heap);
346 typedef struct _stmt_vec_info {
348 enum stmt_vec_info_type type;
350 /* The stmt to which this info struct refers to. */
351 gimple stmt;
353 /* The loop_vec_info with respect to which STMT is vectorized. */
354 loop_vec_info loop_vinfo;
356 /* Not all stmts in the loop need to be vectorized. e.g, the increment
357 of the loop induction variable and computation of array indexes. relevant
358 indicates whether the stmt needs to be vectorized. */
359 enum vect_relevant relevant;
361 /* Indicates whether this stmts is part of a computation whose result is
362 used outside the loop. */
363 bool live;
365 /* The vector type to be used. */
366 tree vectype;
368 /* The vectorized version of the stmt. */
369 gimple vectorized_stmt;
372 /** The following is relevant only for stmts that contain a non-scalar
373 data-ref (array/pointer/struct access). A GIMPLE stmt is expected to have
374 at most one such data-ref. **/
376 /* Information about the data-ref (access function, etc),
377 relative to the inner-most containing loop. */
378 struct data_reference *data_ref_info;
380 /* Information about the data-ref relative to this loop
381 nest (the loop that is being considered for vectorization). */
382 tree dr_base_address;
383 tree dr_init;
384 tree dr_offset;
385 tree dr_step;
386 tree dr_aligned_to;
388 /* Stmt is part of some pattern (computation idiom) */
389 bool in_pattern_p;
391 /* Used for various bookkeeping purposes, generally holding a pointer to
392 some other stmt S that is in some way "related" to this stmt.
393 Current use of this field is:
394 If this stmt is part of a pattern (i.e. the field 'in_pattern_p' is
395 true): S is the "pattern stmt" that represents (and replaces) the
396 sequence of stmts that constitutes the pattern. Similarly, the
397 related_stmt of the "pattern stmt" points back to this stmt (which is
398 the last stmt in the original sequence of stmts that constitutes the
399 pattern). */
400 gimple related_stmt;
402 /* List of datarefs that are known to have the same alignment as the dataref
403 of this stmt. */
404 VEC(dr_p,heap) *same_align_refs;
406 /* Classify the def of this stmt. */
407 enum vect_def_type def_type;
409 /* Interleaving info. */
410 /* First data-ref in the interleaving group. */
411 gimple first_dr;
412 /* Pointer to the next data-ref in the group. */
413 gimple next_dr;
414 /* The size of the interleaving group. */
415 unsigned int size;
416 /* For stores, number of stores from this group seen. We vectorize the last
417 one. */
418 unsigned int store_count;
419 /* For loads only, the gap from the previous load. For consecutive loads, GAP
420 is 1. */
421 unsigned int gap;
422 /* In case that two or more stmts share data-ref, this is the pointer to the
423 previously detected stmt with the same dr. */
424 gimple same_dr_stmt;
425 /* For loads only, if there is a store with the same location, this field is
426 TRUE. */
427 bool read_write_dep;
429 /* Vectorization costs associated with statement. */
430 struct
432 int outside_of_loop; /* Statements generated outside loop. */
433 int inside_of_loop; /* Statements generated inside loop. */
434 } cost;
436 /* Whether the stmt is SLPed, loop-based vectorized, or both. */
437 enum slp_vect_type slp_type;
438 } *stmt_vec_info;
440 /* Access Functions. */
441 #define STMT_VINFO_TYPE(S) (S)->type
442 #define STMT_VINFO_STMT(S) (S)->stmt
443 #define STMT_VINFO_LOOP_VINFO(S) (S)->loop_vinfo
444 #define STMT_VINFO_RELEVANT(S) (S)->relevant
445 #define STMT_VINFO_LIVE_P(S) (S)->live
446 #define STMT_VINFO_VECTYPE(S) (S)->vectype
447 #define STMT_VINFO_VEC_STMT(S) (S)->vectorized_stmt
448 #define STMT_VINFO_DATA_REF(S) (S)->data_ref_info
450 #define STMT_VINFO_DR_BASE_ADDRESS(S) (S)->dr_base_address
451 #define STMT_VINFO_DR_INIT(S) (S)->dr_init
452 #define STMT_VINFO_DR_OFFSET(S) (S)->dr_offset
453 #define STMT_VINFO_DR_STEP(S) (S)->dr_step
454 #define STMT_VINFO_DR_ALIGNED_TO(S) (S)->dr_aligned_to
456 #define STMT_VINFO_IN_PATTERN_P(S) (S)->in_pattern_p
457 #define STMT_VINFO_RELATED_STMT(S) (S)->related_stmt
458 #define STMT_VINFO_SAME_ALIGN_REFS(S) (S)->same_align_refs
459 #define STMT_VINFO_DEF_TYPE(S) (S)->def_type
460 #define STMT_VINFO_DR_GROUP_FIRST_DR(S) (S)->first_dr
461 #define STMT_VINFO_DR_GROUP_NEXT_DR(S) (S)->next_dr
462 #define STMT_VINFO_DR_GROUP_SIZE(S) (S)->size
463 #define STMT_VINFO_DR_GROUP_STORE_COUNT(S) (S)->store_count
464 #define STMT_VINFO_DR_GROUP_GAP(S) (S)->gap
465 #define STMT_VINFO_DR_GROUP_SAME_DR_STMT(S)(S)->same_dr_stmt
466 #define STMT_VINFO_DR_GROUP_READ_WRITE_DEPENDENCE(S) (S)->read_write_dep
467 #define STMT_VINFO_STRIDED_ACCESS(S) ((S)->first_dr != NULL)
469 #define DR_GROUP_FIRST_DR(S) (S)->first_dr
470 #define DR_GROUP_NEXT_DR(S) (S)->next_dr
471 #define DR_GROUP_SIZE(S) (S)->size
472 #define DR_GROUP_STORE_COUNT(S) (S)->store_count
473 #define DR_GROUP_GAP(S) (S)->gap
474 #define DR_GROUP_SAME_DR_STMT(S) (S)->same_dr_stmt
475 #define DR_GROUP_READ_WRITE_DEPENDENCE(S) (S)->read_write_dep
477 #define STMT_VINFO_RELEVANT_P(S) ((S)->relevant != vect_unused_in_loop)
478 #define STMT_VINFO_OUTSIDE_OF_LOOP_COST(S) (S)->cost.outside_of_loop
479 #define STMT_VINFO_INSIDE_OF_LOOP_COST(S) (S)->cost.inside_of_loop
481 #define HYBRID_SLP_STMT(S) ((S)->slp_type == hybrid)
482 #define PURE_SLP_STMT(S) ((S)->slp_type == pure_slp)
483 #define STMT_SLP_TYPE(S) (S)->slp_type
485 /* These are some defines for the initial implementation of the vectorizer's
486 cost model. These will later be target specific hooks. */
488 /* Cost of conditional taken branch. */
489 #ifndef TARG_COND_TAKEN_BRANCH_COST
490 #define TARG_COND_TAKEN_BRANCH_COST 3
491 #endif
493 /* Cost of conditional not taken branch. */
494 #ifndef TARG_COND_NOT_TAKEN_BRANCH_COST
495 #define TARG_COND_NOT_TAKEN_BRANCH_COST 1
496 #endif
498 /* Cost of any scalar operation, excluding load and store. */
499 #ifndef TARG_SCALAR_STMT_COST
500 #define TARG_SCALAR_STMT_COST 1
501 #endif
503 /* Cost of scalar load. */
504 #ifndef TARG_SCALAR_LOAD_COST
505 #define TARG_SCALAR_LOAD_COST 1
506 #endif
508 /* Cost of scalar store. */
509 #ifndef TARG_SCALAR_STORE_COST
510 #define TARG_SCALAR_STORE_COST 1
511 #endif
513 /* Cost of any vector operation, excluding load, store or vector to scalar
514 operation. */
515 #ifndef TARG_VEC_STMT_COST
516 #define TARG_VEC_STMT_COST 1
517 #endif
519 /* Cost of vector to scalar operation. */
520 #ifndef TARG_VEC_TO_SCALAR_COST
521 #define TARG_VEC_TO_SCALAR_COST 1
522 #endif
524 /* Cost of scalar to vector operation. */
525 #ifndef TARG_SCALAR_TO_VEC_COST
526 #define TARG_SCALAR_TO_VEC_COST 1
527 #endif
529 /* Cost of aligned vector load. */
530 #ifndef TARG_VEC_LOAD_COST
531 #define TARG_VEC_LOAD_COST 1
532 #endif
534 /* Cost of misaligned vector load. */
535 #ifndef TARG_VEC_UNALIGNED_LOAD_COST
536 #define TARG_VEC_UNALIGNED_LOAD_COST 2
537 #endif
539 /* Cost of vector store. */
540 #ifndef TARG_VEC_STORE_COST
541 #define TARG_VEC_STORE_COST 1
542 #endif
544 /* Cost of vector permutation. */
545 #ifndef TARG_VEC_PERMUTE_COST
546 #define TARG_VEC_PERMUTE_COST 1
547 #endif
549 /* The maximum number of intermediate steps required in multi-step type
550 conversion. */
551 #define MAX_INTERM_CVT_STEPS 3
553 /* Avoid GTY(()) on stmt_vec_info. */
554 typedef void *vec_void_p;
555 DEF_VEC_P (vec_void_p);
556 DEF_VEC_ALLOC_P (vec_void_p, heap);
558 extern VEC(vec_void_p,heap) *stmt_vec_info_vec;
560 void init_stmt_vec_info_vec (void);
561 void free_stmt_vec_info_vec (void);
563 static inline stmt_vec_info
564 vinfo_for_stmt (gimple stmt)
566 unsigned int uid = gimple_uid (stmt);
567 if (uid == 0)
568 return NULL;
570 gcc_assert (uid <= VEC_length (vec_void_p, stmt_vec_info_vec));
571 return (stmt_vec_info) VEC_index (vec_void_p, stmt_vec_info_vec, uid - 1);
574 static inline void
575 set_vinfo_for_stmt (gimple stmt, stmt_vec_info info)
577 unsigned int uid = gimple_uid (stmt);
578 if (uid == 0)
580 gcc_assert (info);
581 uid = VEC_length (vec_void_p, stmt_vec_info_vec) + 1;
582 gimple_set_uid (stmt, uid);
583 VEC_safe_push (vec_void_p, heap, stmt_vec_info_vec, (vec_void_p) info);
585 else
586 VEC_replace (vec_void_p, stmt_vec_info_vec, uid - 1, (vec_void_p) info);
589 static inline gimple
590 get_earlier_stmt (gimple stmt1, gimple stmt2)
592 unsigned int uid1, uid2;
594 if (stmt1 == NULL)
595 return stmt2;
597 if (stmt2 == NULL)
598 return stmt1;
600 uid1 = gimple_uid (stmt1);
601 uid2 = gimple_uid (stmt2);
603 if (uid1 == 0 || uid2 == 0)
604 return NULL;
606 gcc_assert (uid1 <= VEC_length (vec_void_p, stmt_vec_info_vec));
607 gcc_assert (uid2 <= VEC_length (vec_void_p, stmt_vec_info_vec));
609 if (uid1 < uid2)
610 return stmt1;
611 else
612 return stmt2;
615 static inline bool
616 is_pattern_stmt_p (stmt_vec_info stmt_info)
618 gimple related_stmt;
619 stmt_vec_info related_stmt_info;
621 related_stmt = STMT_VINFO_RELATED_STMT (stmt_info);
622 if (related_stmt
623 && (related_stmt_info = vinfo_for_stmt (related_stmt))
624 && STMT_VINFO_IN_PATTERN_P (related_stmt_info))
625 return true;
627 return false;
630 static inline bool
631 is_loop_header_bb_p (basic_block bb)
633 if (bb == (bb->loop_father)->header)
634 return true;
635 gcc_assert (EDGE_COUNT (bb->preds) == 1);
636 return false;
639 static inline void
640 stmt_vinfo_set_inside_of_loop_cost (stmt_vec_info stmt_info, slp_tree slp_node,
641 int cost)
643 if (slp_node)
644 SLP_TREE_INSIDE_OF_LOOP_COST (slp_node) = cost;
645 else
646 STMT_VINFO_INSIDE_OF_LOOP_COST (stmt_info) = cost;
649 static inline void
650 stmt_vinfo_set_outside_of_loop_cost (stmt_vec_info stmt_info, slp_tree slp_node,
651 int cost)
653 if (slp_node)
654 SLP_TREE_OUTSIDE_OF_LOOP_COST (slp_node) = cost;
655 else
656 STMT_VINFO_OUTSIDE_OF_LOOP_COST (stmt_info) = cost;
659 static inline int
660 vect_pow2 (int x)
662 int i, res = 1;
664 for (i = 0; i < x; i++)
665 res *= 2;
667 return res;
670 /*-----------------------------------------------------------------*/
671 /* Info on data references alignment. */
672 /*-----------------------------------------------------------------*/
674 /* Reflects actual alignment of first access in the vectorized loop,
675 taking into account peeling/versioning if applied. */
676 #define DR_MISALIGNMENT(DR) ((int) (size_t) (DR)->aux)
677 #define SET_DR_MISALIGNMENT(DR, VAL) ((DR)->aux = (void *) (size_t) (VAL))
679 static inline bool
680 aligned_access_p (struct data_reference *data_ref_info)
682 return (DR_MISALIGNMENT (data_ref_info) == 0);
685 static inline bool
686 known_alignment_for_access_p (struct data_reference *data_ref_info)
688 return (DR_MISALIGNMENT (data_ref_info) != -1);
691 /* vect_dump will be set to stderr or dump_file if exist. */
692 extern FILE *vect_dump;
693 extern LOC vect_loop_location;
695 extern enum verbosity_levels vect_verbosity_level;
697 /* Bitmap of virtual variables to be renamed. */
698 extern bitmap vect_memsyms_to_rename;
701 /*-----------------------------------------------------------------*/
702 /* Function prototypes. */
703 /*-----------------------------------------------------------------*/
705 /* Simple loop peeling and versioning utilities for vectorizer's purposes -
706 in tree-vect-loop-manip.c. */
707 extern void slpeel_make_loop_iterate_ntimes (struct loop *, tree);
708 extern bool slpeel_can_duplicate_loop_p (const struct loop *, const_edge);
709 extern void vect_loop_versioning (loop_vec_info, bool, tree *, gimple_seq *);
710 extern void vect_do_peeling_for_loop_bound (loop_vec_info, tree *,
711 tree, gimple_seq);
712 extern void vect_do_peeling_for_alignment (loop_vec_info);
713 extern LOC find_loop_location (struct loop *);
714 extern bool vect_can_advance_ivs_p (loop_vec_info);
716 /* In tree-vect-stmts.c. */
717 extern tree get_vectype_for_scalar_type (tree);
718 extern bool vect_is_simple_use (tree, loop_vec_info, gimple *, tree *,
719 enum vect_def_type *);
720 extern bool supportable_widening_operation (enum tree_code, gimple, tree,
721 tree *, tree *, enum tree_code *,
722 enum tree_code *, int *,
723 VEC (tree, heap) **);
724 extern bool supportable_narrowing_operation (enum tree_code, const_gimple,
725 tree, enum tree_code *, int *,
726 VEC (tree, heap) **);
727 extern stmt_vec_info new_stmt_vec_info (gimple stmt, loop_vec_info);
728 extern void free_stmt_vec_info (gimple stmt);
729 extern tree vectorizable_function (gimple, tree, tree);
730 extern void vect_model_simple_cost (stmt_vec_info, int, enum vect_def_type *,
731 slp_tree);
732 extern void vect_model_store_cost (stmt_vec_info, int, enum vect_def_type,
733 slp_tree);
734 extern void vect_model_load_cost (stmt_vec_info, int, slp_tree);
735 extern void vect_finish_stmt_generation (gimple, gimple,
736 gimple_stmt_iterator *);
737 extern bool vect_mark_stmts_to_be_vectorized (loop_vec_info);
738 extern int cost_for_stmt (gimple);
739 extern tree vect_get_vec_def_for_operand (tree, gimple, tree *);
740 extern tree vect_init_vector (gimple, tree, tree,
741 gimple_stmt_iterator *);
742 extern tree vect_get_vec_def_for_stmt_copy (enum vect_def_type, tree);
743 extern bool vect_transform_stmt (gimple, gimple_stmt_iterator *,
744 bool *, slp_tree, slp_instance);
745 extern void vect_remove_stores (gimple);
746 extern bool vect_analyze_operations (loop_vec_info);
748 /* In tree-vect-data-refs.c. */
749 extern bool vect_can_force_dr_alignment_p (const_tree, unsigned int);
750 extern enum dr_alignment_support vect_supportable_dr_alignment
751 (struct data_reference *);
752 extern tree vect_get_smallest_scalar_type (gimple, HOST_WIDE_INT *,
753 HOST_WIDE_INT *);
754 extern bool vect_analyze_data_ref_dependences (loop_vec_info);
755 extern bool vect_enhance_data_refs_alignment (loop_vec_info);
756 extern bool vect_analyze_data_refs_alignment (loop_vec_info);
757 extern bool vect_analyze_data_ref_accesses (loop_vec_info);
758 extern bool vect_prune_runtime_alias_test_list (loop_vec_info);
759 extern bool vect_analyze_data_refs (loop_vec_info);
760 extern tree vect_create_data_ref_ptr (gimple, struct loop *, tree, tree *,
761 gimple *, bool, bool *);
762 extern tree bump_vector_ptr (tree, gimple, gimple_stmt_iterator *, gimple, tree);
763 extern tree vect_create_destination_var (tree, tree);
764 extern bool vect_strided_store_supported (tree);
765 extern bool vect_strided_load_supported (tree);
766 extern bool vect_permute_store_chain (VEC(tree,heap) *,unsigned int, gimple,
767 gimple_stmt_iterator *, VEC(tree,heap) **);
768 extern tree vect_setup_realignment (gimple, gimple_stmt_iterator *, tree *,
769 enum dr_alignment_support, tree,
770 struct loop **);
771 extern bool vect_permute_load_chain (VEC(tree,heap) *,unsigned int, gimple,
772 gimple_stmt_iterator *, VEC(tree,heap) **);
773 extern bool vect_transform_strided_load (gimple, VEC(tree,heap) *, int,
774 gimple_stmt_iterator *);
775 extern int vect_get_place_in_interleaving_chain (gimple, gimple);
776 extern tree vect_get_new_vect_var (tree, enum vect_var_kind, const char *);
777 extern tree vect_create_addr_base_for_vector_ref (gimple, gimple_seq *,
778 tree, struct loop *);
780 /* In tree-vect-loop.c. */
781 /* FORNOW: Used in tree-parloops.c. */
782 extern void destroy_loop_vec_info (loop_vec_info, bool);
783 extern gimple vect_is_simple_reduction (loop_vec_info, gimple);
784 /* Drive for loop analysis stage. */
785 extern loop_vec_info vect_analyze_loop (struct loop *);
786 /* Drive for loop transformation stage. */
787 extern void vect_transform_loop (loop_vec_info);
788 extern loop_vec_info vect_analyze_loop_form (struct loop *);
789 extern bool vectorizable_live_operation (gimple, gimple_stmt_iterator *,
790 gimple *);
791 extern bool vectorizable_reduction (gimple, gimple_stmt_iterator *, gimple *);
792 extern bool vectorizable_induction (gimple, gimple_stmt_iterator *, gimple *);
793 extern int vect_estimate_min_profitable_iters (loop_vec_info);
794 extern tree get_initial_def_for_reduction (gimple, tree, tree *);
795 extern int vect_min_worthwhile_factor (enum tree_code);
798 /* In tree-vect-slp.c. */
799 extern void vect_free_slp_instance (slp_instance);
800 extern bool vect_transform_slp_perm_load (gimple, VEC (tree, heap) *,
801 gimple_stmt_iterator *, int,
802 slp_instance, bool);
803 extern bool vect_schedule_slp (loop_vec_info);
804 extern void vect_update_slp_costs_according_to_vf (loop_vec_info);
805 extern bool vect_analyze_slp (loop_vec_info);
806 extern void vect_make_slp_decision (loop_vec_info);
807 extern void vect_detect_hybrid_slp (loop_vec_info);
808 extern void vect_get_slp_defs (slp_tree, VEC (tree,heap) **,
809 VEC (tree,heap) **);
811 /* In tree-vect-patterns.c. */
812 /* Pattern recognition functions.
813 Additional pattern recognition functions can (and will) be added
814 in the future. */
815 typedef gimple (* vect_recog_func_ptr) (gimple, tree *, tree *);
816 #define NUM_PATTERNS 4
817 void vect_pattern_recog (loop_vec_info);
819 /* Vectorization debug information - in tree-vectorizer.c. */
820 extern bool vect_print_dump_info (enum verbosity_levels);
821 extern void vect_set_verbosity_level (const char *);
823 #endif /* GCC_TREE_VECTORIZER_H */