2017-02-01 Bill Schmidt <wschmidt@linux.vnet.ibm.com>
[official-gcc.git] / gcc / optabs.h
blobb2dd31acd068c089c0fec4d8909882cdc3e83fe2
1 /* Definitions for code generation pass of GNU compiler.
2 Copyright (C) 2001-2017 Free Software Foundation, Inc.
4 This file is part of GCC.
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.
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.
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/>. */
20 #ifndef GCC_OPTABS_H
21 #define GCC_OPTABS_H
23 #include "optabs-query.h"
24 #include "optabs-libfuncs.h"
26 /* Generate code for a widening multiply. */
27 extern rtx expand_widening_mult (machine_mode, rtx, rtx, rtx, int, optab);
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. */
32 enum 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
42 /* Information about an operand for instruction expansion. */
43 struct expand_operand {
44 /* The type of operand. */
45 ENUM_BITFIELD (expand_operand_type) type : 8;
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;
51 /* Unused; available for future use. */
52 unsigned int unused : 7;
54 /* The mode passed to the convert_*_operand function. It has a
55 type-dependent meaning. */
56 ENUM_BITFIELD (machine_mode) mode : 16;
58 /* The value of the operand. */
59 rtx value;
62 /* Initialize OP with the given fields. Initialise the other fields
63 to their default values. */
65 static inline void
66 create_expand_operand (struct expand_operand *op,
67 enum expand_operand_type type,
68 rtx value, machine_mode mode,
69 bool unsigned_p)
71 op->type = type;
72 op->unsigned_p = unsigned_p;
73 op->unused = 0;
74 op->mode = mode;
75 op->value = value;
78 /* Make OP describe an operand that must use rtx X, even if X is volatile. */
80 static inline void
81 create_fixed_operand (struct expand_operand *op, rtx x)
83 create_expand_operand (op, EXPAND_FIXED, x, VOIDmode, false);
86 /* Make OP describe an output operand that must have mode MODE.
87 X, if nonnull, is a suggestion for where the output should be stored.
88 It is OK for VALUE to be inconsistent with MODE, although it will just
89 be ignored in that case. */
91 static inline void
92 create_output_operand (struct expand_operand *op, rtx x,
93 machine_mode mode)
95 create_expand_operand (op, EXPAND_OUTPUT, x, mode, false);
98 /* Make OP describe an input operand that must have mode MODE and
99 value VALUE; MODE cannot be VOIDmode. The backend may request that
100 VALUE be copied into a different kind of rtx before being passed
101 as an operand. */
103 static inline void
104 create_input_operand (struct expand_operand *op, rtx value,
105 machine_mode mode)
107 create_expand_operand (op, EXPAND_INPUT, value, mode, false);
110 /* Like create_input_operand, except that VALUE must first be converted
111 to mode MODE. UNSIGNED_P says whether VALUE is unsigned. */
113 static inline void
114 create_convert_operand_to (struct expand_operand *op, rtx value,
115 machine_mode mode, bool unsigned_p)
117 create_expand_operand (op, EXPAND_CONVERT_TO, value, mode, unsigned_p);
120 /* Make OP describe an input operand that should have the same value
121 as VALUE, after any mode conversion that the backend might request.
122 If VALUE is a CONST_INT, it should be treated as having mode MODE.
123 UNSIGNED_P says whether VALUE is unsigned. */
125 static inline void
126 create_convert_operand_from (struct expand_operand *op, rtx value,
127 machine_mode mode, bool unsigned_p)
129 create_expand_operand (op, EXPAND_CONVERT_FROM, value, mode, unsigned_p);
133 /* Make OP describe an input Pmode address operand. VALUE is the value
134 of the address, but it may need to be converted to Pmode first. */
136 static inline void
137 create_address_operand (struct expand_operand *op, rtx value)
139 create_expand_operand (op, EXPAND_ADDRESS, value, Pmode, false);
142 /* Make OP describe an input operand that has value INTVAL and that has
143 no inherent mode. This function should only be used for operands that
144 are always expand-time constants. The backend may request that INTVAL
145 be copied into a different kind of rtx, but it must specify the mode
146 of that rtx if so. */
148 static inline void
149 create_integer_operand (struct expand_operand *op, HOST_WIDE_INT intval)
151 create_expand_operand (op, EXPAND_INTEGER, GEN_INT (intval), VOIDmode, false);
155 /* Passed to expand_simple_binop and expand_binop to say which options
156 to try to use if the requested operation can't be open-coded on the
157 requisite mode. Either OPTAB_LIB or OPTAB_LIB_WIDEN says try using
158 a library call. Either OPTAB_WIDEN or OPTAB_LIB_WIDEN says try
159 using a wider mode. OPTAB_MUST_WIDEN says try widening and don't
160 try anything else. */
162 enum optab_methods
164 OPTAB_DIRECT,
165 OPTAB_LIB,
166 OPTAB_WIDEN,
167 OPTAB_LIB_WIDEN,
168 OPTAB_MUST_WIDEN
171 extern rtx expand_widen_pattern_expr (struct separate_ops *, rtx , rtx , rtx,
172 rtx, int);
173 extern rtx expand_ternary_op (machine_mode mode, optab ternary_optab,
174 rtx op0, rtx op1, rtx op2, rtx target,
175 int unsignedp);
176 extern rtx simplify_expand_binop (machine_mode mode, optab binoptab,
177 rtx op0, rtx op1, rtx target, int unsignedp,
178 enum optab_methods methods);
179 extern bool force_expand_binop (machine_mode, optab, rtx, rtx, rtx, int,
180 enum optab_methods);
182 /* Generate code for a simple binary or unary operation. "Simple" in
183 this case means "can be unambiguously described by a (mode, code)
184 pair and mapped to a single optab." */
185 extern rtx expand_simple_binop (machine_mode, enum rtx_code, rtx,
186 rtx, rtx, int, enum optab_methods);
188 /* Expand a binary operation given optab and rtx operands. */
189 extern rtx expand_binop (machine_mode, optab, rtx, rtx, rtx, int,
190 enum optab_methods);
192 /* Expand a binary operation with both signed and unsigned forms. */
193 extern rtx sign_expand_binop (machine_mode, optab, optab, rtx, rtx,
194 rtx, int, enum optab_methods);
196 /* Generate code to perform an operation on one operand with two results. */
197 extern int expand_twoval_unop (optab, rtx, rtx, rtx, int);
199 /* Generate code to perform an operation on two operands with two results. */
200 extern int expand_twoval_binop (optab, rtx, rtx, rtx, rtx, int);
202 /* Generate code to perform an operation on two operands with two
203 results, using a library function. */
204 extern bool expand_twoval_binop_libfunc (optab, rtx, rtx, rtx, rtx,
205 enum rtx_code);
206 extern rtx expand_simple_unop (machine_mode, enum rtx_code, rtx, rtx,
207 int);
209 /* Expand a unary arithmetic operation given optab rtx operand. */
210 extern rtx expand_unop (machine_mode, optab, rtx, rtx, int);
212 /* Expand the absolute value operation. */
213 extern rtx expand_abs_nojump (machine_mode, rtx, rtx, int);
214 extern rtx expand_abs (machine_mode, rtx, rtx, int, int);
216 /* Expand the one's complement absolute value operation. */
217 extern rtx expand_one_cmpl_abs_nojump (machine_mode, rtx, rtx);
219 /* Expand the copysign operation. */
220 extern rtx expand_copysign (rtx, rtx, rtx);
221 /* Generate an instruction with a given INSN_CODE with an output and
222 an input. */
223 extern bool maybe_emit_unop_insn (enum insn_code, rtx, rtx, enum rtx_code);
224 extern void emit_unop_insn (enum insn_code, rtx, rtx, enum rtx_code);
226 /* Emit code to make a call to a constant function or a library call. */
227 extern void emit_libcall_block (rtx_insn *, rtx, rtx, rtx);
229 /* The various uses that a comparison can have; used by can_compare_p:
230 jumps, conditional moves, store flag operations. */
231 enum can_compare_purpose
233 ccp_jump,
234 ccp_cmov,
235 ccp_store_flag
238 /* Nonzero if a compare of mode MODE can be done straightforwardly
239 (without splitting it into pieces). */
240 extern int can_compare_p (enum rtx_code, machine_mode,
241 enum can_compare_purpose);
242 extern rtx prepare_operand (enum insn_code, rtx, int, machine_mode,
243 machine_mode, int);
244 /* Emit a pair of rtl insns to compare two rtx's and to jump
245 to a label if the comparison is true. */
246 extern void emit_cmp_and_jump_insns (rtx, rtx, enum rtx_code, rtx,
247 machine_mode, int, rtx, int prob=-1);
249 /* Generate code to indirectly jump to a location given in the rtx LOC. */
250 extern void emit_indirect_jump (rtx);
252 #include "insn-config.h"
254 #ifndef GCC_INSN_CONFIG_H
255 #error "insn-config.h must be included before optabs.h"
256 #endif
258 /* Emit a conditional move operation. */
259 rtx emit_conditional_move (rtx, enum rtx_code, rtx, rtx, machine_mode,
260 rtx, rtx, machine_mode, int);
262 /* Emit a conditional negate or bitwise complement operation. */
263 rtx emit_conditional_neg_or_complement (rtx, rtx_code, machine_mode, rtx,
264 rtx, rtx);
266 rtx emit_conditional_add (rtx, enum rtx_code, rtx, rtx, machine_mode,
267 rtx, rtx, machine_mode, int);
269 /* Create but don't emit one rtl instruction to perform certain operations.
270 Modes must match; operands must meet the operation's predicates.
271 Likewise for subtraction and for just copying. */
272 extern rtx_insn *gen_add2_insn (rtx, rtx);
273 extern rtx_insn *gen_add3_insn (rtx, rtx, rtx);
274 extern int have_add2_insn (rtx, rtx);
275 extern rtx_insn *gen_addptr3_insn (rtx, rtx, rtx);
276 extern int have_addptr3_insn (rtx, rtx, rtx);
277 extern rtx_insn *gen_sub2_insn (rtx, rtx);
278 extern rtx_insn *gen_sub3_insn (rtx, rtx, rtx);
279 extern int have_sub2_insn (rtx, rtx);
281 /* Generate the body of an insn to extend Y (with mode MFROM)
282 into X (with mode MTO). Do zero-extension if UNSIGNEDP is nonzero. */
283 extern rtx_insn *gen_extend_insn (rtx, rtx, machine_mode, machine_mode, int);
285 /* Generate code for a FLOAT_EXPR. */
286 extern void expand_float (rtx, rtx, int);
288 /* Generate code for a FIX_EXPR. */
289 extern void expand_fix (rtx, rtx, int);
291 /* Generate code for a FIXED_CONVERT_EXPR. */
292 extern void expand_fixed_convert (rtx, rtx, int, int);
294 /* Generate code for float to integral conversion. */
295 extern bool expand_sfix_optab (rtx, rtx, convert_optab);
297 /* Report whether the machine description contains an insn which can
298 perform the operation described by CODE and MODE. */
299 extern int have_insn_for (enum rtx_code, machine_mode);
301 /* Generate a conditional trap instruction. */
302 extern rtx_insn *gen_cond_trap (enum rtx_code, rtx, rtx, rtx);
304 /* Generate code for VEC_PERM_EXPR. */
305 extern rtx expand_vec_perm (machine_mode, rtx, rtx, rtx, rtx);
307 /* Generate code for vector comparison. */
308 extern rtx expand_vec_cmp_expr (tree, tree, rtx);
310 /* Generate code for VEC_COND_EXPR. */
311 extern rtx expand_vec_cond_expr (tree, tree, tree, tree, rtx);
313 /* Generate code for MULT_HIGHPART_EXPR. */
314 extern rtx expand_mult_highpart (machine_mode, rtx, rtx, rtx, bool);
316 extern rtx expand_sync_lock_test_and_set (rtx, rtx, rtx);
317 extern rtx expand_atomic_test_and_set (rtx, rtx, enum memmodel);
318 extern rtx expand_atomic_exchange (rtx, rtx, rtx, enum memmodel);
319 extern bool expand_atomic_compare_and_swap (rtx *, rtx *, rtx, rtx, rtx, bool,
320 enum memmodel, enum memmodel);
321 /* Generate memory barriers. */
322 extern void expand_mem_thread_fence (enum memmodel);
323 extern void expand_mem_signal_fence (enum memmodel);
325 rtx expand_atomic_load (rtx, rtx, enum memmodel);
326 rtx expand_atomic_store (rtx, rtx, enum memmodel, bool);
327 rtx expand_atomic_fetch_op (rtx, rtx, rtx, enum rtx_code, enum memmodel,
328 bool);
330 extern bool insn_operand_matches (enum insn_code icode, unsigned int opno,
331 rtx operand);
332 extern bool valid_multiword_target_p (rtx);
333 extern void create_convert_operand_from_type (struct expand_operand *op,
334 rtx value, tree type);
335 extern bool maybe_legitimize_operands (enum insn_code icode,
336 unsigned int opno, unsigned int nops,
337 struct expand_operand *ops);
338 extern rtx_insn *maybe_gen_insn (enum insn_code icode, unsigned int nops,
339 struct expand_operand *ops);
340 extern bool maybe_expand_insn (enum insn_code icode, unsigned int nops,
341 struct expand_operand *ops);
342 extern bool maybe_expand_jump_insn (enum insn_code icode, unsigned int nops,
343 struct expand_operand *ops);
344 extern void expand_insn (enum insn_code icode, unsigned int nops,
345 struct expand_operand *ops);
346 extern void expand_jump_insn (enum insn_code icode, unsigned int nops,
347 struct expand_operand *ops);
349 extern enum rtx_code get_rtx_code (enum tree_code tcode, bool unsignedp);
351 #endif /* GCC_OPTABS_H */