recog.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. /* Declarations for interface to insn recognizer and insn-output.c.
  2. Copyright (C) 1987-2019 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU General Public License as published by the Free
  6. Software Foundation; either version 3, or (at your option) any later
  7. version.
  8. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11. 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_RECOG_H
  16. #define GCC_RECOG_H
  17. /* Random number that should be large enough for all purposes. Also define
  18. a type that has at least MAX_RECOG_ALTERNATIVES + 1 bits, with the extra
  19. bit giving an invalid value that can be used to mean "uninitialized". */
  20. #define MAX_RECOG_ALTERNATIVES 35
  21. typedef uint64_t alternative_mask; /* Keep in sync with genattrtab.c. */
  22. /* A mask of all alternatives. */
  23. #define ALL_ALTERNATIVES ((alternative_mask) -1)
  24. /* A mask containing just alternative X. */
  25. #define ALTERNATIVE_BIT(X) ((alternative_mask) 1 << (X))
  26. /* Types of operands. */
  27. enum op_type {
  28. OP_IN,
  29. OP_OUT,
  30. OP_INOUT
  31. };
  32. struct operand_alternative
  33. {
  34. /* Pointer to the beginning of the constraint string for this alternative,
  35. for easier access by alternative number. */
  36. const char *constraint;
  37. /* The register class valid for this alternative (possibly NO_REGS). */
  38. ENUM_BITFIELD (reg_class) cl : 16;
  39. /* "Badness" of this alternative, computed from number of '?' and '!'
  40. characters in the constraint string. */
  41. unsigned int reject : 16;
  42. /* -1 if no matching constraint was found, or an operand number. */
  43. int matches : 8;
  44. /* The same information, but reversed: -1 if this operand is not
  45. matched by any other, or the operand number of the operand that
  46. matches this one. */
  47. int matched : 8;
  48. /* Nonzero if '&' was found in the constraint string. */
  49. unsigned int earlyclobber : 1;
  50. /* Nonzero if TARGET_MEM_CONSTRAINT was found in the constraint
  51. string. */
  52. unsigned int memory_ok : 1;
  53. /* Nonzero if 'p' was found in the constraint string. */
  54. unsigned int is_address : 1;
  55. /* Nonzero if 'X' was found in the constraint string, or if the constraint
  56. string for this alternative was empty. */
  57. unsigned int anything_ok : 1;
  58. unsigned int unused : 12;
  59. };
  60. /* Return the class for operand I of alternative ALT, taking matching
  61. constraints into account. */
  62. static inline enum reg_class
  63. alternative_class (const operand_alternative *alt, int i)
  64. {
  65. return alt[i].matches >= 0 ? alt[alt[i].matches].cl : alt[i].cl;
  66. }
  67. extern void init_recog (void);
  68. extern void init_recog_no_volatile (void);
  69. extern int check_asm_operands (rtx);
  70. extern int asm_operand_ok (rtx, const char *, const char **);
  71. extern bool validate_change (rtx, rtx *, rtx, bool);
  72. extern bool validate_unshare_change (rtx, rtx *, rtx, bool);
  73. extern bool canonicalize_change_group (rtx_insn *insn, rtx x);
  74. extern int insn_invalid_p (rtx_insn *, bool);
  75. extern int verify_changes (int);
  76. extern void confirm_change_group (void);
  77. extern int apply_change_group (void);
  78. extern int num_validated_changes (void);
  79. extern void cancel_changes (int);
  80. extern int constrain_operands (int, alternative_mask);
  81. extern int constrain_operands_cached (rtx_insn *, int);
  82. extern int memory_address_addr_space_p (machine_mode, rtx, addr_space_t);
  83. #define memory_address_p(mode,addr) \
  84. memory_address_addr_space_p ((mode), (addr), ADDR_SPACE_GENERIC)
  85. extern int strict_memory_address_addr_space_p (machine_mode, rtx,
  86. addr_space_t);
  87. #define strict_memory_address_p(mode,addr) \
  88. strict_memory_address_addr_space_p ((mode), (addr), ADDR_SPACE_GENERIC)
  89. extern int validate_replace_rtx_subexp (rtx, rtx, rtx_insn *, rtx *);
  90. extern int validate_replace_rtx (rtx, rtx, rtx_insn *);
  91. extern int validate_replace_rtx_part (rtx, rtx, rtx *, rtx_insn *);
  92. extern int validate_replace_rtx_part_nosimplify (rtx, rtx, rtx *, rtx_insn *);
  93. extern void validate_replace_rtx_group (rtx, rtx, rtx_insn *);
  94. extern void validate_replace_src_group (rtx, rtx, rtx_insn *);
  95. extern bool validate_simplify_insn (rtx_insn *insn);
  96. extern int num_changes_pending (void);
  97. extern int next_insn_tests_no_inequality (rtx_insn *);
  98. extern bool reg_fits_class_p (const_rtx, reg_class_t, int, machine_mode);
  99. extern int offsettable_memref_p (rtx);
  100. extern int offsettable_nonstrict_memref_p (rtx);
  101. extern int offsettable_address_addr_space_p (int, machine_mode, rtx,
  102. addr_space_t);
  103. #define offsettable_address_p(strict,mode,addr) \
  104. offsettable_address_addr_space_p ((strict), (mode), (addr), \
  105. ADDR_SPACE_GENERIC)
  106. extern bool mode_dependent_address_p (rtx, addr_space_t);
  107. extern int recog (rtx, rtx_insn *, int *);
  108. #ifndef GENERATOR_FILE
  109. static inline int recog_memoized (rtx_insn *insn);
  110. #endif
  111. extern void add_clobbers (rtx, int);
  112. extern int added_clobbers_hard_reg_p (int);
  113. extern void insn_extract (rtx_insn *);
  114. extern void extract_insn (rtx_insn *);
  115. extern void extract_constrain_insn (rtx_insn *insn);
  116. extern void extract_constrain_insn_cached (rtx_insn *);
  117. extern void extract_insn_cached (rtx_insn *);
  118. extern void preprocess_constraints (int, int, const char **,
  119. operand_alternative *, rtx **);
  120. extern const operand_alternative *preprocess_insn_constraints (unsigned int);
  121. extern void preprocess_constraints (rtx_insn *);
  122. extern rtx_insn *peep2_next_insn (int);
  123. extern int peep2_regno_dead_p (int, int);
  124. extern int peep2_reg_dead_p (int, rtx);
  125. #ifdef CLEAR_HARD_REG_SET
  126. extern rtx peep2_find_free_register (int, int, const char *,
  127. machine_mode, HARD_REG_SET *);
  128. #endif
  129. extern rtx_insn *peephole2_insns (rtx, rtx_insn *, int *);
  130. extern int store_data_bypass_p (rtx_insn *, rtx_insn *);
  131. extern int if_test_bypass_p (rtx_insn *, rtx_insn *);
  132. #ifndef GENERATOR_FILE
  133. /* Try recognizing the instruction INSN,
  134. and return the code number that results.
  135. Remember the code so that repeated calls do not
  136. need to spend the time for actual rerecognition.
  137. This function is the normal interface to instruction recognition.
  138. The automatically-generated function `recog' is normally called
  139. through this one. */
  140. static inline int
  141. recog_memoized (rtx_insn *insn)
  142. {
  143. if (INSN_CODE (insn) < 0)
  144. INSN_CODE (insn) = recog (PATTERN (insn), insn, 0);
  145. return INSN_CODE (insn);
  146. }
  147. #endif
  148. /* Skip chars until the next ',' or the end of the string. This is
  149. useful to skip alternatives in a constraint string. */
  150. static inline const char *
  151. skip_alternative (const char *p)
  152. {
  153. const char *r = p;
  154. while (*r != '\0' && *r != ',')
  155. r++;
  156. if (*r == ',')
  157. r++;
  158. return r;
  159. }
  160. /* Nonzero means volatile operands are recognized. */
  161. extern int volatile_ok;
  162. /* Set by constrain_operands to the number of the alternative that
  163. matched. */
  164. extern int which_alternative;
  165. /* The following vectors hold the results from insn_extract. */
  166. struct recog_data_d
  167. {
  168. /* It is very tempting to make the 5 operand related arrays into a
  169. structure and index on that. However, to be source compatible
  170. with all of the existing md file insn constraints and output
  171. templates, we need `operand' as a flat array. Without that
  172. member, making an array for the rest seems pointless. */
  173. /* Gives value of operand N. */
  174. rtx operand[MAX_RECOG_OPERANDS];
  175. /* Gives location where operand N was found. */
  176. rtx *operand_loc[MAX_RECOG_OPERANDS];
  177. /* Gives the constraint string for operand N. */
  178. const char *constraints[MAX_RECOG_OPERANDS];
  179. /* Nonzero if operand N is a match_operator or a match_parallel. */
  180. char is_operator[MAX_RECOG_OPERANDS];
  181. /* Gives the mode of operand N. */
  182. machine_mode operand_mode[MAX_RECOG_OPERANDS];
  183. /* Gives the type (in, out, inout) for operand N. */
  184. enum op_type operand_type[MAX_RECOG_OPERANDS];
  185. /* Gives location where the Nth duplicate-appearance of an operand
  186. was found. This is something that matched MATCH_DUP. */
  187. rtx *dup_loc[MAX_DUP_OPERANDS];
  188. /* Gives the operand number that was duplicated in the Nth
  189. duplicate-appearance of an operand. */
  190. char dup_num[MAX_DUP_OPERANDS];
  191. /* ??? Note that these are `char' instead of `unsigned char' to (try to)
  192. avoid certain lossage from K&R C, wherein `unsigned char' default
  193. promotes to `unsigned int' instead of `int' as in ISO C. As of 1999,
  194. the most common places to bootstrap from K&R C are SunOS and HPUX,
  195. both of which have signed characters by default. The only other
  196. supported natives that have both K&R C and unsigned characters are
  197. ROMP and Irix 3, and neither have been seen for a while, but do
  198. continue to consider unsignedness when performing arithmetic inside
  199. a comparison. */
  200. /* The number of operands of the insn. */
  201. char n_operands;
  202. /* The number of MATCH_DUPs in the insn. */
  203. char n_dups;
  204. /* The number of alternatives in the constraints for the insn. */
  205. char n_alternatives;
  206. /* True if insn is ASM_OPERANDS. */
  207. bool is_asm;
  208. /* In case we are caching, hold insn data was generated for. */
  209. rtx_insn *insn;
  210. };
  211. extern struct recog_data_d recog_data;
  212. extern const operand_alternative *recog_op_alt;
  213. /* Return a pointer to an array in which index OP describes the constraints
  214. on operand OP of the current instruction alternative (which_alternative).
  215. Only valid after calling preprocess_constraints and constrain_operands. */
  216. inline static const operand_alternative *
  217. which_op_alt ()
  218. {
  219. gcc_checking_assert (IN_RANGE (which_alternative, 0,
  220. recog_data.n_alternatives - 1));
  221. return &recog_op_alt[which_alternative * recog_data.n_operands];
  222. }
  223. /* A table defined in insn-output.c that give information about
  224. each insn-code value. */
  225. typedef int (*insn_operand_predicate_fn) (rtx, machine_mode);
  226. typedef const char * (*insn_output_fn) (rtx *, rtx_insn *);
  227. struct insn_gen_fn
  228. {
  229. typedef rtx_insn * (*f0) (void);
  230. typedef rtx_insn * (*f1) (rtx);
  231. typedef rtx_insn * (*f2) (rtx, rtx);
  232. typedef rtx_insn * (*f3) (rtx, rtx, rtx);
  233. typedef rtx_insn * (*f4) (rtx, rtx, rtx, rtx);
  234. typedef rtx_insn * (*f5) (rtx, rtx, rtx, rtx, rtx);
  235. typedef rtx_insn * (*f6) (rtx, rtx, rtx, rtx, rtx, rtx);
  236. typedef rtx_insn * (*f7) (rtx, rtx, rtx, rtx, rtx, rtx, rtx);
  237. typedef rtx_insn * (*f8) (rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx);
  238. typedef rtx_insn * (*f9) (rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx);
  239. typedef rtx_insn * (*f10) (rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx);
  240. typedef rtx_insn * (*f11) (rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx);
  241. typedef rtx_insn * (*f12) (rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx);
  242. typedef rtx_insn * (*f13) (rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx);
  243. typedef rtx_insn * (*f14) (rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx);
  244. typedef rtx_insn * (*f15) (rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx);
  245. typedef rtx_insn * (*f16) (rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx);
  246. typedef void (*stored_funcptr) (void);
  247. rtx_insn * operator () (void) const { return ((f0)func) (); }
  248. rtx_insn * operator () (rtx a0) const { return ((f1)func) (a0); }
  249. rtx_insn * operator () (rtx a0, rtx a1) const { return ((f2)func) (a0, a1); }
  250. rtx_insn * operator () (rtx a0, rtx a1, rtx a2) const { return ((f3)func) (a0, a1, a2); }
  251. rtx_insn * operator () (rtx a0, rtx a1, rtx a2, rtx a3) const { return ((f4)func) (a0, a1, a2, a3); }
  252. rtx_insn * operator () (rtx a0, rtx a1, rtx a2, rtx a3, rtx a4) const { return ((f5)func) (a0, a1, a2, a3, a4); }
  253. rtx_insn * operator () (rtx a0, rtx a1, rtx a2, rtx a3, rtx a4, rtx a5) const { return ((f6)func) (a0, a1, a2, a3, a4, a5); }
  254. rtx_insn * operator () (rtx a0, rtx a1, rtx a2, rtx a3, rtx a4, rtx a5, rtx a6) const { return ((f7)func) (a0, a1, a2, a3, a4, a5, a6); }
  255. rtx_insn * operator () (rtx a0, rtx a1, rtx a2, rtx a3, rtx a4, rtx a5, rtx a6, rtx a7) const { return ((f8)func) (a0, a1, a2, a3, a4, a5, a6, a7); }
  256. rtx_insn * operator () (rtx a0, rtx a1, rtx a2, rtx a3, rtx a4, rtx a5, rtx a6, rtx a7, rtx a8) const { return ((f9)func) (a0, a1, a2, a3, a4, a5, a6, a7, a8); }
  257. rtx_insn * operator () (rtx a0, rtx a1, rtx a2, rtx a3, rtx a4, rtx a5, rtx a6, rtx a7, rtx a8, rtx a9) const { return ((f10)func) (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9); }
  258. rtx_insn * operator () (rtx a0, rtx a1, rtx a2, rtx a3, rtx a4, rtx a5, rtx a6, rtx a7, rtx a8, rtx a9, rtx a10) const { return ((f11)func) (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); }
  259. rtx_insn * operator () (rtx a0, rtx a1, rtx a2, rtx a3, rtx a4, rtx a5, rtx a6, rtx a7, rtx a8, rtx a9, rtx a10, rtx a11) const { return ((f12)func) (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11); }
  260. rtx_insn * operator () (rtx a0, rtx a1, rtx a2, rtx a3, rtx a4, rtx a5, rtx a6, rtx a7, rtx a8, rtx a9, rtx a10, rtx a11, rtx a12) const { return ((f13)func) (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12); }
  261. rtx_insn * operator () (rtx a0, rtx a1, rtx a2, rtx a3, rtx a4, rtx a5, rtx a6, rtx a7, rtx a8, rtx a9, rtx a10, rtx a11, rtx a12, rtx a13) const { return ((f14)func) (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13); }
  262. rtx_insn * operator () (rtx a0, rtx a1, rtx a2, rtx a3, rtx a4, rtx a5, rtx a6, rtx a7, rtx a8, rtx a9, rtx a10, rtx a11, rtx a12, rtx a13, rtx a14) const { return ((f15)func) (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14); }
  263. rtx_insn * operator () (rtx a0, rtx a1, rtx a2, rtx a3, rtx a4, rtx a5, rtx a6, rtx a7, rtx a8, rtx a9, rtx a10, rtx a11, rtx a12, rtx a13, rtx a14, rtx a15) const { return ((f16)func) (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15); }
  264. // This is for compatibility of code that invokes functions like
  265. // (*funcptr) (arg)
  266. insn_gen_fn operator * (void) const { return *this; }
  267. // The wrapped function pointer must be public and there must not be any
  268. // constructors. Otherwise the insn_data_d struct initializers generated
  269. // by genoutput.c will result in static initializer functions, which defeats
  270. // the purpose of the generated insn_data_d array.
  271. stored_funcptr func;
  272. };
  273. struct insn_operand_data
  274. {
  275. const insn_operand_predicate_fn predicate;
  276. const char *const constraint;
  277. ENUM_BITFIELD(machine_mode) const mode : 16;
  278. const char strict_low;
  279. const char is_operator;
  280. const char eliminable;
  281. const char allows_mem;
  282. };
  283. /* Legal values for insn_data.output_format. Indicate what type of data
  284. is stored in insn_data.output. */
  285. #define INSN_OUTPUT_FORMAT_NONE 0 /* abort */
  286. #define INSN_OUTPUT_FORMAT_SINGLE 1 /* const char * */
  287. #define INSN_OUTPUT_FORMAT_MULTI 2 /* const char * const * */
  288. #define INSN_OUTPUT_FORMAT_FUNCTION 3 /* const char * (*)(...) */
  289. struct insn_data_d
  290. {
  291. const char *const name;
  292. #if HAVE_DESIGNATED_UNION_INITIALIZERS
  293. union {
  294. const char *single;
  295. const char *const *multi;
  296. insn_output_fn function;
  297. } output;
  298. #else
  299. struct {
  300. const char *single;
  301. const char *const *multi;
  302. insn_output_fn function;
  303. } output;
  304. #endif
  305. const insn_gen_fn genfun;
  306. const struct insn_operand_data *const operand;
  307. const char n_generator_args;
  308. const char n_operands;
  309. const char n_dups;
  310. const char n_alternatives;
  311. const char output_format;
  312. };
  313. extern const struct insn_data_d insn_data[];
  314. extern int peep2_current_count;
  315. #ifndef GENERATOR_FILE
  316. #include "insn-codes.h"
  317. /* An enum of boolean attributes that may only depend on the current
  318. subtarget, not on things like operands or compiler phase. */
  319. enum bool_attr {
  320. BA_ENABLED,
  321. BA_PREFERRED_FOR_SPEED,
  322. BA_PREFERRED_FOR_SIZE,
  323. BA_LAST = BA_PREFERRED_FOR_SIZE
  324. };
  325. /* Target-dependent globals. */
  326. struct target_recog {
  327. bool x_initialized;
  328. alternative_mask x_bool_attr_masks[NUM_INSN_CODES][BA_LAST + 1];
  329. operand_alternative *x_op_alt[NUM_INSN_CODES];
  330. };
  331. extern struct target_recog default_target_recog;
  332. #if SWITCHABLE_TARGET
  333. extern struct target_recog *this_target_recog;
  334. #else
  335. #define this_target_recog (&default_target_recog)
  336. #endif
  337. alternative_mask get_enabled_alternatives (rtx_insn *);
  338. alternative_mask get_preferred_alternatives (rtx_insn *);
  339. alternative_mask get_preferred_alternatives (rtx_insn *, basic_block);
  340. bool check_bool_attrs (rtx_insn *);
  341. void recog_init ();
  342. #endif
  343. #endif /* GCC_RECOG_H */