GCC Middle and Back End API Reference
ipa-visibility.cc File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "function.h"
#include "tree.h"
#include "gimple-expr.h"
#include "tree-pass.h"
#include "cgraph.h"
#include "calls.h"
#include "varasm.h"
#include "ipa-utils.h"
#include "stringpool.h"
#include "attribs.h"
Include dependency graph for ipa-visibility.cc:

Data Structures

class  pass_ipa_function_and_variable_visibility
 

Functions

static bool non_local_p (struct cgraph_node *node, void *data)
 
static bool comdat_can_be_unshared_p_1 (symtab_node *node)
 
static bool comdat_can_be_unshared_p (symtab_node *node)
 
static bool cgraph_externally_visible_p (struct cgraph_node *node, bool whole_program)
 
static bool can_replace_by_local_alias (symtab_node *node)
 
static bool can_replace_by_local_alias_in_vtable (symtab_node *node)
 
static tree update_vtable_references (tree *tp, int *walk_subtrees, void *data)
 
static void update_visibility_by_resolution_info (symtab_node *node)
 
static void optimize_weakref (symtab_node *node)
 
static void localize_node (bool whole_program, symtab_node *node)
 
static unsigned int function_and_variable_visibility (bool whole_program)
 
ipa_opt_pass_dmake_pass_ipa_whole_program_visibility (gcc::context *ctxt)
 
simple_ipa_opt_passmake_pass_ipa_function_and_variable_visibility (gcc::context *ctxt)
 

Function Documentation

◆ can_replace_by_local_alias()

static bool can_replace_by_local_alias ( symtab_node * node)
static

◆ can_replace_by_local_alias_in_vtable()

static bool can_replace_by_local_alias_in_vtable ( symtab_node * node)
static
Return true if we can replace reference to NODE by local alias
within a virtual table.  Generally we can replace function pointers
and virtual table pointers.   

References can_replace_by_local_alias(), symtab_node::decl, DECL_VIRTUAL_P, and is_a().

Referenced by function_and_variable_visibility(), and update_vtable_references().

◆ cgraph_externally_visible_p()

◆ comdat_can_be_unshared_p()

static bool comdat_can_be_unshared_p ( symtab_node * node)
static
COMDAT functions must be shared only if they have address taken,
otherwise we can produce our own private implementation with
-fwhole-program.  
Return true when turning COMDAT function static cannot lead to wrong
code when the resulting object links with a library defining same COMDAT.

Virtual functions do have their addresses taken from the vtables,
but in C++ there is no way to compare their addresses for equality.   

References comdat_can_be_unshared_p_1(), and symtab_node::same_comdat_group.

Referenced by cgraph_externally_visible_p(), and varpool_node::externally_visible_p().

◆ comdat_can_be_unshared_p_1()

◆ function_and_variable_visibility()

static unsigned int function_and_variable_visibility ( bool whole_program)
static
Decide on visibility of all symbols.   

References ADDR_SPACE_GENERIC_P, symtab_node::alias, alias_pairs, symtab_node::analyzed, AVAIL_INTERPOSABLE, cgraph_edge::callee, cgraph_node::callees, cgraph_edge::caller, cgraph_node::callers, can_replace_by_local_alias(), can_replace_by_local_alias_in_vtable(), cgraph_externally_visible_p(), symtab_node::decl, DECL_ATTRIBUTES, DECL_COMDAT, DECL_COMMON, decl_default_tls_model(), DECL_EXTERNAL, DECL_INITIAL, DECL_ONE_ONLY, DECL_SECTION_NAME, DECL_STATIC_CONSTRUCTOR, DECL_STATIC_DESTRUCTOR, DECL_STRUCT_FUNCTION, DECL_THREAD_LOCAL_P, decl_tls_model(), DECL_VIRTUAL_P, DECL_WEAK, symtab_node::definition, symtab_node::dissolve_same_comdat_group_list(), dump_file, symtab_node::dump_name(), dyn_cast(), ECF_CONST, ECF_LOOPING_CONST_OR_PURE, ECF_PURE, error_mark_node, symtab_node::externally_visible, varpool_node::externally_visible_p(), flags_from_decl_or_type(), FOR_EACH_DEFINED_FUNCTION, FOR_EACH_DEFINED_VARIABLE, FOR_EACH_FUNCTION, FOR_EACH_VARIABLE, symtab_node::force_output, symtab_node::forced_by_abi, symbol_table::function_flags_ready, cgraph_node::function_symbol(), gcc_assert, gcc_checking_assert, cgraph_node::get_availability(), varpool_node::get_constructor(), gimple_has_body_p(), symtab_node::has_aliases_p(), i, symtab_node::in_same_comdat_group_p(), cgraph_node::inlined_to, IPA_REF_ADDR, IPA_SSA, symtab_node::iterate_reference(), cgraph_node::local, cgraph_node::local_p(), localize_node(), lookup_attribute(), cgraph_edge::next_callee, symtab_node::no_reorder, symtab_node::noninterposable_alias(), NULL, opt_for_fn, optimize_weakref(), pop_cfun(), push_cfun(), record_references_in_initializer(), cgraph_edge::redirect_call_stmt_to_callee(), cgraph_edge::redirect_callee(), symtab_node::ref_list, ipa_ref::referred, ipa_ref_list::referring, symtab_node::remove_all_references(), symtab_node::same_comdat_group, set_decl_tls_model(), symbol_table::state, STATIC_ASSERT, symtab, TARGET_SUPPORTS_ALIASES, cgraph_node::thunk, TLS_MODEL_GLOBAL_DYNAMIC, TLS_MODEL_INITIAL_EXEC, TLS_MODEL_LOCAL_DYNAMIC, TLS_MODEL_LOCAL_EXEC, symtab_node::transparent_alias, TREE_PUBLIC, TREE_TYPE, TYPE_ADDR_SPACE, update_visibility_by_resolution_info(), update_vtable_references(), ipa_ref::use, walk_tree, and symtab_node::weakref.

