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

Data Structures

struct  _elim_graph

Typedefs

typedef struct _elim_graphelim_graph

Functions

bool ssa_is_replaceable_p ()
static void set_location_for_edge ()
static rtx emit_partition_copy ()
static void insert_partition_copy_on_edge ()
static void insert_value_copy_on_edge ()
static void insert_rtx_to_part_on_edge (edge e, int dest, rtx src, int unsignedsrcp, source_location locus)
static void insert_part_to_rtx_on_edge ()
static elim_graph new_elim_graph ()
static void clear_elim_graph ()
static void delete_elim_graph ()
static int elim_graph_size ()
static void elim_graph_add_node ()
static void elim_graph_add_edge ()
static int elim_graph_remove_succ_edge ()
static void eliminate_name ()
static void eliminate_build ()
static void elim_forward ()
static int elim_unvisited_predecessor ()
static void elim_backward ()
static rtx get_temp_reg ()
static void elim_create ()
static void eliminate_phi ()
static void remove_gimple_phi_args ()
static void eliminate_useless_phis ()
static void rewrite_trees ()
void expand_phi_nodes ()
static void remove_ssa_form ()
static void maybe_renumber_stmts_bb ()
static bool trivially_conflicts_p ()
static void insert_backedge_copies ()
void finish_out_of_ssa ()
unsigned int rewrite_out_of_ssa ()

Typedef Documentation

typedef struct _elim_graph * elim_graph
   Used to hold all the components required to do SSA PHI elimination.
   The node and pred/succ list is a simple linear list of nodes and
   edges represented as pairs of nodes.

   The predecessor and successor list:  Nodes are entered in pairs, where
   [0] ->PRED, [1]->SUCC.  All the even indexes in the array represent
   predecessors, all the odd elements are successors.

   Rationale:
   When implemented as bitmaps, very large programs SSA->Normal times were
   being dominated by clearing the interference graph.

   Typically this list of edges is extremely small since it only includes
   PHI results and uses from a single edge which have not coalesced with
   each other.  This means that no virtual PHI nodes are included, and
   empirical evidence suggests that the number of edges rarely exceed
   3, and in a bootstrap of GCC, the maximum size encountered was 7.
   This also limits the number of possible nodes that are involved to
   rarely more than 6, and in the bootstrap of gcc, the maximum number
   of nodes encountered was 12.  

Function Documentation

static void clear_elim_graph ( )
inlinestatic
   Empty elimination graph G.  

References _elim_graph::nodes.

static void delete_elim_graph ( )
inlinestatic
   Delete elimination graph G.  

References _elim_graph::edge_list, and _elim_graph::edge_locus.

static void elim_backward ( )
static
   Process predecessors first, and insert a copy.  

Referenced by elim_unvisited_predecessor().

static void elim_create ( )
static
   Insert required copies for T in graph G.  Check for a strongly connected
   region, and create a temporary to break the cycle if one is found.  
static void elim_forward ( )
static
   Push successors of T onto the elimination stack for G.  

References gen_reg_rtx(), mark_reg_pointer(), promote_decl_mode(), and reg_mode.

Referenced by eliminate_build().

static void elim_graph_add_edge ( )
inlinestatic
   Add the edge PRED->SUCC to graph G.  
static void elim_graph_add_node ( )
inlinestatic
   Add NODE to graph G, if it doesn't exist already.  

Referenced by elim_graph_remove_succ_edge().

static int elim_graph_remove_succ_edge ( )
inlinestatic
   Remove an edge from graph G for which NODE is the predecessor, and
   return the successor node.  -1 is returned if there is no such edge.  

References elim_graph_add_node().

static int elim_graph_size ( )
inlinestatic
   Return the number of nodes in graph G.  

References _elim_graph::edge_list, and _elim_graph::edge_locus.

static int elim_unvisited_predecessor ( )
static
static void eliminate_build ( )
static
   Build elimination graph G for basic block BB on incoming PHI edge
   G->e.  
         Ignore results which are not in partitions.  
         If this argument is a constant, or a SSA_NAME which is being
         left in SSA form, just queue a copy to be emitted on this
         edge.  
             Save constant copies until all other copies have been emitted
             on this edge.  

References bitmap_bit_p(), bitmap_set_bit(), elim_forward(), _elim_graph::stack, and _elim_graph::visited.

static void eliminate_name ( )
inlinestatic
   Add T to elimination graph G.  
static void eliminate_phi ( )
static
   Eliminate all the phi nodes on edge E in graph G.  
     Abnormal edges already have everything coalesced.  
     If there are any pending constant copies, issue them now.  

References dump_file, dump_flags, gsi_for_stmt(), has_zero_uses(), print_gimple_stmt(), remove_gimple_phi_args(), and remove_phi_node().

