]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/lto/lto-dump.c
Fix a typo in two_value_replacement function
[thirdparty/gcc.git] / gcc / lto / lto-dump.c
CommitLineData
66d62d9f
HK
1/* Functions for LTO dump tool.
2 Copyright (C) 2018-2019 Free Software Foundation, Inc.
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8Software Foundation; either version 3, or (at your option) any later
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
19
20#include "config.h"
21#include "system.h"
22#include "coretypes.h"
23#include "tm.h"
24#include "function.h"
25#include "basic-block.h"
26#include "tree.h"
27#include "gimple.h"
28#include "cfg.h"
29#include "tree-cfg.h"
30#include "tree-pass.h"
31#include "tree-streamer.h"
32#include "cgraph.h"
33#include "opts.h"
34#include "debug.h"
35#include "lto-partition.h"
36#include "tree-pretty-print.h"
37#include "lto-common.h"
38
39/* Stores details of symbols for dumping symbol list. */
40
41struct symbol_entry
42{
43 symtab_node *node;
44 symbol_entry (symtab_node *node_): node (node_)
45 {}
46
47 char* get_name () const
48 {
49 if (flag_lto_dump_demangle)
50 return xstrdup (node->name ());
51 else
52 return xstrdup (node->asm_name ());
53 }
54
55 virtual size_t get_size () const = 0;
56
57 virtual void dump ()
58 {
59 const char *name = get_name ();
60 const char *type_name = node->get_symtab_type_string ();
61 const char *visibility = node->get_visibility_string ();
62 size_t sz = get_size ();
63 printf ("%s %s %4lu %s ", type_name, visibility, sz, name);
64 }
65};
66
67/* Stores variable specific details of symbols for dumping symbol list. */
68
69struct variable_entry: public symbol_entry
70{
71 variable_entry (varpool_node *node_): symbol_entry (node_)
72 {}
73
74 virtual size_t get_size () const
75 {
76 varpool_node *vnode = dyn_cast<varpool_node *> (node);
77 if (DECL_SIZE (vnode->decl) && tree_fits_shwi_p (DECL_SIZE (vnode->decl)))
78 return tree_to_shwi (DECL_SIZE (vnode->decl));
79 return 0;
80 }
81
82 virtual void dump ()
83 {
84 symbol_entry :: dump ();
85 varpool_node *vnode = dyn_cast<varpool_node *> (node);
86 vnode->get_constructor ();
87 tree value_tree = DECL_INITIAL (vnode->decl);
88 if (flag_lto_print_value && value_tree)
89 print_generic_expr (stdout, value_tree, TDF_NONE);
90 printf ("\n");
91 }
92};
93
94/* Stores function specific details of symbols for dumping symbol list. */
95
96struct function_entry: public symbol_entry
97{
98 function_entry (cgraph_node *node_): symbol_entry (node_)
99 {}
100
101 virtual void dump ()
102 {
103 symbol_entry :: dump ();
104 printf ("\n");
105 }
106
107 virtual size_t get_size () const
108 {
109 cgraph_node *cnode = dyn_cast<cgraph_node *> (node);
110 gcc_assert (cnode);
111
112 return (cnode->definition)
113 ? n_basic_blocks_for_fn (DECL_STRUCT_FUNCTION (cnode->decl))
114 : 0;
115 }
116};
117
118/* Comparing symbols based on size. */
119
120int size_compare (const void *a, const void *b)
121{
122 const symbol_entry *e1 = *(const symbol_entry * const*) a;
123 const symbol_entry *e2 = *(const symbol_entry * const*) b;
124
125 return e1->get_size () - e2->get_size ();
126}
127
128/* Comparing symbols based on name. */
129
130int name_compare (const void *a, const void *b)
131{
132 const symbol_entry *e1 = *(const symbol_entry * const*) a;
133 const symbol_entry *e2 = *(const symbol_entry * const*) b;
134
135 return strcmp (e1->get_name (), e2->get_name ());
136}
137
138/* Dump list of functions and their details. */
139
140void dump_list_functions (void)
141{
142 auto_vec<symbol_entry *> v;
143
144 cgraph_node *cnode;
145 FOR_EACH_FUNCTION (cnode)
146 {
147 if (cnode->definition)
148 cnode->get_untransformed_body ();
149 symbol_entry *e = new function_entry (cnode);
150 if (!flag_lto_dump_defined || cnode->definition)
151 v.safe_push (e);
152 }
153
154 if (flag_lto_size_sort)
155 v.qsort (size_compare);
156 else if (flag_lto_name_sort)
157 v.qsort (name_compare);
158 if (flag_lto_reverse_sort)
159 v.reverse ();
160
161 printf ("Type Visibility Size Name");
162 if (flag_lto_print_value)
163 printf (" Value");
164 printf ("\n");
165 int i=0;
166 symbol_entry* e;
167 FOR_EACH_VEC_ELT (v, i, e)
168 e->dump ();
169}
170
171/* Dump list of variables and their details. */
172
173void dump_list_variables (void)
174{
175 auto_vec<symbol_entry *> v;
176
177 varpool_node *vnode;
178 FOR_EACH_VARIABLE (vnode)
179 {
180 symbol_entry *e = new variable_entry (vnode);
181 if (!flag_lto_dump_defined || vnode->definition)
182 v.safe_push (e);
183 }
184
185 if (flag_lto_size_sort)
186 v.qsort (size_compare);
187 else if (flag_lto_name_sort)
188 v.qsort (name_compare);
189 if (flag_lto_reverse_sort)
190 v.reverse ();
191
192 printf ("\n");
193 int i=0;
194 symbol_entry* e;
195 FOR_EACH_VEC_ELT (v, i, e)
196 e->dump ();
197}
198
199/* Dump symbol list. */
200
201void dump_list (void)
202{
203 dump_list_functions ();
204 dump_list_variables ();
205 return;
206}
207
208/* Dump specific variables and functions used in IL. */
209void dump_symbol ()
210{
211 symtab_node *node;
212 printf ("Symbol: %s\n", flag_lto_dump_symbol);
213 FOR_EACH_SYMBOL (node)
214 {
215 if (!strcmp (flag_lto_dump_symbol, node->name ()))
216 {
217 node->debug ();
218 printf ("\n");
219 }
220 }
221 return;
222}
223
224/* Dump specific gimple body of specified function. */
225void dump_body ()
226{
227 int flag = 0;
228 dump_flags_t flags = TDF_NONE;
229 if (flag_dump_level)
230 flags = parse_dump_option (flag_dump_level, NULL);
231 if (flags == TDF_ERROR)
232 {
233 error_at (input_location, "Level not found, use none, slim, blocks, vops.");
234 return;
235 }
236 cgraph_node *cnode;
237 FOR_EACH_FUNCTION (cnode)
238 if (cnode->definition && !strcmp (cnode->name (), flag_dump_body))
239 {
240 printf ("Gimple Body of Function: %s\n", cnode->name ());
241 cnode->get_untransformed_body ();
242 debug_function (cnode->decl, flags);
243 flag = 1;
244 }
245 if (!flag)
246 error_at (input_location, "Function not found.");
247 return;
248}
249
250/* List of command line options for dumping. */
251void dump_tool_help ()
252{
253 printf ("Usage: lto-dump [OPTION]... SUB_COMMAND [OPTION]...\n\n");
254 printf ("LTO dump tool command line options.\n\n");
255 printf (" -list [options] Dump the symbol list.\n");
256 printf (" -demangle Dump the demangled output.\n");
257 printf (" -defined-only Dump only the defined symbols.\n");
258 printf (" -print-value Dump initial values of the "
259 "variables.\n");
260 printf (" -name-sort Sort the symbols alphabetically.\n");
261 printf (" -size-sort Sort the symbols according to size.\n");
262 printf (" -reverse-sort Dump the symbols in reverse order.\n");
263 printf (" -symbol= Dump the details of specific symbol.\n");
264 printf (" -objects Dump the details of LTO objects.\n");
265 printf (" -type-stats Dump statistics of tree types.\n");
266 printf (" -tree-stats Dump statistics of trees.\n");
267 printf (" -gimple-stats Dump statistics of gimple "
268 "statements.\n");
269 printf (" -dump-body= Dump the specific gimple body.\n");
270 printf (" -dump-level= Deciding the optimization level "
271 "of body.\n");
272 printf (" -help Display the dump tool help.\n");
273 return;
274}
275
276unsigned int
277lto_option_lang_mask (void)
278{
279 return CL_LTODump;
280}
281
282/* Functions for dumping various details in LTO dump tool are called
283 in lto_main(). The purpose of this dump tool is to analyze the LTO
284 object files. */
285
286void
287lto_main (void)
288{
289 quiet_flag = true;
290 if (flag_lto_dump_tool_help)
291 dump_tool_help ();
292
293 /* LTO is called as a front end, even though it is not a front end.
294 Because it is called as a front end, TV_PHASE_PARSING and
295 TV_PARSE_GLOBAL are active, and we need to turn them off while
296 doing LTO. Later we turn them back on so they are active up in
297 toplev.c. */
298
299 /* Initialize the LTO front end. */
300 lto_fe_init ();
301 g_timer = NULL;
302 /* Read all the symbols and call graph from all the files in the
303 command line. */
304 read_cgraph_and_symbols (num_in_fnames, in_fnames);
305
306 /* Dump symbol list. */
307 if (flag_lto_dump_list)
308 dump_list ();
309 else if (flag_lto_dump_symbol)
310 {
311 /* Dump specific variables and functions used in IL. */
312 dump_symbol ();
313 }
314 else if (flag_lto_gimple_stats)
315 {
316 /* Dump gimple statement statistics. */
317 cgraph_node *node;
318 FOR_EACH_DEFINED_FUNCTION (node)
319 node->get_untransformed_body ();
320 if (!GATHER_STATISTICS)
321 warning_at (input_location, 0,
322 "Not configured with --enable-gather-detailed-mem-stats.");
323 else
324 dump_gimple_statistics ();
325 }
326 else if (flag_lto_tree_stats)
327 {
328 /* Dump tree statistics. */
329 if (!GATHER_STATISTICS)
330 warning_at (input_location, 0,
331 "Not configured with --enable-gather-detailed-mem-stats.");
332 else
333 {
334 printf ("Tree Statistics\n");
335 dump_tree_statistics ();
336 }
337 }
338 else if (flag_dump_body)
339 {
340 /* Dump specific gimple body of specified function. */
341 dump_body ();
342 return;
343 }
344}