GCC Middle and Back End API Reference
|
Data Structures | |
struct | slsr_cand_d |
struct | cand_chain_d |
struct | incr_info_d |
struct | cand_chain_hasher |
Typedefs | |
typedef unsigned | cand_idx |
typedef struct slsr_cand_d | slsr_cand |
typedef struct slsr_cand_d * | slsr_cand_t |
typedef struct slsr_cand_d * | const_slsr_cand_t |
typedef struct cand_chain_d | cand_chain |
typedef struct cand_chain_d * | cand_chain_t |
typedef struct cand_chain_d * | const_cand_chain_t |
typedef struct incr_info_d | incr_info |
typedef struct incr_info_d * | incr_info_t |
Enumerations | |
enum | cand_kind { CAND_MULT, CAND_ADD, CAND_REF, CAND_PHI } |
enum | cost_consts { COST_NEUTRAL = 0, COST_INFINITE = 1000 } |
enum | stride_status { UNKNOWN_STRIDE = 0, KNOWN_STRIDE = 1 } |
enum | phi_adjust_status { NOT_PHI_ADJUST = 0, PHI_ADJUST = 1 } |
enum | count_phis_status { DONT_COUNT_PHIS = 0, COUNT_PHIS = 1 } |
Variables | |
static vec< slsr_cand_t > | cand_vec |
static struct pointer_map_t * | stmt_cand_map |
static struct obstack | cand_obstack |
static struct obstack | chain_obstack |
static incr_info_t | incr_vec |
static unsigned | incr_vec_len |
const int | MAX_INCR_VEC_LEN = 16 |
static bool | address_arithmetic_p |
static hash_table < cand_chain_hasher > | base_cand_map |
typedef struct cand_chain_d cand_chain |
typedef struct cand_chain_d * cand_chain_t |
typedef unsigned cand_idx |
@verbatim Straight-line strength reduction.
Copyright (C) 2012-2013 Free Software Foundation, Inc. Contributed by Bill Schmidt, IBM wschm idt@ linux .ibm .com
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/.
There are many algorithms for performing strength reduction on loops. This is not one of them. IVOPTS handles strength reduction of induction variables just fine. This pass is intended to pick up the crumbs it leaves behind, by considering opportunities for strength reduction along dominator paths. Strength reduction addresses explicit multiplies, and certain multiplies implicit in addressing expressions. It would also be possible to apply strength reduction to divisions and modulos, but such opportunities are relatively uncommon. Strength reduction is also currently restricted to integer operations. If desired, it could be extended to floating-point operations under control of something like -funsafe-math-optimizations.
Information about a strength reduction candidate. Each statement in the candidate table represents an expression of one of the following forms (the special case of CAND_REF will be described later): (CAND_MULT) S1: X = (B + i) * S (CAND_ADD) S1: X = B + (i * S) Here X and B are SSA names, i is an integer constant, and S is either an SSA name or a constant. We call B the "base," i the "index", and S the "stride." Any statement S0 that dominates S1 and is of the form: (CAND_MULT) S0: Y = (B + i') * S (CAND_ADD) S0: Y = B + (i' * S) is called a "basis" for S1. In both cases, S1 may be replaced by S1': X = Y + (i - i') * S, where (i - i') * S is folded to the extent possible. All gimple statements are visited in dominator order, and each statement that may contribute to one of the forms of S1 above is given at least one entry in the candidate table. Such statements include addition, pointer addition, subtraction, multiplication, negation, copies, and nontrivial type casts. If a statement may represent more than one expression of the forms of S1 above, multiple "interpretations" are stored in the table and chained together. Examples: * An add of two SSA names may treat either operand as the base. * A multiply of two SSA names, likewise. * A copy or cast may be thought of as either a CAND_MULT with i = 0 and S = 1, or as a CAND_ADD with i = 0 or S = 0. Candidate records are allocated from an obstack. They are addressed both from a hash table keyed on S1, and from a vector of candidate pointers arranged in predominator order. Opportunity note ---------------- Currently we don't recognize: S0: Y = (S * i') - B S1: X = (S * i) - B as a strength reduction opportunity, even though this S1 would also be replaceable by the S1' above. This can be added if it comes up in practice. Strength reduction in addressing -------------------------------- There is another kind of candidate known as CAND_REF. A CAND_REF describes a statement containing a memory reference having complex addressing that might benefit from strength reduction. Specifically, we are interested in references for which get_inner_reference returns a base address, offset, and bitpos as follows: base: MEM_REF (T1, C1) offset: MULT_EXPR (PLUS_EXPR (T2, C2), C3) bitpos: C4 * BITS_PER_UNIT Here T1 and T2 are arbitrary trees, and C1, C2, C3, C4 are arbitrary integer constants. Note that C2 may be zero, in which case the offset will be MULT_EXPR (T2, C3). When this pattern is recognized, the original memory reference can be replaced with: MEM_REF (POINTER_PLUS_EXPR (T1, MULT_EXPR (T2, C3)), C1 + (C2 * C3) + C4) which distributes the multiply to allow constant folding. When two or more addressing expressions can be represented by MEM_REFs of this form, differing only in the constants C1, C2, and C4, making this substitution produces more efficient addressing during the RTL phases. When there are not at least two expressions with the same values of T1, T2, and C3, there is nothing to be gained by the replacement. Strength reduction of CAND_REFs uses the same infrastructure as that used by CAND_MULTs and CAND_ADDs. We record T1 in the base (B) field, MULT_EXPR (T2, C3) in the stride (S) field, and C1 + (C2 * C3) + C4 in the index (i) field. A basis for a CAND_REF is thus another CAND_REF with the same B and S values. When at least two CAND_REFs are chained together using the basis relation, each of them is replaced as above, resulting in improved code generation for addressing. Conditional candidates ====================== Conditional candidates are best illustrated with an example. Consider the code sequence: (1) x_0 = ...; (2) a_0 = x_0 * 5; MULT (B: x_0; i: 0; S: 5) if (...) (3) x_1 = x_0 + 1; ADD (B: x_0, i: 1; S: 1) (4) x_2 = PHI <x_0, x_1>; PHI (B: x_0, i: 0, S: 1) (5) x_3 = x_2 + 1; ADD (B: x_2, i: 1, S: 1) (6) a_1 = x_3 * 5; MULT (B: x_2, i: 1; S: 5) Here strength reduction is complicated by the uncertain value of x_2. A legitimate transformation is: (1) x_0 = ...; (2) a_0 = x_0 * 5; if (...) { (3) [x_1 = x_0 + 1;] (3a) t_1 = a_0 + 5; } (4) [x_2 = PHI <x_0, x_1>;] (4a) t_2 = PHI <a_0, t_1>; (5) [x_3 = x_2 + 1;] (6r) a_1 = t_2 + 5; where the bracketed instructions may go dead. To recognize this opportunity, we have to observe that statement (6) has a "hidden basis" (2). The hidden basis is unlike a normal basis in that the statement and the hidden basis have different base SSA names (x_2 and x_0, respectively). The relationship is established when a statement's base name (x_2) is defined by a phi statement (4), each argument of which (x_0, x_1) has an identical "derived base name." If the argument is defined by a candidate (as x_1 is by (3)) that is a CAND_ADD having a stride of 1, the derived base name of the argument is the base name of the candidate (x_0). Otherwise, the argument itself is its derived base name (as is the case with argument x_0). The hidden basis for statement (6) is the nearest dominating candidate whose base name is the derived base name (x_0) of the feeding phi (4), and whose stride is identical to that of the statement. We can then create the new "phi basis" (4a) and feeding adds along incoming arcs (3a), allowing the final replacement of (6) by the strength-reduced (6r). To facilitate this, a new kind of candidate (CAND_PHI) is introduced. A CAND_PHI is not a candidate for replacement, but is maintained in the candidate table to ease discovery of hidden bases. Any phi statement whose arguments share a common derived base name is entered into the table with the derived base name, an (arbitrary) index of zero, and a stride of 1. A statement with a hidden basis can then be detected by simply looking up its feeding phi definition in the candidate table, extracting the derived base name, and searching for a basis in the usual manner after substituting the derived base name. Note that the transformation is only valid when the original phi and the statements that define the phi's arguments are all at the same position in the loop hierarchy.
Index into the candidate vector, offset by 1. VECs are zero-based, while cand_idx's are one-based, with zero indicating null.
typedef struct cand_chain_d* const_cand_chain_t |
typedef struct slsr_cand_d* const_slsr_cand_t |
typedef struct incr_info_d incr_info |
typedef struct incr_info_d * incr_info_t |
typedef struct slsr_cand_d slsr_cand |
typedef struct slsr_cand_d * slsr_cand_t |
enum cand_kind |
enum cost_consts |
enum count_phis_status |
enum phi_adjust_status |
enum stride_status |
|
static |
Add an entry to the statement-to-candidate mapping.
References pointer_map_insert().
Referenced by slsr_process_add(), slsr_process_cast(), slsr_process_copy(), slsr_process_mul(), slsr_process_neg(), slsr_process_phi(), and slsr_process_ref().
|
static |
Return TRUE iff all required increments for candidates feeding PHI are profitable to replace on behalf of candidate C.
References address_arithmetic_p, base_cand_from_table(), slsr_cand_d::base_expr, slsr_cand_d::basis, slsr_cand_d::cand_num, dump_double_int(), dump_file, dump_flags, gimple_phi_arg_def(), gimple_phi_num_args(), gimple_phi_result(), incr_vec_index(), slsr_cand_d::index, double_int::is_negative(), lookup_cand(), operand_equal_p(), print_gimple_stmt(), and profitable_increment_p().
Referenced by replace_profitable_candidates().
|
static |
Allocate storage for a new candidate and initialize its fields. Attempt to find a basis for the candidate.
References slsr_cand_d::base_expr, slsr_cand_d::basis, CAND_MULT, slsr_cand_d::cand_num, cand_obstack, CAND_PHI, slsr_cand_d::cand_stmt, slsr_cand_d::cand_type, slsr_cand_d::dead_savings, slsr_cand_d::def_phi, slsr_cand_d::dependent, find_basis_for_candidate(), find_phi_def(), slsr_cand_d::index, slsr_cand_d::kind, slsr_cand_d::next_interp, record_potential_basis(), slsr_cand_d::sibling, and slsr_cand_d::stride.
Referenced by create_add_imm_cand(), create_add_ssa_cand(), create_mul_imm_cand(), create_mul_ssa_cand(), slsr_process_cast(), slsr_process_copy(), slsr_process_phi(), and slsr_process_ref().
|
static |
Analyze costs of related candidates in the candidate vector, and make beneficial replacements.
References address_arithmetic_p, analyze_increments(), slsr_cand_d::basis, CAND_ADD, slsr_cand_d::cand_num, CAND_REF, slsr_cand_d::cand_stmt, slsr_cand_d::cand_type, count_candidates(), slsr_cand_d::dependent, dump_file, dump_flags, dump_incr_vec(), free(), gimple_assign_lhs(), incr_vec_len, insert_initializers(), slsr_cand_d::kind, lookup_cand(), MAX_INCR_VEC_LEN, optimize_cands_for_speed_p(), record_increments(), replace_profitable_candidates(), replace_refs(), replace_uncond_cands_and_profitable_phis(), and slsr_cand_d::stride.
Referenced by execute_strength_reduction().
|
static |
Use target-specific costs to determine and record which increments in the current candidate tree are profitable to replace, assuming MODE and SPEED. FIRST_DEP is the first dependent of the root of the candidate tree. One slight limitation here is that we don't account for the possible introduction of casts in some cases. See replace_one_candidate for the cases where these are introduced. This should probably be cleaned up sometime.
References add_cost(), CAND_MULT, slsr_cand_d::cand_stmt, incr_info_d::cost, COST_INFINITE, COST_NEUTRAL, incr_info_d::count, COUNT_PHIS, DONT_COUNT_PHIS, gimple_assign_lhs(), gimple_assign_rhs_code(), HOST_WIDE_INT, incr_info_d::incr, incr_vec_len, slsr_cand_d::kind, legal_cast_p_1(), lowest_cost_path(), mul_cost(), mult_by_coeff_cost(), slsr_cand_d::stride, double_int::to_shwi(), and total_savings().
Referenced by analyze_candidates_and_replace().
|
static |
Forward function declarations.
Referenced by all_phi_incrs_profitable(), create_add_imm_cand(), create_add_ssa_cand(), create_mul_imm_cand(), create_mul_ssa_cand(), create_phi_basis(), find_phi_def(), ncd_with_phi(), phi_add_costs(), phi_incr_cost(), record_phi_increments(), slsr_process_cast(), slsr_process_copy(), and slsr_process_phi().
|
static |
Look up the defining statement for BASE_IN and return a pointer to its candidate in the candidate table, if any; otherwise NULL. Only CAND_ADD and CAND_MULT candidates are returned.
References CAND_REF, slsr_cand_d::kind, and pointer_map_contains().
|
inlinestatic |
Calculate the increment required for candidate C relative to its basis. If we aren't going to generate pointer arithmetic for this candidate, return the absolute value of that increment instead.
References address_arithmetic_p, cand_increment(), and double_int::is_negative().
Referenced by lowest_cost_path(), ncd_of_cand_and_phis(), replace_profitable_candidates(), and total_savings().
|
inlinestatic |
Return TRUE iff candidate C has already been replaced under another interpretation.
References slsr_cand_d::cand_stmt.
Referenced by count_candidates(), lowest_cost_path(), nearest_common_dominator_for_cands(), record_increments(), replace_profitable_candidates(), replace_unconditional_candidate(), total_savings(), and unreplaced_cand_in_tree().
|
static |
Calculate the increment required for candidate C relative to its basis.
References slsr_cand_d::base_expr, slsr_cand_d::basis, slsr_cand_d::index, lookup_cand(), operand_equal_p(), and phi_dependent_cand_p().
Referenced by cand_abs_increment(), record_increments(), replace_one_candidate(), and replace_unconditional_candidate().
|
static |
Count the number of candidates in the tree rooted at C that have not already been replaced under other interpretations.
References cand_already_replaced(), count, slsr_cand_d::dependent, lookup_cand(), and slsr_cand_d::sibling.
Referenced by analyze_candidates_and_replace().
|
static |
Create a candidate entry for a statement GS, where GS adds SSA name BASE_IN to constant INDEX_IN. Propagate any known information about BASE_IN into the new candidate. Return the new candidate.
References alloc_cand_and_find_basis(), base_cand_from_table(), slsr_cand_d::base_expr, CAND_ADD, CAND_PHI, slsr_cand_d::cand_stmt, slsr_cand_d::cand_type, slsr_cand_d::dead_savings, has_single_use(), slsr_cand_d::index, slsr_cand_d::kind, lookup_cand(), double_int::multiple_of(), slsr_cand_d::next_interp, stmt_cost(), slsr_cand_d::stride, and tree_to_double_int().
Referenced by slsr_process_add().
|
static |
Create a new statement along edge E to add BASIS_NAME to the product of INCREMENT and the stride of candidate C. Create and return a new SSA name from *VAR to be used as the LHS of the new statement. KNOWN_STRIDE is true iff C's stride is a constant.
References address_arithmetic_p, double_int_to_tree(), dump_file, dump_flags, gimple_build_assign_with_ops(), gimple_set_location(), gsi_end_p(), gsi_insert_after(), gsi_insert_before(), gsi_last_bb(), GSI_NEW_STMT, gsi_stmt(), incr_vec_index(), basic_block_def::index, insert_bb(), is_ctrl_stmt(), double_int::is_negative(), double_int::is_zero(), make_temp_ssa_name(), print_gimple_stmt(), single_succ_p(), split_edge(), edge_def::src, slsr_cand_d::stride, and tree_to_double_int().
Referenced by create_phi_basis().
|
static |
Create a candidate entry for a statement GS, where GS adds two SSA names BASE_IN and ADDEND_IN if SUBTRACT_P is false, and subtracts ADDEND_IN from BASE_IN otherwise. Propagate any known information about the two SSA names into the new candidate. Return the new candidate.
References alloc_cand_and_find_basis(), base_cand_from_table(), slsr_cand_d::base_expr, CAND_ADD, CAND_MULT, CAND_PHI, slsr_cand_d::cand_stmt, slsr_cand_d::cand_type, slsr_cand_d::dead_savings, has_single_use(), slsr_cand_d::index, double_int::is_zero(), slsr_cand_d::kind, lookup_cand(), slsr_cand_d::next_interp, operand_equal_p(), stmt_cost(), slsr_cand_d::stride, and tree_to_double_int().
Referenced by slsr_process_add().
|
static |
Create a candidate entry for a statement GS, where GS multiplies SSA name BASE_IN by constant STRIDE_IN. Propagate any known information about BASE_IN into the new candidate. Return the new candidate.
References alloc_cand_and_find_basis(), base_cand_from_table(), slsr_cand_d::base_expr, CAND_ADD, CAND_MULT, CAND_PHI, slsr_cand_d::cand_stmt, slsr_cand_d::cand_type, slsr_cand_d::dead_savings, double_int_to_tree(), has_single_use(), slsr_cand_d::index, integer_onep(), double_int::is_one(), slsr_cand_d::kind, lookup_cand(), slsr_cand_d::next_interp, stmt_cost(), slsr_cand_d::stride, and tree_to_double_int().
Referenced by slsr_process_mul(), and slsr_process_neg().
|
static |
Create a candidate entry for a statement GS, where GS multiplies two SSA names BASE_IN and STRIDE_IN. Propagate any known information about the two SSA names into the new candidate. Return the new candidate.
References alloc_cand_and_find_basis(), base_cand_from_table(), slsr_cand_d::base_expr, CAND_ADD, CAND_MULT, CAND_PHI, slsr_cand_d::cand_stmt, slsr_cand_d::cand_type, slsr_cand_d::dead_savings, has_single_use(), slsr_cand_d::index, integer_onep(), slsr_cand_d::kind, lookup_cand(), slsr_cand_d::next_interp, stmt_cost(), slsr_cand_d::stride, and tree_to_double_int().
Referenced by slsr_process_mul().
|
static |
Given a candidate C with BASIS_NAME being the LHS of C's basis which is hidden by the phi node FROM_PHI, create a new phi node in the same block as FROM_PHI. The new phi is suitable for use as a basis by C, with its phi arguments representing conditional adjustments to the hidden basis along conditional incoming paths. Those adjustments are made by creating add statements (and sometimes recursively creating phis) along those incoming paths. LOC is the location to attach to the introduced statements. KNOWN_STRIDE is true iff C's stride is a constant.
References add_phi_arg(), base_cand_from_table(), slsr_cand_d::base_expr, slsr_cand_d::basis, slsr_cand_d::cand_stmt, create_add_on_incoming_edge(), create_phi_node(), dump_file, dump_flags, gimple_assign_lhs(), gimple_bb(), gimple_phi_arg_def(), gimple_phi_num_args(), gimple_phi_result(), slsr_cand_d::index, double_int::is_zero(), lookup_cand(), make_temp_ssa_name(), operand_equal_p(), basic_block_def::preds, print_gimple_stmt(), and update_stmt().
Referenced by replace_conditional_candidate(), and replace_profitable_candidates().
|
static |
Dump the candidate chains.
References dump_file, ssa_base_cand_dump_callback(), and hash_table< Descriptor, Allocator >::traverse_noresize().
Referenced by execute_strength_reduction().
|
static |
Dump the candidate vector for debug.
References dump_candidate(), and dump_file.
Referenced by execute_strength_reduction().
|
static |
Dump a candidate for debug.
References slsr_cand_d::base_expr, slsr_cand_d::basis, CAND_ADD, CAND_MULT, slsr_cand_d::cand_num, CAND_PHI, CAND_REF, slsr_cand_d::cand_stmt, slsr_cand_d::cand_type, slsr_cand_d::dead_savings, slsr_cand_d::def_phi, slsr_cand_d::dependent, dump_double_int(), dump_file, slsr_cand_d::index, slsr_cand_d::kind, slsr_cand_d::next_interp, print_generic_expr(), print_gimple_stmt(), slsr_cand_d::sibling, and slsr_cand_d::stride.
Referenced by dump_cand_vec().
|
static |
Dump the increment vector for debug.
References count, dump_double_int(), dump_file, dump_flags, incr_vec_len, and print_generic_expr().
Referenced by analyze_candidates_and_replace().
|
static |
References dom_walk_data::after_dom_children, analyze_candidates_and_replace(), dom_walk_data::before_dom_children, dom_walk_data::block_local_data_size, cand_obstack, CDI_DOMINATORS, chain_obstack, hash_table< Descriptor, Allocator >::create(), hash_table< Descriptor, Allocator >::dispose(), dump_cand_chains(), dump_cand_vec(), dump_file, dump_flags, find_candidates_in_block(), fini_walk_dominator_tree(), dom_walk_data::global_data, init_walk_dominator_tree(), dom_walk_data::initialize_block_local_data, loop_optimizer_finalize(), loop_optimizer_init(), pointer_map_create(), pointer_map_destroy(), and walk_dominator_tree().
|
static |
Helper routine for find_basis_for_candidate. May be called twice: once for the candidate's base expr, and optionally again for the candidate's phi definition.
References cand_chain_d::base_expr, cand_chain_d::cand, slsr_cand_d::cand_num, slsr_cand_d::cand_stmt, slsr_cand_d::cand_type, CDI_DOMINATORS, dominated_by_p(), hash_table< Descriptor, Allocator >::find(), slsr_cand_d::kind, cand_chain_d::next, operand_equal_p(), slsr_cand_d::stride, and types_compatible_p().
Referenced by find_basis_for_candidate().
|
static |
Use the base expr from candidate C to look for possible candidates that can serve as a basis for C. Each potential basis must also appear in a block that dominates the candidate statement and have the same stride and type. If more than one possible basis exists, the one with highest index in the vector is chosen; this will be the most immediately dominating basis.
References slsr_cand_d::base_expr, slsr_cand_d::basis, slsr_cand_d::cand_num, slsr_cand_d::cand_stmt, CDI_DOMINATORS, slsr_cand_d::dead_savings, slsr_cand_d::def_phi, slsr_cand_d::dependent, dominated_by_p(), find_basis_for_base_expr(), gimple_bb(), gimple_phi_result(), has_single_use(), lookup_cand(), and slsr_cand_d::sibling.
Referenced by alloc_cand_and_find_basis().
|
static |
Find strength-reduction candidates in block BB.
References gimple_assign_lhs(), gimple_assign_rhs1(), gimple_assign_rhs2(), gimple_assign_rhs_code(), gimple_assign_single_p(), gimple_vuse(), gsi_end_p(), gsi_next(), gsi_start_bb(), gsi_start_phis(), gsi_stmt(), is_gimple_assign(), optimize_bb_for_speed_p(), slsr_process_add(), slsr_process_cast(), slsr_process_copy(), slsr_process_mul(), slsr_process_neg(), slsr_process_phi(), and slsr_process_ref().
Referenced by execute_strength_reduction().
|
static |
Look in the candidate table for a CAND_PHI that defines BASE and return it if found; otherwise return NULL.
References base_cand_from_table(), slsr_cand_d::cand_num, CAND_PHI, and slsr_cand_d::kind.
Referenced by alloc_cand_and_find_basis().
|
static |
|
inlinestatic |
Return the index in the increment vector of the given INCREMENT, or -1 if not found. The latter can occur if more than MAX_INCR_VEC_LEN increments have been found.
References incr_info_d::incr, and incr_vec_len.
Referenced by all_phi_incrs_profitable(), create_add_on_incoming_edge(), and replace_profitable_candidates().
|
static |
For each profitable increment in the increment vector not equal to 0 or 1 (or -1, for non-pointer arithmetic), find the nearest common dominator of all statements in the candidate chain rooted at C that require that increment, and insert an initializer T_0 = stride * increment at that location. Record T_0 with the increment record.
References slsr_cand_d::basis, slsr_cand_d::cand_stmt, double_int_to_tree(), dump_file, dump_flags, gimple_assign_rhs_code(), gimple_build_assign_with_ops(), gimple_location(), gimple_set_location(), gsi_end_p(), gsi_for_stmt(), gsi_insert_after(), gsi_insert_before(), gsi_last_bb(), GSI_SAME_STMT, gsi_stmt(), incr_info_d::incr, incr_vec_len, incr_info_d::initializer, is_ctrl_stmt(), double_int::is_minus_one(), double_int::is_one(), double_int::is_zero(), lookup_cand(), make_temp_ssa_name(), nearest_common_dominator_for_cands(), print_gimple_stmt(), profitable_increment_p(), and slsr_cand_d::stride.
Referenced by analyze_candidates_and_replace().
|
static |
Referenced by replace_mult_candidate(), and replace_one_candidate().
|
static |
Create a NOP_EXPR that copies FROM_EXPR into a new SSA name of type TO_TYPE, and insert it in front of the statement represented by candidate C. Use *NEW_VAR to create the new SSA name. Return the new SSA name.
References slsr_cand_d::cand_stmt, dump_file, dump_flags, gimple_build_assign_with_ops(), gimple_location(), gimple_set_location(), gsi_for_stmt(), gsi_insert_before(), GSI_SAME_STMT, make_temp_ssa_name(), and print_gimple_stmt().
|
static |
Return TRUE if GS is a statement that defines an SSA name from a conversion and is legal for us to combine with an add and multiply in the candidate table. For example, suppose we have: A = B + i; C = (type) A; D = C * S; Without the type-cast, we would create a CAND_MULT for D with base B, index i, and stride S. We want to record this candidate only if it is equivalent to apply the type cast following the multiply: A = B + i; E = A * S; D = (type) E; We will record the type with the candidate for D. This allows us to use a similar previous candidate as a basis. If we have earlier seen A' = B + i'; C' = (type) A'; D' = C' * S; we can replace D with D = D' + (i - i') * S; But if moving the type-cast would change semantics, we mustn't do this. This is legitimate for casts from a non-wrapping integral type to any integral type of the same or larger size. It is not legitimate to convert a wrapping type to a non-wrapping type, or to a wrapping type of a different size. I.e., with a wrapping type, we must assume that the addition B + i could wrap, in which case performing the multiply before or after one of the "illegal" type casts will have different semantics.
References gimple_assign_lhs(), gimple_assign_rhs_code(), is_gimple_assign(), and legal_cast_p_1().
Referenced by slsr_process_cast().
|
static |
Help function for legal_cast_p, operating on two trees. Checks whether it's allowable to cast from RHS to LHS. See legal_cast_p for more details.
Referenced by analyze_increments(), and legal_cast_p().
|
static |
Produce a pointer to the IDX'th candidate in the candidate vector.
Referenced by all_phi_incrs_profitable(), analyze_candidates_and_replace(), cand_increment(), count_candidates(), create_add_imm_cand(), create_add_ssa_cand(), create_mul_imm_cand(), create_mul_ssa_cand(), create_phi_basis(), find_basis_for_candidate(), insert_initializers(), lowest_cost_path(), ncd_of_cand_and_phis(), ncd_with_phi(), nearest_common_dominator_for_cands(), phi_add_costs(), phi_dependent_cand_p(), phi_incr_cost(), record_increments(), replace_conditional_candidate(), replace_profitable_candidates(), replace_refs(), replace_uncond_cands_and_profitable_phis(), replace_unconditional_candidate(), slsr_process_cast(), slsr_process_copy(), slsr_process_phi(), total_savings(), and unreplaced_cand_in_tree().
|
static |
Add COST_IN to the lowest cost of any dependent path starting at candidate C or any of its siblings, counting only candidates along such paths with increment INCR. Assume that replacing a candidate reduces cost by REPL_SAVINGS. Also account for savings from any statements that would go dead. If COUNT_PHIS is true, include costs of introducing feeding statements for conditional candidates.
References cand_abs_increment(), cand_already_replaced(), slsr_cand_d::cand_stmt, slsr_cand_d::dead_savings, slsr_cand_d::def_phi, slsr_cand_d::dependent, gimple_phi_result(), has_single_use(), lookup_cand(), phi_dependent_cand_p(), phi_incr_cost(), and slsr_cand_d::sibling.
Referenced by analyze_increments().
gimple_opt_pass* make_pass_strength_reduction | ( | ) |
|
static |
Return the nearest common dominator of BB1 and BB2. If the blocks are identical, return the earlier of C1 and C2 in *WHERE. Otherwise, if the NCD matches BB1, return C1 in *WHERE; if the NCD matches BB2, return C2 in *WHERE; and if the NCD matches neither, return NULL in *WHERE. Note: It is possible for one of C1 and C2 to be NULL.
References slsr_cand_d::cand_num, CDI_DOMINATORS, and nearest_common_dominator().
Referenced by ncd_with_phi(), and nearest_common_dominator_for_cands().
|
static |
Consider the candidate C together with any candidates that feed C's phi dependence (if any). Find and return the nearest common dominator of those candidates requiring the given increment INCR. If the returned block contains one or more of the candidates, return the earliest candidate in the block in *WHERE.
References cand_abs_increment(), slsr_cand_d::cand_stmt, slsr_cand_d::def_phi, gimple_bb(), lookup_cand(), ncd_with_phi(), and phi_dependent_cand_p().
Referenced by nearest_common_dominator_for_cands().
|
static |
Consider all candidates that feed PHI. Find the nearest common dominator of those candidates requiring the given increment INCR. Further find and return the nearest common dominator of this result with block NCD. If the returned block contains one or more of the candidates, return the earliest candidate in the block in *WHERE.
References address_arithmetic_p, base_cand_from_table(), slsr_cand_d::base_expr, slsr_cand_d::basis, slsr_cand_d::cand_stmt, gimple_phi_arg_def(), gimple_phi_num_args(), gimple_phi_result(), slsr_cand_d::index, lookup_cand(), ncd_for_two_cands(), and operand_equal_p().
Referenced by ncd_of_cand_and_phis().
|
static |
Consider all candidates in the tree rooted at C for which INCR represents the required increment of C relative to its basis. Find and return the basic block that most nearly dominates all such candidates. If the returned block contains one or more of the candidates, return the earliest candidate in the block in *WHERE.
References cand_already_replaced(), slsr_cand_d::dependent, lookup_cand(), ncd_for_two_cands(), ncd_of_cand_and_phis(), and slsr_cand_d::sibling.
Referenced by insert_initializers().
|
static |
Return TRUE if the candidates in the tree rooted at C should be optimized for speed, else FALSE. We estimate this based on the block containing the most dominant candidate in the tree that has not yet been replaced.
References slsr_cand_d::cand_stmt, optimize_bb_for_speed_p(), and unreplaced_cand_in_tree().
Referenced by analyze_candidates_and_replace().
|
static |
Compute the expected costs of inserting basis adjustments for candidate C with phi-definition PHI. The cost of inserting one adjustment is given by ONE_ADD_COST. If PHI has arguments which are themselves phi results, recursively calculate costs for those phis as well.
References base_cand_from_table(), slsr_cand_d::base_expr, slsr_cand_d::basis, slsr_cand_d::cand_stmt, CDI_DOMINATORS, COST_INFINITE, dominated_by_p(), gimple_bb(), gimple_phi_arg_def(), gimple_phi_num_args(), gimple_phi_result(), slsr_cand_d::index, and lookup_cand().
Referenced by replace_uncond_cands_and_profitable_phis().
|
static |
Return TRUE if candidate C is dependent upon a PHI.
References slsr_cand_d::basis, slsr_cand_d::def_phi, and lookup_cand().
Referenced by cand_increment(), lowest_cost_path(), ncd_of_cand_and_phis(), record_increments(), replace_profitable_candidates(), replace_uncond_cands_and_profitable_phis(), and total_savings().
|
static |
Add up and return the costs of introducing add statements that require the increment INCR on behalf of candidate C and phi statement PHI. Accumulate into *SAVINGS the potential savings from removing existing statements that feed PHI and have no other uses.
References add_cost(), base_cand_from_table(), slsr_cand_d::base_expr, slsr_cand_d::basis, slsr_cand_d::cand_stmt, gimple_assign_lhs(), gimple_phi_arg_def(), gimple_phi_num_args(), gimple_phi_result(), has_single_use(), slsr_cand_d::index, lookup_cand(), operand_equal_p(), and stmt_cost().
Referenced by lowest_cost_path(), and total_savings().
|
inlinestatic |
Return TRUE if the increment indexed by INDEX is profitable to replace.
References COST_NEUTRAL.
Referenced by all_phi_incrs_profitable(), insert_initializers(), and replace_profitable_candidates().
|
static |
Increase the count of INCREMENT by one in the increment vector. INCREMENT is associated with candidate C. If INCREMENT is to be conditionally executed as part of a conditional candidate replacement, IS_PHI_ADJUST is true, otherwise false. If an initializer T_0 = stride * I is provided by a candidate that dominates all candidates with the same increment, also record T_0 for subsequent use.
References address_arithmetic_p, slsr_cand_d::base_expr, slsr_cand_d::basis, CAND_ADD, slsr_cand_d::cand_stmt, CDI_DOMINATORS, incr_info_d::cost, COST_INFINITE, incr_info_d::count, dominated_by_p(), gimple_assign_rhs1(), gimple_assign_rhs2(), gimple_assign_rhs_code(), gimple_bb(), incr_info_d::incr, incr_vec_len, slsr_cand_d::index, incr_info_d::init_bb, incr_info_d::initializer, double_int::is_negative(), slsr_cand_d::kind, MAX_INCR_VEC_LEN, operand_equal_p(), double_int::sgt(), and double_int::slt().
Referenced by record_increments(), and record_phi_increments().
|
static |
Determine how many times each unique increment occurs in the set of candidates rooted at C's parent, recording the data in the increment vector. For each unique increment I, if an initializer T_0 = stride * I is provided by a candidate that dominates all candidates with the same increment, also record T_0 for subsequent use.
References slsr_cand_d::basis, cand_already_replaced(), cand_increment(), slsr_cand_d::cand_stmt, slsr_cand_d::def_phi, slsr_cand_d::dependent, slsr_cand_d::index, lookup_cand(), NOT_PHI_ADJUST, phi_dependent_cand_p(), record_increment(), record_phi_increments(), and slsr_cand_d::sibling.
Referenced by analyze_candidates_and_replace().
|
static |
Given phi statement PHI that hides a candidate from its BASIS, find the increments along each incoming arc (recursively handling additional phis that may be present) and record them. These increments are the difference in index between the index-adjusting statements and the index of the basis.
References base_cand_from_table(), slsr_cand_d::base_expr, gimple_phi_arg_def(), gimple_phi_num_args(), gimple_phi_result(), slsr_cand_d::index, operand_equal_p(), PHI_ADJUST, and record_increment().
Referenced by record_increments().
|
static |
Record a mapping from the base expression of C to C itself, indicating that C may potentially serve as a basis using that base expression.
References slsr_cand_d::base_expr, cand_chain_d::base_expr, cand_chain_d::cand, chain_obstack, hash_table< Descriptor, Allocator >::find_slot(), and cand_chain_d::next.
Referenced by alloc_cand_and_find_basis().
|
static |
Given a candidate C whose basis is hidden by at least one intervening phi, introduce a matching number of new phis to represent its basis adjusted by conditional increments along possible incoming paths. Then replace C as though it were an unconditional candidate, using the new basis.
References slsr_cand_d::basis, slsr_cand_d::cand_stmt, create_phi_basis(), slsr_cand_d::def_phi, gimple_assign_lhs(), gimple_location(), slsr_cand_d::index, KNOWN_STRIDE, lookup_cand(), replace_mult_candidate(), slsr_cand_d::stride, and tree_to_double_int().
Referenced by replace_uncond_cands_and_profitable_phis().
|
static |
Common logic used by replace_unconditional_candidate and replace_conditional_candidate.
References slsr_cand_d::cand_stmt, double_int_to_tree(), dump_file, dump_flags, double_int::fits_shwi(), gimple_assign_lhs(), gimple_assign_rhs1(), gimple_assign_rhs2(), gimple_assign_rhs_code(), gimple_assign_set_rhs_with_ops(), gimple_location(), gimple_set_location(), gsi_for_stmt(), gsi_replace(), gsi_stmt(), HOST_WIDE_INT_MIN, introduce_cast_before_cand(), double_int::is_negative(), double_int::is_zero(), operand_equal_p(), print_gimple_stmt(), double_int::to_shwi(), update_stmt(), and useless_type_conversion_p().
Referenced by replace_conditional_candidate(), and replace_unconditional_candidate().
|
static |
Strength-reduce the statement represented by candidate C by replacing it with an equivalent addition or subtraction. I is the index into the increment vector identifying C's increment. NEW_VAR is used to create a new SSA name if a cast needs to be introduced. BASIS_NAME is the rhs1 to use in creating the add/subtract.
References address_arithmetic_p, cand_increment(), slsr_cand_d::cand_stmt, dump_file, dump_flags, gimple_assign_lhs(), gimple_assign_rhs1(), gimple_assign_rhs2(), gimple_assign_rhs_code(), gimple_assign_set_rhs_with_ops(), gimple_build_assign_with_ops(), gimple_location(), gimple_set_location(), gsi_for_stmt(), gsi_replace(), gsi_stmt(), incr_info_d::initializer, introduce_cast_before_cand(), double_int::is_minus_one(), double_int::is_one(), double_int::is_zero(), operand_equal_p(), print_gimple_stmt(), replace_rhs_if_not_dup(), slsr_cand_d::stride, types_compatible_p(), and update_stmt().
Referenced by replace_profitable_candidates().
|
static |
For each candidate in the tree rooted at C, replace it with an increment if such has been shown to be profitable.
References all_phi_incrs_profitable(), slsr_cand_d::basis, cand_abs_increment(), cand_already_replaced(), slsr_cand_d::cand_stmt, create_phi_basis(), slsr_cand_d::def_phi, slsr_cand_d::dependent, gimple_assign_lhs(), gimple_assign_rhs_code(), gimple_location(), incr_vec_index(), lookup_cand(), phi_dependent_cand_p(), profitable_increment_p(), replace_one_candidate(), slsr_cand_d::sibling, and UNKNOWN_STRIDE.
Referenced by analyze_candidates_and_replace().
|
static |
Replace *EXPR in candidate C with an equivalent strength-reduced data reference.
References slsr_cand_d::base_expr, build_aligned_type(), slsr_cand_d::cand_stmt, slsr_cand_d::cand_type, copy_ref_info(), double_int_to_tree(), force_gimple_operand_gsi(), get_object_alignment_1(), gsi_for_stmt(), GSI_SAME_STMT, HOST_WIDE_INT, slsr_cand_d::index, slsr_cand_d::stride, and update_stmt().
Referenced by replace_refs().
|
static |
Replace CAND_REF candidate C, each sibling of candidate C, and each dependent of candidate C with an equivalent strength-reduced data reference.
References slsr_cand_d::cand_stmt, slsr_cand_d::dependent, gimple_assign_lhs_ptr(), gimple_assign_rhs1_ptr(), gimple_vdef(), lookup_cand(), replace_ref(), and slsr_cand_d::sibling.
Referenced by analyze_candidates_and_replace().
|
static |
Replace the RHS of the statement represented by candidate C with NEW_CODE, NEW_RHS1, and NEW_RHS2, provided that to do so doesn't leave C unchanged or just interchange its operands. The original operation and operands are in OLD_CODE, OLD_RHS1, and OLD_RHS2. If the replacement was made and we are doing a details dump, return the revised statement, else NULL.
References slsr_cand_d::cand_stmt, dump_file, dump_flags, gimple_assign_set_rhs_with_ops(), gsi_for_stmt(), gsi_stmt(), operand_equal_p(), and update_stmt().
Referenced by replace_one_candidate().
|
static |
For candidate C, each sibling of candidate C, and each dependent of candidate C, determine whether the candidate is dependent upon a phi that hides its basis. If not, replace the candidate unconditionally. Otherwise, determine whether the cost of introducing compensation code for the candidate is offset by the gains from strength reduction. If so, replace the candidate and introduce the compensation code.
References add_cost(), add_costs(), CAND_MULT, slsr_cand_d::cand_num, slsr_cand_d::cand_stmt, COST_NEUTRAL, slsr_cand_d::dead_savings, slsr_cand_d::def_phi, slsr_cand_d::dependent, dump_file, dump_flags, gimple_phi_result(), slsr_cand_d::kind, lookup_cand(), optimize_bb_for_speed_p(), phi_add_costs(), phi_dependent_cand_p(), replace_conditional_candidate(), replace_unconditional_candidate(), slsr_cand_d::sibling, and stmt_cost().
Referenced by analyze_candidates_and_replace().
|
static |
Replace candidate C with an add or subtract. Note that we only operate on CAND_MULTs with known strides, so we will never generate a POINTER_PLUS_EXPR. Each candidate X = (B + i) * S is replaced by X = Y + ((i - i') * S), as described in the module commentary. The folded value ((i - i') * S) is referred to here as the "bump."
References slsr_cand_d::basis, cand_already_replaced(), cand_increment(), slsr_cand_d::cand_stmt, gimple_assign_lhs(), lookup_cand(), replace_mult_candidate(), slsr_cand_d::stride, and tree_to_double_int().
Referenced by replace_uncond_cands_and_profitable_phis().
|
static |
Look for the following pattern: *PBASE: MEM_REF (T1, C1) *POFFSET: MULT_EXPR (T2, C3) [C2 is zero] or MULT_EXPR (PLUS_EXPR (T2, C2), C3) or MULT_EXPR (MINUS_EXPR (T2, -C2), C3) *PINDEX: C4 * BITS_PER_UNIT If not present, leave the input values unchanged and return FALSE. Otherwise, modify the input values as follows and return TRUE: *PBASE: T1 *POFFSET: MULT_EXPR (T2, C3) *PINDEX: C1 + (C2 * C3) + C4
References double_int_to_tree(), double_int::from_uhwi(), double_int::is_zero(), mem_ref_offset(), offset, tree_to_double_int(), type(), double_int::udiv(), and double_int::umod().
Referenced by slsr_process_ref().
|
static |
Given GS which is an add or subtract of scalar integers or pointers, make at least one appropriate entry in the candidate table.
References add_cand_for_stmt(), create_add_imm_cand(), create_add_ssa_cand(), gimple_assign_rhs_code(), slsr_cand_d::next_interp, operand_equal_p(), and tree_to_double_int().
Referenced by find_candidates_in_block().
|
static |
Given GS which is a cast to a scalar integer type, determine whether the cast is legal for strength reduction. If so, make at least one appropriate entry in the candidate table.
References add_cand_for_stmt(), alloc_cand_and_find_basis(), base_cand_from_table(), slsr_cand_d::base_expr, CAND_ADD, CAND_MULT, slsr_cand_d::cand_num, CAND_PHI, slsr_cand_d::cand_stmt, slsr_cand_d::dead_savings, gimple_assign_lhs(), has_single_use(), slsr_cand_d::index, slsr_cand_d::kind, legal_cast_p(), lookup_cand(), slsr_cand_d::next_interp, stmt_cost(), and slsr_cand_d::stride.
Referenced by find_candidates_in_block().
|
static |
Given GS which is a copy of a scalar integer type, make at least one appropriate entry in the candidate table. This interface is included for completeness, but is unnecessary if this pass immediately follows a pass that performs copy propagation, such as DOM.
References add_cand_for_stmt(), alloc_cand_and_find_basis(), base_cand_from_table(), slsr_cand_d::base_expr, CAND_ADD, CAND_MULT, slsr_cand_d::cand_num, CAND_PHI, slsr_cand_d::cand_stmt, slsr_cand_d::cand_type, slsr_cand_d::dead_savings, has_single_use(), slsr_cand_d::index, slsr_cand_d::kind, lookup_cand(), slsr_cand_d::next_interp, stmt_cost(), and slsr_cand_d::stride.
Referenced by find_candidates_in_block().
|
static |
Given GS which is a multiply of scalar integers, make an appropriate entry in the candidate table. If this is a multiply of two SSA names, create two CAND_MULT interpretations and attempt to find a basis for each of them. Otherwise, create a single CAND_MULT and attempt to find a basis.
References add_cand_for_stmt(), slsr_cand_d::cand_num, create_mul_imm_cand(), create_mul_ssa_cand(), and slsr_cand_d::next_interp.
Referenced by find_candidates_in_block().
|
static |
Given GS which is a negate of a scalar integer, make an appropriate entry in the candidate table. A negate is equivalent to a multiply by -1.
References add_cand_for_stmt(), and create_mul_imm_cand().
Referenced by find_candidates_in_block().
|
static |
Given PHI which contains a phi statement, determine whether it satisfies all the requirements of a phi candidate. If so, create a candidate. Note that a CAND_PHI never has a basis itself, but is used to help find a basis for subsequent candidates.
References add_cand_for_stmt(), alloc_cand_and_find_basis(), base_cand_from_table(), slsr_cand_d::base_expr, CAND_ADD, CAND_PHI, slsr_cand_d::cand_stmt, slsr_cand_d::dead_savings, gimple_bb(), gimple_phi_arg_def(), gimple_phi_num_args(), has_single_use(), integer_onep(), slsr_cand_d::kind, lookup_cand(), basic_block_def::loop_father, slsr_cand_d::next_interp, operand_equal_p(), single_succ(), stmt_cost(), and slsr_cand_d::stride.
Referenced by find_candidates_in_block().
|
static |
Given GS which contains a data reference, create a CAND_REF entry in the candidate table and attempt to find a basis.
References add_cand_for_stmt(), alloc_cand_and_find_basis(), CAND_REF, double_int::from_uhwi(), get_inner_reference(), gimple_assign_lhs(), gimple_assign_rhs1(), gimple_vdef(), handled_component_p(), HOST_WIDE_INT, offset, restructure_reference(), and type().
Referenced by find_candidates_in_block().
int ssa_base_cand_dump_callback | ( | ) |
Callback used to dump the candidate chains hash table.
References cand_chain_d::base_expr, cand_chain_d::cand, slsr_cand_d::cand_num, dump_file, cand_chain_d::next, and print_generic_expr().
Referenced by dump_cand_chains().
|
static |
Determine the target cost of statement GS when compiling according to SPEED.
References add_cost(), convert_cost(), gimple_assign_lhs(), gimple_assign_rhs1(), gimple_assign_rhs2(), gimple_assign_rhs_code(), host_integerp(), is_gimple_assign(), mul_cost(), mult_by_coeff_cost(), and neg_cost().
Referenced by create_add_imm_cand(), create_add_ssa_cand(), create_mul_imm_cand(), create_mul_ssa_cand(), default_add_stmt_cost(), phi_incr_cost(), replace_uncond_cands_and_profitable_phis(), slsr_process_cast(), slsr_process_copy(), slsr_process_phi(), vect_bb_slp_scalar_cost(), and vect_get_single_scalar_iteration_cost().
|
static |
Compute the total savings that would accrue from all replacements in the candidate tree rooted at C, counting only candidates with increment INCR. Assume that replacing a candidate reduces cost by REPL_SAVINGS. Also account for savings from statements that would go dead.
References cand_abs_increment(), cand_already_replaced(), slsr_cand_d::cand_stmt, slsr_cand_d::dead_savings, slsr_cand_d::def_phi, slsr_cand_d::dependent, gimple_phi_result(), has_single_use(), lookup_cand(), phi_dependent_cand_p(), phi_incr_cost(), and slsr_cand_d::sibling.
Referenced by analyze_increments().
|
static |
Return the first candidate in the tree rooted at C that has not already been replaced, favoring siblings over dependents.
References cand_already_replaced(), slsr_cand_d::dependent, lookup_cand(), and slsr_cand_d::sibling.
Referenced by optimize_cands_for_speed_p().
|
static |
For a chain of candidates with unknown stride, indicates whether or not we must generate pointer arithmetic when replacing statements.
Referenced by all_phi_incrs_profitable(), analyze_candidates_and_replace(), cand_abs_increment(), create_add_on_incoming_edge(), ncd_with_phi(), record_increment(), and replace_one_candidate().
|
static |
Hash table embodying a mapping from base exprs to chains of candidates.
|
static |
Obstack for candidates.
Referenced by alloc_cand_and_find_basis(), and execute_strength_reduction().
|
static |
Candidates are maintained in a vector. If candidate X dominates candidate Y, then X appears before Y in the vector; but the converse does not necessarily hold.
|
static |
Obstack for candidate chains.
Referenced by execute_strength_reduction(), and record_potential_basis().
|
static |
An array INCR_VEC of incr_infos is used during analysis of related candidates having an SSA name for a stride. INCR_VEC_LEN describes its current length. MAX_INCR_VEC_LEN is used to avoid costly pathological cases.
|
static |
const int MAX_INCR_VEC_LEN = 16 |
Referenced by analyze_candidates_and_replace(), and record_increment().
|
static |
Pointer map embodying a mapping from statements to candidates.