GCC Middle and Back End API Reference
tree-ssa-coalesce.cc File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "backend.h"
#include "tree.h"
#include "gimple.h"
#include "predict.h"
#include "memmodel.h"
#include "tm_p.h"
#include "ssa.h"
#include "tree-ssa.h"
#include "tree-pretty-print.h"
#include "diagnostic-core.h"
#include "dumpfile.h"
#include "gimple-iterator.h"
#include "tree-ssa-live.h"
#include "tree-ssa-coalesce.h"
#include "explow.h"
#include "tree-dfa.h"
#include "stor-layout.h"
#include "gimple-lower-bitint.h"
Include dependency graph for tree-ssa-coalesce.cc:

Data Structures

struct  coalesce_pair
 
struct  ssa_conflicts
 
struct  coalesce_pair_hasher
 
struct  cost_one_pair
 
struct  coalesce_list
 
class  live_track
 
struct  ssa_name_var_hash
 

Macros

#define NO_BEST_COALESCE   -1
 
#define MUST_COALESCE_COST   INT_MAX
 
#define FOR_EACH_PARTITION_PAIR(PAIR, ITER, CL)
 

Typedefs

typedef hash_table< coalesce_pair_hashercoalesce_table_type
 
typedef coalesce_table_type::iterator coalesce_iterator_type
 

Functions

static int coalesce_cost (int frequency, bool optimize_for_size)
 
static int coalesce_cost_bb (basic_block bb)
 
static int coalesce_cost_edge (edge e)
 
static int pop_cost_one_pair (coalesce_list *cl, int *p1, int *p2)
 
static int pop_best_coalesce (coalesce_list *cl, int *p1, int *p2)
 
static coalesce_listcreate_coalesce_list (void)
 
static void delete_coalesce_list (coalesce_list *cl)
 
static int num_coalesce_pairs (coalesce_list *cl)
 
static coalesce_pairfind_coalesce_pair (coalesce_list *cl, int p1, int p2, bool create)
 
static void add_cost_one_coalesce (coalesce_list *cl, int p1, int p2)
 
static void add_coalesce (coalesce_list *cl, int p1, int p2, int value)
 
static void initialize_conflict_count (coalesce_pair *p, ssa_conflicts *conflicts, var_map map)
 
static int compare_pairs (const void *p1, const void *p2)
 
static void sort_coalesce_list (coalesce_list *cl, ssa_conflicts *conflicts, var_map map)
 
static void dump_coalesce_list (FILE *f, coalesce_list *cl)
 
static ssa_conflictsssa_conflicts_new (unsigned size)
 
static void ssa_conflicts_delete (ssa_conflicts *ptr)
 
static bool ssa_conflicts_test_p (ssa_conflicts *ptr, unsigned x, unsigned y)
 
static void ssa_conflicts_add_one (ssa_conflicts *ptr, unsigned x, unsigned y)
 
static void ssa_conflicts_add (ssa_conflicts *ptr, unsigned x, unsigned y)
 
static void ssa_conflicts_merge (ssa_conflicts *ptr, unsigned x, unsigned y)
 
static void ssa_conflicts_dump (FILE *file, ssa_conflicts *ptr)
 
static live_tracknew_live_track (var_map map)
 
static void delete_live_track (live_track *ptr)
 
static void live_track_remove_partition (live_track *ptr, int partition)
 
static void live_track_add_partition (live_track *ptr, int partition)
 
static void live_track_clear_var (live_track *ptr, tree var)
 
static bool live_track_live_p (live_track *ptr, tree var)
 
static void live_track_process_use (live_track *ptr, tree use)
 
static void live_track_process_def (live_track *ptr, tree def, ssa_conflicts *graph)
 
static void live_track_init (live_track *ptr, bitmap init)
 
static void live_track_clear_base_vars (live_track *ptr)
 
