GCC Middle and Back End API Reference
ipa-devirt.c File Reference

Data Structures

struct  odr_type_d
struct  odr_hasher
struct  polymorphic_call_target_d
struct  polymorphic_call_target_hasher

Typedefs

typedef hash_table< odr_hasherodr_hash_type
typedef hash_table
< polymorphic_call_target_hasher
polymorphic_call_target_hash_type

Functions

static bool polymorphic_type_binfo_p ()
hashval_t hash_type_name ()
odr_type get_odr_type ()
static void dump_odr_type ()
static void dump_type_inheritance_graph ()
tree method_class_type ()
void build_type_inheritance_graph ()
static void maybe_record_node (vec< cgraph_node * > &nodes, tree target, pointer_set_t *inserted)
static void record_binfo (vec< cgraph_node * > &nodes, tree binfo, tree otr_type, tree type_binfo, HOST_WIDE_INT otr_token, pointer_set_t *inserted, pointer_set_t *matched_vtables)
static void possible_polymorphic_call_targets_1 (vec< cgraph_node * > &nodes, pointer_set_t *inserted, pointer_set_t *matched_vtables, tree otr_type, odr_type type, HOST_WIDE_INT otr_token)
static void free_polymorphic_call_targets_hash ()
static void devirt_node_removal_hook ()
vec< cgraph_node * > possible_polymorphic_call_targets (tree otr_type, HOST_WIDE_INT otr_token, bool *finalp, void **cache_token)
void dump_possible_polymorphic_call_targets (FILE *f, tree otr_type, HOST_WIDE_INT otr_token)
bool possible_polymorphic_call_target_p (tree otr_type, HOST_WIDE_INT otr_token, struct cgraph_node *n)
void update_type_inheritance_graph ()

Variables

static pointer_set_tcached_polymorphic_call_targets
static odr_hash_type odr_hash
static vec< odr_type, va_gc > * odr_types_ptr
static
polymorphic_call_target_hash_type 
polymorphic_call_target_hash

Typedef Documentation

ODR type hash used to lookup ODR type based on tree type node.   
Polymorphic call target query cache.   

Function Documentation

static void devirt_node_removal_hook ( )
static
When virtual function is removed, we may need to flush the cache.   

References free_polymorphic_call_targets_hash(), and pointer_set_contains().

Referenced by possible_polymorphic_call_targets().

static void dump_odr_type ( )
static
Dump ODR type T and all its derrived type.  INDENT specify indentation for
   recusive printing.   

References odr_type_d::anonymous_namespace, odr_type_d::bases, odr_type_d::derived_types, odr_type_d::id, indent, print_generic_expr(), and odr_type_d::type.

Referenced by dump_type_inheritance_graph().

void dump_possible_polymorphic_call_targets ( FILE *  f,
tree  otr_type,
HOST_WIDE_INT  otr_token 
)
static void dump_type_inheritance_graph ( )
static
Dump the type inheritance graph.   

References dump_odr_type().

Referenced by build_type_inheritance_graph().

static void free_polymorphic_call_targets_hash ( )
static
hashval_t hash_type_name ( )
Produce hash based on type name.   

References type_in_anonymous_namespace_p().

Referenced by get_odr_type(), and odr_hasher::hash().

static void maybe_record_node ( vec< cgraph_node * > &  nodes,
tree  target,
pointer_set_t inserted 
)
static
If TARGET has associated node, record it in the NODES array.   

References cgraph_get_node(), pointer_set_insert(), and symtab_real_symbol_p().

Referenced by possible_polymorphic_call_targets(), and record_binfo().

tree method_class_type ( )
Given method type T, return type of class it belongs to.
   Lookup this pointer and get its type.     

Referenced by analyze_functions(), build_type_inheritance_graph(), and update_type_inheritance_graph().

