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

Data Structures

struct  dref_d
struct  chain
struct  component
struct  epcc_data

Typedefs

typedef struct dref_ddref
typedef struct chainchain_p

Enumerations

enum  chain_type { CT_INVARIANT, CT_LOAD, CT_STORE_LOAD, CT_COMBINATION }
enum  ref_step_type { RS_INVARIANT, RS_NONZERO, RS_ANY }

Functions

void dump_dref (FILE *, dref)
void dump_dref ()
void dump_chain (FILE *, chain_p)
void dump_chain ()
void dump_chains (FILE *, vec< chain_p >)
void dump_chains ()
void dump_component (FILE *, struct component *)
void dump_component ()
void dump_components (FILE *, struct component *)
void dump_components ()
static void release_chain ()
static void release_chains ()
static void release_component ()
static void release_components ()
static unsigned component_of ()
static void merge_comps ()
static bool suitable_reference_p ()
static void aff_combination_dr_offset ()
static bool determine_offset (struct data_reference *a, struct data_reference *b, double_int *off)
static basic_block last_always_executed_block ()
static struct componentsplit_data_refs_to_components (struct loop *loop, vec< data_reference_p > datarefs, vec< ddr_p > depends)
static bool suitable_component_p ()
static struct componentfilter_suitable_components ()
static int order_drefs ()
static dref get_chain_root ()
static void add_ref_to_chain ()
static chain_p make_invariant_chain ()
static chain_p make_rooted_chain ()
static bool nontrivial_chain_p ()
static tree name_for_ref ()
static bool valid_initializer_p (struct data_reference *ref, unsigned distance, struct data_reference *root)
static gimple find_looparound_phi ()
static void insert_looparound_copy ()
static void add_looparound_copies ()
static void determine_roots_comp (struct loop *loop, struct component *comp, vec< chain_p > *chains)
static void determine_roots (struct loop *loop, struct component *comps, vec< chain_p > *chains)
static void replace_ref_with ()
static tree ref_at_iteration ()
static tree get_init_expr ()
static tree predcom_tmp_var ()
static void initialize_root_vars ()
static void initialize_root ()
static void initialize_root_vars_lm (struct loop *loop, dref root, bool written, vec< tree > *vars, vec< tree > inits, bitmap tmp_vars)
static void execute_load_motion ()
static gimple single_nonlooparound_use ()
static void remove_stmt ()
static void execute_pred_commoning_chain (struct loop *loop, chain_p chain, bitmap tmp_vars)
static unsigned determine_unroll_factor ()
static void execute_pred_commoning (struct loop *loop, vec< chain_p > chains, bitmap tmp_vars)
static void replace_phis_by_defined_names ()
static void replace_names_by_phis ()
static void execute_pred_commoning_cbck ()
static void base_names_in_chain_on ()
static void eliminate_temp_copies ()
static bool chain_can_be_combined_p ()
static gimple find_use_stmt ()
static bool may_reassociate_p ()
static gimple find_associative_operation_root ()
static gimple find_common_use_stmt ()
static bool combinable_refs_p (dref r1, dref r2, enum tree_code *code, bool *swap, tree *rslt_type)
static void remove_name_from_operation ()
static gimple reassociate_to_the_same_stmt ()
static gimple stmt_combining_refs ()
static chain_p combine_chains ()
static void try_combine_chains ()
static bool prepare_initializers_chain ()
static void prepare_initializers ()
static bool tree_predictive_commoning_loop ()
unsigned tree_predictive_commoning ()

Variables

static bitmap looparound_phis
static struct pointer_map_tname_expansions

Typedef Documentation

typedef struct chain * chain_p
Chains of data references.   
typedef struct dref_d * dref
Data references (or phi nodes that carry data reference values across
   loop iterations).   

Enumeration Type Documentation

enum chain_type
Type of the chain of the references.   
Enumerator:
CT_INVARIANT 
CT_LOAD 
CT_STORE_LOAD 
CT_COMBINATION 
Describes the knowledge about the step of the memory references in
   the component.   
Enumerator:
RS_INVARIANT 
RS_NONZERO 
RS_ANY 

Function Documentation

