LCOV - code coverage report
Current view: top level - gcc - ipa-utils.h (source / functions) Hit Total Coverage
Test: gcc.info Lines: 49 49 100.0 %
Date: 2020-04-04 11:58:09 Functions: 9 9 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* Utilities for ipa analysis.
       2                 :            :    Copyright (C) 2004-2020 Free Software Foundation, Inc.
       3                 :            :    Contributed by Kenneth Zadeck <zadeck@naturalbridge.com>
       4                 :            : 
       5                 :            : This file is part of GCC.
       6                 :            : 
       7                 :            : GCC is free software; you can redistribute it and/or modify it under
       8                 :            : the terms of the GNU General Public License as published by the Free
       9                 :            : Software Foundation; either version 3, or (at your option) any later
      10                 :            : version.
      11                 :            : 
      12                 :            : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      13                 :            : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      14                 :            : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      15                 :            : for more details.
      16                 :            : 
      17                 :            : You should have received a copy of the GNU General Public License
      18                 :            : along with GCC; see the file COPYING3.  If not see
      19                 :            : <http://www.gnu.org/licenses/>.  */
      20                 :            : 
      21                 :            : #ifndef GCC_IPA_UTILS_H
      22                 :            : #define GCC_IPA_UTILS_H
      23                 :            : 
      24                 :            : struct ipa_dfs_info {
      25                 :            :   int dfn_number;
      26                 :            :   int low_link;
      27                 :            :   /* This field will have the samy value for any two nodes in the same strongly
      28                 :            :      connected component.  */
      29                 :            :   int scc_no;
      30                 :            :   bool new_node;
      31                 :            :   bool on_stack;
      32                 :            :   struct cgraph_node* next_cycle;
      33                 :            :   PTR aux;
      34                 :            : };
      35                 :            : 
      36                 :            : 
      37                 :            : /* In ipa-utils.c  */
      38                 :            : void ipa_print_order (FILE*, const char *, struct cgraph_node**, int);
      39                 :            : int ipa_reduced_postorder (struct cgraph_node **, bool,
      40                 :            :                           bool (*ignore_edge) (struct cgraph_edge *));
      41                 :            : void ipa_free_postorder_info (void);
      42                 :            : vec<cgraph_node *> ipa_get_nodes_in_cycle (struct cgraph_node *);
      43                 :            : bool ipa_edge_within_scc (struct cgraph_edge *);
      44                 :            : int ipa_reverse_postorder (struct cgraph_node **);
      45                 :            : tree get_base_var (tree);
      46                 :            : void ipa_merge_profiles (struct cgraph_node *dst,
      47                 :            :                          struct cgraph_node *src, bool preserve_body = false);
      48                 :            : bool recursive_call_p (tree, tree);
      49                 :            : 
      50                 :            : /* In ipa-profile.c  */
      51                 :            : bool ipa_propagate_frequency (struct cgraph_node *node);
      52                 :            : 
      53                 :            : /* In ipa-devirt.c  */
      54                 :            : 
      55                 :            : struct odr_type_d;
      56                 :            : typedef odr_type_d *odr_type;
      57                 :            : extern bool thunk_expansion;
      58                 :            : void build_type_inheritance_graph (void);
      59                 :            : void rebuild_type_inheritance_graph (void);
      60                 :            : void update_type_inheritance_graph (void);
      61                 :            : vec <cgraph_node *>
      62                 :            : possible_polymorphic_call_targets (tree, HOST_WIDE_INT,
      63                 :            :                                    ipa_polymorphic_call_context,
      64                 :            :                                    bool *copletep = NULL,
      65                 :            :                                    void **cache_token = NULL,
      66                 :            :                                    bool speuclative = false);
      67                 :            : odr_type get_odr_type (tree, bool insert = false);
      68                 :            : bool odr_type_p (const_tree);
      69                 :            : bool possible_polymorphic_call_target_p (tree ref, gimple *stmt, struct cgraph_node *n);
      70                 :            : void dump_possible_polymorphic_call_targets (FILE *, tree, HOST_WIDE_INT,
      71                 :            :                                              const ipa_polymorphic_call_context &,
      72                 :            :                                              bool verbose = true);
      73                 :            : bool possible_polymorphic_call_target_p (tree, HOST_WIDE_INT,
      74                 :            :                                          const ipa_polymorphic_call_context &,
      75                 :            :                                          struct cgraph_node *);
      76                 :            : tree polymorphic_ctor_dtor_p (tree, bool);
      77                 :            : tree inlined_polymorphic_ctor_dtor_block_p (tree, bool);
      78                 :            : bool decl_maybe_in_construction_p (tree, tree, gimple *, tree);
      79                 :            : tree vtable_pointer_value_to_binfo (const_tree);
      80                 :            : bool vtable_pointer_value_to_vtable (const_tree, tree *, unsigned HOST_WIDE_INT *);
      81                 :            : tree subbinfo_with_vtable_at_offset (tree, unsigned HOST_WIDE_INT, tree);
      82                 :            : void compare_virtual_tables (varpool_node *, varpool_node *);
      83                 :            : bool type_all_derivations_known_p (const_tree);
      84                 :            : bool type_known_to_have_no_derivations_p (tree);
      85                 :            : bool contains_polymorphic_type_p (const_tree);
      86                 :            : void register_odr_type (tree);
      87                 :            : bool types_must_be_same_for_odr (tree, tree);
      88                 :            : bool types_odr_comparable (tree, tree);
      89                 :            : cgraph_node *try_speculative_devirtualization (tree, HOST_WIDE_INT,
      90                 :            :                                                ipa_polymorphic_call_context);
      91                 :            : void warn_types_mismatch (tree t1, tree t2, location_t loc1 = UNKNOWN_LOCATION,
      92                 :            :                           location_t loc2 = UNKNOWN_LOCATION);
      93                 :            : bool odr_or_derived_type_p (const_tree t);
      94                 :            : bool odr_types_equivalent_p (tree type1, tree type2);
      95                 :            : bool odr_type_violation_reported_p (tree type);
      96                 :            : tree prevailing_odr_type (tree type);
      97                 :            : void enable_odr_based_tbaa (tree type);
      98                 :            : bool odr_based_tbaa_p (const_tree type);
      99                 :            : void set_type_canonical_for_odr_type (tree type, tree canonical);
     100                 :            : 
     101                 :            : /* Return vector containing possible targets of polymorphic call E.
     102                 :            :    If COMPLETEP is non-NULL, store true if the list is complete. 
     103                 :            :    CACHE_TOKEN (if non-NULL) will get stored to an unique ID of entry
     104                 :            :    in the target cache.  If user needs to visit every target list
     105                 :            :    just once, it can memoize them.
     106                 :            : 
     107                 :            :    Returned vector is placed into cache.  It is NOT caller's responsibility
     108                 :            :    to free it.  The vector can be freed on cgraph_remove_node call if
     109                 :            :    the particular node is a virtual function present in the cache.  */
     110                 :            : 
     111                 :            : inline vec <cgraph_node *>
     112                 :     161272 : possible_polymorphic_call_targets (struct cgraph_edge *e,
     113                 :            :                                    bool *completep = NULL,
     114                 :            :                                    void **cache_token = NULL,
     115                 :            :                                    bool speculative = false)
     116                 :            : {
     117                 :     161272 :   ipa_polymorphic_call_context context(e);
     118                 :            : 
     119                 :     161272 :   return possible_polymorphic_call_targets (e->indirect_info->otr_type,
     120                 :     161272 :                                             e->indirect_info->otr_token,
     121                 :            :                                             context,
     122                 :            :                                             completep, cache_token,
     123                 :     161272 :                                             speculative);
     124                 :            : }
     125                 :            : 
     126                 :            : /* Same as above but taking OBJ_TYPE_REF as an parameter.  */
     127                 :            : 
     128                 :            : inline vec <cgraph_node *>
     129                 :     338302 : possible_polymorphic_call_targets (tree ref,
     130                 :            :                                    gimple *call,
     131                 :            :                                    bool *completep = NULL,
     132                 :            :                                    void **cache_token = NULL)
     133                 :            : {
     134                 :     338302 :   ipa_polymorphic_call_context context (current_function_decl, ref, call);
     135                 :            : 
     136                 :     338302 :   return possible_polymorphic_call_targets (obj_type_ref_class (ref),
     137                 :            :                                             tree_to_uhwi
     138                 :     338302 :                                               (OBJ_TYPE_REF_TOKEN (ref)),
     139                 :            :                                             context,
     140                 :     338302 :                                             completep, cache_token);
     141                 :            : }
     142                 :            : 
     143                 :            : /* Dump possible targets of a polymorphic call E into F.  */
     144                 :            : 
     145                 :            : inline void
     146                 :         70 : dump_possible_polymorphic_call_targets (FILE *f, struct cgraph_edge *e,
     147                 :            :                                         bool verbose = true)
     148                 :            : {
     149                 :         70 :   ipa_polymorphic_call_context context(e);
     150                 :            : 
     151                 :         70 :   dump_possible_polymorphic_call_targets (f, e->indirect_info->otr_type,
     152                 :         70 :                                           e->indirect_info->otr_token,
     153                 :            :                                           context, verbose);
     154                 :         70 : }
     155                 :            : 
     156                 :            : /* Return true if N can be possibly target of a polymorphic call of
     157                 :            :    E.  */
     158                 :            : 
     159                 :            : inline bool
     160                 :      12273 : possible_polymorphic_call_target_p (struct cgraph_edge *e,
     161                 :            :                                     struct cgraph_node *n)
     162                 :            : {
     163                 :      12273 :   ipa_polymorphic_call_context context(e);
     164                 :            : 
     165                 :      12273 :   return possible_polymorphic_call_target_p (e->indirect_info->otr_type,
     166                 :      12273 :                                              e->indirect_info->otr_token,
     167                 :      12273 :                                              context, n);
     168                 :            : }
     169                 :            : 
     170                 :            : /* Return true if BINFO corresponds to a type with virtual methods. 
     171                 :            : 
     172                 :            :    Every type has several BINFOs.  One is the BINFO associated by the type
     173                 :            :    while other represents bases of derived types.  The BINFOs representing
     174                 :            :    bases do not have BINFO_VTABLE pointer set when this is the single
     175                 :            :    inheritance (because vtables are shared).  Look up the BINFO of type
     176                 :            :    and check presence of its vtable.  */
     177                 :            : 
     178                 :            : inline bool
     179                 :    7695080 : polymorphic_type_binfo_p (const_tree binfo)
     180                 :            : {
     181                 :   15801050 :   return (BINFO_TYPE (binfo) && TYPE_BINFO (BINFO_TYPE (binfo))
     182                 :   15799260 :           && BINFO_VTABLE (TYPE_BINFO (BINFO_TYPE (binfo))));
     183                 :            : }
     184                 :            : 
     185                 :            : /* Return true if T is a type with linkage defined.  */
     186                 :            : 
     187                 :            : inline bool
     188                 :    7876245 : type_with_linkage_p (const_tree t)
     189                 :            : {
     190                 :    7876245 :   gcc_checking_assert (TYPE_MAIN_VARIANT (t) == t);
     191                 :    7876245 :   if (!TYPE_NAME (t) || TREE_CODE (TYPE_NAME (t)) != TYPE_DECL)
     192                 :            :     return false;
     193                 :            : 
     194                 :            :   /* After free_lang_data was run we can recongize
     195                 :            :      types with linkage by presence of mangled name.  */
     196                 :    7667096 :   if (DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (t)))
     197                 :            :     return true;
     198                 :            : 
     199                 :    5514384 :   if (in_lto_p)
     200                 :            :     return false;
     201                 :            : 
     202                 :            :   /* We used to check for TYPE_STUB_DECL but that is set to NULL for forward
     203                 :            :      declarations.  */
     204                 :            : 
     205                 :    5505555 :   if (!RECORD_OR_UNION_TYPE_P (t) && TREE_CODE (t) != ENUMERAL_TYPE)
     206                 :            :     return false;
     207                 :            : 
     208                 :            :   /* Builtin types do not define linkage, their TYPE_CONTEXT is NULL.  */
     209                 :    5324531 :   if (!TYPE_CONTEXT (t))
     210                 :            :     return false;
     211                 :            : 
     212                 :   10641339 :   gcc_checking_assert (TREE_CODE (t) == ENUMERAL_TYPE || TYPE_CXX_ODR_P (t));
     213                 :            : 
     214                 :            :   return true;
     215                 :            : }
     216                 :            : 
     217                 :            : /* Return true if T is in anonymous namespace.
     218                 :            :    This works only on those C++ types with linkage defined.  */
     219                 :            : 
     220                 :            : inline bool
     221                 :    3949715 : type_in_anonymous_namespace_p (const_tree t)
     222                 :            : {
     223                 :    3949715 :   gcc_checking_assert (type_with_linkage_p (t));
     224                 :            : 
     225                 :            :   /* free_lang_data clears TYPE_STUB_DECL but sets assembler name to
     226                 :            :      "<anon>"  */
     227                 :    3949715 :   if (DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (t)))
     228                 :    1078631 :     return !strcmp ("<anon>",
     229                 :    1078631 :                     IDENTIFIER_POINTER
     230                 :    1078631 :                     (DECL_ASSEMBLER_NAME (TYPE_NAME (t))));
     231                 :    2871086 :   else if (!TYPE_STUB_DECL (t))
     232                 :            :     return false;
     233                 :            :   else
     234                 :    2871086 :     return !TREE_PUBLIC (TYPE_STUB_DECL (t));
     235                 :            : }
     236                 :            : 
     237                 :            : /* Return true of T is type with One Definition Rule info attached. 
     238                 :            :    It means that either it is anonymous type or it has assembler name
     239                 :            :    set.  */
     240                 :            : 
     241                 :            : inline bool
     242                 :    1499491 : odr_type_p (const_tree t)
     243                 :            : {
     244                 :            :   /* We do not have this information when not in LTO, but we do not need
     245                 :            :      to care, since it is used only for type merging.  */
     246                 :    1499491 :   gcc_checking_assert (in_lto_p || flag_lto);
     247                 :    2084564 :   return TYPE_NAME (t) && TREE_CODE (TYPE_NAME (t)) == TYPE_DECL
     248                 :    1991783 :          && DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (t));
     249                 :            : }
     250                 :            : 
     251                 :            : /* If TYPE has mangled ODR name, return it.  Otherwise return NULL.
     252                 :            :    The function works only when free_lang_data is run.  */
     253                 :            : 
     254                 :            : inline const char *
     255                 :         66 : get_odr_name_for_type (tree type)
     256                 :            : {
     257                 :         66 :   tree type_name = TYPE_NAME (type);
     258                 :         66 :   if (type_name == NULL_TREE
     259                 :         52 :       || TREE_CODE (type_name) != TYPE_DECL
     260                 :        116 :       || !DECL_ASSEMBLER_NAME_SET_P (type_name))
     261                 :            :     return NULL;
     262                 :            : 
     263                 :         38 :   return IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (type_name));
     264                 :            : }
     265                 :            : 
     266                 :            : #endif  /* GCC_IPA_UTILS_H  */

Generated by: LCOV version 1.0

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto --enable-host-shared. GCC test suite is run with the built compiler.