static ssa_conflictsbuild_ssa_conflict_graph (tree_live_info_p liveinfo)
 
static void fail_abnormal_edge_coalesce (int x, int y)
 
static void coalesce_with_default (tree var, coalesce_list *cl, bitmap used_in_copy)
 
static coalesce_listcreate_coalesce_list_for_region (var_map map, bitmap used_in_copy)
 
static void populate_coalesce_list_for_outofssa (coalesce_list *cl, bitmap used_in_copy)
 
static bool attempt_coalesce (var_map map, ssa_conflicts *graph, int x, int y, FILE *debug)
 
static void coalesce_partitions (var_map map, ssa_conflicts *graph, coalesce_list *cl, FILE *debug)
 
void dump_part_var_map (FILE *f, partition part, var_map map)
 
bool gimple_can_coalesce_p (tree name1, tree name2)
 
static void compute_optimized_partition_bases (var_map map, bitmap used_in_copies, coalesce_list *cl)
 
static void coalesce_bitint (var_map map, ssa_conflicts *graph)
 
void coalesce_ssa_name (var_map map)
 

Variables

static ssa_conflictsconflicts_
 
static var_map map_
 

Macro Definition Documentation

◆ FOR_EACH_PARTITION_PAIR

#define FOR_EACH_PARTITION_PAIR ( PAIR,
ITER,
CL )
Value:
FOR_EACH_HASH_TABLE_ELEMENT (*(CL)->list, (PAIR), coalesce_pair_p, (ITER))
#define FOR_EACH_HASH_TABLE_ELEMENT(HTAB, RESULT, TYPE, ITER)
Definition hash-table.h:1231
#define PAIR(a, b)
Definition tree-complex.cc:67
Iterate over CL using ITER, returning values in PAIR.   

Referenced by compute_optimized_partition_bases(), dump_coalesce_list(), and sort_coalesce_list().

◆ MUST_COALESCE_COST

#define MUST_COALESCE_COST   INT_MAX

◆ NO_BEST_COALESCE

#define NO_BEST_COALESCE   -1

Typedef Documentation

◆ coalesce_iterator_type

◆ coalesce_table_type

Function Documentation

◆ add_coalesce()

static void add_coalesce ( coalesce_list * cl,
int p1,
int p2,
int value )
inlinestatic
Add a coalesce between P1 and P2 in list CL with a cost of VALUE.   

References coalesce_pair::cost, find_coalesce_pair(), gcc_assert, MUST_COALESCE_COST, NULL, and coalesce_list::sorted.

Referenced by create_coalesce_list_for_region(), and populate_coalesce_list_for_outofssa().

◆ add_cost_one_coalesce()

static void add_cost_one_coalesce ( coalesce_list * cl,
int p1,
int p2 )
inlinestatic

◆ attempt_coalesce()

