Skip analyzer strndup test on hppa*-*-hpux*
[official-gcc.git] / gcc / ipa-utils.h
blob84728c589ea1e5a377a0f909dc6b01388f70aff9
1 /* Utilities for ipa analysis.
2 Copyright (C) 2004-2023 Free Software Foundation, Inc.
3 Contributed by Kenneth Zadeck <zadeck@naturalbridge.com>
5 This file is part of GCC.
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.
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.
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/>. */
21 #ifndef GCC_IPA_UTILS_H
22 #define GCC_IPA_UTILS_H
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 void *aux;
37 /* In ipa-utils.cc */
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 bool stmt_may_terminate_function_p (function *fun, gimple *stmt, bool assume_return_or_eh);
50 bitmap find_always_executed_bbs (function *fun, bool assume_return_or_eh);
52 /* In ipa-pure-const.cc */
53 bool finite_function_p ();
54 bool builtin_safe_for_const_function_p (bool *, tree);
55 bool ipa_make_function_const (cgraph_node *, bool, bool);
56 bool ipa_make_function_pure (cgraph_node *, bool, bool);
58 /* In ipa-profile.cc */
59 bool ipa_propagate_frequency (struct cgraph_node *node);
61 /* In ipa-devirt.cc */
63 struct odr_type_d;
64 typedef odr_type_d *odr_type;
65 extern bool thunk_expansion;
66 void build_type_inheritance_graph (void);
67 void rebuild_type_inheritance_graph (void);
68 void update_type_inheritance_graph (void);
69 vec <cgraph_node *>
70 possible_polymorphic_call_targets (tree, HOST_WIDE_INT,
71 ipa_polymorphic_call_context,
72 bool *copletep = NULL,
73 void **cache_token = NULL,
74 bool speuclative = false);
75 odr_type get_odr_type (tree, bool insert = false);
76 bool odr_type_p (const_tree);
77 bool possible_polymorphic_call_target_p (tree ref, gimple *stmt, struct cgraph_node *n);
78 void dump_possible_polymorphic_call_targets (FILE *, tree, HOST_WIDE_INT,
79 const ipa_polymorphic_call_context &,
80 bool verbose = true);
81 bool possible_polymorphic_call_target_p (tree, HOST_WIDE_INT,
82 const ipa_polymorphic_call_context &,
83 struct cgraph_node *);
84 tree polymorphic_ctor_dtor_p (tree, bool);
85 tree inlined_polymorphic_ctor_dtor_block_p (tree, bool);
86 bool decl_maybe_in_construction_p (tree, tree, gimple *, tree);
87 tree vtable_pointer_value_to_binfo (const_tree);
88 bool vtable_pointer_value_to_vtable (const_tree, tree *, unsigned HOST_WIDE_INT *);
89 tree subbinfo_with_vtable_at_offset (tree, unsigned HOST_WIDE_INT, tree);
90 void compare_virtual_tables (varpool_node *, varpool_node *);
91 bool type_all_derivations_known_p (const_tree);
92 bool type_known_to_have_no_derivations_p (tree);
93 bool contains_polymorphic_type_p (const_tree);
94 void register_odr_type (tree);
95 bool types_must_be_same_for_odr (tree, tree);
96 bool types_odr_comparable (tree, tree);
97 cgraph_node *try_speculative_devirtualization (tree, HOST_WIDE_INT,
98 ipa_polymorphic_call_context);
99 void warn_types_mismatch (tree t1, tree t2, location_t loc1 = UNKNOWN_LOCATION,
100 location_t loc2 = UNKNOWN_LOCATION);
101 bool odr_or_derived_type_p (const_tree t);
102 bool odr_types_equivalent_p (tree type1, tree type2);
103 bool odr_type_violation_reported_p (tree type);
104 tree prevailing_odr_type (tree type);
105 void enable_odr_based_tbaa (tree type);
106 bool odr_based_tbaa_p (const_tree type);
107 void set_type_canonical_for_odr_type (tree type, tree canonical);
108 void warn_function_returns_nonnull (tree);
110 void register_odr_enum (tree type);
112 /* Return vector containing possible targets of polymorphic call E.
113 If COMPLETEP is non-NULL, store true if the list is complete.
114 CACHE_TOKEN (if non-NULL) will get stored to an unique ID of entry
115 in the target cache. If user needs to visit every target list
116 just once, it can memoize them.
118 Returned vector is placed into cache. It is NOT caller's responsibility
119 to free it. The vector can be freed on cgraph_remove_node call if
120 the particular node is a virtual function present in the cache. */
122 inline vec <cgraph_node *>
123 possible_polymorphic_call_targets (struct cgraph_edge *e,
124 bool *completep = NULL,
125 void **cache_token = NULL,
126 bool speculative = false)
128 ipa_polymorphic_call_context context(e);
130 return possible_polymorphic_call_targets (e->indirect_info->otr_type,
131 e->indirect_info->otr_token,
132 context,
133 completep, cache_token,
134 speculative);
137 /* Same as above but taking OBJ_TYPE_REF as an parameter. */
139 inline vec <cgraph_node *>
140 possible_polymorphic_call_targets (tree ref,
141 gimple *call,
142 bool *completep = NULL,
143 void **cache_token = NULL)
145 ipa_polymorphic_call_context context (current_function_decl, ref, call);
147 return possible_polymorphic_call_targets (obj_type_ref_class (ref),
148 tree_to_uhwi
149 (OBJ_TYPE_REF_TOKEN (ref)),
150 context,
151 completep, cache_token);
154 /* Dump possible targets of a polymorphic call E into F. */
156 inline void
157 dump_possible_polymorphic_call_targets (FILE *f, struct cgraph_edge *e,
158 bool verbose = true)
160 ipa_polymorphic_call_context context(e);
162 dump_possible_polymorphic_call_targets (f, e->indirect_info->otr_type,
163 e->indirect_info->otr_token,
164 context, verbose);
167 /* Return true if N can be possibly target of a polymorphic call of
168 E. */
170 inline bool
171 possible_polymorphic_call_target_p (struct cgraph_edge *e,
172 struct cgraph_node *n)
174 ipa_polymorphic_call_context context(e);
176 return possible_polymorphic_call_target_p (e->indirect_info->otr_type,
177 e->indirect_info->otr_token,
178 context, n);
181 /* Return true if BINFO corresponds to a type with virtual methods.
183 Every type has several BINFOs. One is the BINFO associated by the type
184 while other represents bases of derived types. The BINFOs representing
185 bases do not have BINFO_VTABLE pointer set when this is the single
186 inheritance (because vtables are shared). Look up the BINFO of type
187 and check presence of its vtable. */
189 inline bool
190 polymorphic_type_binfo_p (const_tree binfo)
192 return (BINFO_TYPE (binfo) && TYPE_BINFO (BINFO_TYPE (binfo))
193 && BINFO_VTABLE (TYPE_BINFO (BINFO_TYPE (binfo))));
196 /* Return true if T is a type with linkage defined. */
198 inline bool
199 type_with_linkage_p (const_tree t)
201 gcc_checking_assert (TYPE_MAIN_VARIANT (t) == t);
202 if (!TYPE_NAME (t) || TREE_CODE (TYPE_NAME (t)) != TYPE_DECL)
203 return false;
205 /* After free_lang_data was run we can recongize
206 types with linkage by presence of mangled name. */
207 if (DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (t)))
208 return true;
210 if (in_lto_p)
211 return false;
213 /* We used to check for TYPE_STUB_DECL but that is set to NULL for forward
214 declarations. */
216 if (!RECORD_OR_UNION_TYPE_P (t) && TREE_CODE (t) != ENUMERAL_TYPE)
217 return false;
219 /* Builtin types do not define linkage, their TYPE_CONTEXT is NULL. */
220 if (!TYPE_CONTEXT (t))
221 return false;
223 return true;
226 /* Return true if T is in anonymous namespace.
227 This works only on those C++ types with linkage defined. */
229 inline bool
230 type_in_anonymous_namespace_p (const_tree t)
232 gcc_checking_assert (type_with_linkage_p (t));
234 /* free_lang_data clears TYPE_STUB_DECL but sets assembler name to
235 "<anon>" */
236 if (DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (t)))
237 return !strcmp ("<anon>",
238 IDENTIFIER_POINTER
239 (DECL_ASSEMBLER_NAME (TYPE_NAME (t))));
240 else if (!TYPE_STUB_DECL (t))
241 return false;
242 else
243 return !TREE_PUBLIC (TYPE_STUB_DECL (t));
246 /* Return true of T is type with One Definition Rule info attached.
247 It means that either it is anonymous type or it has assembler name
248 set. */
250 inline bool
251 odr_type_p (const_tree t)
253 /* We do not have this information when not in LTO, but we do not need
254 to care, since it is used only for type merging. */
255 gcc_checking_assert (in_lto_p || flag_lto || flag_generate_offload);
256 return TYPE_NAME (t) && TREE_CODE (TYPE_NAME (t)) == TYPE_DECL
257 && DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (t));
260 /* If TYPE has mangled ODR name, return it. Otherwise return NULL.
261 The function works only when free_lang_data is run. */
263 inline const char *
264 get_odr_name_for_type (tree type)
266 tree type_name = TYPE_NAME (type);
267 if (type_name == NULL_TREE
268 || TREE_CODE (type_name) != TYPE_DECL
269 || !DECL_ASSEMBLER_NAME_SET_P (type_name))
270 return NULL;
272 return IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (type_name));
275 /* Return true if we are going to do LTO streaming. */
277 inline bool
278 lto_streaming_expected_p ()
280 /* Compilation before LTO stremaing. */
281 if (flag_lto && !in_lto_p && symtab->state < IPA_SSA_AFTER_INLINING)
282 return true;
283 /* WPA or incremental link. */
284 return (flag_wpa || flag_incremental_link == INCREMENTAL_LINK_LTO);
287 #endif /* GCC_IPA_UTILS_H */