OSDN Git Service

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