OSDN Git Service

eb8a5868a77c30667f74867e0af664250f195829
[pf3gnuchains/gcc-fork.git] / gcc / tree-vectorizer.h
1 /* Loop Vectorization
2    Copyright (C) 2003, 2004 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 2, 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 COPYING.  If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.  */
21
22 #ifndef GCC_TREE_VECTORIZER_H
23 #define GCC_TREE_VECTORIZER_H
24
25 /* Used for naming of new temporaries.  */
26 enum vect_var_kind {
27   vect_simple_var,
28   vect_pointer_var
29 };
30
31 /* Defines type of operation: unary or binary.  */
32 enum operation_type {
33   unary_op = 1,
34   binary_op
35 };
36
37 /*-----------------------------------------------------------------*/
38 /* Info on vectorized defs.                                        */
39 /*-----------------------------------------------------------------*/
40 enum stmt_vec_info_type {
41   undef_vec_info_type = 0,
42   load_vec_info_type,
43   store_vec_info_type,
44   op_vec_info_type,
45   assignment_vec_info_type
46 };
47
48 typedef struct _stmt_vec_info {
49
50   enum stmt_vec_info_type type;
51
52   /* The stmt to which this info struct refers to.  */
53   tree stmt;
54
55   /* The loop with respect to which STMT is vectorized.  */
56   struct loop *loop;
57
58   /* Not all stmts in the loop need to be vectorized. e.g, the incrementation
59      of the loop induction variable and computation of array indexes. relevant
60      indicates whether the stmt needs to be vectorized.  */
61   bool relevant;
62
63   /* The vector type to be used.  */
64   tree vectype;
65
66   /* The vectorized version of the stmt.  */
67   tree vectorized_stmt;
68
69
70   /** The following is relevant only for stmts that contain a non-scalar
71      data-ref (array/pointer/struct access). A GIMPLE stmt is expected to have 
72      at most one such data-ref.  **/
73
74   /* Information about the data-ref (access function, etc).  */
75   struct data_reference *data_ref_info;
76
77   /* Aliasing information.  */
78   tree memtag;
79 } *stmt_vec_info;
80
81 /* Access Functions.  */
82 #define STMT_VINFO_TYPE(S)       (S)->type
83 #define STMT_VINFO_STMT(S)       (S)->stmt
84 #define STMT_VINFO_LOOP(S)       (S)->loop
85 #define STMT_VINFO_RELEVANT_P(S) (S)->relevant
86 #define STMT_VINFO_VECTYPE(S)    (S)->vectype
87 #define STMT_VINFO_VEC_STMT(S)   (S)->vectorized_stmt
88 #define STMT_VINFO_DATA_REF(S)   (S)->data_ref_info
89 #define STMT_VINFO_MEMTAG(S)     (S)->memtag
90
91 static inline void set_stmt_info (stmt_ann_t ann, stmt_vec_info stmt_info);
92 static inline stmt_vec_info vinfo_for_stmt (tree stmt);
93
94 static inline void
95 set_stmt_info (stmt_ann_t ann, stmt_vec_info stmt_info)
96 {
97   if (ann)
98     ann->common.aux = (char *) stmt_info;
99 }
100
101 static inline stmt_vec_info
102 vinfo_for_stmt (tree stmt)
103 {
104   stmt_ann_t ann = stmt_ann (stmt);
105   return ann ? (stmt_vec_info) ann->common.aux : NULL;
106 }
107
108 /*-----------------------------------------------------------------*/
109 /* Info on data references alignment.                              */
110 /*-----------------------------------------------------------------*/
111
112 #define DR_MISALIGNMENT(DR)   (DR)->aux
113
114 static inline bool
115 aligned_access_p (struct data_reference *data_ref_info)
116 {
117   return (DR_MISALIGNMENT (data_ref_info) == 0);
118 }
119
120 static inline bool
121 unknown_alignment_for_access_p (struct data_reference *data_ref_info)
122 {
123   return (DR_MISALIGNMENT (data_ref_info) == -1);
124 }
125
126
127 /*-----------------------------------------------------------------*/
128 /* Info on vectorized loops.                                       */
129 /*-----------------------------------------------------------------*/
130 typedef struct _loop_vec_info {
131
132   /* The loop to which this info struct refers to.  */
133   struct loop *loop;
134
135   /* The loop basic blocks.  */
136   basic_block *bbs;
137
138   /* The loop exit_condition.  */
139   tree exit_cond;
140
141   /* Number of iterations. -1 if unknown.  */
142   HOST_WIDE_INT num_iters;
143
144   /* Is the loop vectorizable? */
145   bool vectorizable;
146
147   /* Unrolling factor  */
148   int vectorization_factor;
149
150   /* All data references in the loop that are being written to.  */
151   varray_type data_ref_writes;
152
153   /* All data references in the loop that are being read from.  */
154   varray_type data_ref_reads;
155 } *loop_vec_info;
156
157 /* Access Functions.  */
158 #define LOOP_VINFO_LOOP(L)           (L)->loop
159 #define LOOP_VINFO_BBS(L)            (L)->bbs
160 #define LOOP_VINFO_EXIT_COND(L)      (L)->exit_cond
161 #define LOOP_VINFO_NITERS(L)         (L)->num_iters
162 #define LOOP_VINFO_VECTORIZABLE_P(L) (L)->vectorizable
163 #define LOOP_VINFO_VECT_FACTOR(L)    (L)->vectorization_factor
164 #define LOOP_VINFO_DATAREF_WRITES(L) (L)->data_ref_writes
165 #define LOOP_VINFO_DATAREF_READS(L)  (L)->data_ref_reads
166
167 #define LOOP_VINFO_NITERS_KNOWN_P(L) ((L)->num_iters > 0)
168
169 /*-----------------------------------------------------------------*/
170 /* Function prototypes.                                            */
171 /*-----------------------------------------------------------------*/
172
173 /* Main driver.  */
174 extern void vectorize_loops (struct loops *);
175
176 /* creation and deletion of loop and stmt info structs.  */
177 extern loop_vec_info new_loop_vec_info (struct loop *loop);
178 extern void destroy_loop_vec_info (loop_vec_info);
179 extern stmt_vec_info new_stmt_vec_info (tree stmt, struct loop *loop);
180
181 #endif  /* GCC_TREE_VECTORIZER_H  */