GCC Middle and Back End API Reference
lto-cgraph.cc File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "backend.h"
#include "rtl.h"
#include "tree.h"
#include "gimple.h"
#include "predict.h"
#include "stringpool.h"
#include "tree-streamer.h"
#include "cgraph.h"
#include "tree-pass.h"
#include "profile.h"
#include "context.h"
#include "pass_manager.h"
#include "ipa-utils.h"
#include "omp-offload.h"
#include "omp-general.h"
#include "attribs.h"
#include "alloc-pool.h"
#include "symbol-summary.h"
#include "symtab-thunks.h"
#include "symtab-clones.h"
Include dependency graph for lto-cgraph.cc:

Macros

#define LDPR_NUM_KNOWN   (LDPR_PREVAILING_DEF_IRONLY_EXP + 1)
 

Enumerations

enum  LTO_symtab_tags {
  LTO_symtab_unavail_node = 1 , LTO_symtab_analyzed_node , LTO_symtab_edge , LTO_symtab_indirect_edge ,
  LTO_symtab_variable , LTO_symtab_indirect_function , LTO_symtab_last_tag
}
 

Functions

static void output_cgraph_opt_summary (void)
 
static void input_cgraph_opt_summary (vec< symtab_node * > nodes)
 
lto_symtab_encoder_t lto_symtab_encoder_new (bool for_input)
 
void lto_symtab_encoder_delete (lto_symtab_encoder_t encoder)
 
int lto_symtab_encoder_encode (lto_symtab_encoder_t encoder, symtab_node *node)
 
bool lto_symtab_encoder_delete_node (lto_symtab_encoder_t encoder, symtab_node *node)
 
bool lto_symtab_encoder_only_for_inlining_p (lto_symtab_encoder_t encoder, struct cgraph_node *node)
 
bool lto_symtab_encoder_encode_body_p (lto_symtab_encoder_t encoder, struct cgraph_node *node)
 
bool lto_symtab_encoder_encode_initializer_p (lto_symtab_encoder_t encoder, varpool_node *node)
 
static void lto_set_symtab_encoder_encode_initializer (lto_symtab_encoder_t encoder, varpool_node *node)
 
bool lto_symtab_encoder_in_partition_p (lto_symtab_encoder_t encoder, symtab_node *node)
 
void lto_set_symtab_encoder_in_partition (lto_symtab_encoder_t encoder, symtab_node *node)
 
static void lto_output_edge (struct lto_simple_output_block *ob, struct cgraph_edge *edge, lto_symtab_encoder_t encoder)
 
bool referenced_from_other_partition_p (symtab_node *node, lto_symtab_encoder_t encoder)
 
bool reachable_from_other_partition_p (struct cgraph_node *node, lto_symtab_encoder_t encoder)
 
bool referenced_from_this_partition_p (symtab_node *node, lto_symtab_encoder_t encoder)
 
bool reachable_from_this_partition_p (struct cgraph_node *node, lto_symtab_encoder_t encoder)
 
static void lto_output_node (struct lto_simple_output_block *ob, struct cgraph_node *node, lto_symtab_encoder_t encoder)
 
static void lto_output_varpool_node (struct lto_simple_output_block *ob, varpool_node *node, lto_symtab_encoder_t encoder)
 
static void lto_output_ref (struct lto_simple_output_block *ob, struct ipa_ref *ref, lto_symtab_encoder_t encoder)
 
static void output_profile_summary (struct lto_simple_output_block *ob)
 
static void output_outgoing_cgraph_edges (struct cgraph_edge *edge, struct lto_simple_output_block *ob, lto_symtab_encoder_t encoder)
 
static void output_refs (lto_symtab_encoder_t encoder)
 
static void add_node_to (lto_symtab_encoder_t encoder, struct cgraph_node *node, bool include_body, bool not_inlined)
 
static void add_node_to (lto_symtab_encoder_t encoder, struct cgraph_node *node, bool include_body)
 
