LLVM Bitcode File Format

Abstract

This document describes the LLVM bitstream file format and the encoding of theLLVM IR into it.

Overview

What is commonly known as the LLVM bitcode file format (also, sometimesanachronistically known as bytecode) is actually two things: a bitstreamcontainer format and an encoding of LLVM IR into the container format.

The bitstream format is an abstract encoding of structured data, very similar toXML in some ways. Like XML, bitstream files contain tags, and nestedstructures, and you can parse the file without having to understand the tags.Unlike XML, the bitstream format is a binary encoding, and unlike XML itprovides a mechanism for the file to self-describe “abbreviations”, which areeffectively size optimizations for the content.

LLVM IR files may be optionally embedded into a wrapper structure, or in anative object file. Both of these mechanisms make it easy to embed extradata along with LLVM IR files.

This document first describes the LLVM bitstream format, describes the wrapperformat, then describes the record structure used by LLVM IR files.

Bitstream Format

The bitstream format is literally a stream of bits, with a very simplestructure. This structure consists of the following concepts:

  • A “magic number” that identifies the contents of the stream.
  • Encoding primitives like variable bit-rate integers.
  • Blocks, which define nested content.
  • Data Records, which describe entities within the file.
  • Abbreviations, which specify compression optimizations for the file.

Note that the llvm-bcanalyzer tool can beused to dump and inspect arbitrary bitstreams, which is very useful forunderstanding the encoding.

Magic Numbers

The first four bytes of a bitstream are used as an application-specific magicnumber. Generic bitcode tools may look at the first four bytes to determinewhether the stream is a known stream type. However, these tools should _not_determine whether a bitstream is valid based on its magic number alone. Newapplication-specific bitstream formats are being developed all the time; toolsshould not reject them just because they have a hitherto unseen magic number.

Primitives

A bitstream literally consists of a stream of bits, which are read in orderstarting with the least significant bit of each byte. The stream is made up ofa number of primitive values that encode a stream of unsigned integer values.These integers are encoded in two ways: either as Fixed Width Integers or asVariable Width Integers.

Fixed Width Integers

Fixed-width integer values have their low bits emitted directly to the file.For example, a 3-bit integer value encodes 1 as 001. Fixed width integers areused when there are a well-known number of options for a field. For example,boolean values are usually encoded with a 1-bit wide integer.

Variable Width Integers

Variable-width integer (VBR) values encode values of arbitrary size, optimizingfor the case where the values are small. Given a 4-bit VBR field, any 3-bitvalue (0 through 7) is encoded directly, with the high bit set to zero. Valueslarger than N-1 bits emit their bits in a series of N-1 bit chunks, where allbut the last set the high bit.

For example, the value 27 (0x1B) is encoded as 1011 0011 when emitted as a vbr4value. The first set of four bits indicates the value 3 (011) with acontinuation piece (indicated by a high bit of 1). The next word indicates avalue of 24 (011 << 3) with no continuation. The sum (3+24) yields the value27.

6-bit characters

6-bit characters encode common characters into a fixed 6-bit field. Theyrepresent the following characters with the following 6-bit values:

  1. 'a' .. 'z' --- 0 .. 25
  2. 'A' .. 'Z' --- 26 .. 51
  3. '0' .. '9' --- 52 .. 61
  4. '.' --- 62
  5. '_' --- 63

This encoding is only suitable for encoding characters and strings that consistonly of the above characters. It is completely incapable of encoding charactersnot in the set.

Word Alignment

Occasionally, it is useful to emit zero bits until the bitstream is a multipleof 32 bits. This ensures that the bit position in the stream can be representedas a multiple of 32-bit words.

Abbreviation IDs

A bitstream is a sequential series of Blocks and Data Records. Both ofthese start with an abbreviation ID encoded as a fixed-bitwidth field. Thewidth is specified by the current block, as described below. The value of theabbreviation ID specifies either a builtin ID (which have special meanings,defined below) or one of the abbreviation IDs defined for the current block bythe stream itself.

The set of builtin abbrev IDs is:

  • 0 - END_BLOCK — This abbrev ID marks the end of the current block.
  • 1 - ENTER_SUBBLOCK — This abbrev ID marks the beginning of a newblock.
  • 2 - DEFINE_ABBREV — This defines a new abbreviation.
  • 3 - UNABBREV_RECORD — This ID specifies the definition of anunabbreviated record.

Abbreviation IDs 4 and above are defined by the stream itself, and specify anabbreviated record encoding.

Blocks

Blocks in a bitstream denote nested regions of the stream, and are identified bya content-specific id number (for example, LLVM IR uses an ID of 12 to representfunction bodies). Block IDs 0-7 are reserved for standard blocks whosemeaning is defined by Bitcode; block IDs 8 and greater are applicationspecific. Nested blocks capture the hierarchical structure of the data encodedin it, and various properties are associated with blocks as the file is parsed.Block definitions allow the reader to efficiently skip blocks in constant timeif the reader wants a summary of blocks, or if it wants to efficiently skip datait does not understand. The LLVM IR reader uses this mechanism to skip functionbodies, lazily reading them on demand.

