Home | History | Annotate | Line # | Download | only in gcc
optabs.h revision 1.1.1.2
      1 /* Definitions for code generation pass of GNU compiler.
      2    Copyright (C) 2001-2013 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 "insn-codes.h"
     24 #include "insn-opinit.h"
     25 
     26 typedef enum optab_tag optab;
     27 typedef enum optab_tag convert_optab;
     28 typedef enum optab_tag direct_optab;
     29 
     30 struct optab_libcall_d
     31 {
     32   char libcall_suffix;
     33   const char *libcall_basename;
     34   void (*libcall_gen) (optab, const char *name,
     35 		       char suffix, enum machine_mode);
     36 };
     37 
     38 struct convert_optab_libcall_d
     39 {
     40   const char *libcall_basename;
     41   void (*libcall_gen) (convert_optab, const char *name,
     42 		       enum machine_mode, enum machine_mode);
     43 };
     44 
     45 /* Given an enum insn_code, access the function to construct
     46    the body of that kind of insn.  */
     47 #define GEN_FCN(CODE) (insn_data[CODE].genfun)
     48 
     49 /* Contains the optab used for each rtx code, and vice-versa.  */
     50 extern const optab code_to_optab_[NUM_RTX_CODE];
     51 extern const enum rtx_code optab_to_code_[NUM_OPTABS];
     52 
     53 static inline optab
     54 code_to_optab (enum rtx_code code)
     55 {
     56   return code_to_optab_[code];
     57 }
     58 
     59 static inline enum rtx_code
     60 optab_to_code (optab op)
     61 {
     62   return optab_to_code_[op];
     63 }
     64 
     65 extern const struct convert_optab_libcall_d convlib_def[NUM_CONVLIB_OPTABS];
     66 extern const struct optab_libcall_d normlib_def[NUM_NORMLIB_OPTABS];
     67 
     68 /* Returns the active icode for the given (encoded) optab.  */
     69 extern enum insn_code raw_optab_handler (unsigned);
     70 extern bool swap_optab_enable (optab, enum machine_mode, bool);
     71 
     72 /* Target-dependent globals.  */
     73 struct target_optabs {
     74   /* Patterns that are used by optabs that are enabled for this target.  */
     75   bool pat_enable[NUM_OPTAB_PATTERNS];
     76 };
     77 
     78 extern struct target_optabs default_target_optabs;
     79 extern struct target_optabs *this_fn_optabs;
     80 #if SWITCHABLE_TARGET
     81 extern struct target_optabs *this_target_optabs;
     82 #else
     83 #define this_target_optabs (&default_target_optabs)
     84 #endif
     85 
     86 /* Define functions given in optabs.c.  */
     88 
     89 extern rtx expand_widen_pattern_expr (sepops ops, rtx op0, rtx op1, rtx wide_op,
     90                                       rtx target, int unsignedp);
     91 
     92 extern rtx expand_ternary_op (enum machine_mode mode, optab ternary_optab,
     93 			      rtx op0, rtx op1, rtx op2, rtx target,
     94 			      int unsignedp);
     95 
     96 /* Expand a binary operation given optab and rtx operands.  */
     97 extern rtx expand_binop (enum machine_mode, optab, rtx, rtx, rtx, int,
     98 			 enum optab_methods);
     99 
    100 extern rtx simplify_expand_binop (enum machine_mode mode, optab binoptab,
    101 				  rtx op0, rtx op1, rtx target, int unsignedp,
    102 				  enum optab_methods methods);
    103 
    104 extern bool force_expand_binop (enum machine_mode, optab, rtx, rtx, rtx, int,
    105 				enum optab_methods);
    106 
    107 /* Expand a binary operation with both signed and unsigned forms.  */
    108 extern rtx sign_expand_binop (enum machine_mode, optab, optab, rtx, rtx,
    109 			      rtx, int, enum optab_methods);
    110 
    111 /* Generate code to perform an operation on one operand with two results.  */
    112 extern int expand_twoval_unop (optab, rtx, rtx, rtx, int);
    113 
    114 /* Generate code to perform an operation on two operands with two results.  */
    115 extern int expand_twoval_binop (optab, rtx, rtx, rtx, rtx, int);
    116 
    117 /* Generate code to perform an operation on two operands with two
    118    results, using a library function.  */
    119 extern bool expand_twoval_binop_libfunc (optab, rtx, rtx, rtx, rtx,
    120 					 enum rtx_code);
    121 
    122 /* Expand a unary arithmetic operation given optab rtx operand.  */
    123 extern rtx expand_unop (enum machine_mode, optab, rtx, rtx, int);
    124 
    125 /* Expand the absolute value operation.  */
    126 extern rtx expand_abs_nojump (enum machine_mode, rtx, rtx, int);
    127 extern rtx expand_abs (enum machine_mode, rtx, rtx, int, int);
    128 
    129 /* Expand the one's complement absolute value operation.  */
    130 extern rtx expand_one_cmpl_abs_nojump (enum machine_mode, rtx, rtx);
    131 
    132 /* Expand the copysign operation.  */
    133 extern rtx expand_copysign (rtx, rtx, rtx);
    134 
    135 /* Generate an instruction with a given INSN_CODE with an output and
    136    an input.  */
    137 extern void emit_unop_insn (enum insn_code, rtx, rtx, enum rtx_code);
    138 extern bool maybe_emit_unop_insn (enum insn_code, rtx, rtx, enum rtx_code);
    139 
    140 /* Find a widening optab even if it doesn't widen as much as we want.  */
    141 #define find_widening_optab_handler(A,B,C,D) \
    142   find_widening_optab_handler_and_mode (A, B, C, D, NULL)
    143 extern enum insn_code find_widening_optab_handler_and_mode (optab,
    144 							    enum machine_mode,
    145 							    enum machine_mode,
    146 							    int,
    147 							    enum machine_mode *);
    148 
    149 /* An extra flag to control optab_for_tree_code's behavior.  This is needed to
    150    distinguish between machines with a vector shift that takes a scalar for the
    151    shift amount vs. machines that take a vector for the shift amount.  */
    152 enum optab_subtype
    153 {
    154   optab_default,
    155   optab_scalar,
    156   optab_vector
    157 };
    158 
    159 /* Return the optab used for computing the given operation on the type given by
    160    the second argument.  The third argument distinguishes between the types of
    161    vector shifts and rotates */
    162 extern optab optab_for_tree_code (enum tree_code, const_tree, enum optab_subtype);
    163 
    164 /* The various uses that a comparison can have; used by can_compare_p:
    165    jumps, conditional moves, store flag operations.  */
    166 enum can_compare_purpose
    167 {
    168   ccp_jump,
    169   ccp_cmov,
    170   ccp_store_flag
    171 };
    172 
    173 /* Nonzero if a compare of mode MODE can be done straightforwardly
    174    (without splitting it into pieces).  */
    175 extern int can_compare_p (enum rtx_code, enum machine_mode,
    176 			  enum can_compare_purpose);
    177 
    178 /* Return the INSN_CODE to use for an extend operation.  */
    179 extern enum insn_code can_extend_p (enum machine_mode, enum machine_mode, int);
    180 
    181 /* Generate the body of an insn to extend Y (with mode MFROM)
    182    into X (with mode MTO).  Do zero-extension if UNSIGNEDP is nonzero.  */
    183 extern rtx gen_extend_insn (rtx, rtx, enum machine_mode,
    184 			    enum machine_mode, int);
    185 
    186 /* Call this to reset the function entry for one optab.  */
    187 extern void set_optab_libfunc (optab, enum machine_mode, const char *);
    188 extern void set_conv_libfunc (convert_optab, enum machine_mode,
    189 			      enum machine_mode, const char *);
    190 
    191 /* Call this to install all of the __sync libcalls up to size MAX.  */
    192 extern void init_sync_libfuncs (int max);
    193 
    194 /* Generate code for a FIXED_CONVERT_EXPR.  */
    195 extern void expand_fixed_convert (rtx, rtx, int, int);
    196 
    197 /* Generate code for a FLOAT_EXPR.  */
    198 extern void expand_float (rtx, rtx, int);
    199 
    200 /* Return the insn_code for a FLOAT_EXPR.  */
    201 enum insn_code can_float_p (enum machine_mode, enum machine_mode, int);
    202 
    203 /* Return true if there is an inline compare and swap pattern.  */
    204 extern bool can_compare_and_swap_p (enum machine_mode, bool);
    205 
    206 /* Return true if there is an inline atomic exchange pattern.  */
    207 extern bool can_atomic_exchange_p (enum machine_mode, bool);
    208 
    209 /* Generate code for a compare and swap.  */
    210 extern bool expand_atomic_compare_and_swap (rtx *, rtx *, rtx, rtx, rtx, bool,
    211 					    enum memmodel, enum memmodel);
    212 
    213 /* Generate memory barriers.  */
    214 extern void expand_mem_thread_fence (enum memmodel);
    215 extern void expand_mem_signal_fence (enum memmodel);
    216 
    217 /* Check whether an operation represented by the code CODE is a
    218    convert operation that is supported by the target platform in
    219    vector form */
    220 bool supportable_convert_operation (enum tree_code, tree, tree, tree *,
    221                                     enum tree_code *);
    222 
    223 /* Generate code for a FIX_EXPR.  */
    224 extern void expand_fix (rtx, rtx, int);
    225 
    226 /* Generate code for float to integral conversion.  */
    227 extern bool expand_sfix_optab (rtx, rtx, convert_optab);
    228 
    229 /* Generate code for a widening multiply.  */
    230 extern rtx expand_widening_mult (enum machine_mode, rtx, rtx, rtx, int, optab);
    231 
    232 /* Return tree if target supports vector operations for COND_EXPR.  */
    233 bool expand_vec_cond_expr_p (tree, tree);
    234 
    235 /* Generate code for VEC_COND_EXPR.  */
    236 extern rtx expand_vec_cond_expr (tree, tree, tree, tree, rtx);
    237 /* Generate code for VEC_LSHIFT_EXPR and VEC_RSHIFT_EXPR.  */
    238 extern rtx expand_vec_shift_expr (sepops, rtx);
    239 
    240 /* Return tree if target supports vector operations for VEC_PERM_EXPR.  */
    241 extern bool can_vec_perm_p (enum machine_mode, bool, const unsigned char *);
    242 
    243 /* Generate code for VEC_PERM_EXPR.  */
    244 extern rtx expand_vec_perm (enum machine_mode, rtx, rtx, rtx, rtx);
    245 
    246 /* Return non-zero if target supports a given highpart multiplication.  */
    247 extern int can_mult_highpart_p (enum machine_mode, bool);
    248 
    249 /* Generate code for MULT_HIGHPART_EXPR.  */
    250 extern rtx expand_mult_highpart (enum machine_mode, rtx, rtx, rtx, bool);
    251 
    252 /* Return the insn used to implement mode MODE of OP, or CODE_FOR_nothing
    253    if the target does not have such an insn.  */
    254 
    255 static inline enum insn_code
    256 optab_handler (optab op, enum machine_mode mode)
    257 {
    258   unsigned scode = (op << 16) | mode;
    259   gcc_assert (op > LAST_CONV_OPTAB);
    260   return raw_optab_handler (scode);
    261 }
    262 
    263 /* Return the insn used to perform conversion OP from mode FROM_MODE
    264    to mode TO_MODE; return CODE_FOR_nothing if the target does not have
    265    such an insn.  */
    266 
    267 static inline enum insn_code
    268 convert_optab_handler (convert_optab op, enum machine_mode to_mode,
    269 		       enum machine_mode from_mode)
    270 {
    271   unsigned scode = (op << 16) | (from_mode << 8) | to_mode;
    272   gcc_assert (op > unknown_optab && op <= LAST_CONV_OPTAB);
    273   return raw_optab_handler (scode);
    274 }
    275 
    276 /* Like optab_handler, but for widening_operations that have a
    277    TO_MODE and a FROM_MODE.  */
    278 
    279 static inline enum insn_code
    280 widening_optab_handler (optab op, enum machine_mode to_mode,
    281 			enum machine_mode from_mode)
    282 {
    283   unsigned scode = (op << 16) | to_mode;
    284   if (to_mode != from_mode && from_mode != VOIDmode)
    285     {
    286       /* ??? Why does find_widening_optab_handler_and_mode attempt to
    287 	 widen things that can't be widened?  E.g. add_optab... */
    288       if (op > LAST_CONV_OPTAB)
    289 	return CODE_FOR_nothing;
    290       scode |= from_mode << 8;
    291     }
    292   return raw_optab_handler (scode);
    293 }
    294 
    295 /* Return the insn used to implement mode MODE of OP, or CODE_FOR_nothing
    296    if the target does not have such an insn.  */
    297 
    298 static inline enum insn_code
    299 direct_optab_handler (direct_optab op, enum machine_mode mode)
    300 {
    301   return optab_handler (op, mode);
    302 }
    303 
    304 /* Return true if UNOPTAB is for a trapping-on-overflow operation.  */
    305 
    306 static inline bool
    307 trapv_unoptab_p (optab unoptab)
    308 {
    309   return (unoptab == negv_optab
    310 	  || unoptab == absv_optab);
    311 }
    312 
    313 /* Return true if BINOPTAB is for a trapping-on-overflow operation.  */
    314 
    315 static inline bool
    316 trapv_binoptab_p (optab binoptab)
    317 {
    318   return (binoptab == addv_optab
    319 	  || binoptab == subv_optab
    320 	  || binoptab == smulv_optab);
    321 }
    322 
    323 extern rtx optab_libfunc (optab optab, enum machine_mode mode);
    324 extern rtx convert_optab_libfunc (convert_optab optab, enum machine_mode mode1,
    325 			          enum machine_mode mode2);
    326 
    327 /* Describes an instruction that inserts or extracts a bitfield.  */
    328 struct extraction_insn
    329 {
    330   /* The code of the instruction.  */
    331   enum insn_code icode;
    332 
    333   /* The mode that the structure operand should have.  This is byte_mode
    334      when using the legacy insv, extv and extzv patterns to access memory.  */
    335   enum machine_mode struct_mode;
    336 
    337   /* The mode of the field to be inserted or extracted, and by extension
    338      the mode of the insertion or extraction itself.  */
    339   enum machine_mode field_mode;
    340 
    341   /* The mode of the field's bit position.  This is only important
    342      when the position is variable rather than constant.  */
    343   enum machine_mode pos_mode;
    344 };
    345 
    346 /* Enumerates the possible extraction_insn operations.  */
    347 enum extraction_pattern { EP_insv, EP_extv, EP_extzv };
    348 
    349 extern bool get_best_reg_extraction_insn (extraction_insn *,
    350 					  enum extraction_pattern,
    351 					  unsigned HOST_WIDE_INT,
    352 					  enum machine_mode);
    353 
    354 extern bool get_best_mem_extraction_insn (extraction_insn *,
    355 					  enum extraction_pattern,
    356 					  HOST_WIDE_INT, HOST_WIDE_INT,
    357 					  enum machine_mode);
    358 
    359 extern bool insn_operand_matches (enum insn_code icode, unsigned int opno,
    360 				  rtx operand);
    361 
    362 /* Describes the type of an expand_operand.  Each value is associated
    363    with a create_*_operand function; see the comments above those
    364    functions for details.  */
    365 enum expand_operand_type {
    366   EXPAND_FIXED,
    367   EXPAND_OUTPUT,
    368   EXPAND_INPUT,
    369   EXPAND_CONVERT_TO,
    370   EXPAND_CONVERT_FROM,
    371   EXPAND_ADDRESS,
    372   EXPAND_INTEGER
    373 };
    374 
    375 /* Information about an operand for instruction expansion.  */
    376 struct expand_operand {
    377   /* The type of operand.  */
    378   ENUM_BITFIELD (expand_operand_type) type : 8;
    379 
    380   /* True if any conversion should treat VALUE as being unsigned
    381      rather than signed.  Only meaningful for certain types.  */
    382   unsigned int unsigned_p : 1;
    383 
    384   /* Unused; available for future use.  */
    385   unsigned int unused : 7;
    386 
    387   /* The mode passed to the convert_*_operand function.  It has a
    388      type-dependent meaning.  */
    389   ENUM_BITFIELD (machine_mode) mode : 16;
    390 
    391   /* The value of the operand.  */
    392   rtx value;
    393 };
    394 
    395 /* Initialize OP with the given fields.  Initialise the other fields
    396    to their default values.  */
    397 
    398 static inline void
    399 create_expand_operand (struct expand_operand *op,
    400 		       enum expand_operand_type type,
    401 		       rtx value, enum machine_mode mode,
    402 		       bool unsigned_p)
    403 {
    404   op->type = type;
    405   op->unsigned_p = unsigned_p;
    406   op->unused = 0;
    407   op->mode = mode;
    408   op->value = value;
    409 }
    410 
    411 /* Make OP describe an operand that must use rtx X, even if X is volatile.  */
    412 
    413 static inline void
    414 create_fixed_operand (struct expand_operand *op, rtx x)
    415 {
    416   create_expand_operand (op, EXPAND_FIXED, x, VOIDmode, false);
    417 }
    418 
    419 /* Make OP describe an output operand that must have mode MODE.
    420    X, if nonnull, is a suggestion for where the output should be stored.
    421    It is OK for VALUE to be inconsistent with MODE, although it will just
    422    be ignored in that case.  */
    423 
    424 static inline void
    425 create_output_operand (struct expand_operand *op, rtx x,
    426 		       enum machine_mode mode)
    427 {
    428   create_expand_operand (op, EXPAND_OUTPUT, x, mode, false);
    429 }
    430 
    431 /* Make OP describe an input operand that must have mode MODE and
    432    value VALUE; MODE cannot be VOIDmode.  The backend may request that
    433    VALUE be copied into a different kind of rtx before being passed
    434    as an operand.  */
    435 
    436 static inline void
    437 create_input_operand (struct expand_operand *op, rtx value,
    438 		      enum machine_mode mode)
    439 {
    440   create_expand_operand (op, EXPAND_INPUT, value, mode, false);
    441 }
    442 
    443 /* Like create_input_operand, except that VALUE must first be converted
    444    to mode MODE.  UNSIGNED_P says whether VALUE is unsigned.  */
    445 
    446 static inline void
    447 create_convert_operand_to (struct expand_operand *op, rtx value,
    448 			   enum machine_mode mode, bool unsigned_p)
    449 {
    450   create_expand_operand (op, EXPAND_CONVERT_TO, value, mode, unsigned_p);
    451 }
    452 
    453 /* Make OP describe an input operand that should have the same value
    454    as VALUE, after any mode conversion that the backend might request.
    455    If VALUE is a CONST_INT, it should be treated as having mode MODE.
    456    UNSIGNED_P says whether VALUE is unsigned.  */
    457 
    458 static inline void
    459 create_convert_operand_from (struct expand_operand *op, rtx value,
    460 			     enum machine_mode mode, bool unsigned_p)
    461 {
    462   create_expand_operand (op, EXPAND_CONVERT_FROM, value, mode, unsigned_p);
    463 }
    464 
    465 extern void create_convert_operand_from_type (struct expand_operand *op,
    466 					      rtx value, tree type);
    467 
    468 /* Make OP describe an input Pmode address operand.  VALUE is the value
    469    of the address, but it may need to be converted to Pmode first.  */
    470 
    471 static inline void
    472 create_address_operand (struct expand_operand *op, rtx value)
    473 {
    474   create_expand_operand (op, EXPAND_ADDRESS, value, Pmode, false);
    475 }
    476 
    477 /* Make OP describe an input operand that has value INTVAL and that has
    478    no inherent mode.  This function should only be used for operands that
    479    are always expand-time constants.  The backend may request that INTVAL
    480    be copied into a different kind of rtx, but it must specify the mode
    481    of that rtx if so.  */
    482 
    483 static inline void
    484 create_integer_operand (struct expand_operand *op, HOST_WIDE_INT intval)
    485 {
    486   create_expand_operand (op, EXPAND_INTEGER, GEN_INT (intval), VOIDmode, false);
    487 }
    488 
    489 extern bool valid_multiword_target_p (rtx);
    490 
    491 extern bool maybe_legitimize_operands (enum insn_code icode,
    492 				       unsigned int opno, unsigned int nops,
    493 				       struct expand_operand *ops);
    494 extern rtx maybe_gen_insn (enum insn_code icode, unsigned int nops,
    495 			   struct expand_operand *ops);
    496 extern bool maybe_expand_insn (enum insn_code icode, unsigned int nops,
    497 			       struct expand_operand *ops);
    498 extern bool maybe_expand_jump_insn (enum insn_code icode, unsigned int nops,
    499 				    struct expand_operand *ops);
    500 extern void expand_insn (enum insn_code icode, unsigned int nops,
    501 			 struct expand_operand *ops);
    502 extern void expand_jump_insn (enum insn_code icode, unsigned int nops,
    503 			      struct expand_operand *ops);
    504 
    505 extern rtx prepare_operand (enum insn_code, rtx, int, enum machine_mode,
    506 			    enum machine_mode, int);
    507 
    508 extern void gen_int_libfunc (optab, const char *, char, enum machine_mode);
    509 extern void gen_fp_libfunc (optab, const char *, char, enum machine_mode);
    510 extern void gen_fixed_libfunc (optab, const char *, char, enum machine_mode);
    511 extern void gen_signed_fixed_libfunc (optab, const char *, char,
    512 				      enum machine_mode);
    513 extern void gen_unsigned_fixed_libfunc (optab, const char *, char,
    514 					enum machine_mode);
    515 extern void gen_int_fp_libfunc (optab, const char *, char, enum machine_mode);
    516 extern void gen_intv_fp_libfunc (optab, const char *, char, enum machine_mode);
    517 extern void gen_int_fp_fixed_libfunc (optab, const char *, char,
    518 				      enum machine_mode);
    519 extern void gen_int_fp_signed_fixed_libfunc (optab, const char *, char,
    520 					     enum machine_mode);
    521 extern void gen_int_fixed_libfunc (optab, const char *, char,
    522 				   enum machine_mode);
    523 extern void gen_int_signed_fixed_libfunc (optab, const char *, char,
    524 					  enum machine_mode);
    525 extern void gen_int_unsigned_fixed_libfunc (optab, const char *, char,
    526 					    enum machine_mode);
    527 
    528 extern void gen_interclass_conv_libfunc (convert_optab, const char *,
    529 					 enum machine_mode, enum machine_mode);
    530 extern void gen_int_to_fp_conv_libfunc (convert_optab, const char *,
    531 					enum machine_mode, enum machine_mode);
    532 extern void gen_ufloat_conv_libfunc (convert_optab, const char *,
    533 				     enum machine_mode, enum machine_mode);
    534 extern void gen_int_to_fp_nondecimal_conv_libfunc  (convert_optab,
    535 						    const char *,
    536 						    enum machine_mode,
    537 						    enum machine_mode);
    538 extern void gen_fp_to_int_conv_libfunc (convert_optab, const char *,
    539 					enum machine_mode, enum machine_mode);
    540 extern void gen_intraclass_conv_libfunc (convert_optab, const char *,
    541 					 enum machine_mode, enum machine_mode);
    542 extern void gen_trunc_conv_libfunc (convert_optab, const char *,
    543 				    enum machine_mode, enum machine_mode);
    544 extern void gen_extend_conv_libfunc (convert_optab, const char *,
    545 				     enum machine_mode, enum machine_mode);
    546 extern void gen_fract_conv_libfunc (convert_optab, const char *,
    547 				    enum machine_mode, enum machine_mode);
    548 extern void gen_fractuns_conv_libfunc (convert_optab, const char *,
    549 				       enum machine_mode, enum machine_mode);
    550 extern void gen_satfract_conv_libfunc (convert_optab, const char *,
    551 				       enum machine_mode, enum machine_mode);
    552 extern void gen_satfractuns_conv_libfunc (convert_optab, const char *,
    553 					  enum machine_mode,
    554 					  enum machine_mode);
    555 
    556 #endif /* GCC_OPTABS_H */
    557