GCC Middle and Back End API Reference
lto-cgraph.c File Reference

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_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 ()
void lto_symtab_encoder_delete ()
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_encode_body_p (lto_symtab_encoder_t encoder, struct cgraph_node *node)
static void lto_set_symtab_encoder_encode_body (lto_symtab_encoder_t encoder, struct cgraph_node *node)
bool lto_symtab_encoder_encode_initializer_p (lto_symtab_encoder_t encoder, struct varpool_node *node)
static void lto_set_symtab_encoder_encode_initializer (lto_symtab_encoder_t encoder, struct 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 ()
bool reachable_from_other_partition_p ()
bool referenced_from_this_partition_p (struct ipa_ref_list *list, lto_symtab_encoder_t encoder)
bool reachable_from_this_partition_p ()
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, struct 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 ()
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 ()
static void add_node_to (lto_symtab_encoder_t encoder, struct cgraph_node *node, bool include_body)
static void add_references (lto_symtab_encoder_t encoder, struct ipa_ref_list *list)
lto_symtab_encoder_t compute_ltrans_boundary ()
void output_symtab ()
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)
static tree get_alias_symbol ()
static struct cgraph_nodeinput_node (struct lto_file_decl_data *file_data, struct lto_input_block *ib, enum LTO_symtab_tags tag, vec< symtab_node > nodes)
static struct varpool_nodeinput_varpool_node (struct lto_file_decl_data *file_data, struct lto_input_block *ib)
static void input_ref (struct lto_input_block *ib, symtab_node referring_node, vec< symtab_node > nodes)
static void input_edge (struct lto_input_block *ib, vec< symtab_node > nodes, bool indirect)
static vec< symtab_nodeinput_cgraph_1 (struct lto_file_decl_data *file_data, struct lto_input_block *ib)
static void input_refs (struct lto_input_block *ib, vec< symtab_node > nodes)
static void input_profile_summary (struct lto_input_block *ib, struct lto_file_decl_data *file_data)
static void merge_profile_summaries ()
void input_symtab ()
static int output_cgraph_opt_summary_p ()
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, struct lto_input_block *ib_main)
static void input_node_opt_summary (struct cgraph_node *node, struct lto_input_block *ib_main, struct 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)
static void input_cgraph_opt_summary ()

Variables

static int order_base
static struct gcov_ctr_summary lto_gcov_summary

Enumeration Type Documentation

   Cgraph streaming is organized as set of record whose type
   is indicated by a tag.  
Enumerator:
LTO_symtab_unavail_node 
     Must leave 0 for the stopper.  
     Cgraph node without body available.  
LTO_symtab_analyzed_node 
     Cgraph node with function body.  
LTO_symtab_edge 
     Cgraph edges.  
LTO_symtab_indirect_edge 
LTO_symtab_variable 
LTO_symtab_last_tag 

Function Documentation

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.  

Referenced by output_refs().

static void add_references ( lto_symtab_encoder_t  encoder,
struct ipa_ref_list list 
)
static
   Add all references in LIST to encoders.  
lto_symtab_encoder_t compute_ltrans_boundary ( )
   Find all symbols we want to stream into given partition and insert them
   to encoders.

   The function actually replaces IN_ENCODER by new one.  The reason is that
   streaming code needs clone's origin to be streamed before clone.  This
   means that we need to insert the nodes in specific order.  This order is
   ignored by the partitioning logic earlier.  
     Go over all entries in the IN_ENCODER and duplicate them to
     ENCODER. At the same time insert masters of clones so
     every master appears before clone.  
         For proper debug info, we need to ship the origins, too.  
         For proper debug info, we need to ship the origins, too.  
     Pickle in also the initializer of all referenced readonly variables
     to help folding.  Constant pool variables are not shared, so we must
     pickle those too.  
     Go over all the nodes again to include callees that are not in
     SET.  
                 We should have moved all the inlines.  
         Add all possible targets for late devirtualization.  
                         Adding an external declarations into the unit serves
                         no purpose and just increases its boundary.  
static tree get_alias_symbol ( )
static
   Return string alias is alias of.  
