GCC Middle and Back End API Reference
tree-ssa-loop-ivcanon.c File Reference

Data Structures

struct  loop_size

Enumerations

enum  unroll_level { UL_SINGLE_ITER, UL_NO_GROWTH, UL_ALL }

Functions

static void create_canonical_iv ()
unsigned tree_num_loop_insns ()
static bool constant_after_peeling ()
static bool tree_estimate_loop_size (struct loop *loop, edge exit, edge edge_to_cancel, struct loop_size *size, int upper_bound)
static unsigned HOST_WIDE_INT estimated_unrolled_size (struct loop_size *size, unsigned HOST_WIDE_INT nunroll)
edge loop_edge_to_cancel ()
static bool remove_exits_and_undefined_stmts ()
static bool remove_redundant_iv_tests ()
void unloop_loops (bitmap loop_closed_ssa_invalidated, bool *irred_invalidated)
static bool try_unroll_loop_completely (struct loop *loop, edge exit, tree niter, enum unroll_level ul, HOST_WIDE_INT maxiter, location_t locus)
static bool canonicalize_loop_induction_variables (struct loop *loop, bool create_iv, enum unroll_level ul, bool try_eval)
unsigned int canonicalize_induction_variables ()
static void propagate_into_all_uses ()
static void propagate_constants_for_unrolling ()
static bool tree_unroll_loops_completely_1 (bool may_increase_size, bool unroll_outer, vec< loop_p, va_stack > &father_stack, struct loop *loop)
unsigned int tree_unroll_loops_completely ()

Variables

static vec< loop_ploops_to_unloop
static vec< int > loops_to_unloop_nunroll

Enumeration Type Documentation

@verbatim Induction variable canonicalization and loop peeling.

Copyright (C) 2004-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 detects the loops that iterate a constant number of times,
   adds a canonical induction variable (step -1, tested against 0)
   and replaces the exit test.  This enables the less powerful rtl
   level analysis to use this information.

   This might spoil the code in some cases (by increasing register pressure).
   Note that in the case the new variable is not needed, ivopts will get rid
   of it, so it might only be a problem when there are no other linear induction
   variables.  In that case the created optimization possibilities are likely
   to pay up.

   Additionally in case we detect that it is beneficial to unroll the
   loop completely, we do it right here to expose the optimization
   possibilities to the following passes.   
Specifies types of loops that may be unrolled.   
Enumerator:
UL_SINGLE_ITER 
UL_NO_GROWTH 
UL_ALL 

Function Documentation

static bool canonicalize_loop_induction_variables ( struct loop loop,
bool  create_iv,
enum unroll_level  ul,
bool  try_eval 
)
static
Adds a canonical induction variable to LOOP if suitable.
   CREATE_IV is true if we may create a new iv.  UL determines
   which loops we are allowed to completely unroll.  If TRY_EVAL is true, we try
   to determine the number of iterations of a loop by direct evaluation.
   Returns true if cfg is changed.    

References chrec_contains_undetermined(), create_canonical_iv(), dump_file, dump_flags, find_loop_niter(), find_loop_niter_by_eval(), gimple_location(), HOST_WIDE_INT, just_once_each_iteration_p(), last_stmt(), max_loop_iterations_int(), loop::num, number_of_latch_executions(), print_generic_expr(), record_niter_bound(), remove_redundant_iv_tests(), single_exit(), single_likely_exit(), edge_def::src, tree_to_double_int(), and try_unroll_loop_completely().

Referenced by canonicalize_induction_variables(), and tree_unroll_loops_completely_1().

static bool constant_after_peeling ( )
static
Return true if OP in STMT will be constant after peeling LOOP.   

References affine_iv::base, ctor_for_folding(), handled_component_p(), is_gimple_min_invariant(), loop_containing_stmt(), simple_iv(), and affine_iv::step.

Referenced by tree_estimate_loop_size().

static void create_canonical_iv ( )
static
Adds a canonical induction variable to LOOP iterating NITER times.  EXIT
   is the exit edge whose condition is replaced.   

References build_int_cst(), create_iv(), dump_file, dump_flags, edge_def::flags, gimple_cond_set_code(), gimple_cond_set_lhs(), gimple_cond_set_rhs(), gsi_last_bb(), last_stmt(), loop::num, print_generic_expr(), edge_def::src, type(), and update_stmt().

Referenced by canonicalize_loop_induction_variables().

