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

Data Structures

struct  elim_table
struct  elim_table_1

Functions

static void print_elim_table ()
void lra_debug_elim_table ()
static void setup_can_eliminate ()
static void setup_elimination_map ()
static rtx form_sum ()
int lra_get_elimination_hard_regno ()
static struct elim_tableget_elimination ()
rtx lra_eliminate_regs_1 (rtx x, enum machine_mode mem_mode, bool subst_p, bool update_p, bool full_p)
rtx lra_eliminate_regs (rtx x, enum machine_mode mem_mode, rtx insn)
static void mark_not_eliminable ()
static rtx remove_reg_equal_offset_note ()
static void eliminate_regs_in_insn ()
static void spill_pseudos ()
static bool update_reg_eliminate ()
static void init_elim_table ()
void lra_init_elimination ()
void lra_eliminate_reg_if_possible ()
static void process_insn_for_elimination ()
void lra_eliminate ()

Variables

static struct elim_tablereg_eliminate = 0
static struct elim_table_1 reg_eliminate_1 []
static struct elim_tableelimination_map [FIRST_PSEUDO_REGISTER]
static struct elim_table self_elim_table
static HOST_WIDE_INT self_elim_offsets [FIRST_PSEUDO_REGISTER]
static rtx eliminable_reg_rtx [FIRST_PSEUDO_REGISTER]

Function Documentation

static void eliminate_regs_in_insn ( )
static
   Scan INSN and eliminate all eliminable hard registers in it.

   If REPLACE_P is true, do the replacement destructively.  Also
   delete the insn as dead it if it is setting an eliminable register.

   If REPLACE_P is false, just update the offsets while keeping the
   base register the same.  Attach the note about used elimination for
   insns setting frame pointer to update elimination easy (without
   parsing already generated elimination insns to find offset
   previously used) in future.  
     Check for setting an eliminable register.  
                 If this is setting the frame pointer register to the
                 hardware frame pointer register and this is an
                 elimination that will be done (tested above), this
                 insn is really adjusting the frame pointer downward
                 to compensate for the adjustment done before a
                 nonlocal goto.  
                       First see if this insn remains valid when we
                       make the change.  If not, keep the INSN_CODE
                       the same and let the constraint pass fit it
                       up.  
                       Add offset note for future updates.  
               This insn isn't serving a useful purpose.  We delete it
               when REPLACE is set.  
     We allow one special case which happens to work on all machines we
     currently support: a single set with the source or a REG_EQUAL
     note being a PLUS of an eliminable register and a constant.  
         First see if the source is of the form (plus (...) CST).  
         Check that the first operand of the PLUS is a hard reg or
         the lowpart subreg of one.  
             If we have a nonzero offset, and the source is already a
             simple REG, the following transformation would increase
             the cost of the insn by replacing a simple REG with (plus
             (reg sp) CST).  So try only when we already had a PLUS
             before.  
                 First see if this insn remains valid when we make the
                 change.  If not, try to replace the whole pattern
                 with a simple set (this may help if the original insn
                 was a PARALLEL that was only recognized as single_set
                 due to REG_UNUSED notes).  If this isn't valid
                 either, keep the INSN_CODE the same and let the
                 constraint pass fix it up.  
                 This can't have an effect on elimination offsets, so skip
                 right to the end.  
     Eliminate all eliminable registers occurring in operands that
     can be handled by the constraint pass.  
         For an asm statement, every operand is eliminable.  
             Check for setting a hard register that we know about.  
                 If we are assigning to a hard register that can be
                 eliminated, it must be as part of a PARALLEL, since
                 the code above handles single SETs.  This reg can not
                 be longer eliminated -- it is forced by
                 mark_not_eliminable.  
             Companion to the above plus substitution, we can allow
             invariants as the source of a plain move.  
     Substitute the operands; the new values are in the substed_operand
     array.  
     If we had a move insn but now we don't, re-recognize it.
     This will cause spurious re-recognition if the old move had a
     PARALLEL since the new one still will, but we can't call
     single_set without having put new body into the insn and the
     re-recognition won't hurt in this rare case.  

Referenced by init_elim_table(), maybe_fix_stack_asms(), and spill_hard_reg().

static rtx form_sum ( )
static
   Compute the sum of X and Y, making canonicalizations assumed in an
   address, namely: sum constant integers, surround the sum of two
   constants with a CONST, put the constant as the second operand, and
   group the constant on the outermost sum.

   This routine assumes both inputs are already in canonical form.  
     Note that if the operands of Y are specified in the opposite
     order in the recursive calls below, infinite recursion will
     occur.  
     If both constant, encapsulate sum.  Otherwise, just form sum.  A
     constant will have been placed second.  

Referenced by set_label_offsets(), and setup_elimination_map().

static struct elim_table* get_elimination ( )
staticread
   Return elimination which will be used for hard reg REG, NULL
   otherwise.  
     This is an iteration to restore offsets just after HARD_REGNO
     stopped to be eliminable.  

