]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/ipa-utils.h
[Ada] Warning for out-of-order record representation clauses
[thirdparty/gcc.git] / gcc / ipa-utils.h
CommitLineData
f7d118a9 1/* Utilities for ipa analysis.
fbd26352 2 Copyright (C) 2004-2019 Free Software Foundation, Inc.
f7d118a9 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
8c4c00c1 9Software Foundation; either version 3, or (at your option) any later
f7d118a9 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
8c4c00c1 18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
f7d118a9 20
21#ifndef GCC_IPA_UTILS_H
22#define GCC_IPA_UTILS_H
f7d118a9 23
f7d118a9 24struct ipa_dfs_info {
25 int dfn_number;
26 int low_link;
572635a5 27 /* This field will have the samy value for any two nodes in the same strongly
28 connected component. */
29 int scc_no;
cda6870f 30 bool new_node;
f7d118a9 31 bool on_stack;
32 struct cgraph_node* next_cycle;
33 PTR aux;
34};
35
fff4a6c8 36
f7d118a9 37/* In ipa-utils.c */
7771d558 38void ipa_print_order (FILE*, const char *, struct cgraph_node**, int);
8cdb0206 39int ipa_reduced_postorder (struct cgraph_node **, bool,
7771d558 40 bool (*ignore_edge) (struct cgraph_edge *));
41void ipa_free_postorder_info (void);
415d1b9a 42vec<cgraph_node *> ipa_get_nodes_in_cycle (struct cgraph_node *);
a0255a70 43bool ipa_edge_within_scc (struct cgraph_edge *);
7771d558 44int ipa_reverse_postorder (struct cgraph_node **);
f7d118a9 45tree get_base_var (tree);
06d12890 46void ipa_merge_profiles (struct cgraph_node *dst,
96bf18ea 47 struct cgraph_node *src, bool preserve_body = false);
e9de52cc 48bool recursive_call_p (tree, tree);
f7d118a9 49
6eaf903b 50/* In ipa-profile.c */
51bool ipa_propagate_frequency (struct cgraph_node *node);
52
5514adf9 53/* In ipa-devirt.c */
54
55struct odr_type_d;
56typedef odr_type_d *odr_type;
57void build_type_inheritance_graph (void);
329c480e 58void rebuild_type_inheritance_graph (void);
07c6dcc3 59void update_type_inheritance_graph (void);
5514adf9 60vec <cgraph_node *>
61possible_polymorphic_call_targets (tree, HOST_WIDE_INT,
3af5e0b7 62 ipa_polymorphic_call_context,
379f6698 63 bool *copletep = NULL,
857c5a0b 64 void **cache_token = NULL,
840d898c 65 bool speuclative = false);
5514adf9 66odr_type get_odr_type (tree, bool insert = false);
40175f70 67bool odr_type_p (const_tree);
42acab1c 68bool possible_polymorphic_call_target_p (tree ref, gimple *stmt, struct cgraph_node *n);
3af5e0b7 69void dump_possible_polymorphic_call_targets (FILE *, tree, HOST_WIDE_INT,
1f256e16 70 const ipa_polymorphic_call_context &,
71 bool verbose = true);
07c6dcc3 72bool possible_polymorphic_call_target_p (tree, HOST_WIDE_INT,
3af5e0b7 73 const ipa_polymorphic_call_context &,
40d6aa75 74 struct cgraph_node *);
402d7a90 75tree polymorphic_ctor_dtor_p (tree, bool);
a467a47b 76tree inlined_polymorphic_ctor_dtor_block_p (tree, bool);
42acab1c 77bool decl_maybe_in_construction_p (tree, tree, gimple *, tree);
40d6aa75 78tree vtable_pointer_value_to_binfo (const_tree);
79bool vtable_pointer_value_to_vtable (const_tree, tree *, unsigned HOST_WIDE_INT *);
8d326f11 80tree subbinfo_with_vtable_at_offset (tree, unsigned HOST_WIDE_INT, tree);
1df805e3 81void compare_virtual_tables (varpool_node *, varpool_node *);
8d326f11 82bool type_all_derivations_known_p (const_tree);
2bfdc8e7 83bool type_known_to_have_no_derivations_p (tree);
40d6aa75 84bool contains_polymorphic_type_p (const_tree);
d585ba22 85void register_odr_type (tree);
8d326f11 86bool types_must_be_same_for_odr (tree, tree);
d2dc5bc6 87bool types_odr_comparable (tree, tree);
072ec6eb 88cgraph_node *try_speculative_devirtualization (tree, HOST_WIDE_INT,
89 ipa_polymorphic_call_context);
379ca7f8 90void warn_types_mismatch (tree t1, tree t2, location_t loc1 = UNKNOWN_LOCATION,
91 location_t loc2 = UNKNOWN_LOCATION);
40175f70 92bool odr_or_derived_type_p (const_tree t);
93bool odr_types_equivalent_p (tree type1, tree type2);
c2ef464f 94bool odr_type_violation_reported_p (tree type);
c695b63d 95tree prevailing_odr_type (tree type);
98c0f4ea 96void enable_odr_based_tbaa (tree type);
97bool odr_based_tbaa_p (const_tree type);
98void set_type_canonical_for_odr_type (tree type, tree canonical);
5514adf9 99
100/* Return vector containing possible targets of polymorphic call E.
4cf494ec 101 If COMPLETEP is non-NULL, store true if the list is complete.
5514adf9 102 CACHE_TOKEN (if non-NULL) will get stored to an unique ID of entry
103 in the target cache. If user needs to visit every target list
104 just once, it can memoize them.
105
106 Returned vector is placed into cache. It is NOT caller's responsibility
107 to free it. The vector can be freed on cgraph_remove_node call if
108 the particular node is a virtual function present in the cache. */
109
110inline vec <cgraph_node *>
111possible_polymorphic_call_targets (struct cgraph_edge *e,
379f6698 112 bool *completep = NULL,
857c5a0b 113 void **cache_token = NULL,
840d898c 114 bool speculative = false)
5514adf9 115{
3a4f036a 116 ipa_polymorphic_call_context context(e);
379f6698 117
5514adf9 118 return possible_polymorphic_call_targets (e->indirect_info->otr_type,
119 e->indirect_info->otr_token,
3af5e0b7 120 context,
379f6698 121 completep, cache_token,
840d898c 122 speculative);
3af5e0b7 123}
124
125/* Same as above but taking OBJ_TYPE_REF as an parameter. */
126
127inline vec <cgraph_node *>
1b613a0a 128possible_polymorphic_call_targets (tree ref,
42acab1c 129 gimple *call,
379f6698 130 bool *completep = NULL,
3af5e0b7 131 void **cache_token = NULL)
132{
379f6698 133 ipa_polymorphic_call_context context (current_function_decl, ref, call);
76058579 134
1b613a0a 135 return possible_polymorphic_call_targets (obj_type_ref_class (ref),
3af5e0b7 136 tree_to_uhwi
1b613a0a 137 (OBJ_TYPE_REF_TOKEN (ref)),
76058579 138 context,
379f6698 139 completep, cache_token);
5514adf9 140}
141
142/* Dump possible targets of a polymorphic call E into F. */
48e1416a 143
5514adf9 144inline void
1f256e16 145dump_possible_polymorphic_call_targets (FILE *f, struct cgraph_edge *e,
146 bool verbose = true)
5514adf9 147{
3a4f036a 148 ipa_polymorphic_call_context context(e);
379f6698 149
5514adf9 150 dump_possible_polymorphic_call_targets (f, e->indirect_info->otr_type,
3af5e0b7 151 e->indirect_info->otr_token,
1f256e16 152 context, verbose);
5514adf9 153}
07c6dcc3 154
155/* Return true if N can be possibly target of a polymorphic call of
156 E. */
157
158inline bool
159possible_polymorphic_call_target_p (struct cgraph_edge *e,
160 struct cgraph_node *n)
161{
3a4f036a 162 ipa_polymorphic_call_context context(e);
379f6698 163
07c6dcc3 164 return possible_polymorphic_call_target_p (e->indirect_info->otr_type,
3af5e0b7 165 e->indirect_info->otr_token,
166 context, n);
07c6dcc3 167}
10fba9c0 168
8d326f11 169/* Return true if BINFO corresponds to a type with virtual methods.
170
171 Every type has several BINFOs. One is the BINFO associated by the type
172 while other represents bases of derived types. The BINFOs representing
173 bases do not have BINFO_VTABLE pointer set when this is the single
174 inheritance (because vtables are shared). Look up the BINFO of type
175 and check presence of its vtable. */
176
177inline bool
178polymorphic_type_binfo_p (const_tree binfo)
179{
7ef91cea 180 return (BINFO_TYPE (binfo) && TYPE_BINFO (BINFO_TYPE (binfo))
181 && BINFO_VTABLE (TYPE_BINFO (BINFO_TYPE (binfo))));
8d326f11 182}
ae3326d8 183
184/* Return true if T is a type with linkage defined. */
185
186inline bool
187type_with_linkage_p (const_tree t)
188{
d2dc5bc6 189 gcc_checking_assert (TYPE_MAIN_VARIANT (t) == t);
abf0dec5 190 if (!TYPE_NAME (t) || TREE_CODE (TYPE_NAME (t)) != TYPE_DECL)
191 return false;
192
3dea6fae 193 /* After free_lang_data was run we can recongize
abf0dec5 194 types with linkage by presence of mangled name. */
195 if (DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (t)))
196 return true;
197
56edcef3 198 if (in_lto_p)
ae3326d8 199 return false;
3dea6fae 200
56edcef3 201 /* We used to check for TYPE_STUB_DECL but that is set to NULL for forward
202 declarations. */
ae3326d8 203
204 if (!RECORD_OR_UNION_TYPE_P (t) && TREE_CODE (t) != ENUMERAL_TYPE)
205 return false;
206
207 /* Builtin types do not define linkage, their TYPE_CONTEXT is NULL. */
208 if (!TYPE_CONTEXT (t))
209 return false;
210
aaabc7bc 211 gcc_checking_assert (TREE_CODE (t) == ENUMERAL_TYPE || TYPE_CXX_ODR_P (t));
212
ae3326d8 213 return true;
214}
215
216/* Return true if T is in anonymous namespace.
217 This works only on those C++ types with linkage defined. */
218
219inline bool
220type_in_anonymous_namespace_p (const_tree t)
221{
222 gcc_checking_assert (type_with_linkage_p (t));
223
abf0dec5 224 /* free_lang_data clears TYPE_STUB_DECL but sets assembler name to
225 "<anon>" */
226 if (DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (t)))
227 return !strcmp ("<anon>",
228 IDENTIFIER_POINTER
229 (DECL_ASSEMBLER_NAME (TYPE_NAME (t))));
230 else if (!TYPE_STUB_DECL (t))
231 return false;
232 else
233 return !TREE_PUBLIC (TYPE_STUB_DECL (t));
ae3326d8 234}
235
236/* Return true of T is type with One Definition Rule info attached.
237 It means that either it is anonymous type or it has assembler name
238 set. */
239
240inline bool
241odr_type_p (const_tree t)
242{
243 /* We do not have this information when not in LTO, but we do not need
244 to care, since it is used only for type merging. */
245 gcc_checking_assert (in_lto_p || flag_lto);
3dea6fae 246 return TYPE_NAME (t) && TREE_CODE (TYPE_NAME (t)) == TYPE_DECL
247 && DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (t));
ae3326d8 248}
249
f7d118a9 250#endif /* GCC_IPA_UTILS_H */