GCC Middle and Back End API Reference
|
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "backend.h"
#include "tree.h"
#include "gimple.h"
#include "tree-pass.h"
#include "ssa.h"
#include "gimple-pretty-print.h"
#include "gimple-iterator.h"
#include "stor-layout.h"
#include "tree-into-ssa.h"
#include "tree-ssa.h"
#include "cfgloop.h"
#include "tree-scalar-evolution.h"
#include "value-query.h"
#include "value-range-storage.h"
Macros | |
#define | UNUSED_NAME_VERSION 0 |
#define | FREE_SSANAMES(fun) |
#define | FREE_SSANAMES_QUEUE(fun) |
Variables | |
unsigned int | ssa_name_nodes_reused |
unsigned int | ssa_name_nodes_created |
#define FREE_SSANAMES | ( | fun | ) |
Referenced by fini_ssanames(), flush_ssaname_freelist(), init_ssanames(), make_ssa_name_fn(), release_free_names_and_compact_live_names(), and verify_ssaname_freelists().
#define FREE_SSANAMES_QUEUE | ( | fun | ) |
Referenced by fini_ssanames(), flush_ssaname_freelist(), init_ssanames(), release_ssa_name_fn(), and verify_ssaname_freelists().
#define UNUSED_NAME_VERSION 0 |
Generic routines for manipulating SSA_NAME expressions Copyright (C) 2003-2024 Free Software Foundation, Inc. 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/>.
Rewriting a function into SSA form can create a huge number of SSA_NAMEs, many of which may be thrown away shortly after their creation if jumps were threaded through PHI nodes. While our garbage collection mechanisms will handle this situation, it is extremely wasteful to create nodes and throw them away, especially when the nodes can be reused. For PR 8361, we can significantly reduce the number of nodes allocated and thus the total amount of memory allocated by managing SSA_NAMEs a little. This additionally helps reduce the amount of work done by the garbage collector. Similar results have been seen on a wider variety of tests (such as the compiler itself). Right now we maintain our free list on a per-function basis. It may or may not make sense to maintain the free list for the duration of a compilation unit. External code should rely solely upon HIGHEST_SSA_VERSION and the externally defined functions. External code should not know about the details of the free list management. External code should also not assume the version number on nodes is monotonically increasing. We reuse the version number when we reuse an SSA_NAME expression. This helps keep arrays and bitmaps more compact.
Version numbers with special meanings. We start allocating new version numbers after the special ones.
Referenced by verify_ssaname_freelists().
void adjust_ptr_info_misalignment | ( | struct ptr_info_def * | pi, |
poly_uint64 | increment ) |
If pointer described by PI has known alignment, increase its known misalignment by INCREMENT modulo its current alignment.
References ptr_info_def::align, and ptr_info_def::misalign.
Creates a new SSA name using the template NAME tobe defined by statement STMT in function FN.
References make_ssa_name_fn(), SET_SSA_NAME_VAR_OR_IDENTIFIER, SSA_NAME_IDENTIFIER, SSA_NAME_VAR, and TREE_TYPE.
Referenced by copy_ssa_name(), duplicate_ssa_name_fn(), and replace_ssa_name().
Creates a duplicate of a ssa name NAME tobe defined by statement STMT in function FN.
References copy_ssa_name_fn(), duplicate_ssa_name_ptr_info(), duplicate_ssa_name_range_info(), POINTER_TYPE_P, range_info_p(), SSA_NAME_PTR_INFO, and TREE_TYPE.
Referenced by duplicate_ssa_name().
void duplicate_ssa_name_ptr_info | ( | tree | name, |
struct ptr_info_def * | ptr_info ) |
Creates a duplicate of the ptr_info_def at PTR_INFO for use by the SSA name NAME.
References gcc_assert, ggc_alloc(), POINTER_TYPE_P, SSA_NAME_PTR_INFO, and TREE_TYPE.
Referenced by bump_vector_ptr(), copy_ref_info(), duplicate_ssa_name_fn(), issue_prefetch_ref(), maybe_duplicate_ssa_info_at_copy(), rewrite_use_nonlinear_expr(), and vect_duplicate_ssa_name_ptr_info().
References gcc_checking_assert, POINTER_TYPE_P, range_info_get_range(), range_info_p(), range_info_set_range(), and TREE_TYPE.
Referenced by duplicate_ssa_name_fn(), maybe_duplicate_ssa_info_at_copy(), remap_ssa_name(), and replace_phi_edge_with_variable().
void fini_ssanames | ( | struct function * | fn | ) |
Finalize management of SSA_NAMEs.
References FOR_EACH_VEC_SAFE_ELT, FREE_SSANAMES, FREE_SSANAMES_QUEUE, i, NULL, SSA_NAME_DEF_STMT, SSANAMES, and vec_free().
Referenced by delete_tree_ssa().
void flush_ssaname_freelist | ( | void | ) |
Move all SSA_NAMEs from FREE_SSA_NAMES_QUEUE to FREE_SSA_NAMES. We do not, but should have a mode to verify the state of the SSA_NAMEs lists. In particular at this point every name must be in the IL, on the free list or in the queue. Anything else is an error.
References cfun, FREE_SSANAMES, FREE_SSANAMES_QUEUE, scev_reset_htab(), vec_safe_is_empty(), vec_safe_splice(), and vec_safe_truncate().
Referenced by execute_todo().
wide_int get_known_nonzero_bits | ( | const_tree | name | ) |
Return a wide_int with known non-zero bits in SSA_NAME NAME, the constant for INTEGER_CST, or -1 if unknown. In addition to what get_known_nonzero_bits_1 handles, this handles one level of BIT_IOR_EXPR, either as a def_stmt or tree directly.
References g, get_known_nonzero_bits_1(), gimple_assign_rhs1(), gimple_assign_rhs2(), gimple_assign_rhs_code(), is_gimple_assign(), SSA_NAME_DEF_STMT, TREE_CODE, and TREE_OPERAND.
|
static |
Return a wide_int with known non-zero bits in SSA_NAME NAME (bits whose values aren't known are also clear), the constant for INTEGER_CST, or 0 if unknown.
References element_precision(), irange::get_bitmask(), POINTER_TYPE_P, range_info_get_range(), range_info_p(), wi::shwi(), irange::supports_p(), wi::to_wide(), TREE_CODE, TREE_TYPE, vrange::undefined_p(), and irange_bitmask::value().
Referenced by get_known_nonzero_bits().
wide_int get_nonzero_bits | ( | const_tree | name | ) |
Return a wide_int with potentially non-zero bits in SSA_NAME NAME, the constant for INTEGER_CST, or -1 if unknown. In addition to what get_nonzero_bits_1 handles, this handles one level of BIT_AND_EXPR, either as a def_stmt or tree directly.
References g, get_nonzero_bits_1(), gimple_assign_rhs1(), gimple_assign_rhs2(), gimple_assign_rhs_code(), is_gimple_assign(), SSA_NAME_DEF_STMT, TREE_CODE, and TREE_OPERAND.
Referenced by evaluate_stmt(), expr_not_equal_to(), get_default_value(), range_query::get_tree_range(), ipcp_bits_lattice::get_value_and_mask(), handle_builtin_alloca(), maybe_set_nonzero_bits(), optimize_range_tests_var_bound(), split_constant_offset(), ssa_name_has_boolean_range(), tree_ctz(), tree_nonzero_bits(), validate_test_and_branch(), and vect_get_range_info().
|
static |
Return a wide_int with potentially non-zero bits in SSA_NAME NAME, the constant for INTEGER_CST, or -1 if unknown.
References ptr_info_def::align, element_precision(), vrange::get_nonzero_bits(), ptr_info_def::misalign, POINTER_TYPE_P, POLY_INT_CST_P, range_info_get_range(), range_info_p(), wi::shwi(), SSA_NAME_PTR_INFO, irange::supports_p(), wi::to_poly_wide(), wi::to_wide(), TREE_CODE, and TREE_TYPE.
Referenced by get_nonzero_bits().
struct ptr_info_def * get_ptr_info | ( | tree | t | ) |
Return the alias information associated with pointer T. It creates a new instance if none existed.
References gcc_assert, ggc_cleared_alloc(), mark_ptr_info_alignment_unknown(), NULL, POINTER_TYPE_P, ptr_info_def::pt, pt_solution_reset(), SSA_NAME_PTR_INFO, and TREE_TYPE.
Referenced by ccp_finalize(), copy_ref_info(), create_array_ref(), create_expression_by_pieces(), find_what_p_points_to(), ipcp_update_vr(), lower_builtin_assume_aligned(), maybe_set_nonzero_bits(), remap_ssa_name(), set_ptr_nonnull(), set_range_info(), update_alias_info_with_stack_vars(), vectorizable_load(), and vectorizable_store().
bool get_ptr_info_alignment | ( | struct ptr_info_def * | pi, |
unsigned int * | alignp, | ||
unsigned int * | misalignp ) |
If the alignment of the pointer described by PI is known, return true and store the alignment and the deviation from it into *ALIGNP and *MISALIGNP respectively. Otherwise return false.
References ptr_info_def::align, and ptr_info_def::misalign.
Referenced by dump_ssaname_info(), get_pointer_alignment_1(), and ipcp_update_vr().
void init_ssa_name_imm_use | ( | tree | name | ) |
Initialize SSA_NAME_IMM_USE_NODE of a SSA NAME.
References ssa_use_operand_t::loc, ssa_use_operand_t::next, NULL, ssa_use_operand_t::prev, ssa_use_operand_t::ssa_name, SSA_NAME_IMM_USE_NODE, and ssa_use_operand_t::use.
Referenced by make_ssa_name_fn(), and maybe_fold_comparisons_from_match_pd().
void init_ssanames | ( | struct function * | fn, |
int | size ) |
Initialize management of SSA_NAMEs to default SIZE. If SIZE is zero use default.
References FREE_SSANAMES, FREE_SSANAMES_QUEUE, function::gimple_df, NULL, NULL_TREE, gimple_df::rename_vops, gimple_df::ssa_renaming_needed, SSANAMES, vec_alloc(), and vec_safe_reserve().
Referenced by init_tree_ssa().
gimple_opt_pass * make_pass_release_ssa_names | ( | gcc::context * | ctxt | ) |
Return an SSA_NAME node for variable VAR defined in statement STMT in function FN. STMT may be an empty statement for artificial references (e.g., default definitions created when a variable is used without a preceding definition). If VERISON is not zero then allocate the SSA name with that version.
References FREE_SSANAMES, gcc_assert, init_ssa_name_imm_use(), is_gimple_reg_type(), make_node(), NULL, NULL_TREE, POINTER_TYPE_P, SET_SSA_NAME_VAR_OR_IDENTIFIER, SSA_NAME_DEF_STMT, SSA_NAME_IN_FREE_LIST, SSA_NAME_IS_DEFAULT_DEF, ssa_name_nodes_created, ssa_name_nodes_reused, SSA_NAME_PTR_INFO, SSA_NAME_RANGE_INFO, SSA_NAME_VERSION, SSANAMES, TREE_CODE, TREE_TYPE, TYPE_MAIN_VARIANT, TYPE_P, VAR_P, vec_safe_grow_cleared(), vec_safe_is_empty(), and vec_safe_push().
Referenced by copy_ssa_name_fn(), get_or_create_ssa_default_def(), input_ssa_names(), make_ssa_name(), make_temp_ssa_name(), move_sese_region_to_fn(), and replace_ssa_name().
void mark_ptr_info_alignment_unknown | ( | struct ptr_info_def * | pi | ) |
State that the pointer described by PI has unknown alignment.
References ptr_info_def::align, and ptr_info_def::misalign.
Referenced by bump_vector_ptr(), get_ptr_info(), issue_prefetch_ref(), reset_flow_sensitive_info(), flow_sensitive_info_storage::restore(), rewrite_use_nonlinear_expr(), and vect_duplicate_ssa_name_ptr_info().
For a SSA copy DEST = SRC duplicate SSA info present on DEST to SRC to preserve it in case DEST is eliminated to SRC.
References duplicate_ssa_name_ptr_info(), duplicate_ssa_name_range_info(), gimple_bb(), INTEGRAL_TYPE_P, POINTER_TYPE_P, SSA_NAME_DEF_STMT, SSA_NAME_PTR_INFO, SSA_NAME_RANGE_INFO, and TREE_TYPE.
Referenced by substitute_and_fold_dom_walker::before_dom_children(), eliminate_dom_walker::eliminate_stmt(), fini_copy_prop(), and fwprop_set_lattice_val().
Allocate a new global range for NAME and set it to R. Return the allocation slot.
References ggc_alloc_vrange_storage(), r, and SSA_NAME_RANGE_INFO.
Referenced by range_info_set_range().
Return TRUE if R fits in the global range of NAME.
References vrange_storage::fits_p(), gcc_checking_assert, r, range_info_p(), and SSA_NAME_RANGE_INFO.
Referenced by range_info_set_range().
|
inline |
Free storage allocated for the global range for NAME.
References ggc_free(), and SSA_NAME_RANGE_INFO.
Referenced by range_info_set_range().
|
inline |
Return the global range for NAME in R.
References r, SSA_NAME_RANGE_INFO, and TREE_TYPE.
Referenced by duplicate_ssa_name_range_info(), get_known_nonzero_bits_1(), get_nonzero_bits_1(), and set_range_info().
|
inline |
Return TRUE if NAME has global range info.
References SSA_NAME_RANGE_INFO.
Referenced by duplicate_ssa_name_fn(), duplicate_ssa_name_range_info(), get_known_nonzero_bits_1(), get_nonzero_bits_1(), range_info_fits_p(), range_info_set_range(), and set_range_info().
Set the global range for NAME from R. Return TRUE if successfull, or FALSE if we can't set a range of NAME's type.
References r, range_info_alloc(), range_info_fits_p(), range_info_free(), range_info_p(), and SSA_NAME_RANGE_INFO.
Referenced by duplicate_ssa_name_range_info(), and set_range_info().
void release_defs | ( | gimple * | stmt | ) |
Release all the SSA_NAMEs created by STMT.
References FOR_EACH_SSA_TREE_OPERAND, release_ssa_name(), SSA_OP_ALL_DEFS, and TREE_CODE.
Referenced by strlen_pass::adjust_last_stmt(), adjust_simduid_builtins(), cancel_fma_deferring(), cond_if_else_store_replacement_1(), cond_store_replacement(), convert_mult_to_fma_1(), convert_scalar_cond_reduction(), delete_dead_or_redundant_assignment(), delete_dead_or_redundant_call(), eliminate_dom_walker::eliminate_cleanup(), eliminate_tail_call(), execute_cse_conv_1(), execute_early_expand_coro_ifns(), expand_omp_atomic_fetch_op(), expand_omp_atomic_pipeline(), factor_out_conditional_operation(), forward_propagate_addr_expr(), generate_loops_for_partition(), gimple_seq_discard(), gimplify_and_update_call_from_tree(), strlen_pass::handle_builtin_memset(), strlen_pass::handle_store(), hoist_memory_references(), ifcvt_local_dce(), input_function(), linearize_expr(), match_single_bit_test(), match_uaddc_usubc(), maybe_remove_writeonly_store(), optimize_atomic_bit_test_and(), optimize_clobbers(), optimize_mask_stores(), optimize_recip_sqrt(), dom_opt_dom_walker::optimize_stmt(), optimize_vector_load(), predicate_statements(), propagate_op_to_single_use(), reassociate_bb(), release_defs_bitset(), remove_bb(), remove_dead_stmt(), remove_indirect_clobbers(), remove_prop_source_from_use(), pcom_worker::remove_stmt(), vec_info::remove_stmt(), remove_unused_locals(), remove_visited_stmt_chain(), repropagate_negates(), ipa_param_body_adjustments::reset_debug_stmts(), rewrite_bittest(), simple_dce_from_worklist(), simplify_builtin_call(), sink_clobbers(), sink_code_in_bb(), sink_common_stores_to_bb(), sra_modify_assign(), sra_modify_constructor_assign(), sra_modify_deferred_init(), vect_transform_loop(), and vect_transform_slp_perm_load_1().
|
static |
Release the vector of free SSA_NAMEs and compact the vector of SSA_NAMEs that are live.
References dump_file, FREE_SSANAMES, function::gimple_df, i, num_ssa_names, ssa_name, SSA_NAME_VERSION, gimple_df::ssa_names, statistics_counter_event(), vec_free(), and vec_safe_length().
We no longer need the SSA_NAME expression VAR, release it so that it may be reused. Note it is assumed that no calls to make_ssa_name will be made until all uses of the ssa name are released and that the only use of the SSA_NAME expression is to check its SSA_NAME_VAR. All other fields must be assumed clobbered.
References delink_imm_use(), error_mark_node, FREE_SSANAMES_QUEUE, insert_debug_temp_for_var_def(), ssa_use_operand_t::loc, MAY_HAVE_DEBUG_BIND_STMTS, name_registered_for_update_p(), ssa_use_operand_t::next, NULL, NULL_TREE, ssa_use_operand_t::prev, release_ssa_name_after_update_ssa(), ssa_use_operand_t::ssa_name, SSA_NAME_IMM_USE_NODE, SSA_NAME_IN_FREE_LIST, SSA_NAME_IS_DEFAULT_DEF, SSA_NAME_VERSION, SSANAMES, TREE_SET_CODE, tree_size(), TREE_TYPE, vec_safe_push(), and verify_imm_links().
Referenced by expand_ifn_va_arg_1(), operands_scanner::finalize_ssa_defs(), and release_ssa_name().
Replace the symbol associated with SSA_NAME with SYM.
References SET_SSA_NAME_VAR_OR_IDENTIFIER, ssa_name, and TREE_TYPE.
Referenced by base_names_in_chain_on(), separate_decls_in_region_name(), and set_component_ssa_name().
void reset_flow_sensitive_info | ( | tree | name | ) |
Reset all flow sensitive data on NAME such as range-info, nonzero bits and alignment.
References mark_ptr_info_alignment_unknown(), NULL, POINTER_TYPE_P, SSA_NAME_PTR_INFO, SSA_NAME_RANGE_INFO, and TREE_TYPE.
Referenced by combine_blocks(), cond_removal_in_builtin_zero_pattern(), copy_ref_info(), ifcombine_replace_cond(), minmax_replacement(), move_computations_worker(), move_stmt(), reset_flow_sensitive_info_in_bb(), flow_sensitive_info_storage::save_and_clear(), and value_replacement().
void reset_flow_sensitive_info_in_bb | ( | basic_block | bb | ) |
Clear all flow sensitive data from all statements and PHI definitions in BB.
References FOR_EACH_SSA_TREE_OPERAND, gimple_phi_result(), gsi_end_p(), gsi_next(), gsi_start_bb(), gsi_start_phis(), gsi_stmt(), i, reset_flow_sensitive_info(), and SSA_OP_DEF.
Referenced by ifcombine_replace_cond(), maybe_optimize_range_tests(), and replace_block_by().
Update the known bits of NAME. Zero bits in MASK cover constant values. Set bits in MASK cover unknown values. VALUE are the known bits.
References gcc_assert, POINTER_TYPE_P, r, set_range_info(), and TREE_TYPE.
Referenced by ccp_finalize().
Update the non-zero bits bitmask of NAME.
References gcc_assert, POINTER_TYPE_P, r, set_range_info(), and TREE_TYPE.
Referenced by maybe_set_nonzero_bits().
void set_ptr_info_alignment | ( | struct ptr_info_def * | pi, |
unsigned int | align, | ||
unsigned int | misalign ) |
Store the power-of-two byte alignment and the deviation from that alignment of pointer described by PI to ALIOGN and MISALIGN respectively.
References ptr_info_def::align, gcc_assert, gcc_checking_assert, and ptr_info_def::misalign.
Referenced by ccp_finalize(), create_array_ref(), create_expression_by_pieces(), ipcp_update_vr(), lower_builtin_assume_aligned(), maybe_set_nonzero_bits(), flow_sensitive_info_storage::restore(), vectorizable_load(), and vectorizable_store().
void set_ptr_nonnull | ( | tree | name | ) |
Set nonnull attribute to pointer NAME.
References gcc_assert, get_ptr_info(), pt_solution::null, POINTER_TYPE_P, ptr_info_def::pt, and TREE_TYPE.
Referenced by find_what_p_points_to(), and set_range_info().
Update the range information for NAME, intersecting into an existing range if applicable. Return TRUE if the range was updated.
References value_range::dump(), dump_file, fputc(), get_ptr_info(), gimple_range_global(), value_range::intersect(), pt_solution::null, POINTER_TYPE_P, print_generic_expr(), ptr_info_def::pt, r, range_info_get_range(), range_info_p(), range_info_set_range(), set_ptr_nonnull(), value_range::set_varying(), TDF_SLIM, TREE_TYPE, and value_range::undefined_p().
Referenced by assume_query::assume_query(), gimple_ranger::export_global_ranges(), strlen_pass::handle_builtin_string_cmp(), remove_unreachable::handle_early(), strlen_pass::handle_integral_assign(), insert_into_preds_of_block(), ipcp_update_vr(), optimize_spaceship(), dom_ranger::range_of_stmt(), gimple_ranger::register_inferred_ranges(), remove_unreachable::remove(), remove_unreachable::remove_and_update_globals(), set_bitmask(), dom_opt_dom_walker::set_global_ranges_from_unreachable_edges(), set_nonzero_bits(), set_strlen_range(), simplify_using_ranges::simplify_truth_ops_using_ranges(), value_replacement(), vect_do_peeling(), and vect_gen_vector_loop_niters().
Return TRUE is OP, an SSA_NAME has a range of values [0..1], false otherwise. This can be because it is a boolean type, any unsigned integral type with a single bit of precision, or has known range of [0..1] via range analysis.
References cfun, wi::eq_p(), gcc_assert, get_nonzero_bits(), get_range_query(), INTEGRAL_TYPE_P, r, range_true_and_false(), TREE_CODE, TREE_TYPE, TYPE_PRECISION, and TYPE_UNSIGNED.
Referenced by associate_equivalences_with_edges(), edge_info::derive_equivalences(), dom_opt_dom_walker::optimize_stmt(), and record_edge_info().
void ssanames_print_statistics | ( | void | ) |
Dump some simple statistics regarding the re-use of SSA_NAME nodes.
References PRsa, SIZE_AMOUNT, ssa_name_nodes_created, and ssa_name_nodes_reused.
Referenced by dump_tree_statistics().
DEBUG_FUNCTION void verify_ssaname_freelists | ( | struct function * | fun | ) |
Verify the state of the SSA_NAME lists. There must be no duplicates on the free list. Every name on the free list must be marked as on the free list. Any name on the free list must not appear in the IL. No names can be leaked.
References bitmap_bit_p, bitmap_intersect_p(), bitmap_ior_into(), bitmap_set_bit, bitmap_set_range(), EXECUTE_IF_AND_COMPL_IN_BITMAP, FOR_EACH_BB_FN, FOR_EACH_SSA_TREE_OPERAND, FREE_SSANAMES, FREE_SSANAMES_QUEUE, gcc_assert, gimple_in_ssa_p(), gimple_phi_arg_def(), gimple_phi_num_args(), gimple_phi_result(), gsi_end_p(), gsi_next(), gsi_start_bb(), gsi_start_phis(), gsi_stmt(), i, names_to_release, num_ssa_names, ssa_name, SSA_NAME_IN_FREE_LIST, SSA_NAME_IS_DEFAULT_DEF, SSA_NAME_VERSION, SSA_OP_ALL_OPERANDS, TREE_CODE, and UNUSED_NAME_VERSION.
unsigned int ssa_name_nodes_created |
Referenced by make_ssa_name_fn(), and ssanames_print_statistics().
unsigned int ssa_name_nodes_reused |
Referenced by make_ssa_name_fn(), and ssanames_print_statistics().