Packed types, brought to you by Brad Jones
[oota-llvm.git] / docs / BytecodeFormat.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html>
3 <head>
4   <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5   <title>LLVM Bytecode File Format</title>
6   <link rel="stylesheet" href="llvm.css" type="text/css">
7   <style type="text/css">
8     TR, TD { border: 2px solid gray; padding-left: 4pt; padding-right: 4pt; 
9              padding-top: 2pt; padding-bottom: 2pt; }
10     TH { border: 2px solid gray; font-weight: bold; font-size: 105%; }
11     TABLE { text-align: center; border: 2px solid black; 
12       border-collapse: collapse; margin-top: 1em; margin-left: 1em; 
13       margin-right: 1em; margin-bottom: 1em; }
14     .td_left { border: 2px solid gray; text-align: left; }
15   </style>
16 </head>
17 <body>
18 <div class="doc_title"> LLVM Bytecode File Format </div>
19 <ol>
20   <li><a href="#abstract">Abstract</a></li>
21   <li><a href="#concepts">Concepts</a>
22     <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>
27       <li><a href="#vbr">Variable Bit-Rate Encoding</a></li>
28       <li><a href="#encoding">Encoding Primitives</a></li>
29       <li><a href="#slots">Slots</a></li>
30     </ol>
31   </li>
32   <li><a href="#general">General Structure</a> </li>
33   <li><a href="#blockdefs">Block Definitions</a>
34     <ol>
35       <li><a href="#signature">Signature Block</a></li>
36       <li><a href="#module">Module Block</a></li>
37       <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>
42       <li><a href="#instructionlist">Instruction List</a></li>
43       <li><a href="#symtab">Symbol Table</a></li>
44     </ol>
45   </li>
46   <li><a href="#versiondiffs">Version Differences</a>
47     <ol>
48       <li><a href="#vers13">Version 1.3 Differences From 1.4</a></li>
49       <li><a href="#vers12">Version 1.2 Differences From 1.3</a></li>
50       <li><a href="#vers11">Version 1.1 Differences From 1.2</a></li>
51       <li><a href="#vers10">Version 1.0 Differences From 1.1</a></li>
52     </ol>
53   </li>
54 </ol>
55 <div class="doc_author">
56 <p>Written by <a href="mailto:rspencer@x10sys.com">Reid Spencer</a>
57 </p>
58 </div>
59 <!-- *********************************************************************** -->
60 <div class="doc_section"> <a name="abstract">Abstract </a></div>
61 <!-- *********************************************************************** -->
62 <div class="doc_text">
63 <p>This document describes the LLVM bytecode file format. It specifies
64 the binary encoding rules of the bytecode file format so that
65 equivalent systems can encode bytecode files correctly. The LLVM
66 bytecode representation is used to store the intermediate
67 representation on disk in compacted form.</p>
68 <p>The LLVM bytecode format may change in the future, but LLVM will
69 always be backwards compatible with older formats. This document will
70 only describe the most current version of the bytecode format. See <a
71  href="#versiondiffs">Version Differences</a> for the details on how
72 the current version is different from previous versions.</p>
73 </div>
74 <!-- *********************************************************************** -->
75 <div class="doc_section"> <a name="concepts">Concepts</a> </div>
76 <!-- *********************************************************************** -->
77 <div class="doc_text">
78 <p>This section describes the general concepts of the bytecode file
79 format without getting into specific layout details. It is recommended
80 that you read this section thoroughly before interpreting the detailed
81 descriptions.</p>
82 </div>
83 <!-- _______________________________________________________________________ -->
84 <div class="doc_subsection"><a name="blocks">Blocks</a> </div>
85 <div class="doc_text">
86 <p>LLVM bytecode files consist simply of a sequence of blocks of bytes
87 using a binary encoding Each block begins with an header of two
88 unsigned integers. The first value identifies the type of block and the
89 second value provides the size of the block in bytes. The block
90 identifier is used because it is possible for entire blocks to be
91 omitted from the file if they are empty. The block identifier helps the
92 reader determine which kind of block is next in the file. Note that
93 blocks can be nested within other blocks.</p>
94 <p> All blocks are variable length, and the block header specifies the
95 size of the block. All blocks begin on a byte index that is aligned to
96 an even 32-bit boundary. That is, the first block is 32-bit aligned
97 because it starts at offset 0. Each block is padded with zero fill
98 bytes to ensure that the next block also starts on a 32-bit boundary.</p>
99 </div>
100 <!-- _______________________________________________________________________ -->
101 <div class="doc_subsection"><a name="lists">Lists</a> </div>
102 <div class="doc_text">
103 <p>LLVM Bytecode blocks often contain lists of things of a similar
104 type. For example, a function contains a list of instructions and a
105 function type contains a list of argument types. There are two basic
106 types of lists: length lists (<a href="#llist">llist</a>), and null
107 terminated lists (<a href="#zlist">zlist</a>), as described below in
108 the <a href="#encoding">Encoding Primitives</a>.</p>
109 </div>
110 <!-- _______________________________________________________________________ -->
111 <div class="doc_subsection"><a name="fields">Fields</a> </div>
112 <div class="doc_text">
113 <p>Fields are units of information that LLVM knows how to write atomically. Most 
114 fields have a uniform length or some kind of length indication built into their 
115 encoding. For example, a constant string (array of bytes) is written simply as 
116 the length followed by the characters. Although this is similar to a list, 
117 constant strings are treated atomically and are thus fields.</p>
118 <p>Fields use a condensed bit format specific to the type of information
119 they must contain. As few bits as possible are written for each field. The
120 sections that follow will provide the details on how these fields are
121 written and how the bits are to be interpreted.</p>
122 </div>
123 <!-- _______________________________________________________________________ -->
124 <div class="doc_subsection"><a name="align">Alignment</a> </div>
125 <div class="doc_text">
126   <p>To support cross-platform differences, the bytecode file is aligned on 
127   certain boundaries. This means that a small amount of padding (at most 3 
128   bytes) will be added to ensure that the next entry is aligned to a 32-bit 
129   boundary.</p>
130 </div>
131 <!-- _______________________________________________________________________ -->
132 <div class="doc_subsection"><a name="vbr">Variable Bit-Rate Encoding</a>
133 </div>
134 <div class="doc_text">
135 <p>Most of the values written to LLVM bytecode files are small integers. To 
136 minimize the number of bytes written for these quantities, an encoding scheme 
137 similar to UTF-8 is used to write integer data. The scheme is known as
138 variable bit rate (vbr) encoding. In this encoding, the high bit of
139 each byte is used to indicate if more bytes follow. If (byte &amp;
140 0x80) is non-zero in any given byte, it means there is another byte
141 immediately following that also contributes to the value. For the final
142 byte (byte &amp; 0x80) is false (the high bit is not set). In each byte
143 only the low seven bits contribute to the value. Consequently 32-bit
144 quantities can take from one to <em>five</em> bytes to encode. In
145 general, smaller quantities will encode in fewer bytes, as follows:</p>
146 <table>
147   <tbody>
148     <tr>
149       <th>Byte #</th>
150       <th>Significant Bits</th>
151       <th>Maximum Value</th>
152     </tr>
153     <tr>
154       <td>1</td>
155       <td>0-6</td>
156       <td>127</td>
157     </tr>
158     <tr>
159       <td>2</td>
160       <td>7-13</td>
161       <td>16,383</td>
162     </tr>
163     <tr>
164       <td>3</td>
165       <td>14-20</td>
166       <td>2,097,151</td>
167     </tr>
168     <tr>
169       <td>4</td>
170       <td>21-27</td>
171       <td>268,435,455</td>
172     </tr>
173     <tr>
174       <td>5</td>
175       <td>28-34</td>
176       <td>34,359,738,367</td>
177     </tr>
178     <tr>
179       <td>6</td>
180       <td>35-41</td>
181       <td>4,398,046,511,103</td>
182     </tr>
183     <tr>
184       <td>7</td>
185       <td>42-48</td>
186       <td>562,949,953,421,311</td>
187     </tr>
188     <tr>
189       <td>8</td>
190       <td>49-55</td>
191       <td>72,057,594,037,927,935</td>
192     </tr>
193     <tr>
194       <td>9</td>
195       <td>56-62</td>
196       <td>9,223,372,036,854,775,807</td>
197     </tr>
198     <tr>
199       <td>10</td>
200       <td>63-69</td>
201       <td>1,180,591,620,717,411,303,423</td>
202     </tr>
203   </tbody>
204 </table>
205 <p>Note that in practice, the tenth byte could only encode bit 63 since
206 the maximum quantity to use this encoding is a 64-bit integer.</p>
207 <p><em>Signed</em> VBR values are encoded with the standard vbr
208 encoding, but with the sign bit as the low order bit instead of the
209 high order bit. This allows small negative quantities to be encoded
210 efficiently. For example, -3
211 is encoded as "((3 &lt;&lt; 1) | 1)" and 3 is encoded as "(3 &lt;&lt;
212 1) | 0)", emitted with the standard vbr encoding above.</p>
213 </div>
214 <!-- _______________________________________________________________________ -->
215 <div class="doc_subsection"><a name="encoding">Encoding Primitives</a> </div>
216 <div class="doc_text">
217 <p>Each field in the bytecode format is encoded into the file using a
218 small set of primitive formats. The table below defines the encoding
219 rules for the various primitives used and gives them each a type name.
220 The type names used in the descriptions of blocks and fields in the <a
221  href="#details">Detailed Layout</a>next section. Any type name with
222 the suffix <em>_vbr</em> indicates a quantity that is encoded using
223 variable bit rate encoding as described above.</p>
224 <table class="doc_table">
225   <tbody>
226     <tr>
227       <th><b>Type</b></th>
228       <th class="td_left"><b>Rule</b></th>
229     </tr>
230     <tr>
231       <td><a name="unsigned"><b>unsigned</b></a></td>
232       <td class="td_left">A 32-bit unsigned integer that always occupies four 
233       consecutive bytes. The unsigned integer is encoded using LSB first 
234       ordering. That is bits 2<sup>0</sup> through 2<sup>7</sup> are in the 
235       byte with the lowest file offset (little endian).</td>
236     </tr>
237     <tr>
238       <td style="vertical-align: top;"><a name="uint24_vbr">
239         <b>uint24_vbr</b></a></td>
240       <td style="vertical-align: top; text-align: left;">A 24-bit unsigned 
241       integer that occupies from one to four bytes using variable bit rate 
242       encoding.</td>
243     </tr>
244     <tr>
245       <td><a name="uint32_vbr"><b>uint32_vbr</b></a></td>
246       <td class="td_left">A 32-bit unsigned integer that occupies from one to 
247         five bytes using variable bit rate encoding.</td>
248     </tr>
249     <tr>
250       <td><a name="uint64_vbr"><b>uint64_vbr</b></a></td>
251       <td class="td_left">A 64-bit unsigned integer that occupies from one to ten 
252         bytes using variable bit rate encoding.</td>
253     </tr>
254     <tr>
255       <td><a name="int64_vbr"><b>int64_vbr</b></a></td>
256       <td class="td_left">A 64-bit signed integer that occupies from one to ten 
257         bytes using the signed variable bit rate encoding.</td>
258     </tr>
259     <tr>
260       <td><a name="char"><b>char</b></a></td>
261       <td class="td_left">A single unsigned character encoded into one byte</td>
262     </tr>
263     <tr>
264       <td><a name="bit"><b>bit(n-m)</b></a></td>
265       <td class="td_left">A set of bit within some larger integer field. The values 
266         of <code>n</code> and <code>m</code> specify the inclusive range of bits 
267         that define the subfield. The value for <code>m</code> may be omitted if 
268         its the same as <code>n</code>.</td>
269     </tr>
270     <tr>
271       <td style="vertical-align: top;"><b><a name="float"><b>float</b></a></b></td>
272       <td style="vertical-align: top; text-align: left;">A floating point value encoded 
273         as a 32-bit IEEE value written in little-endian form.<br>
274       </td>
275     </tr>
276     <tr>
277       <td style="vertical-align: top;"><b><b><a name="double"><b>double</b></a></b></b></td>
278       <td style="vertical-align: top; text-align: left;">A floating point value encoded 
279         as a64-bit IEEE value written in little-endian form</td>
280     </tr>
281     <tr>
282       <td><a name="string"><b>string</b></a></td>
283       <td class="td_left">A uint32_vbr indicating the type of the
284 constant string which also includes its length, immediately followed by
285 the characters of the string. There is no terminating null byte in the
286 string.</td>
287     </tr>
288     <tr>
289       <td><a name="data"><b>data</b></a></td>
290       <td class="td_left">An arbitrarily long segment of data to which
291 no interpretation is implied. This is used for constant initializers.<br>
292       </td>
293     </tr>
294     <tr>
295       <td><a name="llist"><b>llist(x)</b></a></td>
296       <td class="td_left">A length list of x. This means the list is
297 encoded as an <a href="#uint32_vbr">uint32_vbr</a> providing the
298 length of the list, followed by a sequence of that many "x" items. This
299 implies that the reader should iterate the number of times provided by
300 the length.</td>
301     </tr>
302     <tr>
303       <td><a name="zlist"><b>zlist(x)</b></a></td>
304       <td class="td_left">A zero-terminated list of x. This means the
305 list is encoded as a sequence of an indeterminate number of "x" items,
306 followed by an <a href="#uint32_vbr">uint32_vbr</a> terminating value.
307 This implies that none of the "x" items can have a zero value (or else
308 the list terminates).</td>
309     </tr>
310     <tr>
311       <td><a name="block"><b>block</b></a></td>
312       <td class="td_left">A block of data that is logically related. A
313 block is an unsigned 32-bit integer that encodes the type of the block
314 in the low 5 bits and the size of the block in the high 27 bits. The
315 length does not include the block header or any alignment bytes at the
316 end of the block. Blocks may compose other blocks. </td>
317     </tr>
318   </tbody>
319 </table>
320 </div>
321 <!-- _______________________________________________________________________ -->
322 <div class="doc_subsection"><a name="notation">Field Notation</a> </div>
323 <div class="doc_text">
324 <p>In the detailed block and field descriptions that follow, a regex
325 like notation is used to describe optional and repeated fields. A very
326 limited subset of regex is used to describe these, as given in the
327 following table: </p>
328 <table class="doc_table">
329   <tbody>
330     <tr>
331       <th><b>Character</b></th>
332       <th class="td_left"><b>Meaning</b></th>
333     </tr>
334     <tr>
335       <td><b><code>?</code></b></td>
336       <td class="td_left">The question mark indicates 0 or 1
337 occurrences of the thing preceding it.</td>
338     </tr>
339     <tr>
340       <td><b><code>*</code></b></td>
341       <td class="td_left">The asterisk indicates 0 or more occurrences
342 of the thing preceding it.</td>
343     </tr>
344     <tr>
345       <td><b><code>+</code></b></td>
346       <td class="td_left">The plus sign indicates 1 or more occurrences
347 of the thing preceding it.</td>
348     </tr>
349     <tr>
350       <td><b><code>()</code></b></td>
351       <td class="td_left">Parentheses are used for grouping.</td>
352     </tr>
353     <tr>
354       <td><b><code>,</code></b></td>
355       <td class="td_left">The comma separates sequential fields.</td>
356     </tr>
357   </tbody>
358 </table>
359 <p>So, for example, consider the following specifications:</p>
360 <div class="doc_code">
361 <ol>
362   <li><code>string?</code></li>
363   <li><code>(uint32_vbr,uin32_vbr)+</code></li>
364   <li><code>(unsigned?,uint32_vbr)*</code></li>
365   <li><code>(llist(unsigned))?</code></li>
366 </ol>
367 </div>
368 <p>with the following interpretations:</p>
369 <ol>
370   <li>An optional string. Matches either nothing or a single string</li>
371   <li>One or more pairs of uint32_vbr.</li>
372   <li>Zero or more occurrences of either an unsigned followed by a
373 uint32_vbr or just a uint32_vbr.</li>
374   <li>An optional length list of unsigned values.</li>
375 </ol>
376 </div>
377 <!-- _______________________________________________________________________ -->
378 <div class="doc_subsection"><a name="slots">Slots</a> </div>
379 <div class="doc_text">
380 <p>The bytecode format uses the notion of a "slot" to reference Types
381 and Values. Since the bytecode file is a <em>direct</em> representation of
382 LLVM's intermediate representation, there is a need to represent pointers in
383 the file.  Slots are used for this purpose. For example, if one has the following
384 assembly:
385 </p>
386 <div class="doc_code"><code> %MyType = type { int, sbyte }<br>
387 %MyVar = external global %MyType
388 </code></div>
389 <p>there are two definitions. The definition of <tt>%MyVar</tt> uses <tt>%MyType</tt>.
390 In the C++ IR this linkage between <tt>%MyVar</tt> and <tt>%MyType</tt>
391 is explicit through the use of C++ pointers. In bytecode, however, there's no
392 ability to store memory addresses. Instead, we compute and write out
393 slot numbers for every Type and Value written to the file.</p>
394 <p>A slot number is simply an unsigned 32-bit integer encoded in the variable
395 bit rate scheme (see <a href="#encoding">encoding</a>). This ensures that
396 low slot numbers are encoded in one byte. Through various bits of magic LLVM
397 attempts to always keep the slot numbers low. The first attempt is to associate
398 slot numbers with their "type plane". That is, Values of the same type
399 are written to the bytecode file in a list (sequentially). Their order in 
400 that list determines their slot number. This means that slot #1 doesn't mean
401 anything unless you also specify for which type you want slot #1. Types are
402 always written to the file first (in the <a href="#globaltypes">Global Type 
403 Pool</a>) and in such a way that both forward and backward references of the 
404 types can often be resolved with a single pass through the type pool. </p>
405 <p>Slot numbers are also kept small by rearranging their order. Because
406 of the structure of LLVM, certain values are much more likely to be used
407 frequently in the body of a function. For this reason, a compaction table is
408 provided in the body of a function if its use would make the function body 
409 smaller.  Suppose you have a function body that uses just the types "int*" and
410 "{double}" but uses them thousands of time. Its worthwhile to ensure that the 
411 slot number for these types are low so they can be encoded in a single byte 
412 (via vbr). This is exactly what the compaction table does.</p>
413 <p>In summary then, a slot number can be though of as just a vbr encoded index 
414 into a list of Type* or Value*. To keep slot numbers low, Value* are indexed by
415 two slot numbers: the "type plane index" (type slot) and the "value index"
416 (value slot).</p>
417 </div>
418 <!-- *********************************************************************** -->
419 <div class="doc_section"> <a name="general">General Structure</a> </div>
420 <!-- *********************************************************************** -->
421 <div class="doc_text">
422 <p>This section provides the general structure of the LLVM bytecode
423 file format. The bytecode file format requires blocks to be in a
424 certain order and nested in a particular way so that an LLVM module can
425 be constructed efficiently from the contents of the file. This ordering
426 defines a general structure for bytecode files as shown below. The
427 table below shows the order in which all block types may appear. Please
428 note that some of the blocks are optional and some may be repeated. The
429 structure is fairly loose because optional blocks, if empty, are
430 completely omitted from the file.</p>
431 <table>
432   <tbody>
433     <tr>
434       <th>ID</th>
435       <th>Parent</th>
436       <th>Optional?</th>
437       <th>Repeated?</th>
438       <th>Level</th>
439       <th>Block Type</th>
440       <th>Description</th>
441     </tr>
442     <tr>
443       <td>N/A</td>
444       <td>File</td>
445       <td>No</td>
446       <td>No</td>
447       <td>0</td>
448       <td class="td_left"><a href="#signature">Signature</a></td>
449       <td class="td_left">This contains the file signature (magic
450 number) that identifies the file as LLVM bytecode.</td>
451     </tr>
452     <tr>
453       <td>0x01</td>
454       <td>File</td>
455       <td>No</td>
456       <td>No</td>
457       <td>0</td>
458       <td class="td_left"><a href="#module">Module</a></td>
459       <td class="td_left">This is the top level block in a bytecode
460 file. It contains all the other blocks. </td>
461     </tr>
462     <tr>
463       <td>0x06</td>
464       <td>Module</td>
465       <td>No</td>
466       <td>No</td>
467       <td>1</td>
468       <td class="td_left">&nbsp;&nbsp;&nbsp;<a href="#globaltypes">Global&nbsp;Type&nbsp;Pool</a></td>
469       <td class="td_left">This block contains all the global (module)
470 level types.</td>
471     </tr>
472     <tr>
473       <td>0x05</td>
474       <td>Module</td>
475       <td>No</td>
476       <td>No</td>
477       <td>1</td>
478       <td class="td_left">&nbsp;&nbsp;&nbsp;<a href="#globalinfo">Module&nbsp;Globals&nbsp;Info</a></td>
479       <td class="td_left">This block contains the type, constness, and
480 linkage for each of the global variables in the module. It also
481 contains the type of the functions and the constant initializers.</td>
482     </tr>
483     <tr>
484       <td>0x03</td>
485       <td>Module</td>
486       <td>Yes</td>
487       <td>No</td>
488       <td>1</td>
489       <td class="td_left">&nbsp;&nbsp;&nbsp;<a href="#constantpool">Module&nbsp;Constant&nbsp;Pool</a></td>
490       <td class="td_left">This block contains all the global constants
491 except function arguments, global values and constant strings.</td>
492     </tr>
493     <tr>
494       <td>0x02</td>
495       <td>Module</td>
496       <td>Yes</td>
497       <td>Yes</td>
498       <td>1</td>
499       <td class="td_left">&nbsp;&nbsp;&nbsp;<a href="#functiondefs">Function&nbsp;Definitions</a>*</td>
500       <td class="td_left">One function block is written for each
501 function in the module. The function block contains the instructions,
502 compaction table, type constant pool, and symbol table for the function.</td>
503     </tr>
504     <tr>
505       <td>0x03</td>
506       <td>Function</td>
507       <td>Yes</td>
508       <td>No</td>
509       <td>2</td>
510       <td class="td_left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a
511  href="#constantpool">Function&nbsp;Constant&nbsp;Pool</a></td>
512       <td class="td_left">Any constants (including types) used solely
513 within the function are emitted here in the function constant pool. </td>
514     </tr>
515     <tr>
516       <td>0x08</td>
517       <td>Function</td>
518       <td>Yes</td>
519       <td>No</td>
520       <td>2</td>
521       <td class="td_left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a
522  href="#compactiontable">Compaction&nbsp;Table</a></td>
523       <td class="td_left">This table reduces bytecode size by providing
524 a funtion-local mapping of type and value slot numbers to their global
525 slot numbers</td>
526     </tr>
527     <tr>
528       <td>0x07</td>
529       <td>Function</td>
530       <td>No</td>
531       <td>No</td>
532       <td>2</td>
533       <td class="td_left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a
534  href="#instructionlist">Instruction&nbsp;List</a></td>
535       <td class="td_left">This block contains all the instructions of
536 the function. The basic blocks are inferred by terminating
537 instructions. </td>
538     </tr>
539     <tr>
540       <td>0x04</td>
541       <td>Function</td>
542       <td>Yes</td>
543       <td>No</td>
544       <td>2</td>
545       <td class="td_left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a
546  href="#symtab">Function&nbsp;Symbol&nbsp;Table</a></td>
547       <td class="td_left">This symbol table provides the names for the
548 function specific values used (basic block labels mostly).</td>
549     </tr>
550     <tr>
551       <td>0x04</td>
552       <td>Module</td>
553       <td>Yes</td>
554       <td>No</td>
555       <td>1</td>
556       <td class="td_left">&nbsp;&nbsp;&nbsp;<a href="#symtab">Module&nbsp;Symbol&nbsp;Table</a></td>
557       <td class="td_left">This symbol table provides the names for the
558 various entries in the file that are not function specific (global
559 vars, and functions mostly).</td>
560     </tr>
561   </tbody>
562 </table>
563 <p>Use the links in the table for details about the contents of each of
564 the block types.</p>
565 </div>
566 <!-- *********************************************************************** -->
567 <div class="doc_section"> <a name="blockdefs">Block Definitions</a> </div>
568 <!-- *********************************************************************** -->
569 <div class="doc_text">
570 <p>This section provides the detailed layout of the individual block
571 types in the LLVM bytecode file format. </p>
572 </div>
573 <!-- _______________________________________________________________________ -->
574 <div class="doc_subsection"><a name="signature">Signature Block</a> </div>
575 <div class="doc_text">
576 <p>The signature occurs in every LLVM bytecode file and is always first.
577 It simply provides a few bytes of data to identify the file as being an LLVM
578 bytecode file. This block is always four bytes in length and differs from the
579 other blocks because there is no identifier and no block length at the start
580 of the block. Essentially, this block is just the "magic number" for the file.
581 </p>
582 <table>
583   <tbody>
584     <tr>
585       <th><b>Type</b></th>
586       <th class="td_left"><b>Field Description</b></th>
587     </tr>
588     <tr>
589       <td><a href="#char">char</a></td>
590       <td class="td_left">Constant "l" (0x6C)</td>
591     </tr>
592     <tr>
593       <td><a href="#char">char</a></td>
594       <td class="td_left">Constant "l" (0x6C)</td>
595     </tr>
596     <tr>
597       <td><a href="#char">char</a></td>
598       <td class="td_left">Constant "v" (0x76)</td>
599     </tr>
600     <tr>
601       <td><a href="#char">char</a></td>
602       <td class="td_left">Constant "m" (0x6D)</td>
603     </tr>
604   </tbody>
605 </table>
606 </div>
607 <!-- _______________________________________________________________________ -->
608 <div class="doc_subsection"><a name="module">Module Block</a> </div>
609 <div class="doc_text">
610 <p>The module block contains a small pre-amble and all the other blocks in
611 the file. The table below shows the structure of the module block. Note that it
612 only provides the module identifier, size of the module block, and the format
613 information. Everything else is contained in other blocks, described in other
614 sections.</p>
615 <table>
616   <tbody>
617     <tr>
618       <th><b>Type</b></th>
619       <th class="td_left"><b>Field Description</b></th>
620     </tr>
621     <tr>
622       <td><a href="#unsigned">unsigned</a><br></td>
623       <td class="td_left"><a href="#mod_header">Module Block Identifier
624           (0x01)</a></td>
625     </tr>
626     <tr>
627       <td><a href="#unsigned">unsigned</a></td>
628       <td class="td_left"><a href="#mod_header">Module Block Size</a></td>
629     </tr>
630     <tr>
631       <td><a href="#uint32_vbr">uint32_vbr</a></td>
632       <td class="td_left"><a href="#format">Format Information</a></td>
633     </tr>
634     <tr>
635       <td><a href="#block">block</a></td>
636       <td class="td_left"><a href="#globaltypes">Global Type Pool</a></td>
637     </tr>
638     <tr>
639       <td><a href="#block">block</a></td>
640       <td class="td_left"><a href="#globalinfo">Module Globals Info</a></td>
641     </tr>
642     <tr>
643       <td><a href="#block">block</a></td>
644       <td class="td_left"><a href="#constantpool">Module Constant Pool</a></td>
645     </tr>
646     <tr>
647       <td><a href="#block">block</a>*</td>
648       <td class="td_left"><a href="#functiondefs">Function Definitions</a></td>
649     </tr>
650     <tr>
651       <td><a href="#block">block</a></td>
652       <td class="td_left"><a href="#symtab">Module Symbol Table</a></td>
653     </tr>
654   </tbody>
655 </table>
656 </div>
657
658 <!-- _______________________________________________________________________ -->
659 <div class="doc_subsubsection"><a name="mod_header">Module Block Header</a></div>
660 <div class="doc_text">
661   <p>The block header for the module block uses a longer format than the other
662   blocks in a bytecode file. Specifically, instead of encoding the type and size
663   of the block into a 32-bit integer with 5-bits for type and 27-bits for size,
664   the module block header uses two 32-bit unsigned values, one for type, and one
665   for size. While the 2<sup>27</sup> byte limit on block size is sufficient for the blocks
666   contained in the module, it isn't sufficient for the module block itself
667   because we want to ensure that bytecode files as large as 2<sup>32</sup> bytes
668   are possible. For this reason, the module block (and only the module block)
669   uses a long format header.</p>
670 </div>
671
672 <!-- _______________________________________________________________________ -->
673 <div class="doc_subsubsection"><a name="format">Format Information</a></div>
674 <div class="doc_text">
675 <p>The format information field is encoded into a <a href="#uint32_vbr">uint32_vbr</a>
676 as shown in the following table.</p>
677 <table>
678   <tbody>
679     <tr>
680       <th><b>Type</b></th>
681       <th class="td_left"><b>Description</b></th>
682     </tr>
683     <tr>
684       <td><a href="#bit">bit(0)</a></td>
685       <td class="td_left">Target is big endian?</td>
686     </tr>
687     <tr>
688       <td><a href="#bit">bit(1)</a></td>
689       <td class="td_left">On target pointers are 64-bit?</td>
690     </tr>
691     <tr>
692       <td><a href="#bit">bit(2)</a></td>
693       <td class="td_left">Target has no endianess?</td>
694     </tr>
695     <tr>
696       <td><a href="#bit">bit(3)</a></td>
697       <td class="td_left">Target has no pointer size?</td>
698     </tr>
699     <tr>
700       <td><a href="#bit">bit(4-31)</a></td>
701       <td class="td_left">Bytecode format version</td>
702     </tr>
703   </tbody>
704 </table>
705 <p>
706 Of particular note, the bytecode format number is simply a 28-bit
707 monotonically increase integer that identifies the version of the bytecode
708 format (which is not directly related to the LLVM release number). The
709 bytecode versions defined so far are (note that this document only
710 describes the latest version, 1.3):</p>
711 <ul>
712   <li>#0: LLVM 1.0 &amp; 1.1</li>
713   <li>#1: LLVM 1.2</li>
714   <li>#2: LLVM 1.2.5 (not released)</li>
715   <li>#3: LLVM 1.3<br>
716   </li>
717 </ul>
718 <p>Note that we plan to eventually expand the target description
719 capabilities
720 of bytecode files to <a href="http://llvm.cs.uiuc.edu/PR263">target
721 triples</a>.
722 </p>
723 </div>
724 <!-- _______________________________________________________________________ -->
725 <div class="doc_subsection"><a name="globaltypes">Global Type Pool</a> </div>
726 <div class="doc_text">
727 <p>The global type pool consists of type definitions. Their order of appearance
728 in the file determines their type slot number (0 based). Slot numbers are
729 used to replace pointers in the intermediate representation. Each slot number 
730 uniquely identifies one entry in a type plane (a collection of values of the
731 same type).  Since all values have types and are associated with the order in 
732 which the type pool is written, the global type pool <em>must</em> be written 
733 as the first block of a module. If it is not, attempts to read the file will
734 fail because both forward and backward type resolution will not be possible.</p>
735 <p>The type pool is simply a list of type definitions, as shown in the
736 table below.</p>
737 <table>
738   <tbody>
739     <tr>
740       <th><b>Type</b></th>
741       <th class="td_left"><b>Field Description</b></th>
742     </tr>
743     <tr>
744       <td><a href="#unsigned">block</a></td>
745       <td class="td_left">Type Pool Identifier (0x06) + Size<br>
746       </td>
747     </tr>
748     <tr>
749       <td><a href="#llist">llist</a>(<a href="#type">type</a>)</td>
750       <td class="td_left">A length list of type definitions.</td>
751     </tr>
752   </tbody>
753 </table>
754 </div>
755 <!-- _______________________________________________________________________ -->
756 <div class="doc_subsubsection"><a name="type">Type Definitions</a></div>
757 <div class="doc_text">
758 <p>Types in the type pool are defined using a different format for each kind
759 of type, as given in the following sections.</p>
760 <h3>Primitive Types</h3>
761 <p>The primitive types encompass the basic integer and floating point
762 types. They are encoded simply as their TypeID.</p>
763 <table>
764   <tbody>
765     <tr>
766       <th><b>Type</b></th>
767       <th class="td_left"><b>Description</b></th>
768     </tr>
769     <tr>
770       <td><a href="#uint24_vbr">uint24_vbr</a></td>
771       <td class="td_left">Type ID for the primitive types (values 1 to
772 11) <sup>1</sup></td>
773     </tr>
774   </tbody>
775 </table>
776 Notes:
777 <ol>
778   <li>The values for the Type IDs for the primitive types are provided
779 by the definition of the <code>llvm::Type::TypeID</code> enumeration
780 in <code>include/llvm/Type.h</code>. The enumeration gives the
781 following mapping:
782     <ol>
783       <li>bool</li>
784       <li>ubyte</li>
785       <li>sbyte</li>
786       <li>ushort</li>
787       <li>short</li>
788       <li>uint</li>
789       <li>int</li>
790       <li>ulong</li>
791       <li>long</li>
792       <li>float</li>
793       <li>double</li>
794     </ol>
795   </li>
796 </ol>
797 <h3>Function Types</h3>
798 <table>
799   <tbody>
800     <tr>
801       <th><b>Type</b></th>
802       <th class="td_left"><b>Description</b></th>
803     </tr>
804     <tr>
805       <td><a href="#uint24_vbr">uint24_vbr</a></td>
806       <td class="td_left">Type ID for function types (13)</td>
807     </tr>
808     <tr>
809       <td><a href="#uint24_vbr">uint24_vbr</a></td>
810       <td class="td_left">Type slot number of function's return type.</td>
811     </tr>
812     <tr>
813       <td><a href="#llist">llist</a>(<a href="#uint24_vbr">uint24_vbr</a>)</td>
814       <td class="td_left">Type slot number of each argument's type.</td>
815     </tr>
816     <tr>
817       <td><a href="#uint32_vbr">uint32_vbr</a>?</td>
818       <td class="td_left">Value 0 if this is a varargs function,
819 missing otherwise.</td>
820     </tr>
821   </tbody>
822 </table>
823 <h3>Structure Types</h3>
824 <table>
825   <tbody>
826     <tr>
827       <th><b>Type</b></th>
828       <th class="td_left"><b>Description</b></th>
829     </tr>
830     <tr>
831       <td><a href="#uint24_vbr">uint24_vbr</a></td>
832       <td class="td_left">Type ID for structure types (14)</td>
833     </tr>
834     <tr>
835       <td><a href="#zlist">zlist</a>(<a href="#uint24_vbr">uint24_vbr</a>)</td>
836       <td class="td_left">Slot number of each of the element's fields.</td>
837     </tr>
838   </tbody>
839 </table>
840 <h3>Array Types</h3>
841 <table>
842   <tbody>
843     <tr>
844       <th><b>Type</b></th>
845       <th class="td_left"><b>Description</b></th>
846     </tr>
847     <tr>
848       <td><a href="#uint24_vbr">uint24_vbr</a></td>
849       <td class="td_left">Type ID for Array Types (15)</td>
850     </tr>
851     <tr>
852       <td><a href="#uint24_vbr">uint24_vbr</a></td>
853       <td class="td_left">Type slot number of array's element type.</td>
854     </tr>
855     <tr>
856       <td><a href="#uint32_vbr">uint32_vbr</a></td>
857       <td class="td_left">The number of elements in the array.</td>
858     </tr>
859   </tbody>
860 </table>
861 <h3>Pointer Types</h3>
862 <table>
863   <tbody>
864     <tr>
865       <th><b>Type</b></th>
866       <th class="td_left"><b>Description</b></th>
867     </tr>
868     <tr>
869       <td><a href="#uint24_vbr">uint24_vbr</a></td>
870       <td class="td_left">Type ID For Pointer Types (16)</td>
871     </tr>
872     <tr>
873       <td><a href="#uint24_vbr">uint24_vbr</a></td>
874       <td class="td_left">Type slot number of pointer's element type.</td>
875     </tr>
876   </tbody>
877 </table>
878 <h3>Opaque Types</h3>
879 <table>
880   <tbody>
881     <tr>
882       <th><b>Type</b></th>
883       <th class="td_left"><b>Description</b></th>
884     </tr>
885     <tr>
886       <td><a href="#uint24_vbr">uint24_vbr</a></td>
887       <td class="td_left">Type ID For Opaque Types (17)</td>
888     </tr>
889   </tbody>
890 </table>
891 <h3>Packed Types</h3>
892 <table>
893   <tbody>
894     <tr>
895       <th><b>Type</b></th>
896       <th class="td_left"><b>Description</b></th>
897     </tr>
898     <tr>
899       <td><a href="#uint24_vbr">uint24_vbr</a></td>
900       <td class="td_left">Type ID for Packed Types (18)</td>
901     </tr>
902     <tr>
903       <td><a href="#uint24_vbr">uint24_vbr</a></td>
904       <td class="td_left">Slot number of packed vector's element type.</td>
905     </tr>
906     <tr>
907       <td><a href="#uint32_vbr">uint32_vbr</a></td>
908       <td class="td_left">The number of elements in the packed vector.</td>
909     </tr>
910   </tbody>
911 </table>
912 </div>
913 <!-- _______________________________________________________________________ -->
914 <div class="doc_subsection"><a name="globalinfo">Module Global Info</a>
915 </div>
916 <div class="doc_text">
917 <p>The module global info block contains the definitions of all global
918 variables including their initializers and the <em>declaration</em> of
919 all functions. The format is shown in the table below:</p>
920 <table>
921   <tbody>
922     <tr>
923       <th><b>Type</b></th>
924       <th class="td_left"><b>Field Description</b></th>
925     </tr>
926     <tr>
927       <td><a href="#block">block</a></td>
928       <td class="td_left">Module global info identifier (0x05) + size<br>
929       </td>
930     </tr>
931     <tr>
932       <td><a href="#zlist">zlist</a>(<a href="#globalvar">globalvar</a>)</td>
933       <td class="td_left">A zero terminated list of global var
934 definitions occurring in the module.</td>
935     </tr>
936     <tr>
937       <td><a href="#zlist">zlist</a>(<a href="#uint24_vbr">uint24_vbr</a>)</td>
938       <td class="td_left">A zero terminated list of function types
939 occurring in the module.</td>
940     </tr>
941     <tr>
942       <td style="vertical-align: top;"><a href="#llist">llist</a>(<a
943  href="#string">string</a>)<br>
944       </td>
945       <td style="vertical-align: top; text-align: left;">A length list
946 of strings that specify the names of the libraries that this module
947 depends upon.<br>
948       </td>
949     </tr>
950     <tr>
951       <td style="vertical-align: top;"><a href="#string">string</a><br>
952       </td>
953       <td style="vertical-align: top; text-align: left;">The target
954 triple for the module (blank means no target triple specified, i.e. a
955 platform independent module).<br>
956       </td>
957     </tr>
958   </tbody>
959 </table>
960 </div>
961 <!-- _______________________________________________________________________ -->
962 <div class="doc_subsubsection"><a name="globalvar">Global Variable Field</a>
963 </div>
964 <div class="doc_text">
965 <p>Global variables are written using an <a href="#uint32_vbr">uint32_vbr</a>
966 that encodes information about the global variable and a list of the
967 constant initializers for the global var, if any.</p>
968 <p>The table below provides the bit layout of the first <a
969  href="#uint32_vbr">uint32_vbr</a> that describes the global variable.</p>
970 <table>
971   <tbody>
972     <tr>
973       <th><b>Type</b></th>
974       <th class="td_left"><b>Description</b></th>
975     </tr>
976     <tr>
977       <td><a href="#bit">bit(0)</a></td>
978       <td class="td_left">Is constant?</td>
979     </tr>
980     <tr>
981       <td><a href="#bit">bit(1)</a></td>
982       <td class="td_left">Has initializer? Note that this bit
983 determines whether the constant initializer field (described below)
984 follows. </td>
985     </tr>
986     <tr>
987       <td><a href="#bit">bit(2-4)</a></td>
988       <td class="td_left">Linkage type: 0=External, 1=Weak,
989 2=Appending, 3=Internal, 4=LinkOnce</td>
990     </tr>
991     <tr>
992       <td><a href="#bit">bit(5-31)</a></td>
993       <td class="td_left">Type slot number of type for the global variable.</td>
994     </tr>
995   </tbody>
996 </table>
997 <p>The table below provides the format of the constant initializers for
998 the global variable field, if it has one.</p>
999 <table>
1000   <tbody>
1001     <tr>
1002       <th><b>Type</b></th>
1003       <th class="td_left"><b>Description</b></th>
1004     </tr>
1005     <tr>
1006       <td>(<a href="#zlist">zlist</a>(<a href="#uint32_vbr">uint32_vbr</a>))?
1007       </td>
1008       <td class="td_left">An optional zero-terminated list of value slot
1009 numbers of the global variable's constant initializer.</td>
1010     </tr>
1011   </tbody>
1012 </table>
1013 </div>
1014 <!-- _______________________________________________________________________ -->
1015 <div class="doc_subsection"><a name="constantpool">Constant Pool</a> </div>
1016 <div class="doc_text">
1017 <p>A constant pool defines as set of constant values. There are
1018 actually two types of constant pool blocks: one for modules and one for
1019 functions. For modules, the block begins with the constant strings
1020 encountered anywhere in the module. For functions, the block begins
1021 with types only encountered in the function. In both cases the header
1022 is identical. The tables that follow, show the header, module constant
1023 pool preamble, function constant pool preamble, and the part common to
1024 both function and module constant pools.</p>
1025 <p><b>Common Block Header</b></p>
1026 <table>
1027   <tbody>
1028     <tr>
1029       <th><b>Type</b></th>
1030       <th class="td_left"><b>Field Description</b></th>
1031     </tr>
1032     <tr>
1033       <td><a href="#block">block</a></td>
1034       <td class="td_left">Constant pool identifier (0x03) + size<br>
1035       </td>
1036     </tr>
1037   </tbody>
1038 </table>
1039 <p><b>Module Constant Pool Preamble (constant strings)</b></p>
1040 <table>
1041   <tbody>
1042     <tr>
1043       <th><b>Type</b></th>
1044       <th class="td_left"><b>Field Description</b></th>
1045     </tr>
1046     <tr>
1047       <td><a href="#uint32_vbr">uint32_vbr</a></td>
1048       <td class="td_left">The number of constant strings that follow.</td>
1049     </tr>
1050     <tr>
1051       <td><a href="#uint32_vbr">uint32_vbr</a></td>
1052       <td class="td_left">Zero. This identifies the following "plane"
1053 as containing the constant strings. This is needed to identify it
1054 uniquely from other constant planes that follow. </td>
1055     </tr>
1056     <tr>
1057       <td><a href="#uint24_vbr">uint24_vbr</a>+</td>
1058       <td class="td_left">Type slot number of the constant string's type.
1059 Note that the constant string's type implicitly defines the length of
1060 the string. </td>
1061     </tr>
1062   </tbody>
1063 </table>
1064 <p><b>Function Constant Pool Preamble (function types)</b></p>
1065 <p>The structure of the types for functions is identical to the <a
1066  href="#globaltypes">Global Type Pool</a>. Please refer to that section
1067 for the details. </p>
1068 <p><b>Common Part (other constants)</b></p>
1069 <table>
1070   <tbody>
1071     <tr>
1072       <th><b>Type</b></th>
1073       <th class="td_left"><b>Field Description</b></th>
1074     </tr>
1075     <tr>
1076       <td><a href="#uint32_vbr">uint32_vbr</a></td>
1077       <td class="td_left">Number of entries in this type plane.</td>
1078     </tr>
1079     <tr>
1080       <td><a href="#uint24_vbr">uint24_vbr</a></td>
1081       <td class="td_left">Type slot number of this plane.</td>
1082     </tr>
1083     <tr>
1084       <td><a href="#constant">constant</a>+</td>
1085       <td class="td_left">The definition of a constant (see below).</td>
1086     </tr>
1087   </tbody>
1088 </table>
1089 </div>
1090 <!-- _______________________________________________________________________ -->
1091 <div class="doc_subsubsection"><a name="constant">Constant Field</a></div>
1092 <div class="doc_text">
1093 <p>Constants come in many shapes and flavors. The sections that follow
1094 define the format for each of them. All constants start with a <a
1095  href="#uint32_vbr">uint32_vbr</a> encoded integer that provides the
1096 number of operands for the constant. For primitive, structure, and
1097 array constants, this will always be zero since those types of
1098 constants have no operands. In this case, we have the following field
1099 definitions:</p>
1100 <ul>
1101   <li><b>Bool</b>. This is written as an <a href="#uint32_vbr">uint32_vbr</a>
1102 of value 1U or 0U.</li>
1103   <li><b>Signed Integers (sbyte,short,int,long)</b>. These are written
1104 as an <a href="#int64_vbr">int64_vbr</a> with the corresponding value.</li>
1105   <li><b>Unsigned Integers (ubyte,ushort,uint,ulong)</b>. These are
1106 written as an <a href="#uint64_vbr">uint64_vbr</a> with the
1107 corresponding value. </li>
1108   <li><b>Floating Point</b>. Both the float and double types are
1109 written literally in binary format.</li>
1110   <li><b>Arrays</b>. Arrays are written simply as a list of <a
1111  href="#uint32_vbr">uint32_vbr</a> encoded value slot numbers to the constant
1112 element values.</li>
1113   <li><b>Structures</b>. Structures are written simply as a list of <a
1114  href="#uint32_vbr">uint32_vbr</a> encoded value slot numbers to the constant
1115 field values of the structure.</li>
1116 </ul>
1117 <p>When the number of operands to the constant is non-zero, we have a
1118 constant expression and its field format is provided in the table below.</p>
1119 <table>
1120   <tbody>
1121     <tr>
1122       <th><b>Type</b></th>
1123       <th class="td_left"><b>Field Description</b></th>
1124     </tr>
1125     <tr>
1126       <td><a href="#uint32_vbr">uint32_vbr</a></td>
1127       <td class="td_left">Op code of the instruction for the constant
1128 expression.</td>
1129     </tr>
1130     <tr>
1131       <td><a href="#uint32_vbr">uint32_vbr</a></td>
1132       <td class="td_left">The value slot number of the constant value for an
1133 operand.<sup>1</sup></td>
1134     </tr>
1135     <tr>
1136       <td><a href="#uint24_vbr">uint24_vbr</a></td>
1137       <td class="td_left">The type slot number for the type of the constant
1138 value for an operand.<sup>1</sup></td>
1139     </tr>
1140   </tbody>
1141 </table>
1142 Notes:
1143 <ol>
1144   <li>Both these fields are repeatable but only in pairs.</li>
1145 </ol>
1146 </div>
1147 <!-- _______________________________________________________________________ -->
1148 <div class="doc_subsection"><a name="functiondefs">Function Definition</a></div>
1149 <div class="doc_text">
1150 <p>Function definitions contain the linkage, constant pool or
1151 compaction table, instruction list, and symbol table for a function.
1152 The following table shows the structure of a function definition.</p>
1153 <table>
1154   <tbody>
1155     <tr>
1156       <th><b>Type</b></th>
1157       <th class="td_left"><b>Field Description</b></th>
1158     </tr>
1159     <tr>
1160       <td><a href="#block">block</a><br>
1161       </td>
1162       <td class="td_left">Function definition block identifier (0x02) +
1163 size<br>
1164       </td>
1165     </tr>
1166     <tr>
1167       <td><a href="#uint32_vbr">uint32_vbr</a></td>
1168       <td class="td_left">The linkage type of the function: 0=External,
1169 1=Weak, 2=Appending, 3=Internal, 4=LinkOnce<sup>1</sup></td>
1170     </tr>
1171     <tr>
1172       <td><a href="#block">block</a></td>
1173       <td class="td_left">The <a href="#constantpool">constant pool</a>
1174 block for this function.<sup>2</sup></td>
1175     </tr>
1176     <tr>
1177       <td><a href="#block">block</a></td>
1178       <td class="td_left">The <a href="#compactiontable">compaction
1179 table</a> block for the function.<sup>2</sup></td>
1180     </tr>
1181     <tr>
1182       <td><a href="#block">block</a></td>
1183       <td class="td_left">The <a href="#instructionlist">instruction
1184 list</a> for the function.</td>
1185     </tr>
1186     <tr>
1187       <td><a href="#block">block</a></td>
1188       <td class="td_left">The function's <a href="#symtab">symbol
1189 table</a> containing only those symbols pertinent to the function
1190 (mostly block labels).</td>
1191     </tr>
1192   </tbody>
1193 </table>
1194 Notes:
1195 <ol>
1196   <li>Note that if the linkage type is "External" then none of the
1197 other fields will be present as the function is defined elsewhere.</li>
1198   <li>Note that only one of the constant pool or compaction table will
1199 be written. Compaction tables are only written if they will actually
1200 save bytecode space. If not, then a regular constant pool is written.</li>
1201 </ol>
1202 </div>
1203 <!-- _______________________________________________________________________ -->
1204 <div class="doc_subsection"><a name="compactiontable">Compaction Table</a>
1205 </div>
1206 <div class="doc_text">
1207 <p>Compaction tables are part of a function definition. They are merely
1208 a device for reducing the size of bytecode files. The size of a
1209 bytecode file is dependent on the <em>values</em> of the slot numbers
1210 used because larger values use more bytes in the variable bit rate
1211 encoding scheme. Furthermore, the compressed instruction format
1212 reserves only six bits for the type of the instruction. In large
1213 modules, declaring hundreds or thousands of types, the values of the
1214 slot numbers can be quite large. However, functions may use only a
1215 small fraction of the global types. In such cases a compaction table is
1216 created that maps the global type and value slot numbers to smaller
1217 values used by a function. Functions will contain either a
1218 function-specific constant pool <em>or</em> a compaction table but not
1219 both. Compaction tables have the format shown in the table below.</p>
1220 <table>
1221   <tbody>
1222     <tr>
1223       <th><b>Type</b></th>
1224       <th class="td_left"><b>Field Description</b></th>
1225     </tr>
1226     <tr>
1227       <td><a href="#uint32_vbr">uint32_vbr</a></td>
1228       <td class="td_left">The number of types that follow</td>
1229     </tr>
1230     <tr>
1231       <td><a href="#uint24_vbr">uint24_vbr</a>+</td>
1232       <td class="td_left">The type slot number in the global types of
1233 the type that will be referenced in the function with the index of this
1234 entry in the compaction table.</td>
1235     </tr>
1236     <tr>
1237       <td><a href="#type_len">type_len</a></td>
1238       <td class="td_left">An encoding of the type and number of values
1239 that follow. This field's encoding varies depending on the size of the
1240 type plane. See <a href="#type_len">Type and Length</a> for further
1241 details.</td>
1242     </tr>
1243     <tr>
1244       <td><a href="#uint32_vbr">uint32_vbr</a>+</td>
1245       <td class="td_left">The value slot number in the global values
1246 that will be referenced in the function with the index of this entry in
1247 the compaction table.</td>
1248     </tr>
1249   </tbody>
1250 </table>
1251 </div>
1252 <!-- _______________________________________________________________________ -->
1253 <div class="doc_subsubsection"><a name="type_len">Type and Length</a></div>
1254 <div class="doc_text">
1255 <p>The type and length of a compaction table type plane is encoded
1256 differently depending on the length of the plane. For planes of length
1257 1 or 2, the length is encoded into bits 0 and 1 of a <a
1258  href="#uint32_vbr">uint32_vbr</a> and the type is encoded into bits
1259 2-31. Because type numbers are often small, this often saves an extra
1260 byte per plane. If the length of the plane is greater than 2 then the
1261 encoding uses a <a href="#uint32_vbr">uint32_vbr</a> for each of the
1262 length and type, in that order.</p>
1263 </div>
1264 <!-- _______________________________________________________________________ -->
1265 <div class="doc_subsection"><a name="instructionlist">Instruction List</a></div>
1266 <div class="doc_text">
1267 <p>The instructions in a function are written as a simple list. Basic
1268 blocks are inferred by the terminating instruction types. The format of
1269 the block is given in the following table.</p>
1270 <table>
1271   <tbody>
1272     <tr>
1273       <th><b>Type</b></th>
1274       <th class="td_left"><b>Field Description</b></th>
1275     </tr>
1276     <tr>
1277       <td><a href="#block">block</a><br>
1278       </td>
1279       <td class="td_left">Instruction list identifier (0x07) + size<br>
1280       </td>
1281     </tr>
1282     <tr>
1283       <td><a href="#instruction">instruction</a>+</td>
1284       <td class="td_left">An instruction. Instructions have a variety
1285 of formats. See <a href="#instruction">Instructions</a> for details.</td>
1286     </tr>
1287   </tbody>
1288 </table>
1289 </div>
1290 <!-- _______________________________________________________________________ -->
1291 <div class="doc_subsubsection"><a name="instruction">Instructions</a></div>
1292 <div class="doc_text">
1293 <p>For brevity, instructions are written in one of four formats,
1294 depending on the number of operands to the instruction. Each
1295 instruction begins with a <a href="#uint32_vbr">uint32_vbr</a> that
1296 encodes the type of the instruction as well as other things. The tables
1297 that follow describe the format of this first part of each instruction.</p>
1298 <p><b>Instruction Format 0</b></p>
1299 <p>This format is used for a few instructions that can't easily be
1300 shortened because they have large numbers of operands (e.g. PHI Node or
1301 getelementptr). Each of the opcode, type, and operand fields is found in
1302 successive fields.</p>
1303 <table>
1304   <tbody>
1305     <tr>
1306       <th><b>Type</b></th>
1307       <th class="td_left"><b>Field Description</b></th>
1308     </tr>
1309     <tr>
1310       <td><a href="#uint32_vbr">uint32_vbr</a></td>
1311       <td class="td_left">Specifies the opcode of the instruction. Note
1312 that for compatibility with the other instruction formats, the opcode
1313 is shifted left by 2 bits. Bits 0 and 1 must have value zero for this
1314 format.</td>
1315     </tr>
1316     <tr>
1317       <td><a href="#uint24_vbr">uint24_vbr</a></td>
1318       <td class="td_left">Provides the type slot number of the result type of
1319         the instruction.</td>
1320     </tr>
1321     <tr>
1322       <td><a href="#uint32_vbr">uint32_vbr</a></td>
1323       <td class="td_left">The number of operands that follow.</td>
1324     </tr>
1325     <tr>
1326       <td><a href="#uint32_vbr">uint32_vbr</a>+</td>
1327       <td class="td_left">The slot number of the value(s) for the operand(s).
1328         <sup>1</sup></td>
1329     </tr>
1330   </tbody>
1331 </table>
1332 Notes:
1333 <ol>
1334   <li>Note that if the instruction is a getelementptr and the type of
1335 the operand is a sequential type (array or pointer) then the slot
1336 number is shifted up two bits and the low order bits will encode the
1337 type of index used, as follows: 0=uint, 1=int, 2=ulong, 3=long.</li>
1338 </ol>
1339 <p><b>Instruction Format 1</b></p>
1340 <p>This format encodes the opcode, type and a single operand into a
1341 single <a href="#uint32_vbr">uint32_vbr</a> as follows:</p>
1342 <table>
1343   <tbody>
1344     <tr>
1345       <th><b>Bits</b></th>
1346       <th><b>Type</b></th>
1347       <th class="td_left"><b>Field Description</b></th>
1348     </tr>
1349     <tr>
1350       <td>0-1</td>
1351       <td>constant "1"</td>
1352       <td class="td_left">These two bits must be the value 1 which identifies 
1353         this as an instruction of format 1.</td>
1354     </tr>
1355     <tr>
1356       <td>2-7</td>
1357       <td><a href="#opcode">opcode</a></td>
1358       <td class="td_left">Specifies the opcode of the instruction. Note that 
1359         the maximum opcode value is 63.</td>
1360     </tr>
1361     <tr>
1362       <td>8-19</td>
1363       <td><a href="#unsigned">unsigned</a></td>
1364       <td class="td_left">Specifies the slot number of the type for this 
1365         instruction. Maximum slot number is 2<sup>12</sup>-1=4095.</td>
1366     </tr>
1367     <tr>
1368       <td>20-31</td>
1369       <td><a href="#unsigned">unsigned</a></td>
1370       <td class="td_left">Specifies the slot number of the value for the 
1371         first operand. Maximum slot number is 2<sup>12</sup>-1=4095. Note that 
1372         the value 2<sup>12</sup>-1 denotes zero operands.</td>
1373     </tr>
1374   </tbody>
1375 </table>
1376 <p><b>Instruction Format 2</b></p>
1377 <p>This format encodes the opcode, type and two operands into a single <a
1378  href="#uint32_vbr">uint32_vbr</a> as follows:</p>
1379 <table>
1380   <tbody>
1381     <tr>
1382       <th><b>Bits</b></th>
1383       <th><b>Type</b></th>
1384       <th class="td_left"><b>Field Description</b></th>
1385     </tr>
1386     <tr>
1387       <td>0-1</td>
1388       <td>constant "2"</td>
1389       <td class="td_left">These two bits must be the value 2 which identifies 
1390         this as an instruction of format 2.</td>
1391     </tr>
1392     <tr>
1393       <td>2-7</td>
1394       <td><a href="#opcodes">opcode</a></td>
1395       <td class="td_left">Specifies the opcode of the instruction. Note that 
1396         the maximum opcode value is 63.</td>
1397     </tr>
1398     <tr>
1399       <td>8-15</td>
1400       <td><a href="#unsigned">unsigned</a></td>
1401       <td class="td_left">Specifies the slot number of the type for this 
1402         instruction. Maximum slot number is 2<sup>8</sup>-1=255.</td>
1403     </tr>
1404     <tr>
1405       <td>16-23</td>
1406       <td><a href="#unsigned">unsigned</a></td>
1407       <td class="td_left">Specifies the slot number of the value for the first 
1408         operand. Maximum slot number is 2<sup>8</sup>-1=255.</td>
1409     </tr>
1410     <tr>
1411       <td>24-31</td>
1412       <td><a href="#unsigned">unsigned</a></td>
1413       <td class="td_left">Specifies the slot number of the value for the second 
1414         operand. Maximum slot number is 2<sup>8</sup>-1=255.</td>
1415     </tr>
1416   </tbody>
1417 </table>
1418 <p><b>Instruction Format 3</b></p>
1419 <p>This format encodes the opcode, type and three operands into a
1420 single <a href="#uint32_vbr">uint32_vbr</a> as follows:</p>
1421 <table>
1422   <tbody>
1423     <tr>
1424       <th><b>Bits</b></th>
1425       <th><b>Type</b></th>
1426       <th class="td_left"><b>Field Description</b></th>
1427     </tr>
1428     <tr>
1429       <td>0-1</td>
1430       <td>constant "3"</td>
1431       <td class="td_left">These two bits must be the value 3 which identifies 
1432         this as an instruction of format 3.</td>
1433     </tr>
1434     <tr>
1435       <td>2-7</td>
1436       <td><a href="#opcodes">opcode</a></td>
1437       <td class="td_left">Specifies the opcode of the instruction. Note that 
1438         the maximum opcode value is 63.</td>
1439     </tr>
1440     <tr>
1441       <td>8-13</td>
1442       <td><a href="#unsigned">unsigned</a></td>
1443       <td class="td_left">Specifies the slot number of the type for this 
1444         instruction. Maximum slot number is 2<sup>6</sup>-1=63.</td>
1445     </tr>
1446     <tr>
1447       <td>14-19</td>
1448       <td><a href="#unsigned">unsigned</a></td>
1449       <td class="td_left">Specifies the slot number of the value for the first 
1450         operand. Maximum slot number is 2<sup>6</sup>-1=63.</td>
1451     </tr>
1452     <tr>
1453       <td>20-25</td>
1454       <td><a href="#unsigned">unsigned</a></td>
1455       <td class="td_left">Specifies the slot number of the value for the second
1456         operand. Maximum slot number is 2<sup>6</sup>-1=63.</td>
1457     </tr>
1458     <tr>
1459       <td>26-31</td>
1460       <td><a href="#unsigned">unsigned</a></td>
1461       <td class="td_left">Specifies the slot number of the value for the third
1462         operand. Maximum slot number is 2<sup>6</sup>-1=63.</td>
1463     </tr>
1464   </tbody>
1465 </table>
1466 </div>
1467
1468 <!-- _______________________________________________________________________ -->
1469 <div class="doc_subsection"><a name="opcodes">Opcodes</a></div>
1470 <div class="doc_text">
1471   <p>Instructions encode an opcode that identifies the kind of instruction.
1472   Opcodes are an enumerated integer value. The specific values used depend on
1473   the version of LLVM you're using. The opcode values are defined in the
1474   <a href="http://llvm.org/cvsweb/cvsweb.cgi/llvm/include/llvm/Instruction.def">
1475   <tt>include/llvm/Instruction.def</tt></a> file. You should check there for the
1476   most recent definitions. The table below provides the opcodes defined as of
1477   the writing of this document. The table associates each opcode mneumonic with
1478   its enumeration value and the bytecode and LLVM version numbers in which the
1479   opcode was introduced.</p>
1480   <table>
1481     <tbody>
1482       <tr>
1483         <th>Opcode</th>
1484         <th>Number</th>
1485         <th>Bytecode Version</th>
1486         <th>LLVM Version</th>
1487       </tr>
1488       <tr><td colspan="4"><b>Terminator Instructions</b></td></tr>
1489       <tr><td>Ret</td><td>1</td><td>1</td><td>1.0</td></tr>
1490       <tr><td>Br</td><td>2</td><td>1</td><td>1.0</td></tr>
1491       <tr><td>Switch</td><td>3</td><td>1</td><td>1.0</td></tr>
1492       <tr><td>Invoke</td><td>4</td><td>1</td><td>1.0</td></tr>
1493       <tr><td>Unwind</td><td>5</td><td>1</td><td>1.0</td></tr>
1494       <tr><td colspan="4"><b>Binary Operators</b></td></tr>
1495       <tr><td>Add</td><td>6</td><td>1</td><td>1.0</td></tr>
1496       <tr><td>Sub</td><td>7</td><td>1</td><td>1.0</td></tr>
1497       <tr><td>Mul</td><td>8</td><td>1</td><td>1.0</td></tr>
1498       <tr><td>Div</td><td>9</td><td>1</td><td>1.0</td></tr>
1499       <tr><td>Rem</td><td>10</td><td>1</td><td>1.0</td></tr>
1500       <tr><td colspan="4"><b>Logical Operators</b></td></tr>
1501       <tr><td>And</td><td>11</td><td>1</td><td>1.0</td></tr>
1502       <tr><td>Or</td><td>12</td><td>1</td><td>1.0</td></tr>
1503       <tr><td>Xor</td><td>13</td><td>1</td><td>1.0</td></tr>
1504       <tr><td colspan="4"><b>Binary Comparison Operators</b></td></tr>
1505       <tr><td>SetEQ</td><td>14</td><td>1</td><td>1.0</td></tr>
1506       <tr><td>SetNE</td><td>15</td><td>1</td><td>1.0</td></tr>
1507       <tr><td>SetLE</td><td>16</td><td>1</td><td>1.0</td></tr>
1508       <tr><td>SetGE</td><td>17</td><td>1</td><td>1.0</td></tr>
1509       <tr><td>SetLT</td><td>18</td><td>1</td><td>1.0</td></tr>
1510       <tr><td>SetGT</td><td>19</td><td>1</td><td>1.0</td></tr>
1511       <tr><td colspan="4"><b>Memory Operators</b></td></tr>
1512       <tr><td>Malloc</td><td>20</td><td>1</td><td>1.0</td></tr>
1513       <tr><td>Free</td><td>21</td><td>1</td><td>1.0</td></tr>
1514       <tr><td>Alloca</td><td>22</td><td>1</td><td>1.0</td></tr>
1515       <tr><td>Load</td><td>23</td><td>1</td><td>1.0</td></tr>
1516       <tr><td>Store</td><td>24</td><td>1</td><td>1.0</td></tr>
1517       <tr><td>GetElementPtr</td><td>25</td><td>1</td><td>1.0</td></tr>
1518       <tr><td colspan="4"><b>Other Operators</b></td></tr>
1519       <tr><td>PHI</td><td>26</td><td>1</td><td>1.0</td></tr>
1520       <tr><td>Cast</td><td>27</td><td>1</td><td>1.0</td></tr>
1521       <tr><td>Call</td><td>28</td><td>1</td><td>1.0</td></tr>
1522       <tr><td>Shl</td><td>29</td><td>1</td><td>1.0</td></tr>
1523       <tr><td>Shr</td><td>30</td><td>1</td><td>1.0</td></tr>
1524       <tr><td>VANext</td><td>31</td><td>1</td><td>1.0</td></tr>
1525       <tr><td>VAArg</td><td>32</td><td>1</td><td>1.0</td></tr>
1526       <tr><td>Select</td><td>33</td><td>2</td><td>1.2</td></tr>
1527       <tr><td>UserOp1</td><td>34</td><td>1</td><td>1.0</td></tr>
1528       <tr><td>UserOp2</td><td>35</td><td>1</td><td>1.0</td></tr>
1529     </tbody>
1530   </table>
1531 </div>
1532
1533 <!-- _______________________________________________________________________ -->
1534 <div class="doc_subsection"><a name="symtab">Symbol Table</a> </div>
1535 <div class="doc_text">
1536 <p>A symbol table can be put out in conjunction with a module or a function. A
1537 symbol table has a list of name/type associations followed by a list of
1538 name/value associations. The name/value associations are organized into "type
1539 planes" so that all values of a common type are listed together.  Each type 
1540 plane starts with the number of entries in the plane and the type slot number
1541 for all the values in that plane (so the type can be looked up in the global 
1542 type pool). For each entry in a type plane, the slot number of the value and 
1543 the name associated with that value are written. The format is given in the 
1544 table below. </p>
1545 <table>
1546   <tbody>
1547     <tr>
1548       <th><b>Type</b></th>
1549       <th class="td_left"><b>Field Description</b></th>
1550     </tr>
1551     <tr>
1552       <td><a href="#block">block</a><br>
1553       </td>
1554       <td class="td_left">Symbol Table Identifier (0x04)</td>
1555     </tr>
1556     <tr>
1557       <td><a href="#llist">llist</a>(<a href="#symtab_entry">type_entry</a>)</td>
1558       <td class="td_left">A length list of symbol table entries for
1559         <tt>Type</tt>s
1560       </td>
1561     </tr>
1562     <tr>
1563       <td><a href="#zlist">llist</a>(<a href="#symtab_plane">symtab_plane</a>)</td>
1564       <td class="td_left">A length list of "type planes" of symbol table
1565         entries for <tt>Value</tt>s</td>
1566     </tr>
1567   </tbody>
1568 </table>
1569 </div>
1570
1571 <!-- _______________________________________________________________________ -->
1572 <div class="doc_subsubsection"> <a name="type_entry">Symbol Table Type
1573 Entry</a>
1574 </div>
1575 <div class="doc_text">
1576 <p>A symbol table type entry associates a name with a type. The name is provided
1577 simply as an array of chars. The type is provided as a type slot number (index)
1578 into the global type pool. The format is given in the following table:</p>
1579 <table>
1580   <tbody>
1581     <tr>
1582       <th><b>Type</b></th>
1583       <th class="td_left"><b>Field Description</b></th>
1584     </tr>
1585     <tr>
1586       <td><a href="#uint32_vbr">uint24_vbr</a></td>
1587       <td class="td_left">Type slot number of the type being given a
1588         name relative to the global type pool.
1589       </td>
1590     </tr>
1591     <tr>
1592       <td><a href="#uint32_vbr">uint32_vbr</a></td>
1593       <td class="td_left">Length of the character array that follows.</td>
1594     </tr>
1595     <tr>
1596       <td><a href="#char">char</a>+</td>
1597       <td class="td_left">The characters of the name.</td>
1598     </tr>
1599   </tbody>
1600 </table>
1601 </div>
1602 <!-- _______________________________________________________________________ -->
1603 <div class="doc_subsubsection"> <a name="symtab_plane">Symbol Table
1604 Plane</a>
1605 </div>
1606 <div class="doc_text">
1607 <p>A symbol table plane provides the symbol table entries for all
1608 values of a common type. The encoding is given in the following table:</p>
1609 <table>
1610   <tbody>
1611     <tr>
1612       <th><b>Type</b></th>
1613       <th class="td_left"><b>Field Description</b></th>
1614     </tr>
1615     <tr>
1616       <td><a href="#uint32_vbr">uint32_vbr</a></td>
1617       <td class="td_left">Number of entries in this plane.</td>
1618     </tr>
1619     <tr>
1620       <td><a href="#uint32_vbr">uint32_vbr</a></td>
1621       <td class="td_left">Type slot number of type for all values in this plane..</td>
1622     </tr>
1623     <tr>
1624       <td><a href="#value_entry">value_entry</a>+</td>
1625       <td class="td_left">The symbol table entries for to associate values with
1626         names.</td>
1627     </tr>
1628   </tbody>
1629 </table>
1630 </div>
1631 <!-- _______________________________________________________________________ -->
1632 <div class="doc_subsubsection"><a name="value_entry">Symbol Table Value
1633 Entry</a>
1634 </div>
1635 <div class="doc_text">
1636 <p>A symbol table value entry provides the assocation between a value and the
1637 name given to the value. The value is referenced by its slot number. The
1638 format is given in the following table:</p>
1639 <table>
1640   <tbody>
1641     <tr>
1642       <th><b>Type</b></th>
1643       <th class="td_left"><b>Field Description</b></th>
1644     </tr>
1645     <tr>
1646       <td><a href="#uint32_vbr">uint24_vbr</a></td>
1647       <td class="td_left">Value slot number of the value being given a name.
1648       </td>
1649     </tr>
1650     <tr>
1651       <td><a href="#uint32_vbr">uint32_vbr</a></td>
1652       <td class="td_left">Length of the character array that follows.</td>
1653     </tr>
1654     <tr>
1655       <td><a href="#char">char</a>+</td>
1656       <td class="td_left">The characters of the name.</td>
1657     </tr>
1658   </tbody>
1659 </table>
1660 </div>
1661
1662 <!-- *********************************************************************** -->
1663 <div class="doc_section"> <a name="versiondiffs">Version Differences</a>
1664 </div>
1665 <!-- *********************************************************************** -->
1666 <div class="doc_text">
1667 <p>This section describes the differences in the Bytecode Format across
1668 LLVM
1669 versions. The versions are listed in reverse order because it assumes
1670 the current version is as documented in the previous sections. Each
1671 section here
1672 describes the differences between that version and the one that <i>follows</i>.
1673 </p>
1674 </div>
1675 <!-- _______________________________________________________________________ -->
1676 <div class="doc_subsection"><a name="vers13">Version 1.3 Differences From 
1677     1.4</a></div>
1678 <!-- _______________________________________________________________________ -->
1679 <div class="doc_subsubsection">Aligned Data</div>
1680 <div class="doc_text">
1681   <p>In version 1.3, certain data items were aligned to 32-bit boundaries. In
1682   version 1.4, alignment of data was done away with completely. The need for
1683   alignment has gone away and the only thing it adds is bytecode file size
1684   overhead. In most cases this overhead was small. However, in functions with
1685   large numbers of format 0 instructions (GEPs and PHIs with lots of parameters)
1686   or regular instructions with large valued operands (e.g. because there's just
1687   a lot of instructions in the function) the overhead can be extreme. In one
1688   test case, the overhead was 44,000 bytes (34% of the total file size).
1689   Consequently in release 1.4, the decision was made to eliminate alignment
1690   altogether.</p>
1691   <p>In version 1.3 format, the following bytecode constructs were aligned (i.e.
1692   they were followed by one to three bytes of padding):</p>
1693   <ul>
1694     <li>All blocks.</li>
1695     <li>Instructions using the long format (format 0).</li>
1696     <li>All call instructions that called a var args function.</li>
1697     <li>The target triple (a string field at the end of the module block).</li>
1698     <li>The version field (immediately following the signature).</li>
1699   </ul>
1700   <p>None of these constructs are aligned in version 1.4</p>
1701 </div>
1702
1703 <!-- _______________________________________________________________________ -->
1704 <div class="doc_subsection"><a name="vers12">Version 1.2 Differences
1705 From 1.3</a></div>
1706 <!-- _______________________________________________________________________ -->
1707 <div class="doc_subsubsection">Type Derives From Value</div>
1708 <div class="doc_text">
1709 <p>In version 1.2, the Type class in the LLVM IR derives from the Value
1710 class. This is not the case in version 1.3. Consequently, in version
1711 1.2 the notion of a "Type Type" was used to write out values that were
1712 Types. The types always occuped plane 12 (corresponding to the
1713 TypeTyID) of any type planed set of values. In 1.3 this representation
1714 is not convenient because the TypeTyID (12) is not present and its
1715 value is now used for LabelTyID. Consequently, the data structures
1716 written that involve types do so by writing all the types first and
1717 then each of the value planes according to those types. In version 1.2,
1718 the types would have been written intermingled with the values.</p>
1719 </div>
1720 <!-- _______________________________________________________________________ -->
1721 <div class="doc_subsubsection">Restricted getelementptr Types</div>
1722 <div class="doc_text">
1723 <p>In version 1.2, the getelementptr instruction required a ubyte type
1724 index for accessing a structure field and a long type index for
1725 accessing an array element. Consequently, it was only possible to
1726 access structures of 255 or fewer elements. Starting in version 1.3,
1727 this restriction was lifted. Structures must now be indexed with uint
1728 constants. Arrays may now be indexed with int, uint, long, or ulong
1729 typed values. The consequence of this was that the bytecode format had
1730 to change in order to accommodate the larger range of structure indices.</p>
1731 </div>
1732 <!-- _______________________________________________________________________ -->
1733 <div class="doc_subsubsection">Short Block Headers</div>
1734 <div class="doc_text">
1735 <p>In version 1.2, block headers were always 8 bytes being comprised of
1736 both an unsigned integer type and an unsigned integer size. For very
1737 small modules, these block headers turn out to be a large fraction of
1738 the total bytecode file size. In an attempt to make these small files
1739 smaller, the type and size information was encoded into a single
1740 unsigned integer (4 bytes) comprised of 5 bits for the block type
1741 (maximum 31 block types) and 27 bits for the block size (max
1742 ~134MBytes). These limits seemed sufficient for any blocks or sizes
1743 forseen in the future. Note that the module block, which encloses all
1744 the other blocks is still written as 8 bytes since bytecode files
1745 larger than 134MBytes might be possible.</p>
1746 </div>
1747 <!-- _______________________________________________________________________ -->
1748 <div class="doc_subsubsection">Dependent Libraries and Target Triples</div>
1749 <div class="doc_text">
1750 <p>In version 1.2, the bytecode format does not store module's target
1751 triple or dependent. These fields have been added to the end of the <a
1752  href="#globalinfo">module global info block</a>. The purpose of these
1753 fields is to allow a front end compiler to specifiy that the generated
1754 module is specific to a particular target triple (operating
1755 system/manufacturer/processor) which makes it non-portable; and to
1756 allow front end compilers to specify the list of libraries that the
1757 module depends on for successful linking.</p>
1758 </div>
1759 <!-- _______________________________________________________________________ -->
1760 <div class="doc_subsubsection">Types Restricted to 24-bits</div>
1761 <div class="doc_text">
1762 <p>In version 1.2, type slot identifiers were written as 32-bit VBR
1763 quantities. In 1.3 this has been reduced to 24-bits in order to ensure
1764 that it is not possible to overflow the type field of a global variable
1765 definition. 24-bits for type slot numbers is deemed sufficient for any
1766 practical use of LLVM.</p>
1767 </div>
1768 <!-- _______________________________________________________________________ -->
1769 <!-- _______________________________________________________________________ -->
1770 <div class="doc_subsection"><a name="vers11">Version 1.1 Differences
1771 From 1.2 </a></div>
1772 <!-- _______________________________________________________________________ -->
1773 <div class="doc_subsubsection">Explicit Primitive Zeros</div>
1774 <div class="doc_text">
1775 <p>In version 1.1, the zero value for primitives was explicitly encoded
1776 into the bytecode format. Since these zero values are constant values
1777 in the LLVM IR and never change, there is no reason to explicitly
1778 encode them. This explicit encoding was removed in version 1.2.</p>
1779 </div>
1780 <!-- _______________________________________________________________________ -->
1781 <div class="doc_subsubsection">Inconsistent Module Global Info</div>
1782 <div class="doc_text">
1783 <p>In version 1.1, the Module Global Info block was not aligned causing
1784 the next block to be read in on an unaligned boundary. This problem was
1785 corrected in version 1.2.<br>
1786 <br>
1787 </p>
1788 </div>
1789 <!-- _______________________________________________________________________ -->
1790 <div class="doc_subsection"><a name="vers10">Version 1.0 Differences
1791 From 1.1</a></div>
1792 <div class="doc_text">
1793 <p>None. Version 1.0 and 1.1 bytecode formats are identical.</p>
1794 </div>
1795 <!-- *********************************************************************** -->
1796 <hr>
1797 <address> <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
1798  src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
1799 <a href="http://validator.w3.org/check/referer"><img
1800  src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!"></a>
1801 <a href="mailto:rspencer@x10sys.com">Reid Spencer</a> and <a
1802  href="mailto:sabre@nondot.org">Chris Lattner</a><br>
1803 <a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a><br>
1804 Last modified: $Date$
1805 </address>
1806 </body>
1807 </html>