GCC Middle and Back End API Reference
cgraph.c File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "tree.h"
#include "tree-inline.h"
#include "langhooks.h"
#include "hashtab.h"
#include "toplev.h"
#include "flags.h"
#include "ggc.h"
#include "debug.h"
#include "target.h"
#include "basic-block.h"
#include "cgraph.h"
#include "intl.h"
#include "gimple.h"
#include "timevar.h"
#include "dumpfile.h"
#include "gimple-ssa.h"
#include "tree-cfg.h"
#include "tree-ssa.h"
#include "value-prof.h"
#include "except.h"
#include "diagnostic-core.h"
#include "rtl.h"
#include "ipa-utils.h"
#include "lto-streamer.h"
#include "ipa-inline.h"
#include "cfgloop.h"
#include "gimple-pretty-print.h"
#include "tree-pass.h"
#include "cif-code.def"
#include "gt-cgraph.h"
Include dependency graph for cgraph.c:

Data Structures

struct  cgraph_edge_hook_list
struct  cgraph_node_hook_list
struct  cgraph_2edge_hook_list
struct  cgraph_2node_hook_list

Macros

#define cgraph_nodes_queue   ((struct cgraph_node *)x_cgraph_nodes_queue)
#define NEXT_FREE_NODE(NODE)   cgraph ((NODE)->next)
#define SET_NEXT_FREE_NODE(NODE, NODE2)   ((NODE))->next = NODE2
#define NEXT_FREE_EDGE(EDGE)   (EDGE)->prev_caller
#define DEFCIFCODE(code, string)   string,

Functions

static void cgraph_node_remove_callers (struct cgraph_node *node)
static void cgraph_edge_remove_caller (struct cgraph_edge *e)
static void cgraph_edge_remove_callee (struct cgraph_edge *e)
static hashval_t cgraph_fnver_htab_hash ()
static int cgraph_fnver_htab_eq ()
struct
cgraph_function_version_info
get_cgraph_node_version ()
struct
cgraph_function_version_info
insert_new_cgraph_node_version ()
void delete_function_version ()
void record_function_versions ()
struct cgraph_edge_hook_listcgraph_add_edge_removal_hook ()
void cgraph_remove_edge_removal_hook ()
static void cgraph_call_edge_removal_hooks ()
struct cgraph_node_hook_listcgraph_add_node_removal_hook ()
void cgraph_remove_node_removal_hook ()
static void cgraph_call_node_removal_hooks ()
struct cgraph_node_hook_listcgraph_add_function_insertion_hook ()
void cgraph_remove_function_insertion_hook ()
void cgraph_call_function_insertion_hooks ()
struct cgraph_2edge_hook_listcgraph_add_edge_duplication_hook ()
void cgraph_remove_edge_duplication_hook ()
void cgraph_call_edge_duplication_hooks (struct cgraph_edge *cs1, struct cgraph_edge *cs2)
struct cgraph_2node_hook_listcgraph_add_node_duplication_hook ()
void cgraph_remove_node_duplication_hook ()
void cgraph_call_node_duplication_hooks (struct cgraph_node *node1, struct cgraph_node *node2)
static struct cgraph_nodecgraph_allocate_node ()
struct cgraph_nodecgraph_create_empty_node ()
struct cgraph_nodecgraph_create_node ()
struct cgraph_nodecgraph_get_create_node ()
struct cgraph_nodecgraph_create_function_alias ()
struct cgraph_nodecgraph_same_body_alias ()
struct cgraph_nodecgraph_add_thunk (struct cgraph_node *decl_node, tree alias, tree decl, bool this_adjusting, HOST_WIDE_INT fixed_offset, HOST_WIDE_INT virtual_value, tree virtual_offset, tree real_alias)
struct cgraph_nodecgraph_node_for_asm ()
static hashval_t edge_hash ()
static int edge_eq ()
static void cgraph_update_edge_in_call_site_hash ()
static void cgraph_add_edge_to_call_site_hash ()
struct cgraph_edgecgraph_edge ()
void cgraph_set_call_stmt (struct cgraph_edge *e, gimple new_stmt, bool update_speculative)
static struct cgraph_edgecgraph_create_edge_1 (struct cgraph_node *caller, struct cgraph_node *callee, gimple call_stmt, gcov_type count, int freq, bool indir_unknown_callee)
struct cgraph_edgecgraph_create_edge (struct cgraph_node *caller, struct cgraph_node *callee, gimple call_stmt, gcov_type count, int freq)
struct cgraph_indirect_call_infocgraph_allocate_init_indirect_info ()
struct cgraph_edgecgraph_create_indirect_edge (struct cgraph_node *caller, gimple call_stmt, int ecf_flags, gcov_type count, int freq)
static void cgraph_edge_remove_callee ()
static void cgraph_edge_remove_caller ()
static void cgraph_free_edge ()
void cgraph_remove_edge ()
static void cgraph_set_edge_callee ()
struct cgraph_edgecgraph_turn_edge_to_speculative (struct cgraph_edge *e, struct cgraph_node *n2, gcov_type direct_count, int direct_frequency)
void cgraph_speculative_call_info (struct cgraph_edge *e, struct cgraph_edge *&direct, struct cgraph_edge *&indirect, struct ipa_ref *&reference)
void cgraph_redirect_edge_callee ()
struct cgraph_edgecgraph_resolve_speculation ()
struct cgraph_edgecgraph_make_edge_direct ()
gimple cgraph_redirect_edge_call_stmt_to_callee ()
static void cgraph_update_edges_for_call_stmt_node (struct cgraph_node *node, gimple old_stmt, tree old_call, gimple new_stmt)
void cgraph_update_edges_for_call_stmt ()
void cgraph_node_remove_callees ()
static void cgraph_node_remove_callers ()
void release_function_body ()
void cgraph_release_function_body ()
void cgraph_remove_node ()
void cgraph_mark_address_taken_node ()
struct cgraph_local_infocgraph_local_info ()
struct cgraph_global_infocgraph_global_info ()
struct cgraph_rtl_infocgraph_rtl_info ()
const char * cgraph_inline_failed_string ()
void dump_cgraph_node ()
DEBUG_FUNCTION void debug_cgraph_node ()
void dump_cgraph ()
DEBUG_FUNCTION void debug_cgraph ()
bool cgraph_function_possibly_inlined_p ()
void cgraph_unnest_node ()
enum availability cgraph_function_body_availability ()
static bool cgraph_node_cannot_be_local_p_1 (struct cgraph_node *node, void *data)
bool cgraph_node_can_be_local_p ()
bool cgraph_for_node_thunks_and_aliases (struct cgraph_node *node, bool(*callback)(struct cgraph_node *, void *), void *data, bool include_overwritable)
bool cgraph_for_node_and_aliases (struct cgraph_node *node, bool(*callback)(struct cgraph_node *, void *), void *data, bool include_overwritable)
static bool cgraph_make_node_local_1 ()
void cgraph_make_node_local ()
static bool cgraph_set_nothrow_flag_1 ()
void cgraph_set_nothrow_flag ()
static bool cgraph_set_const_flag_1 ()
void cgraph_set_const_flag ()
static bool cgraph_set_pure_flag_1 ()
void cgraph_set_pure_flag ()
bool cgraph_node_cannot_return ()
bool cgraph_edge_cannot_lead_to_return ()
bool cgraph_can_remove_if_no_direct_calls_and_refs_p ()
static bool nonremovable_p ()
bool cgraph_can_remove_if_no_direct_calls_p ()
static bool used_from_object_file_p ()
bool cgraph_will_be_removed_from_program_if_no_direct_calls ()
static bool cgraph_not_only_called_directly_p_1 ()
bool cgraph_only_called_directly_p ()
static bool collect_callers_of_node_1 ()
vec< cgraph_edge_pcollect_callers_of_node ()
static bool clone_of_p ()
static bool verify_edge_count_and_frequency ()
static void cgraph_debug_gimple_stmt ()
static bool verify_edge_corresponds_to_fndecl ()
DEBUG_FUNCTION void verify_cgraph_node ()
DEBUG_FUNCTION void verify_cgraph ()
struct cgraph_nodecgraph_get_create_real_symbol_node ()
struct cgraph_nodecgraph_function_node ()
bool cgraph_get_body ()
static bool gimple_check_call_args ()
bool gimple_check_call_matching_types (gimple call_stmt, tree callee, bool args_count_match)

