* cgraph.h (class ipa_polymorphic_call_context): Move here from
[official-gcc.git] / gcc / ipa-utils.h
blob7ff29f8c147ee2f15b626adfaa603a59b52da7b4
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
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
23 #include "cgraph.h"
25 struct ipa_dfs_info {
26 int dfn_number;
27 int low_link;
28 /* This field will have the samy value for any two nodes in the same strongly
29 connected component. */
30 int scc_no;
31 bool new_node;
32 bool on_stack;
33 struct cgraph_node* next_cycle;
34 PTR aux;
38 /* In ipa-utils.c */
39 void ipa_print_order (FILE*, const char *, struct cgraph_node**, int);
40 int ipa_reduced_postorder (struct cgraph_node **, bool, bool,
41 bool (*ignore_edge) (struct cgraph_edge *));
42 void ipa_free_postorder_info (void);
43 vec<cgraph_node *> ipa_get_nodes_in_cycle (struct cgraph_node *);
44 bool ipa_edge_within_scc (struct cgraph_edge *);
45 int ipa_reverse_postorder (struct cgraph_node **);
46 tree get_base_var (tree);
47 void ipa_merge_profiles (struct cgraph_node *dst,
48 struct cgraph_node *src);
49 bool recursive_call_p (tree, tree);
51 /* In ipa-profile.c */
52 bool ipa_propagate_frequency (struct cgraph_node *node);
54 /* In ipa-devirt.c */
56 struct odr_type_d;
57 typedef odr_type_d *odr_type;
58 void build_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 int *nonconstruction_targets = NULL);
66 odr_type get_odr_type (tree, bool insert = false);
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 bool decl_maybe_in_construction_p (tree, tree, gimple, tree);
75 tree vtable_pointer_value_to_binfo (const_tree);
76 bool vtable_pointer_value_to_vtable (const_tree, tree *, unsigned HOST_WIDE_INT *);
77 void compare_virtual_tables (varpool_node *, varpool_node *);
78 bool contains_polymorphic_type_p (const_tree);
79 void register_odr_type (tree);
81 /* Return vector containing possible targets of polymorphic call E.
82 If COMPLETEP is non-NULL, store true if the list is complette.
83 CACHE_TOKEN (if non-NULL) will get stored to an unique ID of entry
84 in the target cache. If user needs to visit every target list
85 just once, it can memoize them.
87 Returned vector is placed into cache. It is NOT caller's responsibility
88 to free it. The vector can be freed on cgraph_remove_node call if
89 the particular node is a virtual function present in the cache. */
91 inline vec <cgraph_node *>
92 possible_polymorphic_call_targets (struct cgraph_edge *e,
93 bool *completep = NULL,
94 void **cache_token = NULL,
95 int *nonconstruction_targets = NULL)
97 ipa_polymorphic_call_context context(e);
99 return possible_polymorphic_call_targets (e->indirect_info->otr_type,
100 e->indirect_info->otr_token,
101 context,
102 completep, cache_token,
103 nonconstruction_targets);
106 /* Same as above but taking OBJ_TYPE_REF as an parameter. */
108 inline vec <cgraph_node *>
109 possible_polymorphic_call_targets (tree ref,
110 gimple call,
111 bool *completep = NULL,
112 void **cache_token = NULL)
114 ipa_polymorphic_call_context context (current_function_decl, ref, call);
116 return possible_polymorphic_call_targets (obj_type_ref_class (ref),
117 tree_to_uhwi
118 (OBJ_TYPE_REF_TOKEN (ref)),
119 context,
120 completep, cache_token);
123 /* Dump possible targets of a polymorphic call E into F. */
125 inline void
126 dump_possible_polymorphic_call_targets (FILE *f, struct cgraph_edge *e)
128 ipa_polymorphic_call_context context(e);
130 dump_possible_polymorphic_call_targets (f, e->indirect_info->otr_type,
131 e->indirect_info->otr_token,
132 context);
135 /* Return true if N can be possibly target of a polymorphic call of
136 E. */
138 inline bool
139 possible_polymorphic_call_target_p (struct cgraph_edge *e,
140 struct cgraph_node *n)
142 ipa_polymorphic_call_context context(e);
144 return possible_polymorphic_call_target_p (e->indirect_info->otr_type,
145 e->indirect_info->otr_token,
146 context, n);
149 /* Return true of T is type with One Definition Rule info attached.
150 It means that either it is anonymous type or it has assembler name
151 set. */
153 static inline bool
154 odr_type_p (const_tree t)
156 if (type_in_anonymous_namespace_p (t))
157 return true;
158 /* We do not have this information when not in LTO, but we do not need
159 to care, since it is used only for type merging. */
160 gcc_assert (in_lto_p || flag_lto);
162 return (TYPE_NAME (t)
163 && (DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (t))));
165 #endif /* GCC_IPA_UTILS_H */