GCC Middle and Back End API Reference
cgraphclones.c File Reference

Functions

struct cgraph_edgecgraph_clone_edge (struct cgraph_edge *e, struct cgraph_node *n, gimple call_stmt, unsigned stmt_uid, gcov_type count_scale, int freq_scale, bool update_original)
struct cgraph_nodecgraph_clone_node (struct cgraph_node *n, tree decl, gcov_type count, int freq, bool update_original, vec< cgraph_edge_p > redirect_callers, bool call_duplication_hook, struct cgraph_node *new_inlined_to)
tree clone_function_name ()
struct cgraph_nodecgraph_create_virtual_clone (struct cgraph_node *old_node, vec< cgraph_edge_p > redirect_callers, vec< ipa_replace_map_p, va_gc > *tree_map, bitmap args_to_skip, const char *suffix)
struct cgraph_nodecgraph_find_replacement_node ()
void cgraph_set_call_stmt_including_clones (struct cgraph_node *orig, gimple old_stmt, gimple new_stmt, bool update_speculative)
void cgraph_create_edge_including_clones (struct cgraph_node *orig, struct cgraph_node *callee, gimple old_stmt, gimple stmt, gcov_type count, int freq, cgraph_inline_failed_t reason)
bool cgraph_remove_node_and_inline_clones ()
static void update_call_expr ()
struct cgraph_nodecgraph_copy_node_for_versioning (struct cgraph_node *old_version, tree new_decl, vec< cgraph_edge_p > redirect_callers, bitmap bbs_to_copy)
struct cgraph_nodecgraph_function_versioning (struct cgraph_node *old_version_node, vec< cgraph_edge_p > redirect_callers, vec< ipa_replace_map_p, va_gc > *tree_map, bitmap args_to_skip, bool skip_return, bitmap bbs_to_copy, basic_block new_entry_block, const char *clone_name)
static void cgraph_materialize_clone ()
void cgraph_materialize_all_clones ()

Variables

static unsigned int clone_fn_id_num

Function Documentation

struct cgraph_edge* cgraph_clone_edge ( struct cgraph_edge e,
struct cgraph_node n,
gimple  call_stmt,
unsigned  stmt_uid,
gcov_type  count_scale,
int  freq_scale,
bool  update_original 
)
read
@verbatim 

Callgraph clones 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 module provide facilities for clonning functions. I.e. creating
   new functions based on existing functions with simple modifications,
   such as replacement of parameters.

   To allow whole program optimization without actual presence of function
   bodies, an additional infrastructure is provided for so-called virtual
   clones

   A virtual clone in the callgraph is a function that has no
   associated body, just a description of how to create its body based
   on a different function (which itself may be a virtual clone).

   The description of function modifications includes adjustments to
   the function's signature (which allows, for example, removing or
   adding function arguments), substitutions to perform on the
   function body, and, for inlined functions, a pointer to the
   function that it will be inlined into.

   It is also possible to redirect any edge of the callgraph from a
   function to its virtual clone.  This implies updating of the call
   site to adjust for the new function signature.

   Most of the transformations performed by inter-procedural
   optimizations can be represented via virtual clones.  For
   instance, a constant propagation pass can produce a virtual clone
   of the function which replaces one of its arguments by a
   constant.  The inliner can represent its decisions by producing a
   clone of a function whose body will be later integrated into
   a given function.

   Using virtual clones, the program can be easily updated
   during the Execute stage, solving most of pass interactions
   problems that would otherwise occur during Transform.

   Virtual clones are later materialized in the LTRANS stage and
   turned into real functions.  Passes executed after the virtual
   clone were introduced also perform their Transform stage
   on new functions, so for a pass there is no significant
   difference between operating on a real function or a virtual
   clone introduced before its Execute stage.

   Optimization passes then work on virtual clones introduced before
   their Execute stage as if they were real functions.  The
   only difference is that clones are not visible during the
   Generate Summary stage.  
   Create clone of E in the node N represented by CALL_EXPR the callgraph.  
     We do not want to ignore loop nest after frequency drops to 0.  
     Clone flags that depend on call_stmt availability manually.  