static bool attempt_coalesce ( var_map map,
ssa_conflicts * 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 debug, map, NO_PARTITION, partition_to_var(), print_generic_expr(), ssa_conflicts_merge(), ssa_conflicts_test_p(), ssa_name, TDF_SLIM, var_to_partition(), var_union(), and y.

Referenced by coalesce_bitint(), and coalesce_partitions().

◆ build_ssa_conflict_graph()

◆ coalesce_bitint()

static void coalesce_bitint ( var_map map,
ssa_conflicts * graph )
static
For the bitint lowering pass, try harder.  Partitions which contain
SSA_NAME default def of a PARM_DECL or have RESULT_DECL need to have
compatible types because they will use that RESULT_DECL or PARM_DECL.
Other partitions can have even incompatible _BitInt types, as long
as they have the same size - those will use VAR_DECLs which are just
arrays of the limbs.   

References attempt_coalesce(), BITMAP_ALLOC, bitmap_bit_p, BITMAP_FREE, bitmap_set_bit, dump_file, dump_flags, EXECUTE_IF_SET_IN_BITMAP, i, map, NULL, num_var_partitions(), partition_to_var(), ssa_name, SSA_NAME_IS_DEFAULT_DEF, SSA_NAME_VAR, SSA_NAME_VERSION, TDF_DETAILS, TREE_CODE, tree_int_cst_equal(), TREE_TYPE, TYPE_SIZE, types_compatible_p(), and var_to_partition().

Referenced by coalesce_ssa_name().

◆ coalesce_cost()

static int coalesce_cost ( int frequency,
bool optimize_for_size )
inlinestatic
Return cost of execution of copy instruction with FREQUENCY.   

References frequency.

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

◆ coalesce_cost_bb()

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

References cfun, coalesce_cost(), basic_block_def::count, optimize_bb_for_size_p(), and profile_count::to_frequency().

Referenced by create_coalesce_list_for_region(), and populate_coalesce_list_for_outofssa().

◆ coalesce_cost_edge()

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

References coalesce_cost(), EDGE_CRITICAL_P, EDGE_FREQUENCY, FOR_EACH_EDGE, MUST_COALESCE_COST, and optimize_edge_for_size_p().

Referenced by create_coalesce_list_for_region().

◆ coalesce_partitions()

static void coalesce_partitions ( var_map map,
ssa_conflicts * graph,
coalesce_list * cl,
FILE * debug )
static

◆ coalesce_ssa_name()

◆ coalesce_with_default()

static void coalesce_with_default ( tree var,
coalesce_list * cl,
bitmap used_in_copy )
static
If VAR is an SSA_NAME associated with a PARM_DECL or a RESULT_DECL,
and the DECL's default def is unused (i.e., it was introduced by
create_default_def for out-of-ssa), mark VAR and the default def for
coalescing.   

References add_cost_one_coalesce(), bitmap_set_bit, cfun, has_zero_uses(), ssa_default_def(), SSA_NAME_IS_DEFAULT_DEF, SSA_NAME_VAR, SSA_NAME_VERSION, and VAR_P.

Referenced by populate_coalesce_list_for_outofssa().

◆ compare_pairs()

static int compare_pairs ( const void * p1,
const void * p2 )
static
Comparison function to allow qsort to sort P1 and P2 in Ascending order.   

References conflicts_, coalesce_pair::cost, initialize_conflict_count(), and map_.

Referenced by sort_coalesce_list().

◆ compute_optimized_partition_bases()

static void compute_optimized_partition_bases ( var_map map,
bitmap used_in_copies,
coalesce_list * cl )
static

◆ create_coalesce_list()

static coalesce_list * create_coalesce_list ( void )
inlinestatic

◆ create_coalesce_list_for_region()

◆ delete_coalesce_list()

static void delete_coalesce_list ( coalesce_list * cl)
inlinestatic

◆ delete_live_track()

static void delete_live_track ( live_track * ptr)
static
This routine will free the memory associated with PTR.   

References bitmap_obstack_release(), live_track::live_base_partitions, and live_track::obstack.

Referenced by build_ssa_conflict_graph().

◆ dump_coalesce_list()

◆ dump_part_var_map()

void dump_part_var_map ( FILE * f,
partition part,
var_map map )

◆ fail_abnormal_edge_coalesce()

static void fail_abnormal_edge_coalesce ( int x,
int y )
inlinestatic
Print a failure to coalesce a MUST_COALESCE pair X and Y.   

References internal_error(), print_generic_expr(), print_generic_stmt(), ssa_name, TDF_SLIM, and y.

Referenced by coalesce_partitions().

◆ find_coalesce_pair()

static coalesce_pair * find_coalesce_pair ( coalesce_list * cl,
int p1,
int p2,
bool create )
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 hash_table< Descriptor, Lazy, Allocator >::find_slot_with_hash(), coalesce_pair::first_element, gcc_assert, coalesce_pair_hasher::hash(), coalesce_list::list, NULL, num_coalesce_pairs(), coalesce_list::ob, coalesce_pair::second_element, and coalesce_list::sorted.