Variables

symtab_node x_cgraph_nodes_queue
int cgraph_n_nodes
int cgraph_max_uid
int cgraph_edge_max_uid
bool cgraph_global_info_ready = false
enum cgraph_state cgraph_state = CGRAPH_STATE_PARSING
bool cgraph_function_flags_ready = false
struct cgraph_edge_hook_listfirst_cgraph_edge_removal_hook
struct cgraph_node_hook_listfirst_cgraph_node_removal_hook
struct cgraph_2edge_hook_listfirst_cgraph_edge_duplicated_hook
struct cgraph_2node_hook_listfirst_cgraph_node_duplicated_hook
struct cgraph_node_hook_listfirst_cgraph_function_insertion_hook
static struct cgraph_nodefree_nodes
static struct cgraph_edgefree_edges
bool cpp_implicit_aliases_done
static htab_t cgraph_fnver_htab = NULL
static struct
cgraph_function_version_info
version_info_node = NULL
const char *const cgraph_availability_names []

Macro Definition Documentation

#define cgraph_nodes_queue   ((struct cgraph_node *)x_cgraph_nodes_queue)
#define DEFCIFCODE (   code,
  string 
)    string,
#define NEXT_FREE_EDGE (   EDGE)    (EDGE)->prev_caller
#define NEXT_FREE_NODE (   NODE)    cgraph ((NODE)->next)

Macros to access the next item in the list of free cgraph nodes and edges.

Referenced by cgraph_add_node_duplication_hook().

#define SET_NEXT_FREE_NODE (   NODE,
  NODE2 
)    ((NODE))->next = NODE2

Function Documentation

struct cgraph_2edge_hook_list* cgraph_add_edge_duplication_hook ( )
read

Register HOOK to be called with DATA on each duplicated edge.

References cgraph_2node_hook_list::data, first_cgraph_node_duplicated_hook, cgraph_2node_hook_list::hook, cgraph_2node_hook_list::next, and NULL.

Referenced by ipa_edge_duplication_hook().

struct cgraph_edge_hook_list* cgraph_add_edge_removal_hook ( )
read

Register HOOK to be called with DATA on each removed edge.