static void add_looparound_copies ( )
static
For references in CHAIN that are copied around the LOOP (created previously
   by PRE, or by user), add the results of such copies to the chain.  This
   enables us to remove the copies by unrolling, and may need less registers
   (also, it may allow us to combine chains together).   

References bitmap_set_bit(), find_looparound_phi(), get_chain_root(), insert_looparound_copy(), data_reference::ref, and chain::refs.

Referenced by determine_roots_comp().

static void aff_combination_dr_offset ( )
static
static void base_names_in_chain_on ( )
static
Base NAME and all the names in the chain of phi nodes that use it
   on variable VAR.  The phi nodes are recognized by being in the copies of
   the header of the LOOP.   

References flow_bb_inside_loop_p(), and replace_ssa_name_symbol().

Referenced by eliminate_temp_copies().

static bool chain_can_be_combined_p ( )
static
Returns true if CHAIN is suitable to be combined.   

References chain::combined, CT_COMBINATION, CT_LOAD, and chain::type.

Referenced by try_combine_chains().

static bool combinable_refs_p ( dref  r1,
dref  r2,
enum tree_code code,
bool *  swap,
tree rslt_type 
)
static
Checks whether R1 and R2 are combined together using CODE, with the result
   in RSLT_TYPE, in order R1 CODE R2 if SWAP is false and in order R2 CODE R1
   if it is true.  If CODE is ERROR_MARK, set these values instead.   

References commutative_tree_code(), find_common_use_stmt(), gimple_assign_lhs(), gimple_assign_rhs1(), gimple_assign_rhs_code(), and name_for_ref().

Referenced by combine_chains().

static chain_p combine_chains ( )
static
Tries to combine chains CH1 and CH2 together.  If this succeeds, the
   description of the new chain is returned, otherwise we return NULL.   

References chain::ch1, chain::ch2, combinable_refs_p(), chain::combined, CT_COMBINATION, dref_d::distance, get_chain_root(), chain::has_max_use_after, chain::length, chain::op, chain::refs, chain::rslt_type, dref_d::stmt, stmt_combining_refs(), stmt_dominates_stmt_p(), swap(), and chain::type.

Referenced by try_combine_chains().

static unsigned component_of ( )
static
Finds a root of tree given by FATHERS containing A, and performs path
   shortening.   

Referenced by merge_comps(), and split_data_refs_to_components().

static bool determine_offset ( struct data_reference a,
struct data_reference b,
double_int off 
)
static
Determines number of iterations of the innermost enclosing loop before B
   refers to exactly the same location as A and stores it to OFF.  If A and
   B do not have the same step, they never meet, or anything else fails,
   returns false, otherwise returns true.  Both A and B are assumed to
   satisfy suitable_reference_p.   

References aff_combination_add(), aff_combination_constant_multiple_p(), aff_combination_dr_offset(), aff_combination_scale(), DR_BASE_ADDRESS, DR_INIT, DR_OFFSET, DR_REF, DR_STEP, integer_zerop(), operand_equal_p(), tree_to_aff_combination_expand(), and useless_type_conversion_p().

Referenced by split_data_refs_to_components(), and suitable_component_p().

static void determine_roots ( struct loop loop,
struct component comps,
vec< chain_p > *  chains 
)
static
Find roots of the values and determine distances in components COMPS, and
   separates the references to CHAINS.  LOOP is the current loop.   

References comp, determine_roots_comp(), and component::next.

Referenced by tree_predictive_commoning_loop().

static void determine_roots_comp ( struct loop loop,
struct component comp,
vec< chain_p > *  chains 
)
static
Find roots of the values and determine distances in the component COMP.
   The references are redistributed into CHAINS.  LOOP is the current
   loop.   

References add_looparound_copies(), add_ref_to_chain(), component::comp_step, DR_IS_WRITE, double_int::from_uhwi(), make_invariant_chain(), make_rooted_chain(), nontrivial_chain_p(), dref_d::offset, order_drefs(), dref_d::ref, component::refs, release_chain(), RS_INVARIANT, and double_int::ule().

Referenced by determine_roots().

static unsigned determine_unroll_factor ( )
static
Determines the unroll factor necessary to remove as many temporary variable
   copies as possible.  CHAINS is the list of chains that will be
   optimized.   