When reading and encoding the stream, several properties are maintained for theblock. In particular, each block maintains:

  • A current abbrev id width. This value starts at 2 at the beginning of thestream, and is set every time a block record is entered. The block entryspecifies the abbrev id width for the body of the block.
  • A set of abbreviations. Abbreviations may be defined within a block, inwhich case they are only defined in that block (neither subblocks norenclosing blocks see the abbreviation). Abbreviations can also be definedinside a BLOCKINFO block, in which case they are defined in all blocksthat match the ID that the BLOCKINFO block is describing.As sub blocks are entered, these properties are saved and the new sub-block hasits own set of abbreviations, and its own abbrev id width. When a sub-block ispopped, the saved values are restored.

ENTER_SUBBLOCK Encoding

[ENTER_SUBBLOCK, blockidvbr8, newabbrevlenvbr4, <align32bits>, blocklen_32]

The ENTER_SUBBLOCK abbreviation ID specifies the start of a new blockrecord. The blockid value is encoded as an 8-bit VBR identifier, andindicates the type of block being entered, which can be a standard block oran application-specific block. The newabbrevlen value is a 4-bit VBR, whichspecifies the abbrev id width for the sub-block. The blocklen value is a32-bit aligned value that specifies the size of the subblock in 32-bitwords. This value allows the reader to skip over the entire block in one jump.

END_BLOCK Encoding

[END_BLOCK, <align32bits>]

The END_BLOCK abbreviation ID specifies the end of the current block record.Its end is aligned to 32-bits to ensure that the size of the block is an evenmultiple of 32-bits.

Data Records

Data records consist of a record code and a number of (up to) 64-bit integervalues. The interpretation of the code and values is application specific andmay vary between different block types. Records can be encoded either using anunabbrev record, or with an abbreviation. In the LLVM IR format, for example,there is a record which encodes the target triple of a module. The code isMODULE_CODE_TRIPLE, and the values of the record are the ASCII codes for thecharacters in the string.

UNABBREV_RECORD Encoding

[UNABBREV_RECORD, codevbr6, numopsvbr6, op0vbr6, op1vbr6, …]

An UNABBREV_RECORD provides a default fallback encoding, which is bothcompletely general and extremely inefficient. It can describe an arbitraryrecord by emitting the code and operands as VBRs.

For example, emitting an LLVM IR target triple as an unabbreviated recordrequires emitting the UNABBREV_RECORD abbrevid, a vbr6 for theMODULE_CODE_TRIPLE code, a vbr6 for the length of the string, which is equalto the number of operands, and a vbr6 for each character. Because there are noletters with values less than 32, each letter would need to be emitted as atleast a two-part VBR, which means that each letter would require at least 12bits. This is not an efficient encoding, but it is fully general.

Abbreviated Record Encoding

[<abbrevid>, fields…]

An abbreviated record is a abbreviation id followed by a set of fields that areencoded according to the abbreviation definition. This allows records to beencoded significantly more densely than records encoded with theUNABBREV_RECORD type, and allows the abbreviation types to be specified inthe stream itself, which allows the files to be completely self describing. Theactual encoding of abbreviations is defined below.

The record code, which is the first field of an abbreviated record, may beencoded in the abbreviation definition (as a literal operand) or supplied in theabbreviated record (as a Fixed or VBR operand value).

Abbreviations

Abbreviations are an important form of compression for bitstreams. The idea isto specify a dense encoding for a class of records once, then use that encodingto emit many records. It takes space to emit the encoding into the file, butthe space is recouped (hopefully plus some) when the records that use it areemitted.

Abbreviations can be determined dynamically per client, per file. Because theabbreviations are stored in the bitstream itself, different streams of the sameformat can contain different sets of abbreviations according to the needs of thespecific stream. As a concrete example, LLVM IR files usually emit anabbreviation for binary operators. If a specific LLVM module contained no orfew binary operators, the abbreviation does not need to be emitted.

DEFINE_ABBREV Encoding

[DEFINE_ABBREV, numabbrevopsvbr5, abbrevop0, abbrevop1, …]

A DEFINE_ABBREV record adds an abbreviation to the list of currently definedabbreviations in the scope of this block. This definition only exists insidethis immediate block — it is not visible in subblocks or enclosing blocks.Abbreviations are implicitly assigned IDs sequentially starting from 4 (thefirst application-defined abbreviation ID). Any abbreviations defined in aBLOCKINFO record for the particular block type receive IDs first, in order,followed by any abbreviations defined within the block itself. Abbreviated datarecords reference this ID to indicate what abbreviation they are invoking.

