00001 /* Define per-register tables for data flow info and register allocation. 00002 Copyright (C) 1987, 1993, 1994, 1995, 1996, 1997, 1998, 00003 1999, 2000 Free Software Foundation, Inc. 00004 00005 This file is part of GCC. 00006 00007 GCC is free software; you can redistribute it and/or modify it under 00008 the terms of the GNU General Public License as published by the Free 00009 Software Foundation; either version 2, or (at your option) any later 00010 version. 00011 00012 GCC is distributed in the hope that it will be useful, but WITHOUT ANY 00013 WARRANTY; without even the implied warranty of MERCHANTABILITY or 00014 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00015 for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with GCC; see the file COPYING. If not, write to the Free 00019 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 00020 02111-1307, USA. */ 00021 00022 00023 #include "varray.h" 00024 #include "hard-reg-set.h" 00025 #include "basic-block.h" 00026 00027 #define REG_BYTES(R) mode_size[(int) GET_MODE (R)] 00028 00029 /* When you only have the mode of a pseudo register before it has a hard 00030 register chosen for it, this reports the size of each hard register 00031 a pseudo in such a mode would get allocated to. A target may 00032 override this. */ 00033 00034 #ifndef REGMODE_NATURAL_SIZE 00035 #define REGMODE_NATURAL_SIZE(MODE) UNITS_PER_WORD 00036 #endif 00037 00038 #ifndef SMALL_REGISTER_CLASSES 00039 #define SMALL_REGISTER_CLASSES 0 00040 #endif 00041 00042 /* Maximum register number used in this function, plus one. */ 00043 00044 extern int max_regno; 00045 00046 /* Register information indexed by register number */ 00047 typedef struct reg_info_def 00048 { /* fields set by reg_scan */ 00049 int first_uid; /* UID of first insn to use (REG n) */ 00050 int last_uid; /* UID of last insn to use (REG n) */ 00051 int last_note_uid; /* UID of last note to use (REG n) */ 00052 00053 /* fields set by reg_scan & flow_analysis */ 00054 int sets; /* # of times (REG n) is set */ 00055 00056 /* fields set by flow_analysis */ 00057 int refs; /* # of times (REG n) is used or set */ 00058 int freq; /* # estimated frequency (REG n) is used or set */ 00059 int deaths; /* # of times (REG n) dies */ 00060 int live_length; /* # of instructions (REG n) is live */ 00061 int calls_crossed; /* # of calls (REG n) is live across */ 00062 int basic_block; /* # of basic blocks (REG n) is used in */ 00063 char changes_mode; /* whether (SUBREG (REG n)) exists and 00064 is illegal. */ 00065 } reg_info; 00066 00067 extern varray_type reg_n_info; 00068 00069 extern bitmap_head subregs_of_mode; 00070 00071 /* Indexed by n, gives number of times (REG n) is used or set. */ 00072 00073 #define REG_N_REFS(N) (VARRAY_REG (reg_n_info, N)->refs) 00074 00075 /* Estimate frequency of references to register N. */ 00076 00077 #define REG_FREQ(N) (VARRAY_REG (reg_n_info, N)->freq) 00078 00079 /* The weights for each insn varries from 0 to REG_FREQ_BASE. 00080 This constant does not need to be high, as in infrequently executed 00081 regions we want to count instructions equivalently to optimize for 00082 size instead of speed. */ 00083 #define REG_FREQ_MAX 1000 00084 00085 /* Compute register frequency from the BB frequency. When optimizing for size, 00086 or profile driven feedback is available and the function is never executed, 00087 frequency is always equivalent. Otherwise rescale the basic block 00088 frequency. */ 00089 #define REG_FREQ_FROM_BB(bb) (optimize_size \ 00090 || (flag_branch_probabilities \ 00091 && !ENTRY_BLOCK_PTR->count) \ 00092 ? REG_FREQ_MAX \ 00093 : ((bb)->frequency * REG_FREQ_MAX / BB_FREQ_MAX)\ 00094 ? ((bb)->frequency * REG_FREQ_MAX / BB_FREQ_MAX)\ 00095 : 1) 00096 00097 /* Indexed by n, gives number of times (REG n) is set. 00098 ??? both regscan and flow allocate space for this. We should settle 00099 on just copy. */ 00100 00101 #define REG_N_SETS(N) (VARRAY_REG (reg_n_info, N)->sets) 00102 00103 /* Indexed by N, gives number of insns in which register N dies. 00104 Note that if register N is live around loops, it can die 00105 in transitions between basic blocks, and that is not counted here. 00106 So this is only a reliable indicator of how many regions of life there are 00107 for registers that are contained in one basic block. */ 00108 00109 #define REG_N_DEATHS(N) (VARRAY_REG (reg_n_info, N)->deaths) 00110 00111 /* Get the number of consecutive words required to hold pseudo-reg N. */ 00112 00113 #define PSEUDO_REGNO_SIZE(N) \ 00114 ((GET_MODE_SIZE (PSEUDO_REGNO_MODE (N)) + UNITS_PER_WORD - 1) \ 00115 / UNITS_PER_WORD) 00116 00117 /* Get the number of bytes required to hold pseudo-reg N. */ 00118 00119 #define PSEUDO_REGNO_BYTES(N) \ 00120 GET_MODE_SIZE (PSEUDO_REGNO_MODE (N)) 00121 00122 /* Get the machine mode of pseudo-reg N. */ 00123 00124 #define PSEUDO_REGNO_MODE(N) GET_MODE (regno_reg_rtx[N]) 00125 00126 /* Indexed by N, gives number of CALL_INSNS across which (REG n) is live. */ 00127 00128 #define REG_N_CALLS_CROSSED(N) (VARRAY_REG (reg_n_info, N)->calls_crossed) 00129 00130 /* Total number of instructions at which (REG n) is live. 00131 The larger this is, the less priority (REG n) gets for 00132 allocation in a hard register (in global-alloc). 00133 This is set in flow.c and remains valid for the rest of the compilation 00134 of the function; it is used to control register allocation. 00135 00136 local-alloc.c may alter this number to change the priority. 00137 00138 Negative values are special. 00139 -1 is used to mark a pseudo reg which has a constant or memory equivalent 00140 and is used infrequently enough that it should not get a hard register. 00141 -2 is used to mark a pseudo reg for a parameter, when a frame pointer 00142 is not required. global.c makes an allocno for this but does 00143 not try to assign a hard register to it. */ 00144 00145 #define REG_LIVE_LENGTH(N) (VARRAY_REG (reg_n_info, N)->live_length) 00146 00147 /* Vector of substitutions of register numbers, 00148 used to map pseudo regs into hardware regs. 00149 00150 This can't be folded into reg_n_info without changing all of the 00151 machine dependent directories, since the reload functions 00152 in the machine dependent files access it. */ 00153 00154 extern short *reg_renumber; 00155 00156 /* Vector indexed by hardware reg 00157 saying whether that reg is ever used. */ 00158 00159 extern char regs_ever_live[FIRST_PSEUDO_REGISTER]; 00160 00161 /* Vector indexed by hardware reg giving its name. */ 00162 00163 extern const char * reg_names[FIRST_PSEUDO_REGISTER]; 00164 00165 /* For each hard register, the widest mode object that it can contain. 00166 This will be a MODE_INT mode if the register can hold integers. Otherwise 00167 it will be a MODE_FLOAT or a MODE_CC mode, whichever is valid for the 00168 register. */ 00169 00170 extern enum machine_mode reg_raw_mode[FIRST_PSEUDO_REGISTER]; 00171 00172 /* Vector indexed by regno; gives uid of first insn using that reg. 00173 This is computed by reg_scan for use by cse and loop. 00174 It is sometimes adjusted for subsequent changes during loop, 00175 but not adjusted by cse even if cse invalidates it. */ 00176 00177 #define REGNO_FIRST_UID(N) (VARRAY_REG (reg_n_info, N)->first_uid) 00178 00179 /* Vector indexed by regno; gives uid of last insn using that reg. 00180 This is computed by reg_scan for use by cse and loop. 00181 It is sometimes adjusted for subsequent changes during loop, 00182 but not adjusted by cse even if cse invalidates it. 00183 This is harmless since cse won't scan through a loop end. */ 00184 00185 #define REGNO_LAST_UID(N) (VARRAY_REG (reg_n_info, N)->last_uid) 00186 00187 /* Similar, but includes insns that mention the reg in their notes. */ 00188 00189 #define REGNO_LAST_NOTE_UID(N) (VARRAY_REG (reg_n_info, N)->last_note_uid) 00190 00191 /* List made of EXPR_LIST rtx's which gives pairs of pseudo registers 00192 that have to go in the same hard reg. */ 00193 extern rtx regs_may_share; 00194 00195 /* Flag set by local-alloc or global-alloc if they decide to allocate 00196 something in a call-clobbered register. */ 00197 00198 extern int caller_save_needed; 00199 00200 /* Predicate to decide whether to give a hard reg to a pseudo which 00201 is referenced REFS times and would need to be saved and restored 00202 around a call CALLS times. */ 00203 00204 #ifndef CALLER_SAVE_PROFITABLE 00205 #define CALLER_SAVE_PROFITABLE(REFS, CALLS) (4 * (CALLS) < (REFS)) 00206 #endif 00207 00208 /* On most machines a register class is likely to be spilled if it 00209 only has one register. */ 00210 #ifndef CLASS_LIKELY_SPILLED_P 00211 #define CLASS_LIKELY_SPILLED_P(CLASS) (reg_class_size[(int) (CLASS)] == 1) 00212 #endif 00213 00214 /* Select a register mode required for caller save of hard regno REGNO. */ 00215 #ifndef HARD_REGNO_CALLER_SAVE_MODE 00216 #define HARD_REGNO_CALLER_SAVE_MODE(REGNO, NREGS, MODE) \ 00217 choose_hard_reg_mode (REGNO, NREGS) 00218 #endif 00219 00220 /* Registers that get partially clobbered by a call in a given mode. 00221 These must not be call used registers. */ 00222 #ifndef HARD_REGNO_CALL_PART_CLOBBERED 00223 #define HARD_REGNO_CALL_PART_CLOBBERED(REGNO, MODE) 0 00224 #endif 00225 00226 /* Allocate reg_n_info tables */ 00227 extern void allocate_reg_info PARAMS ((size_t, int, int));
1.5.6