regs.h revision 117395
1/* Define per-register tables for data flow info and register allocation.
2   Copyright (C) 1987, 1993, 1994, 1995, 1996, 1997, 1998,
3   1999, 2000 Free Software Foundation, Inc.
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9Software Foundation; either version 2, or (at your option) any later
10version.
11
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15for more details.
16
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING.  If not, write to the Free
19Software Foundation, 59 Temple Place - Suite 330, Boston, MA
2002111-1307, USA.  */
21
22
23#include "varray.h"
24#include "hard-reg-set.h"
25#include "basic-block.h"
26
27#define REG_BYTES(R) mode_size[(int) GET_MODE (R)]
28
29/* When you only have the mode of a pseudo register before it has a hard
30   register chosen for it, this reports the size of each hard register
31   a pseudo in such a mode would get allocated to.  A target may
32   override this.  */
33
34#ifndef REGMODE_NATURAL_SIZE
35#define REGMODE_NATURAL_SIZE(MODE)	UNITS_PER_WORD
36#endif
37
38#ifndef SMALL_REGISTER_CLASSES
39#define SMALL_REGISTER_CLASSES 0
40#endif
41
42/* Maximum register number used in this function, plus one.  */
43
44extern int max_regno;
45
46/* Register information indexed by register number */
47typedef struct reg_info_def
48{				/* fields set by reg_scan */
49  int first_uid;		/* UID of first insn to use (REG n) */
50  int last_uid;			/* UID of last insn to use (REG n) */
51  int last_note_uid;		/* UID of last note to use (REG n) */
52
53				/* fields set by reg_scan & flow_analysis */
54  int sets;			/* # of times (REG n) is set */
55
56				/* fields set by flow_analysis */
57  int refs;			/* # of times (REG n) is used or set */
58  int freq;			/* # estimated frequency (REG n) is used or set */
59  int deaths;			/* # of times (REG n) dies */
60  int live_length;		/* # of instructions (REG n) is live */
61  int calls_crossed;		/* # of calls (REG n) is live across */
62  int basic_block;		/* # of basic blocks (REG n) is used in */
63  char changes_mode;		/* whether (SUBREG (REG n)) exists and
64				   is illegal.  */
65} reg_info;
66
67extern varray_type reg_n_info;
68
69extern bitmap_head subregs_of_mode;
70
71/* Indexed by n, gives number of times (REG n) is used or set.  */
72
73#define REG_N_REFS(N) (VARRAY_REG (reg_n_info, N)->refs)
74
75/* Estimate frequency of references to register N.  */
76
77#define REG_FREQ(N) (VARRAY_REG (reg_n_info, N)->freq)
78
79/* The weights for each insn varries from 0 to REG_FREQ_BASE.
80   This constant does not need to be high, as in infrequently executed
81   regions we want to count instructions equivalently to optimize for
82   size instead of speed.  */
83#define REG_FREQ_MAX 1000
84
85/* Compute register frequency from the BB frequency.  When optimizing for size,
86   or profile driven feedback is available and the function is never executed,
87   frequency is always equivalent.  Otherwise rescale the basic block
88   frequency.  */
89#define REG_FREQ_FROM_BB(bb) (optimize_size				      \
90			      || (flag_branch_probabilities		      \
91				  && !ENTRY_BLOCK_PTR->count)		      \
92			      ? REG_FREQ_MAX				      \
93			      : ((bb)->frequency * REG_FREQ_MAX / BB_FREQ_MAX)\
94			      ? ((bb)->frequency * REG_FREQ_MAX / BB_FREQ_MAX)\
95			      : 1)
96
97/* Indexed by n, gives number of times (REG n) is set.
98   ??? both regscan and flow allocate space for this.  We should settle
99   on just copy.  */
100
101#define REG_N_SETS(N) (VARRAY_REG (reg_n_info, N)->sets)
102
103/* Indexed by N, gives number of insns in which register N dies.
104   Note that if register N is live around loops, it can die
105   in transitions between basic blocks, and that is not counted here.
106   So this is only a reliable indicator of how many regions of life there are
107   for registers that are contained in one basic block.  */
108
109#define REG_N_DEATHS(N) (VARRAY_REG (reg_n_info, N)->deaths)
110
111/* Get the number of consecutive words required to hold pseudo-reg N.  */
112
113#define PSEUDO_REGNO_SIZE(N) \
114  ((GET_MODE_SIZE (PSEUDO_REGNO_MODE (N)) + UNITS_PER_WORD - 1)		\
115   / UNITS_PER_WORD)
116
117/* Get the number of bytes required to hold pseudo-reg N.  */
118
119#define PSEUDO_REGNO_BYTES(N) \
120  GET_MODE_SIZE (PSEUDO_REGNO_MODE (N))
121
122/* Get the machine mode of pseudo-reg N.  */
123
124#define PSEUDO_REGNO_MODE(N) GET_MODE (regno_reg_rtx[N])
125
126/* Indexed by N, gives number of CALL_INSNS across which (REG n) is live.  */
127
128#define REG_N_CALLS_CROSSED(N) (VARRAY_REG (reg_n_info, N)->calls_crossed)
129
130/* Total number of instructions at which (REG n) is live.
131   The larger this is, the less priority (REG n) gets for
132   allocation in a hard register (in global-alloc).
133   This is set in flow.c and remains valid for the rest of the compilation
134   of the function; it is used to control register allocation.
135
136   local-alloc.c may alter this number to change the priority.
137
138   Negative values are special.
139   -1 is used to mark a pseudo reg which has a constant or memory equivalent
140   and is used infrequently enough that it should not get a hard register.
141   -2 is used to mark a pseudo reg for a parameter, when a frame pointer
142   is not required.  global.c makes an allocno for this but does
143   not try to assign a hard register to it.  */
144
145#define REG_LIVE_LENGTH(N) (VARRAY_REG (reg_n_info, N)->live_length)
146
147/* Vector of substitutions of register numbers,
148   used to map pseudo regs into hardware regs.
149
150   This can't be folded into reg_n_info without changing all of the
151   machine dependent directories, since the reload functions
152   in the machine dependent files access it.  */
153
154extern short *reg_renumber;
155
156/* Vector indexed by hardware reg
157   saying whether that reg is ever used.  */
158
159extern char regs_ever_live[FIRST_PSEUDO_REGISTER];
160
161/* Vector indexed by hardware reg giving its name.  */
162
163extern const char * reg_names[FIRST_PSEUDO_REGISTER];
164
165/* For each hard register, the widest mode object that it can contain.
166   This will be a MODE_INT mode if the register can hold integers.  Otherwise
167   it will be a MODE_FLOAT or a MODE_CC mode, whichever is valid for the
168   register.  */
169
170extern enum machine_mode reg_raw_mode[FIRST_PSEUDO_REGISTER];
171
172/* Vector indexed by regno; gives uid of first insn using that reg.
173   This is computed by reg_scan for use by cse and loop.
174   It is sometimes adjusted for subsequent changes during loop,
175   but not adjusted by cse even if cse invalidates it.  */
176
177#define REGNO_FIRST_UID(N) (VARRAY_REG (reg_n_info, N)->first_uid)
178
179/* Vector indexed by regno; gives uid of last insn using that reg.
180   This is computed by reg_scan for use by cse and loop.
181   It is sometimes adjusted for subsequent changes during loop,
182   but not adjusted by cse even if cse invalidates it.
183   This is harmless since cse won't scan through a loop end.  */
184
185#define REGNO_LAST_UID(N) (VARRAY_REG (reg_n_info, N)->last_uid)
186
187/* Similar, but includes insns that mention the reg in their notes.  */
188
189#define REGNO_LAST_NOTE_UID(N) (VARRAY_REG (reg_n_info, N)->last_note_uid)
190
191/* List made of EXPR_LIST rtx's which gives pairs of pseudo registers
192   that have to go in the same hard reg.  */
193extern rtx regs_may_share;
194
195/* Flag set by local-alloc or global-alloc if they decide to allocate
196   something in a call-clobbered register.  */
197
198extern int caller_save_needed;
199
200/* Predicate to decide whether to give a hard reg to a pseudo which
201   is referenced REFS times and would need to be saved and restored
202   around a call CALLS times.  */
203
204#ifndef CALLER_SAVE_PROFITABLE
205#define CALLER_SAVE_PROFITABLE(REFS, CALLS)  (4 * (CALLS) < (REFS))
206#endif
207
208/* On most machines a register class is likely to be spilled if it
209   only has one register.  */
210#ifndef CLASS_LIKELY_SPILLED_P
211#define CLASS_LIKELY_SPILLED_P(CLASS) (reg_class_size[(int) (CLASS)] == 1)
212#endif
213
214/* Select a register mode required for caller save of hard regno REGNO.  */
215#ifndef HARD_REGNO_CALLER_SAVE_MODE
216#define HARD_REGNO_CALLER_SAVE_MODE(REGNO, NREGS, MODE) \
217  choose_hard_reg_mode (REGNO, NREGS)
218#endif
219
220/* Registers that get partially clobbered by a call in a given mode.
221   These must not be call used registers.  */
222#ifndef HARD_REGNO_CALL_PART_CLOBBERED
223#define HARD_REGNO_CALL_PART_CLOBBERED(REGNO, MODE) 0
224#endif
225
226/* Allocate reg_n_info tables */
227extern void allocate_reg_info PARAMS ((size_t, int, int));
228