static void create_references (lto_symtab_encoder_t encoder, symtab_node *node)
 
void select_what_to_stream (void)
 
lto_symtab_encoder_t compute_ltrans_boundary (lto_symtab_encoder_t in_encoder)
 
void output_symtab (void)
 
static tree read_identifier (class lto_input_block *ib)
 
static const char * read_string (class lto_input_block *ib)
 
void output_offload_tables (void)
 
static void verify_node_partition (symtab_node *node)
 
static void input_overwrite_node (struct lto_file_decl_data *file_data, struct cgraph_node *node, enum LTO_symtab_tags tag, struct bitpack_d *bp, bool *has_thunk_info)
 
static tree get_alias_symbol (tree decl)
 
static struct cgraph_nodeinput_node (struct lto_file_decl_data *file_data, class lto_input_block *ib, enum LTO_symtab_tags tag, vec< symtab_node * > nodes)
 
static varpool_nodeinput_varpool_node (struct lto_file_decl_data *file_data, class lto_input_block *ib)
 
static void input_ref (class lto_input_block *ib, symtab_node *referring_node, vec< symtab_node * > nodes)
 
static void input_edge (class lto_input_block *ib, vec< symtab_node * > nodes, bool indirect)
 
static vec< symtab_node * > input_cgraph_1 (struct lto_file_decl_data *file_data, class lto_input_block *ib)
 
static void input_refs (class lto_input_block *ib, vec< symtab_node * > nodes)
 
static void input_profile_summary (class lto_input_block *ib, struct lto_file_decl_data *file_data)
 
static void merge_profile_summaries (struct lto_file_decl_data **file_data_vec)
 
void input_symtab (void)
 
static void omp_requires_to_name (char *buf, size_t size, HOST_WIDE_INT requires_mask)
 
void input_offload_tables (bool do_force_output)
 
static int output_cgraph_opt_summary_p (struct cgraph_node *node)
 
static void output_edge_opt_summary (struct output_block *ob, struct cgraph_edge *edge)
 
static void output_node_opt_summary (struct output_block *ob, struct cgraph_node *node, lto_symtab_encoder_t encoder)
 
static void input_edge_opt_summary (struct cgraph_edge *edge, class lto_input_block *ib_main)
 
static void input_node_opt_summary (struct cgraph_node *node, class lto_input_block *ib_main, class data_in *data_in)
 
static void input_cgraph_opt_section (struct lto_file_decl_data *file_data, const char *data, size_t len, vec< symtab_node * > nodes)
 

Variables

bool asm_nodes_output = false
 

Macro Definition Documentation

◆ LDPR_NUM_KNOWN

#define LDPR_NUM_KNOWN   (LDPR_PREVAILING_DEF_IRONLY_EXP + 1)
Number of LDPR values known to GCC.   

Referenced by input_overwrite_node(), input_varpool_node(), lto_output_node(), and lto_output_varpool_node().

Enumeration Type Documentation

◆ LTO_symtab_tags

Cgraph streaming is organized as set of record whose type
is indicated by a tag.   
Enumerator
LTO_symtab_unavail_node 
LTO_symtab_analyzed_node 
LTO_symtab_edge 
LTO_symtab_indirect_edge 
LTO_symtab_variable 
LTO_symtab_indirect_function 
LTO_symtab_last_tag 

Function Documentation

◆ add_node_to() [1/2]

static void add_node_to ( lto_symtab_encoder_t encoder,
struct cgraph_node * node,
bool include_body )
static
Add NODE into encoder as well as nodes it is cloned from.
Do it in a way so clones appear first.   

References add_node_to(), and cgraph_node::inlined_to.

◆ add_node_to() [2/2]

static void add_node_to ( lto_symtab_encoder_t encoder,
struct cgraph_node * node,
bool include_body,
bool not_inlined )
static
Add NODE into encoder as well as nodes it is cloned from.
Do it in a way so clones appear first.   

