[ARM/AArch64][testsuite] Add vmull tests.
[gcc.git] / gcc / symbol-summary.h
1 /* Callgraph summary data structure.
2 Copyright (C) 2014-2015 Free Software Foundation, Inc.
3 Contributed by Martin Liska
4
5 This file is part of GCC.
6
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.
11
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.
16
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/>. */
20
21 #ifndef GCC_SYMBOL_SUMMARY_H
22 #define GCC_SYMBOL_SUMMARY_H
23
24 /* We want to pass just pointer types as argument for function_summary
25 template class. */
26
27 template <class T>
28 class function_summary
29 {
30 private:
31 function_summary();
32 };
33
34 template <class T>
35 class GTY((user)) function_summary <T *>
36 {
37 public:
38 /* Default construction takes SYMTAB as an argument. */
39 function_summary (symbol_table *symtab, bool ggc = false): m_ggc (ggc),
40 m_map (13, ggc), m_insertion_enabled (true), m_symtab (symtab)
41 {
42 #ifdef ENABLE_CHECKING
43 cgraph_node *node;
44
45 FOR_EACH_FUNCTION (node)
46 {
47 gcc_checking_assert (node->summary_uid > 0);
48 }
49 #endif
50
51 m_symtab_insertion_hook =
52 symtab->add_cgraph_insertion_hook
53 (function_summary::symtab_insertion, this);
54
55 m_symtab_removal_hook =
56 symtab->add_cgraph_removal_hook
57 (function_summary::symtab_removal, this);
58 m_symtab_duplication_hook =
59 symtab->add_cgraph_duplication_hook
60 (function_summary::symtab_duplication, this);
61 }
62
63 /* Destructor. */
64 virtual ~function_summary ()
65 {
66 release ();
67 }
68
69 /* Destruction method that can be called for GGT purpose. */
70 void release ()
71 {
72 if (m_symtab_insertion_hook)
73 m_symtab->remove_cgraph_insertion_hook (m_symtab_insertion_hook);
74
75 if (m_symtab_removal_hook)
76 m_symtab->remove_cgraph_removal_hook (m_symtab_removal_hook);
77
78 if (m_symtab_duplication_hook)
79 m_symtab->remove_cgraph_duplication_hook (m_symtab_duplication_hook);
80
81 m_symtab_insertion_hook = NULL;
82 m_symtab_removal_hook = NULL;
83 m_symtab_duplication_hook = NULL;
84 }
85
86 /* Traverses all summarys with a function F called with
87 ARG as argument. */
88 template<typename Arg, bool (*f)(const T &, Arg)>
89 void traverse (Arg a) const
90 {
91 m_map.traverse <f> (a);
92 }
93
94 /* Basic implementation of insert operation. */
95 virtual void insert (cgraph_node *, T *) {}
96
97 /* Basic implementation of removal operation. */
98 virtual void remove (cgraph_node *, T *) {}
99
100 /* Basic implementation of duplication operation. */
101 virtual void duplicate (cgraph_node *, cgraph_node *, T *, T *) {}
102
103 /* Allocates new data that are stored within map. */
104 T* allocate_new ()
105 {
106 return m_ggc ? new (ggc_alloc <T> ()) T() : new T () ;
107 }
108
109 /* Getter for summary callgraph node pointer. */
110 T* get (cgraph_node *node)
111 {
112 return get (node->summary_uid);
113 }
114
115 /* Return number of elements handled by data structure. */
116 size_t elements ()
117 {
118 return m_map.elements ();
119 }
120
121 /* Enable insertion hook invocation. */
122 void enable_insertion_hook ()
123 {
124 m_insertion_enabled = true;
125 }
126
127 /* Enable insertion hook invocation. */
128 void disable_insertion_hook ()
129 {
130 m_insertion_enabled = false;
131 }
132
133 /* Symbol insertion hook that is registered to symbol table. */
134 static void symtab_insertion (cgraph_node *node, void *data)
135 {
136 function_summary *summary = (function_summary <T *> *) (data);
137
138 if (summary->m_insertion_enabled)
139 summary->insert (node, summary->get (node));
140 }
141
142 /* Symbol removal hook that is registered to symbol table. */
143 static void symtab_removal (cgraph_node *node, void *data)
144 {
145 gcc_checking_assert (node->summary_uid);
146 function_summary *summary = (function_summary <T *> *) (data);
147
148 int summary_uid = node->summary_uid;
149 T **v = summary->m_map.get (summary_uid);
150
151 if (v)
152 {
153 summary->remove (node, *v);
154
155 if (!summary->m_ggc)
156 delete (*v);
157
158 summary->m_map.remove (summary_uid);
159 }
160 }
161
162 /* Symbol duplication hook that is registered to symbol table. */
163 static void symtab_duplication (cgraph_node *node, cgraph_node *node2,
164 void *data)
165 {
166 function_summary *summary = (function_summary <T *> *) (data);
167 T **v = summary->m_map.get (node->summary_uid);
168
169 gcc_checking_assert (node2->summary_uid > 0);
170
171 if (v)
172 {
173 /* This load is necessary, because we insert a new value! */
174 T *data = *v;
175 T *duplicate = summary->allocate_new ();
176 summary->m_map.put (node2->summary_uid, duplicate);
177 summary->duplicate (node, node2, data, duplicate);
178 }
179 }
180
181 protected:
182 /* Indication if we use ggc summary. */
183 bool m_ggc;
184
185 private:
186 struct summary_hashmap_traits: default_hashmap_traits
187 {
188 static const int deleted_value = -1;
189 static const int empty_value = 0;
190
191 static hashval_t
192 hash (const int v)
193 {
194 return (hashval_t)v;
195 }
196
197 template<typename Type>
198 static bool
199 is_deleted (Type &e)
200 {
201 return e.m_key == deleted_value;
202 }
203
204 template<typename Type>
205 static bool
206 is_empty (Type &e)
207 {
208 return e.m_key == empty_value;
209 }
210
211 template<typename Type>
212 static void
213 mark_deleted (Type &e)
214 {
215 e.m_key = deleted_value;
216 }
217
218 template<typename Type>
219 static void
220 mark_empty (Type &e)
221 {
222 e.m_key = empty_value;
223 }
224 };
225
226 /* Getter for summary callgraph ID. */
227 T* get (int uid)
228 {
229 bool existed;
230 T **v = &m_map.get_or_insert (uid, &existed);
231 if (!existed)
232 *v = allocate_new ();
233
234 return *v;
235 }
236
237 /* Main summary store, where summary ID is used as key. */
238 hash_map <int, T *, summary_hashmap_traits> m_map;
239 /* Internal summary insertion hook pointer. */
240 cgraph_node_hook_list *m_symtab_insertion_hook;
241 /* Internal summary removal hook pointer. */
242 cgraph_node_hook_list *m_symtab_removal_hook;
243 /* Internal summary duplication hook pointer. */
244 cgraph_2node_hook_list *m_symtab_duplication_hook;
245 /* Indicates if insertion hook is enabled. */
246 bool m_insertion_enabled;
247 /* Symbol table the summary is registered to. */
248 symbol_table *m_symtab;
249
250 template <typename U> friend void gt_ggc_mx (function_summary <U *> * const &);
251 template <typename U> friend void gt_pch_nx (function_summary <U *> * const &);
252 template <typename U> friend void gt_pch_nx (function_summary <U *> * const &,
253 gt_pointer_operator, void *);
254 };
255
256 template <typename T>
257 void
258 gt_ggc_mx(function_summary<T *>* const &summary)
259 {
260 gcc_checking_assert (summary->m_ggc);
261 gt_ggc_mx (&summary->m_map);
262 }
263
264 template <typename T>
265 void
266 gt_pch_nx(function_summary<T *>* const &summary)
267 {
268 gcc_checking_assert (summary->m_ggc);
269 gt_pch_nx (&summary->m_map);
270 }
271
272 template <typename T>
273 void
274 gt_pch_nx(function_summary<T *>* const& summary, gt_pointer_operator op,
275 void *cookie)
276 {
277 gcc_checking_assert (summary->m_ggc);
278 gt_pch_nx (&summary->m_map, op, cookie);
279 }
280
281 #endif /* GCC_SYMBOL_SUMMARY_H */