References cgraph_edge_hook_list::data, cgraph_edge_hook_list::hook, and cgraph_edge_hook_list::next.

Referenced by ipa_edge_duplication_hook().

static void cgraph_add_edge_to_call_site_hash ( )
inlinestatic

Add call graph edge E to call site hash of its caller.

There are two speculative edges for every statement (one direct, one indirect); always hash the direct one.

struct cgraph_node_hook_list* cgraph_add_function_insertion_hook ( )
read

Register HOOK to be called with DATA on each inserted node.

References cgraph_2edge_hook_list::data, first_cgraph_edge_duplicated_hook, cgraph_2edge_hook_list::hook, cgraph_2edge_hook_list::next, and NULL.

Referenced by ipa_edge_duplication_hook().

struct cgraph_2node_hook_list* cgraph_add_node_duplication_hook ( )
read

Register HOOK to be called with DATA on each duplicated node.

References free_nodes, and NEXT_FREE_NODE.

Referenced by ipa_edge_duplication_hook().

struct cgraph_node_hook_list* cgraph_add_node_removal_hook ( )
read

Register HOOK to be called with DATA on each removed node.

Referenced by devirt_variable_node_removal_hook(), and ipa_edge_duplication_hook().

struct cgraph_node* cgraph_add_thunk ( struct cgraph_node decl_node,
tree  alias,
tree  decl,
bool  this_adjusting,
HOST_WIDE_INT  fixed_offset,
HOST_WIDE_INT  virtual_value,
tree  virtual_offset,
tree  real_alias 
)
read

Add thunk alias into callgraph. The alias declaration is ALIAS and it aliases DECL with an adjustments made into the first parameter. See comments in thunk_adjust for detail on the parameters.

struct cgraph_indirect_call_info* cgraph_allocate_init_indirect_info ( void  )
read
static struct cgraph_node* cgraph_allocate_node ( )
staticread

Allocate new callgraph node.

Referenced by cgraph_remove_node_duplication_hook().

void cgraph_call_edge_duplication_hooks ( struct cgraph_edge cs1,
struct cgraph_edge cs2 
)
static void cgraph_call_edge_removal_hooks ( )
static

Call all edge removal hooks.

void cgraph_call_function_insertion_hooks ( )
void cgraph_call_node_duplication_hooks ( struct cgraph_node node1,
struct cgraph_node node2 
)
static void cgraph_call_node_removal_hooks ( )
static
bool cgraph_can_remove_if_no_direct_calls_and_refs_p ( )

Return true when function NODE can be removed from callgraph if all direct calls are eliminated.

 Extern inlines can always go, we will use the external definition.   
 When function is needed, we can not remove it.   
 Only COMDAT functions can be removed if externally visible.   

References cgraph_edge::call_stmt, cgraph_edge::caller, compute_call_stmt_bb_frequency(), symtab_node_base::decl, error(), and cgraph_edge::frequency.

Referenced by cgraph_make_node_local(), and symtab_remove_unreachable_nodes().

bool cgraph_can_remove_if_no_direct_calls_p ( )

Return true when function NODE and its aliases can be removed from callgraph if all direct calls are eliminated.

Extern inlines can always go, we will use the external definition.

References cgraph_edge::callee, cgraph_get_node(), CGRAPH_LTO_STREAMING, cgraph_node::global, and cgraph_global_info::inlined_to.

Referenced by cgraph_set_const_flag_1().

struct cgraph_edge* cgraph_create_edge ( struct cgraph_node caller,
struct cgraph_node callee,
gimple  call_stmt,
gcov_type  count,
int  freq 
)
read

Create edge from CALLER to CALLEE in the cgraph.

Referenced by build_cgraph_edges(), cgraph_clone_edge(), and ipa_tm_diagnose_tm_safe().

static struct cgraph_edge* cgraph_create_edge_1 ( struct cgraph_node caller,
struct cgraph_node callee,
gimple  call_stmt,
gcov_type  count,
int  freq,
bool  indir_unknown_callee 
)
staticread

Allocate a cgraph_edge structure and fill it with data according to the parameters of which only CALLEE can be NULL (when creating an indirect call edge).

LTO does not actually have access to the call_stmt since these have not been loaded yet.

     This is a rather expensive check possibly triggering
     construction of call stmt hashtable.   

References cgraph_node::callees, cgraph_node::callers, initialize_inline_failed(), cgraph_edge::next_callee, cgraph_edge::next_caller, cgraph_edge::prev_callee, and cgraph_edge::prev_caller.

struct cgraph_edge* cgraph_create_indirect_edge ( struct cgraph_node caller,
gimple  call_stmt,
int  ecf_flags,
gcov_type  count,
int  freq 
)
read

Create an indirect edge with a yet-undetermined callee where the call statement destination is a formal parameter of the caller with index PARAM_INDEX.

Record polymorphic call info.

     Only record types can have virtual calls.   

References free_edges, ggc_free(), cgraph_edge::indirect_info, NEXT_FREE_EDGE, and cgraph_edge::uid.

Referenced by build_cgraph_edges(), and cgraph_clone_edge().

struct cgraph_node* cgraph_create_node ( )
read

Return cgraph node assigned to DECL. Create new one when needed.

Referenced by cgraph_create_function_alias(), expand_assign_tm(), and update_call_expr().

