MAINTAINERS (Write After Approval): Add myself.
[platform/upstream/gcc.git] / gcc / optabs.h
1 /* Definitions for code generation pass of GNU compiler.
2    Copyright (C) 2001-2016 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 "optabs-query.h"
24 #include "optabs-libfuncs.h"
25
26 /* Generate code for a widening multiply.  */
27 extern rtx expand_widening_mult (machine_mode, rtx, rtx, rtx, int, optab);
28
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
40 };
41
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;
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
51   /* Unused; available for future use.  */
52   unsigned int unused : 7;
53
54   /* The mode passed to the convert_*_operand function.  It has a
55      type-dependent meaning.  */
56   ENUM_BITFIELD (machine_mode) mode : 16;
57
58   /* The value of the operand.  */
59   rtx value;
60 };
61
62 /* Initialize OP with the given fields.  Initialise the other fields
63    to their default values.  */
64
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)
70 {
71   op->type = type;
72   op->unsigned_p = unsigned_p;
73   op->unused = 0;
74   op->mode = mode;
75   op->value = value;
76 }
77
78 /* Make OP describe an operand that must use rtx X, even if X is volatile.  */
79
80 static inline void
81 create_fixed_operand (struct expand_operand *op, rtx x)
82 {
83   create_expand_operand (op, EXPAND_FIXED, x, VOIDmode, false);
84 }
85
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.  */
90
91 static inline void
92 create_output_operand (struct expand_operand *op, rtx x,
93                        machine_mode mode)
94 {
95   create_expand_operand (op, EXPAND_OUTPUT, x, mode, false);
96 }
97
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.  */
102
103 static inline void
104 create_input_operand (struct expand_operand *op, rtx value,
105                       machine_mode mode)
106 {
107   create_expand_operand (op, EXPAND_INPUT, value, mode, false);
108 }
109
110 /* Like create_input_operand, except that VALUE must first be converted
111    to mode MODE.  UNSIGNED_P says whether VALUE is unsigned.  */
112
113 static inline void
114 create_convert_operand_to (struct expand_operand *op, rtx value,
115                            machine_mode mode, bool unsigned_p)
116 {
117   create_expand_operand (op, EXPAND_CONVERT_TO, value, mode, unsigned_p);
118 }
119
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.  */
124
125 static inline void
126 create_convert_operand_from (struct expand_operand *op, rtx value,
127                              machine_mode mode, bool unsigned_p)
128 {
129   create_expand_operand (op, EXPAND_CONVERT_FROM, value, mode, unsigned_p);
130 }
131
132
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.  */
135
136 static inline void
137 create_address_operand (struct expand_operand *op, rtx value)
138 {
139   create_expand_operand (op, EXPAND_ADDRESS, value, Pmode, false);
140 }
141
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.  */
147
148 static inline void
149 create_integer_operand (struct expand_operand *op, HOST_WIDE_INT intval)
150 {
151   create_expand_operand (op, EXPAND_INTEGER, GEN_INT (intval), VOIDmode, false);
152 }
153
154
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.  */
161
162 enum optab_methods
163 {
164   OPTAB_DIRECT,
165   OPTAB_LIB,
166   OPTAB_WIDEN,
167   OPTAB_LIB_WIDEN,
168   OPTAB_MUST_WIDEN
169 };
170
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);
181
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);
187
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);
191
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);
195
196 /* Generate code to perform an operation on one operand with two results.  */
197 extern int expand_twoval_unop (optab, rtx, rtx, rtx, int);
198
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);
201
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);
208
209 /* Expand a unary arithmetic operation given optab rtx operand.  */
210 extern rtx expand_unop (machine_mode, optab, rtx, rtx, int);
211
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);
215
216 /* Expand the one's complement absolute value operation.  */
217 extern rtx expand_one_cmpl_abs_nojump (machine_mode, rtx, rtx);
218
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);
225
226 /* Emit code to make a call to a constant function or a library call.  */
227 extern void emit_libcall_block (rtx, rtx, rtx, rtx);
228
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
232 {
233   ccp_jump,
234   ccp_cmov,
235   ccp_store_flag
236 };
237
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);
248
249 /* Generate code to indirectly jump to a location given in the rtx LOC.  */
250 extern void emit_indirect_jump (rtx);
251
252 #include "insn-config.h"
253
254 #ifndef GCC_INSN_CONFIG_H
255 #error "insn-config.h must be included before optabs.h"
256 #endif
257
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);
261
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);
265
266 rtx emit_conditional_add (rtx, enum rtx_code, rtx, rtx, machine_mode,
267                           rtx, rtx, machine_mode, int);
268
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);
280
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);
284
285 /* Generate code for a FLOAT_EXPR.  */
286 extern void expand_float (rtx, rtx, int);
287
288 /* Generate code for a FIX_EXPR.  */
289 extern void expand_fix (rtx, rtx, int);
290
291 /* Generate code for a FIXED_CONVERT_EXPR.  */
292 extern void expand_fixed_convert (rtx, rtx, int, int);
293
294 /* Generate code for float to integral conversion.  */
295 extern bool expand_sfix_optab (rtx, rtx, convert_optab);
296
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);
300
301 /* Generate a conditional trap instruction.  */
302 extern rtx_insn *gen_cond_trap (enum rtx_code, rtx, rtx, rtx);
303
304 /* Generate code for VEC_PERM_EXPR.  */
305 extern rtx expand_vec_perm (machine_mode, rtx, rtx, rtx, rtx);
306
307 /* Generate code for vector comparison.  */
308 extern rtx expand_vec_cmp_expr (tree, tree, rtx);
309
310 /* Generate code for VEC_COND_EXPR.  */
311 extern rtx expand_vec_cond_expr (tree, tree, tree, tree, rtx);
312
313 /* Generate code for MULT_HIGHPART_EXPR.  */
314 extern rtx expand_mult_highpart (machine_mode, rtx, rtx, rtx, bool);
315
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);
324
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);
329
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);
348
349 extern enum rtx_code get_rtx_code (enum tree_code tcode, bool unsignedp);
350
351 #endif /* GCC_OPTABS_H */