annotate gcc/optabs-query.c @ 16:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16
kono
parents:
diff changeset
1 /* IR-agnostic target query functions relating to optabs
kono
parents:
diff changeset
2 Copyright (C) 1987-2017 Free Software Foundation, Inc.
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 This file is part of GCC.
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 GCC is free software; you can redistribute it and/or modify it under
kono
parents:
diff changeset
7 the terms of the GNU General Public License as published by the Free
kono
parents:
diff changeset
8 Software Foundation; either version 3, or (at your option) any later
kono
parents:
diff changeset
9 version.
kono
parents:
diff changeset
10
kono
parents:
diff changeset
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
kono
parents:
diff changeset
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
kono
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kono
parents:
diff changeset
14 for more details.
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
17 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
18 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20
kono
parents:
diff changeset
21 #include "config.h"
kono
parents:
diff changeset
22 #include "system.h"
kono
parents:
diff changeset
23 #include "coretypes.h"
kono
parents:
diff changeset
24 #include "target.h"
kono
parents:
diff changeset
25 #include "insn-codes.h"
kono
parents:
diff changeset
26 #include "optabs-query.h"
kono
parents:
diff changeset
27 #include "optabs-libfuncs.h"
kono
parents:
diff changeset
28 #include "insn-config.h"
kono
parents:
diff changeset
29 #include "rtl.h"
kono
parents:
diff changeset
30 #include "recog.h"
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 struct target_optabs default_target_optabs;
kono
parents:
diff changeset
33 struct target_optabs *this_fn_optabs = &default_target_optabs;
kono
parents:
diff changeset
34 #if SWITCHABLE_TARGET
kono
parents:
diff changeset
35 struct target_optabs *this_target_optabs = &default_target_optabs;
kono
parents:
diff changeset
36 #endif
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 /* Return the insn used to perform conversion OP from mode FROM_MODE
kono
parents:
diff changeset
39 to mode TO_MODE; return CODE_FOR_nothing if the target does not have
kono
parents:
diff changeset
40 such an insn, or if it is unsuitable for optimization type OPT_TYPE. */
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 insn_code
kono
parents:
diff changeset
43 convert_optab_handler (convert_optab optab, machine_mode to_mode,
kono
parents:
diff changeset
44 machine_mode from_mode, optimization_type opt_type)
kono
parents:
diff changeset
45 {
kono
parents:
diff changeset
46 insn_code icode = convert_optab_handler (optab, to_mode, from_mode);
kono
parents:
diff changeset
47 if (icode == CODE_FOR_nothing
kono
parents:
diff changeset
48 || !targetm.optab_supported_p (optab, to_mode, from_mode, opt_type))
kono
parents:
diff changeset
49 return CODE_FOR_nothing;
kono
parents:
diff changeset
50 return icode;
kono
parents:
diff changeset
51 }
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 /* Return the insn used to implement mode MODE of OP; return
kono
parents:
diff changeset
54 CODE_FOR_nothing if the target does not have such an insn,
kono
parents:
diff changeset
55 or if it is unsuitable for optimization type OPT_TYPE. */
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 insn_code
kono
parents:
diff changeset
58 direct_optab_handler (convert_optab optab, machine_mode mode,
kono
parents:
diff changeset
59 optimization_type opt_type)
kono
parents:
diff changeset
60 {
kono
parents:
diff changeset
61 insn_code icode = direct_optab_handler (optab, mode);
kono
parents:
diff changeset
62 if (icode == CODE_FOR_nothing
kono
parents:
diff changeset
63 || !targetm.optab_supported_p (optab, mode, mode, opt_type))
kono
parents:
diff changeset
64 return CODE_FOR_nothing;
kono
parents:
diff changeset
65 return icode;
kono
parents:
diff changeset
66 }
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 /* Enumerates the possible types of structure operand to an
kono
parents:
diff changeset
69 extraction_insn. */
kono
parents:
diff changeset
70 enum extraction_type { ET_unaligned_mem, ET_reg };
kono
parents:
diff changeset
71
kono
parents:
diff changeset
72 /* Check whether insv, extv or extzv pattern ICODE can be used for an
kono
parents:
diff changeset
73 insertion or extraction of type TYPE on a structure of mode MODE.
kono
parents:
diff changeset
74 Return true if so and fill in *INSN accordingly. STRUCT_OP is the
kono
parents:
diff changeset
75 operand number of the structure (the first sign_extract or zero_extract
kono
parents:
diff changeset
76 operand) and FIELD_OP is the operand number of the field (the other
kono
parents:
diff changeset
77 side of the set from the sign_extract or zero_extract). */
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 static bool
kono
parents:
diff changeset
80 get_traditional_extraction_insn (extraction_insn *insn,
kono
parents:
diff changeset
81 enum extraction_type type,
kono
parents:
diff changeset
82 machine_mode mode,
kono
parents:
diff changeset
83 enum insn_code icode,
kono
parents:
diff changeset
84 int struct_op, int field_op)
kono
parents:
diff changeset
85 {
kono
parents:
diff changeset
86 const struct insn_data_d *data = &insn_data[icode];
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88 machine_mode struct_mode = data->operand[struct_op].mode;
kono
parents:
diff changeset
89 if (struct_mode == VOIDmode)
kono
parents:
diff changeset
90 struct_mode = word_mode;
kono
parents:
diff changeset
91 if (mode != struct_mode)
kono
parents:
diff changeset
92 return false;
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 machine_mode field_mode = data->operand[field_op].mode;
kono
parents:
diff changeset
95 if (field_mode == VOIDmode)
kono
parents:
diff changeset
96 field_mode = word_mode;
kono
parents:
diff changeset
97
kono
parents:
diff changeset
98 machine_mode pos_mode = data->operand[struct_op + 2].mode;
kono
parents:
diff changeset
99 if (pos_mode == VOIDmode)
kono
parents:
diff changeset
100 pos_mode = word_mode;
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102 insn->icode = icode;
kono
parents:
diff changeset
103 insn->field_mode = as_a <scalar_int_mode> (field_mode);
kono
parents:
diff changeset
104 if (type == ET_unaligned_mem)
kono
parents:
diff changeset
105 insn->struct_mode = byte_mode;
kono
parents:
diff changeset
106 else if (struct_mode == BLKmode)
kono
parents:
diff changeset
107 insn->struct_mode = opt_scalar_int_mode ();
kono
parents:
diff changeset
108 else
kono
parents:
diff changeset
109 insn->struct_mode = as_a <scalar_int_mode> (struct_mode);
kono
parents:
diff changeset
110 insn->pos_mode = as_a <scalar_int_mode> (pos_mode);
kono
parents:
diff changeset
111 return true;
kono
parents:
diff changeset
112 }
kono
parents:
diff changeset
113
kono
parents:
diff changeset
114 /* Return true if an optab exists to perform an insertion or extraction
kono
parents:
diff changeset
115 of type TYPE in mode MODE. Describe the instruction in *INSN if so.
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 REG_OPTAB is the optab to use for register structures and
kono
parents:
diff changeset
118 MISALIGN_OPTAB is the optab to use for misaligned memory structures.
kono
parents:
diff changeset
119 POS_OP is the operand number of the bit position. */
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 static bool
kono
parents:
diff changeset
122 get_optab_extraction_insn (struct extraction_insn *insn,
kono
parents:
diff changeset
123 enum extraction_type type,
kono
parents:
diff changeset
124 machine_mode mode, direct_optab reg_optab,
kono
parents:
diff changeset
125 direct_optab misalign_optab, int pos_op)
kono
parents:
diff changeset
126 {
kono
parents:
diff changeset
127 direct_optab optab = (type == ET_unaligned_mem ? misalign_optab : reg_optab);
kono
parents:
diff changeset
128 enum insn_code icode = direct_optab_handler (optab, mode);
kono
parents:
diff changeset
129 if (icode == CODE_FOR_nothing)
kono
parents:
diff changeset
130 return false;
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132 const struct insn_data_d *data = &insn_data[icode];
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134 machine_mode pos_mode = data->operand[pos_op].mode;
kono
parents:
diff changeset
135 if (pos_mode == VOIDmode)
kono
parents:
diff changeset
136 pos_mode = word_mode;
kono
parents:
diff changeset
137
kono
parents:
diff changeset
138 insn->icode = icode;
kono
parents:
diff changeset
139 insn->field_mode = as_a <scalar_int_mode> (mode);
kono
parents:
diff changeset
140 if (type == ET_unaligned_mem)
kono
parents:
diff changeset
141 insn->struct_mode = opt_scalar_int_mode ();
kono
parents:
diff changeset
142 else
kono
parents:
diff changeset
143 insn->struct_mode = insn->field_mode;
kono
parents:
diff changeset
144 insn->pos_mode = as_a <scalar_int_mode> (pos_mode);
kono
parents:
diff changeset
145 return true;
kono
parents:
diff changeset
146 }
kono
parents:
diff changeset
147
kono
parents:
diff changeset
148 /* Return true if an instruction exists to perform an insertion or
kono
parents:
diff changeset
149 extraction (PATTERN says which) of type TYPE in mode MODE.
kono
parents:
diff changeset
150 Describe the instruction in *INSN if so. */
kono
parents:
diff changeset
151
kono
parents:
diff changeset
152 static bool
kono
parents:
diff changeset
153 get_extraction_insn (extraction_insn *insn,
kono
parents:
diff changeset
154 enum extraction_pattern pattern,
kono
parents:
diff changeset
155 enum extraction_type type,
kono
parents:
diff changeset
156 machine_mode mode)
kono
parents:
diff changeset
157 {
kono
parents:
diff changeset
158 switch (pattern)
kono
parents:
diff changeset
159 {
kono
parents:
diff changeset
160 case EP_insv:
kono
parents:
diff changeset
161 if (targetm.have_insv ()
kono
parents:
diff changeset
162 && get_traditional_extraction_insn (insn, type, mode,
kono
parents:
diff changeset
163 targetm.code_for_insv, 0, 3))
kono
parents:
diff changeset
164 return true;
kono
parents:
diff changeset
165 return get_optab_extraction_insn (insn, type, mode, insv_optab,
kono
parents:
diff changeset
166 insvmisalign_optab, 2);
kono
parents:
diff changeset
167
kono
parents:
diff changeset
168 case EP_extv:
kono
parents:
diff changeset
169 if (targetm.have_extv ()
kono
parents:
diff changeset
170 && get_traditional_extraction_insn (insn, type, mode,
kono
parents:
diff changeset
171 targetm.code_for_extv, 1, 0))
kono
parents:
diff changeset
172 return true;
kono
parents:
diff changeset
173 return get_optab_extraction_insn (insn, type, mode, extv_optab,
kono
parents:
diff changeset
174 extvmisalign_optab, 3);
kono
parents:
diff changeset
175
kono
parents:
diff changeset
176 case EP_extzv:
kono
parents:
diff changeset
177 if (targetm.have_extzv ()
kono
parents:
diff changeset
178 && get_traditional_extraction_insn (insn, type, mode,
kono
parents:
diff changeset
179 targetm.code_for_extzv, 1, 0))
kono
parents:
diff changeset
180 return true;
kono
parents:
diff changeset
181 return get_optab_extraction_insn (insn, type, mode, extzv_optab,
kono
parents:
diff changeset
182 extzvmisalign_optab, 3);
kono
parents:
diff changeset
183
kono
parents:
diff changeset
184 default:
kono
parents:
diff changeset
185 gcc_unreachable ();
kono
parents:
diff changeset
186 }
kono
parents:
diff changeset
187 }
kono
parents:
diff changeset
188
kono
parents:
diff changeset
189 /* Return true if an instruction exists to access a field of mode
kono
parents:
diff changeset
190 FIELDMODE in a structure that has STRUCT_BITS significant bits.
kono
parents:
diff changeset
191 Describe the "best" such instruction in *INSN if so. PATTERN and
kono
parents:
diff changeset
192 TYPE describe the type of insertion or extraction we want to perform.
kono
parents:
diff changeset
193
kono
parents:
diff changeset
194 For an insertion, the number of significant structure bits includes
kono
parents:
diff changeset
195 all bits of the target. For an extraction, it need only include the
kono
parents:
diff changeset
196 most significant bit of the field. Larger widths are acceptable
kono
parents:
diff changeset
197 in both cases. */
kono
parents:
diff changeset
198
kono
parents:
diff changeset
199 static bool
kono
parents:
diff changeset
200 get_best_extraction_insn (extraction_insn *insn,
kono
parents:
diff changeset
201 enum extraction_pattern pattern,
kono
parents:
diff changeset
202 enum extraction_type type,
kono
parents:
diff changeset
203 unsigned HOST_WIDE_INT struct_bits,
kono
parents:
diff changeset
204 machine_mode field_mode)
kono
parents:
diff changeset
205 {
kono
parents:
diff changeset
206 opt_scalar_int_mode mode_iter;
kono
parents:
diff changeset
207 FOR_EACH_MODE_FROM (mode_iter, smallest_int_mode_for_size (struct_bits))
kono
parents:
diff changeset
208 {
kono
parents:
diff changeset
209 scalar_int_mode mode = mode_iter.require ();
kono
parents:
diff changeset
210 if (get_extraction_insn (insn, pattern, type, mode))
kono
parents:
diff changeset
211 {
kono
parents:
diff changeset
212 FOR_EACH_MODE_FROM (mode_iter, mode)
kono
parents:
diff changeset
213 {
kono
parents:
diff changeset
214 mode = mode_iter.require ();
kono
parents:
diff changeset
215 if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (field_mode)
kono
parents:
diff changeset
216 || TRULY_NOOP_TRUNCATION_MODES_P (insn->field_mode,
kono
parents:
diff changeset
217 field_mode))
kono
parents:
diff changeset
218 break;
kono
parents:
diff changeset
219 get_extraction_insn (insn, pattern, type, mode);
kono
parents:
diff changeset
220 }
kono
parents:
diff changeset
221 return true;
kono
parents:
diff changeset
222 }
kono
parents:
diff changeset
223 }
kono
parents:
diff changeset
224 return false;
kono
parents:
diff changeset
225 }
kono
parents:
diff changeset
226
kono
parents:
diff changeset
227 /* Return true if an instruction exists to access a field of mode
kono
parents:
diff changeset
228 FIELDMODE in a register structure that has STRUCT_BITS significant bits.
kono
parents:
diff changeset
229 Describe the "best" such instruction in *INSN if so. PATTERN describes
kono
parents:
diff changeset
230 the type of insertion or extraction we want to perform.
kono
parents:
diff changeset
231
kono
parents:
diff changeset
232 For an insertion, the number of significant structure bits includes
kono
parents:
diff changeset
233 all bits of the target. For an extraction, it need only include the
kono
parents:
diff changeset
234 most significant bit of the field. Larger widths are acceptable
kono
parents:
diff changeset
235 in both cases. */
kono
parents:
diff changeset
236
kono
parents:
diff changeset
237 bool
kono
parents:
diff changeset
238 get_best_reg_extraction_insn (extraction_insn *insn,
kono
parents:
diff changeset
239 enum extraction_pattern pattern,
kono
parents:
diff changeset
240 unsigned HOST_WIDE_INT struct_bits,
kono
parents:
diff changeset
241 machine_mode field_mode)
kono
parents:
diff changeset
242 {
kono
parents:
diff changeset
243 return get_best_extraction_insn (insn, pattern, ET_reg, struct_bits,
kono
parents:
diff changeset
244 field_mode);
kono
parents:
diff changeset
245 }
kono
parents:
diff changeset
246
kono
parents:
diff changeset
247 /* Return true if an instruction exists to access a field of BITSIZE
kono
parents:
diff changeset
248 bits starting BITNUM bits into a memory structure. Describe the
kono
parents:
diff changeset
249 "best" such instruction in *INSN if so. PATTERN describes the type
kono
parents:
diff changeset
250 of insertion or extraction we want to perform and FIELDMODE is the
kono
parents:
diff changeset
251 natural mode of the extracted field.
kono
parents:
diff changeset
252
kono
parents:
diff changeset
253 The instructions considered here only access bytes that overlap
kono
parents:
diff changeset
254 the bitfield; they do not touch any surrounding bytes. */
kono
parents:
diff changeset
255
kono
parents:
diff changeset
256 bool
kono
parents:
diff changeset
257 get_best_mem_extraction_insn (extraction_insn *insn,
kono
parents:
diff changeset
258 enum extraction_pattern pattern,
kono
parents:
diff changeset
259 HOST_WIDE_INT bitsize, HOST_WIDE_INT bitnum,
kono
parents:
diff changeset
260 machine_mode field_mode)
kono
parents:
diff changeset
261 {
kono
parents:
diff changeset
262 unsigned HOST_WIDE_INT struct_bits = (bitnum % BITS_PER_UNIT
kono
parents:
diff changeset
263 + bitsize
kono
parents:
diff changeset
264 + BITS_PER_UNIT - 1);
kono
parents:
diff changeset
265 struct_bits -= struct_bits % BITS_PER_UNIT;
kono
parents:
diff changeset
266 return get_best_extraction_insn (insn, pattern, ET_unaligned_mem,
kono
parents:
diff changeset
267 struct_bits, field_mode);
kono
parents:
diff changeset
268 }
kono
parents:
diff changeset
269
kono
parents:
diff changeset
270 /* Return the insn code used to extend FROM_MODE to TO_MODE.
kono
parents:
diff changeset
271 UNSIGNEDP specifies zero-extension instead of sign-extension. If
kono
parents:
diff changeset
272 no such operation exists, CODE_FOR_nothing will be returned. */
kono
parents:
diff changeset
273
kono
parents:
diff changeset
274 enum insn_code
kono
parents:
diff changeset
275 can_extend_p (machine_mode to_mode, machine_mode from_mode,
kono
parents:
diff changeset
276 int unsignedp)
kono
parents:
diff changeset
277 {
kono
parents:
diff changeset
278 if (unsignedp < 0 && targetm.have_ptr_extend ())
kono
parents:
diff changeset
279 return targetm.code_for_ptr_extend;
kono
parents:
diff changeset
280
kono
parents:
diff changeset
281 convert_optab tab = unsignedp ? zext_optab : sext_optab;
kono
parents:
diff changeset
282 return convert_optab_handler (tab, to_mode, from_mode);
kono
parents:
diff changeset
283 }
kono
parents:
diff changeset
284
kono
parents:
diff changeset
285 /* Return the insn code to convert fixed-point mode FIXMODE to floating-point
kono
parents:
diff changeset
286 mode FLTMODE, or CODE_FOR_nothing if no such instruction exists.
kono
parents:
diff changeset
287 UNSIGNEDP specifies whether FIXMODE is unsigned. */
kono
parents:
diff changeset
288
kono
parents:
diff changeset
289 enum insn_code
kono
parents:
diff changeset
290 can_float_p (machine_mode fltmode, machine_mode fixmode,
kono
parents:
diff changeset
291 int unsignedp)
kono
parents:
diff changeset
292 {
kono
parents:
diff changeset
293 convert_optab tab = unsignedp ? ufloat_optab : sfloat_optab;
kono
parents:
diff changeset
294 return convert_optab_handler (tab, fltmode, fixmode);
kono
parents:
diff changeset
295 }
kono
parents:
diff changeset
296
kono
parents:
diff changeset
297 /* Return the insn code to convert floating-point mode FLTMODE to fixed-point
kono
parents:
diff changeset
298 mode FIXMODE, or CODE_FOR_nothing if no such instruction exists.
kono
parents:
diff changeset
299 UNSIGNEDP specifies whether FIXMODE is unsigned.
kono
parents:
diff changeset
300
kono
parents:
diff changeset
301 On a successful return, set *TRUNCP_PTR to true if it is necessary to
kono
parents:
diff changeset
302 output an explicit FTRUNC before the instruction. */
kono
parents:
diff changeset
303
kono
parents:
diff changeset
304 enum insn_code
kono
parents:
diff changeset
305 can_fix_p (machine_mode fixmode, machine_mode fltmode,
kono
parents:
diff changeset
306 int unsignedp, bool *truncp_ptr)
kono
parents:
diff changeset
307 {
kono
parents:
diff changeset
308 convert_optab tab;
kono
parents:
diff changeset
309 enum insn_code icode;
kono
parents:
diff changeset
310
kono
parents:
diff changeset
311 tab = unsignedp ? ufixtrunc_optab : sfixtrunc_optab;
kono
parents:
diff changeset
312 icode = convert_optab_handler (tab, fixmode, fltmode);
kono
parents:
diff changeset
313 if (icode != CODE_FOR_nothing)
kono
parents:
diff changeset
314 {
kono
parents:
diff changeset
315 *truncp_ptr = false;
kono
parents:
diff changeset
316 return icode;
kono
parents:
diff changeset
317 }
kono
parents:
diff changeset
318
kono
parents:
diff changeset
319 /* FIXME: This requires a port to define both FIX and FTRUNC pattern
kono
parents:
diff changeset
320 for this to work. We need to rework the fix* and ftrunc* patterns
kono
parents:
diff changeset
321 and documentation. */
kono
parents:
diff changeset
322 tab = unsignedp ? ufix_optab : sfix_optab;
kono
parents:
diff changeset
323 icode = convert_optab_handler (tab, fixmode, fltmode);
kono
parents:
diff changeset
324 if (icode != CODE_FOR_nothing
kono
parents:
diff changeset
325 && optab_handler (ftrunc_optab, fltmode) != CODE_FOR_nothing)
kono
parents:
diff changeset
326 {
kono
parents:
diff changeset
327 *truncp_ptr = true;
kono
parents:
diff changeset
328 return icode;
kono
parents:
diff changeset
329 }
kono
parents:
diff changeset
330
kono
parents:
diff changeset
331 return CODE_FOR_nothing;
kono
parents:
diff changeset
332 }
kono
parents:
diff changeset
333
kono
parents:
diff changeset
334 /* Return nonzero if a conditional move of mode MODE is supported.
kono
parents:
diff changeset
335
kono
parents:
diff changeset
336 This function is for combine so it can tell whether an insn that looks
kono
parents:
diff changeset
337 like a conditional move is actually supported by the hardware. If we
kono
parents:
diff changeset
338 guess wrong we lose a bit on optimization, but that's it. */
kono
parents:
diff changeset
339 /* ??? sparc64 supports conditionally moving integers values based on fp
kono
parents:
diff changeset
340 comparisons, and vice versa. How do we handle them? */
kono
parents:
diff changeset
341
kono
parents:
diff changeset
342 bool
kono
parents:
diff changeset
343 can_conditionally_move_p (machine_mode mode)
kono
parents:
diff changeset
344 {
kono
parents:
diff changeset
345 return direct_optab_handler (movcc_optab, mode) != CODE_FOR_nothing;
kono
parents:
diff changeset
346 }
kono
parents:
diff changeset
347
kono
parents:
diff changeset
348 /* Return true if VEC_PERM_EXPR of arbitrary input vectors can be
kono
parents:
diff changeset
349 expanded using SIMD extensions of the CPU. SEL may be NULL, which
kono
parents:
diff changeset
350 stands for an unknown constant. Note that additional permutations
kono
parents:
diff changeset
351 representing whole-vector shifts may also be handled via the vec_shr
kono
parents:
diff changeset
352 optab, but only where the second input vector is entirely constant
kono
parents:
diff changeset
353 zeroes; this case is not dealt with here. */
kono
parents:
diff changeset
354
kono
parents:
diff changeset
355 bool
kono
parents:
diff changeset
356 can_vec_perm_p (machine_mode mode, bool variable, vec_perm_indices *sel)
kono
parents:
diff changeset
357 {
kono
parents:
diff changeset
358 machine_mode qimode;
kono
parents:
diff changeset
359
kono
parents:
diff changeset
360 /* If the target doesn't implement a vector mode for the vector type,
kono
parents:
diff changeset
361 then no operations are supported. */
kono
parents:
diff changeset
362 if (!VECTOR_MODE_P (mode))
kono
parents:
diff changeset
363 return false;
kono
parents:
diff changeset
364
kono
parents:
diff changeset
365 if (!variable)
kono
parents:
diff changeset
366 {
kono
parents:
diff changeset
367 if (direct_optab_handler (vec_perm_const_optab, mode) != CODE_FOR_nothing
kono
parents:
diff changeset
368 && (sel == NULL
kono
parents:
diff changeset
369 || targetm.vectorize.vec_perm_const_ok == NULL
kono
parents:
diff changeset
370 || targetm.vectorize.vec_perm_const_ok (mode, *sel)))
kono
parents:
diff changeset
371 return true;
kono
parents:
diff changeset
372 }
kono
parents:
diff changeset
373
kono
parents:
diff changeset
374 if (direct_optab_handler (vec_perm_optab, mode) != CODE_FOR_nothing)
kono
parents:
diff changeset
375 return true;
kono
parents:
diff changeset
376
kono
parents:
diff changeset
377 /* We allow fallback to a QI vector mode, and adjust the mask. */
kono
parents:
diff changeset
378 if (GET_MODE_INNER (mode) == QImode
kono
parents:
diff changeset
379 || !mode_for_vector (QImode, GET_MODE_SIZE (mode)).exists (&qimode)
kono
parents:
diff changeset
380 || !VECTOR_MODE_P (qimode))
kono
parents:
diff changeset
381 return false;
kono
parents:
diff changeset
382
kono
parents:
diff changeset
383 /* ??? For completeness, we ought to check the QImode version of
kono
parents:
diff changeset
384 vec_perm_const_optab. But all users of this implicit lowering
kono
parents:
diff changeset
385 feature implement the variable vec_perm_optab. */
kono
parents:
diff changeset
386 if (direct_optab_handler (vec_perm_optab, qimode) == CODE_FOR_nothing)
kono
parents:
diff changeset
387 return false;
kono
parents:
diff changeset
388
kono
parents:
diff changeset
389 /* In order to support the lowering of variable permutations,
kono
parents:
diff changeset
390 we need to support shifts and adds. */
kono
parents:
diff changeset
391 if (variable)
kono
parents:
diff changeset
392 {
kono
parents:
diff changeset
393 if (GET_MODE_UNIT_SIZE (mode) > 2
kono
parents:
diff changeset
394 && optab_handler (ashl_optab, mode) == CODE_FOR_nothing
kono
parents:
diff changeset
395 && optab_handler (vashl_optab, mode) == CODE_FOR_nothing)
kono
parents:
diff changeset
396 return false;
kono
parents:
diff changeset
397 if (optab_handler (add_optab, qimode) == CODE_FOR_nothing)
kono
parents:
diff changeset
398 return false;
kono
parents:
diff changeset
399 }
kono
parents:
diff changeset
400
kono
parents:
diff changeset
401 return true;
kono
parents:
diff changeset
402 }
kono
parents:
diff changeset
403
kono
parents:
diff changeset
404 /* Like optab_handler, but for widening_operations that have a
kono
parents:
diff changeset
405 TO_MODE and a FROM_MODE. */
kono
parents:
diff changeset
406
kono
parents:
diff changeset
407 enum insn_code
kono
parents:
diff changeset
408 widening_optab_handler (optab op, machine_mode to_mode,
kono
parents:
diff changeset
409 machine_mode from_mode)
kono
parents:
diff changeset
410 {
kono
parents:
diff changeset
411 unsigned scode = (op << 16) | to_mode;
kono
parents:
diff changeset
412 if (to_mode != from_mode && from_mode != VOIDmode)
kono
parents:
diff changeset
413 {
kono
parents:
diff changeset
414 /* ??? Why does find_widening_optab_handler_and_mode attempt to
kono
parents:
diff changeset
415 widen things that can't be widened? E.g. add_optab... */
kono
parents:
diff changeset
416 if (op > LAST_CONV_OPTAB)
kono
parents:
diff changeset
417 return CODE_FOR_nothing;
kono
parents:
diff changeset
418 scode |= from_mode << 8;
kono
parents:
diff changeset
419 }
kono
parents:
diff changeset
420 return raw_optab_handler (scode);
kono
parents:
diff changeset
421 }
kono
parents:
diff changeset
422
kono
parents:
diff changeset
423 /* Find a widening optab even if it doesn't widen as much as we want.
kono
parents:
diff changeset
424 E.g. if from_mode is HImode, and to_mode is DImode, and there is no
kono
parents:
diff changeset
425 direct HI->SI insn, then return SI->DI, if that exists.
kono
parents:
diff changeset
426 If PERMIT_NON_WIDENING is non-zero then this can be used with
kono
parents:
diff changeset
427 non-widening optabs also. */
kono
parents:
diff changeset
428
kono
parents:
diff changeset
429 enum insn_code
kono
parents:
diff changeset
430 find_widening_optab_handler_and_mode (optab op, machine_mode to_mode,
kono
parents:
diff changeset
431 machine_mode from_mode,
kono
parents:
diff changeset
432 int permit_non_widening,
kono
parents:
diff changeset
433 machine_mode *found_mode)
kono
parents:
diff changeset
434 {
kono
parents:
diff changeset
435 for (; (permit_non_widening || from_mode != to_mode)
kono
parents:
diff changeset
436 && GET_MODE_SIZE (from_mode) <= GET_MODE_SIZE (to_mode)
kono
parents:
diff changeset
437 && from_mode != VOIDmode;
kono
parents:
diff changeset
438 from_mode = GET_MODE_WIDER_MODE (from_mode).else_void ())
kono
parents:
diff changeset
439 {
kono
parents:
diff changeset
440 enum insn_code handler = widening_optab_handler (op, to_mode,
kono
parents:
diff changeset
441 from_mode);
kono
parents:
diff changeset
442
kono
parents:
diff changeset
443 if (handler != CODE_FOR_nothing)
kono
parents:
diff changeset
444 {
kono
parents:
diff changeset
445 if (found_mode)
kono
parents:
diff changeset
446 *found_mode = from_mode;
kono
parents:
diff changeset
447 return handler;
kono
parents:
diff changeset
448 }
kono
parents:
diff changeset
449 }
kono
parents:
diff changeset
450
kono
parents:
diff changeset
451 return CODE_FOR_nothing;
kono
parents:
diff changeset
452 }
kono
parents:
diff changeset
453
kono
parents:
diff changeset
454 /* Return non-zero if a highpart multiply is supported of can be synthisized.
kono
parents:
diff changeset
455 For the benefit of expand_mult_highpart, the return value is 1 for direct,
kono
parents:
diff changeset
456 2 for even/odd widening, and 3 for hi/lo widening. */
kono
parents:
diff changeset
457
kono
parents:
diff changeset
458 int
kono
parents:
diff changeset
459 can_mult_highpart_p (machine_mode mode, bool uns_p)
kono
parents:
diff changeset
460 {
kono
parents:
diff changeset
461 optab op;
kono
parents:
diff changeset
462 unsigned i, nunits;
kono
parents:
diff changeset
463
kono
parents:
diff changeset
464 op = uns_p ? umul_highpart_optab : smul_highpart_optab;
kono
parents:
diff changeset
465 if (optab_handler (op, mode) != CODE_FOR_nothing)
kono
parents:
diff changeset
466 return 1;
kono
parents:
diff changeset
467
kono
parents:
diff changeset
468 /* If the mode is an integral vector, synth from widening operations. */
kono
parents:
diff changeset
469 if (GET_MODE_CLASS (mode) != MODE_VECTOR_INT)
kono
parents:
diff changeset
470 return 0;
kono
parents:
diff changeset
471
kono
parents:
diff changeset
472 nunits = GET_MODE_NUNITS (mode);
kono
parents:
diff changeset
473
kono
parents:
diff changeset
474 op = uns_p ? vec_widen_umult_even_optab : vec_widen_smult_even_optab;
kono
parents:
diff changeset
475 if (optab_handler (op, mode) != CODE_FOR_nothing)
kono
parents:
diff changeset
476 {
kono
parents:
diff changeset
477 op = uns_p ? vec_widen_umult_odd_optab : vec_widen_smult_odd_optab;
kono
parents:
diff changeset
478 if (optab_handler (op, mode) != CODE_FOR_nothing)
kono
parents:
diff changeset
479 {
kono
parents:
diff changeset
480 auto_vec_perm_indices sel (nunits);
kono
parents:
diff changeset
481 for (i = 0; i < nunits; ++i)
kono
parents:
diff changeset
482 sel.quick_push (!BYTES_BIG_ENDIAN
kono
parents:
diff changeset
483 + (i & ~1)
kono
parents:
diff changeset
484 + ((i & 1) ? nunits : 0));
kono
parents:
diff changeset
485 if (can_vec_perm_p (mode, false, &sel))
kono
parents:
diff changeset
486 return 2;
kono
parents:
diff changeset
487 }
kono
parents:
diff changeset
488 }
kono
parents:
diff changeset
489
kono
parents:
diff changeset
490 op = uns_p ? vec_widen_umult_hi_optab : vec_widen_smult_hi_optab;
kono
parents:
diff changeset
491 if (optab_handler (op, mode) != CODE_FOR_nothing)
kono
parents:
diff changeset
492 {
kono
parents:
diff changeset
493 op = uns_p ? vec_widen_umult_lo_optab : vec_widen_smult_lo_optab;
kono
parents:
diff changeset
494 if (optab_handler (op, mode) != CODE_FOR_nothing)
kono
parents:
diff changeset
495 {
kono
parents:
diff changeset
496 auto_vec_perm_indices sel (nunits);
kono
parents:
diff changeset
497 for (i = 0; i < nunits; ++i)
kono
parents:
diff changeset
498 sel.quick_push (2 * i + (BYTES_BIG_ENDIAN ? 0 : 1));
kono
parents:
diff changeset
499 if (can_vec_perm_p (mode, false, &sel))
kono
parents:
diff changeset
500 return 3;
kono
parents:
diff changeset
501 }
kono
parents:
diff changeset
502 }
kono
parents:
diff changeset
503
kono
parents:
diff changeset
504 return 0;
kono
parents:
diff changeset
505 }
kono
parents:
diff changeset
506
kono
parents:
diff changeset
507 /* Return true if target supports vector masked load/store for mode. */
kono
parents:
diff changeset
508
kono
parents:
diff changeset
509 bool
kono
parents:
diff changeset
510 can_vec_mask_load_store_p (machine_mode mode,
kono
parents:
diff changeset
511 machine_mode mask_mode,
kono
parents:
diff changeset
512 bool is_load)
kono
parents:
diff changeset
513 {
kono
parents:
diff changeset
514 optab op = is_load ? maskload_optab : maskstore_optab;
kono
parents:
diff changeset
515 machine_mode vmode;
kono
parents:
diff changeset
516 unsigned int vector_sizes;
kono
parents:
diff changeset
517
kono
parents:
diff changeset
518 /* If mode is vector mode, check it directly. */
kono
parents:
diff changeset
519 if (VECTOR_MODE_P (mode))
kono
parents:
diff changeset
520 return convert_optab_handler (op, mode, mask_mode) != CODE_FOR_nothing;
kono
parents:
diff changeset
521
kono
parents:
diff changeset
522 /* Otherwise, return true if there is some vector mode with
kono
parents:
diff changeset
523 the mask load/store supported. */
kono
parents:
diff changeset
524
kono
parents:
diff changeset
525 /* See if there is any chance the mask load or store might be
kono
parents:
diff changeset
526 vectorized. If not, punt. */
kono
parents:
diff changeset
527 scalar_mode smode;
kono
parents:
diff changeset
528 if (!is_a <scalar_mode> (mode, &smode))
kono
parents:
diff changeset
529 return false;
kono
parents:
diff changeset
530
kono
parents:
diff changeset
531 vmode = targetm.vectorize.preferred_simd_mode (smode);
kono
parents:
diff changeset
532 if (!VECTOR_MODE_P (vmode))
kono
parents:
diff changeset
533 return false;
kono
parents:
diff changeset
534
kono
parents:
diff changeset
535 if ((targetm.vectorize.get_mask_mode
kono
parents:
diff changeset
536 (GET_MODE_NUNITS (vmode), GET_MODE_SIZE (vmode)).exists (&mask_mode))
kono
parents:
diff changeset
537 && convert_optab_handler (op, vmode, mask_mode) != CODE_FOR_nothing)
kono
parents:
diff changeset
538 return true;
kono
parents:
diff changeset
539
kono
parents:
diff changeset
540 vector_sizes = targetm.vectorize.autovectorize_vector_sizes ();
kono
parents:
diff changeset
541 while (vector_sizes != 0)
kono
parents:
diff changeset
542 {
kono
parents:
diff changeset
543 unsigned int cur = 1 << floor_log2 (vector_sizes);
kono
parents:
diff changeset
544 vector_sizes &= ~cur;
kono
parents:
diff changeset
545 if (cur <= GET_MODE_SIZE (smode))
kono
parents:
diff changeset
546 continue;
kono
parents:
diff changeset
547 unsigned int nunits = cur / GET_MODE_SIZE (smode);
kono
parents:
diff changeset
548 if (mode_for_vector (smode, nunits).exists (&vmode)
kono
parents:
diff changeset
549 && VECTOR_MODE_P (vmode)
kono
parents:
diff changeset
550 && targetm.vectorize.get_mask_mode (nunits, cur).exists (&mask_mode)
kono
parents:
diff changeset
551 && convert_optab_handler (op, vmode, mask_mode) != CODE_FOR_nothing)
kono
parents:
diff changeset
552 return true;
kono
parents:
diff changeset
553 }
kono
parents:
diff changeset
554 return false;
kono
parents:
diff changeset
555 }
kono
parents:
diff changeset
556
kono
parents:
diff changeset
557 /* Return true if there is a compare_and_swap pattern. */
kono
parents:
diff changeset
558
kono
parents:
diff changeset
559 bool
kono
parents:
diff changeset
560 can_compare_and_swap_p (machine_mode mode, bool allow_libcall)
kono
parents:
diff changeset
561 {
kono
parents:
diff changeset
562 enum insn_code icode;
kono
parents:
diff changeset
563
kono
parents:
diff changeset
564 /* Check for __atomic_compare_and_swap. */
kono
parents:
diff changeset
565 icode = direct_optab_handler (atomic_compare_and_swap_optab, mode);
kono
parents:
diff changeset
566 if (icode != CODE_FOR_nothing)
kono
parents:
diff changeset
567 return true;
kono
parents:
diff changeset
568
kono
parents:
diff changeset
569 /* Check for __sync_compare_and_swap. */
kono
parents:
diff changeset
570 icode = optab_handler (sync_compare_and_swap_optab, mode);
kono
parents:
diff changeset
571 if (icode != CODE_FOR_nothing)
kono
parents:
diff changeset
572 return true;
kono
parents:
diff changeset
573 if (allow_libcall && optab_libfunc (sync_compare_and_swap_optab, mode))
kono
parents:
diff changeset
574 return true;
kono
parents:
diff changeset
575
kono
parents:
diff changeset
576 /* No inline compare and swap. */
kono
parents:
diff changeset
577 return false;
kono
parents:
diff changeset
578 }
kono
parents:
diff changeset
579
kono
parents:
diff changeset
580 /* Return true if an atomic exchange can be performed. */
kono
parents:
diff changeset
581
kono
parents:
diff changeset
582 bool
kono
parents:
diff changeset
583 can_atomic_exchange_p (machine_mode mode, bool allow_libcall)
kono
parents:
diff changeset
584 {
kono
parents:
diff changeset
585 enum insn_code icode;
kono
parents:
diff changeset
586
kono
parents:
diff changeset
587 /* Check for __atomic_exchange. */
kono
parents:
diff changeset
588 icode = direct_optab_handler (atomic_exchange_optab, mode);
kono
parents:
diff changeset
589 if (icode != CODE_FOR_nothing)
kono
parents:
diff changeset
590 return true;
kono
parents:
diff changeset
591
kono
parents:
diff changeset
592 /* Don't check __sync_test_and_set, as on some platforms that
kono
parents:
diff changeset
593 has reduced functionality. Targets that really do support
kono
parents:
diff changeset
594 a proper exchange should simply be updated to the __atomics. */
kono
parents:
diff changeset
595
kono
parents:
diff changeset
596 return can_compare_and_swap_p (mode, allow_libcall);
kono
parents:
diff changeset
597 }
kono
parents:
diff changeset
598
kono
parents:
diff changeset
599 /* Return true if an atomic load can be performed without falling back to
kono
parents:
diff changeset
600 a compare-and-swap. */
kono
parents:
diff changeset
601
kono
parents:
diff changeset
602 bool
kono
parents:
diff changeset
603 can_atomic_load_p (machine_mode mode)
kono
parents:
diff changeset
604 {
kono
parents:
diff changeset
605 enum insn_code icode;
kono
parents:
diff changeset
606
kono
parents:
diff changeset
607 /* Does the target supports the load directly? */
kono
parents:
diff changeset
608 icode = direct_optab_handler (atomic_load_optab, mode);
kono
parents:
diff changeset
609 if (icode != CODE_FOR_nothing)
kono
parents:
diff changeset
610 return true;
kono
parents:
diff changeset
611
kono
parents:
diff changeset
612 /* If the size of the object is greater than word size on this target,
kono
parents:
diff changeset
613 then we assume that a load will not be atomic. Also see
kono
parents:
diff changeset
614 expand_atomic_load. */
kono
parents:
diff changeset
615 return GET_MODE_PRECISION (mode) <= BITS_PER_WORD;
kono
parents:
diff changeset
616 }
kono
parents:
diff changeset
617
kono
parents:
diff changeset
618 /* Determine whether "1 << x" is relatively cheap in word_mode. */
kono
parents:
diff changeset
619
kono
parents:
diff changeset
620 bool
kono
parents:
diff changeset
621 lshift_cheap_p (bool speed_p)
kono
parents:
diff changeset
622 {
kono
parents:
diff changeset
623 /* FIXME: This should be made target dependent via this "this_target"
kono
parents:
diff changeset
624 mechanism, similar to e.g. can_copy_init_p in gcse.c. */
kono
parents:
diff changeset
625 static bool init[2] = { false, false };
kono
parents:
diff changeset
626 static bool cheap[2] = { true, true };
kono
parents:
diff changeset
627
kono
parents:
diff changeset
628 /* If the targer has no lshift in word_mode, the operation will most
kono
parents:
diff changeset
629 probably not be cheap. ??? Does GCC even work for such targets? */
kono
parents:
diff changeset
630 if (optab_handler (ashl_optab, word_mode) == CODE_FOR_nothing)
kono
parents:
diff changeset
631 return false;
kono
parents:
diff changeset
632
kono
parents:
diff changeset
633 if (!init[speed_p])
kono
parents:
diff changeset
634 {
kono
parents:
diff changeset
635 rtx reg = gen_raw_REG (word_mode, 10000);
kono
parents:
diff changeset
636 int cost = set_src_cost (gen_rtx_ASHIFT (word_mode, const1_rtx, reg),
kono
parents:
diff changeset
637 word_mode, speed_p);
kono
parents:
diff changeset
638 cheap[speed_p] = cost < COSTS_N_INSNS (3);
kono
parents:
diff changeset
639 init[speed_p] = true;
kono
parents:
diff changeset
640 }
kono
parents:
diff changeset
641
kono
parents:
diff changeset
642 return cheap[speed_p];
kono
parents:
diff changeset
643 }