GCC Middle and Back End API Reference
ipa-utils.h
Go to the documentation of this file.
1/* Utilities for ipa analysis.
2 Copyright (C) 2004-2024 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
27 /* This field will have the samy value for any two nodes in the same strongly
28 connected component. */
29 int scc_no;
33 void *aux;
34};
35
36
37/* In ipa-utils.cc */
38void ipa_print_order (FILE*, const char *, struct cgraph_node**, int);
39int ipa_reduced_postorder (struct cgraph_node **, bool,
40 bool (*ignore_edge) (struct cgraph_edge *));
41void ipa_free_postorder_info (void);
43bool ipa_edge_within_scc (struct cgraph_edge *);
46void ipa_merge_profiles (struct cgraph_node *dst,
47 struct cgraph_node *src, bool preserve_body = false);
51
52/* In ipa-pure-const.cc */
53bool finite_function_p ();
55bool ipa_make_function_const (cgraph_node *, bool, bool);
56bool ipa_make_function_pure (cgraph_node *, bool, bool);
57
58/* In ipa-profile.cc */
59bool ipa_propagate_frequency (struct cgraph_node *node);
60void ipa_profile_cc_finalize (void);
61
62/* In ipa-icf.cc */
63void ipa_icf_cc_finalize (void);
64
65/* In ipa-sra.cc */
66void ipa_sra_cc_finalize (void);
67
68/* In ipa-devirt.cc */
69
70struct odr_type_d;
72extern bool thunk_expansion;
76vec <cgraph_node *>
79 bool *copletep = NULL,
80 void **cache_token = NULL,
81 bool speuclative = false);
82odr_type get_odr_type (tree, bool insert = false);
87 bool verbose = true);
90 struct cgraph_node *);
116
118
119/* Return vector containing possible targets of polymorphic call E.
120 If COMPLETEP is non-NULL, store true if the list is complete.
121 CACHE_TOKEN (if non-NULL) will get stored to an unique ID of entry
122 in the target cache. If user needs to visit every target list
123 just once, it can memoize them.
124
125 Returned vector is placed into cache. It is NOT caller's responsibility
126 to free it. The vector can be freed on cgraph_remove_node call if
127 the particular node is a virtual function present in the cache. */
128
129inline vec <cgraph_node *>
131 bool *completep = NULL,
132 void **cache_token = NULL,
133 bool speculative = false)
134{
136
139 context,
141 speculative);
142}
143
144/* Same as above but taking OBJ_TYPE_REF as an parameter. */
145
146inline vec <cgraph_node *>
148 gimple *call,
149 bool *completep = NULL,
150 void **cache_token = NULL)
151{
153
156 (OBJ_TYPE_REF_TOKEN (ref)),
157 context,
159}
160
161/* Dump possible targets of a polymorphic call E into F. */
162
163inline void
173
174/* Return true if N can be possibly target of a polymorphic call of
175 E. */
176
177inline bool
187
188/* Return true if BINFO corresponds to a type with virtual methods.
189
190 Every type has several BINFOs. One is the BINFO associated by the type
191 while other represents bases of derived types. The BINFOs representing
192 bases do not have BINFO_VTABLE pointer set when this is the single
193 inheritance (because vtables are shared). Look up the BINFO of type
194 and check presence of its vtable. */
195
196inline bool
202
203/* Return true if T is a type with linkage defined. */
204
205inline bool
207{
209 if (!TYPE_NAME (t) || TREE_CODE (TYPE_NAME (t)) != TYPE_DECL)
210 return false;
211
212 /* After free_lang_data was run we can recongize
213 types with linkage by presence of mangled name. */
215 return true;
216
217 if (in_lto_p)
218 return false;
219
220 /* We used to check for TYPE_STUB_DECL but that is set to NULL for forward
221 declarations. */
222
224 return false;
225
226 /* Builtin types do not define linkage, their TYPE_CONTEXT is NULL. */
227 if (!TYPE_CONTEXT (t))
228 return false;
229
230 return true;
231}
232
233/* Return true if T is in anonymous namespace.
234 This works only on those C++ types with linkage defined. */
235
236inline bool
238{
240
241 /* free_lang_data clears TYPE_STUB_DECL but sets assembler name to
242 "<anon>" */
244 return !strcmp ("<anon>",
247 else if (!TYPE_STUB_DECL (t))
248 return false;
249 else
250 return !TREE_PUBLIC (TYPE_STUB_DECL (t));
251}
252
253/* Return true of T is type with One Definition Rule info attached.
254 It means that either it is anonymous type or it has assembler name
255 set. */
256
257inline bool
259{
260 /* We do not have this information when not in LTO, but we do not need
261 to care, since it is used only for type merging. */
263 return TYPE_NAME (t) && TREE_CODE (TYPE_NAME (t)) == TYPE_DECL
265}
266
267/* If TYPE has mangled ODR name, return it. Otherwise return NULL.
268 The function works only when free_lang_data is run. */
269
270inline const char *
281
282/* Return true if we are going to do LTO streaming. */
283
284inline bool
286{
287 /* Compilation before LTO stremaing. */
289 return true;
290 /* WPA or incremental link. */
292}
293
294#endif /* GCC_IPA_UTILS_H */
symbol_table * symtab
Definition cgraph.cc:81
@ IPA_SSA_AFTER_INLINING
Definition cgraph.h:2197
Definition cgraph.h:1696
cgraph_indirect_call_info * indirect_info
Definition cgraph.h:1912
HOST_WIDE_INT otr_token
Definition cgraph.h:1663
tree otr_type
Definition cgraph.h:1665
Definition cgraph.h:1555
enum symtab_state state
Definition cgraph.h:2499
bool verbose
Definition collect-utils.cc:35
const union tree_node * const_tree
Definition coretypes.h:98
class bitmap_head * bitmap
Definition coretypes.h:51
union tree_node * tree
Definition coretypes.h:97
@ INCREMENTAL_LINK_LTO
Definition flag-types.h:375
T * ggc_alloc(ALONE_CXX_MEM_STAT_INFO)
Definition ggc.h:184
#define UNKNOWN_LOCATION
Definition input.h:32
tree obj_type_ref_class(const_tree ref, bool for_dump_p)
Definition ipa-devirt.cc:1910
void register_odr_enum(tree type)
Definition ipa-devirt.cc:4044
void compare_virtual_tables(varpool_node *, varpool_node *)
Definition ipa-devirt.cc:662
bool types_odr_comparable(tree, tree)
Definition ipa-devirt.cc:396
void update_type_inheritance_graph(void)
Definition ipa-devirt.cc:3527
void set_type_canonical_for_odr_type(tree type, tree canonical)
Definition ipa-devirt.cc:2067
bool decl_maybe_in_construction_p(tree, tree, gimple *, tree)
Definition ipa-polymorphic-call.cc:543
bool odr_type_p(const_tree)
Definition ipa-utils.h:258
odr_type get_odr_type(tree, bool insert=false)
Definition ipa-devirt.cc:1937
bool ipa_edge_within_scc(struct cgraph_edge *)
Definition ipa-utils.cc:262
const char * get_odr_name_for_type(tree type)
Definition ipa-utils.h:271
cgraph_node * try_speculative_devirtualization(tree, HOST_WIDE_INT, ipa_polymorphic_call_context)
Definition ipa-devirt.cc:3611
void ipa_profile_cc_finalize(void)
Definition ipa-profile.cc:1075
bool odr_based_tbaa_p(const_tree type)
Definition ipa-devirt.cc:2051
void register_odr_type(tree)
Definition ipa-devirt.cc:2092
vec< cgraph_node * > ipa_get_nodes_in_cycle(struct cgraph_node *)
Definition ipa-utils.cc:245
int ipa_reverse_postorder(struct cgraph_node **)
Definition ipa-utils.cc:286
tree get_base_var(tree)
Definition ipa-utils.cc:363
bool thunk_expansion
Definition ipa-devirt.cc:185
bool types_must_be_same_for_odr(tree, tree)
Definition ipa-devirt.cc:408
tree vtable_pointer_value_to_binfo(const_tree)
Definition ipa-devirt.cc:2878
void ipa_print_order(FILE *, const char *, struct cgraph_node **, int)
Definition ipa-utils.cc:54
bool recursive_call_p(tree, tree)
Definition ipa-utils.cc:767
void ipa_merge_profiles(struct cgraph_node *dst, struct cgraph_node *src, bool preserve_body=false)
Definition ipa-utils.cc:397
bool vtable_pointer_value_to_vtable(const_tree, tree *, unsigned HOST_WIDE_INT *)
Definition ipa-devirt.cc:2831
tree polymorphic_ctor_dtor_p(tree, bool)
Definition ipa-polymorphic-call.cc:489
bool ipa_make_function_const(cgraph_node *, bool, bool)
Definition ipa-pure-const.cc:1499
bool possible_polymorphic_call_target_p(tree ref, gimple *stmt, struct cgraph_node *n)
Definition ipa-devirt.cc:3508
tree inlined_polymorphic_ctor_dtor_block_p(tree, bool)
Definition ipa-polymorphic-call.cc:516
odr_type_d * odr_type
Definition ipa-utils.h:71
bool odr_or_derived_type_p(const_tree t)
Definition ipa-devirt.cc:438
bitmap find_always_executed_bbs(function *fun, bool assume_return_or_eh)
Definition ipa-utils.cc:829
void ipa_sra_cc_finalize(void)
Definition ipa-sra.cc:4716
bool finite_function_p()
Definition ipa-pure-const.cc:1021
bool builtin_safe_for_const_function_p(bool *, tree)
Definition ipa-pure-const.cc:524
void warn_function_returns_nonnull(tree)
Definition ipa-pure-const.cc:298
bool lto_streaming_expected_p()
Definition ipa-utils.h:285
bool ipa_make_function_pure(cgraph_node *, bool, bool)
Definition ipa-pure-const.cc:1536
int ipa_reduced_postorder(struct cgraph_node **, bool, bool(*ignore_edge)(struct cgraph_edge *))
Definition ipa-utils.cc:172
void rebuild_type_inheritance_graph(void)
Definition ipa-devirt.cc:2774
bool type_in_anonymous_namespace_p(const_tree t)
Definition ipa-utils.h:237
bool type_all_derivations_known_p(const_tree)
Definition ipa-devirt.cc:240
bool odr_types_equivalent_p(tree type1, tree type2)
Definition ipa-devirt.cc:1592
void warn_types_mismatch(tree t1, tree t2, location_t loc1=UNKNOWN_LOCATION, location_t loc2=UNKNOWN_LOCATION)
Definition ipa-devirt.cc:997
tree subbinfo_with_vtable_at_offset(tree, unsigned HOST_WIDE_INT, tree)
Definition ipa-devirt.cc:2798
void ipa_icf_cc_finalize(void)
Definition ipa-icf.cc:3724
bool type_with_linkage_p(const_tree t)
Definition ipa-utils.h:206
void build_type_inheritance_graph(void)
Definition ipa-devirt.cc:2274
bool polymorphic_type_binfo_p(const_tree binfo)
Definition ipa-utils.h:197
bool ipa_propagate_frequency(struct cgraph_node *node)
Definition ipa-profile.cc:645
bool type_known_to_have_no_derivations_p(tree)
Definition ipa-devirt.cc:2132
bool stmt_may_terminate_function_p(function *fun, gimple *stmt, bool assume_return_or_eh)
Definition ipa-utils.cc:794
bool contains_polymorphic_type_p(const_tree)
Definition ipa-polymorphic-call.cc:53
bool odr_type_violation_reported_p(tree type)
Definition ipa-devirt.cc:2084
void ipa_free_postorder_info(void)
Definition ipa-utils.cc:227
vec< cgraph_node * > possible_polymorphic_call_targets(tree, HOST_WIDE_INT, ipa_polymorphic_call_context, bool *copletep=NULL, void **cache_token=NULL, bool speuclative=false)
Definition ipa-devirt.cc:3041
tree prevailing_odr_type(tree type)
Definition ipa-devirt.cc:2031
void dump_possible_polymorphic_call_targets(FILE *, tree, HOST_WIDE_INT, const ipa_polymorphic_call_context &, bool verbose=true)
Definition ipa-devirt.cc:3416
void enable_odr_based_tbaa(tree type)
Definition ipa-devirt.cc:2042
Definition cgraph.h:875
Definition function.h:249
Definition gimple.h:225
Definition ipa-utils.h:24
int scc_no
Definition ipa-utils.h:29
bool new_node
Definition ipa-utils.h:30
bool on_stack
Definition ipa-utils.h:31
void * aux
Definition ipa-utils.h:33
int dfn_number
Definition ipa-utils.h:25
struct cgraph_node * next_cycle
Definition ipa-utils.h:32
int low_link
Definition ipa-utils.h:26
Definition ipa-devirt.cc:204
Definition gengtype.h:252
Definition cgraph.h:2000
Definition vec.h:450
#define NULL
Definition system.h:50
#define gcc_checking_assert(EXPR)
Definition system.h:828
tree current_function_decl
Definition toplev.cc:124
static void insert(void)
Definition tree-ssa-pre.cc:3796
unsigned HOST_WIDE_INT tree_to_uhwi(const_tree t)
Definition tree.cc:6477
#define TYPE_NAME(NODE)
Definition tree.h:2248
#define DECL_ASSEMBLER_NAME(NODE)
Definition tree.h:3191
#define BINFO_TYPE(NODE)
Definition tree.h:2591
#define OBJ_TYPE_REF_TOKEN(NODE)
Definition tree.h:1466
#define TYPE_STUB_DECL(NODE)
Definition tree.h:2358
#define RECORD_OR_UNION_TYPE_P(TYPE)
Definition tree.h:685
#define TYPE_MAIN_VARIANT(NODE)
Definition tree.h:2250
#define TREE_CODE(NODE)
Definition tree.h:324
#define IDENTIFIER_POINTER(NODE)
Definition tree.h:1196
#define TREE_PUBLIC(NODE)
Definition tree.h:857
#define TYPE_BINFO(NODE)
Definition tree.h:2555
#define DECL_ASSEMBLER_NAME_SET_P(NODE)
Definition tree.h:3205
#define NULL_TREE
Definition tree.h:317
#define BINFO_VTABLE(NODE)
Definition tree.h:2606
#define TYPE_CONTEXT(NODE)
Definition tree.h:2251