static void cgraph_debug_gimple_stmt ( )
static

Switch to THIS_CFUN if needed and print STMT to stderr.

debug_gimple_stmt needs correct cfun

 ...and an actual current_function_decl  

References error().

struct cgraph_edge* cgraph_edge ( )
read

Return the callgraph edge representing the GIMPLE_CALL statement CALL_STMT.

This loop may turn out to be performance problem. In such case adding hashtables into call nodes with very many edges is probably best solution. It is not good idea to add pointer into CALL_EXPR itself because we want to make possible having multiple cgraph nodes representing different clones of the same body before the body is actually cloned.

Referenced by cgraph_set_edge_callee(), and update_call_edge_frequencies().

bool cgraph_edge_cannot_lead_to_return ( )

Return true when call of E can not lead to return from caller and thus it is safe to ignore its side effects for IPA analysis when computing side effects of the caller. FIXME: We could actually mark all edges that have no reaching patch to EXIT_BLOCK_PTR or throw to get better results.

References cgraph_edge::caller, CGRAPH_FREQ_MAX, cgraph_edge::count, symtab_node_base::decl, error(), error_found, cgraph_edge::frequency, gimple_has_body_p(), cgraph_node::global, and cgraph_global_info::inlined_to.

static void cgraph_edge_remove_callee ( struct cgraph_edge e)
inlinestatic
static void cgraph_edge_remove_callee ( )
inlinestatic

Remove the edge E from the list of the callers of the callee.

static void cgraph_edge_remove_caller ( struct cgraph_edge e)
inlinestatic
static void cgraph_edge_remove_caller ( )
inlinestatic

Remove the edge E from the list of the callees of the caller.

References cgraph_edge::caller, cgraph_node_name(), dump_file, and symtab_node_base::order.

static int cgraph_fnver_htab_eq ( )
static

eq function for cgraph_fnver_htab.

static hashval_t cgraph_fnver_htab_hash ( )
static

Hash function for cgraph_fnver_htab.

References cgraph_fnver_htab, NULL, and cgraph_function_version_info::this_node.

bool cgraph_for_node_and_aliases ( struct cgraph_node node,
bool(*)(struct cgraph_node *, void *)  callback,
void *  data,
bool  include_overwritable 
)

Call calback on NODE and aliases associated to NODE. When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are skipped.

References cgraph_edge::callee, cgraph_edge::caller, cgraph_node_cannot_return(), cgraph_indirect_call_info::ecf_flags, ECF_NOTHROW, cgraph_edge::indirect_info, and cgraph_edge::indirect_unknown_callee.

Referenced by cgraph_set_const_flag_1(), cgraph_set_nothrow_flag_1(), cgraph_set_pure_flag_1(), contains_hot_call_p(), and debug_cgraph().

bool cgraph_for_node_thunks_and_aliases ( struct cgraph_node node,
bool(*)(struct cgraph_node *, void *)  callback,
void *  data,
bool  include_overwritable 
)

Call calback on NODE, thunks and aliases associated to NODE. When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are skipped.

Referenced by cgraph_function_body_availability().

static void cgraph_free_edge ( )
static

Put the edge onto the free list.

Clear out the edge so we do not dangle pointers.

enum availability cgraph_function_body_availability ( )

Return function availability. See cgraph.h for description of individual return values.

Inline functions are safe to be analyzed even if their symbol can be overwritten at runtime. It is not meaningful to enforce any sane behaviour on replacing inline function by different body.

 If the function can be overwritten, return OVERWRITABLE.  Take
 care at least of two notable extensions - the COMDAT functions
 used to share template instantiations in C++ (this is symmetric
 to code cp_cannot_inline_tree_fn and probably shall be shared and
 the inlinability hooks completely eliminated).

 ??? Does the C++ one definition rule allow us to always return
 AVAIL_AVAILABLE here?  That would be good reason to preserve this
 bit.   

References cgraph_for_node_thunks_and_aliases(), and cgraph_make_node_local_1().

Referenced by cgraph_unnest_node(), debug_cgraph(), and print_all_lattices().

struct cgraph_node* cgraph_function_node ( )
read

Given NODE, walk the alias chain to return the function NODE is alias of. Walk through thunk, too. When AVAILABILITY is non-NULL, get minimal availability in the chain.

Referenced by ipa_reverse_postorder(), known_aggs_to_agg_replacement_list(), propagate_aggs_accross_jump_function(), read_write_all_from_decl(), and set_reference_optimization_summary().

bool cgraph_function_possibly_inlined_p ( )

Return true when the DECL can possibly be inlined.

bool cgraph_get_body ( )

When doing LTO, read NODE's body from disk if it is not already present.

We may have renamed the declaration, e.g., a static function.

Referenced by cgraph_materialize_clone().

struct cgraph_node* cgraph_get_create_node ( )
read
struct cgraph_node* cgraph_get_create_real_symbol_node ( )
read

Create external decl node for DECL. The difference i nbetween cgraph_get_create_node and cgraph_get_create_real_symbol_node is that cgraph_get_create_node may return inline clone, while cgraph_get_create_real_symbol_node will create a new node in this case. FIXME: This function should be removed once clones are put out of decl hash.

