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