[LLVMdev] Returning multiple values from a function

Chris Lattner sabre at nondot.org
Mon Feb 25 10:20:00 PST 2008


On Mon, 25 Feb 2008, Talin wrote:
> The language I am working on allows multiple return values from a function:
>   def myfunc() -> (int, String);
>   let a, b = myfunc();
> I can think of two ways to implement this:

We're currently working on first class support for multiple return values 
in the LLVM IR.  The goal is to improve our x86-64 ABI compatibility, but 
it will have the side effect of allowing anyone to use it if they want it 
:).  We're hoping this will be done for llvm 2.3 (~3 months or so from 
now).

> 1) Return one of the values as the actual return value of the function,
> and quietly convert the rest to reference arguments.
> 2) Define a temporary, anonymous struct and return it.
>
> Which approach is likely to be more efficient, or is there a better
> approach available?

#2 is the same as #1, because you can't return structs by-value from 
functions in llvm: they are returned through a hidden pointer argument. 
Either way is reasonable until we get first class support for multiple 
return values.

-Chris

-- 
http://nondot.org/sabre/
http://llvm.org/



More information about the llvm-dev mailing list