optabs.h 13 KB

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