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

Data Structures

struct  temp_expr_table_d

Typedefs

typedef struct temp_expr_table_dtemp_expr_table_p

Functions

void debug_ter (FILE *, temp_expr_table_p)
static temp_expr_table_p new_temp_expr_table ()
static bitmap free_temp_expr_table ()
static bool version_to_be_replaced_p ()
static void make_dependent_on_partition ()
static void add_to_partition_kill_list ()
static void remove_from_partition_kill_list ()
static void add_dependence ()
static bool is_replaceable_p ()
bool stmt_is_replaceable_p ()
static void finished_with_expr ()
static void process_replaceable ()
static void kill_expr ()
static void kill_virtual_exprs ()
static void mark_replaceable ()
static void find_replaceable_in_bb ()
bitmap find_replaceable_exprs ()
void dump_replaceable_exprs ()
DEBUG_FUNCTION void debug_ter ()

Variables

static bitmap_obstack ter_bitmap_obstack

Typedef Documentation

@verbatim Routines for performing Temporary Expression Replacement (TER) in SSA trees.

Copyright (C) 2003-2013 Free Software Foundation, Inc. Contributed by Andrew MacLeod amacl.nosp@m.eod@.nosp@m.redha.nosp@m.t.co.nosp@m.m

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

Temporary Expression Replacement (TER)

   Replace SSA version variables during out-of-ssa with their defining
   expression if there is only one use of the variable.

   This pass is required in order for the RTL expansion pass to see larger
   chunks of code.  This allows it to make better choices on RTL pattern
   selection.  When expand is rewritten and merged with out-of-ssa, and
   understands SSA, this should be eliminated.

   A pass is made through the function, one block at a time.  No cross block
   information is tracked.

   Variables which only have one use, and whose defining stmt is considered
   a replaceable expression (see is_replaceable_p) are tracked to see whether
   they can be replaced at their use location.

   n_12 = C * 10
   a_2 = b_5 + 6
   v_9 = a_2 * n_12

   if there are the only use of n_12 and a_2, TER will substitute in their
   expressions in v_9, and end up with:

   v_9 = (b_5 + 6) * (C * 10)

   which will then have the ssa_name assigned to regular variables, and the
   resulting code which will be passed to the expander looks something like:

   v = (b + 6) * (C * 10)


   This requires ensuring that none of the variables used by the expression
   change between the def point and where it is used.  Furthermore, if any
   of the ssa_names used in this expression are themselves replaceable, we
   have to ensure none of that expressions' arguments change either.
   Although SSA_NAMES themselves don't change, this pass is performed after
   coalescing has coalesced different SSA_NAMES together, so there could be a
   definition of an SSA_NAME which is coalesced with a use that causes a
   problem, i.e.,

   PHI b_5 = <b_8(2), b_14(1)>
   <...>
   a_2 = b_5 + 6
   b_8 = c_4 + 4
   v_9 = a_2 * n_12
   <...>

   If b_5, b_8 and b_14 are all coalesced together...
   The expression b_5 + 6 CANNOT replace the use in the statement defining v_9
   because b_8 is in fact killing the value of b_5 since they share a partition
   and will be assigned the same memory or register location.

   TER implements this but stepping through the instructions in a block and
   tracking potential expressions for replacement, and the partitions they are
   dependent on.  Expressions are represented by the SSA_NAME_VERSION of the
   DEF on the LHS of a GIMPLE_ASSIGN and the expression is the RHS.

   When a stmt is determined to be a possible replacement expression, the
   following steps are taken:

   EXPR_DECL_UID bitmap is allocated and set to the base variable UID of the
   def and any uses in the expression.  non-NULL means the expression is being
   tracked.  The UID's themselves are used to prevent TER substitution into
   accumulating sequences, i.e.,

   x = x + y
   x = x + z
   x = x + w
   etc.
   this can result in very large expressions which don't accomplish anything
   see PR tree-optimization/17549.

   PARTITION_DEPENDENCIES is another bitmap array, and it has a bit set for any
   partition which is used in the expression.  This is primarily used to remove
   an expression from the partition kill lists when a decision is made whether
   to replace it or not.  This is indexed by ssa version number as well, and
   indicates a partition number.  virtual operands are not tracked individually,
   but they are summarized by an artificial partition called VIRTUAL_PARTITION.
   This means a MAY or MUST def will kill *ALL* expressions that are dependent
   on a virtual operand.
   Note that the EXPR_DECL_UID and this bitmap represent very similar
   information, but the info in one is not easy to obtain from the other.

   KILL_LIST is yet another bitmap array, this time it is indexed by partition
   number, and represents a list of active expressions which will will no
   longer be valid if a definition into this partition takes place.

   PARTITION_IN_USE is simply a bitmap which is used to track which partitions
   currently have something in their kill list.  This is used at the end of
   a block to clear out the KILL_LIST bitmaps at the end of each block.

   NEW_REPLACEABLE_DEPENDENCIES is used as a temporary place to store
   dependencies which will be reused by the current definition. All the uses
   on an expression are processed before anything else is done. If a use is
   determined to be a replaceable expression AND the current stmt is also going
   to be replaceable, all the dependencies of this replaceable use will be
   picked up by the current stmt's expression. Rather than recreate them, they
   are simply copied here and then copied into the new expression when it is
   processed.

   a_2 = b_5 + 6
   v_8 = a_2 + c_4

   a_2's expression 'b_5 + 6' is determined to be replaceable at the use
   location. It is dependent on the partition 'b_5' is in. This is cached into
   the NEW_REPLACEABLE_DEPENDENCIES bitmap, and when v_8 is examined for
   replaceability, it is a candidate, and it is dependent on the partition
   b_5 is in *NOT* a_2, as well as c_4's partition.

   if v_8 is also replaceable:

   x_9 = v_8 * 5

   x_9 is dependent on partitions b_5, and c_4

   if a statement is found which has either of those partitions written to
   before x_9 is used, then x_9 itself is NOT replaceable.   