References chain::combined, CT_INVARIANT, gcd(), chain::has_max_use_after, chain::length, and chain::type.

Referenced by tree_predictive_commoning_loop().

void dump_chain ( FILE *  ,
chain_p   
)
Dumps CHAIN to FILE.   

Referenced by dump_chains().

void dump_chains ( FILE *  ,
vec< chain_p  
)
Dumps CHAINS to FILE.   

Referenced by tree_predictive_commoning_loop().

void dump_chains ( )

References dump_chain().

void dump_component ( FILE *  ,
struct component  
)
Dumps COMP to FILE.   

Referenced by dump_components().

void dump_component ( )
void dump_components ( FILE *  ,
struct component  
)
Dumps COMPS to FILE.   

Referenced by tree_predictive_commoning_loop().

void dump_components ( )
void dump_dref ( FILE *  ,
dref   
)
Dumps data reference REF to FILE.   

Referenced by dump_chain(), and dump_component().

static void eliminate_temp_copies ( )
static
Given an unrolled LOOP after predictive commoning, remove the
   register copies arising from phi nodes by changing the base
   variables of SSA names.  TMP_VARS is the set of the temporary variables
   for those we want to perform this.   

References base_names_in_chain_on(), bitmap_bit_p(), gsi_end_p(), gsi_next(), gsi_start_phis(), gsi_stmt(), loop::header, loop_latch_edge(), and single_pred_p().

Referenced by tree_predictive_commoning_loop().

static void execute_load_motion ( )
static
Execute load motion for references in chain CHAIN.  Uids of the newly
   created temporary variables are marked in TMP_VARS.   

References chain::combined, CT_INVARIANT, DR_IS_READ, DR_IS_WRITE, get_chain_root(), initialize_root_vars_lm(), chain::inits, make_ssa_name(), dref_d::ref, chain::refs, replace_ref_with(), dref_d::stmt, and chain::type.

Referenced by execute_pred_commoning().

static void execute_pred_commoning ( struct loop loop,
vec< chain_p chains,
bitmap  tmp_vars 
)
static
Perform the predictive commoning optimization for CHAINS.
   Uids of the newly created temporary variables are marked in TMP_VARS.   

References CT_INVARIANT, execute_load_motion(), execute_pred_commoning_chain(), chain::type, and update_ssa().

Referenced by execute_pred_commoning_cbck(), and tree_predictive_commoning_loop().

static void execute_pred_commoning_cbck ( )
static
static void execute_pred_commoning_chain ( struct loop loop,
chain_p  chain,
bitmap  tmp_vars 
)
static
Perform the predictive commoning optimization for a chain CHAIN.
   Uids of the newly created temporary variables are marked in TMP_VARS. 

References chain::combined, dref_d::distance, initialize_root(), chain::length, chain::refs, remove_stmt(), replace_ref_with(), dref_d::stmt, and chain::vars.

Referenced by execute_pred_commoning().

static struct component* filter_suitable_components ( )
staticread
Check the conditions on references inside each of components COMPS,
   and remove the unsuitable components from the list.  The new list
   of components is returned.  The conditions are described in 2) at
   the beginning of this file.  LOOP is the current loop.   

References comp, free(), component::next, component::refs, release_component(), and suitable_component_p().

Referenced by tree_predictive_commoning_loop().

static gimple find_associative_operation_root ( )
static
If the operation used in STMT is associative and commutative, go through the
   tree of the same operations and returns its root.  Distance to the root
   is stored in DISTANCE.   

References find_use_stmt(), gimple_assign_lhs(), gimple_assign_rhs_code(), and may_reassociate_p().

Referenced by find_common_use_stmt(), and reassociate_to_the_same_stmt().

static gimple find_common_use_stmt ( )
static
Returns the common statement in that NAME1 and NAME2 have a use.  If there
   is no such statement, returns NULL_TREE.  In case the operation used on
   NAME1 and NAME2 is associative and commutative, returns the root of the
   tree formed by this operation instead of the statement that uses NAME1 or
   NAME2.   

References find_associative_operation_root(), and find_use_stmt().

Referenced by combinable_refs_p().

static gimple find_looparound_phi ( )
static
Finds looparound phi node of LOOP that copies the value of REF, and if its
   initial value is correct (equal to initial value of REF shifted by one
   iteration), returns the phi node.  Otherwise, NULL_TREE is returned.  ROOT
   is the root of the current chain.   

