xref: /dflybsd-src/contrib/gcc-4.7/gcc/regs.h (revision 04febcfb30580676d3e95f58a16c5137ee478b32)
1*e4b17023SJohn Marino /* Define per-register tables for data flow info and register allocation.
2*e4b17023SJohn Marino    Copyright (C) 1987, 1993, 1994, 1995, 1996, 1997, 1998,
3*e4b17023SJohn Marino    1999, 2000, 2003, 2004, 2005, 2006, 2007, 2008, 2010 Free Software
4*e4b17023SJohn Marino    Foundation, Inc.
5*e4b17023SJohn Marino 
6*e4b17023SJohn Marino This file is part of GCC.
7*e4b17023SJohn Marino 
8*e4b17023SJohn Marino GCC is free software; you can redistribute it and/or modify it under
9*e4b17023SJohn Marino the terms of the GNU General Public License as published by the Free
10*e4b17023SJohn Marino Software Foundation; either version 3, or (at your option) any later
11*e4b17023SJohn Marino version.
12*e4b17023SJohn Marino 
13*e4b17023SJohn Marino GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14*e4b17023SJohn Marino WARRANTY; without even the implied warranty of MERCHANTABILITY or
15*e4b17023SJohn Marino FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16*e4b17023SJohn Marino for more details.
17*e4b17023SJohn Marino 
18*e4b17023SJohn Marino You should have received a copy of the GNU General Public License
19*e4b17023SJohn Marino along with GCC; see the file COPYING3.  If not see
20*e4b17023SJohn Marino <http://www.gnu.org/licenses/>.  */
21*e4b17023SJohn Marino 
22*e4b17023SJohn Marino #ifndef GCC_REGS_H
23*e4b17023SJohn Marino #define GCC_REGS_H
24*e4b17023SJohn Marino 
25*e4b17023SJohn Marino #include "machmode.h"
26*e4b17023SJohn Marino #include "hard-reg-set.h"
27*e4b17023SJohn Marino 
28*e4b17023SJohn Marino #define REG_BYTES(R) mode_size[(int) GET_MODE (R)]
29*e4b17023SJohn Marino 
30*e4b17023SJohn Marino /* When you only have the mode of a pseudo register before it has a hard
31*e4b17023SJohn Marino    register chosen for it, this reports the size of each hard register
32*e4b17023SJohn Marino    a pseudo in such a mode would get allocated to.  A target may
33*e4b17023SJohn Marino    override this.  */
34*e4b17023SJohn Marino 
35*e4b17023SJohn Marino #ifndef REGMODE_NATURAL_SIZE
36*e4b17023SJohn Marino #define REGMODE_NATURAL_SIZE(MODE)	UNITS_PER_WORD
37*e4b17023SJohn Marino #endif
38*e4b17023SJohn Marino 
39*e4b17023SJohn Marino /* Maximum register number used in this function, plus one.  */
40*e4b17023SJohn Marino 
41*e4b17023SJohn Marino extern int max_regno;
42*e4b17023SJohn Marino 
43*e4b17023SJohn Marino /* REG_N_REFS and REG_N_SETS are initialized by a call to
44*e4b17023SJohn Marino    regstat_init_n_sets_and_refs from the current values of
45*e4b17023SJohn Marino    DF_REG_DEF_COUNT and DF_REG_USE_COUNT.  REG_N_REFS and REG_N_SETS
46*e4b17023SJohn Marino    should only be used if a pass need to change these values in some
47*e4b17023SJohn Marino    magical way or the pass needs to have accurate values for these
48*e4b17023SJohn Marino    and is not using incremental df scanning.
49*e4b17023SJohn Marino 
50*e4b17023SJohn Marino    At the end of a pass that uses REG_N_REFS and REG_N_SETS, a call
51*e4b17023SJohn Marino    should be made to regstat_free_n_sets_and_refs.
52*e4b17023SJohn Marino 
53*e4b17023SJohn Marino    Local alloc seems to play pretty loose with these values.
54*e4b17023SJohn Marino    REG_N_REFS is set to 0 if the register is used in an asm.
55*e4b17023SJohn Marino    Furthermore, local_alloc calls regclass to hack both REG_N_REFS and
56*e4b17023SJohn Marino    REG_N_SETS for three address insns.  Other passes seem to have
57*e4b17023SJohn Marino    other special values.  */
58*e4b17023SJohn Marino 
59*e4b17023SJohn Marino 
60*e4b17023SJohn Marino 
61*e4b17023SJohn Marino /* Structure to hold values for REG_N_SETS (i) and REG_N_REFS (i). */
62*e4b17023SJohn Marino 
63*e4b17023SJohn Marino struct regstat_n_sets_and_refs_t
64*e4b17023SJohn Marino {
65*e4b17023SJohn Marino   int sets;			/* # of times (REG n) is set */
66*e4b17023SJohn Marino   int refs;			/* # of times (REG n) is used or set */
67*e4b17023SJohn Marino };
68*e4b17023SJohn Marino 
69*e4b17023SJohn Marino extern struct regstat_n_sets_and_refs_t *regstat_n_sets_and_refs;
70*e4b17023SJohn Marino 
71*e4b17023SJohn Marino /* Indexed by n, gives number of times (REG n) is used or set.  */
72*e4b17023SJohn Marino static inline int
REG_N_REFS(int regno)73*e4b17023SJohn Marino REG_N_REFS(int regno)
74*e4b17023SJohn Marino {
75*e4b17023SJohn Marino   return regstat_n_sets_and_refs[regno].refs;
76*e4b17023SJohn Marino }
77*e4b17023SJohn Marino 
78*e4b17023SJohn Marino /* Indexed by n, gives number of times (REG n) is used or set.  */
79*e4b17023SJohn Marino #define SET_REG_N_REFS(N,V) (regstat_n_sets_and_refs[N].refs = V)
80*e4b17023SJohn Marino #define INC_REG_N_REFS(N,V) (regstat_n_sets_and_refs[N].refs += V)
81*e4b17023SJohn Marino 
82*e4b17023SJohn Marino /* Indexed by n, gives number of times (REG n) is set.  */
83*e4b17023SJohn Marino static inline int
REG_N_SETS(int regno)84*e4b17023SJohn Marino REG_N_SETS (int regno)
85*e4b17023SJohn Marino {
86*e4b17023SJohn Marino   return regstat_n_sets_and_refs[regno].sets;
87*e4b17023SJohn Marino }
88*e4b17023SJohn Marino 
89*e4b17023SJohn Marino /* Indexed by n, gives number of times (REG n) is set.  */
90*e4b17023SJohn Marino #define SET_REG_N_SETS(N,V) (regstat_n_sets_and_refs[N].sets = V)
91*e4b17023SJohn Marino #define INC_REG_N_SETS(N,V) (regstat_n_sets_and_refs[N].sets += V)
92*e4b17023SJohn Marino 
93*e4b17023SJohn Marino 
94*e4b17023SJohn Marino /* Functions defined in reg-stat.c.  */
95*e4b17023SJohn Marino extern void regstat_init_n_sets_and_refs (void);
96*e4b17023SJohn Marino extern void regstat_free_n_sets_and_refs (void);
97*e4b17023SJohn Marino extern void regstat_compute_ri (void);
98*e4b17023SJohn Marino extern void regstat_free_ri (void);
99*e4b17023SJohn Marino extern bitmap regstat_get_setjmp_crosses (void);
100*e4b17023SJohn Marino extern void regstat_compute_calls_crossed (void);
101*e4b17023SJohn Marino extern void regstat_free_calls_crossed (void);
102*e4b17023SJohn Marino 
103*e4b17023SJohn Marino 
104*e4b17023SJohn Marino /* Register information indexed by register number.  This structure is
105*e4b17023SJohn Marino    initialized by calling regstat_compute_ri and is destroyed by
106*e4b17023SJohn Marino    calling regstat_free_ri.  */
107*e4b17023SJohn Marino struct reg_info_t
108*e4b17023SJohn Marino {
109*e4b17023SJohn Marino   int freq;			/* # estimated frequency (REG n) is used or set */
110*e4b17023SJohn Marino   int deaths;			/* # of times (REG n) dies */
111*e4b17023SJohn Marino   int live_length;		/* # of instructions (REG n) is live */
112*e4b17023SJohn Marino   int calls_crossed;		/* # of calls (REG n) is live across */
113*e4b17023SJohn Marino   int freq_calls_crossed;	/* # estimated frequency (REG n) crosses call */
114*e4b17023SJohn Marino   int throw_calls_crossed;	/* # of calls that may throw (REG n) is live across */
115*e4b17023SJohn Marino   int basic_block;		/* # of basic blocks (REG n) is used in */
116*e4b17023SJohn Marino };
117*e4b17023SJohn Marino 
118*e4b17023SJohn Marino extern struct reg_info_t *reg_info_p;
119*e4b17023SJohn Marino 
120*e4b17023SJohn Marino /* The number allocated elements of reg_info_p.  */
121*e4b17023SJohn Marino extern size_t reg_info_p_size;
122*e4b17023SJohn Marino 
123*e4b17023SJohn Marino /* Estimate frequency of references to register N.  */
124*e4b17023SJohn Marino 
125*e4b17023SJohn Marino #define REG_FREQ(N) (reg_info_p[N].freq)
126*e4b17023SJohn Marino 
127*e4b17023SJohn Marino /* The weights for each insn varies from 0 to REG_FREQ_BASE.
128*e4b17023SJohn Marino    This constant does not need to be high, as in infrequently executed
129*e4b17023SJohn Marino    regions we want to count instructions equivalently to optimize for
130*e4b17023SJohn Marino    size instead of speed.  */
131*e4b17023SJohn Marino #define REG_FREQ_MAX 1000
132*e4b17023SJohn Marino 
133*e4b17023SJohn Marino /* Compute register frequency from the BB frequency.  When optimizing for size,
134*e4b17023SJohn Marino    or profile driven feedback is available and the function is never executed,
135*e4b17023SJohn Marino    frequency is always equivalent.  Otherwise rescale the basic block
136*e4b17023SJohn Marino    frequency.  */
137*e4b17023SJohn Marino #define REG_FREQ_FROM_BB(bb) (optimize_size				      \
138*e4b17023SJohn Marino 			      || (flag_branch_probabilities		      \
139*e4b17023SJohn Marino 				  && !ENTRY_BLOCK_PTR->count)		      \
140*e4b17023SJohn Marino 			      ? REG_FREQ_MAX				      \
141*e4b17023SJohn Marino 			      : ((bb)->frequency * REG_FREQ_MAX / BB_FREQ_MAX)\
142*e4b17023SJohn Marino 			      ? ((bb)->frequency * REG_FREQ_MAX / BB_FREQ_MAX)\
143*e4b17023SJohn Marino 			      : 1)
144*e4b17023SJohn Marino 
145*e4b17023SJohn Marino /* Indexed by N, gives number of insns in which register N dies.
146*e4b17023SJohn Marino    Note that if register N is live around loops, it can die
147*e4b17023SJohn Marino    in transitions between basic blocks, and that is not counted here.
148*e4b17023SJohn Marino    So this is only a reliable indicator of how many regions of life there are
149*e4b17023SJohn Marino    for registers that are contained in one basic block.  */
150*e4b17023SJohn Marino 
151*e4b17023SJohn Marino #define REG_N_DEATHS(N) (reg_info_p[N].deaths)
152*e4b17023SJohn Marino 
153*e4b17023SJohn Marino /* Get the number of consecutive words required to hold pseudo-reg N.  */
154*e4b17023SJohn Marino 
155*e4b17023SJohn Marino #define PSEUDO_REGNO_SIZE(N) \
156*e4b17023SJohn Marino   ((GET_MODE_SIZE (PSEUDO_REGNO_MODE (N)) + UNITS_PER_WORD - 1)		\
157*e4b17023SJohn Marino    / UNITS_PER_WORD)
158*e4b17023SJohn Marino 
159*e4b17023SJohn Marino /* Get the number of bytes required to hold pseudo-reg N.  */
160*e4b17023SJohn Marino 
161*e4b17023SJohn Marino #define PSEUDO_REGNO_BYTES(N) \
162*e4b17023SJohn Marino   GET_MODE_SIZE (PSEUDO_REGNO_MODE (N))
163*e4b17023SJohn Marino 
164*e4b17023SJohn Marino /* Get the machine mode of pseudo-reg N.  */
165*e4b17023SJohn Marino 
166*e4b17023SJohn Marino #define PSEUDO_REGNO_MODE(N) GET_MODE (regno_reg_rtx[N])
167*e4b17023SJohn Marino 
168*e4b17023SJohn Marino /* Indexed by N, gives number of CALL_INSNS across which (REG n) is live.  */
169*e4b17023SJohn Marino 
170*e4b17023SJohn Marino #define REG_N_CALLS_CROSSED(N)  (reg_info_p[N].calls_crossed)
171*e4b17023SJohn Marino #define REG_FREQ_CALLS_CROSSED(N)  (reg_info_p[N].freq_calls_crossed)
172*e4b17023SJohn Marino 
173*e4b17023SJohn Marino /* Indexed by N, gives number of CALL_INSNS that may throw, across which
174*e4b17023SJohn Marino    (REG n) is live.  */
175*e4b17023SJohn Marino 
176*e4b17023SJohn Marino #define REG_N_THROWING_CALLS_CROSSED(N) (reg_info_p[N].throw_calls_crossed)
177*e4b17023SJohn Marino 
178*e4b17023SJohn Marino /* Total number of instructions at which (REG n) is live.  The larger
179*e4b17023SJohn Marino    this is, the less priority (REG n) gets for allocation in a hard
180*e4b17023SJohn Marino    register (in global-alloc).  This is set in df-problems.c whenever
181*e4b17023SJohn Marino    register info is requested and remains valid for the rest of the
182*e4b17023SJohn Marino    compilation of the function; it is used to control register
183*e4b17023SJohn Marino    allocation.
184*e4b17023SJohn Marino 
185*e4b17023SJohn Marino    local-alloc.c may alter this number to change the priority.
186*e4b17023SJohn Marino 
187*e4b17023SJohn Marino    Negative values are special.
188*e4b17023SJohn Marino    -1 is used to mark a pseudo reg which has a constant or memory equivalent
189*e4b17023SJohn Marino    and is used infrequently enough that it should not get a hard register.
190*e4b17023SJohn Marino    -2 is used to mark a pseudo reg for a parameter, when a frame pointer
191*e4b17023SJohn Marino    is not required.  global.c makes an allocno for this but does
192*e4b17023SJohn Marino    not try to assign a hard register to it.  */
193*e4b17023SJohn Marino 
194*e4b17023SJohn Marino #define REG_LIVE_LENGTH(N)  (reg_info_p[N].live_length)
195*e4b17023SJohn Marino 
196*e4b17023SJohn Marino /* Indexed by n, gives number of basic block that  (REG n) is used in.
197*e4b17023SJohn Marino    If the value is REG_BLOCK_GLOBAL (-1),
198*e4b17023SJohn Marino    it means (REG n) is used in more than one basic block.
199*e4b17023SJohn Marino    REG_BLOCK_UNKNOWN (0) means it hasn't been seen yet so we don't know.
200*e4b17023SJohn Marino    This information remains valid for the rest of the compilation
201*e4b17023SJohn Marino    of the current function; it is used to control register allocation.  */
202*e4b17023SJohn Marino 
203*e4b17023SJohn Marino #define REG_BLOCK_UNKNOWN 0
204*e4b17023SJohn Marino #define REG_BLOCK_GLOBAL -1
205*e4b17023SJohn Marino 
206*e4b17023SJohn Marino #define REG_BASIC_BLOCK(N) (reg_info_p[N].basic_block)
207*e4b17023SJohn Marino 
208*e4b17023SJohn Marino /* Vector of substitutions of register numbers,
209*e4b17023SJohn Marino    used to map pseudo regs into hardware regs.
210*e4b17023SJohn Marino 
211*e4b17023SJohn Marino    This can't be folded into reg_n_info without changing all of the
212*e4b17023SJohn Marino    machine dependent directories, since the reload functions
213*e4b17023SJohn Marino    in the machine dependent files access it.  */
214*e4b17023SJohn Marino 
215*e4b17023SJohn Marino extern short *reg_renumber;
216*e4b17023SJohn Marino 
217*e4b17023SJohn Marino /* Flag set by local-alloc or global-alloc if they decide to allocate
218*e4b17023SJohn Marino    something in a call-clobbered register.  */
219*e4b17023SJohn Marino 
220*e4b17023SJohn Marino extern int caller_save_needed;
221*e4b17023SJohn Marino 
222*e4b17023SJohn Marino /* Predicate to decide whether to give a hard reg to a pseudo which
223*e4b17023SJohn Marino    is referenced REFS times and would need to be saved and restored
224*e4b17023SJohn Marino    around a call CALLS times.  */
225*e4b17023SJohn Marino 
226*e4b17023SJohn Marino #ifndef CALLER_SAVE_PROFITABLE
227*e4b17023SJohn Marino #define CALLER_SAVE_PROFITABLE(REFS, CALLS)  (4 * (CALLS) < (REFS))
228*e4b17023SJohn Marino #endif
229*e4b17023SJohn Marino 
230*e4b17023SJohn Marino /* Select a register mode required for caller save of hard regno REGNO.  */
231*e4b17023SJohn Marino #ifndef HARD_REGNO_CALLER_SAVE_MODE
232*e4b17023SJohn Marino #define HARD_REGNO_CALLER_SAVE_MODE(REGNO, NREGS, MODE) \
233*e4b17023SJohn Marino   choose_hard_reg_mode (REGNO, NREGS, false)
234*e4b17023SJohn Marino #endif
235*e4b17023SJohn Marino 
236*e4b17023SJohn Marino /* Registers that get partially clobbered by a call in a given mode.
237*e4b17023SJohn Marino    These must not be call used registers.  */
238*e4b17023SJohn Marino #ifndef HARD_REGNO_CALL_PART_CLOBBERED
239*e4b17023SJohn Marino #define HARD_REGNO_CALL_PART_CLOBBERED(REGNO, MODE) 0
240*e4b17023SJohn Marino #endif
241*e4b17023SJohn Marino 
242*e4b17023SJohn Marino typedef unsigned short move_table[N_REG_CLASSES];
243*e4b17023SJohn Marino 
244*e4b17023SJohn Marino /* Target-dependent globals.  */
245*e4b17023SJohn Marino struct target_regs {
246*e4b17023SJohn Marino   /* For each starting hard register, the number of consecutive hard
247*e4b17023SJohn Marino      registers that a given machine mode occupies.  */
248*e4b17023SJohn Marino   unsigned char x_hard_regno_nregs[FIRST_PSEUDO_REGISTER][MAX_MACHINE_MODE];
249*e4b17023SJohn Marino 
250*e4b17023SJohn Marino   /* For each hard register, the widest mode object that it can contain.
251*e4b17023SJohn Marino      This will be a MODE_INT mode if the register can hold integers.  Otherwise
252*e4b17023SJohn Marino      it will be a MODE_FLOAT or a MODE_CC mode, whichever is valid for the
253*e4b17023SJohn Marino      register.  */
254*e4b17023SJohn Marino   enum machine_mode x_reg_raw_mode[FIRST_PSEUDO_REGISTER];
255*e4b17023SJohn Marino 
256*e4b17023SJohn Marino   /* Vector indexed by machine mode saying whether there are regs of
257*e4b17023SJohn Marino      that mode.  */
258*e4b17023SJohn Marino   bool x_have_regs_of_mode[MAX_MACHINE_MODE];
259*e4b17023SJohn Marino 
260*e4b17023SJohn Marino   /* 1 if the corresponding class contains a register of the given mode.  */
261*e4b17023SJohn Marino   char x_contains_reg_of_mode[N_REG_CLASSES][MAX_MACHINE_MODE];
262*e4b17023SJohn Marino 
263*e4b17023SJohn Marino   /* Maximum cost of moving from a register in one class to a register
264*e4b17023SJohn Marino      in another class.  Based on TARGET_REGISTER_MOVE_COST.  */
265*e4b17023SJohn Marino   move_table *x_move_cost[MAX_MACHINE_MODE];
266*e4b17023SJohn Marino 
267*e4b17023SJohn Marino   /* Similar, but here we don't have to move if the first index is a
268*e4b17023SJohn Marino      subset of the second so in that case the cost is zero.  */
269*e4b17023SJohn Marino   move_table *x_may_move_in_cost[MAX_MACHINE_MODE];
270*e4b17023SJohn Marino 
271*e4b17023SJohn Marino   /* Similar, but here we don't have to move if the first index is a
272*e4b17023SJohn Marino      superset of the second so in that case the cost is zero.  */
273*e4b17023SJohn Marino   move_table *x_may_move_out_cost[MAX_MACHINE_MODE];
274*e4b17023SJohn Marino 
275*e4b17023SJohn Marino   /* Keep track of the last mode we initialized move costs for.  */
276*e4b17023SJohn Marino   int x_last_mode_for_init_move_cost;
277*e4b17023SJohn Marino 
278*e4b17023SJohn Marino   /* Record for each mode whether we can move a register directly to or
279*e4b17023SJohn Marino      from an object of that mode in memory.  If we can't, we won't try
280*e4b17023SJohn Marino      to use that mode directly when accessing a field of that mode.  */
281*e4b17023SJohn Marino   char x_direct_load[NUM_MACHINE_MODES];
282*e4b17023SJohn Marino   char x_direct_store[NUM_MACHINE_MODES];
283*e4b17023SJohn Marino 
284*e4b17023SJohn Marino   /* Record for each mode whether we can float-extend from memory.  */
285*e4b17023SJohn Marino   bool x_float_extend_from_mem[NUM_MACHINE_MODES][NUM_MACHINE_MODES];
286*e4b17023SJohn Marino };
287*e4b17023SJohn Marino 
288*e4b17023SJohn Marino extern struct target_regs default_target_regs;
289*e4b17023SJohn Marino #if SWITCHABLE_TARGET
290*e4b17023SJohn Marino extern struct target_regs *this_target_regs;
291*e4b17023SJohn Marino #else
292*e4b17023SJohn Marino #define this_target_regs (&default_target_regs)
293*e4b17023SJohn Marino #endif
294*e4b17023SJohn Marino 
295*e4b17023SJohn Marino #define hard_regno_nregs \
296*e4b17023SJohn Marino   (this_target_regs->x_hard_regno_nregs)
297*e4b17023SJohn Marino #define reg_raw_mode \
298*e4b17023SJohn Marino   (this_target_regs->x_reg_raw_mode)
299*e4b17023SJohn Marino #define have_regs_of_mode \
300*e4b17023SJohn Marino   (this_target_regs->x_have_regs_of_mode)
301*e4b17023SJohn Marino #define contains_reg_of_mode \
302*e4b17023SJohn Marino   (this_target_regs->x_contains_reg_of_mode)
303*e4b17023SJohn Marino #define move_cost \
304*e4b17023SJohn Marino   (this_target_regs->x_move_cost)
305*e4b17023SJohn Marino #define may_move_in_cost \
306*e4b17023SJohn Marino   (this_target_regs->x_may_move_in_cost)
307*e4b17023SJohn Marino #define may_move_out_cost \
308*e4b17023SJohn Marino   (this_target_regs->x_may_move_out_cost)
309*e4b17023SJohn Marino #define direct_load \
310*e4b17023SJohn Marino   (this_target_regs->x_direct_load)
311*e4b17023SJohn Marino #define direct_store \
312*e4b17023SJohn Marino   (this_target_regs->x_direct_store)
313*e4b17023SJohn Marino #define float_extend_from_mem \
314*e4b17023SJohn Marino   (this_target_regs->x_float_extend_from_mem)
315*e4b17023SJohn Marino 
316*e4b17023SJohn Marino /* Return an exclusive upper bound on the registers occupied by hard
317*e4b17023SJohn Marino    register (reg:MODE REGNO).  */
318*e4b17023SJohn Marino 
319*e4b17023SJohn Marino static inline unsigned int
end_hard_regno(enum machine_mode mode,unsigned int regno)320*e4b17023SJohn Marino end_hard_regno (enum machine_mode mode, unsigned int regno)
321*e4b17023SJohn Marino {
322*e4b17023SJohn Marino   return regno + hard_regno_nregs[regno][(int) mode];
323*e4b17023SJohn Marino }
324*e4b17023SJohn Marino 
325*e4b17023SJohn Marino /* Likewise for hard register X.  */
326*e4b17023SJohn Marino 
327*e4b17023SJohn Marino #define END_HARD_REGNO(X) end_hard_regno (GET_MODE (X), REGNO (X))
328*e4b17023SJohn Marino 
329*e4b17023SJohn Marino /* Likewise for hard or pseudo register X.  */
330*e4b17023SJohn Marino 
331*e4b17023SJohn Marino #define END_REGNO(X) (HARD_REGISTER_P (X) ? END_HARD_REGNO (X) : REGNO (X) + 1)
332*e4b17023SJohn Marino 
333*e4b17023SJohn Marino /* Add to REGS all the registers required to store a value of mode MODE
334*e4b17023SJohn Marino    in register REGNO.  */
335*e4b17023SJohn Marino 
336*e4b17023SJohn Marino static inline void
add_to_hard_reg_set(HARD_REG_SET * regs,enum machine_mode mode,unsigned int regno)337*e4b17023SJohn Marino add_to_hard_reg_set (HARD_REG_SET *regs, enum machine_mode mode,
338*e4b17023SJohn Marino 		     unsigned int regno)
339*e4b17023SJohn Marino {
340*e4b17023SJohn Marino   unsigned int end_regno;
341*e4b17023SJohn Marino 
342*e4b17023SJohn Marino   end_regno = end_hard_regno (mode, regno);
343*e4b17023SJohn Marino   do
344*e4b17023SJohn Marino     SET_HARD_REG_BIT (*regs, regno);
345*e4b17023SJohn Marino   while (++regno < end_regno);
346*e4b17023SJohn Marino }
347*e4b17023SJohn Marino 
348*e4b17023SJohn Marino /* Likewise, but remove the registers.  */
349*e4b17023SJohn Marino 
350*e4b17023SJohn Marino static inline void
remove_from_hard_reg_set(HARD_REG_SET * regs,enum machine_mode mode,unsigned int regno)351*e4b17023SJohn Marino remove_from_hard_reg_set (HARD_REG_SET *regs, enum machine_mode mode,
352*e4b17023SJohn Marino 			  unsigned int regno)
353*e4b17023SJohn Marino {
354*e4b17023SJohn Marino   unsigned int end_regno;
355*e4b17023SJohn Marino 
356*e4b17023SJohn Marino   end_regno = end_hard_regno (mode, regno);
357*e4b17023SJohn Marino   do
358*e4b17023SJohn Marino     CLEAR_HARD_REG_BIT (*regs, regno);
359*e4b17023SJohn Marino   while (++regno < end_regno);
360*e4b17023SJohn Marino }
361*e4b17023SJohn Marino 
362*e4b17023SJohn Marino /* Return true if REGS contains the whole of (reg:MODE REGNO).  */
363*e4b17023SJohn Marino 
364*e4b17023SJohn Marino static inline bool
in_hard_reg_set_p(const HARD_REG_SET regs,enum machine_mode mode,unsigned int regno)365*e4b17023SJohn Marino in_hard_reg_set_p (const HARD_REG_SET regs, enum machine_mode mode,
366*e4b17023SJohn Marino 		   unsigned int regno)
367*e4b17023SJohn Marino {
368*e4b17023SJohn Marino   unsigned int end_regno;
369*e4b17023SJohn Marino 
370*e4b17023SJohn Marino   if (!TEST_HARD_REG_BIT (regs, regno))
371*e4b17023SJohn Marino     return false;
372*e4b17023SJohn Marino 
373*e4b17023SJohn Marino   end_regno = end_hard_regno (mode, regno);
374*e4b17023SJohn Marino   while (++regno < end_regno)
375*e4b17023SJohn Marino     if (!TEST_HARD_REG_BIT (regs, regno))
376*e4b17023SJohn Marino       return false;
377*e4b17023SJohn Marino 
378*e4b17023SJohn Marino   return true;
379*e4b17023SJohn Marino }
380*e4b17023SJohn Marino 
381*e4b17023SJohn Marino /* Return true if (reg:MODE REGNO) includes an element of REGS.  */
382*e4b17023SJohn Marino 
383*e4b17023SJohn Marino static inline bool
overlaps_hard_reg_set_p(const HARD_REG_SET regs,enum machine_mode mode,unsigned int regno)384*e4b17023SJohn Marino overlaps_hard_reg_set_p (const HARD_REG_SET regs, enum machine_mode mode,
385*e4b17023SJohn Marino 			 unsigned int regno)
386*e4b17023SJohn Marino {
387*e4b17023SJohn Marino   unsigned int end_regno;
388*e4b17023SJohn Marino 
389*e4b17023SJohn Marino   if (TEST_HARD_REG_BIT (regs, regno))
390*e4b17023SJohn Marino     return true;
391*e4b17023SJohn Marino 
392*e4b17023SJohn Marino   end_regno = end_hard_regno (mode, regno);
393*e4b17023SJohn Marino   while (++regno < end_regno)
394*e4b17023SJohn Marino     if (TEST_HARD_REG_BIT (regs, regno))
395*e4b17023SJohn Marino       return true;
396*e4b17023SJohn Marino 
397*e4b17023SJohn Marino   return false;
398*e4b17023SJohn Marino }
399*e4b17023SJohn Marino 
400*e4b17023SJohn Marino /* Like add_to_hard_reg_set, but use a REGNO/NREGS range instead of
401*e4b17023SJohn Marino    REGNO and MODE.  */
402*e4b17023SJohn Marino 
403*e4b17023SJohn Marino static inline void
add_range_to_hard_reg_set(HARD_REG_SET * regs,unsigned int regno,int nregs)404*e4b17023SJohn Marino add_range_to_hard_reg_set (HARD_REG_SET *regs, unsigned int regno,
405*e4b17023SJohn Marino 			   int nregs)
406*e4b17023SJohn Marino {
407*e4b17023SJohn Marino   while (nregs-- > 0)
408*e4b17023SJohn Marino     SET_HARD_REG_BIT (*regs, regno + nregs);
409*e4b17023SJohn Marino }
410*e4b17023SJohn Marino 
411*e4b17023SJohn Marino /* Likewise, but remove the registers.  */
412*e4b17023SJohn Marino 
413*e4b17023SJohn Marino static inline void
remove_range_from_hard_reg_set(HARD_REG_SET * regs,unsigned int regno,int nregs)414*e4b17023SJohn Marino remove_range_from_hard_reg_set (HARD_REG_SET *regs, unsigned int regno,
415*e4b17023SJohn Marino 				int nregs)
416*e4b17023SJohn Marino {
417*e4b17023SJohn Marino   while (nregs-- > 0)
418*e4b17023SJohn Marino     CLEAR_HARD_REG_BIT (*regs, regno + nregs);
419*e4b17023SJohn Marino }
420*e4b17023SJohn Marino 
421*e4b17023SJohn Marino /* Like overlaps_hard_reg_set_p, but use a REGNO/NREGS range instead of
422*e4b17023SJohn Marino    REGNO and MODE.  */
423*e4b17023SJohn Marino static inline bool
range_overlaps_hard_reg_set_p(const HARD_REG_SET set,unsigned regno,int nregs)424*e4b17023SJohn Marino range_overlaps_hard_reg_set_p (const HARD_REG_SET set, unsigned regno,
425*e4b17023SJohn Marino 			       int nregs)
426*e4b17023SJohn Marino {
427*e4b17023SJohn Marino   while (nregs-- > 0)
428*e4b17023SJohn Marino     if (TEST_HARD_REG_BIT (set, regno + nregs))
429*e4b17023SJohn Marino       return true;
430*e4b17023SJohn Marino   return false;
431*e4b17023SJohn Marino }
432*e4b17023SJohn Marino 
433*e4b17023SJohn Marino /* Like in_hard_reg_set_p, but use a REGNO/NREGS range instead of
434*e4b17023SJohn Marino    REGNO and MODE.  */
435*e4b17023SJohn Marino static inline bool
range_in_hard_reg_set_p(const HARD_REG_SET set,unsigned regno,int nregs)436*e4b17023SJohn Marino range_in_hard_reg_set_p (const HARD_REG_SET set, unsigned regno, int nregs)
437*e4b17023SJohn Marino {
438*e4b17023SJohn Marino   while (nregs-- > 0)
439*e4b17023SJohn Marino     if (!TEST_HARD_REG_BIT (set, regno + nregs))
440*e4b17023SJohn Marino       return false;
441*e4b17023SJohn Marino   return true;
442*e4b17023SJohn Marino }
443*e4b17023SJohn Marino 
444*e4b17023SJohn Marino #endif /* GCC_REGS_H */
445