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: abitstreamcontainer format and anencoding 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 awrapper 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.

  • Encodingprimitives 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 thellvm-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 shouldnotdetermine 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 asFixed 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 30 (0x1E) is encoded as 62 (0b0011’1110) when emitted asa vbr4 value. The first set of four bits starting from the least significantindicates the value 6 (110) with a continuation piece (indicated by a high bitof 1). The next set of four bits indicates a value of 24 (011 << 3) with nocontinuation. The sum (6+24) yields the value 30.

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:

'a'..'z'---0..25'A'..'Z'---26..51'0'..'9'---52..61'.'---62'_'---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 ofBlocks andData 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 forstandard 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:

  1. 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.

  2. 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 aBLOCKINFO block, in which case they are defined in all blocksthat match the ID that theBLOCKINFO 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]

TheENTER_SUBBLOCK abbreviation ID specifies the start of a new blockrecord. Theblockid value is encoded as an 8-bit VBR identifier, andindicates the type of block being entered, which can be astandard block oran application-specific block. Thenewabbrevlen value is a 4-bit VBR, whichspecifies the abbrev id width for the sub-block. Theblocklen 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>]

TheEND_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, …]

AnUNABBREV_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 theUNABBREV_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 an abbreviation id followed by a set of fields that areencoded according to theabbreviation 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, …]

ADEFINE_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 theDEFINE_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).

  1. 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.

  2. Encoding info without data — [01, encoding3] — Operand encodings that do not have extra dataare just emitted as their code.

  3. 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 afixed-width value, whosewidth is specified by the operand’s extra data.

  • VBR (code 2): The field should be emitted as avariable-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 achar6-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:

[0,Fixed,4][0,Array][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:

  1. The first value, 4, is the abbreviation ID for this abbreviation.

  2. The second value, 2, is the record code forTRIPLE records within LLVM IRfileMODULE_BLOCK blocks.

  3. The third value, 4, is the length of the array.

  4. 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 theTRIPLE 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

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

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

TheSETBID 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 aSETBID record prior to anyother records.

StandardDEFINE_ABBREV records can occur insideBLOCKINFO blocks, butunlike their occurrence in normal blocks, the abbreviation is defined for blocksmatching the block ID we are describing,not theBLOCKINFO blockitself. The abbreviations defined inBLOCKINFO blocks receive abbreviationIDs as described inDEFINE_ABBREV.

TheBLOCKNAME 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.

TheSETRECORDNAME 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 inBLOCKINFO 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 always0x0B17C0DE andthe version is currently always0. 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 or.llvmbc for the other objectformats. ELF objects additionally support a.llvm.lto section forFatLTO, which contains bitcode suitable for LTO compilation (i.e. bitcodethat has gone through a pre-link LTO pipeline). The.llvmbc sectionpredates FatLTO support in LLVM, and may not always contain bitcode that issuitable for LTO (i.e. from-fembed-bitcode). The wrapper format is usefulfor accommodating LTO in compilation pipelines where intermediate objects mustbe native object files which contain metadata in other sections.

Not all tools support this format. For example, lld and the gold plugin willignore the.llvmbc section when linking object files, but can use.llvm.lto sections when passed the correct command line options.

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 inCST_CODE_INTEGER andCST_CODE_WIDE_INTEGER records withinCONSTANTS_BLOCK blocks.It is also used for phi instruction operands inMODULE_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

TheMODULE_BLOCK block (id 8) is the top-level block for LLVM bitcode files,and each module in a bitcode file must contain exactly one. A bitcode file withmulti-module bitcode is valid. In addition to records (described below)containing information about the module, aMODULE_BLOCK block may containthe following sub-blocks:

MODULE_CODE_VERSION Record

[VERSION,version#]

TheVERSION 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 ineachFUNCTION_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

#n = load #n-1#n+1 = icmp eq #n, #const0br #n+1, label #(bb1), label #(bb2)

version 1 will encode the instructions as

#n = load #1#n+1 = icmp eq #1, (#n+1)-#const0br #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 recordsFUNCTION,GLOBALVAR,ALIAS,IFUNC andCOMDAT change such that the first two operandsspecify an offset and size of a string in a string table (seeSTRTAB_BLOCKContents), the function name is removed from theFNENTRY record in thevalue symbol table, and the top-levelVALUE_SYMTAB_BLOCK may only containFNENTRY records.

MODULE_CODE_TRIPLE Record

[TRIPLE,...string...]

TheTRIPLE record (code 2) contains a variable number of values representingthe bytes of thetargettriple specification string.

MODULE_CODE_DATALAYOUT Record

[DATALAYOUT,...string...]

TheDATALAYOUT record (code 3) contains a variable number of valuesrepresenting the bytes of thetargetdatalayout specification string.

MODULE_CODE_ASM Record

[ASM,...string...]

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

MODULE_CODE_SECTIONNAME Record

[SECTIONNAME,...string...]

TheSECTIONNAME 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 functionsection attributes) within the module. These recordscan be referenced by the 1-based index in thesection fields ofGLOBALVARorFUNCTION records.

MODULE_CODE_DEPLIB Record

[DEPLIB,...string...]

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

MODULE_CODE_GLOBALVAR Record

[GLOBALVAR,strtaboffset,strtabsize,pointertype,isconst,initid,linkage,alignment,section,visibility,threadlocal,unnamed_addr,externally_initialized,dllstorageclass,comdat,attributes,preemptionspecifier]

TheGLOBALVAR 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.SeeSTRTAB_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:

    • notthreadlocal: code 0

    • threadlocal;defaultTLSmodel: code 1

    • localdynamic: code 2

    • initialexec: code 3

    • localexec: code 4

  • unnamed_addr: If present, an encoding of theunnamed_addr attribute of thisvariable:

    • notunnamed_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,strtaboffset,strtabsize,type,callingconv,isproto,linkage,paramattr,alignment,section,visibility,gc,prologuedata,dllstorageclass,comdat,prefixdata,personalityfn,preemptionspecifier]

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

  • strtab offset,strtab size: Specifies the name of the function.SeeSTRTAB_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*anyregcc: code 13*preserve_mostcc: code 14*preserve_allcc: code 15*swiftcc : code 16*cxx_fast_tlscc: code 17*tailcc : code 18*cfguard_checkcc : code 19*swifttailcc : code 20*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 thelinkage type for this function

  • paramattr: If nonzero, the 1-based parameter attribute index into the tableofPARAMATTR_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 thevisibility of this function

  • gc: If present and nonzero, the 1-based garbage collector index in the tableofMODULE_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 theruntime preemption specifier of this function.

