GCC Middle and Back End API Reference
tree-ssanames.cc File 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-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"
Include dependency graph for tree-ssanames.cc:

Macros

#define UNUSED_NAME_VERSION   0
 
#define FREE_SSANAMES(fun)   (fun)->gimple_df->free_ssanames
 
#define FREE_SSANAMES_QUEUE(fun)   (fun)->gimple_df->free_ssanames_queue
 

Functions

bool range_info_p (const_tree name)
 
bool range_info_fits_p (tree name, const vrange &r)
 
voidrange_info_alloc (tree name, const vrange &r)
 
void range_info_free (tree name)
 
void range_info_get_range (const_tree name, vrange &r)
 
bool range_info_set_range (tree name, const vrange &r)
 
void init_ssanames (struct function *fn, int size)
 
void fini_ssanames (struct function *fn)
 
void ssanames_print_statistics (void)
 
DEBUG_FUNCTION void verify_ssaname_freelists (struct function *fun)
 
void flush_ssaname_freelist (void)
 
void init_ssa_name_imm_use (tree name)
 
tree make_ssa_name_fn (struct function *fn, tree var, gimple *stmt, unsigned int version)
 
bool set_range_info (tree name, const vrange &r)
 
void set_ptr_nonnull (tree name)
 
void set_nonzero_bits (tree name, const wide_int &mask)
 
void set_bitmask (tree name, const wide_int &value, const wide_int &mask)
 
wide_int get_nonzero_bits (const_tree name)
 
bool ssa_name_has_boolean_range (tree op)
 
void release_ssa_name_fn (struct function *fn, tree var)
 
bool get_ptr_info_alignment (struct ptr_info_def *pi, unsigned int *alignp, unsigned int *misalignp)
 
void mark_ptr_info_alignment_unknown (struct ptr_info_def *pi)
 
void set_ptr_info_alignment (struct ptr_info_def *pi, unsigned int align, unsigned int misalign)
 
void adjust_ptr_info_misalignment (struct ptr_info_def *pi, poly_uint64 increment)
 
struct ptr_info_defget_ptr_info (tree t)
 
tree copy_ssa_name_fn (struct function *fn, tree name, gimple *stmt)
 
void duplicate_ssa_name_ptr_info (tree name, struct ptr_info_def *ptr_info)
 
void duplicate_ssa_name_range_info (tree name, tree src)
 
tree duplicate_ssa_name_fn (struct function *fn, tree name, gimple *stmt)
 
void reset_flow_sensitive_info (tree name)
 
void reset_flow_sensitive_info_in_bb (basic_block bb)
 
void release_defs (gimple *stmt)
 
void replace_ssa_name_symbol (tree ssa_name, tree sym)
 
static void release_free_names_and_compact_live_names (function *fun)
 
gimple_opt_passmake_pass_release_ssa_names (gcc::context *ctxt)
 

Variables

unsigned int ssa_name_nodes_reused
 
unsigned int ssa_name_nodes_created
 

Macro Definition Documentation

◆ FREE_SSANAMES

◆ FREE_SSANAMES_QUEUE

#define FREE_SSANAMES_QUEUE ( fun)    (fun)->gimple_df->free_ssanames_queue

◆ UNUSED_NAME_VERSION

#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().

Function Documentation

◆ adjust_ptr_info_misalignment()

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 ggc_alloc().

◆ copy_ssa_name_fn()

tree copy_ssa_name_fn ( struct function * fn,
tree name,
gimple * stmt )
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().

◆ duplicate_ssa_name_fn()

tree duplicate_ssa_name_fn ( struct function * fn,
tree name,
gimple * stmt )
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(), ggc_alloc(), POINTER_TYPE_P, range_info_p(), SSA_NAME_PTR_INFO, and TREE_TYPE.

Referenced by duplicate_ssa_name().

◆ duplicate_ssa_name_ptr_info()

void duplicate_ssa_name_ptr_info ( tree name,
struct ptr_info_def * ptr_info )

◆ duplicate_ssa_name_range_info()

◆ fini_ssanames()

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().

◆ flush_ssaname_freelist()

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().

◆ get_nonzero_bits()

◆ get_ptr_info()

◆ get_ptr_info_alignment()

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 ggc_alloc().

Referenced by dump_ssaname_info(), get_pointer_alignment_1(), and ipcp_update_vr().

◆ init_ssa_name_imm_use()

◆ init_ssanames()

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().

◆ make_pass_release_ssa_names()

gimple_opt_pass * make_pass_release_ssa_names ( gcc::context * ctxt)

References ggc_alloc().

◆ make_ssa_name_fn()

tree make_ssa_name_fn ( struct function * fn,
tree var,
gimple * stmt,
unsigned int version )
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, ggc_alloc(), 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().

◆ mark_ptr_info_alignment_unknown()

void mark_ptr_info_alignment_unknown ( struct ptr_info_def * pi)

◆ range_info_alloc()

void * range_info_alloc ( tree name,
const vrange & r )
inline
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().

◆ range_info_fits_p()

bool range_info_fits_p ( tree name,
const vrange & r )
inline
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().

◆ range_info_free()

void range_info_free ( tree name)
inline
Free storage allocated for the global range for NAME.   

References ggc_free(), and SSA_NAME_RANGE_INFO.

Referenced by range_info_set_range().

◆ range_info_get_range()

void range_info_get_range ( const_tree name,
vrange & r )
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_nonzero_bits(), and set_range_info().

◆ range_info_p()

bool range_info_p ( const_tree name)
inline

◆ range_info_set_range()

bool range_info_set_range ( tree name,
const vrange & r )
inline
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().

◆ release_defs()

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(), 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_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().

◆ release_free_names_and_compact_live_names()

static void release_free_names_and_compact_live_names ( function * fun)
static
Release the vector of free SSA_NAMEs and compact the vector of SSA_NAMEs
that are live.   

References dump_file, FREE_SSANAMES, ggc_alloc(), 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().

◆ release_ssa_name_fn()

void release_ssa_name_fn ( struct function * fn,
tree var )
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, ggc_alloc(), 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_ssa_name_symbol()

void replace_ssa_name_symbol ( tree ssa_name,
tree sym )
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().

◆ reset_flow_sensitive_info()

◆ reset_flow_sensitive_info_in_bb()

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, ggc_alloc(), 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 maybe_optimize_range_tests(), and replace_block_by().

◆ set_bitmask()

void set_bitmask ( tree name,
const wide_int & value,
const wide_int & mask )
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().

◆ set_nonzero_bits()

void set_nonzero_bits ( tree name,
const wide_int & mask )
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().

◆ set_ptr_info_alignment()

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, ggc_alloc(), 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().

◆ set_ptr_nonnull()

void set_ptr_nonnull ( tree name)
Set nonnull attribute to pointer NAME.   

References gcc_assert, get_ptr_info(), ggc_alloc(), POINTER_TYPE_P, and TREE_TYPE.

Referenced by find_what_p_points_to(), and set_range_info().

◆ set_range_info()

◆ ssa_name_has_boolean_range()

bool ssa_name_has_boolean_range ( tree op)
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().

◆ ssanames_print_statistics()

void ssanames_print_statistics ( void )
Dump some simple statistics regarding the re-use of SSA_NAME nodes.   

References ggc_alloc(), PRsa, SIZE_AMOUNT, ssa_name_nodes_created, and ssa_name_nodes_reused.

Referenced by dump_tree_statistics().

◆ verify_ssaname_freelists()

Variable Documentation

◆ ssa_name_nodes_created

unsigned int ssa_name_nodes_created

◆ ssa_name_nodes_reused

unsigned int ssa_name_nodes_reused