References add_node_to(), cgraph_node::clone_of, gcc_checking_assert, lto_symtab_encoder_encode(), and lto_symtab_encoder_d::nodes.

Referenced by add_node_to(), add_node_to(), compute_ltrans_boundary(), and create_references().

◆ compute_ltrans_boundary()

◆ create_references()

static void create_references ( lto_symtab_encoder_t encoder,
symtab_node * node )
static

◆ get_alias_symbol()

static tree get_alias_symbol ( tree decl)
static
Return string alias is alias of.   

References DECL_ATTRIBUTES, get_identifier(), lookup_attribute(), TREE_STRING_POINTER, and TREE_VALUE.

Referenced by input_node(), and input_varpool_node().

◆ input_cgraph_1()

◆ input_cgraph_opt_section()

static void input_cgraph_opt_section ( struct lto_file_decl_data * file_data,
const char * data,
size_t len,
vec< symtab_node * > nodes )
static

◆ input_cgraph_opt_summary()

static void input_cgraph_opt_summary ( vec< symtab_node * > nodes)
static

◆ input_edge()

static void input_edge ( class lto_input_block * ib,
vec< symtab_node * > nodes,
bool indirect )
static
Read an edge from IB.  NODES points to a vector of previously read nodes for
decoding caller and callee of the edge to be read.  If INDIRECT is true, the
edge being read is indirect (in the sense that it has
indirect_unknown_callee set).   

References bp_unpack_enum, bp_unpack_value(), bp_unpack_var_len_unsigned(), count, cgraph_node::create_edge(), cgraph_node::create_indirect_edge(), symtab_node::decl, dyn_cast(), ECF_CONST, ECF_MALLOC, ECF_NORETURN, ECF_NOTHROW, ECF_PURE, ECF_RETURNS_TWICE, cgraph_edge::indirect_inlining_edge, cgraph_edge::inline_failed, internal_error(), NULL, NULL_TREE, cgraph_edge::speculative_id, profile_count::stream_in(), streamer_read_bitpack(), and streamer_read_hwi().

Referenced by input_cgraph_1().

◆ input_edge_opt_summary()

static void input_edge_opt_summary ( struct cgraph_edge * edge,
class lto_input_block * ib_main )
static
Input optimisation summary of EDGE.   

Referenced by input_node_opt_summary().

◆ input_node()

static struct cgraph_node * input_node ( struct lto_file_decl_data * file_data,
class lto_input_block * ib,
enum LTO_symtab_tags tag,
vec< symtab_node * > nodes )
static

◆ input_node_opt_summary()

◆ input_offload_tables()

◆ input_overwrite_node()

static void input_overwrite_node ( struct lto_file_decl_data * file_data,
struct cgraph_node * node,
enum LTO_symtab_tags tag,
struct bitpack_d * bp,
bool * has_thunk_info )
static
Overwrite the information in NODE based on FILE_DATA, TAG, FLAGS,
STACK_SIZE, SELF_TIME and SELF_SIZE.  This is called either to initialize
NODE or to replace the values in it, for instance because the first
time we saw it, the function body was not available but now it
is.  BP is a bitpack with all the bitflags for NODE read from the
stream.  Initialize HAS_THUNK_INFO to indicate if thunk info should
be streamed in.   

References symtab_node::address_taken, symtab_node::alias, symtab_node::analyzed, symtab_node::aux, symtab_node::body_removed, bp_unpack_enum, bp_unpack_value(), cgraph_node::calls_comdat_local, cgraph_node::calls_declare_variant_alt, cgraph_node::can_change_signature, cgraph_node::clone_of, symtab_node::decl, DECL_EXTERNAL, cgraph_node::declare_variant_alt, symtab_node::definition, symtab_node::externally_visible, symtab_node::force_output, symtab_node::forced_by_abi, cgraph_node::frequency, cgraph_node::icf_merged, symtab_node::implicit_section, symtab_node::in_other_partition, LDPR_NUM_KNOWN, cgraph_node::local, cgraph_node::lowered, symtab_node::lto_file_data, LTO_symtab_analyzed_node, cgraph_node::merged_comdat, cgraph_node::merged_extern_inline, symtab_node::no_reorder, cgraph_node::nonfreeing_fn, cgraph_node::only_called_at_exit, cgraph_node::only_called_at_startup, cgraph_node::parallelized_function, cgraph_node::redefined_extern_inline, symtab_node::resolution, symtab_node::semantic_interposition, cgraph_node::split_part, symtab_node::symver, cgraph_node::thunk, cgraph_node::tm_clone, symtab_node::transparent_alias, TREE_STATIC, symtab_node::unique_name, symtab_node::used_from_other_partition, verify_node_partition(), cgraph_node::versionable, and symtab_node::weakref.