static vec<symtab_node> input_cgraph_1 ( struct lto_file_decl_data file_data,
struct lto_input_block ib 
)
static
   Read a cgraph from IB using the info in FILE_DATA.  
     AUX pointers should be all non-zero for function nodes read from the stream.  
             We share declaration of builtins, so we may read same node twice.  
             Fixup inlined_to from reference to pointer.  
         Fixup same_comdat_group from reference to pointer.  

References count, input_ref(), and streamer_read_uhwi().

static void input_cgraph_opt_section ( struct lto_file_decl_data file_data,
const char *  data,
size_t  len,
vec< symtab_node nodes 
)
static
   Read section in file FILE_DATA of length LEN with data DATA.  
static void input_cgraph_opt_summary ( vec< symtab_node nodes)
static
static void input_cgraph_opt_summary ( )
static
   Input optimization summary of cgraph.  
static void input_edge ( struct 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).  
static void input_edge_opt_summary ( struct cgraph_edge edge,
struct lto_input_block ib_main 
)
static
   Input optimisation summary of EDGE.  
static struct cgraph_node* input_node ( struct lto_file_decl_data file_data,
struct lto_input_block ib,
enum LTO_symtab_tags  tag,
vec< symtab_node nodes 
)
staticread
   Read a node from input_block IB.  TAG is the node's tag just read.
   Return the node read or overwriten.  
         Declaration of functions can be already merged with a declaration
         from other input file.  We keep cgraph unmerged until after streaming
         of ipa passes is done.  Alays forcingly create a fresh node.  
     Make sure that we have not read this node before.  Nodes that
     have already been read will have their tag stored in the 'aux'
     field.  Since built-in functions can be referenced in multiple
     functions, they are expected to be read more than once.  
     Store a reference for now, and fix up later to be a pointer.  
     Store a reference for now, and fix up later to be a pointer.  
static void input_node_opt_summary ( struct cgraph_node node,
struct lto_input_block ib_main,
struct data_in data_in 
)
static
   Input optimisation summary of 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 
)
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.  
         Avoid updating decl when we are seeing just inline clone.
         When inlining function that has functions already inlined into it,
         we produce clones of inline clones.

         WPA partitioning might put each clone into different unit and
         we might end up streaming inline clone from other partition
         to support clone we are interested in. 

References cgraph(), cgraph_clone_node(), cgraph_create_empty_node(), count, cgraph_node::count, cgraph_node::count_materialization_scale, symtab_node_base::decl, g, gcc::context::get_passes(), cgraph_node::ipa_transforms_to_apply, symtab_node_base::order, order, order_base, gcc::pass_manager::passes_by_id, streamer_read_gcov_count(), streamer_read_hwi(), streamer_read_uhwi(), symtab_order, symtab_register_node(), and vNULL.

static void input_profile_summary ( struct lto_input_block ib,
struct lto_file_decl_data file_data 
)
static
   Input profile_info from IB.  
         Input the bitpack of non-zero histogram indices.  
         Read in and unpack the full bitpack, flagging non-zero
         histogram entries by setting the num_counters non-zero.  
         IPA-profile computes hot bb threshold based on cumulated
         whole program profile.  We need to stream it down to ltrans.  

References apply_scale(), lto_gcov_summary, lto_file_decl_data::profile_info, gcov_ctr_summary::runs, gcov_ctr_summary::sum_all, and gcov_ctr_summary::sum_max.

