GCC Middle and Back End API Reference
loop-unswitch.c File Reference

Functions

static struct loopunswitch_loop (struct loop *, basic_block, rtx, rtx)
static bool unswitch_single_loop (struct loop *, rtx, int)
static rtx may_unswitch_on (basic_block, struct loop *, rtx *)
rtx compare_and_jump_seq (rtx op0, rtx op1, enum rtx_code comp, rtx label, int prob, rtx cinsn)
void unswitch_loops ()
static rtx may_unswitch_on ()
rtx reversed_condition ()
static bool unswitch_single_loop ()
static struct loopunswitch_loop ()

Function Documentation

rtx compare_and_jump_seq ( rtx  op0,
rtx  op1,
enum rtx_code  comp,
rtx  label,
int  prob,
rtx  cinsn 
)
   Prepare a sequence comparing OP0 with OP1 using COMP and jumping to LABEL if
   true, with probability PROB.  If CINSN is not NULL, it is the insn to copy
   in order to create a jump.  
         A hack -- there seems to be no easy generic way how to make a
         conditional jump from a ccmode comparison.  
static rtx may_unswitch_on ( basic_block  ,
struct loop ,
rtx  
)
static
static rtx may_unswitch_on ( )
static
   Checks whether we can unswitch LOOP on condition at end of BB -- one of its
   basic blocks (for what it means see comments below).  In case condition
   compares loop invariant cc mode register, return the jump in CINSN.  
     BB must end in a simple conditional jump.  
     With branches inside loop.  
     It must be executed just once each iteration (because otherwise we
     are unable to update dominator/irreducible loop information correctly).  
     Condition must be invariant.  
rtx reversed_condition ( )
   Reverses CONDition; returns NULL if we cannot.  

References dump_file, and HOST_WIDE_INT.

Referenced by canon_condition().

static struct loop* unswitch_loop ( struct loop ,
basic_block  ,
rtx  ,
rtx   
)
staticread
@verbatim 

Loop unswitching for GNU compiler. Copyright (C) 2002-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/.

   This pass moves constant conditions out of loops, duplicating the loop
   in progress, i.e. this code:

   while (loop_cond)
     {
       A;
       if (cond)
         branch1;
       else
         branch2;
       B;
       if (cond)
         branch3;
       C;
     }
   where nothing inside the loop alters cond is transformed
   into

   if (cond)
     {
       while (loop_cond)
         {
           A;
           branch1;
           B;
           branch3;
           C;
         }
     }
   else
     {
       while (loop_cond)
         {
           A;
           branch2;
           B;
           C;
         }
     }

  Duplicating the loop might lead to code growth exponential in number of
  branches inside loop, so we limit the number of unswitchings performed
  in a single loop to PARAM_MAX_UNSWITCH_LEVEL.  We only perform the
  transformation on innermost loops, as the benefit of doing it on loops
  containing subloops would not be very large compared to complications
  with handling this case.  
static struct loop* unswitch_loop ( )
staticread
   Unswitch a LOOP w.r. to given basic block UNSWITCH_ON.  We only support
   unswitching of innermost loops.  UNSWITCH_ON must be executed in every
   iteration, i.e. it must dominate LOOP latch.  COND is the condition
   determining which loop is entered.  Returns NULL if impossible, new loop
   otherwise.  The new loop is entered if COND is true.  If CINSN is not
   NULL, it is the insn in that COND is compared.  
     Some sanity checking.  
     Make a copy.  
     Record the block with condition we unswitch on.  
     Create a block with the condition.  
     Loopify from the copy of LOOP body, constructing the new loop.  
     Remove branches that are now unreachable in new loops.  
     Preserve the simple loop preheaders.  
void unswitch_loops ( void  )
   Main entry point.  Perform loop unswitching on all suitable loops.  
     Go through inner loops (only original ones).  
     If we unswitched any loop discover new loops that are eventually
     exposed by making irreducible regions reducible.  

References calculate_dominance_info(), CDI_DOMINATORS, and fix_loop_structure().

static bool unswitch_single_loop ( struct loop ,
rtx  ,
int   
)
static
static bool unswitch_single_loop ( )
static
   Unswitch single LOOP.  COND_CHECKED holds list of conditions we already
   unswitched on and are therefore known to be true in this LOOP.  NUM is
   number of unswitchings done; do not allow it to grow too much, it is too
   easy to create example on that the code would grow exponentially.
   Returns true LOOP was unswitched.  
     Do not unswitch too much.  
     Only unswitch innermost loops.  
     We must be able to duplicate loop body.  
     The loop should not be too large, to limit code growth.  
     Do not unswitch in cold areas.  
     Nor if the loop usually does not roll.  
         Find a bb to unswitch on.  
             Check whether the result can be predicted.  
             Remove false path.  
             Remove true path.  
     We found the condition we can unswitch on.  
     Unswitch the loop on this condition.  
     Invoke itself on modified loops.