blob: 7194c7a6d343e45c75b092ca2344697444cdec2a [file] [log] [blame]
Chris Lattner3a1716d2007-05-12 05:37:42 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
Reid Spencer2c1ce4f2007-01-20 23:21:08 +00003<html>
4<head>
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
6 <title>LLVM Bitcode File Format</title>
7 <link rel="stylesheet" href="llvm.css" type="text/css">
Reid Spencer2c1ce4f2007-01-20 23:21:08 +00008</head>
9<body>
10<div class="doc_title"> LLVM Bitcode File Format </div>
11<ol>
12 <li><a href="#abstract">Abstract</a></li>
Chris Lattnere9ef4572007-05-12 03:23:40 +000013 <li><a href="#overview">Overview</a></li>
14 <li><a href="#bitstream">Bitstream Format</a>
15 <ol>
16 <li><a href="#magic">Magic Numbers</a></li>
Chris Lattner3a1716d2007-05-12 05:37:42 +000017 <li><a href="#primitives">Primitives</a></li>
18 <li><a href="#abbrevid">Abbreviation IDs</a></li>
19 <li><a href="#blocks">Blocks</a></li>
20 <li><a href="#datarecord">Data Records</a></li>
Chris Lattnerdaeb63c2007-05-12 07:49:15 +000021 <li><a href="#abbreviations">Abbreviations</a></li>
Chris Lattner7300af52007-05-13 00:59:52 +000022 <li><a href="#stdblocks">Standard Blocks</a></li>
Chris Lattnere9ef4572007-05-12 03:23:40 +000023 </ol>
24 </li>
Chris Lattner69b3e402007-05-13 01:39:44 +000025 <li><a href="#llvmir">LLVM IR Encoding</a>
26 <ol>
27 <li><a href="#basics">Basics</a></li>
28 </ol>
29 </li>
Reid Spencer2c1ce4f2007-01-20 23:21:08 +000030</ol>
31<div class="doc_author">
Chris Lattnere9ef4572007-05-12 03:23:40 +000032 <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a>.
Reid Spencer2c1ce4f2007-01-20 23:21:08 +000033</p>
34</div>
Chris Lattnere9ef4572007-05-12 03:23:40 +000035
Reid Spencer2c1ce4f2007-01-20 23:21:08 +000036<!-- *********************************************************************** -->
Chris Lattnere9ef4572007-05-12 03:23:40 +000037<div class="doc_section"> <a name="abstract">Abstract</a></div>
Reid Spencer2c1ce4f2007-01-20 23:21:08 +000038<!-- *********************************************************************** -->
Chris Lattnere9ef4572007-05-12 03:23:40 +000039
Reid Spencer2c1ce4f2007-01-20 23:21:08 +000040<div class="doc_text">
Chris Lattnere9ef4572007-05-12 03:23:40 +000041
42<p>This document describes the LLVM bitstream file format and the encoding of
43the LLVM IR into it.</p>
44
Reid Spencer2c1ce4f2007-01-20 23:21:08 +000045</div>
Chris Lattnere9ef4572007-05-12 03:23:40 +000046
Reid Spencer2c1ce4f2007-01-20 23:21:08 +000047<!-- *********************************************************************** -->
Chris Lattnere9ef4572007-05-12 03:23:40 +000048<div class="doc_section"> <a name="overview">Overview</a></div>
Reid Spencer2c1ce4f2007-01-20 23:21:08 +000049<!-- *********************************************************************** -->
Chris Lattnere9ef4572007-05-12 03:23:40 +000050
Reid Spencer2c1ce4f2007-01-20 23:21:08 +000051<div class="doc_text">
Chris Lattnere9ef4572007-05-12 03:23:40 +000052
53<p>
54What is commonly known as the LLVM bitcode file format (also, sometimes
55anachronistically known as bytecode) is actually two things: a <a
56href="#bitstream">bitstream container format</a>
57and an <a href="#llvmir">encoding of LLVM IR</a> into the container format.</p>
58
59<p>
Reid Spencer58d05472007-05-12 08:01:52 +000060The bitstream format is an abstract encoding of structured data, very
Chris Lattnere9ef4572007-05-12 03:23:40 +000061similar to XML in some ways. Like XML, bitstream files contain tags, and nested
62structures, and you can parse the file without having to understand the tags.
63Unlike XML, the bitstream format is a binary encoding, and unlike XML it
64provides a mechanism for the file to self-describe "abbreviations", which are
65effectively size optimizations for the content.</p>
66
67<p>This document first describes the LLVM bitstream format, then describes the
68record structure used by LLVM IR files.
69</p>
70
Reid Spencer2c1ce4f2007-01-20 23:21:08 +000071</div>
Chris Lattnere9ef4572007-05-12 03:23:40 +000072
73<!-- *********************************************************************** -->
74<div class="doc_section"> <a name="bitstream">Bitstream Format</a></div>
75<!-- *********************************************************************** -->
76
77<div class="doc_text">
78
79<p>
80The bitstream format is literally a stream of bits, with a very simple
81structure. This structure consists of the following concepts:
82</p>
83
84<ul>
Chris Lattner3a1716d2007-05-12 05:37:42 +000085<li>A "<a href="#magic">magic number</a>" that identifies the contents of
86 the stream.</li>
87<li>Encoding <a href="#primitives">primitives</a> like variable bit-rate
88 integers.</li>
89<li><a href="#blocks">Blocks</a>, which define nested content.</li>
90<li><a href="#datarecord">Data Records</a>, which describe entities within the
91 file.</li>
Chris Lattnere9ef4572007-05-12 03:23:40 +000092<li>Abbreviations, which specify compression optimizations for the file.</li>
93</ul>
94
95<p>Note that the <a
96href="CommandGuide/html/llvm-bcanalyzer.html">llvm-bcanalyzer</a> tool can be
97used to dump and inspect arbitrary bitstreams, which is very useful for
98understanding the encoding.</p>
99
100</div>
101
102<!-- ======================================================================= -->
103<div class="doc_subsection"><a name="magic">Magic Numbers</a>
104</div>
105
106<div class="doc_text">
107
Chris Lattner3a1716d2007-05-12 05:37:42 +0000108<p>The first four bytes of the stream identify the encoding of the file. This
109is used by a reader to know what is contained in the file.</p>
Chris Lattnere9ef4572007-05-12 03:23:40 +0000110
111</div>
112
Chris Lattner3a1716d2007-05-12 05:37:42 +0000113<!-- ======================================================================= -->
114<div class="doc_subsection"><a name="primitives">Primitives</a>
115</div>
Chris Lattnere9ef4572007-05-12 03:23:40 +0000116
117<div class="doc_text">
118
Chris Lattner3a1716d2007-05-12 05:37:42 +0000119<p>
120A bitstream literally consists of a stream of bits. This stream is made up of a
Chris Lattner69b3e402007-05-13 01:39:44 +0000121number of primitive values that encode a stream of unsigned integer values.
122These
Chris Lattner3a1716d2007-05-12 05:37:42 +0000123integers are are encoded in two ways: either as <a href="#fixedwidth">Fixed
124Width Integers</a> or as <a href="#variablewidth">Variable Width
125Integers</a>.
Chris Lattnere9ef4572007-05-12 03:23:40 +0000126</p>
127
128</div>
129
Chris Lattner3a1716d2007-05-12 05:37:42 +0000130<!-- _______________________________________________________________________ -->
131<div class="doc_subsubsection"> <a name="fixedwidth">Fixed Width Integers</a>
132</div>
133
134<div class="doc_text">
135
136<p>Fixed-width integer values have their low bits emitted directly to the file.
137 For example, a 3-bit integer value encodes 1 as 001. Fixed width integers
138 are used when there are a well-known number of options for a field. For
139 example, boolean values are usually encoded with a 1-bit wide integer.
140</p>
141
142</div>
143
144<!-- _______________________________________________________________________ -->
145<div class="doc_subsubsection"> <a name="variablewidth">Variable Width
146Integers</a></div>
147
148<div class="doc_text">
149
150<p>Variable-width integer (VBR) values encode values of arbitrary size,
151optimizing for the case where the values are small. Given a 4-bit VBR field,
152any 3-bit value (0 through 7) is encoded directly, with the high bit set to
153zero. Values larger than N-1 bits emit their bits in a series of N-1 bit
154chunks, where all but the last set the high bit.</p>
155
156<p>For example, the value 27 (0x1B) is encoded as 1011 0011 when emitted as a
157vbr4 value. The first set of four bits indicates the value 3 (011) with a
158continuation piece (indicated by a high bit of 1). The next word indicates a
159value of 24 (011 << 3) with no continuation. The sum (3+24) yields the value
16027.
161</p>
162
163</div>
164
165<!-- _______________________________________________________________________ -->
166<div class="doc_subsubsection"> <a name="char6">6-bit characters</a></div>
167
168<div class="doc_text">
169
170<p>6-bit characters encode common characters into a fixed 6-bit field. They
Chris Lattnerf1d64e92007-05-12 07:50:14 +0000171represent the following characters with the following 6-bit values:</p>
Chris Lattner3a1716d2007-05-12 05:37:42 +0000172
173<ul>
174<li>'a' .. 'z' - 0 .. 25</li>
175<li>'A' .. 'Z' - 26 .. 52</li>
176<li>'0' .. '9' - 53 .. 61</li>
177<li>'.' - 62</li>
178<li>'_' - 63</li>
179</ul>
180
181<p>This encoding is only suitable for encoding characters and strings that
182consist only of the above characters. It is completely incapable of encoding
183characters not in the set.</p>
184
185</div>
186
187<!-- _______________________________________________________________________ -->
188<div class="doc_subsubsection"> <a name="wordalign">Word Alignment</a></div>
189
190<div class="doc_text">
191
192<p>Occasionally, it is useful to emit zero bits until the bitstream is a
193multiple of 32 bits. This ensures that the bit position in the stream can be
194represented as a multiple of 32-bit words.</p>
195
196</div>
197
198
199<!-- ======================================================================= -->
200<div class="doc_subsection"><a name="abbrevid">Abbreviation IDs</a>
201</div>
202
203<div class="doc_text">
204
205<p>
206A bitstream is a sequential series of <a href="#blocks">Blocks</a> and
207<a href="#datarecord">Data Records</a>. Both of these start with an
208abbreviation ID encoded as a fixed-bitwidth field. The width is specified by
209the current block, as described below. The value of the abbreviation ID
210specifies either a builtin ID (which have special meanings, defined below) or
211one of the abbreviation IDs defined by the stream itself.
212</p>
213
214<p>
215The set of builtin abbrev IDs is:
216</p>
217
218<ul>
219<li>0 - <a href="#END_BLOCK">END_BLOCK</a> - This abbrev ID marks the end of the
220 current block.</li>
221<li>1 - <a href="#ENTER_SUBBLOCK">ENTER_SUBBLOCK</a> - This abbrev ID marks the
222 beginning of a new block.</li>
Chris Lattnerdaeb63c2007-05-12 07:49:15 +0000223<li>2 - <a href="#DEFINE_ABBREV">DEFINE_ABBREV</a> - This defines a new
224 abbreviation.</li>
225<li>3 - <a href="#UNABBREV_RECORD">UNABBREV_RECORD</a> - This ID specifies the
226 definition of an unabbreviated record.</li>
Chris Lattner3a1716d2007-05-12 05:37:42 +0000227</ul>
228
Chris Lattnerdaeb63c2007-05-12 07:49:15 +0000229<p>Abbreviation IDs 4 and above are defined by the stream itself, and specify
230an <a href="#abbrev_records">abbreviated record encoding</a>.</p>
Chris Lattner3a1716d2007-05-12 05:37:42 +0000231
232</div>
233
234<!-- ======================================================================= -->
235<div class="doc_subsection"><a name="blocks">Blocks</a>
236</div>
237
238<div class="doc_text">
239
240<p>
241Blocks in a bitstream denote nested regions of the stream, and are identified by
242a content-specific id number (for example, LLVM IR uses an ID of 12 to represent
243function bodies). Nested blocks capture the hierachical structure of the data
244encoded in it, and various properties are associated with blocks as the file is
245parsed. Block definitions allow the reader to efficiently skip blocks
246in constant time if the reader wants a summary of blocks, or if it wants to
247efficiently skip data they do not understand. The LLVM IR reader uses this
248mechanism to skip function bodies, lazily reading them on demand.
249</p>
250
251<p>
252When reading and encoding the stream, several properties are maintained for the
253block. In particular, each block maintains:
254</p>
255
256<ol>
257<li>A current abbrev id width. This value starts at 2, and is set every time a
258 block record is entered. The block entry specifies the abbrev id width for
259 the body of the block.</li>
260
261<li>A set of abbreviations. Abbreviations may be defined within a block, or
262 they may be associated with all blocks of a particular ID.
263</li>
264</ol>
265
266<p>As sub blocks are entered, these properties are saved and the new sub-block
267has its own set of abbreviations, and its own abbrev id width. When a sub-block
268is popped, the saved values are restored.</p>
269
270</div>
271
272<!-- _______________________________________________________________________ -->
273<div class="doc_subsubsection"> <a name="ENTER_SUBBLOCK">ENTER_SUBBLOCK
274Encoding</a></div>
275
276<div class="doc_text">
277
278<p><tt>[ENTER_SUBBLOCK, blockid<sub>vbr8</sub>, newabbrevlen<sub>vbr4</sub>,
279 &lt;align32bits&gt;, blocklen<sub>32</sub>]</tt></p>
280
281<p>
282The ENTER_SUBBLOCK abbreviation ID specifies the start of a new block record.
283The <tt>blockid</tt> value is encoded as a 8-bit VBR identifier, and indicates
284the type of block being entered (which is application specific). The
285<tt>newabbrevlen</tt> value is a 4-bit VBR which specifies the
286abbrev id width for the sub-block. The <tt>blocklen</tt> is a 32-bit aligned
287value that specifies the size of the subblock, in 32-bit words. This value
288allows the reader to skip over the entire block in one jump.
289</p>
290
291</div>
292
293<!-- _______________________________________________________________________ -->
294<div class="doc_subsubsection"> <a name="END_BLOCK">END_BLOCK
295Encoding</a></div>
296
297<div class="doc_text">
298
299<p><tt>[END_BLOCK, &lt;align32bits&gt;]</tt></p>
300
301<p>
302The END_BLOCK abbreviation ID specifies the end of the current block record.
303Its end is aligned to 32-bits to ensure that the size of the block is an even
304multiple of 32-bits.</p>
305
306</div>
307
308
309
310<!-- ======================================================================= -->
311<div class="doc_subsection"><a name="datarecord">Data Records</a>
312</div>
313
314<div class="doc_text">
Chris Lattnerdaeb63c2007-05-12 07:49:15 +0000315<p>
316Data records consist of a record code and a number of (up to) 64-bit integer
317values. The interpretation of the code and values is application specific and
318there are multiple different ways to encode a record (with an unabbrev record
319or with an abbreviation). In the LLVM IR format, for example, there is a record
320which encodes the target triple of a module. The code is MODULE_CODE_TRIPLE,
321and the values of the record are the ascii codes for the characters in the
322string.</p>
323
324</div>
325
326<!-- _______________________________________________________________________ -->
327<div class="doc_subsubsection"> <a name="UNABBREV_RECORD">UNABBREV_RECORD
328Encoding</a></div>
329
330<div class="doc_text">
331
332<p><tt>[UNABBREV_RECORD, code<sub>vbr6</sub>, numops<sub>vbr6</sub>,
333 op0<sub>vbr6</sub>, op1<sub>vbr6</sub>, ...]</tt></p>
334
335<p>An UNABBREV_RECORD provides a default fallback encoding, which is both
336completely general and also extremely inefficient. It can describe an arbitrary
337record, by emitting the code and operands as vbrs.</p>
338
339<p>For example, emitting an LLVM IR target triple as an unabbreviated record
340requires emitting the UNABBREV_RECORD abbrevid, a vbr6 for the
341MODULE_CODE_TRIPLE code, a vbr6 for the length of the string (which is equal to
342the number of operands), and a vbr6 for each character. Since there are no
343letters with value less than 32, each letter would need to be emitted as at
344least a two-part VBR, which means that each letter would require at least 12
345bits. This is not an efficient encoding, but it is fully general.</p>
346
347</div>
348
349<!-- _______________________________________________________________________ -->
350<div class="doc_subsubsection"> <a name="abbrev_records">Abbreviated Record
351Encoding</a></div>
352
353<div class="doc_text">
354
355<p><tt>[&lt;abbrevid&gt;, fields...]</tt></p>
356
357<p>An abbreviated record is a abbreviation id followed by a set of fields that
358are encoded according to the <a href="#abbreviations">abbreviation
359definition</a>. This allows records to be encoded significantly more densely
360than records encoded with the <a href="#UNABBREV_RECORD">UNABBREV_RECORD</a>
361type, and allows the abbreviation types to be specified in the stream itself,
362which allows the files to be completely self describing. The actual encoding
363of abbreviations is defined below.
364</p>
365
366</div>
367
368<!-- ======================================================================= -->
369<div class="doc_subsection"><a name="abbreviations">Abbreviations</a>
370</div>
371
372<div class="doc_text">
373<p>
374Abbreviations are an important form of compression for bitstreams. The idea is
375to specify a dense encoding for a class of records once, then use that encoding
376to emit many records. It takes space to emit the encoding into the file, but
377the space is recouped (hopefully plus some) when the records that use it are
378emitted.
379</p>
Chris Lattner3a1716d2007-05-12 05:37:42 +0000380
381<p>
Chris Lattnerdaeb63c2007-05-12 07:49:15 +0000382Abbreviations can be determined dynamically per client, per file. Since the
383abbreviations are stored in the bitstream itself, different streams of the same
384format can contain different sets of abbreviations if the specific stream does
385not need it. As a concrete example, LLVM IR files usually emit an abbreviation
386for binary operators. If a specific LLVM module contained no or few binary
387operators, the abbreviation does not need to be emitted.
Chris Lattner3a1716d2007-05-12 05:37:42 +0000388</p>
Chris Lattnerdaeb63c2007-05-12 07:49:15 +0000389</div>
390
391<!-- _______________________________________________________________________ -->
392<div class="doc_subsubsection"><a name="DEFINE_ABBREV">DEFINE_ABBREV
393 Encoding</a></div>
394
395<div class="doc_text">
396
397<p><tt>[DEFINE_ABBREV, numabbrevops<sub>vbr5</sub>, abbrevop0, abbrevop1,
398 ...]</tt></p>
399
400<p>An abbreviation definition consists of the DEFINE_ABBREV abbrevid followed
401by a VBR that specifies the number of abbrev operands, then the abbrev
402operands themselves. Abbreviation operands come in three forms. They all start
403with a single bit that indicates whether the abbrev operand is a literal operand
404(when the bit is 1) or an encoding operand (when the bit is 0).</p>
405
406<ol>
407<li>Literal operands - <tt>[1<sub>1</sub>, litvalue<sub>vbr8</sub>]</tt> -
408Literal operands specify that the value in the result
409is always a single specific value. This specific value is emitted as a vbr8
410after the bit indicating that it is a literal operand.</li>
411<li>Encoding info without data - <tt>[0<sub>1</sub>, encoding<sub>3</sub>]</tt>
Chris Lattner7300af52007-05-13 00:59:52 +0000412 - Operand encodings that do not have extra data are just emitted as their code.
Chris Lattnerdaeb63c2007-05-12 07:49:15 +0000413</li>
414<li>Encoding info with data - <tt>[0<sub>1</sub>, encoding<sub>3</sub>,
Chris Lattner7300af52007-05-13 00:59:52 +0000415value<sub>vbr5</sub>]</tt> - Operand encodings that do have extra data are
416emitted as their code, followed by the extra data.
Chris Lattnerdaeb63c2007-05-12 07:49:15 +0000417</li>
418</ol>
Chris Lattner3a1716d2007-05-12 05:37:42 +0000419
Chris Lattner7300af52007-05-13 00:59:52 +0000420<p>The possible operand encodings are:</p>
421
422<ul>
423<li>1 - Fixed - The field should be emitted as a <a
424 href="#fixedwidth">fixed-width value</a>, whose width
425 is specified by the encoding operand.</li>
426<li>2 - VBR - The field should be emitted as a <a
427 href="#variablewidth">variable-width value</a>, whose width
428 is specified by the encoding operand.</li>
429<li>3 - Array - This field is an array of values. The element type of the array
430 is specified by the next encoding operand.</li>
431<li>4 - Char6 - This field should be emitted as a <a href="#char6">char6-encoded
432 value</a>.</li>
433</ul>
434
435<p>For example, target triples in LLVM modules are encoded as a record of the
436form <tt>[TRIPLE, 'a', 'b', 'c', 'd']</tt>. Consider if the bitstream emitted
437the following abbrev entry:</p>
438
439<ul>
440<li><tt>[0, Fixed, 4]</tt></li>
441<li><tt>[0, Array]</tt></li>
442<li><tt>[0, Char6]</tt></li>
443</ul>
444
445<p>When emitting a record with this abbreviation, the above entry would be
446emitted as:</p>
447
448<p><tt>[4<sub>abbrevwidth</sub>, 2<sub>4</sub>, 4<sub>vbr6</sub>,
449 0<sub>6</sub>, 1<sub>6</sub>, 2<sub>6</sub>, 3<sub>6</sub>]</tt></p>
450
451<p>These values are:</p>
452
453<ol>
454<li>The first value, 4, is the abbreviation ID for this abbreviation.</li>
455<li>The second value, 2, is the code for TRIPLE in LLVM IR files.</li>
456<li>The third value, 4, is the length of the array.</li>
457<li>The rest of the values are the char6 encoded values for "abcd".</li>
458</ol>
459
460<p>With this abbreviation, the triple is emitted with only 37 bits (assuming a
461abbrev id width of 3). Without the abbreviation, significantly more space would
462be required to emit the target triple. Also, since the TRIPLE value is not
463emitted as a literal in the abbreviation, the abbreviation can also be used for
464any other string value.
465</p>
466
Chris Lattner3a1716d2007-05-12 05:37:42 +0000467</div>
468
Chris Lattner7300af52007-05-13 00:59:52 +0000469<!-- ======================================================================= -->
470<div class="doc_subsection"><a name="stdblocks">Standard Blocks</a>
471</div>
472
473<div class="doc_text">
474
475<p>
476In addition to the basic block structure and record encodings, the bitstream
477also defines specific builtin block types. These block types specify how the
478stream is to be decoded or other metadata. In the future, new standard blocks
479may be added.
480</p>
481
482</div>
483
484<!-- _______________________________________________________________________ -->
485<div class="doc_subsubsection"><a name="BLOCKINFO">#0 - BLOCKINFO
486Block</a></div>
487
488<div class="doc_text">
489
490<p>The BLOCKINFO block allows the description of metadata for other blocks. The
491 currently specified records are:</p>
492
493<ul>
494<li><tt>[SETBID (#1), blockid]</tt></li>
495<li><tt>[DEFINE_ABBREV, ...]</tt></li>
496</ul>
497
498<p>
499The SETBID record indicates which block ID is being described. The standard
500DEFINE_ABBREV record specifies an abbreviation. The abbreviation is associated
501with the record ID, and any records with matching ID automatically get the
502abbreviation.
503</p>
504
505</div>
Chris Lattner3a1716d2007-05-12 05:37:42 +0000506
Chris Lattnere9ef4572007-05-12 03:23:40 +0000507<!-- *********************************************************************** -->
508<div class="doc_section"> <a name="llvmir">LLVM IR Encoding</a></div>
509<!-- *********************************************************************** -->
510
511<div class="doc_text">
512
Chris Lattner69b3e402007-05-13 01:39:44 +0000513<p>LLVM IR is encoded into a bitstream by defining blocks and records. It uses
514blocks for things like constant pools, functions, symbol tables, etc. It uses
515records for things like instructions, global variable descriptors, type
516descriptions, etc. This document does not describe the set of abbreviations
517that the writer uses, as these are fully self-described in the file, and the
518reader is not allowed to build in any knowledge of this.</p>
519
520</div>
521
522<!-- ======================================================================= -->
523<div class="doc_subsection"><a name="basics">Basics</a>
524</div>
525
526<!-- _______________________________________________________________________ -->
527<div class="doc_subsubsection"><a name="ir_magic">LLVM IR Magic Number</a></div>
528
529<div class="doc_text">
530
531<p>
532The magic number for LLVM IR files is:
533</p>
534
535<p><tt>['B'<sub>8</sub>, 'C'<sub>8</sub>, 0x0<sub>4</sub>, 0xC<sub>4</sub>,
5360xE<sub>4</sub>, 0xD<sub>4</sub>]</tt></p>
537
538<p>When viewed as bytes, this is "BC 0xC0DE".</p>
539
540</div>
541
542<!-- _______________________________________________________________________ -->
543<div class="doc_subsubsection"><a name="ir_signed_vbr">Signed VBRs</a></div>
544
545<div class="doc_text">
546
547<p>
548<a href="#variablewidth">Variable Width Integers</a> are an efficient way to
549encode arbitrary sized unsigned values, but is an extremely inefficient way to
550encode signed values (as signed values are otherwise treated as maximally large
551unsigned values).</p>
552
553<p>As such, signed vbr values of a specific width are emitted as follows:</p>
554
555<ul>
556<li>Positive values are emitted as vbrs of the specified width, but with their
557 value shifted left by one.</li>
558<li>Negative values are emitted as vbrs of the specified width, but the negated
559 value is shifted left by one, and the low bit is set.</li>
560</ul>
561
562<p>With this encoding, small positive and small negative values can both be
563emitted efficiently.</p>
564
565</div>
566
567
568<!-- _______________________________________________________________________ -->
569<div class="doc_subsubsection"><a name="ir_blocks">LLVM IR Blocks</a></div>
570
571<div class="doc_text">
572
573<p>
574LLVM IR is defined with the following blocks:
575</p>
576
577<ul>
578<li>8 - MODULE_BLOCK - This is the top-level block that contains the
579 entire module, and describes a variety of per-module information.</li>
580<li>9 - PARAMATTR_BLOCK - This enumerates the parameter attributes.</li>
581<li>10 - TYPE_BLOCK - This describes all of the types in the module.</li>
582<li>11 - CONSTANTS_BLOCK - This describes constants for a module or
583 function.</li>
584<li>12 - FUNCTION_BLOCK - This describes a function body.</li>
585<li>13 - TYPE_SYMTAB_BLOCK - This describes the type symbol table.</li>
586<li>14 - VALUE_SYMTAB_BLOCK - This describes a value symbol table.</li>
587</ul>
588
589</div>
590
591<!-- ======================================================================= -->
592<div class="doc_subsection"><a name="MODULE_BLOCK">MODULE_BLOCK Contents</a>
593</div>
594
595<div class="doc_text">
596
597<p>
598</p>
Chris Lattnere9ef4572007-05-12 03:23:40 +0000599
600</div>
601
602
Reid Spencer2c1ce4f2007-01-20 23:21:08 +0000603<!-- *********************************************************************** -->
604<hr>
605<address> <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
606 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
607<a href="http://validator.w3.org/check/referer"><img
608 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!"></a>
Chris Lattnere9ef4572007-05-12 03:23:40 +0000609 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
Reid Spencer2c1ce4f2007-01-20 23:21:08 +0000610<a href="http://llvm.org">The LLVM Compiler Infrastructure</a><br>
611Last modified: $Date$
612</address>
613</body>
614</html>