]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/ipa-utils.h
PR c++/87554 - ICE with extern template and reference member.
[thirdparty/gcc.git] / gcc / ipa-utils.h
1 /* Utilities for ipa analysis.
2 Copyright (C) 2004-2019 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 void build_type_inheritance_graph (void);
58 void rebuild_type_inheritance_graph (void);
59 void update_type_inheritance_graph (void);
60 vec <cgraph_node *>
61 possible_polymorphic_call_targets (tree, HOST_WIDE_INT,
62 ipa_polymorphic_call_context,
63 bool *copletep = NULL,
64 void **cache_token = NULL,
65 bool speuclative = false);
66 odr_type get_odr_type (tree, bool insert = false);
67 bool odr_type_p (const_tree);
68 bool possible_polymorphic_call_target_p (tree ref, gimple *stmt, struct cgraph_node *n);
69 void dump_possible_polymorphic_call_targets (FILE *, tree, HOST_WIDE_INT,
70 const ipa_polymorphic_call_context &,
71 bool verbose = true);
72 bool possible_polymorphic_call_target_p (tree, HOST_WIDE_INT,
73 const ipa_polymorphic_call_context &,
74 struct cgraph_node *);
75 tree polymorphic_ctor_dtor_p (tree, bool);
76 tree inlined_polymorphic_ctor_dtor_block_p (tree, bool);
77 bool decl_maybe_in_construction_p (tree, tree, gimple *, tree);
78 tree vtable_pointer_value_to_binfo (const_tree);
79 bool vtable_pointer_value_to_vtable (const_tree, tree *, unsigned HOST_WIDE_INT *);
80 tree subbinfo_with_vtable_at_offset (tree, unsigned HOST_WIDE_INT, tree);
81 void compare_virtual_tables (varpool_node *, varpool_node *);
82 bool type_all_derivations_known_p (const_tree);
83 bool type_known_to_have_no_derivations_p (tree);
84 bool contains_polymorphic_type_p (const_tree);
85 void register_odr_type (tree);
86 bool types_must_be_same_for_odr (tree, tree);
87 bool types_odr_comparable (tree, tree);
88 cgraph_node *try_speculative_devirtualization (tree, HOST_WIDE_INT,
89 ipa_polymorphic_call_context);
90 void warn_types_mismatch (tree t1, tree t2, location_t loc1 = UNKNOWN_LOCATION,
91 location_t loc2 = UNKNOWN_LOCATION);
92 bool odr_or_derived_type_p (const_tree t);
93 bool odr_types_equivalent_p (tree type1, tree type2);
94 bool odr_type_violation_reported_p (tree type);
95
96 /* Return vector containing possible targets of polymorphic call E.
97 If COMPLETEP is non-NULL, store true if the list is complete.
98 CACHE_TOKEN (if non-NULL) will get stored to an unique ID of entry
99 in the target cache. If user needs to visit every target list
100 just once, it can memoize them.
101
102 Returned vector is placed into cache. It is NOT caller's responsibility
103 to free it. The vector can be freed on cgraph_remove_node call if
104 the particular node is a virtual function present in the cache. */
105
106 inline vec <cgraph_node *>
107 possible_polymorphic_call_targets (struct cgraph_edge *e,
108 bool *completep = NULL,
109 void **cache_token = NULL,
110 bool speculative = false)
111 {
112 ipa_polymorphic_call_context context(e);
113
114 return possible_polymorphic_call_targets (e->indirect_info->otr_type,
115 e->indirect_info->otr_token,
116 context,
117 completep, cache_token,
118 speculative);
119 }
120
121 /* Same as above but taking OBJ_TYPE_REF as an parameter. */
122
123 inline vec <cgraph_node *>
124 possible_polymorphic_call_targets (tree ref,
125 gimple *call,
126 bool *completep = NULL,
127 void **cache_token = NULL)
128 {
129 ipa_polymorphic_call_context context (current_function_decl, ref, call);
130
131 return possible_polymorphic_call_targets (obj_type_ref_class (ref),
132 tree_to_uhwi
133 (OBJ_TYPE_REF_TOKEN (ref)),
134 context,
135 completep, cache_token);
136 }
137
138 /* Dump possible targets of a polymorphic call E into F. */
139
140 inline void
141 dump_possible_polymorphic_call_targets (FILE *f, struct cgraph_edge *e,
142 bool verbose = true)
143 {
144 ipa_polymorphic_call_context context(e);
145
146 dump_possible_polymorphic_call_targets (f, e->indirect_info->otr_type,
147 e->indirect_info->otr_token,
148 context, verbose);
149 }
150
151 /* Return true if N can be possibly target of a polymorphic call of
152 E. */
153
154 inline bool
155 possible_polymorphic_call_target_p (struct cgraph_edge *e,
156 struct cgraph_node *n)
157 {
158 ipa_polymorphic_call_context context(e);
159
160 return possible_polymorphic_call_target_p (e->indirect_info->otr_type,
161 e->indirect_info->otr_token,
162 context, n);
163 }
164
165 /* Return true if BINFO corresponds to a type with virtual methods.
166
167 Every type has several BINFOs. One is the BINFO associated by the type
168 while other represents bases of derived types. The BINFOs representing
169 bases do not have BINFO_VTABLE pointer set when this is the single
170 inheritance (because vtables are shared). Look up the BINFO of type
171 and check presence of its vtable. */
172
173 inline bool
174 polymorphic_type_binfo_p (const_tree binfo)
175 {
176 return (BINFO_TYPE (binfo) && TYPE_BINFO (BINFO_TYPE (binfo))
177 && BINFO_VTABLE (TYPE_BINFO (BINFO_TYPE (binfo))));
178 }
179
180 /* Return true if T is a type with linkage defined. */
181
182 inline bool
183 type_with_linkage_p (const_tree t)
184 {
185 gcc_checking_assert (TYPE_MAIN_VARIANT (t) == t);
186 if (!TYPE_NAME (t) || TREE_CODE (TYPE_NAME (t)) != TYPE_DECL)
187 return false;
188
189 /* To support -fno-lto-odr-type-merigng recognize types with vtables
190 to have linkage. */
191 if (RECORD_OR_UNION_TYPE_P (t)
192 && TYPE_BINFO (t) && BINFO_VTABLE (TYPE_BINFO (t)))
193 return true;
194
195 /* After free_lang_data was run and -flto-odr-type-merging we can recongize
196 types with linkage by presence of mangled name. */
197 if (DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (t)))
198 return true;
199
200 if (in_lto_p)
201 return false;
202 /* We used to check for TYPE_STUB_DECL but that is set to NULL for forward
203 declarations. */
204
205 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 if (!TYPE_CONTEXT (t))
210 return false;
211
212 return true;
213 }
214
215 /* Return true if T is in anonymous namespace.
216 This works only on those C++ types with linkage defined. */
217
218 inline bool
219 type_in_anonymous_namespace_p (const_tree t)
220 {
221 gcc_checking_assert (type_with_linkage_p (t));
222
223 /* free_lang_data clears TYPE_STUB_DECL but sets assembler name to
224 "<anon>" */
225 if (DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (t)))
226 return !strcmp ("<anon>",
227 IDENTIFIER_POINTER
228 (DECL_ASSEMBLER_NAME (TYPE_NAME (t))));
229 else if (!TYPE_STUB_DECL (t))
230 return false;
231 else
232 return !TREE_PUBLIC (TYPE_STUB_DECL (t));
233 }
234
235 /* Return true of T is type with One Definition Rule info attached.
236 It means that either it is anonymous type or it has assembler name
237 set. */
238
239 inline bool
240 odr_type_p (const_tree t)
241 {
242 /* We do not have this information when not in LTO, but we do not need
243 to care, since it is used only for type merging. */
244 gcc_checking_assert (in_lto_p || flag_lto);
245
246 if (!type_with_linkage_p (t))
247 return false;
248
249 /* To support -fno-lto-odr-type-merging consider types with vtables ODR. */
250 if (type_in_anonymous_namespace_p (t))
251 return true;
252
253 if (TYPE_NAME (t) && DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (t)))
254 {
255 /* C++ FE uses magic <anon> as assembler names of anonymous types.
256 verify that this match with type_in_anonymous_namespace_p. */
257 gcc_checking_assert (strcmp ("<anon>",
258 IDENTIFIER_POINTER
259 (DECL_ASSEMBLER_NAME (TYPE_NAME (t)))));
260 return true;
261 }
262 return false;
263 }
264
265 #endif /* GCC_IPA_UTILS_H */
266
267