References dref_d::distance, dr_analyze_innermost(), DR_IS_READ, DR_REF, DR_STMT, gimple_assign_lhs(), gimple_assign_rhs1(), gsi_end_p(), gsi_next(), gsi_start_phis(), gsi_stmt(), loop::header, is_gimple_assign(), loop_latch_edge(), loop_preheader_edge(), memset(), dref_d::ref, dref_d::stmt, and valid_initializer_p().

Referenced by add_looparound_copies().

static gimple find_use_stmt ( )
static
Returns the modify statement that uses NAME.  Skips over assignment
   statements, NAME is replaced with the actual name used in the returned
   statement.   

References get_gimple_rhs_class(), gimple_assign_copy_p(), gimple_assign_lhs(), gimple_assign_rhs1(), gimple_assign_rhs_code(), GIMPLE_BINARY_RHS, and single_nonlooparound_use().

Referenced by find_associative_operation_root(), find_common_use_stmt(), reassociate_to_the_same_stmt(), and stmt_combining_refs().

static dref get_chain_root ( )
inlinestatic
static tree get_init_expr ( )
static
Get the initialization expression for the INDEX-th temporary variable
   of CHAIN.   

References chain::ch1, chain::ch2, CT_COMBINATION, chain::inits, chain::op, chain::rslt_type, and chain::type.

Referenced by initialize_root_vars().

static void initialize_root ( )
static
Create the variables and initialization statement for root of chain
   CHAIN.  Uids of the newly created temporary variables are marked
   in TMP_VARS.   

References CT_COMBINATION, CT_STORE_LOAD, get_chain_root(), initialize_root_vars(), chain::length, replace_ref_with(), dref_d::stmt, chain::type, and chain::vars.

Referenced by execute_pred_commoning_chain().

static void initialize_root_vars ( )
static
Creates the variables for CHAIN, as well as phi nodes for them and
   initialization on entry to LOOP.  Uids of the newly created
   temporary variables are marked in TMP_VARS.   

References add_phi_arg(), create_phi_node(), CT_COMBINATION, DR_REF, force_gimple_operand(), get_chain_root(), get_init_expr(), gimple_assign_lhs(), gsi_insert_seq_on_edge_immediate(), chain::has_max_use_after, loop::header, chain::length, loop_latch_edge(), loop_preheader_edge(), make_ssa_name(), component::next, predcom_tmp_var(), dref_d::ref, dref_d::stmt, chain::type, and chain::vars.

Referenced by initialize_root().

static void initialize_root_vars_lm ( struct loop loop,
dref  root,
bool  written,
vec< tree > *  vars,
vec< tree inits,
bitmap  tmp_vars 
)
static
Initializes a variable for load motion for ROOT and prepares phi nodes and
   initialization on entry to LOOP if necessary.  The ssa name for the variable
   is stored in VARS.  If WRITTEN is true, also a phi node to copy its value
   around the loop is created.  Uid of the newly created temporary variable
   is marked in TMP_VARS.  INITS is the list containing the (single)
   initializer.   

References add_phi_arg(), create_phi_node(), DR_REF, force_gimple_operand(), gsi_insert_on_edge_immediate(), gsi_insert_seq_on_edge_immediate(), loop::header, loop_latch_edge(), loop_preheader_edge(), make_ssa_name(), component::next, predcom_tmp_var(), and dref_d::ref.

Referenced by execute_load_motion().

static void insert_looparound_copy ( )
static
Adds a reference for the looparound copy of REF in PHI to CHAIN.   

References dref_d::always_accessed, dref_d::distance, chain::has_max_use_after, chain::length, chain::refs, and dref_d::stmt.

Referenced by add_looparound_copies().

static basic_block last_always_executed_block ( )
static
Returns the last basic block in LOOP for that we are sure that
   it is executed whenever the loop is entered.   

References CDI_DOMINATORS, get_loop_exit_edges(), last, loop::latch, nearest_common_dominator(), and edge_def::src.

Referenced by split_data_refs_to_components().

static chain_p make_invariant_chain ( )
static
Returns the chain for invariant component COMP.   