static unsigned HOST_WIDE_INT estimated_unrolled_size ( struct loop_size size,
unsigned HOST_WIDE_INT  nunroll 
)
static
Estimate number of insns of completely unrolled loop.
   It is (NUNROLL + 1) * size of loop body with taking into account
   the fact that in last copy everything after exit conditional
   is dead and that some instructions will be eliminated after
   peeling.

   Loop body is likely going to simplify further, this is difficult
   to guess, we just decrease the result by 1/3.   

References loop_size::eliminated_by_peeling, HOST_WIDE_INT, loop_size::last_iteration, loop_size::last_iteration_eliminated_by_peeling, and loop_size::overall.

Referenced by try_unroll_loop_completely().

edge loop_edge_to_cancel ( )
Loop LOOP is known to not loop.  See if there is an edge in the loop
   body that can be remove to make the loop to always exit and at
   the same time it does not make any code potentially executed 
   during the last iteration dead.  

   After complette unrolling we still may get rid of the conditional
   on the exit in the last copy even if we have no idea what it does.
   This is quite common case for loops of form

     int a[5];
     for (i=0;i<b;i++)
       a[i]=0;

   Here we prove the loop to iterate 5 times but we do not know
   it from induction variable.

   For now we handle only simple case where there is exit condition
   just before the latch block and the latch block contains no statements
   with side effect that may otherwise terminate the execution of loop
   (such as by EH or by terminating the program or longjmp).

   In the general case we may want to cancel the paths leading to statements
   loop-niter identified as having undefined effect in the last iteration.
   The other cases are hopefully rare and will be cleaned up later.   

References edge_def::dest, edge_def::flags, get_loop_exit_edges(), gimple_has_side_effects(), gsi_end_p(), gsi_next(), gsi_start_bb(), gsi_stmt(), loop::header, loop::latch, basic_block_def::preds, edge_def::src, and basic_block_def::succs.

Referenced by try_unroll_loop_completely().

static bool remove_exits_and_undefined_stmts ( )
static
static bool tree_estimate_loop_size ( struct loop loop,
edge  exit,
edge  edge_to_cancel,
struct loop_size size,
int  upper_bound 
)
static
unsigned tree_num_loop_insns ( )
Computes an estimated number of insns in LOOP, weighted by WEIGHTS.   

References estimate_num_insns(), free(), get_loop_body(), gsi_end_p(), gsi_next(), gsi_start_bb(), gsi_stmt(), and loop::num_nodes.

static bool tree_unroll_loops_completely_1 ( bool  may_increase_size,
bool  unroll_outer,
vec< loop_p, va_stack > &  father_stack,
struct loop loop 
)
static
Process loops from innermost to outer, stopping at the innermost
   loop we unrolled.   

References loop::aux, canonicalize_loop_induction_variables(), changed, loop::force_vect, loop::inner, loop_outer(), loop::next, optimize_loop_nest_for_speed_p(), ul, UL_ALL, and UL_NO_GROWTH.

Referenced by tree_unroll_loops_completely().

static bool try_unroll_loop_completely ( struct loop loop,
edge  exit,
tree  niter,
enum unroll_level  ul,
HOST_WIDE_INT  maxiter,
location_t  locus 
)
static
void unloop_loops ( bitmap  loop_closed_ssa_invalidated,
bool *  irred_invalidated 
)
Cancel all fully unrolled loops by putting __builtin_unreachable
   on the latch edge.  
   We do it after all unrolling since unlooping moves basic blocks
   across loop boundaries trashing loop closed SSA form as well
   as SCEV info needed to be intact during unrolling. 

   IRRED_INVALIDATED is used to bookkeep if information about
   irreducible regions may become invalid as a result
   of the transformation.  
   LOOP_CLOSED_SSA_INVALIDATED is used to bookkepp the case
   when we need to go into loop closed SSA form.   

References builtin_decl_implicit(), CDI_DOMINATORS, edge_def::count, basic_block_def::count, create_basic_block(), edge_def::dest, edge_def::flags, basic_block_def::frequency, gimple_build_call(), edge_def::goto_locus, gsi_insert_after(), GSI_NEW_STMT, gsi_start_bb(), loop::latch, basic_block_def::loop_father, loop_latch_edge(), make_edge(), edge_def::probability, remove_exits_and_undefined_stmts(), set_immediate_dominator(), edge_def::src, and unloop().

Referenced by canonicalize_induction_variables(), and tree_unroll_loops_completely().


Variable Documentation

vec<loop_p> loops_to_unloop
static
Stores loops that will be unlooped after we process whole loop tree.  
vec<int> loops_to_unloop_nunroll
static