Skip to content
LangRef.html 59.9 KiB
Newer Older
Chris Lattner's avatar
Chris Lattner committed
  &lt;result&gt; = setle &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {bool}:result</i>
  &lt;result&gt; = setge &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {bool}:result</i>
</pre>

<h5>Overview:</h5>
The '<tt>set<i>cc</i></tt>' family of instructions returns a boolean value based on a comparison of their two operands.<p>

<h5>Arguments:</h5> The two arguments to the '<tt>set<i>cc</i></tt>'
instructions must be of <a href="#t_firstclass">first class</a> or <a
href="#t_pointer">pointer</a> type (it is not possible to compare
'<tt>label</tt>'s, '<tt>array</tt>'s, '<tt>structure</tt>' or '<tt>void</tt>'
values).  Both arguments must have identical types.<p>
Chris Lattner's avatar
Chris Lattner committed

The '<tt>setlt</tt>', '<tt>setgt</tt>', '<tt>setle</tt>', and '<tt>setge</tt>' instructions do not operate on '<tt>bool</tt>' typed arguments.<p>

<h5>Semantics:</h5>
The '<tt>seteq</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>' value if both operands are equal.<br>
The '<tt>setne</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>' value if both operands are unequal.<br>
The '<tt>setlt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>' value if the first operand is less than the second operand.<br>
The '<tt>setgt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>' value if the first operand is greater than the second operand.<br>
The '<tt>setle</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>' value if the first operand is less than or equal to the second operand.<br>
The '<tt>setge</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>' value if the first operand is greater than or equal to the second operand.<p>

<h5>Example:</h5>
<pre>
  &lt;result&gt; = seteq int   4, 5        <i>; yields {bool}:result = false</i>
  &lt;result&gt; = setne float 4, 5        <i>; yields {bool}:result = true</i>
  &lt;result&gt; = setlt uint  4, 5        <i>; yields {bool}:result = true</i>
  &lt;result&gt; = setgt sbyte 4, 5        <i>; yields {bool}:result = false</i>
  &lt;result&gt; = setle sbyte 4, 5        <i>; yields {bool}:result = true</i>
  &lt;result&gt; = setge sbyte 4, 5        <i>; yields {bool}:result = false</i>
</pre>



<!-- ======================================================================= -->
</ul><table width="100%" bgcolor="#441188" border=0 cellpadding=4 cellspacing=0>
<tr><td>&nbsp;</td><td width="100%">&nbsp; <font color="#EEEEFF" face="Georgia,Palatino"><b>
Chris Lattner's avatar
Chris Lattner committed
<a name="bitwiseops">Bitwise Binary Operations
</b></font></td></tr></table><ul>

Bitwise binary operators are used to do various forms of bit-twiddling in a
program.  They are generally very efficient instructions, and can commonly be
strength reduced from other instructions.  They require two operands, execute an
operation on them, and produce a single value.  The resulting value of the
bitwise binary operators is always the same type as its first operand.<p>
Chris Lattner's avatar
Chris Lattner committed

<!-- _______________________________________________________________________ -->
</ul><a name="i_and"><h4><hr size=0>'<tt>and</tt>' Instruction</h4><ul>

<h5>Syntax:</h5>
<pre>
  &lt;result&gt; = and &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {ty}:result</i>
</pre>

<h5>Overview:</h5>
The '<tt>and</tt>' instruction returns the bitwise logical and of its two operands.<p>

<h5>Arguments:</h5>
The two arguments to the '<tt>and</tt>' instruction must be either <a href="#t_integral">integral</a> or <a href="#t_bool"><tt>bool</tt></a> values.  Both arguments must have identical types.<p>


<h5>Semantics:</h5>
...<p>


<h5>Example:</h5>
<pre>
  &lt;result&gt; = and int 4, %var         <i>; yields {int}:result = 4 & %var</i>
  &lt;result&gt; = and int 15, 40          <i>; yields {int}:result = 8</i>
  &lt;result&gt; = and int 4, 8            <i>; yields {int}:result = 0</i>