References current_function_decl.

static void init_elim_table ( void  )
static
   Initialize the table of hard registers to eliminate.
   Pre-condition: global flag frame_pointer_needed has been set before
   calling this function.  
     Initiate member values which will be never changed.  
     Count the number of eliminable registers and build the FROM and TO
     REG rtx's.  Note that code in gen_rtx_REG will cause, e.g.,
     gen_rtx_REG (Pmode, STACK_POINTER_REGNUM) to equal stack_pointer_rtx.
     We depend on this.  

References eliminate_regs_in_insn(), lra_push_insn(), lra_set_used_insn_alternative(), lra_update_insn_recog_data(), lra_update_insn_regno_info(), and recog().

void lra_debug_elim_table ( void  )
   Print info about elimination table to stderr.  
void lra_eliminate ( )
   Entry function to do final elimination if FINAL_P or to update
   elimination register offsets.  
         We change eliminable hard registers in insns so we should do
         this for all insns containing any eliminable hard
         register.  
       A dead insn can be deleted in process_insn_for_elimination.  
void lra_eliminate_reg_if_possible ( )
   Eliminate hard reg given by its location LOC.  
rtx lra_eliminate_regs ( rtx  x,
enum machine_mode  mem_mode,
rtx  insn 
)
   This function is used externally in subsequent passes of GCC.  It
   always does a full elimination of X.  
rtx lra_eliminate_regs_1 ( rtx  x,
enum machine_mode  mem_mode,
bool  subst_p,
bool  update_p,
bool  full_p 
)
   Scan X and replace any eliminable registers (such as fp) with a
   replacement (such as sp) if SUBST_P, plus an offset.  The offset is
   a change in the offset between the eliminable register and its
   substitution if UPDATE_P, or the full offset if FULL_P, or
   otherwise zero.

   MEM_MODE is the mode of an enclosing MEM.  We need this to know how
   much to adjust a register for, e.g., PRE_DEC.  Also, if we are
   inside a MEM, we are allowed to replace a sum of a hard register
   and the constant zero with the hard register, which we cannot do
   outside a MEM.  In addition, we need to record the fact that a
   hard register is referenced outside a MEM.

   Alternatively, INSN may be a note (an EXPR_LIST or INSN_LIST).
   That's used when we eliminate in expressions stored in notes.  
         First handle the case where we encounter a bare hard register
         that is eliminable.  Replace it with a PLUS.  
         If this is the sum of an eliminable register and a constant, rework
         the sum.  
             If the hard register is not eliminable, we are done since
             the other operand is a constant.  
         If this is part of an address, we want to bring any constant
         to the outermost PLUS.  We will do this by doing hard
         register replacement in our operands and seeing if a constant
         shows up in one of them.

         Note that there is no risk of modifying the structure of the
         insn, since we only get called for its operands, thus we are
         either modifying the address inside a MEM, or something like
         an address operand of a load-address insn.  
         If this is the product of an eliminable hard register and a
         constant, apply the distribute law and move the constant out
         so that we have (plus (mult ..) ..).  This is needed in order
         to keep load-address insns valid.  This case is pathological.
         We ignore the possibility of overflow here.  
         ... fall through ...  
       See comments before PLUS about handling MINUS.  
         If we have something in XEXP (x, 0), the usual case,
         eliminate it.  
                 If this is a REG_DEAD note, it is not valid anymore.
                 Using the eliminated version could result in creating a
                 REG_DEAD note for the stack or frame pointer.  
         ... fall through ...  
         Now do eliminations in the rest of the chain.  If this was
         an EXPR_LIST, this might result in allocating more memory than is
         strictly needed, but it simplifies the code.  
         We do not support elimination of a register that is modified.
         elimination_effects has already make sure that this does not
         happen.  
         We do not support elimination of a hard register that is
         modified.  LRA has already make sure that this does not
         happen. The only remaining case we need to consider here is
         that the increment value may be an eliminable register.  
         Our only special processing is to pass the mode of the MEM to our
         recursive call and copy the flags.  While we are here, handle this
         case more efficiently.  
         Handle insn_list USE that a call to a pure function may generate.  
     Process each of our operands recursively.  If any have changed, make a
     copy of the rtx.  

References elim_table::from_rtx, elim_table::offset, plus_constant(), elim_table::previous_offset, elim_table::to, and elim_table::to_rtx.

Referenced by assign_mem_slot().

int lra_get_elimination_hard_regno ( )
   Return the current substitution hard register of the elimination of
   HARD_REGNO.  If HARD_REGNO is not eliminable, return itself.  
void lra_init_elimination ( void  )
   Entry function for initialization of elimination once per
   function.  

References lra_dump_file, and print_elim_table().

