From: Jon Harrop <jon@ffconsultancy.com>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Google summer of Code proposal
Date: Sat, 21 Mar 2009 21:35:28 +0000 [thread overview]
Message-ID: <200903212135.28525.jon@ffconsultancy.com> (raw)
In-Reply-To: <D605AE61-1A87-4271-BC9C-27D8B5518EC5@gmail.com>
On Saturday 21 March 2009 20:49:28 Joel Reymont wrote:
> On Mar 21, 2009, at 2:51 PM, Jon Harrop wrote:
> > . I found that LLVM's x86 backend breaks tail calls when the return
> > type is a
> > first class struct. The workaround is to use sret form, having the
> > caller
> > preallocate the return struct and passing a pointer to the struct as
> > an extra
> > first argument.
>
> Returning a structure by having the caller preallocate space, etc. is
> part of the Intel ABI or something like that. This is how it's done,
> period.
No, not at all. Other calling conventions have many benefits including better
performance and the ability to return multiple values. LLVM provides a "fast"
calling convention as well as the (Intel-compatible) C callcc for precisely
this reason. HLVM uses LLVM's fast callcc. OCaml uses its own non-standard
calling convention.
Indeed, if HLVM were not using fastcc it would not have any tail calls at all!
This raises some interesting issues. For example, HLVM allows you to declare
external C functions from your high-level language and call them directly.
But it also has first-class function pointers so it is necessary to wrap the
C calls in fastcc calls so the C functions can be used interchangeably with
internal functions. There are many such subtleties in the design of HLVM and
I described them all in the relevant OCaml Journal articles.
> Not sure how it relates to breaking tail calls, though.
A design flaw in the implementation of tail calls in LLVM requires code to be
injected by the architecture-specific code gen after the tail call and before
the actual return in order to move the struct elements into place. That
prevents such tail calls from being eliminated later in the code gen.
Fortunately the author was there to assist. Even more remarkably, the same
student is responsible for tail calls on the JVM (!). He must be busy...
--
Dr Jon Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?e
next prev parent reply other threads:[~2009-03-21 21:29 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-21 12:39 Andrey Riabushenko
2009-03-21 13:01 ` [Caml-list] " Seo Sanghyeon
2009-03-21 13:47 ` Andrey Riabushenko
2009-03-21 14:51 ` Jon Harrop
2009-03-21 20:49 ` Joel Reymont
2009-03-21 21:35 ` Jon Harrop [this message]
2009-03-21 13:38 ` Jon Harrop
2009-03-21 20:43 ` Joel Reymont
2009-03-21 21:28 ` Michael Ekstrand
2009-03-23 17:23 ` [Caml-list] " Kuba Ober
2009-03-21 22:21 ` [Caml-list] " Jon Harrop
2009-03-22 0:12 ` Fermin Reig
2009-03-23 14:19 ` Xavier Leroy
2009-03-23 19:38 ` Jon Harrop
2009-03-24 15:39 ` Xavier Leroy
2009-03-30 15:42 ` Nicolas Cannasse
2009-03-30 15:56 ` Joel Reymont
2009-03-30 21:21 ` Jon Harrop
2009-03-31 0:36 ` Jon Harrop
[not found] <20090321204943.E2ACCBBFA@yquem.inria.fr>
2009-03-21 21:45 ` Andrey Riabushenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200903212135.28525.jon@ffconsultancy.com \
--to=jon@ffconsultancy.com \
--cc=caml-list@yquem.inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox