genconfig.c 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. /* Generate from machine description:
  2. - some #define configuration flags.
  3. Copyright (C) 1987-2015 Free Software Foundation, Inc.
  4. This file is part of GCC.
  5. GCC is free software; you can redistribute it and/or modify it under
  6. the terms of the GNU General Public License as published by the Free
  7. Software Foundation; either version 3, or (at your option) any later
  8. version.
  9. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with GCC; see the file COPYING3. If not see
  15. <http://www.gnu.org/licenses/>. */
  16. #include "bconfig.h"
  17. #include "system.h"
  18. #include "coretypes.h"
  19. #include "tm.h"
  20. #include "rtl.h"
  21. #include "errors.h"
  22. #include "gensupport.h"
  23. /* flags to determine output of machine description dependent #define's. */
  24. static int max_recog_operands; /* Largest operand number seen. */
  25. static int max_dup_operands; /* Largest number of match_dup in any insn. */
  26. static int max_clobbers_per_insn;
  27. static int have_cc0_flag;
  28. static int have_cmove_flag;
  29. static int have_cond_exec_flag;
  30. static int have_lo_sum_flag;
  31. static int have_rotate_flag;
  32. static int have_rotatert_flag;
  33. static int have_peephole_flag;
  34. static int have_peephole2_flag;
  35. /* Maximum number of insns seen in a split. */
  36. static int max_insns_per_split = 1;
  37. /* Maximum number of input insns for peephole2. */
  38. static int max_insns_per_peep2;
  39. static int clobbers_seen_this_insn;
  40. static int dup_operands_seen_this_insn;
  41. static void walk_insn_part (rtx, int, int);
  42. static void gen_insn (rtx);
  43. static void gen_expand (rtx);
  44. static void gen_split (rtx);
  45. static void gen_peephole (rtx);
  46. static void gen_peephole2 (rtx);
  47. /* RECOG_P will be nonzero if this pattern was seen in a context where it will
  48. be used to recognize, rather than just generate an insn.
  49. NON_PC_SET_SRC will be nonzero if this pattern was seen in a SET_SRC
  50. of a SET whose destination is not (pc). */
  51. static void
  52. walk_insn_part (rtx part, int recog_p, int non_pc_set_src)
  53. {
  54. int i, j;
  55. RTX_CODE code;
  56. const char *format_ptr;
  57. if (part == 0)
  58. return;
  59. code = GET_CODE (part);
  60. switch (code)
  61. {
  62. case CLOBBER:
  63. clobbers_seen_this_insn++;
  64. break;
  65. case MATCH_OPERAND:
  66. if (XINT (part, 0) > max_recog_operands)
  67. max_recog_operands = XINT (part, 0);
  68. return;
  69. case MATCH_OP_DUP:
  70. case MATCH_PAR_DUP:
  71. ++dup_operands_seen_this_insn;
  72. case MATCH_SCRATCH:
  73. case MATCH_PARALLEL:
  74. case MATCH_OPERATOR:
  75. if (XINT (part, 0) > max_recog_operands)
  76. max_recog_operands = XINT (part, 0);
  77. /* Now scan the rtl's in the vector inside the MATCH_OPERATOR or
  78. MATCH_PARALLEL. */
  79. break;
  80. case LABEL_REF:
  81. if (GET_CODE (LABEL_REF_LABEL (part)) == MATCH_OPERAND
  82. || GET_CODE (LABEL_REF_LABEL (part)) == MATCH_DUP)
  83. break;
  84. return;
  85. case MATCH_DUP:
  86. ++dup_operands_seen_this_insn;
  87. if (XINT (part, 0) > max_recog_operands)
  88. max_recog_operands = XINT (part, 0);
  89. return;
  90. case CC0:
  91. if (recog_p)
  92. have_cc0_flag = 1;
  93. return;
  94. case LO_SUM:
  95. if (recog_p)
  96. have_lo_sum_flag = 1;
  97. return;
  98. case ROTATE:
  99. if (recog_p)
  100. have_rotate_flag = 1;
  101. return;
  102. case ROTATERT:
  103. if (recog_p)
  104. have_rotatert_flag = 1;
  105. return;
  106. case SET:
  107. walk_insn_part (SET_DEST (part), 0, recog_p);
  108. walk_insn_part (SET_SRC (part), recog_p,
  109. GET_CODE (SET_DEST (part)) != PC);
  110. return;
  111. case IF_THEN_ELSE:
  112. /* Only consider this machine as having a conditional move if the
  113. two arms of the IF_THEN_ELSE are both MATCH_OPERAND. Otherwise,
  114. we have some specific IF_THEN_ELSE construct (like the doz
  115. instruction on the RS/6000) that can't be used in the general
  116. context we want it for. */
  117. if (recog_p && non_pc_set_src
  118. && GET_CODE (XEXP (part, 1)) == MATCH_OPERAND
  119. && GET_CODE (XEXP (part, 2)) == MATCH_OPERAND)
  120. have_cmove_flag = 1;
  121. break;
  122. case COND_EXEC:
  123. if (recog_p)
  124. have_cond_exec_flag = 1;
  125. break;
  126. case REG: case CONST_INT: case SYMBOL_REF:
  127. case PC:
  128. return;
  129. default:
  130. break;
  131. }
  132. format_ptr = GET_RTX_FORMAT (GET_CODE (part));
  133. for (i = 0; i < GET_RTX_LENGTH (GET_CODE (part)); i++)
  134. switch (*format_ptr++)
  135. {
  136. case 'e':
  137. case 'u':
  138. walk_insn_part (XEXP (part, i), recog_p, non_pc_set_src);
  139. break;
  140. case 'E':
  141. if (XVEC (part, i) != NULL)
  142. for (j = 0; j < XVECLEN (part, i); j++)
  143. walk_insn_part (XVECEXP (part, i, j), recog_p, non_pc_set_src);
  144. break;
  145. }
  146. }
  147. static void
  148. gen_insn (rtx insn)
  149. {
  150. int i;
  151. /* Walk the insn pattern to gather the #define's status. */
  152. clobbers_seen_this_insn = 0;
  153. dup_operands_seen_this_insn = 0;
  154. if (XVEC (insn, 1) != 0)
  155. for (i = 0; i < XVECLEN (insn, 1); i++)
  156. walk_insn_part (XVECEXP (insn, 1, i), 1, 0);
  157. if (clobbers_seen_this_insn > max_clobbers_per_insn)
  158. max_clobbers_per_insn = clobbers_seen_this_insn;
  159. if (dup_operands_seen_this_insn > max_dup_operands)
  160. max_dup_operands = dup_operands_seen_this_insn;
  161. }
  162. /* Similar but scan a define_expand. */
  163. static void
  164. gen_expand (rtx insn)
  165. {
  166. int i;
  167. /* Walk the insn pattern to gather the #define's status. */
  168. /* Note that we don't bother recording the number of MATCH_DUPs
  169. that occur in a gen_expand, because only reload cares about that. */
  170. if (XVEC (insn, 1) != 0)
  171. for (i = 0; i < XVECLEN (insn, 1); i++)
  172. {
  173. /* Compute the maximum SETs and CLOBBERS
  174. in any one of the sub-insns;
  175. don't sum across all of them. */
  176. clobbers_seen_this_insn = 0;
  177. walk_insn_part (XVECEXP (insn, 1, i), 0, 0);
  178. if (clobbers_seen_this_insn > max_clobbers_per_insn)
  179. max_clobbers_per_insn = clobbers_seen_this_insn;
  180. }
  181. }
  182. /* Similar but scan a define_split. */
  183. static void
  184. gen_split (rtx split)
  185. {
  186. int i;
  187. /* Look through the patterns that are matched
  188. to compute the maximum operand number. */
  189. for (i = 0; i < XVECLEN (split, 0); i++)
  190. walk_insn_part (XVECEXP (split, 0, i), 1, 0);
  191. /* Look at the number of insns this insn could split into. */
  192. if (XVECLEN (split, 2) > max_insns_per_split)
  193. max_insns_per_split = XVECLEN (split, 2);
  194. }
  195. static void
  196. gen_peephole (rtx peep)
  197. {
  198. int i;
  199. /* Look through the patterns that are matched
  200. to compute the maximum operand number. */
  201. for (i = 0; i < XVECLEN (peep, 0); i++)
  202. walk_insn_part (XVECEXP (peep, 0, i), 1, 0);
  203. }
  204. static void
  205. gen_peephole2 (rtx peep)
  206. {
  207. int i, n;
  208. /* Look through the patterns that are matched
  209. to compute the maximum operand number. */
  210. for (i = XVECLEN (peep, 0) - 1; i >= 0; --i)
  211. walk_insn_part (XVECEXP (peep, 0, i), 1, 0);
  212. /* Look at the number of insns this insn can be matched from. */
  213. for (i = XVECLEN (peep, 0) - 1, n = 0; i >= 0; --i)
  214. if (GET_CODE (XVECEXP (peep, 0, i)) != MATCH_DUP
  215. && GET_CODE (XVECEXP (peep, 0, i)) != MATCH_SCRATCH)
  216. n++;
  217. if (n > max_insns_per_peep2)
  218. max_insns_per_peep2 = n;
  219. }
  220. int
  221. main (int argc, char **argv)
  222. {
  223. rtx desc;
  224. progname = "genconfig";
  225. if (!init_rtx_reader_args (argc, argv))
  226. return (FATAL_EXIT_CODE);
  227. puts ("/* Generated automatically by the program `genconfig'");
  228. puts (" from the machine description file `md'. */\n");
  229. puts ("#ifndef GCC_INSN_CONFIG_H");
  230. puts ("#define GCC_INSN_CONFIG_H\n");
  231. /* Allow at least 30 operands for the sake of asm constructs. */
  232. /* ??? We *really* ought to reorganize things such that there
  233. is no fixed upper bound. */
  234. max_recog_operands = 29; /* We will add 1 later. */
  235. max_dup_operands = 1;
  236. /* Read the machine description. */
  237. while (1)
  238. {
  239. int line_no, insn_code_number = 0;
  240. desc = read_md_rtx (&line_no, &insn_code_number);
  241. if (desc == NULL)
  242. break;
  243. switch (GET_CODE (desc))
  244. {
  245. case DEFINE_INSN:
  246. gen_insn (desc);
  247. break;
  248. case DEFINE_EXPAND:
  249. gen_expand (desc);
  250. break;
  251. case DEFINE_SPLIT:
  252. gen_split (desc);
  253. break;
  254. case DEFINE_PEEPHOLE2:
  255. have_peephole2_flag = 1;
  256. gen_peephole2 (desc);
  257. break;
  258. case DEFINE_PEEPHOLE:
  259. have_peephole_flag = 1;
  260. gen_peephole (desc);
  261. break;
  262. default:
  263. break;
  264. }
  265. }
  266. printf ("#define MAX_RECOG_OPERANDS %d\n", max_recog_operands + 1);
  267. printf ("#define MAX_DUP_OPERANDS %d\n", max_dup_operands);
  268. /* This is conditionally defined, in case the user writes code which emits
  269. more splits than we can readily see (and knows s/he does it). */
  270. printf ("#ifndef MAX_INSNS_PER_SPLIT\n");
  271. printf ("#define MAX_INSNS_PER_SPLIT %d\n", max_insns_per_split);
  272. printf ("#endif\n");
  273. if (have_cc0_flag)
  274. {
  275. printf ("#define HAVE_cc0 1\n");
  276. printf ("#define CC0_P(X) ((X) == cc0_rtx)\n");
  277. }
  278. else
  279. {
  280. /* We output CC0_P this way to make sure that X is declared
  281. somewhere. */
  282. printf ("#define CC0_P(X) ((X) ? 0 : 0)\n");
  283. }
  284. if (have_cmove_flag)
  285. printf ("#define HAVE_conditional_move 1\n");
  286. if (have_cond_exec_flag)
  287. printf ("#define HAVE_conditional_execution 1\n");
  288. if (have_lo_sum_flag)
  289. printf ("#define HAVE_lo_sum 1\n");
  290. if (have_rotate_flag)
  291. printf ("#define HAVE_rotate 1\n");
  292. if (have_rotatert_flag)
  293. printf ("#define HAVE_rotatert 1\n");
  294. if (have_peephole_flag)
  295. printf ("#define HAVE_peephole 1\n");
  296. if (have_peephole2_flag)
  297. {
  298. printf ("#define HAVE_peephole2 1\n");
  299. printf ("#define MAX_INSNS_PER_PEEP2 %d\n", max_insns_per_peep2);
  300. }
  301. puts ("\n#endif /* GCC_INSN_CONFIG_H */");
  302. if (ferror (stdout) || fflush (stdout) || fclose (stdout))
  303. return FATAL_EXIT_CODE;
  304. return SUCCESS_EXIT_CODE;
  305. }