</pre>



<!-- _______________________________________________________________________ -->
</ul><a name="i_or"><h4><hr size=0>'<tt>or</tt>' Instruction</h4><ul>

<h5>Syntax:</h5>
<pre>
  &lt;result&gt; = or &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {ty}:result</i>
</pre>

<h5>Overview:</h5> The '<tt>or</tt>' instruction returns the bitwise logical
inclusive or of its two operands.<p>
Chris Lattner's avatar
Chris Lattner committed

<h5>Arguments:</h5>

The two arguments to the '<tt>or</tt>' instruction must be either <a
href="#t_integral">integral</a> or <a href="#t_bool"><tt>bool</tt></a> values.
Both arguments must have identical types.<p>
Chris Lattner's avatar
Chris Lattner committed


<h5>Semantics:</h5>
...<p>


<h5>Example:</h5>
<pre>
  &lt;result&gt; = or int 4, %var         <i>; yields {int}:result = 4 | %var</i>
  &lt;result&gt; = or int 15, 40          <i>; yields {int}:result = 47</i>
  &lt;result&gt; = or int 4, 8            <i>; yields {int}:result = 12</i>
</pre>


<!-- _______________________________________________________________________ -->
</ul><a name="i_xor"><h4><hr size=0>'<tt>xor</tt>' Instruction</h4><ul>

<h5>Syntax:</h5>
<pre>
  &lt;result&gt; = xor &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {ty}:result</i>
</pre>

<h5>Overview:</h5>

The '<tt>xor</tt>' instruction returns the bitwise logical exclusive or of its
two operands.<p>
Chris Lattner's avatar
Chris Lattner committed

<h5>Arguments:</h5>

The two arguments to the '<tt>xor</tt>' instruction must be either <a
href="#t_integral">integral</a> or <a href="#t_bool"><tt>bool</tt></a> values.
Both arguments must have identical types.<p>
Chris Lattner's avatar
Chris Lattner committed


<h5>Semantics:</h5>
...<p>


<h5>Example:</h5>
<pre>
  &lt;result&gt; = xor int 4, %var         <i>; yields {int}:result = 4 ^ %var</i>
  &lt;result&gt; = xor int 15, 40          <i>; yields {int}:result = 39</i>
  &lt;result&gt; = xor int 4, 8            <i>; yields {int}:result = 12</i>
</pre>


<!-- _______________________________________________________________________ -->
</ul><a name="i_shl"><h4><hr size=0>'<tt>shl</tt>' Instruction</h4><ul>

<h5>Syntax:</h5>
<pre>
  &lt;result&gt; = shl &lt;ty&gt; &lt;var1&gt;, ubyte &lt;var2&gt;   <i>; yields {ty}:result</i>
</pre>

<h5>Overview:</h5>

The '<tt>shl</tt>' instruction returns the first operand shifted to the left a
specified number of bits.
Chris Lattner's avatar
Chris Lattner committed

<h5>Arguments:</h5>

The first argument to the '<tt>shl</tt>' instruction must be an <a
href="#t_integral">integral</a> type.  The second argument must be an
'<tt>ubyte</tt>' type.<p>
Chris Lattner's avatar
Chris Lattner committed

<h5>Semantics:</h5>
... 0 bits are shifted into the emptied bit positions...<p>


<h5>Example:</h5>
<pre>
  &lt;result&gt; = shl int 4, ubyte %var   <i>; yields {int}:result = 4 << %var</i>
  &lt;result&gt; = shl int 4, ubyte 2      <i>; yields {int}:result = 16</i>
  &lt;result&gt; = shl int 1, ubyte 10     <i>; yields {int}:result = 1024</i>
</pre>


<!-- _______________________________________________________________________ -->
</ul><a name="i_shr"><h4><hr size=0>'<tt>shr</tt>' Instruction</h4><ul>


<h5>Syntax:</h5>
<pre>
  &lt;result&gt; = shr &lt;ty&gt; &lt;var1&gt;, ubyte &lt;var2&gt;   <i>; yields {ty}:result</i>
</pre>

<h5>Overview:</h5>
The '<tt>shr</tt>' instruction returns the first operand shifted to the right a specified number of bits.

<h5>Arguments:</h5>
The first argument to the '<tt>shr</tt>' instruction must be an  <a href="#t_integral">integral</a> type.  The second argument must be an '<tt>ubyte</tt>' type.<p>

<h5>Semantics:</h5>
... if the first argument is a <a href="#t_signed">signed</a> type, the most significant bit is duplicated in the newly free'd bit positions.  If the first argument is unsigned, zeros shall fill the empty positions...<p>

<h5>Example:</h5>
<pre>
  &lt;result&gt; = shr int 4, ubyte %var   <i>; yields {int}:result = 4 >> %var</i>
  &lt;result&gt; = shr int 4, ubyte 1      <i>; yields {int}:result = 2</i>
  &lt;result&gt; = shr int 4, ubyte 2      <i>; yields {int}:result = 1</i>
  &lt;result&gt; = shr int 4, ubyte 3      <i>; yields {int}:result = 0</i>
</pre>





<!-- ======================================================================= -->
</ul><table width="100%" bgcolor="#441188" border=0 cellpadding=4 cellspacing=0>
<tr><td>&nbsp;</td><td width="100%">&nbsp; <font color="#EEEEFF" face="Georgia,Palatino"><b>
Chris Lattner's avatar
Chris Lattner committed
<a name="memoryops">Memory Access Operations
</b></font></td></tr></table><ul>

Accessing memory in SSA form is, well, sticky at best.  This section describes how to read and write memory in LLVM.<p>


<!-- _______________________________________________________________________ -->
</ul><a name="i_malloc"><h4><hr size=0>'<tt>malloc</tt>' Instruction</h4><ul>

<h5>Syntax:</h5>
<pre>
  &lt;result&gt; = malloc &lt;type&gt;, uint &lt;NumElements&gt;     <i>; yields {type*}:result</i>
  &lt;result&gt; = malloc &lt;type&gt;                         <i>; yields {type*}:result</i>
Chris Lattner's avatar
Chris Lattner committed
</pre>

<h5>Overview:</h5>
The '<tt>malloc</tt>' instruction allocates memory from the system heap and returns a pointer to it.<p>

<h5>Arguments:</h5>

The the '<tt>malloc</tt>' instruction allocates
<tt>sizeof(&lt;type&gt;)*NumElements</tt> bytes of memory from the operating
system, and returns a pointer of the appropriate type to the program.  The
second form of the instruction is a shorter version of the first instruction
that defaults to allocating one element.<p>
Chris Lattner's avatar
Chris Lattner committed

'<tt>type</tt>' must be a sized type<p>
Chris Lattner's avatar
Chris Lattner committed

<h5>Semantics:</h5>
Memory is allocated, a pointer is returned.<p>

<h5>Example:</h5>
<pre>
  %array  = malloc [4 x ubyte ]                    <i>; yields {[%4 x ubyte]*}:array</i>

  %size   = <a href="#i_add">add</a> uint 2, 2                          <i>; yields {uint}:size = uint 4</i>
  %array1 = malloc ubyte, uint 4                   <i>; yields {ubyte*}:array1</i>
  %array2 = malloc [12 x ubyte], uint %size        <i>; yields {[12 x ubyte]*}:array2</i>
Chris Lattner's avatar
Chris Lattner committed
</pre>


<!-- _______________________________________________________________________ -->
</ul><a name="i_free"><h4><hr size=0>'<tt>free</tt>' Instruction</h4><ul>

<h5>Syntax:</h5>
<pre>
  free &lt;type&gt; &lt;value&gt;                              <i>; yields {void}</i>
</pre>


<h5>Overview:</h5>
The '<tt>free</tt>' instruction returns memory back to the unused memory heap, to be reallocated in the future.<p>


<h5>Arguments:</h5>

