Introducing nocapture, a parameter attribute for pointers to indicate that the
[oota-llvm.git] / docs / LangRef.html
index 27bcb920025cf9a029262bdcc200d9a9f92157e3..95fb8de319bca7704d55e0d4d916c9fd7f9fbd5c 100644 (file)
           <li><a href="#int_it">'<tt>llvm.init.trampoline</tt>' Intrinsic</a></li>
         </ol>
       </li>
-          <li><a href="#int_atomics">Atomic intrinsics</a>
-            <ol>
-              <li><a href="#int_memory_barrier"><tt>llvm.memory_barrier</tt></a></li>
-              <li><a href="#int_atomic_cmp_swap"><tt>llvm.atomic.cmp.swap</tt></a></li>
-              <li><a href="#int_atomic_swap"><tt>llvm.atomic.swap</tt></a></li>
-              <li><a href="#int_atomic_load_add"><tt>llvm.atomic.load.add</tt></a></li>
-              <li><a href="#int_atomic_load_sub"><tt>llvm.atomic.load.sub</tt></a></li>
-              <li><a href="#int_atomic_load_and"><tt>llvm.atomic.load.and</tt></a></li>
-              <li><a href="#int_atomic_load_nand"><tt>llvm.atomic.load.nand</tt></a></li>
-              <li><a href="#int_atomic_load_or"><tt>llvm.atomic.load.or</tt></a></li>
-              <li><a href="#int_atomic_load_xor"><tt>llvm.atomic.load.xor</tt></a></li>
-              <li><a href="#int_atomic_load_max"><tt>llvm.atomic.load.max</tt></a></li>
-              <li><a href="#int_atomic_load_min"><tt>llvm.atomic.load.min</tt></a></li>
-              <li><a href="#int_atomic_load_umax"><tt>llvm.atomic.load.umax</tt></a></li>
-              <li><a href="#int_atomic_load_umin"><tt>llvm.atomic.load.umin</tt></a></li>
-            </ol>
-          </li>
+      <li><a href="#int_atomics">Atomic intrinsics</a>
+        <ol>
+          <li><a href="#int_memory_barrier"><tt>llvm.memory_barrier</tt></a></li>
+          <li><a href="#int_atomic_cmp_swap"><tt>llvm.atomic.cmp.swap</tt></a></li>
+          <li><a href="#int_atomic_swap"><tt>llvm.atomic.swap</tt></a></li>
+          <li><a href="#int_atomic_load_add"><tt>llvm.atomic.load.add</tt></a></li>
+          <li><a href="#int_atomic_load_sub"><tt>llvm.atomic.load.sub</tt></a></li>
+          <li><a href="#int_atomic_load_and"><tt>llvm.atomic.load.and</tt></a></li>
+          <li><a href="#int_atomic_load_nand"><tt>llvm.atomic.load.nand</tt></a></li>
+          <li><a href="#int_atomic_load_or"><tt>llvm.atomic.load.or</tt></a></li>
+          <li><a href="#int_atomic_load_xor"><tt>llvm.atomic.load.xor</tt></a></li>
+          <li><a href="#int_atomic_load_max"><tt>llvm.atomic.load.max</tt></a></li>
+          <li><a href="#int_atomic_load_min"><tt>llvm.atomic.load.min</tt></a></li>
+          <li><a href="#int_atomic_load_umax"><tt>llvm.atomic.load.umax</tt></a></li>
+          <li><a href="#int_atomic_load_umin"><tt>llvm.atomic.load.umin</tt></a></li>
+        </ol>
+      </li>
       <li><a href="#int_general">General intrinsics</a>
         <ol>
           <li><a href="#int_var_annotation">
-            <tt>llvm.var.annotation</tt>' Intrinsic</a></li>
+            '<tt>llvm.var.annotation</tt>' Intrinsic</a></li>
           <li><a href="#int_annotation">
-            <tt>llvm.annotation.*</tt>' Intrinsic</a></li>
+            '<tt>llvm.annotation.*</tt>' Intrinsic</a></li>
           <li><a href="#int_trap">
-            <tt>llvm.trap</tt>' Intrinsic</a></li>
+            '<tt>llvm.trap</tt>' Intrinsic</a></li>
+          <li><a href="#int_stackprotector">
+            '<tt>llvm.stackprotector</tt>' Intrinsic</a></li>
         </ol>
       </li>
     </ol>
