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