Referenced by pass_ipa_function_and_variable_visibility::execute().

◆ localize_node()

◆ make_pass_ipa_function_and_variable_visibility()

simple_ipa_opt_pass * make_pass_ipa_function_and_variable_visibility ( gcc::context * ctxt)

◆ make_pass_ipa_whole_program_visibility()

ipa_opt_pass_d * make_pass_ipa_whole_program_visibility ( gcc::context * ctxt)

◆ non_local_p()

static bool non_local_p ( struct cgraph_node * node,
void * data )
static
IPA visibility pass
   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/>.   
This file implements two related passes: 

  - pass_data_ipa_function_and_variable_visibility run just after
    symbol table, references and callgraph are built

  - pass_data_ipa_function_and_variable_visibility run as first
    proper IPA pass (that is after early optimization, or, (with LTO)
    as a first pass done at link-time.

Purpose of both passes is to set correctly visibility properties
of all symbols.  This includes:

 - Symbol privatization:

   Some symbols that are declared public by frontend may be
   turned local (either by -fwhole-program flag, by linker plugin feedback
   or by other reasons)

 - Discovery of local functions:

   A local function is one whose calls can occur only in the current
   compilation unit and all its calls are explicit, so we can change
   its calling convention.  We simply mark all static functions whose
   address is not taken as local.

   externally_visible flag is set for symbols that cannot be privatized.
   For privatized symbols we clear TREE_PUBLIC flag and dismantle comdat
   group.

 - Dismantling of comdat groups:

   Comdat group represent a section that may be replaced by linker by
   a different copy of the same section from other unit.
   If we have resolution information (from linker plugin) and we know that
   a given comdat gorup is prevailing, we can dismantle it and turn symbols
   into normal symbols.  If the resolution information says that the
   section was previaled by copy from non-LTO code, we can also dismantle
   it and turn all symbols into external.

 - Local aliases:

   Some symbols can be interposed by dynamic linker. Refering to these
   symbols is expensive, since it needs to be overwritable by the dynamic
   linker.  In some cases we know that the interposition does not change
   semantic and we can always refer to a local copy (as in the case of
   inline function).  In this case we produce a local alias and redirect
   calls to it.

   TODO: This should be done for references, too.

 - Removal of static ocnstructors and destructors that have no side effects.

 - Regularization of several oddities introduced by frontends that may
   be impractical later in the optimization queue.   
Return true when NODE cannot be local. Worker for cgraph_local_node_p.   

References AVAIL_AVAILABLE, symtab_node::decl, DECL_ATTRIBUTES, DECL_EXTERNAL, DECL_STATIC_CONSTRUCTOR, DECL_STATIC_DESTRUCTOR, symtab_node::definition, symtab_node::externally_visible, cgraph_node::get_availability(), symtab_node::in_other_partition, lookup_attribute(), cgraph_node::only_called_directly_or_aliased_p(), cgraph_node::thunk, and symtab_node::used_from_other_partition.

Referenced by cgraph_node::local_p().

◆ optimize_weakref()

◆ update_visibility_by_resolution_info()

static void update_visibility_by_resolution_info ( symtab_node * node)
static
In LTO we can remove COMDAT groups and weak symbols.
Either turn them into normal symbols or external symbol depending on 
resolution info.   

References symtab_node::decl, DECL_EXTERNAL, DECL_ONE_ONLY, DECL_WEAK, symtab_node::dissolve_same_comdat_group_list(), symtab_node::externally_visible, gcc_assert, NULL, symtab_node::resolution, symtab_node::same_comdat_group, and symtab_node::set_comdat_group().

Referenced by function_and_variable_visibility().

◆ update_vtable_references()

static tree update_vtable_references ( tree * tp,
int * walk_subtrees,
void * data )
static