An abbreviation definition consists of the DEFINE_ABBREV abbrevid followedby a VBR that specifies the number of abbrev operands, then the abbrev operandsthemselves. Abbreviation operands come in three forms. They all start with asingle bit that indicates whether the abbrev operand is a literal operand (whenthe bit is 1) or an encoding operand (when the bit is 0).

  • Literal operands — [11, litvaluevbr8] — Literal operands specify that the value inthe result is always a single specific value. This specific value is emittedas a vbr8 after the bit indicating that it is a literal operand.
  • Encoding info without data — [01, encoding3] — Operand encodings that do not have extra dataare just emitted as their code.
  • Encoding info with data — [01, encoding3, valuevbr5] — Operand encodings that dohave extra data are emitted as their code, followed by the extra data.The possible operand encodings are:
  • Fixed (code 1): The field should be emitted as a fixed-width value, whosewidth is specified by the operand’s extra data.
  • VBR (code 2): The field should be emitted as a variable-width value, whosewidth is specified by the operand’s extra data.
  • Array (code 3): This field is an array of values. The array operand has noextra data, but expects another operand to follow it, indicating the elementtype of the array. When reading an array in an abbreviated record, the firstinteger is a vbr6 that indicates the array length, followed by the encodedelements of the array. An array may only occur as the last operand of anabbreviation (except for the one final operand that gives the array’stype).
  • Char6 (code 4): This field should be emitted as a char6-encoded value.This operand type takes no extra data. Char6 encoding is normally used as anarray element type.
  • Blob (code 5): This field is emitted as a vbr6, followed by padding to a32-bit boundary (for alignment) and an array of 8-bit objects. The array ofbytes is further followed by tail padding to ensure that its total length is amultiple of 4 bytes. This makes it very efficient for the reader to decodethe data without having to make a copy of it: it can use a pointer to the datain the mapped in file and poke directly at it. A blob may only occur as thelast operand of an abbreviation.

For example, target triples in LLVM modules are encoded as a record of the form[TRIPLE, 'a', 'b', 'c', 'd']. Consider if the bitstream emitted thefollowing abbrev entry:

  1. [0, Fixed, 4]
  2. [0, Array]
  3. [0, Char6]

When emitting a record with this abbreviation, the above entry would be emittedas:

[4abbrevwidth, 24, 4vbr6, 06, 16, 26, 36]

These values are:

  • The first value, 4, is the abbreviation ID for this abbreviation.
  • The second value, 2, is the record code for TRIPLE records within LLVM IRfile MODULE_BLOCK blocks.
  • The third value, 4, is the length of the array.
  • The rest of the values are the char6 encoded values for "abcd".With this abbreviation, the triple is emitted with only 37 bits (assuming aabbrev id width of 3). Without the abbreviation, significantly more space wouldbe required to emit the target triple. Also, because the TRIPLE value isnot emitted as a literal in the abbreviation, the abbreviation can also be usedfor any other string value.

Standard Blocks

In addition to the basic block structure and record encodings, the bitstreamalso defines specific built-in block types. These block types specify how thestream is to be decoded or other metadata. In the future, new standard blocksmay be added. Block IDs 0-7 are reserved for standard blocks.

#0 - BLOCKINFO Block

