GCC Middle and Back End API Reference
caller-save.c File Reference

Data Structures

struct  saved_hard_reg

Typedefs

typedef void refmarker_fn (rtx *loc, enum machine_mode mode, int hardregno, void *mark_arg)

Functions

static int reg_save_code (int, enum machine_mode)
static int reg_restore_code (int, enum machine_mode)
static void initiate_saved_hard_regs (void)
static void new_saved_hard_reg (int, int)
static void finish_saved_hard_regs (void)
static int saved_hard_reg_compare_func (const void *, const void *)
static void mark_set_regs (rtx, const_rtx, void *)
static void mark_referenced_regs (rtx *, refmarker_fn *mark, void *mark_arg)
static int insert_save (struct insn_chain *, int, int, HARD_REG_SET *, enum machine_mode *)
static int insert_restore (struct insn_chain *, int, int, int, enum machine_mode *)
static struct insn_chaininsert_one_insn (struct insn_chain *, int, int, rtx)
static void add_stored_regs (rtx, const_rtx, void *)
static int reg_save_code ()
static int reg_restore_code ()
void init_caller_save ()
void init_save_areas ()
static void new_saved_hard_reg ()
static int saved_hard_reg_compare_func ()
void setup_save_areas ()
void save_call_clobbered_regs ()
static void mark_set_regs ()
static void add_stored_regs ()
static void mark_referenced_regs ()
static void mark_reg_as_referenced (rtx *loc, enum machine_mode mode, int hardregno, void *arg)
static void replace_reg_with_saved_mem (rtx *loc, enum machine_mode mode, int regno, void *arg)
static int add_used_regs_1 ()
static void add_used_regs ()
static struct insn_chaininsert_one_insn ()

Variables

static rtx regno_save_mem [FIRST_PSEUDO_REGISTER][MAX_MOVE_MAX/MIN_UNITS_PER_WORD+1]
static int save_slots_num
static rtx save_slots [FIRST_PSEUDO_REGISTER]
static HARD_REG_SET hard_regs_saved
static int n_regs_saved
static HARD_REG_SET referenced_regs
static refmarker_fn mark_reg_as_referenced
static refmarker_fn replace_reg_with_saved_mem
static rtx savepat
static rtx restpat
static rtx test_reg
static rtx test_mem
static rtx saveinsn
static rtx restinsn
static struct saved_hard_reghard_reg_map [FIRST_PSEUDO_REGISTER]
static int saved_regs_num
static struct saved_hard_regall_saved_regs [FIRST_PSEUDO_REGISTER]

Typedef Documentation

typedef void refmarker_fn(rtx *loc, enum machine_mode mode, int hardregno, void *mark_arg)

Function Documentation

static void add_stored_regs ( rtx  ,
const_rtx  ,
void *   
)
static

Referenced by insert_one_insn().

static void add_stored_regs ( )
static
Here from note_stores when an insn stores a value in a register.
   Set the proper bit or bits in the passed regset.  All pseudos that have
   been assigned hard regs have had their register number changed already,
   so we can ignore pseudos.   

References end_hard_regno(), offset, subreg_nregs(), and subreg_regno_offset().

static void add_used_regs ( )
static
A note_uses callback used by insert_one_insn.  Add the hard-register
   equivalent of each REG to regset DATA.   

References add_used_regs_1(), and for_each_rtx().

Referenced by insert_one_insn().

static int add_used_regs_1 ( )
static
A for_each_rtx callback used by add_used_regs.  Add the hard-register
   equivalent of each REG to regset DATA.   

References bitmap_set_range(), live, and reg_renumber.

Referenced by add_used_regs().

static void finish_saved_hard_regs ( )
static
Free memory allocated for the saved hard registers.   

References free(), and saved_regs_num.

Referenced by setup_save_areas().

void init_caller_save ( void  )
Initialize for caller-save.

   Look at all the hard registers that are used by a call and for which
   reginfo.c has not already excluded from being used across a call.

   Ensure that we can find a mode to save the register and that there is a
   simple insn to save and restore the register.  This latter check avoids
   problems that would occur if we tried to save the MQ register of some
   machines directly into memory.   

References base_reg_class(), gen_rtx_MEM(), gen_rtx_REG(), HOST_BITS_PER_INT, offset, reg_save_code(), restinsn, restpat, saveinsn, savepat, test_mem, and test_reg.

