This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
needless deep recursion in gt-c-decl.h
- From: Per Bothner <per at bothner dot com>
- To: gcc at gcc dot gnu dot org
- Cc: Geoffrey Keating <geoffk at redhat dot com>
- Date: Tue, 23 Jul 2002 20:11:54 -0700
- Subject: needless deep recursion in gt-c-decl.h
The gt_ggc_mx_lang_tree_node routine in the generated
gt-c-decl.h file causes a stack overflow when I tried
it under Darwin. Perhaps I need to increase the stack
limit, but the deep recursion is a performance problem
that needlessly increases the working set.
Specifically, we should iterate, not recurse, on the
field that is most likely to be a long list, the TREE_CHAIN.
I don't understand how gengtype works, but the generated
code should be something like this:
void
gt_ggc_mx_lang_tree_node (x_p)
void *x_p;
{
union lang_tree_node * const x = (union lang_tree_node *)x_p;
for (;;) {
if (! ggc_test_and_set_mark (x))
return;
{
...
gt_ggc_m_tree_node ((*x).generic.common.type);
x = (*x).generic.common.chain;
if (x != NULL_TREE)
continue;
return;
}
}
All the comparisons against tag1 and tag2 may also be a performance
problem. I don't know if the compiler is smart enough to convert
if (tag2 == (TS_REAL_CST) ...;
if (tag2 == (TS_VECTOR)) ...;
to:
if (tag2 == (TS_REAL_CST) ...;
else if (tag2 == (TS_VECTOR)) ...;
Assuming it is, it would still be an advantage if we could
order the type tests by frequency, unless the compiler is
smart enough to compile all the tests into a switch. Is it?
--
--Per Bothner
per@bothner.com http://www.bothner.com/per/