regs.h revision 50397
11590Srgrimes/* Define per-register tables for data flow info and register allocation.
21590Srgrimes   Copyright (C) 1987, 1993, 1994, 1995, 1997, 1998 Free Software Foundation, Inc.
31590Srgrimes
41590SrgrimesThis file is part of GNU CC.
51590Srgrimes
61590SrgrimesGNU CC is free software; you can redistribute it and/or modify
71590Srgrimesit under the terms of the GNU General Public License as published by
81590Srgrimesthe Free Software Foundation; either version 2, or (at your option)
91590Srgrimesany later version.
101590Srgrimes
111590SrgrimesGNU CC is distributed in the hope that it will be useful,
121590Srgrimesbut WITHOUT ANY WARRANTY; without even the implied warranty of
131590SrgrimesMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
141590SrgrimesGNU General Public License for more details.
151590Srgrimes
161590SrgrimesYou should have received a copy of the GNU General Public License
171590Srgrimesalong with GNU CC; see the file COPYING.  If not, write to
181590Srgrimesthe Free Software Foundation, 59 Temple Place - Suite 330,
191590SrgrimesBoston, MA 02111-1307, USA.  */
201590Srgrimes
211590Srgrimes
221590Srgrimes#include "varray.h"
231590Srgrimes
241590Srgrimes#define REG_BYTES(R) mode_size[(int) GET_MODE (R)]
251590Srgrimes
261590Srgrimes/* Get the number of consecutive hard regs required to hold the REG rtx R.
271590Srgrimes   When something may be an explicit hard reg, REG_SIZE is the only
281590Srgrimes   valid way to get this value.  You cannot get it from the regno.  */
2929759Swollman
3050477Speter#define REG_SIZE(R) \
311590Srgrimes  ((mode_size[(int) GET_MODE (R)] + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
321590Srgrimes
331590Srgrimes#ifndef SMALL_REGISTER_CLASSES
341590Srgrimes#define SMALL_REGISTER_CLASSES 0
351590Srgrimes#endif
36226396Sed
37226396Sed/* Maximum register number used in this function, plus one.  */
38226396Sed
39226396Sedextern int max_regno;
4029759Swollman
4129759Swollman/* Maximum number of SCRATCH rtx's in each block of this function.  */
4229759Swollman
4387715Smarkmextern int max_scratch;
4429759Swollman
451590Srgrimes/* Register information indexed by register number */
461590Srgrimestypedef struct reg_info_def {
471590Srgrimes				/* fields set by reg_scan */
48158161Sbde  int first_uid;		/* UID of first insn to use (REG n) */
4974671Stmm  int last_uid;			/* UID of last insn to use (REG n) */
5074671Stmm  int last_note_uid;		/* UID of last note to use (REG n) */
5174671Stmm
5274671Stmm				/* fields set by both reg_scan and flow_analysis */
53158161Sbde  int sets;			/* # of times (REG n) is set */
5474671Stmm
551590Srgrimes				/* fields set by flow_analysis */
561590Srgrimes  int refs;			/* # of times (REG n) is used or set */
57288306Smr  int deaths;			/* # of times (REG n) dies */
581590Srgrimes  int live_length;		/* # of instructions (REG n) is live */
591590Srgrimes  int calls_crossed;		/* # of calls (REG n) is live across */
601590Srgrimes  int basic_block;		/* # of basic blocks (REG n) is used in */
611590Srgrimes  char changes_size;		/* whether (SUBREG (REG n)) changes size */
62158160Sbde} reg_info;
63158160Sbde
6474671Stmmextern varray_type reg_n_info;
651590Srgrimes
661590Srgrimesextern unsigned int reg_n_max;
671590Srgrimes
681590Srgrimes/* Indexed by n, gives number of times (REG n) is used or set.
69   References within loops may be counted more times.  */
70
71#define REG_N_REFS(N) (VARRAY_REG (reg_n_info, N)->refs)
72
73/* Indexed by n, gives number of times (REG n) is set.
74   ??? both regscan and flow allocate space for this.  We should settle
75   on just copy.  */
76
77#define REG_N_SETS(N) (VARRAY_REG (reg_n_info, N)->sets)
78
79/* Indexed by N, gives number of insns in which register N dies.
80   Note that if register N is live around loops, it can die
81   in transitions between basic blocks, and that is not counted here.
82   So this is only a reliable indicator of how many regions of life there are
83   for registers that are contained in one basic block.  */
84
85#define REG_N_DEATHS(N) (VARRAY_REG (reg_n_info, N)->deaths)
86
87/* Indexed by N; says whether a pseudo register N was ever used
88   within a SUBREG that changes the size of the reg.  Some machines prohibit
89   such objects to be in certain (usually floating-point) registers.  */
90
91#define REG_CHANGES_SIZE(N) (VARRAY_REG (reg_n_info, N)->changes_size)
92
93/* Get the number of consecutive words required to hold pseudo-reg N.  */
94
95#define PSEUDO_REGNO_SIZE(N) \
96  ((GET_MODE_SIZE (PSEUDO_REGNO_MODE (N)) + UNITS_PER_WORD - 1)		\
97   / UNITS_PER_WORD)
98
99/* Get the number of bytes required to hold pseudo-reg N.  */
100
101#define PSEUDO_REGNO_BYTES(N) \
102  GET_MODE_SIZE (PSEUDO_REGNO_MODE (N))
103
104/* Get the machine mode of pseudo-reg N.  */
105
106#define PSEUDO_REGNO_MODE(N) GET_MODE (regno_reg_rtx[N])
107
108/* Indexed by N, gives number of CALL_INSNS across which (REG n) is live.  */
109
110#define REG_N_CALLS_CROSSED(N) (VARRAY_REG (reg_n_info, N)->calls_crossed)
111
112/* Total number of instructions at which (REG n) is live.
113   The larger this is, the less priority (REG n) gets for
114   allocation in a hard register (in global-alloc).
115   This is set in flow.c and remains valid for the rest of the compilation
116   of the function; it is used to control register allocation.
117
118   local-alloc.c may alter this number to change the priority.
119
120   Negative values are special.
121   -1 is used to mark a pseudo reg which has a constant or memory equivalent
122   and is used infrequently enough that it should not get a hard register.
123   -2 is used to mark a pseudo reg for a parameter, when a frame pointer
124   is not required.  global.c makes an allocno for this but does
125   not try to assign a hard register to it.  */
126
127#define REG_LIVE_LENGTH(N) (VARRAY_REG (reg_n_info, N)->live_length)
128
129/* Vector of substitutions of register numbers,
130   used to map pseudo regs into hardware regs.
131
132   This can't be folded into reg_n_info without changing all of the
133   machine dependent directories, since the reload functions
134   in the machine dependent files access it.  */
135
136extern short *reg_renumber;
137
138/* Vector indexed by hardware reg
139   saying whether that reg is ever used.  */
140
141extern char regs_ever_live[FIRST_PSEUDO_REGISTER];
142
143/* Vector indexed by hardware reg giving its name.  */
144
145extern char *reg_names[FIRST_PSEUDO_REGISTER];
146
147/* For each hard register, the widest mode object that it can contain.
148   This will be a MODE_INT mode if the register can hold integers.  Otherwise
149   it will be a MODE_FLOAT or a MODE_CC mode, whichever is valid for the
150   register.  */
151
152extern enum machine_mode reg_raw_mode[FIRST_PSEUDO_REGISTER];
153
154/* Vector indexed by regno; gives uid of first insn using that reg.
155   This is computed by reg_scan for use by cse and loop.
156   It is sometimes adjusted for subsequent changes during loop,
157   but not adjusted by cse even if cse invalidates it.  */
158
159#define REGNO_FIRST_UID(N) (VARRAY_REG (reg_n_info, N)->first_uid)
160
161/* Vector indexed by regno; gives uid of last insn using that reg.
162   This is computed by reg_scan for use by cse and loop.
163   It is sometimes adjusted for subsequent changes during loop,
164   but not adjusted by cse even if cse invalidates it.
165   This is harmless since cse won't scan through a loop end.  */
166
167#define REGNO_LAST_UID(N) (VARRAY_REG (reg_n_info, N)->last_uid)
168
169/* Similar, but includes insns that mention the reg in their notes.  */
170
171#define REGNO_LAST_NOTE_UID(N) (VARRAY_REG (reg_n_info, N)->last_note_uid)
172
173/* This is reset to LAST_VIRTUAL_REGISTER + 1 at the start of each function.
174   After rtl generation, it is 1 plus the largest register number used.  */
175
176extern int reg_rtx_no;
177
178/* Vector indexed by regno; contains 1 for a register is considered a pointer.
179   Reloading, etc. will use a pointer register rather than a non-pointer
180   as the base register in an address, when there is a choice of two regs.  */
181
182extern char *regno_pointer_flag;
183#define REGNO_POINTER_FLAG(REGNO) regno_pointer_flag[REGNO]
184extern int regno_pointer_flag_length;
185
186/* List made of EXPR_LIST rtx's which gives pairs of pseudo registers
187   that have to go in the same hard reg.  */
188extern rtx regs_may_share;
189
190/* Vector mapping pseudo regno into the REG rtx for that register.
191   This is computed by reg_scan.  */
192
193extern rtx *regno_reg_rtx;
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/* Allocated in local_alloc.  */
215
216/* A list of SCRATCH rtl allocated by local-alloc.  */
217extern rtx *scratch_list;
218/* The basic block in which each SCRATCH is used.  */
219extern int *scratch_block;
220/* The length of the arrays pointed to by scratch_block and scratch_list.  */
221extern int scratch_list_length;
222
223/* Allocate reg_n_info tables */
224extern void allocate_reg_info PROTO((size_t, int, int));
225