OSDN Git Service

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