static void mark_not_eliminable ( )
static
   Scan rtx X for references to elimination source or target registers
   in contexts that would prevent the elimination from happening.
   Update the table of eliminables to reflect the changed state.
   MEM_MODE is the mode of an enclosing MEM rtx, or VOIDmode if not
   within a MEM.  
           If we modify the source of an elimination rule, disable
           it.  Do the same if it is the source and not the hard frame
           register.  
           If using a hard register that is the source of an eliminate
           we still think can be performed, note it cannot be
           performed since we don't know how this hard register is
           used.  
           If clobbering a hard register that is the replacement
           register for an elimination we still think can be
           performed, note that it cannot be performed.  Otherwise, we
           need not be concerned about it.  
         Check for setting a hard register that we know about.  
             See if this is setting the replacement hard register for
             an elimination.

             If DEST is the hard frame pointer, we do nothing because
             we assume that all assignments to the frame pointer are
             for non-local gotos and are being done at a time when
             they are valid and do not disturb anything else.  Some
             machines want to eliminate a fake argument pointer (or
             even a fake frame pointer) with either the real frame
             pointer or the stack pointer.  Assignments to the hard
             frame pointer must not prevent this elimination.  
static void print_elim_table ( )
static
   Print info about elimination table to file F.  

Referenced by lra_init_elimination().

static void process_insn_for_elimination ( )
static
   Do (final if FINAL_P) elimination in INSN.  Add the insn for
   subsequent processing in the constraint pass, update the insn info.  
         Check that insn changed its code.  This is a case when a move
         insn becomes an add insn and we do not want to process the
         insn as a move anymore.  
static rtx remove_reg_equal_offset_note ( )
static
   Find offset equivalence note for reg WHAT in INSN and return the
   found elmination offset.  If the note is not found, return NULL.
   Remove the found note.  

References elim_table::can_eliminate, elim_table::from, elim_table::from_rtx, HOST_WIDE_INT, offset, elim_table::to, and elim_table::to_rtx.

static void setup_can_eliminate ( )
static
   Setup possibility of elimination in elimination table element EP to
   VALUE.  Setup FRAME_POINTER_NEEDED if elimination from frame
   pointer to stack pointer is not possible anymore.  
static void setup_elimination_map ( )
static
   Set up ELIMINATION_MAP of the currently used eliminations.  

References form_sum(), and plus_constant().

static void spill_pseudos ( )
static
   Spill pseudos which are assigned to hard registers in SET.  Add
   affected insns for processing in the subsequent constraint
   pass.  

References bitmap_ior_into(), elim_table::can_eliminate, elim_table::from, lra_reg::insn_bitmap, lra_dump_file, lra_reg_info, elim_table::offset, elim_table::previous_offset, and elim_table::to.

static bool update_reg_eliminate ( )
static
   Update all offsets and possibility for elimination on eliminable
   registers.  Spill pseudos assigned to registers which became
   uneliminable, update LRA_NO_ALLOC_REGS and ELIMINABLE_REG_SET.  Add
   insns to INSNS_WITH_CHANGED_OFFSETS containing eliminable hard
   registers whose offsets should be changed.  Return true if any
   elimination offset changed.  
     Clear self elimination offsets.  
         If it is a currently used elimination: update the previous
         offset.  
             It is possible that not eliminable register becomes
             eliminable because we took other reasons into account to
             set up eliminable regs in the initial set up.  Just
             ignore new eliminable registers.  
             We cannot use this elimination anymore -- find another
             one.  
             Mark that is not eliminable anymore.  
                 Prevent the hard register into which we eliminate now
                 from the usage for pseudos.  
                 There is no elimination anymore just use the hard
                 register `from' itself.  Setup self elimination
                 offset to restore the original offset values.  
           Update offset when the eliminate offset have been
           changed.  

Variable Documentation

rtx eliminable_reg_rtx[FIRST_PSEUDO_REGISTER]
static
   Map: hard regno -> RTL presentation.  RTL presentations of all
   potentially eliminable hard registers are stored in the map.  
struct elim_table* elimination_map[FIRST_PSEUDO_REGISTER]
static
   Map: eliminable "from" register -> its current elimination,
   or NULL if none.  The elimination table may contain more than
   one elimination for the same hard register, but this map specifies
   the one that we are currently using.  
struct elim_table* reg_eliminate = 0
static
   The elimination table.  Each array entry describes one possible way
   of eliminating a register in favor of another.  If there is more
   than one way of eliminating a particular register, the most
   preferred should be specified first.  
struct elim_table_1 reg_eliminate_1[]
static
HOST_WIDE_INT self_elim_offsets[FIRST_PSEUDO_REGISTER]
static
   Offsets should be used to restore original offsets for eliminable
   hard register which just became not eliminable.  Zero,
   otherwise.  
struct elim_table self_elim_table
static
   When an eliminable hard register becomes not eliminable, we use the
   following special structure to restore original offsets for the
   register.