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