static bool polymorphic_type_binfo_p ( )
inlinestatic
Return true if BINFO corresponds to a type with virtual methods. 

   Every type has several BINFOs.  One is the BINFO associated by the type
   while other represents bases of derived types.  The BINFOs representing
   bases do not have BINFO_VTABLE pointer set when this is the single
   inheritance (because vtables are shared).  Look up the BINFO of type
   and check presence of its vtable.   

Referenced by get_odr_type(), and record_binfo().

bool possible_polymorphic_call_target_p ( tree  otr_type,
HOST_WIDE_INT  otr_token,
struct cgraph_node n 
)
Return true if N can be possibly target of a polymorphic call of
   OTR_TYPE/OTR_TOKEN.   

References hash_table< Descriptor, Allocator >::is_created(), odr_hash, and possible_polymorphic_call_targets().

Referenced by possible_polymorphic_call_target_p().

vec<cgraph_node *> possible_polymorphic_call_targets ( tree  otr_type,
HOST_WIDE_INT  otr_token,
bool *  finalp,
void **  cache_token 
)
Return vector containing possible targets of polymorphic call of type
   OTR_TYPE caling method OTR_TOKEN with OFFSET.  If FINALp is non-NULL,
   store true if the list is complette. 
   CACHE_TOKEN (if non-NULL) will get stored to an unique ID of entry
   in the target cache.  If user needs to visit every target list
   just once, it can memoize them.

   Returned vector is placed into cache.  It is NOT caller's responsibility
   to free it.  The vector can be freed on cgraph_remove_node call if
   the particular node is a virtual function present in the cache.   

References odr_type_d::anonymous_namespace, cgraph_add_node_removal_hook(), hash_table< Descriptor, Allocator >::create(), odr_type_d::derived_types, devirt_node_removal_hook(), hash_table< Descriptor, Allocator >::find_slot(), get_odr_type(), gimple_get_virt_method_for_binfo(), inserted, maybe_record_node(), node_removal_hook_holder, polymorphic_call_target_d::otr_token, pointer_set_create(), pointer_set_destroy(), pointer_set_insert(), polymorphic_call_target_hash, possible_polymorphic_call_targets_1(), polymorphic_call_target_d::targets, timevar_pop(), timevar_push(), odr_type_d::type, type(), polymorphic_call_target_d::type, and vNULL.

Referenced by analyze_functions(), dump_possible_polymorphic_call_targets(), possible_polymorphic_call_target_p(), and possible_polymorphic_call_targets().

static void possible_polymorphic_call_targets_1 ( vec< cgraph_node * > &  nodes,
pointer_set_t inserted,
pointer_set_t matched_vtables,
tree  otr_type,
odr_type  type,
HOST_WIDE_INT  otr_token 
)
static
Lookup virtual methods matching OTR_TYPE (with OFFSET and OTR_TOKEN)
   of TYPE, insert them to NODES, recurse into derived nodes. 
   INSERTED is used to avoid duplicate insertions of methods into NODES.
   MATCHED_VTABLES are used to avoid duplicate walking vtables.   

References odr_type_d::derived_types, record_binfo(), and odr_type_d::type.

Referenced by possible_polymorphic_call_targets().

static void record_binfo ( vec< cgraph_node * > &  nodes,
tree  binfo,
tree  otr_type,
tree  type_binfo,
HOST_WIDE_INT  otr_token,
pointer_set_t inserted,
pointer_set_t matched_vtables 
)
static
See if BINFO's type match OTR_TYPE.  If so, lookup method
   in vtable of TYPE_BINFO and insert method to NODES array.
   Otherwise recurse to base BINFOs.
   This match what get_binfo_at_offset does, but with offset
   being unknown.

   TYPE_BINFO is binfo holding an virtual table matching
   BINFO's type.  In the case of single inheritance, this
   is binfo of BINFO's type ancestor (vtable is shared),
   otherwise it is binfo of BINFO's type.

   MATCHED_VTABLES tracks virtual tables we already did lookup
   for virtual function in.