'<tt>value</tt>' shall be a pointer value that points to a value that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>' instruction.<p>


<h5>Semantics:</h5>
Memory is available for use after this point.  The contents of the '<tt>value</tt>' pointer are undefined after this instruction.<p>


<h5>Example:</h5>
<pre>
  %array  = <a href="#i_malloc">malloc</a> [4 x ubyte]                    <i>; yields {[4 x ubyte]*}:array</i>
            free   [4 x ubyte]* %array
</pre>


<!-- _______________________________________________________________________ -->
</ul><a name="i_alloca"><h4><hr size=0>'<tt>alloca</tt>' Instruction</h4><ul>

<h5>Syntax:</h5>
<pre>
  &lt;result&gt; = alloca &lt;type&gt;, uint &lt;NumElements&gt;  <i>; yields {type*}:result</i>
  &lt;result&gt; = alloca &lt;type&gt;                      <i>; yields {type*}:result</i>
Chris Lattner's avatar
Chris Lattner committed
</pre>

<h5>Overview:</h5>

The '<tt>alloca</tt>' instruction allocates memory on the current stack frame of
the procedure that is live until the current function returns to its caller.<p>
Chris Lattner's avatar
Chris Lattner committed

<h5>Arguments:</h5>

The the '<tt>alloca</tt>' instruction allocates
<tt>sizeof(&lt;type&gt;)*NumElements</tt> bytes of memory on the runtime stack,
returning a pointer of the appropriate type to the program.  The second form of
the instruction is a shorter version of the first that defaults to allocating
one element.<p>
Chris Lattner's avatar
Chris Lattner committed

'<tt>type</tt>' may be any sized type.<p>
Chris Lattner's avatar
Chris Lattner committed

<h5>Semantics:</h5>

Memory is allocated, a pointer is returned.  '<tt>alloca</tt>'d memory is
automatically released when the function returns.  The '<tt>alloca</tt>'
instruction is commonly used to represent automatic variables that must have an
address available, as well as spilled variables.<p>
Chris Lattner's avatar
Chris Lattner committed

<h5>Example:</h5>
<pre>
  %ptr = alloca int                              <i>; yields {int*}:ptr</i>
  %ptr = alloca int, uint 4                      <i>; yields {int*}:ptr</i>
</pre>


<!-- _______________________________________________________________________ -->
</ul><a name="i_load"><h4><hr size=0>'<tt>load</tt>' Instruction</h4><ul>
  &lt;result&gt; = load &lt;ty&gt;* &lt;pointer&gt;
The '<tt>load</tt>' instruction is used to read from memory.<p>
The argument to the '<tt>load</tt>' instruction specifies the memory address to load from.  The pointer must point to a <a href="t_firstclass">first class</a> type.<p>
The location of memory pointed to is loaded.
<h5>Examples:</h5>
  %ptr = <a href="#i_alloca">alloca</a> int                               <i>; yields {int*}:ptr</i>
  <a href="#i_store">store</a> int 3, int* %ptr                          <i>; yields {void}</i>
  %val = load int* %ptr                           <i>; yields {int}:val = int 3</i>
Chris Lattner's avatar
Chris Lattner committed
<!-- _______________________________________________________________________ -->
</ul><a name="i_store"><h4><hr size=0>'<tt>store</tt>' Instruction</h4><ul>
Chris Lattner's avatar
Chris Lattner committed

<h5>Syntax:</h5>
<pre>
  store &lt;ty&gt; &lt;value&gt;, &lt;ty&gt;* &lt;pointer&gt;                   <i>; yields {void}</i>
Chris Lattner's avatar
Chris Lattner committed
</pre>

<h5>Overview:</h5>
The '<tt>store</tt>' instruction is used to write to memory.<p>
Chris Lattner's avatar
Chris Lattner committed

<h5>Arguments:</h5>

