tree-vectorizer.h (struct _slp_oprnd_info): Remove first_const_oprnd field, rename...
[gcc.git] / gcc / tree-vectorizer.h
1 /* Vectorizer
2 Copyright (C) 2003-2013 Free Software Foundation, Inc.
3 Contributed by Dorit Naishlos <dorit@il.ibm.com>
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
20
21 #ifndef GCC_TREE_VECTORIZER_H
22 #define GCC_TREE_VECTORIZER_H
23
24 #include "tree-data-ref.h"
25 #include "target.h"
26
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)
32
33 /* Used for naming of new temporaries. */
34 enum vect_var_kind {
35 vect_simple_var,
36 vect_pointer_var,
37 vect_scalar_var
38 };
39
40 /* Defines type of operation. */
41 enum operation_type {
42 unary_op = 1,
43 binary_op,
44 ternary_op
45 };
46
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
54 };
55
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
67 };
68
69 #define VECTORIZABLE_CYCLE_DEF(D) (((D) == vect_reduction_def) \
70 || ((D) == vect_double_reduction_def) \
71 || ((D) == vect_nested_cycle))
72
73 /* Structure to encapsulate information about a group of like
74 instructions to be presented to the target cost model. */
75 typedef struct _stmt_info_for_cost {
76 int count;
77 enum vect_cost_for_stmt kind;
78 gimple stmt;
79 int misalign;
80 } stmt_info_for_cost;
81
82
83 typedef vec<stmt_info_for_cost> stmt_vector_for_cost;
84
85 static inline void
86 add_stmt_info_to_vec (stmt_vector_for_cost *stmt_cost_vec, int count,
87 enum vect_cost_for_stmt kind, gimple stmt, int misalign)
88 {
89 stmt_info_for_cost si;
90 si.count = count;
91 si.kind = kind;
92 si.stmt = stmt;
93 si.misalign = misalign;
94 stmt_cost_vec->safe_push (si);
95 }
96
97 /************************************************************************
98 SLP
99 ************************************************************************/
100 typedef struct _slp_tree *slp_tree;
101
102 /* A computation tree of an SLP instance. Each node corresponds to a group of
103 stmts to be packed in a SIMD stmt. */
104 struct _slp_tree {
105 /* Nodes that contain def-stmts of this node statements operands. */
106 vec<slp_tree> children;
107 /* A group of scalar stmts to be vectorized together. */
108 vec<gimple> stmts;
109 /* Vectorized stmt/s. */
110 vec<gimple> vec_stmts;
111 /* Number of vector stmts that are created to replace the group of scalar
112 stmts. It is calculated during the transformation phase as the number of
113 scalar elements in one scalar iteration (GROUP_SIZE) multiplied by VF
114 divided by vector size. */
115 unsigned int vec_stmts_size;
116 };
117
118
119 /* SLP instance is a sequence of stmts in a loop that can be packed into
120 SIMD stmts. */
121 typedef struct _slp_instance {
122 /* The root of SLP tree. */
123 slp_tree root;
124
125 /* Size of groups of scalar stmts that will be replaced by SIMD stmt/s. */
126 unsigned int group_size;
127
128 /* The unrolling factor required to vectorized this SLP instance. */
129 unsigned int unrolling_factor;
130
131 /* Vectorization costs associated with SLP instance. */
132 stmt_vector_for_cost body_cost_vec;
133
134 /* Loads permutation relatively to the stores, NULL if there is no
135 permutation. */
136 vec<int> load_permutation;
137
138 /* The group of nodes that contain loads of this SLP instance. */
139 vec<slp_tree> loads;
140
141 /* The first scalar load of the instance. The created vector loads will be
142 inserted before this statement. */
143 gimple first_load;
144 } *slp_instance;
145
146
147 /* Access Functions. */
148 #define SLP_INSTANCE_TREE(S) (S)->root
149 #define SLP_INSTANCE_GROUP_SIZE(S) (S)->group_size
150 #define SLP_INSTANCE_UNROLLING_FACTOR(S) (S)->unrolling_factor
151 #define SLP_INSTANCE_BODY_COST_VEC(S) (S)->body_cost_vec
152 #define SLP_INSTANCE_LOAD_PERMUTATION(S) (S)->load_permutation
153 #define SLP_INSTANCE_LOADS(S) (S)->loads
154 #define SLP_INSTANCE_FIRST_LOAD_STMT(S) (S)->first_load
155
156 #define SLP_TREE_CHILDREN(S) (S)->children
157 #define SLP_TREE_SCALAR_STMTS(S) (S)->stmts
158 #define SLP_TREE_VEC_STMTS(S) (S)->vec_stmts
159 #define SLP_TREE_NUMBER_OF_VEC_STMTS(S) (S)->vec_stmts_size
160
161 /* This structure is used in creation of an SLP tree. Each instance
162 corresponds to the same operand in a group of scalar stmts in an SLP
163 node. */
164 typedef struct _slp_oprnd_info
165 {
166 /* Def-stmts for the operands. */
167 vec<gimple> def_stmts;
168 /* Information about the first statement, its vector def-type, type, the
169 operand itself in case it's constant, and an indication if it's a pattern
170 stmt. */
171 enum vect_def_type first_dt;
172 tree first_op_type;
173 bool first_pattern;
174 } *slp_oprnd_info;
175
176
177
178 typedef struct _vect_peel_info
179 {
180 int npeel;
181 struct data_reference *dr;
182 unsigned int count;
183 } *vect_peel_info;
184
185 typedef struct _vect_peel_extended_info
186 {
187 struct _vect_peel_info peel_info;
188 unsigned int inside_cost;
189 unsigned int outside_cost;
190 stmt_vector_for_cost body_cost_vec;
191 } *vect_peel_extended_info;
192
193 /*-----------------------------------------------------------------*/
194 /* Info on vectorized loops. */
195 /*-----------------------------------------------------------------*/
196 typedef struct _loop_vec_info {
197
198 /* The loop to which this info struct refers to. */
199 struct loop *loop;
200
201 /* The loop basic blocks. */
202 basic_block *bbs;
203
204 /* Number of iterations. */
205 tree num_iters;
206 tree num_iters_unchanged;
207
208 /* Minimum number of iterations below which vectorization is expected to
209 not be profitable (as estimated by the cost model).
210 -1 indicates that vectorization will not be profitable.
211 FORNOW: This field is an int. Will be a tree in the future, to represent
212 values unknown at compile time. */
213 int min_profitable_iters;
214
215 /* Is the loop vectorizable? */
216 bool vectorizable;
217
218 /* Unrolling factor */
219 int vectorization_factor;
220
221 /* The loop location in the source. */
222 LOC loop_line_number;
223
224 /* Unknown DRs according to which loop was peeled. */
225 struct data_reference *unaligned_dr;
226
227 /* peeling_for_alignment indicates whether peeling for alignment will take
228 place, and what the peeling factor should be:
229 peeling_for_alignment = X means:
230 If X=0: Peeling for alignment will not be applied.
231 If X>0: Peel first X iterations.
232 If X=-1: Generate a runtime test to calculate the number of iterations
233 to be peeled, using the dataref recorded in the field
234 unaligned_dr. */
235 int peeling_for_alignment;
236
237 /* The mask used to check the alignment of pointers or arrays. */
238 int ptr_mask;
239
240 /* The loop nest in which the data dependences are computed. */
241 vec<loop_p> loop_nest;
242
243 /* All data references in the loop. */
244 vec<data_reference_p> datarefs;
245
246 /* All data dependences in the loop. */
247 vec<ddr_p> ddrs;
248
249 /* Data Dependence Relations defining address ranges that are candidates
250 for a run-time aliasing check. */
251 vec<ddr_p> may_alias_ddrs;
252
253 /* Statements in the loop that have data references that are candidates for a
254 runtime (loop versioning) misalignment check. */
255 vec<gimple> may_misalign_stmts;
256
257 /* All interleaving chains of stores in the loop, represented by the first
258 stmt in the chain. */
259 vec<gimple> grouped_stores;
260
261 /* All SLP instances in the loop. This is a subset of the set of GROUP_STORES
262 of the loop. */
263 vec<slp_instance> slp_instances;
264
265 /* The unrolling factor needed to SLP the loop. In case of that pure SLP is
266 applied to the loop, i.e., no unrolling is needed, this is 1. */
267 unsigned slp_unrolling_factor;
268
269 /* Reduction cycles detected in the loop. Used in loop-aware SLP. */
270 vec<gimple> reductions;
271
272 /* All reduction chains in the loop, represented by the first
273 stmt in the chain. */
274 vec<gimple> reduction_chains;
275
276 /* Hash table used to choose the best peeling option. */
277 htab_t peeling_htab;
278
279 /* Cost data used by the target cost model. */
280 void *target_cost_data;
281
282 /* When we have grouped data accesses with gaps, we may introduce invalid
283 memory accesses. We peel the last iteration of the loop to prevent
284 this. */
285 bool peeling_for_gaps;
286
287 /* Reductions are canonicalized so that the last operand is the reduction
288 operand. If this places a constant into RHS1, this decanonicalizes
289 GIMPLE for other phases, so we must track when this has occurred and
290 fix it up. */
291 bool operands_swapped;
292
293 } *loop_vec_info;
294
295 /* Access Functions. */
296 #define LOOP_VINFO_LOOP(L) (L)->loop
297 #define LOOP_VINFO_BBS(L) (L)->bbs
298 #define LOOP_VINFO_NITERS(L) (L)->num_iters
299 /* Since LOOP_VINFO_NITERS can change after prologue peeling
300 retain total unchanged scalar loop iterations for cost model. */
301 #define LOOP_VINFO_NITERS_UNCHANGED(L) (L)->num_iters_unchanged
302 #define LOOP_VINFO_COST_MODEL_MIN_ITERS(L) (L)->min_profitable_iters
303 #define LOOP_VINFO_VECTORIZABLE_P(L) (L)->vectorizable
304 #define LOOP_VINFO_VECT_FACTOR(L) (L)->vectorization_factor
305 #define LOOP_VINFO_PTR_MASK(L) (L)->ptr_mask
306 #define LOOP_VINFO_LOOP_NEST(L) (L)->loop_nest
307 #define LOOP_VINFO_DATAREFS(L) (L)->datarefs
308 #define LOOP_VINFO_DDRS(L) (L)->ddrs
309 #define LOOP_VINFO_INT_NITERS(L) (TREE_INT_CST_LOW ((L)->num_iters))
310 #define LOOP_PEELING_FOR_ALIGNMENT(L) (L)->peeling_for_alignment
311 #define LOOP_VINFO_UNALIGNED_DR(L) (L)->unaligned_dr
312 #define LOOP_VINFO_MAY_MISALIGN_STMTS(L) (L)->may_misalign_stmts
313 #define LOOP_VINFO_LOC(L) (L)->loop_line_number
314 #define LOOP_VINFO_MAY_ALIAS_DDRS(L) (L)->may_alias_ddrs
315 #define LOOP_VINFO_GROUPED_STORES(L) (L)->grouped_stores
316 #define LOOP_VINFO_SLP_INSTANCES(L) (L)->slp_instances
317 #define LOOP_VINFO_SLP_UNROLLING_FACTOR(L) (L)->slp_unrolling_factor
318 #define LOOP_VINFO_REDUCTIONS(L) (L)->reductions
319 #define LOOP_VINFO_REDUCTION_CHAINS(L) (L)->reduction_chains
320 #define LOOP_VINFO_PEELING_HTAB(L) (L)->peeling_htab
321 #define LOOP_VINFO_TARGET_COST_DATA(L) (L)->target_cost_data
322 #define LOOP_VINFO_PEELING_FOR_GAPS(L) (L)->peeling_for_gaps
323 #define LOOP_VINFO_OPERANDS_SWAPPED(L) (L)->operands_swapped
324
325 #define LOOP_REQUIRES_VERSIONING_FOR_ALIGNMENT(L) \
326 (L)->may_misalign_stmts.length () > 0
327 #define LOOP_REQUIRES_VERSIONING_FOR_ALIAS(L) \
328 (L)->may_alias_ddrs.length () > 0
329
330 #define NITERS_KNOWN_P(n) \
331 (host_integerp ((n),0) \
332 && TREE_INT_CST_LOW ((n)) > 0)
333
334 #define LOOP_VINFO_NITERS_KNOWN_P(L) \
335 NITERS_KNOWN_P((L)->num_iters)
336
337 static inline loop_vec_info
338 loop_vec_info_for_loop (struct loop *loop)
339 {
340 return (loop_vec_info) loop->aux;
341 }
342
343 static inline bool
344 nested_in_vect_loop_p (struct loop *loop, gimple stmt)
345 {
346 return (loop->inner
347 && (loop->inner == (gimple_bb (stmt))->loop_father));
348 }
349
350 typedef struct _bb_vec_info {
351
352 basic_block bb;
353 /* All interleaving chains of stores in the basic block, represented by the
354 first stmt in the chain. */
355 vec<gimple> grouped_stores;
356
357 /* All SLP instances in the basic block. This is a subset of the set of
358 GROUP_STORES of the basic block. */
359 vec<slp_instance> slp_instances;
360
361 /* All data references in the basic block. */
362 vec<data_reference_p> datarefs;
363
364 /* All data dependences in the basic block. */
365 vec<ddr_p> ddrs;
366
367 /* Cost data used by the target cost model. */
368 void *target_cost_data;
369
370 } *bb_vec_info;
371
372 #define BB_VINFO_BB(B) (B)->bb
373 #define BB_VINFO_GROUPED_STORES(B) (B)->grouped_stores
374 #define BB_VINFO_SLP_INSTANCES(B) (B)->slp_instances
375 #define BB_VINFO_DATAREFS(B) (B)->datarefs
376 #define BB_VINFO_DDRS(B) (B)->ddrs
377 #define BB_VINFO_TARGET_COST_DATA(B) (B)->target_cost_data
378
379 static inline bb_vec_info
380 vec_info_for_bb (basic_block bb)
381 {
382 return (bb_vec_info) bb->aux;
383 }
384
385 /*-----------------------------------------------------------------*/
386 /* Info on vectorized defs. */
387 /*-----------------------------------------------------------------*/
388 enum stmt_vec_info_type {
389 undef_vec_info_type = 0,
390 load_vec_info_type,
391 store_vec_info_type,
392 shift_vec_info_type,
393 op_vec_info_type,
394 call_vec_info_type,
395 assignment_vec_info_type,
396 condition_vec_info_type,
397 reduc_vec_info_type,
398 induc_vec_info_type,
399 type_promotion_vec_info_type,
400 type_demotion_vec_info_type,
401 type_conversion_vec_info_type,
402 loop_exit_ctrl_vec_info_type
403 };
404
405 /* Indicates whether/how a variable is used in the scope of loop/basic
406 block. */
407 enum vect_relevant {
408 vect_unused_in_scope = 0,
409 /* The def is in the inner loop, and the use is in the outer loop, and the
410 use is a reduction stmt. */
411 vect_used_in_outer_by_reduction,
412 /* The def is in the inner loop, and the use is in the outer loop (and is
413 not part of reduction). */
414 vect_used_in_outer,
415
416 /* defs that feed computations that end up (only) in a reduction. These
417 defs may be used by non-reduction stmts, but eventually, any
418 computations/values that are affected by these defs are used to compute
419 a reduction (i.e. don't get stored to memory, for example). We use this
420 to identify computations that we can change the order in which they are
421 computed. */
422 vect_used_by_reduction,
423
424 vect_used_in_scope
425 };
426
427 /* The type of vectorization that can be applied to the stmt: regular loop-based
428 vectorization; pure SLP - the stmt is a part of SLP instances and does not
429 have uses outside SLP instances; or hybrid SLP and loop-based - the stmt is
430 a part of SLP instance and also must be loop-based vectorized, since it has
431 uses outside SLP sequences.
432
433 In the loop context the meanings of pure and hybrid SLP are slightly
434 different. By saying that pure SLP is applied to the loop, we mean that we
435 exploit only intra-iteration parallelism in the loop; i.e., the loop can be
436 vectorized without doing any conceptual unrolling, cause we don't pack
437 together stmts from different iterations, only within a single iteration.
438 Loop hybrid SLP means that we exploit both intra-iteration and
439 inter-iteration parallelism (e.g., number of elements in the vector is 4
440 and the slp-group-size is 2, in which case we don't have enough parallelism
441 within an iteration, so we obtain the rest of the parallelism from subsequent
442 iterations by unrolling the loop by 2). */
443 enum slp_vect_type {
444 loop_vect = 0,
445 pure_slp,
446 hybrid
447 };
448
449
450 typedef struct data_reference *dr_p;
451
452 typedef struct _stmt_vec_info {
453
454 enum stmt_vec_info_type type;
455
456 /* Indicates whether this stmts is part of a computation whose result is
457 used outside the loop. */
458 bool live;
459
460 /* Stmt is part of some pattern (computation idiom) */
461 bool in_pattern_p;
462
463 /* For loads only, if there is a store with the same location, this field is
464 TRUE. */
465 bool read_write_dep;
466
467 /* The stmt to which this info struct refers to. */
468 gimple stmt;
469
470 /* The loop_vec_info with respect to which STMT is vectorized. */
471 loop_vec_info loop_vinfo;
472
473 /* The vector type to be used for the LHS of this statement. */
474 tree vectype;
475
476 /* The vectorized version of the stmt. */
477 gimple vectorized_stmt;
478
479
480 /** The following is relevant only for stmts that contain a non-scalar
481 data-ref (array/pointer/struct access). A GIMPLE stmt is expected to have
482 at most one such data-ref. **/
483
484 /* Information about the data-ref (access function, etc),
485 relative to the inner-most containing loop. */
486 struct data_reference *data_ref_info;
487
488 /* Information about the data-ref relative to this loop
489 nest (the loop that is being considered for vectorization). */
490 tree dr_base_address;
491 tree dr_init;
492 tree dr_offset;
493 tree dr_step;
494 tree dr_aligned_to;
495
496 /* For loop PHI nodes, the evolution part of it. This makes sure
497 this information is still available in vect_update_ivs_after_vectorizer
498 where we may not be able to re-analyze the PHI nodes evolution as
499 peeling for the prologue loop can make it unanalyzable. The evolution
500 part is still correct though. */
501 tree loop_phi_evolution_part;
502
503 /* Used for various bookkeeping purposes, generally holding a pointer to
504 some other stmt S that is in some way "related" to this stmt.
505 Current use of this field is:
506 If this stmt is part of a pattern (i.e. the field 'in_pattern_p' is
507 true): S is the "pattern stmt" that represents (and replaces) the
508 sequence of stmts that constitutes the pattern. Similarly, the
509 related_stmt of the "pattern stmt" points back to this stmt (which is
510 the last stmt in the original sequence of stmts that constitutes the
511 pattern). */
512 gimple related_stmt;
513
514 /* Used to keep a sequence of def stmts of a pattern stmt if such exists. */
515 gimple_seq pattern_def_seq;
516
517 /* List of datarefs that are known to have the same alignment as the dataref
518 of this stmt. */
519 vec<dr_p> same_align_refs;
520
521 /* Classify the def of this stmt. */
522 enum vect_def_type def_type;
523
524 /* Whether the stmt is SLPed, loop-based vectorized, or both. */
525 enum slp_vect_type slp_type;
526
527 /* Interleaving and reduction chains info. */
528 /* First element in the group. */
529 gimple first_element;
530 /* Pointer to the next element in the group. */
531 gimple next_element;
532 /* For data-refs, in case that two or more stmts share data-ref, this is the
533 pointer to the previously detected stmt with the same dr. */
534 gimple same_dr_stmt;
535 /* The size of the group. */
536 unsigned int size;
537 /* For stores, number of stores from this group seen. We vectorize the last
538 one. */
539 unsigned int store_count;
540 /* For loads only, the gap from the previous load. For consecutive loads, GAP
541 is 1. */
542 unsigned int gap;
543
544 /* Not all stmts in the loop need to be vectorized. e.g, the increment
545 of the loop induction variable and computation of array indexes. relevant
546 indicates whether the stmt needs to be vectorized. */
547 enum vect_relevant relevant;
548
549 /* The bb_vec_info with respect to which STMT is vectorized. */
550 bb_vec_info bb_vinfo;
551
552 /* Is this statement vectorizable or should it be skipped in (partial)
553 vectorization. */
554 bool vectorizable;
555
556 /* For loads only, true if this is a gather load. */
557 bool gather_p;
558 bool stride_load_p;
559 } *stmt_vec_info;
560
561 /* Access Functions. */
562 #define STMT_VINFO_TYPE(S) (S)->type
563 #define STMT_VINFO_STMT(S) (S)->stmt
564 #define STMT_VINFO_LOOP_VINFO(S) (S)->loop_vinfo
565 #define STMT_VINFO_BB_VINFO(S) (S)->bb_vinfo
566 #define STMT_VINFO_RELEVANT(S) (S)->relevant
567 #define STMT_VINFO_LIVE_P(S) (S)->live
568 #define STMT_VINFO_VECTYPE(S) (S)->vectype
569 #define STMT_VINFO_VEC_STMT(S) (S)->vectorized_stmt
570 #define STMT_VINFO_VECTORIZABLE(S) (S)->vectorizable
571 #define STMT_VINFO_DATA_REF(S) (S)->data_ref_info
572 #define STMT_VINFO_GATHER_P(S) (S)->gather_p
573 #define STMT_VINFO_STRIDE_LOAD_P(S) (S)->stride_load_p
574
575 #define STMT_VINFO_DR_BASE_ADDRESS(S) (S)->dr_base_address
576 #define STMT_VINFO_DR_INIT(S) (S)->dr_init
577 #define STMT_VINFO_DR_OFFSET(S) (S)->dr_offset
578 #define STMT_VINFO_DR_STEP(S) (S)->dr_step
579 #define STMT_VINFO_DR_ALIGNED_TO(S) (S)->dr_aligned_to
580
581 #define STMT_VINFO_IN_PATTERN_P(S) (S)->in_pattern_p
582 #define STMT_VINFO_RELATED_STMT(S) (S)->related_stmt
583 #define STMT_VINFO_PATTERN_DEF_SEQ(S) (S)->pattern_def_seq
584 #define STMT_VINFO_SAME_ALIGN_REFS(S) (S)->same_align_refs
585 #define STMT_VINFO_DEF_TYPE(S) (S)->def_type
586 #define STMT_VINFO_GROUP_FIRST_ELEMENT(S) (S)->first_element
587 #define STMT_VINFO_GROUP_NEXT_ELEMENT(S) (S)->next_element
588 #define STMT_VINFO_GROUP_SIZE(S) (S)->size
589 #define STMT_VINFO_GROUP_STORE_COUNT(S) (S)->store_count
590 #define STMT_VINFO_GROUP_GAP(S) (S)->gap
591 #define STMT_VINFO_GROUP_SAME_DR_STMT(S) (S)->same_dr_stmt
592 #define STMT_VINFO_GROUP_READ_WRITE_DEPENDENCE(S) (S)->read_write_dep
593 #define STMT_VINFO_GROUPED_ACCESS(S) ((S)->first_element != NULL && (S)->data_ref_info)
594 #define STMT_VINFO_LOOP_PHI_EVOLUTION_PART(S) (S)->loop_phi_evolution_part
595
596 #define GROUP_FIRST_ELEMENT(S) (S)->first_element
597 #define GROUP_NEXT_ELEMENT(S) (S)->next_element
598 #define GROUP_SIZE(S) (S)->size
599 #define GROUP_STORE_COUNT(S) (S)->store_count
600 #define GROUP_GAP(S) (S)->gap
601 #define GROUP_SAME_DR_STMT(S) (S)->same_dr_stmt
602 #define GROUP_READ_WRITE_DEPENDENCE(S) (S)->read_write_dep
603
604 #define STMT_VINFO_RELEVANT_P(S) ((S)->relevant != vect_unused_in_scope)
605
606 #define HYBRID_SLP_STMT(S) ((S)->slp_type == hybrid)
607 #define PURE_SLP_STMT(S) ((S)->slp_type == pure_slp)
608 #define STMT_SLP_TYPE(S) (S)->slp_type
609
610 #define VECT_MAX_COST 1000
611
612 /* The maximum number of intermediate steps required in multi-step type
613 conversion. */
614 #define MAX_INTERM_CVT_STEPS 3
615
616 /* The maximum vectorization factor supported by any target (V32QI). */
617 #define MAX_VECTORIZATION_FACTOR 32
618
619 /* Avoid GTY(()) on stmt_vec_info. */
620 typedef void *vec_void_p;
621
622 extern vec<vec_void_p> stmt_vec_info_vec;
623
624 void init_stmt_vec_info_vec (void);
625 void free_stmt_vec_info_vec (void);
626
627 /* Return a stmt_vec_info corresponding to STMT. */
628
629 static inline stmt_vec_info
630 vinfo_for_stmt (gimple stmt)
631 {
632 unsigned int uid = gimple_uid (stmt);
633 if (uid == 0)
634 return NULL;
635
636 return (stmt_vec_info) stmt_vec_info_vec[uid - 1];
637 }
638
639 /* Set vectorizer information INFO for STMT. */
640
641 static inline void
642 set_vinfo_for_stmt (gimple stmt, stmt_vec_info info)
643 {
644 unsigned int uid = gimple_uid (stmt);
645 if (uid == 0)
646 {
647 gcc_checking_assert (info);
648 uid = stmt_vec_info_vec.length () + 1;
649 gimple_set_uid (stmt, uid);
650 stmt_vec_info_vec.safe_push ((vec_void_p) info);
651 }
652 else
653 stmt_vec_info_vec[uid - 1] = (vec_void_p) info;
654 }
655
656 /* Return the earlier statement between STMT1 and STMT2. */
657
658 static inline gimple
659 get_earlier_stmt (gimple stmt1, gimple stmt2)
660 {
661 unsigned int uid1, uid2;
662
663 if (stmt1 == NULL)
664 return stmt2;
665
666 if (stmt2 == NULL)
667 return stmt1;
668
669 uid1 = gimple_uid (stmt1);
670 uid2 = gimple_uid (stmt2);
671
672 if (uid1 == 0 || uid2 == 0)
673 return NULL;
674
675 gcc_checking_assert (uid1 <= stmt_vec_info_vec.length ()
676 && uid2 <= stmt_vec_info_vec.length ());
677
678 if (uid1 < uid2)
679 return stmt1;
680 else
681 return stmt2;
682 }
683
684 /* Return the later statement between STMT1 and STMT2. */
685
686 static inline gimple
687 get_later_stmt (gimple stmt1, gimple stmt2)
688 {
689 unsigned int uid1, uid2;
690
691 if (stmt1 == NULL)
692 return stmt2;
693
694 if (stmt2 == NULL)
695 return stmt1;
696
697 uid1 = gimple_uid (stmt1);
698 uid2 = gimple_uid (stmt2);
699
700 if (uid1 == 0 || uid2 == 0)
701 return NULL;
702
703 gcc_assert (uid1 <= stmt_vec_info_vec.length ());
704 gcc_assert (uid2 <= stmt_vec_info_vec.length ());
705
706 if (uid1 > uid2)
707 return stmt1;
708 else
709 return stmt2;
710 }
711
712 /* Return TRUE if a statement represented by STMT_INFO is a part of a
713 pattern. */
714
715 static inline bool
716 is_pattern_stmt_p (stmt_vec_info stmt_info)
717 {
718 gimple related_stmt;
719 stmt_vec_info related_stmt_info;
720
721 related_stmt = STMT_VINFO_RELATED_STMT (stmt_info);
722 if (related_stmt
723 && (related_stmt_info = vinfo_for_stmt (related_stmt))
724 && STMT_VINFO_IN_PATTERN_P (related_stmt_info))
725 return true;
726
727 return false;
728 }
729
730 /* Return true if BB is a loop header. */
731
732 static inline bool
733 is_loop_header_bb_p (basic_block bb)
734 {
735 if (bb == (bb->loop_father)->header)
736 return true;
737 gcc_checking_assert (EDGE_COUNT (bb->preds) == 1);
738 return false;
739 }
740
741 /* Return pow2 (X). */
742
743 static inline int
744 vect_pow2 (int x)
745 {
746 int i, res = 1;
747
748 for (i = 0; i < x; i++)
749 res *= 2;
750
751 return res;
752 }
753
754 /* Alias targetm.vectorize.builtin_vectorization_cost. */
755
756 static inline int
757 builtin_vectorization_cost (enum vect_cost_for_stmt type_of_cost,
758 tree vectype, int misalign)
759 {
760 return targetm.vectorize.builtin_vectorization_cost (type_of_cost,
761 vectype, misalign);
762 }
763
764 /* Get cost by calling cost target builtin. */
765
766 static inline
767 int vect_get_stmt_cost (enum vect_cost_for_stmt type_of_cost)
768 {
769 return builtin_vectorization_cost (type_of_cost, NULL, 0);
770 }
771
772 /* Alias targetm.vectorize.init_cost. */
773
774 static inline void *
775 init_cost (struct loop *loop_info)
776 {
777 return targetm.vectorize.init_cost (loop_info);
778 }
779
780 /* Alias targetm.vectorize.add_stmt_cost. */
781
782 static inline unsigned
783 add_stmt_cost (void *data, int count, enum vect_cost_for_stmt kind,
784 stmt_vec_info stmt_info, int misalign,
785 enum vect_cost_model_location where)
786 {
787 return targetm.vectorize.add_stmt_cost (data, count, kind,
788 stmt_info, misalign, where);
789 }
790
791 /* Alias targetm.vectorize.finish_cost. */
792
793 static inline void
794 finish_cost (void *data, unsigned *prologue_cost,
795 unsigned *body_cost, unsigned *epilogue_cost)
796 {
797 targetm.vectorize.finish_cost (data, prologue_cost, body_cost, epilogue_cost);
798 }
799
800 /* Alias targetm.vectorize.destroy_cost_data. */
801
802 static inline void
803 destroy_cost_data (void *data)
804 {
805 targetm.vectorize.destroy_cost_data (data);
806 }
807
808
809 /*-----------------------------------------------------------------*/
810 /* Info on data references alignment. */
811 /*-----------------------------------------------------------------*/
812
813 /* Reflects actual alignment of first access in the vectorized loop,
814 taking into account peeling/versioning if applied. */
815 #define DR_MISALIGNMENT(DR) ((int) (size_t) (DR)->aux)
816 #define SET_DR_MISALIGNMENT(DR, VAL) ((DR)->aux = (void *) (size_t) (VAL))
817
818 /* Return TRUE if the data access is aligned, and FALSE otherwise. */
819
820 static inline bool
821 aligned_access_p (struct data_reference *data_ref_info)
822 {
823 return (DR_MISALIGNMENT (data_ref_info) == 0);
824 }
825
826 /* Return TRUE if the alignment of the data access is known, and FALSE
827 otherwise. */
828
829 static inline bool
830 known_alignment_for_access_p (struct data_reference *data_ref_info)
831 {
832 return (DR_MISALIGNMENT (data_ref_info) != -1);
833 }
834
835 /* Source location */
836 extern LOC vect_location;
837
838 /*-----------------------------------------------------------------*/
839 /* Function prototypes. */
840 /*-----------------------------------------------------------------*/
841
842 /* Simple loop peeling and versioning utilities for vectorizer's purposes -
843 in tree-vect-loop-manip.c. */
844 extern void slpeel_make_loop_iterate_ntimes (struct loop *, tree);
845 extern bool slpeel_can_duplicate_loop_p (const struct loop *, const_edge);
846 extern void vect_loop_versioning (loop_vec_info, unsigned int, bool);
847 extern void vect_do_peeling_for_loop_bound (loop_vec_info, tree *,
848 unsigned int, bool);
849 extern void vect_do_peeling_for_alignment (loop_vec_info, unsigned int, bool);
850 extern LOC find_loop_location (struct loop *);
851 extern bool vect_can_advance_ivs_p (loop_vec_info);
852
853 /* In tree-vect-stmts.c. */
854 extern unsigned int current_vector_size;
855 extern tree get_vectype_for_scalar_type (tree);
856 extern tree get_same_sized_vectype (tree, tree);
857 extern bool vect_is_simple_use (tree, gimple, loop_vec_info,
858 bb_vec_info, gimple *,
859 tree *, enum vect_def_type *);
860 extern bool vect_is_simple_use_1 (tree, gimple, loop_vec_info,
861 bb_vec_info, gimple *,
862 tree *, enum vect_def_type *, tree *);
863 extern bool supportable_widening_operation (enum tree_code, gimple, tree, tree,
864 enum tree_code *, enum tree_code *,
865 int *, vec<tree> *);
866 extern bool supportable_narrowing_operation (enum tree_code, tree, tree,
867 enum tree_code *,
868 int *, vec<tree> *);
869 extern stmt_vec_info new_stmt_vec_info (gimple stmt, loop_vec_info,
870 bb_vec_info);
871 extern void free_stmt_vec_info (gimple stmt);
872 extern tree vectorizable_function (gimple, tree, tree);
873 extern void vect_model_simple_cost (stmt_vec_info, int, enum vect_def_type *,
874 stmt_vector_for_cost *,
875 stmt_vector_for_cost *);
876 extern void vect_model_store_cost (stmt_vec_info, int, bool,
877 enum vect_def_type, slp_tree,
878 stmt_vector_for_cost *,
879 stmt_vector_for_cost *);
880 extern void vect_model_load_cost (stmt_vec_info, int, bool, slp_tree,
881 stmt_vector_for_cost *,
882 stmt_vector_for_cost *);
883 extern unsigned record_stmt_cost (stmt_vector_for_cost *, int,
884 enum vect_cost_for_stmt, stmt_vec_info,
885 int, enum vect_cost_model_location);
886 extern void vect_finish_stmt_generation (gimple, gimple,
887 gimple_stmt_iterator *);
888 extern bool vect_mark_stmts_to_be_vectorized (loop_vec_info);
889 extern tree vect_get_vec_def_for_operand (tree, gimple, tree *);
890 extern tree vect_init_vector (gimple, tree, tree,
891 gimple_stmt_iterator *);
892 extern tree vect_get_vec_def_for_stmt_copy (enum vect_def_type, tree);
893 extern bool vect_transform_stmt (gimple, gimple_stmt_iterator *,
894 bool *, slp_tree, slp_instance);
895 extern void vect_remove_stores (gimple);
896 extern bool vect_analyze_stmt (gimple, bool *, slp_tree);
897 extern bool vectorizable_condition (gimple, gimple_stmt_iterator *, gimple *,
898 tree, int, slp_tree);
899 extern void vect_get_load_cost (struct data_reference *, int, bool,
900 unsigned int *, unsigned int *,
901 stmt_vector_for_cost *,
902 stmt_vector_for_cost *, bool);
903 extern void vect_get_store_cost (struct data_reference *, int,
904 unsigned int *, stmt_vector_for_cost *);
905 extern bool vect_supportable_shift (enum tree_code, tree);
906 extern void vect_get_vec_defs (tree, tree, gimple, vec<tree> *,
907 vec<tree> *, slp_tree, int);
908 extern tree vect_gen_perm_mask (tree, unsigned char *);
909
910 /* In tree-vect-data-refs.c. */
911 extern bool vect_can_force_dr_alignment_p (const_tree, unsigned int);
912 extern enum dr_alignment_support vect_supportable_dr_alignment
913 (struct data_reference *, bool);
914 extern tree vect_get_smallest_scalar_type (gimple, HOST_WIDE_INT *,
915 HOST_WIDE_INT *);
916 extern bool vect_analyze_data_ref_dependences (loop_vec_info, int *);
917 extern bool vect_slp_analyze_data_ref_dependences (bb_vec_info);
918 extern bool vect_enhance_data_refs_alignment (loop_vec_info);
919 extern bool vect_analyze_data_refs_alignment (loop_vec_info, bb_vec_info);
920 extern bool vect_verify_datarefs_alignment (loop_vec_info, bb_vec_info);
921 extern bool vect_analyze_data_ref_accesses (loop_vec_info, bb_vec_info);
922 extern bool vect_prune_runtime_alias_test_list (loop_vec_info);
923 extern tree vect_check_gather (gimple, loop_vec_info, tree *, tree *,
924 int *);
925 extern bool vect_analyze_data_refs (loop_vec_info, bb_vec_info, int *);
926 extern tree vect_create_data_ref_ptr (gimple, tree, struct loop *, tree,
927 tree *, gimple_stmt_iterator *,
928 gimple *, bool, bool *);
929 extern tree bump_vector_ptr (tree, gimple, gimple_stmt_iterator *, gimple, tree);
930 extern tree vect_create_destination_var (tree, tree);
931 extern bool vect_grouped_store_supported (tree, unsigned HOST_WIDE_INT);
932 extern bool vect_store_lanes_supported (tree, unsigned HOST_WIDE_INT);
933 extern bool vect_grouped_load_supported (tree, unsigned HOST_WIDE_INT);
934 extern bool vect_load_lanes_supported (tree, unsigned HOST_WIDE_INT);
935 extern void vect_permute_store_chain (vec<tree> ,unsigned int, gimple,
936 gimple_stmt_iterator *, vec<tree> *);
937 extern tree vect_setup_realignment (gimple, gimple_stmt_iterator *, tree *,
938 enum dr_alignment_support, tree,
939 struct loop **);
940 extern void vect_transform_grouped_load (gimple, vec<tree> , int,
941 gimple_stmt_iterator *);
942 extern void vect_record_grouped_load_vectors (gimple, vec<tree> );
943 extern tree vect_get_new_vect_var (tree, enum vect_var_kind, const char *);
944 extern tree vect_create_addr_base_for_vector_ref (gimple, gimple_seq *,
945 tree, struct loop *);
946
947 /* In tree-vect-loop.c. */
948 /* FORNOW: Used in tree-parloops.c. */
949 extern void destroy_loop_vec_info (loop_vec_info, bool);
950 extern gimple vect_force_simple_reduction (loop_vec_info, gimple, bool, bool *);
951 /* Drive for loop analysis stage. */
952 extern loop_vec_info vect_analyze_loop (struct loop *);
953 /* Drive for loop transformation stage. */
954 extern void vect_transform_loop (loop_vec_info);
955 extern loop_vec_info vect_analyze_loop_form (struct loop *);
956 extern bool vectorizable_live_operation (gimple, gimple_stmt_iterator *,
957 gimple *);
958 extern bool vectorizable_reduction (gimple, gimple_stmt_iterator *, gimple *,
959 slp_tree);
960 extern bool vectorizable_induction (gimple, gimple_stmt_iterator *, gimple *);
961 extern tree get_initial_def_for_reduction (gimple, tree, tree *);
962 extern int vect_min_worthwhile_factor (enum tree_code);
963 extern int vect_get_known_peeling_cost (loop_vec_info, int, int *, int,
964 stmt_vector_for_cost *,
965 stmt_vector_for_cost *);
966 extern int vect_get_single_scalar_iteration_cost (loop_vec_info);
967
968 /* In tree-vect-slp.c. */
969 extern void vect_free_slp_instance (slp_instance);
970 extern bool vect_transform_slp_perm_load (gimple, vec<tree> ,
971 gimple_stmt_iterator *, int,
972 slp_instance, bool);
973 extern bool vect_schedule_slp (loop_vec_info, bb_vec_info);
974 extern void vect_update_slp_costs_according_to_vf (loop_vec_info);
975 extern bool vect_analyze_slp (loop_vec_info, bb_vec_info);
976 extern bool vect_make_slp_decision (loop_vec_info);
977 extern void vect_detect_hybrid_slp (loop_vec_info);
978 extern void vect_get_slp_defs (vec<tree> , slp_tree,
979 vec<vec<tree> > *, int);
980
981 extern LOC find_bb_location (basic_block);
982 extern bb_vec_info vect_slp_analyze_bb (basic_block);
983 extern void vect_slp_transform_bb (basic_block);
984
985 /* In tree-vect-patterns.c. */
986 /* Pattern recognition functions.
987 Additional pattern recognition functions can (and will) be added
988 in the future. */
989 typedef gimple (* vect_recog_func_ptr) (vec<gimple> *, tree *, tree *);
990 #define NUM_PATTERNS 10
991 void vect_pattern_recog (loop_vec_info, bb_vec_info);
992
993 /* In tree-vectorizer.c. */
994 unsigned vectorize_loops (void);
995
996 #endif /* GCC_TREE_VECTORIZER_H */