This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: show size of stack needed by functions
- From: Sebastian <sebastianspublicaddress at googlemail dot com>
- To: Eric Botcazou <ebotcazou at adacore dot com>, Eric Botcazou <ebotcazou at adacore dot com>
- Cc: gcc at gcc dot gnu dot org, gcc at gcc dot gnu dot org
- Date: Wed, 18 May 2016 22:52:36 +0200
- Subject: Re: show size of stack needed by functions
- Authentication-results: sourceware.org; auth=none
- References: <1287000338 dot 3466 dot 9 dot camel at svetz> <AANLkTimW2rsS6_f50LA52AZBQ0hTsLg5kXUM7Djpkh90 at mail dot gmail dot com> <20160509234710 dot 4fa38d7c at wrona> <4381869 dot lFxcenRLCY at polaris>
Attached is a patch with some experiments of mine.
On Tue, 10 May 2016 01:17:37 +0200
Eric Botcazou <ebotcazou@adacore.com> wrote:
> > Wishes:
> > - Add stack-usage in output of -fdump-ipa-cgraph, so that you don't need to
> > relate information from two input files at all. I guess this is not
> > trivial. Or is it?
>
> It's not difficult, but there is a conflict between them because -fstack-usage
> is designed to be conservatively correct while -fdump-ipa-cgraph is not (it
> does not dump the full callgraph).
This is what I tried first (see attached patch). Doesn't seem to work. I get only outputs of "no su" and "no func".
So at the point in time when the callgraph dump happens, there is no stack-usage data attached to the "function" structures?
Can you elaborate on the conflict you mentioned?
Under which circumstances are there missing functions in the cgraph?
For my example AVR program, all identifiers appearing in the stack-usage output also appeared in the cgraph output.
On Mon, 9 May 2016 23:47:10 +0200
Sebastian <SebastiansPublicAddress@googlemail.com> wrote:
> - In -fstack-usage, use the same unique identifiers as in -fdump-ipa-cgraph.
This is what I tried next (see attached patch).
Currently, I just add another column with the cgraph identifier. Assuming the patch will go into SVN eventually, do you think I should replace the existing identifier instead? What would be less trouble for existing tools that parse the output?
With just changing the output of the identifier, still some functions are missing.
But for all of them I've got something like this:
References: SYMBOL/ORDER (alias)
which then is in stack-usage. So no problem.
Summary:
With the unique identifiers from cgraph node->asm_name() / node->order patched into stack-usage, cgraph and stack-usage are consistent for my example program.
I wonder what I should change (output format, anything else?) before it's fit for SVN.
Sebastian
diff -aur gcc-5.3.0/gcc/cgraph.c ../gcc-5.3.0/gcc/cgraph.c
--- gcc-5.3.0/gcc/cgraph.c 2015-06-17 09:42:39.000000000 +0200
+++ ../gcc-5.3.0/gcc/cgraph.c 2016-05-16 21:27:58.351356039 +0200
@@ -2061,6 +2061,28 @@
fprintf (f, "\n");
}
+ if (flag_stack_usage_info)
+ {
+ function *func = get_fun();
+ if(func && func->su)
+ {
+ fprintf (f, "\n stack-usage: %d", func->su->static_stack_size);
+ }
+ else if(func)
+ {
+ fprintf (f, "\n stack-usage: no su");
+ }
+ else
+ {
+ fprintf (f, "\n stack-usage: no func");
+ }
+ }
+ else
+ {
+ fprintf (f, "\n stack-usage: disabled");
+ }
+ fprintf (f, "\n");
+
fprintf (f, " Called by: ");
for (edge = callers; edge; edge = edge->next_caller)
@@ -2110,6 +2132,7 @@
fprintf (f, " Is instrumented version.\n");
else if (instrumented_version)
fprintf (f, " Has instrumented version.\n");
+
}
/* Dump call graph node NODE to stderr. */
diff -aur gcc-5.3.0/gcc/toplev.c ../gcc-5.3.0/gcc/toplev.c
--- gcc-5.3.0/gcc/toplev.c 2015-07-10 14:33:28.000000000 +0200
+++ ../gcc-5.3.0/gcc/toplev.c 2016-05-18 21:18:38.603461168 +0200
@@ -1122,15 +1122,28 @@
}
fprintf (stack_usage_file,
- "%s:%d:%d:%s\t"HOST_WIDE_INT_PRINT_DEC"\t%s\n",
+ "%s:%d:%d:%s\t"HOST_WIDE_INT_PRINT_DEC"\t%s",
lbasename (loc.file),
loc.line,
loc.column,
name,
stack_usage,
stack_usage_kind_str[stack_usage_kind]);
+ cgraph_node *node = cgraph_node::get (current_function_decl);
+ if(node)
+ {
+ // cfun->funcdef_no is different than node->order in some cases.
+ fprintf (stack_usage_file, "\t%s/%i\n",
+ xstrdup_for_dump (node->asm_name ()),
+ node->order);
+ }
+ else
+ {
+ fprintf (stack_usage_file, "\n");
+ }
}
+
if (warn_stack_usage >= 0)
{
const location_t loc = DECL_SOURCE_LOCATION (current_function_decl);