PR testsuite/85483: Move aarch64/sve/vcond_1.c test to g++.dg/other/
[official-gcc.git] / gcc / ipa-utils.h
blob1609ac14d7fbea5da73cc5f6806807d7fbe4ff91
1 /* Utilities for ipa analysis.
2 Copyright (C) 2004-2018 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 PTR aux;
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, 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);
50 /* In ipa-profile.c */
51 bool ipa_propagate_frequency (struct cgraph_node *node);
53 /* In ipa-devirt.c */
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 possible_polymorphic_call_target_p (tree, HOST_WIDE_INT,
72 const ipa_polymorphic_call_context &,
73 struct cgraph_node *);
74 tree polymorphic_ctor_dtor_p (tree, bool);
75 tree inlined_polymorphic_ctor_dtor_block_p (tree, bool);
76 bool decl_maybe_in_construction_p (tree, tree, gimple *, tree);
77 tree vtable_pointer_value_to_binfo (const_tree);
78 bool vtable_pointer_value_to_vtable (const_tree, tree *, unsigned HOST_WIDE_INT *);
79 tree subbinfo_with_vtable_at_offset (tree, unsigned HOST_WIDE_INT, tree);
80 void compare_virtual_tables (varpool_node *, varpool_node *);
81 bool type_all_derivations_known_p (const_tree);
82 bool type_known_to_have_no_derivations_p (tree);
83 bool contains_polymorphic_type_p (const_tree);
84 void register_odr_type (tree);
85 bool types_must_be_same_for_odr (tree, tree);
86 bool types_odr_comparable (tree, tree, bool strict = false);
87 cgraph_node *try_speculative_devirtualization (tree, HOST_WIDE_INT,
88 ipa_polymorphic_call_context);
89 void warn_types_mismatch (tree t1, tree t2, location_t loc1 = UNKNOWN_LOCATION,
90 location_t loc2 = UNKNOWN_LOCATION);
91 bool odr_or_derived_type_p (const_tree t);
92 bool odr_types_equivalent_p (tree type1, tree type2);
94 /* Return vector containing possible targets of polymorphic call E.
95 If COMPLETEP is non-NULL, store true if the list is complete.
96 CACHE_TOKEN (if non-NULL) will get stored to an unique ID of entry
97 in the target cache. If user needs to visit every target list
98 just once, it can memoize them.
100 Returned vector is placed into cache. It is NOT caller's responsibility
101 to free it. The vector can be freed on cgraph_remove_node call if
102 the particular node is a virtual function present in the cache. */
104 inline vec <cgraph_node *>
105 possible_polymorphic_call_targets (struct cgraph_edge *e,
106 bool *completep = NULL,
107 void **cache_token = NULL,
108 bool speculative = false)
110 ipa_polymorphic_call_context context(e);
112 return possible_polymorphic_call_targets (e->indirect_info->otr_type,
113 e->indirect_info->otr_token,
114 context,
115 completep, cache_token,
116 speculative);
119 /* Same as above but taking OBJ_TYPE_REF as an parameter. */
121 inline vec <cgraph_node *>
122 possible_polymorphic_call_targets (tree ref,
123 gimple *call,
124 bool *completep = NULL,
125 void **cache_token = NULL)
127 ipa_polymorphic_call_context context (current_function_decl, ref, call);
129 return possible_polymorphic_call_targets (obj_type_ref_class (ref),
130 tree_to_uhwi
131 (OBJ_TYPE_REF_TOKEN (ref)),
132 context,
133 completep, cache_token);
136 /* Dump possible targets of a polymorphic call E into F. */
138 inline void
139 dump_possible_polymorphic_call_targets (FILE *f, struct cgraph_edge *e)
141 ipa_polymorphic_call_context context(e);
143 dump_possible_polymorphic_call_targets (f, e->indirect_info->otr_type,
144 e->indirect_info->otr_token,
145 context);
148 /* Return true if N can be possibly target of a polymorphic call of
149 E. */
151 inline bool
152 possible_polymorphic_call_target_p (struct cgraph_edge *e,
153 struct cgraph_node *n)
155 ipa_polymorphic_call_context context(e);
157 return possible_polymorphic_call_target_p (e->indirect_info->otr_type,
158 e->indirect_info->otr_token,
159 context, n);
162 /* Return true if BINFO corresponds to a type with virtual methods.
164 Every type has several BINFOs. One is the BINFO associated by the type
165 while other represents bases of derived types. The BINFOs representing
166 bases do not have BINFO_VTABLE pointer set when this is the single
167 inheritance (because vtables are shared). Look up the BINFO of type
168 and check presence of its vtable. */
170 inline bool
171 polymorphic_type_binfo_p (const_tree binfo)
173 return (BINFO_TYPE (binfo) && TYPE_BINFO (BINFO_TYPE (binfo))
174 && BINFO_VTABLE (TYPE_BINFO (BINFO_TYPE (binfo))));
177 /* Return true if T is a type with linkage defined. */
179 inline bool
180 type_with_linkage_p (const_tree t)
182 if (!TYPE_NAME (t) || TREE_CODE (TYPE_NAME (t)) != TYPE_DECL
183 || !TYPE_STUB_DECL (t))
184 return false;
185 /* In LTO do not get confused by non-C++ produced types or types built
186 with -fno-lto-odr-type-merigng. */
187 if (in_lto_p)
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 /* With -flto-odr-type-merging C++ FE specify mangled names
195 for all types with the linkage. */
196 return DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (t));
199 if (!RECORD_OR_UNION_TYPE_P (t) && TREE_CODE (t) != ENUMERAL_TYPE)
200 return false;
202 /* Builtin types do not define linkage, their TYPE_CONTEXT is NULL. */
203 if (!TYPE_CONTEXT (t))
204 return false;
206 return true;
209 /* Return true if T is in anonymous namespace.
210 This works only on those C++ types with linkage defined. */
212 inline bool
213 type_in_anonymous_namespace_p (const_tree t)
215 gcc_checking_assert (type_with_linkage_p (t));
217 if (!TREE_PUBLIC (TYPE_STUB_DECL (t)))
219 /* C++ FE uses magic <anon> as assembler names of anonymous types.
220 verify that this match with type_in_anonymous_namespace_p. */
221 gcc_checking_assert (!in_lto_p
222 || !DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (t))
223 || !strcmp ("<anon>",
224 IDENTIFIER_POINTER
225 (DECL_ASSEMBLER_NAME (TYPE_NAME (t)))));
226 return true;
228 return false;
231 /* Return true of T is type with One Definition Rule info attached.
232 It means that either it is anonymous type or it has assembler name
233 set. */
235 inline bool
236 odr_type_p (const_tree t)
238 /* We do not have this information when not in LTO, but we do not need
239 to care, since it is used only for type merging. */
240 gcc_checking_assert (in_lto_p || flag_lto);
242 if (!type_with_linkage_p (t))
243 return false;
245 /* To support -fno-lto-odr-type-merging consider types with vtables ODR. */
246 if (type_in_anonymous_namespace_p (t))
247 return true;
249 if (TYPE_NAME (t) && DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (t)))
251 /* C++ FE uses magic <anon> as assembler names of anonymous types.
252 verify that this match with type_in_anonymous_namespace_p. */
253 gcc_checking_assert (strcmp ("<anon>",
254 IDENTIFIER_POINTER
255 (DECL_ASSEMBLER_NAME (TYPE_NAME (t)))));
256 return true;
258 return false;
261 #endif /* GCC_IPA_UTILS_H */