GCC Middle and Back End API Reference
lra-spills.c File Reference

Data Structures

struct  pseudo_slot
struct  slot


static void assign_mem_slot ()
static int regno_freq_compare ()
static int pseudo_reg_slot_compare ()
static int assign_spill_hard_regs ()
static void add_pseudo_to_slot ()
static void assign_stack_slot_num_and_sort_pseudos ()
static void remove_pseudos ()
static void spill_pseudos ()
bool lra_need_for_spills_p ()
void lra_spill ()
static bool alter_subregs ()
void lra_final_code_change ()


static int regs_num
static rtxspill_hard_reg
static struct pseudo_slotpseudo_slots
static struct slotslots
static int slots_num

Function Documentation

static void add_pseudo_to_slot ( )
   Add pseudo REGNO to slot SLOT_NUM.  
         It is the first pseudo in the slot.  

References slot::hard_regno, slot::live_ranges, lra_intersected_live_ranges_p(), lra_reg_info, slot::mem, slot::regno, and slots_num.

static bool alter_subregs ( )
   Apply alter_subreg for subregs of regs in *LOC.  Use FINAL_P for
   alter_subreg calls. Return true if any subreg of reg is
static void assign_mem_slot ( )
   Set up memory of the spilled pseudo I.  The function can allocate
   the corresponding stack slot if it is not done yet.  
     We can use a slot already allocated because it is guaranteed the
     slot provides both enough inherent space and enough total
     Each pseudo has an inherent size which comes from its own mode,
     and a total size which provides room for paradoxical subregs
     which refer to the pseudo reg in wider modes.  We allocate a new
     slot, making sure that it has enough inherent space and total
         No known place to spill from => no slot to reuse.  
         Cancel the big-endian correction done in assign_stack_local.
         Get the address of the beginning of the slot.  This is so we
         can do a big-endian correction unconditionally below.  
     On a big endian machine, the "address" of the slot is the address
     of the low part that fits its inherent mode.  
     Set all of the memory attributes as appropriate for a spill.  

References assign_stack_local(), lra_eliminate_regs_1(), slot::mem, mode_for_size(), and pseudo_slot::slot_num.

static int assign_spill_hard_regs ( )
   Assign spill hard registers to N pseudos in PSEUDO_REGNOS which is
   sorted in order of highest frequency first.  Put the pseudos which
   did not get a spill hard register at the beginning of array
   PSEUDO_REGNOS.  Return the number of such pseudos.  
     Hard registers which can not be used for any purpose at given
     program point because they are unallocatable or already allocated
     for other pseudos.  
     Set up reserved hard regs for every program point.  
              There is no available regs -- assign memory later.  
         Update reserved_hard_regs.  
           Just loop.  

References targetm.

static void assign_stack_slot_num_and_sort_pseudos ( )
   Assign stack slot numbers to pseudos in array PSEUDO_REGNOS of
   length N.  Sort pseudos in PSEUDO_REGNOS for subsequent assigning
   memory stack slots.  
     Assign stack slot numbers to spilled pseudos, use smaller numbers
     for most frequently used pseudos.  
             New slot.  
     Sort regnos according to their slot numbers.  

References copy_rtx(), gdbhooks::GET_RTX_FORMAT(), gdbhooks::GET_RTX_LENGTH(), lra_former_scratch_p(), lra_get_regno_hard_regno(), pseudo_slot::mem, and remove_pseudos().

