1/* Utilities for ipa analysis.
2   Copyright (C) 2004-2015 Free Software Foundation, Inc.
3   Contributed by Kenneth Zadeck <zadeck@naturalbridge.com>
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9Software Foundation; either version 3, or (at your option) any later
10version.
11
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15for more details.
16
17You should have received a copy of the GNU General Public License
18along 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
24struct 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  */
38void ipa_print_order (FILE*, const char *, struct cgraph_node**, int);
39int ipa_reduced_postorder (struct cgraph_node **, bool, bool,
40			  bool (*ignore_edge) (struct cgraph_edge *));
41void ipa_free_postorder_info (void);
42vec<cgraph_node *> ipa_get_nodes_in_cycle (struct cgraph_node *);
43bool ipa_edge_within_scc (struct cgraph_edge *);
44int ipa_reverse_postorder (struct cgraph_node **);
45tree get_base_var (tree);
46void ipa_merge_profiles (struct cgraph_node *dst,
47			 struct cgraph_node *src, bool preserve_body = false);
48bool recursive_call_p (tree, tree);
49
50/* In ipa-profile.c  */
51bool ipa_propagate_frequency (struct cgraph_node *node);
52
53/* In ipa-devirt.c  */
54
55struct odr_type_d;
56typedef odr_type_d *odr_type;
57void build_type_inheritance_graph (void);
58void update_type_inheritance_graph (void);
59vec <cgraph_node *>
60possible_polymorphic_call_targets (tree, HOST_WIDE_INT,
61				   ipa_polymorphic_call_context,
62				   bool *copletep = NULL,
63				   void **cache_token = NULL,
64				   bool speuclative = false);
65odr_type get_odr_type (tree, bool insert = false);
66bool possible_polymorphic_call_target_p (tree ref, gimple stmt, struct cgraph_node *n);
67void dump_possible_polymorphic_call_targets (FILE *, tree, HOST_WIDE_INT,
68					     const ipa_polymorphic_call_context &);
69bool possible_polymorphic_call_target_p (tree, HOST_WIDE_INT,
70				         const ipa_polymorphic_call_context &,
71					 struct cgraph_node *);
72tree method_class_type (const_tree);
73tree inlined_polymorphic_ctor_dtor_block_p (tree, bool);
74bool decl_maybe_in_construction_p (tree, tree, gimple, tree);
75tree vtable_pointer_value_to_binfo (const_tree);
76bool vtable_pointer_value_to_vtable (const_tree, tree *, unsigned HOST_WIDE_INT *);
77tree subbinfo_with_vtable_at_offset (tree, unsigned HOST_WIDE_INT, tree);
78void compare_virtual_tables (varpool_node *, varpool_node *);
79bool type_all_derivations_known_p (const_tree);
80bool type_known_to_have_no_deriavations_p (tree);
81bool contains_polymorphic_type_p (const_tree);
82void register_odr_type (tree);
83bool types_must_be_same_for_odr (tree, tree);
84bool types_odr_comparable (tree, tree, bool strict = false);
85cgraph_node *try_speculative_devirtualization (tree, HOST_WIDE_INT,
86					       ipa_polymorphic_call_context);
87
88/* Return vector containing possible targets of polymorphic call E.
89   If COMPLETEP is non-NULL, store true if the list is complete.
90   CACHE_TOKEN (if non-NULL) will get stored to an unique ID of entry
91   in the target cache.  If user needs to visit every target list
92   just once, it can memoize them.
93
94   Returned vector is placed into cache.  It is NOT caller's responsibility
95   to free it.  The vector can be freed on cgraph_remove_node call if
96   the particular node is a virtual function present in the cache.  */
97
98inline vec <cgraph_node *>
99possible_polymorphic_call_targets (struct cgraph_edge *e,
100				   bool *completep = NULL,
101				   void **cache_token = NULL,
102				   bool speculative = false)
103{
104  ipa_polymorphic_call_context context(e);
105
106  return possible_polymorphic_call_targets (e->indirect_info->otr_type,
107					    e->indirect_info->otr_token,
108					    context,
109					    completep, cache_token,
110					    speculative);
111}
112
113/* Same as above but taking OBJ_TYPE_REF as an parameter.  */
114
115inline vec <cgraph_node *>
116possible_polymorphic_call_targets (tree ref,
117				   gimple call,
118				   bool *completep = NULL,
119				   void **cache_token = NULL)
120{
121  ipa_polymorphic_call_context context (current_function_decl, ref, call);
122
123  return possible_polymorphic_call_targets (obj_type_ref_class (ref),
124					    tree_to_uhwi
125					      (OBJ_TYPE_REF_TOKEN (ref)),
126					    context,
127					    completep, cache_token);
128}
129
130/* Dump possible targets of a polymorphic call E into F.  */
131
132inline void
133dump_possible_polymorphic_call_targets (FILE *f, struct cgraph_edge *e)
134{
135  ipa_polymorphic_call_context context(e);
136
137  dump_possible_polymorphic_call_targets (f, e->indirect_info->otr_type,
138					  e->indirect_info->otr_token,
139					  context);
140}
141
142/* Return true if N can be possibly target of a polymorphic call of
143   E.  */
144
145inline bool
146possible_polymorphic_call_target_p (struct cgraph_edge *e,
147				    struct cgraph_node *n)
148{
149  ipa_polymorphic_call_context context(e);
150
151  return possible_polymorphic_call_target_p (e->indirect_info->otr_type,
152					     e->indirect_info->otr_token,
153					     context, n);
154}
155
156/* Return true of T is type with One Definition Rule info attached.
157   It means that either it is anonymous type or it has assembler name
158   set.  */
159
160static inline bool
161odr_type_p (const_tree t)
162{
163  if (type_in_anonymous_namespace_p (t))
164    return true;
165  /* We do not have this information when not in LTO, but we do not need
166     to care, since it is used only for type merging.  */
167  gcc_assert (in_lto_p || flag_lto);
168
169  return (TYPE_NAME (t)
170          && (DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (t))));
171}
172
173/* Return true if BINFO corresponds to a type with virtual methods.
174
175   Every type has several BINFOs.  One is the BINFO associated by the type
176   while other represents bases of derived types.  The BINFOs representing
177   bases do not have BINFO_VTABLE pointer set when this is the single
178   inheritance (because vtables are shared).  Look up the BINFO of type
179   and check presence of its vtable.  */
180
181inline bool
182polymorphic_type_binfo_p (const_tree binfo)
183{
184  /* See if BINFO's type has an virtual table associtated with it.
185     Check is defensive because of Java FE produces BINFOs
186     without BINFO_TYPE set.   */
187  return (BINFO_TYPE (binfo) && TYPE_BINFO (BINFO_TYPE (binfo))
188	  && BINFO_VTABLE (TYPE_BINFO (BINFO_TYPE (binfo))));
189}
190#endif  /* GCC_IPA_UTILS_H  */
191
192
193