OSDN Git Service

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