create symbol table node. even if inline clone exists, we can not take it as a target of non-inlined call.

 ok, we previously inlined the function, then removed the offline copy and
 now we want it back for external call.  this can happen when devirtualizing
 while inlining function called once that happens after extern inlined and
 virtuals are already removed.  in this case introduce the external node
 and make it available for call.   

Return local info for the compiled function.

const char* cgraph_inline_failed_string ( )

Return a string describing the failure REASON.

This file contains the definitions of the cgraph_inline_failed_t enums used in GCC.

Copyright (C) 2008-2013 Free Software Foundation, Inc. Contributed by Doug Kwan dougk.nosp@m.wan@.nosp@m.googl.nosp@m.e.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/.

The format of this file is DEFCIFCODE(code, string).

Where symbol is the enumeration name without the ``''. The argument STRING is a explain the failure. Except for OK, which is a NULL pointer.

Inlining successful. This must be the first code.

Inlining failed for an unspecified reason.

Function has not be considered for inlining. This is the code for functions that have not been rejected for inlining yet.

Caller is compiled with optimizations disabled.

Inlining failed owing to unavailable function body.

Extern inline function that has been redefined.

Function is not inlinable.

Function is overwritable.

Function is not an inlining candidate.

Inlining failed because of various limit parameters.

Recursive inlining.

Call is unlikely.

Function is not declared as inline.

Inlining suppressed due to size optimization.

Caller and callee disagree on the arguments.

Call was originally indirect.

Ths edge represents an indirect edge with a yet-undetermined callee .

We can't inline different EH personalities together.

We can't inline if the callee can throw non-call exceptions but the caller cannot.

We can't inline because of mismatched target specific options.

We can't inline because of mismatched optimization levels.

 Signedness of an enum type is implementation defined, so cast it
 to unsigned before testing.  

Return local info for the compiled function.

struct cgraph_edge* cgraph_make_edge_direct ( )
read

Make an indirect EDGE with an unknown callee an ordinary edge leading to CALLEE. DELTA is an integer constant that is to be added to the this pointer (first parameter) to compensate for skipping a thunk adjustment.

 If we are redirecting speculative call, make it non-speculative.   
     On successful speculation just return the pre existing direct edge.   
 Get the edge out of the indirect edge list.  
 Put it into the normal callee list  
 Insert to callers list of the new callee.   
 We need to re-determine the inlining status of the edge.   
void cgraph_make_node_local ( )
static bool cgraph_make_node_local_1 ( )
static

Worker to bring NODE local.

Referenced by cgraph_function_body_availability().

void cgraph_mark_address_taken_node ( )

Likewise indicate that a node is having address taken.

Indirect inlining can figure out that all uses of the address are inlined.

 FIXME: address_taken flag is used both as a shortcut for testing whether
 IPA_REF_ADDR reference exists (and thus it should be set on node
 representing alias we take address of) and as a test whether address
 of the object was taken (and thus it should be set on node alias is
 referring to).  We should remove the first use and the remove the
 following set.   
bool cgraph_node_can_be_local_p ( )

Return true if NODE can be made local for API change. Extern inline functions and C++ COMDAT functions can be made local at the expense of possible code size growth if function is used in multiple compilation units.

static bool cgraph_node_cannot_be_local_p_1 ( struct cgraph_node node,
void *  data 
)
static

Worker for cgraph_node_can_be_local_p.

References symtab_node_base::decl, DECL_STATIC_CONSTRUCTOR, and DECL_STATIC_DESTRUCTOR.

bool cgraph_node_cannot_return ( )

Return true when NODE can not return or throw and thus it is safe to ignore its side effects for IPA analysis.

Referenced by cgraph_for_node_and_aliases().

struct cgraph_node* cgraph_node_for_asm ( )
read

Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME. Return NULL if there's no such node.

We do not want to look at inline clones.

References cgraph_edge::callee, and gcc_assert.

void cgraph_node_remove_callees ( )
static void cgraph_node_remove_callers ( struct cgraph_node node)
static

Callgraph handling code. Copyright (C) 2003-2013 Free Software Foundation, Inc. Contributed by Jan Hubicka

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 contains basic routines manipulating call graph

The call-graph is a data structure designed for intra-procedural optimization. It represents a multi-graph where nodes are functions and edges are call sites. FIXME: Only for PROP_loops, but cgraph shouldn't have to know about this.

Referenced by cgraph_node_remove_callees().

static void cgraph_node_remove_callers ( )
static

Remove all callers from the node.

It is sufficient to remove the edges from the lists of callees of the callers. The caller list of the node can be zapped with one assignment.

References cgraph_node::clone_of, cgraph_node::clones, cgraph_node::next_sibling_clone, and cgraph_node::prev_sibling_clone.

static bool cgraph_not_only_called_directly_p_1 ( )
static

Worker for cgraph_only_called_directly_p.

Referenced by cgraph_set_pure_flag_1().

bool cgraph_only_called_directly_p ( )

Return true when function NODE and all its aliases are only called directly. i.e. it is not externally visible, address was not taken and it is not used in any other non-standard way.

Referenced by cgraph_set_const_flag_1().

gimple cgraph_redirect_edge_call_stmt_to_callee ( )