Referenced by add_coalesce().

◆ gimple_can_coalesce_p()

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

This must stay consistent with compute_samebase_partition_bases and
compute_optimized_partition_bases.   

References DECL_IGNORED_P, DECL_MODE, LOCAL_DECL_ALIGNMENT, MINIMUM_ALIGNMENT, NULL_TREE, promote_ssa_mode(), SSA_NAME_VAR, TREE_TYPE, TYPE_ALIGN, TYPE_MODE, types_compatible_p(), use_register_for_decl(), and VAR_P.

Referenced by coalesce_partitions(), create_coalesce_list_for_region(), populate_coalesce_list_for_outofssa(), and uncprop_into_successor_phis().

◆ initialize_conflict_count()

static void initialize_conflict_count ( coalesce_pair * p,
ssa_conflicts * conflicts,
var_map map )
static
Compute and record how many unique conflicts would exist for the
representative partition for each coalesce pair in CL.

CONFLICTS is the conflict graph and MAP is the current partition view.   

References bitmap_count_bits(), bitmap_count_unique_bits(), coalesce_pair::conflict_count, conflicts, coalesce_pair::first_element, map, coalesce_pair::second_element, ssa_name, and var_to_partition().

Referenced by compare_pairs().

◆ live_track_add_partition()

static void live_track_add_partition ( live_track * ptr,
int partition )
inlinestatic
This function will adds PARTITION to the live list in PTR.   

References basevar_index(), bitmap_clear(), bitmap_set_bit, live_track::live_base_partitions, live_track::live_base_var, and live_track::map.

Referenced by live_track_init(), and live_track_process_use().

◆ live_track_clear_base_vars()

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

References bitmap_clear(), and live_track::live_base_var.

Referenced by build_ssa_conflict_graph().

◆ live_track_clear_var()

static void live_track_clear_var ( live_track * ptr,
tree var )
inlinestatic
Clear the live bit for VAR in PTR.   

References live_track_remove_partition(), live_track::map, NO_PARTITION, and var_to_partition().

Referenced by build_ssa_conflict_graph().

◆ live_track_init()

static void live_track_init ( live_track * ptr,
bitmap init )
inlinestatic
Initialize PTR with the partitions set in INIT.   

References EXECUTE_IF_SET_IN_BITMAP, and live_track_add_partition().

Referenced by build_ssa_conflict_graph().

◆ live_track_live_p()

static bool live_track_live_p ( live_track * ptr,
tree var )
inlinestatic

◆ live_track_process_def()

static void live_track_process_def ( live_track * ptr,
tree def,
ssa_conflicts * graph )
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 b, basevar_index(), bitmap_bit_p, EXECUTE_IF_SET_IN_BITMAP, live_track::live_base_partitions, live_track::live_base_var, live_track_remove_partition(), live_track::map, NO_PARTITION, ssa_conflicts_add(), and var_to_partition().

Referenced by build_ssa_conflict_graph().

◆ live_track_process_use()

