Tzu-Chien Chiu
2005-Jul-29 06:18 UTC
[LLVMdev] How to define a function with multiple return values?
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>
Chris Lattner
2005-Jul-29 07:09 UTC
[LLVMdev] How to define a function with multiple return values?
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 4No. 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_retCorrect.> 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/