1 /* Sets (bit vectors) of hard registers, and operations on them.
2 Copyright (C) 1987, 1992, 1994, 2000 Free Software Foundation, Inc.
4 This file is part of GCC
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
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 the Free
18 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
21 #ifndef GCC_HARD_REG_SET_H
22 #define GCC_HARD_REG_SET_H
24 /* Define the type of a set of hard registers. */
26 /* HARD_REG_ELT_TYPE is a typedef of the unsigned integral type which
27 will be used for hard reg sets, either alone or in an array.
29 If HARD_REG_SET is a macro, its definition is HARD_REG_ELT_TYPE,
30 and it has enough bits to represent all the target machine's hard
31 registers. Otherwise, it is a typedef for a suitably sized array
32 of HARD_REG_ELT_TYPEs. HARD_REG_SET_LONGS is defined as how many.
34 Note that lots of code assumes that the first part of a regset is
35 the same format as a HARD_REG_SET. To help make sure this is true,
36 we only try the widest integer mode (HOST_WIDE_INT) instead of all the
37 smaller types. This approach loses only if there are a very few
38 registers and then only in the few cases where we have an array of
39 HARD_REG_SETs, so it needn't be as complex as it used to be. */
41 typedef unsigned HOST_WIDE_INT HARD_REG_ELT_TYPE
;
43 #if FIRST_PSEUDO_REGISTER <= HOST_BITS_PER_WIDE_INT
45 #define HARD_REG_SET HARD_REG_ELT_TYPE
49 #define HARD_REG_SET_LONGS \
50 ((FIRST_PSEUDO_REGISTER + HOST_BITS_PER_WIDE_INT - 1) \
51 / HOST_BITS_PER_WIDE_INT)
52 typedef HARD_REG_ELT_TYPE HARD_REG_SET
[HARD_REG_SET_LONGS
];
56 /* HARD_CONST is used to cast a constant to the appropriate type
57 for use with a HARD_REG_SET. */
59 #define HARD_CONST(X) ((HARD_REG_ELT_TYPE) (X))
61 /* Define macros SET_HARD_REG_BIT, CLEAR_HARD_REG_BIT and TEST_HARD_REG_BIT
62 to set, clear or test one bit in a hard reg set of type HARD_REG_SET.
63 All three take two arguments: the set and the register number.
65 In the case where sets are arrays of longs, the first argument
66 is actually a pointer to a long.
68 Define two macros for initializing a set:
69 CLEAR_HARD_REG_SET and SET_HARD_REG_SET.
70 These take just one argument.
72 Also define macros for copying hard reg sets:
73 COPY_HARD_REG_SET and COMPL_HARD_REG_SET.
74 These take two arguments TO and FROM; they read from FROM
75 and store into TO. COMPL_HARD_REG_SET complements each bit.
77 Also define macros for combining hard reg sets:
78 IOR_HARD_REG_SET and AND_HARD_REG_SET.
79 These take two arguments TO and FROM; they read from FROM
80 and combine bitwise into TO. Define also two variants
81 IOR_COMPL_HARD_REG_SET and AND_COMPL_HARD_REG_SET
82 which use the complement of the set FROM.
84 Also define GO_IF_HARD_REG_SUBSET (X, Y, TO):
85 if X is a subset of Y, go to TO.
90 #define SET_HARD_REG_BIT(SET, BIT) \
91 ((SET) |= HARD_CONST (1) << (BIT))
92 #define CLEAR_HARD_REG_BIT(SET, BIT) \
93 ((SET) &= ~(HARD_CONST (1) << (BIT)))
94 #define TEST_HARD_REG_BIT(SET, BIT) \
95 (!!((SET) & (HARD_CONST (1) << (BIT))))
97 #define CLEAR_HARD_REG_SET(TO) ((TO) = HARD_CONST (0))
98 #define SET_HARD_REG_SET(TO) ((TO) = ~ HARD_CONST (0))
100 #define COPY_HARD_REG_SET(TO, FROM) ((TO) = (FROM))
101 #define COMPL_HARD_REG_SET(TO, FROM) ((TO) = ~(FROM))
103 #define IOR_HARD_REG_SET(TO, FROM) ((TO) |= (FROM))
104 #define IOR_COMPL_HARD_REG_SET(TO, FROM) ((TO) |= ~ (FROM))
105 #define AND_HARD_REG_SET(TO, FROM) ((TO) &= (FROM))
106 #define AND_COMPL_HARD_REG_SET(TO, FROM) ((TO) &= ~ (FROM))
108 #define GO_IF_HARD_REG_SUBSET(X,Y,TO) if (HARD_CONST (0) == ((X) & ~(Y))) goto TO
110 #define GO_IF_HARD_REG_EQUAL(X,Y,TO) if ((X) == (Y)) goto TO
114 #define UHOST_BITS_PER_WIDE_INT ((unsigned) HOST_BITS_PER_WIDE_INT)
116 #define SET_HARD_REG_BIT(SET, BIT) \
117 ((SET)[(BIT) / UHOST_BITS_PER_WIDE_INT] \
118 |= HARD_CONST (1) << ((BIT) % UHOST_BITS_PER_WIDE_INT))
120 #define CLEAR_HARD_REG_BIT(SET, BIT) \
121 ((SET)[(BIT) / UHOST_BITS_PER_WIDE_INT] \
122 &= ~(HARD_CONST (1) << ((BIT) % UHOST_BITS_PER_WIDE_INT)))
124 #define TEST_HARD_REG_BIT(SET, BIT) \
125 (!!((SET)[(BIT) / UHOST_BITS_PER_WIDE_INT] \
126 & (HARD_CONST (1) << ((BIT) % UHOST_BITS_PER_WIDE_INT))))
128 #if FIRST_PSEUDO_REGISTER <= 2*HOST_BITS_PER_WIDE_INT
129 #define CLEAR_HARD_REG_SET(TO) \
130 do { HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
132 scan_tp_[1] = 0; } while (0)
134 #define SET_HARD_REG_SET(TO) \
135 do { HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
137 scan_tp_[1] = -1; } while (0)
139 #define COPY_HARD_REG_SET(TO, FROM) \
140 do { HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
141 scan_tp_[0] = scan_fp_[0]; \
142 scan_tp_[1] = scan_fp_[1]; } while (0)
144 #define COMPL_HARD_REG_SET(TO, FROM) \
145 do { HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
146 scan_tp_[0] = ~ scan_fp_[0]; \
147 scan_tp_[1] = ~ scan_fp_[1]; } while (0)
149 #define AND_HARD_REG_SET(TO, FROM) \
150 do { HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
151 scan_tp_[0] &= scan_fp_[0]; \
152 scan_tp_[1] &= scan_fp_[1]; } while (0)
154 #define AND_COMPL_HARD_REG_SET(TO, FROM) \
155 do { HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
156 scan_tp_[0] &= ~ scan_fp_[0]; \
157 scan_tp_[1] &= ~ scan_fp_[1]; } while (0)
159 #define IOR_HARD_REG_SET(TO, FROM) \
160 do { HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
161 scan_tp_[0] |= scan_fp_[0]; \
162 scan_tp_[1] |= scan_fp_[1]; } while (0)
164 #define IOR_COMPL_HARD_REG_SET(TO, FROM) \
165 do { HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
166 scan_tp_[0] |= ~ scan_fp_[0]; \
167 scan_tp_[1] |= ~ scan_fp_[1]; } while (0)
169 #define GO_IF_HARD_REG_SUBSET(X,Y,TO) \
170 do { HARD_REG_ELT_TYPE *scan_xp_ = (X), *scan_yp_ = (Y); \
171 if ((0 == (scan_xp_[0] & ~ scan_yp_[0])) \
172 && (0 == (scan_xp_[1] & ~ scan_yp_[1]))) \
175 #define GO_IF_HARD_REG_EQUAL(X,Y,TO) \
176 do { HARD_REG_ELT_TYPE *scan_xp_ = (X), *scan_yp_ = (Y); \
177 if ((scan_xp_[0] == scan_yp_[0]) \
178 && (scan_xp_[1] == scan_yp_[1])) \
182 #if FIRST_PSEUDO_REGISTER <= 3*HOST_BITS_PER_WIDE_INT
183 #define CLEAR_HARD_REG_SET(TO) \
184 do { HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
187 scan_tp_[2] = 0; } while (0)
189 #define SET_HARD_REG_SET(TO) \
190 do { HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
193 scan_tp_[2] = -1; } while (0)
195 #define COPY_HARD_REG_SET(TO, FROM) \
196 do { HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
197 scan_tp_[0] = scan_fp_[0]; \
198 scan_tp_[1] = scan_fp_[1]; \
199 scan_tp_[2] = scan_fp_[2]; } while (0)
201 #define COMPL_HARD_REG_SET(TO, FROM) \
202 do { HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
203 scan_tp_[0] = ~ scan_fp_[0]; \
204 scan_tp_[1] = ~ scan_fp_[1]; \
205 scan_tp_[2] = ~ scan_fp_[2]; } while (0)
207 #define AND_HARD_REG_SET(TO, FROM) \
208 do { HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
209 scan_tp_[0] &= scan_fp_[0]; \
210 scan_tp_[1] &= scan_fp_[1]; \
211 scan_tp_[2] &= scan_fp_[2]; } while (0)
213 #define AND_COMPL_HARD_REG_SET(TO, FROM) \
214 do { HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
215 scan_tp_[0] &= ~ scan_fp_[0]; \
216 scan_tp_[1] &= ~ scan_fp_[1]; \
217 scan_tp_[2] &= ~ scan_fp_[2]; } while (0)
219 #define IOR_HARD_REG_SET(TO, FROM) \
220 do { HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
221 scan_tp_[0] |= scan_fp_[0]; \
222 scan_tp_[1] |= scan_fp_[1]; \
223 scan_tp_[2] |= scan_fp_[2]; } while (0)
225 #define IOR_COMPL_HARD_REG_SET(TO, FROM) \
226 do { HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
227 scan_tp_[0] |= ~ scan_fp_[0]; \
228 scan_tp_[1] |= ~ scan_fp_[1]; \
229 scan_tp_[2] |= ~ scan_fp_[2]; } while (0)
231 #define GO_IF_HARD_REG_SUBSET(X,Y,TO) \
232 do { HARD_REG_ELT_TYPE *scan_xp_ = (X), *scan_yp_ = (Y); \
233 if ((0 == (scan_xp_[0] & ~ scan_yp_[0])) \
234 && (0 == (scan_xp_[1] & ~ scan_yp_[1])) \
235 && (0 == (scan_xp_[2] & ~ scan_yp_[2]))) \
238 #define GO_IF_HARD_REG_EQUAL(X,Y,TO) \
239 do { HARD_REG_ELT_TYPE *scan_xp_ = (X), *scan_yp_ = (Y); \
240 if ((scan_xp_[0] == scan_yp_[0]) \
241 && (scan_xp_[1] == scan_yp_[1]) \
242 && (scan_xp_[2] == scan_yp_[2])) \
246 #if FIRST_PSEUDO_REGISTER <= 4*HOST_BITS_PER_WIDE_INT
247 #define CLEAR_HARD_REG_SET(TO) \
248 do { HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
252 scan_tp_[3] = 0; } while (0)
254 #define SET_HARD_REG_SET(TO) \
255 do { HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
259 scan_tp_[3] = -1; } while (0)
261 #define COPY_HARD_REG_SET(TO, FROM) \
262 do { HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
263 scan_tp_[0] = scan_fp_[0]; \
264 scan_tp_[1] = scan_fp_[1]; \
265 scan_tp_[2] = scan_fp_[2]; \
266 scan_tp_[3] = scan_fp_[3]; } while (0)
268 #define COMPL_HARD_REG_SET(TO, FROM) \
269 do { HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
270 scan_tp_[0] = ~ scan_fp_[0]; \
271 scan_tp_[1] = ~ scan_fp_[1]; \
272 scan_tp_[2] = ~ scan_fp_[2]; \
273 scan_tp_[3] = ~ scan_fp_[3]; } while (0)
275 #define AND_HARD_REG_SET(TO, FROM) \
276 do { HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
277 scan_tp_[0] &= scan_fp_[0]; \
278 scan_tp_[1] &= scan_fp_[1]; \
279 scan_tp_[2] &= scan_fp_[2]; \
280 scan_tp_[3] &= scan_fp_[3]; } while (0)
282 #define AND_COMPL_HARD_REG_SET(TO, FROM) \
283 do { HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
284 scan_tp_[0] &= ~ scan_fp_[0]; \
285 scan_tp_[1] &= ~ scan_fp_[1]; \
286 scan_tp_[2] &= ~ scan_fp_[2]; \
287 scan_tp_[3] &= ~ scan_fp_[3]; } while (0)
289 #define IOR_HARD_REG_SET(TO, FROM) \
290 do { HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
291 scan_tp_[0] |= scan_fp_[0]; \
292 scan_tp_[1] |= scan_fp_[1]; \
293 scan_tp_[2] |= scan_fp_[2]; \
294 scan_tp_[3] |= scan_fp_[3]; } while (0)
296 #define IOR_COMPL_HARD_REG_SET(TO, FROM) \
297 do { HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
298 scan_tp_[0] |= ~ scan_fp_[0]; \
299 scan_tp_[1] |= ~ scan_fp_[1]; \
300 scan_tp_[2] |= ~ scan_fp_[2]; \
301 scan_tp_[3] |= ~ scan_fp_[3]; } while (0)
303 #define GO_IF_HARD_REG_SUBSET(X,Y,TO) \
304 do { HARD_REG_ELT_TYPE *scan_xp_ = (X), *scan_yp_ = (Y); \
305 if ((0 == (scan_xp_[0] & ~ scan_yp_[0])) \
306 && (0 == (scan_xp_[1] & ~ scan_yp_[1])) \
307 && (0 == (scan_xp_[2] & ~ scan_yp_[2])) \
308 && (0 == (scan_xp_[3] & ~ scan_yp_[3]))) \
311 #define GO_IF_HARD_REG_EQUAL(X,Y,TO) \
312 do { HARD_REG_ELT_TYPE *scan_xp_ = (X), *scan_yp_ = (Y); \
313 if ((scan_xp_[0] == scan_yp_[0]) \
314 && (scan_xp_[1] == scan_yp_[1]) \
315 && (scan_xp_[2] == scan_yp_[2]) \
316 && (scan_xp_[3] == scan_yp_[3])) \
319 #else /* FIRST_PSEUDO_REGISTER > 3*HOST_BITS_PER_WIDE_INT */
321 #define CLEAR_HARD_REG_SET(TO) \
322 do { HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
324 for (i = 0; i < HARD_REG_SET_LONGS; i++) \
325 *scan_tp_++ = 0; } while (0)
327 #define SET_HARD_REG_SET(TO) \
328 do { HARD_REG_ELT_TYPE *scan_tp_ = (TO); \
330 for (i = 0; i < HARD_REG_SET_LONGS; i++) \
331 *scan_tp_++ = -1; } while (0)
333 #define COPY_HARD_REG_SET(TO, FROM) \
334 do { HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
336 for (i = 0; i < HARD_REG_SET_LONGS; i++) \
337 *scan_tp_++ = *scan_fp_++; } while (0)
339 #define COMPL_HARD_REG_SET(TO, FROM) \
340 do { HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
342 for (i = 0; i < HARD_REG_SET_LONGS; i++) \
343 *scan_tp_++ = ~ *scan_fp_++; } while (0)
345 #define AND_HARD_REG_SET(TO, FROM) \
346 do { HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
348 for (i = 0; i < HARD_REG_SET_LONGS; i++) \
349 *scan_tp_++ &= *scan_fp_++; } while (0)
351 #define AND_COMPL_HARD_REG_SET(TO, FROM) \
352 do { HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
354 for (i = 0; i < HARD_REG_SET_LONGS; i++) \
355 *scan_tp_++ &= ~ *scan_fp_++; } while (0)
357 #define IOR_HARD_REG_SET(TO, FROM) \
358 do { HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
360 for (i = 0; i < HARD_REG_SET_LONGS; i++) \
361 *scan_tp_++ |= *scan_fp_++; } while (0)
363 #define IOR_COMPL_HARD_REG_SET(TO, FROM) \
364 do { HARD_REG_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
366 for (i = 0; i < HARD_REG_SET_LONGS; i++) \
367 *scan_tp_++ |= ~ *scan_fp_++; } while (0)
369 #define GO_IF_HARD_REG_SUBSET(X,Y,TO) \
370 do { HARD_REG_ELT_TYPE *scan_xp_ = (X), *scan_yp_ = (Y); \
372 for (i = 0; i < HARD_REG_SET_LONGS; i++) \
373 if (0 != (*scan_xp_++ & ~ *scan_yp_++)) break; \
374 if (i == HARD_REG_SET_LONGS) goto TO; } while (0)
376 #define GO_IF_HARD_REG_EQUAL(X,Y,TO) \
377 do { HARD_REG_ELT_TYPE *scan_xp_ = (X), *scan_yp_ = (Y); \
379 for (i = 0; i < HARD_REG_SET_LONGS; i++) \
380 if (*scan_xp_++ != *scan_yp_++) break; \
381 if (i == HARD_REG_SET_LONGS) goto TO; } while (0)
388 /* Define some standard sets of registers. */
390 /* Indexed by hard register number, contains 1 for registers
391 that are fixed use (stack pointer, pc, frame pointer, etc.).
392 These are the registers that cannot be used to allocate
393 a pseudo reg whose life does not cross calls. */
395 extern char fixed_regs
[FIRST_PSEUDO_REGISTER
];
397 /* The same info as a HARD_REG_SET. */
399 extern HARD_REG_SET fixed_reg_set
;
401 /* Indexed by hard register number, contains 1 for registers
402 that are fixed use or are clobbered by function calls.
403 These are the registers that cannot be used to allocate
404 a pseudo reg whose life crosses calls. */
406 extern char call_used_regs
[FIRST_PSEUDO_REGISTER
];
408 #ifdef CALL_REALLY_USED_REGISTERS
409 extern char call_really_used_regs
[];
412 /* The same info as a HARD_REG_SET. */
414 extern HARD_REG_SET call_used_reg_set
;
416 /* Registers that we don't want to caller save. */
417 extern HARD_REG_SET losing_caller_save_reg_set
;
419 /* Indexed by hard register number, contains 1 for registers that are
420 fixed use -- i.e. in fixed_regs -- or a function value return register
421 or STRUCT_VALUE_REGNUM or STATIC_CHAIN_REGNUM. These are the
422 registers that cannot hold quantities across calls even if we are
423 willing to save and restore them. */
425 extern char call_fixed_regs
[FIRST_PSEUDO_REGISTER
];
427 /* The same info as a HARD_REG_SET. */
429 extern HARD_REG_SET call_fixed_reg_set
;
431 /* Indexed by hard register number, contains 1 for registers
432 that are being used for global register decls.
433 These must be exempt from ordinary flow analysis
434 and are also considered fixed. */
436 extern char global_regs
[FIRST_PSEUDO_REGISTER
];
438 /* Contains 1 for registers that are set or clobbered by calls. */
439 /* ??? Ideally, this would be just call_used_regs plus global_regs, but
440 for someone's bright idea to have call_used_regs strictly include
441 fixed_regs. Which leaves us guessing as to the set of fixed_regs
442 that are actually preserved. We know for sure that those associated
443 with the local stack frame are safe, but scant others. */
445 extern HARD_REG_SET regs_invalidated_by_call
;
447 #ifdef REG_ALLOC_ORDER
448 /* Table of register numbers in the order in which to try to use them. */
450 extern int reg_alloc_order
[FIRST_PSEUDO_REGISTER
];
452 /* The inverse of reg_alloc_order. */
454 extern int inv_reg_alloc_order
[FIRST_PSEUDO_REGISTER
];
457 /* For each reg class, a HARD_REG_SET saying which registers are in it. */
459 extern HARD_REG_SET reg_class_contents
[N_REG_CLASSES
];
461 /* For each reg class, number of regs it contains. */
463 extern unsigned int reg_class_size
[N_REG_CLASSES
];
465 /* For each reg class, table listing all the containing classes. */
467 extern enum reg_class reg_class_superclasses
[N_REG_CLASSES
][N_REG_CLASSES
];
469 /* For each reg class, table listing all the classes contained in it. */
471 extern enum reg_class reg_class_subclasses
[N_REG_CLASSES
][N_REG_CLASSES
];
473 /* For each pair of reg classes,
474 a largest reg class contained in their union. */
476 extern enum reg_class reg_class_subunion
[N_REG_CLASSES
][N_REG_CLASSES
];
478 /* For each pair of reg classes,
479 the smallest reg class that contains their union. */
481 extern enum reg_class reg_class_superunion
[N_REG_CLASSES
][N_REG_CLASSES
];
483 /* Number of non-fixed registers. */
485 extern int n_non_fixed_regs
;
487 /* Vector indexed by hardware reg giving its name. */
489 extern const char * reg_names
[FIRST_PSEUDO_REGISTER
];
491 /* Given a hard REGN a FROM mode and a TO mode, return nonzero if
492 REGN cannot change modes between the specified modes. */
493 #define REG_CANNOT_CHANGE_MODE_P(REGN, FROM, TO) \
495 (reg_class_contents[(int) CANNOT_CHANGE_MODE_CLASS (FROM, TO)], \
498 #endif /* ! GCC_HARD_REG_SET_H */