regs.h revision 132718
186146Stmm/* Define per-register tables for data flow info and register allocation. 286146Stmm Copyright (C) 1987, 1993, 1994, 1995, 1996, 1997, 1998, 386146Stmm 1999, 2000, 2003 Free Software Foundation, Inc. 486146Stmm 586146StmmThis file is part of GCC. 686146Stmm 786146StmmGCC is free software; you can redistribute it and/or modify it under 886146Stmmthe terms of the GNU General Public License as published by the Free 986146StmmSoftware Foundation; either version 2, or (at your option) any later 1086146Stmmversion. 1186146Stmm 1286146StmmGCC is distributed in the hope that it will be useful, but WITHOUT ANY 1386146StmmWARRANTY; without even the implied warranty of MERCHANTABILITY or 1486146StmmFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1586146Stmmfor more details. 1686146Stmm 1786146StmmYou should have received a copy of the GNU General Public License 1886146Stmmalong with GCC; see the file COPYING. If not, write to the Free 1986146StmmSoftware Foundation, 59 Temple Place - Suite 330, Boston, MA 2086146Stmm02111-1307, USA. */ 2186146Stmm 2286146Stmm 2386146Stmm#include "varray.h" 2486146Stmm#include "hard-reg-set.h" 2586146Stmm#include "basic-block.h" 2686146Stmm 2786146Stmm#define REG_BYTES(R) mode_size[(int) GET_MODE (R)] 2886146Stmm 2986146Stmm/* When you only have the mode of a pseudo register before it has a hard 3086146Stmm register chosen for it, this reports the size of each hard register 3186146Stmm a pseudo in such a mode would get allocated to. A target may 3286146Stmm override this. */ 3386146Stmm 3486146Stmm#ifndef REGMODE_NATURAL_SIZE 3586146Stmm#define REGMODE_NATURAL_SIZE(MODE) UNITS_PER_WORD 3686146Stmm#endif 3786146Stmm 3886146Stmm#ifndef SMALL_REGISTER_CLASSES 3986146Stmm#define SMALL_REGISTER_CLASSES 0 4086146Stmm#endif 4186146Stmm 4286146Stmm/* Maximum register number used in this function, plus one. */ 4386146Stmm 4486146Stmmextern int max_regno; 4586146Stmm 4686146Stmm/* Register information indexed by register number */ 4786146Stmmtypedef struct reg_info_def 4886146Stmm{ /* fields set by reg_scan */ 4986146Stmm int first_uid; /* UID of first insn to use (REG n) */ 5086146Stmm int last_uid; /* UID of last insn to use (REG n) */ 5186146Stmm int last_note_uid; /* UID of last note to use (REG n) */ 5286146Stmm 5386146Stmm /* fields set by reg_scan & flow_analysis */ 5486146Stmm int sets; /* # of times (REG n) is set */ 5586146Stmm 5686146Stmm /* fields set by flow_analysis */ 5786146Stmm int refs; /* # of times (REG n) is used or set */ 5886146Stmm int freq; /* # estimated frequency (REG n) is used or set */ 5986146Stmm int deaths; /* # of times (REG n) dies */ 6086146Stmm int live_length; /* # of instructions (REG n) is live */ 6186146Stmm int calls_crossed; /* # of calls (REG n) is live across */ 6286146Stmm int basic_block; /* # of basic blocks (REG n) is used in */ 6386146Stmm char changes_mode; /* whether (SUBREG (REG n)) exists and 6492050Stmm is illegal. */ 6592050Stmm} reg_info; 6686146Stmm 6786146Stmmextern varray_type reg_n_info; 6886146Stmm 6986146Stmmextern bitmap_head subregs_of_mode; 7086146Stmm 7186146Stmm/* Indexed by n, gives number of times (REG n) is used or set. */ 7286146Stmm 7386146Stmm#define REG_N_REFS(N) (VARRAY_REG (reg_n_info, N)->refs) 7486146Stmm 7586146Stmm/* Estimate frequency of references to register N. */ 7686146Stmm 7786146Stmm#define REG_FREQ(N) (VARRAY_REG (reg_n_info, N)->freq) 7886146Stmm 7986146Stmm/* The weights for each insn varries from 0 to REG_FREQ_BASE. 8086146Stmm This constant does not need to be high, as in infrequently executed 8186146Stmm regions we want to count instructions equivalently to optimize for 8286146Stmm size instead of speed. */ 8386146Stmm#define REG_FREQ_MAX 1000 8486146Stmm 8586146Stmm/* Compute register frequency from the BB frequency. When optimizing for size, 8692050Stmm or profile driven feedback is available and the function is never executed, 8792050Stmm frequency is always equivalent. Otherwise rescale the basic block 8886146Stmm frequency. */ 8986146Stmm#define REG_FREQ_FROM_BB(bb) (optimize_size \ 9086146Stmm || (flag_branch_probabilities \ 9186146Stmm && !ENTRY_BLOCK_PTR->count) \ 9286146Stmm ? REG_FREQ_MAX \ 9386146Stmm : ((bb)->frequency * REG_FREQ_MAX / BB_FREQ_MAX)\ 9486146Stmm ? ((bb)->frequency * REG_FREQ_MAX / BB_FREQ_MAX)\ 9586146Stmm : 1) 9686146Stmm 9786146Stmm/* Indexed by n, gives number of times (REG n) is set. 9886146Stmm ??? both regscan and flow allocate space for this. We should settle 9986146Stmm on just copy. */ 10086146Stmm 10186146Stmm#define REG_N_SETS(N) (VARRAY_REG (reg_n_info, N)->sets) 10286146Stmm 10386146Stmm/* Indexed by N, gives number of insns in which register N dies. 10486146Stmm Note that if register N is live around loops, it can die 10586146Stmm in transitions between basic blocks, and that is not counted here. 10686146Stmm So this is only a reliable indicator of how many regions of life there are 10786146Stmm for registers that are contained in one basic block. */ 10886146Stmm 10986146Stmm#define REG_N_DEATHS(N) (VARRAY_REG (reg_n_info, N)->deaths) 11086146Stmm 11186146Stmm/* Get the number of consecutive words required to hold pseudo-reg N. */ 11286146Stmm 11386146Stmm#define PSEUDO_REGNO_SIZE(N) \ 11486146Stmm ((GET_MODE_SIZE (PSEUDO_REGNO_MODE (N)) + UNITS_PER_WORD - 1) \ 11586146Stmm / UNITS_PER_WORD) 11686146Stmm 11786146Stmm/* Get the number of bytes required to hold pseudo-reg N. */ 11886146Stmm 11986146Stmm#define PSEUDO_REGNO_BYTES(N) \ 12086146Stmm GET_MODE_SIZE (PSEUDO_REGNO_MODE (N)) 12186146Stmm 12286146Stmm/* Get the machine mode of pseudo-reg N. */ 12386146Stmm 12486146Stmm#define PSEUDO_REGNO_MODE(N) GET_MODE (regno_reg_rtx[N]) 12586146Stmm 12686146Stmm/* Indexed by N, gives number of CALL_INSNS across which (REG n) is live. */ 12786146Stmm 12886146Stmm#define REG_N_CALLS_CROSSED(N) (VARRAY_REG (reg_n_info, N)->calls_crossed) 12986146Stmm 13086146Stmm/* Total number of instructions at which (REG n) is live. 13186146Stmm The larger this is, the less priority (REG n) gets for 13286146Stmm allocation in a hard register (in global-alloc). 13386146Stmm This is set in flow.c and remains valid for the rest of the compilation 13486146Stmm of the function; it is used to control register allocation. 13586146Stmm 13686146Stmm local-alloc.c may alter this number to change the priority. 13786146Stmm 13886146Stmm Negative values are special. 13986146Stmm -1 is used to mark a pseudo reg which has a constant or memory equivalent 14086146Stmm and is used infrequently enough that it should not get a hard register. 14186146Stmm -2 is used to mark a pseudo reg for a parameter, when a frame pointer 14286146Stmm is not required. global.c makes an allocno for this but does 14386146Stmm not try to assign a hard register to it. */ 14488663Sjake 14588663Sjake#define REG_LIVE_LENGTH(N) (VARRAY_REG (reg_n_info, N)->live_length) 14686146Stmm 14786146Stmm/* Vector of substitutions of register numbers, 14886146Stmm used to map pseudo regs into hardware regs. 14986146Stmm 15086146Stmm This can't be folded into reg_n_info without changing all of the 15186146Stmm machine dependent directories, since the reload functions 15286146Stmm in the machine dependent files access it. */ 15386146Stmm 15486146Stmmextern short *reg_renumber; 15586146Stmm 15686146Stmm/* Vector indexed by hardware reg saying whether that reg is ever used. */ 15786146Stmm 15886146Stmmextern char regs_ever_live[FIRST_PSEUDO_REGISTER]; 15986146Stmm 16086146Stmm/* Like regs_ever_live, but saying whether reg is set by asm statements. */ 16186146Stmm 16286146Stmmextern char regs_asm_clobbered[FIRST_PSEUDO_REGISTER]; 16386146Stmm 16486146Stmm/* For each hard register, the widest mode object that it can contain. 16586146Stmm This will be a MODE_INT mode if the register can hold integers. Otherwise 16686146Stmm it will be a MODE_FLOAT or a MODE_CC mode, whichever is valid for the 16786146Stmm register. */ 16886146Stmm 16986146Stmmextern enum machine_mode reg_raw_mode[FIRST_PSEUDO_REGISTER]; 17086146Stmm 17186146Stmm/* Vector indexed by regno; gives uid of first insn using that reg. 17286146Stmm This is computed by reg_scan for use by cse and loop. 17386146Stmm It is sometimes adjusted for subsequent changes during loop, 17486146Stmm but not adjusted by cse even if cse invalidates it. */ 17586146Stmm 17686146Stmm#define REGNO_FIRST_UID(N) (VARRAY_REG (reg_n_info, N)->first_uid) 17792050Stmm 17886146Stmm/* Vector indexed by regno; gives uid of last insn using that reg. 17986146Stmm This is computed by reg_scan for use by cse and loop. 18086146Stmm It is sometimes adjusted for subsequent changes during loop, 18186146Stmm but not adjusted by cse even if cse invalidates it. 18286146Stmm This is harmless since cse won't scan through a loop end. */ 18386146Stmm 18486146Stmm#define REGNO_LAST_UID(N) (VARRAY_REG (reg_n_info, N)->last_uid) 18586146Stmm 18686146Stmm/* Similar, but includes insns that mention the reg in their notes. */ 18786146Stmm 18892050Stmm#define REGNO_LAST_NOTE_UID(N) (VARRAY_REG (reg_n_info, N)->last_note_uid) 18986146Stmm 19086146Stmm/* List made of EXPR_LIST rtx's which gives pairs of pseudo registers 19186146Stmm that have to go in the same hard reg. */ 19286146Stmmextern rtx regs_may_share; 19386146Stmm 19486146Stmm/* Flag set by local-alloc or global-alloc if they decide to allocate 19586146Stmm something in a call-clobbered register. */ 19686146Stmm 19786146Stmmextern int caller_save_needed; 19886146Stmm 19986146Stmm/* Predicate to decide whether to give a hard reg to a pseudo which 20086146Stmm is referenced REFS times and would need to be saved and restored 20186146Stmm around a call CALLS times. */ 20286146Stmm 20386146Stmm#ifndef CALLER_SAVE_PROFITABLE 20486146Stmm#define CALLER_SAVE_PROFITABLE(REFS, CALLS) (4 * (CALLS) < (REFS)) 20586146Stmm#endif 20686146Stmm 20786146Stmm/* On most machines a register class is likely to be spilled if it 20886146Stmm only has one register. */ 20986146Stmm#ifndef CLASS_LIKELY_SPILLED_P 21086146Stmm#define CLASS_LIKELY_SPILLED_P(CLASS) (reg_class_size[(int) (CLASS)] == 1) 21186146Stmm#endif 21286146Stmm 21386146Stmm/* Select a register mode required for caller save of hard regno REGNO. */ 21486146Stmm#ifndef HARD_REGNO_CALLER_SAVE_MODE 21586146Stmm#define HARD_REGNO_CALLER_SAVE_MODE(REGNO, NREGS, MODE) \ 21686146Stmm choose_hard_reg_mode (REGNO, NREGS, false) 21786146Stmm#endif 21886146Stmm 21986146Stmm/* Registers that get partially clobbered by a call in a given mode. 22086146Stmm These must not be call used registers. */ 22186146Stmm#ifndef HARD_REGNO_CALL_PART_CLOBBERED 22286146Stmm#define HARD_REGNO_CALL_PART_CLOBBERED(REGNO, MODE) 0 22386146Stmm#endif 22486146Stmm 22586146Stmm/* Allocate reg_n_info tables */ 22686146Stmmextern void allocate_reg_info (size_t, int, int); 22786146Stmm