How to define a function with multiple return values?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to define a function with multiple return values?

Tzu-Chien Chiu
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

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

  Syntax:

    ret <type> <value>       ; Return a value from a non-void function
    ret void                 ; Return from void function

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.


--
Tzu-Chien Chiu,
3D Graphics Hardware Architect
<URL:http://www.csie.nctu.edu.tw/~jwchiu>

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: How to define a function with multiple return values?

Chris Lattner
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/

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev