]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/ipa-utils.h
[Ada] Remove Determine_License
[thirdparty/gcc.git] / gcc / ipa-utils.h
CommitLineData
ea900239 1/* Utilities for ipa analysis.
8d9254fc 2 Copyright (C) 2004-2020 Free Software Foundation, Inc.
ea900239
DB
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
9dcd6f09 9Software Foundation; either version 3, or (at your option) any later
ea900239
DB
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
9dcd6f09
NC
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
ea900239
DB
20
21#ifndef GCC_IPA_UTILS_H
22#define GCC_IPA_UTILS_H
ea900239 23
ea900239
DB
24struct ipa_dfs_info {
25 int dfn_number;
26 int low_link;
11026b51
MJ
27 /* This field will have the samy value for any two nodes in the same strongly
28 connected component. */
29 int scc_no;
c5274326 30 bool new_node;
ea900239
DB
31 bool on_stack;
32 struct cgraph_node* next_cycle;
33 PTR aux;
34};
35
a1981458 36
ea900239 37/* In ipa-utils.c */
af8bca3c 38void ipa_print_order (FILE*, const char *, struct cgraph_node**, int);
45272fd2 39int ipa_reduced_postorder (struct cgraph_node **, bool,
af8bca3c
MJ
40 bool (*ignore_edge) (struct cgraph_edge *));
41void ipa_free_postorder_info (void);
d52f5295 42vec<cgraph_node *> ipa_get_nodes_in_cycle (struct cgraph_node *);
4cb13597 43bool ipa_edge_within_scc (struct cgraph_edge *);
af8bca3c 44int ipa_reverse_postorder (struct cgraph_node **);
ea900239 45tree get_base_var (tree);
5e581212 46void ipa_merge_profiles (struct cgraph_node *dst,
b730d1c9 47 struct cgraph_node *src, bool preserve_body = false);
fc11f321 48bool recursive_call_p (tree, tree);
ea900239 49
08f835dc
JH
50/* In ipa-profile.c */
51bool ipa_propagate_frequency (struct cgraph_node *node);
52
eefe9a99
JH
53/* In ipa-devirt.c */
54
55struct odr_type_d;
56typedef odr_type_d *odr_type;
2bc2379b 57extern bool thunk_expansion;
eefe9a99 58void build_type_inheritance_graph (void);
c1b8f25d 59void rebuild_type_inheritance_graph (void);
0e1474e5 60void update_type_inheritance_graph (void);
eefe9a99
JH
61vec <cgraph_node *>
62possible_polymorphic_call_targets (tree, HOST_WIDE_INT,
68377e53 63 ipa_polymorphic_call_context,
6f8091fc 64 bool *copletep = NULL,
ec77d61f 65 void **cache_token = NULL,
2f28755f 66 bool speuclative = false);
eefe9a99 67odr_type get_odr_type (tree, bool insert = false);
259d29e3 68bool odr_type_p (const_tree);
355fe088 69bool possible_polymorphic_call_target_p (tree ref, gimple *stmt, struct cgraph_node *n);
68377e53 70void dump_possible_polymorphic_call_targets (FILE *, tree, HOST_WIDE_INT,
c1dd347c
JH
71 const ipa_polymorphic_call_context &,
72 bool verbose = true);
0e1474e5 73bool possible_polymorphic_call_target_p (tree, HOST_WIDE_INT,
68377e53 74 const ipa_polymorphic_call_context &,
d570d364 75 struct cgraph_node *);
967ca9b9 76tree polymorphic_ctor_dtor_p (tree, bool);
00a0ea64 77tree inlined_polymorphic_ctor_dtor_block_p (tree, bool);
355fe088 78bool decl_maybe_in_construction_p (tree, tree, gimple *, tree);
d570d364
JH
79tree vtable_pointer_value_to_binfo (const_tree);
80bool vtable_pointer_value_to_vtable (const_tree, tree *, unsigned HOST_WIDE_INT *);
aa803cc7 81tree subbinfo_with_vtable_at_offset (tree, unsigned HOST_WIDE_INT, tree);
56b1f114 82void compare_virtual_tables (varpool_node *, varpool_node *);
aa803cc7 83bool type_all_derivations_known_p (const_tree);
4d6eb35a 84bool type_known_to_have_no_derivations_p (tree);
d570d364 85bool contains_polymorphic_type_p (const_tree);
1ee85ee1 86void register_odr_type (tree);
aa803cc7 87bool types_must_be_same_for_odr (tree, tree);
420672bc 88bool types_odr_comparable (tree, tree);
5ce97055
JH
89cgraph_node *try_speculative_devirtualization (tree, HOST_WIDE_INT,
90 ipa_polymorphic_call_context);
6542950e
JH
91void warn_types_mismatch (tree t1, tree t2, location_t loc1 = UNKNOWN_LOCATION,
92 location_t loc2 = UNKNOWN_LOCATION);
259d29e3
JH
93bool odr_or_derived_type_p (const_tree t);
94bool odr_types_equivalent_p (tree type1, tree type2);
d840d7a2 95bool odr_type_violation_reported_p (tree type);
e4b44fd7 96tree prevailing_odr_type (tree type);
a0276c00
JH
97void enable_odr_based_tbaa (tree type);
98bool odr_based_tbaa_p (const_tree type);
99void set_type_canonical_for_odr_type (tree type, tree canonical);
eefe9a99 100
3fb68f2e
JH
101void register_odr_enum (tree type);
102
eefe9a99 103/* Return vector containing possible targets of polymorphic call E.
1c5fd343 104 If COMPLETEP is non-NULL, store true if the list is complete.
eefe9a99
JH
105 CACHE_TOKEN (if non-NULL) will get stored to an unique ID of entry
106 in the target cache. If user needs to visit every target list
107 just once, it can memoize them.
108
109 Returned vector is placed into cache. It is NOT caller's responsibility
110 to free it. The vector can be freed on cgraph_remove_node call if
111 the particular node is a virtual function present in the cache. */
112
113inline vec <cgraph_node *>
114possible_polymorphic_call_targets (struct cgraph_edge *e,
6f8091fc 115 bool *completep = NULL,
ec77d61f 116 void **cache_token = NULL,
2f28755f 117 bool speculative = false)
eefe9a99 118{
4d7cf10d 119 ipa_polymorphic_call_context context(e);
6f8091fc 120
eefe9a99
JH
121 return possible_polymorphic_call_targets (e->indirect_info->otr_type,
122 e->indirect_info->otr_token,
68377e53 123 context,
6f8091fc 124 completep, cache_token,
2f28755f 125 speculative);
68377e53
JH
126}
127
128/* Same as above but taking OBJ_TYPE_REF as an parameter. */
129
130inline vec <cgraph_node *>
058d0a90 131possible_polymorphic_call_targets (tree ref,
355fe088 132 gimple *call,
6f8091fc 133 bool *completep = NULL,
68377e53
JH
134 void **cache_token = NULL)
135{
6f8091fc 136 ipa_polymorphic_call_context context (current_function_decl, ref, call);
61dd6a2e 137
058d0a90 138 return possible_polymorphic_call_targets (obj_type_ref_class (ref),
68377e53 139 tree_to_uhwi
058d0a90 140 (OBJ_TYPE_REF_TOKEN (ref)),
61dd6a2e 141 context,
6f8091fc 142 completep, cache_token);
eefe9a99
JH
143}
144
145/* Dump possible targets of a polymorphic call E into F. */
b8698a0f 146
eefe9a99 147inline void
c1dd347c
JH
148dump_possible_polymorphic_call_targets (FILE *f, struct cgraph_edge *e,
149 bool verbose = true)
eefe9a99 150{
4d7cf10d 151 ipa_polymorphic_call_context context(e);
6f8091fc 152
eefe9a99 153 dump_possible_polymorphic_call_targets (f, e->indirect_info->otr_type,
68377e53 154 e->indirect_info->otr_token,
c1dd347c 155 context, verbose);
eefe9a99 156}
0e1474e5
JH
157
158/* Return true if N can be possibly target of a polymorphic call of
159 E. */
160
161inline bool
162possible_polymorphic_call_target_p (struct cgraph_edge *e,
163 struct cgraph_node *n)
164{
4d7cf10d 165 ipa_polymorphic_call_context context(e);
6f8091fc 166
0e1474e5 167 return possible_polymorphic_call_target_p (e->indirect_info->otr_type,
68377e53
JH
168 e->indirect_info->otr_token,
169 context, n);
0e1474e5 170}
450ad0cd 171
aa803cc7
JH
172/* Return true if BINFO corresponds to a type with virtual methods.
173
174 Every type has several BINFOs. One is the BINFO associated by the type
175 while other represents bases of derived types. The BINFOs representing
176 bases do not have BINFO_VTABLE pointer set when this is the single
177 inheritance (because vtables are shared). Look up the BINFO of type
178 and check presence of its vtable. */
179
180inline bool
181polymorphic_type_binfo_p (const_tree binfo)
182{
1be0e58d
JH
183 return (BINFO_TYPE (binfo) && TYPE_BINFO (BINFO_TYPE (binfo))
184 && BINFO_VTABLE (TYPE_BINFO (BINFO_TYPE (binfo))));
aa803cc7 185}
a6c5361c
JH
186
187/* Return true if T is a type with linkage defined. */
188
189inline bool
190type_with_linkage_p (const_tree t)
191{
420672bc 192 gcc_checking_assert (TYPE_MAIN_VARIANT (t) == t);
2ebbdb6c
JH
193 if (!TYPE_NAME (t) || TREE_CODE (TYPE_NAME (t)) != TYPE_DECL)
194 return false;
195
686a56a8 196 /* After free_lang_data was run we can recongize
2ebbdb6c
JH
197 types with linkage by presence of mangled name. */
198 if (DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (t)))
199 return true;
200
9a97772f 201 if (in_lto_p)
a6c5361c 202 return false;
686a56a8 203
9a97772f
JH
204 /* We used to check for TYPE_STUB_DECL but that is set to NULL for forward
205 declarations. */
a6c5361c
JH
206
207 if (!RECORD_OR_UNION_TYPE_P (t) && TREE_CODE (t) != ENUMERAL_TYPE)
208 return false;
209
210 /* Builtin types do not define linkage, their TYPE_CONTEXT is NULL. */
211 if (!TYPE_CONTEXT (t))
212 return false;
213
f4af4019
JH
214 gcc_checking_assert (TREE_CODE (t) == ENUMERAL_TYPE || TYPE_CXX_ODR_P (t));
215
a6c5361c
JH
216 return true;
217}
218
219/* Return true if T is in anonymous namespace.
220 This works only on those C++ types with linkage defined. */
221
222inline bool
223type_in_anonymous_namespace_p (const_tree t)
224{
225 gcc_checking_assert (type_with_linkage_p (t));
226
2ebbdb6c
JH
227 /* free_lang_data clears TYPE_STUB_DECL but sets assembler name to
228 "<anon>" */
229 if (DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (t)))
230 return !strcmp ("<anon>",
231 IDENTIFIER_POINTER
232 (DECL_ASSEMBLER_NAME (TYPE_NAME (t))));
233 else if (!TYPE_STUB_DECL (t))
234 return false;
235 else
236 return !TREE_PUBLIC (TYPE_STUB_DECL (t));
a6c5361c
JH
237}
238
239/* Return true of T is type with One Definition Rule info attached.
240 It means that either it is anonymous type or it has assembler name
241 set. */
242
243inline bool
244odr_type_p (const_tree t)
245{
246 /* We do not have this information when not in LTO, but we do not need
247 to care, since it is used only for type merging. */
c5ab336b 248 gcc_checking_assert (in_lto_p || flag_lto || flag_generate_offload);
686a56a8
JH
249 return TYPE_NAME (t) && TREE_CODE (TYPE_NAME (t)) == TYPE_DECL
250 && DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (t));
a6c5361c
JH
251}
252
74fee042
ML
253/* If TYPE has mangled ODR name, return it. Otherwise return NULL.
254 The function works only when free_lang_data is run. */
255
256inline const char *
257get_odr_name_for_type (tree type)
258{
259 tree type_name = TYPE_NAME (type);
260 if (type_name == NULL_TREE
c175aa77 261 || TREE_CODE (type_name) != TYPE_DECL
74fee042
ML
262 || !DECL_ASSEMBLER_NAME_SET_P (type_name))
263 return NULL;
264
265 return IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (type_name));
266}
267
ea900239 268#endif /* GCC_IPA_UTILS_H */