]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/optabs.h
Refactor expand_vec_perm
[thirdparty/gcc.git] / gcc / optabs.h
CommitLineData
e78d8e51 1/* Definitions for code generation pass of GNU compiler.
cbe34bb5 2 Copyright (C) 2001-2017 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
385399a8
RS
23#include "optabs-query.h"
24#include "optabs-libfuncs.h"
e78d8e51 25
b99279f3 26/* Generate code for a widening multiply. */
ef4bddc2 27extern rtx expand_widening_mult (machine_mode, rtx, rtx, rtx, int, optab);
b99279f3 28
a5c7d693
RS
29/* Describes the type of an expand_operand. Each value is associated
30 with a create_*_operand function; see the comments above those
31 functions for details. */
32enum expand_operand_type {
33 EXPAND_FIXED,
34 EXPAND_OUTPUT,
35 EXPAND_INPUT,
36 EXPAND_CONVERT_TO,
37 EXPAND_CONVERT_FROM,
38 EXPAND_ADDRESS,
39 EXPAND_INTEGER
40};
41
42/* Information about an operand for instruction expansion. */
43struct expand_operand {
44 /* The type of operand. */
45 ENUM_BITFIELD (expand_operand_type) type : 8;
46
47 /* True if any conversion should treat VALUE as being unsigned
48 rather than signed. Only meaningful for certain types. */
49 unsigned int unsigned_p : 1;
50
f96bf49a
JW
51 /* Is the target operand. */
52 unsigned int target : 1;
53
a5c7d693 54 /* Unused; available for future use. */
f96bf49a 55 unsigned int unused : 6;
a5c7d693
RS
56
57 /* The mode passed to the convert_*_operand function. It has a
58 type-dependent meaning. */
59 ENUM_BITFIELD (machine_mode) mode : 16;
60
61 /* The value of the operand. */
62 rtx value;
f8832fe1
RS
63
64 /* The value of an EXPAND_INTEGER operand. */
65 poly_int64 int_value;
a5c7d693
RS
66};
67
68/* Initialize OP with the given fields. Initialise the other fields
69 to their default values. */
70
71static inline void
72create_expand_operand (struct expand_operand *op,
73 enum expand_operand_type type,
ef4bddc2 74 rtx value, machine_mode mode,
f8832fe1 75 bool unsigned_p, poly_int64 int_value = 0)
a5c7d693
RS
76{
77 op->type = type;
78 op->unsigned_p = unsigned_p;
79 op->unused = 0;
80 op->mode = mode;
81 op->value = value;
f8832fe1 82 op->int_value = int_value;
a5c7d693
RS
83}
84
85/* Make OP describe an operand that must use rtx X, even if X is volatile. */
86
87static inline void
88create_fixed_operand (struct expand_operand *op, rtx x)
89{
90 create_expand_operand (op, EXPAND_FIXED, x, VOIDmode, false);
91}
92
93/* Make OP describe an output operand that must have mode MODE.
94 X, if nonnull, is a suggestion for where the output should be stored.
95 It is OK for VALUE to be inconsistent with MODE, although it will just
96 be ignored in that case. */
97
98static inline void
99create_output_operand (struct expand_operand *op, rtx x,
ef4bddc2 100 machine_mode mode)
a5c7d693
RS
101{
102 create_expand_operand (op, EXPAND_OUTPUT, x, mode, false);
103}
104
105/* Make OP describe an input operand that must have mode MODE and
106 value VALUE; MODE cannot be VOIDmode. The backend may request that
107 VALUE be copied into a different kind of rtx before being passed
108 as an operand. */
109
110static inline void
111create_input_operand (struct expand_operand *op, rtx value,
ef4bddc2 112 machine_mode mode)
a5c7d693
RS
113{
114 create_expand_operand (op, EXPAND_INPUT, value, mode, false);
115}
116
117/* Like create_input_operand, except that VALUE must first be converted
118 to mode MODE. UNSIGNED_P says whether VALUE is unsigned. */
119
120static inline void
121create_convert_operand_to (struct expand_operand *op, rtx value,
ef4bddc2 122 machine_mode mode, bool unsigned_p)
a5c7d693
RS
123{
124 create_expand_operand (op, EXPAND_CONVERT_TO, value, mode, unsigned_p);
125}
126
127/* Make OP describe an input operand that should have the same value
128 as VALUE, after any mode conversion that the backend might request.
129 If VALUE is a CONST_INT, it should be treated as having mode MODE.
130 UNSIGNED_P says whether VALUE is unsigned. */
131
132static inline void
133create_convert_operand_from (struct expand_operand *op, rtx value,
ef4bddc2 134 machine_mode mode, bool unsigned_p)
a5c7d693
RS
135{
136 create_expand_operand (op, EXPAND_CONVERT_FROM, value, mode, unsigned_p);
137}
138
a5c7d693
RS
139
140/* Make OP describe an input Pmode address operand. VALUE is the value
141 of the address, but it may need to be converted to Pmode first. */
142
143static inline void
144create_address_operand (struct expand_operand *op, rtx value)
145{
146 create_expand_operand (op, EXPAND_ADDRESS, value, Pmode, false);
147}
148
f8832fe1 149extern void create_integer_operand (struct expand_operand *, poly_int64);
02972eaf 150
b0710fe1
AM
151/* Passed to expand_simple_binop and expand_binop to say which options
152 to try to use if the requested operation can't be open-coded on the
153 requisite mode. Either OPTAB_LIB or OPTAB_LIB_WIDEN says try using
154 a library call. Either OPTAB_WIDEN or OPTAB_LIB_WIDEN says try
155 using a wider mode. OPTAB_MUST_WIDEN says try widening and don't
156 try anything else. */
157
158enum optab_methods
159{
160 OPTAB_DIRECT,
161 OPTAB_LIB,
162 OPTAB_WIDEN,
163 OPTAB_LIB_WIDEN,
164 OPTAB_MUST_WIDEN
165};
166
b0710fe1
AM
167extern rtx expand_widen_pattern_expr (struct separate_ops *, rtx , rtx , rtx,
168 rtx, int);
169extern rtx expand_ternary_op (machine_mode mode, optab ternary_optab,
170 rtx op0, rtx op1, rtx op2, rtx target,
171 int unsignedp);
172extern rtx simplify_expand_binop (machine_mode mode, optab binoptab,
173 rtx op0, rtx op1, rtx target, int unsignedp,
174 enum optab_methods methods);
175extern bool force_expand_binop (machine_mode, optab, rtx, rtx, rtx, int,
176 enum optab_methods);
be4c1d4a 177extern rtx expand_vector_broadcast (machine_mode, rtx);
b0710fe1
AM
178
179/* Generate code for a simple binary or unary operation. "Simple" in
180 this case means "can be unambiguously described by a (mode, code)
181 pair and mapped to a single optab." */
182extern rtx expand_simple_binop (machine_mode, enum rtx_code, rtx,
183 rtx, rtx, int, enum optab_methods);
184
185/* Expand a binary operation given optab and rtx operands. */
186extern rtx expand_binop (machine_mode, optab, rtx, rtx, rtx, int,
187 enum optab_methods);
a5c7d693 188
b0710fe1
AM
189/* Expand a binary operation with both signed and unsigned forms. */
190extern rtx sign_expand_binop (machine_mode, optab, optab, rtx, rtx,
191 rtx, int, enum optab_methods);
192
193/* Generate code to perform an operation on one operand with two results. */
194extern int expand_twoval_unop (optab, rtx, rtx, rtx, int);
195
196/* Generate code to perform an operation on two operands with two results. */
197extern int expand_twoval_binop (optab, rtx, rtx, rtx, rtx, int);
198
199/* Generate code to perform an operation on two operands with two
200 results, using a library function. */
201extern bool expand_twoval_binop_libfunc (optab, rtx, rtx, rtx, rtx,
202 enum rtx_code);
203extern rtx expand_simple_unop (machine_mode, enum rtx_code, rtx, rtx,
204 int);
205
206/* Expand a unary arithmetic operation given optab rtx operand. */
207extern rtx expand_unop (machine_mode, optab, rtx, rtx, int);
208
209/* Expand the absolute value operation. */
210extern rtx expand_abs_nojump (machine_mode, rtx, rtx, int);
211extern rtx expand_abs (machine_mode, rtx, rtx, int, int);
212
213/* Expand the one's complement absolute value operation. */
214extern rtx expand_one_cmpl_abs_nojump (machine_mode, rtx, rtx);
215
216/* Expand the copysign operation. */
217extern rtx expand_copysign (rtx, rtx, rtx);
218/* Generate an instruction with a given INSN_CODE with an output and
219 an input. */
220extern bool maybe_emit_unop_insn (enum insn_code, rtx, rtx, enum rtx_code);
221extern void emit_unop_insn (enum insn_code, rtx, rtx, enum rtx_code);
222
223/* Emit code to make a call to a constant function or a library call. */
f087c773 224extern void emit_libcall_block (rtx_insn *, rtx, rtx, rtx);
b0710fe1
AM
225
226/* The various uses that a comparison can have; used by can_compare_p:
227 jumps, conditional moves, store flag operations. */
228enum can_compare_purpose
229{
230 ccp_jump,
231 ccp_cmov,
232 ccp_store_flag
233};
234
235/* Nonzero if a compare of mode MODE can be done straightforwardly
236 (without splitting it into pieces). */
237extern int can_compare_p (enum rtx_code, machine_mode,
238 enum can_compare_purpose);
ef4bddc2
RS
239extern rtx prepare_operand (enum insn_code, rtx, int, machine_mode,
240 machine_mode, int);
b0710fe1
AM
241/* Emit a pair of rtl insns to compare two rtx's and to jump
242 to a label if the comparison is true. */
243extern void emit_cmp_and_jump_insns (rtx, rtx, enum rtx_code, rtx,
357067f2
JH
244 machine_mode, int, rtx,
245 profile_probability prob
246 = profile_probability::uninitialized ());
b0710fe1
AM
247
248/* Generate code to indirectly jump to a location given in the rtx LOC. */
249extern void emit_indirect_jump (rtx);
250
251#include "insn-config.h"
252
253#ifndef GCC_INSN_CONFIG_H
254#error "insn-config.h must be included before optabs.h"
255#endif
256
b0710fe1
AM
257/* Emit a conditional move operation. */
258rtx emit_conditional_move (rtx, enum rtx_code, rtx, rtx, machine_mode,
259 rtx, rtx, machine_mode, int);
260
ce68b5cf
KT
261/* Emit a conditional negate or bitwise complement operation. */
262rtx emit_conditional_neg_or_complement (rtx, rtx_code, machine_mode, rtx,
263 rtx, rtx);
264
b0710fe1
AM
265rtx emit_conditional_add (rtx, enum rtx_code, rtx, rtx, machine_mode,
266 rtx, rtx, machine_mode, int);
267
268/* Create but don't emit one rtl instruction to perform certain operations.
269 Modes must match; operands must meet the operation's predicates.
270 Likewise for subtraction and for just copying. */
e67d1102
RS
271extern rtx_insn *gen_add2_insn (rtx, rtx);
272extern rtx_insn *gen_add3_insn (rtx, rtx, rtx);
b0710fe1 273extern int have_add2_insn (rtx, rtx);
e67d1102 274extern rtx_insn *gen_addptr3_insn (rtx, rtx, rtx);
b0710fe1 275extern int have_addptr3_insn (rtx, rtx, rtx);
e67d1102
RS
276extern rtx_insn *gen_sub2_insn (rtx, rtx);
277extern rtx_insn *gen_sub3_insn (rtx, rtx, rtx);
b0710fe1
AM
278extern int have_sub2_insn (rtx, rtx);
279
b0710fe1
AM
280/* Generate the body of an insn to extend Y (with mode MFROM)
281 into X (with mode MTO). Do zero-extension if UNSIGNEDP is nonzero. */
e67d1102 282extern rtx_insn *gen_extend_insn (rtx, rtx, machine_mode, machine_mode, int);
b0710fe1 283
b0710fe1
AM
284/* Generate code for a FLOAT_EXPR. */
285extern void expand_float (rtx, rtx, int);
286
287/* Generate code for a FIX_EXPR. */
288extern void expand_fix (rtx, rtx, int);
289
290/* Generate code for a FIXED_CONVERT_EXPR. */
291extern void expand_fixed_convert (rtx, rtx, int, int);
292
293/* Generate code for float to integral conversion. */
294extern bool expand_sfix_optab (rtx, rtx, convert_optab);
295
296/* Report whether the machine description contains an insn which can
297 perform the operation described by CODE and MODE. */
298extern int have_insn_for (enum rtx_code, machine_mode);
2ef6ce06 299
b0710fe1 300/* Generate a conditional trap instruction. */
e67d1102 301extern rtx_insn *gen_cond_trap (enum rtx_code, rtx, rtx, rtx);
b0710fe1 302
b0710fe1
AM
303/* Generate code for VEC_PERM_EXPR. */
304extern rtx expand_vec_perm (machine_mode, rtx, rtx, rtx, rtx);
305
42fd8198
IE
306/* Generate code for vector comparison. */
307extern rtx expand_vec_cmp_expr (tree, tree, rtx);
308
b0710fe1
AM
309/* Generate code for VEC_COND_EXPR. */
310extern rtx expand_vec_cond_expr (tree, tree, tree, tree, rtx);
311
9adab579
RS
312/* Generate code for VEC_SERIES_EXPR. */
313extern rtx expand_vec_series_expr (machine_mode, rtx, rtx, rtx);
314
b0710fe1
AM
315/* Generate code for MULT_HIGHPART_EXPR. */
316extern rtx expand_mult_highpart (machine_mode, rtx, rtx, rtx, bool);
317
b0710fe1
AM
318extern rtx expand_sync_lock_test_and_set (rtx, rtx, rtx);
319extern rtx expand_atomic_test_and_set (rtx, rtx, enum memmodel);
320extern rtx expand_atomic_exchange (rtx, rtx, rtx, enum memmodel);
321extern bool expand_atomic_compare_and_swap (rtx *, rtx *, rtx, rtx, rtx, bool,
322 enum memmodel, enum memmodel);
323/* Generate memory barriers. */
324extern void expand_mem_thread_fence (enum memmodel);
325extern void expand_mem_signal_fence (enum memmodel);
326
327rtx expand_atomic_load (rtx, rtx, enum memmodel);
328rtx expand_atomic_store (rtx, rtx, enum memmodel, bool);
329rtx expand_atomic_fetch_op (rtx, rtx, rtx, enum rtx_code, enum memmodel,
330 bool);
331
332extern bool insn_operand_matches (enum insn_code icode, unsigned int opno,
333 rtx operand);
334extern bool valid_multiword_target_p (rtx);
335extern void create_convert_operand_from_type (struct expand_operand *op,
336 rtx value, tree type);
337extern bool maybe_legitimize_operands (enum insn_code icode,
338 unsigned int opno, unsigned int nops,
339 struct expand_operand *ops);
1476d1bd
MM
340extern rtx_insn *maybe_gen_insn (enum insn_code icode, unsigned int nops,
341 struct expand_operand *ops);
b0710fe1
AM
342extern bool maybe_expand_insn (enum insn_code icode, unsigned int nops,
343 struct expand_operand *ops);
344extern bool maybe_expand_jump_insn (enum insn_code icode, unsigned int nops,
345 struct expand_operand *ops);
346extern void expand_insn (enum insn_code icode, unsigned int nops,
347 struct expand_operand *ops);
348extern void expand_jump_insn (enum insn_code icode, unsigned int nops,
349 struct expand_operand *ops);
350
2d52a3a1
ZC
351extern enum rtx_code get_rtx_code (enum tree_code tcode, bool unsignedp);
352
e78d8e51 353#endif /* GCC_OPTABS_H */