There are two arguments to the '<tt>store</tt>' instruction: a value to store
and an address to store it into.  The type of the '<tt>&lt;pointer&gt;</tt>'
operand must be a pointer to the type of the '<tt>&lt;value&gt;</tt>'
operand.<p>
<h5>Semantics:</h5> The contents of memory are updated to contain
'<tt>&lt;value&gt;</tt>' at the location specified by the
'<tt>&lt;pointer&gt;</tt>' operand.<p>
Chris Lattner's avatar
Chris Lattner committed

<h5>Example:</h5>
Chris Lattner's avatar
Chris Lattner committed
<pre>
  %ptr = <a href="#i_alloca">alloca</a> int                               <i>; yields {int*}:ptr</i>
  <a href="#i_store">store</a> int 3, int* %ptr                          <i>; yields {void}</i>
Chris Lattner's avatar
Chris Lattner committed
  %val = load int* %ptr                           <i>; yields {int}:val = int 3</i>
</pre>




<!-- _______________________________________________________________________ -->
</ul><a name="i_getelementptr"><h4><hr size=0>'<tt>getelementptr</tt>' Instruction</h4><ul>
Chris Lattner's avatar
Chris Lattner committed

<h5>Syntax:</h5>
<pre>
  &lt;result&gt; = getelementptr &lt;ty&gt;* &lt;ptrval&gt;{, uint &lt;aidx&gt;|, ubyte &lt;sidx&gt;}*
Chris Lattner's avatar
Chris Lattner committed
</pre>

<h5>Overview:</h5>

The '<tt>getelementptr</tt>' instruction is used to get the address of a
subelement of an aggregate data structure.  In addition to being present as an
explicit instruction, the '<tt>getelementptr</tt>' functionality is present in
both the '<tt><a href="#i_load">load</a></tt>' and '<tt><a
href="#i_store">store</a></tt>' instructions to allow more compact specification
of common expressions.<p>
Chris Lattner's avatar
Chris Lattner committed

<h5>Arguments:</h5>

This instruction takes a list of <tt>uint</tt> values and <tt>ubyte</tt>
constants that indicate what form of addressing to perform.  The actual types of
the arguments provided depend on the type of the first pointer argument.  The
'<tt>getelementptr</tt>' instruction is used to index down through the type
levels of a structure.<p>

TODO.
Chris Lattner's avatar
Chris Lattner committed

<h5>Semantics:</h5>
Chris Lattner's avatar
Chris Lattner committed

<h5>Example:</h5>
<pre>
  %aptr = getelementptr {int, [12 x ubyte]}* %sptr, 1   <i>; yields {[12 x ubyte]*}:aptr</i>
  %ub   = load [12x ubyte]* %aptr, 4                    <i>;yields {ubyte}:ub</i>
Chris Lattner's avatar
Chris Lattner committed
</pre>



<!-- ======================================================================= -->
</ul><table width="100%" bgcolor="#441188" border=0 cellpadding=4 cellspacing=0>
<tr><td>&nbsp;</td><td width="100%">&nbsp; <font color="#EEEEFF" face="Georgia,Palatino"><b>
Chris Lattner's avatar
Chris Lattner committed
<a name="otherops">Other Operations
</b></font></td></tr></table><ul>

The instructions in this catagory are the "miscellaneous" functions, that defy better classification.<p>


<!-- _______________________________________________________________________ -->
</ul><a name="i_cast"><h4><hr size=0>'<tt>cast .. to</tt>' Instruction</h4><ul>

<h1>TODO</h1>

<a name="logical_integrals">
  Talk about what is considered true or false for integrals.



<h5>Syntax:</h5>
<pre>
</pre>

<h5>Overview:</h5>


<h5>Arguments:</h5>


<h5>Semantics:</h5>


<h5>Example:</h5>
<pre>
</pre>



Chris Lattner's avatar
Chris Lattner committed
<!-- _______________________________________________________________________ -->
</ul><a name="i_call"><h4><hr size=0>'<tt>call</tt>' Instruction</h4><ul>

<h5>Syntax:</h5>
<pre>

</pre>

<h5>Overview:</h5>


<h5>Arguments:</h5>


<h5>Semantics:</h5>