@@ -335,8 +337,9 @@ the parser.</p>
   For example, %foo, @DivisionByZero, %a.really.long.identifier.  The actual
   regular expression used is '<tt>[%@][a-zA-Z$._][a-zA-Z$._0-9]*</tt>'.
   Identifiers which require other characters in their names can be surrounded
-  with quotes.  In this way, anything except a <tt>&quot;</tt> character can 
-  be used in a named value.</li>
+  with quotes. Special characters may be escaped using "\xx" where xx is the 
+  ASCII code for the character in hexadecimal.  In this way, any character can 
+  be used in a name value, even quotes themselves.
 
   <li>Unnamed values are represented as an unsigned numeric value with their
   prefix.  For example, %12, @2, %44.</li>
@@ -562,7 +565,7 @@ All Global Variables and Functions have one of the following types of linkage:
 
 </dl>
 
-<p><a name="linkage_external"></a>For example, since the "<tt>.LC0</tt>"
+<p>For example, since the "<tt>.LC0</tt>"
 variable is defined to be internal, if another module defined a "<tt>.LC0</tt>"
 variable and was linked with this one, one of the two would be renamed,
 preventing a collision.  Since "<tt>main</tt>" and "<tt>puts</tt>" are
@@ -887,10 +890,19 @@ declare signext i8 @returns_signed_char()
     return values. </dd>
 
     <dt><tt>noalias</tt></dt>
-    <dd>This indicates that the parameter does not alias any global or any other
-    parameter.  The caller is responsible for ensuring that this is the case,
-    usually by placing the value in a stack allocation. This is not a valid
-    attribute for return values.</dd>
+    <dd>This indicates that the pointer does not alias any global or any other
+    parameter.  The caller is responsible for ensuring that this is the
+    case. On a function return value, <tt>noalias</tt> additionally indicates
+    that the pointer does not alias any other pointers visible to the
+    caller. For further details, please see the discussion of the NoAlias
+    response in
+    <a href="http://llvm.org/docs/AliasAnalysis.html#MustMayNo">alias
+    analysis</a>.</dd>
+
+    <dt><tt>nocapture</tt></dt>
+    <dd>This indicates that the callee does not make any copies of the pointer
+    that outlive the callee itself. This is not a valid attribute for return
+    values.</dd>
 
     <dt><tt>nest</tt></dt>
     <dd>This indicates that the pointer parameter can be excised using the
@@ -984,6 +996,27 @@ caller functions.  It may dereference pointer arguments and read state that may
 be set in the caller.  A readonly function always returns the same value (or
 throws the same exception) when called with the same set of arguments and global
 state.</dd>
+
+<dt><tt><a name="ssp">ssp</a></tt></dt>
+<dd>This attribute indicates that the function should emit a stack smashing
+protector. It is in the form of a "canary"&mdash;a random value placed on the
+stack before the local variables that's checked upon return from the function to
+see if it has been overwritten. A heuristic is used to determine if a function
+needs stack protectors or not.
+
+<p>If a function that has an <tt>ssp</tt> attribute is inlined into a function
+that doesn't have an <tt>ssp</tt> attribute, then the resulting function will
+have an <tt>ssp</tt> attribute.</p></dd>
+
+<dt><tt>sspreq</tt></dt>
+<dd>This attribute indicates that the function should <em>always</em> emit a
+stack smashing protector. This overrides the <tt><a href="#ssp">ssp</a></tt>
+function attribute.
+
+<p>If a function that has an <tt>sspreq</tt> attribute is inlined into a
+function that doesn't have an <tt>sspreq</tt> attribute or which has
+an <tt>ssp</tt> attribute, then the resulting function will have
+an <tt>sspreq</tt> attribute.</p></dd>
 </dl>
 
 </div>
@@ -1379,8 +1412,8 @@ Variable argument functions can access their arguments with the <a
     </td>
   </tr><tr class="layout">
     <td class="left"><tt>{i32, i32} (i32)</tt></td>
