GCC Middle and Back End API Reference
lra-spills.cc File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "backend.h"
#include "target.h"
#include "rtl.h"
#include "df.h"
#include "insn-config.h"
#include "regs.h"
#include "memmodel.h"
#include "ira.h"
#include "recog.h"
#include "output.h"
#include "cfgrtl.h"
#include "lra.h"
#include "lra-int.h"
Include dependency graph for lra-spills.cc:

Data Structures

struct  pseudo_slot
class  slot


static void assign_mem_slot (int i)
static int regno_freq_compare (const void *v1p, const void *v2p)
static int pseudo_reg_slot_compare (const void *v1p, const void *v2p)
static int assign_spill_hard_regs (int *pseudo_regnos, int n)
static void add_pseudo_to_slot (int regno, int slot_num)
static void assign_stack_slot_num_and_sort_pseudos (int *pseudo_regnos, int n)
static bool remove_pseudos (rtx *loc, rtx_insn *insn)
static void spill_pseudos (void)
bool lra_need_for_scratch_reg_p (void)
bool lra_need_for_spills_p (void)
void lra_spill (void)
static bool alter_subregs (rtx *loc, bool final_p)
void lra_final_code_change (void)


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

Function Documentation

◆ add_pseudo_to_slot()

◆ alter_subregs()

static bool alter_subregs ( rtx * loc,
bool final_p )
Apply alter_subreg for subregs of regs in *LOC.  Use FINAL_P for
alter_subreg calls. Return true if any subreg of reg is

References alter_subreg(), alter_subregs(), GET_CODE, GET_RTX_FORMAT, GET_RTX_LENGTH, ggc_alloc(), i, lra_assert, NULL_RTX, REG_P, REGNO, SUBREG_REG, XEXP, XVECEXP, and XVECLEN.

Referenced by alter_subregs(), and lra_final_code_change().

◆ assign_mem_slot()

static void assign_mem_slot ( int i)

◆ assign_spill_hard_regs()

◆ assign_stack_slot_num_and_sort_pseudos()

static void assign_stack_slot_num_and_sort_pseudos ( int * pseudo_regnos,
int n )
Assign stack slot numbers to pseudos in array PSEUDO_REGNOS of
length N.  Sort pseudos in PSEUDO_REGNOS for subsequent assigning
memory stack slots.      

References add_pseudo_to_slot(), slot::align, GET_MODE_SIZE(), ggc_alloc(), slot::hard_regno, i, slot::live_ranges, lra_intersected_live_ranges_p(), lra_reg_info, slot::mem, NULL, NULL_RTX, pseudo_reg_slot_compare(), PSEUDO_REGNO_MODE, qsort, slot::regno, slot::size, slots, slots_num, and wider_subreg_mode().

Referenced by lra_spill().

◆ lra_final_code_change()

◆ lra_need_for_scratch_reg_p()

bool lra_need_for_scratch_reg_p ( void )
Return true if we need scratch reg assignments.   

References ggc_alloc(), i, ira_former_scratch_p(), lra_get_regno_hard_regno(), lra_reg_info, max_reg_num(), and max_regno.

Referenced by lra().

◆ lra_need_for_spills_p()

bool lra_need_for_spills_p ( void )
Return true if we need to change some pseudos into memory.   

References ggc_alloc(), i, ira_former_scratch_p(), lra_get_regno_hard_regno(), lra_reg_info, max_reg_num(), and max_regno.

Referenced by lra().

◆ lra_spill()

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.   

References assign_mem_slot(), assign_spill_hard_regs(), assign_stack_local(), assign_stack_slot_num_and_sort_pseudos(), crtl, free(), GET_MODE, GET_MODE_SIZE(), ggc_alloc(), i, ira_former_scratch_p(), lra_assert, lra_dump_file, lra_get_regno_hard_regno(), lra_reg_info, lra_update_fp2sp_elimination(), max_reg_num(), pseudo_slot::mem, pseudo_slot::next, NULL, NULL_RTX, print_dec(), pseudo_slots, qsort, regno_freq_compare(), regs_num, SIGNED, slots, slots_num, spill_hard_reg, and spill_pseudos().

Referenced by lra().

◆ pseudo_reg_slot_compare()

static int pseudo_reg_slot_compare ( const void * v1p,
const void * v2p )
Sort pseudos according to their slots, putting the slots in the order
that they should be allocated.

First prefer to group slots with variable sizes together and slots
with constant sizes together, since that usually makes them easier
to address from a common anchor point.  E.g. loads of polynomial-sized
registers tend to take polynomial offsets while loads of constant-sized
registers tend to take constant (non-polynomial) offsets.

Next, 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.   

References FRAME_GROWS_DOWNWARD, frame_pointer_needed, GET_MODE_SIZE(), ggc_alloc(), poly_int< N, C >::is_constant(), lra_reg_info, pseudo_slots, slot::size, pseudo_slot::slot_num, slots, and STACK_GROWS_DOWNWARD.

Referenced by assign_stack_slot_num_and_sort_pseudos().

◆ regno_freq_compare()

static int regno_freq_compare ( const void * v1p,
const void * v2p )
Sort pseudos according their usage frequencies.   

References ggc_alloc(), and lra_reg_info.

Referenced by lra_spill().

◆ remove_pseudos()

static bool remove_pseudos ( rtx * loc,
rtx_insn * insn )
Recursively process LOC in INSN and change spilled pseudos to the
corresponding memory or spilled hard reg.  Ignore spilled pseudos
created from the scratches.  Return true if the pseudo nrefs equal
to 0 (don't change the pseudo in this case).  Otherwise return false.   

References alter_subreg(), copy_rtx(), GET_CODE, GET_MODE, GET_RTX_FORMAT, GET_RTX_LENGTH, ggc_alloc(), i, INSN_UID(), ira_former_scratch_p(), lra_dump_file, lra_eliminate_regs_1(), lra_get_regno_hard_regno(), lra_reg_info, lra_update_insn_recog_data(), pseudo_slot::mem, NULL, NULL_RTX, pseudo_slots, REG_P, REGNO, remove_pseudos(), spill_hard_reg, SUBREG_REG, XEXP, XVECEXP, and XVECLEN.

Referenced by lra_undo_inheritance(), remove_inheritance_pseudos(), remove_pseudos(), and spill_pseudos().

◆ spill_pseudos()

Variable Documentation

◆ pseudo_slots

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

Referenced by add_pseudo_to_slot(), assign_mem_slot(), lra_spill(), pseudo_reg_slot_compare(), and remove_pseudos().

◆ regs_num

int regs_num
Change pseudos by memory.
   Copyright (C) 2010-2024 Free Software Foundation, Inc.
   Contributed by Vladimir Makarov <vmakarov@redhat.com>.

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

GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
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
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 assign_spill_hard_regs(), lra_spill(), and spill_pseudos().

◆ slots

class 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 add_pseudo_to_slot(), assign_mem_slot(), assign_stack_slot_num_and_sort_pseudos(), lra_spill(), make_return_insns(), and pseudo_reg_slot_compare().

◆ slots_num

int slots_num
The number of the stack slots currently existing.   

Referenced by assign_stack_slot_num_and_sort_pseudos(), and lra_spill().

◆ spill_hard_reg

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

Referenced by assign_spill_hard_regs(), lra_spill(), reload(), remove_pseudos(), and update_eliminables_and_spill().