The BLOCKINFO block allows the description of metadata for other blocks.The currently specified records are:

  1. [SETBID (#1), blockid]
  2. [DEFINE_ABBREV, ...]
  3. [BLOCKNAME, ...name...]
  4. [SETRECORDNAME, RecordID, ...name...]

The SETBID record (code 1) indicates which block ID is being described.SETBID records can occur multiple times throughout the block to change whichblock ID is being described. There must be a SETBID record prior to anyother records.

Standard DEFINEABBREV records can occur inside BLOCKINFO blocks, butunlike their occurrence in normal blocks, the abbreviation is defined for blocksmatching the block ID we are describing, _not the BLOCKINFO blockitself. The abbreviations defined in BLOCKINFO blocks receive abbreviationIDs as described in DEFINE_ABBREV.

The BLOCKNAME record (code 2) can optionally occur in this block. Theelements of the record are the bytes of the string name of the block.llvm-bcanalyzer can use this to dump out bitcode files symbolically.

The SETRECORDNAME record (code 3) can also optionally occur in this block.The first operand value is a record ID number, and the rest of the elements ofthe record are the bytes for the string name of the record. llvm-bcanalyzer canuse this to dump out bitcode files symbolically.

Note that although the data in BLOCKINFO blocks is described as “metadata,”the abbreviations they contain are essential for parsing records from thecorresponding blocks. It is not safe to skip them.

Bitcode Wrapper Format

Bitcode files for LLVM IR may optionally be wrapped in a simple wrapperstructure. This structure contains a simple header that indicates the offsetand size of the embedded BC file. This allows additional information to bestored alongside the BC file. The structure of this file header is:

[Magic32, Version32, Offset32, Size32, CPUType32]

Each of the fields are 32-bit fields stored in little endian form (as with therest of the bitcode file fields). The Magic number is always 0x0B17C0DE andthe version is currently always 0. The Offset field is the offset in bytesto the start of the bitcode stream in the file, and the Size field is the sizein bytes of the stream. CPUType is a target-specific value that can be used toencode the CPU of the target.

Native Object File Wrapper Format

Bitcode files for LLVM IR may also be wrapped in a native object file(i.e. ELF, COFF, Mach-O). The bitcode must be stored in a section of the objectfile named LLVM,bitcode for MachO and .llvmbc for the other objectformats. This wrapper format is useful for accommodating LTO in compilationpipelines where intermediate objects must be native object files which containmetadata in other sections.

Not all tools support this format.

LLVM IR Encoding

LLVM IR is encoded into a bitstream by defining blocks and records. It usesblocks for things like constant pools, functions, symbol tables, etc. It usesrecords for things like instructions, global variable descriptors, typedescriptions, etc. This document does not describe the set of abbreviationsthat the writer uses, as these are fully self-described in the file, and thereader is not allowed to build in any knowledge of this.

Basics

LLVM IR Magic Number

The magic number for LLVM IR files is:

[‘B’8, ‘C’8, 0x04, 0xC4, 0xE4, 0xD4]

Signed VBRs

Variable Width Integer encoding is an efficient way to encode arbitrary sizedunsigned values, but is an extremely inefficient for encoding signed values, assigned values are otherwise treated as maximally large unsigned values.

As such, signed VBR values of a specific width are emitted as follows:

  • Positive values are emitted as VBRs of the specified width, but with theirvalue shifted left by one.
  • Negative values are emitted as VBRs of the specified width, but the negatedvalue is shifted left by one, and the low bit is set.

With this encoding, small positive and small negative values can both be emittedefficiently. Signed VBR encoding is used in CST_CODE_INTEGER andCST_CODE_WIDE_INTEGER records within CONSTANTS_BLOCK blocks.It is also used for phi instruction operands in MODULE_CODE_VERSION 1.

LLVM IR Blocks

LLVM IR is defined with the following blocks:

  • 8 — MODULE_BLOCK — This is the top-level block that contains the entiremodule, and describes a variety of per-module information.
  • 9 — PARAMATTR_BLOCK — This enumerates the parameter attributes.
  • 10 — PARAMATTR_GROUP_BLOCK — This describes the attribute group table.
  • 11 — CONSTANTS_BLOCK — This describes constants for a module orfunction.
  • 12 — FUNCTION_BLOCK — This describes a function body.
  • 14 — VALUE_SYMTAB_BLOCK — This describes a value symbol table.
  • 15 — METADATA_BLOCK — This describes metadata items.
  • 16 — METADATA_ATTACHMENT — This contains records associating metadatawith function instruction values.
  • 17 — TYPE_BLOCK — This describes all of the types in the module.
  • 23 — STRTAB_BLOCK — The bitcode file’s string table.

MODULE_BLOCK Contents

The MODULE_BLOCK block (id 8) is the top-level block for LLVM bitcode files,and each bitcode file must contain exactly one. In addition to records(described below) containing information about the module, a MODULE_BLOCKblock may contain the following sub-blocks:

MODULE_CODE_VERSION Record

[VERSION, version#]

The VERSION record (code 1) contains a single value indicating the formatversion. Versions 0, 1 and 2 are supported at this time. The difference betweenversion 0 and 1 is in the encoding of instruction operands ineach FUNCTION_BLOCK.

In version 0, each value defined by an instruction is assigned an IDunique to the function. Function-level value IDs are assigned starting fromNumModuleValues since they share the same namespace as module-levelvalues. The value enumerator resets after each function. When a value isan operand of an instruction, the value ID is used to represent the operand.For large functions or large modules, these operand values can be large.

The encoding in version 1 attempts to avoid large operand valuesin common cases. Instead of using the value ID directly, operands areencoded as relative to the current instruction. Thus, if an operandis the value defined by the previous instruction, the operandwill be encoded as 1.

For example, instead of

  1. #n = load #n-1
  2. #n+1 = icmp eq #n, #const0
  3. br #n+1, label #(bb1), label #(bb2)

version 1 will encode the instructions as

  1. #n = load #1
  2. #n+1 = icmp eq #1, (#n+1)-#const0
  3. br #1, label #(bb1), label #(bb2)

Note in the example that operands which are constants also usethe relative encoding, while operands like basic block labelsdo not use the relative encoding.

Forward references will result in a negative value.This can be inefficient, as operands are normally encodedas unsigned VBRs. However, forward references are rare, except in thecase of phi instructions. For phi instructions, operands are encoded asSigned VBRs to deal with forward references.

In version 2, the meaning of module records FUNCTION, GLOBALVAR,ALIAS, IFUNC and COMDAT change such that the first two operandsspecify an offset and size of a string in a string table (see STRTAB_BLOCKContents), the function name is removed from the FNENTRY record in thevalue symbol table, and the top-level VALUE_SYMTAB_BLOCK may only containFNENTRY records.

MODULE_CODE_TRIPLE Record

[TRIPLE, …string…]

The TRIPLE record (code 2) contains a variable number of values representingthe bytes of the target triple specification string.

MODULE_CODE_DATALAYOUT Record

[DATALAYOUT, …string…]

The DATALAYOUT record (code 3) contains a variable number of valuesrepresenting the bytes of the target datalayout specification string.

MODULE_CODE_ASM Record

[ASM, …string…]

The ASM record (code 4) contains a variable number of values representingthe bytes of module asm strings, with individual assembly blocks separatedby newline (ASCII 10) characters.

MODULE_CODE_SECTIONNAME Record

[SECTIONNAME, …string…]

The SECTIONNAME record (code 5) contains a variable number of valuesrepresenting the bytes of a single section name string. There should be oneSECTIONNAME record for each section name referenced (e.g., in globalvariable or function section attributes) within the module. These recordscan be referenced by the 1-based index in the section fields of GLOBALVARor FUNCTION records.

MODULE_CODE_DEPLIB Record

[DEPLIB, …string…]

The DEPLIB record (code 6) contains a variable number of values representingthe bytes of a single dependent library name string, one of the librariesmentioned in a deplibs declaration. There should be one DEPLIB recordfor each library name referenced.

MODULE_CODE_GLOBALVAR Record

[GLOBALVAR, strtab offset, strtab size, pointer type, isconst, initid, linkage, alignment, section, visibility, threadlocal, unnamed_addr, externally_initialized, dllstorageclass, comdat, attributes, preemptionspecifier]

The GLOBALVAR record (code 7) marks the declaration or definition of aglobal variable. The operand fields are:

  • strtab offset, strtab size: Specifies the name of the global variable.See STRTAB_BLOCK Contents.
  • pointer type: The type index of the pointer type used to point to thisglobal variable
  • isconst: Non-zero if the variable is treated as constant within the module,or zero if it is not
  • initid: If non-zero, the value index of the initializer for this variable,plus 1.
  • linkage: An encoding of the linkage type for this variable:
    • external: code 0
    • weak: code 1
    • appending: code 2
    • internal: code 3
    • linkonce: code 4
    • dllimport: code 5
    • dllexport: code 6
    • extern_weak: code 7
    • common: code 8
    • private: code 9
    • weak_odr: code 10
    • linkonce_odr: code 11
    • available_externally: code 12
    • deprecated : code 13
    • deprecated : code 14
  • alignment*: The logarithm base 2 of the variable’s requested alignment, plus 1
  • section: If non-zero, the 1-based section index in the table ofMODULE_CODE_SECTIONNAME entries.
  • visibility: If present, an encoding of the visibility of this variable:
    • default: code 0
    • hidden: code 1
    • protected: code 2
  • threadlocal: If present, an encoding of the thread local storage mode of thevariable:
    • not thread local: code 0
    • thread local; default TLS model: code 1
    • localdynamic: code 2
    • initialexec: code 3
    • localexec: code 4
  • unnamed_addr: If present, an encoding of the unnamed_addr attribute of thisvariable:
    • not unnamed_addr: code 0
    • unnamed_addr: code 1
    • local_unnamed_addr: code 2
  • dllstorageclass: If present, an encoding of the DLL storage class of this variable:
    • default: code 0
    • dllimport: code 1
    • dllexport: code 2
  • comdat: An encoding of the COMDAT of this function
  • attributes: If nonzero, the 1-based index into the table of AttributeLists.
  • preemptionspecifier: If present, an encoding of the runtime preemption specifier of this variable:
    • dso_preemptable: code 0
    • dso_local: code 1

MODULE_CODE_FUNCTION Record

[FUNCTION, strtab offset, strtab size, type, callingconv, isproto, linkage, paramattr, alignment, section, visibility, gc, prologuedata, dllstorageclass, comdat, prefixdata, personalityfn, preemptionspecifier]

The FUNCTION record (code 8) marks the declaration or definition of afunction. The operand fields are:

  • strtab offset, strtab size: Specifies the name of the function.See STRTAB_BLOCK Contents.
  • type: The type index of the function type describing this function
  • callingconv: The calling convention number: ccc: code 0 fastcc: code 8 coldcc: code 9 webkit_jscc: code 12 anyregcc: code 13 preserve_mostcc: code 14 preserve_allcc: code 15 swiftcc : code 16 cxx_fast_tlscc: code 17 tailcc : code 18 x86_stdcallcc: code 64 x86_fastcallcc: code 65 arm_apcscc: code 66 arm_aapcscc: code 67* arm_aapcs_vfpcc: code 68
  • isproto*: Non-zero if this entry represents a declaration rather than adefinition
  • linkage: An encoding of the linkage type for this function
  • paramattr: If nonzero, the 1-based parameter attribute index into the tableof PARAMATTR_CODE_ENTRY entries.
  • alignment: The logarithm base 2 of the function’s requested alignment, plus1
  • section: If non-zero, the 1-based section index in the table ofMODULE_CODE_SECTIONNAME entries.
  • visibility: An encoding of the visibility of this function
  • gc: If present and nonzero, the 1-based garbage collector index in the tableof MODULE_CODE_GCNAME entries.
  • unnamed_addr: If present, an encoding of theunnamed_addr attribute of this function
  • prologuedata: If non-zero, the value index of the prologue data for this function,plus 1.
  • dllstorageclass: An encoding of thedllstorageclass of this function
  • comdat: An encoding of the COMDAT of this function
  • prefixdata: If non-zero, the value index of the prefix data for this function,plus 1.
  • personalityfn: If non-zero, the value index of the personality function for this function,plus 1.
  • preemptionspecifier: If present, an encoding of the runtime preemption specifier of this function.

MODULE_CODE_ALIAS Record

[ALIAS, strtab offset, strtab size, alias type, aliasee val#, linkage, visibility, dllstorageclass, threadlocal, unnamed_addr, preemptionspecifier]

The ALIAS record (code 9) marks the definition of an alias. The operandfields are

  • strtab offset, strtab size: Specifies the name of the alias.See STRTAB_BLOCK Contents.
  • alias type: The type index of the alias
  • aliasee val#: The value index of the aliased value
  • linkage: An encoding of the linkage type for this alias
  • visibility: If present, an encoding of the visibility of the alias
  • dllstorageclass: If present, an encoding of thedllstorageclass of the alias
  • threadlocal: If present, an encoding of thethread local property of the alias
  • unnamed_addr: If present, an encoding of theunnamed_addr attribute of this alias
  • preemptionspecifier: If present, an encoding of the runtime preemption specifier of this alias.

MODULE_CODE_GCNAME Record

[GCNAME, …string…]

The GCNAME record (code 11) contains a variable number of valuesrepresenting the bytes of a single garbage collector name string. There shouldbe one GCNAME record for each garbage collector name referenced in functiongc attributes within the module. These records can be referenced by 1-basedindex in the gc fields of FUNCTION records.

PARAMATTR_BLOCK Contents

The PARAMATTRBLOCK block (id 9) contains a table of entries describing theattributes of function parameters. These entries are referenced by 1-based indexin the _paramattr field of module block FUNCTION records, or within theattr field of function block INST_INVOKE and INST_CALL records.

Entries within PARAMATTR_BLOCK are constructed to ensure that each is unique(i.e., no two indices represent equivalent attribute lists).

PARAMATTR_CODE_ENTRY Record

[ENTRY, attrgrp0, attrgrp1, …]

The ENTRY record (code 2) contains a variable number of values describing aunique set of function parameter attributes. Each attrgrp value is used as akey with which to look up an entry in the attribute group table describedin the PARAMATTR_GROUP_BLOCK block.

PARAMATTR_CODE_ENTRY_OLD Record

Note

This is a legacy encoding for attributes, produced by LLVM versions 3.2 andearlier. It is guaranteed to be understood by the current LLVM version, asspecified in the IR Backwards Compatibility policy.

[ENTRY, paramidx0, attr0, paramidx1, attr1…]

The ENTRY record (code 1) contains an even number of values describing aunique set of function parameter attributes. Each paramidx value indicateswhich set of attributes is represented, with 0 representing the return valueattributes, 0xFFFFFFFF representing function attributes, and other valuesrepresenting 1-based function parameters. Each attr value is a bitmap with thefollowing interpretation:

  • bit 0: zeroext
  • bit 1: signext
  • bit 2: noreturn
  • bit 3: inreg
  • bit 4: sret
  • bit 5: nounwind
  • bit 6: noalias
  • bit 7: byval
  • bit 8: nest
  • bit 9: readnone
  • bit 10: readonly
  • bit 11: noinline
  • bit 12: alwaysinline
  • bit 13: optsize
  • bit 14: ssp
  • bit 15: sspreq
  • bits 16-31: align n
  • bit 32: nocapture
  • bit 33: noredzone
  • bit 34: noimplicitfloat
  • bit 35: naked
  • bit 36: inlinehint
  • bits 37-39: alignstack n, represented as the logarithmbase 2 of the requested alignment, plus 1

PARAMATTR_GROUP_BLOCK Contents

The PARAMATTR_GROUP_BLOCK block (id 10) contains a table of entriesdescribing the attribute groups present in the module. These entries can bereferenced within PARAMATTR_CODE_ENTRY entries.

PARAMATTR_GRP_CODE_ENTRY Record

[ENTRY, grpid, paramidx, attr0, attr1, …]

The ENTRY record (code 3) contains grpid and paramidx values, followedby a variable number of values describing a unique group of attributes. Thegrpid value is a unique key for the attribute group, which can be referencedwithin PARAMATTRCODE_ENTRY entries. The _paramidx value indicates whichset of attributes is represented, with 0 representing the return valueattributes, 0xFFFFFFFF representing function attributes, and other valuesrepresenting 1-based function parameters.

Each attr is itself represented as a variable number of values:

kind, key [, …], [value [, …]]

Each attribute is either a well-known LLVM attribute (possibly with an integervalue associated with it), or an arbitrary string (possibly with an arbitrarystring value associated with it). The kind value is an integer codedistinguishing between these possibilities:

  • code 0: well-known attribute
  • code 1: well-known attribute with an integer value
  • code 3: string attribute
  • code 4: string attribute with a string value

For well-known attributes (code 0 or 1), the key value is an integer codeidentifying the attribute. For attributes with an integer argument (code 1),the value value indicates the argument.

For string attributes (code 3 or 4), the key value is actually a variablenumber of values representing the bytes of a null-terminated string. Forattributes with a string argument (code 4), the value value is similarly avariable number of values representing the bytes of a null-terminated string.

The integer codes are mapped to well-known attributes as follows.

  • code 1: align(<n>)
  • code 2: alwaysinline
  • code 3: byval
  • code 4: inlinehint
  • code 5: inreg
  • code 6: minsize
  • code 7: naked
  • code 8: nest
  • code 9: noalias
  • code 10: nobuiltin
  • code 11: nocapture
  • code 12: noduplicates
  • code 13: noimplicitfloat
  • code 14: noinline
  • code 15: nonlazybind
  • code 16: noredzone
  • code 17: noreturn
  • code 18: nounwind
  • code 19: optsize
  • code 20: readnone
  • code 21: readonly
  • code 22: returned
  • code 23: returns_twice
  • code 24: signext
  • code 25: alignstack(<n>)
  • code 26: ssp
  • code 27: sspreq
  • code 28: sspstrong
  • code 29: sret
  • code 30: sanitize_address
  • code 31: sanitize_thread
  • code 32: sanitize_memory
  • code 33: uwtable
  • code 34: zeroext
  • code 35: builtin
  • code 36: cold
  • code 37: optnone
  • code 38: inalloca
  • code 39: nonnull
  • code 40: jumptable
  • code 41: dereferenceable(<n>)
  • code 42: dereferenceable_or_null(<n>)
  • code 43: convergent
  • code 44: safestack
  • code 45: argmemonly
  • code 46: swiftself
  • code 47: swifterror
  • code 48: norecurse
  • code 49: inaccessiblememonly
  • code 50: inaccessiblememonly_or_argmemonly
  • code 51: allocsize(<EltSizeParam>[, <NumEltsParam>])
  • code 52: writeonly
  • code 53: speculatable
  • code 54: strictfp
  • code 55: sanitize_hwaddress
  • code 56: nocf_check
  • code 57: optforfuzzing
  • code 58: shadowcallstack
  • code 64: sanitize_memtag

Note

The allocsize attribute has a special encoding for its arguments. Its twoarguments, which are 32-bit integers, are packed into one 64-bit integer value(i.e. (EltSizeParam << 32) | NumEltsParam), with NumEltsParam taking onthe sentinel value -1 if it is not specified.

TYPE_BLOCK Contents

The TYPE_BLOCK block (id 17) contains records which constitute a table oftype operator entries used to represent types referenced within an LLVMmodule. Each record (with the exception of NUMENTRY) generates a single typetable entry, which may be referenced by 0-based index from instructions,constants, metadata, type symbol table entries, or other type operator records.

Entries within TYPE_BLOCK are constructed to ensure that each entry isunique (i.e., no two indices represent structurally equivalent types).

TYPE_CODE_NUMENTRY Record

[NUMENTRY, numentries]

The NUMENTRY record (code 1) contains a single value which indicates thetotal number of type code entries in the type table of the module. If present,NUMENTRY should be the first record in the block.

TYPE_CODE_VOID Record

[VOID]

The VOID record (code 2) adds a void type to the type table.

TYPE_CODE_HALF Record

[HALF]

The HALF record (code 10) adds a half (16-bit floating point) type tothe type table.

TYPE_CODE_FLOAT Record

[FLOAT]

The FLOAT record (code 3) adds a float (32-bit floating point) type tothe type table.

TYPE_CODE_DOUBLE Record

[DOUBLE]

The DOUBLE record (code 4) adds a double (64-bit floating point) type tothe type table.

TYPE_CODE_LABEL Record

[LABEL]

The LABEL record (code 5) adds a label type to the type table.

TYPE_CODE_OPAQUE Record

[OPAQUE]

The OPAQUE record (code 6) adds an opaque type to the type table, witha name defined by a previously encountered STRUCT_NAME record. Note thatdistinct opaque types are not unified.

TYPE_CODE_INTEGER Record

[INTEGER, width]

The INTEGER record (code 7) adds an integer type to the type table. Thesingle width field indicates the width of the integer type.

TYPE_CODE_POINTER Record

[POINTER, pointee type, address space]

The POINTER record (code 8) adds a pointer type to the type table. Theoperand fields are

  • pointee type: The type index of the pointed-to type
  • address space: If supplied, the target-specific numbered address space wherethe pointed-to object resides. Otherwise, the default address space is zero.

TYPE_CODE_FUNCTION_OLD Record

Note

This is a legacy encoding for functions, produced by LLVM versions 3.0 andearlier. It is guaranteed to be understood by the current LLVM version, asspecified in the IR Backwards Compatibility policy.

[FUNCTION_OLD, vararg, ignored, retty, …paramty… ]

The FUNCTION_OLD record (code 9) adds a function type to the type table.The operand fields are

  • vararg: Non-zero if the type represents a varargs function
  • ignored: This value field is present for backward compatibility only, and isignored
  • retty: The type index of the function’s return type
  • paramty: Zero or more type indices representing the parameter types of thefunction

TYPE_CODE_ARRAY Record

[ARRAY, numelts, eltty]

The ARRAY record (code 11) adds an array type to the type table. Theoperand fields are

  • numelts: The number of elements in arrays of this type
  • eltty: The type index of the array element type

TYPE_CODE_VECTOR Record

[VECTOR, numelts, eltty]

The VECTOR record (code 12) adds a vector type to the type table. Theoperand fields are

  • numelts: The number of elements in vectors of this type
  • eltty: The type index of the vector element type

TYPE_CODE_X86_FP80 Record

[X86_FP80]

The X86_FP80 record (code 13) adds an x86_fp80 (80-bit floating point)type to the type table.

TYPE_CODE_FP128 Record

[FP128]

The FP128 record (code 14) adds an fp128 (128-bit floating point) typeto the type table.

TYPE_CODE_PPC_FP128 Record

[PPC_FP128]

The PPC_FP128 record (code 15) adds a ppc_fp128 (128-bit floating point)type to the type table.

TYPE_CODE_METADATA Record

[METADATA]

The METADATA record (code 16) adds a metadata type to the type table.

TYPE_CODE_X86_MMX Record

[X86_MMX]

The X86_MMX record (code 17) adds an x86_mmx type to the type table.

TYPE_CODE_STRUCT_ANON Record

[STRUCT_ANON, ispacked, …eltty…]

The STRUCT_ANON record (code 18) adds a literal struct type to the typetable. The operand fields are

  • ispacked: Non-zero if the type represents a packed structure
  • eltty: Zero or more type indices representing the element types of thestructure

TYPE_CODE_STRUCT_NAME Record

[STRUCT_NAME, …string…]

The STRUCT_NAME record (code 19) contains a variable number of valuesrepresenting the bytes of a struct name. The next OPAQUE orSTRUCT_NAMED record will use this name.

TYPE_CODE_STRUCT_NAMED Record

[STRUCT_NAMED, ispacked, …eltty…]

The STRUCT_NAMED record (code 20) adds an identified struct type to thetype table, with a name defined by a previously encountered STRUCT_NAMErecord. The operand fields are

  • ispacked: Non-zero if the type represents a packed structure
  • eltty: Zero or more type indices representing the element types of thestructure

TYPE_CODE_FUNCTION Record

[FUNCTION, vararg, retty, …paramty… ]

The FUNCTION record (code 21) adds a function type to the type table. Theoperand fields are

  • vararg: Non-zero if the type represents a varargs function
  • retty: The type index of the function’s return type
  • paramty: Zero or more type indices representing the parameter types of thefunction

CONSTANTS_BLOCK Contents

The CONSTANTS_BLOCK block (id 11) …

FUNCTION_BLOCK Contents

The FUNCTION_BLOCK block (id 12) …

In addition to the record types described below, a FUNCTION_BLOCK block maycontain the following sub-blocks:

VALUE_SYMTAB_BLOCK Contents

The VALUE_SYMTAB_BLOCK block (id 14) …

METADATA_BLOCK Contents

The METADATA_BLOCK block (id 15) …

METADATA_ATTACHMENT Contents

The METADATA_ATTACHMENT block (id 16) …

STRTAB_BLOCK Contents

The STRTAB block (id 23) contains a single record (STRTAB_BLOB, id 1)with a single blob operand containing the bitcode file’s string table.

Strings in the string table are not null terminated. A record’s strtaboffset and strtab size operands specify the byte offset and size of astring within the string table.

The string table is used by all preceding blocks in the bitcode file that arenot succeeded by another intervening STRTAB block. Normally a bitcodefile will have a single string table, but it may have more than one if itwas created by binary concatenation of multiple bitcode files.