GCC Middle and Back End API Reference
combine-stack-adj.c File Reference

Data Structures

struct  csa_reflist
struct  record_stack_refs_data

Functions

static int stack_memref_p (rtx)
static rtx single_set_for_csa (rtx)
static void free_csa_reflist (struct csa_reflist *)
static struct csa_reflistrecord_one_stack_ref (rtx, rtx *, struct csa_reflist *)
static int try_apply_stack_adjustment (rtx, struct csa_reflist *, HOST_WIDE_INT, HOST_WIDE_INT)
static void combine_stack_adjustments_for_block (basic_block)
static int record_stack_refs (rtx *, void *)
static void combine_stack_adjustments ()
static int stack_memref_p ()
static rtx single_set_for_csa ()
static void free_csa_reflist ()
static struct csa_reflistrecord_one_stack_ref ()
static int record_stack_refs ()
static void maybe_move_args_size_note ()
static rtx prev_active_insn_bb ()
static rtx next_active_insn_bb ()
static void force_move_args_size_note ()
static void combine_stack_adjustments_for_block ()
static bool gate_handle_stack_adjustments ()
static unsigned int rest_of_handle_stack_adjustments ()
rtl_opt_passmake_pass_stack_adjustments ()

Function Documentation

static void combine_stack_adjustments ( )
static
   Main entry point for stack adjustment combination.  
static void combine_stack_adjustments_for_block ( basic_block  )
static
static void combine_stack_adjustments_for_block ( )
static
   Subroutine of combine_stack_adjustments, called for each basic block.  
             Find constant additions to the stack pointer.  
                 If we've not seen an adjustment previously, record
                 it now and continue.  
                 If not all recorded refs can be adjusted, or the
                 adjustment is now too large for a constant addition,
                 we cannot merge the two stack adjustments.

                 Also we need to be careful to not move stack pointer
                 such that we create stack accesses outside the allocated
                 area.  We can combine an allocation into the first insn,
                 or a deallocation into the second insn.  We can not
                 combine an allocation followed by a deallocation.

                 The only somewhat frequent occurrence of the later is when
                 a function allocates a stack frame but does not use it.
                 For this case, we would need to analyze rtl stream to be
                 sure that allocated area is really unused.  This means not
                 only checking the memory references, but also all registers
                 or global memory references possibly containing a stack
                 frame address.

                 Perhaps the best way to address this problem is to teach
                 gcc not to allocate stack for objects never used.  
                 Combine an allocation into the first instruction.  
                         It worked!  
                 Otherwise we have a deallocation.  Do not combine with
                 a previous allocation.  Combine into the second insn.  
                         It worked!  
                 Combination failed.  Restart processing from here.  If
                 deallocation+allocation conspired to cancel, we can
                 delete the old deallocation insn.  
             Find a store with pre-(dec|inc)rement or pre-modify of exactly
             the previous adjustment and turn it into a simple store.  This
             is equivalent to anticipating the stack adjustment so this must
             be an allocation.  
         Otherwise, we were not able to process the instruction.
         Do not continue collecting data across such a one.  

References record_stack_refs_data::insn.

static void force_move_args_size_note ( )
static
   If INSN has a REG_ARGS_SIZE note, if possible move it to PREV.  Otherwise
   search for a nearby candidate within BB where we can stick the note.  
     If PREV exists, tail-call to the logic in the other function.  
     First, make sure there's anything that needs doing.  
     We need to find a spot between the previous and next exception points
     where we can place the note and "properly" deallocate the arguments.  
     It is often the case that we have insns in the order:
        call
        add sp (previous deallocation)
        sub sp (align for next arglist)
        push arg
     and the add/sub cancel.  Therefore we begin by searching forward.  
         Found an existing note: nothing to do.  
         Found something that affects unwinding.  Stop searching.  
         Found a place that seems logical to adjust the stack.  
         Found something that affects unwinding.  Stop searching.  
         ??? We *must* have a place, lest we ICE on the lost adjustment.
         Options are: dummy clobber insn, nop, or prevent the removal of
         the sp += 0 insn.  
         TODO: Find another way to indicate to the dwarf2 code that we
         have not in fact lost an adjustment.  

References find_reg_note(), and insn_nothrow_p().

static void free_csa_reflist ( struct csa_reflist )
static
static void free_csa_reflist ( )
static
   Free the list of csa_reflist nodes.  

References csa_reflist::sp_offset.

static bool gate_handle_stack_adjustments ( )
static
     This is kind of a heuristic.  We need to run combine_stack_adjustments
     even for machines with possibly nonzero TARGET_RETURN_POPS_ARGS
     and ACCUMULATE_OUTGOING_ARGS.  We expect that only ports having
     push instructions will have popping returns.  
rtl_opt_pass* make_pass_stack_adjustments ( )
static void maybe_move_args_size_note ( )
static
   If INSN has a REG_ARGS_SIZE note, move it to LAST.
   AFTER is true iff LAST follows INSN in the instruction stream.  
         The ARGS_SIZE notes are *not* cumulative.  They represent an
         absolute value, and the "most recent" note wins.  

Referenced by next_active_insn_bb().

static rtx next_active_insn_bb ( )
static
static rtx prev_active_insn_bb ( )
static
   Return the next (or previous) active insn within BB.  
static struct csa_reflist* record_one_stack_ref ( rtx  ,
rtx ,
struct csa_reflist  
)
staticread

Referenced by record_stack_refs().

static struct csa_reflist* record_one_stack_ref ( )
staticread
   Create a new csa_reflist node from the given stack reference.
   It is already known that the reference is either a MEM satisfying the
   predicate stack_memref_p or a REG representing the stack pointer.  
static int record_stack_refs ( rtx ,
void *   
)
static
static int record_stack_refs ( )
static
         We are not able to handle correctly all possible memrefs containing
         stack pointer, so this check is necessary.  
         Try harder for DEBUG_INSNs, handle e.g. (mem (mem (sp + 16) + 4).  
         ??? We want be able to handle non-memory stack pointer
         references later.  For now just discard all insns referring to
         stack pointer outside mem expressions.  We would probably
         want to teach validate_replace to simplify expressions first.

         We can't just compare with STACK_POINTER_RTX because the
         reference to the stack pointer might be in some other mode.
         In particular, an explicit clobber in an asm statement will
         result in a QImode clobber.

         In DEBUG_INSNs, we want to replace all occurrences, otherwise
         they will cause -fcompare-debug failures.  

References record_stack_refs_data::insn, record_one_stack_ref(), and record_stack_refs_data::reflist.

static unsigned int rest_of_handle_stack_adjustments ( )
static
static rtx single_set_for_csa ( rtx  )
static
static rtx single_set_for_csa ( )
static
   Recognize either normal single_set or the hack in i386.md for
   tying fp and sp adjustments.  
         The special case is allowing a no-op set.  
static int stack_memref_p ( rtx  )
static
static int stack_memref_p ( )
static
   Recognize a MEM of the form (sp) or (plus sp const).  
static int try_apply_stack_adjustment ( rtx  insn,
struct csa_reflist reflist,
HOST_WIDE_INT  new_adjust,
HOST_WIDE_INT  delta 
)
static
   Attempt to apply ADJUST to the stack adjusting insn INSN, as well
   as each of the memories and stack references in REFLIST.  Return true
   on success.  
         Succeeded.  Update our knowledge of the stack references.