[llvm-commits] [llvm] r48173 - /llvm/trunk/docs/LangRef.html

Devang Patel dpatel at apple.com
Mon Mar 10 13:49:15 PDT 2008

Author: dpatel
Date: Mon Mar 10 15:49:15 2008
New Revision: 48173

URL: http://llvm.org/viewvc/llvm-project?rev=48173&view=rev
Document multiple return values.


Modified: llvm/trunk/docs/LangRef.html
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/LangRef.html?rev=48173&r1=48172&r2=48173&view=diff

--- llvm/trunk/docs/LangRef.html (original)
+++ llvm/trunk/docs/LangRef.html Mon Mar 10 15:49:15 2008
@@ -144,6 +144,7 @@
           <li><a href="#i_select">'<tt>select</tt>' Instruction</a></li>
           <li><a href="#i_call">'<tt>call</tt>'  Instruction</a></li>
           <li><a href="#i_va_arg">'<tt>va_arg</tt>'  Instruction</a></li>
+          <li><a href="#i_getresult">'<tt>getresult</tt>'  Instruction</a></li>
@@ -1226,16 +1227,16 @@
 Function types are usually used to build virtual function tables
 (which are structures of pointers to functions), for indirect function
 calls, and when defining a function.</p>
-The return type of a function type cannot be an aggregate type.
-<pre>  <returntype> (<parameter list>)<br></pre>
+<pre>  <returntype list> (<parameter list>)<br></pre>
 <p>...where '<tt><parameter list></tt>' is a comma-separated list of type
 specifiers.  Optionally, the parameter list may include a type <tt>...</tt>,
 which indicates that the function takes a variable number of arguments.
 Variable argument functions can access their arguments with the <a
- href="#int_varargs">variable argument handling intrinsic</a> functions.</p>
+ href="#int_varargs">variable argument handling intrinsic</a> functions.
+'<tt><returntype list></tt>' is a comma-separated list of
+<a href="#t_firstclass">first class</a> type specifiers.</p>
 <table class="layout">
   <tr class="layout">
@@ -1788,6 +1789,7 @@
 <pre>  ret <type> <value>       <i>; Return a value from a non-void function</i>
   ret void                 <i>; Return from void function</i>
+  ret <type> <value>, <type> <value>  <i>; Return two values from a non-void function </i>
 <p>The '<tt>ret</tt>' instruction is used to return control flow (and a
@@ -1796,11 +1798,11 @@
 returns a value and then causes control flow, and one that just causes
 control flow to occur.</p>
-<p>The '<tt>ret</tt>' instruction may return any '<a
- href="#t_firstclass">first class</a>' type.  Notice that a function is
-not <a href="#wellformed">well formed</a> if there exists a '<tt>ret</tt>'
-instruction inside of the function that returns a value that does not
-match the return type of the function.</p>
+<p>The '<tt>ret</tt>' instruction may return one or multiple values. The
+type of each return value must be '<a href="#t_firstclass">first class</a>'
+ type.  Notice that a function is not <a href="#wellformed">well formed</a> 
+if there exists a '<tt>ret</tt>' instruction inside of the function that 
+returns values that does not match the return type of the function.</p>
 <p>When the '<tt>ret</tt>' instruction is executed, control flow
 returns back to the calling function's context.  If the caller is a "<a
@@ -1809,10 +1811,13 @@
  href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues
 at the beginning of the "normal" destination block.  If the instruction
 returns a value, that value shall set the call or invoke instruction's
-return value.</p>
+return value. If the instruction returns multiple values then these 
+value can only be accessed through '<a href="#i_getresult"><tt>getresult</tt>
+</a>' insctruction.</p>
 <pre>  ret i32 5                       <i>; Return an integer value of 5</i>
   ret void                        <i>; Return from a void function</i>
+  ret i32 4, i8 2                 <i>; Return two values 4 and 2 </i> 
 <!-- _______________________________________________________________________ -->
@@ -1922,7 +1927,9 @@
 "<tt><a href="#i_ret">ret</a></tt>" instruction, control flow will return to the
 "normal" label.  If the callee (or any indirect callees) returns with the "<a
 href="#i_unwind"><tt>unwind</tt></a>" instruction, control is interrupted and
-continued at the dynamically nearest "exception" label.</p>
+continued at the dynamically nearest "exception" label. If the callee function 
+returns multiple values then individual return values are accessed only through 
+'<tt><a href="#i_getresult">getresult</a></tt>' instruction.</p>
@@ -3810,7 +3817,10 @@
 the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>'
 instruction in the called function, control flow continues with the
 instruction after the function call, and the return value of the
-function is bound to the result argument.  This is a simpler case of
+function is bound to the result argument.  If the '<tt><a href="#i_ret">ret</a>
+</tt>' instruction returns multiple values then the return value of the
+function is only accessed through '<tt><a href="#i_getresult">getresult</a>
+</tt>' instruction. This is a simpler case of
 the <a href="#i_invoke">invoke</a> instruction.</p>
@@ -3821,6 +3831,11 @@
   %X = tail call i32 @foo()
   %Y = tail call <a href="#callingconv">fastcc</a> i32 @foo()
   %Z = call void %foo(i8 97 signext)
+  %struct.A = type { i32, i8 }
+  %r = call %struct.A @foo()
+  %gr = getresult %struct.A %r, 0
+  %gr1 = getresult %struct.A %r, 1
@@ -3873,6 +3888,48 @@
+<!-- _______________________________________________________________________ -->
+<div class="doc_subsubsection">
+  <a name="i_getresult">'<tt>getresult</tt>' Instruction</a>
+<div class="doc_text">
+  <resultval> = getresult <type> <retval>,  <index>
+<p> The '<tt>getresult</tt>' instruction is used to extract individual values
+from multiple values returned by '<tt><a href="#i_call">call</a></tt>' 
+or '<tt><a href="#i_invoke">invoke</a></tt>' instruction.
+The '<tt>getresult</tt>' instruction takes return value as first argument. The 
+value must have <a href="#t_struct">structure type</a>. The second argument 
+is unsigned index value. 
+The '<tt>getresult</tt>' instruction extracts element identified by
+'<tt>index</tt>' from the aggregate value.
+  %struct.A = type { i32, i8 }
+  %r = call %struct.A @foo()
+  %gr = getresult %struct.A %r, 0
+  %gr1 = getresult %struct.A %r, 1 
+  add i32 %gr, 42
+  add i8 %gr1, 41
 <!-- *********************************************************************** -->
 <div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div>
 <!-- *********************************************************************** -->

More information about the llvm-commits mailing list