-    <td class="left">A function taking an <tt>i32></tt>, returning two 
-        <tt> i32 </tt> values as an aggregate of type <tt>{ i32, i32 }</tt>
+    <td class="left">A function taking an <tt>i32</tt>, returning two 
+        <tt>i32</tt> values as an aggregate of type <tt>{ i32, i32 }</tt>
     </td>
   </tr>
 </table>
@@ -2557,13 +2590,16 @@ type.  '<tt>op2</tt>' is treated as an unsigned value.</p>
 
 <p>The value produced is <tt>op1</tt> * 2<sup><tt>op2</tt></sup> mod 2<sup>n</sup>,
 where n is the width of the result.  If <tt>op2</tt> is (statically or dynamically) negative or
-equal to or larger than the number of bits in <tt>op1</tt>, the result is undefined.</p>
+equal to or larger than the number of bits in <tt>op1</tt>, the result is undefined.
+If the arguments are vectors, each vector element of <tt>op1</tt> is shifted by the
+corresponding shift amount in <tt>op2</tt>.</p>
 
 <h5>Example:</h5><pre>
   &lt;result&gt; = shl i32 4, %var   <i>; yields {i32}: 4 &lt;&lt; %var</i>
   &lt;result&gt; = shl i32 4, 2      <i>; yields {i32}: 16</i>
   &lt;result&gt; = shl i32 1, 10     <i>; yields {i32}: 1024</i>
   &lt;result&gt; = shl i32 1, 32     <i>; undefined</i>
+  &lt;result&gt; = shl &lt;2 x i32&gt; &lt; i32 1, i32 1&gt;, &lt; i32 1, i32 2&gt;   <i>; yields: result=&lt;2 x i32&gt; &lt; i32 2, i32 4&gt;</i>
 </pre>
 </div>
 <!-- _______________________________________________________________________ -->
@@ -2588,7 +2624,9 @@ type.  '<tt>op2</tt>' is treated as an unsigned value.</p>
 <p>This instruction always performs a logical shift right operation. The most
 significant bits of the result will be filled with zero bits after the 
 shift.  If <tt>op2</tt> is (statically or dynamically) equal to or larger than
-the number of bits in <tt>op1</tt>, the result is undefined.</p>
+the number of bits in <tt>op1</tt>, the result is undefined. If the arguments are
+vectors, each vector element of <tt>op1</tt> is shifted by the corresponding shift
+amount in <tt>op2</tt>.</p>
 
 <h5>Example:</h5>
 <pre>
@@ -2597,6 +2635,7 @@ the number of bits in <tt>op1</tt>, the result is undefined.</p>
   &lt;result&gt; = lshr i8  4, 3   <i>; yields {i8}:result = 0</i>
   &lt;result&gt; = lshr i8 -2, 1   <i>; yields {i8}:result = 0x7FFFFFFF </i>
   &lt;result&gt; = lshr i32 1, 32  <i>; undefined</i>
+  &lt;result&gt; = lshr &lt;2 x i32&gt; &lt; i32 -2, i32 4&gt;, &lt; i32 1, i32 2&gt;   <i>; yields: result=&lt;2 x i32&gt; &lt; i32 0x7FFFFFFF, i32 1&gt;</i>
 </pre>
 </div>
 
@@ -2622,8 +2661,9 @@ type.  '<tt>op2</tt>' is treated as an unsigned value.</p>
 <p>This instruction always performs an arithmetic shift right operation, 
 The most significant bits of the result will be filled with the sign bit 
 of <tt>op1</tt>.  If <tt>op2</tt> is (statically or dynamically) equal to or
-larger than the number of bits in <tt>op1</tt>, the result is undefined.
-</p>
+larger than the number of bits in <tt>op1</tt>, the result is undefined. If the
+arguments are vectors, each vector element of <tt>op1</tt> is shifted by the
+corresponding shift amount in <tt>op2</tt>.</p>
 
 <h5>Example:</h5>
 <pre>
@@ -2632,6 +2672,7 @@ larger than the number of bits in <tt>op1</tt>, the result is undefined.
   &lt;result&gt; = ashr i8  4, 3   <i>; yields {i8}:result = 0</i>
   &lt;result&gt; = ashr i8 -2, 1   <i>; yields {i8}:result = -1</i>
   &lt;result&gt; = ashr i32 1, 32  <i>; undefined</i>