References apply_probability(), cgraph_edge::call_stmt_cannot_inline_p, cgraph_edge::callee, cgraph_edge::can_throw_external, cgraph_call_edge_duplication_hooks(), cgraph_create_edge(), cgraph_create_indirect_edge(), cgraph_get_node(), count, cgraph_edge::count, cgraph_indirect_call_info::ecf_flags, cgraph_edge::frequency, gimple_call_fndecl(), cgraph_edge::indirect_info, cgraph_edge::indirect_inlining_edge, cgraph_edge::indirect_unknown_callee, cgraph_edge::inline_failed, cgraph_edge::lto_stmt_uid, and cgraph_edge::speculative.

Referenced by update_call_expr().

struct cgraph_node* cgraph_clone_node ( struct cgraph_node n,
tree  decl,
gcov_type  count,
int  freq,
bool  update_original,
vec< cgraph_edge_p redirect_callers,
bool  call_duplication_hook,
struct cgraph_node new_inlined_to 
)
read
   Create node representing clone of N executed COUNT times.  Decrease
   the execution counts from original node too.
   The new clone will have decl set to DECL that may or may not be the same
   as decl of N.

   When UPDATE_ORIGINAL is true, the counts are subtracted from the original
   function's profile to reflect the fact that part of execution is handled
   by node.  
   When CALL_DUPLICATOIN_HOOK is true, the ipa passes are acknowledged about
   the new clone. Otherwise the caller is responsible for doing so later.

   If the new node is being inlined into another one, NEW_INLINED_TO should be
   the outline function the new one is (even indirectly) inlined to.  All hooks
   will see this in node's global.inlined_to, when invoked.  Can be NULL if the
   node is not inlined.  
         Redirect calls to the old version node to point to its new
         version.  

Referenced by clone_inlined_nodes(), and input_overwrite_node().

struct cgraph_node* cgraph_copy_node_for_versioning ( struct cgraph_node old_version,
tree  new_decl,
vec< cgraph_edge_p redirect_callers,
bitmap  bbs_to_copy 
)
read
   Create a new cgraph node which is the new version of
   OLD_VERSION node.  REDIRECT_CALLERS holds the callers
   edges which should be redirected to point to
   NEW_VERSION.  ALL the callees edges of OLD_VERSION
   are cloned to the new version node.  Return the new
   version node. 

   If non-NULL BLOCK_TO_COPY determine what basic blocks 
   was copied to prevent duplications of calls that are dead
   in the clone.  
          Redirect calls to the old version node to point to its new
          version.  
void cgraph_create_edge_including_clones ( struct cgraph_node orig,
struct cgraph_node callee,
gimple  old_stmt,
gimple  stmt,
gcov_type  count,
int  freq,
cgraph_inline_failed_t  reason 
)
   Like cgraph_create_edge walk the clone tree and update all clones sharing
   same function body.  If clones already have edge for OLD_STMT; only
   update the edge same way as cgraph_set_call_stmt_including_clones does.

   TODO: COUNT and LOOP_DEPTH should be properly distributed based on relative
   frequencies of the clones.  
           It is possible that clones already contain the edge while
           master didn't.  Either we promoted indirect call into direct
           call in the clone or we are processing clones of unreachable
           master where edges has been removed.  
struct cgraph_node* cgraph_create_virtual_clone ( struct cgraph_node old_node,
vec< cgraph_edge_p redirect_callers,
vec< ipa_replace_map_p, va_gc > *  tree_map,
bitmap  args_to_skip,
const char *  suffix 
)
read
   Create callgraph node clone with new declaration.  The actual body will
   be copied later at compilation stage.

   TODO: after merging in ipa-sra use function call notes instead of args_to_skip
   bitmap interface.
     Make a new FUNCTION_DECL tree node 
     These pointers represent function body and will be populated only when clone
     is materialized.  
     We can not do DECL_RESULT (new_decl) = NULL; here because of LTO partitioning
     sometimes storing only clone decl instead of original.  
     Generate a new name for the new version. 
     Update the properties.
     Make clone visible only within this translation unit.  Make sure
     that is not weak also.
     ??? We cannot use COMDAT linkage because there is no
     ABI support for this.  
     Clones of global symbols or symbols with unique names are unique.  
struct cgraph_node* cgraph_find_replacement_node ( )
read
   NODE is being removed from symbol table; see if its entry can be replaced by
   other inline clone.  
     If there is inline clone of the node being removed, we need
     to put it into the position of removed node and reorganize all
     other clones to be based on it.  
         Unlink inline clone from the list of clones of removed node.  
         Copy clone info.  
         Now place it into clone tree at same level at NODE.  
         Merge the clone list.  
         Update clone_of pointers.  

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