Temporary Expression Replacement (TER) table information.   

Function Documentation

static void add_dependence ( )
static
Add a dependency between the def of ssa VERSION and VAR.  If VAR is
   replaceable by an expression, add a dependence each of the elements of the
   expression.  These are contained in the new_replaceable list.  TAB is the
   expression table.   

References add_to_partition_kill_list(), bitmap_clear(), bitmap_empty_p(), bitmap_ior_into(), make_dependent_on_partition(), temp_expr_table_d::map, temp_expr_table_d::new_replaceable_dependencies, temp_expr_table_d::num_in_part, temp_expr_table_d::partition_dependencies, temp_expr_table_d::partition_in_use, var_to_partition(), and version_to_be_replaced_p().

static void add_to_partition_kill_list ( )
inlinestatic
Add VER to the kill list for P.  TAB is the expression table  

References bitmap_set_bit(), temp_expr_table_d::kill_list, and temp_expr_table_d::partition_in_use.

Referenced by add_dependence(), and process_replaceable().

void debug_ter ( FILE *  ,
temp_expr_table_p   
)
DEBUG_FUNCTION void debug_ter ( )
void dump_replaceable_exprs ( )
Dump TER expression table EXPR to file F.   

References bitmap_bit_p(), print_generic_expr(), and print_gimple_stmt().

bitmap find_replaceable_exprs ( )
This function is the driver routine for replacement of temporary expressions
   in the SSA->normal phase, operating on MAP.  If there are replaceable
   expressions, a table is returned which maps SSA versions to the
   expressions they should be replaced with.  A NULL_TREE indicates no
   replacement should take place.  If there are no replacements at all,
   NULL is returned by the function, otherwise an expression vector indexed
   by SSA_NAME version numbers.   

References bitmap_empty_p(), bitmap_obstack_initialize(), bitmap_obstack_release(), find_replaceable_in_bb(), free_temp_expr_table(), new_temp_expr_table(), temp_expr_table_d::partition_in_use, and table.

static void finished_with_expr ( )
static
This function will remove the expression for VERSION from replacement
   consideration in table TAB.  If FREE_EXPR is true, then remove the
   expression from consideration as well by freeing the decl uid bitmap.   

References temp_expr_table_d::expr_decl_uids, temp_expr_table_d::partition_dependencies, and remove_from_partition_kill_list().

Referenced by find_replaceable_in_bb(), kill_expr(), and mark_replaceable().

static bool is_replaceable_p ( )
inlinestatic
Return TRUE if expression STMT is suitable for replacement.
   TER is true if is_replaceable_p is called from within TER, false
   when used from within stmt_is_replaceable_p, i.e. EXPAND_INITIALIZER
   expansion.  The differences are that with !TER some tests are skipped
   to make it more aggressive (doesn't require the same bb, or for -O0
   same locus and same BLOCK), on the other side never considers memory
   loads as replaceable, because those don't ever lead into constant
   expressions.   

References gimple_assign_rhs1(), gimple_assign_rhs_code(), gimple_assign_single_p(), gimple_expr_type(), gimple_has_volatile_ops(), gimple_location(), gimple_phi_arg_location(), gimple_vdef(), is_gimple_assign(), is_gimple_call(), is_gimple_val(), single_imm_use(), and stmt_could_throw_p().

Referenced by find_replaceable_in_bb(), process_replaceable(), and stmt_is_replaceable_p().

static void kill_expr ( )
inlinestatic
This function removes any expression in TAB which is dependent on PARTITION
   from consideration, making it not replaceable.   

References bitmap_first_set_bit(), finished_with_expr(), and temp_expr_table_d::kill_list.

Referenced by find_replaceable_in_bb(), and kill_virtual_exprs().

static void kill_virtual_exprs ( )
inlinestatic
This function kills all expressions in TAB which are dependent on virtual
   partitions.   

References kill_expr().

Referenced by find_replaceable_in_bb().

static void make_dependent_on_partition ( )
inlinestatic
Add partition P to the list if partitions VERSION is dependent on.  TAB is
   the expression table  

References bitmap_set_bit(), and temp_expr_table_d::partition_dependencies.

Referenced by add_dependence(), and process_replaceable().

static void mark_replaceable ( )
static
Mark the expression associated with VAR as replaceable, and enter
   the defining stmt into the partition_dependencies table TAB.  If
   MORE_REPLACING is true, accumulate the pending partition dependencies.   

References bitmap_ior_into(), bitmap_set_bit(), finished_with_expr(), temp_expr_table_d::new_replaceable_dependencies, temp_expr_table_d::partition_dependencies, and temp_expr_table_d::replaceable_expressions.

Referenced by find_replaceable_in_bb().

static void process_replaceable ( )
static
static void remove_from_partition_kill_list ( )
inlinestatic
Remove VER from the partition kill list for P.  TAB is the expression
   table.   

References bitmap_clear_bit(), bitmap_empty_p(), temp_expr_table_d::kill_list, and temp_expr_table_d::partition_in_use.

Referenced by finished_with_expr().

bool stmt_is_replaceable_p ( )
Variant of is_replaceable_p test for use in EXPAND_INITIALIZER
   expansion.   

References is_replaceable_p().

static bool version_to_be_replaced_p ( )
inlinestatic
Return TRUE if VERSION is to be replaced by an expression in TAB.   

References bitmap_bit_p(), and temp_expr_table_d::replaceable_expressions.

Referenced by add_dependence().


Variable Documentation

bitmap_obstack ter_bitmap_obstack
static
A place for the many, many bitmaps we create.