blob: 4c1f64b30a4ce4041da5145600ca2c2e8679b21d [file] [log] [blame]
Reid Spencer9bd2be22004-07-29 00:13:04 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
Reid Spencer50026612004-05-22 02:28:36 +00002<html>
3<head>
Reid Spencer09daa632004-08-18 20:06:19 +00004 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
Reid Spencer50026612004-05-22 02:28:36 +00005 <title>LLVM Bytecode File Format</title>
6 <link rel="stylesheet" href="llvm.css" type="text/css">
Reid Spencer1ab929c2004-07-05 08:18:07 +00007 <style type="text/css">
Reid Spencer2de29992004-08-03 20:21:05 +00008 TR, TD { border: 2px solid gray; padding-left: 4pt; padding-right: 4pt;
9 padding-top: 2pt; padding-bottom: 2pt; }
Reid Spencer1ab929c2004-07-05 08:18:07 +000010 TH { border: 2px solid gray; font-weight: bold; font-size: 105%; }
Reid Spencer2cc36152004-07-05 19:04:27 +000011 TABLE { text-align: center; border: 2px solid black;
Reid Spencer2de29992004-08-03 20:21:05 +000012 border-collapse: collapse; margin-top: 1em; margin-left: 1em;
13 margin-right: 1em; margin-bottom: 1em; }
Reid Spencer2cc36152004-07-05 19:04:27 +000014 .td_left { border: 2px solid gray; text-align: left; }
Reid Spencer50026612004-05-22 02:28:36 +000015 </style>
16</head>
17<body>
Reid Spencer9bd2be22004-07-29 00:13:04 +000018<div class="doc_title"> LLVM Bytecode File Format </div>
Reid Spencer50026612004-05-22 02:28:36 +000019<ol>
20 <li><a href="#abstract">Abstract</a></li>
Reid Spencer1ab929c2004-07-05 08:18:07 +000021 <li><a href="#concepts">Concepts</a>
Reid Spencer50026612004-05-22 02:28:36 +000022 <ol>
23 <li><a href="#blocks">Blocks</a></li>
24 <li><a href="#lists">Lists</a></li>
25 <li><a href="#fields">Fields</a></li>
26 <li><a href="#align">Alignment</a></li>
Reid Spencer82c46712004-07-07 13:34:26 +000027 <li><a href="#vbr">Variable Bit-Rate Encoding</a></li>
Reid Spencer1ab929c2004-07-05 08:18:07 +000028 <li><a href="#encoding">Encoding Primitives</a></li>
29 <li><a href="#slots">Slots</a></li>
30 </ol>
31 </li>
Reid Spencer51f31e02004-07-05 22:28:02 +000032 <li><a href="#general">General Structure</a> </li>
33 <li><a href="#blockdefs">Block Definitions</a>
Reid Spencer1ab929c2004-07-05 08:18:07 +000034 <ol>
Reid Spencerb39021b2004-05-23 17:05:09 +000035 <li><a href="#signature">Signature Block</a></li>
36 <li><a href="#module">Module Block</a></li>
Reid Spencer1ab929c2004-07-05 08:18:07 +000037 <li><a href="#globaltypes">Global Type Pool</a></li>
38 <li><a href="#globalinfo">Module Info Block</a></li>
39 <li><a href="#constantpool">Global Constant Pool</a></li>
40 <li><a href="#functiondefs">Function Definition</a></li>
41 <li><a href="#compactiontable">Compaction Table</a></li>
Chris Lattnerf97fa592005-11-05 22:20:06 +000042 <li><a href="#instructionlist">Instructions List</a></li>
43 <li><a href="#instructions">Instructions</a></li>
Reid Spencer1ab929c2004-07-05 08:18:07 +000044 <li><a href="#symtab">Symbol Table</a></li>
Reid Spencer50026612004-05-22 02:28:36 +000045 </ol>
46 </li>
Reid Spencer7c76d332004-06-08 07:41:41 +000047 <li><a href="#versiondiffs">Version Differences</a>
48 <ol>
Chris Lattnera1dad812004-10-16 18:03:55 +000049 <li><a href="#vers13">Version 1.3 Differences From 1.4</a></li>
Reid Spencer7c76d332004-06-08 07:41:41 +000050 <li><a href="#vers12">Version 1.2 Differences From 1.3</a></li>
51 <li><a href="#vers11">Version 1.1 Differences From 1.2</a></li>
52 <li><a href="#vers10">Version 1.0 Differences From 1.1</a></li>
53 </ol>
54 </li>
Reid Spencer50026612004-05-22 02:28:36 +000055</ol>
Chris Lattner8dabb502004-05-25 17:44:58 +000056<div class="doc_author">
57<p>Written by <a href="mailto:rspencer@x10sys.com">Reid Spencer</a>
58</p>
Reid Spencer50026612004-05-22 02:28:36 +000059</div>
60<!-- *********************************************************************** -->
61<div class="doc_section"> <a name="abstract">Abstract </a></div>
62<!-- *********************************************************************** -->
63<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +000064<p>This document describes the LLVM bytecode file format. It specifies
65the binary encoding rules of the bytecode file format so that
66equivalent systems can encode bytecode files correctly. The LLVM
67bytecode representation is used to store the intermediate
68representation on disk in compacted form.</p>
69<p>The LLVM bytecode format may change in the future, but LLVM will
70always be backwards compatible with older formats. This document will
71only describe the most current version of the bytecode format. See <a
72 href="#versiondiffs">Version Differences</a> for the details on how
73the current version is different from previous versions.</p>
Reid Spencer50026612004-05-22 02:28:36 +000074</div>
75<!-- *********************************************************************** -->
Reid Spencer1ab929c2004-07-05 08:18:07 +000076<div class="doc_section"> <a name="concepts">Concepts</a> </div>
Reid Spencer50026612004-05-22 02:28:36 +000077<!-- *********************************************************************** -->
78<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +000079<p>This section describes the general concepts of the bytecode file
80format without getting into specific layout details. It is recommended
81that you read this section thoroughly before interpreting the detailed
82descriptions.</p>
Reid Spencer50026612004-05-22 02:28:36 +000083</div>
84<!-- _______________________________________________________________________ -->
85<div class="doc_subsection"><a name="blocks">Blocks</a> </div>
86<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +000087<p>LLVM bytecode files consist simply of a sequence of blocks of bytes
88using a binary encoding Each block begins with an header of two
89unsigned integers. The first value identifies the type of block and the
90second value provides the size of the block in bytes. The block
91identifier is used because it is possible for entire blocks to be
92omitted from the file if they are empty. The block identifier helps the
93reader determine which kind of block is next in the file. Note that
94blocks can be nested within other blocks.</p>
95<p> All blocks are variable length, and the block header specifies the
96size of the block. All blocks begin on a byte index that is aligned to
97an even 32-bit boundary. That is, the first block is 32-bit aligned
98because it starts at offset 0. Each block is padded with zero fill
99bytes to ensure that the next block also starts on a 32-bit boundary.</p>
Reid Spencer50026612004-05-22 02:28:36 +0000100</div>
101<!-- _______________________________________________________________________ -->
102<div class="doc_subsection"><a name="lists">Lists</a> </div>
103<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +0000104<p>LLVM Bytecode blocks often contain lists of things of a similar
105type. For example, a function contains a list of instructions and a
106function type contains a list of argument types. There are two basic
107types of lists: length lists (<a href="#llist">llist</a>), and null
108terminated lists (<a href="#zlist">zlist</a>), as described below in
109the <a href="#encoding">Encoding Primitives</a>.</p>
Reid Spencer50026612004-05-22 02:28:36 +0000110</div>
111<!-- _______________________________________________________________________ -->
112<div class="doc_subsection"><a name="fields">Fields</a> </div>
113<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +0000114<p>Fields are units of information that LLVM knows how to write atomically. Most
115fields have a uniform length or some kind of length indication built into their
116encoding. For example, a constant string (array of bytes) is written simply as
117the length followed by the characters. Although this is similar to a list,
118constant strings are treated atomically and are thus fields.</p>
Reid Spencer50026612004-05-22 02:28:36 +0000119<p>Fields use a condensed bit format specific to the type of information
120they must contain. As few bits as possible are written for each field. The
Reid Spencer9bd2be22004-07-29 00:13:04 +0000121sections that follow will provide the details on how these fields are
Reid Spencer50026612004-05-22 02:28:36 +0000122written and how the bits are to be interpreted.</p>
123</div>
124<!-- _______________________________________________________________________ -->
Reid Spencer1ab929c2004-07-05 08:18:07 +0000125<div class="doc_subsection"><a name="align">Alignment</a> </div>
Reid Spencer7aa940d2004-05-25 15:47:57 +0000126<div class="doc_text">
Reid Spencer267660f2004-08-03 20:33:56 +0000127 <p>To support cross-platform differences, the bytecode file is aligned on
128 certain boundaries. This means that a small amount of padding (at most 3
129 bytes) will be added to ensure that the next entry is aligned to a 32-bit
130 boundary.</p>
Chris Lattner8dabb502004-05-25 17:44:58 +0000131</div>
Reid Spencer7aa940d2004-05-25 15:47:57 +0000132<!-- _______________________________________________________________________ -->
Reid Spencer9bd2be22004-07-29 00:13:04 +0000133<div class="doc_subsection"><a name="vbr">Variable Bit-Rate Encoding</a>
Reid Spencer82c46712004-07-07 13:34:26 +0000134</div>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000135<div class="doc_text">
136<p>Most of the values written to LLVM bytecode files are small integers. To
137minimize the number of bytes written for these quantities, an encoding scheme
138similar to UTF-8 is used to write integer data. The scheme is known as
139variable bit rate (vbr) encoding. In this encoding, the high bit of
140each byte is used to indicate if more bytes follow. If (byte &amp;
1410x80) is non-zero in any given byte, it means there is another byte
142immediately following that also contributes to the value. For the final
143byte (byte &amp; 0x80) is false (the high bit is not set). In each byte
144only the low seven bits contribute to the value. Consequently 32-bit
145quantities can take from one to <em>five</em> bytes to encode. In
146general, smaller quantities will encode in fewer bytes, as follows:</p>
147<table>
148 <tbody>
149 <tr>
150 <th>Byte #</th>
151 <th>Significant Bits</th>
152 <th>Maximum Value</th>
153 </tr>
154 <tr>
155 <td>1</td>
156 <td>0-6</td>
157 <td>127</td>
158 </tr>
159 <tr>
160 <td>2</td>
161 <td>7-13</td>
162 <td>16,383</td>
163 </tr>
164 <tr>
165 <td>3</td>
166 <td>14-20</td>
167 <td>2,097,151</td>
168 </tr>
169 <tr>
170 <td>4</td>
171 <td>21-27</td>
172 <td>268,435,455</td>
173 </tr>
174 <tr>
175 <td>5</td>
176 <td>28-34</td>
177 <td>34,359,738,367</td>
178 </tr>
179 <tr>
180 <td>6</td>
181 <td>35-41</td>
182 <td>4,398,046,511,103</td>
183 </tr>
184 <tr>
185 <td>7</td>
186 <td>42-48</td>
187 <td>562,949,953,421,311</td>
188 </tr>
189 <tr>
190 <td>8</td>
191 <td>49-55</td>
192 <td>72,057,594,037,927,935</td>
193 </tr>
194 <tr>
195 <td>9</td>
196 <td>56-62</td>
197 <td>9,223,372,036,854,775,807</td>
198 </tr>
199 <tr>
200 <td>10</td>
201 <td>63-69</td>
202 <td>1,180,591,620,717,411,303,423</td>
203 </tr>
204 </tbody>
205</table>
206<p>Note that in practice, the tenth byte could only encode bit 63 since
207the maximum quantity to use this encoding is a 64-bit integer.</p>
208<p><em>Signed</em> VBR values are encoded with the standard vbr
209encoding, but with the sign bit as the low order bit instead of the
210high order bit. This allows small negative quantities to be encoded
211efficiently. For example, -3
212is encoded as "((3 &lt;&lt; 1) | 1)" and 3 is encoded as "(3 &lt;&lt;
2131) | 0)", emitted with the standard vbr encoding above.</p>
214</div>
Reid Spencer82c46712004-07-07 13:34:26 +0000215<!-- _______________________________________________________________________ -->
216<div class="doc_subsection"><a name="encoding">Encoding Primitives</a> </div>
217<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +0000218<p>Each field in the bytecode format is encoded into the file using a
219small set of primitive formats. The table below defines the encoding
220rules for the various primitives used and gives them each a type name.
221The type names used in the descriptions of blocks and fields in the <a
222 href="#details">Detailed Layout</a>next section. Any type name with
223the suffix <em>_vbr</em> indicates a quantity that is encoded using
224variable bit rate encoding as described above.</p>
225<table class="doc_table">
226 <tbody>
227 <tr>
228 <th><b>Type</b></th>
229 <th class="td_left"><b>Rule</b></th>
230 </tr>
231 <tr>
232 <td><a name="unsigned"><b>unsigned</b></a></td>
233 <td class="td_left">A 32-bit unsigned integer that always occupies four
Reid Spencerb39021b2004-05-23 17:05:09 +0000234 consecutive bytes. The unsigned integer is encoded using LSB first
235 ordering. That is bits 2<sup>0</sup> through 2<sup>7</sup> are in the
236 byte with the lowest file offset (little endian).</td>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000237 </tr>
238 <tr>
Reid Spencer301fe482004-08-03 20:57:56 +0000239 <td style="vertical-align: top;"><a name="uint24_vbr">
240 <b>uint24_vbr</b></a></td>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000241 <td style="vertical-align: top; text-align: left;">A 24-bit unsigned
242 integer that occupies from one to four bytes using variable bit rate
243 encoding.</td>
244 </tr>
245 <tr>
246 <td><a name="uint32_vbr"><b>uint32_vbr</b></a></td>
Reid Spencerf08561f2004-08-03 19:20:18 +0000247 <td class="td_left">A 32-bit unsigned integer that occupies from one to
248 five bytes using variable bit rate encoding.</td>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000249 </tr>
250 <tr>
251 <td><a name="uint64_vbr"><b>uint64_vbr</b></a></td>
Reid Spencerf08561f2004-08-03 19:20:18 +0000252 <td class="td_left">A 64-bit unsigned integer that occupies from one to ten
253 bytes using variable bit rate encoding.</td>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000254 </tr>
255 <tr>
256 <td><a name="int64_vbr"><b>int64_vbr</b></a></td>
Reid Spencerf08561f2004-08-03 19:20:18 +0000257 <td class="td_left">A 64-bit signed integer that occupies from one to ten
258 bytes using the signed variable bit rate encoding.</td>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000259 </tr>
260 <tr>
261 <td><a name="char"><b>char</b></a></td>
Reid Spencerf08561f2004-08-03 19:20:18 +0000262 <td class="td_left">A single unsigned character encoded into one byte</td>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000263 </tr>
264 <tr>
265 <td><a name="bit"><b>bit(n-m)</b></a></td>
Reid Spencerf08561f2004-08-03 19:20:18 +0000266 <td class="td_left">A set of bit within some larger integer field. The values
267 of <code>n</code> and <code>m</code> specify the inclusive range of bits
268 that define the subfield. The value for <code>m</code> may be omitted if
269 its the same as <code>n</code>.</td>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000270 </tr>
271 <tr>
272 <td style="vertical-align: top;"><b><a name="float"><b>float</b></a></b></td>
Reid Spencerf08561f2004-08-03 19:20:18 +0000273 <td style="vertical-align: top; text-align: left;">A floating point value encoded
274 as a 32-bit IEEE value written in little-endian form.<br>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000275 </td>
276 </tr>
277 <tr>
278 <td style="vertical-align: top;"><b><b><a name="double"><b>double</b></a></b></b></td>
Reid Spencerf08561f2004-08-03 19:20:18 +0000279 <td style="vertical-align: top; text-align: left;">A floating point value encoded
280 as a64-bit IEEE value written in little-endian form</td>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000281 </tr>
282 <tr>
283 <td><a name="string"><b>string</b></a></td>
284 <td class="td_left">A uint32_vbr indicating the type of the
285constant string which also includes its length, immediately followed by
286the characters of the string. There is no terminating null byte in the
287string.</td>
288 </tr>
289 <tr>
290 <td><a name="data"><b>data</b></a></td>
291 <td class="td_left">An arbitrarily long segment of data to which
292no interpretation is implied. This is used for constant initializers.<br>
293 </td>
294 </tr>
295 <tr>
296 <td><a name="llist"><b>llist(x)</b></a></td>
297 <td class="td_left">A length list of x. This means the list is
298encoded as an <a href="#uint32_vbr">uint32_vbr</a> providing the
299length of the list, followed by a sequence of that many "x" items. This
300implies that the reader should iterate the number of times provided by
301the length.</td>
302 </tr>
303 <tr>
304 <td><a name="zlist"><b>zlist(x)</b></a></td>
305 <td class="td_left">A zero-terminated list of x. This means the
306list is encoded as a sequence of an indeterminate number of "x" items,
307followed by an <a href="#uint32_vbr">uint32_vbr</a> terminating value.
308This implies that none of the "x" items can have a zero value (or else
309the list terminates).</td>
310 </tr>
311 <tr>
312 <td><a name="block"><b>block</b></a></td>
313 <td class="td_left">A block of data that is logically related. A
314block is an unsigned 32-bit integer that encodes the type of the block
315in the low 5 bits and the size of the block in the high 27 bits. The
316length does not include the block header or any alignment bytes at the
317end of the block. Blocks may compose other blocks. </td>
318 </tr>
319 </tbody>
Reid Spencerb39021b2004-05-23 17:05:09 +0000320</table>
321</div>
322<!-- _______________________________________________________________________ -->
Reid Spencer82c46712004-07-07 13:34:26 +0000323<div class="doc_subsection"><a name="notation">Field Notation</a> </div>
324<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +0000325<p>In the detailed block and field descriptions that follow, a regex
326like notation is used to describe optional and repeated fields. A very
327limited subset of regex is used to describe these, as given in the
328following table: </p>
329<table class="doc_table">
330 <tbody>
Reid Spencer82c46712004-07-07 13:34:26 +0000331 <tr>
332 <th><b>Character</b></th>
333 <th class="td_left"><b>Meaning</b></th>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000334 </tr>
335 <tr>
Reid Spencer82c46712004-07-07 13:34:26 +0000336 <td><b><code>?</code></b></td>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000337 <td class="td_left">The question mark indicates 0 or 1
338occurrences of the thing preceding it.</td>
339 </tr>
340 <tr>
Reid Spencer82c46712004-07-07 13:34:26 +0000341 <td><b><code>*</code></b></td>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000342 <td class="td_left">The asterisk indicates 0 or more occurrences
343of the thing preceding it.</td>
344 </tr>
345 <tr>
Reid Spencer82c46712004-07-07 13:34:26 +0000346 <td><b><code>+</code></b></td>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000347 <td class="td_left">The plus sign indicates 1 or more occurrences
348of the thing preceding it.</td>
349 </tr>
350 <tr>
Reid Spencer82c46712004-07-07 13:34:26 +0000351 <td><b><code>()</code></b></td>
352 <td class="td_left">Parentheses are used for grouping.</td>
Reid Spencer82c46712004-07-07 13:34:26 +0000353 </tr>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000354 <tr>
355 <td><b><code>,</code></b></td>
356 <td class="td_left">The comma separates sequential fields.</td>
357 </tr>
358 </tbody>
359</table>
360<p>So, for example, consider the following specifications:</p>
361<div class="doc_code">
362<ol>
363 <li><code>string?</code></li>
364 <li><code>(uint32_vbr,uin32_vbr)+</code></li>
365 <li><code>(unsigned?,uint32_vbr)*</code></li>
366 <li><code>(llist(unsigned))?</code></li>
367</ol>
Reid Spencer82c46712004-07-07 13:34:26 +0000368</div>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000369<p>with the following interpretations:</p>
370<ol>
371 <li>An optional string. Matches either nothing or a single string</li>
372 <li>One or more pairs of uint32_vbr.</li>
373 <li>Zero or more occurrences of either an unsigned followed by a
374uint32_vbr or just a uint32_vbr.</li>
375 <li>An optional length list of unsigned values.</li>
376</ol>
377</div>
Reid Spencer82c46712004-07-07 13:34:26 +0000378<!-- _______________________________________________________________________ -->
Reid Spencer1ab929c2004-07-05 08:18:07 +0000379<div class="doc_subsection"><a name="slots">Slots</a> </div>
Reid Spencer50026612004-05-22 02:28:36 +0000380<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +0000381<p>The bytecode format uses the notion of a "slot" to reference Types
382and Values. Since the bytecode file is a <em>direct</em> representation of
383LLVM's intermediate representation, there is a need to represent pointers in
384the file. Slots are used for this purpose. For example, if one has the following
385assembly:
Reid Spencer1ab929c2004-07-05 08:18:07 +0000386</p>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000387<div class="doc_code"><code> %MyType = type { int, sbyte }<br>
388%MyVar = external global %MyType
Reid Spencer82c46712004-07-07 13:34:26 +0000389</code></div>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000390<p>there are two definitions. The definition of <tt>%MyVar</tt> uses <tt>%MyType</tt>.
391In the C++ IR this linkage between <tt>%MyVar</tt> and <tt>%MyType</tt>
392is explicit through the use of C++ pointers. In bytecode, however, there's no
393ability to store memory addresses. Instead, we compute and write out
394slot numbers for every Type and Value written to the file.</p>
Reid Spencer1ab929c2004-07-05 08:18:07 +0000395<p>A slot number is simply an unsigned 32-bit integer encoded in the variable
396bit rate scheme (see <a href="#encoding">encoding</a>). This ensures that
397low slot numbers are encoded in one byte. Through various bits of magic LLVM
398attempts to always keep the slot numbers low. The first attempt is to associate
Reid Spencer9bd2be22004-07-29 00:13:04 +0000399slot numbers with their "type plane". That is, Values of the same type
400are written to the bytecode file in a list (sequentially). Their order in
401that list determines their slot number. This means that slot #1 doesn't mean
402anything unless you also specify for which type you want slot #1. Types are
Reid Spencer09daa632004-08-18 20:06:19 +0000403always written to the file first (in the <a href="#globaltypes">Global Type
404Pool</a>) and in such a way that both forward and backward references of the
405types can often be resolved with a single pass through the type pool. </p>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000406<p>Slot numbers are also kept small by rearranging their order. Because
407of the structure of LLVM, certain values are much more likely to be used
408frequently in the body of a function. For this reason, a compaction table is
409provided in the body of a function if its use would make the function body
410smaller. Suppose you have a function body that uses just the types "int*" and
411"{double}" but uses them thousands of time. Its worthwhile to ensure that the
412slot number for these types are low so they can be encoded in a single byte
413(via vbr). This is exactly what the compaction table does.</p>
Reid Spencer09daa632004-08-18 20:06:19 +0000414<p>In summary then, a slot number can be though of as just a vbr encoded index
415into a list of Type* or Value*. To keep slot numbers low, Value* are indexed by
416two slot numbers: the "type plane index" (type slot) and the "value index"
417(value slot).</p>
Reid Spencer1ab929c2004-07-05 08:18:07 +0000418</div>
Reid Spencer1ab929c2004-07-05 08:18:07 +0000419<!-- *********************************************************************** -->
Reid Spencer51f31e02004-07-05 22:28:02 +0000420<div class="doc_section"> <a name="general">General Structure</a> </div>
Reid Spencer1ab929c2004-07-05 08:18:07 +0000421<!-- *********************************************************************** -->
422<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +0000423<p>This section provides the general structure of the LLVM bytecode
424file format. The bytecode file format requires blocks to be in a
425certain order and nested in a particular way so that an LLVM module can
426be constructed efficiently from the contents of the file. This ordering
427defines a general structure for bytecode files as shown below. The
428table below shows the order in which all block types may appear. Please
429note that some of the blocks are optional and some may be repeated. The
430structure is fairly loose because optional blocks, if empty, are
431completely omitted from the file.</p>
Reid Spencer1ab929c2004-07-05 08:18:07 +0000432<table>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000433 <tbody>
434 <tr>
435 <th>ID</th>
436 <th>Parent</th>
437 <th>Optional?</th>
438 <th>Repeated?</th>
439 <th>Level</th>
440 <th>Block Type</th>
441 <th>Description</th>
442 </tr>
443 <tr>
444 <td>N/A</td>
445 <td>File</td>
446 <td>No</td>
447 <td>No</td>
448 <td>0</td>
449 <td class="td_left"><a href="#signature">Signature</a></td>
450 <td class="td_left">This contains the file signature (magic
451number) that identifies the file as LLVM bytecode.</td>
452 </tr>
453 <tr>
454 <td>0x01</td>
455 <td>File</td>
456 <td>No</td>
457 <td>No</td>
458 <td>0</td>
459 <td class="td_left"><a href="#module">Module</a></td>
460 <td class="td_left">This is the top level block in a bytecode
461file. It contains all the other blocks. </td>
462 </tr>
463 <tr>
464 <td>0x06</td>
465 <td>Module</td>
466 <td>No</td>
467 <td>No</td>
468 <td>1</td>
469 <td class="td_left">&nbsp;&nbsp;&nbsp;<a href="#globaltypes">Global&nbsp;Type&nbsp;Pool</a></td>
470 <td class="td_left">This block contains all the global (module)
471level types.</td>
472 </tr>
473 <tr>
474 <td>0x05</td>
475 <td>Module</td>
476 <td>No</td>
477 <td>No</td>
478 <td>1</td>
479 <td class="td_left">&nbsp;&nbsp;&nbsp;<a href="#globalinfo">Module&nbsp;Globals&nbsp;Info</a></td>
480 <td class="td_left">This block contains the type, constness, and
481linkage for each of the global variables in the module. It also
482contains the type of the functions and the constant initializers.</td>
483 </tr>
484 <tr>
485 <td>0x03</td>
486 <td>Module</td>
487 <td>Yes</td>
488 <td>No</td>
489 <td>1</td>
490 <td class="td_left">&nbsp;&nbsp;&nbsp;<a href="#constantpool">Module&nbsp;Constant&nbsp;Pool</a></td>
491 <td class="td_left">This block contains all the global constants
492except function arguments, global values and constant strings.</td>
493 </tr>
494 <tr>
495 <td>0x02</td>
496 <td>Module</td>
497 <td>Yes</td>
498 <td>Yes</td>
499 <td>1</td>
500 <td class="td_left">&nbsp;&nbsp;&nbsp;<a href="#functiondefs">Function&nbsp;Definitions</a>*</td>
501 <td class="td_left">One function block is written for each
502function in the module. The function block contains the instructions,
503compaction table, type constant pool, and symbol table for the function.</td>
504 </tr>
505 <tr>
506 <td>0x03</td>
507 <td>Function</td>
508 <td>Yes</td>
509 <td>No</td>
510 <td>2</td>
511 <td class="td_left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a
512 href="#constantpool">Function&nbsp;Constant&nbsp;Pool</a></td>
513 <td class="td_left">Any constants (including types) used solely
514within the function are emitted here in the function constant pool. </td>
515 </tr>
516 <tr>
517 <td>0x08</td>
518 <td>Function</td>
519 <td>Yes</td>
520 <td>No</td>
521 <td>2</td>
522 <td class="td_left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a
523 href="#compactiontable">Compaction&nbsp;Table</a></td>
524 <td class="td_left">This table reduces bytecode size by providing
525a funtion-local mapping of type and value slot numbers to their global
526slot numbers</td>
527 </tr>
528 <tr>
529 <td>0x07</td>
530 <td>Function</td>
531 <td>No</td>
532 <td>No</td>
533 <td>2</td>
534 <td class="td_left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a
535 href="#instructionlist">Instruction&nbsp;List</a></td>
536 <td class="td_left">This block contains all the instructions of
537the function. The basic blocks are inferred by terminating
538instructions. </td>
539 </tr>
540 <tr>
541 <td>0x04</td>
542 <td>Function</td>
543 <td>Yes</td>
544 <td>No</td>
545 <td>2</td>
546 <td class="td_left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a
547 href="#symtab">Function&nbsp;Symbol&nbsp;Table</a></td>
548 <td class="td_left">This symbol table provides the names for the
549function specific values used (basic block labels mostly).</td>
550 </tr>
551 <tr>
552 <td>0x04</td>
553 <td>Module</td>
554 <td>Yes</td>
555 <td>No</td>
556 <td>1</td>
557 <td class="td_left">&nbsp;&nbsp;&nbsp;<a href="#symtab">Module&nbsp;Symbol&nbsp;Table</a></td>
558 <td class="td_left">This symbol table provides the names for the
559various entries in the file that are not function specific (global
560vars, and functions mostly).</td>
561 </tr>
562 </tbody>
Reid Spencer1ab929c2004-07-05 08:18:07 +0000563</table>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000564<p>Use the links in the table for details about the contents of each of
565the block types.</p>
Reid Spencer1ab929c2004-07-05 08:18:07 +0000566</div>
Reid Spencer50026612004-05-22 02:28:36 +0000567<!-- *********************************************************************** -->
Reid Spencer51f31e02004-07-05 22:28:02 +0000568<div class="doc_section"> <a name="blockdefs">Block Definitions</a> </div>
Reid Spencer50026612004-05-22 02:28:36 +0000569<!-- *********************************************************************** -->
570<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +0000571<p>This section provides the detailed layout of the individual block
572types in the LLVM bytecode file format. </p>
Reid Spencer50026612004-05-22 02:28:36 +0000573</div>
Reid Spencer50026612004-05-22 02:28:36 +0000574<!-- _______________________________________________________________________ -->
Reid Spencerb39021b2004-05-23 17:05:09 +0000575<div class="doc_subsection"><a name="signature">Signature Block</a> </div>
Reid Spencer50026612004-05-22 02:28:36 +0000576<div class="doc_text">
Chris Lattner2b905652004-05-24 05:35:17 +0000577<p>The signature occurs in every LLVM bytecode file and is always first.
Reid Spencerb39021b2004-05-23 17:05:09 +0000578It simply provides a few bytes of data to identify the file as being an LLVM
579bytecode file. This block is always four bytes in length and differs from the
580other blocks because there is no identifier and no block length at the start
581of the block. Essentially, this block is just the "magic number" for the file.
Reid Spencer9bd2be22004-07-29 00:13:04 +0000582</p>
Reid Spencerda794e72004-11-08 08:55:21 +0000583<p>There are two types of signatures for LLVM bytecode: uncompressed and
584compressed as shown in the table below. </p>
Reid Spencer2cc36152004-07-05 19:04:27 +0000585<table>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000586 <tbody>
587 <tr>
588 <th><b>Type</b></th>
Reid Spencerda794e72004-11-08 08:55:21 +0000589 <th class="td_left"><b>Uncompressed</b></th>
590 <th class="td_left"><b>Compressed</b></th>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000591 </tr>
592 <tr>
593 <td><a href="#char">char</a></td>
594 <td class="td_left">Constant "l" (0x6C)</td>
Reid Spencerda794e72004-11-08 08:55:21 +0000595 <td class="td_left">Constant "l" (0x6C)</td>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000596 </tr>
597 <tr>
598 <td><a href="#char">char</a></td>
599 <td class="td_left">Constant "l" (0x6C)</td>
Reid Spencerda794e72004-11-08 08:55:21 +0000600 <td class="td_left">Constant "l" (0x6C)</td>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000601 </tr>
602 <tr>
603 <td><a href="#char">char</a></td>
604 <td class="td_left">Constant "v" (0x76)</td>
Reid Spencerda794e72004-11-08 08:55:21 +0000605 <td class="td_left">Constant "v" (0x76)</td>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000606 </tr>
607 <tr>
608 <td><a href="#char">char</a></td>
609 <td class="td_left">Constant "m" (0x6D)</td>
Reid Spencerda794e72004-11-08 08:55:21 +0000610 <td class="td_left">Constant "c" (0x63)</td>
611 </tr>
612 <tr>
613 <td><a href="#char">char</a></td>
614 <td class="td_left">N/A</td>
615 <td class="td_left">'0'=null,'1'=gzip,'2'=bzip2</td>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000616 </tr>
617 </tbody>
Reid Spencerb39021b2004-05-23 17:05:09 +0000618</table>
Reid Spencerda794e72004-11-08 08:55:21 +0000619<p>In other words, the uncompressed signature is just the characters 'llvm'
620while the compressed signature is the characters 'llvc' followed by an ascii
621digit ('0', '1', or '2') that indicates the kind of compression used. A value of
622'0' indicates that null compression was used. This can happen when compression
623was requested on a platform that wasn't configured for gzip or bzip2. A value of
624'1' means that the rest of the file is compressed using the gzip algorithm and
625should be uncompressed before interpretation. A value of '2' means that the rest
626of the file is compressed using the bzip2 algorithm and should be uncompressed
627before interpretation. In all cases, the data resulting from uncompression
628should be interpreted as if it occurred immediately after the 'llvm'
629signature (i.e. the uncompressed data begins with the
630<a href="#module">Module Block</a></p>
631<p><b>NOTE:</b> As of LLVM 1.4, all bytecode files produced by the LLVM tools
Reid Spencera4213b22004-11-08 09:10:50 +0000632are compressed by default. To disable compression, pass the
Reid Spencerda794e72004-11-08 08:55:21 +0000633<tt>--disable-compression</tt> option to the tool, if it supports it.
Reid Spencerb39021b2004-05-23 17:05:09 +0000634</div>
635<!-- _______________________________________________________________________ -->
636<div class="doc_subsection"><a name="module">Module Block</a> </div>
637<div class="doc_text">
638<p>The module block contains a small pre-amble and all the other blocks in
Reid Spencer1ab929c2004-07-05 08:18:07 +0000639the file. The table below shows the structure of the module block. Note that it
640only provides the module identifier, size of the module block, and the format
641information. Everything else is contained in other blocks, described in other
642sections.</p>
Reid Spencer2cc36152004-07-05 19:04:27 +0000643<table>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000644 <tbody>
645 <tr>
646 <th><b>Type</b></th>
647 <th class="td_left"><b>Field Description</b></th>
648 </tr>
649 <tr>
Reid Spencer5bc74d52004-08-16 19:24:36 +0000650 <td><a href="#unsigned">unsigned</a><br></td>
651 <td class="td_left"><a href="#mod_header">Module Block Identifier
652 (0x01)</a></td>
653 </tr>
654 <tr>
655 <td><a href="#unsigned">unsigned</a></td>
656 <td class="td_left"><a href="#mod_header">Module Block Size</a></td>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000657 </tr>
658 <tr>
659 <td><a href="#uint32_vbr">uint32_vbr</a></td>
660 <td class="td_left"><a href="#format">Format Information</a></td>
661 </tr>
662 <tr>
663 <td><a href="#block">block</a></td>
664 <td class="td_left"><a href="#globaltypes">Global Type Pool</a></td>
665 </tr>
666 <tr>
667 <td><a href="#block">block</a></td>
668 <td class="td_left"><a href="#globalinfo">Module Globals Info</a></td>
669 </tr>
670 <tr>
671 <td><a href="#block">block</a></td>
672 <td class="td_left"><a href="#constantpool">Module Constant Pool</a></td>
673 </tr>
674 <tr>
675 <td><a href="#block">block</a>*</td>
676 <td class="td_left"><a href="#functiondefs">Function Definitions</a></td>
677 </tr>
678 <tr>
679 <td><a href="#block">block</a></td>
Reid Spencer8996e552004-08-17 00:49:03 +0000680 <td class="td_left"><a href="#symtab">Module Symbol Table</a></td>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000681 </tr>
682 </tbody>
Reid Spencer1ab929c2004-07-05 08:18:07 +0000683</table>
684</div>
Reid Spencer5bc74d52004-08-16 19:24:36 +0000685
686<!-- _______________________________________________________________________ -->
687<div class="doc_subsubsection"><a name="mod_header">Module Block Header</a></div>
688<div class="doc_text">
689 <p>The block header for the module block uses a longer format than the other
690 blocks in a bytecode file. Specifically, instead of encoding the type and size
691 of the block into a 32-bit integer with 5-bits for type and 27-bits for size,
692 the module block header uses two 32-bit unsigned values, one for type, and one
693 for size. While the 2<sup>27</sup> byte limit on block size is sufficient for the blocks
694 contained in the module, it isn't sufficient for the module block itself
695 because we want to ensure that bytecode files as large as 2<sup>32</sup> bytes
696 are possible. For this reason, the module block (and only the module block)
697 uses a long format header.</p>
698</div>
699
Reid Spencer1ab929c2004-07-05 08:18:07 +0000700<!-- _______________________________________________________________________ -->
701<div class="doc_subsubsection"><a name="format">Format Information</a></div>
702<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +0000703<p>The format information field is encoded into a <a href="#uint32_vbr">uint32_vbr</a>
704as shown in the following table.</p>
Reid Spencer1ab929c2004-07-05 08:18:07 +0000705<table>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000706 <tbody>
707 <tr>
708 <th><b>Type</b></th>
709 <th class="td_left"><b>Description</b></th>
710 </tr>
711 <tr>
712 <td><a href="#bit">bit(0)</a></td>
713 <td class="td_left">Target is big endian?</td>
714 </tr>
715 <tr>
716 <td><a href="#bit">bit(1)</a></td>
717 <td class="td_left">On target pointers are 64-bit?</td>
718 </tr>
719 <tr>
720 <td><a href="#bit">bit(2)</a></td>
721 <td class="td_left">Target has no endianess?</td>
722 </tr>
723 <tr>
724 <td><a href="#bit">bit(3)</a></td>
725 <td class="td_left">Target has no pointer size?</td>
726 </tr>
727 <tr>
728 <td><a href="#bit">bit(4-31)</a></td>
729 <td class="td_left">Bytecode format version</td>
730 </tr>
731 </tbody>
Reid Spencer1ab929c2004-07-05 08:18:07 +0000732</table>
733<p>
734Of particular note, the bytecode format number is simply a 28-bit
John Criswell611a8d12005-10-24 16:20:10 +0000735monotonically increasing integer that identifies the version of the bytecode
Reid Spencer9bd2be22004-07-29 00:13:04 +0000736format (which is not directly related to the LLVM release number). The
737bytecode versions defined so far are (note that this document only
738describes the latest version, 1.3):</p>
Chris Lattner2b905652004-05-24 05:35:17 +0000739<ul>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000740 <li>#0: LLVM 1.0 &amp; 1.1</li>
741 <li>#1: LLVM 1.2</li>
742 <li>#2: LLVM 1.2.5 (not released)</li>
John Criswell1d9be9e2005-10-24 17:10:57 +0000743 <li>#3: LLVM 1.3</li>
744 <li>#4: LLVM 1.3.x (not released)</li>
Tanya Lattnerfcccd6b2006-04-20 05:05:12 +0000745 <li>#5: LLVM 1.4 and newer</li>
Chris Lattner2b905652004-05-24 05:35:17 +0000746</ul>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000747<p>Note that we plan to eventually expand the target description
748capabilities
Reid Spencer05fe4b02006-03-14 05:39:39 +0000749of bytecode files to <a href="http://llvm.org/PR263">target
Reid Spencer9bd2be22004-07-29 00:13:04 +0000750triples</a>.
Reid Spencer1ab929c2004-07-05 08:18:07 +0000751</p>
Reid Spencer50026612004-05-22 02:28:36 +0000752</div>
753<!-- _______________________________________________________________________ -->
Reid Spencer1ab929c2004-07-05 08:18:07 +0000754<div class="doc_subsection"><a name="globaltypes">Global Type Pool</a> </div>
Reid Spencer50026612004-05-22 02:28:36 +0000755<div class="doc_text">
Chris Lattner2b905652004-05-24 05:35:17 +0000756<p>The global type pool consists of type definitions. Their order of appearance
Reid Spencer09daa632004-08-18 20:06:19 +0000757in the file determines their type slot number (0 based). Slot numbers are
Reid Spencer9bd2be22004-07-29 00:13:04 +0000758used to replace pointers in the intermediate representation. Each slot number
759uniquely identifies one entry in a type plane (a collection of values of the
760same type). Since all values have types and are associated with the order in
761which the type pool is written, the global type pool <em>must</em> be written
762as the first block of a module. If it is not, attempts to read the file will
763fail because both forward and backward type resolution will not be possible.</p>
764<p>The type pool is simply a list of type definitions, as shown in the
765table below.</p>
Reid Spencer2cc36152004-07-05 19:04:27 +0000766<table>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000767 <tbody>
768 <tr>
769 <th><b>Type</b></th>
770 <th class="td_left"><b>Field Description</b></th>
771 </tr>
772 <tr>
773 <td><a href="#unsigned">block</a></td>
774 <td class="td_left">Type Pool Identifier (0x06) + Size<br>
775 </td>
776 </tr>
777 <tr>
778 <td><a href="#llist">llist</a>(<a href="#type">type</a>)</td>
779 <td class="td_left">A length list of type definitions.</td>
780 </tr>
781 </tbody>
Reid Spencerb39021b2004-05-23 17:05:09 +0000782</table>
Reid Spencer50026612004-05-22 02:28:36 +0000783</div>
784<!-- _______________________________________________________________________ -->
Reid Spencer1ab929c2004-07-05 08:18:07 +0000785<div class="doc_subsubsection"><a name="type">Type Definitions</a></div>
786<div class="doc_text">
Reid Spencer82c46712004-07-07 13:34:26 +0000787<p>Types in the type pool are defined using a different format for each kind
788of type, as given in the following sections.</p>
Reid Spencer1ab929c2004-07-05 08:18:07 +0000789<h3>Primitive Types</h3>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000790<p>The primitive types encompass the basic integer and floating point
Reid Spencer09daa632004-08-18 20:06:19 +0000791types. They are encoded simply as their TypeID.</p>
Reid Spencer1ab929c2004-07-05 08:18:07 +0000792<table>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000793 <tbody>
794 <tr>
795 <th><b>Type</b></th>
796 <th class="td_left"><b>Description</b></th>
797 </tr>
798 <tr>
799 <td><a href="#uint24_vbr">uint24_vbr</a></td>
800 <td class="td_left">Type ID for the primitive types (values 1 to
80111) <sup>1</sup></td>
802 </tr>
803 </tbody>
Reid Spencer1ab929c2004-07-05 08:18:07 +0000804</table>
Reid Spencer2cc36152004-07-05 19:04:27 +0000805Notes:
806<ol>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000807 <li>The values for the Type IDs for the primitive types are provided
808by the definition of the <code>llvm::Type::TypeID</code> enumeration
809in <code>include/llvm/Type.h</code>. The enumeration gives the
810following mapping:
811 <ol>
812 <li>bool</li>
813 <li>ubyte</li>
814 <li>sbyte</li>
815 <li>ushort</li>
816 <li>short</li>
817 <li>uint</li>
818 <li>int</li>
819 <li>ulong</li>
820 <li>long</li>
821 <li>float</li>
822 <li>double</li>
823 </ol>
824 </li>
Reid Spencer2cc36152004-07-05 19:04:27 +0000825</ol>
Reid Spencer1ab929c2004-07-05 08:18:07 +0000826<h3>Function Types</h3>
827<table>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000828 <tbody>
829 <tr>
830 <th><b>Type</b></th>
831 <th class="td_left"><b>Description</b></th>
832 </tr>
833 <tr>
834 <td><a href="#uint24_vbr">uint24_vbr</a></td>
835 <td class="td_left">Type ID for function types (13)</td>
836 </tr>
837 <tr>
838 <td><a href="#uint24_vbr">uint24_vbr</a></td>
Reid Spencer09daa632004-08-18 20:06:19 +0000839 <td class="td_left">Type slot number of function's return type.</td>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000840 </tr>
841 <tr>
842 <td><a href="#llist">llist</a>(<a href="#uint24_vbr">uint24_vbr</a>)</td>
Reid Spencer09daa632004-08-18 20:06:19 +0000843 <td class="td_left">Type slot number of each argument's type.</td>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000844 </tr>
845 <tr>
846 <td><a href="#uint32_vbr">uint32_vbr</a>?</td>
847 <td class="td_left">Value 0 if this is a varargs function,
848missing otherwise.</td>
849 </tr>
850 </tbody>
Reid Spencer1ab929c2004-07-05 08:18:07 +0000851</table>
852<h3>Structure Types</h3>
853<table>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000854 <tbody>
855 <tr>
856 <th><b>Type</b></th>
857 <th class="td_left"><b>Description</b></th>
858 </tr>
859 <tr>
860 <td><a href="#uint24_vbr">uint24_vbr</a></td>
861 <td class="td_left">Type ID for structure types (14)</td>
862 </tr>
863 <tr>
864 <td><a href="#zlist">zlist</a>(<a href="#uint24_vbr">uint24_vbr</a>)</td>
865 <td class="td_left">Slot number of each of the element's fields.</td>
866 </tr>
867 </tbody>
Reid Spencer1ab929c2004-07-05 08:18:07 +0000868</table>
869<h3>Array Types</h3>
870<table>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000871 <tbody>
872 <tr>
873 <th><b>Type</b></th>
874 <th class="td_left"><b>Description</b></th>
875 </tr>
876 <tr>
877 <td><a href="#uint24_vbr">uint24_vbr</a></td>
878 <td class="td_left">Type ID for Array Types (15)</td>
879 </tr>
880 <tr>
881 <td><a href="#uint24_vbr">uint24_vbr</a></td>
Reid Spencer09daa632004-08-18 20:06:19 +0000882 <td class="td_left">Type slot number of array's element type.</td>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000883 </tr>
884 <tr>
885 <td><a href="#uint32_vbr">uint32_vbr</a></td>
886 <td class="td_left">The number of elements in the array.</td>
887 </tr>
888 </tbody>
Reid Spencer1ab929c2004-07-05 08:18:07 +0000889</table>
890<h3>Pointer Types</h3>
891<table>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000892 <tbody>
893 <tr>
894 <th><b>Type</b></th>
895 <th class="td_left"><b>Description</b></th>
896 </tr>
897 <tr>
898 <td><a href="#uint24_vbr">uint24_vbr</a></td>
899 <td class="td_left">Type ID For Pointer Types (16)</td>
900 </tr>
901 <tr>
902 <td><a href="#uint24_vbr">uint24_vbr</a></td>
Reid Spencer09daa632004-08-18 20:06:19 +0000903 <td class="td_left">Type slot number of pointer's element type.</td>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000904 </tr>
905 </tbody>
Reid Spencer1ab929c2004-07-05 08:18:07 +0000906</table>
907<h3>Opaque Types</h3>
908<table>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000909 <tbody>
910 <tr>
911 <th><b>Type</b></th>
912 <th class="td_left"><b>Description</b></th>
913 </tr>
914 <tr>
915 <td><a href="#uint24_vbr">uint24_vbr</a></td>
916 <td class="td_left">Type ID For Opaque Types (17)</td>
917 </tr>
918 </tbody>
Reid Spencer1ab929c2004-07-05 08:18:07 +0000919</table>
Brian Gaeke715c90b2004-08-20 06:00:58 +0000920<h3>Packed Types</h3>
921<table>
922 <tbody>
923 <tr>
924 <th><b>Type</b></th>
925 <th class="td_left"><b>Description</b></th>
926 </tr>
927 <tr>
928 <td><a href="#uint24_vbr">uint24_vbr</a></td>
929 <td class="td_left">Type ID for Packed Types (18)</td>
930 </tr>
931 <tr>
932 <td><a href="#uint24_vbr">uint24_vbr</a></td>
933 <td class="td_left">Slot number of packed vector's element type.</td>
934 </tr>
935 <tr>
936 <td><a href="#uint32_vbr">uint32_vbr</a></td>
937 <td class="td_left">The number of elements in the packed vector.</td>
938 </tr>
939 </tbody>
940</table>
Andrew Lenharth88942552006-12-08 17:50:05 +0000941<h3>Packed Structure Types</h3>
942<table>
943 <tbody>
944 <tr>
945 <th><b>Type</b></th>
946 <th class="td_left"><b>Description</b></th>
947 </tr>
948 <tr>
949 <td><a href="#uint24_vbr">uint24_vbr</a></td>
950 <td class="td_left">Type ID for packed structure types (19)</td>
951 </tr>
952 <tr>
953 <td><a href="#zlist">zlist</a>(<a href="#uint24_vbr">uint24_vbr</a>)</td>
954 <td class="td_left">Slot number of each of the element's fields.</td>
955 </tr>
956 </tbody>
957</table>
Reid Spencer1ab929c2004-07-05 08:18:07 +0000958</div>
959<!-- _______________________________________________________________________ -->
Reid Spencer9bd2be22004-07-29 00:13:04 +0000960<div class="doc_subsection"><a name="globalinfo">Module Global Info</a>
961</div>
Reid Spencer50026612004-05-22 02:28:36 +0000962<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +0000963<p>The module global info block contains the definitions of all global
964variables including their initializers and the <em>declaration</em> of
965all functions. The format is shown in the table below:</p>
966<table>
967 <tbody>
Reid Spencer2cc36152004-07-05 19:04:27 +0000968 <tr>
969 <th><b>Type</b></th>
970 <th class="td_left"><b>Field Description</b></th>
Reid Spencer2cc36152004-07-05 19:04:27 +0000971 </tr>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000972 <tr>
973 <td><a href="#block">block</a></td>
Chris Lattner45f50512006-01-23 23:38:09 +0000974 <td class="td_left">Module global info identifier (0x05) + size</td>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000975 </tr>
976 <tr>
977 <td><a href="#zlist">zlist</a>(<a href="#globalvar">globalvar</a>)</td>
978 <td class="td_left">A zero terminated list of global var
Reid Spencer09daa632004-08-18 20:06:19 +0000979definitions occurring in the module.</td>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000980 </tr>
981 <tr>
Chris Lattnera1dad812004-10-16 18:03:55 +0000982 <td><a href="#zlist">zlist</a>(<a href="#funcfield">funcfield</a>)</td>
983 <td class="td_left">A zero terminated list of function definitions
Reid Spencer09daa632004-08-18 20:06:19 +0000984occurring in the module.</td>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000985 </tr>
986 <tr>
Chris Lattner45f50512006-01-23 23:38:09 +0000987 <td><a href="#llist">llist</a>(<a href="#string">string</a>)</td>
Chris Lattner767d6ba2005-11-12 01:46:21 +0000988 <td class="td_left">A length list
Reid Spencer9bd2be22004-07-29 00:13:04 +0000989of strings that specify the names of the libraries that this module
Chris Lattner45f50512006-01-23 23:38:09 +0000990depends upon.</td>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000991 </tr>
992 <tr>
Chris Lattner45f50512006-01-23 23:38:09 +0000993 <td><a href="#string">string</a></td>
Chris Lattner767d6ba2005-11-12 01:46:21 +0000994 <td class="td_left">The target
Reid Spencer9bd2be22004-07-29 00:13:04 +0000995triple for the module (blank means no target triple specified, i.e. a
Chris Lattner45f50512006-01-23 23:38:09 +0000996platform independent module).</td>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000997 </tr>
Chris Lattner767d6ba2005-11-12 01:46:21 +0000998 <tr>
Chris Lattner45f50512006-01-23 23:38:09 +0000999 <td><a href="#llist">llist</a>(<a href="#string">string</a>)</td>
Chris Lattner767d6ba2005-11-12 01:46:21 +00001000 <td class="td_left">A length list
1001of strings that defines a table of section strings for globals. A global's
Chris Lattner45f50512006-01-23 23:38:09 +00001002SectionID is an index into this table.</td>
1003 </tr>
1004 <tr>
1005 <td><a href="#string">string</a></td>
1006 <td class="td_left">The inline asm block for this module.</td>
Chris Lattner767d6ba2005-11-12 01:46:21 +00001007 </tr>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001008 </tbody>
1009</table>
Reid Spencer50026612004-05-22 02:28:36 +00001010</div>
Chris Lattnera1dad812004-10-16 18:03:55 +00001011
Reid Spencer2cc36152004-07-05 19:04:27 +00001012<!-- _______________________________________________________________________ -->
1013<div class="doc_subsubsection"><a name="globalvar">Global Variable Field</a>
1014</div>
Chris Lattnerafedcb32005-11-06 07:20:25 +00001015
Reid Spencer2cc36152004-07-05 19:04:27 +00001016<div class="doc_text">
Chris Lattnerafedcb32005-11-06 07:20:25 +00001017
Reid Spencer9bd2be22004-07-29 00:13:04 +00001018<p>Global variables are written using an <a href="#uint32_vbr">uint32_vbr</a>
Chris Lattnerafedcb32005-11-06 07:20:25 +00001019that encodes information about the global variable, an optional extension vbr,
1020and a an optional initializers for the global var.</p>
1021
Reid Spencer9bd2be22004-07-29 00:13:04 +00001022<p>The table below provides the bit layout of the first <a
1023 href="#uint32_vbr">uint32_vbr</a> that describes the global variable.</p>
Chris Lattnerafedcb32005-11-06 07:20:25 +00001024
Reid Spencer9bd2be22004-07-29 00:13:04 +00001025<table>
1026 <tbody>
Reid Spencer82c46712004-07-07 13:34:26 +00001027 <tr>
1028 <th><b>Type</b></th>
1029 <th class="td_left"><b>Description</b></th>
Reid Spencer82c46712004-07-07 13:34:26 +00001030 </tr>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001031 <tr>
1032 <td><a href="#bit">bit(0)</a></td>
1033 <td class="td_left">Is constant?</td>
1034 </tr>
1035 <tr>
1036 <td><a href="#bit">bit(1)</a></td>
1037 <td class="td_left">Has initializer? Note that this bit
1038determines whether the constant initializer field (described below)
1039follows. </td>
1040 </tr>
1041 <tr>
1042 <td><a href="#bit">bit(2-4)</a></td>
1043 <td class="td_left">Linkage type: 0=External, 1=Weak,
Anton Korobeynikovb74ed072006-09-14 18:23:27 +00001044 2=Appending, 3=Internal, 4=LinkOnce, 5=DllImport,
1045 6=DllExport, 7=ExternWeak</td>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001046 </tr>
1047 <tr>
1048 <td><a href="#bit">bit(5-31)</a></td>
Reid Spencer09daa632004-08-18 20:06:19 +00001049 <td class="td_left">Type slot number of type for the global variable.</td>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001050 </tr>
1051 </tbody>
1052</table>
Chris Lattnerafedcb32005-11-06 07:20:25 +00001053
1054<p>When the Linkage type is set to 3 (internal) and the initializer field is set
1055to 0 (an invalid combination), an extension word follows the first <a
1056href="#uint32_vbr">uint32_vbr</a> which encodes the real linkage and init flag,
1057and can includes more information:</p>
1058
1059<table>
1060 <tbody>
1061 <tr>
1062 <th><b>Type</b></th>
1063 <th class="td_left"><b>Description</b></th>
1064 </tr>
1065 <tr>
1066 <td><a href="#bit">bit(0)</a></td>
1067 <td class="td_left">Has initializer? Indicates the real value of the "Has
1068 initializer" field for the global. </td>
1069 </tr>
1070 <tr>
1071 <td><a href="#bit">bit(2-4)</a></td>
1072 <td class="td_left">Linkage type: Indicates the real value of the "linkage
1073 type" field for the global.</td>
1074 </tr>
1075 <tr>
1076 <td><a href="#bit">bit(4-8)</a></td>
1077 <td class="td_left">The log-base-2 of the alignment for the global.</td>
1078 </tr>
1079 <tr>
Chris Lattner767d6ba2005-11-12 01:46:21 +00001080 <td><a href="#bit">bit(9)</a></td>
1081 <td class="td_left">If this bit is set, a SectionID follows this vbr.</td>
1082 </tr>
1083 <tr>
Anton Korobeynikov7f705592007-01-12 19:20:47 +00001084 <td><a href="#bit">bit(10-12)</a></td>
1085 <td class="td_left">Visibility style: 0=Default, 1=Hidden.</td>
1086 </tr>
1087 <tr>
1088 <td><a href="#bit">bit(13-31)</a></td>
Chris Lattnerafedcb32005-11-06 07:20:25 +00001089 <td class="td_left">Currently unassigned.</td>
1090 </tr>
1091 </tbody>
1092</table>
1093
Chris Lattner767d6ba2005-11-12 01:46:21 +00001094<p>If the SectionID bit is set above, the following field is included:</p>
Chris Lattnerafedcb32005-11-06 07:20:25 +00001095
Reid Spencer9bd2be22004-07-29 00:13:04 +00001096<table>
1097 <tbody>
1098 <tr>
1099 <th><b>Type</b></th>
1100 <th class="td_left"><b>Description</b></th>
1101 </tr>
1102 <tr>
Chris Lattner767d6ba2005-11-12 01:46:21 +00001103 <td><a href="#uint32_vbr">uint32_vbr</a>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001104 </td>
Chris Lattner767d6ba2005-11-12 01:46:21 +00001105 <td class="td_left">An optional section ID number, specifying the string
1106 to use for the section of the global. This an index (+1) of an entry
1107 into the SectionID llist in the <a href="#globalinfo">Module Global
1108 Info</a> block. If this value is 0 or not present, the global has an
1109 empty section string.</td>
1110 </tr>
1111 </tbody>
1112</table>
1113
1114<p>If the "Has initializer" field is set, the following field is included:</p>
1115
1116<table>
1117 <tbody>
1118 <tr>
1119 <th><b>Type</b></th>
1120 <th class="td_left"><b>Description</b></th>
1121 </tr>
1122 <tr>
1123 <td><a href="#uint32_vbr">uint32_vbr</a>
1124 </td>
1125 <td class="td_left">An optional value slot number for the global
1126 variable's constant initializer.</td>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001127 </tr>
1128 </tbody>
1129</table>
Reid Spencer2cc36152004-07-05 19:04:27 +00001130</div>
Chris Lattnera1dad812004-10-16 18:03:55 +00001131
1132<!-- _______________________________________________________________________ -->
1133<div class="doc_subsubsection"><a name="funcfield">Function Field</a>
1134</div>
1135<div class="doc_text">
1136<p>Functions are written using an <a href="#uint32_vbr">uint32_vbr</a>
Chris Lattnerafedcb32005-11-06 07:20:25 +00001137that encodes information about the function and a set of flags. If needed,
1138an extension word may follow this first field.</p>
Chris Lattnera1dad812004-10-16 18:03:55 +00001139
1140<p>The table below provides the bit layout of the <a
1141href="#uint32_vbr">uint32_vbr</a> that describes the function.</p>
1142
1143<table>
1144 <tbody>
1145 <tr>
1146 <th><b>Type</b></th>
1147 <th class="td_left"><b>Description</b></th>
1148 </tr>
1149 <tr>
Chris Lattnerced62222004-11-15 22:54:50 +00001150 <td><a href="#bit">bit(0-3)</a></td>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001151 <td class="td_left">
Chris Lattner52942b52005-11-06 07:48:11 +00001152 Encodes the calling convention number of the function. The
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001153 CC number of the function is the value of this field minus one.
1154 </td>
Chris Lattnerced62222004-11-15 22:54:50 +00001155 </tr>
1156 <tr>
1157 <td><a href="#bit">bit(4)</a></td>
1158 <td class="td_left">If this bit is set to 1, the indicated function is
1159 external, and there is no <a href="#functiondefs">Function Definiton
Anton Korobeynikovb74ed072006-09-14 18:23:27 +00001160 Block</a> in the bytecode file for the function. If the function is
1161 external and has <tt>dllimport or extern_weak</tt> linkage additional
1162 field in the extension word is used to indicate the actual linkage
1163 type.</td>
Chris Lattnera1dad812004-10-16 18:03:55 +00001164 </tr>
1165 <tr>
Chris Lattnerafedcb32005-11-06 07:20:25 +00001166 <td><a href="#bit">bit(5-30)</a></td>
Chris Lattnera1dad812004-10-16 18:03:55 +00001167 <td class="td_left">Type slot number of type for the function.</td>
1168 </tr>
Anton Korobeynikovb74ed072006-09-14 18:23:27 +00001169 <tr>
Chris Lattnerafedcb32005-11-06 07:20:25 +00001170 <td><a href="#bit">bit(31)</a></td>
1171 <td class="td_left">Indicates whether an extension word follows.</td>
1172 </tr>
1173 </tbody>
1174</table>
1175
1176<p>If bit(31) is set, an additional <a href="#uint32_vbr">uint32_vbr</a> word
1177follows with the following fields:</p>
1178
1179<table>
1180 <tbody>
1181 <tr>
1182 <th><b>Type</b></th>
1183 <th class="td_left"><b>Description</b></th>
1184 </tr>
1185 <tr>
1186 <td><a href="#bit">bit(0-4)</a></td>
1187 <td class="td_left">The log-base-2 of the alignment for the function.</td>
1188 </tr>
1189 <tr>
Chris Lattner52942b52005-11-06 07:48:11 +00001190 <td><a href="#bit">bit(5-9)</a></td>
1191 <td class="td_left">The top nibble of the calling convention.</td>
1192 </tr>
1193 <tr>
Chris Lattner767d6ba2005-11-12 01:46:21 +00001194 <td><a href="#bit">bit(10)</a></td>
1195 <td class="td_left">If this bit is set, a SectionID follows this vbr.</td>
1196 </tr>
1197 <tr>
Anton Korobeynikovb74ed072006-09-14 18:23:27 +00001198 <td><a href="#bit">bit(11-12)</a></td>
1199 <td class="td_left">Linkage type for external functions. 0 - External
1200 linkage, 1 - DLLImport linkage, 2 - External weak linkage.</td>
1201 </tr>
1202 <tr>
1203 <td><a href="#bit">bit(13-31)</a></td>
Chris Lattnerafedcb32005-11-06 07:20:25 +00001204 <td class="td_left">Currently unassigned.</td>
1205 </tr>
Chris Lattnera1dad812004-10-16 18:03:55 +00001206 </tbody>
1207</table>
1208
Chris Lattner767d6ba2005-11-12 01:46:21 +00001209<p>If the SectionID bit is set above, the following field is included:</p>
1210
1211<table>
1212 <tbody>
1213 <tr>
1214 <th><b>Type</b></th>
1215 <th class="td_left"><b>Description</b></th>
1216 </tr>
1217 <tr>
1218 <td><a href="#uint32_vbr">uint32_vbr</a>
1219 </td>
1220 <td class="td_left">An optional section ID number, specifying the string
1221 to use for the section of the function. This an index (+1) of an entry
1222 into the SectionID llist in the <a href="#globalinfo">Module Global
1223 Info</a> block. If this value is 0 or not present, the function has an
1224 empty section string.</td>
1225 </tr>
1226 </tbody>
1227</table>
1228
Chris Lattnera1dad812004-10-16 18:03:55 +00001229</div>
1230
Reid Spencer50026612004-05-22 02:28:36 +00001231<!-- _______________________________________________________________________ -->
Reid Spencer1ab929c2004-07-05 08:18:07 +00001232<div class="doc_subsection"><a name="constantpool">Constant Pool</a> </div>
Reid Spencer50026612004-05-22 02:28:36 +00001233<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +00001234<p>A constant pool defines as set of constant values. There are
1235actually two types of constant pool blocks: one for modules and one for
1236functions. For modules, the block begins with the constant strings
1237encountered anywhere in the module. For functions, the block begins
1238with types only encountered in the function. In both cases the header
1239is identical. The tables that follow, show the header, module constant
1240pool preamble, function constant pool preamble, and the part common to
1241both function and module constant pools.</p>
1242<p><b>Common Block Header</b></p>
1243<table>
1244 <tbody>
Reid Spencer2cc36152004-07-05 19:04:27 +00001245 <tr>
1246 <th><b>Type</b></th>
1247 <th class="td_left"><b>Field Description</b></th>
Reid Spencer2cc36152004-07-05 19:04:27 +00001248 </tr>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001249 <tr>
1250 <td><a href="#block">block</a></td>
1251 <td class="td_left">Constant pool identifier (0x03) + size<br>
1252 </td>
1253 </tr>
1254 </tbody>
1255</table>
1256<p><b>Module Constant Pool Preamble (constant strings)</b></p>
1257<table>
1258 <tbody>
Reid Spencer2cc36152004-07-05 19:04:27 +00001259 <tr>
1260 <th><b>Type</b></th>
1261 <th class="td_left"><b>Field Description</b></th>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001262 </tr>
1263 <tr>
Reid Spencer2cc36152004-07-05 19:04:27 +00001264 <td><a href="#uint32_vbr">uint32_vbr</a></td>
1265 <td class="td_left">The number of constant strings that follow.</td>
Reid Spencer2cc36152004-07-05 19:04:27 +00001266 </tr>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001267 <tr>
1268 <td><a href="#uint32_vbr">uint32_vbr</a></td>
1269 <td class="td_left">Zero. This identifies the following "plane"
1270as containing the constant strings. This is needed to identify it
1271uniquely from other constant planes that follow. </td>
1272 </tr>
1273 <tr>
1274 <td><a href="#uint24_vbr">uint24_vbr</a>+</td>
Reid Spencer09daa632004-08-18 20:06:19 +00001275 <td class="td_left">Type slot number of the constant string's type.
Reid Spencer9bd2be22004-07-29 00:13:04 +00001276Note that the constant string's type implicitly defines the length of
1277the string. </td>
1278 </tr>
1279 </tbody>
1280</table>
1281<p><b>Function Constant Pool Preamble (function types)</b></p>
1282<p>The structure of the types for functions is identical to the <a
1283 href="#globaltypes">Global Type Pool</a>. Please refer to that section
1284for the details. </p>
1285<p><b>Common Part (other constants)</b></p>
1286<table>
1287 <tbody>
Reid Spencer2cc36152004-07-05 19:04:27 +00001288 <tr>
1289 <th><b>Type</b></th>
1290 <th class="td_left"><b>Field Description</b></th>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001291 </tr>
1292 <tr>
Reid Spencer2cc36152004-07-05 19:04:27 +00001293 <td><a href="#uint32_vbr">uint32_vbr</a></td>
1294 <td class="td_left">Number of entries in this type plane.</td>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001295 </tr>
1296 <tr>
1297 <td><a href="#uint24_vbr">uint24_vbr</a></td>
Reid Spencer2cc36152004-07-05 19:04:27 +00001298 <td class="td_left">Type slot number of this plane.</td>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001299 </tr>
1300 <tr>
Reid Spencer82c46712004-07-07 13:34:26 +00001301 <td><a href="#constant">constant</a>+</td>
Reid Spencer2cc36152004-07-05 19:04:27 +00001302 <td class="td_left">The definition of a constant (see below).</td>
1303 </tr>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001304 </tbody>
1305</table>
Reid Spencer2cc36152004-07-05 19:04:27 +00001306</div>
Chris Lattner591d0492006-01-25 23:31:53 +00001307
Reid Spencer2cc36152004-07-05 19:04:27 +00001308<!-- _______________________________________________________________________ -->
Chris Lattner591d0492006-01-25 23:31:53 +00001309<div class="doc_subsubsection"><a name="constant">Simple Constant Pool
1310Entries</a></div>
1311
Reid Spencer2cc36152004-07-05 19:04:27 +00001312<div class="doc_text">
Chris Lattner591d0492006-01-25 23:31:53 +00001313
1314<p>Constant pool entries come in many shapes and flavors. The sections that
1315follow define the format for each of them. All constants start with a <a
Reid Spencer9bd2be22004-07-29 00:13:04 +00001316 href="#uint32_vbr">uint32_vbr</a> encoded integer that provides the
1317number of operands for the constant. For primitive, structure, and
Chris Lattner591d0492006-01-25 23:31:53 +00001318array constants, this will always be zero to indicate that the form of the
1319constant is solely determined by its type. In this case, we have the following
1320field definitions, based on type:</p>
1321
Reid Spencer9bd2be22004-07-29 00:13:04 +00001322<ul>
1323 <li><b>Bool</b>. This is written as an <a href="#uint32_vbr">uint32_vbr</a>
1324of value 1U or 0U.</li>
1325 <li><b>Signed Integers (sbyte,short,int,long)</b>. These are written
1326as an <a href="#int64_vbr">int64_vbr</a> with the corresponding value.</li>
1327 <li><b>Unsigned Integers (ubyte,ushort,uint,ulong)</b>. These are
1328written as an <a href="#uint64_vbr">uint64_vbr</a> with the
1329corresponding value. </li>
1330 <li><b>Floating Point</b>. Both the float and double types are
1331written literally in binary format.</li>
1332 <li><b>Arrays</b>. Arrays are written simply as a list of <a
Reid Spencer09daa632004-08-18 20:06:19 +00001333 href="#uint32_vbr">uint32_vbr</a> encoded value slot numbers to the constant
Reid Spencer9bd2be22004-07-29 00:13:04 +00001334element values.</li>
1335 <li><b>Structures</b>. Structures are written simply as a list of <a
Reid Spencer09daa632004-08-18 20:06:19 +00001336 href="#uint32_vbr">uint32_vbr</a> encoded value slot numbers to the constant
Reid Spencer9bd2be22004-07-29 00:13:04 +00001337field values of the structure.</li>
1338</ul>
Chris Lattnera1dad812004-10-16 18:03:55 +00001339
Chris Lattner591d0492006-01-25 23:31:53 +00001340</div>
1341
1342<!-- _______________________________________________________________________ -->
Anton Korobeynikov7f705592007-01-12 19:20:47 +00001343<div class="doc_subsubsection">Undef Entries</div>
Chris Lattner591d0492006-01-25 23:31:53 +00001344
1345<div class="doc_text">
Chris Lattnera1dad812004-10-16 18:03:55 +00001346<p>When the number of operands to the constant is one, we have an 'undef' value
1347of the specified type.</p>
Chris Lattner591d0492006-01-25 23:31:53 +00001348</div>
Chris Lattnera1dad812004-10-16 18:03:55 +00001349
Chris Lattner591d0492006-01-25 23:31:53 +00001350<!-- _______________________________________________________________________ -->
Anton Korobeynikov7f705592007-01-12 19:20:47 +00001351<div class="doc_subsubsection">Inline Assembler Entries</div>
Chris Lattner591d0492006-01-25 23:31:53 +00001352
1353<div class="doc_text">
1354<p>Inline Assembler entries are stored in the constant pool, though they are not
1355 officially LLVM constants. These entries are marked with a value of
1356 "4294967295" (all ones) for the number of operands. They are encoded as
1357 follows:</p>
1358
1359<table>
1360 <tbody>
1361 <tr>
1362 <th><b>Type</b></th>
1363 <th class="td_left"><b>Field Description</b></th>
1364 </tr>
1365 <tr>
1366 <td><a href="#string">string</a></td>
1367 <td class="td_left">The asm string.</td>
1368 </tr>
1369 <tr>
1370 <td><a href="#string">string</a></td>
1371 <td class="td_left">The constraints string.</td>
1372 </tr>
1373 <tr>
1374 <td><a href="#uint32_vbr">uint32_vbr</a></td>
Anton Korobeynikov7f705592007-01-12 19:20:47 +00001375 <td class="td_left">Flags</td>
Chris Lattner591d0492006-01-25 23:31:53 +00001376 </tr>
1377 </tbody>
1378</table>
1379
1380<p>Currently, the only defined flag, the low bit, indicates whether or not the
1381 inline assembler has side effects.</p>
1382
1383</div>
1384
1385<!-- _______________________________________________________________________ -->
Anton Korobeynikov7f705592007-01-12 19:20:47 +00001386<div class="doc_subsubsection">Constant Expression Entries</div>
Chris Lattner591d0492006-01-25 23:31:53 +00001387
1388<div class="doc_text">
1389
1390<p>Otherwise, we have a constant expression. The format of the constant
1391expression is specified in the table below, and the number is equal to the
1392number of operands+1.</p>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001393<table>
1394 <tbody>
Reid Spencer2cc36152004-07-05 19:04:27 +00001395 <tr>
1396 <th><b>Type</b></th>
1397 <th class="td_left"><b>Field Description</b></th>
Reid Spencer2cc36152004-07-05 19:04:27 +00001398 </tr>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001399 <tr>
1400 <td><a href="#uint32_vbr">uint32_vbr</a></td>
1401 <td class="td_left">Op code of the instruction for the constant
1402expression.</td>
1403 </tr>
1404 <tr>
1405 <td><a href="#uint32_vbr">uint32_vbr</a></td>
Reid Spencer09daa632004-08-18 20:06:19 +00001406 <td class="td_left">The value slot number of the constant value for an
Reid Spencer9bd2be22004-07-29 00:13:04 +00001407operand.<sup>1</sup></td>
1408 </tr>
1409 <tr>
1410 <td><a href="#uint24_vbr">uint24_vbr</a></td>
Reid Spencer09daa632004-08-18 20:06:19 +00001411 <td class="td_left">The type slot number for the type of the constant
Reid Spencer9bd2be22004-07-29 00:13:04 +00001412value for an operand.<sup>1</sup></td>
1413 </tr>
1414 </tbody>
1415</table>
1416Notes:
1417<ol>
1418 <li>Both these fields are repeatable but only in pairs.</li>
1419</ol>
Reid Spencer50026612004-05-22 02:28:36 +00001420</div>
1421<!-- _______________________________________________________________________ -->
Reid Spencer51f31e02004-07-05 22:28:02 +00001422<div class="doc_subsection"><a name="functiondefs">Function Definition</a></div>
Reid Spencer1ab929c2004-07-05 08:18:07 +00001423<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +00001424<p>Function definitions contain the linkage, constant pool or
1425compaction table, instruction list, and symbol table for a function.
1426The following table shows the structure of a function definition.</p>
1427<table>
1428 <tbody>
Reid Spencer51f31e02004-07-05 22:28:02 +00001429 <tr>
1430 <th><b>Type</b></th>
1431 <th class="td_left"><b>Field Description</b></th>
Reid Spencer51f31e02004-07-05 22:28:02 +00001432 </tr>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001433 <tr>
1434 <td><a href="#block">block</a><br>
1435 </td>
1436 <td class="td_left">Function definition block identifier (0x02) +
1437size<br>
1438 </td>
1439 </tr>
1440 <tr>
1441 <td><a href="#uint32_vbr">uint32_vbr</a></td>
Anton Korobeynikov7f705592007-01-12 19:20:47 +00001442 <td class="td_left"><a href="#funclinkage_and_visibility">The linkage and
1443 visibility</a> style field</td>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001444 </tr>
1445 <tr>
1446 <td><a href="#block">block</a></td>
1447 <td class="td_left">The <a href="#constantpool">constant pool</a>
1448block for this function.<sup>2</sup></td>
1449 </tr>
1450 <tr>
1451 <td><a href="#block">block</a></td>
1452 <td class="td_left">The <a href="#compactiontable">compaction
1453table</a> block for the function.<sup>2</sup></td>
1454 </tr>
1455 <tr>
1456 <td><a href="#block">block</a></td>
1457 <td class="td_left">The <a href="#instructionlist">instruction
1458list</a> for the function.</td>
1459 </tr>
1460 <tr>
1461 <td><a href="#block">block</a></td>
Reid Spencer8996e552004-08-17 00:49:03 +00001462 <td class="td_left">The function's <a href="#symtab">symbol
Reid Spencer9bd2be22004-07-29 00:13:04 +00001463table</a> containing only those symbols pertinent to the function
1464(mostly block labels).</td>
1465 </tr>
1466 </tbody>
1467</table>
1468Notes:
1469<ol>
1470 <li>Note that if the linkage type is "External" then none of the
1471other fields will be present as the function is defined elsewhere.</li>
1472 <li>Note that only one of the constant pool or compaction table will
1473be written. Compaction tables are only written if they will actually
1474save bytecode space. If not, then a regular constant pool is written.</li>
1475</ol>
Anton Korobeynikov7f705592007-01-12 19:20:47 +00001476
1477<!-- _______________________________________________________________________ -->
1478<div class="doc_subsubsection"><a name="funclinkage_and_visibility">Linkage and
1479 visibility word</a>
Reid Spencer1ab929c2004-07-05 08:18:07 +00001480</div>
Anton Korobeynikov7f705592007-01-12 19:20:47 +00001481<div class="doc_text">
1482
1483<table>
1484 <tbody>
1485 <tr>
1486 <th><b>Type</b></th>
1487 <th class="td_left"><b>Field Description</b></th>
1488 </tr>
1489 <tr>
1490 <td><a href="#bit">bit(0-15)</a></td>
1491 <td class="td_left">The linkage type of the function: 0=External, 1=Weak,
14922=Appending, 3=Internal, 4=LinkOnce, 5=DllImport, 6=DllExport<sup>1</sup></td>
1493 </tr>
1494 <tr>
Anton Korobeynikovdaa31892007-01-23 12:43:53 +00001495 <td><a href="#bit">bit(16-18)</a></td>
Anton Korobeynikov7f705592007-01-12 19:20:47 +00001496 <td class="td_left">Visibility style: 0=Default, 1=Hidden.</td>
1497 </tr>
Anton Korobeynikovdaa31892007-01-23 12:43:53 +00001498 <tr>
1499 <td><a href="#bit">bit(19-31)</a></td>
1500 <td class="td_left>Currently unassigned.</td>
1501 </tr>
Anton Korobeynikov7f705592007-01-12 19:20:47 +00001502 </tbody>
1503</table>
1504
1505</div>
1506</div>
1507
Reid Spencer1ab929c2004-07-05 08:18:07 +00001508<!-- _______________________________________________________________________ -->
Reid Spencer9bd2be22004-07-29 00:13:04 +00001509<div class="doc_subsection"><a name="compactiontable">Compaction Table</a>
1510</div>
Reid Spencer1ab929c2004-07-05 08:18:07 +00001511<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +00001512<p>Compaction tables are part of a function definition. They are merely
1513a device for reducing the size of bytecode files. The size of a
Reid Spencer09daa632004-08-18 20:06:19 +00001514bytecode file is dependent on the <em>values</em> of the slot numbers
Reid Spencer9bd2be22004-07-29 00:13:04 +00001515used because larger values use more bytes in the variable bit rate
1516encoding scheme. Furthermore, the compressed instruction format
1517reserves only six bits for the type of the instruction. In large
1518modules, declaring hundreds or thousands of types, the values of the
1519slot numbers can be quite large. However, functions may use only a
1520small fraction of the global types. In such cases a compaction table is
1521created that maps the global type and value slot numbers to smaller
1522values used by a function. Functions will contain either a
1523function-specific constant pool <em>or</em> a compaction table but not
1524both. Compaction tables have the format shown in the table below.</p>
1525<table>
1526 <tbody>
Reid Spencer2cc36152004-07-05 19:04:27 +00001527 <tr>
1528 <th><b>Type</b></th>
1529 <th class="td_left"><b>Field Description</b></th>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001530 </tr>
1531 <tr>
Reid Spencer2cc36152004-07-05 19:04:27 +00001532 <td><a href="#uint32_vbr">uint32_vbr</a></td>
1533 <td class="td_left">The number of types that follow</td>
Reid Spencer2cc36152004-07-05 19:04:27 +00001534 </tr>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001535 <tr>
1536 <td><a href="#uint24_vbr">uint24_vbr</a>+</td>
Reid Spencer09daa632004-08-18 20:06:19 +00001537 <td class="td_left">The type slot number in the global types of
Reid Spencer9bd2be22004-07-29 00:13:04 +00001538the type that will be referenced in the function with the index of this
1539entry in the compaction table.</td>
1540 </tr>
1541 <tr>
1542 <td><a href="#type_len">type_len</a></td>
1543 <td class="td_left">An encoding of the type and number of values
1544that follow. This field's encoding varies depending on the size of the
1545type plane. See <a href="#type_len">Type and Length</a> for further
1546details.</td>
1547 </tr>
1548 <tr>
1549 <td><a href="#uint32_vbr">uint32_vbr</a>+</td>
Reid Spencer09daa632004-08-18 20:06:19 +00001550 <td class="td_left">The value slot number in the global values
Reid Spencer9bd2be22004-07-29 00:13:04 +00001551that will be referenced in the function with the index of this entry in
Reid Spencer09daa632004-08-18 20:06:19 +00001552the compaction table.</td>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001553 </tr>
1554 </tbody>
1555</table>
Reid Spencer1ab929c2004-07-05 08:18:07 +00001556</div>
Reid Spencer2cc36152004-07-05 19:04:27 +00001557<!-- _______________________________________________________________________ -->
1558<div class="doc_subsubsection"><a name="type_len">Type and Length</a></div>
1559<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +00001560<p>The type and length of a compaction table type plane is encoded
1561differently depending on the length of the plane. For planes of length
15621 or 2, the length is encoded into bits 0 and 1 of a <a
1563 href="#uint32_vbr">uint32_vbr</a> and the type is encoded into bits
15642-31. Because type numbers are often small, this often saves an extra
1565byte per plane. If the length of the plane is greater than 2 then the
1566encoding uses a <a href="#uint32_vbr">uint32_vbr</a> for each of the
1567length and type, in that order.</p>
Reid Spencer2cc36152004-07-05 19:04:27 +00001568</div>
Reid Spencer1ab929c2004-07-05 08:18:07 +00001569<!-- _______________________________________________________________________ -->
Reid Spencer09daa632004-08-18 20:06:19 +00001570<div class="doc_subsection"><a name="instructionlist">Instruction List</a></div>
Reid Spencer50026612004-05-22 02:28:36 +00001571<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +00001572<p>The instructions in a function are written as a simple list. Basic
1573blocks are inferred by the terminating instruction types. The format of
1574the block is given in the following table.</p>
1575<table>
1576 <tbody>
Reid Spencer51f31e02004-07-05 22:28:02 +00001577 <tr>
1578 <th><b>Type</b></th>
1579 <th class="td_left"><b>Field Description</b></th>
Reid Spencer51f31e02004-07-05 22:28:02 +00001580 </tr>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001581 <tr>
1582 <td><a href="#block">block</a><br>
1583 </td>
1584 <td class="td_left">Instruction list identifier (0x07) + size<br>
1585 </td>
1586 </tr>
1587 <tr>
1588 <td><a href="#instruction">instruction</a>+</td>
1589 <td class="td_left">An instruction. Instructions have a variety
1590of formats. See <a href="#instruction">Instructions</a> for details.</td>
1591 </tr>
1592 </tbody>
1593</table>
Reid Spencer50026612004-05-22 02:28:36 +00001594</div>
Chris Lattnerf97fa592005-11-05 22:20:06 +00001595
Reid Spencer51f31e02004-07-05 22:28:02 +00001596<!-- _______________________________________________________________________ -->
Chris Lattnerf97fa592005-11-05 22:20:06 +00001597<div class="doc_subsection"><a name="instructions">Instructions</a></div>
1598
Reid Spencer51f31e02004-07-05 22:28:02 +00001599<div class="doc_text">
Chris Lattnerf97fa592005-11-05 22:20:06 +00001600<p>Instructions are written out one at a time as distinct units. Each
1601instruction
1602record contains at least an <a href="#opcodes">opcode</a> and a type field,
Chris Lattner49b16022005-11-05 22:32:06 +00001603and may contain a <a href="#instoperands">list of operands</a> (whose
1604interpretation depends on the opcode). Based on the number of operands, the
Chris Lattnerf97fa592005-11-05 22:20:06 +00001605<a href="#instencode">instruction is encoded</a> in a
1606dense format that tries to encoded each instruction into 32-bits if
1607possible. </p>
Reid Spencer51f31e02004-07-05 22:28:02 +00001608</div>
Reid Spencer09daa632004-08-18 20:06:19 +00001609
1610<!-- _______________________________________________________________________ -->
Chris Lattnerf97fa592005-11-05 22:20:06 +00001611<div class="doc_subsubsection"><a name="opcodes">Instruction Opcodes</a></div>
Reid Spencer09daa632004-08-18 20:06:19 +00001612<div class="doc_text">
1613 <p>Instructions encode an opcode that identifies the kind of instruction.
1614 Opcodes are an enumerated integer value. The specific values used depend on
1615 the version of LLVM you're using. The opcode values are defined in the
Reid Spencer05fe4b02006-03-14 05:39:39 +00001616 <a href="http://llvm.org/cvsweb/cvsweb.cgi/llvm/include/llvm/Instruction.def">
Reid Spencer09daa632004-08-18 20:06:19 +00001617 <tt>include/llvm/Instruction.def</tt></a> file. You should check there for the
1618 most recent definitions. The table below provides the opcodes defined as of
Nate Begeman52ca9e42004-08-27 07:59:37 +00001619 the writing of this document. The table associates each opcode mnemonic with
Reid Spencer09daa632004-08-18 20:06:19 +00001620 its enumeration value and the bytecode and LLVM version numbers in which the
1621 opcode was introduced.</p>
1622 <table>
1623 <tbody>
1624 <tr>
1625 <th>Opcode</th>
1626 <th>Number</th>
1627 <th>Bytecode Version</th>
1628 <th>LLVM Version</th>
1629 </tr>
1630 <tr><td colspan="4"><b>Terminator Instructions</b></td></tr>
1631 <tr><td>Ret</td><td>1</td><td>1</td><td>1.0</td></tr>
1632 <tr><td>Br</td><td>2</td><td>1</td><td>1.0</td></tr>
1633 <tr><td>Switch</td><td>3</td><td>1</td><td>1.0</td></tr>
1634 <tr><td>Invoke</td><td>4</td><td>1</td><td>1.0</td></tr>
1635 <tr><td>Unwind</td><td>5</td><td>1</td><td>1.0</td></tr>
Chris Lattnera1dad812004-10-16 18:03:55 +00001636 <tr><td>Unreachable</td><td>6</td><td>1</td><td>1.4</td></tr>
Reid Spencer09daa632004-08-18 20:06:19 +00001637 <tr><td colspan="4"><b>Binary Operators</b></td></tr>
Chris Lattnera1dad812004-10-16 18:03:55 +00001638 <tr><td>Add</td><td>7</td><td>1</td><td>1.0</td></tr>
1639 <tr><td>Sub</td><td>8</td><td>1</td><td>1.0</td></tr>
1640 <tr><td>Mul</td><td>9</td><td>1</td><td>1.0</td></tr>
Reid Spencer3727fd32006-11-08 20:06:36 +00001641 <tr><td>UDiv</td><td>10</td><td>1</td><td>1.9</td></tr>
1642 <tr><td>SDiv</td><td>11</td><td>1</td><td>1.9</td></tr>
1643 <tr><td>FDiv</td><td>12</td><td>1</td><td>1.9</td></tr>
1644 <tr><td>URem</td><td>13</td><td>1</td><td>1.9</td></tr>
1645 <tr><td>SRem</td><td>14</td><td>1</td><td>1.9</td></tr>
1646 <tr><td>FRem</td><td>15</td><td>1</td><td>1.9</td></tr>
Reid Spencer09daa632004-08-18 20:06:19 +00001647 <tr><td colspan="4"><b>Logical Operators</b></td></tr>
Reid Spencer3727fd32006-11-08 20:06:36 +00001648 <tr><td>And</td><td>16</td><td>1</td><td>1.0</td></tr>
1649 <tr><td>Or</td><td>17</td><td>1</td><td>1.0</td></tr>
1650 <tr><td>Xor</td><td>18</td><td>1</td><td>1.0</td></tr>
Reid Spencer09daa632004-08-18 20:06:19 +00001651 <tr><td colspan="4"><b>Binary Comparison Operators</b></td></tr>
Reid Spencer3727fd32006-11-08 20:06:36 +00001652 <tr><td>SetEQ</td><td>19</td><td>1</td><td>1.0</td></tr>
1653 <tr><td>SetNE</td><td>20</td><td>1</td><td>1.0</td></tr>
1654 <tr><td>SetLE</td><td>21</td><td>1</td><td>1.0</td></tr>
1655 <tr><td>SetGE</td><td>22</td><td>1</td><td>1.0</td></tr>
1656 <tr><td>SetLT</td><td>23</td><td>1</td><td>1.0</td></tr>
1657 <tr><td>SetGT</td><td>24</td><td>1</td><td>1.0</td></tr>
Reid Spencer09daa632004-08-18 20:06:19 +00001658 <tr><td colspan="4"><b>Memory Operators</b></td></tr>
Reid Spencer3727fd32006-11-08 20:06:36 +00001659 <tr><td>Malloc</td><td>25</td><td>1</td><td>1.0</td></tr>
1660 <tr><td>Free</td><td>26</td><td>1</td><td>1.0</td></tr>
1661 <tr><td>Alloca</td><td>27</td><td>1</td><td>1.0</td></tr>
1662 <tr><td>Load</td><td>28</td><td>1</td><td>1.0</td></tr>
1663 <tr><td>Store</td><td>29</td><td>1</td><td>1.0</td></tr>
1664 <tr><td>GetElementPtr</td><td>30</td><td>1</td><td>1.0</td></tr>
Reid Spencer09daa632004-08-18 20:06:19 +00001665 <tr><td colspan="4"><b>Other Operators</b></td></tr>
Reid Spencer3727fd32006-11-08 20:06:36 +00001666 <tr><td>PHI</td><td>31</td><td>1</td><td>1.0</td></tr>
1667 <tr><td>Cast</td><td>32</td><td>1</td><td>1.0</td></tr>
1668 <tr><td>Call</td><td>33</td><td>1</td><td>1.0</td></tr>
1669 <tr><td>Shl</td><td>34</td><td>1</td><td>1.0</td></tr>
Reid Spencer3727fd32006-11-08 20:06:36 +00001670 <tr><td>LShr</td><td>35</td><td>6</td><td>2.0</td></tr>
1671 <tr><td>AShr</td><td>36</td><td>6</td><td>2.0</td></tr>
Reid Spencer145b2532006-11-08 20:07:40 +00001672 <tr><td>Select</td><td>37</td><td>2</td><td>1.2</td></tr>
1673 <tr><td>UserOp1</td><td>38</td><td>1</td><td>1.0</td></tr>
1674 <tr><td>UserOp2</td><td>39</td><td>1</td><td>1.0</td></tr>
1675 <tr><td>VAArg</td><td>40</td><td>5</td><td>1.5</td></tr>
1676 <tr><td>ExtractElement</td><td>41</td><td>5</td><td>1.5</td></tr>
1677 <tr><td>InsertElement</td><td>42</td><td>5</td><td>1.5</td></tr>
1678 <tr><td>ShuffleElement</td><td>43</td><td>5</td><td>1.5</td></tr>
Reid Spencera5681772005-05-14 00:06:06 +00001679 <tr><td colspan="4">
1680 <b>Pseudo Instructions<a href="#pi_note">*</a></b>
1681 </td></tr>
1682 <tr><td>Invoke+CC </td><td>56</td><td>5</td><td>1.5</td></tr>
1683 <tr><td>Invoke+FastCC</td><td>57</td><td>5</td><td>1.5</td></tr>
1684 <tr><td>Call+CC</td><td>58</td><td>5</td><td>1.5</td></tr>
1685 <tr><td>Call+FastCC+TailCall</td><td>59</td><td>5</td><td>1.5</td></tr>
1686 <tr><td>Call+FastCC</td><td>60</td><td>5</td><td>1.5</td></tr>
1687 <tr><td>Call+CCC+TailCall</td><td>61</td><td>5</td><td>1.5</td></tr>
1688 <tr><td>Load+Volatile</td><td>62</td><td>3</td><td>1.3</td></tr>
1689 <tr><td>Store+Volatile</td><td>63</td><td>3</td><td>1.3</td></tr>
Reid Spencer09daa632004-08-18 20:06:19 +00001690 </tbody>
1691 </table>
Reid Spencer09daa632004-08-18 20:06:19 +00001692
Reid Spencera5681772005-05-14 00:06:06 +00001693<p><b><a name="pi_note">* Note: </a></b>
Chris Lattnerf97fa592005-11-05 22:20:06 +00001694These aren't really opcodes from an LLVM language perspective. They encode
Reid Spencera5681772005-05-14 00:06:06 +00001695information into other opcodes without reserving space for that information.
1696For example, opcode=63 is a Volatile Store. The opcode for this
1697instruction is 25 (Store) but we encode it as 63 to indicate that is a Volatile
1698Store. The same is done for the calling conventions and tail calls.
1699In each of these entries in range 56-63, the opcode is documented as the base
1700opcode (Invoke, Call, Store) plus some set of modifiers, as follows:</p>
1701<dl>
1702 <dt>CC</dt>
Chris Lattner120bc6d2005-05-14 01:30:15 +00001703 <dd>This means an arbitrary calling convention is specified
1704 in a VBR that follows the opcode. This is used when the instruction cannot
1705 be encoded with one of the more compact forms.
Reid Spencera5681772005-05-14 00:06:06 +00001706 </dd>
1707 <dt>FastCC</dt>
1708 <dd>This indicates that the Call or Invoke is using the FastCC calling
Chris Lattner120bc6d2005-05-14 01:30:15 +00001709 convention.</dd>
Reid Spencera5681772005-05-14 00:06:06 +00001710 <dt>CCC</dt>
Chris Lattner120bc6d2005-05-14 01:30:15 +00001711 <dd>This indicates that the Call or Invoke is using the native "C" calling
1712 convention.</dd>
Reid Spencera5681772005-05-14 00:06:06 +00001713 <dt>TailCall</dt>
Chris Lattner120bc6d2005-05-14 01:30:15 +00001714 <dd>This indicates that the Call has the 'tail' modifier.</dd>
Reid Spencera5681772005-05-14 00:06:06 +00001715</dl>
Chris Lattnerf97fa592005-11-05 22:20:06 +00001716</div>
1717
Chris Lattner49b16022005-11-05 22:32:06 +00001718<!-- _______________________________________________________________________ -->
1719<div class="doc_subsubsection"><a name="instoperands">Instruction
1720Operands</a></div>
1721
1722<div class="doc_text">
1723<p>
1724Based on the instruction opcode and type, the bytecode format implicitly (to
1725save space) specifies the interpretation of the operand list. For most
1726instructions, the type of each operand is implicit from the type of the
1727instruction itself (e.g. the type of operands of a binary operator must match
1728the type of the instruction). As such, the bytecode format generally only
1729encodes the value number of the operand, not the type.</p>
1730
1731<p>In some cases, however, this is not sufficient. This section enumerates
1732those cases:</p>
1733
1734<ul>
1735<li>getelementptr: the slot numbers for sequential type indexes are shifted up
1736two bits. This allows the low order bits will encode the type of index used,
1737as follows: 0=uint, 1=int, 2=ulong, 3=long.</li>
1738<li>cast: the result type number is encoded as the second operand.</li>
1739<li>alloca/malloc: If the allocation has an explicit alignment, the log2 of the
1740 alignment is encoded as the second operand.</li>
1741<li>call: If the tail marker and calling convention cannot be <a
1742 href="#pi_note">encoded into the opcode</a> of the call, it is passed as an
1743 additional operand. The low bit of the operand is a flag indicating whether
1744 the call is a tail call. The rest of the bits contain the calling
1745 convention number (shifted left by one bit).</li>
1746</ul>
1747</div>
Chris Lattnerf97fa592005-11-05 22:20:06 +00001748
1749<!-- _______________________________________________________________________ -->
1750<div class="doc_subsubsection"><a name="instencode">Instruction
1751Encoding</a></div>
1752
1753<div class="doc_text">
1754<p>For brevity, instructions are written in one of four formats,
1755depending on the number of operands to the instruction. Each
1756instruction begins with a <a href="#uint32_vbr">uint32_vbr</a> that
1757encodes the type of the instruction as well as other things. The tables
1758that follow describe the format of this first part of each instruction.</p>
1759<p><b>Instruction Format 0</b></p>
1760<p>This format is used for a few instructions that can't easily be
1761shortened because they have large numbers of operands (e.g. PHI Node or
1762getelementptr). Each of the opcode, type, and operand fields is found in
1763successive fields.</p>
1764<table>
1765 <tbody>
1766 <tr>
1767 <th><b>Type</b></th>
1768 <th class="td_left"><b>Field Description</b></th>
1769 </tr>
1770 <tr>
1771 <td><a href="#uint32_vbr">uint32_vbr</a></td>
1772 <td class="td_left">Specifies the opcode of the instruction. Note
1773that for compatibility with the other instruction formats, the opcode
1774is shifted left by 2 bits. Bits 0 and 1 must have value zero for this
1775format.</td>
1776 </tr>
1777 <tr>
1778 <td><a href="#uint24_vbr">uint24_vbr</a></td>
1779 <td class="td_left">Provides the type slot number of the result type of
1780 the instruction.</td>
1781 </tr>
1782 <tr>
1783 <td><a href="#uint32_vbr">uint32_vbr</a></td>
1784 <td class="td_left">The number of operands that follow.</td>
1785 </tr>
1786 <tr>
1787 <td><a href="#uint32_vbr">uint32_vbr</a>+</td>
1788 <td class="td_left">The slot number of the value(s) for the operand(s).
Chris Lattner49b16022005-11-05 22:32:06 +00001789 </td>
Chris Lattnerf97fa592005-11-05 22:20:06 +00001790 </tr>
1791 </tbody>
1792</table>
Chris Lattner49b16022005-11-05 22:32:06 +00001793
Chris Lattnerf97fa592005-11-05 22:20:06 +00001794<p><b>Instruction Format 1</b></p>
1795<p>This format encodes the opcode, type and a single operand into a
1796single <a href="#uint32_vbr">uint32_vbr</a> as follows:</p>
1797<table>
1798 <tbody>
1799 <tr>
1800 <th><b>Bits</b></th>
1801 <th><b>Type</b></th>
1802 <th class="td_left"><b>Field Description</b></th>
1803 </tr>
1804 <tr>
1805 <td>0-1</td>
1806 <td>constant "1"</td>
1807 <td class="td_left">These two bits must be the value 1 which identifies
1808 this as an instruction of format 1.</td>
1809 </tr>
1810 <tr>
1811 <td>2-7</td>
1812 <td><a href="#instructions">opcode</a></td>
1813 <td class="td_left">Specifies the opcode of the instruction. Note that
1814 the maximum opcode value is 63.</td>
1815 </tr>
1816 <tr>
1817 <td>8-19</td>
1818 <td><a href="#unsigned">unsigned</a></td>
1819 <td class="td_left">Specifies the slot number of the type for this
1820 instruction. Maximum slot number is 2<sup>12</sup>-1=4095.</td>
1821 </tr>
1822 <tr>
1823 <td>20-31</td>
1824 <td><a href="#unsigned">unsigned</a></td>
1825 <td class="td_left">Specifies the slot number of the value for the
1826 first operand. Maximum slot number is 2<sup>12</sup>-1=4095. Note that
1827 the value 2<sup>12</sup>-1 denotes zero operands.</td>
1828 </tr>
1829 </tbody>
1830</table>
1831<p><b>Instruction Format 2</b></p>
1832<p>This format encodes the opcode, type and two operands into a single <a
1833 href="#uint32_vbr">uint32_vbr</a> as follows:</p>
1834<table>
1835 <tbody>
1836 <tr>
1837 <th><b>Bits</b></th>
1838 <th><b>Type</b></th>
1839 <th class="td_left"><b>Field Description</b></th>
1840 </tr>
1841 <tr>
1842 <td>0-1</td>
1843 <td>constant "2"</td>
1844 <td class="td_left">These two bits must be the value 2 which identifies
1845 this as an instruction of format 2.</td>
1846 </tr>
1847 <tr>
1848 <td>2-7</td>
1849 <td><a href="#instructions">opcode</a></td>
1850 <td class="td_left">Specifies the opcode of the instruction. Note that
1851 the maximum opcode value is 63.</td>
1852 </tr>
1853 <tr>
1854 <td>8-15</td>
1855 <td><a href="#unsigned">unsigned</a></td>
1856 <td class="td_left">Specifies the slot number of the type for this
1857 instruction. Maximum slot number is 2<sup>8</sup>-1=255.</td>
1858 </tr>
1859 <tr>
1860 <td>16-23</td>
1861 <td><a href="#unsigned">unsigned</a></td>
1862 <td class="td_left">Specifies the slot number of the value for the first
1863 operand. Maximum slot number is 2<sup>8</sup>-1=255.</td>
1864 </tr>
1865 <tr>
1866 <td>24-31</td>
1867 <td><a href="#unsigned">unsigned</a></td>
1868 <td class="td_left">Specifies the slot number of the value for the second
1869 operand. Maximum slot number is 2<sup>8</sup>-1=255.</td>
1870 </tr>
1871 </tbody>
1872</table>
1873<p><b>Instruction Format 3</b></p>
1874<p>This format encodes the opcode, type and three operands into a
1875single <a href="#uint32_vbr">uint32_vbr</a> as follows:</p>
1876<table>
1877 <tbody>
1878 <tr>
1879 <th><b>Bits</b></th>
1880 <th><b>Type</b></th>
1881 <th class="td_left"><b>Field Description</b></th>
1882 </tr>
1883 <tr>
1884 <td>0-1</td>
1885 <td>constant "3"</td>
1886 <td class="td_left">These two bits must be the value 3 which identifies
1887 this as an instruction of format 3.</td>
1888 </tr>
1889 <tr>
1890 <td>2-7</td>
1891 <td><a href="#instructions">opcode</a></td>
1892 <td class="td_left">Specifies the opcode of the instruction. Note that
1893 the maximum opcode value is 63.</td>
1894 </tr>
1895 <tr>
1896 <td>8-13</td>
1897 <td><a href="#unsigned">unsigned</a></td>
1898 <td class="td_left">Specifies the slot number of the type for this
1899 instruction. Maximum slot number is 2<sup>6</sup>-1=63.</td>
1900 </tr>
1901 <tr>
1902 <td>14-19</td>
1903 <td><a href="#unsigned">unsigned</a></td>
1904 <td class="td_left">Specifies the slot number of the value for the first
1905 operand. Maximum slot number is 2<sup>6</sup>-1=63.</td>
1906 </tr>
1907 <tr>
1908 <td>20-25</td>
1909 <td><a href="#unsigned">unsigned</a></td>
1910 <td class="td_left">Specifies the slot number of the value for the second
1911 operand. Maximum slot number is 2<sup>6</sup>-1=63.</td>
1912 </tr>
1913 <tr>
1914 <td>26-31</td>
1915 <td><a href="#unsigned">unsigned</a></td>
1916 <td class="td_left">Specifies the slot number of the value for the third
1917 operand. Maximum slot number is 2<sup>6</sup>-1=63.</td>
1918 </tr>
1919 </tbody>
1920</table>
1921</div>
Reid Spencera5681772005-05-14 00:06:06 +00001922
Reid Spencer50026612004-05-22 02:28:36 +00001923<!-- _______________________________________________________________________ -->
Reid Spencerb39021b2004-05-23 17:05:09 +00001924<div class="doc_subsection"><a name="symtab">Symbol Table</a> </div>
Reid Spencer50026612004-05-22 02:28:36 +00001925<div class="doc_text">
Reid Spencer09daa632004-08-18 20:06:19 +00001926<p>A symbol table can be put out in conjunction with a module or a function. A
1927symbol table has a list of name/type associations followed by a list of
1928name/value associations. The name/value associations are organized into "type
1929planes" so that all values of a common type are listed together. Each type
1930plane starts with the number of entries in the plane and the type slot number
1931for all the values in that plane (so the type can be looked up in the global
1932type pool). For each entry in a type plane, the slot number of the value and
1933the name associated with that value are written. The format is given in the
1934table below. </p>
Reid Spencer2cc36152004-07-05 19:04:27 +00001935<table>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001936 <tbody>
1937 <tr>
1938 <th><b>Type</b></th>
1939 <th class="td_left"><b>Field Description</b></th>
1940 </tr>
1941 <tr>
1942 <td><a href="#block">block</a><br>
1943 </td>
1944 <td class="td_left">Symbol Table Identifier (0x04)</td>
1945 </tr>
1946 <tr>
Reid Spencer09daa632004-08-18 20:06:19 +00001947 <td><a href="#llist">llist</a>(<a href="#symtab_entry">type_entry</a>)</td>
Reid Spencer8996e552004-08-17 00:49:03 +00001948 <td class="td_left">A length list of symbol table entries for
1949 <tt>Type</tt>s
1950 </td>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001951 </tr>
1952 <tr>
Reid Spencer8996e552004-08-17 00:49:03 +00001953 <td><a href="#zlist">llist</a>(<a href="#symtab_plane">symtab_plane</a>)</td>
Reid Spencer09daa632004-08-18 20:06:19 +00001954 <td class="td_left">A length list of "type planes" of symbol table
Reid Spencer8996e552004-08-17 00:49:03 +00001955 entries for <tt>Value</tt>s</td>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001956 </tr>
1957 </tbody>
Reid Spencerb39021b2004-05-23 17:05:09 +00001958</table>
Reid Spencer50026612004-05-22 02:28:36 +00001959</div>
Reid Spencer09daa632004-08-18 20:06:19 +00001960
1961<!-- _______________________________________________________________________ -->
1962<div class="doc_subsubsection"> <a name="type_entry">Symbol Table Type
1963Entry</a>
1964</div>
1965<div class="doc_text">
1966<p>A symbol table type entry associates a name with a type. The name is provided
1967simply as an array of chars. The type is provided as a type slot number (index)
1968into the global type pool. The format is given in the following table:</p>
1969<table>
1970 <tbody>
1971 <tr>
1972 <th><b>Type</b></th>
1973 <th class="td_left"><b>Field Description</b></th>
1974 </tr>
1975 <tr>
1976 <td><a href="#uint32_vbr">uint24_vbr</a></td>
1977 <td class="td_left">Type slot number of the type being given a
1978 name relative to the global type pool.
1979 </td>
1980 </tr>
1981 <tr>
1982 <td><a href="#uint32_vbr">uint32_vbr</a></td>
1983 <td class="td_left">Length of the character array that follows.</td>
1984 </tr>
1985 <tr>
1986 <td><a href="#char">char</a>+</td>
1987 <td class="td_left">The characters of the name.</td>
1988 </tr>
1989 </tbody>
1990</table>
1991</div>
Reid Spencer51f31e02004-07-05 22:28:02 +00001992<!-- _______________________________________________________________________ -->
Reid Spencer9bd2be22004-07-29 00:13:04 +00001993<div class="doc_subsubsection"> <a name="symtab_plane">Symbol Table
1994Plane</a>
Reid Spencer51f31e02004-07-05 22:28:02 +00001995</div>
1996<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +00001997<p>A symbol table plane provides the symbol table entries for all
1998values of a common type. The encoding is given in the following table:</p>
Reid Spencer51f31e02004-07-05 22:28:02 +00001999<table>
Reid Spencer9bd2be22004-07-29 00:13:04 +00002000 <tbody>
2001 <tr>
2002 <th><b>Type</b></th>
2003 <th class="td_left"><b>Field Description</b></th>
2004 </tr>
2005 <tr>
2006 <td><a href="#uint32_vbr">uint32_vbr</a></td>
2007 <td class="td_left">Number of entries in this plane.</td>
2008 </tr>
2009 <tr>
2010 <td><a href="#uint32_vbr">uint32_vbr</a></td>
Reid Spencer09daa632004-08-18 20:06:19 +00002011 <td class="td_left">Type slot number of type for all values in this plane..</td>
Reid Spencer9bd2be22004-07-29 00:13:04 +00002012 </tr>
2013 <tr>
Reid Spencer09daa632004-08-18 20:06:19 +00002014 <td><a href="#value_entry">value_entry</a>+</td>
2015 <td class="td_left">The symbol table entries for to associate values with
2016 names.</td>
Reid Spencer9bd2be22004-07-29 00:13:04 +00002017 </tr>
2018 </tbody>
Reid Spencer51f31e02004-07-05 22:28:02 +00002019</table>
2020</div>
Reid Spencer51f31e02004-07-05 22:28:02 +00002021<!-- _______________________________________________________________________ -->
Reid Spencer09daa632004-08-18 20:06:19 +00002022<div class="doc_subsubsection"><a name="value_entry">Symbol Table Value
Reid Spencer9bd2be22004-07-29 00:13:04 +00002023Entry</a>
Reid Spencer51f31e02004-07-05 22:28:02 +00002024</div>
2025<div class="doc_text">
Reid Spencer09daa632004-08-18 20:06:19 +00002026<p>A symbol table value entry provides the assocation between a value and the
2027name given to the value. The value is referenced by its slot number. The
Reid Spencer9bd2be22004-07-29 00:13:04 +00002028format is given in the following table:</p>
Reid Spencer51f31e02004-07-05 22:28:02 +00002029<table>
Reid Spencer9bd2be22004-07-29 00:13:04 +00002030 <tbody>
2031 <tr>
2032 <th><b>Type</b></th>
2033 <th class="td_left"><b>Field Description</b></th>
2034 </tr>
2035 <tr>
2036 <td><a href="#uint32_vbr">uint24_vbr</a></td>
Reid Spencer09daa632004-08-18 20:06:19 +00002037 <td class="td_left">Value slot number of the value being given a name.
Reid Spencer8996e552004-08-17 00:49:03 +00002038 </td>
Reid Spencer9bd2be22004-07-29 00:13:04 +00002039 </tr>
2040 <tr>
2041 <td><a href="#uint32_vbr">uint32_vbr</a></td>
2042 <td class="td_left">Length of the character array that follows.</td>
2043 </tr>
2044 <tr>
2045 <td><a href="#char">char</a>+</td>
2046 <td class="td_left">The characters of the name.</td>
2047 </tr>
2048 </tbody>
Reid Spencer51f31e02004-07-05 22:28:02 +00002049</table>
2050</div>
Reid Spencer09daa632004-08-18 20:06:19 +00002051
Reid Spencer7c76d332004-06-08 07:41:41 +00002052<!-- *********************************************************************** -->
Reid Spencer9bd2be22004-07-29 00:13:04 +00002053<div class="doc_section"> <a name="versiondiffs">Version Differences</a>
2054</div>
Reid Spencer7c76d332004-06-08 07:41:41 +00002055<!-- *********************************************************************** -->
2056<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +00002057<p>This section describes the differences in the Bytecode Format across
2058LLVM
2059versions. The versions are listed in reverse order because it assumes
2060the current version is as documented in the previous sections. Each
2061section here
Chris Lattner1cc070c2004-07-05 18:05:48 +00002062describes the differences between that version and the one that <i>follows</i>.
Reid Spencer7c76d332004-06-08 07:41:41 +00002063</p>
2064</div>
Chris Lattnera1dad812004-10-16 18:03:55 +00002065
Reid Spencer7c76d332004-06-08 07:41:41 +00002066<!-- _______________________________________________________________________ -->
Reid Spencer43dfdb72004-08-18 20:17:05 +00002067<div class="doc_subsection"><a name="vers13">Version 1.3 Differences From
Chris Lattnera1dad812004-10-16 18:03:55 +00002068 1.4</a></div>
Reid Spencercf549e12004-08-17 07:43:43 +00002069<!-- _______________________________________________________________________ -->
Chris Lattnera1dad812004-10-16 18:03:55 +00002070
2071<div class="doc_subsubsection">Unreachable Instruction</div>
2072<div class="doc_text">
2073 <p>The LLVM <a href="LangRef.html#i_unreachable">Unreachable</a> instruction
2074 was added in version 1.4 of LLVM. This caused all instruction numbers after
2075 it to shift down by one.</p>
2076</div>
2077
2078<div class="doc_subsubsection">Function Flags</div>
2079<div class="doc_text">
2080 <p>LLVM bytecode versions prior to 1.4 did not include the 5 bit offset
2081 in <a href="#funcfield">the function list</a> in the <a
2082 href="#globalinfo">Module Global Info</a> block.</p>
2083</div>
2084
2085<div class="doc_subsubsection">Function Flags</div>
2086<div class="doc_text">
2087 <p>LLVM bytecode versions prior to 1.4 did not include the 'undef' constant
2088 value, which affects the encoding of <a href="#constant">Constant
2089 Fields</a>.</p>
2090</div>
2091
Chris Lattner1dfc8e52004-10-16 00:29:30 +00002092<!--
Reid Spencercf549e12004-08-17 07:43:43 +00002093<div class="doc_subsubsection">Aligned Data</div>
2094<div class="doc_text">
2095 <p>In version 1.3, certain data items were aligned to 32-bit boundaries. In
2096 version 1.4, alignment of data was done away with completely. The need for
2097 alignment has gone away and the only thing it adds is bytecode file size
2098 overhead. In most cases this overhead was small. However, in functions with
2099 large numbers of format 0 instructions (GEPs and PHIs with lots of parameters)
2100 or regular instructions with large valued operands (e.g. because there's just
2101 a lot of instructions in the function) the overhead can be extreme. In one
2102 test case, the overhead was 44,000 bytes (34% of the total file size).
2103 Consequently in release 1.4, the decision was made to eliminate alignment
2104 altogether.</p>
2105 <p>In version 1.3 format, the following bytecode constructs were aligned (i.e.
2106 they were followed by one to three bytes of padding):</p>
2107 <ul>
2108 <li>All blocks.</li>
2109 <li>Instructions using the long format (format 0).</li>
2110 <li>All call instructions that called a var args function.</li>
2111 <li>The target triple (a string field at the end of the module block).</li>
2112 <li>The version field (immediately following the signature).</li>
2113 </ul>
2114 <p>None of these constructs are aligned in version 1.4</p>
2115</div>
Chris Lattner1dfc8e52004-10-16 00:29:30 +00002116-->
Chris Lattnera1dad812004-10-16 18:03:55 +00002117
Reid Spencercf549e12004-08-17 07:43:43 +00002118<!-- _______________________________________________________________________ -->
Reid Spencer9bd2be22004-07-29 00:13:04 +00002119<div class="doc_subsection"><a name="vers12">Version 1.2 Differences
2120From 1.3</a></div>
Reid Spencer1ab929c2004-07-05 08:18:07 +00002121<!-- _______________________________________________________________________ -->
Chris Lattnera1dad812004-10-16 18:03:55 +00002122
Reid Spencer1ab929c2004-07-05 08:18:07 +00002123<div class="doc_subsubsection">Type Derives From Value</div>
Reid Spencer7c76d332004-06-08 07:41:41 +00002124<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +00002125<p>In version 1.2, the Type class in the LLVM IR derives from the Value
2126class. This is not the case in version 1.3. Consequently, in version
21271.2 the notion of a "Type Type" was used to write out values that were
2128Types. The types always occuped plane 12 (corresponding to the
2129TypeTyID) of any type planed set of values. In 1.3 this representation
2130is not convenient because the TypeTyID (12) is not present and its
2131value is now used for LabelTyID. Consequently, the data structures
2132written that involve types do so by writing all the types first and
2133then each of the value planes according to those types. In version 1.2,
2134the types would have been written intermingled with the values.</p>
Reid Spencer1ab929c2004-07-05 08:18:07 +00002135</div>
Reid Spencer1ab929c2004-07-05 08:18:07 +00002136<!-- _______________________________________________________________________ -->
Reid Spencer9bd2be22004-07-29 00:13:04 +00002137<div class="doc_subsubsection">Restricted getelementptr Types</div>
Reid Spencer1ab929c2004-07-05 08:18:07 +00002138<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +00002139<p>In version 1.2, the getelementptr instruction required a ubyte type
2140index for accessing a structure field and a long type index for
2141accessing an array element. Consequently, it was only possible to
2142access structures of 255 or fewer elements. Starting in version 1.3,
2143this restriction was lifted. Structures must now be indexed with uint
2144constants. Arrays may now be indexed with int, uint, long, or ulong
2145typed values. The consequence of this was that the bytecode format had
2146to change in order to accommodate the larger range of structure indices.</p>
Reid Spencer7c76d332004-06-08 07:41:41 +00002147</div>
Reid Spencer7c76d332004-06-08 07:41:41 +00002148<!-- _______________________________________________________________________ -->
Reid Spencer9bd2be22004-07-29 00:13:04 +00002149<div class="doc_subsubsection">Short Block Headers</div>
2150<div class="doc_text">
2151<p>In version 1.2, block headers were always 8 bytes being comprised of
2152both an unsigned integer type and an unsigned integer size. For very
2153small modules, these block headers turn out to be a large fraction of
2154the total bytecode file size. In an attempt to make these small files
2155smaller, the type and size information was encoded into a single
2156unsigned integer (4 bytes) comprised of 5 bits for the block type
2157(maximum 31 block types) and 27 bits for the block size (max
2158~134MBytes). These limits seemed sufficient for any blocks or sizes
2159forseen in the future. Note that the module block, which encloses all
2160the other blocks is still written as 8 bytes since bytecode files
2161larger than 134MBytes might be possible.</p>
2162</div>
2163<!-- _______________________________________________________________________ -->
2164<div class="doc_subsubsection">Dependent Libraries and Target Triples</div>
2165<div class="doc_text">
2166<p>In version 1.2, the bytecode format does not store module's target
2167triple or dependent. These fields have been added to the end of the <a
2168 href="#globalinfo">module global info block</a>. The purpose of these
2169fields is to allow a front end compiler to specifiy that the generated
2170module is specific to a particular target triple (operating
2171system/manufacturer/processor) which makes it non-portable; and to
2172allow front end compilers to specify the list of libraries that the
2173module depends on for successful linking.</p>
2174</div>
2175<!-- _______________________________________________________________________ -->
2176<div class="doc_subsubsection">Types Restricted to 24-bits</div>
2177<div class="doc_text">
2178<p>In version 1.2, type slot identifiers were written as 32-bit VBR
2179quantities. In 1.3 this has been reduced to 24-bits in order to ensure
2180that it is not possible to overflow the type field of a global variable
2181definition. 24-bits for type slot numbers is deemed sufficient for any
2182practical use of LLVM.</p>
2183</div>
2184<!-- _______________________________________________________________________ -->
2185<!-- _______________________________________________________________________ -->
2186<div class="doc_subsection"><a name="vers11">Version 1.1 Differences
2187From 1.2 </a></div>
Reid Spencer1ab929c2004-07-05 08:18:07 +00002188<!-- _______________________________________________________________________ -->
2189<div class="doc_subsubsection">Explicit Primitive Zeros</div>
Reid Spencer7c76d332004-06-08 07:41:41 +00002190<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +00002191<p>In version 1.1, the zero value for primitives was explicitly encoded
2192into the bytecode format. Since these zero values are constant values
2193in the LLVM IR and never change, there is no reason to explicitly
2194encode them. This explicit encoding was removed in version 1.2.</p>
Reid Spencer1ab929c2004-07-05 08:18:07 +00002195</div>
Reid Spencer1ab929c2004-07-05 08:18:07 +00002196<!-- _______________________________________________________________________ -->
2197<div class="doc_subsubsection">Inconsistent Module Global Info</div>
2198<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +00002199<p>In version 1.1, the Module Global Info block was not aligned causing
2200the next block to be read in on an unaligned boundary. This problem was
2201corrected in version 1.2.<br>
2202<br>
2203</p>
Reid Spencer7c76d332004-06-08 07:41:41 +00002204</div>
Reid Spencer7c76d332004-06-08 07:41:41 +00002205<!-- _______________________________________________________________________ -->
Reid Spencer9bd2be22004-07-29 00:13:04 +00002206<div class="doc_subsection"><a name="vers10">Version 1.0 Differences
2207From 1.1</a></div>
Reid Spencer7c76d332004-06-08 07:41:41 +00002208<div class="doc_text">
Reid Spencer1ab929c2004-07-05 08:18:07 +00002209<p>None. Version 1.0 and 1.1 bytecode formats are identical.</p>
Reid Spencer7c76d332004-06-08 07:41:41 +00002210</div>
Reid Spencer50026612004-05-22 02:28:36 +00002211<!-- *********************************************************************** -->
2212<hr>
Reid Spencer9bd2be22004-07-29 00:13:04 +00002213<address> <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
2214 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
2215<a href="http://validator.w3.org/check/referer"><img
2216 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!"></a>
2217<a href="mailto:rspencer@x10sys.com">Reid Spencer</a> and <a
2218 href="mailto:sabre@nondot.org">Chris Lattner</a><br>
Reid Spencer05fe4b02006-03-14 05:39:39 +00002219<a href="http://llvm.org">The LLVM Compiler Infrastructure</a><br>
Reid Spencer9bd2be22004-07-29 00:13:04 +00002220Last modified: $Date$
Reid Spencer50026612004-05-22 02:28:36 +00002221</address>
Reid Spencer9bd2be22004-07-29 00:13:04 +00002222</body>
2223</html>