GCC Middle and Back End API 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"
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_d * | make_pass_ipa_whole_program_visibility (gcc::context *ctxt) |
simple_ipa_opt_pass * | make_pass_ipa_function_and_variable_visibility (gcc::context *ctxt) |
|
static |
Return true if reference to NODE can be replaced by a local alias. Local aliases save dynamic linking overhead and enable more optimizations.
References AVAIL_INTERPOSABLE, symtab_node::can_be_discarded_p(), symtab_node::decl, decl_binds_to_current_def_p(), symtab_node::definition, symtab_node::get_alias_target(), symtab_node::get_availability(), TARGET_SUPPORTS_ALIASES, symtab_node::transparent_alias, and symtab_node::weakref.
Referenced by can_replace_by_local_alias_in_vtable(), and function_and_variable_visibility().
|
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().
|
static |
Return true when function NODE should be considered externally visible.
References comdat_can_be_unshared_p(), symtab_node::decl, DECL_ATTRIBUTES, DECL_COMDAT, DECL_EXTERNAL, DECL_NAME, DECL_PRESERVE_P, DECL_VISIBILITY, symtab_node::definition, fndecl_built_in_p(), FOR_EACH_ALIAS, cgraph_node::get_alias_target(), lookup_attribute(), MAIN_NAME_P, ipa_ref::referring, symtab_node::resolution, symtab_node::symver, TARGET_DLLIMPORT_DECL_ATTRIBUTES, symtab_node::transparent_alias, TREE_PUBLIC, symtab_node::used_from_object_file_p(), VISIBILITY_HIDDEN, and VISIBILITY_INTERNAL.
Referenced by function_and_variable_visibility().
|
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().
|
static |
A helper for comdat_can_be_unshared_p.
References symtab_node::address_can_be_compared_p(), ipa_ref::address_matters_p(), symtab_node::decl, symtab_node::externally_visible, symtab_node::force_output, symtab_node::forced_by_abi, i, is_a(), symtab_node::iterate_referring(), symtab_node::resolution, TREE_PUBLIC, TREE_READONLY, and TREE_THIS_VOLATILE.
Referenced by comdat_can_be_unshared_p().
|
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().
|
static |
NODE is an externally visible definition, which we've discovered is not needed externally. Make it local to this compilation.
References symtab_node::alias, symtab_node::comdat_local_p(), symtab_node::decl, DECL_COMDAT, symtab_node::dissolve_same_comdat_group_list(), gcc_assert, symtab_node::make_decl_local(), NULL, symtab_node::resolution, symtab_node::same_comdat_group, symtab_node::set_comdat_group(), symtab_node::set_section(), symtab_node::transparent_alias, TREE_PUBLIC, and symtab_node::unique_name.
Referenced by function_and_variable_visibility().
simple_ipa_opt_pass * make_pass_ipa_function_and_variable_visibility | ( | gcc::context * | ctxt | ) |
ipa_opt_pass_d * make_pass_ipa_whole_program_visibility | ( | gcc::context * | ctxt | ) |
|
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().
|
static |
Try to get rid of weakref.
References symtab_node::alias, symtab_node::analyzed, symtab_node::can_be_discarded_p(), symbol_table::change_decl_assembler_name(), symtab_node::copy_visibility_from(), symtab_node::decl, DECL_ASSEMBLER_NAME, DECL_ATTRIBUTES, decl_binds_to_current_def_p(), DECL_EXTERNAL, DECL_PRESERVE_P, DECL_WEAK, symtab_node::definition, dump_file, symtab_node::dump_name(), symtab_node::externally_visible, symtab_node::forced_by_abi, gcc_assert, symtab_node::get_alias_target(), IDENTIFIER_TRANSPARENT_ALIAS, symtab_node::make_decl_local(), NULL_TREE, optimize_weakref(), remove_attribute(), symtab_node::resolution, symtab, TARGET_SUPPORTS_ALIASES, symtab_node::transparent_alias, TREE_CHAIN, TREE_PUBLIC, and symtab_node::weakref.
Referenced by function_and_variable_visibility(), and optimize_weakref().
|
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().
walk_tree callback that rewrites initializer references.
References can_replace_by_local_alias_in_vtable(), symtab_node::decl, symtab_node::get(), IS_TYPE_OR_DECL_P, symtab_node::noninterposable_alias(), NULL, and VAR_OR_FUNCTION_DECL_P.
Referenced by function_and_variable_visibility().