1 /* Define control and data flow tables, and regsets.
2 Copyright (C) 1987, 1997 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 /* Number of bits in each actual element of a regset. We get slightly
23 better code for reg%bits and reg/bits if bits is unsigned, assuming
24 it is a power of 2. */
26 #define REGSET_ELT_BITS ((unsigned) HOST_BITS_PER_WIDE_INT)
28 /* Type to use for a regset element. Note that lots of code assumes
29 that the initial part of a regset that contains information on the
30 hard registers is the same format as a HARD_REG_SET. */
32 #define REGSET_ELT_TYPE unsigned HOST_WIDE_INT
34 /* Define the type for a pointer to a set with a bit for each
35 (hard or pseudo) register. */
37 typedef REGSET_ELT_TYPE *regset;
39 /* Size of a regset for the current function,
40 in (1) bytes and (2) elements. */
42 extern int regset_bytes;
43 extern int regset_size;
45 /* clear a register set */
46 #define CLEAR_REG_SET(TO) \
47 do { register REGSET_ELT_TYPE *scan_tp_ = (TO); \
49 for (i_ = 0; i_ < regset_size; i_++) \
50 *scan_tp_++ = 0; } while (0)
52 /* copy a register to another register */
53 #define COPY_REG_SET(TO, FROM) \
54 do { register REGSET_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
56 for (i_ = 0; i_ < regset_size; i_++) \
57 *scan_tp_++ = *scan_fp_++; } while (0)
59 /* complent a register set, storing it in a second register set. */
60 #define COMPL_REG_SET(TO, FROM) \
61 do { register REGSET_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
63 for (i_ = 0; i_ < regset_size; i_++) \
64 *scan_tp_++ = ~ *scan_fp_++; } while (0)
66 /* and a register set with a second register set. */
67 #define AND_REG_SET(TO, FROM) \
68 do { register REGSET_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
70 for (i_ = 0; i_ < regset_size; i_++) \
71 *scan_tp_++ &= *scan_fp_++; } while (0)
73 /* and the complement of a register set to a register set. */
74 #define AND_COMPL_REG_SET(TO, FROM) \
75 do { register REGSET_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
77 for (i_ = 0; i_ < regset_size; i_++) \
78 *scan_tp_++ &= ~ *scan_fp_++; } while (0)
80 /* inclusive or a register set with a second register set. */
81 #define IOR_REG_SET(TO, FROM) \
82 do { register REGSET_ELT_TYPE *scan_tp_ = (TO), *scan_fp_ = (FROM); \
84 for (i_ = 0; i_ < regset_size; i_++) \
85 *scan_tp_++ |= *scan_fp_++; } while (0)
87 /* complement two register sets and or in the result into a third. */
88 #define IOR_AND_COMPL_REG_SET(TO, FROM1, FROM2) \
89 do { register REGSET_ELT_TYPE *scan_tp_ = (TO); \
90 register REGSET_ELT_TYPE *scan_fp1_ = (FROM1); \
91 register REGSET_ELT_TYPE *scan_fp2_ = (FROM2); \
93 for (i_ = 0; i_ < regset_size; i_++) \
94 *scan_tp_++ |= *scan_fp1_++ & ~ *scan_fp2_++; } while (0)
96 /* Clear a single register in a register set. */
97 #define CLEAR_REGNO_REG_SET(TO, REG) \
99 register REGSET_ELT_TYPE *tp_ = (TO); \
100 tp_[ (REG) / REGSET_ELT_BITS ] \
101 &= ~ ((REGSET_ELT_TYPE) 1 << ((REG) % REGSET_ELT_BITS)); } while (0);
103 /* Set a single register in a register set. */
104 #define SET_REGNO_REG_SET(TO, REG) \
106 register REGSET_ELT_TYPE *tp_ = (TO); \
107 tp_[ (REG) / REGSET_ELT_BITS ] \
108 |= ((REGSET_ELT_TYPE) 1 << ((REG) % REGSET_ELT_BITS)); } while (0);
110 /* Return true if a register is set in a register set. */
111 #define REGNO_REG_SET_P(TO, REG) \
112 (((TO)[ (REG) / REGSET_ELT_BITS ] \
113 & (((REGSET_ELT_TYPE)1) << (REG) % REGSET_ELT_BITS)) != 0)
115 /* Copy the hard registers in a register set to the hard register set. */
116 #define REG_SET_TO_HARD_REG_SET(TO, FROM) \
119 CLEAR_HARD_REG_SET (TO); \
120 for (i_ = 0; i_ < FIRST_PSEUDO_REGISTER; i_++) \
121 if (REGNO_REG_SET_P (FROM, i_)) \
122 SET_HARD_REG_BIT (TO, i_); \
125 /* Loop over all registers in REGSET, starting with MIN, setting REGNUM to the
126 register number and executing CODE for all registers that are set. */
127 #define EXECUTE_IF_SET_IN_REG_SET(REGSET, MIN, REGNUM, CODE) \
129 register int i_ = (MIN) / REGSET_ELT_BITS; \
130 register int shift_ = (MIN) % REGSET_ELT_BITS; \
131 register REGSET_ELT_TYPE *scan_rs_ = (REGSET) + i_; \
132 for ( ; i_ < regset_size; i_++) \
134 REGSET_ELT_TYPE word_ = *scan_rs_++; \
137 REGSET_ELT_TYPE j_; \
138 REGNUM = (i_ * REGSET_ELT_BITS) + shift_; \
139 for (j_ = ((REGSET_ELT_TYPE)1) << shift_; \
141 (j_ <<= 1), REGNUM++) \
156 /* Like EXECUTE_IF_SET_IN_REG_SET, but also clear the register set. */
157 #define EXECUTE_IF_SET_AND_RESET_IN_REG_SET(REGSET, MIN, REGNUM, CODE) \
159 register int i_ = (MIN) / REGSET_ELT_BITS; \
160 register int shift_ = (MIN) % REGSET_ELT_BITS; \
161 register REGSET_ELT_TYPE *scan_rs_ = (REGSET) + i_; \
162 for ( ; i_ < regset_size; i_++) \
164 REGSET_ELT_TYPE word_ = *scan_rs_++; \
167 REGSET_ELT_TYPE j_; \
168 REGNUM = (i_ * REGSET_ELT_BITS) + shift_; \
170 for (j_ = ((REGSET_ELT_TYPE)1) << shift_; \
172 (j_ <<= 1), REGNUM++) \
187 /* Loop over all registers in REGSET1 and REGSET2, starting with MIN, setting
188 REGNUM to the register number and executing CODE for all registers that are
189 set in both regsets. */
190 #define EXECUTE_IF_AND_IN_REG_SET(REGSET1, REGSET2, MIN, REGNUM, CODE) \
192 register int i_ = (MIN) / REGSET_ELT_BITS; \
193 register int shift_ = (MIN) % REGSET_ELT_BITS; \
194 register REGSET_ELT_TYPE *scan_rs1_ = (REGSET1) + i_; \
195 register REGSET_ELT_TYPE *scan_rs2_ = (REGSET2) + i_; \
196 for ( ; i_ < regset_size; i_++) \
198 REGSET_ELT_TYPE word_ = *scan_rs1_++ & *scan_rs2_++; \
201 REGSET_ELT_TYPE j_; \
202 REGNUM = (i_ * REGSET_ELT_BITS) + shift_; \
203 for (j_ = ((REGSET_ELT_TYPE)1) << shift_; \
205 (j_ <<= 1), REGNUM++) \
220 /* Loop over all registers in REGSET1 and REGSET2, starting with MIN, setting
221 REGNUM to the register number and executing CODE for all registers that are
222 set in the first regset and not set in the second. */
223 #define EXECUTE_IF_AND_COMPL_IN_REG_SET(REGSET1, REGSET2, MIN, REGNUM, CODE) \
225 register int i_ = (MIN) / REGSET_ELT_BITS; \
226 register int shift_ = (MIN) % REGSET_ELT_BITS; \
227 register REGSET_ELT_TYPE *scan_rs1_ = (REGSET1) + i_; \
228 register REGSET_ELT_TYPE *scan_rs2_ = (REGSET2) + i_; \
229 for ( ; i_ < regset_size; i_++) \
231 REGSET_ELT_TYPE word_ = *scan_rs1_++ & ~ *scan_rs2_++; \
234 REGSET_ELT_TYPE j_; \
235 REGNUM = (i_ * REGSET_ELT_BITS) + shift_; \
236 for (j_ = ((REGSET_ELT_TYPE)1) << shift_; \
238 (j_ <<= 1), REGNUM++) \
253 /* Allocate a register set with oballoc. */
254 #define OBSTACK_ALLOC_REG_SET(OBSTACK) \
255 ((regset) obstack_alloc (OBSTACK, regset_bytes))
257 /* Allocate a register set with alloca. */
258 #define ALLOCA_REG_SET() ((regset) alloca (regset_bytes))
260 /* Number of basic blocks in the current function. */
262 extern int n_basic_blocks;
264 /* Index by basic block number, get first insn in the block. */
266 extern rtx *basic_block_head;
268 /* Index by basic block number, get last insn in the block. */
270 extern rtx *basic_block_end;
272 /* Index by basic block number, get address of regset
273 describing the registers live at the start of that block. */
275 extern regset *basic_block_live_at_start;
277 /* Indexed by n, gives number of basic block that (REG n) is used in.
278 If the value is REG_BLOCK_GLOBAL (-2),
279 it means (REG n) is used in more than one basic block.
280 REG_BLOCK_UNKNOWN (-1) means it hasn't been seen yet so we don't know.
281 This information remains valid for the rest of the compilation
282 of the current function; it is used to control register allocation. */
284 #define REG_BLOCK_UNKNOWN -1
285 #define REG_BLOCK_GLOBAL -2
287 #define REG_BASIC_BLOCK(N) (reg_n_info[(N)].basic_block)