Referenced by ira().

void init_save_areas ( void  )
Initialize save areas by showing that we haven't allocated any yet.   

References regno_save_mem, and save_slots_num.

Referenced by reload().

static void initiate_saved_hard_regs ( )
static
First called function for work with saved hard registers.   

Referenced by setup_save_areas().

static struct insn_chain* insert_one_insn ( struct insn_chain ,
int  ,
int  ,
rtx   
)
staticread
static int insert_restore ( struct insn_chain chain,
int  before_p,
int  regno,
int  maxrestore,
enum machine_mode *  save_mode 
)
static
Insert a sequence of insns to restore.  Place these insns in front of
   CHAIN if BEFORE_P is nonzero, behind the insn otherwise.  MAXRESTORE is
   the maximum number of registers which should be restored during this call.
   It should never be less than 1 since we only work with entire registers.

   Note that we have verified in init_caller_save that we can do this
   with a simple SET, so use it.  Set INSN_CODE to what we save there
   since the address might not be valid so the insn might not be recognized.
   These insns will be reloaded and have register elimination done by
   find_reload, so we need not worry about that here.

   Return the extra number of registers saved.   

References copy_rtx(), insn_chain::dead_or_set, gen_rtx_REG(), hard_regs_saved, insert_one_insn(), n_regs_saved, reg_restore_code(), reg_save_code(), and regno_save_mem.

Referenced by save_call_clobbered_regs().

static int insert_save ( struct insn_chain chain,
int  before_p,
int  regno,
HARD_REG_SET to_save,
enum machine_mode *  save_mode 
)
static
Like insert_restore above, but save registers instead.   

References copy_rtx(), insn_chain::dead_or_set, gen_rtx_REG(), hard_regs_saved, insert_one_insn(), n_regs_saved, reg_save_code(), and regno_save_mem.

Referenced by save_call_clobbered_regs().

static void mark_referenced_regs ( rtx ,
refmarker_fn mark,
void *  mark_arg 
)
static
static void mark_referenced_regs ( )
static
Walk X and record all referenced registers in REFERENCED_REGS.   

References mark_referenced_regs(), reg_renumber, and SET.

static void mark_reg_as_referenced ( rtx loc,
enum machine_mode  mode,
int  hardregno,
void *  arg 
)
static
Parameter function for mark_referenced_regs() that adds registers
   present in the insn and in equivalent mems and addresses to
   referenced_regs.   

References add_to_hard_reg_set(), and referenced_regs.

static void mark_set_regs ( rtx  ,
const_rtx  ,
void *   
)
static
static void mark_set_regs ( )
static
Here from note_stores, or directly from save_call_clobbered_regs, when
   an insn stores a value in a register.
   Set the proper bit or bits in this_insn_sets.  All pseudos that have
   been assigned hard regs have had their register number changed already,
   so we can ignore pseudos.   

References subreg_nregs(), and subreg_regno().

static void new_saved_hard_reg ( int  ,
int   
)
static

Referenced by setup_save_areas().

static void new_saved_hard_reg ( )
static
Allocate and return new saved hard register with given REGNO and
   CALL_FREQ.   

References saved_hard_reg::call_freq, saved_hard_reg::first_p, saved_hard_reg::hard_regno, saved_hard_reg::next, saved_hard_reg::num, and saved_regs_num.

static int reg_restore_code ( int  ,
enum  machine_mode 
)
static

Referenced by insert_restore().

static int reg_restore_code ( )
static
Return the INSN_CODE used to restore register REG in mode MODE.   

References reg_save_code().

static int reg_save_code ( int  ,
enum  machine_mode 
)
static
static int reg_save_code ( )
static
Return the INSN_CODE used to save register REG in mode MODE.   

References constrain_operands(), extract_insn(), and recog_memoized().

static void replace_reg_with_saved_mem ( rtx loc,
enum machine_mode  mode,
int  regno,
void *  arg 
)
static
Parameter function for mark_referenced_regs() that replaces
   registers referenced in a debug_insn that would have been restored,
   should it be a non-debug_insn, with their save locations.   

References copy_rtx(), gen_rtx_REG(), hard_regs_saved, offset, regno_save_mem, and rtvec_alloc().

