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