struct cgraph_node* cgraph_function_versioning ( struct cgraph_node old_version_node,
vec< cgraph_edge_p redirect_callers,
vec< ipa_replace_map_p, va_gc > *  tree_map,
bitmap  args_to_skip,
bool  skip_return,
bitmap  bbs_to_copy,
basic_block  new_entry_block,
const char *  clone_name 
)
read
   Perform function versioning.
   Function versioning includes copying of the tree and
   a callgraph update (creating a new cgraph node and updating
   its callees and callers).

   REDIRECT_CALLERS varray includes the edges to be redirected
   to the new version.

   TREE_MAP is a mapping of tree nodes we want to replace with
   new ones (according to results of prior analysis).
   OLD_VERSION_NODE is the node that is versioned.

   If non-NULL ARGS_TO_SKIP determine function parameters to remove
   from new version.
   If SKIP_RETURN is true, the new version will return void.
   If non-NULL BLOCK_TO_COPY determine what basic blocks to copy.
   If non_NULL NEW_ENTRY determine new entry BB of the clone.

   Return the new version's cgraph node.  
     Make a new FUNCTION_DECL tree node for the new version. 
     Generate a new name for the new version. 
     When the old decl was a con-/destructor make sure the clone isn't.  
     Create the new version's call-graph node.
     and update the edges of the new node. 
     Copy the OLD_VERSION_NODE function tree to the new version.  
     Update the new version's properties.
     Make The new version visible only within this translation unit.  Make sure
     that is not weak also.
     ??? We cannot use COMDAT linkage because there is no
     ABI support for this.  
     Clones of global symbols or symbols with unique names are unique.  
     Update the call_expr on the edges to call the new version node. 
void cgraph_materialize_all_clones ( void  )
   Once all functions from compilation unit are in memory, produce all clones
   and update all calls.  We might also do this on demand if we don't want to
   bring all functions to memory prior compilation, but current WHOPR
   implementation does that and it is is bit easier to keep everything right in
   this order.  
     We can also do topological order, but number of iterations should be
     bounded by number of IPA passes since single IPA pass is probably not
     going to create clones of clones it created itself.  
static void cgraph_materialize_clone ( )
static
   Given virtual clone, turn it into actual clone.  
     Copy the OLD_VERSION_NODE function tree to the new version.  
     Function is no longer clone.  

References cgraph_dump_file, cgraph_get_body(), cgraph_node_name(), cgraph_node::clone, cgraph_node::clone_of, symtab_node_base::decl, gimple_has_body_p(), ipa_replace_map::old_tree, print_generic_expr(), cgraph_clone_info::tree_map, vec_safe_length(), and verify_cgraph().

bool cgraph_remove_node_and_inline_clones ( )
   Remove the node from cgraph and all inline clones inlined into it.
   Skip however removal of FORBIDDEN_NODE and return true if it needs to be
   removed.  This allows to call the function from outer loop walking clone
   tree.  
void cgraph_set_call_stmt_including_clones ( struct cgraph_node orig,
gimple  old_stmt,
gimple  new_stmt,
bool  update_speculative 
)
   Like cgraph_set_call_stmt but walk the clone tree and update all
   clones sharing the same function body.  
   When WHOLE_SPECULATIVE_EDGES is true, all three components of
   speculative edge gets updated.  Otherwise we update only direct
   call.  
               If UPDATE_SPECULATIVE is false, it means that we are turning
               speculative call into a real code sequence.  Update the
               callgraph edges.  
tree clone_function_name ( )
static void update_call_expr ( )
static
   The edges representing the callers of the NEW_VERSION node were
   fixed by cgraph_function_versioning (), now the call_expr in their
   respective tree code should be updated to call the NEW_VERSION.  
     Update the call expr on the edges to call the new version.  

References symtab_node_base::analyzed, bitmap_bit_p(), cgraph_edge::call_stmt, cgraph_node::callees, cgraph_clone_edge(), cgraph_create_node(), cgraph_node::count, symtab_node_base::definition, symtab_node_base::externally_visible, cgraph_node::global, cgraph_node::indirect_calls, cgraph_local_info::local, cgraph_node::local, cgraph_edge::lto_stmt_uid, cgraph_edge::next_callee, and cgraph_node::rtl.


Variable Documentation

unsigned int clone_fn_id_num
static
   Return a new assembler name for a clone of DECL with SUFFIX.