accepts and what is considered 'well formed'. For example, the
following instruction is syntactically okay, but not well formed:</p>
+<div class="doc_code">
<pre>
- %x = <a href="#i_add">add</a> i32 1, %x
+%x = <a href="#i_add">add</a> i32 1, %x
</pre>
+</div>
<p>...because the definition of <tt>%x</tt> does not dominate all of
its uses. The LLVM infrastructure provides a verification pass that may
the optimizer before it outputs bytecode. The violations pointed out
by the verifier pass indicate bugs in transformation passes or input to
the parser.</p>
+</div>
<!-- Describe the typesetting conventions here. --> </div>
<p>The easy way:</p>
+<div class="doc_code">
<pre>
- %result = <a href="#i_mul">mul</a> i32 %X, 8
+%result = <a href="#i_mul">mul</a> i32 %X, 8
</pre>
+</div>
<p>After strength reduction:</p>
+<div class="doc_code">
<pre>
- %result = <a href="#i_shl">shl</a> i32 %X, i8 3
+%result = <a href="#i_shl">shl</a> i32 %X, i8 3
</pre>
+</div>
<p>And the hard way:</p>
+<div class="doc_code">
<pre>
- <a href="#i_add">add</a> i32 %X, %X <i>; yields {i32}:%0</i>
- <a href="#i_add">add</a> i32 %0, %0 <i>; yields {i32}:%1</i>
- %result = <a href="#i_add">add</a> i32 %1, %1
+<a href="#i_add">add</a> i32 %X, %X <i>; yields {i32}:%0</i>
+<a href="#i_add">add</a> i32 %0, %0 <i>; yields {i32}:%1</i>
+%result = <a href="#i_add">add</a> i32 %1, %1
</pre>
+</div>
<p>This last way of multiplying <tt>%X</tt> by 8 illustrates several
important lexical features of LLVM:</p>
global variable) definitions, resolves forward declarations, and merges
symbol table entries. Here is an example of the "hello world" module:</p>
+<div class="doc_code">
<pre><i>; Declare the string constant as a global constant...</i>
<a href="#identifiers">%.LC0</a> = <a href="#linkage_internal">internal</a> <a
href="#globalvars">constant</a> <a href="#t_array">[13 x i8 ]</a> c"hello world\0A\00" <i>; [13 x i8 ]*</i>
<a
href="#i_call">call</a> i32 %puts(i8 * %cast210) <i>; i32</i>
<a
- href="#i_ret">ret</a> i32 0<br>}<br></pre>
+ href="#i_ret">ret</a> i32 0<br>}<br>
+</pre>
+</div>
<p>This example is made up of a <a href="#globalvars">global variable</a>
named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>"
<p>For example, the following defines a global with an initializer, section,
and alignment:</p>
+<div class="doc_code">
<pre>
- %G = constant float 1.0, section "foo", align 4
+%G = constant float 1.0, section "foo", align 4
</pre>
+</div>
</div>
<h5>Syntax:</h5>
+<div class="doc_code">
<pre>
- @<Name> = [Linkage] [Visibility] alias <AliaseeTy> @<Aliasee>
+@<Name> = [Linkage] [Visibility] alias <AliaseeTy> @<Aliasee>
</pre>
+</div>
</div>
<p>Parameter attributes are simple keywords that follow the type specified. If
multiple parameter attributes are needed, they are space separated. For
- example:</p><pre>
- %someFunc = i16 (i8 sext %someParam) zext
- %someFunc = i16 (i8 zext %someParam) zext</pre>
+ example:</p>
+
+<div class="doc_code">
+<pre>
+%someFunc = i16 (i8 sext %someParam) zext
+%someFunc = i16 (i8 zext %someParam) zext
+</pre>
+</div>
+
<p>Note that the two function types above are unique because the parameter has
a different attribute (sext in the first one, zext in the second). Also note
that the attribute for the function result (zext) comes immediately after the
desired. The syntax is very simple:
</p>
-<div class="doc_code"><pre>
- module asm "inline asm code goes here"
- module asm "more can go here"
-</pre></div>
+<div class="doc_code">
+<pre>
+module asm "inline asm code goes here"
+module asm "more can go here"
+</pre>
+</div>
<p>The strings can contain any character by escaping non-printable characters.
The escape sequence used is simply "\xx" where "xx" is the two digit hex code
</td>
</tr>
</table>
+</div>
<!-- _______________________________________________________________________ -->
<div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div>
href="#t_pointer">pointer</a> type. For example, the following is a legal LLVM
file:</p>
+<div class="doc_code">
<pre>
- %X = global i32 17
- %Y = global i32 42
- %Z = global [2 x i32*] [ i32* %X, i32* %Y ]
+%X = global i32 17
+%Y = global i32 42
+%Z = global [2 x i32*] [ i32* %X, i32* %Y ]
</pre>
+</div>
</div>
inline assembler expression is:
</p>
+<div class="doc_code">
<pre>
- i32 (i32) asm "bswap $0", "=r,r"
+i32 (i32) asm "bswap $0", "=r,r"
</pre>
+</div>
<p>
Inline assembler expressions may <b>only</b> be used as the callee operand of
a <a href="#i_call"><tt>call</tt> instruction</a>. Thus, typically we have:
</p>
+<div class="doc_code">
<pre>
- %X = call i32 asm "<a href="#int_bswap">bswap</a> $0", "=r,r"(i32 %Y)
+%X = call i32 asm "<a href="#int_bswap">bswap</a> $0", "=r,r"(i32 %Y)
</pre>
+</div>
<p>
Inline asms with side effects not visible in the constraint list must be marked
'<tt>sideeffect</tt>' keyword, like so:
</p>
+<div class="doc_code">
<pre>
- call void asm sideeffect "eieio", ""()
+call void asm sideeffect "eieio", ""()
</pre>
+</div>
<p>TODO: The format of the asm and constraints string still need to be
documented here. Constraints on what can be done (e.g. duplication, moving, etc
<pre>
%ptr = alloca i32 <i>; yields {i32*}:ptr</i>
- %ptr = alloca i32, i32 4 <i>; yields {i32*}:ptr</i>
- %ptr = alloca i32, i32 4, align 1024 <i>; yields {i32*}:ptr</i>
+ %ptr = alloca i32, i32 4 <i>; yields {i32*}:ptr</i>
+ %ptr = alloca i32, i32 4, align 1024 <i>; yields {i32*}:ptr</i>
%ptr = alloca i32, align 1024 <i>; yields {i32*}:ptr</i>
</pre>
</div>
<p>For example, let's consider a C code fragment and how it gets
compiled to LLVM:</p>
+<div class="doc_code">
<pre>
- struct RT {
- char A;
- i32 B[10][20];
- char C;
- };
- struct ST {
- i32 X;
- double Y;
- struct RT Z;
- };
-
- define i32 *foo(struct ST *s) {
- return &s[1].Z.B[5][13];
- }
+struct RT {
+ char A;
+ i32 B[10][20];
+ char C;
+};
+struct ST {
+ i32 X;
+ double Y;
+ struct RT Z;
+};
+
+i32 *foo(struct ST *s) {
+ return &s[1].Z.B[5][13];
+}
</pre>
+</div>
<p>The LLVM code generated by the GCC frontend is:</p>
+<div class="doc_code">
<pre>
- %RT = type { i8 , [10 x [20 x i32]], i8 }
- %ST = type { i32, double, %RT }
+%RT = type { i8 , [10 x [20 x i32]], i8 }
+%ST = type { i32, double, %RT }
- define i32* %foo(%ST* %s) {
- entry:
- %reg = getelementptr %ST* %s, i32 1, i32 2, i32 1, i32 5, i32 13
- ret i32* %reg
- }
+define i32* %foo(%ST* %s) {
+entry:
+ %reg = getelementptr %ST* %s, i32 1, i32 2, i32 1, i32 5, i32 13
+ ret i32* %reg
+}
</pre>
+</div>
<h5>Semantics:</h5>
instruction and the variable argument handling intrinsic functions are
used.</p>
+<div class="doc_code">
<pre>
define i32 @test(i32 %X, ...) {
; Initialize variable argument processing
</pre>
</div>
+</div>
+
<!-- _______________________________________________________________________ -->
<div class="doc_subsubsection">
<a name="int_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a>