]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/optabs.h
gcc/ada/
[thirdparty/gcc.git] / gcc / optabs.h
1 /* Definitions for code generation pass of GNU compiler.
2 Copyright (C) 2001-2014 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
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
10
11 GCC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License 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 #ifndef GCC_OPTABS_H
21 #define GCC_OPTABS_H
22
23 #include "insn-codes.h"
24 #include "insn-opinit.h"
25
26 typedef enum optab_tag optab;
27 typedef enum optab_tag convert_optab;
28 typedef enum optab_tag direct_optab;
29
30 struct optab_libcall_d
31 {
32 char libcall_suffix;
33 const char *libcall_basename;
34 void (*libcall_gen) (optab, const char *name,
35 char suffix, machine_mode);
36 };
37
38 struct convert_optab_libcall_d
39 {
40 const char *libcall_basename;
41 void (*libcall_gen) (convert_optab, const char *name,
42 machine_mode, machine_mode);
43 };
44
45 /* Given an enum insn_code, access the function to construct
46 the body of that kind of insn. */
47 #define GEN_FCN(CODE) (insn_data[CODE].genfun)
48
49 /* Contains the optab used for each rtx code, and vice-versa. */
50 extern const optab code_to_optab_[NUM_RTX_CODE];
51 extern const enum rtx_code optab_to_code_[NUM_OPTABS];
52
53 static inline optab
54 code_to_optab (enum rtx_code code)
55 {
56 return code_to_optab_[code];
57 }
58
59 static inline enum rtx_code
60 optab_to_code (optab op)
61 {
62 return optab_to_code_[op];
63 }
64
65 extern const struct convert_optab_libcall_d convlib_def[NUM_CONVLIB_OPTABS];
66 extern const struct optab_libcall_d normlib_def[NUM_NORMLIB_OPTABS];
67
68 /* Returns the active icode for the given (encoded) optab. */
69 extern enum insn_code raw_optab_handler (unsigned);
70 extern bool swap_optab_enable (optab, machine_mode, bool);
71
72 /* Target-dependent globals. */
73 struct target_optabs {
74 /* Patterns that are used by optabs that are enabled for this target. */
75 bool pat_enable[NUM_OPTAB_PATTERNS];
76 };
77
78 extern struct target_optabs default_target_optabs;
79 extern struct target_optabs *this_fn_optabs;
80 #if SWITCHABLE_TARGET
81 extern struct target_optabs *this_target_optabs;
82 #else
83 #define this_target_optabs (&default_target_optabs)
84 #endif
85 \f
86 /* Define functions given in optabs.c. */
87
88 extern rtx expand_widen_pattern_expr (sepops ops, rtx op0, rtx op1, rtx wide_op,
89 rtx target, int unsignedp);
90
91 extern rtx expand_ternary_op (machine_mode mode, optab ternary_optab,
92 rtx op0, rtx op1, rtx op2, rtx target,
93 int unsignedp);
94
95 /* Expand a binary operation given optab and rtx operands. */
96 extern rtx expand_binop (machine_mode, optab, rtx, rtx, rtx, int,
97 enum optab_methods);
98
99 extern rtx simplify_expand_binop (machine_mode mode, optab binoptab,
100 rtx op0, rtx op1, rtx target, int unsignedp,
101 enum optab_methods methods);
102
103 extern bool force_expand_binop (machine_mode, optab, rtx, rtx, rtx, int,
104 enum optab_methods);
105
106 /* Expand a binary operation with both signed and unsigned forms. */
107 extern rtx sign_expand_binop (machine_mode, optab, optab, rtx, rtx,
108 rtx, int, enum optab_methods);
109
110 /* Generate code to perform an operation on one operand with two results. */
111 extern int expand_twoval_unop (optab, rtx, rtx, rtx, int);
112
113 /* Generate code to perform an operation on two operands with two results. */
114 extern int expand_twoval_binop (optab, rtx, rtx, rtx, rtx, int);
115
116 /* Generate code to perform an operation on two operands with two
117 results, using a library function. */
118 extern bool expand_twoval_binop_libfunc (optab, rtx, rtx, rtx, rtx,
119 enum rtx_code);
120
121 /* Expand a unary arithmetic operation given optab rtx operand. */
122 extern rtx expand_unop (machine_mode, optab, rtx, rtx, int);
123
124 /* Expand the absolute value operation. */
125 extern rtx expand_abs_nojump (machine_mode, rtx, rtx, int);
126 extern rtx expand_abs (machine_mode, rtx, rtx, int, int);
127
128 /* Expand the one's complement absolute value operation. */
129 extern rtx expand_one_cmpl_abs_nojump (machine_mode, rtx, rtx);
130
131 /* Expand the copysign operation. */
132 extern rtx expand_copysign (rtx, rtx, rtx);
133
134 /* Generate an instruction with a given INSN_CODE with an output and
135 an input. */
136 extern void emit_unop_insn (enum insn_code, rtx, rtx, enum rtx_code);
137 extern bool maybe_emit_unop_insn (enum insn_code, rtx, rtx, enum rtx_code);
138
139 /* Find a widening optab even if it doesn't widen as much as we want. */
140 #define find_widening_optab_handler(A,B,C,D) \
141 find_widening_optab_handler_and_mode (A, B, C, D, NULL)
142 extern enum insn_code find_widening_optab_handler_and_mode (optab,
143 machine_mode,
144 machine_mode,
145 int,
146 machine_mode *);
147 extern enum insn_code widening_optab_handler (optab, machine_mode,
148 machine_mode);
149
150 /* An extra flag to control optab_for_tree_code's behavior. This is needed to
151 distinguish between machines with a vector shift that takes a scalar for the
152 shift amount vs. machines that take a vector for the shift amount. */
153 enum optab_subtype
154 {
155 optab_default,
156 optab_scalar,
157 optab_vector
158 };
159
160 /* Return the optab used for computing the given operation on the type given by
161 the second argument. The third argument distinguishes between the types of
162 vector shifts and rotates */
163 extern optab optab_for_tree_code (enum tree_code, const_tree, enum optab_subtype);
164
165 /* Given an optab that reduces a vector to a scalar, find instead the old
166 optab that produces a vector with the reduction result in one element,
167 for a tree with the specified type. */
168 extern optab scalar_reduc_to_vector (optab, const_tree type);
169
170 /* The various uses that a comparison can have; used by can_compare_p:
171 jumps, conditional moves, store flag operations. */
172 enum can_compare_purpose
173 {
174 ccp_jump,
175 ccp_cmov,
176 ccp_store_flag
177 };
178
179 /* Nonzero if a compare of mode MODE can be done straightforwardly
180 (without splitting it into pieces). */
181 extern int can_compare_p (enum rtx_code, machine_mode,
182 enum can_compare_purpose);
183
184 /* Return the INSN_CODE to use for an extend operation. */
185 extern enum insn_code can_extend_p (machine_mode, machine_mode, int);
186
187 /* Generate the body of an insn to extend Y (with mode MFROM)
188 into X (with mode MTO). Do zero-extension if UNSIGNEDP is nonzero. */
189 extern rtx gen_extend_insn (rtx, rtx, machine_mode,
190 machine_mode, int);
191
192 /* Call this to reset the function entry for one optab. */
193 extern void set_optab_libfunc (optab, machine_mode, const char *);
194 extern void set_conv_libfunc (convert_optab, machine_mode,
195 machine_mode, const char *);
196
197 /* Call this to install all of the __sync libcalls up to size MAX. */
198 extern void init_sync_libfuncs (int max);
199
200 /* Generate code for a FIXED_CONVERT_EXPR. */
201 extern void expand_fixed_convert (rtx, rtx, int, int);
202
203 /* Generate code for a FLOAT_EXPR. */
204 extern void expand_float (rtx, rtx, int);
205
206 /* Return the insn_code for a FLOAT_EXPR. */
207 enum insn_code can_float_p (machine_mode, machine_mode, int);
208
209 /* Return true if there is an inline compare and swap pattern. */
210 extern bool can_compare_and_swap_p (machine_mode, bool);
211
212 /* Return true if there is an inline atomic exchange pattern. */
213 extern bool can_atomic_exchange_p (machine_mode, bool);
214
215 /* Generate code for a compare and swap. */
216 extern bool expand_atomic_compare_and_swap (rtx *, rtx *, rtx, rtx, rtx, bool,
217 enum memmodel, enum memmodel);
218
219 /* Generate memory barriers. */
220 extern void expand_mem_thread_fence (enum memmodel);
221 extern void expand_mem_signal_fence (enum memmodel);
222
223 /* Check whether an operation represented by the code CODE is a
224 convert operation that is supported by the target platform in
225 vector form */
226 bool supportable_convert_operation (enum tree_code, tree, tree, tree *,
227 enum tree_code *);
228
229 /* Generate code for a FIX_EXPR. */
230 extern void expand_fix (rtx, rtx, int);
231
232 /* Generate code for float to integral conversion. */
233 extern bool expand_sfix_optab (rtx, rtx, convert_optab);
234
235 /* Generate code for a widening multiply. */
236 extern rtx expand_widening_mult (machine_mode, rtx, rtx, rtx, int, optab);
237
238 /* Return tree if target supports vector operations for COND_EXPR. */
239 bool expand_vec_cond_expr_p (tree, tree);
240
241 /* Generate code for VEC_COND_EXPR. */
242 extern rtx expand_vec_cond_expr (tree, tree, tree, tree, rtx);
243 /* Generate code for VEC_RSHIFT_EXPR. */
244 extern rtx expand_vec_shift_expr (sepops, rtx);
245
246 /* Return true if target supports vector operations for VEC_PERM_EXPR. */
247 extern bool can_vec_perm_p (machine_mode, bool, const unsigned char *);
248
249 /* Generate code for VEC_PERM_EXPR. */
250 extern rtx expand_vec_perm (machine_mode, rtx, rtx, rtx, rtx);
251
252 /* Return non-zero if target supports a given highpart multiplication. */
253 extern int can_mult_highpart_p (machine_mode, bool);
254
255 /* Generate code for MULT_HIGHPART_EXPR. */
256 extern rtx expand_mult_highpart (machine_mode, rtx, rtx, rtx, bool);
257
258 /* Return true if target supports vector masked load/store for mode. */
259 extern bool can_vec_mask_load_store_p (machine_mode, bool);
260
261 /* Return the insn used to implement mode MODE of OP, or CODE_FOR_nothing
262 if the target does not have such an insn. */
263
264 static inline enum insn_code
265 optab_handler (optab op, machine_mode mode)
266 {
267 unsigned scode = (op << 16) | mode;
268 gcc_assert (op > LAST_CONV_OPTAB);
269 return raw_optab_handler (scode);
270 }
271
272 /* Return the insn used to perform conversion OP from mode FROM_MODE
273 to mode TO_MODE; return CODE_FOR_nothing if the target does not have
274 such an insn. */
275
276 static inline enum insn_code
277 convert_optab_handler (convert_optab op, machine_mode to_mode,
278 machine_mode from_mode)
279 {
280 unsigned scode = (op << 16) | (from_mode << 8) | to_mode;
281 gcc_assert (op > unknown_optab && op <= LAST_CONV_OPTAB);
282 return raw_optab_handler (scode);
283 }
284
285 /* Return the insn used to implement mode MODE of OP, or CODE_FOR_nothing
286 if the target does not have such an insn. */
287
288 static inline enum insn_code
289 direct_optab_handler (direct_optab op, machine_mode mode)
290 {
291 return optab_handler (op, mode);
292 }
293
294 /* Return true if UNOPTAB is for a trapping-on-overflow operation. */
295
296 static inline bool
297 trapv_unoptab_p (optab unoptab)
298 {
299 return (unoptab == negv_optab
300 || unoptab == absv_optab);
301 }
302
303 /* Return true if BINOPTAB is for a trapping-on-overflow operation. */
304
305 static inline bool
306 trapv_binoptab_p (optab binoptab)
307 {
308 return (binoptab == addv_optab
309 || binoptab == subv_optab
310 || binoptab == smulv_optab);
311 }
312
313 extern rtx optab_libfunc (optab optab, machine_mode mode);
314 extern rtx convert_optab_libfunc (convert_optab optab, machine_mode mode1,
315 machine_mode mode2);
316
317 /* Describes an instruction that inserts or extracts a bitfield. */
318 struct extraction_insn
319 {
320 /* The code of the instruction. */
321 enum insn_code icode;
322
323 /* The mode that the structure operand should have. This is byte_mode
324 when using the legacy insv, extv and extzv patterns to access memory. */
325 machine_mode struct_mode;
326
327 /* The mode of the field to be inserted or extracted, and by extension
328 the mode of the insertion or extraction itself. */
329 machine_mode field_mode;
330
331 /* The mode of the field's bit position. This is only important
332 when the position is variable rather than constant. */
333 machine_mode pos_mode;
334 };
335
336 /* Enumerates the possible extraction_insn operations. */
337 enum extraction_pattern { EP_insv, EP_extv, EP_extzv };
338
339 extern bool get_best_reg_extraction_insn (extraction_insn *,
340 enum extraction_pattern,
341 unsigned HOST_WIDE_INT,
342 machine_mode);
343
344 extern bool get_best_mem_extraction_insn (extraction_insn *,
345 enum extraction_pattern,
346 HOST_WIDE_INT, HOST_WIDE_INT,
347 machine_mode);
348
349 extern bool insn_operand_matches (enum insn_code icode, unsigned int opno,
350 rtx operand);
351
352 /* Describes the type of an expand_operand. Each value is associated
353 with a create_*_operand function; see the comments above those
354 functions for details. */
355 enum expand_operand_type {
356 EXPAND_FIXED,
357 EXPAND_OUTPUT,
358 EXPAND_INPUT,
359 EXPAND_CONVERT_TO,
360 EXPAND_CONVERT_FROM,
361 EXPAND_ADDRESS,
362 EXPAND_INTEGER
363 };
364
365 /* Information about an operand for instruction expansion. */
366 struct expand_operand {
367 /* The type of operand. */
368 ENUM_BITFIELD (expand_operand_type) type : 8;
369
370 /* True if any conversion should treat VALUE as being unsigned
371 rather than signed. Only meaningful for certain types. */
372 unsigned int unsigned_p : 1;
373
374 /* Unused; available for future use. */
375 unsigned int unused : 7;
376
377 /* The mode passed to the convert_*_operand function. It has a
378 type-dependent meaning. */
379 ENUM_BITFIELD (machine_mode) mode : 16;
380
381 /* The value of the operand. */
382 rtx value;
383 };
384
385 /* Initialize OP with the given fields. Initialise the other fields
386 to their default values. */
387
388 static inline void
389 create_expand_operand (struct expand_operand *op,
390 enum expand_operand_type type,
391 rtx value, machine_mode mode,
392 bool unsigned_p)
393 {
394 op->type = type;
395 op->unsigned_p = unsigned_p;
396 op->unused = 0;
397 op->mode = mode;
398 op->value = value;
399 }
400
401 /* Make OP describe an operand that must use rtx X, even if X is volatile. */
402
403 static inline void
404 create_fixed_operand (struct expand_operand *op, rtx x)
405 {
406 create_expand_operand (op, EXPAND_FIXED, x, VOIDmode, false);
407 }
408
409 /* Make OP describe an output operand that must have mode MODE.
410 X, if nonnull, is a suggestion for where the output should be stored.
411 It is OK for VALUE to be inconsistent with MODE, although it will just
412 be ignored in that case. */
413
414 static inline void
415 create_output_operand (struct expand_operand *op, rtx x,
416 machine_mode mode)
417 {
418 create_expand_operand (op, EXPAND_OUTPUT, x, mode, false);
419 }
420
421 /* Make OP describe an input operand that must have mode MODE and
422 value VALUE; MODE cannot be VOIDmode. The backend may request that
423 VALUE be copied into a different kind of rtx before being passed
424 as an operand. */
425
426 static inline void
427 create_input_operand (struct expand_operand *op, rtx value,
428 machine_mode mode)
429 {
430 create_expand_operand (op, EXPAND_INPUT, value, mode, false);
431 }
432
433 /* Like create_input_operand, except that VALUE must first be converted
434 to mode MODE. UNSIGNED_P says whether VALUE is unsigned. */
435
436 static inline void
437 create_convert_operand_to (struct expand_operand *op, rtx value,
438 machine_mode mode, bool unsigned_p)
439 {
440 create_expand_operand (op, EXPAND_CONVERT_TO, value, mode, unsigned_p);
441 }
442
443 /* Make OP describe an input operand that should have the same value
444 as VALUE, after any mode conversion that the backend might request.
445 If VALUE is a CONST_INT, it should be treated as having mode MODE.
446 UNSIGNED_P says whether VALUE is unsigned. */
447
448 static inline void
449 create_convert_operand_from (struct expand_operand *op, rtx value,
450 machine_mode mode, bool unsigned_p)
451 {
452 create_expand_operand (op, EXPAND_CONVERT_FROM, value, mode, unsigned_p);
453 }
454
455 extern void create_convert_operand_from_type (struct expand_operand *op,
456 rtx value, tree type);
457
458 /* Make OP describe an input Pmode address operand. VALUE is the value
459 of the address, but it may need to be converted to Pmode first. */
460
461 static inline void
462 create_address_operand (struct expand_operand *op, rtx value)
463 {
464 create_expand_operand (op, EXPAND_ADDRESS, value, Pmode, false);
465 }
466
467 /* Make OP describe an input operand that has value INTVAL and that has
468 no inherent mode. This function should only be used for operands that
469 are always expand-time constants. The backend may request that INTVAL
470 be copied into a different kind of rtx, but it must specify the mode
471 of that rtx if so. */
472
473 static inline void
474 create_integer_operand (struct expand_operand *op, HOST_WIDE_INT intval)
475 {
476 create_expand_operand (op, EXPAND_INTEGER, GEN_INT (intval), VOIDmode, false);
477 }
478
479 extern bool valid_multiword_target_p (rtx);
480
481 extern bool maybe_legitimize_operands (enum insn_code icode,
482 unsigned int opno, unsigned int nops,
483 struct expand_operand *ops);
484 extern rtx maybe_gen_insn (enum insn_code icode, unsigned int nops,
485 struct expand_operand *ops);
486 extern bool maybe_expand_insn (enum insn_code icode, unsigned int nops,
487 struct expand_operand *ops);
488 extern bool maybe_expand_jump_insn (enum insn_code icode, unsigned int nops,
489 struct expand_operand *ops);
490 extern void expand_insn (enum insn_code icode, unsigned int nops,
491 struct expand_operand *ops);
492 extern void expand_jump_insn (enum insn_code icode, unsigned int nops,
493 struct expand_operand *ops);
494
495 extern rtx prepare_operand (enum insn_code, rtx, int, machine_mode,
496 machine_mode, int);
497
498 extern void gen_int_libfunc (optab, const char *, char, machine_mode);
499 extern void gen_fp_libfunc (optab, const char *, char, machine_mode);
500 extern void gen_fixed_libfunc (optab, const char *, char, machine_mode);
501 extern void gen_signed_fixed_libfunc (optab, const char *, char,
502 machine_mode);
503 extern void gen_unsigned_fixed_libfunc (optab, const char *, char,
504 machine_mode);
505 extern void gen_int_fp_libfunc (optab, const char *, char, machine_mode);
506 extern void gen_intv_fp_libfunc (optab, const char *, char, machine_mode);
507 extern void gen_int_fp_fixed_libfunc (optab, const char *, char,
508 machine_mode);
509 extern void gen_int_fp_signed_fixed_libfunc (optab, const char *, char,
510 machine_mode);
511 extern void gen_int_fixed_libfunc (optab, const char *, char,
512 machine_mode);
513 extern void gen_int_signed_fixed_libfunc (optab, const char *, char,
514 machine_mode);
515 extern void gen_int_unsigned_fixed_libfunc (optab, const char *, char,
516 machine_mode);
517
518 extern void gen_interclass_conv_libfunc (convert_optab, const char *,
519 machine_mode, machine_mode);
520 extern void gen_int_to_fp_conv_libfunc (convert_optab, const char *,
521 machine_mode, machine_mode);
522 extern void gen_ufloat_conv_libfunc (convert_optab, const char *,
523 machine_mode, machine_mode);
524 extern void gen_int_to_fp_nondecimal_conv_libfunc (convert_optab,
525 const char *,
526 machine_mode,
527 machine_mode);
528 extern void gen_fp_to_int_conv_libfunc (convert_optab, const char *,
529 machine_mode, machine_mode);
530 extern void gen_intraclass_conv_libfunc (convert_optab, const char *,
531 machine_mode, machine_mode);
532 extern void gen_trunc_conv_libfunc (convert_optab, const char *,
533 machine_mode, machine_mode);
534 extern void gen_extend_conv_libfunc (convert_optab, const char *,
535 machine_mode, machine_mode);
536 extern void gen_fract_conv_libfunc (convert_optab, const char *,
537 machine_mode, machine_mode);
538 extern void gen_fractuns_conv_libfunc (convert_optab, const char *,
539 machine_mode, machine_mode);
540 extern void gen_satfract_conv_libfunc (convert_optab, const char *,
541 machine_mode, machine_mode);
542 extern void gen_satfractuns_conv_libfunc (convert_optab, const char *,
543 machine_mode,
544 machine_mode);
545 extern void init_tree_optimization_optabs (tree);
546 extern bool lshift_cheap_p (bool);
547
548 #endif /* GCC_OPTABS_H */