Referenced by input_node().

◆ input_profile_summary()

static void input_profile_summary ( class lto_input_block * ib,
struct lto_file_decl_data * file_data )
static

◆ input_ref()

static void input_ref ( class lto_input_block * ib,
symtab_node * referring_node,
vec< symtab_node * > nodes )
static
Read a node from input_block IB.  TAG is the node's tag just read.
Return the node read or overwriten.   

References bp_unpack_value(), symtab_node::create_reference(), is_a(), ipa_ref::lto_stmt_uid, NULL, ipa_ref::speculative, ipa_ref::speculative_id, streamer_read_bitpack(), and streamer_read_hwi().

Referenced by input_refs().

◆ input_refs()

static void input_refs ( class lto_input_block * ib,
vec< symtab_node * > nodes )
static

◆ input_symtab()

◆ input_varpool_node()

◆ lto_output_edge()

◆ lto_output_node()

static void lto_output_node ( struct lto_simple_output_block * ob,
struct cgraph_node * node,
lto_symtab_encoder_t encoder )
static
Output the cgraph NODE to OB.  ENCODER is used to find the
reference number of NODE->inlined_to.  SET is the set of nodes we
are writing to the current file.  If NODE is not in SET, then NODE
is a boundary of a cgraph_node_set and we pretend NODE just has a
decl and no callees.  WRITTEN_DECLS is the set of FUNCTION_DECLs
that have had their callgraph node written so far.  This is used to
determine if NODE is a clone of a previously written node.   

References symtab_node::address_taken, symtab_node::alias, symtab_node::analyzed, bitpack_create(), symtab_node::body_removed, bp_pack_enum, bp_pack_value(), cgraph_node::calls_comdat_local, cgraph_node::calls_declare_variant_alt, cgraph_node::can_change_signature, cgraph_node::clone_of, cgraph_node::count, cgraph_node::count_materialization_scale, symtab_node::decl, DECL_ATTRIBUTES, lto_simple_output_block::decl_state, DECL_STATIC_CONSTRUCTOR, DECL_STATIC_DESTRUCTOR, cgraph_node::declare_variant_alt, symtab_node::definition, symtab_node::externally_visible, FOR_EACH_VEC_ELT, symtab_node::force_output, symtab_node::forced_by_abi, cgraph_node::frequency, gcc_assert, hash_map< KeyId, Value, Traits >::get(), thunk_info::get(), symtab_node::get_comdat_group(), cgraph_node::get_fini_priority(), symtab_node::get_init_priority(), symtab_node::get_partitioning_class(), symtab_node::get_section(), i, cgraph_node::icf_merged, IDENTIFIER_POINTER, symtab_node::implicit_section, symtab_node::in_other_partition, INCREMENTAL_LINK_LTO, cgraph_node::inlined_to, cgraph_node::ipa_transforms_to_apply, LCC_NOT_FOUND, LDPR_NUM_KNOWN, cgraph_node::local, lookup_attribute(), cgraph_node::lowered, lto_output_fn_decl_ref(), lto_stream_offload_p, LTO_symtab_analyzed_node, lto_symtab_encoder_encode_body_p(), lto_symtab_encoder_in_partition_p(), lto_symtab_encoder_lookup(), LTO_symtab_last_tag, LTO_symtab_unavail_node, lto_simple_output_block::main_stream, cgraph_node::merged_comdat, cgraph_node::merged_extern_inline, symtab_node::no_reorder, cgraph_node::nonfreeing_fn, NULL, cgraph_node::only_called_at_exit, cgraph_node::only_called_at_startup, symtab_node::order, lto_symtab_encoder_d::order_remap, cgraph_node::parallelized_function, cgraph_node::prev_sibling_clone, cgraph_node::profile_id, reachable_from_other_partition_p(), cgraph_node::redefined_extern_inline, referenced_from_other_partition_p(), symtab_node::resolution, symtab_node::same_comdat_group, symtab_node::semantic_interposition, cgraph_node::split_part, opt_pass::static_pass_number, profile_count::stream_out(), thunk_info::stream_out(), streamer_write_bitpack(), streamer_write_data_stream(), streamer_write_enum, streamer_write_hwi_stream(), SYMBOL_PARTITION, symtab_node::symver, cgraph_node::thunk, cgraph_node::tm_clone, cgraph_node::tp_first_run, symtab_node::transparent_alias, symtab_node::unique_name, cgraph_node::unit_id, UNLIKELY, cgraph_node::versionable, and symtab_node::weakref.