If necessary, change the function declaration in the call statement associated with E so that it corresponds to the edge callee.

     If there already is an direct call (i.e. as a result of inliner's
     substitution), forget about speculating.   
     If types do not match, speculation was likely wrong. 
     The direct edge was posisbly redirected to the clone with a different
     signature.  We did not update the call statement yet, so compare it 
     with the reference that still points to the proper type.   
         We are producing the final function body and will throw away the
         callgraph edges really soon.  Reset the counts/frequencies to
         keep verifier happy in the case of roundoff errors.   
     Expand speculation into GIMPLE code.   
         Indirect edges are not both in the call site hash.
         get it updated.   
         Continue redirecting E to proper target.   
     We need to defer cleaning EH info on the new statement to
     fixup-cfg.  We may not have dominator information at this point
     and thus would end up with unreachable blocks and have no way
     to communicate that we need to run CFG cleanup then.   

References cgraph_edge::callee, cgraph_dump_file, cgraph_node::clone, cgraph_clone_info::combined_args_to_skip, and dump_bitmap().

void cgraph_redirect_edge_callee ( )

Redirect callee of E to N. The function does not update underlying call expression.

Remove from callers list of the current callee.

 Insert to callers list of the new callee.   

Referenced by clone_inlined_nodes(), known_aggs_to_agg_replacement_list(), lookup_recursive_calls(), and recursive_inlining().

void cgraph_release_function_body ( )

Release memory used to represent body of function NODE. Use this only for functions that are released before being translated to target code (i.e. RTL). Functions that are compiled to RTL and beyond are free'd in final.c via free_after_compilation().

If the node is abstract and needed, then do not clear DECL_INITIAL of its associated function function declaration because it's needed to emit debug info later.

References cgraph_node::callers, cfun, gcc_assert, and cgraph_edge::indirect_inlining_edge.

Referenced by comp_type_attributes().

void cgraph_remove_edge ( )

Remove the edge E in the cgraph.

 Call all edge removal hooks.   
   Remove from callers list of the callee.   
 Remove from callees list of the callers.   
 Put the edge onto the free list.   

Referenced by replace_locals_op().

void cgraph_remove_edge_duplication_hook ( )

Remove ENTRY from the list of hooks called on duplicating edges.

References first_cgraph_node_duplicated_hook, and cgraph_2node_hook_list::next.

void cgraph_remove_edge_removal_hook ( )

Remove ENTRY from the list of hooks called on removing edges.

void cgraph_remove_function_insertion_hook ( )

Remove ENTRY from the list of hooks called on inserted nodes.

References first_cgraph_edge_duplicated_hook, and cgraph_2edge_hook_list::next.

void cgraph_remove_node ( )

Remove the node from cgraph.

 Incremental inlining access removed nodes stored in the postorder list.
         We are removing node with clones.  This makes clones inconsistent,
         but assume they will be removed subsequently and just keep clone
         tree intact.  This can happen in unreachable function removal since
         we remove unreachable functions in random order, not by bottom-up
         walk of clone trees.   
 While all the clones are removed after being proceeded, the function
 itself is kept in the cgraph even after it is compiled.  Check whether
 we are done with this body and reclaim it proactively if this is the case.
 Clear out the node to NULL all pointers and add the node to the free
 list.   

Referenced by cgraph_create_function_alias().

void cgraph_remove_node_duplication_hook ( )

Remove ENTRY from the list of hooks called on duplicating nodes.

References cgraph_allocate_node(), cgraph_n_nodes, cgraph_node::count_materialization_scale, NODE_FREQUENCY_NORMAL, REG_BR_PROB_BASE, and SYMTAB_FUNCTION.

void cgraph_remove_node_removal_hook ( )

Remove ENTRY from the list of hooks called on removing nodes.

struct cgraph_edge* cgraph_resolve_speculation ( )
read

Speculative call EDGE turned out to be direct call to CALLE_DECL. Remove the speculative call sequence and return edge representing the call. It is up to caller to redirect the call as appropriate.

FIXME: If EDGE is inlined, we should scale up the frequencies and counts in the functions inlined through it.

Referenced by add_new_edges_to_heap().

struct cgraph_rtl_info* cgraph_rtl_info ( )
read

Return local info for the compiled function.

struct cgraph_node* cgraph_same_body_alias ( )
read

Attempt to mark ALIAS as an alias to DECL. Return alias node if successful and NULL otherwise. Same body aliases are output whenever the body of DECL is output, and cgraph_get_node (ALIAS) transparently returns cgraph_get_node (DECL).

If aliases aren't supported by the assembler, fail.

 Langhooks can create same body aliases of symbols not defined.
 Those are useless. Drop them on the floor.   
void cgraph_set_call_stmt ( struct cgraph_edge e,
gimple  new_stmt,
bool  update_speculative 
)

Change field call_stmt of edge E to NEW_STMT. If UPDATE_SPECULATIVE and E is any component of speculative edge, then update all components.

 Speculative edges has three component, update all of them
 when asked to.   
 Only direct speculative edges go to call_site_hash.   
     Constant propagation (and possibly also inlining?) can turn an
     indirect call into a direct one.   
void cgraph_set_const_flag ( )

Set TREE_READONLY on NODE's decl and on aliases of NODE if any to READONLY.

References cgraph_only_called_directly_or_aliased_p().

static bool cgraph_set_const_flag_1 ( )
static
static void cgraph_set_edge_callee ( )
static
void cgraph_set_nothrow_flag ( )

