hard-reg-set.h 24 KB

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