GCC Middle and Back End API Reference
|
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "backend.h"
#include "target.h"
#include "tree.h"
#include "gimple.h"
#include "alloc-pool.h"
#include "tree-pass.h"
#include "stringpool.h"
#include "cgraph.h"
#include "gimplify.h"
#include "tree-iterator.h"
#include "ipa-utils.h"
#include "symbol-summary.h"
#include "tree-vrp.h"
#include "sreal.h"
#include "ipa-cp.h"
#include "ipa-prop.h"
#include "ipa-fnsummary.h"
#include "dbgcnt.h"
#include "debug.h"
#include "attribs.h"
Macros | |
#define | BOTTOM ((cgraph_node *)(size_t) 2) |
#define BOTTOM ((cgraph_node *)(size_t) 2) |
Invalid pointer representing BOTTOM for single user dataflow.
Referenced by ipa_single_use(), meet(), and propagate_single_user().
Define global constructors/destructor functions for the CDTORS, of which they are LEN. The CDTORS are sorted by initialization priority. If CTOR_P is true, these are constructors; otherwise, they are destructors.
References append_to_statement_list(), build_call_expr(), cgraph_build_static_cdtor_1(), DECL_FINI_PRIORITY, DECL_FUNCTION_SPECIFIC_OPTIMIZATION, DECL_FUNCTION_SPECIFIC_TARGET, DECL_INIT_PRIORITY, DECL_STATIC_CONSTRUCTOR, DECL_STATIC_DESTRUCTOR, gcc_assert, i, NULL_TREE, targetm, and TREE_SIDE_EFFECTS.
Referenced by build_cdtor_fns(), and build_cxa_atexit_fns().
Generate functions to call static constructors and destructors for targets that do not support .ctors/.dtors sections. These functions have magic names which are detected by collect2.
References build_cdtor(), compare_ctor(), compare_dtor(), gcc_assert, and targetm.
Referenced by ipa_cdtor_merge().
|
static |
Helper functions for build_cxa_dtor_registrations (). Build a decl for __cxa_atexit ().
References build_decl(), build_function_type_list(), build_pointer_type(), BUILTINS_LOCATION, DECL_ARTIFICIAL, DECL_EXTERNAL, DECL_VISIBILITY, DECL_VISIBILITY_SPECIFIED, ECF_LEAF, ECF_NOTHROW, get_identifier(), integer_type_node, NULL_TREE, ptr_type_node, set_call_expr_flags(), SET_DECL_ASSEMBLER_NAME, TREE_PUBLIC, VISIBILITY_DEFAULT, and void_type_node.
Referenced by build_cxa_dtor_registrations().
Generate new CTORs to register static destructors with __cxa_atexit and add them to the existing list of CTORs; we then process the revised CTORs list. We sort the DTORs into priority and then TU order, this means that they are registered in that order with __cxa_atexit () and therefore will be run in the reverse order. Likewise, CTORs are sorted into priority and then TU order, which means that they will run in that order. This matches the behavior of using init/fini or mod_init_func/mod_term_func sections.
References build_cdtor(), build_cxa_dtor_registrations(), compare_cdtor_tu_order(), gcc_assert, and targetm.
Referenced by ipa_cdtor_merge().
This builds one or more constructor functions that register DTORs with __cxa_atexit (). Within a priority level, DTORs are registered in TU order - which means that they will run in reverse TU order from cxa_atexit. This is the same behavior as using a .fini / .mod_term_funcs section. As the functions are built, they are appended to the CTORs vector.
References append_to_statement_list(), build1_loc(), build_call_expr_loc(), build_cxa_atexit_decl(), build_dso_handle_decl(), cgraph_build_static_cdtor_1(), DECL_FINI_PRIORITY, DECL_FUNCTION_SPECIFIC_OPTIMIZATION, DECL_FUNCTION_SPECIFIC_TARGET, DECL_STATIC_DESTRUCTOR, gcc_assert, i, input_location, null_pointer_node, NULL_TREE, ptr_type_node, TREE_SIDE_EFFECTS, and UNKNOWN_LOCATION.
Referenced by build_cxa_atexit_fns().
|
static |
Build a decl for __dso_handle.
References build_decl(), DECL_ARTIFICIAL, DECL_EXTERNAL, DECL_VISIBILITY, DECL_VISIBILITY_SPECIFIED, error_mark_node, get_identifier(), ptr_type_node, TREE_PUBLIC, UNKNOWN_LOCATION, and VISIBILITY_HIDDEN.
Referenced by build_cxa_dtor_registrations().
void cgraph_build_static_cdtor | ( | char | which, |
tree | body, | ||
int | priority ) |
Generate and emit a static constructor or destructor. WHICH must be one of 'I' (for a constructor) or 'D' (for a destructor). BODY is a STATEMENT_LIST containing GENERIC statements. PRIORITY is the initialization priority for this constructor or destructor.
References cgraph_build_static_cdtor_1(), optimization_default_node, and target_option_default_node.
Referenced by asan_finish_file(), build_gcov_exit_decl(), build_init_ctor(), hwasan_finish_file(), ipa_lower_emutls(), and tsan_finish_file().
|
static |
Generate and emit a static constructor or destructor. WHICH must be one of 'I' (for a constructor), 'D' (for a destructor). BODY is a STATEMENT_LIST containing GENERIC statements. PRIORITY is the initialization priority for this constructor or destructor. FINAL specify whether the externally visible name for collect2 should be produced.
References cgraph_node::add_new_function(), allocate_struct_function(), BLOCK_SUPERCONTEXT, build_decl(), build_function_type_list(), cfun, current_function_decl, DECL_ARTIFICIAL, DECL_CONTEXT, decl_fini_priority_insert(), DECL_FUNCTION_SPECIFIC_OPTIMIZATION, DECL_FUNCTION_SPECIFIC_TARGET, DECL_IGNORED_P, decl_init_priority_insert(), DECL_INITIAL, DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT, DECL_PRESERVE_P, DECL_RESULT, DECL_SAVED_TREE, DECL_SOURCE_LOCATION, DECL_STATIC_CONSTRUCTOR, DECL_STATIC_DESTRUCTOR, DECL_UNINLINABLE, gcc_unreachable, get_file_function_name(), get_identifier(), gimplify_function_tree(), input_location, make_node(), NULL, NULL_TREE, set_cfun(), targetm, TREE_PUBLIC, TREE_STATIC, TREE_USED, and void_type_node.
Referenced by build_cdtor(), build_cxa_dtor_registrations(), and cgraph_build_static_cdtor().
bool clear_addressable_bit | ( | varpool_node * | vnode, |
void * | data ) |
Clear addressale bit of VNODE.
References symtab_node::address_taken, symtab_node::decl, and TREE_ADDRESSABLE.
Referenced by ipa_discover_variable_flags().
|
static |
Comparison function for qsort. P1 and P2 are of type "tree *" and point to a pair of static constructors or destructors. We first sort on the basis of priority and then into TU order (on the strict assumption that DECL_UIDs are ordered in the same way as the original functions). ???: this seems quite fragile.
References DECL_FINI_PRIORITY, DECL_INIT_PRIORITY, DECL_STATIC_DESTRUCTOR, DECL_UID, f1, f2, and gcc_checking_assert.
Referenced by build_cxa_atexit_fns().
|
static |
Comparison function for qsort. P1 and P2 are actually of type "tree *" and point to static constructors. DECL_INIT_PRIORITY is used to determine the sort order.
References DECL_INIT_PRIORITY, DECL_UID, f1, and f2.
Referenced by build_cdtor_fns().
|
static |
Comparison function for qsort. P1 and P2 are actually of type "tree *" and point to static destructors. DECL_FINI_PRIORITY is used to determine the sort order.
References DECL_FINI_PRIORITY, DECL_UID, f1, and f2.
Referenced by build_cdtor_fns().
|
static |
Add symtab NODE to queue starting at FIRST. The queue is linked via AUX pointers and terminated by pointer to 1. We enqueue nodes at two occasions: when we find them reachable or when we find their bodies needed for further clonning. In the second case we mark them by pointer to 2 after processing so they are re-queue when they become reachable.
References symtab_node::aux, and hash_set< KeyId, Lazy, Traits >::contains().
Referenced by process_references(), and walk_polymorphic_call_targets().
|
static |
Basic IPA optimizations and utilities. Copyright (C) 2003-2025 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/>.
Return true when NODE has ADDR reference.
References i, IPA_REF_ADDR, symtab_node::iterate_referring(), NULL, and ipa_ref::use.
Referenced by symbol_table::remove_unreachable_nodes().
|
static |
Look for constructors and destructors and produce function calling them. This is needed for targets not supporting ctors or dtors, but we perform the transformation also at linktime to merge possibly numerous constructors/destructors into single function to improve code locality and reduce size.
References build_cdtor_fns(), build_cxa_atexit_fns(), symtab_node::decl, DECL_STATIC_CONSTRUCTOR, DECL_STATIC_DESTRUCTOR, FOR_EACH_DEFINED_FUNCTION, record_cdtor_fn(), and targetm.
bool ipa_discover_variable_flags | ( | void | ) |
Discover variables that have no longer address taken, are read-only or write-only and update their flags. Return true when unreachable symbol removal should be done. FIXME: This cannot be done in between gimplify and omp_expand since readonly flag plays role on what is shared and what is not. Currently we do this transformation as part of whole program visibility and re-do at ipa-reference pass (to take into account clonning), but it would make sense to do it before early optimizations.
References symtab_node::alias, varpool_node::call_for_symbol_and_aliases(), clear_addressable_bit(), symtab_node::decl, dump_file, symtab_node::dump_name(), FOR_EACH_VARIABLE, symtab_node::get_section(), NULL, process_references(), set_readonly_bit(), set_writeonly_bit(), TREE_ADDRESSABLE, TREE_READONLY, and symtab_node::writeonly.
Referenced by propagate().
|
static |
Pass setting used_by_single_function flag. This flag is set on variable when there is only one function that may possibly referr to it.
References varpool_node::all_refs_explicit_p(), symtab_node::aux, BOTTOM, symtab_node::definition, dump_file, symtab_node::dump_name(), dyn_cast(), FOR_EACH_DEFINED_VARIABLE, gcc_checking_assert, hash_map< KeyId, Value, Traits >::get(), i, is_a(), symtab_node::iterate_direct_aliases(), symtab_node::iterate_reference(), NULL, propagate_single_user(), hash_map< KeyId, Value, Traits >::put(), ipa_ref::referred, ipa_ref::referring, and varpool_node::used_by_single_function.
|
static |
Return true when NODE can be target of an indirect call.
References cgraph_node::indirect_call_target.
Referenced by symbol_table::remove_unreachable_nodes().
ipa_opt_pass_d * make_pass_ipa_cdtor_merge | ( | gcc::context * | ctxt | ) |
ipa_opt_pass_d * make_pass_ipa_single_use | ( | gcc::context * | ctxt | ) |
cgraph_node * meet | ( | cgraph_node * | function, |
varpool_node * | var, | ||
hash_map< varpool_node *, cgraph_node * > & | single_user_map ) |
Meet operation for single user dataflow. Here we want to associate variables with sigle function that may access it. FUNCTION is current single user of a variable, VAR is variable that uses it. Latttice is stored in SINGLE_USER_MAP. We represent: - TOP by no entry in SIGNLE_USER_MAP - BOTTOM by BOTTOM in AUX pointer (to save lookups) - known single user by cgraph pointer in SINGLE_USER_MAP.
References symtab_node::aux, BOTTOM, and hash_map< KeyId, Value, Traits >::get().
Referenced by propagate_single_user().
|
static |
Return true if NODE may get inlined later. This is used to keep DECL_EXTERNAL function bodies around long enough so inliner can proces them.
References symtab_node::decl, DECL_ATTRIBUTES, DECL_UNINLINABLE, dyn_cast(), IPA_SSA, IPA_SSA_AFTER_INLINING, lookup_attribute(), opt_for_fn, and symtab.
Referenced by process_references(), symbol_table::remove_unreachable_nodes(), and walk_polymorphic_call_targets().
|
static |
Process references.
References hash_set< KeyId, Lazy, Traits >::add(), symtab_node::alias, symtab_node::decl, DECL_EXTERNAL, symtab_node::definition, dyn_cast(), enqueue_node(), i, symtab_node::in_other_partition, INCREMENTAL_LINK_LTO, IPA_SSA_AFTER_INLINING, symtab_node::iterate_reference(), NULL, possible_inline_candidate_p(), ipa_ref::referred, symtab, symtab_node::ultimate_alias_target(), and VAR_P.
Referenced by ipa_discover_variable_flags(), process_references(), and symbol_table::remove_unreachable_nodes().
void process_references | ( | varpool_node * | vnode, |
bool * | written, | ||
bool * | address_taken, | ||
bool * | read, | ||
bool * | explicit_refs ) |
Process references to VNODE and set flags WRITTEN, ADDRESS_TAKEN, READ as needed, also clear EXPLICIT_REFS if the references to given variable do not need to be explicit.
References varpool_node::all_refs_explicit_p(), symtab_node::decl, dyn_cast(), i, IPA_REF_ADDR, IPA_REF_ALIAS, IPA_REF_LOAD, IPA_REF_STORE, symtab_node::iterate_referring(), process_references(), ipa_ref::referring, TREE_THIS_VOLATILE, and ipa_ref::use.
cgraph_node * propagate_single_user | ( | varpool_node * | vnode, |
cgraph_node * | function, | ||
hash_map< varpool_node *, cgraph_node * > & | single_user_map ) |
Propagation step of single-use dataflow. Check all uses of VNODE and see if they are used by single function FUNCTION. SINGLE_USER_MAP represents the dataflow lattice.
References symtab_node::alias, BOTTOM, dyn_cast(), symtab_node::externally_visible, gcc_assert, varpool_node::get_alias_target(), i, cgraph_node::inlined_to, symtab_node::iterate_referring(), meet(), and ipa_ref::referring.
Referenced by ipa_single_use().
|
static |
When target does not have ctors and dtors, we call all constructor and destructor by special initialization/destruction function recognized by collect2. When we are going to build this function, collect all constructors and destructors and turn them into normal functions.
References symtab_node::decl, DECL_DISREGARD_INLINE_LIMITS, DECL_STATIC_CONSTRUCTOR, DECL_STATIC_DESTRUCTOR, and cgraph_node::get().
Referenced by ipa_cdtor_merge().
bool set_readonly_bit | ( | varpool_node * | vnode, |
void * | data ) |
Set TREE_READONLY bit.
References symtab_node::decl, and TREE_READONLY.
Referenced by ipa_discover_variable_flags().
bool set_writeonly_bit | ( | varpool_node * | vnode, |
void * | data ) |
Set writeonly bit and clear the initalizer, since it will not be needed.
References symtab_node::alias, symtab_node::decl, DECL_INITIAL, NULL, symtab_node::num_references(), symtab_node::remove_all_references(), and symtab_node::writeonly.
Referenced by ipa_discover_variable_flags().
|
static |
Look for all functions inlined to NODE and update their inlined_to pointers to INLINED_TO.
References cgraph_edge::callee, cgraph_node::callees, cgraph_node::inlined_to, cgraph_edge::next_callee, and update_inlined_to_pointer().
Referenced by symbol_table::remove_unreachable_nodes(), and update_inlined_to_pointer().
|
static |
EDGE is an polymorphic call. If BEFORE_INLINING_P is set, mark all its potential targets as reachable to permit later inlining if devirtualization happens. After inlining still keep their declarations around, so we can devirtualize to a direct call. Also try to make trivial devirutalization when no or only one target is possible.
References hash_set< KeyId, Lazy, Traits >::add(), symtab_node::alias, builtin_decl_unreachable(), dbg_cnt(), symtab_node::decl, DECL_EXTERNAL, symtab_node::definition, dump_enabled_p(), symtab_node::dump_name(), dump_printf_loc(), enqueue_node(), cgraph_node::function_symbol(), cgraph_node::get_create(), i, cgraph_node::indirect_call_target, cgraph_node::inlined_to, ipa_fn_summaries, IPA_SSA_AFTER_INLINING, ipa_update_overall_fn_summary(), cgraph_edge::make_direct(), MSG_OPTIMIZED_LOCATIONS, NULL, opt_for_fn, possible_inline_candidate_p(), possible_polymorphic_call_targets(), cgraph_edge::redirect_call_stmt_to_callee(), symtab, TREE_CODE, TREE_TYPE, type_in_anonymous_namespace_p(), and TYPE_METHOD_BASETYPE.