References gimple_get_virt_method_for_binfo(), inserted, maybe_record_node(), pointer_set_insert(), polymorphic_type_binfo_p(), and types_same_for_odr().

Referenced by possible_polymorphic_call_targets_1().

void update_type_inheritance_graph ( void  )

Variable Documentation

pointer_set_t* cached_polymorphic_call_targets
static
@verbatim Basic IPA utilities for type inheritance graph construction and

devirtualization. Copyright (C) 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/.

Brief vocalburary:
     ODR = One Definition Rule
        In short, the ODR states that:
        1 In any translation unit, a template, type, function, or object can
          have no more than one definition. Some of these can have any number
          of declarations. A definition provides an instance.
        2 In the entire program, an object or non-inline function cannot have
          more than one definition; if an object or function is used, it must
          have exactly one definition. You can declare an object or function
          that is never used, in which case you don't have to provide
          a definition. In no event can there be more than one definition.
        3 Some things, like types, templates, and extern inline functions, can
          be defined in more than one translation unit. For a given entity,
          each definition must be the same. Non-extern objects and functions
          in different translation units are different entities, even if their
          names and types are the same.

     OTR = OBJ_TYPE_REF
       This is the Gimple representation of type information of a polymorphic call.
       It contains two parameters:
         otr_type is a type of class whose method is called.
         otr_token is the index into virtual table where address is taken.

     BINFO
       This is the type inheritance information attached to each tree
       RECORD_TYPE by the C++ frotend.  It provides information about base
       types and virtual tables.

       BINFO is linked to the RECORD_TYPE by TYPE_BINFO.
       BINFO also links to its type by BINFO_TYPE and to the virtual table by
       BINFO_VTABLE.

       Base types of a given type are enumerated by BINFO_BASE_BINFO
       vector.  Members of this vectors are not BINFOs associated
       with a base type.  Rather they are new copies of BINFOs
       (base BINFOs). Their virtual tables may differ from
       virtual table of the base type.  Also BINFO_OFFSET specifies
       offset of the base within the type.

       In the case of single inheritance, the virtual table is shared
       and BINFO_VTABLE of base BINFO is NULL.  In the case of multiple
       inheritance the individual virtual tables are pointer to by
       BINFO_VTABLE of base binfos (that differs of BINFO_VTABLE of 
       binfo associated to the base type).

       BINFO lookup for a given base type and offset can be done by
       get_binfo_at_offset.  It returns proper BINFO whose virtual table
       can be used for lookup of virtual methods associated with the
       base type.

     token
       This is an index of virtual method in virtual table associated
       to the type defining it. Token can be looked up from OBJ_TYPE_REF
       or from DECL_VINDEX of a given virtual table.

     polymorphic (indirect) call
       This is callgraph represention of virtual method call.  Every
       polymorphic call contains otr_type and otr_token taken from
       original OBJ_TYPE_REF at callgraph construction time.

   What we do here:

   build_type_inheritance_graph triggers a construction of the type inheritance
   graph.

     We reconstruct it based on types of methods we see in the unit.
     This means that the graph is not complete. Types with no methods are not
     inserted into the graph.  Also types without virtual methods are not
     represented at all, though it may be easy to add this.
  
     The inheritance graph is represented as follows:

       Vertices are structures odr_type.  Every odr_type may correspond
       to one or more tree type nodes that are equivalent by ODR rule.
       (the multiple type nodes appear only with linktime optimization)

       Edges are represented by odr_type->base and odr_type->derived_types.
       At the moment we do not track offsets of types for multiple inheritance.
       Adding this is easy.

  possible_polymorphic_call_targets returns, given an parameters found in
  indirect polymorphic edge all possible polymorphic call targets of the call.
Pointer set of all call targets appearing in the cache.   
vec<odr_type, va_gc>* odr_types_ptr
static
ODR types are also stored into ODR_TYPE vector to allow consistent
   walking.  Bases appear before derived types.  Vector is garbage collected
   so we won't end up visiting empty types.