regs.h revision 169690
1139749Simp/* Define per-register tables for data flow info and register allocation.
2116735Sharti   Copyright (C) 1987, 1993, 1994, 1995, 1996, 1997, 1998,
3116735Sharti   1999, 2000, 2003, 2004 Free Software Foundation, Inc.
4116735Sharti
5116735ShartiThis file is part of GCC.
6116735Sharti
7116735ShartiGCC is free software; you can redistribute it and/or modify it under
8116735Shartithe terms of the GNU General Public License as published by the Free
9116735ShartiSoftware Foundation; either version 2, or (at your option) any later
10116735Shartiversion.
11116735Sharti
12116735ShartiGCC is distributed in the hope that it will be useful, but WITHOUT ANY
13116735ShartiWARRANTY; without even the implied warranty of MERCHANTABILITY or
14116735ShartiFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15116735Shartifor more details.
16116735Sharti
17116735ShartiYou should have received a copy of the GNU General Public License
18116735Shartialong with GCC; see the file COPYING.  If not, write to the Free
19116735ShartiSoftware Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
20116735Sharti02110-1301, USA.  */
21116735Sharti
22116735Sharti#ifndef GCC_REGS_H
23116735Sharti#define GCC_REGS_H
24116735Sharti
25116735Sharti#include "varray.h"
26116735Sharti#include "obstack.h"
27116735Sharti#include "hard-reg-set.h"
28116735Sharti#include "basic-block.h"
29116735Sharti
30116735Sharti#define REG_BYTES(R) mode_size[(int) GET_MODE (R)]
31119418Sobrien
32116735Sharti/* When you only have the mode of a pseudo register before it has a hard
33116735Sharti   register chosen for it, this reports the size of each hard register
34116735Sharti   a pseudo in such a mode would get allocated to.  A target may
35116735Sharti   override this.  */
36116735Sharti
37116735Sharti#ifndef REGMODE_NATURAL_SIZE
38116735Sharti#define REGMODE_NATURAL_SIZE(MODE)	UNITS_PER_WORD
39116735Sharti#endif
40116735Sharti
41116735Sharti#ifndef SMALL_REGISTER_CLASSES
42116735Sharti#define SMALL_REGISTER_CLASSES 0
43116735Sharti#endif
44116735Sharti
45116735Sharti/* Maximum register number used in this function, plus one.  */
46116735Sharti
47116735Shartiextern int max_regno;
48116735Sharti
49116735Sharti/* Register information indexed by register number */
50116735Shartitypedef struct reg_info_def
51116735Sharti{				/* fields set by reg_scan */
52118208Sharti  int first_uid;		/* UID of first insn to use (REG n) */
53116735Sharti  int last_uid;			/* UID of last insn to use (REG n) */
54116735Sharti
55116735Sharti				/* fields set by reg_scan & flow_analysis */
56116735Sharti  int sets;			/* # of times (REG n) is set */
57116735Sharti
58116735Sharti				/* fields set by flow_analysis */
59257176Sglebius  int refs;			/* # of times (REG n) is used or set */
60116735Sharti  int freq;			/* # estimated frequency (REG n) is used or set */
61147256Sbrooks  int deaths;			/* # of times (REG n) dies */
62116735Sharti  int live_length;		/* # of instructions (REG n) is live */
63116735Sharti  int calls_crossed;		/* # of calls (REG n) is live across */
64147525Sharti  int throw_calls_crossed;	/* # of calls that may throw (REG n) is live across */
65147525Sharti  int basic_block;		/* # of basic blocks (REG n) is used in */
66147525Sharti} reg_info;
67116735Sharti
68116735Shartitypedef reg_info *reg_info_p;
69116735Sharti
70116735ShartiDEF_VEC_P(reg_info_p);
71116735ShartiDEF_VEC_ALLOC_P(reg_info_p,heap);
72116735Sharti
73116735Shartiextern VEC(reg_info_p,heap) *reg_n_info;
74116735Sharti
75116735Sharti/* Indexed by n, gives number of times (REG n) is used or set.  */
76119277Simp
77119277Simp#define REG_N_REFS(N) (VEC_index (reg_info_p, reg_n_info, N)->refs)
78116735Sharti
79116735Sharti/* Estimate frequency of references to register N.  */
80116735Sharti
81116735Sharti#define REG_FREQ(N) (VEC_index (reg_info_p, reg_n_info, N)->freq)
82116735Sharti
83116735Sharti/* The weights for each insn varries from 0 to REG_FREQ_BASE.
84116735Sharti   This constant does not need to be high, as in infrequently executed
85116735Sharti   regions we want to count instructions equivalently to optimize for
86116735Sharti   size instead of speed.  */
87116735Sharti#define REG_FREQ_MAX 1000
88116735Sharti
89116735Sharti/* Compute register frequency from the BB frequency.  When optimizing for size,
90116735Sharti   or profile driven feedback is available and the function is never executed,
91116735Sharti   frequency is always equivalent.  Otherwise rescale the basic block
92116735Sharti   frequency.  */
93116735Sharti#define REG_FREQ_FROM_BB(bb) (optimize_size				      \
94116735Sharti			      || (flag_branch_probabilities		      \
95116735Sharti				  && !ENTRY_BLOCK_PTR->count)		      \
96116735Sharti			      ? REG_FREQ_MAX				      \
97116735Sharti			      : ((bb)->frequency * REG_FREQ_MAX / BB_FREQ_MAX)\
98116735Sharti			      ? ((bb)->frequency * REG_FREQ_MAX / BB_FREQ_MAX)\
99116735Sharti			      : 1)
100116735Sharti
101116735Sharti/* Indexed by n, gives number of times (REG n) is set.
102116735Sharti   ??? both regscan and flow allocate space for this.  We should settle
103116735Sharti   on just copy.  */
104116735Sharti
105116735Sharti#define REG_N_SETS(N) (VEC_index (reg_info_p, reg_n_info, N)->sets)
106116735Sharti
107116735Sharti/* Indexed by N, gives number of insns in which register N dies.
108116735Sharti   Note that if register N is live around loops, it can die
109116735Sharti   in transitions between basic blocks, and that is not counted here.
110116735Sharti   So this is only a reliable indicator of how many regions of life there are
111116735Sharti   for registers that are contained in one basic block.  */
112116735Sharti
113116735Sharti#define REG_N_DEATHS(N) (VEC_index (reg_info_p, reg_n_info, N)->deaths)
114116735Sharti
115116735Sharti/* Get the number of consecutive words required to hold pseudo-reg N.  */
116116735Sharti
117116735Sharti#define PSEUDO_REGNO_SIZE(N) \
118116735Sharti  ((GET_MODE_SIZE (PSEUDO_REGNO_MODE (N)) + UNITS_PER_WORD - 1)		\
119298433Spfg   / UNITS_PER_WORD)
120298433Spfg
121116735Sharti/* Get the number of bytes required to hold pseudo-reg N.  */
122118596Sharti
123118596Sharti#define PSEUDO_REGNO_BYTES(N) \
124116735Sharti  GET_MODE_SIZE (PSEUDO_REGNO_MODE (N))
125116735Sharti
126116735Sharti/* Get the machine mode of pseudo-reg N.  */
127116735Sharti
128116735Sharti#define PSEUDO_REGNO_MODE(N) GET_MODE (regno_reg_rtx[N])
129116735Sharti
130116735Sharti/* Indexed by N, gives number of CALL_INSNS across which (REG n) is live.  */
131116735Sharti
132116735Sharti#define REG_N_CALLS_CROSSED(N)					\
133116735Sharti  (VEC_index (reg_info_p, reg_n_info, N)->calls_crossed)
134116735Sharti
135116735Sharti/* Indexed by N, gives number of CALL_INSNS that may throw, across which
136116735Sharti   (REG n) is live.  */
137143161Simp
138116735Sharti#define REG_N_THROWING_CALLS_CROSSED(N) \
139116735Sharti  (VEC_index (reg_info_p, reg_n_info, N)->throw_calls_crossed)
140116735Sharti
141116735Sharti/* Total number of instructions at which (REG n) is live.
142116735Sharti   The larger this is, the less priority (REG n) gets for
143116735Sharti   allocation in a hard register (in global-alloc).
144116735Sharti   This is set in flow.c and remains valid for the rest of the compilation
145116735Sharti   of the function; it is used to control register allocation.
146116735Sharti
147116735Sharti   local-alloc.c may alter this number to change the priority.
148116735Sharti
149116735Sharti   Negative values are special.
150116735Sharti   -1 is used to mark a pseudo reg which has a constant or memory equivalent
151116735Sharti   and is used infrequently enough that it should not get a hard register.
152116735Sharti   -2 is used to mark a pseudo reg for a parameter, when a frame pointer
153116735Sharti   is not required.  global.c makes an allocno for this but does
154116735Sharti   not try to assign a hard register to it.  */
155116735Sharti
156116735Sharti#define REG_LIVE_LENGTH(N)				\
157116735Sharti  (VEC_index (reg_info_p, reg_n_info, N)->live_length)
158116735Sharti
159116735Sharti/* Vector of substitutions of register numbers,
160116735Sharti   used to map pseudo regs into hardware regs.
161116735Sharti
162116735Sharti   This can't be folded into reg_n_info without changing all of the
163116735Sharti   machine dependent directories, since the reload functions
164116735Sharti   in the machine dependent files access it.  */
165116735Sharti
166116735Shartiextern short *reg_renumber;
167116735Sharti
168116735Sharti/* Vector indexed by hardware reg saying whether that reg is ever used.  */
169116735Sharti
170116735Shartiextern char regs_ever_live[FIRST_PSEUDO_REGISTER];
171116735Sharti
172116735Sharti/* Like regs_ever_live, but saying whether reg is set by asm statements.  */
173147256Sbrooks
174116735Shartiextern char regs_asm_clobbered[FIRST_PSEUDO_REGISTER];
175148887Srwatson
176116735Sharti/* Vector indexed by machine mode saying whether there are regs of that mode.  */
177116735Sharti
178116735Shartiextern bool have_regs_of_mode [MAX_MACHINE_MODE];
179116735Sharti
180116735Sharti/* For each hard register, the widest mode object that it can contain.
181116735Sharti   This will be a MODE_INT mode if the register can hold integers.  Otherwise
182116735Sharti   it will be a MODE_FLOAT or a MODE_CC mode, whichever is valid for the
183116735Sharti   register.  */
184116735Sharti
185116735Shartiextern enum machine_mode reg_raw_mode[FIRST_PSEUDO_REGISTER];
186116735Sharti
187116735Sharti/* Vector indexed by regno; gives uid of first insn using that reg.
188116735Sharti   This is computed by reg_scan for use by cse and loop.
189116735Sharti   It is sometimes adjusted for subsequent changes during loop,
190116735Sharti   but not adjusted by cse even if cse invalidates it.  */
191116735Sharti
192116735Sharti#define REGNO_FIRST_UID(N) (VEC_index (reg_info_p, reg_n_info, N)->first_uid)
193116735Sharti
194116735Sharti/* Vector indexed by regno; gives uid of last insn using that reg.
195116735Sharti   This is computed by reg_scan for use by cse and loop.
196116735Sharti   It is sometimes adjusted for subsequent changes during loop,
197116735Sharti   but not adjusted by cse even if cse invalidates it.
198116735Sharti   This is harmless since cse won't scan through a loop end.  */
199116735Sharti
200116735Sharti#define REGNO_LAST_UID(N) (VEC_index (reg_info_p, reg_n_info, N)->last_uid)
201116735Sharti
202116735Sharti/* List made of EXPR_LIST rtx's which gives pairs of pseudo registers
203116735Sharti   that have to go in the same hard reg.  */
204116735Shartiextern rtx regs_may_share;
205116735Sharti
206116735Sharti/* Flag set by local-alloc or global-alloc if they decide to allocate
207116735Sharti   something in a call-clobbered register.  */
208116735Sharti
209116735Shartiextern int caller_save_needed;
210116735Sharti
211116735Sharti/* Predicate to decide whether to give a hard reg to a pseudo which
212116735Sharti   is referenced REFS times and would need to be saved and restored
213116735Sharti   around a call CALLS times.  */
214116735Sharti
215116735Sharti#ifndef CALLER_SAVE_PROFITABLE
216116735Sharti#define CALLER_SAVE_PROFITABLE(REFS, CALLS)  (4 * (CALLS) < (REFS))
217116735Sharti#endif
218116735Sharti
219116735Sharti/* On most machines a register class is likely to be spilled if it
220116735Sharti   only has one register.  */
221116735Sharti#ifndef CLASS_LIKELY_SPILLED_P
222116735Sharti#define CLASS_LIKELY_SPILLED_P(CLASS) (reg_class_size[(int) (CLASS)] == 1)
223116735Sharti#endif
224116735Sharti
225116735Sharti/* Select a register mode required for caller save of hard regno REGNO.  */
226116735Sharti#ifndef HARD_REGNO_CALLER_SAVE_MODE
227116735Sharti#define HARD_REGNO_CALLER_SAVE_MODE(REGNO, NREGS, MODE) \
228116735Sharti  choose_hard_reg_mode (REGNO, NREGS, false)
229116735Sharti#endif
230116735Sharti
231116735Sharti/* Registers that get partially clobbered by a call in a given mode.
232116735Sharti   These must not be call used registers.  */
233116735Sharti#ifndef HARD_REGNO_CALL_PART_CLOBBERED
234116735Sharti#define HARD_REGNO_CALL_PART_CLOBBERED(REGNO, MODE) 0
235116735Sharti#endif
236116735Sharti
237116735Sharti/* Allocate reg_n_info tables */
238116735Shartiextern void allocate_reg_info (size_t, int, int);
239116735Sharti
240116735Sharti/* Specify number of hard registers given machine mode occupy.  */
241116735Shartiextern unsigned char hard_regno_nregs[FIRST_PSEUDO_REGISTER][MAX_MACHINE_MODE];
242116735Sharti
243116735Sharti#endif /* GCC_REGS_H */
244116735Sharti