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

Data Structures

struct  coalesce_pair
struct  coalesce_pair_hasher
struct  cost_one_pair_d
struct  coalesce_list_d
struct  ssa_conflicts_d
struct  live_track_d
struct  ssa_name_var_hash

Typedefs

typedef struct coalesce_paircoalesce_pair_p
typedef struct coalesce_pairconst_coalesce_pair_p
typedef hash_table
< coalesce_pair_hasher
coalesce_table_type
typedef
coalesce_table_type::iterator 
coalesce_iterator_type
typedef struct cost_one_pair_dcost_one_pair_p
typedef struct coalesce_list_dcoalesce_list_p
typedef struct ssa_conflicts_dssa_conflicts_p
typedef struct live_track_dlive_track_p

Functions

static int coalesce_cost ()
static int coalesce_cost_bb ()
static int coalesce_cost_edge ()
static int pop_cost_one_pair ()
static int pop_best_coalesce ()
static coalesce_list_p create_coalesce_list ()
static void delete_coalesce_list ()
static coalesce_pair_p find_coalesce_pair ()
static void add_cost_one_coalesce ()
static void add_coalesce ()
static int compare_pairs ()
static int num_coalesce_pairs ()
static void sort_coalesce_list ()
static void dump_coalesce_list ()
static ssa_conflicts_p ssa_conflicts_new ()
static void ssa_conflicts_delete ()
static bool ssa_conflicts_test_p ()
static void ssa_conflicts_add_one ()
static void ssa_conflicts_add ()
static void ssa_conflicts_merge ()
static void ssa_conflicts_dump ()
static live_track_p new_live_track ()
static void delete_live_track ()
static void live_track_remove_partition ()
static void live_track_add_partition ()
static void live_track_clear_var ()
static bool live_track_live_p ()
static void live_track_process_use ()
static void live_track_process_def ()
static void live_track_init ()
static void live_track_clear_base_vars ()
static ssa_conflicts_p build_ssa_conflict_graph ()
static void print_exprs (FILE *f, const char *str1, tree expr1, const char *str2, tree expr2, const char *str3)
static void fail_abnormal_edge_coalesce ()
static var_map create_outofssa_var_map ()
static bool attempt_coalesce (var_map map, ssa_conflicts_p graph, int x, int y, FILE *debug)
static void coalesce_partitions (var_map map, ssa_conflicts_p graph, coalesce_list_p cl, FILE *debug)
var_map coalesce_ssa_name ()
bool gimple_can_coalesce_p ()

Typedef Documentation

typedef coalesce_table_type::iterator coalesce_iterator_type
typedef struct coalesce_list_d * coalesce_list_p
This structure maintains the list of coalesce pairs.   
typedef struct coalesce_pair * coalesce_pair_p
@verbatim Coalesce SSA_NAMES together for the out-of-ssa pass.

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

This set of routines implements a coalesce_list.  This is an object which
   is used to track pairs of ssa_names which are desirable to coalesce
   together to avoid copies.  Costs are associated with each pair, and when
   all desired information has been collected, the object can be used to
   order the pairs for processing.   
This structure defines a pair entry.   
typedef struct cost_one_pair_d * cost_one_pair_p
typedef struct live_track_d * live_track_p
This structure is used to efficiently record the current status of live
   SSA_NAMES when building a conflict graph.
   LIVE_BASE_VAR has a bit set for each base variable which has at least one
   ssa version live.
   LIVE_BASE_PARTITIONS is an array of bitmaps using the basevar table as an
   index, and is used to track what partitions of each base variable are
   live.  This makes it easy to add conflicts between just live partitions
   with the same base variable.
   The values in LIVE_BASE_PARTITIONS are only valid if the base variable is
   marked as being live.  This delays clearing of these bitmaps until
   they are actually needed again.   
typedef struct ssa_conflicts_d * ssa_conflicts_p
This represents a conflict graph.  Implemented as an array of bitmaps.
   A full matrix is used for conflicts rather than just upper triangular form.
   this make sit much simpler and faster to perform conflict merges.   

Function Documentation

static void add_coalesce ( )
inlinestatic
Add a coalesce between P1 and P2 in list CL with a cost of VALUE.   

References coalesce_pair::cost, find_coalesce_pair(), and coalesce_list_d::sorted.

Referenced by coalesce_ssa_name(), and create_outofssa_var_map().

static bool attempt_coalesce ( var_map  map,
ssa_conflicts_p  graph,
int  x,
int  y,
FILE *  debug 
)
inlinestatic
Attempt to coalesce ssa versions X and Y together using the partition
   mapping in MAP and checking conflicts in GRAPH.  Output any debug info to
   DEBUG, if it is nun-NULL.   

