1 /* Utilities for ipa analysis.
2 Copyright (C) 2004-2015 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
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
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
27 /* This field will have the samy value for any two nodes in the same strongly
28 connected component. */
32 struct cgraph_node
* next_cycle
;
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
);
56 typedef odr_type_d
*odr_type
;
57 void build_type_inheritance_graph (void);
58 void update_type_inheritance_graph (void);
60 possible_polymorphic_call_targets (tree
, HOST_WIDE_INT
,
61 ipa_polymorphic_call_context
,
62 bool *copletep
= NULL
,
63 void **cache_token
= NULL
,
64 bool speuclative
= false);
65 odr_type
get_odr_type (tree
, bool insert
= false);
66 bool odr_type_p (const_tree t
);
67 bool possible_polymorphic_call_target_p (tree ref
, gimple stmt
, struct cgraph_node
*n
);
68 void dump_possible_polymorphic_call_targets (FILE *, tree
, HOST_WIDE_INT
,
69 const ipa_polymorphic_call_context
&);
70 bool possible_polymorphic_call_target_p (tree
, HOST_WIDE_INT
,
71 const ipa_polymorphic_call_context
&,
72 struct cgraph_node
*);
73 tree
method_class_type (const_tree
);
74 tree
inlined_polymorphic_ctor_dtor_block_p (tree
, bool);
75 bool decl_maybe_in_construction_p (tree
, tree
, gimple
, tree
);
76 tree
vtable_pointer_value_to_binfo (const_tree
);
77 bool vtable_pointer_value_to_vtable (const_tree
, tree
*, unsigned HOST_WIDE_INT
*);
78 tree
subbinfo_with_vtable_at_offset (tree
, unsigned HOST_WIDE_INT
, tree
);
79 void compare_virtual_tables (varpool_node
*, varpool_node
*);
80 bool type_all_derivations_known_p (const_tree
);
81 bool type_known_to_have_no_deriavations_p (tree
);
82 bool contains_polymorphic_type_p (const_tree
);
83 void register_odr_type (tree
);
84 bool types_must_be_same_for_odr (tree
, tree
);
85 bool types_odr_comparable (tree
, tree
, bool strict
= false);
86 cgraph_node
*try_speculative_devirtualization (tree
, HOST_WIDE_INT
,
87 ipa_polymorphic_call_context
);
89 /* Return vector containing possible targets of polymorphic call E.
90 If COMPLETEP is non-NULL, store true if the list is complete.
91 CACHE_TOKEN (if non-NULL) will get stored to an unique ID of entry
92 in the target cache. If user needs to visit every target list
93 just once, it can memoize them.
95 Returned vector is placed into cache. It is NOT caller's responsibility
96 to free it. The vector can be freed on cgraph_remove_node call if
97 the particular node is a virtual function present in the cache. */
99 inline vec
<cgraph_node
*>
100 possible_polymorphic_call_targets (struct cgraph_edge
*e
,
101 bool *completep
= NULL
,
102 void **cache_token
= NULL
,
103 bool speculative
= false)
105 ipa_polymorphic_call_context
context(e
);
107 return possible_polymorphic_call_targets (e
->indirect_info
->otr_type
,
108 e
->indirect_info
->otr_token
,
110 completep
, cache_token
,
114 /* Same as above but taking OBJ_TYPE_REF as an parameter. */
116 inline vec
<cgraph_node
*>
117 possible_polymorphic_call_targets (tree ref
,
119 bool *completep
= NULL
,
120 void **cache_token
= NULL
)
122 ipa_polymorphic_call_context
context (current_function_decl
, ref
, call
);
124 return possible_polymorphic_call_targets (obj_type_ref_class (ref
),
126 (OBJ_TYPE_REF_TOKEN (ref
)),
128 completep
, cache_token
);
131 /* Dump possible targets of a polymorphic call E into F. */
134 dump_possible_polymorphic_call_targets (FILE *f
, struct cgraph_edge
*e
)
136 ipa_polymorphic_call_context
context(e
);
138 dump_possible_polymorphic_call_targets (f
, e
->indirect_info
->otr_type
,
139 e
->indirect_info
->otr_token
,
143 /* Return true if N can be possibly target of a polymorphic call of
147 possible_polymorphic_call_target_p (struct cgraph_edge
*e
,
148 struct cgraph_node
*n
)
150 ipa_polymorphic_call_context
context(e
);
152 return possible_polymorphic_call_target_p (e
->indirect_info
->otr_type
,
153 e
->indirect_info
->otr_token
,
157 /* Return true if BINFO corresponds to a type with virtual methods.
159 Every type has several BINFOs. One is the BINFO associated by the type
160 while other represents bases of derived types. The BINFOs representing
161 bases do not have BINFO_VTABLE pointer set when this is the single
162 inheritance (because vtables are shared). Look up the BINFO of type
163 and check presence of its vtable. */
166 polymorphic_type_binfo_p (const_tree binfo
)
168 /* See if BINFO's type has an virtual table associtated with it.
169 Check is defensive because of Java FE produces BINFOs
170 without BINFO_TYPE set. */
171 return (BINFO_TYPE (binfo
) && TYPE_BINFO (BINFO_TYPE (binfo
))
172 && BINFO_VTABLE (TYPE_BINFO (BINFO_TYPE (binfo
))));
174 #endif /* GCC_IPA_UTILS_H */