diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2004-07-29 00:13:04 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2004-07-29 00:13:04 +0000 |
commit | 9bd2be2dcd4aa68f3eaf99353ee65335ef4e884b (patch) | |
tree | bdc808f930f603c1717443b2e4d892afa53b78d2 /docs/BytecodeFormat.html | |
parent | 69c5889d603133454a3f06c200cff689eee916cc (diff) |
Updates to reflect most recent changes to bytecode file format:
* Dependent libraries & target triple
* Short block headers
* 24-bit type slot ids.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15314 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'docs/BytecodeFormat.html')
-rw-r--r-- | docs/BytecodeFormat.html | 2219 |
1 files changed, 1279 insertions, 940 deletions
diff --git a/docs/BytecodeFormat.html b/docs/BytecodeFormat.html index 68f724309c..78b3976a8a 100644 --- a/docs/BytecodeFormat.html +++ b/docs/BytecodeFormat.html @@ -1,5 +1,4 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" - "http://www.w3.org/TR/html4/strict.dtd"> +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>LLVM Bytecode File Format</title> @@ -13,7 +12,7 @@ </style> </head> <body> - <div class="doc_title"> LLVM Bytecode File Format </div> +<div class="doc_title"> LLVM Bytecode File Format </div> <ol> <li><a href="#abstract">Abstract</a></li> <li><a href="#concepts">Concepts</a> @@ -53,385 +52,518 @@ <p>Written by <a href="mailto:rspencer@x10sys.com">Reid Spencer</a> </p> </div> - <!-- *********************************************************************** --> <div class="doc_section"> <a name="abstract">Abstract </a></div> <!-- *********************************************************************** --> <div class="doc_text"> - <p>This document describes the LLVM bytecode file format. It specifies the - binary encoding rules of the bytecode file format so that equivalent systems - can encode bytecode files correctly. The LLVM bytecode representation is - used to store the intermediate representation on disk in compacted form.</p> - <p>The LLVM bytecode format may change in the future, but LLVM will always be - backwards compatible with older formats. This document will only describe - the most current version of the bytecode format. See - <a href="#versiondiffs">Version Differences</a> for the details on how the - current version is different from previous versions.</p> -</p> +<p>This document describes the LLVM bytecode file format. It specifies +the binary encoding rules of the bytecode file format so that +equivalent systems can encode bytecode files correctly. The LLVM +bytecode representation is used to store the intermediate +representation on disk in compacted form.</p> +<p>The LLVM bytecode format may change in the future, but LLVM will +always be backwards compatible with older formats. This document will +only describe the most current version of the bytecode format. See <a + href="#versiondiffs">Version Differences</a> for the details on how +the current version is different from previous versions.</p> </div> - <!-- *********************************************************************** --> <div class="doc_section"> <a name="concepts">Concepts</a> </div> <!-- *********************************************************************** --> <div class="doc_text"> - <p>This section describes the general concepts of the bytecode file format - without getting into specific layout details. It is recommended that you read - this section thoroughly before interpreting the detailed descriptions.</p> +<p>This section describes the general concepts of the bytecode file +format without getting into specific layout details. It is recommended +that you read this section thoroughly before interpreting the detailed +descriptions.</p> </div> - <!-- _______________________________________________________________________ --> <div class="doc_subsection"><a name="blocks">Blocks</a> </div> <div class="doc_text"> - <p>LLVM bytecode files consist simply of a sequence of blocks of bytes using - a binary encoding Each block begins with an header of two unsigned integers. - The first value identifies the type of block and the second value provides - the size of the block in bytes. The block identifier is used because it is - possible for entire blocks to be omitted from the file if they are empty. - The block identifier helps the reader determine which kind of block is next - in the file. Note that blocks can be nested within other blocks.</p> - <p> All blocks are variable length, and the block header specifies the size - of the block. All blocks begin on a byte index that is aligned to an even - 32-bit boundary. That is, the first block is 32-bit aligned because it - starts at offset 0. Each block is padded with zero fill bytes to ensure that - the next block also starts on a 32-bit boundary.</p> +<p>LLVM bytecode files consist simply of a sequence of blocks of bytes +using a binary encoding Each block begins with an header of two +unsigned integers. The first value identifies the type of block and the +second value provides the size of the block in bytes. The block +identifier is used because it is possible for entire blocks to be +omitted from the file if they are empty. The block identifier helps the +reader determine which kind of block is next in the file. Note that +blocks can be nested within other blocks.</p> +<p> All blocks are variable length, and the block header specifies the +size of the block. All blocks begin on a byte index that is aligned to +an even 32-bit boundary. That is, the first block is 32-bit aligned +because it starts at offset 0. Each block is padded with zero fill +bytes to ensure that the next block also starts on a 32-bit boundary.</p> </div> - <!-- _______________________________________________________________________ --> <div class="doc_subsection"><a name="lists">Lists</a> </div> <div class="doc_text"> - <p>LLVM Bytecode blocks often contain lists of things of a similar type. For - example, a function contains a list of instructions and a function type - contains a list of argument types. There are two basic types of lists: - length lists (<a href="#llist">llist</a>), and null terminated lists - (<a href="#zlist">zlist</a>), as described below in the - <a href="#encoding">Encoding Primitives</a>.</p> +<p>LLVM Bytecode blocks often contain lists of things of a similar +type. For example, a function contains a list of instructions and a +function type contains a list of argument types. There are two basic +types of lists: length lists (<a href="#llist">llist</a>), and null +terminated lists (<a href="#zlist">zlist</a>), as described below in +the <a href="#encoding">Encoding Primitives</a>.</p> </div> - <!-- _______________________________________________________________________ --> <div class="doc_subsection"><a name="fields">Fields</a> </div> <div class="doc_text"> -<p>Fields are units of information that LLVM knows how to write atomically. -Most fields have a uniform length or some kind of length indication built into -their encoding. For example, a constant string (array of bytes) is -written simply as the length followed by the characters. Although this is -similar to a list, constant strings are treated atomically and are thus -fields.</p> +<p>Fields are units of information that LLVM knows how to write atomically. Most +fields have a uniform length or some kind of length indication built into their +encoding. For example, a constant string (array of bytes) is written simply as +the length followed by the characters. Although this is similar to a list, +constant strings are treated atomically and are thus fields.</p> <p>Fields use a condensed bit format specific to the type of information they must contain. As few bits as possible are written for each field. The -sections that follow will provide the details on how these fields are +sections that follow will provide the details on how these fields are written and how the bits are to be interpreted.</p> </div> - <!-- _______________________________________________________________________ --> <div class="doc_subsection"><a name="align">Alignment</a> </div> <div class="doc_text"> - <p>To support cross-platform differences, the bytecode file is aligned on - certain boundaries. This means that a small amount of padding (at most 3 - bytes) will be added to ensure that the next entry is aligned to a 32-bit - boundary.</p> +<p>To support cross-platform differences, the bytecode file is aligned +on certain boundaries. This means that a small amount of padding (at +most 3 bytes) will be added to ensure that the next entry is aligned to +a 32-bit boundary.</p> </div> - <!-- _______________________________________________________________________ --> -<div class="doc_subsection"><a name="vbr">Variable Bit-Rate Encoding</a> </div> +<div class="doc_subsection"><a name="vbr">Variable Bit-Rate Encoding</a> +</div> <div class="doc_text"> -<p>Most of the values written to LLVM bytecode files are small integers. To -minimize the number of bytes written for these quantities, an encoding -scheme similar to UTF-8 is used to write integer data. The scheme is known as -variable bit rate (vbr) encoding. In this encoding, the high bit of each -byte is used to indicate if more bytes follow. If (byte & 0x80) is non-zero -in any given byte, it means there is another byte immediately following that -also contributes to the value. For the final byte (byte & 0x80) is false -(the high bit is not set). In each byte only the low seven bits contribute to -the value. Consequently 32-bit quantities can take from one to <em>five</em> -bytes to encode. In general, smaller quantities will encode in fewer bytes, -as follows:</p> +<p>Most of the values written to LLVM bytecode files are small integers. To +minimize the number of bytes written for these quantities, an encoding scheme +similar to UTF-8 is used to write integer data. The scheme is known as +variable bit rate (vbr) encoding. In this encoding, the high bit of +each byte is used to indicate if more bytes follow. If (byte & +0x80) is non-zero in any given byte, it means there is another byte +immediately following that also contributes to the value. For the final +byte (byte & 0x80) is false (the high bit is not set). In each byte +only the low seven bits contribute to the value. Consequently 32-bit +quantities can take from one to <em>five</em> bytes to encode. In +general, smaller quantities will encode in fewer bytes, as follows:</p> <table> - <tr> - <th>Byte #</th> - <th>Significant Bits</th> - <th>Maximum Value</th> - </tr> - <tr><td>1</td><td>0-6</td><td>127</td></tr> - <tr><td>2</td><td>7-13</td><td>16,383</td></tr> - <tr><td>3</td><td>14-20</td><td>2,097,151</td></tr> - <tr><td>4</td><td>21-27</td><td>268,435,455</td></tr> - <tr><td>5</td><td>28-34</td><td>34,359,738,367</td></tr> - <tr><td>6</td><td>35-41</td><td>4,398,046,511,103</td></tr> - <tr><td>7</td><td>42-48</td><td>562,949,953,421,311</td></tr> - <tr><td>8</td><td>49-55</td><td>72,057,594,037,927,935</td></tr> - <tr><td>9</td><td>56-62</td><td>9,223,372,036,854,775,807</td></tr> - <tr><td>10</td><td>63-69</td><td>1,180,591,620,717,411,303,423</td></tr> + <tbody> + <tr> + <th>Byte #</th> + <th>Significant Bits</th> + <th>Maximum Value</th> + </tr> + <tr> + <td>1</td> + <td>0-6</td> + <td>127</td> + </tr> + <tr> + <td>2</td> + <td>7-13</td> + <td>16,383</td> + </tr> + <tr> + <td>3</td> + <td>14-20</td> + <td>2,097,151</td> + </tr> + <tr> + <td>4</td> + <td>21-27</td> + <td>268,435,455</td> + </tr> + <tr> + <td>5</td> + <td>28-34</td> + <td>34,359,738,367</td> + </tr> + <tr> + <td>6</td> + <td>35-41</td> + <td>4,398,046,511,103</td> + </tr> + <tr> + <td>7</td> + <td>42-48</td> + <td>562,949,953,421,311</td> + </tr> + <tr> + <td>8</td> + <td>49-55</td> + <td>72,057,594,037,927,935</td> + </tr> + <tr> + <td>9</td> + <td>56-62</td> + <td>9,223,372,036,854,775,807</td> + </tr> + <tr> + <td>10</td> + <td>63-69</td> + <td>1,180,591,620,717,411,303,423</td> + </tr> + </tbody> </table> -<p>Note that in practice, the tenth byte could only encode bit 63 -since the maximum quantity to use this encoding is a 64-bit integer.</p> - -<p><em>Signed</em> VBR values are encoded with the standard vbr encoding, but -with the sign bit as the low order bit instead of the high order bit. This -allows small negative quantities to be encoded efficiently. For example, -3 -is encoded as "((3 << 1) | 1)" and 3 is encoded as "(3 << 1) | -0)", emitted with the standard vbr encoding above.</p> +<p>Note that in practice, the tenth byte could only encode bit 63 since +the maximum quantity to use this encoding is a 64-bit integer.</p> +<p><em>Signed</em> VBR values are encoded with the standard vbr +encoding, but with the sign bit as the low order bit instead of the +high order bit. This allows small negative quantities to be encoded +efficiently. For example, -3 +is encoded as "((3 << 1) | 1)" and 3 is encoded as "(3 << +1) | 0)", emitted with the standard vbr encoding above.</p> </div> - <!-- _______________________________________________________________________ --> <div class="doc_subsection"><a name="encoding">Encoding Primitives</a> </div> <div class="doc_text"> - <p>Each field in the bytecode format is encoded into the file using a small - set of primitive formats. The table below defines the encoding rules for the - various primitives used and gives them each a type name. The type names used - in the descriptions of blocks and fields in the <a href="#details">Detailed - Layout</a>next section. Any type name with the suffix <em>_vbr</em> indicates - a quantity that is encoded using variable bit rate encoding as described - above.</p> -<table class="doc_table" > - <tr> - <th><b>Type</b></th> - <th class="td_left"><b>Rule</b></th> - </tr> - <tr> - <td><a name="unsigned"><b>unsigned</b></a></td> - <td class="td_left">A 32-bit unsigned integer that always occupies four +<p>Each field in the bytecode format is encoded into the file using a +small set of primitive formats. The table below defines the encoding +rules for the various primitives used and gives them each a type name. +The type names used in the descriptions of blocks and fields in the <a + href="#details">Detailed Layout</a>next section. Any type name with +the suffix <em>_vbr</em> indicates a quantity that is encoded using +variable bit rate encoding as described above.</p> +<table class="doc_table"> + <tbody> + <tr> + <th><b>Type</b></th> + <th class="td_left"><b>Rule</b></th> + </tr> + <tr> + <td><a name="unsigned"><b>unsigned</b></a></td> + <td class="td_left">A 32-bit unsigned integer that always occupies four consecutive bytes. The unsigned integer is encoded using LSB first ordering. That is bits 2<sup>0</sup> through 2<sup>7</sup> are in the byte with the lowest file offset (little endian).</td> - </tr><tr> - <td><a name="uint32_vbr"><b>uint32_vbr</b></a></td> - <td class="td_left">A 32-bit unsigned integer that occupies from one to five - bytes using variable bit rate encoding.</td> - </tr><tr> - <td><a name="uint64_vbr"><b>uint64_vbr</b></a></td> - <td class="td_left">A 64-bit unsigned integer that occupies from one to ten - bytes using variable bit rate encoding.</td> - </tr><tr> - <td><a name="int64_vbr"><b>int64_vbr</b></a></td> - <td class="td_left">A 64-bit signed integer that occupies from one to ten - bytes using the signed variable bit rate encoding.</td> - </tr><tr> - <td><a name="char"><b>char</b></a></td> - <td class="td_left">A single unsigned character encoded into one byte</td> - </tr><tr> - <td><a name="bit"><b>bit(n-m)</b></a></td> - <td class="td_left">A set of bit within some larger integer field. The - values of <code>n</code> and <code>m</code> specify the inclusive range - of bits that define the subfield. The value for <code>m</code> may be - omitted if its the same as <code>n</code>.</td> - </tr><tr> - <td><a name="string"><b>string</b></a></td> - <td class="td_left">A uint32_vbr indicating the type of the constant string - which also includes its length, immediately followed by the characters of - the string. There is no terminating null byte in the string.</td> - </tr><tr> - <td><a name="data"><b>data</b></a></td> - <td class="td_left">An arbitrarily long segment of data to which no - interpretation is implied. This is used for float, double, and constant - initializers.</td> - </tr><tr> - <td><a name="llist"><b>llist(x)</b></a></td> - <td class="td_left">A length list of x. This means the list is encoded as - an <a href="#uint32_vbr">uint32_vbr</a> providing the length of the list, - followed by a sequence of that many "x" items. This implies that the reader - should iterate the number of times provided by the length.</td> - </tr><tr> - <td><a name="zlist"><b>zlist(x)</b></a></td> - <td class="td_left">A zero-terminated list of x. This means the list is encoded - as a sequence of an indeterminate number of "x" items, followed by an - <a href="#uint32_vbr">uint32_vbr</a> terminating value. This implies that none - of the "x" items can have a zero value (or else the list terminates).</td> - </tr><tr> - <td><a name="block"><b>block</b></a></td> - <td class="td_left">A block of data that is logically related. A block - begins with an <a href="#unsigned">unsigned</a> that provides the block - identifier (constant value) and an <a href="#unsigned">unsigned</a> that - provides the length of the block. Blocks may compose other blocks. - </td> - </tr> + </tr> + <tr> + <td style="vertical-align: top;"><a name="uint24_vbr"><b>uint24_vbr</b></a></td> + <td style="vertical-align: top; text-align: left;">A 24-bit unsigned + integer that occupies from one to four bytes using variable bit rate + encoding.</td> + </tr> + <tr> + <td><a name="uint32_vbr"><b>uint32_vbr</b></a></td> + <td class="td_left">A 32-bit unsigned integer that occupies from +one to five bytes using variable bit rate encoding.</td> + </tr> + <tr> + <td><a name="uint64_vbr"><b>uint64_vbr</b></a></td> + <td class="td_left">A 64-bit unsigned integer that occupies from +one to ten bytes using variable bit rate encoding.</td> + </tr> + <tr> + <td><a name="int64_vbr"><b>int64_vbr</b></a></td> + <td class="td_left">A 64-bit signed integer that occupies from +one to ten bytes using the signed variable bit rate encoding.</td> + </tr> + <tr> + <td><a name="char"><b>char</b></a></td> + <td class="td_left">A single unsigned character encoded into one +byte</td> + </tr> + <tr> + <td><a name="bit"><b>bit(n-m)</b></a></td> + <td class="td_left">A set of bit within some larger integer +field. The values of <code>n</code> and <code>m</code> specify the +inclusive range of bits that define the subfield. The value for <code>m</code> +may be omitted if its the same as <code>n</code>.</td> + </tr> + <tr> + <td style="vertical-align: top;"><b><a name="float"><b>float</b></a></b></td> + <td style="vertical-align: top; text-align: left;">A floating +point value encoded as a 32-bit IEEE value written in little-endian +form.<br> + </td> + </tr> + <tr> + <td style="vertical-align: top;"><b><b><a name="double"><b>double</b></a></b></b></td> + <td style="vertical-align: top; text-align: left;">A floating +point value encoded as a64-bit IEEE value written in little-endian form</td> + </tr> + <tr> + <td><a name="string"><b>string</b></a></td> + <td class="td_left">A uint32_vbr indicating the type of the +constant string which also includes its length, immediately followed by +the characters of the string. There is no terminating null byte in the +string.</td> + </tr> + <tr> + <td><a name="data"><b>data</b></a></td> + <td class="td_left">An arbitrarily long segment of data to which +no interpretation is implied. This is used for constant initializers.<br> + </td> + </tr> + <tr> + <td><a name="llist"><b>llist(x)</b></a></td> + <td class="td_left">A length list of x. This means the list is +encoded as an <a href="#uint32_vbr">uint32_vbr</a> providing the +length of the list, followed by a sequence of that many "x" items. This +implies that the reader should iterate the number of times provided by +the length.</td> + </tr> + <tr> + <td><a name="zlist"><b>zlist(x)</b></a></td> + <td class="td_left">A zero-terminated list of x. This means the +list is encoded as a sequence of an indeterminate number of "x" items, +followed by an <a href="#uint32_vbr">uint32_vbr</a> terminating value. +This implies that none of the "x" items can have a zero value (or else +the list terminates).</td> + </tr> + <tr> + <td><a name="block"><b>block</b></a></td> + <td class="td_left">A block of data that is logically related. A +block is an unsigned 32-bit integer that encodes the type of the block +in the low 5 bits and the size of the block in the high 27 bits. The +length does not include the block header or any alignment bytes at the +end of the block. Blocks may compose other blocks. </td> + </tr> + </tbody> </table> </div> - <!-- _______________________________________________________________________ --> <div class="doc_subsection"><a name="notation">Field Notation</a> </div> <div class="doc_text"> - <p>In the detailed block and field descriptions that follow, a regex like - notation is used to describe optional and repeated fields. A very limited - subset of regex is used to describe these, as given in the following table: - </p> - <table class="doc_table" > +<p>In the detailed block and field descriptions that follow, a regex +like notation is used to describe optional and repeated fields. A very +limited subset of regex is used to describe these, as given in the +following table: </p> +<table class="doc_table"> + <tbody> <tr> <th><b>Character</b></th> <th class="td_left"><b>Meaning</b></th> - </tr><tr> + </tr> + <tr> <td><b><code>?</code></b></td> - <td class="td_left">The question mark indicates 0 or 1 occurrences of - the thing preceding it.</td> - </tr><tr> + <td class="td_left">The question mark indicates 0 or 1 +occurrences of the thing preceding it.</td> + </tr> + <tr> <td><b><code>*</code></b></td> - <td class="td_left">The asterisk indicates 0 or more occurrences of the - thing preceding it.</td> - </tr><tr> + <td class="td_left">The asterisk indicates 0 or more occurrences +of the thing preceding it.</td> + </tr> + <tr> <td><b><code>+</code></b></td> - <td class="td_left">The plus sign indicates 1 or more occurrences of the - thing preceding it.</td> - </tr><tr> + <td class="td_left">The plus sign indicates 1 or more occurrences +of the thing preceding it.</td> + </tr> + <tr> <td><b><code>()</code></b></td> <td class="td_left">Parentheses are used for grouping.</td> - </tr><tr> + </tr> + <tr> <td><b><code>,</code></b></td> - <td class="td_left">The comma separates sequential fields.</td> + <td class="td_left">The comma separates sequential fields.</td> </tr> - </table> - <p>So, for example, consider the following specifications:</p> - <div class="doc_code"> - <ol> - <li><code>string?</code></li> - <li><code>(uint32_vbr,uin32_vbr)+</code></li> - <li><code>(unsigned?,uint32_vbr)*</code></li> - <li><code>(llist(unsigned))?</code></li> - </ol> - </div> - <p>with the following interpretations:</p> - <ol> - <li>An optional string. Matches either nothing or a single string</li> - <li>One or more pairs of uint32_vbr.</li> - <li>Zero or more occurrences of either an unsigned followed by a uint32_vbr - or just a uint32_vbr.</li> - <li>An optional length list of unsigned values.</li> - </ol> + </tbody> +</table> +<p>So, for example, consider the following specifications:</p> +<div class="doc_code"> +<ol> + <li><code>string?</code></li> + <li><code>(uint32_vbr,uin32_vbr)+</code></li> + <li><code>(unsigned?,uint32_vbr)*</code></li> + <li><code>(llist(unsigned))?</code></li> +</ol> +</div> +<p>with the following interpretations:</p> +<ol> + <li>An optional string. Matches either nothing or a single string</li> + <li>One or more pairs of uint32_vbr.</li> + <li>Zero or more occurrences of either an unsigned followed by a +uint32_vbr or just a uint32_vbr.</li> + <li>An optional length list of unsigned values.</li> +</ol> </div> - <!-- _______________________________________________________________________ --> <div class="doc_subsection"><a name="slots">Slots</a> </div> <div class="doc_text"> -<p>The bytecode format uses the notion of a "slot" to reference Types and -Values. Since the bytecode file is a <em>direct</em> representation of LLVM's -intermediate representation, there is a need to represent pointers in the file. -Slots are used for this purpose. For example, if one has the following assembly: +<p>The bytecode format uses the notion of a "slot" to reference Types +and Values. Since the bytecode file is a <em>direct</em> representation of +LLVM's intermediate representation, there is a need to represent pointers in +the file. Slots are used for this purpose. For example, if one has the following +assembly: </p> -<div class="doc_code"><code> - %MyType = type { int, sbyte }<br> - %MyVar = external global %MyType +<div class="doc_code"><code> %MyType = type { int, sbyte }<br> +%MyVar = external global %MyType </code></div> -<p>there are two definitions. The definition of <tt>%MyVar</tt> uses -<tt>%MyType</tt>. In the C++ IR this linkage between <tt>%MyVar</tt> and -<tt>%MyType</tt> is -explicit through the use of C++ pointers. In bytecode, however, there's no -ability to store memory addresses. Instead, we compute and write out slot -numbers for every Type and Value written to the file.</p> +<p>there are two definitions. The definition of <tt>%MyVar</tt> uses <tt>%MyType</tt>. +In the C++ IR this linkage between <tt>%MyVar</tt> and <tt>%MyType</tt> +is explicit through the use of C++ pointers. In bytecode, however, there's no +ability to store memory addresses. Instead, we compute and write out +slot numbers for every Type and Value written to the file.</p> <p>A slot number is simply an unsigned 32-bit integer encoded in the variable bit rate scheme (see <a href="#encoding">encoding</a>). This ensures that low slot numbers are encoded in one byte. Through various bits of magic LLVM attempts to always keep the slot numbers low. The first attempt is to associate -slot numbers with their "type plane". That is, Values of the same type are -written to the bytecode file in a list (sequentially). Their order in that list -determines their slot number. This means that slot #1 doesn't mean anything -unless you also specify for which type you want slot #1. Types are handled -specially and are always written to the file first (in the -<a href="#globaltypes">Global Type Pool</a>) and -in such a way that both forward and backward references of the types can often be -resolved with a single pass through the type pool. </p> -<p>Slot numbers are also kept small by rearranging their order. Because of the -structure of LLVM, certain values are much more likely to be used frequently -in the body of a function. For this reason, a compaction table is provided in -the body of a function if its use would make the function body smaller. -Suppose you have a function body that uses just the types "int*" and "{double}" -but uses them thousands of time. Its worthwhile to ensure that the slot number -for these types are low so they can be encoded in a single byte (via vbr). -This is exactly what the compaction table does.</p> +slot numbers with their "type plane". That is, Values of the same type +are written to the bytecode file in a list (sequentially). Their order in +that list determines their slot number. This means that slot #1 doesn't mean +anything unless you also specify for which type you want slot #1. Types are +handled specially and are always written to the file first (in the <a + href="#globaltypes">Global Type Pool</a>) and in such a way that both forward +and backward references of the types can often be resolved with a single pass +through the type pool. </p> +<p>Slot numbers are also kept small by rearranging their order. Because +of the structure of LLVM, certain values are much more likely to be used +frequently in the body of a function. For this reason, a compaction table is +provided in the body of a function if its use would make the function body +smaller. Suppose you have a function body that uses just the types "int*" and +"{double}" but uses them thousands of time. Its worthwhile to ensure that the +slot number for these types are low so they can be encoded in a single byte +(via vbr). This is exactly what the compaction table does.</p> </div> - <!-- *********************************************************************** --> <div class="doc_section"> <a name="general">General Structure</a> </div> <!-- *********************************************************************** --> <div class="doc_text"> - <p>This section provides the general structure of the LLVM bytecode file - format. The bytecode file format requires blocks to be in a certain order and - nested in a particular way so that an LLVM module can be constructed - efficiently from the contents of the file. This ordering defines a general - structure for bytecode files as shown below. The table below shows the order - in which all block types may appear. Please note that some of the blocks are - optional and some may be repeated. The structure is fairly loose because - optional blocks, if empty, are completely omitted from the file.</p> +<p>This section provides the general structure of the LLVM bytecode +file format. The bytecode file format requires blocks to be in a +certain order and nested in a particular way so that an LLVM module can +be constructed efficiently from the contents of the file. This ordering +defines a general structure for bytecode files as shown below. The +table below shows the order in which all block types may appear. Please +note that some of the blocks are optional and some may be repeated. The +structure is fairly loose because optional blocks, if empty, are +completely omitted from the file.</p> <table> - <tr> - <th>ID</th> - <th>Parent</th> - <th>Optional?</th> - <th>Repeated?</th> - <th>Level</th> - <th>Block Type</th> - <th>Description</th> - </tr> - <tr><td>N/A</td><td>File</td><td>No</td><td>No</td><td>0</td> - <td class="td_left"><a href="#signature">Signature</a></td> - <td class="td_left">This contains the file signature (magic number) - that identifies the file as LLVM bytecode.</td> - </tr> - <tr><td>0x01</td><td>File</td><td>No</td><td>No</td><td>0</td> - <td class="td_left"><a href="#module">Module</a></td> - <td class="td_left">This is the top level block in a bytecode file. It - contains all the other blocks.</li> - </tr> - <tr><td>0x15</td><td>Module</td><td>No</td><td>No</td><td>1</td> - <td class="td_left"> <a href="#globaltypes">Global Type Pool</a></td> - <td class="td_left">This block contains all the global (module) level - types.</td> - </tr> - <tr><td>0x14</td><td>Module</td><td>No</td><td>No</td><td>1</td> - <td class="td_left"> <a href="#globalinfo">Module Globals Info</a></td> - <td class="td_left">This block contains the type, constness, and linkage - for each of the global variables in the module. It also contains the - type of the functions and the constant initializers.</td> - </tr> - <tr><td>0x12</td><td>Module</td><td>Yes</td><td>No</td><td>1</td> - <td class="td_left"> <a href="#constantpool">Module Constant Pool</a></td> - <td class="td_left">This block contains all the global constants - except function arguments, global values and constant strings.</td> - </tr> - <tr><td>0x11</td><td>Module</td><td>Yes</td><td>Yes</td><td>1</td> - <td class="td_left"> <a href="#functiondefs">Function Definitions</a>*</td> - <td class="td_left">One function block is written for each function in - the module. The function block contains the instructions, compaction - table, type constant pool, and symbol table for the function.</td> - </tr> - <tr><td>0x12</td><td>Function</td><td>Yes</td><td>No</td><td>2</td> - <td class="td_left"> <a href="#constantpool">Function Constant Pool</a></td> - <td class="td_left">Any constants (including types) used solely - within the function are emitted here in the function constant pool. - </td> - </tr> - <tr><td>0x33</td><td>Function</td><td>Yes</td><td>No</td><td>2</td> - <td class="td_left"> <a href="#compactiontable">Compaction Table</a></td> - <td class="td_left">This table reduces bytecode size by providing a - funtion-local mapping of type and value slot numbers to their - global slot numbers</td> - </tr> - <tr><td>0x32</td><td>Function</td><td>No</td><td>No</td><td>2</td> - <td class="td_left"> <a href="#instructionlist">Instruction List</a></td> - <td class="td_left">This block contains all the instructions of the - function. The basic blocks are inferred by terminating instructions. - </td> - </tr> - <tr><td>0x13</td><td>Function</td><td>Yes</td><td>No</td><td>2</td> - <td class="td_left"> <a href="#symtab">Function Symbol Table</a></td> - <td class="td_left">This symbol table provides the names for the - function specific values used (basic block labels mostly).</td> - </tr> - <tr><td>0x13</td><td>Module</td><td>Yes</td><td>No</td><td>1</td> - <td class="td_left"> <a href="#symtab">Module Symbol Table</a></td> - <td class="td_left">This symbol table provides the names for the various - entries in the file that are not function specific (global vars, and - functions mostly).</td> - </tr> + <tbody> + <tr> + <th>ID</th> + <th>Parent</th> + <th>Optional?</th> + <th>Repeated?</th> + <th>Level</th> + <th>Block Type</th> + <th>Description</th> + </tr> + <tr> + <td>N/A</td> + <td>File</td> + <td>No</td> + <td>No</td> + <td>0</td> + <td class="td_left"><a href="#signature">Signature</a></td> + <td class="td_left">This contains the file signature (magic +number) that identifies the file as LLVM bytecode.</td> + </tr> + <tr> + <td>0x01</td> + <td>File</td> + <td>No</td> + <td>No</td> + <td>0</td> + <td class="td_left"><a href="#module">Module</a></td> + <td class="td_left">This is the top level block in a bytecode +file. It contains all the other blocks. </td> + </tr> + <tr> + <td>0x06</td> + <td>Module</td> + <td>No</td> + <td>No</td> + <td>1</td> + <td class="td_left"> <a h |