hard-reg-set.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. /* Sets (bit vectors) of hard registers, and operations on them.
  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_HARD_REG_SET_H
  16. #define GCC_HARD_REG_SET_H
  17. #include "hash-table.h"
  18. /* Define the type of a set of hard registers. */
  19. /* HARD_REG_ELT_TYPE is a typedef of the unsigned integral type which
  20. will be used for hard reg sets, either alone or in an array.
  21. If HARD_REG_SET is a macro, its definition is HARD_REG_ELT_TYPE,
  22. and it has enough bits to represent all the target machine's hard
  23. registers. Otherwise, it is a typedef for a suitably sized array
  24. of HARD_REG_ELT_TYPEs. HARD_REG_SET_LONGS is defined as how many.
  25. Note that lots of code assumes that the first part of a regset is
  26. the same format as a HARD_REG_SET. To help make sure this is true,
  27. we only try the widest fast integer mode (HOST_WIDEST_FAST_INT)
  28. instead of all the smaller types. This approach loses only if
  29. there are very few registers and then only in the few cases where
  30. we have an array of HARD_REG_SETs, so it needn't be as complex as
  31. it used to be. */
  32. typedef unsigned HOST_WIDEST_FAST_INT HARD_REG_ELT_TYPE;
  33. #if FIRST_PSEUDO_REGISTER <= HOST_BITS_PER_WIDEST_FAST_INT
  34. #define HARD_REG_SET HARD_REG_ELT_TYPE
  35. #else
  36. #define HARD_REG_SET_LONGS \
  37. ((FIRST_PSEUDO_REGISTER + HOST_BITS_PER_WIDEST_FAST_INT - 1) \
  38. / HOST_BITS_PER_WIDEST_FAST_INT)
  39. typedef HARD_REG_ELT_TYPE HARD_REG_SET[HARD_REG_SET_LONGS];
  40. #endif
  41. /* HARD_REG_SET wrapped into a structure, to make it possible to
  42. use HARD_REG_SET even in APIs that should not include
  43. hard-reg-set.h. */
  44. struct hard_reg_set_container
  45. {
  46. HARD_REG_SET set;
  47. };
  48. /* HARD_CONST is used to cast a constant to the appropriate type
  49. for use with a HARD_REG_SET. */
  50. #define HARD_CONST(X) ((HARD_REG_ELT_TYPE) (X))
  51. /* Define macros SET_HARD_REG_BIT, CLEAR_HARD_REG_BIT and TEST_HARD_REG_BIT
  52. to set, clear or test one bit in a hard reg set of type HARD_REG_SET.
  53. All three take two arguments: the set and the register number.
  54. In the case where sets are arrays of longs, the first argument
  55. is actually a pointer to a long.
  56. Define two macros for initializing a set:
  57. CLEAR_HARD_REG_SET and SET_HARD_REG_SET.
  58. These take just one argument.
  59. Also define macros for copying hard reg sets:
  60. COPY_HARD_REG_SET and COMPL_HARD_REG_SET.
  61. These take two arguments TO and FROM; they read from FROM
  62. and store into TO. COMPL_HARD_REG_SET complements each bit.
  63. Also define macros for combining hard reg sets:
  64. IOR_HARD_REG_SET and AND_HARD_REG_SET.
  65. These take two arguments TO and FROM; they read from FROM
  66. and combine bitwise into TO. Define also two variants
  67. IOR_COMPL_HARD_REG_SET and AND_COMPL_HARD_REG_SET
  68. which use the complement of the set FROM.
  69. Also define:
  70. hard_reg_set_subset_p (X, Y), which returns true if X is a subset of Y.
  71. hard_reg_set_equal_p (X, Y), which returns true if X and Y are equal.
  72. hard_reg_set_intersect_p (X, Y), which returns true if X and Y intersect.
  73. hard_reg_set_empty_p (X), which returns true if X is empty. */
  74. #define UHOST_BITS_PER_WIDE_INT ((unsigned) HOST_BITS_PER_WIDEST_FAST_INT)
  75. #ifdef HARD_REG_SET
  76. #define SET_HARD_REG_BIT(SET, BIT) \
  77. ((SET) |= HARD_CONST (1) << (BIT))
  78. #define CLEAR_HARD_REG_BIT(SET, BIT) \
  79. ((SET) &= ~(HARD_CONST (1) << (BIT)))
  80. #define TEST_HARD_REG_BIT(SET, BIT) \
  81. (!!((SET) & (HARD_CONST (1) << (BIT))))
  82. #define CLEAR_HARD_REG_SET(TO) ((TO) = HARD_CONST (0))
  83. #define SET_HARD_REG_SET(TO) ((TO) = ~ HARD_CONST (0))
  84. #define COPY_HARD_REG_SET(TO, FROM) ((TO) = (FROM))
  85. #define COMPL_HARD_REG_SET(TO, FROM) ((TO) = ~(FROM))
  86. #define IOR_HARD_REG_SET(TO, FROM) ((TO) |= (FROM))
  87. #define IOR_COMPL_HARD_REG_SET(TO, FROM) ((TO) |= ~ (FROM))
  88. #define AND_HARD_REG_SET(TO, FROM) ((TO) &= (FROM))
  89. #define AND_COMPL_HARD_REG_SET(TO, FROM) ((TO) &= ~ (FROM))
  90. static inline bool
  91. hard_reg_set_subset_p (const HARD_REG_SET x, const HARD_REG_SET y)
  92. {
  93. return (x & ~y) == HARD_CONST (0);
  94. }
  95. static inline bool
  96. hard_reg_set_equal_p (const HARD_REG_SET x, const HARD_REG_SET y)
  97. {
  98. return x == y;
  99. }
  100. static inline bool
  101. hard_reg_set_intersect_p (const HARD_REG_SET x, const HARD_REG_SET y)
  102. {
  103. return (x & y) != HARD_CONST (0);
  104. }
  105. static inline bool
  106. hard_reg_set_empty_p (const HARD_REG_SET x)
  107. {
  108. return x == HARD_CONST (0);
  109. }
  110. #else
  111. #define SET_HARD_REG_BIT(SET, BIT) \
  112. ((SET)[(BIT) / UHOST_BITS_PER_WIDE_INT] \
  113. |= HARD_CONST (1) << ((BIT) % UHOST_BITS_PER_WIDE_INT))
  114. #define CLEAR_HARD_REG_BIT(SET, BIT) \
  115. ((SET)[(BIT) / UHOST_BITS_PER_WIDE_INT] \
  116. &= ~(HARD_CONST (1) << ((BIT) % UHOST_BITS_PER_WIDE_INT)))
  117. #define TEST_HARD_REG_BIT(SET, BIT) \
  118. (!!((SET)[(BIT) / UHOST_BITS_PER_WIDE_INT] \
  119. & (HARD_CONST (1) << ((BIT) % UHOST_BITS_PER_WIDE_INT))))
  120. #if FIRST_PSEUDO_REGISTER <= 2*HOST_BITS_PER_WIDEST_FAST_INT
  121. #define CLEAR_HARD_REG_SET(TO) \
  122. do { HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
  123. scan_tp_[0] = 0; \
  124. scan_tp_[1] = 0; } while (0)
  125. #define SET_HARD_REG_SET(TO) \
  126. do { HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
  127. scan_tp_[0] = -1; \
  128. scan_tp_[1] = -1; } while (0)
  129. #define COPY_HARD_REG_SET(TO, FROM) \
  130. do { HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
  131. const HARD_REG_ELT_TYPE *scan_fp_ = (FROM); \
  132. scan_tp_[0] = scan_fp_[0]; \
  133. scan_tp_[1] = scan_fp_[1]; } while (0)
  134. #define COMPL_HARD_REG_SET(TO, FROM) \
  135. do { HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
  136. const HARD_REG_ELT_TYPE *scan_fp_ = (FROM); \
  137. scan_tp_[0] = ~ scan_fp_[0]; \
  138. scan_tp_[1] = ~ scan_fp_[1]; } while (0)
  139. #define AND_HARD_REG_SET(TO, FROM) \
  140. do { HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
  141. const HARD_REG_ELT_TYPE *scan_fp_ = (FROM); \
  142. scan_tp_[0] &= scan_fp_[0]; \
  143. scan_tp_[1] &= scan_fp_[1]; } while (0)
  144. #define AND_COMPL_HARD_REG_SET(TO, FROM) \
  145. do { HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
  146. const HARD_REG_ELT_TYPE *scan_fp_ = (FROM); \
  147. scan_tp_[0] &= ~ scan_fp_[0]; \
  148. scan_tp_[1] &= ~ scan_fp_[1]; } while (0)
  149. #define IOR_HARD_REG_SET(TO, FROM) \
  150. do { HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
  151. const HARD_REG_ELT_TYPE *scan_fp_ = (FROM); \
  152. scan_tp_[0] |= scan_fp_[0]; \
  153. scan_tp_[1] |= scan_fp_[1]; } while (0)
  154. #define IOR_COMPL_HARD_REG_SET(TO, FROM) \
  155. do { HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
  156. const HARD_REG_ELT_TYPE *scan_fp_ = (FROM); \
  157. scan_tp_[0] |= ~ scan_fp_[0]; \
  158. scan_tp_[1] |= ~ scan_fp_[1]; } while (0)
  159. static inline bool
  160. hard_reg_set_subset_p (const HARD_REG_SET x, const HARD_REG_SET y)
  161. {
  162. return (x[0] & ~y[0]) == 0 && (x[1] & ~y[1]) == 0;
  163. }
  164. static inline bool
  165. hard_reg_set_equal_p (const HARD_REG_SET x, const HARD_REG_SET y)
  166. {
  167. return x[0] == y[0] && x[1] == y[1];
  168. }
  169. static inline bool
  170. hard_reg_set_intersect_p (const HARD_REG_SET x, const HARD_REG_SET y)
  171. {
  172. return (x[0] & y[0]) != 0 || (x[1] & y[1]) != 0;
  173. }
  174. static inline bool
  175. hard_reg_set_empty_p (const HARD_REG_SET x)
  176. {
  177. return x[0] == 0 && x[1] == 0;
  178. }
  179. #else
  180. #if FIRST_PSEUDO_REGISTER <= 3*HOST_BITS_PER_WIDEST_FAST_INT
  181. #define CLEAR_HARD_REG_SET(TO) \
  182. do { HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
  183. scan_tp_[0] = 0; \
  184. scan_tp_[1] = 0; \
  185. scan_tp_[2] = 0; } while (0)
  186. #define SET_HARD_REG_SET(TO) \
  187. do { HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
  188. scan_tp_[0] = -1; \
  189. scan_tp_[1] = -1; \
  190. scan_tp_[2] = -1; } while (0)
  191. #define COPY_HARD_REG_SET(TO, FROM) \
  192. do { HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
  193. const HARD_REG_ELT_TYPE *scan_fp_ = (FROM); \
  194. scan_tp_[0] = scan_fp_[0]; \
  195. scan_tp_[1] = scan_fp_[1]; \
  196. scan_tp_[2] = scan_fp_[2]; } while (0)
  197. #define COMPL_HARD_REG_SET(TO, FROM) \
  198. do { HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
  199. const HARD_REG_ELT_TYPE *scan_fp_ = (FROM); \
  200. scan_tp_[0] = ~ scan_fp_[0]; \
  201. scan_tp_[1] = ~ scan_fp_[1]; \
  202. scan_tp_[2] = ~ scan_fp_[2]; } while (0)
  203. #define AND_HARD_REG_SET(TO, FROM) \
  204. do { HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
  205. const HARD_REG_ELT_TYPE *scan_fp_ = (FROM); \
  206. scan_tp_[0] &= scan_fp_[0]; \
  207. scan_tp_[1] &= scan_fp_[1]; \
  208. scan_tp_[2] &= scan_fp_[2]; } while (0)
  209. #define AND_COMPL_HARD_REG_SET(TO, FROM) \
  210. do { HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
  211. const HARD_REG_ELT_TYPE *scan_fp_ = (FROM); \
  212. scan_tp_[0] &= ~ scan_fp_[0]; \
  213. scan_tp_[1] &= ~ scan_fp_[1]; \
  214. scan_tp_[2] &= ~ scan_fp_[2]; } while (0)
  215. #define IOR_HARD_REG_SET(TO, FROM) \
  216. do { HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
  217. const HARD_REG_ELT_TYPE *scan_fp_ = (FROM); \
  218. scan_tp_[0] |= scan_fp_[0]; \
  219. scan_tp_[1] |= scan_fp_[1]; \
  220. scan_tp_[2] |= scan_fp_[2]; } while (0)
  221. #define IOR_COMPL_HARD_REG_SET(TO, FROM) \
  222. do { HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
  223. const HARD_REG_ELT_TYPE *scan_fp_ = (FROM); \
  224. scan_tp_[0] |= ~ scan_fp_[0]; \
  225. scan_tp_[1] |= ~ scan_fp_[1]; \
  226. scan_tp_[2] |= ~ scan_fp_[2]; } while (0)
  227. static inline bool
  228. hard_reg_set_subset_p (const HARD_REG_SET x, const HARD_REG_SET y)
  229. {
  230. return ((x[0] & ~y[0]) == 0
  231. && (x[1] & ~y[1]) == 0
  232. && (x[2] & ~y[2]) == 0);
  233. }
  234. static inline bool
  235. hard_reg_set_equal_p (const HARD_REG_SET x, const HARD_REG_SET y)
  236. {
  237. return x[0] == y[0] && x[1] == y[1] && x[2] == y[2];
  238. }
  239. static inline bool
  240. hard_reg_set_intersect_p (const HARD_REG_SET x, const HARD_REG_SET y)
  241. {
  242. return ((x[0] & y[0]) != 0
  243. || (x[1] & y[1]) != 0
  244. || (x[2] & y[2]) != 0);
  245. }
  246. static inline bool
  247. hard_reg_set_empty_p (const HARD_REG_SET x)
  248. {
  249. return x[0] == 0 && x[1] == 0 && x[2] == 0;
  250. }
  251. #else
  252. #if FIRST_PSEUDO_REGISTER <= 4*HOST_BITS_PER_WIDEST_FAST_INT
  253. #define CLEAR_HARD_REG_SET(TO) \
  254. do { HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
  255. scan_tp_[0] = 0; \
  256. scan_tp_[1] = 0; \
  257. scan_tp_[2] = 0; \
  258. scan_tp_[3] = 0; } while (0)
  259. #define SET_HARD_REG_SET(TO) \
  260. do { HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
  261. scan_tp_[0] = -1; \
  262. scan_tp_[1] = -1; \
  263. scan_tp_[2] = -1; \
  264. scan_tp_[3] = -1; } while (0)
  265. #define COPY_HARD_REG_SET(TO, FROM) \
  266. do { HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
  267. const HARD_REG_ELT_TYPE *scan_fp_ = (FROM); \
  268. scan_tp_[0] = scan_fp_[0]; \
  269. scan_tp_[1] = scan_fp_[1]; \
  270. scan_tp_[2] = scan_fp_[2]; \
  271. scan_tp_[3] = scan_fp_[3]; } while (0)
  272. #define COMPL_HARD_REG_SET(TO, FROM) \
  273. do { HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
  274. const HARD_REG_ELT_TYPE *scan_fp_ = (FROM); \
  275. scan_tp_[0] = ~ scan_fp_[0]; \
  276. scan_tp_[1] = ~ scan_fp_[1]; \
  277. scan_tp_[2] = ~ scan_fp_[2]; \
  278. scan_tp_[3] = ~ scan_fp_[3]; } while (0)
  279. #define AND_HARD_REG_SET(TO, FROM) \
  280. do { HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
  281. const HARD_REG_ELT_TYPE *scan_fp_ = (FROM); \
  282. scan_tp_[0] &= scan_fp_[0]; \
  283. scan_tp_[1] &= scan_fp_[1]; \
  284. scan_tp_[2] &= scan_fp_[2]; \
  285. scan_tp_[3] &= scan_fp_[3]; } while (0)
  286. #define AND_COMPL_HARD_REG_SET(TO, FROM) \
  287. do { HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
  288. const HARD_REG_ELT_TYPE *scan_fp_ = (FROM); \
  289. scan_tp_[0] &= ~ scan_fp_[0]; \
  290. scan_tp_[1] &= ~ scan_fp_[1]; \
  291. scan_tp_[2] &= ~ scan_fp_[2]; \
  292. scan_tp_[3] &= ~ scan_fp_[3]; } while (0)
  293. #define IOR_HARD_REG_SET(TO, FROM) \
  294. do { HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
  295. const HARD_REG_ELT_TYPE *scan_fp_ = (FROM); \
  296. scan_tp_[0] |= scan_fp_[0]; \
  297. scan_tp_[1] |= scan_fp_[1]; \
  298. scan_tp_[2] |= scan_fp_[2]; \
  299. scan_tp_[3] |= scan_fp_[3]; } while (0)
  300. #define IOR_COMPL_HARD_REG_SET(TO, FROM) \
  301. do { HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
  302. const HARD_REG_ELT_TYPE *scan_fp_ = (FROM); \
  303. scan_tp_[0] |= ~ scan_fp_[0]; \
  304. scan_tp_[1] |= ~ scan_fp_[1]; \
  305. scan_tp_[2] |= ~ scan_fp_[2]; \
  306. scan_tp_[3] |= ~ scan_fp_[3]; } while (0)
  307. static inline bool
  308. hard_reg_set_subset_p (const HARD_REG_SET x, const HARD_REG_SET y)
  309. {
  310. return ((x[0] & ~y[0]) == 0
  311. && (x[1] & ~y[1]) == 0
  312. && (x[2] & ~y[2]) == 0
  313. && (x[3] & ~y[3]) == 0);
  314. }
  315. static inline bool
  316. hard_reg_set_equal_p (const HARD_REG_SET x, const HARD_REG_SET y)
  317. {
  318. return x[0] == y[0] && x[1] == y[1] && x[2] == y[2] && x[3] == y[3];
  319. }
  320. static inline bool
  321. hard_reg_set_intersect_p (const HARD_REG_SET x, const HARD_REG_SET y)
  322. {
  323. return ((x[0] & y[0]) != 0
  324. || (x[1] & y[1]) != 0
  325. || (x[2] & y[2]) != 0
  326. || (x[3] & y[3]) != 0);
  327. }
  328. static inline bool
  329. hard_reg_set_empty_p (const HARD_REG_SET x)
  330. {
  331. return x[0] == 0 && x[1] == 0 && x[2] == 0 && x[3] == 0;
  332. }
  333. #else /* FIRST_PSEUDO_REGISTER > 4*HOST_BITS_PER_WIDEST_FAST_INT */
  334. #define CLEAR_HARD_REG_SET(TO) \
  335. do { HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
  336. int i; \
  337. for (i = 0; i < HARD_REG_SET_LONGS; i++) \
  338. *scan_tp_++ = 0; } while (0)
  339. #define SET_HARD_REG_SET(TO) \
  340. do { HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
  341. int i; \
  342. for (i = 0; i < HARD_REG_SET_LONGS; i++) \
  343. *scan_tp_++ = -1; } while (0)
  344. #define COPY_HARD_REG_SET(TO, FROM) \
  345. do { HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
  346. const HARD_REG_ELT_TYPE *scan_fp_ = (FROM); \
  347. int i; \
  348. for (i = 0; i < HARD_REG_SET_LONGS; i++) \
  349. *scan_tp_++ = *scan_fp_++; } while (0)
  350. #define COMPL_HARD_REG_SET(TO, FROM) \
  351. do { HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
  352. const HARD_REG_ELT_TYPE *scan_fp_ = (FROM); \
  353. int i; \
  354. for (i = 0; i < HARD_REG_SET_LONGS; i++) \
  355. *scan_tp_++ = ~ *scan_fp_++; } while (0)
  356. #define AND_HARD_REG_SET(TO, FROM) \
  357. do { HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
  358. const HARD_REG_ELT_TYPE *scan_fp_ = (FROM); \
  359. int i; \
  360. for (i = 0; i < HARD_REG_SET_LONGS; i++) \
  361. *scan_tp_++ &= *scan_fp_++; } while (0)
  362. #define AND_COMPL_HARD_REG_SET(TO, FROM) \
  363. do { HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
  364. const HARD_REG_ELT_TYPE *scan_fp_ = (FROM); \
  365. int i; \
  366. for (i = 0; i < HARD_REG_SET_LONGS; i++) \
  367. *scan_tp_++ &= ~ *scan_fp_++; } while (0)
  368. #define IOR_HARD_REG_SET(TO, FROM) \
  369. do { HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
  370. const HARD_REG_ELT_TYPE *scan_fp_ = (FROM); \
  371. int i; \
  372. for (i = 0; i < HARD_REG_SET_LONGS; i++) \
  373. *scan_tp_++ |= *scan_fp_++; } while (0)
  374. #define IOR_COMPL_HARD_REG_SET(TO, FROM) \
  375. do { HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
  376. const HARD_REG_ELT_TYPE *scan_fp_ = (FROM); \
  377. int i; \
  378. for (i = 0; i < HARD_REG_SET_LONGS; i++) \
  379. *scan_tp_++ |= ~ *scan_fp_++; } while (0)
  380. static inline bool
  381. hard_reg_set_subset_p (const HARD_REG_SET x, const HARD_REG_SET y)
  382. {
  383. int i;
  384. for (i = 0; i < HARD_REG_SET_LONGS; i++)
  385. if ((x[i] & ~y[i]) != 0)
  386. return false;
  387. return true;
  388. }
  389. static inline bool
  390. hard_reg_set_equal_p (const HARD_REG_SET x, const HARD_REG_SET y)
  391. {
  392. int i;
  393. for (i = 0; i < HARD_REG_SET_LONGS; i++)
  394. if (x[i] != y[i])
  395. return false;
  396. return true;
  397. }
  398. static inline bool
  399. hard_reg_set_intersect_p (const HARD_REG_SET x, const HARD_REG_SET y)
  400. {
  401. int i;
  402. for (i = 0; i < HARD_REG_SET_LONGS; i++)
  403. if ((x[i] & y[i]) != 0)
  404. return true;
  405. return false;
  406. }
  407. static inline bool
  408. hard_reg_set_empty_p (const HARD_REG_SET x)
  409. {
  410. int i;
  411. for (i = 0; i < HARD_REG_SET_LONGS; i++)
  412. if (x[i] != 0)
  413. return false;
  414. return true;
  415. }
  416. #endif
  417. #endif
  418. #endif
  419. #endif
  420. /* Iterator for hard register sets. */
  421. struct hard_reg_set_iterator
  422. {
  423. /* Pointer to the current element. */
  424. HARD_REG_ELT_TYPE *pelt;
  425. /* The length of the set. */
  426. unsigned short length;
  427. /* Word within the current element. */
  428. unsigned short word_no;
  429. /* Contents of the actually processed word. When finding next bit
  430. it is shifted right, so that the actual bit is always the least
  431. significant bit of ACTUAL. */
  432. HARD_REG_ELT_TYPE bits;
  433. };
  434. #define HARD_REG_ELT_BITS UHOST_BITS_PER_WIDE_INT
  435. /* The implementation of the iterator functions is fully analogous to
  436. the bitmap iterators. */
  437. static inline void
  438. hard_reg_set_iter_init (hard_reg_set_iterator *iter, HARD_REG_SET set,
  439. unsigned min, unsigned *regno)
  440. {
  441. #ifdef HARD_REG_SET_LONGS
  442. iter->pelt = set;
  443. iter->length = HARD_REG_SET_LONGS;
  444. #else
  445. iter->pelt = &set;
  446. iter->length = 1;
  447. #endif
  448. iter->word_no = min / HARD_REG_ELT_BITS;
  449. if (iter->word_no < iter->length)
  450. {
  451. iter->bits = iter->pelt[iter->word_no];
  452. iter->bits >>= min % HARD_REG_ELT_BITS;
  453. /* This is required for correct search of the next bit. */
  454. min += !iter->bits;
  455. }
  456. *regno = min;
  457. }
  458. static inline bool
  459. hard_reg_set_iter_set (hard_reg_set_iterator *iter, unsigned *regno)
  460. {
  461. while (1)
  462. {
  463. /* Return false when we're advanced past the end of the set. */
  464. if (iter->word_no >= iter->length)
  465. return false;
  466. if (iter->bits)
  467. {
  468. /* Find the correct bit and return it. */
  469. while (!(iter->bits & 1))
  470. {
  471. iter->bits >>= 1;
  472. *regno += 1;
  473. }
  474. return (*regno < FIRST_PSEUDO_REGISTER);
  475. }
  476. /* Round to the beginning of the next word. */
  477. *regno = (*regno + HARD_REG_ELT_BITS - 1);
  478. *regno -= *regno % HARD_REG_ELT_BITS;
  479. /* Find the next non-zero word. */
  480. while (++iter->word_no < iter->length)
  481. {
  482. iter->bits = iter->pelt[iter->word_no];
  483. if (iter->bits)
  484. break;
  485. *regno += HARD_REG_ELT_BITS;
  486. }
  487. }
  488. }
  489. static inline void
  490. hard_reg_set_iter_next (hard_reg_set_iterator *iter, unsigned *regno)
  491. {
  492. iter->bits >>= 1;
  493. *regno += 1;
  494. }
  495. #define EXECUTE_IF_SET_IN_HARD_REG_SET(SET, MIN, REGNUM, ITER) \
  496. for (hard_reg_set_iter_init (&(ITER), (SET), (MIN), &(REGNUM)); \
  497. hard_reg_set_iter_set (&(ITER), &(REGNUM)); \
  498. hard_reg_set_iter_next (&(ITER), &(REGNUM)))
  499. /* Define some standard sets of registers. */
  500. /* Indexed by hard register number, contains 1 for registers
  501. that are being used for global register decls.
  502. These must be exempt from ordinary flow analysis
  503. and are also considered fixed. */
  504. extern char global_regs[FIRST_PSEUDO_REGISTER];
  505. struct simplifiable_subregs_hasher;
  506. struct target_hard_regs {
  507. void finalize ();
  508. /* The set of registers that actually exist on the current target. */
  509. HARD_REG_SET x_accessible_reg_set;
  510. /* The set of registers that should be considered to be register
  511. operands. It is a subset of x_accessible_reg_set. */
  512. HARD_REG_SET x_operand_reg_set;
  513. /* Indexed by hard register number, contains 1 for registers
  514. that are fixed use (stack pointer, pc, frame pointer, etc.;.
  515. These are the registers that cannot be used to allocate
  516. a pseudo reg whose life does not cross calls. */
  517. char x_fixed_regs[FIRST_PSEUDO_REGISTER];
  518. /* The same info as a HARD_REG_SET. */
  519. HARD_REG_SET x_fixed_reg_set;
  520. /* Indexed by hard register number, contains 1 for registers
  521. that are fixed use or are clobbered by function calls.
  522. These are the registers that cannot be used to allocate
  523. a pseudo reg whose life crosses calls. */
  524. char x_call_used_regs[FIRST_PSEUDO_REGISTER];
  525. char x_call_really_used_regs[FIRST_PSEUDO_REGISTER];
  526. /* The same info as a HARD_REG_SET. */
  527. HARD_REG_SET x_call_used_reg_set;
  528. /* Contains registers that are fixed use -- i.e. in fixed_reg_set -- or
  529. a function value return register or TARGET_STRUCT_VALUE_RTX or
  530. STATIC_CHAIN_REGNUM. These are the registers that cannot hold quantities
  531. across calls even if we are willing to save and restore them. */
  532. HARD_REG_SET x_call_fixed_reg_set;
  533. /* Contains 1 for registers that are set or clobbered by calls. */
  534. /* ??? Ideally, this would be just call_used_regs plus global_regs, but
  535. for someone's bright idea to have call_used_regs strictly include
  536. fixed_regs. Which leaves us guessing as to the set of fixed_regs
  537. that are actually preserved. We know for sure that those associated
  538. with the local stack frame are safe, but scant others. */
  539. HARD_REG_SET x_regs_invalidated_by_call;
  540. /* Call used hard registers which can not be saved because there is no
  541. insn for this. */
  542. HARD_REG_SET x_no_caller_save_reg_set;
  543. /* Table of register numbers in the order in which to try to use them. */
  544. int x_reg_alloc_order[FIRST_PSEUDO_REGISTER];
  545. /* The inverse of reg_alloc_order. */
  546. int x_inv_reg_alloc_order[FIRST_PSEUDO_REGISTER];
  547. /* For each reg class, a HARD_REG_SET saying which registers are in it. */
  548. HARD_REG_SET x_reg_class_contents[N_REG_CLASSES];
  549. /* For each reg class, a boolean saying whether the class contains only
  550. fixed registers. */
  551. bool x_class_only_fixed_regs[N_REG_CLASSES];
  552. /* For each reg class, number of regs it contains. */
  553. unsigned int x_reg_class_size[N_REG_CLASSES];
  554. /* For each reg class, table listing all the classes contained in it. */
  555. enum reg_class x_reg_class_subclasses[N_REG_CLASSES][N_REG_CLASSES];
  556. /* For each pair of reg classes,
  557. a largest reg class contained in their union. */
  558. enum reg_class x_reg_class_subunion[N_REG_CLASSES][N_REG_CLASSES];
  559. /* For each pair of reg classes,
  560. the smallest reg class that contains their union. */
  561. enum reg_class x_reg_class_superunion[N_REG_CLASSES][N_REG_CLASSES];
  562. /* Vector indexed by hardware reg giving its name. */
  563. const char *x_reg_names[FIRST_PSEUDO_REGISTER];
  564. /* Records which registers can form a particular subreg, with the subreg
  565. being identified by its outer mode, inner mode and offset. */
  566. hash_table <simplifiable_subregs_hasher> *x_simplifiable_subregs;
  567. };
  568. extern struct target_hard_regs default_target_hard_regs;
  569. #if SWITCHABLE_TARGET
  570. extern struct target_hard_regs *this_target_hard_regs;
  571. #else
  572. #define this_target_hard_regs (&default_target_hard_regs)
  573. #endif
  574. #define accessible_reg_set \
  575. (this_target_hard_regs->x_accessible_reg_set)
  576. #define operand_reg_set \
  577. (this_target_hard_regs->x_operand_reg_set)
  578. #define fixed_regs \
  579. (this_target_hard_regs->x_fixed_regs)
  580. #define fixed_reg_set \
  581. (this_target_hard_regs->x_fixed_reg_set)
  582. #define call_used_regs \
  583. (this_target_hard_regs->x_call_used_regs)
  584. #define call_really_used_regs \
  585. (this_target_hard_regs->x_call_really_used_regs)
  586. #define call_used_reg_set \
  587. (this_target_hard_regs->x_call_used_reg_set)
  588. #define call_fixed_reg_set \
  589. (this_target_hard_regs->x_call_fixed_reg_set)
  590. #define regs_invalidated_by_call \
  591. (this_target_hard_regs->x_regs_invalidated_by_call)
  592. #define no_caller_save_reg_set \
  593. (this_target_hard_regs->x_no_caller_save_reg_set)
  594. #define reg_alloc_order \
  595. (this_target_hard_regs->x_reg_alloc_order)
  596. #define inv_reg_alloc_order \
  597. (this_target_hard_regs->x_inv_reg_alloc_order)
  598. #define reg_class_contents \
  599. (this_target_hard_regs->x_reg_class_contents)
  600. #define class_only_fixed_regs \
  601. (this_target_hard_regs->x_class_only_fixed_regs)
  602. #define reg_class_size \
  603. (this_target_hard_regs->x_reg_class_size)
  604. #define reg_class_subclasses \
  605. (this_target_hard_regs->x_reg_class_subclasses)
  606. #define reg_class_subunion \
  607. (this_target_hard_regs->x_reg_class_subunion)
  608. #define reg_class_superunion \
  609. (this_target_hard_regs->x_reg_class_superunion)
  610. #define reg_names \
  611. (this_target_hard_regs->x_reg_names)
  612. /* Vector indexed by reg class giving its name. */
  613. extern const char * reg_class_names[];
  614. /* Given a hard REGN a FROM mode and a TO mode, return nonzero if
  615. REGN cannot change modes between the specified modes. */
  616. #define REG_CANNOT_CHANGE_MODE_P(REGN, FROM, TO) \
  617. CANNOT_CHANGE_MODE_CLASS (FROM, TO, REGNO_REG_CLASS (REGN))
  618. #endif /* ! GCC_HARD_REG_SET_H */