static int saved_hard_reg_compare_func ( const void *  ,
const void *   
)
static

Referenced by setup_save_areas().

static int saved_hard_reg_compare_func ( )
static
The function is used to sort the saved hard register structures
   according their frequency.   

References saved_hard_reg::call_freq, and saved_hard_reg::num.

void setup_save_areas ( void  )
Allocate save areas for any hard registers that might need saving.
   We take a conservative approach here and look for call-clobbered hard
   registers that are assigned to pseudos that cross calls.  This may
   overestimate slightly (especially if some of these registers are later
   used as spill registers), but it should not be significant.

   For IRA we use priority coloring to decrease stack slots needed for
   saving hard registers through calls.  We build conflicts for them
   to do coloring.

   Future work:

     In the fallback case we should iterate backwards across all possible
     modes for the save, choosing the largest available one instead of
     falling back to the smallest mode immediately.  (eg TF -> DF -> SF).

     We do not try to use "move multiple" instructions that exist
     on some machines (such as the 68k moveml).  It could be a win to try
     and use them when possible.  The hard part is doing it in a way that is
     machine independent since they might be saving non-consecutive
     registers. (imagine caller-saving d0,d1,a0,a1 on the 68k)  

References assign_stack_local_1(), saved_hard_reg::call_freq, dump_file, find_reg_note(), finish_saved_hard_regs(), saved_hard_reg::first_p, free(), get_frame_alias_set(), saved_hard_reg::hard_regno, initiate_saved_hard_regs(), insn_chain::insn, insn_chain::live_throughout, mark_set_regs(), memcpy(), memset(), new_saved_hard_reg(), insn_chain::next, saved_hard_reg::next, note_stores(), saved_hard_reg::num, reg_renumber, regno_reg_rtx, regno_save_mem, reload_insn_chain, save_slots, save_slots_num, saved_hard_reg_compare_func(), saved_regs_num, set_mem_alias_set(), saved_hard_reg::slot, and used_regs.

Referenced by reload().


Variable Documentation

struct saved_hard_reg* all_saved_regs[FIRST_PSEUDO_REGISTER]
static
Pointers to all the structures.  Index is the order number of the
   corresponding structure.   
struct saved_hard_reg* hard_reg_map[FIRST_PSEUDO_REGISTER]
static
Map: hard register number to the corresponding structure.   
HARD_REG_SET hard_regs_saved
static
Set of hard regs currently residing in save area (during insn scan).   

Referenced by insert_restore(), insert_save(), replace_reg_with_saved_mem(), and save_call_clobbered_regs().

refmarker_fn mark_reg_as_referenced
static
int n_regs_saved
static
Number of registers currently in hard_regs_saved.   

Referenced by insert_restore(), insert_save(), and save_call_clobbered_regs().

HARD_REG_SET referenced_regs
static
Computed by mark_referenced_regs, all regs referenced in a given
   insn.   

Referenced by mark_reg_as_referenced(), and save_call_clobbered_regs().

rtx regno_save_mem[FIRST_PSEUDO_REGISTER][MAX_MOVE_MAX/MIN_UNITS_PER_WORD+1]
static
For each hard register, a place on the stack where it can be saved,
   if needed.   

Referenced by init_save_areas(), insert_restore(), insert_save(), replace_reg_with_saved_mem(), and setup_save_areas().

refmarker_fn replace_reg_with_saved_mem
static
rtx restinsn
static

Referenced by init_caller_save().

rtx restpat
static

Referenced by init_caller_save().

rtx save_slots[FIRST_PSEUDO_REGISTER]
static
Allocated slots so far.   

Referenced by setup_save_areas().

int save_slots_num
static
The number of elements in the subsequent array.   

Referenced by init_save_areas(), and setup_save_areas().

int saved_regs_num
static
The number of all structures representing hard registers should be
   saved, in order words, the number of used elements in the following
   array.   

Referenced by finish_saved_hard_regs(), new_saved_hard_reg(), and setup_save_areas().

rtx saveinsn
static

Referenced by init_caller_save().

rtx savepat
static

Referenced by init_caller_save().

rtx test_mem
static

Referenced by init_caller_save().

rtx test_reg
static

Referenced by init_caller_save().