blob: 76365b4ea0df941a916f0291401aa9d14719df73 [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>
4 <title>LLVM Bytecode File Format</title>
5 <link rel="stylesheet" href="llvm.css" type="text/css">
Reid Spencer1ab929c2004-07-05 08:18:07 +00006 <style type="text/css">
Reid Spencer2de29992004-08-03 20:21:05 +00007 TR, TD { border: 2px solid gray; padding-left: 4pt; padding-right: 4pt;
8 padding-top: 2pt; padding-bottom: 2pt; }
Reid Spencer1ab929c2004-07-05 08:18:07 +00009 TH { border: 2px solid gray; font-weight: bold; font-size: 105%; }
Reid Spencer2cc36152004-07-05 19:04:27 +000010 TABLE { text-align: center; border: 2px solid black;
Reid Spencer2de29992004-08-03 20:21:05 +000011 border-collapse: collapse; margin-top: 1em; margin-left: 1em;
12 margin-right: 1em; margin-bottom: 1em; }
Reid Spencer2cc36152004-07-05 19:04:27 +000013 .td_left { border: 2px solid gray; text-align: left; }
Reid Spencer50026612004-05-22 02:28:36 +000014 </style>
15</head>
16<body>
Reid Spencer9bd2be22004-07-29 00:13:04 +000017<div class="doc_title"> LLVM Bytecode File Format </div>
Reid Spencer50026612004-05-22 02:28:36 +000018<ol>
19 <li><a href="#abstract">Abstract</a></li>
Reid Spencer1ab929c2004-07-05 08:18:07 +000020 <li><a href="#concepts">Concepts</a>
Reid Spencer50026612004-05-22 02:28:36 +000021 <ol>
22 <li><a href="#blocks">Blocks</a></li>
23 <li><a href="#lists">Lists</a></li>
24 <li><a href="#fields">Fields</a></li>
25 <li><a href="#align">Alignment</a></li>
Reid Spencer82c46712004-07-07 13:34:26 +000026 <li><a href="#vbr">Variable Bit-Rate Encoding</a></li>
Reid Spencer1ab929c2004-07-05 08:18:07 +000027 <li><a href="#encoding">Encoding Primitives</a></li>
28 <li><a href="#slots">Slots</a></li>
29 </ol>
30 </li>
Reid Spencer51f31e02004-07-05 22:28:02 +000031 <li><a href="#general">General Structure</a> </li>
32 <li><a href="#blockdefs">Block Definitions</a>
Reid Spencer1ab929c2004-07-05 08:18:07 +000033 <ol>
Reid Spencerb39021b2004-05-23 17:05:09 +000034 <li><a href="#signature">Signature Block</a></li>
35 <li><a href="#module">Module Block</a></li>
Reid Spencer1ab929c2004-07-05 08:18:07 +000036 <li><a href="#globaltypes">Global Type Pool</a></li>
37 <li><a href="#globalinfo">Module Info Block</a></li>
38 <li><a href="#constantpool">Global Constant Pool</a></li>
39 <li><a href="#functiondefs">Function Definition</a></li>
40 <li><a href="#compactiontable">Compaction Table</a></li>
41 <li><a href="#instructionlist">Instruction List</a></li>
42 <li><a href="#symtab">Symbol Table</a></li>
Reid Spencer50026612004-05-22 02:28:36 +000043 </ol>
44 </li>
Reid Spencer7c76d332004-06-08 07:41:41 +000045 <li><a href="#versiondiffs">Version Differences</a>
46 <ol>
47 <li><a href="#vers12">Version 1.2 Differences From 1.3</a></li>
48 <li><a href="#vers11">Version 1.1 Differences From 1.2</a></li>
49 <li><a href="#vers10">Version 1.0 Differences From 1.1</a></li>
50 </ol>
51 </li>
Reid Spencer50026612004-05-22 02:28:36 +000052</ol>
Chris Lattner8dabb502004-05-25 17:44:58 +000053<div class="doc_author">
54<p>Written by <a href="mailto:rspencer@x10sys.com">Reid Spencer</a>
55</p>
Reid Spencer50026612004-05-22 02:28:36 +000056</div>
57<!-- *********************************************************************** -->
58<div class="doc_section"> <a name="abstract">Abstract </a></div>
59<!-- *********************************************************************** -->
60<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +000061<p>This document describes the LLVM bytecode file format. It specifies
62the binary encoding rules of the bytecode file format so that
63equivalent systems can encode bytecode files correctly. The LLVM
64bytecode representation is used to store the intermediate
65representation on disk in compacted form.</p>
66<p>The LLVM bytecode format may change in the future, but LLVM will
67always be backwards compatible with older formats. This document will
68only describe the most current version of the bytecode format. See <a
69 href="#versiondiffs">Version Differences</a> for the details on how
70the current version is different from previous versions.</p>
Reid Spencer50026612004-05-22 02:28:36 +000071</div>
72<!-- *********************************************************************** -->
Reid Spencer1ab929c2004-07-05 08:18:07 +000073<div class="doc_section"> <a name="concepts">Concepts</a> </div>
Reid Spencer50026612004-05-22 02:28:36 +000074<!-- *********************************************************************** -->
75<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +000076<p>This section describes the general concepts of the bytecode file
77format without getting into specific layout details. It is recommended
78that you read this section thoroughly before interpreting the detailed
79descriptions.</p>
Reid Spencer50026612004-05-22 02:28:36 +000080</div>
81<!-- _______________________________________________________________________ -->
82<div class="doc_subsection"><a name="blocks">Blocks</a> </div>
83<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +000084<p>LLVM bytecode files consist simply of a sequence of blocks of bytes
85using a binary encoding Each block begins with an header of two
86unsigned integers. The first value identifies the type of block and the
87second value provides the size of the block in bytes. The block
88identifier is used because it is possible for entire blocks to be
89omitted from the file if they are empty. The block identifier helps the
90reader determine which kind of block is next in the file. Note that
91blocks can be nested within other blocks.</p>
92<p> All blocks are variable length, and the block header specifies the
93size of the block. All blocks begin on a byte index that is aligned to
94an even 32-bit boundary. That is, the first block is 32-bit aligned
95because it starts at offset 0. Each block is padded with zero fill
96bytes to ensure that the next block also starts on a 32-bit boundary.</p>
Reid Spencer50026612004-05-22 02:28:36 +000097</div>
98<!-- _______________________________________________________________________ -->
99<div class="doc_subsection"><a name="lists">Lists</a> </div>
100<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +0000101<p>LLVM Bytecode blocks often contain lists of things of a similar
102type. For example, a function contains a list of instructions and a
103function type contains a list of argument types. There are two basic
104types of lists: length lists (<a href="#llist">llist</a>), and null
105terminated lists (<a href="#zlist">zlist</a>), as described below in
106the <a href="#encoding">Encoding Primitives</a>.</p>
Reid Spencer50026612004-05-22 02:28:36 +0000107</div>
108<!-- _______________________________________________________________________ -->
109<div class="doc_subsection"><a name="fields">Fields</a> </div>
110<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +0000111<p>Fields are units of information that LLVM knows how to write atomically. Most
112fields have a uniform length or some kind of length indication built into their
113encoding. For example, a constant string (array of bytes) is written simply as
114the length followed by the characters. Although this is similar to a list,
115constant strings are treated atomically and are thus fields.</p>
Reid Spencer50026612004-05-22 02:28:36 +0000116<p>Fields use a condensed bit format specific to the type of information
117they must contain. As few bits as possible are written for each field. The
Reid Spencer9bd2be22004-07-29 00:13:04 +0000118sections that follow will provide the details on how these fields are
Reid Spencer50026612004-05-22 02:28:36 +0000119written and how the bits are to be interpreted.</p>
120</div>
121<!-- _______________________________________________________________________ -->
Reid Spencer1ab929c2004-07-05 08:18:07 +0000122<div class="doc_subsection"><a name="align">Alignment</a> </div>
Reid Spencer7aa940d2004-05-25 15:47:57 +0000123<div class="doc_text">
Reid Spencer267660f2004-08-03 20:33:56 +0000124 <p>To support cross-platform differences, the bytecode file is aligned on
125 certain boundaries. This means that a small amount of padding (at most 3
126 bytes) will be added to ensure that the next entry is aligned to a 32-bit
127 boundary.</p>
Chris Lattner8dabb502004-05-25 17:44:58 +0000128</div>
Reid Spencer7aa940d2004-05-25 15:47:57 +0000129<!-- _______________________________________________________________________ -->
Reid Spencer9bd2be22004-07-29 00:13:04 +0000130<div class="doc_subsection"><a name="vbr">Variable Bit-Rate Encoding</a>
Reid Spencer82c46712004-07-07 13:34:26 +0000131</div>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000132<div class="doc_text">
133<p>Most of the values written to LLVM bytecode files are small integers. To
134minimize the number of bytes written for these quantities, an encoding scheme
135similar to UTF-8 is used to write integer data. The scheme is known as
136variable bit rate (vbr) encoding. In this encoding, the high bit of
137each byte is used to indicate if more bytes follow. If (byte &amp;
1380x80) is non-zero in any given byte, it means there is another byte
139immediately following that also contributes to the value. For the final
140byte (byte &amp; 0x80) is false (the high bit is not set). In each byte
141only the low seven bits contribute to the value. Consequently 32-bit
142quantities can take from one to <em>five</em> bytes to encode. In
143general, smaller quantities will encode in fewer bytes, as follows:</p>
144<table>
145 <tbody>
146 <tr>
147 <th>Byte #</th>
148 <th>Significant Bits</th>
149 <th>Maximum Value</th>
150 </tr>
151 <tr>
152 <td>1</td>
153 <td>0-6</td>
154 <td>127</td>
155 </tr>
156 <tr>
157 <td>2</td>
158 <td>7-13</td>
159 <td>16,383</td>
160 </tr>
161 <tr>
162 <td>3</td>
163 <td>14-20</td>
164 <td>2,097,151</td>
165 </tr>
166 <tr>
167 <td>4</td>
168 <td>21-27</td>
169 <td>268,435,455</td>
170 </tr>
171 <tr>
172 <td>5</td>
173 <td>28-34</td>
174 <td>34,359,738,367</td>
175 </tr>
176 <tr>
177 <td>6</td>
178 <td>35-41</td>
179 <td>4,398,046,511,103</td>
180 </tr>
181 <tr>
182 <td>7</td>
183 <td>42-48</td>
184 <td>562,949,953,421,311</td>
185 </tr>
186 <tr>
187 <td>8</td>
188 <td>49-55</td>
189 <td>72,057,594,037,927,935</td>
190 </tr>
191 <tr>
192 <td>9</td>
193 <td>56-62</td>
194 <td>9,223,372,036,854,775,807</td>
195 </tr>
196 <tr>
197 <td>10</td>
198 <td>63-69</td>
199 <td>1,180,591,620,717,411,303,423</td>
200 </tr>
201 </tbody>
202</table>
203<p>Note that in practice, the tenth byte could only encode bit 63 since
204the maximum quantity to use this encoding is a 64-bit integer.</p>
205<p><em>Signed</em> VBR values are encoded with the standard vbr
206encoding, but with the sign bit as the low order bit instead of the
207high order bit. This allows small negative quantities to be encoded
208efficiently. For example, -3
209is encoded as "((3 &lt;&lt; 1) | 1)" and 3 is encoded as "(3 &lt;&lt;
2101) | 0)", emitted with the standard vbr encoding above.</p>
211</div>
Reid Spencer82c46712004-07-07 13:34:26 +0000212<!-- _______________________________________________________________________ -->
213<div class="doc_subsection"><a name="encoding">Encoding Primitives</a> </div>
214<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +0000215<p>Each field in the bytecode format is encoded into the file using a
216small set of primitive formats. The table below defines the encoding
217rules for the various primitives used and gives them each a type name.
218The type names used in the descriptions of blocks and fields in the <a
219 href="#details">Detailed Layout</a>next section. Any type name with
220the suffix <em>_vbr</em> indicates a quantity that is encoded using
221variable bit rate encoding as described above.</p>
222<table class="doc_table">
223 <tbody>
224 <tr>
225 <th><b>Type</b></th>
226 <th class="td_left"><b>Rule</b></th>
227 </tr>
228 <tr>
229 <td><a name="unsigned"><b>unsigned</b></a></td>
230 <td class="td_left">A 32-bit unsigned integer that always occupies four
Reid Spencerb39021b2004-05-23 17:05:09 +0000231 consecutive bytes. The unsigned integer is encoded using LSB first
232 ordering. That is bits 2<sup>0</sup> through 2<sup>7</sup> are in the
233 byte with the lowest file offset (little endian).</td>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000234 </tr>
235 <tr>
Reid Spencer301fe482004-08-03 20:57:56 +0000236 <td style="vertical-align: top;"><a name="uint24_vbr">
237 <b>uint24_vbr</b></a></td>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000238 <td style="vertical-align: top; text-align: left;">A 24-bit unsigned
239 integer that occupies from one to four bytes using variable bit rate
240 encoding.</td>
241 </tr>
242 <tr>
243 <td><a name="uint32_vbr"><b>uint32_vbr</b></a></td>
Reid Spencerf08561f2004-08-03 19:20:18 +0000244 <td class="td_left">A 32-bit unsigned integer that occupies from one to
245 five bytes using variable bit rate encoding.</td>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000246 </tr>
247 <tr>
248 <td><a name="uint64_vbr"><b>uint64_vbr</b></a></td>
Reid Spencerf08561f2004-08-03 19:20:18 +0000249 <td class="td_left">A 64-bit unsigned integer that occupies from one to ten
250 bytes using variable bit rate encoding.</td>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000251 </tr>
252 <tr>
253 <td><a name="int64_vbr"><b>int64_vbr</b></a></td>
Reid Spencerf08561f2004-08-03 19:20:18 +0000254 <td class="td_left">A 64-bit signed integer that occupies from one to ten
255 bytes using the signed variable bit rate encoding.</td>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000256 </tr>
257 <tr>
258 <td><a name="char"><b>char</b></a></td>
Reid Spencerf08561f2004-08-03 19:20:18 +0000259 <td class="td_left">A single unsigned character encoded into one byte</td>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000260 </tr>
261 <tr>
262 <td><a name="bit"><b>bit(n-m)</b></a></td>
Reid Spencerf08561f2004-08-03 19:20:18 +0000263 <td class="td_left">A set of bit within some larger integer field. The values
264 of <code>n</code> and <code>m</code> specify the inclusive range of bits
265 that define the subfield. The value for <code>m</code> may be omitted if
266 its the same as <code>n</code>.</td>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000267 </tr>
268 <tr>
269 <td style="vertical-align: top;"><b><a name="float"><b>float</b></a></b></td>
Reid Spencerf08561f2004-08-03 19:20:18 +0000270 <td style="vertical-align: top; text-align: left;">A floating point value encoded
271 as a 32-bit IEEE value written in little-endian form.<br>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000272 </td>
273 </tr>
274 <tr>
275 <td style="vertical-align: top;"><b><b><a name="double"><b>double</b></a></b></b></td>
Reid Spencerf08561f2004-08-03 19:20:18 +0000276 <td style="vertical-align: top; text-align: left;">A floating point value encoded
277 as a64-bit IEEE value written in little-endian form</td>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000278 </tr>
279 <tr>
280 <td><a name="string"><b>string</b></a></td>
281 <td class="td_left">A uint32_vbr indicating the type of the
282constant string which also includes its length, immediately followed by
283the characters of the string. There is no terminating null byte in the
284string.</td>
285 </tr>
286 <tr>
287 <td><a name="data"><b>data</b></a></td>
288 <td class="td_left">An arbitrarily long segment of data to which
289no interpretation is implied. This is used for constant initializers.<br>
290 </td>
291 </tr>
292 <tr>
293 <td><a name="llist"><b>llist(x)</b></a></td>
294 <td class="td_left">A length list of x. This means the list is
295encoded as an <a href="#uint32_vbr">uint32_vbr</a> providing the
296length of the list, followed by a sequence of that many "x" items. This
297implies that the reader should iterate the number of times provided by
298the length.</td>
299 </tr>
300 <tr>
301 <td><a name="zlist"><b>zlist(x)</b></a></td>
302 <td class="td_left">A zero-terminated list of x. This means the
303list is encoded as a sequence of an indeterminate number of "x" items,
304followed by an <a href="#uint32_vbr">uint32_vbr</a> terminating value.
305This implies that none of the "x" items can have a zero value (or else
306the list terminates).</td>
307 </tr>
308 <tr>
309 <td><a name="block"><b>block</b></a></td>
310 <td class="td_left">A block of data that is logically related. A
311block is an unsigned 32-bit integer that encodes the type of the block
312in the low 5 bits and the size of the block in the high 27 bits. The
313length does not include the block header or any alignment bytes at the
314end of the block. Blocks may compose other blocks. </td>
315 </tr>
316 </tbody>
Reid Spencerb39021b2004-05-23 17:05:09 +0000317</table>
318</div>
319<!-- _______________________________________________________________________ -->
Reid Spencer82c46712004-07-07 13:34:26 +0000320<div class="doc_subsection"><a name="notation">Field Notation</a> </div>
321<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +0000322<p>In the detailed block and field descriptions that follow, a regex
323like notation is used to describe optional and repeated fields. A very
324limited subset of regex is used to describe these, as given in the
325following table: </p>
326<table class="doc_table">
327 <tbody>
Reid Spencer82c46712004-07-07 13:34:26 +0000328 <tr>
329 <th><b>Character</b></th>
330 <th class="td_left"><b>Meaning</b></th>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000331 </tr>
332 <tr>
Reid Spencer82c46712004-07-07 13:34:26 +0000333 <td><b><code>?</code></b></td>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000334 <td class="td_left">The question mark indicates 0 or 1
335occurrences of the thing preceding it.</td>
336 </tr>
337 <tr>
Reid Spencer82c46712004-07-07 13:34:26 +0000338 <td><b><code>*</code></b></td>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000339 <td class="td_left">The asterisk indicates 0 or more occurrences
340of the thing preceding it.</td>
341 </tr>
342 <tr>
Reid Spencer82c46712004-07-07 13:34:26 +0000343 <td><b><code>+</code></b></td>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000344 <td class="td_left">The plus sign indicates 1 or more occurrences
345of the thing preceding it.</td>
346 </tr>
347 <tr>
Reid Spencer82c46712004-07-07 13:34:26 +0000348 <td><b><code>()</code></b></td>
349 <td class="td_left">Parentheses are used for grouping.</td>
Reid Spencer82c46712004-07-07 13:34:26 +0000350 </tr>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000351 <tr>
352 <td><b><code>,</code></b></td>
353 <td class="td_left">The comma separates sequential fields.</td>
354 </tr>
355 </tbody>
356</table>
357<p>So, for example, consider the following specifications:</p>
358<div class="doc_code">
359<ol>
360 <li><code>string?</code></li>
361 <li><code>(uint32_vbr,uin32_vbr)+</code></li>
362 <li><code>(unsigned?,uint32_vbr)*</code></li>
363 <li><code>(llist(unsigned))?</code></li>
364</ol>
Reid Spencer82c46712004-07-07 13:34:26 +0000365</div>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000366<p>with the following interpretations:</p>
367<ol>
368 <li>An optional string. Matches either nothing or a single string</li>
369 <li>One or more pairs of uint32_vbr.</li>
370 <li>Zero or more occurrences of either an unsigned followed by a
371uint32_vbr or just a uint32_vbr.</li>
372 <li>An optional length list of unsigned values.</li>
373</ol>
374</div>
Reid Spencer82c46712004-07-07 13:34:26 +0000375<!-- _______________________________________________________________________ -->
Reid Spencer1ab929c2004-07-05 08:18:07 +0000376<div class="doc_subsection"><a name="slots">Slots</a> </div>
Reid Spencer50026612004-05-22 02:28:36 +0000377<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +0000378<p>The bytecode format uses the notion of a "slot" to reference Types
379and Values. Since the bytecode file is a <em>direct</em> representation of
380LLVM's intermediate representation, there is a need to represent pointers in
381the file. Slots are used for this purpose. For example, if one has the following
382assembly:
Reid Spencer1ab929c2004-07-05 08:18:07 +0000383</p>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000384<div class="doc_code"><code> %MyType = type { int, sbyte }<br>
385%MyVar = external global %MyType
Reid Spencer82c46712004-07-07 13:34:26 +0000386</code></div>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000387<p>there are two definitions. The definition of <tt>%MyVar</tt> uses <tt>%MyType</tt>.
388In the C++ IR this linkage between <tt>%MyVar</tt> and <tt>%MyType</tt>
389is explicit through the use of C++ pointers. In bytecode, however, there's no
390ability to store memory addresses. Instead, we compute and write out
391slot numbers for every Type and Value written to the file.</p>
Reid Spencer1ab929c2004-07-05 08:18:07 +0000392<p>A slot number is simply an unsigned 32-bit integer encoded in the variable
393bit rate scheme (see <a href="#encoding">encoding</a>). This ensures that
394low slot numbers are encoded in one byte. Through various bits of magic LLVM
395attempts to always keep the slot numbers low. The first attempt is to associate
Reid Spencer9bd2be22004-07-29 00:13:04 +0000396slot numbers with their "type plane". That is, Values of the same type
397are written to the bytecode file in a list (sequentially). Their order in
398that list determines their slot number. This means that slot #1 doesn't mean
399anything unless you also specify for which type you want slot #1. Types are
400handled specially and are always written to the file first (in the <a
401 href="#globaltypes">Global Type Pool</a>) and in such a way that both forward
402and backward references of the types can often be resolved with a single pass
403through the type pool. </p>
404<p>Slot numbers are also kept small by rearranging their order. Because
405of the structure of LLVM, certain values are much more likely to be used
406frequently in the body of a function. For this reason, a compaction table is
407provided in the body of a function if its use would make the function body
408smaller. Suppose you have a function body that uses just the types "int*" and
409"{double}" but uses them thousands of time. Its worthwhile to ensure that the
410slot number for these types are low so they can be encoded in a single byte
411(via vbr). This is exactly what the compaction table does.</p>
Reid Spencer1ab929c2004-07-05 08:18:07 +0000412</div>
Reid Spencer1ab929c2004-07-05 08:18:07 +0000413<!-- *********************************************************************** -->
Reid Spencer51f31e02004-07-05 22:28:02 +0000414<div class="doc_section"> <a name="general">General Structure</a> </div>
Reid Spencer1ab929c2004-07-05 08:18:07 +0000415<!-- *********************************************************************** -->
416<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +0000417<p>This section provides the general structure of the LLVM bytecode
418file format. The bytecode file format requires blocks to be in a
419certain order and nested in a particular way so that an LLVM module can
420be constructed efficiently from the contents of the file. This ordering
421defines a general structure for bytecode files as shown below. The
422table below shows the order in which all block types may appear. Please
423note that some of the blocks are optional and some may be repeated. The
424structure is fairly loose because optional blocks, if empty, are
425completely omitted from the file.</p>
Reid Spencer1ab929c2004-07-05 08:18:07 +0000426<table>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000427 <tbody>
428 <tr>
429 <th>ID</th>
430 <th>Parent</th>
431 <th>Optional?</th>
432 <th>Repeated?</th>
433 <th>Level</th>
434 <th>Block Type</th>
435 <th>Description</th>
436 </tr>
437 <tr>
438 <td>N/A</td>
439 <td>File</td>
440 <td>No</td>
441 <td>No</td>
442 <td>0</td>
443 <td class="td_left"><a href="#signature">Signature</a></td>
444 <td class="td_left">This contains the file signature (magic
445number) that identifies the file as LLVM bytecode.</td>
446 </tr>
447 <tr>
448 <td>0x01</td>
449 <td>File</td>
450 <td>No</td>
451 <td>No</td>
452 <td>0</td>
453 <td class="td_left"><a href="#module">Module</a></td>
454 <td class="td_left">This is the top level block in a bytecode
455file. It contains all the other blocks. </td>
456 </tr>
457 <tr>
458 <td>0x06</td>
459 <td>Module</td>
460 <td>No</td>
461 <td>No</td>
462 <td>1</td>
463 <td class="td_left">&nbsp;&nbsp;&nbsp;<a href="#globaltypes">Global&nbsp;Type&nbsp;Pool</a></td>
464 <td class="td_left">This block contains all the global (module)
465level types.</td>
466 </tr>
467 <tr>
468 <td>0x05</td>
469 <td>Module</td>
470 <td>No</td>
471 <td>No</td>
472 <td>1</td>
473 <td class="td_left">&nbsp;&nbsp;&nbsp;<a href="#globalinfo">Module&nbsp;Globals&nbsp;Info</a></td>
474 <td class="td_left">This block contains the type, constness, and
475linkage for each of the global variables in the module. It also
476contains the type of the functions and the constant initializers.</td>
477 </tr>
478 <tr>
479 <td>0x03</td>
480 <td>Module</td>
481 <td>Yes</td>
482 <td>No</td>
483 <td>1</td>
484 <td class="td_left">&nbsp;&nbsp;&nbsp;<a href="#constantpool">Module&nbsp;Constant&nbsp;Pool</a></td>
485 <td class="td_left">This block contains all the global constants
486except function arguments, global values and constant strings.</td>
487 </tr>
488 <tr>
489 <td>0x02</td>
490 <td>Module</td>
491 <td>Yes</td>
492 <td>Yes</td>
493 <td>1</td>
494 <td class="td_left">&nbsp;&nbsp;&nbsp;<a href="#functiondefs">Function&nbsp;Definitions</a>*</td>
495 <td class="td_left">One function block is written for each
496function in the module. The function block contains the instructions,
497compaction table, type constant pool, and symbol table for the function.</td>
498 </tr>
499 <tr>
500 <td>0x03</td>
501 <td>Function</td>
502 <td>Yes</td>
503 <td>No</td>
504 <td>2</td>
505 <td class="td_left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a
506 href="#constantpool">Function&nbsp;Constant&nbsp;Pool</a></td>
507 <td class="td_left">Any constants (including types) used solely
508within the function are emitted here in the function constant pool. </td>
509 </tr>
510 <tr>
511 <td>0x08</td>
512 <td>Function</td>
513 <td>Yes</td>
514 <td>No</td>
515 <td>2</td>
516 <td class="td_left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a
517 href="#compactiontable">Compaction&nbsp;Table</a></td>
518 <td class="td_left">This table reduces bytecode size by providing
519a funtion-local mapping of type and value slot numbers to their global
520slot numbers</td>
521 </tr>
522 <tr>
523 <td>0x07</td>
524 <td>Function</td>
525 <td>No</td>
526 <td>No</td>
527 <td>2</td>
528 <td class="td_left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a
529 href="#instructionlist">Instruction&nbsp;List</a></td>
530 <td class="td_left">This block contains all the instructions of
531the function. The basic blocks are inferred by terminating
532instructions. </td>
533 </tr>
534 <tr>
535 <td>0x04</td>
536 <td>Function</td>
537 <td>Yes</td>
538 <td>No</td>
539 <td>2</td>
540 <td class="td_left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a
541 href="#symtab">Function&nbsp;Symbol&nbsp;Table</a></td>
542 <td class="td_left">This symbol table provides the names for the
543function specific values used (basic block labels mostly).</td>
544 </tr>
545 <tr>
546 <td>0x04</td>
547 <td>Module</td>
548 <td>Yes</td>
549 <td>No</td>
550 <td>1</td>
551 <td class="td_left">&nbsp;&nbsp;&nbsp;<a href="#symtab">Module&nbsp;Symbol&nbsp;Table</a></td>
552 <td class="td_left">This symbol table provides the names for the
553various entries in the file that are not function specific (global
554vars, and functions mostly).</td>
555 </tr>
556 </tbody>
Reid Spencer1ab929c2004-07-05 08:18:07 +0000557</table>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000558<p>Use the links in the table for details about the contents of each of
559the block types.</p>
Reid Spencer1ab929c2004-07-05 08:18:07 +0000560</div>
Reid Spencer50026612004-05-22 02:28:36 +0000561<!-- *********************************************************************** -->
Reid Spencer51f31e02004-07-05 22:28:02 +0000562<div class="doc_section"> <a name="blockdefs">Block Definitions</a> </div>
Reid Spencer50026612004-05-22 02:28:36 +0000563<!-- *********************************************************************** -->
564<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +0000565<p>This section provides the detailed layout of the individual block
566types in the LLVM bytecode file format. </p>
Reid Spencer50026612004-05-22 02:28:36 +0000567</div>
Reid Spencer50026612004-05-22 02:28:36 +0000568<!-- _______________________________________________________________________ -->
Reid Spencerb39021b2004-05-23 17:05:09 +0000569<div class="doc_subsection"><a name="signature">Signature Block</a> </div>
Reid Spencer50026612004-05-22 02:28:36 +0000570<div class="doc_text">
Chris Lattner2b905652004-05-24 05:35:17 +0000571<p>The signature occurs in every LLVM bytecode file and is always first.
Reid Spencerb39021b2004-05-23 17:05:09 +0000572It simply provides a few bytes of data to identify the file as being an LLVM
573bytecode file. This block is always four bytes in length and differs from the
574other blocks because there is no identifier and no block length at the start
575of the block. Essentially, this block is just the "magic number" for the file.
Reid Spencer9bd2be22004-07-29 00:13:04 +0000576</p>
Reid Spencer2cc36152004-07-05 19:04:27 +0000577<table>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000578 <tbody>
579 <tr>
580 <th><b>Type</b></th>
581 <th class="td_left"><b>Field Description</b></th>
582 </tr>
583 <tr>
584 <td><a href="#char">char</a></td>
585 <td class="td_left">Constant "l" (0x6C)</td>
586 </tr>
587 <tr>
588 <td><a href="#char">char</a></td>
589 <td class="td_left">Constant "l" (0x6C)</td>
590 </tr>
591 <tr>
592 <td><a href="#char">char</a></td>
593 <td class="td_left">Constant "v" (0x76)</td>
594 </tr>
595 <tr>
596 <td><a href="#char">char</a></td>
597 <td class="td_left">Constant "m" (0x6D)</td>
598 </tr>
599 </tbody>
Reid Spencerb39021b2004-05-23 17:05:09 +0000600</table>
601</div>
602<!-- _______________________________________________________________________ -->
603<div class="doc_subsection"><a name="module">Module Block</a> </div>
604<div class="doc_text">
605<p>The module block contains a small pre-amble and all the other blocks in
Reid Spencer1ab929c2004-07-05 08:18:07 +0000606the file. The table below shows the structure of the module block. Note that it
607only provides the module identifier, size of the module block, and the format
608information. Everything else is contained in other blocks, described in other
609sections.</p>
Reid Spencer2cc36152004-07-05 19:04:27 +0000610<table>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000611 <tbody>
612 <tr>
613 <th><b>Type</b></th>
614 <th class="td_left"><b>Field Description</b></th>
615 </tr>
616 <tr>
Reid Spencer5bc74d52004-08-16 19:24:36 +0000617 <td><a href="#unsigned">unsigned</a><br></td>
618 <td class="td_left"><a href="#mod_header">Module Block Identifier
619 (0x01)</a></td>
620 </tr>
621 <tr>
622 <td><a href="#unsigned">unsigned</a></td>
623 <td class="td_left"><a href="#mod_header">Module Block Size</a></td>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000624 </tr>
625 <tr>
626 <td><a href="#uint32_vbr">uint32_vbr</a></td>
627 <td class="td_left"><a href="#format">Format Information</a></td>
628 </tr>
629 <tr>
630 <td><a href="#block">block</a></td>
631 <td class="td_left"><a href="#globaltypes">Global Type Pool</a></td>
632 </tr>
633 <tr>
634 <td><a href="#block">block</a></td>
635 <td class="td_left"><a href="#globalinfo">Module Globals Info</a></td>
636 </tr>
637 <tr>
638 <td><a href="#block">block</a></td>
639 <td class="td_left"><a href="#constantpool">Module Constant Pool</a></td>
640 </tr>
641 <tr>
642 <td><a href="#block">block</a>*</td>
643 <td class="td_left"><a href="#functiondefs">Function Definitions</a></td>
644 </tr>
645 <tr>
646 <td><a href="#block">block</a></td>
647 <td class="td_left"><a href="#symboltable">Module Symbol Table</a></td>
648 </tr>
649 </tbody>
Reid Spencer1ab929c2004-07-05 08:18:07 +0000650</table>
651</div>
Reid Spencer5bc74d52004-08-16 19:24:36 +0000652
653<!-- _______________________________________________________________________ -->
654<div class="doc_subsubsection"><a name="mod_header">Module Block Header</a></div>
655<div class="doc_text">
656 <p>The block header for the module block uses a longer format than the other
657 blocks in a bytecode file. Specifically, instead of encoding the type and size
658 of the block into a 32-bit integer with 5-bits for type and 27-bits for size,
659 the module block header uses two 32-bit unsigned values, one for type, and one
660 for size. While the 2<sup>27</sup> byte limit on block size is sufficient for the blocks
661 contained in the module, it isn't sufficient for the module block itself
662 because we want to ensure that bytecode files as large as 2<sup>32</sup> bytes
663 are possible. For this reason, the module block (and only the module block)
664 uses a long format header.</p>
665</div>
666
Reid Spencer1ab929c2004-07-05 08:18:07 +0000667<!-- _______________________________________________________________________ -->
668<div class="doc_subsubsection"><a name="format">Format Information</a></div>
669<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +0000670<p>The format information field is encoded into a <a href="#uint32_vbr">uint32_vbr</a>
671as shown in the following table.</p>
Reid Spencer1ab929c2004-07-05 08:18:07 +0000672<table>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000673 <tbody>
674 <tr>
675 <th><b>Type</b></th>
676 <th class="td_left"><b>Description</b></th>
677 </tr>
678 <tr>
679 <td><a href="#bit">bit(0)</a></td>
680 <td class="td_left">Target is big endian?</td>
681 </tr>
682 <tr>
683 <td><a href="#bit">bit(1)</a></td>
684 <td class="td_left">On target pointers are 64-bit?</td>
685 </tr>
686 <tr>
687 <td><a href="#bit">bit(2)</a></td>
688 <td class="td_left">Target has no endianess?</td>
689 </tr>
690 <tr>
691 <td><a href="#bit">bit(3)</a></td>
692 <td class="td_left">Target has no pointer size?</td>
693 </tr>
694 <tr>
695 <td><a href="#bit">bit(4-31)</a></td>
696 <td class="td_left">Bytecode format version</td>
697 </tr>
698 </tbody>
Reid Spencer1ab929c2004-07-05 08:18:07 +0000699</table>
700<p>
701Of particular note, the bytecode format number is simply a 28-bit
702monotonically increase integer that identifies the version of the bytecode
Reid Spencer9bd2be22004-07-29 00:13:04 +0000703format (which is not directly related to the LLVM release number). The
704bytecode versions defined so far are (note that this document only
705describes the latest version, 1.3):</p>
Chris Lattner2b905652004-05-24 05:35:17 +0000706<ul>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000707 <li>#0: LLVM 1.0 &amp; 1.1</li>
708 <li>#1: LLVM 1.2</li>
709 <li>#2: LLVM 1.2.5 (not released)</li>
710 <li>#3: LLVM 1.3<br>
711 </li>
Chris Lattner2b905652004-05-24 05:35:17 +0000712</ul>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000713<p>Note that we plan to eventually expand the target description
714capabilities
715of bytecode files to <a href="http://llvm.cs.uiuc.edu/PR263">target
716triples</a>.
Reid Spencer1ab929c2004-07-05 08:18:07 +0000717</p>
Reid Spencer50026612004-05-22 02:28:36 +0000718</div>
719<!-- _______________________________________________________________________ -->
Reid Spencer1ab929c2004-07-05 08:18:07 +0000720<div class="doc_subsection"><a name="globaltypes">Global Type Pool</a> </div>
Reid Spencer50026612004-05-22 02:28:36 +0000721<div class="doc_text">
Chris Lattner2b905652004-05-24 05:35:17 +0000722<p>The global type pool consists of type definitions. Their order of appearance
Reid Spencer9bd2be22004-07-29 00:13:04 +0000723in the file determines their slot number (0 based). Slot numbers are
724used to replace pointers in the intermediate representation. Each slot number
725uniquely identifies one entry in a type plane (a collection of values of the
726same type). Since all values have types and are associated with the order in
727which the type pool is written, the global type pool <em>must</em> be written
728as the first block of a module. If it is not, attempts to read the file will
729fail because both forward and backward type resolution will not be possible.</p>
730<p>The type pool is simply a list of type definitions, as shown in the
731table below.</p>
Reid Spencer2cc36152004-07-05 19:04:27 +0000732<table>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000733 <tbody>
734 <tr>
735 <th><b>Type</b></th>
736 <th class="td_left"><b>Field Description</b></th>
737 </tr>
738 <tr>
739 <td><a href="#unsigned">block</a></td>
740 <td class="td_left">Type Pool Identifier (0x06) + Size<br>
741 </td>
742 </tr>
743 <tr>
744 <td><a href="#llist">llist</a>(<a href="#type">type</a>)</td>
745 <td class="td_left">A length list of type definitions.</td>
746 </tr>
747 </tbody>
Reid Spencerb39021b2004-05-23 17:05:09 +0000748</table>
Reid Spencer50026612004-05-22 02:28:36 +0000749</div>
750<!-- _______________________________________________________________________ -->
Reid Spencer1ab929c2004-07-05 08:18:07 +0000751<div class="doc_subsubsection"><a name="type">Type Definitions</a></div>
752<div class="doc_text">
Reid Spencer82c46712004-07-07 13:34:26 +0000753<p>Types in the type pool are defined using a different format for each kind
754of type, as given in the following sections.</p>
Reid Spencer1ab929c2004-07-05 08:18:07 +0000755<h3>Primitive Types</h3>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000756<p>The primitive types encompass the basic integer and floating point
757types</p>
Reid Spencer1ab929c2004-07-05 08:18:07 +0000758<table>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000759 <tbody>
760 <tr>
761 <th><b>Type</b></th>
762 <th class="td_left"><b>Description</b></th>
763 </tr>
764 <tr>
765 <td><a href="#uint24_vbr">uint24_vbr</a></td>
766 <td class="td_left">Type ID for the primitive types (values 1 to
76711) <sup>1</sup></td>
768 </tr>
769 </tbody>
Reid Spencer1ab929c2004-07-05 08:18:07 +0000770</table>
Reid Spencer2cc36152004-07-05 19:04:27 +0000771Notes:
772<ol>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000773 <li>The values for the Type IDs for the primitive types are provided
774by the definition of the <code>llvm::Type::TypeID</code> enumeration
775in <code>include/llvm/Type.h</code>. The enumeration gives the
776following mapping:
777 <ol>
778 <li>bool</li>
779 <li>ubyte</li>
780 <li>sbyte</li>
781 <li>ushort</li>
782 <li>short</li>
783 <li>uint</li>
784 <li>int</li>
785 <li>ulong</li>
786 <li>long</li>
787 <li>float</li>
788 <li>double</li>
789 </ol>
790 </li>
Reid Spencer2cc36152004-07-05 19:04:27 +0000791</ol>
Reid Spencer1ab929c2004-07-05 08:18:07 +0000792<h3>Function Types</h3>
793<table>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000794 <tbody>
795 <tr>
796 <th><b>Type</b></th>
797 <th class="td_left"><b>Description</b></th>
798 </tr>
799 <tr>
800 <td><a href="#uint24_vbr">uint24_vbr</a></td>
801 <td class="td_left">Type ID for function types (13)</td>
802 </tr>
803 <tr>
804 <td><a href="#uint24_vbr">uint24_vbr</a></td>
805 <td class="td_left">Slot number of function's return type.</td>
806 </tr>
807 <tr>
808 <td><a href="#llist">llist</a>(<a href="#uint24_vbr">uint24_vbr</a>)</td>
Reid Spencer82c46712004-07-07 13:34:26 +0000809 <td class="td_left">Slot number of each argument's type.</td>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000810 </tr>
811 <tr>
812 <td><a href="#uint32_vbr">uint32_vbr</a>?</td>
813 <td class="td_left">Value 0 if this is a varargs function,
814missing otherwise.</td>
815 </tr>
816 </tbody>
Reid Spencer1ab929c2004-07-05 08:18:07 +0000817</table>
818<h3>Structure Types</h3>
819<table>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000820 <tbody>
821 <tr>
822 <th><b>Type</b></th>
823 <th class="td_left"><b>Description</b></th>
824 </tr>
825 <tr>
826 <td><a href="#uint24_vbr">uint24_vbr</a></td>
827 <td class="td_left">Type ID for structure types (14)</td>
828 </tr>
829 <tr>
830 <td><a href="#zlist">zlist</a>(<a href="#uint24_vbr">uint24_vbr</a>)</td>
831 <td class="td_left">Slot number of each of the element's fields.</td>
832 </tr>
833 </tbody>
Reid Spencer1ab929c2004-07-05 08:18:07 +0000834</table>
835<h3>Array Types</h3>
836<table>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000837 <tbody>
838 <tr>
839 <th><b>Type</b></th>
840 <th class="td_left"><b>Description</b></th>
841 </tr>
842 <tr>
843 <td><a href="#uint24_vbr">uint24_vbr</a></td>
844 <td class="td_left">Type ID for Array Types (15)</td>
845 </tr>
846 <tr>
847 <td><a href="#uint24_vbr">uint24_vbr</a></td>
848 <td class="td_left">Slot number of array's element type.</td>
849 </tr>
850 <tr>
851 <td><a href="#uint32_vbr">uint32_vbr</a></td>
852 <td class="td_left">The number of elements in the array.</td>
853 </tr>
854 </tbody>
Reid Spencer1ab929c2004-07-05 08:18:07 +0000855</table>
856<h3>Pointer Types</h3>
857<table>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000858 <tbody>
859 <tr>
860 <th><b>Type</b></th>
861 <th class="td_left"><b>Description</b></th>
862 </tr>
863 <tr>
864 <td><a href="#uint24_vbr">uint24_vbr</a></td>
865 <td class="td_left">Type ID For Pointer Types (16)</td>
866 </tr>
867 <tr>
868 <td><a href="#uint24_vbr">uint24_vbr</a></td>
869 <td class="td_left">Slot number of pointer's element type.</td>
870 </tr>
871 </tbody>
Reid Spencer1ab929c2004-07-05 08:18:07 +0000872</table>
873<h3>Opaque Types</h3>
874<table>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000875 <tbody>
876 <tr>
877 <th><b>Type</b></th>
878 <th class="td_left"><b>Description</b></th>
879 </tr>
880 <tr>
881 <td><a href="#uint24_vbr">uint24_vbr</a></td>
882 <td class="td_left">Type ID For Opaque Types (17)</td>
883 </tr>
884 </tbody>
Reid Spencer1ab929c2004-07-05 08:18:07 +0000885</table>
886</div>
887<!-- _______________________________________________________________________ -->
Reid Spencer9bd2be22004-07-29 00:13:04 +0000888<div class="doc_subsection"><a name="globalinfo">Module Global Info</a>
889</div>
Reid Spencer50026612004-05-22 02:28:36 +0000890<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +0000891<p>The module global info block contains the definitions of all global
892variables including their initializers and the <em>declaration</em> of
893all functions. The format is shown in the table below:</p>
894<table>
895 <tbody>
Reid Spencer2cc36152004-07-05 19:04:27 +0000896 <tr>
897 <th><b>Type</b></th>
898 <th class="td_left"><b>Field Description</b></th>
Reid Spencer2cc36152004-07-05 19:04:27 +0000899 </tr>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000900 <tr>
901 <td><a href="#block">block</a></td>
902 <td class="td_left">Module global info identifier (0x05) + size<br>
903 </td>
904 </tr>
905 <tr>
906 <td><a href="#zlist">zlist</a>(<a href="#globalvar">globalvar</a>)</td>
907 <td class="td_left">A zero terminated list of global var
908definitions occuring in the module.</td>
909 </tr>
910 <tr>
911 <td><a href="#zlist">zlist</a>(<a href="#uint24_vbr">uint24_vbr</a>)</td>
912 <td class="td_left">A zero terminated list of function types
913occuring in the module.</td>
914 </tr>
915 <tr>
916 <td style="vertical-align: top;"><a href="#llist">llist</a>(<a
917 href="#string">string</a>)<br>
918 </td>
919 <td style="vertical-align: top; text-align: left;">A length list
920of strings that specify the names of the libraries that this module
921depends upon.<br>
922 </td>
923 </tr>
924 <tr>
925 <td style="vertical-align: top;"><a href="#string">string</a><br>
926 </td>
927 <td style="vertical-align: top; text-align: left;">The target
928triple for the module (blank means no target triple specified, i.e. a
929platform independent module).<br>
930 </td>
931 </tr>
932 </tbody>
933</table>
Reid Spencer50026612004-05-22 02:28:36 +0000934</div>
Reid Spencer2cc36152004-07-05 19:04:27 +0000935<!-- _______________________________________________________________________ -->
936<div class="doc_subsubsection"><a name="globalvar">Global Variable Field</a>
937</div>
938<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +0000939<p>Global variables are written using an <a href="#uint32_vbr">uint32_vbr</a>
940that encodes information about the global variable and a list of the
941constant initializers for the global var, if any.</p>
942<p>The table below provides the bit layout of the first <a
943 href="#uint32_vbr">uint32_vbr</a> that describes the global variable.</p>
944<table>
945 <tbody>
Reid Spencer82c46712004-07-07 13:34:26 +0000946 <tr>
947 <th><b>Type</b></th>
948 <th class="td_left"><b>Description</b></th>
Reid Spencer82c46712004-07-07 13:34:26 +0000949 </tr>
Reid Spencer9bd2be22004-07-29 00:13:04 +0000950 <tr>
951 <td><a href="#bit">bit(0)</a></td>
952 <td class="td_left">Is constant?</td>
953 </tr>
954 <tr>
955 <td><a href="#bit">bit(1)</a></td>
956 <td class="td_left">Has initializer? Note that this bit
957determines whether the constant initializer field (described below)
958follows. </td>
959 </tr>
960 <tr>
961 <td><a href="#bit">bit(2-4)</a></td>
962 <td class="td_left">Linkage type: 0=External, 1=Weak,
9632=Appending, 3=Internal, 4=LinkOnce</td>
964 </tr>
965 <tr>
966 <td><a href="#bit">bit(5-31)</a></td>
967 <td class="td_left">Slot number of type for the global variable.</td>
968 </tr>
969 </tbody>
970</table>
971<p>The table below provides the format of the constant initializers for
972the global variable field, if it has one.</p>
973<table>
974 <tbody>
975 <tr>
976 <th><b>Type</b></th>
977 <th class="td_left"><b>Description</b></th>
978 </tr>
979 <tr>
980 <td>(<a href="#zlist">zlist</a>(<a href="#uint32_vbr">uint32_vbr</a>))?
981 </td>
982 <td class="td_left">An optional zero-terminated list of slot
983numbers of the global variable's constant initializer.</td>
984 </tr>
985 </tbody>
986</table>
Reid Spencer2cc36152004-07-05 19:04:27 +0000987</div>
Reid Spencer50026612004-05-22 02:28:36 +0000988<!-- _______________________________________________________________________ -->
Reid Spencer1ab929c2004-07-05 08:18:07 +0000989<div class="doc_subsection"><a name="constantpool">Constant Pool</a> </div>
Reid Spencer50026612004-05-22 02:28:36 +0000990<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +0000991<p>A constant pool defines as set of constant values. There are
992actually two types of constant pool blocks: one for modules and one for
993functions. For modules, the block begins with the constant strings
994encountered anywhere in the module. For functions, the block begins
995with types only encountered in the function. In both cases the header
996is identical. The tables that follow, show the header, module constant
997pool preamble, function constant pool preamble, and the part common to
998both function and module constant pools.</p>
999<p><b>Common Block Header</b></p>
1000<table>
1001 <tbody>
Reid Spencer2cc36152004-07-05 19:04:27 +00001002 <tr>
1003 <th><b>Type</b></th>
1004 <th class="td_left"><b>Field Description</b></th>
Reid Spencer2cc36152004-07-05 19:04:27 +00001005 </tr>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001006 <tr>
1007 <td><a href="#block">block</a></td>
1008 <td class="td_left">Constant pool identifier (0x03) + size<br>
1009 </td>
1010 </tr>
1011 </tbody>
1012</table>
1013<p><b>Module Constant Pool Preamble (constant strings)</b></p>
1014<table>
1015 <tbody>
Reid Spencer2cc36152004-07-05 19:04:27 +00001016 <tr>
1017 <th><b>Type</b></th>
1018 <th class="td_left"><b>Field Description</b></th>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001019 </tr>
1020 <tr>
Reid Spencer2cc36152004-07-05 19:04:27 +00001021 <td><a href="#uint32_vbr">uint32_vbr</a></td>
1022 <td class="td_left">The number of constant strings that follow.</td>
Reid Spencer2cc36152004-07-05 19:04:27 +00001023 </tr>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001024 <tr>
1025 <td><a href="#uint32_vbr">uint32_vbr</a></td>
1026 <td class="td_left">Zero. This identifies the following "plane"
1027as containing the constant strings. This is needed to identify it
1028uniquely from other constant planes that follow. </td>
1029 </tr>
1030 <tr>
1031 <td><a href="#uint24_vbr">uint24_vbr</a>+</td>
1032 <td class="td_left">Slot number of the constant string's type.
1033Note that the constant string's type implicitly defines the length of
1034the string. </td>
1035 </tr>
1036 </tbody>
1037</table>
1038<p><b>Function Constant Pool Preamble (function types)</b></p>
1039<p>The structure of the types for functions is identical to the <a
1040 href="#globaltypes">Global Type Pool</a>. Please refer to that section
1041for the details. </p>
1042<p><b>Common Part (other constants)</b></p>
1043<table>
1044 <tbody>
Reid Spencer2cc36152004-07-05 19:04:27 +00001045 <tr>
1046 <th><b>Type</b></th>
1047 <th class="td_left"><b>Field Description</b></th>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001048 </tr>
1049 <tr>
Reid Spencer2cc36152004-07-05 19:04:27 +00001050 <td><a href="#uint32_vbr">uint32_vbr</a></td>
1051 <td class="td_left">Number of entries in this type plane.</td>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001052 </tr>
1053 <tr>
1054 <td><a href="#uint24_vbr">uint24_vbr</a></td>
Reid Spencer2cc36152004-07-05 19:04:27 +00001055 <td class="td_left">Type slot number of this plane.</td>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001056 </tr>
1057 <tr>
Reid Spencer82c46712004-07-07 13:34:26 +00001058 <td><a href="#constant">constant</a>+</td>
Reid Spencer2cc36152004-07-05 19:04:27 +00001059 <td class="td_left">The definition of a constant (see below).</td>
1060 </tr>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001061 </tbody>
1062</table>
Reid Spencer2cc36152004-07-05 19:04:27 +00001063</div>
1064<!-- _______________________________________________________________________ -->
1065<div class="doc_subsubsection"><a name="constant">Constant Field</a></div>
1066<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +00001067<p>Constants come in many shapes and flavors. The sections that followe
1068define the format for each of them. All constants start with a <a
1069 href="#uint32_vbr">uint32_vbr</a> encoded integer that provides the
1070number of operands for the constant. For primitive, structure, and
1071array constants, this will always be zero since those types of
1072constants have no operands. In this case, we have the following field
1073definitions:</p>
1074<ul>
1075 <li><b>Bool</b>. This is written as an <a href="#uint32_vbr">uint32_vbr</a>
1076of value 1U or 0U.</li>
1077 <li><b>Signed Integers (sbyte,short,int,long)</b>. These are written
1078as an <a href="#int64_vbr">int64_vbr</a> with the corresponding value.</li>
1079 <li><b>Unsigned Integers (ubyte,ushort,uint,ulong)</b>. These are
1080written as an <a href="#uint64_vbr">uint64_vbr</a> with the
1081corresponding value. </li>
1082 <li><b>Floating Point</b>. Both the float and double types are
1083written literally in binary format.</li>
1084 <li><b>Arrays</b>. Arrays are written simply as a list of <a
1085 href="#uint32_vbr">uint32_vbr</a> encoded slot numbers to the constant
1086element values.</li>
1087 <li><b>Structures</b>. Structures are written simply as a list of <a
1088 href="#uint32_vbr">uint32_vbr</a> encoded slot numbers to the constant
1089field values of the structure.</li>
1090</ul>
1091<p>When the number of operands to the constant is non-zero, we have a
1092constant expression and its field format is provided in the table below.</p>
1093<table>
1094 <tbody>
Reid Spencer2cc36152004-07-05 19:04:27 +00001095 <tr>
1096 <th><b>Type</b></th>
1097 <th class="td_left"><b>Field Description</b></th>
Reid Spencer2cc36152004-07-05 19:04:27 +00001098 </tr>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001099 <tr>
1100 <td><a href="#uint32_vbr">uint32_vbr</a></td>
1101 <td class="td_left">Op code of the instruction for the constant
1102expression.</td>
1103 </tr>
1104 <tr>
1105 <td><a href="#uint32_vbr">uint32_vbr</a></td>
1106 <td class="td_left">The slot number of the constant value for an
1107operand.<sup>1</sup></td>
1108 </tr>
1109 <tr>
1110 <td><a href="#uint24_vbr">uint24_vbr</a></td>
1111 <td class="td_left">The slot number for the type of the constant
1112value for an operand.<sup>1</sup></td>
1113 </tr>
1114 </tbody>
1115</table>
1116Notes:
1117<ol>
1118 <li>Both these fields are repeatable but only in pairs.</li>
1119</ol>
Reid Spencer50026612004-05-22 02:28:36 +00001120</div>
1121<!-- _______________________________________________________________________ -->
Reid Spencer51f31e02004-07-05 22:28:02 +00001122<div class="doc_subsection"><a name="functiondefs">Function Definition</a></div>
Reid Spencer1ab929c2004-07-05 08:18:07 +00001123<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +00001124<p>Function definitions contain the linkage, constant pool or
1125compaction table, instruction list, and symbol table for a function.
1126The following table shows the structure of a function definition.</p>
1127<table>
1128 <tbody>
Reid Spencer51f31e02004-07-05 22:28:02 +00001129 <tr>
1130 <th><b>Type</b></th>
1131 <th class="td_left"><b>Field Description</b></th>
Reid Spencer51f31e02004-07-05 22:28:02 +00001132 </tr>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001133 <tr>
1134 <td><a href="#block">block</a><br>
1135 </td>
1136 <td class="td_left">Function definition block identifier (0x02) +
1137size<br>
1138 </td>
1139 </tr>
1140 <tr>
1141 <td><a href="#uint32_vbr">uint32_vbr</a></td>
1142 <td class="td_left">The linkage type of the function: 0=External,
11431=Weak, 2=Appending, 3=Internal, 4=LinkOnce<sup>1</sup></td>
1144 </tr>
1145 <tr>
1146 <td><a href="#block">block</a></td>
1147 <td class="td_left">The <a href="#constantpool">constant pool</a>
1148block for this function.<sup>2</sup></td>
1149 </tr>
1150 <tr>
1151 <td><a href="#block">block</a></td>
1152 <td class="td_left">The <a href="#compactiontable">compaction
1153table</a> block for the function.<sup>2</sup></td>
1154 </tr>
1155 <tr>
1156 <td><a href="#block">block</a></td>
1157 <td class="td_left">The <a href="#instructionlist">instruction
1158list</a> for the function.</td>
1159 </tr>
1160 <tr>
1161 <td><a href="#block">block</a></td>
1162 <td class="td_left">The function's <a href="#symboltable">symbol
1163table</a> containing only those symbols pertinent to the function
1164(mostly block labels).</td>
1165 </tr>
1166 </tbody>
1167</table>
1168Notes:
1169<ol>
1170 <li>Note that if the linkage type is "External" then none of the
1171other fields will be present as the function is defined elsewhere.</li>
1172 <li>Note that only one of the constant pool or compaction table will
1173be written. Compaction tables are only written if they will actually
1174save bytecode space. If not, then a regular constant pool is written.</li>
1175</ol>
Reid Spencer1ab929c2004-07-05 08:18:07 +00001176</div>
1177<!-- _______________________________________________________________________ -->
Reid Spencer9bd2be22004-07-29 00:13:04 +00001178<div class="doc_subsection"><a name="compactiontable">Compaction Table</a>
1179</div>
Reid Spencer1ab929c2004-07-05 08:18:07 +00001180<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +00001181<p>Compaction tables are part of a function definition. They are merely
1182a device for reducing the size of bytecode files. The size of a
1183bytecode file is dependent on the <em>value</em> of the slot numbers
1184used because larger values use more bytes in the variable bit rate
1185encoding scheme. Furthermore, the compressed instruction format
1186reserves only six bits for the type of the instruction. In large
1187modules, declaring hundreds or thousands of types, the values of the
1188slot numbers can be quite large. However, functions may use only a
1189small fraction of the global types. In such cases a compaction table is
1190created that maps the global type and value slot numbers to smaller
1191values used by a function. Functions will contain either a
1192function-specific constant pool <em>or</em> a compaction table but not
1193both. Compaction tables have the format shown in the table below.</p>
1194<table>
1195 <tbody>
Reid Spencer2cc36152004-07-05 19:04:27 +00001196 <tr>
1197 <th><b>Type</b></th>
1198 <th class="td_left"><b>Field Description</b></th>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001199 </tr>
1200 <tr>
Reid Spencer2cc36152004-07-05 19:04:27 +00001201 <td><a href="#uint32_vbr">uint32_vbr</a></td>
1202 <td class="td_left">The number of types that follow</td>
Reid Spencer2cc36152004-07-05 19:04:27 +00001203 </tr>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001204 <tr>
1205 <td><a href="#uint24_vbr">uint24_vbr</a>+</td>
1206 <td class="td_left">The slot number in the global type plane of
1207the type that will be referenced in the function with the index of this
1208entry in the compaction table.</td>
1209 </tr>
1210 <tr>
1211 <td><a href="#type_len">type_len</a></td>
1212 <td class="td_left">An encoding of the type and number of values
1213that follow. This field's encoding varies depending on the size of the
1214type plane. See <a href="#type_len">Type and Length</a> for further
1215details.</td>
1216 </tr>
1217 <tr>
1218 <td><a href="#uint32_vbr">uint32_vbr</a>+</td>
1219 <td class="td_left">The slot number in the globals of the value
1220that will be referenced in the function with the index of this entry in
1221the compaction table</td>
1222 </tr>
1223 </tbody>
1224</table>
Reid Spencer1ab929c2004-07-05 08:18:07 +00001225</div>
Reid Spencer2cc36152004-07-05 19:04:27 +00001226<!-- _______________________________________________________________________ -->
1227<div class="doc_subsubsection"><a name="type_len">Type and Length</a></div>
1228<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +00001229<p>The type and length of a compaction table type plane is encoded
1230differently depending on the length of the plane. For planes of length
12311 or 2, the length is encoded into bits 0 and 1 of a <a
1232 href="#uint32_vbr">uint32_vbr</a> and the type is encoded into bits
12332-31. Because type numbers are often small, this often saves an extra
1234byte per plane. If the length of the plane is greater than 2 then the
1235encoding uses a <a href="#uint32_vbr">uint32_vbr</a> for each of the
1236length and type, in that order.</p>
Reid Spencer2cc36152004-07-05 19:04:27 +00001237</div>
Reid Spencer1ab929c2004-07-05 08:18:07 +00001238<!-- _______________________________________________________________________ -->
Reid Spencer9bd2be22004-07-29 00:13:04 +00001239<div class="doc_subsection"><a name="instructionlist">Instruction List</a>
1240</div>
Reid Spencer50026612004-05-22 02:28:36 +00001241<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +00001242<p>The instructions in a function are written as a simple list. Basic
1243blocks are inferred by the terminating instruction types. The format of
1244the block is given in the following table.</p>
1245<table>
1246 <tbody>
Reid Spencer51f31e02004-07-05 22:28:02 +00001247 <tr>
1248 <th><b>Type</b></th>
1249 <th class="td_left"><b>Field Description</b></th>
Reid Spencer51f31e02004-07-05 22:28:02 +00001250 </tr>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001251 <tr>
1252 <td><a href="#block">block</a><br>
1253 </td>
1254 <td class="td_left">Instruction list identifier (0x07) + size<br>
1255 </td>
1256 </tr>
1257 <tr>
1258 <td><a href="#instruction">instruction</a>+</td>
1259 <td class="td_left">An instruction. Instructions have a variety
1260of formats. See <a href="#instruction">Instructions</a> for details.</td>
1261 </tr>
1262 </tbody>
1263</table>
Reid Spencer50026612004-05-22 02:28:36 +00001264</div>
Reid Spencer51f31e02004-07-05 22:28:02 +00001265<!-- _______________________________________________________________________ -->
1266<div class="doc_subsubsection"><a name="instruction">Instructions</a></div>
1267<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +00001268<p>For brevity, instructions are written in one of four formats,
1269depending on the number of operands to the instruction. Each
1270instruction begins with a <a href="#uint32_vbr">uint32_vbr</a> that
1271encodes the type of the instruction as well as other things. The tables
1272that follow describe the format of this first word of each instruction.</p>
1273<p><b>Instruction Format 0</b></p>
1274<p>This format is used for a few instructions that can't easily be
1275optimized because they have large numbers of operands (e.g. PHI Node or
1276getelementptr). Each of the opcode, type, and operand fields is as
1277successive fields.</p>
1278<table>
1279 <tbody>
Reid Spencer51f31e02004-07-05 22:28:02 +00001280 <tr>
1281 <th><b>Type</b></th>
1282 <th class="td_left"><b>Field Description</b></th>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001283 </tr>
1284 <tr>
Reid Spencer51f31e02004-07-05 22:28:02 +00001285 <td><a href="#uint32_vbr">uint32_vbr</a></td>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001286 <td class="td_left">Specifies the opcode of the instruction. Note
1287that for compatibility with the other instruction formats, the opcode
1288is shifted left by 2 bits. Bits 0 and 1 must have value zero for this
1289format.</td>
1290 </tr>
1291 <tr>
1292 <td><a href="#uint24_vbr">uint24_vbr</a></td>
1293 <td class="td_left">Provides the slot number of the result type
1294of the instruction</td>
1295 </tr>
1296 <tr>
Reid Spencer51f31e02004-07-05 22:28:02 +00001297 <td><a href="#uint32_vbr">uint32_vbr</a></td>
1298 <td class="td_left">The number of operands that follow.</td>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001299 </tr>
1300 <tr>
Reid Spencer82c46712004-07-07 13:34:26 +00001301 <td><a href="#uint32_vbr">uint32_vbr</a>+</td>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001302 <td class="td_left">The slot number of the value(s) for the
1303operand(s). <sup>1</sup></td>
Reid Spencer51f31e02004-07-05 22:28:02 +00001304 </tr>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001305 </tbody>
1306</table>
1307Notes:
1308<ol>
1309 <li>Note that if the instruction is a getelementptr and the type of
1310the operand is a sequential type (array or pointer) then the slot
1311number is shifted up two bits and the low order bits will encode the
1312type of index used, as follows: 0=uint, 1=int, 2=ulong, 3=long.</li>
1313</ol>
1314<p><b>Instruction Format 1</b></p>
1315<p>This format encodes the opcode, type and a single operand into a
1316single <a href="#uint32_vbr">uint32_vbr</a> as follows:</p>
1317<table>
1318 <tbody>
Reid Spencer51f31e02004-07-05 22:28:02 +00001319 <tr>
1320 <th><b>Bits</b></th>
1321 <th><b>Type</b></th>
1322 <th class="td_left"><b>Field Description</b></th>
Reid Spencer51f31e02004-07-05 22:28:02 +00001323 </tr>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001324 <tr>
1325 <td>0-1</td>
1326 <td>constant "1"</td>
1327 <td class="td_left">These two bits must be the value 1 which
1328identifies this as an instruction of format 1.</td>
1329 </tr>
1330 <tr>
1331 <td>2-7</td>
1332 <td><a href="#opcodes">opcode</a></td>
1333 <td class="td_left">Specifies the opcode of the instruction. Note
1334that the maximum opcode value is 63.</td>
1335 </tr>
1336 <tr>
1337 <td>8-19</td>
1338 <td><a href="#unsigned">unsigned</a></td>
1339 <td class="td_left">Specifies the slot number of the type for
1340this instruction. Maximum slot number is 2<sup>12</sup>-1=4095.</td>
1341 </tr>
1342 <tr>
1343 <td>20-31</td>
1344 <td><a href="#unsigned">unsigned</a></td>
1345 <td class="td_left">Specifies the slot number of the value for
1346the first operand. Maximum slot number is 2<sup>12</sup>-1=4095. Note
1347that the value 2<sup>12</sup>-1 denotes zero operands.</td>
1348 </tr>
1349 </tbody>
1350</table>
1351<p><b>Instruction Format 2</b></p>
1352<p>This format encodes the opcode, type and two operands into a single <a
1353 href="#uint32_vbr">uint32_vbr</a> as follows:</p>
1354<table>
1355 <tbody>
Reid Spencer51f31e02004-07-05 22:28:02 +00001356 <tr>
1357 <th><b>Bits</b></th>
1358 <th><b>Type</b></th>
1359 <th class="td_left"><b>Field Description</b></th>
Reid Spencer51f31e02004-07-05 22:28:02 +00001360 </tr>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001361 <tr>
1362 <td>0-1</td>
1363 <td>constant "2"</td>
1364 <td class="td_left">These two bits must be the value 2 which
1365identifies this as an instruction of format 2.</td>
1366 </tr>
1367 <tr>
1368 <td>2-7</td>
1369 <td><a href="#opcodes">opcode</a></td>
1370 <td class="td_left">Specifies the opcode of the instruction. Note
1371that the maximum opcode value is 63.</td>
1372 </tr>
1373 <tr>
1374 <td>8-15</td>
1375 <td><a href="#unsigned">unsigned</a></td>
1376 <td class="td_left">Specifies the slot number of the type for
1377this instruction. Maximum slot number is 2<sup>8</sup>-1=255.</td>
1378 </tr>
1379 <tr>
1380 <td>16-23</td>
1381 <td><a href="#unsigned">unsigned</a></td>
1382 <td class="td_left">Specifies the slot number of the value for
1383the first operand. Maximum slot number is 2<sup>8</sup>-1=255.</td>
1384 </tr>
1385 <tr>
1386 <td>24-31</td>
1387 <td><a href="#unsigned">unsigned</a></td>
1388 <td class="td_left">Specifies the slot number of the value for
1389the second operand. Maximum slot number is 2<sup>8</sup>-1=255.</td>
1390 </tr>
1391 </tbody>
1392</table>
1393<p><b>Instruction Format 3</b></p>
1394<p>This format encodes the opcode, type and three operands into a
1395single <a href="#uint32_vbr">uint32_vbr</a> as follows:</p>
1396<table>
1397 <tbody>
Reid Spencer51f31e02004-07-05 22:28:02 +00001398 <tr>
1399 <th><b>Bits</b></th>
1400 <th><b>Type</b></th>
1401 <th class="td_left"><b>Field Description</b></th>
Reid Spencer51f31e02004-07-05 22:28:02 +00001402 </tr>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001403 <tr>
1404 <td>0-1</td>
1405 <td>constant "3"</td>
1406 <td class="td_left">These two bits must be the value 3 which
1407identifies this as an instruction of format 3.</td>
1408 </tr>
1409 <tr>
1410 <td>2-7</td>
1411 <td><a href="#opcodes">opcode</a></td>
1412 <td class="td_left">Specifies the opcode of the instruction. Note
1413that the maximum opcode value is 63.</td>
1414 </tr>
1415 <tr>
1416 <td>8-13</td>
1417 <td><a href="#unsigned">unsigned</a></td>
1418 <td class="td_left">Specifies the slot number of the type for
1419this instruction. Maximum slot number is 2<sup>6</sup>-1=63.</td>
1420 </tr>
1421 <tr>
1422 <td>14-19</td>
1423 <td><a href="#unsigned">unsigned</a></td>
1424 <td class="td_left">Specifies the slot number of the value for
1425the first operand. Maximum slot number is 2<sup>6</sup>-1=63.</td>
1426 </tr>
1427 <tr>
1428 <td>20-25</td>
1429 <td><a href="#unsigned">unsigned</a></td>
1430 <td class="td_left">Specifies the slot number of the value for
1431the second operand. Maximum slot number is 2<sup>6</sup>-1=63.</td>
1432 </tr>
1433 <tr>
1434 <td>26-31</td>
1435 <td><a href="#unsigned">unsigned</a></td>
1436 <td class="td_left">Specifies the slot number of the value for
1437the third operand. Maximum slot number is 2<sup>6</sup>-1=63.</td>
1438 </tr>
1439 </tbody>
1440</table>
Reid Spencer51f31e02004-07-05 22:28:02 +00001441</div>
Reid Spencer50026612004-05-22 02:28:36 +00001442<!-- _______________________________________________________________________ -->
Reid Spencerb39021b2004-05-23 17:05:09 +00001443<div class="doc_subsection"><a name="symtab">Symbol Table</a> </div>
Reid Spencer50026612004-05-22 02:28:36 +00001444<div class="doc_text">
Reid Spencerb39021b2004-05-23 17:05:09 +00001445<p>A symbol table can be put out in conjunction with a module or a function.
1446A symbol table is a list of type planes. Each type plane starts with the number
Reid Spencer9bd2be22004-07-29 00:13:04 +00001447of entries in the plane and the type plane's slot number (so the type
1448can be looked up in the global type pool). For each entry in a type
1449plane, the slot number of the value and the name associated with that
1450value are written. The format is given in the table below. </p>
Reid Spencer2cc36152004-07-05 19:04:27 +00001451<table>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001452 <tbody>
1453 <tr>
1454 <th><b>Type</b></th>
1455 <th class="td_left"><b>Field Description</b></th>
1456 </tr>
1457 <tr>
1458 <td><a href="#block">block</a><br>
1459 </td>
1460 <td class="td_left">Symbol Table Identifier (0x04)</td>
1461 </tr>
1462 <tr>
1463 <td><a href="#uint32_vbr">uint32_vbr</a></td>
1464 <td class="td_left">Number of entries in type plane</td>
1465 </tr>
1466 <tr>
1467 <td><a href="#symtab_entry">symtab_entry</a>*</td>
1468 <td class="td_left">Provides the slot number of the type and its
1469name.</td>
1470 </tr>
1471 <tr>
1472 <td><a href="#symtab_plane">symtab_plane</a>*</td>
1473 <td class="td_left">A type plane containing value slot number and
1474name for all values of the same type.</td>
1475 </tr>
1476 </tbody>
Reid Spencerb39021b2004-05-23 17:05:09 +00001477</table>
Reid Spencer50026612004-05-22 02:28:36 +00001478</div>
Reid Spencer51f31e02004-07-05 22:28:02 +00001479<!-- _______________________________________________________________________ -->
Reid Spencer9bd2be22004-07-29 00:13:04 +00001480<div class="doc_subsubsection"> <a name="symtab_plane">Symbol Table
1481Plane</a>
Reid Spencer51f31e02004-07-05 22:28:02 +00001482</div>
1483<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +00001484<p>A symbol table plane provides the symbol table entries for all
1485values of a common type. The encoding is given in the following table:</p>
Reid Spencer51f31e02004-07-05 22:28:02 +00001486<table>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001487 <tbody>
1488 <tr>
1489 <th><b>Type</b></th>
1490 <th class="td_left"><b>Field Description</b></th>
1491 </tr>
1492 <tr>
1493 <td><a href="#uint32_vbr">uint32_vbr</a></td>
1494 <td class="td_left">Number of entries in this plane.</td>
1495 </tr>
1496 <tr>
1497 <td><a href="#uint32_vbr">uint32_vbr</a></td>
1498 <td class="td_left">Slot number of type for this plane.</td>
1499 </tr>
1500 <tr>
1501 <td><a href="#symtab_entry">symtab_entry</a>+</td>
1502 <td class="td_left">The symbol table entries for this plane.</td>
1503 </tr>
1504 </tbody>
Reid Spencer51f31e02004-07-05 22:28:02 +00001505</table>
1506</div>
Reid Spencer51f31e02004-07-05 22:28:02 +00001507<!-- _______________________________________________________________________ -->
Reid Spencer9bd2be22004-07-29 00:13:04 +00001508<div class="doc_subsubsection"> <a name="symtab_entry">Symbol Table
1509Entry</a>
Reid Spencer51f31e02004-07-05 22:28:02 +00001510</div>
1511<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +00001512<p>A symbol table entry provides the assocation between a type or
1513value's slot number and the name given to that type or value. The
1514format is given in the following table:</p>
Reid Spencer51f31e02004-07-05 22:28:02 +00001515<table>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001516 <tbody>
1517 <tr>
1518 <th><b>Type</b></th>
1519 <th class="td_left"><b>Field Description</b></th>
1520 </tr>
1521 <tr>
1522 <td><a href="#uint32_vbr">uint24_vbr</a></td>
1523 <td class="td_left">Slot number of the type or value being given
1524a name. </td>
1525 </tr>
1526 <tr>
1527 <td><a href="#uint32_vbr">uint32_vbr</a></td>
1528 <td class="td_left">Length of the character array that follows.</td>
1529 </tr>
1530 <tr>
1531 <td><a href="#char">char</a>+</td>
1532 <td class="td_left">The characters of the name.</td>
1533 </tr>
1534 </tbody>
Reid Spencer51f31e02004-07-05 22:28:02 +00001535</table>
1536</div>
Reid Spencer7c76d332004-06-08 07:41:41 +00001537<!-- *********************************************************************** -->
Reid Spencer9bd2be22004-07-29 00:13:04 +00001538<div class="doc_section"> <a name="versiondiffs">Version Differences</a>
1539</div>
Reid Spencer7c76d332004-06-08 07:41:41 +00001540<!-- *********************************************************************** -->
1541<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +00001542<p>This section describes the differences in the Bytecode Format across
1543LLVM
1544versions. The versions are listed in reverse order because it assumes
1545the current version is as documented in the previous sections. Each
1546section here
Chris Lattner1cc070c2004-07-05 18:05:48 +00001547describes the differences between that version and the one that <i>follows</i>.
Reid Spencer7c76d332004-06-08 07:41:41 +00001548</p>
1549</div>
1550<!-- _______________________________________________________________________ -->
Reid Spencer9bd2be22004-07-29 00:13:04 +00001551<div class="doc_subsection"><a name="vers12">Version 1.2 Differences
1552From 1.3</a></div>
Reid Spencer1ab929c2004-07-05 08:18:07 +00001553<!-- _______________________________________________________________________ -->
1554<div class="doc_subsubsection">Type Derives From Value</div>
Reid Spencer7c76d332004-06-08 07:41:41 +00001555<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +00001556<p>In version 1.2, the Type class in the LLVM IR derives from the Value
1557class. This is not the case in version 1.3. Consequently, in version
15581.2 the notion of a "Type Type" was used to write out values that were
1559Types. The types always occuped plane 12 (corresponding to the
1560TypeTyID) of any type planed set of values. In 1.3 this representation
1561is not convenient because the TypeTyID (12) is not present and its
1562value is now used for LabelTyID. Consequently, the data structures
1563written that involve types do so by writing all the types first and
1564then each of the value planes according to those types. In version 1.2,
1565the types would have been written intermingled with the values.</p>
Reid Spencer1ab929c2004-07-05 08:18:07 +00001566</div>
Reid Spencer1ab929c2004-07-05 08:18:07 +00001567<!-- _______________________________________________________________________ -->
Reid Spencer9bd2be22004-07-29 00:13:04 +00001568<div class="doc_subsubsection">Restricted getelementptr Types</div>
Reid Spencer1ab929c2004-07-05 08:18:07 +00001569<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +00001570<p>In version 1.2, the getelementptr instruction required a ubyte type
1571index for accessing a structure field and a long type index for
1572accessing an array element. Consequently, it was only possible to
1573access structures of 255 or fewer elements. Starting in version 1.3,
1574this restriction was lifted. Structures must now be indexed with uint
1575constants. Arrays may now be indexed with int, uint, long, or ulong
1576typed values. The consequence of this was that the bytecode format had
1577to change in order to accommodate the larger range of structure indices.</p>
Reid Spencer7c76d332004-06-08 07:41:41 +00001578</div>
Reid Spencer7c76d332004-06-08 07:41:41 +00001579<!-- _______________________________________________________________________ -->
Reid Spencer9bd2be22004-07-29 00:13:04 +00001580<div class="doc_subsubsection">Short Block Headers</div>
1581<div class="doc_text">
1582<p>In version 1.2, block headers were always 8 bytes being comprised of
1583both an unsigned integer type and an unsigned integer size. For very
1584small modules, these block headers turn out to be a large fraction of
1585the total bytecode file size. In an attempt to make these small files
1586smaller, the type and size information was encoded into a single
1587unsigned integer (4 bytes) comprised of 5 bits for the block type
1588(maximum 31 block types) and 27 bits for the block size (max
1589~134MBytes). These limits seemed sufficient for any blocks or sizes
1590forseen in the future. Note that the module block, which encloses all
1591the other blocks is still written as 8 bytes since bytecode files
1592larger than 134MBytes might be possible.</p>
1593</div>
1594<!-- _______________________________________________________________________ -->
1595<div class="doc_subsubsection">Dependent Libraries and Target Triples</div>
1596<div class="doc_text">
1597<p>In version 1.2, the bytecode format does not store module's target
1598triple or dependent. These fields have been added to the end of the <a
1599 href="#globalinfo">module global info block</a>. The purpose of these
1600fields is to allow a front end compiler to specifiy that the generated
1601module is specific to a particular target triple (operating
1602system/manufacturer/processor) which makes it non-portable; and to
1603allow front end compilers to specify the list of libraries that the
1604module depends on for successful linking.</p>
1605</div>
1606<!-- _______________________________________________________________________ -->
1607<div class="doc_subsubsection">Types Restricted to 24-bits</div>
1608<div class="doc_text">
1609<p>In version 1.2, type slot identifiers were written as 32-bit VBR
1610quantities. In 1.3 this has been reduced to 24-bits in order to ensure
1611that it is not possible to overflow the type field of a global variable
1612definition. 24-bits for type slot numbers is deemed sufficient for any
1613practical use of LLVM.</p>
1614</div>
1615<!-- _______________________________________________________________________ -->
1616<!-- _______________________________________________________________________ -->
1617<div class="doc_subsection"><a name="vers11">Version 1.1 Differences
1618From 1.2 </a></div>
Reid Spencer1ab929c2004-07-05 08:18:07 +00001619<!-- _______________________________________________________________________ -->
1620<div class="doc_subsubsection">Explicit Primitive Zeros</div>
Reid Spencer7c76d332004-06-08 07:41:41 +00001621<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +00001622<p>In version 1.1, the zero value for primitives was explicitly encoded
1623into the bytecode format. Since these zero values are constant values
1624in the LLVM IR and never change, there is no reason to explicitly
1625encode them. This explicit encoding was removed in version 1.2.</p>
Reid Spencer1ab929c2004-07-05 08:18:07 +00001626</div>
Reid Spencer1ab929c2004-07-05 08:18:07 +00001627<!-- _______________________________________________________________________ -->
1628<div class="doc_subsubsection">Inconsistent Module Global Info</div>
1629<div class="doc_text">
Reid Spencer9bd2be22004-07-29 00:13:04 +00001630<p>In version 1.1, the Module Global Info block was not aligned causing
1631the next block to be read in on an unaligned boundary. This problem was
1632corrected in version 1.2.<br>
1633<br>
1634</p>
Reid Spencer7c76d332004-06-08 07:41:41 +00001635</div>
Reid Spencer7c76d332004-06-08 07:41:41 +00001636<!-- _______________________________________________________________________ -->
Reid Spencer9bd2be22004-07-29 00:13:04 +00001637<div class="doc_subsection"><a name="vers10">Version 1.0 Differences
1638From 1.1</a></div>
Reid Spencer7c76d332004-06-08 07:41:41 +00001639<div class="doc_text">
Reid Spencer1ab929c2004-07-05 08:18:07 +00001640<p>None. Version 1.0 and 1.1 bytecode formats are identical.</p>
Reid Spencer7c76d332004-06-08 07:41:41 +00001641</div>
Reid Spencer50026612004-05-22 02:28:36 +00001642<!-- *********************************************************************** -->
1643<hr>
Reid Spencer9bd2be22004-07-29 00:13:04 +00001644<address> <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
1645 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
1646<a href="http://validator.w3.org/check/referer"><img
1647 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!"></a>
1648<a href="mailto:rspencer@x10sys.com">Reid Spencer</a> and <a
1649 href="mailto:sabre@nondot.org">Chris Lattner</a><br>
1650<a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a><br>
1651Last modified: $Date$
Reid Spencer50026612004-05-22 02:28:36 +00001652</address>
Reid Spencer50026612004-05-22 02:28:36 +00001653<!-- vim: sw=2
1654-->
Reid Spencer9bd2be22004-07-29 00:13:04 +00001655</body>
1656</html>