OSDN Git Service

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