References chain::all_always_accessed, dref_d::always_accessed, CT_INVARIANT, chain::refs, component::refs, and chain::type.

Referenced by determine_roots_comp().

static chain_p make_rooted_chain ( )
static
static bool may_reassociate_p ( )
static
Returns true if we may perform reassociation for operation CODE in TYPE.   

References associative_tree_code(), and commutative_tree_code().

Referenced by find_associative_operation_root().

static void merge_comps ( )
static
Join operation for DFU.  FATHERS gives the tree, SIZES are sizes of the
   components, A and B are components to merge.   

References component_of().

Referenced by split_data_refs_to_components().

static tree name_for_ref ( )
static
Returns the ssa name that contains the value of REF, or NULL_TREE if there
   is no such name.   

References DR_IS_READ, gimple_assign_lhs(), gimple_assign_rhs1(), is_gimple_assign(), dref_d::ref, and dref_d::stmt.

Referenced by combinable_refs_p(), and stmt_combining_refs().

static bool nontrivial_chain_p ( )
static
Returns true if CHAIN is not trivial.   

References chain::refs.

Referenced by determine_roots_comp().

static int order_drefs ( )
static
Compares two drefs A and B by their offset and position.  Callback for
   qsort.   

References dref_d::offset, and double_int::scmp().

Referenced by determine_roots_comp().

static tree predcom_tmp_var ( )
static
Returns a new temporary variable used for the I-th variable carrying
   value of REF.  The variable's uid is marked in TMP_VARS.   

References bitmap_set_bit(), create_tmp_reg(), and get_lsm_tmp_name().

Referenced by initialize_root_vars(), and initialize_root_vars_lm().

static void prepare_initializers ( )
static
Prepare initializers for CHAINS in LOOP, and free chains that cannot
   be used because the initializers might trap.   

References prepare_initializers_chain(), and release_chain().

Referenced by tree_predictive_commoning_loop().

static bool prepare_initializers_chain ( )
static
Prepare initializers for CHAIN in LOOP.  Returns false if this is
   impossible because one of these initializers may trap, true otherwise.   

References chain::all_always_accessed, CT_INVARIANT, dref_d::distance, DR_REF, force_gimple_operand(), get_chain_root(), gsi_insert_seq_on_edge_immediate(), chain::inits, chain::length, loop_preheader_edge(), dref_d::ref, ref_at_iteration(), chain::refs, dref_d::stmt, tree_could_trap_p(), and chain::type.

Referenced by prepare_initializers().

static gimple reassociate_to_the_same_stmt ( )
static
static tree ref_at_iteration ( )
static
Returns the reference to the address of REF in the ITER-th iteration of
   LOOP, or NULL if we fail to determine it (ITER may be negative).  We
   try to preserve the original shape of the reference (not rewrite it
   as an indirect ref to the address), to make tree_could_trap_p in
   prepare_initializers_chain return false more often.   

References affine_iv::base, build_int_cst_type(), expand_simple_operations(), expr_invariant_in_loop_p(), handled_component_p(), integer_zerop(), simple_iv(), affine_iv::step, type(), and unshare_expr().

Referenced by prepare_initializers_chain().

static void release_chain ( )
static
Frees a chain CHAIN.   

References free(), chain::inits, chain::refs, and chain::vars.

Referenced by determine_roots_comp(), prepare_initializers(), and release_chains().

static void release_chains ( )
static
Frees CHAINS.   

References release_chain().

Referenced by tree_predictive_commoning_loop().

static void release_component ( )
static
Frees a component COMP.   

References free(), and component::refs.

Referenced by filter_suitable_components(), and release_components().

static void release_components ( )
static
Frees list of components COMPS.   

References component::next, and release_component().

Referenced by tree_predictive_commoning_loop().

static void remove_name_from_operation ( )
static
Remove OP from the operation on rhs of STMT, and replace STMT with
   an assignment of the remaining operand.   

References gimple_assign_rhs1(), gimple_assign_rhs2(), gimple_assign_set_rhs_from_tree(), gsi_for_stmt(), gsi_stmt(), is_gimple_assign(), si, and update_stmt().

Referenced by reassociate_to_the_same_stmt().