<h5>Example:</h5>
<pre>
  %retval = call int %test(int %argc)
</pre>


<!-- _______________________________________________________________________ --></ul><a name="i_icall"><h3><hr size=0>'<tt>icall</tt>' Instruction</h3><ul>

Indirect calls are desperately needed to implement virtual function tables (C++, java) and function pointers (C, C++, ...).<p>

A new instruction <tt>icall</tt> or similar should be introduced to represent an indirect call.<p>

Example:
<pre>
  %retval = icall int %funcptr(int %arg1)          <i>; yields {int}:%retval</i>
</pre>



<!-- _______________________________________________________________________ -->
</ul><a name="i_phi"><h4><hr size=0>'<tt>phi</tt>' Instruction</h4><ul>

<h5>Syntax:</h5>
<pre>
</pre>

<h5>Overview:</h5>


<h5>Arguments:</h5>


<h5>Semantics:</h5>


<h5>Example:</h5>
<pre>
</pre>



<!-- *********************************************************************** -->
</ul><table width="100%" bgcolor="#330077" border=0 cellpadding=4 cellspacing=0>
<tr><td align=center><font color="#EEEEFF" size=+2 face="Georgia,Palatino"><b>
Chris Lattner's avatar
Chris Lattner committed
<a name="related">Related Work
</b></font></td></tr></table><ul>
<!-- *********************************************************************** -->


Codesigned virtual machines.<p>

<dl>
<a name="rw_safetsa">
<dt>SafeTSA
<DD>Description here<p>

<a name="rw_java">
<dt><a href="http://www.javasoft.com">Java</a>
<DD>Desciption here<p>

<a name="rw_net">
<dt><a href="http://www.microsoft.com/net">Microsoft .net</a>
<DD>Desciption here<p>

<a name="rw_gccrtl">
<dt><a href="http://www.math.umn.edu/systems_guide/gcc-2.95.1/gcc_15.html">GNU RTL Intermediate Representation</a>
<DD>Desciption here<p>

<a name="rw_ia64">
<dt><a href="http://developer.intel.com/design/ia-64/index.htm">IA64 Architecture &amp; Instruction Set</a>
<DD>Desciption here<p>

<a name="rw_mmix">
<dt><a href="http://www-cs-faculty.stanford.edu/~knuth/mmix-news.html">MMIX Instruction Set</a>
<DD>Desciption here<p>

<a name="rw_stroustrup">
<dt><a href="http://www.research.att.com/~bs/devXinterview.html">"Interview With Bjarne Stroustrup"</a>
<DD>This interview influenced the design and thought process behind LLVM in several ways, most notably the way that derived types are written in text format. See the question that starts with "you defined the C declarator syntax as an experiment that failed".<p>
</dl>

<!-- _______________________________________________________________________ -->
</ul><a name="rw_vectorization"><h3><hr size=0>Vectorized Architectures</h3><ul>

<dl>
<a name="rw_intel_simd">
<dt>Intel MMX, MMX2, SSE, SSE2
<DD>Description here<p>

<a name="rw_amd_simd">
<dt><a href="http://www.nondot.org/~sabre/os/H1ChipFeatures/3DNow!TechnologyManual.pdf">AMD 3Dnow!, 3Dnow! 2</a>
<DD>Desciption here<p>

<a name="rw_sun_simd">
<dt><a href="http://www.nondot.org/~sabre/os/H1ChipFeatures/VISInstructionSetUsersManual.pdf">Sun VIS ISA</a>
<DD>Desciption here<p>


</dl>

more...

<!-- *********************************************************************** -->
</ul>
<!-- *********************************************************************** -->


<hr>
<font size=-1>
<address><a href="mailto:sabre@nondot.org">Chris Lattner</a></address>
<!-- Created: Tue Jan 23 15:19:28 CST 2001 -->
<!-- hhmts start -->
Last modified: Fri May  3 14:39:52 CDT 2002
Chris Lattner's avatar
Chris Lattner committed
<!-- hhmts end -->
</font>
</body></html>