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