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.   

References add_reg_note(), copy_insn(), do_compare_rtx_and_jump(), emit_jump_insn(), end_sequence(), force_operand(), get_insns(), get_last_insn(), pc_set(), redirect_jump(), rtx_equal_p(), and start_sequence().

Referenced by unroll_loop_runtime_iterations(), and unswitch_loop().

static rtx may_unswitch_on ( basic_block  ,
struct loop ,
rtx  
)
static

Referenced by unswitch_single_loop().

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.   

References any_condjump_p(), canon_condition(), const_true_rtx, rtx_iv::first_special, flow_bb_inside_loop_p(), get_condition(), get_iv_value(), iv_analyze(), just_once_each_iteration_p(), rtx_iv::mode, rtx_equal_p(), simplify_gen_relational(), rtx_iv::step, and basic_block_def::succs.

rtx reversed_condition ( )
Reverses CONDition; returns NULL if we cannot.   

References reversed_comparison_code().

Referenced by check_simple_exit(), simplify_using_condition(), simplify_using_initial_values(), and unswitch_single_loop().

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.   

Referenced by unswitch_single_loop().

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.   

References apply_probability(), block_label(), compare_and_jump_seq(), copy_loop_info(), edge_def::count, create_empty_bb(), edge_def::dest, duplicate_loop_to_header_edge(), emit_insn_after(), edge_def::flags, basic_block_def::flags, flow_bb_inside_loop_p(), get_bb_copy(), loop::header, loop::inner, just_once_each_iteration_p(), loop::latch, loop_preheader_edge(), loopify(), make_edge(), prob, edge_def::probability, remove_path(), single_pred_edge(), single_succ_edge(), split_edge(), and basic_block_def::succs.

void unswitch_loops ( void  )
Main entry point.  Perform loop unswitching on all suitable loops.   

References calculate_dominance_info(), CDI_DOMINATORS, changed, fix_loop_structure(), iv_analysis_done(), LI_ONLY_INNERMOST, and unswitch_single_loop().

Referenced by rtl_unswitch().

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.   

References alloc_EXPR_LIST(), can_duplicate_loop_p(), canon_condition(), const_true_rtx, copy_rtx_if_shared(), dump_file, estimated_loop_iterations_int(), free(), free_EXPR_LIST_node(), get_loop_body(), HOST_WIDE_INT, loop::inner, iv_analysis_loop_init(), may_unswitch_on(), num_loop_insns(), loop::num_nodes, optimize_loop_for_size_p(), remove_path(), reversed_condition(), simplify_using_condition(), unswitch_loop(), and unswitch_single_loop().