+  &lt;result&gt; = ashr &lt;2 x i32&gt; &lt; i32 -2, i32 4&gt;, &lt; i32 1, i32 3&gt;   <i>; yields: result=&lt;2 x i32&gt; &lt; i32 -1, i32 0&gt;</i>
 </pre>
 </div>
 
@@ -2931,23 +2972,25 @@ exceeds the length of <tt>val</tt>, the results are undefined.
 <h5>Syntax:</h5>
 
 <pre>
-  &lt;result&gt; = shufflevector &lt;n x &lt;ty&gt;&gt; &lt;v1&gt;, &lt;n x &lt;ty&gt;&gt; &lt;v2&gt;, &lt;n x i32&gt; &lt;mask&gt;    <i>; yields &lt;n x &lt;ty&gt;&gt;</i>
+  &lt;result&gt; = shufflevector &lt;n x &lt;ty&gt;&gt; &lt;v1&gt;, &lt;n x &lt;ty&gt;&gt; &lt;v2&gt;, &lt;m x i32&gt; &lt;mask&gt;    <i>; yields &lt;m x &lt;ty&gt;&gt;</i>
 </pre>
 
 <h5>Overview:</h5>
 
 <p>
 The '<tt>shufflevector</tt>' instruction constructs a permutation of elements
-from two input vectors, returning a vector of the same type.
+from two input vectors, returning a vector with the same element type as
+the input and length that is the same as the shuffle mask.
 </p>
 
 <h5>Arguments:</h5>
 
 <p>
-The first two operands of a '<tt>shufflevector</tt>' instruction are vectors
-with types that match each other and types that match the result of the
-instruction.  The third argument is a shuffle mask, which has the same number
-of elements as the other vector type, but whose element type is always 'i32'.
+The first two operands of a '<tt>shufflevector</tt>' instruction are vectors 
+with types that match each other. The third argument is a shuffle mask whose
+element type is always 'i32'.  The result of the instruction is a vector whose
+length is the same as the shuffle mask and whose element type is the same as
+the element type of the first two operands.
 </p>
 
 <p>
@@ -2960,7 +3003,7 @@ constant integer or undef values.
 <p>
 The elements of the two input vectors are numbered from left to right across
 both of the vectors.  The shuffle mask operand specifies, for each element of
-the result vector, which element of the two input registers the result element
+the result vector, which element of the two input vectors the result element
 gets.  The element selector may be undef (meaning "don't care") and the second
 operand may be undef if performing a shuffle from only one vector.
 </p>
@@ -2972,6 +3015,10 @@ operand may be undef if performing a shuffle from only one vector.
                           &lt;4 x i32&gt; &lt;i32 0, i32 4, i32 1, i32 5&gt;  <i>; yields &lt;4 x i32&gt;</i>
   %result = shufflevector &lt;4 x i32&gt; %v1, &lt;4 x i32&gt; undef, 
                           &lt;4 x i32&gt; &lt;i32 0, i32 1, i32 2, i32 3&gt;  <i>; yields &lt;4 x i32&gt;</i> - Identity shuffle.
+  %result = shufflevector &lt;8 x i32&gt; %v1, &lt;8 x i32&gt; undef, 
+                          &lt;4 x i32&gt; &lt;i32 0, i32 1, i32 2, i32 3&gt;  <i>; yields &lt;4 x i32&gt;</i>
+  %result = shufflevector &lt;4 x i32&gt; %v1, &lt;4 x i32&gt; %v2, 
+                          &lt;8 x i32&gt; &lt;i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7 &gt;  <i>; yields &lt;8 x i32&gt;</i>
 </pre>
 </div>
 
@@ -3134,7 +3181,7 @@ choose to align the allocation on any convenient boundary.</p>
 <h5>Semantics:</h5>
 
 <p>Memory is allocated using the system "<tt>malloc</tt>" function, and
-a pointer is returned.  The result of a zero byte allocattion is undefined.  The
+a pointer is returned.  The result of a zero byte allocation is undefined.  The
 result is null if there is insufficient memory available.</p>
 
 <h5>Example:</h5>
@@ -5049,7 +5096,13 @@ for more efficient code generation.
 <div class="doc_text">
 
 <h5>Syntax:</h5>
