xref: /openbsd-src/gnu/llvm/llvm/docs/BitCodeFormat.rst (revision d415bd752c734aee168c4ee86ff32e8cc249eb16)
1.. role:: raw-html(raw)
2   :format: html
3
4========================
5LLVM Bitcode File Format
6========================
7
8.. contents::
9   :local:
10
11Abstract
12========
13
14This document describes the LLVM bitstream file format and the encoding of the
15LLVM IR into it.
16
17Overview
18========
19
20What is commonly known as the LLVM bitcode file format (also, sometimes
21anachronistically known as bytecode) is actually two things: a `bitstream
22container format`_ and an `encoding of LLVM IR`_ into the container format.
23
24The bitstream format is an abstract encoding of structured data, very similar to
25XML in some ways.  Like XML, bitstream files contain tags, and nested
26structures, and you can parse the file without having to understand the tags.
27Unlike XML, the bitstream format is a binary encoding, and unlike XML it
28provides a mechanism for the file to self-describe "abbreviations", which are
29effectively size optimizations for the content.
30
31LLVM IR files may be optionally embedded into a `wrapper`_ structure, or in a
32`native object file`_. Both of these mechanisms make it easy to embed extra
33data along with LLVM IR files.
34
35This document first describes the LLVM bitstream format, describes the wrapper
36format, then describes the record structure used by LLVM IR files.
37
38.. _bitstream container format:
39
40Bitstream Format
41================
42
43The bitstream format is literally a stream of bits, with a very simple
44structure.  This structure consists of the following concepts:
45
46* A "`magic number`_" that identifies the contents of the stream.
47
48* Encoding `primitives`_ like variable bit-rate integers.
49
50* `Blocks`_, which define nested content.
51
52* `Data Records`_, which describe entities within the file.
53
54* Abbreviations, which specify compression optimizations for the file.
55
56Note that the :doc:`llvm-bcanalyzer <CommandGuide/llvm-bcanalyzer>` tool can be
57used to dump and inspect arbitrary bitstreams, which is very useful for
58understanding the encoding.
59
60.. _magic number:
61
62Magic Numbers
63-------------
64
65The first four bytes of a bitstream are used as an application-specific magic
66number.  Generic bitcode tools may look at the first four bytes to determine
67whether the stream is a known stream type.  However, these tools should *not*
68determine whether a bitstream is valid based on its magic number alone.  New
69application-specific bitstream formats are being developed all the time; tools
70should not reject them just because they have a hitherto unseen magic number.
71
72.. _primitives:
73
74Primitives
75----------
76
77A bitstream literally consists of a stream of bits, which are read in order
78starting with the least significant bit of each byte.  The stream is made up of
79a number of primitive values that encode a stream of unsigned integer values.
80These integers are encoded in two ways: either as `Fixed Width Integers`_ or as
81`Variable Width Integers`_.
82
83.. _Fixed Width Integers:
84.. _fixed-width value:
85
86Fixed Width Integers
87^^^^^^^^^^^^^^^^^^^^
88
89Fixed-width integer values have their low bits emitted directly to the file.
90For example, a 3-bit integer value encodes 1 as 001.  Fixed width integers are
91used when there are a well-known number of options for a field.  For example,
92boolean values are usually encoded with a 1-bit wide integer.
93
94.. _Variable Width Integers:
95.. _Variable Width Integer:
96.. _variable-width value:
97
98Variable Width Integers
99^^^^^^^^^^^^^^^^^^^^^^^
100
101Variable-width integer (VBR) values encode values of arbitrary size, optimizing
102for the case where the values are small.  Given a 4-bit VBR field, any 3-bit
103value (0 through 7) is encoded directly, with the high bit set to zero.  Values
104larger than N-1 bits emit their bits in a series of N-1 bit chunks, where all
105but the last set the high bit.
106
107For example, the value 30 (0x1E) is encoded as 62 (0b0011'1110) when emitted as
108a vbr4 value.  The first set of four bits starting from the least significant
109indicates the value 6 (110) with a continuation piece (indicated by a high bit
110of 1).  The next set of four bits indicates a value of 24 (011 << 3) with no
111continuation.  The sum (6+24) yields the value 30.
112
113.. _char6-encoded value:
114
1156-bit characters
116^^^^^^^^^^^^^^^^
117
1186-bit characters encode common characters into a fixed 6-bit field.  They
119represent the following characters with the following 6-bit values:
120
121::
122
123  'a' .. 'z' ---  0 .. 25
124  'A' .. 'Z' --- 26 .. 51
125  '0' .. '9' --- 52 .. 61
126         '.' --- 62
127         '_' --- 63
128
129This encoding is only suitable for encoding characters and strings that consist
130only of the above characters.  It is completely incapable of encoding characters
131not in the set.
132
133Word Alignment
134^^^^^^^^^^^^^^
135
136Occasionally, it is useful to emit zero bits until the bitstream is a multiple
137of 32 bits.  This ensures that the bit position in the stream can be represented
138as a multiple of 32-bit words.
139
140Abbreviation IDs
141----------------
142
143A bitstream is a sequential series of `Blocks`_ and `Data Records`_.  Both of
144these start with an abbreviation ID encoded as a fixed-bitwidth field.  The
145width is specified by the current block, as described below.  The value of the
146abbreviation ID specifies either a builtin ID (which have special meanings,
147defined below) or one of the abbreviation IDs defined for the current block by
148the stream itself.
149
150The set of builtin abbrev IDs is:
151
152* 0 - `END_BLOCK`_ --- This abbrev ID marks the end of the current block.
153
154* 1 - `ENTER_SUBBLOCK`_ --- This abbrev ID marks the beginning of a new
155  block.
156
157* 2 - `DEFINE_ABBREV`_ --- This defines a new abbreviation.
158
159* 3 - `UNABBREV_RECORD`_ --- This ID specifies the definition of an
160  unabbreviated record.
161
162Abbreviation IDs 4 and above are defined by the stream itself, and specify an
163`abbreviated record encoding`_.
164
165.. _Blocks:
166
167Blocks
168------
169
170Blocks in a bitstream denote nested regions of the stream, and are identified by
171a content-specific id number (for example, LLVM IR uses an ID of 12 to represent
172function bodies).  Block IDs 0-7 are reserved for `standard blocks`_ whose
173meaning is defined by Bitcode; block IDs 8 and greater are application
174specific. Nested blocks capture the hierarchical structure of the data encoded
175in it, and various properties are associated with blocks as the file is parsed.
176Block definitions allow the reader to efficiently skip blocks in constant time
177if the reader wants a summary of blocks, or if it wants to efficiently skip data
178it does not understand.  The LLVM IR reader uses this mechanism to skip function
179bodies, lazily reading them on demand.
180
181When reading and encoding the stream, several properties are maintained for the
182block.  In particular, each block maintains:
183
184#. A current abbrev id width.  This value starts at 2 at the beginning of the
185   stream, and is set every time a block record is entered.  The block entry
186   specifies the abbrev id width for the body of the block.
187
188#. A set of abbreviations.  Abbreviations may be defined within a block, in
189   which case they are only defined in that block (neither subblocks nor
190   enclosing blocks see the abbreviation).  Abbreviations can also be defined
191   inside a `BLOCKINFO`_ block, in which case they are defined in all blocks
192   that match the ID that the ``BLOCKINFO`` block is describing.
193
194As sub blocks are entered, these properties are saved and the new sub-block has
195its own set of abbreviations, and its own abbrev id width.  When a sub-block is
196popped, the saved values are restored.
197
198.. _ENTER_SUBBLOCK:
199
200ENTER_SUBBLOCK Encoding
201^^^^^^^^^^^^^^^^^^^^^^^
202
203:raw-html:`<tt>`
204[ENTER_SUBBLOCK, blockid\ :sub:`vbr8`, newabbrevlen\ :sub:`vbr4`, <align32bits>, blocklen_32]
205:raw-html:`</tt>`
206
207The ``ENTER_SUBBLOCK`` abbreviation ID specifies the start of a new block
208record.  The ``blockid`` value is encoded as an 8-bit VBR identifier, and
209indicates the type of block being entered, which can be a `standard block`_ or
210an application-specific block.  The ``newabbrevlen`` value is a 4-bit VBR, which
211specifies the abbrev id width for the sub-block.  The ``blocklen`` value is a
21232-bit aligned value that specifies the size of the subblock in 32-bit
213words. This value allows the reader to skip over the entire block in one jump.
214
215.. _END_BLOCK:
216
217END_BLOCK Encoding
218^^^^^^^^^^^^^^^^^^
219
220``[END_BLOCK, <align32bits>]``
221
222The ``END_BLOCK`` abbreviation ID specifies the end of the current block record.
223Its end is aligned to 32-bits to ensure that the size of the block is an even
224multiple of 32-bits.
225
226.. _Data Records:
227
228Data Records
229------------
230
231Data records consist of a record code and a number of (up to) 64-bit integer
232values.  The interpretation of the code and values is application specific and
233may vary between different block types.  Records can be encoded either using an
234unabbrev record, or with an abbreviation.  In the LLVM IR format, for example,
235there is a record which encodes the target triple of a module.  The code is
236``MODULE_CODE_TRIPLE``, and the values of the record are the ASCII codes for the
237characters in the string.
238
239.. _UNABBREV_RECORD:
240
241UNABBREV_RECORD Encoding
242^^^^^^^^^^^^^^^^^^^^^^^^
243
244:raw-html:`<tt>`
245[UNABBREV_RECORD, code\ :sub:`vbr6`, numops\ :sub:`vbr6`, op0\ :sub:`vbr6`, op1\ :sub:`vbr6`, ...]
246:raw-html:`</tt>`
247
248An ``UNABBREV_RECORD`` provides a default fallback encoding, which is both
249completely general and extremely inefficient.  It can describe an arbitrary
250record by emitting the code and operands as VBRs.
251
252For example, emitting an LLVM IR target triple as an unabbreviated record
253requires emitting the ``UNABBREV_RECORD`` abbrevid, a vbr6 for the
254``MODULE_CODE_TRIPLE`` code, a vbr6 for the length of the string, which is equal
255to the number of operands, and a vbr6 for each character.  Because there are no
256letters with values less than 32, each letter would need to be emitted as at
257least a two-part VBR, which means that each letter would require at least 12
258bits.  This is not an efficient encoding, but it is fully general.
259
260.. _abbreviated record encoding:
261
262Abbreviated Record Encoding
263^^^^^^^^^^^^^^^^^^^^^^^^^^^
264
265``[<abbrevid>, fields...]``
266
267An abbreviated record is an abbreviation id followed by a set of fields that are
268encoded according to the `abbreviation definition`_.  This allows records to be
269encoded significantly more densely than records encoded with the
270`UNABBREV_RECORD`_ type, and allows the abbreviation types to be specified in
271the stream itself, which allows the files to be completely self describing.  The
272actual encoding of abbreviations is defined below.
273
274The record code, which is the first field of an abbreviated record, may be
275encoded in the abbreviation definition (as a literal operand) or supplied in the
276abbreviated record (as a Fixed or VBR operand value).
277
278.. _abbreviation definition:
279
280Abbreviations
281-------------
282
283Abbreviations are an important form of compression for bitstreams.  The idea is
284to specify a dense encoding for a class of records once, then use that encoding
285to emit many records.  It takes space to emit the encoding into the file, but
286the space is recouped (hopefully plus some) when the records that use it are
287emitted.
288
289Abbreviations can be determined dynamically per client, per file. Because the
290abbreviations are stored in the bitstream itself, different streams of the same
291format can contain different sets of abbreviations according to the needs of the
292specific stream.  As a concrete example, LLVM IR files usually emit an
293abbreviation for binary operators.  If a specific LLVM module contained no or
294few binary operators, the abbreviation does not need to be emitted.
295
296.. _DEFINE_ABBREV:
297
298DEFINE_ABBREV Encoding
299^^^^^^^^^^^^^^^^^^^^^^
300
301:raw-html:`<tt>`
302[DEFINE_ABBREV, numabbrevops\ :sub:`vbr5`, abbrevop0, abbrevop1, ...]
303:raw-html:`</tt>`
304
305A ``DEFINE_ABBREV`` record adds an abbreviation to the list of currently defined
306abbreviations in the scope of this block.  This definition only exists inside
307this immediate block --- it is not visible in subblocks or enclosing blocks.
308Abbreviations are implicitly assigned IDs sequentially starting from 4 (the
309first application-defined abbreviation ID).  Any abbreviations defined in a
310``BLOCKINFO`` record for the particular block type receive IDs first, in order,
311followed by any abbreviations defined within the block itself.  Abbreviated data
312records reference this ID to indicate what abbreviation they are invoking.
313
314An abbreviation definition consists of the ``DEFINE_ABBREV`` abbrevid followed
315by a VBR that specifies the number of abbrev operands, then the abbrev operands
316themselves.  Abbreviation operands come in three forms.  They all start with a
317single bit that indicates whether the abbrev operand is a literal operand (when
318the bit is 1) or an encoding operand (when the bit is 0).
319
320#. Literal operands --- :raw-html:`<tt>` [1\ :sub:`1`, litvalue\
321   :sub:`vbr8`] :raw-html:`</tt>` --- Literal operands specify that the value in
322   the result is always a single specific value.  This specific value is emitted
323   as a vbr8 after the bit indicating that it is a literal operand.
324
325#. Encoding info without data --- :raw-html:`<tt>` [0\ :sub:`1`, encoding\
326   :sub:`3`] :raw-html:`</tt>` --- Operand encodings that do not have extra data
327   are just emitted as their code.
328
329#. Encoding info with data --- :raw-html:`<tt>` [0\ :sub:`1`, encoding\
330   :sub:`3`, value\ :sub:`vbr5`] :raw-html:`</tt>` --- Operand encodings that do
331   have extra data are emitted as their code, followed by the extra data.
332
333The possible operand encodings are:
334
335* Fixed (code 1): The field should be emitted as a `fixed-width value`_, whose
336  width is specified by the operand's extra data.
337
338* VBR (code 2): The field should be emitted as a `variable-width value`_, whose
339  width is specified by the operand's extra data.
340
341* Array (code 3): This field is an array of values.  The array operand has no
342  extra data, but expects another operand to follow it, indicating the element
343  type of the array.  When reading an array in an abbreviated record, the first
344  integer is a vbr6 that indicates the array length, followed by the encoded
345  elements of the array.  An array may only occur as the last operand of an
346  abbreviation (except for the one final operand that gives the array's
347  type).
348
349* Char6 (code 4): This field should be emitted as a `char6-encoded value`_.
350  This operand type takes no extra data. Char6 encoding is normally used as an
351  array element type.
352
353* Blob (code 5): This field is emitted as a vbr6, followed by padding to a
354  32-bit boundary (for alignment) and an array of 8-bit objects.  The array of
355  bytes is further followed by tail padding to ensure that its total length is a
356  multiple of 4 bytes.  This makes it very efficient for the reader to decode
357  the data without having to make a copy of it: it can use a pointer to the data
358  in the mapped in file and poke directly at it.  A blob may only occur as the
359  last operand of an abbreviation.
360
361For example, target triples in LLVM modules are encoded as a record of the form
362``[TRIPLE, 'a', 'b', 'c', 'd']``.  Consider if the bitstream emitted the
363following abbrev entry:
364
365::
366
367  [0, Fixed, 4]
368  [0, Array]
369  [0, Char6]
370
371When emitting a record with this abbreviation, the above entry would be emitted
372as:
373
374:raw-html:`<tt><blockquote>`
375[4\ :sub:`abbrevwidth`, 2\ :sub:`4`, 4\ :sub:`vbr6`, 0\ :sub:`6`, 1\ :sub:`6`, 2\ :sub:`6`, 3\ :sub:`6`]
376:raw-html:`</blockquote></tt>`
377
378These values are:
379
380#. The first value, 4, is the abbreviation ID for this abbreviation.
381
382#. The second value, 2, is the record code for ``TRIPLE`` records within LLVM IR
383   file ``MODULE_BLOCK`` blocks.
384
385#. The third value, 4, is the length of the array.
386
387#. The rest of the values are the char6 encoded values for ``"abcd"``.
388
389With this abbreviation, the triple is emitted with only 37 bits (assuming a
390abbrev id width of 3).  Without the abbreviation, significantly more space would
391be required to emit the target triple.  Also, because the ``TRIPLE`` value is
392not emitted as a literal in the abbreviation, the abbreviation can also be used
393for any other string value.
394
395.. _standard blocks:
396.. _standard block:
397
398Standard Blocks
399---------------
400
401In addition to the basic block structure and record encodings, the bitstream
402also defines specific built-in block types.  These block types specify how the
403stream is to be decoded or other metadata.  In the future, new standard blocks
404may be added.  Block IDs 0-7 are reserved for standard blocks.
405
406.. _BLOCKINFO:
407
408#0 - BLOCKINFO Block
409^^^^^^^^^^^^^^^^^^^^
410
411The ``BLOCKINFO`` block allows the description of metadata for other blocks.
412The currently specified records are:
413
414::
415
416  [SETBID (#1), blockid]
417  [DEFINE_ABBREV, ...]
418  [BLOCKNAME, ...name...]
419  [SETRECORDNAME, RecordID, ...name...]
420
421The ``SETBID`` record (code 1) indicates which block ID is being described.
422``SETBID`` records can occur multiple times throughout the block to change which
423block ID is being described.  There must be a ``SETBID`` record prior to any
424other records.
425
426Standard ``DEFINE_ABBREV`` records can occur inside ``BLOCKINFO`` blocks, but
427unlike their occurrence in normal blocks, the abbreviation is defined for blocks
428matching the block ID we are describing, *not* the ``BLOCKINFO`` block
429itself.  The abbreviations defined in ``BLOCKINFO`` blocks receive abbreviation
430IDs as described in `DEFINE_ABBREV`_.
431
432The ``BLOCKNAME`` record (code 2) can optionally occur in this block.  The
433elements of the record are the bytes of the string name of the block.
434llvm-bcanalyzer can use this to dump out bitcode files symbolically.
435
436The ``SETRECORDNAME`` record (code 3) can also optionally occur in this block.
437The first operand value is a record ID number, and the rest of the elements of
438the record are the bytes for the string name of the record.  llvm-bcanalyzer can
439use this to dump out bitcode files symbolically.
440
441Note that although the data in ``BLOCKINFO`` blocks is described as "metadata,"
442the abbreviations they contain are essential for parsing records from the
443corresponding blocks.  It is not safe to skip them.
444
445.. _wrapper:
446
447Bitcode Wrapper Format
448======================
449
450Bitcode files for LLVM IR may optionally be wrapped in a simple wrapper
451structure.  This structure contains a simple header that indicates the offset
452and size of the embedded BC file.  This allows additional information to be
453stored alongside the BC file.  The structure of this file header is:
454
455:raw-html:`<tt><blockquote>`
456[Magic\ :sub:`32`, Version\ :sub:`32`, Offset\ :sub:`32`, Size\ :sub:`32`, CPUType\ :sub:`32`]
457:raw-html:`</blockquote></tt>`
458
459Each of the fields are 32-bit fields stored in little endian form (as with the
460rest of the bitcode file fields).  The Magic number is always ``0x0B17C0DE`` and
461the version is currently always ``0``.  The Offset field is the offset in bytes
462to the start of the bitcode stream in the file, and the Size field is the size
463in bytes of the stream. CPUType is a target-specific value that can be used to
464encode the CPU of the target.
465
466.. _native object file:
467
468Native Object File Wrapper Format
469=================================
470
471Bitcode files for LLVM IR may also be wrapped in a native object file
472(i.e. ELF, COFF, Mach-O).  The bitcode must be stored in a section of the object
473file named ``__LLVM,__bitcode`` for MachO and ``.llvmbc`` for the other object
474formats.  This wrapper format is useful for accommodating LTO in compilation
475pipelines where intermediate objects must be native object files which contain
476metadata in other sections.
477
478Not all tools support this format.  For example, lld and the gold plugin will
479ignore these sections when linking object files.
480
481.. _encoding of LLVM IR:
482
483LLVM IR Encoding
484================
485
486LLVM IR is encoded into a bitstream by defining blocks and records.  It uses
487blocks for things like constant pools, functions, symbol tables, etc.  It uses
488records for things like instructions, global variable descriptors, type
489descriptions, etc.  This document does not describe the set of abbreviations
490that the writer uses, as these are fully self-described in the file, and the
491reader is not allowed to build in any knowledge of this.
492
493Basics
494------
495
496LLVM IR Magic Number
497^^^^^^^^^^^^^^^^^^^^
498
499The magic number for LLVM IR files is:
500
501:raw-html:`<tt><blockquote>`
502['B'\ :sub:`8`, 'C'\ :sub:`8`, 0x0\ :sub:`4`, 0xC\ :sub:`4`, 0xE\ :sub:`4`, 0xD\ :sub:`4`]
503:raw-html:`</blockquote></tt>`
504
505.. _Signed VBRs:
506
507Signed VBRs
508^^^^^^^^^^^
509
510`Variable Width Integer`_ encoding is an efficient way to encode arbitrary sized
511unsigned values, but is an extremely inefficient for encoding signed values, as
512signed values are otherwise treated as maximally large unsigned values.
513
514As such, signed VBR values of a specific width are emitted as follows:
515
516* Positive values are emitted as VBRs of the specified width, but with their
517  value shifted left by one.
518
519* Negative values are emitted as VBRs of the specified width, but the negated
520  value is shifted left by one, and the low bit is set.
521
522With this encoding, small positive and small negative values can both be emitted
523efficiently. Signed VBR encoding is used in ``CST_CODE_INTEGER`` and
524``CST_CODE_WIDE_INTEGER`` records within ``CONSTANTS_BLOCK`` blocks.
525It is also used for phi instruction operands in `MODULE_CODE_VERSION`_ 1.
526
527LLVM IR Blocks
528^^^^^^^^^^^^^^
529
530LLVM IR is defined with the following blocks:
531
532* 8 --- `MODULE_BLOCK`_ --- This is the top-level block that contains the entire
533  module, and describes a variety of per-module information.
534
535* 9 --- `PARAMATTR_BLOCK`_ --- This enumerates the parameter attributes.
536
537* 10 --- `PARAMATTR_GROUP_BLOCK`_ --- This describes the attribute group table.
538
539* 11 --- `CONSTANTS_BLOCK`_ --- This describes constants for a module or
540  function.
541
542* 12 --- `FUNCTION_BLOCK`_ --- This describes a function body.
543
544* 14 --- `VALUE_SYMTAB_BLOCK`_ --- This describes a value symbol table.
545
546* 15 --- `METADATA_BLOCK`_ --- This describes metadata items.
547
548* 16 --- `METADATA_ATTACHMENT`_ --- This contains records associating metadata
549  with function instruction values.
550
551* 17 --- `TYPE_BLOCK`_ --- This describes all of the types in the module.
552
553* 23 --- `STRTAB_BLOCK`_ --- The bitcode file's string table.
554
555.. _MODULE_BLOCK:
556
557MODULE_BLOCK Contents
558---------------------
559
560The ``MODULE_BLOCK`` block (id 8) is the top-level block for LLVM bitcode files,
561and each module in a bitcode file must contain exactly one. A bitcode file with
562multi-module bitcode is valid. In addition to records (described below)
563containing information about the module, a ``MODULE_BLOCK`` block may contain
564the following sub-blocks:
565
566* `BLOCKINFO`_
567* `PARAMATTR_BLOCK`_
568* `PARAMATTR_GROUP_BLOCK`_
569* `TYPE_BLOCK`_
570* `VALUE_SYMTAB_BLOCK`_
571* `CONSTANTS_BLOCK`_
572* `FUNCTION_BLOCK`_
573* `METADATA_BLOCK`_
574
575.. _MODULE_CODE_VERSION:
576
577MODULE_CODE_VERSION Record
578^^^^^^^^^^^^^^^^^^^^^^^^^^
579
580``[VERSION, version#]``
581
582The ``VERSION`` record (code 1) contains a single value indicating the format
583version. Versions 0, 1 and 2 are supported at this time. The difference between
584version 0 and 1 is in the encoding of instruction operands in
585each `FUNCTION_BLOCK`_.
586
587In version 0, each value defined by an instruction is assigned an ID
588unique to the function. Function-level value IDs are assigned starting from
589``NumModuleValues`` since they share the same namespace as module-level
590values. The value enumerator resets after each function. When a value is
591an operand of an instruction, the value ID is used to represent the operand.
592For large functions or large modules, these operand values can be large.
593
594The encoding in version 1 attempts to avoid large operand values
595in common cases. Instead of using the value ID directly, operands are
596encoded as relative to the current instruction. Thus, if an operand
597is the value defined by the previous instruction, the operand
598will be encoded as 1.
599
600For example, instead of
601
602.. code-block:: none
603
604  #n = load #n-1
605  #n+1 = icmp eq #n, #const0
606  br #n+1, label #(bb1), label #(bb2)
607
608version 1 will encode the instructions as
609
610.. code-block:: none
611
612  #n = load #1
613  #n+1 = icmp eq #1, (#n+1)-#const0
614  br #1, label #(bb1), label #(bb2)
615
616Note in the example that operands which are constants also use
617the relative encoding, while operands like basic block labels
618do not use the relative encoding.
619
620Forward references will result in a negative value.
621This can be inefficient, as operands are normally encoded
622as unsigned VBRs. However, forward references are rare, except in the
623case of phi instructions. For phi instructions, operands are encoded as
624`Signed VBRs`_ to deal with forward references.
625
626In version 2, the meaning of module records ``FUNCTION``, ``GLOBALVAR``,
627``ALIAS``, ``IFUNC`` and ``COMDAT`` change such that the first two operands
628specify an offset and size of a string in a string table (see `STRTAB_BLOCK
629Contents`_), the function name is removed from the ``FNENTRY`` record in the
630value symbol table, and the top-level ``VALUE_SYMTAB_BLOCK`` may only contain
631``FNENTRY`` records.
632
633MODULE_CODE_TRIPLE Record
634^^^^^^^^^^^^^^^^^^^^^^^^^
635
636``[TRIPLE, ...string...]``
637
638The ``TRIPLE`` record (code 2) contains a variable number of values representing
639the bytes of the ``target triple`` specification string.
640
641MODULE_CODE_DATALAYOUT Record
642^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
643
644``[DATALAYOUT, ...string...]``
645
646The ``DATALAYOUT`` record (code 3) contains a variable number of values
647representing the bytes of the ``target datalayout`` specification string.
648
649MODULE_CODE_ASM Record
650^^^^^^^^^^^^^^^^^^^^^^
651
652``[ASM, ...string...]``
653
654The ``ASM`` record (code 4) contains a variable number of values representing
655the bytes of ``module asm`` strings, with individual assembly blocks separated
656by newline (ASCII 10) characters.
657
658.. _MODULE_CODE_SECTIONNAME:
659
660MODULE_CODE_SECTIONNAME Record
661^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
662
663``[SECTIONNAME, ...string...]``
664
665The ``SECTIONNAME`` record (code 5) contains a variable number of values
666representing the bytes of a single section name string. There should be one
667``SECTIONNAME`` record for each section name referenced (e.g., in global
668variable or function ``section`` attributes) within the module. These records
669can be referenced by the 1-based index in the *section* fields of ``GLOBALVAR``
670or ``FUNCTION`` records.
671
672MODULE_CODE_DEPLIB Record
673^^^^^^^^^^^^^^^^^^^^^^^^^
674
675``[DEPLIB, ...string...]``
676
677The ``DEPLIB`` record (code 6) contains a variable number of values representing
678the bytes of a single dependent library name string, one of the libraries
679mentioned in a ``deplibs`` declaration.  There should be one ``DEPLIB`` record
680for each library name referenced.
681
682MODULE_CODE_GLOBALVAR Record
683^^^^^^^^^^^^^^^^^^^^^^^^^^^^
684
685``[GLOBALVAR, strtab offset, strtab size, pointer type, isconst, initid, linkage, alignment, section, visibility, threadlocal, unnamed_addr, externally_initialized, dllstorageclass, comdat, attributes, preemptionspecifier]``
686
687The ``GLOBALVAR`` record (code 7) marks the declaration or definition of a
688global variable. The operand fields are:
689
690* *strtab offset*, *strtab size*: Specifies the name of the global variable.
691  See `STRTAB_BLOCK Contents`_.
692
693* *pointer type*: The type index of the pointer type used to point to this
694  global variable
695
696* *isconst*: Non-zero if the variable is treated as constant within the module,
697  or zero if it is not
698
699* *initid*: If non-zero, the value index of the initializer for this variable,
700  plus 1.
701
702.. _linkage type:
703
704* *linkage*: An encoding of the linkage type for this variable:
705
706  * ``external``: code 0
707  * ``weak``: code 1
708  * ``appending``: code 2
709  * ``internal``: code 3
710  * ``linkonce``: code 4
711  * ``dllimport``: code 5
712  * ``dllexport``: code 6
713  * ``extern_weak``: code 7
714  * ``common``: code 8
715  * ``private``: code 9
716  * ``weak_odr``: code 10
717  * ``linkonce_odr``: code 11
718  * ``available_externally``: code 12
719  * deprecated : code 13
720  * deprecated : code 14
721
722* alignment*: The logarithm base 2 of the variable's requested alignment, plus 1
723
724* *section*: If non-zero, the 1-based section index in the table of
725  `MODULE_CODE_SECTIONNAME`_ entries.
726
727.. _visibility:
728
729* *visibility*: If present, an encoding of the visibility of this variable:
730
731  * ``default``: code 0
732  * ``hidden``: code 1
733  * ``protected``: code 2
734
735.. _bcthreadlocal:
736
737* *threadlocal*: If present, an encoding of the thread local storage mode of the
738  variable:
739
740  * ``not thread local``: code 0
741  * ``thread local; default TLS model``: code 1
742  * ``localdynamic``: code 2
743  * ``initialexec``: code 3
744  * ``localexec``: code 4
745
746.. _bcunnamedaddr:
747
748* *unnamed_addr*: If present, an encoding of the ``unnamed_addr`` attribute of this
749  variable:
750
751  * not ``unnamed_addr``: code 0
752  * ``unnamed_addr``: code 1
753  * ``local_unnamed_addr``: code 2
754
755.. _bcdllstorageclass:
756
757* *dllstorageclass*: If present, an encoding of the DLL storage class of this variable:
758
759  * ``default``: code 0
760  * ``dllimport``: code 1
761  * ``dllexport``: code 2
762
763* *comdat*: An encoding of the COMDAT of this function
764
765* *attributes*: If nonzero, the 1-based index into the table of AttributeLists.
766
767.. _bcpreemptionspecifier:
768
769* *preemptionspecifier*: If present, an encoding of the runtime preemption specifier of this variable:
770
771  * ``dso_preemptable``: code 0
772  * ``dso_local``: code 1
773
774.. _FUNCTION:
775
776MODULE_CODE_FUNCTION Record
777^^^^^^^^^^^^^^^^^^^^^^^^^^^
778
779``[FUNCTION, strtab offset, strtab size, type, callingconv, isproto, linkage, paramattr, alignment, section, visibility, gc, prologuedata, dllstorageclass, comdat, prefixdata, personalityfn, preemptionspecifier]``
780
781The ``FUNCTION`` record (code 8) marks the declaration or definition of a
782function. The operand fields are:
783
784* *strtab offset*, *strtab size*: Specifies the name of the function.
785  See `STRTAB_BLOCK Contents`_.
786
787* *type*: The type index of the function type describing this function
788
789* *callingconv*: The calling convention number:
790  * ``ccc``: code 0
791  * ``fastcc``: code 8
792  * ``coldcc``: code 9
793  * ``webkit_jscc``: code 12
794  * ``anyregcc``: code 13
795  * ``preserve_mostcc``: code 14
796  * ``preserve_allcc``: code 15
797  * ``swiftcc`` : code 16
798  * ``cxx_fast_tlscc``: code 17
799  * ``tailcc`` : code 18
800  * ``cfguard_checkcc`` : code 19
801  * ``swifttailcc`` : code 20
802  * ``x86_stdcallcc``: code 64
803  * ``x86_fastcallcc``: code 65
804  * ``arm_apcscc``: code 66
805  * ``arm_aapcscc``: code 67
806  * ``arm_aapcs_vfpcc``: code 68
807
808* isproto*: Non-zero if this entry represents a declaration rather than a
809  definition
810
811* *linkage*: An encoding of the `linkage type`_ for this function
812
813* *paramattr*: If nonzero, the 1-based parameter attribute index into the table
814  of `PARAMATTR_CODE_ENTRY`_ entries.
815
816* *alignment*: The logarithm base 2 of the function's requested alignment, plus
817  1
818
819* *section*: If non-zero, the 1-based section index in the table of
820  `MODULE_CODE_SECTIONNAME`_ entries.
821
822* *visibility*: An encoding of the `visibility`_ of this function
823
824* *gc*: If present and nonzero, the 1-based garbage collector index in the table
825  of `MODULE_CODE_GCNAME`_ entries.
826
827* *unnamed_addr*: If present, an encoding of the
828  :ref:`unnamed_addr<bcunnamedaddr>` attribute of this function
829
830* *prologuedata*: If non-zero, the value index of the prologue data for this function,
831  plus 1.
832
833* *dllstorageclass*: An encoding of the
834  :ref:`dllstorageclass<bcdllstorageclass>` of this function
835
836* *comdat*: An encoding of the COMDAT of this function
837
838* *prefixdata*: If non-zero, the value index of the prefix data for this function,
839  plus 1.
840
841* *personalityfn*: If non-zero, the value index of the personality function for this function,
842  plus 1.
843
844* *preemptionspecifier*: If present, an encoding of the :ref:`runtime preemption specifier<bcpreemptionspecifier>`  of this function.
845
846MODULE_CODE_ALIAS Record
847^^^^^^^^^^^^^^^^^^^^^^^^
848
849``[ALIAS, strtab offset, strtab size, alias type, aliasee val#, linkage, visibility, dllstorageclass, threadlocal, unnamed_addr, preemptionspecifier]``
850
851The ``ALIAS`` record (code 9) marks the definition of an alias. The operand
852fields are
853
854* *strtab offset*, *strtab size*: Specifies the name of the alias.
855  See `STRTAB_BLOCK Contents`_.
856
857* *alias type*: The type index of the alias
858
859* *aliasee val#*: The value index of the aliased value
860
861* *linkage*: An encoding of the `linkage type`_ for this alias
862
863* *visibility*: If present, an encoding of the `visibility`_ of the alias
864
865* *dllstorageclass*: If present, an encoding of the
866  :ref:`dllstorageclass<bcdllstorageclass>` of the alias
867
868* *threadlocal*: If present, an encoding of the
869  :ref:`thread local property<bcthreadlocal>` of the alias
870
871* *unnamed_addr*: If present, an encoding of the
872  :ref:`unnamed_addr<bcunnamedaddr>` attribute of this alias
873
874* *preemptionspecifier*: If present, an encoding of the :ref:`runtime preemption specifier<bcpreemptionspecifier>`  of this alias.
875
876.. _MODULE_CODE_GCNAME:
877
878MODULE_CODE_GCNAME Record
879^^^^^^^^^^^^^^^^^^^^^^^^^
880
881``[GCNAME, ...string...]``
882
883The ``GCNAME`` record (code 11) contains a variable number of values
884representing the bytes of a single garbage collector name string. There should
885be one ``GCNAME`` record for each garbage collector name referenced in function
886``gc`` attributes within the module. These records can be referenced by 1-based
887index in the *gc* fields of ``FUNCTION`` records.
888
889.. _PARAMATTR_BLOCK:
890
891PARAMATTR_BLOCK Contents
892------------------------
893
894The ``PARAMATTR_BLOCK`` block (id 9) contains a table of entries describing the
895attributes of function parameters. These entries are referenced by 1-based index
896in the *paramattr* field of module block `FUNCTION`_ records, or within the
897*attr* field of function block ``INST_INVOKE`` and ``INST_CALL`` records.
898
899Entries within ``PARAMATTR_BLOCK`` are constructed to ensure that each is unique
900(i.e., no two indices represent equivalent attribute lists).
901
902.. _PARAMATTR_CODE_ENTRY:
903
904PARAMATTR_CODE_ENTRY Record
905^^^^^^^^^^^^^^^^^^^^^^^^^^^
906
907``[ENTRY, attrgrp0, attrgrp1, ...]``
908
909The ``ENTRY`` record (code 2) contains a variable number of values describing a
910unique set of function parameter attributes. Each *attrgrp* value is used as a
911key with which to look up an entry in the attribute group table described
912in the ``PARAMATTR_GROUP_BLOCK`` block.
913
914.. _PARAMATTR_CODE_ENTRY_OLD:
915
916PARAMATTR_CODE_ENTRY_OLD Record
917^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
918
919.. note::
920  This is a legacy encoding for attributes, produced by LLVM versions 3.2 and
921  earlier. It is guaranteed to be understood by the current LLVM version, as
922  specified in the :ref:`IR backwards compatibility` policy.
923
924``[ENTRY, paramidx0, attr0, paramidx1, attr1...]``
925
926The ``ENTRY`` record (code 1) contains an even number of values describing a
927unique set of function parameter attributes. Each *paramidx* value indicates
928which set of attributes is represented, with 0 representing the return value
929attributes, 0xFFFFFFFF representing function attributes, and other values
930representing 1-based function parameters. Each *attr* value is a bitmap with the
931following interpretation:
932
933* bit 0: ``zeroext``
934* bit 1: ``signext``
935* bit 2: ``noreturn``
936* bit 3: ``inreg``
937* bit 4: ``sret``
938* bit 5: ``nounwind``
939* bit 6: ``noalias``
940* bit 7: ``byval``
941* bit 8: ``nest``
942* bit 9: ``readnone``
943* bit 10: ``readonly``
944* bit 11: ``noinline``
945* bit 12: ``alwaysinline``
946* bit 13: ``optsize``
947* bit 14: ``ssp``
948* bit 15: ``sspreq``
949* bits 16-31: ``align n``
950* bit 32: ``nocapture``
951* bit 33: ``noredzone``
952* bit 34: ``noimplicitfloat``
953* bit 35: ``naked``
954* bit 36: ``inlinehint``
955* bits 37-39: ``alignstack n``, represented as the logarithm
956  base 2 of the requested alignment, plus 1
957
958.. _PARAMATTR_GROUP_BLOCK:
959
960PARAMATTR_GROUP_BLOCK Contents
961------------------------------
962
963The ``PARAMATTR_GROUP_BLOCK`` block (id 10) contains a table of entries
964describing the attribute groups present in the module. These entries can be
965referenced within ``PARAMATTR_CODE_ENTRY`` entries.
966
967.. _PARAMATTR_GRP_CODE_ENTRY:
968
969PARAMATTR_GRP_CODE_ENTRY Record
970^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
971
972``[ENTRY, grpid, paramidx, attr0, attr1, ...]``
973
974The ``ENTRY`` record (code 3) contains *grpid* and *paramidx* values, followed
975by a variable number of values describing a unique group of attributes. The
976*grpid* value is a unique key for the attribute group, which can be referenced
977within ``PARAMATTR_CODE_ENTRY`` entries. The *paramidx* value indicates which
978set of attributes is represented, with 0 representing the return value
979attributes, 0xFFFFFFFF representing function attributes, and other values
980representing 1-based function parameters.
981
982Each *attr* is itself represented as a variable number of values:
983
984``kind, key [, ...], [value [, ...]]``
985
986Each attribute is either a well-known LLVM attribute (possibly with an integer
987value associated with it), or an arbitrary string (possibly with an arbitrary
988string value associated with it). The *kind* value is an integer code
989distinguishing between these possibilities:
990
991* code 0: well-known attribute
992* code 1: well-known attribute with an integer value
993* code 3: string attribute
994* code 4: string attribute with a string value
995
996For well-known attributes (code 0 or 1), the *key* value is an integer code
997identifying the attribute. For attributes with an integer argument (code 1),
998the *value* value indicates the argument.
999
1000For string attributes (code 3 or 4), the *key* value is actually a variable
1001number of values representing the bytes of a null-terminated string. For
1002attributes with a string argument (code 4), the *value* value is similarly a
1003variable number of values representing the bytes of a null-terminated string.
1004
1005The integer codes are mapped to well-known attributes as follows.
1006
1007* code 1: ``align(<n>)``
1008* code 2: ``alwaysinline``
1009* code 3: ``byval``
1010* code 4: ``inlinehint``
1011* code 5: ``inreg``
1012* code 6: ``minsize``
1013* code 7: ``naked``
1014* code 8: ``nest``
1015* code 9: ``noalias``
1016* code 10: ``nobuiltin``
1017* code 11: ``nocapture``
1018* code 12: ``nodeduplicate``
1019* code 13: ``noimplicitfloat``
1020* code 14: ``noinline``
1021* code 15: ``nonlazybind``
1022* code 16: ``noredzone``
1023* code 17: ``noreturn``
1024* code 18: ``nounwind``
1025* code 19: ``optsize``
1026* code 20: ``readnone``
1027* code 21: ``readonly``
1028* code 22: ``returned``
1029* code 23: ``returns_twice``
1030* code 24: ``signext``
1031* code 25: ``alignstack(<n>)``
1032* code 26: ``ssp``
1033* code 27: ``sspreq``
1034* code 28: ``sspstrong``
1035* code 29: ``sret``
1036* code 30: ``sanitize_address``
1037* code 31: ``sanitize_thread``
1038* code 32: ``sanitize_memory``
1039* code 33: ``uwtable``
1040* code 34: ``zeroext``
1041* code 35: ``builtin``
1042* code 36: ``cold``
1043* code 37: ``optnone``
1044* code 38: ``inalloca``
1045* code 39: ``nonnull``
1046* code 40: ``jumptable``
1047* code 41: ``dereferenceable(<n>)``
1048* code 42: ``dereferenceable_or_null(<n>)``
1049* code 43: ``convergent``
1050* code 44: ``safestack``
1051* code 45: ``argmemonly``
1052* code 46: ``swiftself``
1053* code 47: ``swifterror``
1054* code 48: ``norecurse``
1055* code 49: ``inaccessiblememonly``
1056* code 50: ``inaccessiblememonly_or_argmemonly``
1057* code 51: ``allocsize(<EltSizeParam>[, <NumEltsParam>])``
1058* code 52: ``writeonly``
1059* code 53: ``speculatable``
1060* code 54: ``strictfp``
1061* code 55: ``sanitize_hwaddress``
1062* code 56: ``nocf_check``
1063* code 57: ``optforfuzzing``
1064* code 58: ``shadowcallstack``
1065* code 59: ``speculative_load_hardening``
1066* code 60: ``immarg``
1067* code 61: ``willreturn``
1068* code 62: ``nofree``
1069* code 63: ``nosync``
1070* code 64: ``sanitize_memtag``
1071* code 65: ``preallocated``
1072* code 66: ``no_merge``
1073* code 67: ``null_pointer_is_valid``
1074* code 68: ``noundef``
1075* code 69: ``byref``
1076* code 70: ``mustprogress``
1077* code 74: ``vscale_range(<Min>[, <Max>])``
1078* code 75: ``swiftasync``
1079* code 76: ``nosanitize_coverage``
1080* code 77: ``elementtype``
1081* code 78: ``disable_sanitizer_instrumentation``
1082* code 79: ``nosanitize_bounds``
1083
1084.. note::
1085  The ``allocsize`` attribute has a special encoding for its arguments. Its two
1086  arguments, which are 32-bit integers, are packed into one 64-bit integer value
1087  (i.e. ``(EltSizeParam << 32) | NumEltsParam``), with ``NumEltsParam`` taking on
1088  the sentinel value -1 if it is not specified.
1089
1090.. note::
1091  The ``vscale_range`` attribute has a special encoding for its arguments. Its two
1092  arguments, which are 32-bit integers, are packed into one 64-bit integer value
1093  (i.e. ``(Min << 32) | Max``), with ``Max`` taking on the value of ``Min`` if
1094  it is not specified.
1095
1096.. _TYPE_BLOCK:
1097
1098TYPE_BLOCK Contents
1099-------------------
1100
1101The ``TYPE_BLOCK`` block (id 17) contains records which constitute a table of
1102type operator entries used to represent types referenced within an LLVM
1103module. Each record (with the exception of `NUMENTRY`_) generates a single type
1104table entry, which may be referenced by 0-based index from instructions,
1105constants, metadata, type symbol table entries, or other type operator records.
1106
1107Entries within ``TYPE_BLOCK`` are constructed to ensure that each entry is
1108unique (i.e., no two indices represent structurally equivalent types).
1109
1110.. _TYPE_CODE_NUMENTRY:
1111.. _NUMENTRY:
1112
1113TYPE_CODE_NUMENTRY Record
1114^^^^^^^^^^^^^^^^^^^^^^^^^
1115
1116``[NUMENTRY, numentries]``
1117
1118The ``NUMENTRY`` record (code 1) contains a single value which indicates the
1119total number of type code entries in the type table of the module. If present,
1120``NUMENTRY`` should be the first record in the block.
1121
1122TYPE_CODE_VOID Record
1123^^^^^^^^^^^^^^^^^^^^^
1124
1125``[VOID]``
1126
1127The ``VOID`` record (code 2) adds a ``void`` type to the type table.
1128
1129TYPE_CODE_HALF Record
1130^^^^^^^^^^^^^^^^^^^^^
1131
1132``[HALF]``
1133
1134The ``HALF`` record (code 10) adds a ``half`` (16-bit floating point) type to
1135the type table.
1136
1137TYPE_CODE_BFLOAT Record
1138^^^^^^^^^^^^^^^^^^^^^^^
1139
1140``[BFLOAT]``
1141
1142The ``BFLOAT`` record (code 23) adds a ``bfloat`` (16-bit brain floating point)
1143type to the type table.
1144
1145TYPE_CODE_FLOAT Record
1146^^^^^^^^^^^^^^^^^^^^^^
1147
1148``[FLOAT]``
1149
1150The ``FLOAT`` record (code 3) adds a ``float`` (32-bit floating point) type to
1151the type table.
1152
1153TYPE_CODE_DOUBLE Record
1154^^^^^^^^^^^^^^^^^^^^^^^
1155
1156``[DOUBLE]``
1157
1158The ``DOUBLE`` record (code 4) adds a ``double`` (64-bit floating point) type to
1159the type table.
1160
1161TYPE_CODE_LABEL Record
1162^^^^^^^^^^^^^^^^^^^^^^
1163
1164``[LABEL]``
1165
1166The ``LABEL`` record (code 5) adds a ``label`` type to the type table.
1167
1168TYPE_CODE_OPAQUE Record
1169^^^^^^^^^^^^^^^^^^^^^^^
1170
1171``[OPAQUE]``
1172
1173The ``OPAQUE`` record (code 6) adds an ``opaque`` type to the type table, with
1174a name defined by a previously encountered ``STRUCT_NAME`` record. Note that
1175distinct ``opaque`` types are not unified.
1176
1177TYPE_CODE_INTEGER Record
1178^^^^^^^^^^^^^^^^^^^^^^^^
1179
1180``[INTEGER, width]``
1181
1182The ``INTEGER`` record (code 7) adds an integer type to the type table. The
1183single *width* field indicates the width of the integer type.
1184
1185TYPE_CODE_POINTER Record
1186^^^^^^^^^^^^^^^^^^^^^^^^
1187
1188``[POINTER, pointee type, address space]``
1189
1190The ``POINTER`` record (code 8) adds a pointer type to the type table. The
1191operand fields are
1192
1193* *pointee type*: The type index of the pointed-to type
1194
1195* *address space*: If supplied, the target-specific numbered address space where
1196  the pointed-to object resides. Otherwise, the default address space is zero.
1197
1198TYPE_CODE_FUNCTION_OLD Record
1199^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1200
1201.. note::
1202  This is a legacy encoding for functions, produced by LLVM versions 3.0 and
1203  earlier. It is guaranteed to be understood by the current LLVM version, as
1204  specified in the :ref:`IR backwards compatibility` policy.
1205
1206``[FUNCTION_OLD, vararg, ignored, retty, ...paramty... ]``
1207
1208The ``FUNCTION_OLD`` record (code 9) adds a function type to the type table.
1209The operand fields are
1210
1211* *vararg*: Non-zero if the type represents a varargs function
1212
1213* *ignored*: This value field is present for backward compatibility only, and is
1214  ignored
1215
1216* *retty*: The type index of the function's return type
1217
1218* *paramty*: Zero or more type indices representing the parameter types of the
1219  function
1220
1221TYPE_CODE_ARRAY Record
1222^^^^^^^^^^^^^^^^^^^^^^
1223
1224``[ARRAY, numelts, eltty]``
1225
1226The ``ARRAY`` record (code 11) adds an array type to the type table.  The
1227operand fields are
1228
1229* *numelts*: The number of elements in arrays of this type
1230
1231* *eltty*: The type index of the array element type
1232
1233TYPE_CODE_VECTOR Record
1234^^^^^^^^^^^^^^^^^^^^^^^
1235
1236``[VECTOR, numelts, eltty]``
1237
1238The ``VECTOR`` record (code 12) adds a vector type to the type table.  The
1239operand fields are
1240
1241* *numelts*: The number of elements in vectors of this type
1242
1243* *eltty*: The type index of the vector element type
1244
1245TYPE_CODE_X86_FP80 Record
1246^^^^^^^^^^^^^^^^^^^^^^^^^
1247
1248``[X86_FP80]``
1249
1250The ``X86_FP80`` record (code 13) adds an ``x86_fp80`` (80-bit floating point)
1251type to the type table.
1252
1253TYPE_CODE_FP128 Record
1254^^^^^^^^^^^^^^^^^^^^^^
1255
1256``[FP128]``
1257
1258The ``FP128`` record (code 14) adds an ``fp128`` (128-bit floating point) type
1259to the type table.
1260
1261TYPE_CODE_PPC_FP128 Record
1262^^^^^^^^^^^^^^^^^^^^^^^^^^
1263
1264``[PPC_FP128]``
1265
1266The ``PPC_FP128`` record (code 15) adds a ``ppc_fp128`` (128-bit floating point)
1267type to the type table.
1268
1269TYPE_CODE_METADATA Record
1270^^^^^^^^^^^^^^^^^^^^^^^^^
1271
1272``[METADATA]``
1273
1274The ``METADATA`` record (code 16) adds a ``metadata`` type to the type table.
1275
1276TYPE_CODE_X86_MMX Record
1277^^^^^^^^^^^^^^^^^^^^^^^^
1278
1279``[X86_MMX]``
1280
1281The ``X86_MMX`` record (code 17) adds an ``x86_mmx`` type to the type table.
1282
1283TYPE_CODE_STRUCT_ANON Record
1284^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1285
1286``[STRUCT_ANON, ispacked, ...eltty...]``
1287
1288The ``STRUCT_ANON`` record (code 18) adds a literal struct type to the type
1289table. The operand fields are
1290
1291* *ispacked*: Non-zero if the type represents a packed structure
1292
1293* *eltty*: Zero or more type indices representing the element types of the
1294  structure
1295
1296TYPE_CODE_STRUCT_NAME Record
1297^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1298
1299``[STRUCT_NAME, ...string...]``
1300
1301The ``STRUCT_NAME`` record (code 19) contains a variable number of values
1302representing the bytes of a struct name. The next ``OPAQUE`` or
1303``STRUCT_NAMED`` record will use this name.
1304
1305TYPE_CODE_STRUCT_NAMED Record
1306^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1307
1308``[STRUCT_NAMED, ispacked, ...eltty...]``
1309
1310The ``STRUCT_NAMED`` record (code 20) adds an identified struct type to the
1311type table, with a name defined by a previously encountered ``STRUCT_NAME``
1312record. The operand fields are
1313
1314* *ispacked*: Non-zero if the type represents a packed structure
1315
1316* *eltty*: Zero or more type indices representing the element types of the
1317  structure
1318
1319TYPE_CODE_FUNCTION Record
1320^^^^^^^^^^^^^^^^^^^^^^^^^
1321
1322``[FUNCTION, vararg, retty, ...paramty... ]``
1323
1324The ``FUNCTION`` record (code 21) adds a function type to the type table. The
1325operand fields are
1326
1327* *vararg*: Non-zero if the type represents a varargs function
1328
1329* *retty*: The type index of the function's return type
1330
1331* *paramty*: Zero or more type indices representing the parameter types of the
1332  function
1333
1334TYPE_CODE_X86_AMX Record
1335^^^^^^^^^^^^^^^^^^^^^^^^
1336
1337``[X86_AMX]``
1338
1339The ``X86_AMX`` record (code 24) adds an ``x86_amx`` type to the type table.
1340
1341TYPE_CODE_TARGET_TYPE Record
1342^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1343
1344``[TARGET_TYPE, num_tys, ...ty_params..., ...int_params... ]``
1345
1346The ``TARGET_TYPE`` record (code 26) adds a target extension type to the type
1347table, with a name defined by a previously encountered ``STRUCT_NAME`` record.
1348The operand fields are
1349
1350* *num_tys*: The number of parameters that are types (as opposed to integers)
1351
1352* *ty_params*: Type indices that represent type parameters
1353
1354* *int_params*: Numbers that correspond to the integer parameters.
1355
1356.. _CONSTANTS_BLOCK:
1357
1358CONSTANTS_BLOCK Contents
1359------------------------
1360
1361The ``CONSTANTS_BLOCK`` block (id 11) ...
1362
1363.. _FUNCTION_BLOCK:
1364
1365FUNCTION_BLOCK Contents
1366-----------------------
1367
1368The ``FUNCTION_BLOCK`` block (id 12) ...
1369
1370In addition to the record types described below, a ``FUNCTION_BLOCK`` block may
1371contain the following sub-blocks:
1372
1373* `CONSTANTS_BLOCK`_
1374* `VALUE_SYMTAB_BLOCK`_
1375* `METADATA_ATTACHMENT`_
1376
1377.. _VALUE_SYMTAB_BLOCK:
1378
1379VALUE_SYMTAB_BLOCK Contents
1380---------------------------
1381
1382The ``VALUE_SYMTAB_BLOCK`` block (id 14) ...
1383
1384.. _METADATA_BLOCK:
1385
1386METADATA_BLOCK Contents
1387-----------------------
1388
1389The ``METADATA_BLOCK`` block (id 15) ...
1390
1391.. _METADATA_ATTACHMENT:
1392
1393METADATA_ATTACHMENT Contents
1394----------------------------
1395
1396The ``METADATA_ATTACHMENT`` block (id 16) ...
1397
1398.. _STRTAB_BLOCK:
1399
1400STRTAB_BLOCK Contents
1401---------------------
1402
1403The ``STRTAB`` block (id 23) contains a single record (``STRTAB_BLOB``, id 1)
1404with a single blob operand containing the bitcode file's string table.
1405
1406Strings in the string table are not null terminated. A record's *strtab
1407offset* and *strtab size* operands specify the byte offset and size of a
1408string within the string table.
1409
1410The string table is used by all preceding blocks in the bitcode file that are
1411not succeeded by another intervening ``STRTAB`` block. Normally a bitcode
1412file will have a single string table, but it may have more than one if it
1413was created by binary concatenation of multiple bitcode files.
1414