needless deep recursion in gt-c-decl.h

Per Bothner per@bothner.com
Wed Jul 24 04:53:00 GMT 2002


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/



More information about the Gcc mailing list