BitCodeFormat.rst 46 KB

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