[m-dev.] Mutually recursive tailcalls in hlc.

Paul Bone paul at bone.id.au
Mon Nov 9 12:27:03 AEDT 2015


On Sat, Nov 07, 2015 at 06:06:21AM +1100, Mark Brown wrote:
> On Fri, Nov 6, 2015 at 11:37 AM, Paul Bone <paul at bone.id.au> wrote:
> > I've transformed it to this:
> >
> > /* Struct is used to represent arguments for recursive calls */
> > typedef struct {
> >   MR_Float Nr;
> >   MR_Float Ni;
> >   MR_Float Cr;
> >   MR_Float Ci;
> >   MR_Integer MaxIters;
> >   MR_Integer Iters_0;
> >   MR_Integer * Iters;
> > } escape_data;
> 
> If all the functions in the SCC take something like this as an
> argument, and return void, would gcc already make the calls tail
> recursive? Come to think of it, could you meet gcc's criteria by just
> padding out the functions in the SCC so they all have the same number
> of arguments?
> 

Zoltan has already said that this is only one factor in the stack frame
sizes.  In addition to this I want to avoid depending on depending on any
behaviour of a C compiler in the high level C backend.  That's what the
low-level C backend is for. :-P

That said if we thought that a majority of popular C compilers could
optimise mutual recursion in the general case, then I wouldn't bother making
this change to Mercury.  I'm pretty sure that that's not the case.


-- 
Paul Bone



More information about the developers mailing list