static void live_track_process_use ( live_track * ptr,
tree 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::map, NO_PARTITION, and var_to_partition().

Referenced by build_ssa_conflict_graph().

◆ live_track_remove_partition()

static void live_track_remove_partition ( live_track * ptr,
int partition )
inlinestatic
This function will remove PARTITION from the live list in PTR.   

References basevar_index(), bitmap_clear_bit(), bitmap_empty_p(), live_track::live_base_partitions, live_track::live_base_var, and live_track::map.

Referenced by live_track_clear_var(), and live_track_process_def().

◆ new_live_track()

static live_track * new_live_track ( var_map map)
static
This routine will create a new live track structure based on the partitions
in MAP.   

References bitmap_initialize(), bitmap_obstack_initialize(), gcc_assert, live_track::live_base_partitions, live_track::live_base_var, live_track::map, map, NULL, num_basevars(), and live_track::obstack.

Referenced by build_ssa_conflict_graph().

◆ num_coalesce_pairs()

static int num_coalesce_pairs ( coalesce_list * cl)
inlinestatic
Return the number of unique coalesce pairs in CL.   

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

Referenced by find_coalesce_pair(), and sort_coalesce_list().

◆ pop_best_coalesce()

static int pop_best_coalesce ( coalesce_list * cl,
int * p1,
int * p2 )
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, NULL, coalesce_list::num_sorted, pop_cost_one_pair(), coalesce_pair::second_element, and coalesce_list::sorted.

Referenced by coalesce_partitions().

◆ pop_cost_one_pair()

static int pop_cost_one_pair ( coalesce_list * cl,
int * p1,
int * p2 )
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::cost_one_list, cost_one_pair::first_element, cost_one_pair::next, NO_BEST_COALESCE, and cost_one_pair::second_element.

Referenced by pop_best_coalesce().

◆ populate_coalesce_list_for_outofssa()

static void populate_coalesce_list_for_outofssa ( coalesce_list * cl,
bitmap used_in_copy )
static

◆ sort_coalesce_list()

static void sort_coalesce_list ( coalesce_list * cl,
ssa_conflicts * conflicts,
var_map map )
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(), conflicts, conflicts_, FOR_EACH_PARTITION_PAIR, gcc_assert, map, map_, NULL, num_coalesce_pairs(), coalesce_list::num_sorted, qsort, and coalesce_list::sorted.

Referenced by coalesce_ssa_name().

◆ ssa_conflicts_add()

static void ssa_conflicts_add ( ssa_conflicts * ptr,
unsigned x,
unsigned y )
inlinestatic
Add conflicts between X and Y in graph PTR.   

References gcc_checking_assert, ssa_conflicts_add_one(), and y.

Referenced by live_track_process_def().

◆ ssa_conflicts_add_one()

static void ssa_conflicts_add_one ( ssa_conflicts * ptr,
unsigned x,
unsigned y )
inlinestatic
Add a conflict with Y to the bitmap for X in graph PTR.   

References BITMAP_ALLOC, bitmap_set_bit, ssa_conflicts::conflicts, ssa_conflicts::obstack, and y.

Referenced by ssa_conflicts_add().

◆ ssa_conflicts_delete()

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

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

Referenced by coalesce_ssa_name().

◆ ssa_conflicts_dump()

static void ssa_conflicts_dump ( FILE * file,
ssa_conflicts * ptr )
static
Dump a conflicts graph.   

References b, ssa_conflicts::conflicts, dump_bitmap(), and FOR_EACH_VEC_ELT.

Referenced by coalesce_ssa_name().

◆ ssa_conflicts_merge()

static void ssa_conflicts_merge ( ssa_conflicts * ptr,
unsigned x,
unsigned y )
inlinestatic

◆ ssa_conflicts_new()

static ssa_conflicts * ssa_conflicts_new ( unsigned size)
inlinestatic
Return an empty new conflict graph for SIZE elements.   

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

Referenced by build_ssa_conflict_graph().

◆ ssa_conflicts_test_p()

static bool ssa_conflicts_test_p ( ssa_conflicts * ptr,
unsigned x,
unsigned y )
inlinestatic
Test if elements X and Y conflict in graph PTR.   

References bitmap_bit_p, ssa_conflicts::conflicts, gcc_checking_assert, and y.

Referenced by attempt_coalesce().

Variable Documentation

◆ conflicts_

ssa_conflicts* conflicts_
static
The narrow API of the qsort comparison function doesn't allow easy
access to additional arguments.  So we have two globals (ick) to hold
the data we need.  They're initialized before the call to qsort and
wiped immediately after.   

Referenced by compare_pairs(), and sort_coalesce_list().

◆ map_

var_map map_
static