Referenced by output_symtab().

◆ lto_output_ref()

◆ lto_output_varpool_node()

static void lto_output_varpool_node ( struct lto_simple_output_block * ob,
varpool_node * node,
lto_symtab_encoder_t encoder )
static

◆ lto_set_symtab_encoder_encode_initializer()

static void lto_set_symtab_encoder_encode_initializer ( lto_symtab_encoder_t encoder,
varpool_node * node )
static
Specify that we should encode initializer of NODE (if any).   

References lto_symtab_encoder_lookup(), and lto_symtab_encoder_d::nodes.

Referenced by compute_ltrans_boundary().

◆ lto_set_symtab_encoder_in_partition()

void lto_set_symtab_encoder_in_partition ( lto_symtab_encoder_t encoder,
symtab_node * node )
Specify that NODE is in this partition.   

References lto_symtab_encoder_encode(), and lto_symtab_encoder_d::nodes.

Referenced by compute_ltrans_boundary(), and ipa_write_summaries().

◆ lto_symtab_encoder_delete()

void lto_symtab_encoder_delete ( lto_symtab_encoder_t encoder)

◆ lto_symtab_encoder_delete_node()

◆ lto_symtab_encoder_encode()

◆ lto_symtab_encoder_encode_body_p()

bool lto_symtab_encoder_encode_body_p ( lto_symtab_encoder_t encoder,
struct cgraph_node * node )
Return TRUE if we should encode the body of NODE (if any).   

References lto_symtab_encoder_lookup(), and lto_symtab_encoder_d::nodes.

Referenced by ipcp_write_transformation_summaries(), lto_output(), and lto_output_node().

◆ lto_symtab_encoder_encode_initializer_p()

bool lto_symtab_encoder_encode_initializer_p ( lto_symtab_encoder_t encoder,
varpool_node * node )
Return TRUE if we should encode initializer of NODE (if any).   

References LCC_NOT_FOUND, lto_symtab_encoder_lookup(), and lto_symtab_encoder_d::nodes.

Referenced by compute_ltrans_boundary(), get_symbol_initial_value(), lto_output(), and lto_output_varpool_node().

◆ lto_symtab_encoder_in_partition_p()

◆ lto_symtab_encoder_new()

lto_symtab_encoder_t lto_symtab_encoder_new ( bool for_input)
Create a new symtab encoder.
if FOR_INPUT, the encoder allocate only datastructures needed
to read the symtab.   

References lto_symtab_encoder_d::map, and lto_symtab_encoder_d::nodes.

Referenced by compute_ltrans_boundary(), input_symtab(), and ipa_write_summaries().

◆ lto_symtab_encoder_only_for_inlining_p()

