[LLVMdev] Using "packed" to return lots of values

Chris Lattner sabre at nondot.org
Mon Apr 3 09:07:00 PDT 2006


On Mon, 3 Apr 2006, Nikhil Patil wrote:
> The LLVM manual mentions that it is not possible to return multiple
> values in LLVM.  I really need to get around this.  I am trying to
> compile for a (weird, proof-of-concept) language with infinite registers
> and no memory, where I need to pass several (easily hundreds) of
> registers to a function, and also return several (hundreds) of registers
> back.

ok

> Would using packed values be the right thing to do?  Even if I am able
> to pass only operands of a single type say (an int or a bool), that
> would be sufficient.

Sure, you can do this, as long as the returned values are all the same 
LLVM type, and that type is not a pointer (packed vectors of pointers are 
not legal).  Note that passing and returning packed values is not *yet* 
supported by any of the code generators, but they will be soon.

Alternatively, you could pass these many values as 'out' parameters, by 
reference.  For example, instead of:

int,int foo() {
   return 1,2;
}

Use this:

void foo(int *A, int *B) {
   *A = 1; *B = 2;
}

Alternatively, you can aggregate the results into a struct and pass *its* 
address, instead of each result value individually.

-Chris

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




More information about the llvm-dev mailing list