GCC Middle and Back End API Reference
|
Data Structures | |
struct | prop_stats_d |
Functions | |
static bool | cfg_blocks_empty_p () |
static void | cfg_blocks_add () |
static basic_block | cfg_blocks_get () |
static void | add_ssa_edge () |
static void | add_control_edge () |
static void | simulate_stmt () |
static void | process_ssa_edge_worklist () |
static void | simulate_block () |
static void | ssa_prop_init () |
static void | ssa_prop_fini () |
bool | valid_gimple_rhs_p () |
static bool | valid_gimple_call_p () |
void | move_ssa_defining_stmt_for_defs () |
static void | finish_update_gimple_call (gimple_stmt_iterator *si_p, gimple new_stmt, gimple stmt) |
bool | update_gimple_call () |
bool | update_call_from_tree () |
void | ssa_propagate (ssa_prop_visit_stmt_fn visit_stmt, ssa_prop_visit_phi_fn visit_phi) |
bool | stmt_makes_single_store () |
static bool | replace_uses_in () |
static void | replace_phi_args_in () |
bool | substitute_and_fold (ssa_prop_get_value_fn get_value_fn, ssa_prop_fold_stmt_fn fold_fn, bool do_dce) |
Variables | |
static ssa_prop_visit_stmt_fn | ssa_prop_visit_stmt |
static ssa_prop_visit_phi_fn | ssa_prop_visit_phi |
static sbitmap | executable_blocks |
static vec< basic_block > | cfg_blocks |
static unsigned int | cfg_blocks_num = 0 |
static int | cfg_blocks_tail |
static int | cfg_blocks_head |
static sbitmap | bb_in_list |
static vec< gimple, va_gc > * | interesting_ssa_edges |
static vec< gimple, va_gc > * | varying_ssa_edges |
static struct prop_stats_d | prop_stats |
|
static |
Add edge E to the control flow worklist.
References bitmap_bit_p(), cfg_blocks_add(), edge_def::dest, dump_file, dump_flags, edge_def::flags, basic_block_def::index, and edge_def::src.
Referenced by simulate_block(), simulate_stmt(), and ssa_prop_init().
|
static |
We have just defined a new value for VAR. If IS_VARYING is true, add all immediate uses of VAR to VARYING_SSA_EDGES, otherwise add them to INTERESTING_SSA_EDGES.
References gimple_plf(), gimple_set_plf(), interesting_ssa_edges, prop_simulate_again_p(), varying_ssa_edges, and vec_safe_push().
Referenced by simulate_stmt().
|
static |
Add a basic block to the worklist. The block must not be already in the worklist, and it must not be the ENTRY or EXIT block.
References bitmap_bit_p(), bitmap_set_bit(), cfg_blocks_empty_p(), cfg_blocks_head, cfg_blocks_num, cfg_blocks_tail, basic_block_def::index, and basic_block_def::preds.
Referenced by add_control_edge().
|
inlinestatic |
Return true if the block worklist empty.
References cfg_blocks_num.
Referenced by cfg_blocks_add(), cfg_blocks_get(), and ssa_propagate().
|
static |
Remove a block from the worklist.
References bitmap_clear_bit(), cfg_blocks_empty_p(), cfg_blocks_head, cfg_blocks_num, and basic_block_def::index.
Referenced by ssa_propagate().
|
static |
Helper function for update_gimple_call and update_call_from_tree. A GIMPLE_CALL STMT is being replaced with GIMPLE_CALL NEW_STMT.
References gimple_block(), gimple_call_lhs(), gimple_call_set_lhs(), gimple_location(), gimple_set_block(), gimple_set_location(), gimple_set_vdef(), gimple_set_vuse(), gimple_vdef(), gimple_vuse(), gsi_replace(), and move_ssa_defining_stmt_for_defs().
Referenced by update_call_from_tree(), and update_gimple_call().
void move_ssa_defining_stmt_for_defs | ( | ) |
Make SSA names defined by OLD_STMT point to NEW_STMT as their defining statement.
References cfun, and gimple_in_ssa_p().
Referenced by finish_update_gimple_call(), and update_call_from_tree().
|
static |
Process an SSA edge worklist. WORKLIST is the SSA edge worklist to drain. This pops statements off the given WORKLIST and processes them until there are no more statements on WORKLIST. We take a pointer to WORKLIST because it may be reallocated when an SSA edge is added to it in simulate_stmt.
References bitmap_bit_p(), dump_file, dump_flags, gimple_bb(), gimple_plf(), gimple_set_plf(), basic_block_def::index, print_gimple_stmt(), and simulate_stmt().
Referenced by ssa_propagate().
|
static |
Replace propagated values into all the arguments for PHI using the values from PROP_VALUE.
References dump_file, dump_flags, edge_def::flags, gimple_phi_arg_def(), gimple_phi_arg_edge(), gimple_phi_num_args(), may_propagate_copy(), prop_stats_d::num_const_prop, prop_stats_d::num_copy_prop, print_gimple_stmt(), prop_stats, and propagate_value().
Referenced by substitute_and_fold().
|
static |
Replace USE references in statement STMT with the values stored in PROP_VALUE. Return true if at least one reference was replaced.
References may_propagate_copy(), may_propagate_copy_into_asm(), prop_stats_d::num_const_prop, prop_stats_d::num_copy_prop, prop_stats, and propagate_value().
Referenced by substitute_and_fold().
|
static |
Simulate the execution of BLOCK. Evaluate the statement associated with each variable reference inside the block.
References add_control_edge(), bitmap_bit_p(), bitmap_set_bit(), dump_file, dump_flags, edge_def::flags, gimple_plf(), gimple_set_plf(), gsi_end_p(), gsi_next(), gsi_start_bb(), gsi_start_phis(), gsi_stmt(), basic_block_def::index, simulate_stmt(), and basic_block_def::succs.
Referenced by ssa_propagate().
|
static |
Simulate the execution of STMT and update the work lists accordingly.
References add_control_edge(), add_ssa_edge(), gimple_bb(), gimple_phi_result(), prop_set_simulate_again(), prop_simulate_again_p(), SSA_PROP_INTERESTING, SSA_PROP_NOT_INTERESTING, SSA_PROP_VARYING, ssa_prop_visit_phi, ssa_prop_visit_stmt, stmt_ends_bb_p(), and basic_block_def::succs.
Referenced by process_ssa_edge_worklist(), and simulate_block().
|
static |
Free allocated storage.
References interesting_ssa_edges, sbitmap_free(), varying_ssa_edges, and vec_free().
Referenced by ssa_propagate().
|
static |
Initialize local data structures and work lists.
References add_control_edge(), bitmap_clear(), dump_file, dump_flags, dump_immediate_uses(), edge_def::flags, gimple_set_plf(), gsi_end_p(), gsi_next(), gsi_start_bb(), gsi_start_phis(), gsi_stmt(), interesting_ssa_edges, sbitmap_alloc(), si, basic_block_def::succs, varying_ssa_edges, and vec_alloc().
Referenced by ssa_propagate().
void ssa_propagate | ( | ssa_prop_visit_stmt_fn | visit_stmt, |
ssa_prop_visit_phi_fn | visit_phi | ||
) |
Entry point to the propagation engine. VISIT_STMT is called for every statement visited. VISIT_PHI is called for every PHI node visited.
References cfg_blocks_empty_p(), cfg_blocks_get(), interesting_ssa_edges, process_ssa_edge_worklist(), simulate_block(), ssa_prop_fini(), ssa_prop_init(), ssa_prop_visit_phi, ssa_prop_visit_stmt, varying_ssa_edges, and visit_phi().
Referenced by do_ssa_ccp(), execute_copy_prop(), execute_vrp(), and tree_lower_complex().
bool stmt_makes_single_store | ( | ) |
Return true if STMT is of the form 'mem_ref = RHS', where 'mem_ref' is a non-volatile pointer dereference, a structure reference or a reference to a single _DECL. Ignore volatile memory references because they are not interesting for the optimizers.
References gimple_get_lhs(), and gimple_vdef().
Referenced by determine_invariantness_stmt().
bool substitute_and_fold | ( | ssa_prop_get_value_fn | get_value_fn, |
ssa_prop_fold_stmt_fn | fold_fn, | ||
bool | do_dce | ||
) |
Perform final substitution and folding of propagated values. PROP_VALUE[I] contains the single value that should be substituted at every use of SSA name N_I. If PROP_VALUE is NULL, no values are substituted. If FOLD_FN is non-NULL the function will be invoked on all statements before propagating values for pass specific simplification. DO_DCE is true if trivially dead stmts can be removed. If DO_DCE is true, the statements within a BB are walked from last to first element. Otherwise we scan from first to last element. Return TRUE when something changed.
References cfun, dump_file, dump_flags, fold_stmt(), get_gimple_rhs_class(), gimple_assign_rhs1(), gimple_assign_rhs_code(), gimple_assign_set_rhs_with_ops(), gimple_assign_single_p(), gimple_call_flags(), gimple_get_lhs(), gimple_has_side_effects(), gimple_nop_p(), gimple_purge_dead_eh_edges(), GIMPLE_SINGLE_RHS, gsi_after_labels(), gsi_end_p(), gsi_for_stmt(), gsi_insert_before(), gsi_last_bb(), gsi_next(), gsi_prev(), gsi_remove(), GSI_SAME_STMT, gsi_start_bb(), gsi_start_phis(), gsi_stmt(), has_zero_uses(), i2, is_gimple_assign(), is_gimple_call(), is_gimple_debug(), may_propagate_copy(), maybe_clean_eh_stmt(), maybe_clean_or_replace_eh_stmt(), memset(), prop_stats_d::num_const_prop, prop_stats_d::num_copy_prop, prop_stats_d::num_dce, prop_stats_d::num_stmts_folded, print_gimple_stmt(), prop_stats, recompute_tree_invariant_for_addr_expr(), release_defs(), remove_phi_node(), replace_phi_args_in(), replace_uses_in(), statistics_counter_event(), stmt_could_throw_p(), update_call_from_tree(), update_stmt(), and virtual_operand_p().
Referenced by ccp_finalize(), fini_copy_prop(), and vrp_finalize().
bool update_call_from_tree | ( | ) |
Update a GIMPLE_CALL statement at iterator *SI_P to reflect the value of EXPR, which is expected to be the result of folding the call. This can only be done if EXPR is a CALL_EXPR with valid GIMPLE operands as arguments, or if it is a suitable RHS expression for a GIMPLE_ASSIGN. More complex expressions will require gimplification, which will introduce additional statements. In this event, no update is performed, and the function returns false. Note that we cannot mutate a GIMPLE_CALL in-place, so we always replace the statement at *SI_P with an entirely new statement. The new statement need not be a call, e.g., if the original call folded to a constant.
References cfun, create_tmp_var(), finish_update_gimple_call(), gimple_build_call_vec(), gimple_build_nop(), gimple_call_lhs(), gimple_in_ssa_p(), gimple_location(), gimple_set_location(), gimple_set_vdef(), gimple_set_vuse(), gimple_vdef(), gimple_vuse(), gsi_replace(), gsi_stmt(), make_ssa_name(), move_ssa_defining_stmt_for_defs(), release_defs(), unlink_stmt_vdef(), valid_gimple_call_p(), valid_gimple_rhs_p(), and vNULL.
Referenced by adjust_simduid_builtins(), ccp_fold_stmt(), compute_object_sizes(), execute_fold_all_builtins(), gimple_fold_call(), handle_builtin_strchr(), handle_builtin_strlen(), optimize_stack_restore(), propagate_tree_value_into_stmt(), and substitute_and_fold().
bool update_gimple_call | ( | ) |
Update a GIMPLE_CALL statement at iterator *SI_P to call to FN with number of arguments NARGS, where the arguments in GIMPLE form follow NARGS argument.
References finish_update_gimple_call(), gimple_build_call_valist(), gsi_stmt(), and is_gimple_call().
Referenced by handle_builtin_strcat(), handle_builtin_strcpy(), and instrument_builtin_call().
|
static |
Return true if EXPR is a CALL_EXPR suitable for representation as a single GIMPLE_CALL statement. If the arguments require further gimplification, return false.
References is_gimple_lvalue(), is_gimple_reg_type(), and is_gimple_val().
Referenced by update_call_from_tree().
bool valid_gimple_rhs_p | ( | ) |
Return true if EXPR is an acceptable right-hand-side for a GIMPLE assignment. We validate the entire tree, not just the root node, thus catching expressions that embed complex operands that are not permitted in GIMPLE. This function is needed because the folding routines in fold-const.c may return such expressions in some cases, e.g., an array access with an embedded index addition. It may make more sense to have folding routines that are sensitive to the constraints on GIMPLE operands, rather than abandoning any any attempt to fold if the usual folding turns out to be too aggressive.
References get_gimple_rhs_class(), GIMPLE_TERNARY_RHS, handled_component_p(), is_gimple_condexpr(), is_gimple_id(), is_gimple_min_invariant(), is_gimple_val(), is_gimple_variable(), tcc_binary, tcc_comparison, tcc_constant, tcc_declaration, tcc_exceptional, tcc_expression, tcc_reference, tcc_unary, and tcc_vl_exp.
Referenced by fold_gimple_assign(), fold_gimple_cond(), rewrite_use_nonlinear_expr(), simplify_binary_expression(), simplify_bitfield_ref(), simplify_unary_expression(), update_call_from_tree(), and visit_use().
|
static |
|
static |
Array of control flow edges on the worklist.
|
static |
Referenced by cfg_blocks_add(), and cfg_blocks_get().
|
static |
Referenced by cfg_blocks_add(), cfg_blocks_empty_p(), and cfg_blocks_get().
|
static |
Referenced by cfg_blocks_add().
|
static |
A bitmap to keep track of executable blocks in the CFG.
Worklist of SSA edges which will need reexamination as their definition has changed. SSA edges are def-use edges in the SSA web. For each D-U edge, we store the target statement or PHI node U.
Referenced by add_ssa_edge(), ssa_prop_fini(), ssa_prop_init(), and ssa_propagate().
|
static |
Referenced by replace_phi_args_in(), replace_uses_in(), and substitute_and_fold().
|
static |
Referenced by simulate_stmt(), and ssa_propagate().
|
static |
Generic SSA value propagation engine. Copyright (C) 2004-2013 Free Software Foundation, Inc. Contributed by Diego Novillo <dnovillo@redhat.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/>.
This file implements a generic value propagation engine based on the same propagation used by the SSA-CCP algorithm [1]. Propagation is performed by simulating the execution of every statement that produces the value being propagated. Simulation proceeds as follows: 1- Initially, all edges of the CFG are marked not executable and the CFG worklist is seeded with all the statements in the entry basic block (block 0). 2- Every statement S is simulated with a call to the call-back function SSA_PROP_VISIT_STMT. This evaluation may produce 3 results: SSA_PROP_NOT_INTERESTING: Statement S produces nothing of interest and does not affect any of the work lists. SSA_PROP_VARYING: The value produced by S cannot be determined at compile time. Further simulation of S is not required. If S is a conditional jump, all the outgoing edges for the block are considered executable and added to the work list. SSA_PROP_INTERESTING: S produces a value that can be computed at compile time. Its result can be propagated into the statements that feed from S. Furthermore, if S is a conditional jump, only the edge known to be taken is added to the work list. Edges that are known not to execute are never simulated. 3- PHI nodes are simulated with a call to SSA_PROP_VISIT_PHI. The return value from SSA_PROP_VISIT_PHI has the same semantics as described in #2. 4- Three work lists are kept. Statements are only added to these lists if they produce one of SSA_PROP_INTERESTING or SSA_PROP_VARYING. CFG_BLOCKS contains the list of blocks to be simulated. Blocks are added to this list if their incoming edges are found executable. VARYING_SSA_EDGES contains the list of statements that feed from statements that produce an SSA_PROP_VARYING result. These are simulated first to speed up processing. INTERESTING_SSA_EDGES contains the list of statements that feed from statements that produce an SSA_PROP_INTERESTING result. 5- Simulation terminates when all three work lists are drained. Before calling ssa_propagate, it is important to clear prop_simulate_again_p for all the statements in the program that should be simulated. This initialization allows an implementation to specify which statements should never be simulated. It is also important to compute def-use information before calling ssa_propagate. References: [1] Constant propagation with conditional branches, Wegman and Zadeck, ACM TOPLAS 13(2):181-210. [2] Building an Optimizing Compiler, Robert Morgan, Butterworth-Heinemann, 1998, Section 8.9. [3] Advanced Compiler Design and Implementation, Steven Muchnick, Morgan Kaufmann, 1997, Section 12.6
Function pointers used to parameterize the propagation engine.
Referenced by simulate_stmt(), and ssa_propagate().
Identical to INTERESTING_SSA_EDGES. For performance reasons, the list of SSA edges is split into two. One contains all SSA edges who need to be reexamined because their lattice value changed to varying (this worklist), and the other contains all other SSA edges to be reexamined (INTERESTING_SSA_EDGES). Since most values in the program are VARYING, the ideal situation is to move them to that lattice value as quickly as possible. Thus, it doesn't make sense to process any other type of lattice value until all VARYING values are propagated fully, which is one thing using the VARYING worklist achieves. In addition, if we don't use a separate worklist for VARYING edges, we end up with situations where lattice values move from UNDEFINED->INTERESTING->VARYING instead of UNDEFINED->VARYING.
Referenced by add_ssa_edge(), ssa_prop_fini(), ssa_prop_init(), and ssa_propagate().