* c-common.c (catenate_strings): New.
[official-gcc.git] / gcc / tree-vectorizer.h
blob8ec9576544a5298be37c0e006636095d24d48cfd
1 /* Loop Vectorization
2 Copyright (C) 2003, 2004 Free Software Foundation, Inc.
3 Contributed by Dorit Naishlos <dorit@il.ibm.com>
5 This file is part of GCC.
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.
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.
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. */
22 #ifndef GCC_TREE_VECTORIZER_H
23 #define GCC_TREE_VECTORIZER_H
25 /* Used for naming of new temporaries. */
26 enum vect_var_kind {
27 vect_simple_var,
28 vect_pointer_var
31 /* Defines type of operation: unary or binary. */
32 enum operation_type {
33 unary_op = 1,
34 binary_op
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
48 typedef struct _stmt_vec_info {
50 enum stmt_vec_info_type type;
52 /* The stmt to which this info struct refers to. */
53 tree stmt;
55 /* The loop with respect to which STMT is vectorized. */
56 struct loop *loop;
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;
63 /* The vector type to be used. */
64 tree vectype;
66 /* The vectorized version of the stmt. */
67 tree vectorized_stmt;
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. **/
74 /* Information about the data-ref (access function, etc). */
75 struct data_reference *data_ref_info;
77 /* Aliasing information. */
78 tree memtag;
80 /* Data reference base. This field holds the entire invariant part of the
81 data-reference (with respect to the relevant loop), as opposed to the
82 field DR_BASE of the STMT_VINFO_DATA_REF struct, which holds only the
83 initial base; e.g:
84 REF BR_BASE VECT_DR_BASE
85 a[i] a a
86 a[i][j] a a[i] */
87 tree vect_dr_base;
88 } *stmt_vec_info;
90 /* Access Functions. */
91 #define STMT_VINFO_TYPE(S) (S)->type
92 #define STMT_VINFO_STMT(S) (S)->stmt
93 #define STMT_VINFO_LOOP(S) (S)->loop
94 #define STMT_VINFO_RELEVANT_P(S) (S)->relevant
95 #define STMT_VINFO_VECTYPE(S) (S)->vectype
96 #define STMT_VINFO_VEC_STMT(S) (S)->vectorized_stmt
97 #define STMT_VINFO_DATA_REF(S) (S)->data_ref_info
98 #define STMT_VINFO_MEMTAG(S) (S)->memtag
99 #define STMT_VINFO_VECT_DR_BASE(S) (S)->vect_dr_base
101 static inline void set_stmt_info (stmt_ann_t ann, stmt_vec_info stmt_info);
102 static inline stmt_vec_info vinfo_for_stmt (tree stmt);
104 static inline void
105 set_stmt_info (stmt_ann_t ann, stmt_vec_info stmt_info)
107 if (ann)
108 ann->common.aux = (char *) stmt_info;
111 static inline stmt_vec_info
112 vinfo_for_stmt (tree stmt)
114 stmt_ann_t ann = stmt_ann (stmt);
115 return ann ? (stmt_vec_info) ann->common.aux : NULL;
118 /*-----------------------------------------------------------------*/
119 /* Info on data references alignment. */
120 /*-----------------------------------------------------------------*/
122 /* The misalignment of the memory access in bytes. */
123 #define DR_MISALIGNMENT(DR) (DR)->aux
124 #define MAX_NUMBER_OF_UNALIGNED_DATA_REFS 1
126 static inline bool
127 aligned_access_p (struct data_reference *data_ref_info)
129 return (DR_MISALIGNMENT (data_ref_info) == 0);
132 static inline bool
133 unknown_alignment_for_access_p (struct data_reference *data_ref_info)
135 return (DR_MISALIGNMENT (data_ref_info) == -1);
138 /* Perform signed modulo, always returning a non-negative value. */
139 #define VECT_SMODULO(x,y) ((x) % (y) < 0 ? ((x) % (y) + (y)) : (x) % (y))
142 /*-----------------------------------------------------------------*/
143 /* Info on vectorized loops. */
144 /*-----------------------------------------------------------------*/
145 typedef struct _loop_vec_info {
147 /* The loop to which this info struct refers to. */
148 struct loop *loop;
150 /* The loop basic blocks. */
151 basic_block *bbs;
153 /* The loop exit_condition. */
154 tree exit_cond;
156 /* Number of iterations. */
157 tree num_iters;
159 /* Is the loop vectorizable? */
160 bool vectorizable;
162 /* Unrolling factor */
163 int vectorization_factor;
165 /* Unknown DRs according to which loop was peeled. */
166 struct data_reference *unaligned_drs [MAX_NUMBER_OF_UNALIGNED_DATA_REFS];
168 /* If true, loop is peeled.
169 unaligned_drs show in this case DRs used for peeling. */
170 bool do_peeling_for_alignment;
172 /* All data references in the loop that are being written to. */
173 varray_type data_ref_writes;
175 /* All data references in the loop that are being read from. */
176 varray_type data_ref_reads;
177 } *loop_vec_info;
179 /* Access Functions. */
180 #define LOOP_VINFO_LOOP(L) (L)->loop
181 #define LOOP_VINFO_BBS(L) (L)->bbs
182 #define LOOP_VINFO_EXIT_COND(L) (L)->exit_cond
183 #define LOOP_VINFO_NITERS(L) (L)->num_iters
184 #define LOOP_VINFO_VECTORIZABLE_P(L) (L)->vectorizable
185 #define LOOP_VINFO_VECT_FACTOR(L) (L)->vectorization_factor
186 #define LOOP_VINFO_DATAREF_WRITES(L) (L)->data_ref_writes
187 #define LOOP_VINFO_DATAREF_READS(L) (L)->data_ref_reads
188 #define LOOP_VINFO_INT_NITERS(L) (TREE_INT_CST_LOW ((L)->num_iters))
189 #define LOOP_DO_PEELING_FOR_ALIGNMENT(L) (L)->do_peeling_for_alignment
190 #define LOOP_UNALIGNED_DR(L, I) (L)->unaligned_drs[(I)]
193 #define LOOP_VINFO_NITERS_KNOWN_P(L) \
194 (host_integerp ((L)->num_iters,0) \
195 && TREE_INT_CST_LOW ((L)->num_iters) > 0)
197 /*-----------------------------------------------------------------*/
198 /* Function prototypes. */
199 /*-----------------------------------------------------------------*/
201 /* Main driver. */
202 extern void vectorize_loops (struct loops *);
204 /* creation and deletion of loop and stmt info structs. */
205 extern loop_vec_info new_loop_vec_info (struct loop *loop);
206 extern void destroy_loop_vec_info (loop_vec_info);
207 extern stmt_vec_info new_stmt_vec_info (tree stmt, struct loop *loop);
209 #endif /* GCC_TREE_VECTORIZER_H */