On Tue, Nov 20, 2012 at 08:50:38AM +0100, Jonas Bonn wrote:
> 
> The register that immediately jumps out at me as a natural choice is
> r11... that register then becomes an IN/OUT parameter and doesn't
> disrupt the regular allocation of parameter registers where r3 usually
> is the first parameter.
> 
> But I've given this about 3 minutes of thought; maybe r3 is better.  I
> would, however, be curious to know why in that case...
> 

Ah, I didn't necessarily mean it's a better choice than r11,
just that it doesn't really cause any trouble.
I'm not supersure about the whole thing neither, but this is what we have.
But if we expand on that thought, why do we even have seperate return
registers, couldn't r3 and r4 be combined return value and function parameters?
A bit late to change that, but still.

I'm not sure about the disrupting the reg allocator, from what I remember
in LLVM it's automatically assigned to the first function parameter.

> > 
> > 16.2.5 Functions Returning Structures or Unions
> > 
> > A function that returns a structure or union places the address of the 
> > structure or 
> > union in the general-purpose RV register.
> > 
> > A  function  that  returns  a  structure  by  value  expects  the  location 
> >  where  that
> > structure is to be placed to be supplied in function parameter word 0 (R3).
> 
> This means we put X in r3 going into the function call and get X in r11
> coming out... what's the point?
> 

Actually, I asked the same thing and was inclined to omit putting X in r11
in LLVM.

Joern came with this input regarding the issue (hope he don't mind I quote the
IRC conversation here):

< amylaar> Hello, I heard you have a question for me?
< stekern> amylaar: yes, I was speaking with jeremybennett about the ABI for 
returning structs, and I was trying to come up with a case where the pointer in 
r11 actually would be used
< stekern> since the struct is returned on the callers stack, it will already 
know about the pointer
< amylaar> The callee has to know where to put it.
< stekern> yes, but that is passed in r3
< stekern> I was wondering about the return value in r11
< stekern> and if the caller ever will use the pointer that is returned in r11, 
or if it will just always use the stack offset that it has already calculated 
(my small tests indicates the latter)
< amylaar> In general, it will be most convenient for the caller to tell the 
callee where it wants the value, and then be happy with where it knows it is.
< amylaar> But I could imagine that there are some cases where having the 
pointer in r11 is convenient.
< amylaar> Like, when the caller in turn is supposed to return a pointer to 
that kind of struct, which it allocated (e.g. with malloc).
< amylaar> So, ideally, it would pass the address of that allocated storage to 
its callee, and it can do a tail-call, as the return value of the callee will 
be the same as that of the caller.

Stefan
_______________________________________________
OpenRISC mailing list
[email protected]
http://lists.openrisc.net/listinfo/openrisc

Reply via email to