]>
Commit | Line | Data |
---|---|---|
385399a8 RS |
1 | /* Tree-based target query functions relating to optabs |
2 | Copyright (C) 1987-2015 Free Software Foundation, Inc. | |
3 | ||
4 | This file is part of GCC. | |
5 | ||
6 | GCC is free software; you can redistribute it and/or modify it under | |
7 | the terms of the GNU General Public License as published by the Free | |
8 | Software Foundation; either version 3, or (at your option) any later | |
9 | version. | |
10 | ||
11 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
12 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
14 | for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GCC; see the file COPYING3. If not see | |
18 | <http://www.gnu.org/licenses/>. */ | |
19 | ||
20 | ||
21 | #include "config.h" | |
22 | #include "system.h" | |
23 | #include "coretypes.h" | |
24 | #include "target.h" | |
25 | #include "insn-codes.h" | |
26 | #include "tree.h" | |
27 | #include "optabs-tree.h" | |
28 | #include "stor-layout.h" | |
29 | ||
30 | /* Return the optab used for computing the operation given by the tree code, | |
31 | CODE and the tree EXP. This function is not always usable (for example, it | |
32 | cannot give complete results for multiplication or division) but probably | |
33 | ought to be relied on more widely throughout the expander. */ | |
34 | optab | |
35 | optab_for_tree_code (enum tree_code code, const_tree type, | |
36 | enum optab_subtype subtype) | |
37 | { | |
38 | bool trapv; | |
39 | switch (code) | |
40 | { | |
41 | case BIT_AND_EXPR: | |
42 | return and_optab; | |
43 | ||
44 | case BIT_IOR_EXPR: | |
45 | return ior_optab; | |
46 | ||
47 | case BIT_NOT_EXPR: | |
48 | return one_cmpl_optab; | |
49 | ||
50 | case BIT_XOR_EXPR: | |
51 | return xor_optab; | |
52 | ||
53 | case MULT_HIGHPART_EXPR: | |
54 | return TYPE_UNSIGNED (type) ? umul_highpart_optab : smul_highpart_optab; | |
55 | ||
56 | case TRUNC_MOD_EXPR: | |
57 | case CEIL_MOD_EXPR: | |
58 | case FLOOR_MOD_EXPR: | |
59 | case ROUND_MOD_EXPR: | |
60 | return TYPE_UNSIGNED (type) ? umod_optab : smod_optab; | |
61 | ||
62 | case RDIV_EXPR: | |
63 | case TRUNC_DIV_EXPR: | |
64 | case CEIL_DIV_EXPR: | |
65 | case FLOOR_DIV_EXPR: | |
66 | case ROUND_DIV_EXPR: | |
67 | case EXACT_DIV_EXPR: | |
68 | if (TYPE_SATURATING (type)) | |
69 | return TYPE_UNSIGNED (type) ? usdiv_optab : ssdiv_optab; | |
70 | return TYPE_UNSIGNED (type) ? udiv_optab : sdiv_optab; | |
71 | ||
72 | case LSHIFT_EXPR: | |
73 | if (TREE_CODE (type) == VECTOR_TYPE) | |
74 | { | |
75 | if (subtype == optab_vector) | |
76 | return TYPE_SATURATING (type) ? unknown_optab : vashl_optab; | |
77 | ||
78 | gcc_assert (subtype == optab_scalar); | |
79 | } | |
80 | if (TYPE_SATURATING (type)) | |
81 | return TYPE_UNSIGNED (type) ? usashl_optab : ssashl_optab; | |
82 | return ashl_optab; | |
83 | ||
84 | case RSHIFT_EXPR: | |
85 | if (TREE_CODE (type) == VECTOR_TYPE) | |
86 | { | |
87 | if (subtype == optab_vector) | |
88 | return TYPE_UNSIGNED (type) ? vlshr_optab : vashr_optab; | |
89 | ||
90 | gcc_assert (subtype == optab_scalar); | |
91 | } | |
92 | return TYPE_UNSIGNED (type) ? lshr_optab : ashr_optab; | |
93 | ||
94 | case LROTATE_EXPR: | |
95 | if (TREE_CODE (type) == VECTOR_TYPE) | |
96 | { | |
97 | if (subtype == optab_vector) | |
98 | return vrotl_optab; | |
99 | ||
100 | gcc_assert (subtype == optab_scalar); | |
101 | } | |
102 | return rotl_optab; | |
103 | ||
104 | case RROTATE_EXPR: | |
105 | if (TREE_CODE (type) == VECTOR_TYPE) | |
106 | { | |
107 | if (subtype == optab_vector) | |
108 | return vrotr_optab; | |
109 | ||
110 | gcc_assert (subtype == optab_scalar); | |
111 | } | |
112 | return rotr_optab; | |
113 | ||
114 | case MAX_EXPR: | |
115 | return TYPE_UNSIGNED (type) ? umax_optab : smax_optab; | |
116 | ||
117 | case MIN_EXPR: | |
118 | return TYPE_UNSIGNED (type) ? umin_optab : smin_optab; | |
119 | ||
120 | case REALIGN_LOAD_EXPR: | |
121 | return vec_realign_load_optab; | |
122 | ||
123 | case WIDEN_SUM_EXPR: | |
124 | return TYPE_UNSIGNED (type) ? usum_widen_optab : ssum_widen_optab; | |
125 | ||
126 | case DOT_PROD_EXPR: | |
127 | return TYPE_UNSIGNED (type) ? udot_prod_optab : sdot_prod_optab; | |
128 | ||
129 | case SAD_EXPR: | |
130 | return TYPE_UNSIGNED (type) ? usad_optab : ssad_optab; | |
131 | ||
132 | case WIDEN_MULT_PLUS_EXPR: | |
133 | return (TYPE_UNSIGNED (type) | |
134 | ? (TYPE_SATURATING (type) | |
135 | ? usmadd_widen_optab : umadd_widen_optab) | |
136 | : (TYPE_SATURATING (type) | |
137 | ? ssmadd_widen_optab : smadd_widen_optab)); | |
138 | ||
139 | case WIDEN_MULT_MINUS_EXPR: | |
140 | return (TYPE_UNSIGNED (type) | |
141 | ? (TYPE_SATURATING (type) | |
142 | ? usmsub_widen_optab : umsub_widen_optab) | |
143 | : (TYPE_SATURATING (type) | |
144 | ? ssmsub_widen_optab : smsub_widen_optab)); | |
145 | ||
146 | case FMA_EXPR: | |
147 | return fma_optab; | |
148 | ||
149 | case REDUC_MAX_EXPR: | |
150 | return TYPE_UNSIGNED (type) | |
151 | ? reduc_umax_scal_optab : reduc_smax_scal_optab; | |
152 | ||
153 | case REDUC_MIN_EXPR: | |
154 | return TYPE_UNSIGNED (type) | |
155 | ? reduc_umin_scal_optab : reduc_smin_scal_optab; | |
156 | ||
157 | case REDUC_PLUS_EXPR: | |
158 | return reduc_plus_scal_optab; | |
159 | ||
160 | case VEC_WIDEN_MULT_HI_EXPR: | |
161 | return TYPE_UNSIGNED (type) ? | |
162 | vec_widen_umult_hi_optab : vec_widen_smult_hi_optab; | |
163 | ||
164 | case VEC_WIDEN_MULT_LO_EXPR: | |
165 | return TYPE_UNSIGNED (type) ? | |
166 | vec_widen_umult_lo_optab : vec_widen_smult_lo_optab; | |
167 | ||
168 | case VEC_WIDEN_MULT_EVEN_EXPR: | |
169 | return TYPE_UNSIGNED (type) ? | |
170 | vec_widen_umult_even_optab : vec_widen_smult_even_optab; | |
171 | ||
172 | case VEC_WIDEN_MULT_ODD_EXPR: | |
173 | return TYPE_UNSIGNED (type) ? | |
174 | vec_widen_umult_odd_optab : vec_widen_smult_odd_optab; | |
175 | ||
176 | case VEC_WIDEN_LSHIFT_HI_EXPR: | |
177 | return TYPE_UNSIGNED (type) ? | |
178 | vec_widen_ushiftl_hi_optab : vec_widen_sshiftl_hi_optab; | |
179 | ||
180 | case VEC_WIDEN_LSHIFT_LO_EXPR: | |
181 | return TYPE_UNSIGNED (type) ? | |
182 | vec_widen_ushiftl_lo_optab : vec_widen_sshiftl_lo_optab; | |
183 | ||
184 | case VEC_UNPACK_HI_EXPR: | |
185 | return TYPE_UNSIGNED (type) ? | |
186 | vec_unpacku_hi_optab : vec_unpacks_hi_optab; | |
187 | ||
188 | case VEC_UNPACK_LO_EXPR: | |
189 | return TYPE_UNSIGNED (type) ? | |
190 | vec_unpacku_lo_optab : vec_unpacks_lo_optab; | |
191 | ||
192 | case VEC_UNPACK_FLOAT_HI_EXPR: | |
193 | /* The signedness is determined from input operand. */ | |
194 | return TYPE_UNSIGNED (type) ? | |
195 | vec_unpacku_float_hi_optab : vec_unpacks_float_hi_optab; | |
196 | ||
197 | case VEC_UNPACK_FLOAT_LO_EXPR: | |
198 | /* The signedness is determined from input operand. */ | |
199 | return TYPE_UNSIGNED (type) ? | |
200 | vec_unpacku_float_lo_optab : vec_unpacks_float_lo_optab; | |
201 | ||
202 | case VEC_PACK_TRUNC_EXPR: | |
203 | return vec_pack_trunc_optab; | |
204 | ||
205 | case VEC_PACK_SAT_EXPR: | |
206 | return TYPE_UNSIGNED (type) ? vec_pack_usat_optab : vec_pack_ssat_optab; | |
207 | ||
208 | case VEC_PACK_FIX_TRUNC_EXPR: | |
209 | /* The signedness is determined from output operand. */ | |
210 | return TYPE_UNSIGNED (type) ? | |
211 | vec_pack_ufix_trunc_optab : vec_pack_sfix_trunc_optab; | |
212 | ||
213 | default: | |
214 | break; | |
215 | } | |
216 | ||
217 | trapv = INTEGRAL_TYPE_P (type) && TYPE_OVERFLOW_TRAPS (type); | |
218 | switch (code) | |
219 | { | |
220 | case POINTER_PLUS_EXPR: | |
221 | case PLUS_EXPR: | |
222 | if (TYPE_SATURATING (type)) | |
223 | return TYPE_UNSIGNED (type) ? usadd_optab : ssadd_optab; | |
224 | return trapv ? addv_optab : add_optab; | |
225 | ||
226 | case MINUS_EXPR: | |
227 | if (TYPE_SATURATING (type)) | |
228 | return TYPE_UNSIGNED (type) ? ussub_optab : sssub_optab; | |
229 | return trapv ? subv_optab : sub_optab; | |
230 | ||
231 | case MULT_EXPR: | |
232 | if (TYPE_SATURATING (type)) | |
233 | return TYPE_UNSIGNED (type) ? usmul_optab : ssmul_optab; | |
234 | return trapv ? smulv_optab : smul_optab; | |
235 | ||
236 | case NEGATE_EXPR: | |
237 | if (TYPE_SATURATING (type)) | |
238 | return TYPE_UNSIGNED (type) ? usneg_optab : ssneg_optab; | |
239 | return trapv ? negv_optab : neg_optab; | |
240 | ||
241 | case ABS_EXPR: | |
242 | return trapv ? absv_optab : abs_optab; | |
243 | ||
244 | default: | |
245 | return unknown_optab; | |
246 | } | |
247 | } | |
248 | ||
249 | /* Given optab UNOPTAB that reduces a vector to a scalar, find instead the old | |
250 | optab that produces a vector with the reduction result in one element, | |
251 | for a tree with type TYPE. */ | |
252 | ||
253 | optab | |
254 | scalar_reduc_to_vector (optab unoptab, const_tree type) | |
255 | { | |
256 | switch (unoptab) | |
257 | { | |
258 | case reduc_plus_scal_optab: | |
259 | return TYPE_UNSIGNED (type) ? reduc_uplus_optab : reduc_splus_optab; | |
260 | ||
261 | case reduc_smin_scal_optab: return reduc_smin_optab; | |
262 | case reduc_umin_scal_optab: return reduc_umin_optab; | |
263 | case reduc_smax_scal_optab: return reduc_smax_optab; | |
264 | case reduc_umax_scal_optab: return reduc_umax_optab; | |
265 | default: return unknown_optab; | |
266 | } | |
267 | } | |
268 | ||
269 | /* Function supportable_convert_operation | |
270 | ||
271 | Check whether an operation represented by the code CODE is a | |
272 | convert operation that is supported by the target platform in | |
273 | vector form (i.e., when operating on arguments of type VECTYPE_IN | |
274 | producing a result of type VECTYPE_OUT). | |
275 | ||
276 | Convert operations we currently support directly are FIX_TRUNC and FLOAT. | |
277 | This function checks if these operations are supported | |
278 | by the target platform either directly (via vector tree-codes), or via | |
279 | target builtins. | |
280 | ||
281 | Output: | |
282 | - CODE1 is code of vector operation to be used when | |
283 | vectorizing the operation, if available. | |
284 | - DECL is decl of target builtin functions to be used | |
285 | when vectorizing the operation, if available. In this case, | |
286 | CODE1 is CALL_EXPR. */ | |
287 | ||
288 | bool | |
289 | supportable_convert_operation (enum tree_code code, | |
290 | tree vectype_out, tree vectype_in, | |
291 | tree *decl, enum tree_code *code1) | |
292 | { | |
293 | machine_mode m1,m2; | |
294 | bool truncp; | |
295 | ||
296 | m1 = TYPE_MODE (vectype_out); | |
297 | m2 = TYPE_MODE (vectype_in); | |
298 | ||
299 | /* First check if we can done conversion directly. */ | |
300 | if ((code == FIX_TRUNC_EXPR | |
301 | && can_fix_p (m1,m2,TYPE_UNSIGNED (vectype_out), &truncp) | |
302 | != CODE_FOR_nothing) | |
303 | || (code == FLOAT_EXPR | |
304 | && can_float_p (m1,m2,TYPE_UNSIGNED (vectype_in)) | |
305 | != CODE_FOR_nothing)) | |
306 | { | |
307 | *code1 = code; | |
308 | return true; | |
309 | } | |
310 | ||
311 | /* Now check for builtin. */ | |
312 | if (targetm.vectorize.builtin_conversion | |
313 | && targetm.vectorize.builtin_conversion (code, vectype_out, vectype_in)) | |
314 | { | |
315 | *code1 = CALL_EXPR; | |
316 | *decl = targetm.vectorize.builtin_conversion (code, vectype_out, | |
317 | vectype_in); | |
318 | return true; | |
319 | } | |
320 | return false; | |
321 | } | |
322 | ||
323 | /* Return TRUE iff, appropriate vector insns are available | |
324 | for vector cond expr with vector type VALUE_TYPE and a comparison | |
325 | with operand vector types in CMP_OP_TYPE. */ | |
326 | ||
327 | bool | |
328 | expand_vec_cond_expr_p (tree value_type, tree cmp_op_type) | |
329 | { | |
330 | machine_mode value_mode = TYPE_MODE (value_type); | |
331 | machine_mode cmp_op_mode = TYPE_MODE (cmp_op_type); | |
332 | if (GET_MODE_SIZE (value_mode) != GET_MODE_SIZE (cmp_op_mode) | |
333 | || GET_MODE_NUNITS (value_mode) != GET_MODE_NUNITS (cmp_op_mode) | |
334 | || get_vcond_icode (TYPE_MODE (value_type), TYPE_MODE (cmp_op_type), | |
335 | TYPE_UNSIGNED (cmp_op_type)) == CODE_FOR_nothing) | |
336 | return false; | |
337 | return true; | |
338 | } | |
339 | ||
340 | /* Use the current target and options to initialize | |
341 | TREE_OPTIMIZATION_OPTABS (OPTNODE). */ | |
342 | ||
343 | void | |
344 | init_tree_optimization_optabs (tree optnode) | |
345 | { | |
346 | /* Quick exit if we have already computed optabs for this target. */ | |
347 | if (TREE_OPTIMIZATION_BASE_OPTABS (optnode) == this_target_optabs) | |
348 | return; | |
349 | ||
350 | /* Forget any previous information and set up for the current target. */ | |
351 | TREE_OPTIMIZATION_BASE_OPTABS (optnode) = this_target_optabs; | |
352 | struct target_optabs *tmp_optabs = (struct target_optabs *) | |
353 | TREE_OPTIMIZATION_OPTABS (optnode); | |
354 | if (tmp_optabs) | |
355 | memset (tmp_optabs, 0, sizeof (struct target_optabs)); | |
356 | else | |
357 | tmp_optabs = ggc_alloc<target_optabs> (); | |
358 | ||
359 | /* Generate a new set of optabs into tmp_optabs. */ | |
360 | init_all_optabs (tmp_optabs); | |
361 | ||
362 | /* If the optabs changed, record it. */ | |
363 | if (memcmp (tmp_optabs, this_target_optabs, sizeof (struct target_optabs))) | |
364 | TREE_OPTIMIZATION_OPTABS (optnode) = tmp_optabs; | |
365 | else | |
366 | { | |
367 | TREE_OPTIMIZATION_OPTABS (optnode) = NULL; | |
368 | ggc_free (tmp_optabs); | |
369 | } | |
370 | } |