References partition_to_var(), print_generic_expr(), ssa_conflicts_merge(), ssa_conflicts_test_p(), var_to_partition(), and var_union().

Referenced by coalesce_partitions().

static ssa_conflicts_p build_ssa_conflict_graph ( )
static
Build a conflict graph based on LIVEINFO.  Any partitions which are in the
   partition view of the var_map liveinfo is based on get entries in the
   conflict graph.  Only conflicts between ssa_name partitions with the same
   base variable are added.   

References delete_live_track(), gimple_assign_copy_p(), gimple_assign_lhs(), gimple_assign_rhs1(), graph, gsi_end_p(), gsi_last_bb(), gsi_next(), gsi_prev(), gsi_start_phis(), gsi_stmt(), is_gimple_assign(), is_gimple_debug(), live, live_on_exit(), live_track_clear_base_vars(), live_track_clear_var(), live_track_init(), live_track_live_p(), live_track_process_def(), live_track_process_use(), live_var_map(), map, new_live_track(), num_var_partitions(), and ssa_conflicts_new().

Referenced by coalesce_ssa_name().

static int coalesce_cost ( )
inlinestatic
Return cost of execution of copy instruction with FREQUENCY.   

References frequency.

Referenced by coalesce_cost_bb(), coalesce_cost_edge(), and create_outofssa_var_map().

static int coalesce_cost_bb ( )
inlinestatic
Return the cost of executing a copy instruction in basic block BB.   

References coalesce_cost(), basic_block_def::frequency, and optimize_bb_for_size_p().

Referenced by create_outofssa_var_map().

static int coalesce_cost_edge ( )
inlinestatic
Return the cost of executing a copy instruction on edge E.   

References coalesce_cost(), edge_def::dest, edge_def::flags, mult, optimize_edge_for_size_p(), and basic_block_def::preds.

Referenced by create_outofssa_var_map().

static void coalesce_partitions ( var_map  map,
ssa_conflicts_p  graph,
coalesce_list_p  cl,
FILE *  debug 
)
static
Attempt to Coalesce partitions in MAP which occur in the list CL using
   GRAPH.  Debug output is sent to DEBUG if it is non-NULL.   

References attempt_coalesce(), edge_def::dest_idx, fail_abnormal_edge_coalesce(), edge_def::flags, gimple_can_coalesce_p(), gsi_end_p(), gsi_next(), gsi_start_phis(), gsi_stmt(), pop_best_coalesce(), and basic_block_def::preds.

Referenced by coalesce_ssa_name().

static int compare_pairs ( )
static
Comparison function to allow qsort to sort P1 and P2 in Ascending order.   

References coalesce_pair::cost.

Referenced by sort_coalesce_list().

static coalesce_list_p create_coalesce_list ( )
inlinestatic
static void delete_coalesce_list ( )
inlinestatic
static void delete_live_track ( )
static
This routine will free the memory associated with PTR.   

References bitmap_obstack_release(), free(), live_track_d::live_base_partitions, and live_track_d::obstack.

Referenced by build_ssa_conflict_graph().

static void dump_coalesce_list ( )
static
static void fail_abnormal_edge_coalesce ( )
inlinestatic
Print a failure to coalesce a MUST_COALESCE pair X and Y.   

References internal_error(), print_generic_expr(), and print_generic_stmt().

Referenced by coalesce_partitions().

static coalesce_pair_p find_coalesce_pair ( )
static
Find a matching coalesce pair object in CL for the pair P1 and P2.  If
   one isn't found, return NULL if CREATE is false, otherwise create a new
   coalesce pair object and return it.   

References coalesce_pair::cost, hash_table< Descriptor, Allocator >::find_slot_with_hash(), coalesce_pair::first_element, coalesce_pair_hasher::hash(), coalesce_list_d::list, coalesce_pair::second_element, and coalesce_list_d::sorted.

Referenced by add_coalesce().

bool gimple_can_coalesce_p ( )
Given SSA_NAMEs NAME1 and NAME2, return true if they are candidates for
   coalescing together, false otherwise.

   This must stay consistent with var_map_base_init in tree-ssa-live.c.   

References types_compatible_p().

static void live_track_add_partition ( )
inlinestatic
static void live_track_clear_base_vars ( )
inlinestatic
This routine will clear all live partitions in PTR.    

References bitmap_clear(), and live_track_d::live_base_var.

Referenced by build_ssa_conflict_graph().

static void live_track_clear_var ( )
inlinestatic
Clear the live bit for VAR in PTR.   

References live_track_remove_partition(), live_track_d::map, and var_to_partition().

Referenced by build_ssa_conflict_graph().