+<p>This is an overloaded intrinsic. You can use llvm.memcpy on any integer bit
+width. Not all targets support all bit widths however.</p>
 <pre>
+  declare void @llvm.memcpy.i8(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
+                                i8 &lt;len&gt;, i32 &lt;align&gt;)
+  declare void @llvm.memcpy.i16(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
+                                i16 &lt;len&gt;, i32 &lt;align&gt;)
   declare void @llvm.memcpy.i32(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
                                 i32 &lt;len&gt;, i32 &lt;align&gt;)
   declare void @llvm.memcpy.i64(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
@@ -5103,7 +5156,13 @@ be set to 0 or 1.
 <div class="doc_text">
 
 <h5>Syntax:</h5>
+<p>This is an overloaded intrinsic. You can use llvm.memmove on any integer bit
+width. Not all targets support all bit widths however.</p>
 <pre>
+  declare void @llvm.memmove.i8(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
+                                 i8 &lt;len&gt;, i32 &lt;align&gt;)
+  declare void @llvm.memmove.i16(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
+                                 i16 &lt;len&gt;, i32 &lt;align&gt;)
   declare void @llvm.memmove.i32(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
                                  i32 &lt;len&gt;, i32 &lt;align&gt;)
   declare void @llvm.memmove.i64(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
@@ -5158,7 +5217,13 @@ be set to 0 or 1.
 <div class="doc_text">
 
 <h5>Syntax:</h5>
+<p>This is an overloaded intrinsic. You can use llvm.memset on any integer bit
+width. Not all targets support all bit widths however.</p>
 <pre>
+  declare void @llvm.memset.i8(i8 * &lt;dest&gt;, i8 &lt;val&gt;,
+                                i8 &lt;len&gt;, i32 &lt;align&gt;)
+  declare void @llvm.memset.i16(i8 * &lt;dest&gt;, i8 &lt;val&gt;,
+                                i16 &lt;len&gt;, i32 &lt;align&gt;)
   declare void @llvm.memset.i32(i8 * &lt;dest&gt;, i8 &lt;val&gt;,
                                 i32 &lt;len&gt;, i32 &lt;align&gt;)
   declare void @llvm.memset.i64(i8 * &lt;dest&gt;, i8 &lt;val&gt;,
@@ -6400,13 +6465,47 @@ call of the abort() function.
 </p>
 </div>
 
+<!-- _______________________________________________________________________ -->
+<div class="doc_subsubsection">
+  <a name="int_stackprotector">'<tt>llvm.stackprotector</tt>' Intrinsic</a>
+</div>
+<div class="doc_text">
+<h5>Syntax:</h5>
+<pre>
+declare void @llvm.stackprotector( i8* &lt;guard&gt;, i8** &lt;slot&gt; )
+
+</pre>
+<h5>Overview:</h5>
+<p>
+  The <tt>llvm.stackprotector</tt> intrinsic takes the <tt>guard</tt> and stores
+  it onto the stack at <tt>slot</tt>. The stack slot is adjusted to ensure that
+  it is placed on the stack before local variables.
+</p>
+<h5>Arguments:</h5>
+<p>
+  The <tt>llvm.stackprotector</tt> intrinsic requires two pointer arguments. The
+  first argument is the value loaded from the stack guard
+  <tt>@__stack_chk_guard</tt>. The second variable is an <tt>alloca</tt> that
+  has enough space to hold the value of the guard.
+</p>
+<h5>Semantics:</h5>
+<p>
+  This intrinsic causes the prologue/epilogue inserter to force the position of
+  the <tt>AllocaInst</tt> stack slot to be before local variables on the
+  stack. This is to ensure that if a local variable on the stack is overwritten,
+  it will destroy the value of the guard. When the function exits, the guard on
+  the stack is checked against the original guard. If they're different, then
+  the program aborts by calling the <tt>__stack_chk_fail()</tt> function.
+</p>
+</div>
+
 <!-- *********************************************************************** -->
 <hr>
 <address>
   <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
-  src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
+  src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS"></a>
   <a href="http://validator.w3.org/check/referer"><img
-  src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!"></a>
+  src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01"></a>
 
   <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
   <a href="http://llvm.org">The LLVM Compiler Infrastructure</a><br>