recog.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. /* Declarations for interface to insn recognizer and insn-output.c.
  2. Copyright (C) 1987-2015 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;
  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, 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, rtx *);
  90. extern int validate_replace_rtx (rtx, rtx, rtx);
  91. extern int validate_replace_rtx_part (rtx, rtx, rtx *, rtx);
  92. extern int validate_replace_rtx_part_nosimplify (rtx, rtx, rtx *, rtx);
  93. extern void validate_replace_rtx_group (rtx, rtx, rtx);
  94. extern void validate_replace_src_group (rtx, rtx, rtx);
  95. extern bool validate_simplify_insn (rtx insn);
  96. extern int num_changes_pending (void);
  97. #ifdef HAVE_cc0
  98. extern int next_insn_tests_no_inequality (rtx);
  99. #endif
  100. extern bool reg_fits_class_p (const_rtx, reg_class_t, int, machine_mode);
  101. extern int offsettable_memref_p (rtx);
  102. extern int offsettable_nonstrict_memref_p (rtx);
  103. extern int offsettable_address_addr_space_p (int, machine_mode, rtx,
  104. addr_space_t);
  105. #define offsettable_address_p(strict,mode,addr) \
  106. offsettable_address_addr_space_p ((strict), (mode), (addr), \
  107. ADDR_SPACE_GENERIC)
  108. extern bool mode_dependent_address_p (rtx, addr_space_t);
  109. extern int recog (rtx, rtx, int *);
  110. #ifndef GENERATOR_FILE
  111. static inline int recog_memoized (rtx_insn *insn);
  112. #endif
  113. extern void add_clobbers (rtx, int);
  114. extern int added_clobbers_hard_reg_p (int);
  115. extern void insn_extract (rtx_insn *);
  116. extern void extract_insn (rtx_insn *);
  117. extern void extract_constrain_insn (rtx_insn *insn);
  118. extern void extract_constrain_insn_cached (rtx_insn *);
  119. extern void extract_insn_cached (rtx_insn *);
  120. extern void preprocess_constraints (int, int, const char **,
  121. operand_alternative *);
  122. extern const operand_alternative *preprocess_insn_constraints (int);
  123. extern void preprocess_constraints (rtx);
  124. extern rtx peep2_next_insn (int);
  125. extern int peep2_regno_dead_p (int, int);
  126. extern int peep2_reg_dead_p (int, rtx);
  127. #ifdef CLEAR_HARD_REG_SET
  128. extern rtx peep2_find_free_register (int, int, const char *,
  129. machine_mode, HARD_REG_SET *);
  130. #endif
  131. extern rtx peephole2_insns (rtx, rtx, int *);
  132. extern int store_data_bypass_p (rtx_insn *, rtx_insn *);
  133. extern int if_test_bypass_p (rtx_insn *, rtx_insn *);
  134. #ifndef GENERATOR_FILE
  135. /* Try recognizing the instruction INSN,
  136. and return the code number that results.
  137. Remember the code so that repeated calls do not
  138. need to spend the time for actual rerecognition.
  139. This function is the normal interface to instruction recognition.
  140. The automatically-generated function `recog' is normally called
  141. through this one. */
  142. static inline int
  143. recog_memoized (rtx_insn *insn)
  144. {
  145. if (INSN_CODE (insn) < 0)
  146. INSN_CODE (insn) = recog (PATTERN (insn), insn, 0);
  147. return INSN_CODE (insn);
  148. }
  149. #endif
  150. /* Skip chars until the next ',' or the end of the string. This is
  151. useful to skip alternatives in a constraint string. */
  152. static inline const char *
  153. skip_alternative (const char *p)
  154. {
  155. const char *r = p;
  156. while (*r != '\0' && *r != ',')
  157. r++;
  158. if (*r == ',')
  159. r++;
  160. return r;
  161. }
  162. /* Nonzero means volatile operands are recognized. */
  163. extern int volatile_ok;
  164. /* Set by constrain_operands to the number of the alternative that
  165. matched. */
  166. extern int which_alternative;
  167. /* The following vectors hold the results from insn_extract. */
  168. struct recog_data_d
  169. {
  170. /* It is very tempting to make the 5 operand related arrays into a
  171. structure and index on that. However, to be source compatible
  172. with all of the existing md file insn constraints and output
  173. templates, we need `operand' as a flat array. Without that
  174. member, making an array for the rest seems pointless. */
  175. /* Gives value of operand N. */
  176. rtx operand[MAX_RECOG_OPERANDS];
  177. /* Gives location where operand N was found. */
  178. rtx *operand_loc[MAX_RECOG_OPERANDS];
  179. /* Gives the constraint string for operand N. */
  180. const char *constraints[MAX_RECOG_OPERANDS];
  181. /* Nonzero if operand N is a match_operator or a match_parallel. */
  182. char is_operator[MAX_RECOG_OPERANDS];
  183. /* Gives the mode of operand N. */
  184. machine_mode operand_mode[MAX_RECOG_OPERANDS];
  185. /* Gives the type (in, out, inout) for operand N. */
  186. enum op_type operand_type[MAX_RECOG_OPERANDS];
  187. /* Gives location where the Nth duplicate-appearance of an operand
  188. was found. This is something that matched MATCH_DUP. */
  189. rtx *dup_loc[MAX_DUP_OPERANDS];
  190. /* Gives the operand number that was duplicated in the Nth
  191. duplicate-appearance of an operand. */
  192. char dup_num[MAX_DUP_OPERANDS];
  193. /* ??? Note that these are `char' instead of `unsigned char' to (try to)
  194. avoid certain lossage from K&R C, wherein `unsigned char' default
  195. promotes to `unsigned int' instead of `int' as in ISO C. As of 1999,
  196. the most common places to bootstrap from K&R C are SunOS and HPUX,
  197. both of which have signed characters by default. The only other
  198. supported natives that have both K&R C and unsigned characters are
  199. ROMP and Irix 3, and neither have been seen for a while, but do
  200. continue to consider unsignedness when performing arithmetic inside
  201. a comparison. */
  202. /* The number of operands of the insn. */
  203. char n_operands;
  204. /* The number of MATCH_DUPs in the insn. */
  205. char n_dups;
  206. /* The number of alternatives in the constraints for the insn. */
  207. char n_alternatives;
  208. /* True if insn is ASM_OPERANDS. */
  209. bool is_asm;
  210. /* In case we are caching, hold insn data was generated for. */
  211. rtx insn;
  212. };
  213. extern struct recog_data_d recog_data;
  214. extern const operand_alternative *recog_op_alt;
  215. /* Return a pointer to an array in which index OP describes the constraints
  216. on operand OP of the current instruction alternative (which_alternative).
  217. Only valid after calling preprocess_constraints and constrain_operands. */
  218. inline static const operand_alternative *
  219. which_op_alt ()
  220. {
  221. gcc_checking_assert (IN_RANGE (which_alternative, 0,
  222. recog_data.n_alternatives - 1));
  223. return &recog_op_alt[which_alternative * recog_data.n_operands];
  224. }
  225. /* A table defined in insn-output.c that give information about
  226. each insn-code value. */
  227. typedef int (*insn_operand_predicate_fn) (rtx, machine_mode);
  228. typedef const char * (*insn_output_fn) (rtx *, rtx_insn *);
  229. struct insn_gen_fn
  230. {
  231. typedef rtx (*f0) (void);
  232. typedef rtx (*f1) (rtx);
  233. typedef rtx (*f2) (rtx, rtx);
  234. typedef rtx (*f3) (rtx, rtx, rtx);
  235. typedef rtx (*f4) (rtx, rtx, rtx, rtx);
  236. typedef rtx (*f5) (rtx, rtx, rtx, rtx, rtx);
  237. typedef rtx (*f6) (rtx, rtx, rtx, rtx, rtx, rtx);
  238. typedef rtx (*f7) (rtx, rtx, rtx, rtx, rtx, rtx, rtx);
  239. typedef rtx (*f8) (rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx);
  240. typedef rtx (*f9) (rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx);
  241. typedef rtx (*f10) (rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx);
  242. typedef rtx (*f11) (rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx);
  243. typedef rtx (*f12) (rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx);
  244. typedef rtx (*f13) (rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx);
  245. typedef rtx (*f14) (rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx);
  246. typedef rtx (*f15) (rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx);
  247. typedef rtx (*f16) (rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx);
  248. typedef f0 stored_funcptr;
  249. rtx operator () (void) const { return ((f0)func) (); }
  250. rtx operator () (rtx a0) const { return ((f1)func) (a0); }
  251. rtx operator () (rtx a0, rtx a1) const { return ((f2)func) (a0, a1); }
  252. rtx operator () (rtx a0, rtx a1, rtx a2) const { return ((f3)func) (a0, a1, a2); }
  253. rtx operator () (rtx a0, rtx a1, rtx a2, rtx a3) const { return ((f4)func) (a0, a1, a2, a3); }
  254. rtx operator () (rtx a0, rtx a1, rtx a2, rtx a3, rtx a4) const { return ((f5)func) (a0, a1, a2, a3, a4); }
  255. rtx operator () (rtx a0, rtx a1, rtx a2, rtx a3, rtx a4, rtx a5) const { return ((f6)func) (a0, a1, a2, a3, a4, a5); }
  256. rtx 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); }
  257. rtx 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); }
  258. rtx 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); }
  259. rtx 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); }
  260. rtx 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); }
  261. rtx 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); }
  262. rtx 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); }
  263. rtx 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); }
  264. rtx 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); }
  265. rtx 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); }
  266. // This is for compatibility of code that invokes functions like
  267. // (*funcptr) (arg)
  268. insn_gen_fn operator * (void) const { return *this; }
  269. // The wrapped function pointer must be public and there must not be any
  270. // constructors. Otherwise the insn_data_d struct initializers generated
  271. // by genoutput.c will result in static initializer functions, which defeats
  272. // the purpose of the generated insn_data_d array.
  273. stored_funcptr func;
  274. };
  275. struct insn_operand_data
  276. {
  277. const insn_operand_predicate_fn predicate;
  278. const char *const constraint;
  279. ENUM_BITFIELD(machine_mode) const mode : 16;
  280. const char strict_low;
  281. const char is_operator;
  282. const char eliminable;
  283. const char allows_mem;
  284. };
  285. /* Legal values for insn_data.output_format. Indicate what type of data
  286. is stored in insn_data.output. */
  287. #define INSN_OUTPUT_FORMAT_NONE 0 /* abort */
  288. #define INSN_OUTPUT_FORMAT_SINGLE 1 /* const char * */
  289. #define INSN_OUTPUT_FORMAT_MULTI 2 /* const char * const * */
  290. #define INSN_OUTPUT_FORMAT_FUNCTION 3 /* const char * (*)(...) */
  291. struct insn_data_d
  292. {
  293. const char *const name;
  294. #if HAVE_DESIGNATED_UNION_INITIALIZERS
  295. union {
  296. const char *single;
  297. const char *const *multi;
  298. insn_output_fn function;
  299. } output;
  300. #else
  301. struct {
  302. const char *single;
  303. const char *const *multi;
  304. insn_output_fn function;
  305. } output;
  306. #endif
  307. const insn_gen_fn genfun;
  308. const struct insn_operand_data *const operand;
  309. const char n_generator_args;
  310. const char n_operands;
  311. const char n_dups;
  312. const char n_alternatives;
  313. const char output_format;
  314. };
  315. extern const struct insn_data_d insn_data[];
  316. extern int peep2_current_count;
  317. #ifndef GENERATOR_FILE
  318. #include "insn-codes.h"
  319. /* An enum of boolean attributes that may only depend on the current
  320. subtarget, not on things like operands or compiler phase. */
  321. enum bool_attr {
  322. BA_ENABLED,
  323. BA_PREFERRED_FOR_SPEED,
  324. BA_PREFERRED_FOR_SIZE,
  325. BA_LAST = BA_PREFERRED_FOR_SIZE
  326. };
  327. /* Target-dependent globals. */
  328. struct target_recog {
  329. bool x_initialized;
  330. alternative_mask x_bool_attr_masks[LAST_INSN_CODE][BA_LAST + 1];
  331. operand_alternative *x_op_alt[LAST_INSN_CODE];
  332. };
  333. extern struct target_recog default_target_recog;
  334. #if SWITCHABLE_TARGET
  335. extern struct target_recog *this_target_recog;
  336. #else
  337. #define this_target_recog (&default_target_recog)
  338. #endif
  339. alternative_mask get_enabled_alternatives (rtx_insn *);
  340. alternative_mask get_preferred_alternatives (rtx_insn *);
  341. alternative_mask get_preferred_alternatives (rtx_insn *, basic_block);
  342. bool check_bool_attrs (rtx_insn *);
  343. void recog_init ();
  344. #endif
  345. #endif /* GCC_RECOG_H */