1 /* Sets (bit vectors) of hard registers, and operations on them.
2 Copyright (C) 1987, 1992, 1994 Free Software Foundation, Inc.
4 This file is part of GNU CC
6 GNU CC 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)
11 GNU CC 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.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 /* Define the type of a set of hard registers. */
24 /* HARD_REG_ELT_TYPE is a typedef of the unsigned integral type which
25 will be used for hard reg sets, either alone or in an array.
27 If HARD_REG_SET is a macro, its definition is HARD_REG_ELT_TYPE,
28 and it has enough bits to represent all the target machine's hard
29 registers. Otherwise, it is a typedef for a suitably sized array
30 of HARD_REG_ELT_TYPEs. HARD_REG_SET_LONGS is defined as how many.
32 Note that lots of code assumes that the first part of a regset is
33 the same format as a HARD_REG_SET. To help make sure this is true,
34 we only try the widest integer mode (HOST_WIDE_INT) instead of all the
35 smaller types. This approach loses only if there are a very few
36 registers and then only in the few cases where we have an array of
37 HARD_REG_SETs, so it needn't be as complex as it used to be. */
39 typedef unsigned HOST_WIDE_INT HARD_REG_ELT_TYPE
;
41 #if FIRST_PSEUDO_REGISTER <= HOST_BITS_PER_WIDE_INT
43 #define HARD_REG_SET HARD_REG_ELT_TYPE
47 #define HARD_REG_SET_LONGS \
48 ((FIRST_PSEUDO_REGISTER + HOST_BITS_PER_WIDE_INT - 1) \
49 / HOST_BITS_PER_WIDE_INT)
50 typedef HARD_REG_ELT_TYPE HARD_REG_SET
[HARD_REG_SET_LONGS
];
54 /* HARD_CONST is used to cast a constant to the appropriate type
55 for use with a HARD_REG_SET. */
57 #define HARD_CONST(X) ((HARD_REG_ELT_TYPE) (X))
59 /* Define macros SET_HARD_REG_BIT, CLEAR_HARD_REG_BIT and TEST_HARD_REG_BIT
60 to set, clear or test one bit in a hard reg set of type HARD_REG_SET.
61 All three take two arguments: the set and the register number.
63 In the case where sets are arrays of longs, the first argument
64 is actually a pointer to a long.
66 Define two macros for initializing a set:
67 CLEAR_HARD_REG_SET and SET_HARD_REG_SET.
68 These take just one argument.
70 Also define macros for copying hard reg sets:
71 COPY_HARD_REG_SET and COMPL_HARD_REG_SET.
72 These take two arguments TO and FROM; they read from FROM
73 and store into TO. COMPL_HARD_REG_SET complements each bit.
75 Also define macros for combining hard reg sets:
76 IOR_HARD_REG_SET and AND_HARD_REG_SET.
77 These take two arguments TO and FROM; they read from FROM
78 and combine bitwise into TO. Define also two variants
79 IOR_COMPL_HARD_REG_SET and AND_COMPL_HARD_REG_SET
80 which use the complement of the set FROM.
82 Also define GO_IF_HARD_REG_SUBSET (X, Y, TO):
83 if X is a subset of Y, go to TO.
88 #define SET_HARD_REG_BIT(SET, BIT) \
89 ((SET) |= HARD_CONST (1) << (BIT))
90 #define CLEAR_HARD_REG_BIT(SET, BIT) \
91 ((SET) &= ~(HARD_CONST (1) << (BIT)))
92 #define TEST_HARD_REG_BIT(SET, BIT) \
93 ((SET) & (HARD_CONST (1) << (BIT)))
95 #define CLEAR_HARD_REG_SET(TO) ((TO) = HARD_CONST (0))
96 #define SET_HARD_REG_SET(TO) ((TO) = ~ HARD_CONST (0))
98 #define COPY_HARD_REG_SET(TO, FROM) ((TO) = (FROM))
99 #define COMPL_HARD_REG_SET(TO, FROM) ((TO) = ~(FROM))
101 #define IOR_HARD_REG_SET(TO, FROM) ((TO) |= (FROM))
102 #define IOR_COMPL_HARD_REG_SET(TO, FROM) ((TO) |= ~ (FROM))
103 #define AND_HARD_REG_SET(TO, FROM) ((TO) &= (FROM))
104 #define AND_COMPL_HARD_REG_SET(TO, FROM) ((TO) &= ~ (FROM))
106 #define GO_IF_HARD_REG_SUBSET(X,Y,TO) if (HARD_CONST (0) == ((X) & ~(Y))) goto TO
108 #define GO_IF_HARD_REG_EQUAL(X,Y,TO) if ((X) == (Y)) goto TO
112 #define UHOST_BITS_PER_WIDE_INT ((unsigned) HOST_BITS_PER_WIDE_INT)
114 #define SET_HARD_REG_BIT(SET, BIT) \
115 ((SET)[(BIT) / UHOST_BITS_PER_WIDE_INT] \
116 |= HARD_CONST (1) << ((BIT) % UHOST_BITS_PER_WIDE_INT))
118 #define CLEAR_HARD_REG_BIT(SET, BIT) \
119 ((SET)[(BIT) / UHOST_BITS_PER_WIDE_INT] \
120 &= ~(HARD_CONST (1) << ((BIT) % UHOST_BITS_PER_WIDE_INT)))
122 #define TEST_HARD_REG_BIT(SET, BIT) \
123 ((SET)[(BIT) / UHOST_BITS_PER_WIDE_INT] \
124 & (HARD_CONST (1) << ((BIT) % UHOST_BITS_PER_WIDE_INT)))
126 #if FIRST_PSEUDO_REGISTER <= 2*HOST_BITS_PER_WIDE_INT
127 #define CLEAR_HARD_REG_SET(TO) \
128 do { register HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
130 scan_tp_[1] = 0; } while (0)
132 #define SET_HARD_REG_SET(TO) \
133 do { register HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
135 scan_tp_[1] = -1; } while (0)
137 #define COPY_HARD_REG_SET(TO, FROM) \
138 do { register HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
139 scan_tp_[0] = scan_fp_[0]; \
140 scan_tp_[1] = scan_fp_[1]; } while (0)
142 #define COMPL_HARD_REG_SET(TO, FROM) \
143 do { register HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
144 scan_tp_[0] = ~ scan_fp_[0]; \
145 scan_tp_[1] = ~ scan_fp_[1]; } while (0)
147 #define AND_HARD_REG_SET(TO, FROM) \
148 do { register HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
149 scan_tp_[0] &= scan_fp_[0]; \
150 scan_tp_[1] &= scan_fp_[1]; } while (0)
152 #define AND_COMPL_HARD_REG_SET(TO, FROM) \
153 do { register HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
154 scan_tp_[0] &= ~ scan_fp_[0]; \
155 scan_tp_[1] &= ~ scan_fp_[1]; } while (0)
157 #define IOR_HARD_REG_SET(TO, FROM) \
158 do { register HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
159 scan_tp_[0] |= scan_fp_[0]; \
160 scan_tp_[1] |= scan_fp_[1]; } while (0)
162 #define IOR_COMPL_HARD_REG_SET(TO, FROM) \
163 do { register HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
164 scan_tp_[0] |= ~ scan_fp_[0]; \
165 scan_tp_[1] |= ~ scan_fp_[1]; } while (0)
167 #define GO_IF_HARD_REG_SUBSET(X,Y,TO) \
168 do { register HARD_REG_ELT_TYPE *scan_xp_ = (X), *scan_yp_ = (Y); \
169 if ((0 == (scan_xp_[0] & ~ scan_yp_[0])) \
170 && (0 == (scan_xp_[1] & ~ scan_yp_[1]))) \
173 #define GO_IF_HARD_REG_EQUAL(X,Y,TO) \
174 do { register HARD_REG_ELT_TYPE *scan_xp_ = (X), *scan_yp_ = (Y); \
175 if ((scan_xp_[0] == scan_yp_[0]) \
176 && (scan_xp_[1] == scan_yp_[1])) \
180 #if FIRST_PSEUDO_REGISTER <= 3*HOST_BITS_PER_WIDE_INT
181 #define CLEAR_HARD_REG_SET(TO) \
182 do { register HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
185 scan_tp_[2] = 0; } while (0)
187 #define SET_HARD_REG_SET(TO) \
188 do { register HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
191 scan_tp_[2] = -1; } while (0)
193 #define COPY_HARD_REG_SET(TO, FROM) \
194 do { register HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
195 scan_tp_[0] = scan_fp_[0]; \
196 scan_tp_[1] = scan_fp_[1]; \
197 scan_tp_[2] = scan_fp_[2]; } while (0)
199 #define COMPL_HARD_REG_SET(TO, FROM) \
200 do { register HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
201 scan_tp_[0] = ~ scan_fp_[0]; \
202 scan_tp_[1] = ~ scan_fp_[1]; \
203 scan_tp_[2] = ~ scan_fp_[2]; } while (0)
205 #define AND_HARD_REG_SET(TO, FROM) \
206 do { register HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
207 scan_tp_[0] &= scan_fp_[0]; \
208 scan_tp_[1] &= scan_fp_[1]; \
209 scan_tp_[2] &= scan_fp_[2]; } while (0)
211 #define AND_COMPL_HARD_REG_SET(TO, FROM) \
212 do { register HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
213 scan_tp_[0] &= ~ scan_fp_[0]; \
214 scan_tp_[1] &= ~ scan_fp_[1]; \
215 scan_tp_[2] &= ~ scan_fp_[2]; } while (0)
217 #define IOR_HARD_REG_SET(TO, FROM) \
218 do { register HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
219 scan_tp_[0] |= scan_fp_[0]; \
220 scan_tp_[1] |= scan_fp_[1]; \
221 scan_tp_[2] |= scan_fp_[2]; } while (0)
223 #define IOR_COMPL_HARD_REG_SET(TO, FROM) \
224 do { register HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
225 scan_tp_[0] |= ~ scan_fp_[0]; \
226 scan_tp_[1] |= ~ scan_fp_[1]; \
227 scan_tp_[2] |= ~ scan_fp_[2]; } while (0)
229 #define GO_IF_HARD_REG_SUBSET(X,Y,TO) \
230 do { register HARD_REG_ELT_TYPE *scan_xp_ = (X), *scan_yp_ = (Y); \
231 if ((0 == (scan_xp_[0] & ~ scan_yp_[0])) \
232 && (0 == (scan_xp_[1] & ~ scan_yp_[1])) \
233 && (0 == (scan_xp_[2] & ~ scan_yp_[2]))) \
236 #define GO_IF_HARD_REG_EQUAL(X,Y,TO) \
237 do { register HARD_REG_ELT_TYPE *scan_xp_ = (X), *scan_yp_ = (Y); \
238 if ((scan_xp_[0] == scan_yp_[0]) \
239 && (scan_xp_[1] == scan_yp_[1]) \
240 && (scan_xp_[2] == scan_yp_[2])) \
244 #if FIRST_PSEUDO_REGISTER <= 4*HOST_BITS_PER_WIDE_INT
245 #define CLEAR_HARD_REG_SET(TO) \
246 do { register HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
250 scan_tp_[3] = 0; } while (0)
252 #define SET_HARD_REG_SET(TO) \
253 do { register HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
257 scan_tp_[3] = -1; } while (0)
259 #define COPY_HARD_REG_SET(TO, FROM) \
260 do { register HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
261 scan_tp_[0] = scan_fp_[0]; \
262 scan_tp_[1] = scan_fp_[1]; \
263 scan_tp_[2] = scan_fp_[2]; \
264 scan_tp_[3] = scan_fp_[3]; } while (0)
266 #define COMPL_HARD_REG_SET(TO, FROM) \
267 do { register HARD_REG_ELT_TYPE *scan_tp_ = (TO), *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)
273 #define AND_HARD_REG_SET(TO, FROM) \
274 do { register HARD_REG_ELT_TYPE *scan_tp_ = (TO), *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)
280 #define AND_COMPL_HARD_REG_SET(TO, FROM) \
281 do { register HARD_REG_ELT_TYPE *scan_tp_ = (TO), *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)
287 #define IOR_HARD_REG_SET(TO, FROM) \
288 do { register HARD_REG_ELT_TYPE *scan_tp_ = (TO), *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)
294 #define IOR_COMPL_HARD_REG_SET(TO, FROM) \
295 do { register HARD_REG_ELT_TYPE *scan_tp_ = (TO), *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)
301 #define GO_IF_HARD_REG_SUBSET(X,Y,TO) \
302 do { register HARD_REG_ELT_TYPE *scan_xp_ = (X), *scan_yp_ = (Y); \
303 if ((0 == (scan_xp_[0] & ~ scan_yp_[0])) \
304 && (0 == (scan_xp_[1] & ~ scan_yp_[1])) \
305 && (0 == (scan_xp_[2] & ~ scan_yp_[2])) \
306 && (0 == (scan_xp_[3] & ~ scan_yp_[3]))) \
309 #define GO_IF_HARD_REG_EQUAL(X,Y,TO) \
310 do { register HARD_REG_ELT_TYPE *scan_xp_ = (X), *scan_yp_ = (Y); \
311 if ((scan_xp_[0] == scan_yp_[0]) \
312 && (scan_xp_[1] == scan_yp_[1]) \
313 && (scan_xp_[2] == scan_yp_[2]) \
314 && (scan_xp_[3] == scan_yp_[3])) \
317 #else /* FIRST_PSEUDO_REGISTER > 3*HOST_BITS_PER_WIDE_INT */
319 #define CLEAR_HARD_REG_SET(TO) \
320 do { register HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
322 for (i = 0; i < HARD_REG_SET_LONGS; i++) \
323 *scan_tp_++ = 0; } while (0)
325 #define SET_HARD_REG_SET(TO) \
326 do { register HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
328 for (i = 0; i < HARD_REG_SET_LONGS; i++) \
329 *scan_tp_++ = -1; } while (0)
331 #define COPY_HARD_REG_SET(TO, FROM) \
332 do { register HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
334 for (i = 0; i < HARD_REG_SET_LONGS; i++) \
335 *scan_tp_++ = *scan_fp_++; } while (0)
337 #define COMPL_HARD_REG_SET(TO, FROM) \
338 do { register HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
340 for (i = 0; i < HARD_REG_SET_LONGS; i++) \
341 *scan_tp_++ = ~ *scan_fp_++; } while (0)
343 #define AND_HARD_REG_SET(TO, FROM) \
344 do { register HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
346 for (i = 0; i < HARD_REG_SET_LONGS; i++) \
347 *scan_tp_++ &= *scan_fp_++; } while (0)
349 #define AND_COMPL_HARD_REG_SET(TO, FROM) \
350 do { register HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
352 for (i = 0; i < HARD_REG_SET_LONGS; i++) \
353 *scan_tp_++ &= ~ *scan_fp_++; } while (0)
355 #define IOR_HARD_REG_SET(TO, FROM) \
356 do { register HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
358 for (i = 0; i < HARD_REG_SET_LONGS; i++) \
359 *scan_tp_++ |= *scan_fp_++; } while (0)
361 #define IOR_COMPL_HARD_REG_SET(TO, FROM) \
362 do { register HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
364 for (i = 0; i < HARD_REG_SET_LONGS; i++) \
365 *scan_tp_++ |= ~ *scan_fp_++; } while (0)
367 #define GO_IF_HARD_REG_SUBSET(X,Y,TO) \
368 do { register HARD_REG_ELT_TYPE *scan_xp_ = (X), *scan_yp_ = (Y); \
370 for (i = 0; i < HARD_REG_SET_LONGS; i++) \
371 if (0 != (*scan_xp_++ & ~ *scan_yp_++)) break; \
372 if (i == HARD_REG_SET_LONGS) goto TO; } while (0)
374 #define GO_IF_HARD_REG_EQUAL(X,Y,TO) \
375 do { register HARD_REG_ELT_TYPE *scan_xp_ = (X), *scan_yp_ = (Y); \
377 for (i = 0; i < HARD_REG_SET_LONGS; i++) \
378 if (*scan_xp_++ != *scan_yp_++) break; \
379 if (i == HARD_REG_SET_LONGS) goto TO; } while (0)
386 /* Define some standard sets of registers. */
388 /* Indexed by hard register number, contains 1 for registers
389 that are fixed use (stack pointer, pc, frame pointer, etc.).
390 These are the registers that cannot be used to allocate
391 a pseudo reg whose life does not cross calls. */
393 extern char fixed_regs
[FIRST_PSEUDO_REGISTER
];
395 /* The same info as a HARD_REG_SET. */
397 extern HARD_REG_SET fixed_reg_set
;
399 /* Indexed by hard register number, contains 1 for registers
400 that are fixed use or are clobbered by function calls.
401 These are the registers that cannot be used to allocate
402 a pseudo reg whose life crosses calls. */
404 extern char call_used_regs
[FIRST_PSEUDO_REGISTER
];
406 /* The same info as a HARD_REG_SET. */
408 extern HARD_REG_SET call_used_reg_set
;
410 /* Registers that we don't want to caller save. */
411 extern HARD_REG_SET losing_caller_save_reg_set
;
413 /* Indexed by hard register number, contains 1 for registers that are
414 fixed use -- i.e. in fixed_regs -- or a function value return register
415 or STRUCT_VALUE_REGNUM or STATIC_CHAIN_REGNUM. These are the
416 registers that cannot hold quantities across calls even if we are
417 willing to save and restore them. */
419 extern char call_fixed_regs
[FIRST_PSEUDO_REGISTER
];
421 /* The same info as a HARD_REG_SET. */
423 extern HARD_REG_SET call_fixed_reg_set
;
425 /* Indexed by hard register number, contains 1 for registers
426 that are being used for global register decls.
427 These must be exempt from ordinary flow analysis
428 and are also considered fixed. */
430 extern char global_regs
[FIRST_PSEUDO_REGISTER
];
432 /* Table of register numbers in the order in which to try to use them. */
434 #ifdef REG_ALLOC_ORDER /* Avoid undef symbol in certain broken linkers. */
435 extern int reg_alloc_order
[FIRST_PSEUDO_REGISTER
];
438 /* For each reg class, a HARD_REG_SET saying which registers are in it. */
440 extern HARD_REG_SET reg_class_contents
[];
442 /* For each reg class, number of regs it contains. */
444 extern int reg_class_size
[N_REG_CLASSES
];
446 /* For each reg class, table listing all the containing classes. */
448 extern enum reg_class reg_class_superclasses
[N_REG_CLASSES
][N_REG_CLASSES
];
450 /* For each reg class, table listing all the classes contained in it. */
452 extern enum reg_class reg_class_subclasses
[N_REG_CLASSES
][N_REG_CLASSES
];
454 /* For each pair of reg classes,
455 a largest reg class contained in their union. */
457 extern enum reg_class reg_class_subunion
[N_REG_CLASSES
][N_REG_CLASSES
];
459 /* For each pair of reg classes,
460 the smallest reg class that contains their union. */
462 extern enum reg_class reg_class_superunion
[N_REG_CLASSES
][N_REG_CLASSES
];
464 /* Number of non-fixed registers. */
466 extern int n_non_fixed_regs
;
468 /* Vector indexed by hardware reg giving its name. */
470 extern char *reg_names
[FIRST_PSEUDO_REGISTER
];