]>
git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/lto/lto-dump.c
e9de33cf5d81227a3d5f08dd215150c1bd1fcaf1
1 /* Functions for LTO dump tool.
2 Copyright (C) 2018-2019 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
22 #include "coretypes.h"
25 #include "basic-block.h"
30 #include "tree-pass.h"
31 #include "tree-streamer.h"
35 #include "lto-partition.h"
36 #include "tree-pretty-print.h"
37 #include "lto-common.h"
39 /* Stores details of symbols for dumping symbol list. */
44 symbol_entry (symtab_node
*node_
): node (node_
)
47 virtual ~symbol_entry ()
50 char* get_name () const
52 if (flag_lto_dump_demangle
)
53 return xstrdup (node
->name ());
55 return xstrdup (node
->asm_name ());
58 virtual size_t get_size () const = 0;
62 const char *name
= get_name ();
63 const char *type_name
= node
->get_symtab_type_string ();
64 const char *visibility
= node
->get_visibility_string ();
65 size_t sz
= get_size ();
66 printf ("%s %s %4" PRIu64
" %s ", type_name
, visibility
, (uint64_t) sz
,
71 /* Stores variable specific details of symbols for dumping symbol list. */
73 struct variable_entry
: public symbol_entry
75 variable_entry (varpool_node
*node_
): symbol_entry (node_
)
78 virtual ~variable_entry ()
81 virtual size_t get_size () const
83 varpool_node
*vnode
= dyn_cast
<varpool_node
*> (node
);
84 if (DECL_SIZE (vnode
->decl
) && tree_fits_shwi_p (DECL_SIZE (vnode
->decl
)))
85 return tree_to_shwi (DECL_SIZE (vnode
->decl
));
91 symbol_entry :: dump ();
92 varpool_node
*vnode
= dyn_cast
<varpool_node
*> (node
);
93 vnode
->get_constructor ();
94 tree value_tree
= DECL_INITIAL (vnode
->decl
);
95 if (flag_lto_print_value
&& value_tree
)
96 print_generic_expr (stdout
, value_tree
, TDF_NONE
);
101 /* Stores function specific details of symbols for dumping symbol list. */
103 struct function_entry
: public symbol_entry
105 function_entry (cgraph_node
*node_
): symbol_entry (node_
)
108 virtual ~function_entry ()
113 symbol_entry :: dump ();
117 virtual size_t get_size () const
119 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
);
122 return (cnode
->definition
)
123 ? n_basic_blocks_for_fn (DECL_STRUCT_FUNCTION (cnode
->decl
))
128 /* Comparing symbols based on size. */
130 int size_compare (const void *a
, const void *b
)
132 const symbol_entry
*e1
= *(const symbol_entry
* const*) a
;
133 const symbol_entry
*e2
= *(const symbol_entry
* const*) b
;
135 return e1
->get_size () - e2
->get_size ();
138 /* Comparing symbols based on name. */
140 int name_compare (const void *a
, const void *b
)
142 const symbol_entry
*e1
= *(const symbol_entry
* const*) a
;
143 const symbol_entry
*e2
= *(const symbol_entry
* const*) b
;
145 return strcmp (e1
->get_name (), e2
->get_name ());
148 /* Dump list of functions and their details. */
150 void dump_list_functions (void)
152 auto_vec
<symbol_entry
*> v
;
155 FOR_EACH_FUNCTION (cnode
)
157 if (cnode
->definition
)
158 cnode
->get_untransformed_body ();
159 symbol_entry
*e
= new function_entry (cnode
);
160 if (!flag_lto_dump_defined
|| cnode
->definition
)
164 if (flag_lto_size_sort
)
165 v
.qsort (size_compare
);
166 else if (flag_lto_name_sort
)
167 v
.qsort (name_compare
);
168 if (flag_lto_reverse_sort
)
171 printf ("Type Visibility Size Name");
172 if (flag_lto_print_value
)
177 FOR_EACH_VEC_ELT (v
, i
, e
)
184 /* Dump list of variables and their details. */
186 void dump_list_variables (void)
188 auto_vec
<symbol_entry
*> v
;
191 FOR_EACH_VARIABLE (vnode
)
193 symbol_entry
*e
= new variable_entry (vnode
);
194 if (!flag_lto_dump_defined
|| vnode
->definition
)
198 if (flag_lto_size_sort
)
199 v
.qsort (size_compare
);
200 else if (flag_lto_name_sort
)
201 v
.qsort (name_compare
);
202 if (flag_lto_reverse_sort
)
208 FOR_EACH_VEC_ELT (v
, i
, e
)
215 /* Dump symbol list. */
217 void dump_list (void)
219 dump_list_functions ();
220 dump_list_variables ();
224 /* Dump specific variables and functions used in IL. */
228 printf ("Symbol: %s\n", flag_lto_dump_symbol
);
229 FOR_EACH_SYMBOL (node
)
231 if (!strcmp (flag_lto_dump_symbol
, node
->name ()))
240 /* Dump specific gimple body of specified function. */
244 dump_flags_t flags
= TDF_NONE
;
246 flags
= parse_dump_option (flag_dump_level
, NULL
);
247 if (flags
== TDF_ERROR
)
249 error_at (input_location
, "Level not found, use none, slim, blocks, vops.");
253 FOR_EACH_FUNCTION (cnode
)
254 if (cnode
->definition
&& !strcmp (cnode
->name (), flag_dump_body
))
256 printf ("Gimple Body of Function: %s\n", cnode
->name ());
257 cnode
->get_untransformed_body ();
258 debug_function (cnode
->decl
, flags
);
262 error_at (input_location
, "Function not found.");
266 /* List of command line options for dumping. */
267 void dump_tool_help ()
269 printf ("Usage: lto-dump [OPTION]... SUB_COMMAND [OPTION]...\n\n");
270 printf ("LTO dump tool command line options.\n\n");
271 printf (" -list [options] Dump the symbol list.\n");
272 printf (" -demangle Dump the demangled output.\n");
273 printf (" -defined-only Dump only the defined symbols.\n");
274 printf (" -print-value Dump initial values of the "
276 printf (" -name-sort Sort the symbols alphabetically.\n");
277 printf (" -size-sort Sort the symbols according to size.\n");
278 printf (" -reverse-sort Dump the symbols in reverse order.\n");
279 printf (" -symbol= Dump the details of specific symbol.\n");
280 printf (" -objects Dump the details of LTO objects.\n");
281 printf (" -type-stats Dump statistics of tree types.\n");
282 printf (" -tree-stats Dump statistics of trees.\n");
283 printf (" -gimple-stats Dump statistics of gimple "
285 printf (" -dump-body= Dump the specific gimple body.\n");
286 printf (" -dump-level= Deciding the optimization level "
288 printf (" -help Display the dump tool help.\n");
293 lto_option_lang_mask (void)
298 /* Functions for dumping various details in LTO dump tool are called
299 in lto_main(). The purpose of this dump tool is to analyze the LTO
306 if (flag_lto_dump_tool_help
)
309 /* LTO is called as a front end, even though it is not a front end.
310 Because it is called as a front end, TV_PHASE_PARSING and
311 TV_PARSE_GLOBAL are active, and we need to turn them off while
312 doing LTO. Later we turn them back on so they are active up in
315 /* Initialize the LTO front end. */
318 /* Read all the symbols and call graph from all the files in the
320 read_cgraph_and_symbols (num_in_fnames
, in_fnames
);
322 /* Dump symbol list. */
323 if (flag_lto_dump_list
)
325 else if (flag_lto_dump_symbol
)
327 /* Dump specific variables and functions used in IL. */
330 else if (flag_lto_gimple_stats
)
332 /* Dump gimple statement statistics. */
334 FOR_EACH_DEFINED_FUNCTION (node
)
335 node
->get_untransformed_body ();
336 if (!GATHER_STATISTICS
)
337 warning_at (input_location
, 0,
338 "Not configured with "
339 "%<--enable-gather-detailed-mem-stats%>.");
341 dump_gimple_statistics ();
343 else if (flag_lto_tree_stats
)
345 /* Dump tree statistics. */
346 if (!GATHER_STATISTICS
)
347 warning_at (input_location
, 0,
348 "Not configured with "
349 "%<--enable-gather-detailed-mem-stats%>.");
352 printf ("Tree Statistics\n");
353 dump_tree_statistics ();
356 else if (flag_dump_body
)
358 /* Dump specific gimple body of specified function. */