[LLVMdev] How to define a function with multiple return values?

Chris Lattner sabre at nondot.org
Fri Jul 29 00:09:40 PDT 2005


On Fri, 29 Jul 2005, Tzu-Chien Chiu wrote:
> LegalizeDAG.cpp
>  SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) {
>    case ISD::RET:
>      Tmp1 = LegalizeOp(Node->getOperand(0));  // Legalize the chain.
>      switch (Node->getNumOperands()) {
>      case 2:  // ret val
>      [skipped]
>      case 1:  // ret void
>      [skipped]
>      default: { // ret <values>
>      [skipped]
>
> Does it imply that a ret instruction may return more than one values?
>
>  ret uint 1, uint 2, ubyte 3, uint 4

No.  This code is used when a target must return a value in multiple 
registers.  For example, on the i386, a 64-bit integer is returned in EAX 
and EDX.

> But at most one return value is allowed, according to
> http://llvm.cs.uiuc.edu/docs/LangRef.html#i_ret

Correct.

> How to define a function with multiple return values? The code:
>  uint, uint, ubyte, uint %main() {
>    ret uint 1, uint 2, ubyte 3, uint 4
>  }
>
> cannot be correctly assembled by llvm-as.

LLVM does not currently support this.  I would like to add this extension 
in the future, but we do not have it yet.  If you're interested, here are 
my personal notes on the topic:
http://nondot.org/sabre/LLVMNotes/MultipleReturnValues.txt

In the meantime, multiple values must be returned with by-reference 
parameters.

-Chris

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




More information about the llvm-dev mailing list