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