Set TREE_NOTHROW on NODE's decl and on aliases of NODE if any to NOTHROW.

static bool cgraph_set_nothrow_flag_1 ( )
static
void cgraph_set_pure_flag ( )

Set DECL_PURE_P on NODE's decl and on aliases of NODE if any to PURE.

Referenced by skip_function_for_local_pure_const().

static bool cgraph_set_pure_flag_1 ( )
static

Worker to set pure flag.

Static constructors and destructors without a side effect can be optimized out.

References cgraph_for_node_and_aliases(), cgraph_function_or_thunk_node(), cgraph_not_only_called_directly_p_1(), and gcc_assert.

void cgraph_speculative_call_info ( struct cgraph_edge e,
struct cgraph_edge *&  direct,
struct cgraph_edge *&  indirect,
struct ipa_ref *&  reference 
)

Speculative call consist of three components: 1) an indirect edge representing the original call 2) an direct edge representing the new call 3) ADDR_EXPR reference representing the speculative check. All three components are attached to single statement (the indirect call) and if one of them exists, all of them must exist.

Given speculative call edge E, return all three components.

We can take advantage of the call stmt hash.   

Speculative edge always consist of all three components - direct edge, indirect and reference.

struct cgraph_edge* cgraph_turn_edge_to_speculative ( struct cgraph_edge e,
struct cgraph_node n2,
gcov_type  direct_count,
int  direct_frequency 
)
read

Turn edge E into speculative call calling N2. Update the profile so the direct call is taken COUNT times with FREQUENCY.

At clone materialization time, the indirect call E will be expanded as:

if (call_dest == N2) n2 (); else call call_dest

At this time the function just creates the direct call, the referencd representing the if conditional and attaches them all to the orginal indirect call statement.

Return direct edge created.

static void cgraph_update_edge_in_call_site_hash ( )
inlinestatic

Add call graph edge E to call site hash of its caller.

References cgraph_edge::call_stmt.

void cgraph_update_edges_for_call_stmt ( )

Update or remove the corresponding cgraph edge if a GIMPLE_CALL OLD_STMT changed into NEW_STMT. OLD_DECL is gimple_call_fndecl of OLD_STMT before it was updated (updating can happen inplace).

static void cgraph_update_edges_for_call_stmt_node ( struct cgraph_node node,
gimple  old_stmt,
tree  old_call,
gimple  new_stmt 
)
static

Update or remove the corresponding cgraph edge if a GIMPLE_CALL OLD_STMT changed into NEW_STMT. OLD_CALL is gimple_call_fndecl of OLD_STMT if it was previously call statement. If NEW_STMT is NULL, the call has been dropped without any replacement.

 We are seeing indirect calls, then there is nothing to update.   
 See if we turned indirect call into direct call or folded call to one builtin
 into different builtin.   
         See if the edge is already there and has the correct callee.  It
         might be so because of indirect inlining has already updated
         it.  We also might've cloned and redirected the edge.   
         Otherwise remove edge and create new one; we can't simply redirect
         since function has changed, so inline plan and other information
         attached to edge is invalid.   
         We are seeing new direct call; compute profile info based on BB.   
 We only updated the call stmt; update pointer in cgraph edge..   
bool cgraph_will_be_removed_from_program_if_no_direct_calls ( )

Return true when function NODE can be expected to be removed from program when direct calls in this compilation unit are removed.

As a special case COMDAT functions are cgraph_can_remove_if_no_direct_calls_p while the are not cgraph_only_called_directly_p (it is possible they are called from other unit)

This function behaves as cgraph_only_called_directly_p because eliminating all uses of COMDAT function does not make it necessarily disappear from the program unless we are compiling whole program or we do LTO. In this case we know we win since dynamic linking will not really discard the linkonce section.

static bool clone_of_p ( )
static

Return TRUE if NODE2 is equivalent to NODE or its clone.

References error().

vec<cgraph_edge_p> collect_callers_of_node ( )

Collect all callers of NODE and its aliases that are known to lead to NODE (i.e. are not overwritable).

static bool collect_callers_of_node_1 ( )
static

Collect all callers of NODE. Worker for collect_callers_of_node.

References error().

DEBUG_FUNCTION void debug_cgraph ( void  )
DEBUG_FUNCTION void debug_cgraph_node ( )

Dump call graph node NODE to stderr.

void delete_function_version ( )
void dump_cgraph ( )

Dump the callgraph to file F.

References ipa_ref_list_referring_iterate, and symtab_node_base::ref_list.

void dump_cgraph_node ( )

Dump call graph node NODE to file F.

Referenced by compile(), and ipa_print_order().

static int edge_eq ( )
static

Return nonzero if the call_stmt of of cgraph_edge X is stmt *Y.

References cgraph_edge::call_stmt.

static hashval_t edge_hash ( )
static

Returns a hash value for X (which really is a cgraph_edge).

struct cgraph_function_version_info* get_cgraph_node_version ( )
read

Get the cgraph_function_version_info node corresponding to node.

Referenced by delete_function_version().

static bool gimple_check_call_args ( )
static