MODULE_CODE_ALIAS Record

[ALIAS,strtaboffset,strtabsize,aliastype,aliaseeval#,linkage,visibility,dllstorageclass,threadlocal,unnamed_addr,preemptionspecifier]

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

  • strtab offset,strtab size: Specifies the name of the alias.SeeSTRTAB_BLOCK Contents.

  • alias type: The type index of the alias

  • aliasee val#: The value index of the aliased value

  • linkage: An encoding of thelinkage type for this alias

  • visibility: If present, an encoding of thevisibility 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 theruntime preemption specifier of this alias.

MODULE_CODE_GCNAME Record

[GCNAME,...string...]

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

PARAMATTR_BLOCK Contents

ThePARAMATTR_BLOCK block (id 9) contains a table of entries describing theattributes of function parameters. These entries are referenced by 1-based indexin theparamattr field of module blockFUNCTION records, or within theattr field of function blockINST_INVOKE andINST_CALL records.

Entries withinPARAMATTR_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,...]

TheENTRY record (code 2) contains a variable number of values describing aunique set of function parameter attributes. Eachattrgrp value is used as akey with which to look up an entry in the attribute group table describedin thePARAMATTR_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 theIR Backwards Compatibility policy.

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

TheENTRY record (code 1) contains an even number of values describing aunique set of function parameter attributes. Eachparamidx value indicateswhich set of attributes is represented, with 0 representing the return valueattributes, 0xFFFFFFFF representing function attributes, and other valuesrepresenting 1-based function parameters. Eachattr 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:alignn

  • bit 32:nocapture

  • bit 33:noredzone

  • bit 34:noimplicitfloat

  • bit 35:naked

  • bit 36:inlinehint

  • bits 37-39:alignstackn, represented as the logarithmbase 2 of the requested alignment, plus 1

PARAMATTR_GROUP_BLOCK Contents

ThePARAMATTR_GROUP_BLOCK block (id 10) contains a table of entriesdescribing the attribute groups present in the module. These entries can bereferenced withinPARAMATTR_CODE_ENTRY entries.

PARAMATTR_GRP_CODE_ENTRY Record

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

TheENTRY record (code 3) containsgrpid andparamidx 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 referencedwithinPARAMATTR_CODE_ENTRY entries. Theparamidx value indicates whichset of attributes is represented, with 0 representing the return valueattributes, 0xFFFFFFFF representing function attributes, and other valuesrepresenting 1-based function parameters.

Eachattr 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). Thekind 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), thekey value is an integer codeidentifying the attribute. For attributes with an integer argument (code 1),thevalue value indicates the argument.

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

The integer codes are mapped to attributes as described in theAttributeKindCodes enumeration in the fileLLVMBitCodes.h.

For example:

enumAttributeKindCodes{//=0isunusedATTR_KIND_ALIGNMENT=1,ATTR_KIND_ALWAYS_INLINE=2,...}

Correspond to:

  • code 1:align(<n>)

  • code 2:alwaysinline

The mappings between the enumeration and the attribute name string may be foundin the fileAttributes.td.

Note

Theallocsize 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), withNumEltsParam taking onthe sentinel value -1 if it is not specified.

Note

Thevscale_range 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.(Min<<32)|Max), withMax taking on the value ofMin ifit is not specified.

TYPE_BLOCK Contents

TheTYPE_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 ofNUMENTRY) 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 withinTYPE_BLOCK are constructed to ensure that each entry isunique (i.e., no two indices represent structurally equivalent types).

TYPE_CODE_NUMENTRY Record

[NUMENTRY,numentries]

TheNUMENTRY 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]

TheVOID record (code 2) adds avoid type to the type table.

TYPE_CODE_HALF Record

[HALF]

TheHALF record (code 10) adds ahalf (16-bit floating point) type tothe type table.

TYPE_CODE_BFLOAT Record

[BFLOAT]

TheBFLOAT record (code 23) adds abfloat (16-bit brain floating point)type to the type table.

TYPE_CODE_FLOAT Record

[FLOAT]

TheFLOAT record (code 3) adds afloat (32-bit floating point) type tothe type table.

TYPE_CODE_DOUBLE Record

[DOUBLE]

TheDOUBLE record (code 4) adds adouble (64-bit floating point) type tothe type table.

TYPE_CODE_LABEL Record

[LABEL]

TheLABEL record (code 5) adds alabel type to the type table.

TYPE_CODE_OPAQUE Record

[OPAQUE]

TheOPAQUE record (code 6) adds anopaque type to the type table, witha name defined by a previously encounteredSTRUCT_NAME record. Note thatdistinctopaque types are not unified.

TYPE_CODE_INTEGER Record

[INTEGER,width]

TheINTEGER record (code 7) adds an integer type to the type table. Thesinglewidth field indicates the width of the integer type.

TYPE_CODE_POINTER Record

[POINTER,pointeetype,addressspace]

ThePOINTER 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 theIR Backwards Compatibility policy.

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

TheFUNCTION_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]

TheARRAY 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]

TheVECTOR 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]

TheX86_FP80 record (code 13) adds anx86_fp80 (80-bit floating point)type to the type table.

TYPE_CODE_FP128 Record

[FP128]

TheFP128 record (code 14) adds anfp128 (128-bit floating point) typeto the type table.

TYPE_CODE_PPC_FP128 Record

[PPC_FP128]

ThePPC_FP128 record (code 15) adds appc_fp128 (128-bit floating point)type to the type table.

TYPE_CODE_METADATA Record

[METADATA]

TheMETADATA record (code 16) adds ametadata type to the type table.

TYPE_CODE_X86_MMX Record

[X86_MMX]

TheX86_MMX record (code 17) is deprecated, and imported as a <1 x i64> vector.

TYPE_CODE_STRUCT_ANON Record

[STRUCT_ANON,ispacked,...eltty...]

TheSTRUCT_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...]

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

TYPE_CODE_STRUCT_NAMED Record

[STRUCT_NAMED,ispacked,...eltty...]

TheSTRUCT_NAMED record (code 20) adds an identified struct type to thetype table, with a name defined by a previously encounteredSTRUCT_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...]

TheFUNCTION 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

TYPE_CODE_X86_AMX Record

[X86_AMX]

TheX86_AMX record (code 24) adds anx86_amx type to the type table.

TYPE_CODE_TARGET_TYPE Record

[TARGET_TYPE,num_tys,...ty_params...,...int_params...]

TheTARGET_TYPE record (code 26) adds a target extension type to the typetable, with a name defined by a previously encounteredSTRUCT_NAME record.The operand fields are

  • num_tys: The number of parameters that are types (as opposed to integers)

  • ty_params: Type indices that represent type parameters

  • int_params: Numbers that correspond to the integer parameters.

CONSTANTS_BLOCK Contents

TheCONSTANTS_BLOCK block (id 11) …

FUNCTION_BLOCK Contents

TheFUNCTION_BLOCK block (id 12) …

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

VALUE_SYMTAB_BLOCK Contents

TheVALUE_SYMTAB_BLOCK block (id 14) …

METADATA_BLOCK Contents

TheMETADATA_BLOCK block (id 15) …

METADATA_ATTACHMENT Contents

TheMETADATA_ATTACHMENT block (id 16) …

STRTAB_BLOCK Contents

TheSTRTAB 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’sstrtaboffset andstrtab 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 interveningSTRTAB 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.