/GCC/gcc/config/v850/predicates.md

https://github.com/gatoatigrado/gccxmlclone · Markdown · 439 lines · 349 code · 90 blank · 0 comment · 0 complexity · 35915c2eac3dfbdf65055d1c91830be4 MD5 · raw file

  1. ;; Predicate definitions for NEC V850.
  2. ;; Copyright (C) 2005 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 2, 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 COPYING. If not, write to
  18. ;; the Free Software Foundation, 51 Franklin Street, Fifth Floor,
  19. ;; Boston, MA 02110-1301, USA.
  20. ;; Return true if OP is either a register or 0.
  21. (define_predicate "reg_or_0_operand"
  22. (match_code "reg,subreg,const_int,const_double")
  23. {
  24. if (GET_CODE (op) == CONST_INT)
  25. return INTVAL (op) == 0;
  26. else if (GET_CODE (op) == CONST_DOUBLE)
  27. return CONST_DOUBLE_OK_FOR_G (op);
  28. else
  29. return register_operand (op, mode);
  30. })
  31. ;; Return true if OP is either a register or a signed five bit
  32. ;; integer.
  33. (define_predicate "reg_or_int5_operand"
  34. (match_code "reg,subreg,const_int")
  35. {
  36. if (GET_CODE (op) == CONST_INT)
  37. return CONST_OK_FOR_J (INTVAL (op));
  38. else
  39. return register_operand (op, mode);
  40. })
  41. ;; Return true if OP is either a register or a signed nine bit
  42. ;; integer.
  43. (define_predicate "reg_or_int9_operand"
  44. (match_code "reg,subreg,const_int")
  45. {
  46. if (GET_CODE (op) == CONST_INT)
  47. return CONST_OK_FOR_O (INTVAL (op));
  48. return register_operand (op, mode);
  49. })
  50. ;; Return true if OP is either a register or a const integer.
  51. (define_predicate "reg_or_const_operand"
  52. (match_code "reg,const_int")
  53. {
  54. if (GET_CODE (op) == CONST_INT)
  55. return TRUE;
  56. return register_operand (op, mode);
  57. })
  58. ;; Return true if OP is a valid call operand.
  59. (define_predicate "call_address_operand"
  60. (match_code "reg,symbol_ref")
  61. {
  62. /* Only registers are valid call operands if TARGET_LONG_CALLS. */
  63. if (TARGET_LONG_CALLS)
  64. return GET_CODE (op) == REG;
  65. return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == REG);
  66. })
  67. ;; TODO: Add a comment here.
  68. (define_predicate "movsi_source_operand"
  69. (match_code "label_ref,symbol_ref,const_int,const_double,const,high,mem,reg,subreg")
  70. {
  71. /* Some constants, as well as symbolic operands
  72. must be done with HIGH & LO_SUM patterns. */
  73. if (CONSTANT_P (op)
  74. && GET_CODE (op) != HIGH
  75. && !(GET_CODE (op) == CONST_INT
  76. && (CONST_OK_FOR_J (INTVAL (op))
  77. || CONST_OK_FOR_K (INTVAL (op))
  78. || CONST_OK_FOR_L (INTVAL (op)))))
  79. return special_symbolref_operand (op, mode);
  80. else
  81. return general_operand (op, mode);
  82. })
  83. ;; TODO: Add a comment here.
  84. (define_predicate "special_symbolref_operand"
  85. (match_code "symbol_ref")
  86. {
  87. if (GET_CODE (op) == CONST
  88. && GET_CODE (XEXP (op, 0)) == PLUS
  89. && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT
  90. && CONST_OK_FOR_K (INTVAL (XEXP (XEXP (op, 0), 1))))
  91. op = XEXP (XEXP (op, 0), 0);
  92. if (GET_CODE (op) == SYMBOL_REF)
  93. return (SYMBOL_REF_FLAGS (op)
  94. & (SYMBOL_FLAG_ZDA | SYMBOL_FLAG_TDA | SYMBOL_FLAG_SDA)) != 0;
  95. return FALSE;
  96. })
  97. ;; TODO: Add a comment here.
  98. (define_predicate "power_of_two_operand"
  99. (match_code "const_int")
  100. {
  101. if (GET_CODE (op) != CONST_INT)
  102. return 0;
  103. if (exact_log2 (INTVAL (op)) == -1)
  104. return 0;
  105. return 1;
  106. })
  107. ;; Return nonzero if the given RTX is suitable for collapsing into a
  108. ;; jump to a function prologue.
  109. (define_predicate "pattern_is_ok_for_prologue"
  110. (match_code "parallel")
  111. {
  112. int count = XVECLEN (op, 0);
  113. int i;
  114. rtx vector_element;
  115. /* If there are no registers to save then the function prologue
  116. is not suitable. */
  117. if (count <= 2)
  118. return 0;
  119. /* The pattern matching has already established that we are adjusting the
  120. stack and pushing at least one register. We must now check that the
  121. remaining entries in the vector to make sure that they are also register
  122. pushes, except for the last entry which should be a CLOBBER of r10.
  123. The test below performs the C equivalent of this machine description
  124. pattern match:
  125. (set (mem:SI (plus:SI (reg:SI 3)
  126. (match_operand:SI 2 "immediate_operand" "i")))
  127. (match_operand:SI 3 "register_is_ok_for_epilogue" "r"))
  128. */
  129. for (i = 2; i < count - (TARGET_LONG_CALLS ? 2: 1); i++)
  130. {
  131. rtx dest;
  132. rtx src;
  133. rtx plus;
  134. vector_element = XVECEXP (op, 0, i);
  135. if (GET_CODE (vector_element) != SET)
  136. return 0;
  137. dest = SET_DEST (vector_element);
  138. src = SET_SRC (vector_element);
  139. if (GET_CODE (dest) != MEM
  140. || GET_MODE (dest) != SImode
  141. || GET_CODE (src) != REG
  142. || GET_MODE (src) != SImode
  143. || ! register_is_ok_for_epilogue (src, SImode))
  144. return 0;
  145. plus = XEXP (dest, 0);
  146. if ( GET_CODE (plus) != PLUS
  147. || GET_CODE (XEXP (plus, 0)) != REG
  148. || GET_MODE (XEXP (plus, 0)) != SImode
  149. || REGNO (XEXP (plus, 0)) != STACK_POINTER_REGNUM
  150. || GET_CODE (XEXP (plus, 1)) != CONST_INT)
  151. return 0;
  152. /* If the register is being pushed somewhere other than the stack
  153. space just acquired by the first operand then abandon this quest.
  154. Note: the test is <= because both values are negative. */
  155. if (INTVAL (XEXP (plus, 1))
  156. <= INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1)))
  157. {
  158. return 0;
  159. }
  160. }
  161. /* Make sure that the last entries in the vector are clobbers. */
  162. for (; i < count; i++)
  163. {
  164. vector_element = XVECEXP (op, 0, i);
  165. if (GET_CODE (vector_element) != CLOBBER
  166. || GET_CODE (XEXP (vector_element, 0)) != REG
  167. || !(REGNO (XEXP (vector_element, 0)) == 10
  168. || (TARGET_LONG_CALLS ? (REGNO (XEXP (vector_element, 0)) == 11) : 0 )))
  169. return 0;
  170. }
  171. return 1;
  172. })
  173. ;; Return nonzero if the given RTX is suitable for collapsing into
  174. ;; jump to a function epilogue.
  175. (define_predicate "pattern_is_ok_for_epilogue"
  176. (match_code "parallel")
  177. {
  178. int count = XVECLEN (op, 0);
  179. int i;
  180. /* If there are no registers to restore then the function epilogue
  181. is not suitable. */
  182. if (count <= 2)
  183. return 0;
  184. /* The pattern matching has already established that we are performing a
  185. function epilogue and that we are popping at least one register. We must
  186. now check the remaining entries in the vector to make sure that they are
  187. also register pops. There is no good reason why there should ever be
  188. anything else in this vector, but being paranoid always helps...
  189. The test below performs the C equivalent of this machine description
  190. pattern match:
  191. (set (match_operand:SI n "register_is_ok_for_epilogue" "r")
  192. (mem:SI (plus:SI (reg:SI 3) (match_operand:SI n "immediate_operand" "i"))))
  193. */
  194. for (i = 3; i < count; i++)
  195. {
  196. rtx vector_element = XVECEXP (op, 0, i);
  197. rtx dest;
  198. rtx src;
  199. rtx plus;
  200. if (GET_CODE (vector_element) != SET)
  201. return 0;
  202. dest = SET_DEST (vector_element);
  203. src = SET_SRC (vector_element);
  204. if (GET_CODE (dest) != REG
  205. || GET_MODE (dest) != SImode
  206. || ! register_is_ok_for_epilogue (dest, SImode)
  207. || GET_CODE (src) != MEM
  208. || GET_MODE (src) != SImode)
  209. return 0;
  210. plus = XEXP (src, 0);
  211. if (GET_CODE (plus) != PLUS
  212. || GET_CODE (XEXP (plus, 0)) != REG
  213. || GET_MODE (XEXP (plus, 0)) != SImode
  214. || REGNO (XEXP (plus, 0)) != STACK_POINTER_REGNUM
  215. || GET_CODE (XEXP (plus, 1)) != CONST_INT)
  216. return 0;
  217. }
  218. return 1;
  219. })
  220. ;; Return true if the given RTX is a register which can be restored by
  221. ;; a function epilogue.
  222. (define_predicate "register_is_ok_for_epilogue"
  223. (match_code "reg")
  224. {
  225. /* The save/restore routines can only cope with registers 20 - 31. */
  226. return ((GET_CODE (op) == REG)
  227. && (((REGNO (op) >= 20) && REGNO (op) <= 31)));
  228. })
  229. ;; Return nonzero if the given RTX is suitable for collapsing into a
  230. ;; DISPOSE instruction.
  231. (define_predicate "pattern_is_ok_for_dispose"
  232. (match_code "parallel")
  233. {
  234. int count = XVECLEN (op, 0);
  235. int i;
  236. /* If there are no registers to restore then
  237. the dispose instruction is not suitable. */
  238. if (count <= 2)
  239. return 0;
  240. /* The pattern matching has already established that we are performing a
  241. function epilogue and that we are popping at least one register. We must
  242. now check the remaining entries in the vector to make sure that they are
  243. also register pops. There is no good reason why there should ever be
  244. anything else in this vector, but being paranoid always helps...
  245. The test below performs the C equivalent of this machine description
  246. pattern match:
  247. (set (match_operand:SI n "register_is_ok_for_epilogue" "r")
  248. (mem:SI (plus:SI (reg:SI 3)
  249. (match_operand:SI n "immediate_operand" "i"))))
  250. */
  251. for (i = 3; i < count; i++)
  252. {
  253. rtx vector_element = XVECEXP (op, 0, i);
  254. rtx dest;
  255. rtx src;
  256. rtx plus;
  257. if (GET_CODE (vector_element) != SET)
  258. return 0;
  259. dest = SET_DEST (vector_element);
  260. src = SET_SRC (vector_element);
  261. if ( GET_CODE (dest) != REG
  262. || GET_MODE (dest) != SImode
  263. || ! register_is_ok_for_epilogue (dest, SImode)
  264. || GET_CODE (src) != MEM
  265. || GET_MODE (src) != SImode)
  266. return 0;
  267. plus = XEXP (src, 0);
  268. if ( GET_CODE (plus) != PLUS
  269. || GET_CODE (XEXP (plus, 0)) != REG
  270. || GET_MODE (XEXP (plus, 0)) != SImode
  271. || REGNO (XEXP (plus, 0)) != STACK_POINTER_REGNUM
  272. || GET_CODE (XEXP (plus, 1)) != CONST_INT)
  273. return 0;
  274. }
  275. return 1;
  276. })
  277. ;; Return nonzero if the given RTX is suitable for collapsing into a
  278. ;; PREPARE instruction.
  279. (define_predicate "pattern_is_ok_for_prepare"
  280. (match_code "parallel")
  281. {
  282. int count = XVECLEN (op, 0);
  283. int i;
  284. /* If there are no registers to restore then the prepare instruction
  285. is not suitable. */
  286. if (count <= 1)
  287. return 0;
  288. /* The pattern matching has already established that we are adjusting the
  289. stack and pushing at least one register. We must now check that the
  290. remaining entries in the vector to make sure that they are also register
  291. pushes.
  292. The test below performs the C equivalent of this machine description
  293. pattern match:
  294. (set (mem:SI (plus:SI (reg:SI 3)
  295. (match_operand:SI 2 "immediate_operand" "i")))
  296. (match_operand:SI 3 "register_is_ok_for_epilogue" "r"))
  297. */
  298. for (i = 2; i < count; i++)
  299. {
  300. rtx vector_element = XVECEXP (op, 0, i);
  301. rtx dest;
  302. rtx src;
  303. rtx plus;
  304. if (GET_CODE (vector_element) != SET)
  305. return 0;
  306. dest = SET_DEST (vector_element);
  307. src = SET_SRC (vector_element);
  308. if ( GET_CODE (dest) != MEM
  309. || GET_MODE (dest) != SImode
  310. || GET_CODE (src) != REG
  311. || GET_MODE (src) != SImode
  312. || ! register_is_ok_for_epilogue (src, SImode)
  313. )
  314. return 0;
  315. plus = XEXP (dest, 0);
  316. if ( GET_CODE (plus) != PLUS
  317. || GET_CODE (XEXP (plus, 0)) != REG
  318. || GET_MODE (XEXP (plus, 0)) != SImode
  319. || REGNO (XEXP (plus, 0)) != STACK_POINTER_REGNUM
  320. || GET_CODE (XEXP (plus, 1)) != CONST_INT)
  321. return 0;
  322. /* If the register is being pushed somewhere other than the stack
  323. space just acquired by the first operand then abandon this quest.
  324. Note: the test is <= because both values are negative. */
  325. if (INTVAL (XEXP (plus, 1))
  326. <= INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1)))
  327. return 0;
  328. }
  329. return 1;
  330. })
  331. ;; TODO: Add a comment here.
  332. (define_predicate "not_power_of_two_operand"
  333. (match_code "const_int")
  334. {
  335. unsigned int mask;
  336. if (mode == QImode)
  337. mask = 0xff;
  338. else if (mode == HImode)
  339. mask = 0xffff;
  340. else if (mode == SImode)
  341. mask = 0xffffffff;
  342. else
  343. return 0;
  344. if (GET_CODE (op) != CONST_INT)
  345. return 0;
  346. if (exact_log2 (~INTVAL (op) & mask) == -1)
  347. return 0;
  348. return 1;
  349. })