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
168   /* Minimum number of iterations below which vectorization is expected to
169      not be profitable (as estimated by the cost model). 
170      -1 indicates that vectorization will not be profitable.
171      FORNOW: This field is an int. Will be a tree in the future, to represent
172              values unknown at compile time.  */ 
173   int min_profitable_iters;  
174   
175   /* Is the loop vectorizable? */
176   bool vectorizable;
177
178   /* Unrolling factor  */
179   int vectorization_factor;
180
181   /* Unknown DRs according to which loop was peeled.  */
182   struct data_reference *unaligned_dr;
183
184   /* peeling_for_alignment indicates whether peeling for alignment will take
185      place, and what the peeling factor should be:
186      peeling_for_alignment = X means:
187         If X=0: Peeling for alignment will not be applied.
188         If X>0: Peel first X iterations.
189         If X=-1: Generate a runtime test to calculate the number of iterations
190                  to be peeled, using the dataref recorded in the field
191                  unaligned_dr.  */
192   int peeling_for_alignment;
193
194   /* The mask used to check the alignment of pointers or arrays.  */
195   int ptr_mask;
196
197   /* All data references in the loop.  */
198   VEC (data_reference_p, heap) *datarefs;
199
200   /* All data dependences in the loop.  */
201   VEC (ddr_p, heap) *ddrs;
202
203   /* Data Dependence Relations defining address ranges that are candidates
204      for a run-time aliasing check.  */
205   VEC (ddr_p, heap) *may_alias_ddrs;
206
207   /* Statements in the loop that have data references that are candidates for a
208      runtime (loop versioning) misalignment check.  */
209   VEC(tree,heap) *may_misalign_stmts;
210
211   /* The loop location in the source.  */
212   LOC loop_line_number;
213
214   /* All interleaving chains of stores in the loop, represented by the first
215      stmt in the chain.  */
216   VEC(tree, heap) *strided_stores;
217
218   /* All SLP instances in the loop. This is a subset of the set of STRIDED_STORES
219      of the loop.  */
220   VEC(slp_instance, heap) *slp_instances;
221
222   /* The unrolling factor needed to SLP the loop. In case of that pure SLP is 
223      applied to the loop, i.e., no unrolling is needed, this is 1.  */
224   unsigned slp_unrolling_factor;
225 } *loop_vec_info;
226
227 /* Access Functions.  */
228 #define LOOP_VINFO_LOOP(L)            (L)->loop
229 #define LOOP_VINFO_BBS(L)             (L)->bbs
230 #define LOOP_VINFO_NITERS(L)          (L)->num_iters
231 #define LOOP_VINFO_COST_MODEL_MIN_ITERS(L)      (L)->min_profitable_iters
232 #define LOOP_VINFO_VECTORIZABLE_P(L)  (L)->vectorizable
233 #define LOOP_VINFO_VECT_FACTOR(L)     (L)->vectorization_factor
234 #define LOOP_VINFO_PTR_MASK(L)        (L)->ptr_mask
235 #define LOOP_VINFO_DATAREFS(L)        (L)->datarefs
236 #define LOOP_VINFO_DDRS(L)            (L)->ddrs
237 #define LOOP_VINFO_INT_NITERS(L)      (TREE_INT_CST_LOW ((L)->num_iters))
238 #define LOOP_PEELING_FOR_ALIGNMENT(L) (L)->peeling_for_alignment
239 #define LOOP_VINFO_UNALIGNED_DR(L)    (L)->unaligned_dr
240 #define LOOP_VINFO_MAY_MISALIGN_STMTS(L) (L)->may_misalign_stmts
241 #define LOOP_VINFO_LOC(L)             (L)->loop_line_number
242 #define LOOP_VINFO_MAY_ALIAS_DDRS(L)  (L)->may_alias_ddrs
243 #define LOOP_VINFO_STRIDED_STORES(L)  (L)->strided_stores
244 #define LOOP_VINFO_SLP_INSTANCES(L)   (L)->slp_instances
245 #define LOOP_VINFO_SLP_UNROLLING_FACTOR(L) (L)->slp_unrolling_factor
246
247 #define NITERS_KNOWN_P(n)                     \
248 (host_integerp ((n),0)                        \
249 && TREE_INT_CST_LOW ((n)) > 0)
250
251 #define LOOP_VINFO_NITERS_KNOWN_P(L)                     \
252 NITERS_KNOWN_P((L)->num_iters)
253
254 static inline loop_vec_info
255 loop_vec_info_for_loop (struct loop *loop)
256 {
257   return (loop_vec_info) loop->aux;
258 }
259
260 static inline bool
261 nested_in_vect_loop_p (struct loop *loop, tree stmt)
262 {
263   return (loop->inner 
264           && (loop->inner == (bb_for_stmt (stmt))->loop_father));
265 }
266
267 /*-----------------------------------------------------------------*/
268 /* Info on vectorized defs.                                        */
269 /*-----------------------------------------------------------------*/
270 enum stmt_vec_info_type {
271   undef_vec_info_type = 0,
272   load_vec_info_type,
273   store_vec_info_type,
274   op_vec_info_type,
275   call_vec_info_type,
276   assignment_vec_info_type,
277   condition_vec_info_type,
278   reduc_vec_info_type,
279   induc_vec_info_type,
280   type_promotion_vec_info_type,
281   type_demotion_vec_info_type,
282   type_conversion_vec_info_type,
283   loop_exit_ctrl_vec_info_type
284 };
285
286 /* Indicates whether/how a variable is used in the loop.  */
287 enum vect_relevant {
288   vect_unused_in_loop = 0,
289   vect_used_in_outer_by_reduction,
290   vect_used_in_outer,
291
292   /* defs that feed computations that end up (only) in a reduction. These
293      defs may be used by non-reduction stmts, but eventually, any 
294      computations/values that are affected by these defs are used to compute 
295      a reduction (i.e. don't get stored to memory, for example). We use this 
296      to identify computations that we can change the order in which they are 
297      computed.  */
298   vect_used_by_reduction,
299
300   vect_used_in_loop  
301 };
302
303 /* The type of vectorization that can be applied to the stmt: regular loop-based
304    vectorization; pure SLP - the stmt is a part of SLP instances and does not
305    have uses outside SLP instances; or hybrid SLP and loop-based - the stmt is
306    a part of SLP instance and also must be loop-based vectorized, since it has
307    uses outside SLP sequences. 
308
309    In the loop context the meanings of pure and hybrid SLP are slightly 
310    different. By saying that pure SLP is applied to the loop, we mean that we 
311    exploit only intra-iteration parallelism in the loop; i.e., the loop can be 
312    vectorized without doing any conceptual unrolling, cause we don't pack 
313    together stmts from different iterations, only within a single iteration. 
314    Loop hybrid SLP means that we exploit both intra-iteration and 
315    inter-iteration parallelism (e.g., number of elements in the vector is 4
316    and the slp-group-size is 2, in which case we don't have enough parallelism 
317    within an iteration, so we obtain the rest of the parallelism from subsequent 
318    iterations by unrolling the loop by 2).  */
319 enum slp_vect_type { 
320   loop_vect = 0,
321   pure_slp,
322   hybrid
323 };
324
325
326 typedef struct data_reference *dr_p;
327 DEF_VEC_P(dr_p);
328 DEF_VEC_ALLOC_P(dr_p,heap);
329
330 typedef struct _stmt_vec_info {
331
332   enum stmt_vec_info_type type;
333
334   /* The stmt to which this info struct refers to.  */
335   tree stmt;
336
337   /* The loop_vec_info with respect to which STMT is vectorized.  */
338   loop_vec_info loop_vinfo;
339
340   /* Not all stmts in the loop need to be vectorized. e.g, the increment
341      of the loop induction variable and computation of array indexes. relevant
342      indicates whether the stmt needs to be vectorized.  */
343   enum vect_relevant relevant;
344
345   /* Indicates whether this stmts is part of a computation whose result is
346      used outside the loop.  */
347   bool live;
348
349   /* The vector type to be used.  */
350   tree vectype;
351
352   /* The vectorized version of the stmt.  */
353   tree vectorized_stmt;
354
355
356   /** The following is relevant only for stmts that contain a non-scalar
357      data-ref (array/pointer/struct access). A GIMPLE stmt is expected to have 
358      at most one such data-ref.  **/
359
360   /* Information about the data-ref (access function, etc),
361      relative to the inner-most containing loop.  */
362   struct data_reference *data_ref_info;
363
364   /* Information about the data-ref relative to this loop
365      nest (the loop that is being considered for vectorization).  */
366   tree dr_base_address;
367   tree dr_init;
368   tree dr_offset;
369   tree dr_step;
370   tree dr_aligned_to;
371
372   /* Stmt is part of some pattern (computation idiom)  */
373   bool in_pattern_p;
374
375   /* Used for various bookkeeping purposes, generally holding a pointer to 
376      some other stmt S that is in some way "related" to this stmt. 
377      Current use of this field is:
378         If this stmt is part of a pattern (i.e. the field 'in_pattern_p' is 
379         true): S is the "pattern stmt" that represents (and replaces) the 
380         sequence of stmts that constitutes the pattern.  Similarly, the 
381         related_stmt of the "pattern stmt" points back to this stmt (which is 
382         the last stmt in the original sequence of stmts that constitutes the 
383         pattern).  */
384   tree related_stmt;
385
386   /* List of datarefs that are known to have the same alignment as the dataref
387      of this stmt.  */
388   VEC(dr_p,heap) *same_align_refs;
389
390   /* Classify the def of this stmt.  */
391   enum vect_def_type def_type;
392
393   /* Interleaving info.  */
394   /* First data-ref in the interleaving group.  */
395   tree first_dr;
396   /* Pointer to the next data-ref in the group.  */
397   tree next_dr;
398   /* The size of the interleaving group.  */
399   unsigned int size;
400   /* For stores, number of stores from this group seen. We vectorize the last
401      one.  */
402   unsigned int store_count;
403   /* For loads only, the gap from the previous load. For consecutive loads, GAP
404      is 1.  */
405   unsigned int gap;
406   /* In case that two or more stmts share data-ref, this is the pointer to the
407      previously detected stmt with the same dr.  */
408   tree same_dr_stmt;
409   /* For loads only, if there is a store with the same location, this field is
410      TRUE.  */
411   bool read_write_dep;
412
413   /* Vectorization costs associated with statement.  */
414   struct  
415   {
416     int outside_of_loop;     /* Statements generated outside loop.  */
417     int inside_of_loop;      /* Statements generated inside loop.  */
418   } cost;
419
420   /*  Whether the stmt is SLPed, loop-based vectorized, or both.  */
421   enum slp_vect_type slp_type;
422 } *stmt_vec_info;
423
424 /* Access Functions.  */
425 #define STMT_VINFO_TYPE(S)                 (S)->type
426 #define STMT_VINFO_STMT(S)                 (S)->stmt
427 #define STMT_VINFO_LOOP_VINFO(S)           (S)->loop_vinfo
428 #define STMT_VINFO_RELEVANT(S)             (S)->relevant
429 #define STMT_VINFO_LIVE_P(S)               (S)->live
430 #define STMT_VINFO_VECTYPE(S)              (S)->vectype
431 #define STMT_VINFO_VEC_STMT(S)             (S)->vectorized_stmt
432 #define STMT_VINFO_DATA_REF(S)             (S)->data_ref_info
433
434 #define STMT_VINFO_DR_BASE_ADDRESS(S)      (S)->dr_base_address
435 #define STMT_VINFO_DR_INIT(S)              (S)->dr_init
436 #define STMT_VINFO_DR_OFFSET(S)            (S)->dr_offset
437 #define STMT_VINFO_DR_STEP(S)              (S)->dr_step
438 #define STMT_VINFO_DR_ALIGNED_TO(S)        (S)->dr_aligned_to
439
440 #define STMT_VINFO_IN_PATTERN_P(S)         (S)->in_pattern_p
441 #define STMT_VINFO_RELATED_STMT(S)         (S)->related_stmt
442 #define STMT_VINFO_SAME_ALIGN_REFS(S)      (S)->same_align_refs
443 #define STMT_VINFO_DEF_TYPE(S)             (S)->def_type
444 #define STMT_VINFO_DR_GROUP_FIRST_DR(S)    (S)->first_dr
445 #define STMT_VINFO_DR_GROUP_NEXT_DR(S)     (S)->next_dr
446 #define STMT_VINFO_DR_GROUP_SIZE(S)        (S)->size
447 #define STMT_VINFO_DR_GROUP_STORE_COUNT(S) (S)->store_count
448 #define STMT_VINFO_DR_GROUP_GAP(S)         (S)->gap
449 #define STMT_VINFO_DR_GROUP_SAME_DR_STMT(S)(S)->same_dr_stmt
450 #define STMT_VINFO_DR_GROUP_READ_WRITE_DEPENDENCE(S)  (S)->read_write_dep
451 #define STMT_VINFO_STRIDED_ACCESS(S)      ((S)->first_dr != NULL)
452
453 #define DR_GROUP_FIRST_DR(S)               (S)->first_dr
454 #define DR_GROUP_NEXT_DR(S)                (S)->next_dr
455 #define DR_GROUP_SIZE(S)                   (S)->size
456 #define DR_GROUP_STORE_COUNT(S)            (S)->store_count
457 #define DR_GROUP_GAP(S)                    (S)->gap
458 #define DR_GROUP_SAME_DR_STMT(S)           (S)->same_dr_stmt
459 #define DR_GROUP_READ_WRITE_DEPENDENCE(S)  (S)->read_write_dep
460
461 #define STMT_VINFO_RELEVANT_P(S)          ((S)->relevant != vect_unused_in_loop)
462 #define STMT_VINFO_OUTSIDE_OF_LOOP_COST(S) (S)->cost.outside_of_loop
463 #define STMT_VINFO_INSIDE_OF_LOOP_COST(S)  (S)->cost.inside_of_loop
464
465 #define HYBRID_SLP_STMT(S)                ((S)->slp_type == hybrid)
466 #define PURE_SLP_STMT(S)                  ((S)->slp_type == pure_slp)
467 #define STMT_SLP_TYPE(S)                   (S)->slp_type
468
469 /* These are some defines for the initial implementation of the vectorizer's
470    cost model.  These will later be target specific hooks.  */
471
472 /* Cost of conditional taken branch.  */
473 #ifndef TARG_COND_TAKEN_BRANCH_COST
474 #define TARG_COND_TAKEN_BRANCH_COST        3
475 #endif
476
477 /* Cost of conditional not taken branch.  */
478 #ifndef TARG_COND_NOT_TAKEN_BRANCH_COST
479 #define TARG_COND_NOT_TAKEN_BRANCH_COST        1
480 #endif
481
482 /* Cost of any scalar operation, excluding load and store.  */
483 #ifndef TARG_SCALAR_STMT_COST
484 #define TARG_SCALAR_STMT_COST           1
485 #endif
486
487 /* Cost of scalar load.  */
488 #ifndef TARG_SCALAR_LOAD_COST
489 #define TARG_SCALAR_LOAD_COST           1
490 #endif
491
492 /* Cost of scalar store.  */
493 #ifndef TARG_SCALAR_STORE_COST
494 #define TARG_SCALAR_STORE_COST           1
495 #endif
496
497 /* Cost of any vector operation, excluding load, store or vector to scalar
498    operation.  */ 
499 #ifndef TARG_VEC_STMT_COST
500 #define TARG_VEC_STMT_COST           1
501 #endif
502
503 /* Cost of vector to scalar operation.  */
504 #ifndef TARG_VEC_TO_SCALAR_COST
505 #define TARG_VEC_TO_SCALAR_COST      1
506 #endif
507
508 /* Cost of scalar to vector operation.  */
509 #ifndef TARG_SCALAR_TO_VEC_COST
510 #define TARG_SCALAR_TO_VEC_COST      1
511 #endif
512
513 /* Cost of aligned vector load.  */
514 #ifndef TARG_VEC_LOAD_COST
515 #define TARG_VEC_LOAD_COST           1
516 #endif
517
518 /* Cost of misaligned vector load.  */
519 #ifndef TARG_VEC_UNALIGNED_LOAD_COST
520 #define TARG_VEC_UNALIGNED_LOAD_COST 2
521 #endif
522
523 /* Cost of vector store.  */
524 #ifndef TARG_VEC_STORE_COST
525 #define TARG_VEC_STORE_COST          1
526 #endif
527
528 static inline void set_stmt_info (stmt_ann_t ann, stmt_vec_info stmt_info);
529 static inline stmt_vec_info vinfo_for_stmt (tree stmt);
530
531 static inline void
532 set_stmt_info (stmt_ann_t ann, stmt_vec_info stmt_info)
533 {
534   if (ann)
535     ann->common.aux = (char *) stmt_info;
536 }
537
538 static inline stmt_vec_info
539 vinfo_for_stmt (tree stmt)
540 {
541   stmt_ann_t ann = stmt_ann (stmt);
542   return ann ? (stmt_vec_info) ann->common.aux : NULL;
543 }
544
545 static inline bool
546 is_pattern_stmt_p (stmt_vec_info stmt_info)
547 {
548   tree related_stmt;
549   stmt_vec_info related_stmt_info;
550
551   related_stmt = STMT_VINFO_RELATED_STMT (stmt_info);
552   if (related_stmt
553       && (related_stmt_info = vinfo_for_stmt (related_stmt))
554       && STMT_VINFO_IN_PATTERN_P (related_stmt_info))
555     return true;
556
557   return false;
558 }
559
560 static inline bool
561 is_loop_header_bb_p (basic_block bb)
562 {
563   if (bb == (bb->loop_father)->header)
564     return true;
565   gcc_assert (EDGE_COUNT (bb->preds) == 1);
566   return false;
567 }
568
569 static inline void 
570 stmt_vinfo_set_inside_of_loop_cost (stmt_vec_info stmt_info, slp_tree slp_node, 
571                                     int cost)
572 {
573   if (slp_node)
574     SLP_TREE_INSIDE_OF_LOOP_COST (slp_node) = cost;
575   else
576     STMT_VINFO_INSIDE_OF_LOOP_COST (stmt_info) = cost;
577 }     
578
579 static inline void 
580 stmt_vinfo_set_outside_of_loop_cost (stmt_vec_info stmt_info, slp_tree slp_node, 
581                                      int cost)
582 {
583   if (slp_node)
584     SLP_TREE_OUTSIDE_OF_LOOP_COST (slp_node) = cost;
585   else
586     STMT_VINFO_OUTSIDE_OF_LOOP_COST (stmt_info) = cost;
587 }     
588
589
590 /*-----------------------------------------------------------------*/
591 /* Info on data references alignment.                              */
592 /*-----------------------------------------------------------------*/
593
594 /* Reflects actual alignment of first access in the vectorized loop,
595    taking into account peeling/versioning if applied.  */
596 #define DR_MISALIGNMENT(DR)   ((int) (size_t) (DR)->aux)
597 #define SET_DR_MISALIGNMENT(DR, VAL)   ((DR)->aux = (void *) (size_t) (VAL))
598
599 static inline bool
600 aligned_access_p (struct data_reference *data_ref_info)
601 {
602   return (DR_MISALIGNMENT (data_ref_info) == 0);
603 }
604
605 static inline bool
606 known_alignment_for_access_p (struct data_reference *data_ref_info)
607 {
608   return (DR_MISALIGNMENT (data_ref_info) != -1);
609 }
610
611 /* vect_dump will be set to stderr or dump_file if exist.  */
612 extern FILE *vect_dump;
613 extern enum verbosity_levels vect_verbosity_level;
614
615 /* Bitmap of virtual variables to be renamed.  */
616 extern bitmap vect_memsyms_to_rename;
617
618 /*-----------------------------------------------------------------*/
619 /* Function prototypes.                                            */
620 /*-----------------------------------------------------------------*/
621
622 /*************************************************************************
623   Simple Loop Peeling Utilities - in tree-vectorizer.c
624  *************************************************************************/
625 /* Entry point for peeling of simple loops.
626    Peel the first/last iterations of a loop.
627    It can be used outside of the vectorizer for loops that are simple enough
628    (see function documentation).  In the vectorizer it is used to peel the
629    last few iterations when the loop bound is unknown or does not evenly
630    divide by the vectorization factor, and to peel the first few iterations
631    to force the alignment of data references in the loop.  */
632 extern struct loop *slpeel_tree_peel_loop_to_edge 
633   (struct loop *, edge, tree, tree, bool, unsigned int);
634 extern void slpeel_make_loop_iterate_ntimes (struct loop *, tree);
635 extern bool slpeel_can_duplicate_loop_p (const struct loop *, const_edge);
636 #ifdef ENABLE_CHECKING
637 extern void slpeel_verify_cfg_after_peeling (struct loop *, struct loop *);
638 #endif
639
640
641 /*************************************************************************
642   General Vectorization Utilities
643  *************************************************************************/
644 /** In tree-vectorizer.c **/
645 extern tree get_vectype_for_scalar_type (tree);
646 extern bool vect_is_simple_use (tree, loop_vec_info, tree *, tree *,
647                                 enum vect_def_type *);
648 extern bool vect_is_simple_iv_evolution (unsigned, tree, tree *, tree *);
649 extern tree vect_is_simple_reduction (loop_vec_info, tree);
650 extern bool vect_can_force_dr_alignment_p (const_tree, unsigned int);
651 extern enum dr_alignment_support vect_supportable_dr_alignment
652   (struct data_reference *);
653 extern bool reduction_code_for_scalar_code (enum tree_code, enum tree_code *);
654 extern bool supportable_widening_operation (enum tree_code, tree, tree,
655   tree *, tree *, enum tree_code *, enum tree_code *);
656 extern bool supportable_narrowing_operation (enum tree_code, const_tree,
657                                              const_tree, enum tree_code *);
658
659 /* Creation and deletion of loop and stmt info structs.  */
660 extern loop_vec_info new_loop_vec_info (struct loop *loop);
661 extern void destroy_loop_vec_info (loop_vec_info, bool);
662 extern stmt_vec_info new_stmt_vec_info (tree stmt, loop_vec_info);
663
664
665 /** In tree-vect-analyze.c  **/
666 /* Driver for analysis stage.  */
667 extern loop_vec_info vect_analyze_loop (struct loop *);
668 extern void vect_free_slp_tree (slp_tree);
669 extern loop_vec_info vect_analyze_loop_form (struct loop *);
670
671 /** In tree-vect-patterns.c  **/
672 /* Pattern recognition functions.
673    Additional pattern recognition functions can (and will) be added
674    in the future.  */
675 typedef tree (* vect_recog_func_ptr) (tree, tree *, tree *);
676 #define NUM_PATTERNS 4
677 void vect_pattern_recog (loop_vec_info);
678
679
680 /** In tree-vect-transform.c  **/
681 extern bool vectorizable_load (tree, block_stmt_iterator *, tree *, slp_tree);
682 extern bool vectorizable_store (tree, block_stmt_iterator *, tree *, slp_tree);
683 extern bool vectorizable_operation (tree, block_stmt_iterator *, tree *, 
684                                     slp_tree);
685 extern bool vectorizable_type_promotion (tree, block_stmt_iterator *, tree *);
686 extern bool vectorizable_type_demotion (tree, block_stmt_iterator *, tree *);
687 extern bool vectorizable_conversion (tree, block_stmt_iterator *, 
688                                      tree *, slp_tree);
689 extern bool vectorizable_assignment (tree, block_stmt_iterator *, tree *, 
690                                      slp_tree);
691 extern tree vectorizable_function (tree, tree, tree);
692 extern bool vectorizable_call (tree, block_stmt_iterator *, tree *);
693 extern bool vectorizable_condition (tree, block_stmt_iterator *, tree *);
694 extern bool vectorizable_live_operation (tree, block_stmt_iterator *, tree *);
695 extern bool vectorizable_reduction (tree, block_stmt_iterator *, tree *);
696 extern bool vectorizable_induction (tree, block_stmt_iterator *, tree *);
697 extern int  vect_estimate_min_profitable_iters (loop_vec_info);
698 extern void vect_model_simple_cost (stmt_vec_info, int, enum vect_def_type *, 
699                                     slp_tree);
700 extern void vect_model_store_cost (stmt_vec_info, int, enum vect_def_type, 
701                                    slp_tree);
702 extern void vect_model_load_cost (stmt_vec_info, int, slp_tree);
703 /* Driver for transformation stage.  */
704 extern void vect_transform_loop (loop_vec_info);
705
706 /*************************************************************************
707   Vectorization Debug Information - in tree-vectorizer.c
708  *************************************************************************/
709 extern bool vect_print_dump_info (enum verbosity_levels);
710 extern void vect_set_verbosity_level (const char *);
711 extern LOC find_loop_location (struct loop *);
712
713 #endif  /* GCC_TREE_VECTORIZER_H  */