GCC Middle and Back End API Reference
tree-outof-ssa.c File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "tree.h"
#include "ggc.h"
#include "basic-block.h"
#include "gimple-pretty-print.h"
#include "bitmap.h"
#include "sbitmap.h"
#include "gimple.h"
#include "gimple-ssa.h"
#include "tree-cfg.h"
#include "tree-phinodes.h"
#include "ssa-iterators.h"
#include "tree-ssanames.h"
#include "dumpfile.h"
#include "diagnostic-core.h"
#include "tree-ssa-live.h"
#include "tree-ssa-ter.h"
#include "tree-ssa-coalesce.h"
#include "tree-outof-ssa.h"
#include "expr.h"
Include dependency graph for tree-outof-ssa.c:

Data Structures

struct  _elim_graph

Macros

#define FOR_EACH_ELIM_GRAPH_SUCC(GRAPH, NODE, VAR, LOCUS, CODE)
#define FOR_EACH_ELIM_GRAPH_PRED(GRAPH, NODE, VAR, LOCUS, CODE)

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 ()

Macro Definition Documentation

#define FOR_EACH_ELIM_GRAPH_PRED (   GRAPH,
  NODE,
  VAR,
  LOCUS,
  CODE 
)
Value:
do { \
unsigned x_; \
int y_; \
for (x_ = 0; x_ < (GRAPH)->edge_list.length (); x_ += 2) \
{ \
y_ = (GRAPH)->edge_list[x_ + 1]; \
if (y_ != (NODE)) \
continue; \
(void) ((VAR) = (GRAPH)->edge_list[x_]); \
(void) ((LOCUS) = (GRAPH)->edge_locus[x_ / 2]); \
CODE; \
} \
} while (0)

Find all the nodes which are predecessors of NODE in the edge list for GRAPH. VAR will hold the partition number found. CODE is the code fragment executed for every node found.

Referenced by elim_unvisited_predecessor().

#define FOR_EACH_ELIM_GRAPH_SUCC (   GRAPH,
  NODE,
  VAR,
  LOCUS,
  CODE 
)
Value:
do { \
unsigned x_; \
int y_; \
for (x_ = 0; x_ < (GRAPH)->edge_list.length (); x_ += 2) \
{ \
y_ = (GRAPH)->edge_list[x_]; \
if (y_ != (NODE)) \
continue; \
(void) ((VAR) = (GRAPH)->edge_list[x_ + 1]); \
(void) ((LOCUS) = (GRAPH)->edge_locus[x_ / 2]); \
CODE; \
} \
} while (0)

Find all the nodes in GRAPH which are successors to NODE in the edge list. VAR will hold the partition number found. CODE is the code fragment executed for every node found.

Referenced by eliminate_build().


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 FOR_EACH_VEC_ELT, and _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(), POINTER_TYPE_P, promote_decl_mode(), reg_mode, SSA_NAME_VAR, TREE_CODE, TREE_TYPE, and TYPE_ALIGN.

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, _elim_graph::edge_locus, and UNKNOWN_LOCATION.

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(), FOR_EACH_ELIM_GRAPH_SUCC, S, _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, FOR_EACH_PHI_ARG, gsi_for_stmt(), has_zero_uses(), NULL_TREE, print_gimple_stmt(), remove_gimple_phi_args(), remove_phi_node(), SET_USE, SSA_NAME_DEF_STMT, SSA_OP_USE, TDF_SLIM, TREE_CODE, and USE_FROM_PTR.

static void eliminate_useless_phis ( )
static
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(), gcc_assert, 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(), edge_def::src, TREE_TYPE, and TYPE_UNSIGNED.

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 FOR_EACH_IMM_USE_FAST, gimple_uid(), is_gimple_debug(), maybe_renumber_stmts_bb(), SSA_NAME_DEF_STMT, and USE_STMT.

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.

References ei_next(), edge_def::insns, NULL_RTX, 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 ( )

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_build_assign, 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, NULL, SSA_NAME_DEF_STMT, stmt_ends_bb_p(), and TREE_CODE.