Well yes, LLVM is Turing complete :-) but I take your point, one could in a pinch hack the same functionality in the front-end. Would that likely be easier or harder than doing it properly in the code generator? Other things equal, of course the latter would be preferable. How do LLVM-GCC and Clang handle it? On Mon, Mar 1, 2010 at 3:36 PM, Duncan Sands <baldrick at free.fr> wrote:> Hi Russel, > >> Are there any plans to change this? It's needed for a correct >> implementation of C, after all. > > I guess it will happen when someone needs it enough. My understanding is > that > it wouldn't be hard to implement for most processors. By the way, you are > wrong > to say that it is needed for a correct implementation in C. Here's an > analogy: > consider the x86 instruction set. It does not have an instruction for > returning > arbitrarily large arrays. In fact it doesn't have any instructions for > manipulating arrays or structs at all. Even worse, it doesn't even have a > notion of function! So clearly C programs cannot run on x86 processors! > Yet > still they do, how can this be? The same answer applies to LLVM. > > Ciao, > > Duncan. >
On Mon, Mar 1, 2010 at 10:58 AM, Russell Wallace <russell.wallace at gmail.com> wrote:> How do LLVM-GCC and Clang handle it?IIRC they lower it themselves, doing whatever the ABI says they should, which is usually adding a hidden sret parameter to the function once you get beyond small structs. It'd be nice to move some of that logic back into LLVM, but it's tricky because C99 says things about complex numbers which requires special frontend type knowledge that LLVM doesn't have. I'm just echoing previous discussion, and you can probably get a more reliable answer by finding the original discussion in the archives. Reid
On Mon, Mar 1, 2010 at 7:39 PM, Reid Kleckner <rnk at mit.edu> wrote:> IIRC they lower it themselves, doing whatever the ABI says they > should, which is usually adding a hidden sret parameter to the > function once you get beyond small structs.Okay, so we seem to be saying sret or suchlike is how you pass and return large objects by value in LLVM. What exactly counts as large? As I understand it, the largest integers correctly handled as first-class values are the size of two pointers, i.e. usually either 64 or 128 bits. Is the same true of structs?> It'd be nice to move some > of that logic back into LLVM, but it's tricky because C99 says things > about complex numbers which requires special frontend type knowledge > that LLVM doesn't have.I hadn't realized that, I would've expected complex numbers to be doable as just a pair of scalar values. What's the fly in the ointment with C99 complex numbers?> I'm just echoing previous discussion, and you can probably get a more > reliable answer by finding the original discussion in the archives.I don't suppose you've any idea what search keywords might work?