Verify if the type of the argument matches that of the function declaration. If we cannot verify this or there is a mismatch, return false.

 Calls to internal functions always match their signature.   
 Get argument types for verification.   
 Verify if the type of the argument matches that of the function
 declaration.  If we cannot verify this or there is a mismatch,
 return false.   
         We cannot distinguish a varargs function from the case
         of excess parameters, still deferring the inlining decision
         to the callee is possible.   
         If this is a varargs function defer inlining decision
         to callee.   
bool gimple_check_call_matching_types ( gimple  call_stmt,
tree  callee,
bool  args_count_match 
)

Verify if the type of the argument and lhs of CALL_STMT matches that of the function declaration CALLEE. If ARGS_COUNT_MATCH is true, the arg count needs to be the same. If we cannot verify this or there is a mismatch, return false.

struct cgraph_function_version_info* insert_new_cgraph_node_version ( )
read

Insert a new cgraph_function_version_info node into cgraph_fnver_htab corresponding to cgraph_node NODE.

Referenced by delete_function_version().

static bool nonremovable_p ( )
static

Worker for cgraph_can_remove_if_no_direct_calls_p.

Referenced by cgraph_set_nothrow_flag_1().

void record_function_versions ( )

Record that DECL1 and DECL2 are semantically identical function versions.

Chain decl2_v and decl1_v. All semantically identical versions will be chained together.

void release_function_body ( )

Helper function for cgraph_release_function_body and free_lang_data. It releases body from function DECL without having to inspect its possibly non-existent symtab node.

Struct function hangs a lot of data that would leak if we didn't removed all pointers to it.

Referenced by comp_type_attributes().

static bool used_from_object_file_p ( )
static

Worker for cgraph_can_remove_if_no_direct_calls_p.

Referenced by cgraph_set_const_flag_1().

DEBUG_FUNCTION void verify_cgraph ( void  )

Verify whole cgraph structure.

Referenced by cgraph_materialize_clone().

DEBUG_FUNCTION void verify_cgraph_node ( )

Verify cgraph nodes of given cgraph node.

Reach the trees by walking over the CFG, and note the enclosing basic-blocks in the call edges.

       No CFG available?!   
static bool verify_edge_corresponds_to_fndecl ( )
static

Verify that call graph edge E corresponds to DECL from the associated statement. Return true if the verification should fail.

We do not know if a node from a different partition is an alias or what it aliases and therefore cannot do the former_clone_of check reliably.

     IPA-CP sometimes redirect edge to clone and then back to the former
     function.  This ping-pong has to go, eventually.   
static bool verify_edge_count_and_frequency ( )
static

Verify edge E count and frequency.

FIXME: Inline-analysis sets frequency to 0 when edge is optimized out. Remove this once edges are actually removed from the function at that time.

References error().


Variable Documentation

const char* const cgraph_availability_names[]
Initial value:
{"unset", "not_available", "overwritable", "available", "local"}

Names used to print out the availability enum.

Referenced by varpool_remove_initializer().

int cgraph_edge_max_uid

Maximal uid used in cgraph edges.

Referenced by ipcp_propagate_stage().

htab_t cgraph_fnver_htab = NULL
static

Map a cgraph_node to cgraph_function_version_info using this htab. The cgraph_function_version_info has a THIS_NODE field that is the corresponding cgraph_node..

Referenced by cgraph_fnver_htab_hash().

bool cgraph_function_flags_ready = false

Set when the cgraph is fully build and the basic flags are computed.

Referenced by cgraph_variable_initializer_availability(), and varpool_remove_initializer().

bool cgraph_global_info_ready = false

Set when whole unit has been analyzed so we can access global info.

int cgraph_max_uid

Maximal uid used in cgraph nodes.

int cgraph_n_nodes

Number of nodes in existence.

Referenced by cgraph_remove_node_duplication_hook().

What state callgraph is in right now.

bool cpp_implicit_aliases_done

Did procss_same_body_aliases run?

struct cgraph_2edge_hook_list* first_cgraph_edge_duplicated_hook

List of hooks triggered when an edge is duplicated.

Referenced by cgraph_add_function_insertion_hook(), cgraph_call_function_insertion_hooks(), and cgraph_remove_function_insertion_hook().

struct cgraph_edge_hook_list* first_cgraph_edge_removal_hook

List of hooks triggered when an edge is removed.

struct cgraph_node_hook_list* first_cgraph_function_insertion_hook

List of hooks triggered when an function is inserted.

Referenced by cgraph_call_node_removal_hooks().

struct cgraph_2node_hook_list* first_cgraph_node_duplicated_hook

List of hooks triggered when a node is duplicated.

Referenced by cgraph_add_edge_duplication_hook(), cgraph_call_edge_duplication_hooks(), and cgraph_remove_edge_duplication_hook().

struct cgraph_node_hook_list* first_cgraph_node_removal_hook

List of hooks triggered when a node is removed.

struct cgraph_edge* free_edges
static

Head of a linked list of unused (freed) call graph edges. Do not this list so UIDs gets reliably recycled.

Referenced by cgraph_create_indirect_edge().

struct cgraph_node* free_nodes
static

Head of a linked list of unused (freed) call graph nodes. Do not this list so UIDs gets reliably recycled.

Referenced by cgraph_add_node_duplication_hook().

struct cgraph_function_version_info* version_info_node = NULL
static

Mark as GC root all allocated nodes.

symtab_node x_cgraph_nodes_queue

Queue of cgraph nodes scheduled to be lowered.