bool lto_symtab_encoder_only_for_inlining_p ( lto_symtab_encoder_t encoder,
struct cgraph_node * node )
Return TRUE if the NODE and its clones are always inlined.   

References lto_symtab_encoder_lookup(), and lto_symtab_encoder_d::nodes.

Referenced by write_ipcp_transformation_info().

◆ merge_profile_summaries()

◆ omp_requires_to_name()

static void omp_requires_to_name ( char * buf,
size_t size,
HOST_WIDE_INT requires_mask )
static

References end(), and lto_input_block::p.

Referenced by input_offload_tables().

◆ output_cgraph_opt_summary()

◆ output_cgraph_opt_summary_p()

static int output_cgraph_opt_summary_p ( struct cgraph_node * node)
static

◆ output_edge_opt_summary()

static void output_edge_opt_summary ( struct output_block * ob,
struct cgraph_edge * edge )
static
Output optimization summary for EDGE to OB.   

Referenced by output_node_opt_summary().

◆ output_node_opt_summary()

◆ output_offload_tables()

◆ output_outgoing_cgraph_edges()

static void output_outgoing_cgraph_edges ( struct cgraph_edge * edge,
struct lto_simple_output_block * ob,
lto_symtab_encoder_t encoder )
static
Output all callees or indirect outgoing edges.  EDGE must be the first such
edge.   

References lto_output_edge().

Referenced by output_symtab().

◆ output_profile_summary()

static void output_profile_summary ( struct lto_simple_output_block * ob)
static

◆ output_refs()

◆ output_symtab()

◆ reachable_from_other_partition_p()

◆ reachable_from_this_partition_p()

bool reachable_from_this_partition_p ( struct cgraph_node * node,
lto_symtab_encoder_t encoder )
Return true when node is reachable from other partition.   

References cgraph_edge::caller, cgraph_node::callers, lto_symtab_encoder_in_partition_p(), and cgraph_edge::next_caller.

Referenced by write_node_summary_p().

◆ read_identifier()

static tree read_identifier ( class lto_input_block * ib)
static
Return identifier encoded in IB as a plain string.   

References lto_input_block::data, get_identifier(), lto_input_block::len, lto_section_overrun(), NULL, and lto_input_block::p.

Referenced by input_node(), and input_varpool_node().

◆ read_string()

static const char * read_string ( class lto_input_block * ib)
static
Return string encoded in IB, NULL if string is empty.   

References lto_input_block::data, lto_input_block::len, lto_section_overrun(), NULL, and lto_input_block::p.

Referenced by input_node(), and input_varpool_node().

◆ referenced_from_other_partition_p()

bool referenced_from_other_partition_p ( symtab_node * node,
lto_symtab_encoder_t encoder )

◆ referenced_from_this_partition_p()

bool referenced_from_this_partition_p ( symtab_node * node,
lto_symtab_encoder_t encoder )
Return if NODE contain references from other partitions.   

References i, symtab_node::iterate_referring(), lto_symtab_encoder_in_partition_p(), NULL, and ipa_ref::referring.

Referenced by ipa_reference_write_optimization_summary(), and write_node_summary_p().

◆ select_what_to_stream()

void select_what_to_stream ( void )
Select what needs to be streamed out.  In regular lto mode stream everything.
In offload lto mode stream only nodes marked as offloadable.   

References FOR_EACH_SYMBOL, lto_stream_offload_p, symtab_node::need_lto_streaming, and symtab_node::offloadable.

Referenced by ipa_write_summaries().

◆ verify_node_partition()

Variable Documentation

◆ asm_nodes_output

bool asm_nodes_output = false
Write and read the cgraph to the memory mapped representation of a
   .o file.

   Copyright (C) 2009-2024 Free Software Foundation, Inc.
   Contributed by Kenneth Zadeck <zadeck@naturalbridge.com>

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/>.   
True when asm nodes has been output.   

Referenced by create_order_remap(), and output_symtab().