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