static void live_track_init ( )
inlinestatic
Initialize PTR with the partitions set in INIT.   

References live_track_add_partition().

Referenced by build_ssa_conflict_graph().

static bool live_track_live_p ( )
inlinestatic
static void live_track_process_def ( )
inlinestatic
This routine will process a DEF in PTR.  DEF will be removed from the live
   lists, and if there are any other live partitions with the same base
   variable, conflicts will be added to GRAPH.   

References basevar_index(), bitmap_bit_p(), live_track_d::live_base_partitions, live_track_d::live_base_var, live_track_remove_partition(), live_track_d::map, ssa_conflicts_add(), and var_to_partition().

Referenced by build_ssa_conflict_graph().

static void live_track_process_use ( )
inlinestatic
This routine will add USE to PTR.  USE will be marked as live in both the
   ssa live map and the live bitmap for the root of USE.   

References live_track_add_partition(), live_track_d::map, and var_to_partition().

Referenced by build_ssa_conflict_graph().

static void live_track_remove_partition ( )
inlinestatic
static live_track_p new_live_track ( )
static
static int num_coalesce_pairs ( )
inlinestatic
Return the number of unique coalesce pairs in CL.   

References hash_table< Descriptor, Allocator >::elements(), and coalesce_list_d::list.

Referenced by sort_coalesce_list().

static int pop_best_coalesce ( )
inlinestatic
Retrieve the most expensive remaining pair to coalesce from CL.  Returns the
   2 elements via P1 and P2.  Their calculated cost is returned by the function.
   NO_BEST_COALESCE is returned if the coalesce list is empty.   

References coalesce_pair::cost, coalesce_pair::first_element, free(), coalesce_list_d::num_sorted, pop_cost_one_pair(), coalesce_pair::second_element, and coalesce_list_d::sorted.

Referenced by coalesce_partitions().

static int pop_cost_one_pair ( )
inlinestatic
Retrieve a pair to coalesce from the cost_one_list in CL.  Returns the
   2 elements via P1 and P2.  1 is returned by the function if there is a pair,
   NO_BEST_COALESCE is returned if there aren't any.   

References coalesce_list_d::cost_one_list, cost_one_pair_d::first_element, free(), cost_one_pair_d::next, and cost_one_pair_d::second_element.

Referenced by pop_best_coalesce().

static void print_exprs ( FILE *  f,
const char *  str1,
tree  expr1,
const char *  str2,
tree  expr2,
const char *  str3 
)
inlinestatic
Shortcut routine to print messages to file F of the form:
   "STR1 EXPR1 STR2 EXPR2 STR3."   

References print_generic_expr().

static void sort_coalesce_list ( )
static
Prepare CL for removal of preferred pairs.  When finished they are sorted
   in order from most important coalesce to least important.   

References compare_pairs(), coalesce_pair::cost, num_coalesce_pairs(), coalesce_list_d::num_sorted, and coalesce_list_d::sorted.

Referenced by coalesce_ssa_name().

static void ssa_conflicts_add ( )
inlinestatic
Add conflicts between X and Y in graph PTR.   

References ssa_conflicts_add_one().

Referenced by live_track_process_def().

static void ssa_conflicts_add_one ( )
inlinestatic
Add a conflict with Y to the bitmap for X in graph PTR.   

References bitmap_set_bit(), ssa_conflicts_d::conflicts, and ssa_conflicts_d::obstack.

Referenced by ssa_conflicts_add().

static void ssa_conflicts_delete ( )
inlinestatic
Free storage for conflict graph PTR.   

References bitmap_obstack_release(), ssa_conflicts_d::conflicts, free(), and ssa_conflicts_d::obstack.

Referenced by coalesce_ssa_name().

static void ssa_conflicts_dump ( )
static
Dump a conflicts graph.   

References ssa_conflicts_d::conflicts, and dump_bitmap().

Referenced by coalesce_ssa_name().

static void ssa_conflicts_merge ( )
inlinestatic
Merge all Y's conflict into X in graph PTR.   

References bitmap_ior_into(), bitmap_set_bit(), and ssa_conflicts_d::conflicts.

Referenced by attempt_coalesce().

static ssa_conflicts_p ssa_conflicts_new ( )
inlinestatic
Return an empty new conflict graph for SIZE elements.   

References bitmap_obstack_initialize(), ssa_conflicts_d::conflicts, and ssa_conflicts_d::obstack.

Referenced by build_ssa_conflict_graph().

static bool ssa_conflicts_test_p ( )
inlinestatic
Test if elements X and Y conflict in graph PTR.   

References bitmap_bit_p(), and ssa_conflicts_d::conflicts.

Referenced by attempt_coalesce().