void lra_final_code_change ( void  )
   Final change of pseudos got hard registers into the corresponding
   hard registers and removing temporary clobbers.  
                 Remove clobbers temporarily created in LRA.  We don't
                 need them anymore and don't want to waste compiler
                 time processing them in a few subsequent passes.  
                 Remove an useless move insn but only involving
                 pseudos as some subsequent optimizations are based on
                 that move insns involving originally hard registers
                 are preserved.  IRA can generate move insns involving
                 pseudos.  It is better remove them earlier to speed
                 up compiler a bit.  It is also better to do it here
                 as they might not pass final RTL check in LRA,
                 (e.g. insn moving a control register into

References delete_insn(), and lra_invalidate_insn_data().

bool lra_need_for_spills_p ( void  )
   Return true if we need to change some pseudos into memory.  
void lra_spill ( void  )
   Change spilled pseudos into memory or spill hard regs.  Put changed
   insns on the constraint stack (these insns will be considered on
   the next constraint pass).  The changed insns are all insns in
   which pseudos were changed.  
           We do not want to assign memory for former scratches.  
     Sort regnos according their usage frequencies.  
       If we have a stack frame, we must align it now.  The stack size
       may be a part of the offset computation for register
static int pseudo_reg_slot_compare ( )
   Sort pseudos according to their slots, putting the slots in the order
   that they should be allocated.  Slots with lower numbers have the highest
   priority and should get the smallest displacement from the stack or
   frame pointer (whichever is being used).

   The first allocated slot is always closest to the frame pointer,
   so prefer lower slot numbers when frame_pointer_needed.  If the stack
   and frame grow in the same direction, then the first allocated slot is
   always closest to the initial stack pointer and furthest away from the
   final stack pointer, so allocate higher numbers first when using the
   stack pointer in that case.  The reverse is true if the stack and
   frame grow in opposite directions.  
static int regno_freq_compare ( )
   Sort pseudos according their usage frequencies.  

References lra_reg_info, and pseudo_slot::slot_num.

static void remove_pseudos ( )
   Recursively process LOC in INSN and change spilled pseudos to the
   corresponding memory or spilled hard reg.  Ignore spilled pseudos
   created from the scratches.  
         We do not want to assign memory for former scratches because
         it might result in an address reload for some targets.  In
         any case we transform such pseudos not getting hard registers
         into scratches back.  

References bitmap_bit_p(), bitmap_ior_into(), bitmap_set_bit(), lra_dump_file, lra_former_scratch_p(), lra_get_regno_hard_regno(), lra_push_insn(), lra_reg_info, lra_reg_spill_p, lra_set_used_insn_alternative(), reg_obstack, regs_num, spilled_pseudos, and targetm.

Referenced by assign_stack_slot_num_and_sort_pseudos().

static void spill_pseudos ( )
   Convert spilled pseudos into their stack slots or spill hard regs,
   put insns to process on the constraint stack (that is all insns in
   which pseudos were changed to memory or spill hard regs).   
             Presence of any pseudo in CALL_INSN_FUNCTION_USAGE does
             not affect value of insn_bitmap of the corresponding
             lra_reg_info.  That is because we don't need to reload
             pseudos in CALL_INSN_FUNCTION_USAGEs.  So if we process
             only insns in the insn_bitmap of given pseudo here, we
             can miss the pseudo in some

Variable Documentation

struct pseudo_slot* pseudo_slots
   The stack slots for each spilled pseudo.  Indexed by regnos.  
int regs_num

Change pseudos by memory. Copyright (C) 2010-2013 Free Software Foundation, Inc. Contributed by Vladimir Makarov vmaka.nosp@m.rov@.nosp@m.redha.nosp@m.t.co.nosp@m.m.

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.

GCC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with GCC; see the file COPYING3. If not see http://www.gnu.org/licenses/.

   This file contains code for a pass to change spilled pseudos into

   The pass creates necessary stack slots and assigns spilled pseudos
   to the stack slots in following way:

   for all spilled pseudos P most frequently used first do
     for all stack slots S do
       if P doesn't conflict with pseudos assigned to S then
         assign S to P and goto to the next pseudo process
     create new stack slot S and assign P to S

   The actual algorithm is bit more complicated because of different
   pseudo sizes.

   After that the code changes spilled pseudos (except ones created
   from scratches) by corresponding stack slot memory in RTL.

   If at least one stack slot was created, we need to run more passes
   because we have new addresses which should be checked and because
   the old address displacements might change and address constraints
   (or insn memory constraints) might not be satisfied any more.

   For some targets, the pass can spill some pseudos into hard
   registers of different class (usually into vector registers)
   instead of spilling them into memory if it is possible and
   profitable.  Spilling GENERAL_REGS pseudo into SSE registers for
   Intel Corei7 is an example of such optimization.  And this is
   actually recommended by Intel optimization guide.

   The file also contains code for final change of pseudos on hard
   regs correspondingly assigned to them.  
   Max regno at the start of the pass.  

Referenced by remove_pseudos().

struct slot* slots
   Array containing info about the stack slots.  The array element is
   indexed by the stack slot number in the range [0..slots_num).  

Referenced by pointer_map< T >::insert().

int slots_num
   The number of the stack slots currently existing.  

Referenced by add_pseudo_to_slot().

rtx* spill_hard_reg
   Map spilled regno -> hard regno used instead of memory for