1 /* Utilities for ipa analysis.
2 Copyright (C) 2004-2014 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
25 /* Used for parsing attributes of asm code. */
26 extern tree memory_identifier_string
;
27 extern tree
get_memory_identifier_string (void);
32 /* This field will have the samy value for any two nodes in the same strongly
33 connected component. */
37 struct cgraph_node
* next_cycle
;
41 /* Context of polymorphic call. This is used by ipa-devirt walkers of the
42 type inheritance graph. */
43 struct ipa_polymorphic_call_context
{
44 /* The called object appears in an object of type OUTER_TYPE
45 at offset OFFSET. When information is not 100% reliable, we
46 use SPECULATIVE_OUTER_TYPE and SPECULATIVE_OFFSET. */
48 HOST_WIDE_INT speculative_offset
;
50 tree speculative_outer_type
;
51 /* True if outer object may be in construction or destruction. */
52 bool maybe_in_construction
;
53 /* True if outer object may be of derived type. */
54 bool maybe_derived_type
;
55 /* True if speculative outer object may be of derived type. We always
56 speculate that construction does not happen. */
57 bool speculative_maybe_derived_type
;
60 /* Context representing "I know nothing". */
61 extern const ipa_polymorphic_call_context ipa_dummy_polymorphic_call_context
;
64 void ipa_print_order (FILE*, const char *, struct cgraph_node
**, int);
65 int ipa_reduced_postorder (struct cgraph_node
**, bool, bool,
66 bool (*ignore_edge
) (struct cgraph_edge
*));
67 void ipa_free_postorder_info (void);
68 vec
<cgraph_node
*> ipa_get_nodes_in_cycle (struct cgraph_node
*);
69 bool ipa_edge_within_scc (struct cgraph_edge
*);
70 int ipa_reverse_postorder (struct cgraph_node
**);
71 tree
get_base_var (tree
);
72 void ipa_merge_profiles (struct cgraph_node
*dst
,
73 struct cgraph_node
*src
);
74 bool recursive_call_p (tree
, tree
);
76 /* In ipa-profile.c */
77 bool ipa_propagate_frequency (struct cgraph_node
*node
);
82 typedef odr_type_d
*odr_type
;
83 void build_type_inheritance_graph (void);
84 void update_type_inheritance_graph (void);
86 possible_polymorphic_call_targets (tree
, HOST_WIDE_INT
,
87 ipa_polymorphic_call_context
,
89 void **cache_token
= NULL
,
90 int *nonconstruction_targets
= NULL
);
91 odr_type
get_odr_type (tree
, bool insert
= false);
92 void dump_possible_polymorphic_call_targets (FILE *, tree
, HOST_WIDE_INT
,
93 const ipa_polymorphic_call_context
&);
94 bool possible_polymorphic_call_target_p (tree
, HOST_WIDE_INT
,
95 const ipa_polymorphic_call_context
&,
96 struct cgraph_node
*);
97 tree
method_class_type (const_tree
);
98 tree
get_polymorphic_call_info (tree
, tree
, tree
*,
100 ipa_polymorphic_call_context
*,
102 bool get_dynamic_type (tree
, ipa_polymorphic_call_context
*, tree
, gimple
);
103 bool get_polymorphic_call_info_from_invariant (ipa_polymorphic_call_context
*,
104 tree
, tree
, HOST_WIDE_INT
);
105 bool decl_maybe_in_construction_p (tree
, tree
, gimple
, tree
);
106 tree
vtable_pointer_value_to_binfo (const_tree
);
107 bool vtable_pointer_value_to_vtable (const_tree
, tree
*, unsigned HOST_WIDE_INT
*);
108 bool contains_polymorphic_type_p (const_tree
);
110 /* Return vector containing possible targets of polymorphic call E.
111 If FINALP is non-NULL, store true if the list is complette.
112 CACHE_TOKEN (if non-NULL) will get stored to an unique ID of entry
113 in the target cache. If user needs to visit every target list
114 just once, it can memoize them.
116 Returned vector is placed into cache. It is NOT caller's responsibility
117 to free it. The vector can be freed on cgraph_remove_node call if
118 the particular node is a virtual function present in the cache. */
120 inline vec
<cgraph_node
*>
121 possible_polymorphic_call_targets (struct cgraph_edge
*e
,
123 void **cache_token
= NULL
,
124 int *nonconstruction_targets
= NULL
)
126 gcc_checking_assert (e
->indirect_info
->polymorphic
);
127 ipa_polymorphic_call_context context
= {e
->indirect_info
->offset
,
128 e
->indirect_info
->speculative_offset
,
129 e
->indirect_info
->outer_type
,
130 e
->indirect_info
->speculative_outer_type
,
131 e
->indirect_info
->maybe_in_construction
,
132 e
->indirect_info
->maybe_derived_type
,
133 e
->indirect_info
->speculative_maybe_derived_type
};
134 return possible_polymorphic_call_targets (e
->indirect_info
->otr_type
,
135 e
->indirect_info
->otr_token
,
138 nonconstruction_targets
);
141 /* Same as above but taking OBJ_TYPE_REF as an parameter. */
143 inline vec
<cgraph_node
*>
144 possible_polymorphic_call_targets (tree ref
,
147 void **cache_token
= NULL
)
150 HOST_WIDE_INT otr_token
;
151 ipa_polymorphic_call_context context
;
153 get_polymorphic_call_info (current_function_decl
,
155 &otr_type
, &otr_token
, &context
, call
);
156 return possible_polymorphic_call_targets (obj_type_ref_class (ref
),
158 (OBJ_TYPE_REF_TOKEN (ref
)),
163 /* Dump possible targets of a polymorphic call E into F. */
166 dump_possible_polymorphic_call_targets (FILE *f
, struct cgraph_edge
*e
)
168 gcc_checking_assert (e
->indirect_info
->polymorphic
);
169 ipa_polymorphic_call_context context
= {e
->indirect_info
->offset
,
170 e
->indirect_info
->speculative_offset
,
171 e
->indirect_info
->outer_type
,
172 e
->indirect_info
->speculative_outer_type
,
173 e
->indirect_info
->maybe_in_construction
,
174 e
->indirect_info
->maybe_derived_type
,
175 e
->indirect_info
->speculative_maybe_derived_type
};
176 dump_possible_polymorphic_call_targets (f
, e
->indirect_info
->otr_type
,
177 e
->indirect_info
->otr_token
,
181 /* Return true if N can be possibly target of a polymorphic call of
185 possible_polymorphic_call_target_p (struct cgraph_edge
*e
,
186 struct cgraph_node
*n
)
188 ipa_polymorphic_call_context context
= {e
->indirect_info
->offset
, 0,
189 e
->indirect_info
->outer_type
, NULL
,
190 e
->indirect_info
->maybe_in_construction
,
191 e
->indirect_info
->maybe_derived_type
,
193 return possible_polymorphic_call_target_p (e
->indirect_info
->otr_type
,
194 e
->indirect_info
->otr_token
,
198 /* Return true if N can be possibly target of a polymorphic call of
199 OBJ_TYPE_REF expression CALL. */
202 possible_polymorphic_call_target_p (tree call
,
203 struct cgraph_node
*n
)
205 return possible_polymorphic_call_target_p (obj_type_ref_class (call
),
207 (OBJ_TYPE_REF_TOKEN (call
)),
208 ipa_dummy_polymorphic_call_context
,
211 #endif /* GCC_IPA_UTILS_H */