static void input_ref ( struct 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.  

Referenced by input_cgraph_1().

static void input_refs ( struct lto_input_block ib,
vec< symtab_node nodes 
)
static
   Input ipa_refs.  

References sorry().

void input_symtab ( void  )
   Input and merge the symtab from each of the .o files passed to
   lto1.  
     Clear out the aux field that was used to store enough state to
     tell which nodes should be overwritten.  
         Some nodes may have been created by cgraph_node.  This
         happens when the callgraph contains nested functions.  If the
         node for the parent function was never emitted to the gimple
         file, cgraph_node will create a node for it when setting the
         context of the nested function.  
static struct varpool_node* input_varpool_node ( struct lto_file_decl_data file_data,
struct lto_input_block ib 
)
staticread
   Read a node from input_block IB.  TAG is the node's tag just read.
   Return the node read or overwriten.  
     Declaration of functions can be already merged with a declaration
     from other input file.  We keep cgraph unmerged until after streaming
     of ipa passes is done.  Alays forcingly create a fresh node.  
     Store a reference for now, and fix up later to be a pointer.  
static void lto_output_edge ( struct lto_simple_output_block ob,
struct cgraph_edge edge,
lto_symtab_encoder_t  encoder 
)
static
   Output the cgraph EDGE to OB using ENCODER.  
         Flags that should not appear on indirect calls.  
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.  
     In WPA mode, we only output part of the call-graph.  Also, we
     fake cgraph node attributes.  There are two cases that we care.

     Boundary nodes: There are nodes that are not part of SET but are
     called from within SET.  We artificially make them look like
     externally visible nodes with no function body.

     Cherry-picked nodes:  These are nodes we pulled from other
     translation units into SET during IPA-inlining.  We make them as
     local static nodes to prevent clashes with other local statics.  
         Inline clones can not be part of boundary.  
         gcc_assert (!node->global.inlined_to);  

         FIXME: At the moment they can be, when partition contains an inline
         clone that is clone of inline clone from outside partition.  We can
         reshape the clone tree and make other tree to be the root, but it
         needs a bit extra work and will be promplty done by cgraph_remove_node
         after reading back.  
     See if body of the master function is output.  If not, we are seeing only
     an declaration and we do not need to pass down clone tree. 
     Real aliases in a boundary become non-aliases. However we still stream
     alias info on weakrefs. 
     TODO: We lose a bit of information here - when we know that variable is
     defined in other unit, we may use the info on aliases to resolve 
     symbol1 != symbol2 type tests that we can do only for locally defined objects
     otherwise.  
static void lto_output_ref ( struct lto_simple_output_block ob,
struct ipa_ref ref,
lto_symtab_encoder_t  encoder 
)
static
   Output the varpool NODE to OB. 
   If NODE is not in SET, then NODE is a boundary.  
static void lto_output_varpool_node ( struct lto_simple_output_block ob,
struct varpool_node node,
lto_symtab_encoder_t  encoder 
)
static
   Output the varpool NODE to OB. 
   If NODE is not in SET, then NODE is a boundary.  
     Constant pool initializers can be de-unified into individual ltrans units.
     FIXME: Alternatively at -Os we may want to avoid generating for them the local
     labels and share them across LTRANS partitions.  
             in_other_partition.  

References symtab_node_base::analyzed, bp_pack_value(), symtab_node_base::decl, symtab_node_base::definition, symtab_node_base::ref_list, and referenced_from_other_partition_p().

static void lto_set_symtab_encoder_encode_body ( lto_symtab_encoder_t  encoder,
struct cgraph_node node 
)
static
   Return TRUE if we should encode body of NODE (if any).  
static void lto_set_symtab_encoder_encode_initializer ( lto_symtab_encoder_t  encoder,
struct varpool_node node 
)
static
   Return TRUE if we should encode initializer of NODE (if any).  

References lto_symtab_encoder_encode(), and lto_symtab_encoder_d::nodes.

void lto_set_symtab_encoder_in_partition ( lto_symtab_encoder_t  encoder,
symtab_node  node 
)
   Return TRUE if we should encode body of NODE (if any).  
void lto_symtab_encoder_delete ( )
   Delete ENCODER and its components.  

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

bool lto_symtab_encoder_delete_node ( lto_symtab_encoder_t  encoder,
symtab_node  node 
)
   Remove NODE from encoder.  
     Remove from vector. We do this by swapping node with the last element
     of the vector.  
         Move the last element to the original spot of NODE.  
     Remove element from hash table.  
int lto_symtab_encoder_encode ( lto_symtab_encoder_t  encoder,
symtab_node  node 
)
   Return the existing reference number of NODE in the symtab encoder in
   output block OB.  Assign a new reference if this is the first time
   NODE is encoded.  

Referenced by lto_set_symtab_encoder_encode_initializer(), and output_refs().

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

References lto_symtab_encoder_lookup(), and lto_symtab_encoder_d::nodes.

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

References free(), lto_symtab_encoder_d::map, lto_symtab_encoder_d::nodes, and pointer_map_destroy().

static void merge_profile_summaries ( )
static
   Rescale profile summaries to the same number of runs in the whole unit.  
     Find unit with maximal number of runs.  If we ever get serious about
     roundoff errors, we might also consider computing smallest common
     multiply.  
     Simple overflow check.  We probably don't need to support that many train
     runs. Such a large value probably imply data corruption anyway.  
     Rescale all units to the maximal number of runs.
     sum_max can not be easily merged, as we have no idea what files come from
     the same run.  We do not use the info anyway, so leave it 0.  
           Save a pointer to the profile_info with the largest
           scaled sum_all and the scale for use in merging the
           histogram.  
     Scale up the histogram from the profile that had the largest
     scaled sum_all above.  
         Scale up the min value as we did the corresponding sum_all
         above. Use that to find the new histogram index.  
         The new index may be shared with another scaled histogram entry,
         so we need to account for a non-zero histogram entry at new_ix.  
         Some of the scaled counter values would ostensibly need to be placed
         into different (larger) histogram buckets, but we keep things simple
         here and place the scaled cumulative counter value in the bucket
         corresponding to the scaled minimum counter value.  
     Watch roundoff errors.  
     If merging already happent at WPA time, we are done.  
     Now compute count_materialization_scale of each node.
     During LTRANS we already have values of count_materialization_scale
     computed, so just update them.  
static void output_cgraph_opt_summary ( void  )
static
@verbatim 

Write and read the cgraph to the memory mapped representation of a .o file.

Copyright (C) 2009-2013 Free Software Foundation, Inc. Contributed by Kenneth Zadeck zadec.nosp@m.k@na.nosp@m.tural.nosp@m.brid.nosp@m.ge.co.nosp@m.m

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/.

   Output optimization summaries stored in callgraph.
   At the moment it is the clone info structure.  
static int output_cgraph_opt_summary_p ( )
static
   True when we need optimization summary for NODE.  
static void output_edge_opt_summary ( struct output_block ob,
struct cgraph_edge edge 
)
static
   Output optimization summary for EDGE to OB.  
static void output_node_opt_summary ( struct output_block ob,
struct cgraph_node node,
lto_symtab_encoder_t  encoder 
)
static
   Output optimization summary for NODE to OB.  
         At the moment we assume all old trees to be PARM_DECLs, because we have no
         mechanism to store function local declarations into summaries.  
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.  
     Output edges in backward direction, so the reconstructed callgraph match
     and it is easy to associate call sites in the IPA pass summaries.  
static void output_profile_summary ( )
static
   Stream out profile_summary to OB.  
         We do not output num and run_max, they are not used by
         GCC profile feedback and they are difficult to merge from multiple
         units.  
         sum_all is needed for computing the working set with the
         histogram.  
         Create and output a bitpack of non-zero histogram entries indices.  
         Now stream out only those non-zero entries.  
         IPA-profile computes hot bb threshold based on cumulated
         whole program profile.  We need to stream it down to ltrans.  
static void output_refs ( )
static
   Output the part of the cgraph in SET.  

References add_node_to(), ipa_ref_node(), lto_symtab_encoder_encode(), and ipa_ref::referred.

void output_symtab ( void  )
   Output the part of the symtab in SET and VSET.  
     An encoder for cgraph nodes should have been created by
     ipa_write_summaries_1.  
     Write out the nodes.  We must first output a node and then its clones,
     otherwise at a time reading back the node there would be nothing to clone
     from.  
     Go over the nodes in SET again to write edges.  
     Emit toplevel asms.
     When doing WPA we must output every asm just once.  Since we do not partition asm
     nodes at all, output them to first output.  This is kind of hack, but should work
     well.  
bool reachable_from_other_partition_p ( )
   Return true when node is reachable from other partition.  
bool reachable_from_this_partition_p ( )
   Return true when node is reachable from other partition.  
bool referenced_from_other_partition_p ( )
   Return if LIST contain references from other partitions.  

Referenced by lto_output_varpool_node().

bool referenced_from_this_partition_p ( struct ipa_ref_list list,
lto_symtab_encoder_t  encoder 
)
   Return if LIST contain references from other partitions.  

References cgraph_node::clone_of.


Variable Documentation

struct gcov_ctr_summary lto_gcov_summary
static

Referenced by input_profile_summary().

int order_base
static
   All node orders are ofsetted by ORDER_BASE.  

Referenced by input_overwrite_node().