GCC Middle and Back End API Reference
hw-doloop.c File Reference

Functions

static void dump_hwloops ()
static bool bb_in_loop_p ()
static void scan_loop ()
static bool process_incoming_edges ()
static bool add_forwarder_blocks ()
static void discover_loop ()
static hwloop_info discover_loops ()
static void free_loops ()
static void set_bb_indices ()
static void reorder_loops ()
static void optimize_loop ()
void reorg_loops ()

Function Documentation

static bool add_forwarder_blocks ( )
static
   Try to identify a forwarder block that jump into LOOP, and add it to
   the set of blocks in the loop, updating the vector of incoming blocks as
   well.  This transformation gives a second chance to loops we couldn't
   otherwise handle by increasing the chance that we'll end up with one
   incoming_src block.
   Return true if we made a change, false otherwise.  

References bitmap_set_bit(), hwloop_info_d::block_bitmap, hwloop_info_d::blocks, dump_file, forwarder_block_p(), hwloop_info_d::incoming, basic_block_def::index, edge_iterator::index, hwloop_info_d::loop_no, basic_block_def::preds, edge_def::src, and vec_safe_push().

static bool bb_in_loop_p ( )
static
   Return true if BB is part of LOOP.  

Referenced by scan_loop().

static void discover_loop ( )
static
   Called from reorg_loops when a potential loop end is found.  LOOP is
   a newly set up structure describing the loop, it is this function's
   responsibility to fill most of it.  TAIL_BB and TAIL_INSN point to the
   loop_end insn and its enclosing basic block.  REG is the loop counter
   register.
   For our purposes, a loop is defined by the set of blocks reachable from
   the loop head in which the loop counter register is live.  This matches
   the expected use; targets that call into this code usually replace the
   loop counter with a different special register.  
             We've reached the exit block.  The loop must be bad. 
         We've not seen this block before.  Add it to the loop's
         list and then add each successor to the work list.  
     Find the predecessor, and make sure nothing else jumps into this loop.  

Referenced by discover_loops().

static hwloop_info discover_loops ( )
static
   Analyze the structure of the loops in the current function.  Use
   LOOP_STACK for bitmap allocations.  Returns all the valid candidates for
   hardware loops found in this function.  HOOKS is the argument
   passed to reorg_loops, used here to find the iteration registers
   from a loop_end pattern.  
     Find all the possible loop tails.  This means searching for every
     loop_end instruction.  For each one found, create a hwloop_info
     structure and add the head block to the work list. 
         A possible loop end 
         There's a degenerate case we can handle - an empty loop consisting
         of only a back branch.  Handle that by deleting the branch.  
     Compute loop nestings.  Given two loops A and B, either the sets
     of their blocks don't intersect at all, or one is the subset of
     the other, or the blocks don't form a good nesting structure.  

References hwloop_info_d::block_bitmap, hwloop_info_d::blocks, delete_insn_and_edges(), df_get_live_in(), discover_loop(), dump_file, hw_doloop_hooks::end_pattern_reg, hwloop_info_d::loop_no, hwloop_info_d::next, and print_rtl_single().

static void dump_hwloops ( )
static
@verbatim 

Code to analyze doloop loops in order for targets to perform late optimizations converting doloops to other forms of hardware loops. Copyright (C) 2011-2013 Free Software Foundation, Inc.

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/.

   Dump information collected in LOOPS.  

References hwloop_info_d::bad, hwloop_info_d::blocks, hwloop_info_d::depth, dump_file, hwloop_info_d::head, basic_block_def::index, hwloop_info_d::iter_reg, hwloop_info_d::loop_no, and hwloop_info_d::loops.

static void free_loops ( )
static
   Free up the loop structures in LOOPS.  

References basic_block_def::aux.

static void optimize_loop ( )
static
   Call the OPT function for LOOP and all of its sub-loops.  This is
   done in a depth-first search; innermost loops are visited first.
   OPTIMIZE and FAIL are the functions passed to reorg_loops by the
   target's reorg pass.  
     Every loop contains in its list of inner loops every loop nested inside
     it, even if there are intermediate loops.  This works because we're doing
     a depth-first search here and never visit a loop more than once.
     Recursion depth is effectively limited by the number of available
     hardware registers.  
         The set of registers may be changed while optimizing the inner
         loop.  

References hwloop_info_d::bad, hwloop_info_d::depth, and hwloop_info_d::regs_set_in_loop.

static bool process_incoming_edges ( )
static
   Compute the incoming_dest and incoming_src members of LOOP by
   identifying the edges that jump into the loop.  If there is more
   than one block that jumps into the loop, incoming_src will be set
   to NULL; likewise, if there is more than one block in the loop that
   is the destination of an incoming edge, incoming_dest will be NULL.

   Return true if either of these two fields is nonnull, false
   otherwise.  

References edge_def::dest, hwloop_info_d::incoming_dest, hwloop_info_d::incoming_src, and edge_def::src.

static void reorder_loops ( )
static
   The taken-branch edge from the loop end can actually go forward.
   If the target's hardware loop support requires that the loop end be
   after the loop start, try to reorder a loop's basic blocks when we
   find such a case.
   This is not very aggressive; it only moves at most one block.  It
   does not introduce new branches into loops; it may remove them, or
   it may switch fallthru/jump edges.  

References bitmap_bit_p(), hwloop_info_d::block_bitmap, edge_def::dest, dump_file, hwloop_info_d::head, basic_block_def::index, basic_block_def::next_bb, basic_block_def::prev_bb, set_bb_indices(), and hwloop_info_d::tail.

void reorg_loops ( )
   This function can be used from a port's machine_dependent_reorg to
   find and analyze loops that end in loop_end instructions.  It uses
   a set of function pointers in HOOKS to call back into the
   target-specific functions to perform the actual machine-specific
   transformations.

   Such transformations typically involve additional set-up
   instructions before the loop, to define loop bounds or set up a
   special loop counter register.

   DO_REORDER should be set to true if we should try to use the
   reorder_loops function to ensure the loop end occurs after the loop
   start.  This is for use by targets where the loop hardware requires
   this condition.

   HOOKS is used to pass in target specific hooks; see
   hw-doloop.h.  
     Now apply the optimizations.  
static void set_bb_indices ( )
static
   Initialize the aux fields to give ascending indices to basic blocks.  

References hwloop_info_d::bad, cfg_layout_initialize(), hwloop_info_d::head, hwloop_info_d::next, and hwloop_info_d::tail.

Referenced by reorder_loops().