static void eliminate_useless_phis ( )
static
   Remove any PHI node which is a virtual PHI, or a PHI with no uses.  
                 There should be no arguments which are not virtual, or the
                 results will be incorrect.  
                 Also remove real PHIs with no uses.  

References gimple_phi_num_args(), gimple_phi_result(), gsi_end_p(), gsi_next(), gsi_start_phis(), gsi_stmt(), internal_error(), map, print_generic_expr(), print_gimple_stmt(), var_to_partition(), and var_to_partition_to_var().

static rtx emit_partition_copy ( )
inlinestatic
   Emit insns to copy SRC into DEST converting SRC if necessary.  As
   SRC/DEST might be BLKmode memory locations SIZEEXP is a tree from
   which we deduce the size to copy in that case.  

References edge_def::dest, dump_file, basic_block_def::index, and edge_def::src.

Referenced by insert_rtx_to_part_on_edge().

void expand_phi_nodes ( )
   Given the out-of-ssa info object SA (with prepared partitions)
   eliminate all phi nodes in all basic blocks.  Afterwards no
   basic block will have phi nodes anymore and there are possibly
   some RTL instructions inserted on edges.  
           We can't redirect EH edges in RTL land, so we need to do this
           here.  Redirection happens only when splitting is necessary,
           which it is only for critical edges, normally.  For EH edges
           it might also be necessary when the successor has more than
           one predecessor.  In that case the edge is either required to
           be fallthru (which EH edges aren't), or the predecessor needs
           to end with a jump (which again, isn't the case with EH edges).
           Hence, split all EH edges on which we inserted instructions
           and whose successor has multiple predecessors.  

References dump_file, dump_flags, dump_replaceable_exprs(), and find_replaceable_exprs().

void finish_out_of_ssa ( )
   Free all memory associated with going out of SSA form.  SA is
   the outof-SSA info object.  
static rtx get_temp_reg ( )
static
   Allocate a new pseudo register usable for storing values sitting
   in NAME (a decl or SSA name), i.e. with matching mode and attributes.  

Referenced by elim_unvisited_predecessor().

static void insert_backedge_copies ( )
static
   Search every PHI node for arguments associated with backedges which
   we can trivially determine will need a copy (the argument is either
   not an SSA_NAME or the argument has a different underlying variable
   than the PHI result).

   Insert a copy from the PHI argument to a new destination at the
   end of the block with the backedge to the top of the loop.  Update
   the PHI argument to reference this new destination.  
         Mark block as possibly needing calculation of UIDs.  
                 If the argument is not an SSA_NAME, then we will need a
                 constant initialization.  If the argument is an SSA_NAME with
                 a different underlying variable then a copy statement will be
                 needed.  
                     In theory the only way we ought to get back to the
                     start of a loop should be with a COND_EXPR or GOTO_EXPR.
                     However, better safe than sorry.
                     If the block ends with a control statement or
                     something that might throw, then we have to
                     insert this assignment before the last
                     statement.  Else insert it after the last statement.  
                         If the last statement in the block is the definition
                         site of the PHI argument, then we can't insert
                         anything after it.  
                     Create a new instance of the underlying variable of the
                     PHI result.  
                     copy location if present.  
                     Insert the new statement into the block and update
                     the PHI node.  
         Unmark this block again.  
static void insert_part_to_rtx_on_edge ( )
static
   Insert a copy instruction from partition SRC to RTL lvalue DEST
   onto edge E.  
     If a locus is provided, override the default.  

References _elim_graph::const_copies, _elim_graph::const_dests, _elim_graph::copy_locus, _elim_graph::edge_list, _elim_graph::edge_locus, g, _elim_graph::nodes, sbitmap_alloc(), _elim_graph::stack, and _elim_graph::visited.

Referenced by elim_unvisited_predecessor().

static void insert_partition_copy_on_edge ( )
static
   Insert a copy instruction from partition SRC to DEST onto edge E.  
     If a locus is provided, override the default.  
static void insert_rtx_to_part_on_edge ( edge  e,
int  dest,
rtx  src,
int  unsignedsrcp,
source_location  locus 
)
static
   Insert a copy instruction from RTL expression SRC to partition DEST
   onto edge E.  
     If a locus is provided, override the default.  
     We give the destination as sizeexp in case src/dest are BLKmode
     mems.  Usually we give the source.  As we result from SSA names
     the left and right size should be the same (and no WITH_SIZE_EXPR
     involved), so it doesn't matter.  

References edge_def::dest, dump_file, dump_flags, emit_partition_copy(), basic_block_def::index, insert_insn_on_edge(), ssaexpand::map, ssaexpand::partition_to_pseudo, partition_to_var(), print_simple_rtl(), SA, set_curr_insn_location(), set_location_for_edge(), and edge_def::src.

static void insert_value_copy_on_edge ( )
static
   Insert a copy instruction from expression SRC to partition DEST
   onto edge E.  
     If a locus is provided, override the default.  
static void maybe_renumber_stmts_bb ( )
static
   If not already done so for basic block BB, assign increasing uids
   to each of its instructions.  

Referenced by remove_ssa_form().

static elim_graph new_elim_graph ( )
static
   Create an elimination graph with SIZE nodes and associated data
   structures.  
static void remove_gimple_phi_args ( )
static
   Remove each argument from PHI.  If an arg was the last use of an SSA_NAME,
   check to see if this allows another PHI node to be removed.  
             Remove the reference to the existing argument.  
                 Also remove the def if it is a PHI node.  

Referenced by eliminate_phi().

static void remove_ssa_form ( )
static
   Remove the ssa-names in the current function and translate them into normal
   compiler variables.  PERFORM_TER is true if Temporary Expression Replacement
   should also be used.  
     Return to viewing the variable list as just all reference variables after
     coalescing has been performed.  

References gimple_uid(), is_gimple_debug(), and maybe_renumber_stmts_bb().

unsigned int rewrite_out_of_ssa ( )
   Take the current function out of SSA form, translating PHIs as described in
   R. Morgan, ``Building an Optimizing Compiler'',
   Butterworth-Heinemann, Boston, MA, 1998. pp 176-186.  
     If elimination of a PHI requires inserting a copy on a backedge,
     then we will have to split the backedge which has numerous
     undesirable performance effects.

     A significant number of such cases can be handled here by inserting
     copies into the loop itself.  
     Eliminate PHIs which are of no use, such as virtual or dead phis.  
static void rewrite_trees ( )
static
   This function will rewrite the current program using the variable mapping
   found in MAP.  If the replacement vector VALUES is provided, any
   occurrences of partitions with non-null entries in the vector will be
   replaced with the expression in the vector instead of its mapped
   variable.  
     Search for PHIs where the destination has no partition, but one
     or more arguments has a partition.  This should not happen and can
     create incorrect code.  

References ei_next(), edge_def::insns, edge_def::edge_def_insns::r, single_pred_edge(), single_pred_p(), and split_edge().

static void set_location_for_edge ( )
static
   For an edge E find out a good source location to associate with
   instructions inserted on edge E.  If E has an implicit goto set,
   use its location.  Otherwise search instructions in predecessors
   of E for a location, and use that one.  That makes sense because
   we insert on edges for PHI nodes, and effects of PHIs happen on
   the end of the predecessor conceptually.  
             Nothing found in this basic block.  Make a half-assed attempt
             to continue with another block.  

Referenced by insert_rtx_to_part_on_edge().

bool ssa_is_replaceable_p ( )
@verbatim 

Convert a program in SSA form into Normal form. Copyright (C) 2004-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/.

   FIXME: A lot of code here deals with expanding to RTL.  All that code
   should be in cfgexpand.c.  
   Return TRUE if expression STMT is suitable for replacement.  
     Only consider modify stmts.  
     If the statement may throw an exception, it cannot be replaced.  
     Punt if there is more than 1 def.  
     Only consider definitions which have a single use.  
     Used in this block, but at the TOP of the block, not the end.  
     There must be no VDEFs.  
     Float expressions must go through memory if float-store is on.  
     An assignment with a register variable on the RHS is not
     replaceable.  
     No function calls can be replaced.  
     Leave any stmt with volatile operands alone as well.  

Referenced by finished_with_expr().

static bool trivially_conflicts_p ( )
static
   Return true if we can determine that the SSA_NAMEs RESULT (a result
   of a PHI node) and ARG (one of its arguments) conflict.  Return false
   otherwise, also when we simply aren't sure.  
     If ARG isn't defined in the same block it's too complicated for
     our little mind.  
         Now, if there's a use of RESULT that lies outside this basic block,
         then there surely is a conflict with ARG.  
         The use now is in a real stmt of BB, so if ARG was defined
         in a PHI node (like RESULT) both conflict.  
         If the use of RESULT occurs after the definition of ARG,
         the two conflict too.  

References copy_ssa_name(), gimple_phi_arg_def(), gimple_phi_arg_edge(), gimple_phi_arg_has_location(), gimple_phi_arg_location(), gimple_set_location(), gsi_end_p(), gsi_insert_after(), gsi_insert_before(), gsi_last_bb(), GSI_NEW_STMT, gsi_stmt(), last, and stmt_ends_bb_p().