]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/tree-vectorizer.h
[Ada] Avoid "others => <>" association in resolved record aggregates
[thirdparty/gcc.git] / gcc / tree-vectorizer.h
1 /* Vectorizer
2 Copyright (C) 2003-2020 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 typedef class _stmt_vec_info *stmt_vec_info;
25
26 #include "tree-data-ref.h"
27 #include "tree-hash-traits.h"
28 #include "target.h"
29 #include <utility>
30
31 /* Used for naming of new temporaries. */
32 enum vect_var_kind {
33 vect_simple_var,
34 vect_pointer_var,
35 vect_scalar_var,
36 vect_mask_var
37 };
38
39 /* Defines type of operation. */
40 enum operation_type {
41 unary_op = 1,
42 binary_op,
43 ternary_op
44 };
45
46 /* Define type of available alignment support. */
47 enum dr_alignment_support {
48 dr_unaligned_unsupported,
49 dr_unaligned_supported,
50 dr_explicit_realign,
51 dr_explicit_realign_optimized,
52 dr_aligned
53 };
54
55 /* Define type of def-use cross-iteration cycle. */
56 enum vect_def_type {
57 vect_uninitialized_def = 0,
58 vect_constant_def = 1,
59 vect_external_def,
60 vect_internal_def,
61 vect_induction_def,
62 vect_reduction_def,
63 vect_double_reduction_def,
64 vect_nested_cycle,
65 vect_unknown_def_type
66 };
67
68 /* Define type of reduction. */
69 enum vect_reduction_type {
70 TREE_CODE_REDUCTION,
71 COND_REDUCTION,
72 INTEGER_INDUC_COND_REDUCTION,
73 CONST_COND_REDUCTION,
74
75 /* Retain a scalar phi and use a FOLD_EXTRACT_LAST within the loop
76 to implement:
77
78 for (int i = 0; i < VF; ++i)
79 res = cond[i] ? val[i] : res; */
80 EXTRACT_LAST_REDUCTION,
81
82 /* Use a folding reduction within the loop to implement:
83
84 for (int i = 0; i < VF; ++i)
85 res = res OP val[i];
86
87 (with no reassocation). */
88 FOLD_LEFT_REDUCTION
89 };
90
91 #define VECTORIZABLE_CYCLE_DEF(D) (((D) == vect_reduction_def) \
92 || ((D) == vect_double_reduction_def) \
93 || ((D) == vect_nested_cycle))
94
95 /* Structure to encapsulate information about a group of like
96 instructions to be presented to the target cost model. */
97 struct stmt_info_for_cost {
98 int count;
99 enum vect_cost_for_stmt kind;
100 enum vect_cost_model_location where;
101 stmt_vec_info stmt_info;
102 tree vectype;
103 int misalign;
104 };
105
106 typedef vec<stmt_info_for_cost> stmt_vector_for_cost;
107
108 /* Maps base addresses to an innermost_loop_behavior that gives the maximum
109 known alignment for that base. */
110 typedef hash_map<tree_operand_hash,
111 innermost_loop_behavior *> vec_base_alignments;
112
113 /************************************************************************
114 SLP
115 ************************************************************************/
116 typedef struct _slp_tree *slp_tree;
117
118 /* A computation tree of an SLP instance. Each node corresponds to a group of
119 stmts to be packed in a SIMD stmt. */
120 struct _slp_tree {
121 _slp_tree ();
122 ~_slp_tree ();
123
124 /* Nodes that contain def-stmts of this node statements operands. */
125 vec<slp_tree> children;
126
127 /* A group of scalar stmts to be vectorized together. */
128 vec<stmt_vec_info> stmts;
129 /* A group of scalar operands to be vectorized together. */
130 vec<tree> ops;
131 /* The representative that should be used for analysis and
132 code generation. */
133 stmt_vec_info representative;
134
135 /* Load permutation relative to the stores, NULL if there is no
136 permutation. */
137 vec<unsigned> load_permutation;
138
139 tree vectype;
140 /* Vectorized stmt/s. */
141 vec<gimple *> vec_stmts;
142 vec<tree> vec_defs;
143 /* Number of vector stmts that are created to replace the group of scalar
144 stmts. It is calculated during the transformation phase as the number of
145 scalar elements in one scalar iteration (GROUP_SIZE) multiplied by VF
146 divided by vector size. */
147 unsigned int vec_stmts_size;
148
149 /* Reference count in the SLP graph. */
150 unsigned int refcnt;
151 /* The maximum number of vector elements for the subtree rooted
152 at this node. */
153 poly_uint64 max_nunits;
154 /* Whether the scalar computations use two different operators. */
155 bool two_operators;
156 /* The DEF type of this node. */
157 enum vect_def_type def_type;
158 /* The number of scalar lanes produced by this node. */
159 unsigned int lanes;
160 };
161
162
163 /* SLP instance is a sequence of stmts in a loop that can be packed into
164 SIMD stmts. */
165 typedef class _slp_instance {
166 public:
167 /* The root of SLP tree. */
168 slp_tree root;
169
170 /* For vector constructors, the constructor stmt that the SLP tree is built
171 from, NULL otherwise. */
172 stmt_vec_info root_stmt;
173
174 /* The unrolling factor required to vectorized this SLP instance. */
175 poly_uint64 unrolling_factor;
176
177 /* The group of nodes that contain loads of this SLP instance. */
178 vec<slp_tree> loads;
179
180 /* The SLP node containing the reduction PHIs. */
181 slp_tree reduc_phis;
182 } *slp_instance;
183
184
185 /* Access Functions. */
186 #define SLP_INSTANCE_TREE(S) (S)->root
187 #define SLP_INSTANCE_UNROLLING_FACTOR(S) (S)->unrolling_factor
188 #define SLP_INSTANCE_LOADS(S) (S)->loads
189 #define SLP_INSTANCE_ROOT_STMT(S) (S)->root_stmt
190
191 #define SLP_TREE_CHILDREN(S) (S)->children
192 #define SLP_TREE_SCALAR_STMTS(S) (S)->stmts
193 #define SLP_TREE_SCALAR_OPS(S) (S)->ops
194 #define SLP_TREE_VEC_STMTS(S) (S)->vec_stmts
195 #define SLP_TREE_VEC_DEFS(S) (S)->vec_defs
196 #define SLP_TREE_NUMBER_OF_VEC_STMTS(S) (S)->vec_stmts_size
197 #define SLP_TREE_LOAD_PERMUTATION(S) (S)->load_permutation
198 #define SLP_TREE_TWO_OPERATORS(S) (S)->two_operators
199 #define SLP_TREE_DEF_TYPE(S) (S)->def_type
200 #define SLP_TREE_VECTYPE(S) (S)->vectype
201 #define SLP_TREE_REPRESENTATIVE(S) (S)->representative
202 #define SLP_TREE_LANES(S) (S)->lanes
203
204 /* Key for map that records association between
205 scalar conditions and corresponding loop mask, and
206 is populated by vect_record_loop_mask. */
207
208 struct scalar_cond_masked_key
209 {
210 scalar_cond_masked_key (tree t, unsigned ncopies_)
211 : ncopies (ncopies_)
212 {
213 get_cond_ops_from_tree (t);
214 }
215
216 void get_cond_ops_from_tree (tree);
217
218 unsigned ncopies;
219 tree_code code;
220 tree op0;
221 tree op1;
222 };
223
224 template<>
225 struct default_hash_traits<scalar_cond_masked_key>
226 {
227 typedef scalar_cond_masked_key compare_type;
228 typedef scalar_cond_masked_key value_type;
229
230 static inline hashval_t
231 hash (value_type v)
232 {
233 inchash::hash h;
234 h.add_int (v.code);
235 inchash::add_expr (v.op0, h, 0);
236 inchash::add_expr (v.op1, h, 0);
237 h.add_int (v.ncopies);
238 return h.end ();
239 }
240
241 static inline bool
242 equal (value_type existing, value_type candidate)
243 {
244 return (existing.ncopies == candidate.ncopies
245 && existing.code == candidate.code
246 && operand_equal_p (existing.op0, candidate.op0, 0)
247 && operand_equal_p (existing.op1, candidate.op1, 0));
248 }
249
250 static const bool empty_zero_p = true;
251
252 static inline void
253 mark_empty (value_type &v)
254 {
255 v.ncopies = 0;
256 }
257
258 static inline bool
259 is_empty (value_type v)
260 {
261 return v.ncopies == 0;
262 }
263
264 static inline void mark_deleted (value_type &) {}
265
266 static inline bool is_deleted (const value_type &)
267 {
268 return false;
269 }
270
271 static inline void remove (value_type &) {}
272 };
273
274 typedef hash_set<scalar_cond_masked_key> scalar_cond_masked_set_type;
275
276 /* Describes two objects whose addresses must be unequal for the vectorized
277 loop to be valid. */
278 typedef std::pair<tree, tree> vec_object_pair;
279
280 /* Records that vectorization is only possible if abs (EXPR) >= MIN_VALUE.
281 UNSIGNED_P is true if we can assume that abs (EXPR) == EXPR. */
282 class vec_lower_bound {
283 public:
284 vec_lower_bound () {}
285 vec_lower_bound (tree e, bool u, poly_uint64 m)
286 : expr (e), unsigned_p (u), min_value (m) {}
287
288 tree expr;
289 bool unsigned_p;
290 poly_uint64 min_value;
291 };
292
293 /* Vectorizer state shared between different analyses like vector sizes
294 of the same CFG region. */
295 class vec_info_shared {
296 public:
297 vec_info_shared();
298 ~vec_info_shared();
299
300 void save_datarefs();
301 void check_datarefs();
302
303 /* All data references. Freed by free_data_refs, so not an auto_vec. */
304 vec<data_reference_p> datarefs;
305 vec<data_reference> datarefs_copy;
306
307 /* The loop nest in which the data dependences are computed. */
308 auto_vec<loop_p> loop_nest;
309
310 /* All data dependences. Freed by free_dependence_relations, so not
311 an auto_vec. */
312 vec<ddr_p> ddrs;
313 };
314
315 /* Vectorizer state common between loop and basic-block vectorization. */
316 class vec_info {
317 public:
318 typedef hash_set<int_hash<machine_mode, E_VOIDmode, E_BLKmode> > mode_set;
319 enum vec_kind { bb, loop };
320
321 vec_info (vec_kind, void *, vec_info_shared *);
322 ~vec_info ();
323
324 stmt_vec_info add_stmt (gimple *);
325 stmt_vec_info lookup_stmt (gimple *);
326 stmt_vec_info lookup_def (tree);
327 stmt_vec_info lookup_single_use (tree);
328 class dr_vec_info *lookup_dr (data_reference *);
329 void move_dr (stmt_vec_info, stmt_vec_info);
330 void remove_stmt (stmt_vec_info);
331 void replace_stmt (gimple_stmt_iterator *, stmt_vec_info, gimple *);
332
333 /* The type of vectorization. */
334 vec_kind kind;
335
336 /* Shared vectorizer state. */
337 vec_info_shared *shared;
338
339 /* The mapping of GIMPLE UID to stmt_vec_info. */
340 vec<stmt_vec_info> stmt_vec_infos;
341 /* Whether the above mapping is complete. */
342 bool stmt_vec_info_ro;
343
344 /* The SLP graph. */
345 auto_vec<slp_instance> slp_instances;
346 auto_vec<slp_tree> slp_loads;
347
348 /* Maps base addresses to an innermost_loop_behavior that gives the maximum
349 known alignment for that base. */
350 vec_base_alignments base_alignments;
351
352 /* All interleaving chains of stores, represented by the first
353 stmt in the chain. */
354 auto_vec<stmt_vec_info> grouped_stores;
355
356 /* Cost data used by the target cost model. */
357 void *target_cost_data;
358
359 /* The set of vector modes used in the vectorized region. */
360 mode_set used_vector_modes;
361
362 /* The argument we should pass to related_vector_mode when looking up
363 the vector mode for a scalar mode, or VOIDmode if we haven't yet
364 made any decisions about which vector modes to use. */
365 machine_mode vector_mode;
366
367 private:
368 stmt_vec_info new_stmt_vec_info (gimple *stmt);
369 void set_vinfo_for_stmt (gimple *, stmt_vec_info);
370 void free_stmt_vec_infos ();
371 void free_stmt_vec_info (stmt_vec_info);
372 };
373
374 class _loop_vec_info;
375 class _bb_vec_info;
376
377 template<>
378 template<>
379 inline bool
380 is_a_helper <_loop_vec_info *>::test (vec_info *i)
381 {
382 return i->kind == vec_info::loop;
383 }
384
385 template<>
386 template<>
387 inline bool
388 is_a_helper <_bb_vec_info *>::test (vec_info *i)
389 {
390 return i->kind == vec_info::bb;
391 }
392
393 /* In general, we can divide the vector statements in a vectorized loop
394 into related groups ("rgroups") and say that for each rgroup there is
395 some nS such that the rgroup operates on nS values from one scalar
396 iteration followed by nS values from the next. That is, if VF is the
397 vectorization factor of the loop, the rgroup operates on a sequence:
398
399 (1,1) (1,2) ... (1,nS) (2,1) ... (2,nS) ... (VF,1) ... (VF,nS)
400
401 where (i,j) represents a scalar value with index j in a scalar
402 iteration with index i.
403
404 [ We use the term "rgroup" to emphasise that this grouping isn't
405 necessarily the same as the grouping of statements used elsewhere.
406 For example, if we implement a group of scalar loads using gather
407 loads, we'll use a separate gather load for each scalar load, and
408 thus each gather load will belong to its own rgroup. ]
409
410 In general this sequence will occupy nV vectors concatenated
411 together. If these vectors have nL lanes each, the total number
412 of scalar values N is given by:
413
414 N = nS * VF = nV * nL
415
416 None of nS, VF, nV and nL are required to be a power of 2. nS and nV
417 are compile-time constants but VF and nL can be variable (if the target
418 supports variable-length vectors).
419
420 In classical vectorization, each iteration of the vector loop would
421 handle exactly VF iterations of the original scalar loop. However,
422 in vector loops that are able to operate on partial vectors, a
423 particular iteration of the vector loop might handle fewer than VF
424 iterations of the scalar loop. The vector lanes that correspond to
425 iterations of the scalar loop are said to be "active" and the other
426 lanes are said to be "inactive".
427
428 In such vector loops, many rgroups need to be controlled to ensure
429 that they have no effect for the inactive lanes. Conceptually, each
430 such rgroup needs a sequence of booleans in the same order as above,
431 but with each (i,j) replaced by a boolean that indicates whether
432 iteration i is active. This sequence occupies nV vector controls
433 that again have nL lanes each. Thus the control sequence as a whole
434 consists of VF independent booleans that are each repeated nS times.
435
436 Taking mask-based approach as a partially-populated vectors example.
437 We make the simplifying assumption that if a sequence of nV masks is
438 suitable for one (nS,nL) pair, we can reuse it for (nS/2,nL/2) by
439 VIEW_CONVERTing it. This holds for all current targets that support
440 fully-masked loops. For example, suppose the scalar loop is:
441
442 float *f;
443 double *d;
444 for (int i = 0; i < n; ++i)
445 {
446 f[i * 2 + 0] += 1.0f;
447 f[i * 2 + 1] += 2.0f;
448 d[i] += 3.0;
449 }
450
451 and suppose that vectors have 256 bits. The vectorized f accesses
452 will belong to one rgroup and the vectorized d access to another:
453
454 f rgroup: nS = 2, nV = 1, nL = 8
455 d rgroup: nS = 1, nV = 1, nL = 4
456 VF = 4
457
458 [ In this simple example the rgroups do correspond to the normal
459 SLP grouping scheme. ]
460
461 If only the first three lanes are active, the masks we need are:
462
463 f rgroup: 1 1 | 1 1 | 1 1 | 0 0
464 d rgroup: 1 | 1 | 1 | 0
465
466 Here we can use a mask calculated for f's rgroup for d's, but not
467 vice versa.
468
469 Thus for each value of nV, it is enough to provide nV masks, with the
470 mask being calculated based on the highest nL (or, equivalently, based
471 on the highest nS) required by any rgroup with that nV. We therefore
472 represent the entire collection of masks as a two-level table, with the
473 first level being indexed by nV - 1 (since nV == 0 doesn't exist) and
474 the second being indexed by the mask index 0 <= i < nV. */
475
476 /* The controls (like masks) needed by rgroups with nV vectors,
477 according to the description above. */
478 struct rgroup_controls {
479 /* The largest nS for all rgroups that use these controls. */
480 unsigned int max_nscalars_per_iter;
481
482 /* The type of control to use, based on the highest nS recorded above.
483 For mask-based approach, it's used for mask_type. */
484 tree type;
485
486 /* A vector of nV controls, in iteration order. */
487 vec<tree> controls;
488 };
489
490 typedef auto_vec<rgroup_controls> vec_loop_masks;
491
492 typedef auto_vec<std::pair<data_reference*, tree> > drs_init_vec;
493
494 /*-----------------------------------------------------------------*/
495 /* Info on vectorized loops. */
496 /*-----------------------------------------------------------------*/
497 typedef class _loop_vec_info : public vec_info {
498 public:
499 _loop_vec_info (class loop *, vec_info_shared *);
500 ~_loop_vec_info ();
501
502 /* The loop to which this info struct refers to. */
503 class loop *loop;
504
505 /* The loop basic blocks. */
506 basic_block *bbs;
507
508 /* Number of latch executions. */
509 tree num_itersm1;
510 /* Number of iterations. */
511 tree num_iters;
512 /* Number of iterations of the original loop. */
513 tree num_iters_unchanged;
514 /* Condition under which this loop is analyzed and versioned. */
515 tree num_iters_assumptions;
516
517 /* Threshold of number of iterations below which vectorization will not be
518 performed. It is calculated from MIN_PROFITABLE_ITERS and
519 param_min_vect_loop_bound. */
520 unsigned int th;
521
522 /* When applying loop versioning, the vector form should only be used
523 if the number of scalar iterations is >= this value, on top of all
524 the other requirements. Ignored when loop versioning is not being
525 used. */
526 poly_uint64 versioning_threshold;
527
528 /* Unrolling factor */
529 poly_uint64 vectorization_factor;
530
531 /* Maximum runtime vectorization factor, or MAX_VECTORIZATION_FACTOR
532 if there is no particular limit. */
533 unsigned HOST_WIDE_INT max_vectorization_factor;
534
535 /* The masks that a fully-masked loop should use to avoid operating
536 on inactive scalars. */
537 vec_loop_masks masks;
538
539 /* Set of scalar conditions that have loop mask applied. */
540 scalar_cond_masked_set_type scalar_cond_masked_set;
541
542 /* If we are using a loop mask to align memory addresses, this variable
543 contains the number of vector elements that we should skip in the
544 first iteration of the vector loop (i.e. the number of leading
545 elements that should be false in the first mask). */
546 tree mask_skip_niters;
547
548 /* Type of the variables to use in the WHILE_ULT call for fully-masked
549 loops. */
550 tree mask_compare_type;
551
552 /* For #pragma omp simd if (x) loops the x expression. If constant 0,
553 the loop should not be vectorized, if constant non-zero, simd_if_cond
554 shouldn't be set and loop vectorized normally, if SSA_NAME, the loop
555 should be versioned on that condition, using scalar loop if the condition
556 is false and vectorized loop otherwise. */
557 tree simd_if_cond;
558
559 /* Type of the IV to use in the WHILE_ULT call for fully-masked
560 loops. */
561 tree iv_type;
562
563 /* Unknown DRs according to which loop was peeled. */
564 class dr_vec_info *unaligned_dr;
565
566 /* peeling_for_alignment indicates whether peeling for alignment will take
567 place, and what the peeling factor should be:
568 peeling_for_alignment = X means:
569 If X=0: Peeling for alignment will not be applied.
570 If X>0: Peel first X iterations.
571 If X=-1: Generate a runtime test to calculate the number of iterations
572 to be peeled, using the dataref recorded in the field
573 unaligned_dr. */
574 int peeling_for_alignment;
575
576 /* The mask used to check the alignment of pointers or arrays. */
577 int ptr_mask;
578
579 /* Data Dependence Relations defining address ranges that are candidates
580 for a run-time aliasing check. */
581 auto_vec<ddr_p> may_alias_ddrs;
582
583 /* Data Dependence Relations defining address ranges together with segment
584 lengths from which the run-time aliasing check is built. */
585 auto_vec<dr_with_seg_len_pair_t> comp_alias_ddrs;
586
587 /* Check that the addresses of each pair of objects is unequal. */
588 auto_vec<vec_object_pair> check_unequal_addrs;
589
590 /* List of values that are required to be nonzero. This is used to check
591 whether things like "x[i * n] += 1;" are safe and eventually gets added
592 to the checks for lower bounds below. */
593 auto_vec<tree> check_nonzero;
594
595 /* List of values that need to be checked for a minimum value. */
596 auto_vec<vec_lower_bound> lower_bounds;
597
598 /* Statements in the loop that have data references that are candidates for a
599 runtime (loop versioning) misalignment check. */
600 auto_vec<stmt_vec_info> may_misalign_stmts;
601
602 /* Reduction cycles detected in the loop. Used in loop-aware SLP. */
603 auto_vec<stmt_vec_info> reductions;
604
605 /* All reduction chains in the loop, represented by the first
606 stmt in the chain. */
607 auto_vec<stmt_vec_info> reduction_chains;
608
609 /* Cost vector for a single scalar iteration. */
610 auto_vec<stmt_info_for_cost> scalar_cost_vec;
611
612 /* Map of IV base/step expressions to inserted name in the preheader. */
613 hash_map<tree_operand_hash, tree> *ivexpr_map;
614
615 /* Map of OpenMP "omp simd array" scan variables to corresponding
616 rhs of the store of the initializer. */
617 hash_map<tree, tree> *scan_map;
618
619 /* The unrolling factor needed to SLP the loop. In case of that pure SLP is
620 applied to the loop, i.e., no unrolling is needed, this is 1. */
621 poly_uint64 slp_unrolling_factor;
622
623 /* Cost of a single scalar iteration. */
624 int single_scalar_iteration_cost;
625
626 /* The cost of the vector prologue and epilogue, including peeled
627 iterations and set-up code. */
628 int vec_outside_cost;
629
630 /* The cost of the vector loop body. */
631 int vec_inside_cost;
632
633 /* Is the loop vectorizable? */
634 bool vectorizable;
635
636 /* Records whether we still have the option of vectorizing this loop
637 using partially-populated vectors; in other words, whether it is
638 still possible for one iteration of the vector loop to handle
639 fewer than VF scalars. */
640 bool can_use_partial_vectors_p;
641
642 /* True if we've decided to use partially-populated vectors, so that
643 the vector loop can handle fewer than VF scalars. */
644 bool using_partial_vectors_p;
645
646 /* When we have grouped data accesses with gaps, we may introduce invalid
647 memory accesses. We peel the last iteration of the loop to prevent
648 this. */
649 bool peeling_for_gaps;
650
651 /* When the number of iterations is not a multiple of the vector size
652 we need to peel off iterations at the end to form an epilogue loop. */
653 bool peeling_for_niter;
654
655 /* True if there are no loop carried data dependencies in the loop.
656 If loop->safelen <= 1, then this is always true, either the loop
657 didn't have any loop carried data dependencies, or the loop is being
658 vectorized guarded with some runtime alias checks, or couldn't
659 be vectorized at all, but then this field shouldn't be used.
660 For loop->safelen >= 2, the user has asserted that there are no
661 backward dependencies, but there still could be loop carried forward
662 dependencies in such loops. This flag will be false if normal
663 vectorizer data dependency analysis would fail or require versioning
664 for alias, but because of loop->safelen >= 2 it has been vectorized
665 even without versioning for alias. E.g. in:
666 #pragma omp simd
667 for (int i = 0; i < m; i++)
668 a[i] = a[i + k] * c;
669 (or #pragma simd or #pragma ivdep) we can vectorize this and it will
670 DTRT even for k > 0 && k < m, but without safelen we would not
671 vectorize this, so this field would be false. */
672 bool no_data_dependencies;
673
674 /* Mark loops having masked stores. */
675 bool has_mask_store;
676
677 /* Queued scaling factor for the scalar loop. */
678 profile_probability scalar_loop_scaling;
679
680 /* If if-conversion versioned this loop before conversion, this is the
681 loop version without if-conversion. */
682 class loop *scalar_loop;
683
684 /* For loops being epilogues of already vectorized loops
685 this points to the original vectorized loop. Otherwise NULL. */
686 _loop_vec_info *orig_loop_info;
687
688 /* Used to store loop_vec_infos of epilogues of this loop during
689 analysis. */
690 vec<_loop_vec_info *> epilogue_vinfos;
691
692 } *loop_vec_info;
693
694 /* Access Functions. */
695 #define LOOP_VINFO_LOOP(L) (L)->loop
696 #define LOOP_VINFO_BBS(L) (L)->bbs
697 #define LOOP_VINFO_NITERSM1(L) (L)->num_itersm1
698 #define LOOP_VINFO_NITERS(L) (L)->num_iters
699 /* Since LOOP_VINFO_NITERS and LOOP_VINFO_NITERSM1 can change after
700 prologue peeling retain total unchanged scalar loop iterations for
701 cost model. */
702 #define LOOP_VINFO_NITERS_UNCHANGED(L) (L)->num_iters_unchanged
703 #define LOOP_VINFO_NITERS_ASSUMPTIONS(L) (L)->num_iters_assumptions
704 #define LOOP_VINFO_COST_MODEL_THRESHOLD(L) (L)->th
705 #define LOOP_VINFO_VERSIONING_THRESHOLD(L) (L)->versioning_threshold
706 #define LOOP_VINFO_VECTORIZABLE_P(L) (L)->vectorizable
707 #define LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P(L) (L)->can_use_partial_vectors_p
708 #define LOOP_VINFO_USING_PARTIAL_VECTORS_P(L) (L)->using_partial_vectors_p
709 #define LOOP_VINFO_VECT_FACTOR(L) (L)->vectorization_factor
710 #define LOOP_VINFO_MAX_VECT_FACTOR(L) (L)->max_vectorization_factor
711 #define LOOP_VINFO_MASKS(L) (L)->masks
712 #define LOOP_VINFO_MASK_SKIP_NITERS(L) (L)->mask_skip_niters
713 #define LOOP_VINFO_MASK_COMPARE_TYPE(L) (L)->mask_compare_type
714 #define LOOP_VINFO_MASK_IV_TYPE(L) (L)->iv_type
715 #define LOOP_VINFO_PTR_MASK(L) (L)->ptr_mask
716 #define LOOP_VINFO_LOOP_NEST(L) (L)->shared->loop_nest
717 #define LOOP_VINFO_DATAREFS(L) (L)->shared->datarefs
718 #define LOOP_VINFO_DDRS(L) (L)->shared->ddrs
719 #define LOOP_VINFO_INT_NITERS(L) (TREE_INT_CST_LOW ((L)->num_iters))
720 #define LOOP_VINFO_PEELING_FOR_ALIGNMENT(L) (L)->peeling_for_alignment
721 #define LOOP_VINFO_UNALIGNED_DR(L) (L)->unaligned_dr
722 #define LOOP_VINFO_MAY_MISALIGN_STMTS(L) (L)->may_misalign_stmts
723 #define LOOP_VINFO_MAY_ALIAS_DDRS(L) (L)->may_alias_ddrs
724 #define LOOP_VINFO_COMP_ALIAS_DDRS(L) (L)->comp_alias_ddrs
725 #define LOOP_VINFO_CHECK_UNEQUAL_ADDRS(L) (L)->check_unequal_addrs
726 #define LOOP_VINFO_CHECK_NONZERO(L) (L)->check_nonzero
727 #define LOOP_VINFO_LOWER_BOUNDS(L) (L)->lower_bounds
728 #define LOOP_VINFO_GROUPED_STORES(L) (L)->grouped_stores
729 #define LOOP_VINFO_SLP_INSTANCES(L) (L)->slp_instances
730 #define LOOP_VINFO_SLP_UNROLLING_FACTOR(L) (L)->slp_unrolling_factor
731 #define LOOP_VINFO_REDUCTIONS(L) (L)->reductions
732 #define LOOP_VINFO_REDUCTION_CHAINS(L) (L)->reduction_chains
733 #define LOOP_VINFO_TARGET_COST_DATA(L) (L)->target_cost_data
734 #define LOOP_VINFO_PEELING_FOR_GAPS(L) (L)->peeling_for_gaps
735 #define LOOP_VINFO_PEELING_FOR_NITER(L) (L)->peeling_for_niter
736 #define LOOP_VINFO_NO_DATA_DEPENDENCIES(L) (L)->no_data_dependencies
737 #define LOOP_VINFO_SCALAR_LOOP(L) (L)->scalar_loop
738 #define LOOP_VINFO_SCALAR_LOOP_SCALING(L) (L)->scalar_loop_scaling
739 #define LOOP_VINFO_HAS_MASK_STORE(L) (L)->has_mask_store
740 #define LOOP_VINFO_SCALAR_ITERATION_COST(L) (L)->scalar_cost_vec
741 #define LOOP_VINFO_SINGLE_SCALAR_ITERATION_COST(L) (L)->single_scalar_iteration_cost
742 #define LOOP_VINFO_ORIG_LOOP_INFO(L) (L)->orig_loop_info
743 #define LOOP_VINFO_SIMD_IF_COND(L) (L)->simd_if_cond
744
745 #define LOOP_VINFO_FULLY_MASKED_P(L) \
746 (LOOP_VINFO_USING_PARTIAL_VECTORS_P (L) \
747 && !LOOP_VINFO_MASKS (L).is_empty ())
748
749 #define LOOP_REQUIRES_VERSIONING_FOR_ALIGNMENT(L) \
750 ((L)->may_misalign_stmts.length () > 0)
751 #define LOOP_REQUIRES_VERSIONING_FOR_ALIAS(L) \
752 ((L)->comp_alias_ddrs.length () > 0 \
753 || (L)->check_unequal_addrs.length () > 0 \
754 || (L)->lower_bounds.length () > 0)
755 #define LOOP_REQUIRES_VERSIONING_FOR_NITERS(L) \
756 (LOOP_VINFO_NITERS_ASSUMPTIONS (L))
757 #define LOOP_REQUIRES_VERSIONING_FOR_SIMD_IF_COND(L) \
758 (LOOP_VINFO_SIMD_IF_COND (L))
759 #define LOOP_REQUIRES_VERSIONING(L) \
760 (LOOP_REQUIRES_VERSIONING_FOR_ALIGNMENT (L) \
761 || LOOP_REQUIRES_VERSIONING_FOR_ALIAS (L) \
762 || LOOP_REQUIRES_VERSIONING_FOR_NITERS (L) \
763 || LOOP_REQUIRES_VERSIONING_FOR_SIMD_IF_COND (L))
764
765 #define LOOP_VINFO_NITERS_KNOWN_P(L) \
766 (tree_fits_shwi_p ((L)->num_iters) && tree_to_shwi ((L)->num_iters) > 0)
767
768 #define LOOP_VINFO_EPILOGUE_P(L) \
769 (LOOP_VINFO_ORIG_LOOP_INFO (L) != NULL)
770
771 #define LOOP_VINFO_ORIG_MAX_VECT_FACTOR(L) \
772 (LOOP_VINFO_MAX_VECT_FACTOR (LOOP_VINFO_ORIG_LOOP_INFO (L)))
773
774 /* Wrapper for loop_vec_info, for tracking success/failure, where a non-NULL
775 value signifies success, and a NULL value signifies failure, supporting
776 propagating an opt_problem * describing the failure back up the call
777 stack. */
778 typedef opt_pointer_wrapper <loop_vec_info> opt_loop_vec_info;
779
780 static inline loop_vec_info
781 loop_vec_info_for_loop (class loop *loop)
782 {
783 return (loop_vec_info) loop->aux;
784 }
785
786 typedef class _bb_vec_info : public vec_info
787 {
788 public:
789 _bb_vec_info (gimple_stmt_iterator, gimple_stmt_iterator, vec_info_shared *);
790 ~_bb_vec_info ();
791
792 basic_block bb;
793 gimple_stmt_iterator region_begin;
794 gimple_stmt_iterator region_end;
795 } *bb_vec_info;
796
797 #define BB_VINFO_BB(B) (B)->bb
798 #define BB_VINFO_GROUPED_STORES(B) (B)->grouped_stores
799 #define BB_VINFO_SLP_INSTANCES(B) (B)->slp_instances
800 #define BB_VINFO_DATAREFS(B) (B)->shared->datarefs
801 #define BB_VINFO_DDRS(B) (B)->shared->ddrs
802 #define BB_VINFO_TARGET_COST_DATA(B) (B)->target_cost_data
803
804 static inline bb_vec_info
805 vec_info_for_bb (basic_block bb)
806 {
807 return (bb_vec_info) bb->aux;
808 }
809
810 /*-----------------------------------------------------------------*/
811 /* Info on vectorized defs. */
812 /*-----------------------------------------------------------------*/
813 enum stmt_vec_info_type {
814 undef_vec_info_type = 0,
815 load_vec_info_type,
816 store_vec_info_type,
817 shift_vec_info_type,
818 op_vec_info_type,
819 call_vec_info_type,
820 call_simd_clone_vec_info_type,
821 assignment_vec_info_type,
822 condition_vec_info_type,
823 comparison_vec_info_type,
824 reduc_vec_info_type,
825 induc_vec_info_type,
826 type_promotion_vec_info_type,
827 type_demotion_vec_info_type,
828 type_conversion_vec_info_type,
829 cycle_phi_info_type,
830 lc_phi_info_type,
831 loop_exit_ctrl_vec_info_type
832 };
833
834 /* Indicates whether/how a variable is used in the scope of loop/basic
835 block. */
836 enum vect_relevant {
837 vect_unused_in_scope = 0,
838
839 /* The def is only used outside the loop. */
840 vect_used_only_live,
841 /* The def is in the inner loop, and the use is in the outer loop, and the
842 use is a reduction stmt. */
843 vect_used_in_outer_by_reduction,
844 /* The def is in the inner loop, and the use is in the outer loop (and is
845 not part of reduction). */
846 vect_used_in_outer,
847
848 /* defs that feed computations that end up (only) in a reduction. These
849 defs may be used by non-reduction stmts, but eventually, any
850 computations/values that are affected by these defs are used to compute
851 a reduction (i.e. don't get stored to memory, for example). We use this
852 to identify computations that we can change the order in which they are
853 computed. */
854 vect_used_by_reduction,
855
856 vect_used_in_scope
857 };
858
859 /* The type of vectorization that can be applied to the stmt: regular loop-based
860 vectorization; pure SLP - the stmt is a part of SLP instances and does not
861 have uses outside SLP instances; or hybrid SLP and loop-based - the stmt is
862 a part of SLP instance and also must be loop-based vectorized, since it has
863 uses outside SLP sequences.
864
865 In the loop context the meanings of pure and hybrid SLP are slightly
866 different. By saying that pure SLP is applied to the loop, we mean that we
867 exploit only intra-iteration parallelism in the loop; i.e., the loop can be
868 vectorized without doing any conceptual unrolling, cause we don't pack
869 together stmts from different iterations, only within a single iteration.
870 Loop hybrid SLP means that we exploit both intra-iteration and
871 inter-iteration parallelism (e.g., number of elements in the vector is 4
872 and the slp-group-size is 2, in which case we don't have enough parallelism
873 within an iteration, so we obtain the rest of the parallelism from subsequent
874 iterations by unrolling the loop by 2). */
875 enum slp_vect_type {
876 loop_vect = 0,
877 pure_slp,
878 hybrid
879 };
880
881 /* Says whether a statement is a load, a store of a vectorized statement
882 result, or a store of an invariant value. */
883 enum vec_load_store_type {
884 VLS_LOAD,
885 VLS_STORE,
886 VLS_STORE_INVARIANT
887 };
888
889 /* Describes how we're going to vectorize an individual load or store,
890 or a group of loads or stores. */
891 enum vect_memory_access_type {
892 /* An access to an invariant address. This is used only for loads. */
893 VMAT_INVARIANT,
894
895 /* A simple contiguous access. */
896 VMAT_CONTIGUOUS,
897
898 /* A contiguous access that goes down in memory rather than up,
899 with no additional permutation. This is used only for stores
900 of invariants. */
901 VMAT_CONTIGUOUS_DOWN,
902
903 /* A simple contiguous access in which the elements need to be permuted
904 after loading or before storing. Only used for loop vectorization;
905 SLP uses separate permutes. */
906 VMAT_CONTIGUOUS_PERMUTE,
907
908 /* A simple contiguous access in which the elements need to be reversed
909 after loading or before storing. */
910 VMAT_CONTIGUOUS_REVERSE,
911
912 /* An access that uses IFN_LOAD_LANES or IFN_STORE_LANES. */
913 VMAT_LOAD_STORE_LANES,
914
915 /* An access in which each scalar element is loaded or stored
916 individually. */
917 VMAT_ELEMENTWISE,
918
919 /* A hybrid of VMAT_CONTIGUOUS and VMAT_ELEMENTWISE, used for grouped
920 SLP accesses. Each unrolled iteration uses a contiguous load
921 or store for the whole group, but the groups from separate iterations
922 are combined in the same way as for VMAT_ELEMENTWISE. */
923 VMAT_STRIDED_SLP,
924
925 /* The access uses gather loads or scatter stores. */
926 VMAT_GATHER_SCATTER
927 };
928
929 class dr_vec_info {
930 public:
931 /* The data reference itself. */
932 data_reference *dr;
933 /* The statement that contains the data reference. */
934 stmt_vec_info stmt;
935 /* The misalignment in bytes of the reference, or -1 if not known. */
936 int misalignment;
937 /* The byte alignment that we'd ideally like the reference to have,
938 and the value that misalignment is measured against. */
939 poly_uint64 target_alignment;
940 /* If true the alignment of base_decl needs to be increased. */
941 bool base_misaligned;
942 tree base_decl;
943
944 /* Stores current vectorized loop's offset. To be added to the DR's
945 offset to calculate current offset of data reference. */
946 tree offset;
947 };
948
949 typedef struct data_reference *dr_p;
950
951 class _stmt_vec_info {
952 public:
953
954 enum stmt_vec_info_type type;
955
956 /* Indicates whether this stmts is part of a computation whose result is
957 used outside the loop. */
958 bool live;
959
960 /* Stmt is part of some pattern (computation idiom) */
961 bool in_pattern_p;
962
963 /* True if the statement was created during pattern recognition as
964 part of the replacement for RELATED_STMT. This implies that the
965 statement isn't part of any basic block, although for convenience
966 its gimple_bb is the same as for RELATED_STMT. */
967 bool pattern_stmt_p;
968
969 /* Is this statement vectorizable or should it be skipped in (partial)
970 vectorization. */
971 bool vectorizable;
972
973 /* The stmt to which this info struct refers to. */
974 gimple *stmt;
975
976 /* The vector type to be used for the LHS of this statement. */
977 tree vectype;
978
979 /* The vectorized stmts. */
980 vec<gimple *> vec_stmts;
981
982 /* The following is relevant only for stmts that contain a non-scalar
983 data-ref (array/pointer/struct access). A GIMPLE stmt is expected to have
984 at most one such data-ref. */
985
986 dr_vec_info dr_aux;
987
988 /* Information about the data-ref relative to this loop
989 nest (the loop that is being considered for vectorization). */
990 innermost_loop_behavior dr_wrt_vec_loop;
991
992 /* For loop PHI nodes, the base and evolution part of it. This makes sure
993 this information is still available in vect_update_ivs_after_vectorizer
994 where we may not be able to re-analyze the PHI nodes evolution as
995 peeling for the prologue loop can make it unanalyzable. The evolution
996 part is still correct after peeling, but the base may have changed from
997 the version here. */
998 tree loop_phi_evolution_base_unchanged;
999 tree loop_phi_evolution_part;
1000
1001 /* Used for various bookkeeping purposes, generally holding a pointer to
1002 some other stmt S that is in some way "related" to this stmt.
1003 Current use of this field is:
1004 If this stmt is part of a pattern (i.e. the field 'in_pattern_p' is
1005 true): S is the "pattern stmt" that represents (and replaces) the
1006 sequence of stmts that constitutes the pattern. Similarly, the
1007 related_stmt of the "pattern stmt" points back to this stmt (which is
1008 the last stmt in the original sequence of stmts that constitutes the
1009 pattern). */
1010 stmt_vec_info related_stmt;
1011
1012 /* Used to keep a sequence of def stmts of a pattern stmt if such exists.
1013 The sequence is attached to the original statement rather than the
1014 pattern statement. */
1015 gimple_seq pattern_def_seq;
1016
1017 /* List of datarefs that are known to have the same alignment as the dataref
1018 of this stmt. */
1019 vec<dr_p> same_align_refs;
1020
1021 /* Selected SIMD clone's function info. First vector element
1022 is SIMD clone's function decl, followed by a pair of trees (base + step)
1023 for linear arguments (pair of NULLs for other arguments). */
1024 vec<tree> simd_clone_info;
1025
1026 /* Classify the def of this stmt. */
1027 enum vect_def_type def_type;
1028
1029 /* Whether the stmt is SLPed, loop-based vectorized, or both. */
1030 enum slp_vect_type slp_type;
1031
1032 /* Interleaving and reduction chains info. */
1033 /* First element in the group. */
1034 stmt_vec_info first_element;
1035 /* Pointer to the next element in the group. */
1036 stmt_vec_info next_element;
1037 /* The size of the group. */
1038 unsigned int size;
1039 /* For stores, number of stores from this group seen. We vectorize the last
1040 one. */
1041 unsigned int store_count;
1042 /* For loads only, the gap from the previous load. For consecutive loads, GAP
1043 is 1. */
1044 unsigned int gap;
1045
1046 /* The minimum negative dependence distance this stmt participates in
1047 or zero if none. */
1048 unsigned int min_neg_dist;
1049
1050 /* Not all stmts in the loop need to be vectorized. e.g, the increment
1051 of the loop induction variable and computation of array indexes. relevant
1052 indicates whether the stmt needs to be vectorized. */
1053 enum vect_relevant relevant;
1054
1055 /* For loads if this is a gather, for stores if this is a scatter. */
1056 bool gather_scatter_p;
1057
1058 /* True if this is an access with loop-invariant stride. */
1059 bool strided_p;
1060
1061 /* For both loads and stores. */
1062 unsigned simd_lane_access_p : 3;
1063
1064 /* Classifies how the load or store is going to be implemented
1065 for loop vectorization. */
1066 vect_memory_access_type memory_access_type;
1067
1068 /* For INTEGER_INDUC_COND_REDUCTION, the initial value to be used. */
1069 tree induc_cond_initial_val;
1070
1071 /* If not NULL the value to be added to compute final reduction value. */
1072 tree reduc_epilogue_adjustment;
1073
1074 /* On a reduction PHI the reduction type as detected by
1075 vect_is_simple_reduction and vectorizable_reduction. */
1076 enum vect_reduction_type reduc_type;
1077
1078 /* The original reduction code, to be used in the epilogue. */
1079 enum tree_code reduc_code;
1080 /* An internal function we should use in the epilogue. */
1081 internal_fn reduc_fn;
1082
1083 /* On a stmt participating in the reduction the index of the operand
1084 on the reduction SSA cycle. */
1085 int reduc_idx;
1086
1087 /* On a reduction PHI the def returned by vect_force_simple_reduction.
1088 On the def returned by vect_force_simple_reduction the
1089 corresponding PHI. */
1090 stmt_vec_info reduc_def;
1091
1092 /* The vector input type relevant for reduction vectorization. */
1093 tree reduc_vectype_in;
1094
1095 /* The vector type for performing the actual reduction. */
1096 tree reduc_vectype;
1097
1098 /* Whether we force a single cycle PHI during reduction vectorization. */
1099 bool force_single_cycle;
1100
1101 /* Whether on this stmt reduction meta is recorded. */
1102 bool is_reduc_info;
1103
1104 /* The number of scalar stmt references from active SLP instances. */
1105 unsigned int num_slp_uses;
1106
1107 /* If nonzero, the lhs of the statement could be truncated to this
1108 many bits without affecting any users of the result. */
1109 unsigned int min_output_precision;
1110
1111 /* If nonzero, all non-boolean input operands have the same precision,
1112 and they could each be truncated to this many bits without changing
1113 the result. */
1114 unsigned int min_input_precision;
1115
1116 /* If OPERATION_BITS is nonzero, the statement could be performed on
1117 an integer with the sign and number of bits given by OPERATION_SIGN
1118 and OPERATION_BITS without changing the result. */
1119 unsigned int operation_precision;
1120 signop operation_sign;
1121
1122 /* If the statement produces a boolean result, this value describes
1123 how we should choose the associated vector type. The possible
1124 values are:
1125
1126 - an integer precision N if we should use the vector mask type
1127 associated with N-bit integers. This is only used if all relevant
1128 input booleans also want the vector mask type for N-bit integers,
1129 or if we can convert them into that form by pattern-matching.
1130
1131 - ~0U if we considered choosing a vector mask type but decided
1132 to treat the boolean as a normal integer type instead.
1133
1134 - 0 otherwise. This means either that the operation isn't one that
1135 could have a vector mask type (and so should have a normal vector
1136 type instead) or that we simply haven't made a choice either way. */
1137 unsigned int mask_precision;
1138
1139 /* True if this is only suitable for SLP vectorization. */
1140 bool slp_vect_only_p;
1141 };
1142
1143 /* Information about a gather/scatter call. */
1144 struct gather_scatter_info {
1145 /* The internal function to use for the gather/scatter operation,
1146 or IFN_LAST if a built-in function should be used instead. */
1147 internal_fn ifn;
1148
1149 /* The FUNCTION_DECL for the built-in gather/scatter function,
1150 or null if an internal function should be used instead. */
1151 tree decl;
1152
1153 /* The loop-invariant base value. */
1154 tree base;
1155
1156 /* The original scalar offset, which is a non-loop-invariant SSA_NAME. */
1157 tree offset;
1158
1159 /* Each offset element should be multiplied by this amount before
1160 being added to the base. */
1161 int scale;
1162
1163 /* The definition type for the vectorized offset. */
1164 enum vect_def_type offset_dt;
1165
1166 /* The type of the vectorized offset. */
1167 tree offset_vectype;
1168
1169 /* The type of the scalar elements after loading or before storing. */
1170 tree element_type;
1171
1172 /* The type of the scalar elements being loaded or stored. */
1173 tree memory_type;
1174 };
1175
1176 /* Access Functions. */
1177 #define STMT_VINFO_TYPE(S) (S)->type
1178 #define STMT_VINFO_STMT(S) (S)->stmt
1179 #define STMT_VINFO_RELEVANT(S) (S)->relevant
1180 #define STMT_VINFO_LIVE_P(S) (S)->live
1181 #define STMT_VINFO_VECTYPE(S) (S)->vectype
1182 #define STMT_VINFO_VEC_STMTS(S) (S)->vec_stmts
1183 #define STMT_VINFO_VECTORIZABLE(S) (S)->vectorizable
1184 #define STMT_VINFO_DATA_REF(S) ((S)->dr_aux.dr + 0)
1185 #define STMT_VINFO_GATHER_SCATTER_P(S) (S)->gather_scatter_p
1186 #define STMT_VINFO_STRIDED_P(S) (S)->strided_p
1187 #define STMT_VINFO_MEMORY_ACCESS_TYPE(S) (S)->memory_access_type
1188 #define STMT_VINFO_SIMD_LANE_ACCESS_P(S) (S)->simd_lane_access_p
1189 #define STMT_VINFO_VEC_INDUC_COND_INITIAL_VAL(S) (S)->induc_cond_initial_val
1190 #define STMT_VINFO_REDUC_EPILOGUE_ADJUSTMENT(S) (S)->reduc_epilogue_adjustment
1191 #define STMT_VINFO_REDUC_IDX(S) (S)->reduc_idx
1192 #define STMT_VINFO_FORCE_SINGLE_CYCLE(S) (S)->force_single_cycle
1193
1194 #define STMT_VINFO_DR_WRT_VEC_LOOP(S) (S)->dr_wrt_vec_loop
1195 #define STMT_VINFO_DR_BASE_ADDRESS(S) (S)->dr_wrt_vec_loop.base_address
1196 #define STMT_VINFO_DR_INIT(S) (S)->dr_wrt_vec_loop.init
1197 #define STMT_VINFO_DR_OFFSET(S) (S)->dr_wrt_vec_loop.offset
1198 #define STMT_VINFO_DR_STEP(S) (S)->dr_wrt_vec_loop.step
1199 #define STMT_VINFO_DR_BASE_ALIGNMENT(S) (S)->dr_wrt_vec_loop.base_alignment
1200 #define STMT_VINFO_DR_BASE_MISALIGNMENT(S) \
1201 (S)->dr_wrt_vec_loop.base_misalignment
1202 #define STMT_VINFO_DR_OFFSET_ALIGNMENT(S) \
1203 (S)->dr_wrt_vec_loop.offset_alignment
1204 #define STMT_VINFO_DR_STEP_ALIGNMENT(S) \
1205 (S)->dr_wrt_vec_loop.step_alignment
1206
1207 #define STMT_VINFO_DR_INFO(S) \
1208 (gcc_checking_assert ((S)->dr_aux.stmt == (S)), &(S)->dr_aux)
1209
1210 #define STMT_VINFO_IN_PATTERN_P(S) (S)->in_pattern_p
1211 #define STMT_VINFO_RELATED_STMT(S) (S)->related_stmt
1212 #define STMT_VINFO_PATTERN_DEF_SEQ(S) (S)->pattern_def_seq
1213 #define STMT_VINFO_SAME_ALIGN_REFS(S) (S)->same_align_refs
1214 #define STMT_VINFO_SIMD_CLONE_INFO(S) (S)->simd_clone_info
1215 #define STMT_VINFO_DEF_TYPE(S) (S)->def_type
1216 #define STMT_VINFO_GROUPED_ACCESS(S) \
1217 ((S)->dr_aux.dr && DR_GROUP_FIRST_ELEMENT(S))
1218 #define STMT_VINFO_LOOP_PHI_EVOLUTION_BASE_UNCHANGED(S) (S)->loop_phi_evolution_base_unchanged
1219 #define STMT_VINFO_LOOP_PHI_EVOLUTION_PART(S) (S)->loop_phi_evolution_part
1220 #define STMT_VINFO_MIN_NEG_DIST(S) (S)->min_neg_dist
1221 #define STMT_VINFO_NUM_SLP_USES(S) (S)->num_slp_uses
1222 #define STMT_VINFO_REDUC_TYPE(S) (S)->reduc_type
1223 #define STMT_VINFO_REDUC_CODE(S) (S)->reduc_code
1224 #define STMT_VINFO_REDUC_FN(S) (S)->reduc_fn
1225 #define STMT_VINFO_REDUC_DEF(S) (S)->reduc_def
1226 #define STMT_VINFO_REDUC_VECTYPE(S) (S)->reduc_vectype
1227 #define STMT_VINFO_REDUC_VECTYPE_IN(S) (S)->reduc_vectype_in
1228 #define STMT_VINFO_SLP_VECT_ONLY(S) (S)->slp_vect_only_p
1229
1230 #define DR_GROUP_FIRST_ELEMENT(S) \
1231 (gcc_checking_assert ((S)->dr_aux.dr), (S)->first_element)
1232 #define DR_GROUP_NEXT_ELEMENT(S) \
1233 (gcc_checking_assert ((S)->dr_aux.dr), (S)->next_element)
1234 #define DR_GROUP_SIZE(S) \
1235 (gcc_checking_assert ((S)->dr_aux.dr), (S)->size)
1236 #define DR_GROUP_STORE_COUNT(S) \
1237 (gcc_checking_assert ((S)->dr_aux.dr), (S)->store_count)
1238 #define DR_GROUP_GAP(S) \
1239 (gcc_checking_assert ((S)->dr_aux.dr), (S)->gap)
1240
1241 #define REDUC_GROUP_FIRST_ELEMENT(S) \
1242 (gcc_checking_assert (!(S)->dr_aux.dr), (S)->first_element)
1243 #define REDUC_GROUP_NEXT_ELEMENT(S) \
1244 (gcc_checking_assert (!(S)->dr_aux.dr), (S)->next_element)
1245 #define REDUC_GROUP_SIZE(S) \
1246 (gcc_checking_assert (!(S)->dr_aux.dr), (S)->size)
1247
1248 #define STMT_VINFO_RELEVANT_P(S) ((S)->relevant != vect_unused_in_scope)
1249
1250 #define HYBRID_SLP_STMT(S) ((S)->slp_type == hybrid)
1251 #define PURE_SLP_STMT(S) ((S)->slp_type == pure_slp)
1252 #define STMT_SLP_TYPE(S) (S)->slp_type
1253
1254 #define VECT_MAX_COST 1000
1255
1256 /* The maximum number of intermediate steps required in multi-step type
1257 conversion. */
1258 #define MAX_INTERM_CVT_STEPS 3
1259
1260 #define MAX_VECTORIZATION_FACTOR INT_MAX
1261
1262 /* Nonzero if TYPE represents a (scalar) boolean type or type
1263 in the middle-end compatible with it (unsigned precision 1 integral
1264 types). Used to determine which types should be vectorized as
1265 VECTOR_BOOLEAN_TYPE_P. */
1266
1267 #define VECT_SCALAR_BOOLEAN_TYPE_P(TYPE) \
1268 (TREE_CODE (TYPE) == BOOLEAN_TYPE \
1269 || ((TREE_CODE (TYPE) == INTEGER_TYPE \
1270 || TREE_CODE (TYPE) == ENUMERAL_TYPE) \
1271 && TYPE_PRECISION (TYPE) == 1 \
1272 && TYPE_UNSIGNED (TYPE)))
1273
1274 static inline bool
1275 nested_in_vect_loop_p (class loop *loop, stmt_vec_info stmt_info)
1276 {
1277 return (loop->inner
1278 && (loop->inner == (gimple_bb (stmt_info->stmt))->loop_father));
1279 }
1280
1281 /* Return true if STMT_INFO should produce a vector mask type rather than
1282 a normal nonmask type. */
1283
1284 static inline bool
1285 vect_use_mask_type_p (stmt_vec_info stmt_info)
1286 {
1287 return stmt_info->mask_precision && stmt_info->mask_precision != ~0U;
1288 }
1289
1290 /* Return TRUE if a statement represented by STMT_INFO is a part of a
1291 pattern. */
1292
1293 static inline bool
1294 is_pattern_stmt_p (stmt_vec_info stmt_info)
1295 {
1296 return stmt_info->pattern_stmt_p;
1297 }
1298
1299 /* If STMT_INFO is a pattern statement, return the statement that it
1300 replaces, otherwise return STMT_INFO itself. */
1301
1302 inline stmt_vec_info
1303 vect_orig_stmt (stmt_vec_info stmt_info)
1304 {
1305 if (is_pattern_stmt_p (stmt_info))
1306 return STMT_VINFO_RELATED_STMT (stmt_info);
1307 return stmt_info;
1308 }
1309
1310 /* Return the later statement between STMT1_INFO and STMT2_INFO. */
1311
1312 static inline stmt_vec_info
1313 get_later_stmt (stmt_vec_info stmt1_info, stmt_vec_info stmt2_info)
1314 {
1315 if (gimple_uid (vect_orig_stmt (stmt1_info)->stmt)
1316 > gimple_uid (vect_orig_stmt (stmt2_info)->stmt))
1317 return stmt1_info;
1318 else
1319 return stmt2_info;
1320 }
1321
1322 /* If STMT_INFO has been replaced by a pattern statement, return the
1323 replacement statement, otherwise return STMT_INFO itself. */
1324
1325 inline stmt_vec_info
1326 vect_stmt_to_vectorize (stmt_vec_info stmt_info)
1327 {
1328 if (STMT_VINFO_IN_PATTERN_P (stmt_info))
1329 return STMT_VINFO_RELATED_STMT (stmt_info);
1330 return stmt_info;
1331 }
1332
1333 /* Return true if BB is a loop header. */
1334
1335 static inline bool
1336 is_loop_header_bb_p (basic_block bb)
1337 {
1338 if (bb == (bb->loop_father)->header)
1339 return true;
1340 gcc_checking_assert (EDGE_COUNT (bb->preds) == 1);
1341 return false;
1342 }
1343
1344 /* Return pow2 (X). */
1345
1346 static inline int
1347 vect_pow2 (int x)
1348 {
1349 int i, res = 1;
1350
1351 for (i = 0; i < x; i++)
1352 res *= 2;
1353
1354 return res;
1355 }
1356
1357 /* Alias targetm.vectorize.builtin_vectorization_cost. */
1358
1359 static inline int
1360 builtin_vectorization_cost (enum vect_cost_for_stmt type_of_cost,
1361 tree vectype, int misalign)
1362 {
1363 return targetm.vectorize.builtin_vectorization_cost (type_of_cost,
1364 vectype, misalign);
1365 }
1366
1367 /* Get cost by calling cost target builtin. */
1368
1369 static inline
1370 int vect_get_stmt_cost (enum vect_cost_for_stmt type_of_cost)
1371 {
1372 return builtin_vectorization_cost (type_of_cost, NULL, 0);
1373 }
1374
1375 /* Alias targetm.vectorize.init_cost. */
1376
1377 static inline void *
1378 init_cost (class loop *loop_info)
1379 {
1380 return targetm.vectorize.init_cost (loop_info);
1381 }
1382
1383 extern void dump_stmt_cost (FILE *, void *, int, enum vect_cost_for_stmt,
1384 stmt_vec_info, tree, int, unsigned,
1385 enum vect_cost_model_location);
1386
1387 /* Alias targetm.vectorize.add_stmt_cost. */
1388
1389 static inline unsigned
1390 add_stmt_cost (vec_info *vinfo, void *data, int count,
1391 enum vect_cost_for_stmt kind,
1392 stmt_vec_info stmt_info, tree vectype, int misalign,
1393 enum vect_cost_model_location where)
1394 {
1395 unsigned cost = targetm.vectorize.add_stmt_cost (vinfo, data, count, kind,
1396 stmt_info, vectype,
1397 misalign, where);
1398 if (dump_file && (dump_flags & TDF_DETAILS))
1399 dump_stmt_cost (dump_file, data, count, kind, stmt_info, vectype, misalign,
1400 cost, where);
1401 return cost;
1402 }
1403
1404 /* Alias targetm.vectorize.finish_cost. */
1405
1406 static inline void
1407 finish_cost (void *data, unsigned *prologue_cost,
1408 unsigned *body_cost, unsigned *epilogue_cost)
1409 {
1410 targetm.vectorize.finish_cost (data, prologue_cost, body_cost, epilogue_cost);
1411 }
1412
1413 /* Alias targetm.vectorize.destroy_cost_data. */
1414
1415 static inline void
1416 destroy_cost_data (void *data)
1417 {
1418 targetm.vectorize.destroy_cost_data (data);
1419 }
1420
1421 inline void
1422 add_stmt_costs (vec_info *vinfo, void *data, stmt_vector_for_cost *cost_vec)
1423 {
1424 stmt_info_for_cost *cost;
1425 unsigned i;
1426 FOR_EACH_VEC_ELT (*cost_vec, i, cost)
1427 add_stmt_cost (vinfo, data, cost->count, cost->kind, cost->stmt_info,
1428 cost->vectype, cost->misalign, cost->where);
1429 }
1430
1431 /*-----------------------------------------------------------------*/
1432 /* Info on data references alignment. */
1433 /*-----------------------------------------------------------------*/
1434 #define DR_MISALIGNMENT_UNKNOWN (-1)
1435 #define DR_MISALIGNMENT_UNINITIALIZED (-2)
1436
1437 inline void
1438 set_dr_misalignment (dr_vec_info *dr_info, int val)
1439 {
1440 dr_info->misalignment = val;
1441 }
1442
1443 inline int
1444 dr_misalignment (dr_vec_info *dr_info)
1445 {
1446 int misalign = dr_info->misalignment;
1447 gcc_assert (misalign != DR_MISALIGNMENT_UNINITIALIZED);
1448 return misalign;
1449 }
1450
1451 /* Reflects actual alignment of first access in the vectorized loop,
1452 taking into account peeling/versioning if applied. */
1453 #define DR_MISALIGNMENT(DR) dr_misalignment (DR)
1454 #define SET_DR_MISALIGNMENT(DR, VAL) set_dr_misalignment (DR, VAL)
1455
1456 /* Only defined once DR_MISALIGNMENT is defined. */
1457 #define DR_TARGET_ALIGNMENT(DR) ((DR)->target_alignment)
1458
1459 /* Return true if data access DR_INFO is aligned to its target alignment
1460 (which may be less than a full vector). */
1461
1462 static inline bool
1463 aligned_access_p (dr_vec_info *dr_info)
1464 {
1465 return (DR_MISALIGNMENT (dr_info) == 0);
1466 }
1467
1468 /* Return TRUE if the alignment of the data access is known, and FALSE
1469 otherwise. */
1470
1471 static inline bool
1472 known_alignment_for_access_p (dr_vec_info *dr_info)
1473 {
1474 return (DR_MISALIGNMENT (dr_info) != DR_MISALIGNMENT_UNKNOWN);
1475 }
1476
1477 /* Return the minimum alignment in bytes that the vectorized version
1478 of DR_INFO is guaranteed to have. */
1479
1480 static inline unsigned int
1481 vect_known_alignment_in_bytes (dr_vec_info *dr_info)
1482 {
1483 if (DR_MISALIGNMENT (dr_info) == DR_MISALIGNMENT_UNKNOWN)
1484 return TYPE_ALIGN_UNIT (TREE_TYPE (DR_REF (dr_info->dr)));
1485 if (DR_MISALIGNMENT (dr_info) == 0)
1486 return known_alignment (DR_TARGET_ALIGNMENT (dr_info));
1487 return DR_MISALIGNMENT (dr_info) & -DR_MISALIGNMENT (dr_info);
1488 }
1489
1490 /* Return the behavior of DR_INFO with respect to the vectorization context
1491 (which for outer loop vectorization might not be the behavior recorded
1492 in DR_INFO itself). */
1493
1494 static inline innermost_loop_behavior *
1495 vect_dr_behavior (vec_info *vinfo, dr_vec_info *dr_info)
1496 {
1497 stmt_vec_info stmt_info = dr_info->stmt;
1498 loop_vec_info loop_vinfo = dyn_cast<loop_vec_info> (vinfo);
1499 if (loop_vinfo == NULL
1500 || !nested_in_vect_loop_p (LOOP_VINFO_LOOP (loop_vinfo), stmt_info))
1501 return &DR_INNERMOST (dr_info->dr);
1502 else
1503 return &STMT_VINFO_DR_WRT_VEC_LOOP (stmt_info);
1504 }
1505
1506 /* Return the offset calculated by adding the offset of this DR_INFO to the
1507 corresponding data_reference's offset. If CHECK_OUTER then use
1508 vect_dr_behavior to select the appropriate data_reference to use. */
1509
1510 inline tree
1511 get_dr_vinfo_offset (vec_info *vinfo,
1512 dr_vec_info *dr_info, bool check_outer = false)
1513 {
1514 innermost_loop_behavior *base;
1515 if (check_outer)
1516 base = vect_dr_behavior (vinfo, dr_info);
1517 else
1518 base = &dr_info->dr->innermost;
1519
1520 tree offset = base->offset;
1521
1522 if (!dr_info->offset)
1523 return offset;
1524
1525 offset = fold_convert (sizetype, offset);
1526 return fold_build2 (PLUS_EXPR, TREE_TYPE (dr_info->offset), offset,
1527 dr_info->offset);
1528 }
1529
1530
1531 /* Return true if the vect cost model is unlimited. */
1532 static inline bool
1533 unlimited_cost_model (loop_p loop)
1534 {
1535 if (loop != NULL && loop->force_vectorize
1536 && flag_simd_cost_model != VECT_COST_MODEL_DEFAULT)
1537 return flag_simd_cost_model == VECT_COST_MODEL_UNLIMITED;
1538 return (flag_vect_cost_model == VECT_COST_MODEL_UNLIMITED);
1539 }
1540
1541 /* Return true if the loop described by LOOP_VINFO is fully-masked and
1542 if the first iteration should use a partial mask in order to achieve
1543 alignment. */
1544
1545 static inline bool
1546 vect_use_loop_mask_for_alignment_p (loop_vec_info loop_vinfo)
1547 {
1548 return (LOOP_VINFO_FULLY_MASKED_P (loop_vinfo)
1549 && LOOP_VINFO_PEELING_FOR_ALIGNMENT (loop_vinfo));
1550 }
1551
1552 /* Return the number of vectors of type VECTYPE that are needed to get
1553 NUNITS elements. NUNITS should be based on the vectorization factor,
1554 so it is always a known multiple of the number of elements in VECTYPE. */
1555
1556 static inline unsigned int
1557 vect_get_num_vectors (poly_uint64 nunits, tree vectype)
1558 {
1559 return exact_div (nunits, TYPE_VECTOR_SUBPARTS (vectype)).to_constant ();
1560 }
1561
1562 /* Return the number of copies needed for loop vectorization when
1563 a statement operates on vectors of type VECTYPE. This is the
1564 vectorization factor divided by the number of elements in
1565 VECTYPE and is always known at compile time. */
1566
1567 static inline unsigned int
1568 vect_get_num_copies (loop_vec_info loop_vinfo, tree vectype)
1569 {
1570 return vect_get_num_vectors (LOOP_VINFO_VECT_FACTOR (loop_vinfo), vectype);
1571 }
1572
1573 /* Update maximum unit count *MAX_NUNITS so that it accounts for
1574 NUNITS. *MAX_NUNITS can be 1 if we haven't yet recorded anything. */
1575
1576 static inline void
1577 vect_update_max_nunits (poly_uint64 *max_nunits, poly_uint64 nunits)
1578 {
1579 /* All unit counts have the form vec_info::vector_size * X for some
1580 rational X, so two unit sizes must have a common multiple.
1581 Everything is a multiple of the initial value of 1. */
1582 *max_nunits = force_common_multiple (*max_nunits, nunits);
1583 }
1584
1585 /* Update maximum unit count *MAX_NUNITS so that it accounts for
1586 the number of units in vector type VECTYPE. *MAX_NUNITS can be 1
1587 if we haven't yet recorded any vector types. */
1588
1589 static inline void
1590 vect_update_max_nunits (poly_uint64 *max_nunits, tree vectype)
1591 {
1592 vect_update_max_nunits (max_nunits, TYPE_VECTOR_SUBPARTS (vectype));
1593 }
1594
1595 /* Return the vectorization factor that should be used for costing
1596 purposes while vectorizing the loop described by LOOP_VINFO.
1597 Pick a reasonable estimate if the vectorization factor isn't
1598 known at compile time. */
1599
1600 static inline unsigned int
1601 vect_vf_for_cost (loop_vec_info loop_vinfo)
1602 {
1603 return estimated_poly_value (LOOP_VINFO_VECT_FACTOR (loop_vinfo));
1604 }
1605
1606 /* Estimate the number of elements in VEC_TYPE for costing purposes.
1607 Pick a reasonable estimate if the exact number isn't known at
1608 compile time. */
1609
1610 static inline unsigned int
1611 vect_nunits_for_cost (tree vec_type)
1612 {
1613 return estimated_poly_value (TYPE_VECTOR_SUBPARTS (vec_type));
1614 }
1615
1616 /* Return the maximum possible vectorization factor for LOOP_VINFO. */
1617
1618 static inline unsigned HOST_WIDE_INT
1619 vect_max_vf (loop_vec_info loop_vinfo)
1620 {
1621 unsigned HOST_WIDE_INT vf;
1622 if (LOOP_VINFO_VECT_FACTOR (loop_vinfo).is_constant (&vf))
1623 return vf;
1624 return MAX_VECTORIZATION_FACTOR;
1625 }
1626
1627 /* Return the size of the value accessed by unvectorized data reference
1628 DR_INFO. This is only valid once STMT_VINFO_VECTYPE has been calculated
1629 for the associated gimple statement, since that guarantees that DR_INFO
1630 accesses either a scalar or a scalar equivalent. ("Scalar equivalent"
1631 here includes things like V1SI, which can be vectorized in the same way
1632 as a plain SI.) */
1633
1634 inline unsigned int
1635 vect_get_scalar_dr_size (dr_vec_info *dr_info)
1636 {
1637 return tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (DR_REF (dr_info->dr))));
1638 }
1639
1640 /* Return true if LOOP_VINFO requires a runtime check for whether the
1641 vector loop is profitable. */
1642
1643 inline bool
1644 vect_apply_runtime_profitability_check_p (loop_vec_info loop_vinfo)
1645 {
1646 unsigned int th = LOOP_VINFO_COST_MODEL_THRESHOLD (loop_vinfo);
1647 return (!LOOP_VINFO_NITERS_KNOWN_P (loop_vinfo)
1648 && th >= vect_vf_for_cost (loop_vinfo));
1649 }
1650
1651 /* Source location + hotness information. */
1652 extern dump_user_location_t vect_location;
1653
1654 /* A macro for calling:
1655 dump_begin_scope (MSG, vect_location);
1656 via an RAII object, thus printing "=== MSG ===\n" to the dumpfile etc,
1657 and then calling
1658 dump_end_scope ();
1659 once the object goes out of scope, thus capturing the nesting of
1660 the scopes.
1661
1662 These scopes affect dump messages within them: dump messages at the
1663 top level implicitly default to MSG_PRIORITY_USER_FACING, whereas those
1664 in a nested scope implicitly default to MSG_PRIORITY_INTERNALS. */
1665
1666 #define DUMP_VECT_SCOPE(MSG) \
1667 AUTO_DUMP_SCOPE (MSG, vect_location)
1668
1669 /* A sentinel class for ensuring that the "vect_location" global gets
1670 reset at the end of a scope.
1671
1672 The "vect_location" global is used during dumping and contains a
1673 location_t, which could contain references to a tree block via the
1674 ad-hoc data. This data is used for tracking inlining information,
1675 but it's not a GC root; it's simply assumed that such locations never
1676 get accessed if the blocks are optimized away.
1677
1678 Hence we need to ensure that such locations are purged at the end
1679 of any operations using them (e.g. via this class). */
1680
1681 class auto_purge_vect_location
1682 {
1683 public:
1684 ~auto_purge_vect_location ();
1685 };
1686
1687 /*-----------------------------------------------------------------*/
1688 /* Function prototypes. */
1689 /*-----------------------------------------------------------------*/
1690
1691 /* Simple loop peeling and versioning utilities for vectorizer's purposes -
1692 in tree-vect-loop-manip.c. */
1693 extern void vect_set_loop_condition (class loop *, loop_vec_info,
1694 tree, tree, tree, bool);
1695 extern bool slpeel_can_duplicate_loop_p (const class loop *, const_edge);
1696 class loop *slpeel_tree_duplicate_loop_to_edge_cfg (class loop *,
1697 class loop *, edge);
1698 class loop *vect_loop_versioning (loop_vec_info, gimple *);
1699 extern class loop *vect_do_peeling (loop_vec_info, tree, tree,
1700 tree *, tree *, tree *, int, bool, bool,
1701 tree *);
1702 extern void vect_prepare_for_masked_peels (loop_vec_info);
1703 extern dump_user_location_t find_loop_location (class loop *);
1704 extern bool vect_can_advance_ivs_p (loop_vec_info);
1705 extern void vect_update_inits_of_drs (loop_vec_info, tree, tree_code);
1706
1707 /* In tree-vect-stmts.c. */
1708 extern tree get_related_vectype_for_scalar_type (machine_mode, tree,
1709 poly_uint64 = 0);
1710 extern tree get_vectype_for_scalar_type (vec_info *, tree, unsigned int = 0);
1711 extern tree get_vectype_for_scalar_type (vec_info *, tree, slp_tree);
1712 extern tree get_mask_type_for_scalar_type (vec_info *, tree, unsigned int = 0);
1713 extern tree get_same_sized_vectype (tree, tree);
1714 extern bool vect_chooses_same_modes_p (vec_info *, machine_mode);
1715 extern bool vect_get_loop_mask_type (loop_vec_info);
1716 extern bool vect_is_simple_use (tree, vec_info *, enum vect_def_type *,
1717 stmt_vec_info * = NULL, gimple ** = NULL);
1718 extern bool vect_is_simple_use (tree, vec_info *, enum vect_def_type *,
1719 tree *, stmt_vec_info * = NULL,
1720 gimple ** = NULL);
1721 extern bool vect_is_simple_use (vec_info *, stmt_vec_info, slp_tree,
1722 unsigned, tree *, slp_tree *,
1723 enum vect_def_type *,
1724 tree *, stmt_vec_info * = NULL);
1725 extern bool vect_maybe_update_slp_op_vectype (slp_tree, tree);
1726 extern bool supportable_widening_operation (vec_info *,
1727 enum tree_code, stmt_vec_info,
1728 tree, tree, enum tree_code *,
1729 enum tree_code *, int *,
1730 vec<tree> *);
1731 extern bool supportable_narrowing_operation (enum tree_code, tree, tree,
1732 enum tree_code *, int *,
1733 vec<tree> *);
1734
1735 extern unsigned record_stmt_cost (stmt_vector_for_cost *, int,
1736 enum vect_cost_for_stmt, stmt_vec_info,
1737 tree, int, enum vect_cost_model_location);
1738
1739 /* Overload of record_stmt_cost with VECTYPE derived from STMT_INFO. */
1740
1741 static inline unsigned
1742 record_stmt_cost (stmt_vector_for_cost *body_cost_vec, int count,
1743 enum vect_cost_for_stmt kind, stmt_vec_info stmt_info,
1744 int misalign, enum vect_cost_model_location where)
1745 {
1746 return record_stmt_cost (body_cost_vec, count, kind, stmt_info,
1747 STMT_VINFO_VECTYPE (stmt_info), misalign, where);
1748 }
1749
1750 extern void vect_finish_replace_stmt (vec_info *, stmt_vec_info, gimple *);
1751 extern void vect_finish_stmt_generation (vec_info *, stmt_vec_info, gimple *,
1752 gimple_stmt_iterator *);
1753 extern opt_result vect_mark_stmts_to_be_vectorized (loop_vec_info, bool *);
1754 extern tree vect_get_store_rhs (stmt_vec_info);
1755 void vect_get_vec_defs_for_operand (vec_info *vinfo, stmt_vec_info, unsigned,
1756 tree op, vec<tree> *, tree = NULL);
1757 void vect_get_vec_defs (vec_info *, stmt_vec_info, slp_tree, unsigned,
1758 tree, vec<tree> *,
1759 tree = NULL, vec<tree> * = NULL,
1760 tree = NULL, vec<tree> * = NULL,
1761 tree = NULL, vec<tree> * = NULL);
1762 void vect_get_vec_defs (vec_info *, stmt_vec_info, slp_tree, unsigned,
1763 tree, vec<tree> *, tree,
1764 tree = NULL, vec<tree> * = NULL, tree = NULL,
1765 tree = NULL, vec<tree> * = NULL, tree = NULL,
1766 tree = NULL, vec<tree> * = NULL, tree = NULL);
1767 extern tree vect_init_vector (vec_info *, stmt_vec_info, tree, tree,
1768 gimple_stmt_iterator *);
1769 extern tree vect_get_slp_vect_def (slp_tree, unsigned);
1770 extern bool vect_transform_stmt (vec_info *, stmt_vec_info,
1771 gimple_stmt_iterator *,
1772 slp_tree, slp_instance);
1773 extern void vect_remove_stores (vec_info *, stmt_vec_info);
1774 extern bool vect_nop_conversion_p (stmt_vec_info);
1775 extern opt_result vect_analyze_stmt (vec_info *, stmt_vec_info, bool *,
1776 slp_tree,
1777 slp_instance, stmt_vector_for_cost *);
1778 extern void vect_get_load_cost (vec_info *, stmt_vec_info, int, bool,
1779 unsigned int *, unsigned int *,
1780 stmt_vector_for_cost *,
1781 stmt_vector_for_cost *, bool);
1782 extern void vect_get_store_cost (vec_info *, stmt_vec_info, int,
1783 unsigned int *, stmt_vector_for_cost *);
1784 extern bool vect_supportable_shift (vec_info *, enum tree_code, tree);
1785 extern tree vect_gen_perm_mask_any (tree, const vec_perm_indices &);
1786 extern tree vect_gen_perm_mask_checked (tree, const vec_perm_indices &);
1787 extern void optimize_mask_stores (class loop*);
1788 extern gcall *vect_gen_while (tree, tree, tree);
1789 extern tree vect_gen_while_not (gimple_seq *, tree, tree, tree);
1790 extern opt_result vect_get_vector_types_for_stmt (vec_info *,
1791 stmt_vec_info, tree *,
1792 tree *, unsigned int = 0);
1793 extern opt_tree vect_get_mask_type_for_stmt (stmt_vec_info, unsigned int = 0);
1794
1795 /* In tree-vect-data-refs.c. */
1796 extern bool vect_can_force_dr_alignment_p (const_tree, poly_uint64);
1797 extern enum dr_alignment_support vect_supportable_dr_alignment
1798 (vec_info *, dr_vec_info *, bool);
1799 extern tree vect_get_smallest_scalar_type (stmt_vec_info, HOST_WIDE_INT *,
1800 HOST_WIDE_INT *);
1801 extern opt_result vect_analyze_data_ref_dependences (loop_vec_info, unsigned int *);
1802 extern bool vect_slp_analyze_instance_dependence (vec_info *, slp_instance);
1803 extern opt_result vect_enhance_data_refs_alignment (loop_vec_info);
1804 extern opt_result vect_analyze_data_refs_alignment (loop_vec_info);
1805 extern opt_result vect_verify_datarefs_alignment (loop_vec_info);
1806 extern bool vect_slp_analyze_and_verify_instance_alignment (vec_info *,
1807 slp_instance);
1808 extern opt_result vect_analyze_data_ref_accesses (vec_info *);
1809 extern opt_result vect_prune_runtime_alias_test_list (loop_vec_info);
1810 extern bool vect_gather_scatter_fn_p (vec_info *, bool, bool, tree, tree,
1811 tree, int, internal_fn *, tree *);
1812 extern bool vect_check_gather_scatter (stmt_vec_info, loop_vec_info,
1813 gather_scatter_info *);
1814 extern opt_result vect_find_stmt_data_reference (loop_p, gimple *,
1815 vec<data_reference_p> *);
1816 extern opt_result vect_analyze_data_refs (vec_info *, poly_uint64 *, bool *);
1817 extern void vect_record_base_alignments (vec_info *);
1818 extern tree vect_create_data_ref_ptr (vec_info *,
1819 stmt_vec_info, tree, class loop *, tree,
1820 tree *, gimple_stmt_iterator *,
1821 gimple **, bool,
1822 tree = NULL_TREE, tree = NULL_TREE);
1823 extern tree bump_vector_ptr (vec_info *, tree, gimple *, gimple_stmt_iterator *,
1824 stmt_vec_info, tree);
1825 extern void vect_copy_ref_info (tree, tree);
1826 extern tree vect_create_destination_var (tree, tree);
1827 extern bool vect_grouped_store_supported (tree, unsigned HOST_WIDE_INT);
1828 extern bool vect_store_lanes_supported (tree, unsigned HOST_WIDE_INT, bool);
1829 extern bool vect_grouped_load_supported (tree, bool, unsigned HOST_WIDE_INT);
1830 extern bool vect_load_lanes_supported (tree, unsigned HOST_WIDE_INT, bool);
1831 extern void vect_permute_store_chain (vec_info *,
1832 vec<tree> ,unsigned int, stmt_vec_info,
1833 gimple_stmt_iterator *, vec<tree> *);
1834 extern tree vect_setup_realignment (vec_info *,
1835 stmt_vec_info, gimple_stmt_iterator *,
1836 tree *, enum dr_alignment_support, tree,
1837 class loop **);
1838 extern void vect_transform_grouped_load (vec_info *, stmt_vec_info, vec<tree>,
1839 int, gimple_stmt_iterator *);
1840 extern void vect_record_grouped_load_vectors (vec_info *,
1841 stmt_vec_info, vec<tree>);
1842 extern tree vect_get_new_vect_var (tree, enum vect_var_kind, const char *);
1843 extern tree vect_get_new_ssa_name (tree, enum vect_var_kind,
1844 const char * = NULL);
1845 extern tree vect_create_addr_base_for_vector_ref (vec_info *,
1846 stmt_vec_info, gimple_seq *,
1847 tree, tree = NULL_TREE);
1848
1849 /* In tree-vect-loop.c. */
1850 extern widest_int vect_iv_limit_for_full_masking (loop_vec_info loop_vinfo);
1851 /* Used in tree-vect-loop-manip.c */
1852 extern void determine_peel_for_niter (loop_vec_info);
1853 /* Used in gimple-loop-interchange.c and tree-parloops.c. */
1854 extern bool check_reduction_path (dump_user_location_t, loop_p, gphi *, tree,
1855 enum tree_code);
1856 extern bool needs_fold_left_reduction_p (tree, tree_code);
1857 /* Drive for loop analysis stage. */
1858 extern opt_loop_vec_info vect_analyze_loop (class loop *, vec_info_shared *);
1859 extern tree vect_build_loop_niters (loop_vec_info, bool * = NULL);
1860 extern void vect_gen_vector_loop_niters (loop_vec_info, tree, tree *,
1861 tree *, bool);
1862 extern tree vect_halve_mask_nunits (tree, machine_mode);
1863 extern tree vect_double_mask_nunits (tree, machine_mode);
1864 extern void vect_record_loop_mask (loop_vec_info, vec_loop_masks *,
1865 unsigned int, tree, tree);
1866 extern tree vect_get_loop_mask (gimple_stmt_iterator *, vec_loop_masks *,
1867 unsigned int, tree, unsigned int);
1868 extern stmt_vec_info info_for_reduction (vec_info *, stmt_vec_info);
1869
1870 /* Drive for loop transformation stage. */
1871 extern class loop *vect_transform_loop (loop_vec_info, gimple *);
1872 extern opt_loop_vec_info vect_analyze_loop_form (class loop *,
1873 vec_info_shared *);
1874 extern bool vectorizable_live_operation (loop_vec_info,
1875 stmt_vec_info, gimple_stmt_iterator *,
1876 slp_tree, slp_instance, int,
1877 bool, stmt_vector_for_cost *);
1878 extern bool vectorizable_reduction (loop_vec_info, stmt_vec_info,
1879 slp_tree, slp_instance,
1880 stmt_vector_for_cost *);
1881 extern bool vectorizable_induction (loop_vec_info, stmt_vec_info,
1882 gimple_stmt_iterator *,
1883 gimple **, slp_tree,
1884 stmt_vector_for_cost *);
1885 extern bool vect_transform_reduction (loop_vec_info, stmt_vec_info,
1886 gimple_stmt_iterator *,
1887 gimple **, slp_tree);
1888 extern bool vect_transform_cycle_phi (loop_vec_info, stmt_vec_info,
1889 gimple **,
1890 slp_tree, slp_instance);
1891 extern bool vectorizable_lc_phi (loop_vec_info, stmt_vec_info,
1892 gimple **, slp_tree);
1893 extern bool vect_worthwhile_without_simd_p (vec_info *, tree_code);
1894 extern int vect_get_known_peeling_cost (loop_vec_info, int, int *,
1895 stmt_vector_for_cost *,
1896 stmt_vector_for_cost *,
1897 stmt_vector_for_cost *);
1898 extern tree cse_and_gimplify_to_preheader (loop_vec_info, tree);
1899
1900 /* In tree-vect-slp.c. */
1901 extern void vect_free_slp_instance (slp_instance, bool);
1902 extern bool vect_transform_slp_perm_load (vec_info *, slp_tree, vec<tree>,
1903 gimple_stmt_iterator *, poly_uint64,
1904 bool, unsigned *);
1905 extern bool vect_slp_analyze_operations (vec_info *);
1906 extern void vect_schedule_slp (vec_info *);
1907 extern opt_result vect_analyze_slp (vec_info *, unsigned);
1908 extern bool vect_make_slp_decision (loop_vec_info);
1909 extern void vect_detect_hybrid_slp (loop_vec_info);
1910 extern void vect_optimize_slp (vec_info *);
1911 extern void vect_get_slp_defs (slp_tree, vec<tree> *);
1912 extern void vect_get_slp_defs (vec_info *, slp_tree, vec<vec<tree> > *,
1913 unsigned n = -1U);
1914 extern bool vect_slp_bb (basic_block);
1915 extern stmt_vec_info vect_find_last_scalar_stmt_in_slp (slp_tree);
1916 extern bool is_simple_and_all_uses_invariant (stmt_vec_info, loop_vec_info);
1917 extern bool can_duplicate_and_interleave_p (vec_info *, unsigned int, tree,
1918 unsigned int * = NULL,
1919 tree * = NULL, tree * = NULL);
1920 extern void duplicate_and_interleave (vec_info *, gimple_seq *, tree,
1921 vec<tree>, unsigned int, vec<tree> &);
1922 extern int vect_get_place_in_interleaving_chain (stmt_vec_info, stmt_vec_info);
1923
1924 /* In tree-vect-patterns.c. */
1925 /* Pattern recognition functions.
1926 Additional pattern recognition functions can (and will) be added
1927 in the future. */
1928 void vect_pattern_recog (vec_info *);
1929
1930 /* In tree-vectorizer.c. */
1931 unsigned vectorize_loops (void);
1932 void vect_free_loop_info_assumptions (class loop *);
1933 gimple *vect_loop_vectorized_call (class loop *, gcond **cond = NULL);
1934
1935
1936 #endif /* GCC_TREE_VECTORIZER_H */