static void remove_stmt ( )
static
static void replace_names_by_phis ( )
static
For each reference in CHAINS, if name_defined_by_phi is not
   NULL, use it to set the stmt field.   

References dref_d::name_defined_by_phi, chain::refs, and dref_d::stmt.

Referenced by execute_pred_commoning_cbck().

static void replace_phis_by_defined_names ( )
static
For each reference in CHAINS, if its defining statement is
   phi node, record the ssa name that is defined by it.   

References dref_d::name_defined_by_phi, chain::refs, and dref_d::stmt.

Referenced by tree_predictive_commoning_loop().

static void replace_ref_with ( )
static
Replace the reference in statement STMT with temporary variable
   NEW_TREE.  If SET is true, NEW_TREE is instead initialized to the value of
   the reference in the statement.  IN_LHS is true if the reference
   is in the lhs of STMT, false if it is in rhs.   

References cfun, get_or_create_ssa_default_def(), gimple_assign_copy_p(), gimple_assign_lhs(), gimple_assign_rhs1(), gimple_assign_set_rhs_from_tree(), gimple_assign_single_p(), gsi_after_labels(), gsi_for_stmt(), gsi_insert_after(), gsi_insert_before(), GSI_NEW_STMT, gsi_stmt(), is_gimple_assign(), remove_phi_node(), unshare_expr(), and update_stmt().

Referenced by execute_load_motion(), execute_pred_commoning_chain(), and initialize_root().

static gimple single_nonlooparound_use ( )
static
Returns the single statement in that NAME is used, excepting
   the looparound phi nodes contained in one of the chains.  If there is no
   such statement, or more statements, NULL is returned.   

References bitmap_bit_p(), and is_gimple_debug().

Referenced by find_use_stmt(), and remove_stmt().

static struct component* split_data_refs_to_components ( struct loop loop,
vec< data_reference_p datarefs,
vec< ddr_p depends 
)
staticread
static gimple stmt_combining_refs ( )
static
Returns the statement that combines references R1 and R2.  In case R1
   and R2 are not used in the same statement, but they are used with an
   associative and commutative operation in the same expression, reassociate
   the expression so that they are used in the same statement.   

References find_use_stmt(), name_for_ref(), and reassociate_to_the_same_stmt().

Referenced by combine_chains().

static bool suitable_component_p ( )
static
Returns true if the component COMP satisfies the conditions
   described in 2) at the beginning of this file.  LOOP is the current
   loop.   

References CDI_DOMINATORS, component::comp_step, determine_offset(), dominated_by_p(), DR_IS_WRITE, first, gimple_bb(), loop::header, just_once_each_iteration_p(), dref_d::offset, dref_d::ref, component::refs, RS_ANY, dref_d::stmt, and suitable_reference_p().

Referenced by filter_suitable_components().

static bool suitable_reference_p ( )
static
Returns true if A is a reference that is suitable for predictive commoning
   in the innermost loop that contains it.  REF_STEP is set according to the
   step of the reference A.   

References DR_REF, DR_STEP, integer_nonzerop(), integer_zerop(), is_gimple_reg_type(), RS_ANY, RS_INVARIANT, RS_NONZERO, and tree_could_throw_p().

Referenced by split_data_refs_to_components(), and suitable_component_p().

static void try_combine_chains ( )
static
Try to combine the CHAINS.   

References chain_can_be_combined_p(), combine_chains(), vNULL, and worklist.

Referenced by tree_predictive_commoning_loop().

static bool valid_initializer_p ( struct data_reference ref,
unsigned  distance,
struct data_reference root 
)
static
Returns true if REF is a valid initializer for ROOT with given DISTANCE (in
   iterations of the innermost enclosing loop).   

References aff_combination_add(), aff_combination_constant_multiple_p(), aff_combination_dr_offset(), aff_combination_scale(), DR_BASE_ADDRESS, DR_INIT, DR_OFFSET, DR_STEP, double_int::from_uhwi(), integer_zerop(), operand_equal_p(), and tree_to_aff_combination_expand().

Referenced by find_looparound_phi().


Variable Documentation

bitmap looparound_phis
static
Bitmap of ssa names defined by looparound phi nodes covered by chains.   
struct pointer_map_t* name_expansions
static
Cache used by tree_to_aff_combination_expand.