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
28 /* This field will have the samy value for any two nodes in the same strongly
29 connected component. */
33 struct cgraph_node
* next_cycle
;
37 /* Context of polymorphic call. This is used by ipa-devirt walkers of the
38 type inheritance graph. */
39 struct ipa_polymorphic_call_context
{
40 /* The called object appears in an object of type OUTER_TYPE
44 /* True if outer object may be in construction or destruction. */
45 bool maybe_in_construction
;
46 /* True if outer object may be of derived type. */
47 bool maybe_derived_type
;
50 /* Context representing "I know nothing". */
51 extern const ipa_polymorphic_call_context ipa_dummy_polymorphic_call_context
;
54 void ipa_print_order (FILE*, const char *, struct cgraph_node
**, int);
55 int ipa_reduced_postorder (struct cgraph_node
**, bool, bool,
56 bool (*ignore_edge
) (struct cgraph_edge
*));
57 void ipa_free_postorder_info (void);
58 vec
<cgraph_node_ptr
> ipa_get_nodes_in_cycle (struct cgraph_node
*);
59 bool ipa_edge_within_scc (struct cgraph_edge
*);
60 int ipa_reverse_postorder (struct cgraph_node
**);
61 tree
get_base_var (tree
);
62 void ipa_merge_profiles (struct cgraph_node
*dst
,
63 struct cgraph_node
*src
);
64 bool recursive_call_p (tree
, tree
);
66 /* In ipa-profile.c */
67 bool ipa_propagate_frequency (struct cgraph_node
*node
);
72 typedef odr_type_d
*odr_type
;
73 void build_type_inheritance_graph (void);
74 void update_type_inheritance_graph (void);
76 possible_polymorphic_call_targets (tree
, HOST_WIDE_INT
,
77 ipa_polymorphic_call_context
,
79 void **cache_token
= NULL
,
80 int *nonconstruction_targets
= NULL
);
81 odr_type
get_odr_type (tree
, bool insert
= false);
82 void dump_possible_polymorphic_call_targets (FILE *, tree
, HOST_WIDE_INT
,
83 const ipa_polymorphic_call_context
&);
84 bool possible_polymorphic_call_target_p (tree
, HOST_WIDE_INT
,
85 const ipa_polymorphic_call_context
&,
86 struct cgraph_node
*);
87 tree
method_class_type (const_tree
);
88 tree
get_polymorphic_call_info (tree
, tree
, tree
*,
90 ipa_polymorphic_call_context
*,
92 bool get_polymorphic_call_info_from_invariant (ipa_polymorphic_call_context
*,
93 tree
, tree
, HOST_WIDE_INT
);
94 bool decl_maybe_in_construction_p (tree
, tree
, gimple
, tree
);
95 tree
vtable_pointer_value_to_binfo (const_tree
);
96 bool vtable_pointer_value_to_vtable (const_tree
, tree
*, unsigned HOST_WIDE_INT
*);
97 bool contains_polymorphic_type_p (const_tree
);
99 /* Return vector containing possible targets of polymorphic call E.
100 If FINALP is non-NULL, store true if the list is complette.
101 CACHE_TOKEN (if non-NULL) will get stored to an unique ID of entry
102 in the target cache. If user needs to visit every target list
103 just once, it can memoize them.
105 Returned vector is placed into cache. It is NOT caller's responsibility
106 to free it. The vector can be freed on cgraph_remove_node call if
107 the particular node is a virtual function present in the cache. */
109 inline vec
<cgraph_node
*>
110 possible_polymorphic_call_targets (struct cgraph_edge
*e
,
112 void **cache_token
= NULL
,
113 int *nonconstruction_targets
= NULL
)
115 gcc_checking_assert (e
->indirect_info
->polymorphic
);
116 ipa_polymorphic_call_context context
= {e
->indirect_info
->offset
,
117 e
->indirect_info
->outer_type
,
118 e
->indirect_info
->maybe_in_construction
,
119 e
->indirect_info
->maybe_derived_type
};
120 return possible_polymorphic_call_targets (e
->indirect_info
->otr_type
,
121 e
->indirect_info
->otr_token
,
124 nonconstruction_targets
);
127 /* Same as above but taking OBJ_TYPE_REF as an parameter. */
129 inline vec
<cgraph_node
*>
130 possible_polymorphic_call_targets (tree ref
,
133 void **cache_token
= NULL
)
136 HOST_WIDE_INT otr_token
;
137 ipa_polymorphic_call_context context
;
139 get_polymorphic_call_info (current_function_decl
,
141 &otr_type
, &otr_token
, &context
, call
);
142 return possible_polymorphic_call_targets (obj_type_ref_class (ref
),
144 (OBJ_TYPE_REF_TOKEN (ref
)),
149 /* Dump possible targets of a polymorphic call E into F. */
152 dump_possible_polymorphic_call_targets (FILE *f
, struct cgraph_edge
*e
)
154 gcc_checking_assert (e
->indirect_info
->polymorphic
);
155 ipa_polymorphic_call_context context
= {e
->indirect_info
->offset
,
156 e
->indirect_info
->outer_type
,
157 e
->indirect_info
->maybe_in_construction
,
158 e
->indirect_info
->maybe_derived_type
};
159 dump_possible_polymorphic_call_targets (f
, e
->indirect_info
->otr_type
,
160 e
->indirect_info
->otr_token
,
164 /* Return true if N can be possibly target of a polymorphic call of
168 possible_polymorphic_call_target_p (struct cgraph_edge
*e
,
169 struct cgraph_node
*n
)
171 ipa_polymorphic_call_context context
= {e
->indirect_info
->offset
,
172 e
->indirect_info
->outer_type
,
173 e
->indirect_info
->maybe_in_construction
,
174 e
->indirect_info
->maybe_derived_type
};
175 return possible_polymorphic_call_target_p (e
->indirect_info
->otr_type
,
176 e
->indirect_info
->otr_token
,
180 /* Return true if N can be possibly target of a polymorphic call of
181 OBJ_TYPE_REF expression CALL. */
184 possible_polymorphic_call_target_p (tree call
,
185 struct cgraph_node
*n
)
187 return possible_polymorphic_call_target_p (obj_type_ref_class (call
),
189 (OBJ_TYPE_REF_TOKEN (call
)),
190 ipa_dummy_polymorphic_call_context
,
193 #endif /* GCC_IPA_UTILS_H */