1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
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: 4pt 4pt 4pt 4pt; }
9 TH { border: 2px solid gray; font-weight: bold; font-size: 105%; }
10 TABLE { text-align: center; padding: 4pt 4pt 4pt 4pt; border: 2px solid black;
11 border-collapse: collapse; margin-top: 1em; margin-left: 1em; margin-right: 1em; margin-bottom: 1em; }
12 .td_left { border: 2px solid gray; padding: 4pt 4pt 4pt 4pt; text-align: left; }
16 <div class="doc_title"> LLVM Bytecode File Format </div>
18 <li><a href="#abstract">Abstract</a></li>
19 <li><a href="#concepts">Concepts</a>
21 <li><a href="#blocks">Blocks</a></li>
22 <li><a href="#lists">Lists</a></li>
23 <li><a href="#fields">Fields</a></li>
24 <li><a href="#align">Alignment</a></li>
25 <li><a href="#encoding">Encoding Primitives</a></li>
26 <li><a href="#slots">Slots</a></li>
29 <li><a href="#general">General Layout</a>
31 <li><a href="#structure">Structure</a></li>
34 <li><a href="#details">Detailed Layout</a>
36 <li><a href="#notation">Notation</a></li>
37 <li><a href="#blocktypes">Blocks Types</a></li>
38 <li><a href="#signature">Signature Block</a></li>
39 <li><a href="#module">Module Block</a></li>
40 <li><a href="#globaltypes">Global Type Pool</a></li>
41 <li><a href="#globalinfo">Module Info Block</a></li>
42 <li><a href="#constantpool">Global Constant Pool</a></li>
43 <li><a href="#functiondefs">Function Definition</a></li>
44 <li><a href="#compactiontable">Compaction Table</a></li>
45 <li><a href="#instructionlist">Instruction List</a></li>
46 <li><a href="#symtab">Symbol Table</a></li>
49 <li><a href="#versiondiffs">Version Differences</a>
51 <li><a href="#vers12">Version 1.2 Differences From 1.3</a></li>
52 <li><a href="#vers11">Version 1.1 Differences From 1.2</a></li>
53 <li><a href="#vers10">Version 1.0 Differences From 1.1</a></li>
57 <div class="doc_author">
58 <p>Written by <a href="mailto:rspencer@x10sys.com">Reid Spencer</a>
61 <div class="doc_warning">
62 <p>Warning: This is a work in progress.</p>
65 <!-- *********************************************************************** -->
66 <div class="doc_section"> <a name="abstract">Abstract </a></div>
67 <!-- *********************************************************************** -->
68 <div class="doc_text">
69 <p>This document describes the LLVM bytecode file format as of version 1.3.
70 It specifies the binary encoding rules of the bytecode file format
71 so that equivalent systems can encode bytecode files correctly. The LLVM
72 bytecode representation is used to store the intermediate representation on
73 disk in compacted form.
77 <!-- *********************************************************************** -->
78 <div class="doc_section"> <a name="concepts">Concepts</a> </div>
79 <!-- *********************************************************************** -->
80 <div class="doc_text">
81 <p>This section describes the general concepts of the bytecode file format
82 without getting into bit and byte level specifics. Note that the LLVM bytecode
83 format may change in the future, but will always be backwards compatible with
84 older formats. This document only describes the most current version of the
88 <!-- _______________________________________________________________________ -->
89 <div class="doc_subsection"><a name="blocks">Blocks</a> </div>
90 <div class="doc_text">
91 <p>LLVM bytecode files consist simply of a sequence of blocks of bytes.
92 Each block begins with an header of two unsigned integers. The first value
93 identifies the type of block and the second value provides the size of the
94 block in bytes. The block identifier is used because it is possible for entire
95 blocks to be omitted from the file if they are empty. The block identifier helps
96 the reader determine which kind of block is next in the file. Note that blocks
97 can be nested within other blocks.</p>
98 <p> All blocks are variable length, and the block header specifies the size of
99 the block. All blocks begin on a byte index that is aligned to an even 32-bit
100 boundary. That is, the first block is 32-bit aligned because it starts at offset
101 0. Each block is padded with zero fill bytes to ensure that the next block also
102 starts on a 32-bit boundary.</p>
105 <!-- _______________________________________________________________________ -->
106 <div class="doc_subsection"><a name="lists">Lists</a> </div>
107 <div class="doc_text">
108 <p>LLVM Bytecode blocks often contain lists of things of a similar type. For
109 example, a function contains a list of instructions and a function type
110 contains a list of argument types. There are two basic types of lists:
111 length lists, and null terminated lists, as described here:</p>
113 <li><b>Length Lists</b>. Length lists are simply preceded by the number
114 of items in the list. The bytecode reader will read the count first and
115 then iterate that many times to read in the list contents.</li>
116 <li><b>Null Terminated Lists</b>. For some lists, the number of elements
117 in the list is not readily available at the time of writing the bytecode.
118 In these cases, the list is terminated by some null value. What constitutes
119 a null value differs, but it almost always boils down to a zero value.</li>
123 <!-- _______________________________________________________________________ -->
124 <div class="doc_subsection"><a name="fields">Fields</a> </div>
125 <div class="doc_text">
126 <p>Fields are units of information that LLVM knows how to write atomically.
127 Most fields have a uniform length or some kind of length indication built into
128 their encoding. For example, a constant string (array of bytes) is
129 written simply as the length followed by the characters. Although this is
130 similar to a list, constant strings are treated atomically and are thus
132 <p>Fields use a condensed bit format specific to the type of information
133 they must contain. As few bits as possible are written for each field. The
134 sections that follow will provide the details on how these fields are
135 written and how the bits are to be interpreted.</p>
138 <!-- _______________________________________________________________________ -->
139 <div class="doc_subsection"><a name="align">Alignment</a> </div>
140 <div class="doc_text">
141 <p>To support cross-platform differences, the bytecode file is aligned on
142 certain boundaries. This means that a small amount of padding (at most 3
143 bytes) will be added to ensure that the next entry is aligned to a 32-bit
147 <!-- _______________________________________________________________________ -->
148 <div class="doc_subsection"><a name="encoding">Encoding Primitives</a> </div>
149 <div class="doc_text">
150 <p>Each field that can be put out is encoded into the file using a small set
151 of primitives. The rules for these primitives are described below.</p>
152 <h3>Variable Bit Rate Encoding</h3>
153 <p>Most of the values written to LLVM bytecode files are small integers. To
154 minimize the number of bytes written for these quantities, an encoding
155 scheme similar to UTF-8 is used to write integer data. The scheme is known as
156 variable bit rate (vbr) encoding. In this encoding, the high bit of each
157 byte is used to indicate if more bytes follow. If (byte & 0x80) is non-zero
158 in any given byte, it means there is another byte immediately following that
159 also contributes to the value. For the final byte (byte & 0x80) is false
160 (the high bit is not set). In each byte only the low seven bits contribute to
161 the value. Consequently 32-bit quantities can take from one to <em>five</em>
162 bytes to encode. In general, smaller quantities will encode in fewer bytes,
164 <table class="doc_table_nw">
167 <th>Significant Bits</th>
168 <th>Maximum Value</th>
170 <tr><td>1</td><td>0-6</td><td>127</td></tr>
171 <tr><td>2</td><td>7-13</td><td>16,383</td></tr>
172 <tr><td>3</td><td>14-20</td><td>2,097,151</td></tr>
173 <tr><td>4</td><td>21-27</td><td>268,435,455</td></tr>
174 <tr><td>5</td><td>28-34</td><td>34,359,738,367</td></tr>
175 <tr><td>6</td><td>35-41</td><td>4,398,046,511,103</td></tr>
176 <tr><td>7</td><td>42-48</td><td>562,949,953,421,311</td></tr>
177 <tr><td>8</td><td>49-55</td><td>72,057,594,037,927,935</td></tr>
178 <tr><td>9</td><td>56-62</td><td>9,223,372,036,854,775,807</td></tr>
179 <tr><td>10</td><td>63-69</td><td>1,180,591,620,717,411,303,423</td></tr>
181 <p>Note that in practice, the tenth byte could only encode bit 63
182 since the maximum quantity to use this encoding is a 64-bit integer.</p>
184 <p><em>Signed</em> VBR values are encoded with the standard vbr encoding, but
185 with the sign bit as the low order bit instead of the high order bit. This
186 allows small negative quantities to be encoded efficiently. For example, -3
187 is encoded as "((3 << 1) | 1)" and 3 is encoded as "(3 << 1) |
188 0)", emitted with the standard vbr encoding above.</p>
190 <p>The table below defines the encoding rules for type names used in the
191 descriptions of blocks and fields in the next section. Any type name with
192 the suffix <em>_vbr</em> indicate a quantity that is encoded using
193 variable bit rate encoding as described above.</p>
194 <table class="doc_table" >
197 <th class="td_left"><b>Rule</b></th>
200 <td><a name="unsigned">unsigned</a></td>
201 <td class="td_left">A 32-bit unsigned integer that always occupies four
202 consecutive bytes. The unsigned integer is encoded using LSB first
203 ordering. That is bits 2<sup>0</sup> through 2<sup>7</sup> are in the
204 byte with the lowest file offset (little endian).</td>
206 <td><a name="uint_vbr">uint_vbr</a></td>
207 <td class="td_left">A 32-bit unsigned integer that occupies from one to five
208 bytes using variable bit rate encoding.</td>
210 <td><a name="uint64_vbr">uint64_vbr</a></td>
211 <td class="td_left">A 64-bit unsigned integer that occupies from one to ten
212 bytes using variable bit rate encoding.</td>
214 <td><a name="int64_vbr">int64_vbr</a></td>
215 <td class="td_left">A 64-bit signed integer that occupies from one to ten
216 bytes using the signed variable bit rate encoding.</td>
218 <td><a name="char">char</a></td>
219 <td class="td_left">A single unsigned character encoded into one byte</td>
221 <td><a name="bit">bit</a></td>
222 <td class="td_left">A single bit within some larger integer field.</td>
224 <td><a name="string">string</a></td>
225 <td class="td_left">A uint_vbr indicating the length of the character string
226 immediately followed by the characters of the string. There is no
227 terminating null byte in the string.</td>
229 <td><a name="data">data</a></td>
230 <td class="td_left">An arbitrarily long segment of data to which no
231 interpretation is implied. This is used for float, double, and constant
234 <td><a name="block">block</a></td>
235 <td class="td_left">A block of data that is logically related. A block
236 begins with an <a href="#unsigned">unsigned</a> that provides the block
237 identifier (constant value) and an <a href="#unsigned">unsigned</a> that
238 provides the length of the block. Blocks may compose other blocks.
244 <!-- _______________________________________________________________________ -->
245 <div class="doc_subsection"><a name="slots">Slots</a> </div>
246 <div class="doc_text">
247 <p>The bytecode format uses the notion of a "slot" to reference Types and
248 Values. Since the bytecode file is a <em>direct</em> representation of LLVM's
249 intermediate representation, there is a need to represent pointers in the file.
250 Slots are used for this purpose. For example, if one has the following assembly:
252 <div class="doc_code">
253 %MyType = type { int, sbyte }<br>
254 %MyVar = external global %MyType
256 <p>there are two definitions. The definition of <tt>%MyVar</tt> uses
257 <tt>%MyType</tt>. In the C++ IR this linkage between <tt>%MyVar</tt> and
259 explicit through the use of C++ pointers. In bytecode, however, there's no
260 ability to store memory addresses. Instead, we compute and write out slot
261 numbers for every Type and Value written to the file.</p>
262 <p>A slot number is simply an unsigned 32-bit integer encoded in the variable
263 bit rate scheme (see <a href="#encoding">encoding</a>). This ensures that
264 low slot numbers are encoded in one byte. Through various bits of magic LLVM
265 attempts to always keep the slot numbers low. The first attempt is to associate
266 slot numbers with their "type plane". That is, Values of the same type are
267 written to the bytecode file in a list (sequentially). Their order in that list
268 determines their slot number. This means that slot #1 doesn't mean anything
269 unless you also specify for which type you want slot #1. Types are handled
270 specially and are always written to the file first (in the
271 <a href="#globaltypes">Global Type Pool</a>) and
272 in such a way that both forward and backward references of the types can often be
273 resolved with a single pass through the type pool. </p>
274 <p>Slot numbers are also kept small by rearranging their order. Because of the
275 structure of LLVM, certain values are much more likely to be used frequently
276 in the body of a function. For this reason, a compaction table is provided in
277 the body of a function if its use would make the function body smaller.
278 Suppose you have a function body that uses just the types "int*" and "{double}"
279 but uses them thousands of time. Its worthwhile to ensure that the slot number
280 for these types are low so they can be encoded in a single byte (via vbr).
281 This is exactly what the compaction table does.</p>
284 <!-- *********************************************************************** -->
285 <div class="doc_section"> <a name="general">General Layout</a> </div>
286 <!-- *********************************************************************** -->
287 <div class="doc_text">
288 <p>This section provides the general layout of the LLVM bytecode file format.
289 The detailed layout can be found in the <a href="#details">next section</a>.
293 <!-- _______________________________________________________________________ -->
294 <div class="doc_subsection"><a name="structure">Structure</a> </div>
295 <div class="doc_text">
296 <p>The bytecode file format requires blocks to be in a certain order and
297 nested in a particular way so that an LLVM module can be constructed
298 efficiently from the contents of the file. This ordering defines a general
299 structure for bytecode files as shown below. The table below shows the order
300 in which all block types may appear. Please note that some of the blocks are
301 optional and some may be repeated. The structure is fairly loose because
302 optional blocks, if empty, are completely omitted from the file.
313 <tr><td>N/A</td><td>File</td><td>No</td><td>No</td><td>0</td>
314 <td class="td_left"><a href="#signature">Signature</a></td>
316 <tr><td>0x01</td><td>File</td><td>No</td><td>No</td><td>0</td>
317 <td class="td_left"><a href="#module">Module</a></td>
319 <tr><td>0x15</td><td>Module</td><td>No</td><td>No</td><td>1</td>
320 <td class="td_left">
321 <a href="#globaltypes">Global Type Pool</a></td>
323 <tr><td>0x14</td><td>Module</td><td>No</td><td>No</td><td>1</td>
324 <td class="td_left">
325 <a href="#globalinfo">Module Globals Info</a></td>
327 <tr><td>0x12</td><td>Module</td><td>Yes</td><td>No</td><td>1</td>
328 <td class="td_left">
329 <a href="#constantpool">Module Constant Pool</a></td>
331 <tr><td>0x11</td><td>Module</td><td>Yes</td><td>Yes</td><td>1</td>
332 <td class="td_left">
333 <a href="#functiondefs">Function Definitions</a></td>
335 <tr><td>0x12</td><td>Function</td><td>Yes</td><td>No</td><td>2</td>
336 <td class="td_left">
337 <a href="#constantpool">Function Constant Pool</a></td>
339 <tr><td>0x33</td><td>Function</td><td>Yes</td><td>No</td><td>2</td>
340 <td class="td_left">
341 <a href="#compactiontable">Compaction Table</a></td>
343 <tr><td>0x32</td><td>Function</td><td>No</td><td>No</td><td>2</td>
344 <td class="td_left">
345 <a href="#instructionlist">Instruction List</a></td>
347 <tr><td>0x13</td><td>Function</td><td>Yes</td><td>No</td><td>2</td>
348 <td class="td_left">
349 <a href="#symboltable">Function Symbol Table</a></td>
351 <tr><td>0x13</td><td>Module</td><td>Yes</td><td>No</td><td>1</td>
352 <td class="td_left">
353 <a href="#symboltable">Module Symbol Table</a></td>
356 <p>Use the links in the table or see <a href="#blocktypes">Block Types</a> for
357 details about the contents of each of the block types.</p>
360 <!-- *********************************************************************** -->
361 <div class="doc_section"> <a name="details">Detailed Layout</a> </div>
362 <!-- *********************************************************************** -->
363 <div class="doc_text">
364 <p>This section provides the detailed layout of the LLVM bytecode file format.
367 <!-- _______________________________________________________________________ -->
368 <div class="doc_subsection"><a name="notation">Notation</a></div>
369 <div class="doc_text">
370 <p>The descriptions of the bytecode format that follow describe the order, type
371 and bit fields in detail. These descriptions are provided in tabular form.
372 Each table has four columns that specify:</p>
374 <li><b>Byte(s)</b>: The offset in bytes of the field from the start of
375 its container (block, list, other field).</li>
376 <li><b>Bit(s)</b>: The offset in bits of the field from the start of
377 the byte field. Bits are always little endian. That is, bit addresses with
378 smaller values have smaller address (i.e. 2<sup>0</sup> is at bit 0,
379 2<sup>1</sup> at 1, etc.)
381 <li><b>Align?</b>: Indicates if this field is aligned to 32 bits or not.
382 This indicates where the <em>next</em> field starts, always on a 32 bit
384 <li><b>Type</b>: The basic type of information contained in the field.</li>
385 <li><b>Description</b>: Describes the contents of the field.</li>
388 <!-- _______________________________________________________________________ -->
389 <div class="doc_subsection"><a name="blocktypes">Block Types</a></div>
390 <div class="doc_text">
391 <p>The bytecode format encodes the intermediate representation into groups
392 of bytes known as blocks. The blocks are written sequentially to the file in
393 the following order:</p>
395 <li><a href="#signature">Signature</a>: This contains the file signature
396 (magic number) that identifies the file as LLVM bytecode and the bytecode
398 <li><a href="#module">Module Block</a>: This is the top level block in a
399 bytecode file. It contains all the other blocks.</li>
400 <li><a href="#gtypepool">Global Type Pool</a>: This block contains all the
401 global (module) level types.</li>
402 <li><a href="#modinfo">Module Info</a>: This block contains the types of the
403 global variables and functions in the module as well as the constant
404 initializers for the global variables</li>
405 <li><a href="#constants">Constants</a>: This block contains all the global
406 constants except function arguments, global values and constant strings.</li>
407 <li><a href="#functions">Functions</a>: One function block is written for
408 each function in the module. </li>
409 <li><a href="#symtab">Symbol Table</a>: The module level symbol table that
410 provides names for the various other entries in the file is the final block
414 <!-- _______________________________________________________________________ -->
415 <div class="doc_subsection"><a name="signature">Signature Block</a> </div>
416 <div class="doc_text">
417 <p>The signature occurs in every LLVM bytecode file and is always first.
418 It simply provides a few bytes of data to identify the file as being an LLVM
419 bytecode file. This block is always four bytes in length and differs from the
420 other blocks because there is no identifier and no block length at the start
421 of the block. Essentially, this block is just the "magic number" for the file.
422 <table class="doc_table_nw" >
425 <th class="td_left"><b>Field Description</b></th>
427 <td><a href="#char">char</a></td>
428 <td class="td_left">Constant "l" (0x6C)</td>
430 <td><a href="#char">char</a></td>
431 <td class="td_left">Constant "l" (0x6C)</td>
433 <td><a href="#char">char</a></td>
434 <td class="td_left">Constant "v" (0x76)</td>
436 <td><a href="#char">char</a></td>
437 <td class="td_left">Constant "m" (0x6D)</td>
442 <!-- _______________________________________________________________________ -->
443 <div class="doc_subsection"><a name="module">Module Block</a> </div>
444 <div class="doc_text">
445 <p>The module block contains a small pre-amble and all the other blocks in
446 the file. The table below shows the structure of the module block. Note that it
447 only provides the module identifier, size of the module block, and the format
448 information. Everything else is contained in other blocks, described in other
450 <table class="doc_table_nw" >
453 <th class="td_left"><b>Field Description</b></th>
455 <td><a href="#unsigned">unsigned</a></td>
456 <td class="td_left">Module Identifier (0x01)</td>
458 <td><a href="#unsigned">unsigned</a></td>
459 <td class="td_left">Size of the module block in bytes</td>
461 <td><a href="#uint32_vbr">uint32_vbr</a></td>
462 <td class="td_left"><a href="#format">Format Information</a></td>
464 <td><a href="#block">block</a></td>
465 <td class="td_left"><a href="#globaltypes">Global Type Pool</a></td>
467 <td><a href="#block">block</a></td>
468 <td class="td_left"><a href="#globalinfo">Module Globals Info</a></td>
470 <td><a href="#block">block</a></td>
471 <td class="td_left"><a href="#constantpool">Module Constant Pool</a></td>
473 <td><a href="#block">block</a></td>
474 <td class="td_left"><a href="#functiondefs">Function Definitions</a></td>
476 <td><a href="#block">block</a></td>
477 <td class="td_left"><a href="#symboltable">Module Symbol Table</a></td>
482 <!-- _______________________________________________________________________ -->
483 <div class="doc_subsubsection"><a name="format">Format Information</a></div>
484 <div class="doc_text">
485 <p>The format information field is encoded into a 32-bit vbr-encoded unsigned
486 integer as shown in the following table.</p>
489 <th><b>Bit(s)</b></th>
491 <th class="td_left"><b>Description</b></th>
493 <td>0</td><td>bit</td>
494 <td class="td_left">Big Endian?</td>
496 <td>1</td><td>bit</td>
497 <td class="td_left">Pointers Are 64-bit?</td>
499 <td>2</td><td>bit</td>
500 <td class="td_left">Has No Endianess?</td>
502 <td>3</td><td>bit</td>
503 <td class="td_left">Has No Pointer Size?</td>
505 <td>4-31</td><td>bit</td>
506 <td class="td_left">Bytecode Format Version</td>
510 Of particular note, the bytecode format number is simply a 28-bit
511 monotonically increase integer that identifies the version of the bytecode
512 format (which is not directly related to the LLVM release number). The
513 bytecode versions defined so far are (note that this document only describes
514 the latest version, 1.3):</p>
516 <li>#0: LLVM 1.0 & 1.1</li>
517 <li>#1: LLVM 1.2</li>
518 <li>#2: LLVM 1.3</li>
520 <p>Note that we plan to eventually expand the target description capabilities
521 of bytecode files to <a href="http://llvm.cs.uiuc.edu/PR263">target triples</a>.
525 <!-- _______________________________________________________________________ -->
526 <div class="doc_subsection"><a name="globaltypes">Global Type Pool</a> </div>
527 <div class="doc_text">
528 <p>The global type pool consists of type definitions. Their order of appearance
529 in the file determines their slot number (0 based). Slot numbers are used to
530 replace pointers in the intermediate representation. Each slot number uniquely
531 identifies one entry in a type plane (a collection of values of the same type).
532 Since all values have types and are associated with the order in which the type
533 pool is written, the global type pool <em>must</em> be written as the first
534 block of a module. If it is not, attempts to read the file will fail because
535 both forward and backward type resolution will not be possible.</p>
536 <p>The type pool is simply a list of type definitions, as shown in the table
538 <table class="doc_table_nw" >
541 <th class="td_left"><b>Field Description</b></th>
543 <td><a href="#unsigned">unsigned</a></td>
544 <td class="td_left">Type Pool Identifier (0x13)</td>
546 <td><a href="#unsigned">unsigned</a></td>
547 <td class="td_left">Size in bytes of the symbol table block.</td>
549 <td><a href="#uint32_vbr">uint32_vbr</a></td>
550 <td class="td_left">Number of entries in type plane</td>
552 <td><a href="#type">type</a></td>
553 <td class="td_left">Each of the type definitions (see below)<sup>1</sup></td>
555 <td class="td_left" colspan="2">
556 <sup>1</sup>Repeated field.<br/>
561 <!-- _______________________________________________________________________ -->
562 <div class="doc_subsubsection"><a name="type">Type Definitions</a></div>
563 <div class="doc_text">
564 <p>Types in the type pool are defined using a different format for each
565 basic type of type as given in the following sections.</p>
566 <h3>Primitive Types</h3>
567 <p>The primitive types encompass the basic integer and floating point types</p>
571 <th class="td_left"><b>Description</b></th>
573 <td><a href="#uint32_vbr">uint32_vbr</td>
574 <td class="td_left">Type ID For The Primitive (1-11)<sup>1</sup></td>
576 <td class="td_left" colspan="2">
577 <sup>1</sup>See the definition of Type::TypeID in Type.h for the numeric
578 equivalents of the primitive type ids.<br/>
582 <h3>Function Types</h3>
586 <th class="td_left"><b>Description</b></th>
588 <td><a href="#uint32_vbr">uint32_vbr</td>
589 <td class="td_left">Type ID for function types (13)</td>
591 <td><a href="#uint32_vbr">uint32_vbr</td>
592 <td class="td_left">Slot number of function's return type.</td>
594 <td><a href="#uint32_vbr">uint32_vbr</td>
595 <td class="td_left">The number of arguments in the function.</td>
597 <td><a href="#uint32_vbr">uint32_vbr</td>
598 <td class="td_left">Slot number of each argument's type.<sup>1</sup></td>
600 <td><a href="#uint32_vbr">uint32_vbr</td>
601 <td class="td_left">Value 0 if this is a varargs function.<sup>2</sup></td>
603 <td class="td_left" colspan="2">
604 <sup>1</sup>Repeated field.<br/>
605 <sup>2</sup>Optional field.
609 <h3>Structure Types</h3>
613 <th class="td_left"><b>Description</b></th>
615 <td><a href="#uint32_vbr">uint32_vbr</td>
616 <td class="td_left">Type ID for structure types (14)</td>
618 <td><a href="#uint32_vbr">uint32_vbr</td>
619 <td class="td_left">Slot number of each of the element's fields.<sup>1</sup></td>
621 <td><a href="#uint32_vbr">uint32_vbr</td>
622 <td class="td_left">Null Terminator (VoidTy type id)</td>
624 <td class="td_left" colspan="2">
625 <sup>1</sup>Repeated field.<br/>
633 <th class="td_left"><b>Description</b></th>
635 <td><a href="#uint32_vbr">uint32_vbr</td>
636 <td class="td_left">Type ID for Array Types (15)</td>
638 <td><a href="#uint32_vbr">uint32_vbr</td>
639 <td class="td_left">Slot number of array's element type.</td>
641 <td><a href="#uint32_vbr">uint32_vbr</td>
642 <td class="td_left">The number of elements in the array.</td>
645 <h3>Pointer Types</h3>
649 <th class="td_left"><b>Description</b></th>
651 <td><a href="#uint32_vbr">uint32_vbr</td>
652 <td class="td_left">Type ID For Pointer Types (16)</td>
654 <td><a href="#uint32_vbr">uint32_vbr</td>
655 <td class="td_left">Slot number of pointer's element type.</td>
658 <h3>Opaque Types</h3>
662 <th class="td_left"><b>Description</b></th>
664 <td><a href="#uint32_vbr">uint32_vbr</td>
665 <td class="td_left">Type ID For Opaque Types (17)</td>
669 <!-- _______________________________________________________________________ -->
670 <div class="doc_subsection"><a name="globalinfo">Module Global Info</a> </div>
671 <div class="doc_text">
672 <p>To be determined.</p>
674 <!-- _______________________________________________________________________ -->
675 <div class="doc_subsection"><a name="constantpool">Constant Pool</a> </div>
676 <div class="doc_text">
677 <p>To be determined.</p>
679 <!-- _______________________________________________________________________ -->
680 <div class="doc_subsection"><a name="functiondefs">Function Definition</a> </div>
681 <div class="doc_text">
682 <p>To be determined.</p>
684 <!-- _______________________________________________________________________ -->
685 <div class="doc_subsection"><a name="compactiontable">Compaction Table</a> </div>
686 <div class="doc_text">
687 <p>To be determined.</p>
689 <!-- _______________________________________________________________________ -->
690 <div class="doc_subsection"><a name="instructionlist">Instruction List</a> </div>
691 <div class="doc_text">
692 <p>To be determined.</p>
694 <!-- _______________________________________________________________________ -->
695 <div class="doc_subsection"><a name="symtab">Symbol Table</a> </div>
696 <div class="doc_text">
697 <p>A symbol table can be put out in conjunction with a module or a function.
698 A symbol table is a list of type planes. Each type plane starts with the number
699 of entries in the plane and the type plane's slot number (so the type can be
700 looked up in the global type pool). For each entry in a type plane, the slot
701 number of the value and the name associated with that value are written. The
702 format is given in the table below. </p>
703 <table class="doc_table_nw" >
705 <th><b>Byte(s)</b></th>
706 <th><b>Bit(s)</b></th>
707 <th><b>Align?</b></th>
709 <th class="td_left"><b>Field Description</b></th>
711 <td>00-03</td><td>-</td><td>No</td><td>unsigned</td>
712 <td class="td_left">Symbol Table Identifier (0x13)</td>
714 <td>04-07</td><td>-</td><td>No</td><td>unsigned</td>
715 <td class="td_left">Size in bytes of the symbol table block.</td>
717 <td>08-11<sup>1</sup></td><td>-</td><td>No</td><td>uint32_vbr</td>
718 <td class="td_left">Number of entries in type plane</td>
720 <td>12-15<sup>1</sup></td><td>-</td><td>No</td><td>uint32_vbr</td>
721 <td class="td_left">Type plane index for following entries</td>
723 <td>16-19<sup>1,2</sup></td><td>-</td><td>No</td><td>uint32_vbr</td>
724 <td class="td_left">Slot number of a value.</td>
726 <td>variable<sup>1,2</sup></td><td>-</td><td>No</td><td>string</td>
727 <td class="td_left">Name of the value in the symbol table.</td>
730 <td class="td_left" colspan="5"><sup>1</sup>Maximum length shown,
731 may be smaller<br><sup>2</sup>Repeated field.
735 <!-- *********************************************************************** -->
736 <div class="doc_section"> <a name="versiondiffs">Version Differences</a> </div>
737 <!-- *********************************************************************** -->
738 <div class="doc_text">
739 <p>This section describes the differences in the Bytecode Format across LLVM
740 versions. The versions are listed in reverse order because it assumes the
741 current version is as documented in the previous sections. Each section here
742 describes the differences between that version and the one that <i>follows</i>
745 <!-- _______________________________________________________________________ -->
746 <div class="doc_subsection">
747 <a name="vers12">Version 1.2 Differences From 1.3</a></div>
748 <!-- _______________________________________________________________________ -->
749 <div class="doc_subsubsection">Type Derives From Value</div>
750 <div class="doc_text">
751 <p>In version 1.2, the Type class in the LLVM IR derives from the Value class.
752 This is not the case in version 1.3. Consequently, in version 1.2 the notion
753 of a "Type Type" was used to write out values that were Types. The types
754 always occuped plane 12 (corresponding to the TypeTyID) of any type planed
755 set of values. In 1.3 this representation is not convenient because the
756 TypeTyID (12) is not present and its value is now used for LabelTyID.
757 Consequently, the data structures written that involve types do so by writing
758 all the types first and then each of the value planes according to those
759 types. In version 1.2, the types would have been written intermingled with
763 <!-- _______________________________________________________________________ -->
764 <div class="doc_subsubsection">Restricted getelementptr Types</a></div>
765 <div class="doc_text">
766 <p>In version 1.2, the getelementptr instruction required a ubyte type index
767 for accessing a structure field and a long type index for accessing an array
768 element. Consequently, it was only possible to access structures of 255 or
769 fewer elements. Starting in version 1.3, this restriction was lifted.
770 Structures must now be indexed with int or uint types. Arrays must now be
771 indexed with long or ulong types. This requirement was needed so that LLVM
772 could compile several test cases that used large numbers of fields in their
773 structures. The consequence of this was that the bytecode format had to
774 change in order to accommodate the larger range of structure indices.</p>
777 <!-- _______________________________________________________________________ -->
778 <div class="doc_subsection">
779 <a name="vers11">Version 1.1 Differences From 1.2 </a></div>
780 <!-- _______________________________________________________________________ -->
781 <div class="doc_subsubsection">Explicit Primitive Zeros</div>
782 <div class="doc_text">
783 <p>In version 1.1, the zero value for primitives was explicitly encoded into
784 the bytecode format. Since these zero values are constant values in the
785 LLVM IR and never change, there is no reason to explicitly encode them. This
786 explicit encoding was removed in version 1.2.</p>
789 <!-- _______________________________________________________________________ -->
790 <div class="doc_subsubsection">Inconsistent Module Global Info</div>
791 <div class="doc_text">
792 <p>In version 1.1, the Module Global Info block was not aligned causing the
793 next block to be read in on an unaligned boundary. This problem was corrected
797 <!-- _______________________________________________________________________ -->
798 <div class="doc_subsection">
799 <a name="vers11">Version 1.0 Differences From 1.1</a></div>
800 <div class="doc_text">
801 <p>None. Version 1.0 and 1.1 bytecode formats are identical.</p>
804 <!-- *********************************************************************** -->
807 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
808 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
809 <a href="http://validator.w3.org/check/referer"><img
810 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a>
812 <a href="mailto:rspencer@x10sys.com">Reid Spencer</a> and
813 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
814 <a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a><br>
815 Last modified: $Date$