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
|
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>TableGen BackEnds — 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="1 TableGen Backend Developer’s Guide" href="BackGuide.html" />
<link rel="prev" title="TableGen Overview" href="index.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="BackGuide.html" title="1 TableGen Backend Developer’s Guide"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="index.html" title="TableGen Overview"
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="../UserGuides.html" >User Guides</a> »</li>
<li class="nav-item nav-item-2"><a href="index.html" accesskey="U">TableGen Overview</a> »</li>
<li class="nav-item nav-item-this"><a href="">TableGen BackEnds</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/TableGen/BackEnds.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="tablegen-backends">
<h1>TableGen BackEnds<a class="headerlink" href="#tablegen-backends" title="Permalink to this headline">¶</a></h1>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><p><a class="reference internal" href="#introduction" id="id1">Introduction</a></p></li>
<li><p><a class="reference internal" href="#llvm-backends" id="id2">LLVM BackEnds</a></p>
<ul>
<li><p><a class="reference internal" href="#codeemitter" id="id3">CodeEmitter</a></p></li>
<li><p><a class="reference internal" href="#registerinfo" id="id4">RegisterInfo</a></p></li>
<li><p><a class="reference internal" href="#instrinfo" id="id5">InstrInfo</a></p></li>
<li><p><a class="reference internal" href="#asmwriter" id="id6">AsmWriter</a></p></li>
<li><p><a class="reference internal" href="#asmmatcher" id="id7">AsmMatcher</a></p></li>
<li><p><a class="reference internal" href="#disassembler" id="id8">Disassembler</a></p></li>
<li><p><a class="reference internal" href="#pseudolowering" id="id9">PseudoLowering</a></p></li>
<li><p><a class="reference internal" href="#callingconv" id="id10">CallingConv</a></p></li>
<li><p><a class="reference internal" href="#dagisel" id="id11">DAGISel</a></p></li>
<li><p><a class="reference internal" href="#dfapacketizer" id="id12">DFAPacketizer</a></p></li>
<li><p><a class="reference internal" href="#fastisel" id="id13">FastISel</a></p></li>
<li><p><a class="reference internal" href="#subtarget" id="id14">Subtarget</a></p></li>
<li><p><a class="reference internal" href="#intrinsic" id="id15">Intrinsic</a></p></li>
<li><p><a class="reference internal" href="#optparserdefs" id="id16">OptParserDefs</a></p></li>
<li><p><a class="reference internal" href="#searchabletables" id="id17">SearchableTables</a></p></li>
<li><p><a class="reference internal" href="#ctags" id="id18">CTags</a></p></li>
<li><p><a class="reference internal" href="#x86evex2vex" id="id19">X86EVEX2VEX</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#clang-backends" id="id20">Clang BackEnds</a></p>
<ul>
<li><p><a class="reference internal" href="#clangattrclasses" id="id21">ClangAttrClasses</a></p></li>
<li><p><a class="reference internal" href="#clangattrparserstringswitches" id="id22">ClangAttrParserStringSwitches</a></p></li>
<li><p><a class="reference internal" href="#clangattrimpl" id="id23">ClangAttrImpl</a></p></li>
<li><p><a class="reference internal" href="#clangattrlist" id="id24">ClangAttrList</a></p></li>
<li><p><a class="reference internal" href="#clangattrpchread" id="id25">ClangAttrPCHRead</a></p></li>
<li><p><a class="reference internal" href="#clangattrpchwrite" id="id26">ClangAttrPCHWrite</a></p></li>
<li><p><a class="reference internal" href="#clangattrspellings" id="id27">ClangAttrSpellings</a></p></li>
<li><p><a class="reference internal" href="#clangattrspellinglistindex" id="id28">ClangAttrSpellingListIndex</a></p></li>
<li><p><a class="reference internal" href="#clangattrvisitor" id="id29">ClangAttrVisitor</a></p></li>
<li><p><a class="reference internal" href="#clangattrtemplateinstantiate" id="id30">ClangAttrTemplateInstantiate</a></p></li>
<li><p><a class="reference internal" href="#clangattrparsedattrlist" id="id31">ClangAttrParsedAttrList</a></p></li>
<li><p><a class="reference internal" href="#clangattrparsedattrimpl" id="id32">ClangAttrParsedAttrImpl</a></p></li>
<li><p><a class="reference internal" href="#clangattrparsedattrkinds" id="id33">ClangAttrParsedAttrKinds</a></p></li>
<li><p><a class="reference internal" href="#clangattrdump" id="id34">ClangAttrDump</a></p></li>
<li><p><a class="reference internal" href="#clangdiagsdefs" id="id35">ClangDiagsDefs</a></p></li>
<li><p><a class="reference internal" href="#clangdiaggroups" id="id36">ClangDiagGroups</a></p></li>
<li><p><a class="reference internal" href="#clangdiagsindexname" id="id37">ClangDiagsIndexName</a></p></li>
<li><p><a class="reference internal" href="#clangcommentnodes" id="id38">ClangCommentNodes</a></p></li>
<li><p><a class="reference internal" href="#clangdeclnodes" id="id39">ClangDeclNodes</a></p></li>
<li><p><a class="reference internal" href="#clangstmtnodes" id="id40">ClangStmtNodes</a></p></li>
<li><p><a class="reference internal" href="#clangsacheckers" id="id41">ClangSACheckers</a></p></li>
<li><p><a class="reference internal" href="#clangcommenthtmltags" id="id42">ClangCommentHTMLTags</a></p></li>
<li><p><a class="reference internal" href="#clangcommenthtmltagsproperties" id="id43">ClangCommentHTMLTagsProperties</a></p></li>
<li><p><a class="reference internal" href="#clangcommenthtmlnamedcharacterreferences" id="id44">ClangCommentHTMLNamedCharacterReferences</a></p></li>
<li><p><a class="reference internal" href="#clangcommentcommandinfo" id="id45">ClangCommentCommandInfo</a></p></li>
<li><p><a class="reference internal" href="#clangcommentcommandlist" id="id46">ClangCommentCommandList</a></p></li>
<li><p><a class="reference internal" href="#armneon" id="id47">ArmNeon</a></p></li>
<li><p><a class="reference internal" href="#armneonsema" id="id48">ArmNeonSema</a></p></li>
<li><p><a class="reference internal" href="#armneontest" id="id49">ArmNeonTest</a></p></li>
<li><p><a class="reference internal" href="#attrdocs" id="id50">AttrDocs</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#general-backends" id="id51">General BackEnds</a></p>
<ul>
<li><p><a class="reference internal" href="#print-records" id="id52">Print Records</a></p></li>
<li><p><a class="reference internal" href="#print-detailed-records" id="id53">Print Detailed Records</a></p></li>
<li><p><a class="reference internal" href="#json-reference" id="id54">JSON Reference</a></p></li>
<li><p><a class="reference internal" href="#searchabletables-reference" id="id55">SearchableTables Reference</a></p>
<ul>
<li><p><a class="reference internal" href="#generic-enumerated-types" id="id56">Generic Enumerated Types</a></p></li>
<li><p><a class="reference internal" href="#generic-tables" id="id57">Generic Tables</a></p></li>
<li><p><a class="reference internal" href="#search-indexes" id="id58">Search Indexes</a></p></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="introduction">
<h2><a class="toc-backref" href="#id1">Introduction</a><a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2>
<p>TableGen backends are at the core of TableGen’s functionality. The source
files provide the classes and records that are parsed and end up as a
collection of record instances, but it’s up to the backend to interpret and
print the records in a way that is meaningful to the user (normally a C++
include file or a textual list of warnings, options, and error messages).</p>
<p>TableGen is used by both LLVM, Clang, and MLIR with very different goals.
LLVM uses it as a way to automate the generation of massive amounts of
information regarding instructions, schedules, cores, and architecture
features. Some backends generate output that is consumed by more than one
source file, so they need to be created in a way that makes it is easy for
preprocessor tricks to be used. Some backends can also print C++ code
structures, so that they can be directly included as-is.</p>
<p>Clang, on the other hand, uses it mainly for diagnostic messages (errors,
warnings, tips) and attributes, so more on the textual end of the scale.</p>
<p>MLIR uses TableGen to define operations, operation dialects, and operation
traits.</p>
<p>See the <a class="reference internal" href="ProgRef.html"><span class="doc">TableGen Programmer’s Reference</span></a> for an in-depth
description of TableGen, and the <a class="reference internal" href="BackGuide.html"><span class="doc">TableGen Backend Developer’s Guide</span></a> for a guide to writing a new backend.</p>
</div>
<div class="section" id="llvm-backends">
<h2><a class="toc-backref" href="#id2">LLVM BackEnds</a><a class="headerlink" href="#llvm-backends" title="Permalink to this headline">¶</a></h2>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>This portion is incomplete. Each section below needs three subsections:
description of its purpose with a list of users, output generated from
generic input, and finally why it needed a new backend (in case there’s
something similar).</p>
</div>
<p>Overall, each backend will take the same TableGen file type and transform into
similar output for different targets/uses. There is an implicit contract between
the TableGen files, the back-ends and their users.</p>
<p>For instance, a global contract is that each back-end produces macro-guarded
sections. Based on whether the file is included by a header or a source file,
or even in which context of each file the include is being used, you have
todefine a macro just before including it, to get the right output:</p>
<div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="cp">#define GET_REGINFO_TARGET_DESC</span>
<span class="cp">#include</span> <span class="cpf">"ARMGenRegisterInfo.inc"</span><span class="cp"></span>
</pre></div>
</div>
<p>And just part of the generated file would be included. This is useful if
you need the same information in multiple formats (instantiation, initialization,
getter/setter functions, etc) from the same source TableGen file without having
to re-compile the TableGen file multiple times.</p>
<p>Sometimes, multiple macros might be defined before the same include file to
output multiple blocks:</p>
<div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="cp">#define GET_REGISTER_MATCHER</span>
<span class="cp">#define GET_SUBTARGET_FEATURE_NAME</span>
<span class="cp">#define GET_MATCHER_IMPLEMENTATION</span>
<span class="cp">#include</span> <span class="cpf">"ARMGenAsmMatcher.inc"</span><span class="cp"></span>
</pre></div>
</div>
<p>The macros will be undef’d automatically as they’re used, in the include file.</p>
<p>On all LLVM back-ends, the <code class="docutils literal notranslate"><span class="pre">llvm-tblgen</span></code> binary will be executed on the root
TableGen file <code class="docutils literal notranslate"><span class="pre"><Target>.td</span></code>, which should include all others. This guarantees
that all information needed is accessible, and that no duplication is needed
in the TableGen files.</p>
<div class="section" id="codeemitter">
<h3><a class="toc-backref" href="#id3">CodeEmitter</a><a class="headerlink" href="#codeemitter" title="Permalink to this headline">¶</a></h3>
<p><strong>Purpose</strong>: CodeEmitterGen uses the descriptions of instructions and their fields to
construct an automated code emitter: a function that, given a MachineInstr,
returns the (currently, 32-bit unsigned) value of the instruction.</p>
<p><strong>Output</strong>: C++ code, implementing the target’s CodeEmitter
class by overriding the virtual functions as <code class="docutils literal notranslate"><span class="pre"><Target>CodeEmitter::function()</span></code>.</p>
<p><strong>Usage</strong>: Used to include directly at the end of <code class="docutils literal notranslate"><span class="pre"><Target>MCCodeEmitter.cpp</span></code>.</p>
</div>
<div class="section" id="registerinfo">
<h3><a class="toc-backref" href="#id4">RegisterInfo</a><a class="headerlink" href="#registerinfo" title="Permalink to this headline">¶</a></h3>
<p><strong>Purpose</strong>: This tablegen backend is responsible for emitting a description of a target
register file for a code generator. It uses instances of the Register,
RegisterAliases, and RegisterClass classes to gather this information.</p>
<p><strong>Output</strong>: C++ code with enums and structures representing the register mappings,
properties, masks, etc.</p>
<p><strong>Usage</strong>: Both on <code class="docutils literal notranslate"><span class="pre"><Target>BaseRegisterInfo</span></code> and <code class="docutils literal notranslate"><span class="pre"><Target>MCTargetDesc</span></code> (headers
and source files) with macros defining in which they are for declaration vs.
initialization issues.</p>
</div>
<div class="section" id="instrinfo">
<h3><a class="toc-backref" href="#id5">InstrInfo</a><a class="headerlink" href="#instrinfo" title="Permalink to this headline">¶</a></h3>
<p><strong>Purpose</strong>: This tablegen backend is responsible for emitting a description of the target
instruction set for the code generator. (what are the differences from CodeEmitter?)</p>
<p><strong>Output</strong>: C++ code with enums and structures representing the instruction mappings,
properties, masks, etc.</p>
<p><strong>Usage</strong>: Both on <code class="docutils literal notranslate"><span class="pre"><Target>BaseInstrInfo</span></code> and <code class="docutils literal notranslate"><span class="pre"><Target>MCTargetDesc</span></code> (headers
and source files) with macros defining in which they are for declaration vs.
initialization issues.</p>
</div>
<div class="section" id="asmwriter">
<h3><a class="toc-backref" href="#id6">AsmWriter</a><a class="headerlink" href="#asmwriter" title="Permalink to this headline">¶</a></h3>
<p><strong>Purpose</strong>: Emits an assembly printer for the current target.</p>
<p><strong>Output</strong>: Implementation of <code class="docutils literal notranslate"><span class="pre"><Target>InstPrinter::printInstruction()</span></code>, among
other things.</p>
<p><strong>Usage</strong>: Included directly into <code class="docutils literal notranslate"><span class="pre">InstPrinter/<Target>InstPrinter.cpp</span></code>.</p>
</div>
<div class="section" id="asmmatcher">
<h3><a class="toc-backref" href="#id7">AsmMatcher</a><a class="headerlink" href="#asmmatcher" title="Permalink to this headline">¶</a></h3>
<p><strong>Purpose</strong>: Emits a target specifier matcher for
converting parsed assembly operands in the MCInst structures. It also
emits a matcher for custom operand parsing. Extensive documentation is
written on the <code class="docutils literal notranslate"><span class="pre">AsmMatcherEmitter.cpp</span></code> file.</p>
<p><strong>Output</strong>: Assembler parsers’ matcher functions, declarations, etc.</p>
<p><strong>Usage</strong>: Used in back-ends’ <code class="docutils literal notranslate"><span class="pre">AsmParser/<Target>AsmParser.cpp</span></code> for
building the AsmParser class.</p>
</div>
<div class="section" id="disassembler">
<h3><a class="toc-backref" href="#id8">Disassembler</a><a class="headerlink" href="#disassembler" title="Permalink to this headline">¶</a></h3>
<p><strong>Purpose</strong>: Contains disassembler table emitters for various
architectures. Extensive documentation is written on the
<code class="docutils literal notranslate"><span class="pre">DisassemblerEmitter.cpp</span></code> file.</p>
<p><strong>Output</strong>: Decoding tables, static decoding functions, etc.</p>
<p><strong>Usage</strong>: Directly included in <code class="docutils literal notranslate"><span class="pre">Disassembler/<Target>Disassembler.cpp</span></code>
to cater for all default decodings, after all hand-made ones.</p>
</div>
<div class="section" id="pseudolowering">
<h3><a class="toc-backref" href="#id9">PseudoLowering</a><a class="headerlink" href="#pseudolowering" title="Permalink to this headline">¶</a></h3>
<p><strong>Purpose</strong>: Generate pseudo instruction lowering.</p>
<p><strong>Output</strong>: Implements <code class="docutils literal notranslate"><span class="pre"><Target>AsmPrinter::emitPseudoExpansionLowering()</span></code>.</p>
<p><strong>Usage</strong>: Included directly into <code class="docutils literal notranslate"><span class="pre"><Target>AsmPrinter.cpp</span></code>.</p>
</div>
<div class="section" id="callingconv">
<h3><a class="toc-backref" href="#id10">CallingConv</a><a class="headerlink" href="#callingconv" title="Permalink to this headline">¶</a></h3>
<p><strong>Purpose</strong>: Responsible for emitting descriptions of the calling
conventions supported by this target.</p>
<p><strong>Output</strong>: Implement static functions to deal with calling conventions
chained by matching styles, returning false on no match.</p>
<p><strong>Usage</strong>: Used in ISelLowering and FastIsel as function pointers to
implementation returned by a CC selection function.</p>
</div>
<div class="section" id="dagisel">
<h3><a class="toc-backref" href="#id11">DAGISel</a><a class="headerlink" href="#dagisel" title="Permalink to this headline">¶</a></h3>
<p><strong>Purpose</strong>: Generate a DAG instruction selector.</p>
<p><strong>Output</strong>: Creates huge functions for automating DAG selection.</p>
<p><strong>Usage</strong>: Included in <code class="docutils literal notranslate"><span class="pre"><Target>ISelDAGToDAG.cpp</span></code> inside the target’s
implementation of <code class="docutils literal notranslate"><span class="pre">SelectionDAGISel</span></code>.</p>
</div>
<div class="section" id="dfapacketizer">
<h3><a class="toc-backref" href="#id12">DFAPacketizer</a><a class="headerlink" href="#dfapacketizer" title="Permalink to this headline">¶</a></h3>
<p><strong>Purpose</strong>: This class parses the Schedule.td file and produces an API that
can be used to reason about whether an instruction can be added to a packet
on a VLIW architecture. The class internally generates a deterministic finite
automaton (DFA) that models all possible mappings of machine instructions
to functional units as instructions are added to a packet.</p>
<p><strong>Output</strong>: Scheduling tables for GPU back-ends (Hexagon, AMD).</p>
<p><strong>Usage</strong>: Included directly on <code class="docutils literal notranslate"><span class="pre"><Target>InstrInfo.cpp</span></code>.</p>
</div>
<div class="section" id="fastisel">
<h3><a class="toc-backref" href="#id13">FastISel</a><a class="headerlink" href="#fastisel" title="Permalink to this headline">¶</a></h3>
<p><strong>Purpose</strong>: This tablegen backend emits code for use by the “fast”
instruction selection algorithm. See the comments at the top of
lib/CodeGen/SelectionDAG/FastISel.cpp for background. This file
scans through the target’s tablegen instruction-info files
and extracts instructions with obvious-looking patterns, and it emits
code to look up these instructions by type and operator.</p>
<p><strong>Output</strong>: Generates <code class="docutils literal notranslate"><span class="pre">Predicate</span></code> and <code class="docutils literal notranslate"><span class="pre">FastEmit</span></code> methods.</p>
<p><strong>Usage</strong>: Implements private methods of the targets’ implementation
of <code class="docutils literal notranslate"><span class="pre">FastISel</span></code> class.</p>
</div>
<div class="section" id="subtarget">
<h3><a class="toc-backref" href="#id14">Subtarget</a><a class="headerlink" href="#subtarget" title="Permalink to this headline">¶</a></h3>
<p><strong>Purpose</strong>: Generate subtarget enumerations.</p>
<p><strong>Output</strong>: Enums, globals, local tables for sub-target information.</p>
<p><strong>Usage</strong>: Populates <code class="docutils literal notranslate"><span class="pre"><Target>Subtarget</span></code> and
<code class="docutils literal notranslate"><span class="pre">MCTargetDesc/<Target>MCTargetDesc</span></code> files (both headers and source).</p>
</div>
<div class="section" id="intrinsic">
<h3><a class="toc-backref" href="#id15">Intrinsic</a><a class="headerlink" href="#intrinsic" title="Permalink to this headline">¶</a></h3>
<p><strong>Purpose</strong>: Generate (target) intrinsic information.</p>
</div>
<div class="section" id="optparserdefs">
<h3><a class="toc-backref" href="#id16">OptParserDefs</a><a class="headerlink" href="#optparserdefs" title="Permalink to this headline">¶</a></h3>
<p><strong>Purpose</strong>: Print enum values for a class.</p>
</div>
<div class="section" id="searchabletables">
<h3><a class="toc-backref" href="#id17">SearchableTables</a><a class="headerlink" href="#searchabletables" title="Permalink to this headline">¶</a></h3>
<p><strong>Purpose</strong>: Generate custom searchable tables.</p>
<p><strong>Output</strong>: Enums, global tables, and lookup helper functions.</p>
<p><strong>Usage</strong>: This backend allows generating free-form, target-specific tables
from TableGen records. The ARM and AArch64 targets use this backend to generate
tables of system registers; the AMDGPU target uses it to generate meta-data
about complex image and memory buffer instructions.</p>
<p>See <a class="reference internal" href="#searchabletables-reference">SearchableTables Reference</a> for a detailed description.</p>
</div>
<div class="section" id="ctags">
<h3><a class="toc-backref" href="#id18">CTags</a><a class="headerlink" href="#ctags" title="Permalink to this headline">¶</a></h3>
<p><strong>Purpose</strong>: This tablegen backend emits an index of definitions in ctags(1)
format. A helper script, utils/TableGen/tdtags, provides an easier-to-use
interface; run ‘tdtags -H’ for documentation.</p>
</div>
<div class="section" id="x86evex2vex">
<h3><a class="toc-backref" href="#id19">X86EVEX2VEX</a><a class="headerlink" href="#x86evex2vex" title="Permalink to this headline">¶</a></h3>
<p><strong>Purpose</strong>: This X86 specific tablegen backend emits tables that map EVEX
encoded instructions to their VEX encoded identical instruction.</p>
</div>
</div>
<div class="section" id="clang-backends">
<h2><a class="toc-backref" href="#id20">Clang BackEnds</a><a class="headerlink" href="#clang-backends" title="Permalink to this headline">¶</a></h2>
<div class="section" id="clangattrclasses">
<h3><a class="toc-backref" href="#id21">ClangAttrClasses</a><a class="headerlink" href="#clangattrclasses" title="Permalink to this headline">¶</a></h3>
<p><strong>Purpose</strong>: Creates Attrs.inc, which contains semantic attribute class
declarations for any attribute in <code class="docutils literal notranslate"><span class="pre">Attr.td</span></code> that has not set <code class="docutils literal notranslate"><span class="pre">ASTNode</span> <span class="pre">=</span> <span class="pre">0</span></code>.
This file is included as part of <code class="docutils literal notranslate"><span class="pre">Attr.h</span></code>.</p>
</div>
<div class="section" id="clangattrparserstringswitches">
<h3><a class="toc-backref" href="#id22">ClangAttrParserStringSwitches</a><a class="headerlink" href="#clangattrparserstringswitches" title="Permalink to this headline">¶</a></h3>
<p><strong>Purpose</strong>: Creates AttrParserStringSwitches.inc, which contains
StringSwitch::Case statements for parser-related string switches. Each switch
is given its own macro (such as <code class="docutils literal notranslate"><span class="pre">CLANG_ATTR_ARG_CONTEXT_LIST</span></code>, or
<code class="docutils literal notranslate"><span class="pre">CLANG_ATTR_IDENTIFIER_ARG_LIST</span></code>), which is expected to be defined before
including AttrParserStringSwitches.inc, and undefined after.</p>
</div>
<div class="section" id="clangattrimpl">
<h3><a class="toc-backref" href="#id23">ClangAttrImpl</a><a class="headerlink" href="#clangattrimpl" title="Permalink to this headline">¶</a></h3>
<p><strong>Purpose</strong>: Creates AttrImpl.inc, which contains semantic attribute class
definitions for any attribute in <code class="docutils literal notranslate"><span class="pre">Attr.td</span></code> that has not set <code class="docutils literal notranslate"><span class="pre">ASTNode</span> <span class="pre">=</span> <span class="pre">0</span></code>.
This file is included as part of <code class="docutils literal notranslate"><span class="pre">AttrImpl.cpp</span></code>.</p>
</div>
<div class="section" id="clangattrlist">
<h3><a class="toc-backref" href="#id24">ClangAttrList</a><a class="headerlink" href="#clangattrlist" title="Permalink to this headline">¶</a></h3>
<p><strong>Purpose</strong>: Creates AttrList.inc, which is used when a list of semantic
attribute identifiers is required. For instance, <code class="docutils literal notranslate"><span class="pre">AttrKinds.h</span></code> includes this
file to generate the list of <code class="docutils literal notranslate"><span class="pre">attr::Kind</span></code> enumeration values. This list is
separated out into multiple categories: attributes, inheritable attributes, and
inheritable parameter attributes. This categorization happens automatically
based on information in <code class="docutils literal notranslate"><span class="pre">Attr.td</span></code> and is used to implement the <code class="docutils literal notranslate"><span class="pre">classof</span></code>
functionality required for <code class="docutils literal notranslate"><span class="pre">dyn_cast</span></code> and similar APIs.</p>
</div>
<div class="section" id="clangattrpchread">
<h3><a class="toc-backref" href="#id25">ClangAttrPCHRead</a><a class="headerlink" href="#clangattrpchread" title="Permalink to this headline">¶</a></h3>
<p><strong>Purpose</strong>: Creates AttrPCHRead.inc, which is used to deserialize attributes
in the <code class="docutils literal notranslate"><span class="pre">ASTReader::ReadAttributes</span></code> function.</p>
</div>
<div class="section" id="clangattrpchwrite">
<h3><a class="toc-backref" href="#id26">ClangAttrPCHWrite</a><a class="headerlink" href="#clangattrpchwrite" title="Permalink to this headline">¶</a></h3>
<p><strong>Purpose</strong>: Creates AttrPCHWrite.inc, which is used to serialize attributes in
the <code class="docutils literal notranslate"><span class="pre">ASTWriter::WriteAttributes</span></code> function.</p>
</div>
<div class="section" id="clangattrspellings">
<h3><a class="toc-backref" href="#id27">ClangAttrSpellings</a><a class="headerlink" href="#clangattrspellings" title="Permalink to this headline">¶</a></h3>
<p><strong>Purpose</strong>: Creates AttrSpellings.inc, which is used to implement the
<code class="docutils literal notranslate"><span class="pre">__has_attribute</span></code> feature test macro.</p>
</div>
<div class="section" id="clangattrspellinglistindex">
<h3><a class="toc-backref" href="#id28">ClangAttrSpellingListIndex</a><a class="headerlink" href="#clangattrspellinglistindex" title="Permalink to this headline">¶</a></h3>
<p><strong>Purpose</strong>: Creates AttrSpellingListIndex.inc, which is used to map parsed
attribute spellings (including which syntax or scope was used) to an attribute
spelling list index. These spelling list index values are internal
implementation details exposed via
<code class="docutils literal notranslate"><span class="pre">AttributeList::getAttributeSpellingListIndex</span></code>.</p>
</div>
<div class="section" id="clangattrvisitor">
<h3><a class="toc-backref" href="#id29">ClangAttrVisitor</a><a class="headerlink" href="#clangattrvisitor" title="Permalink to this headline">¶</a></h3>
<p><strong>Purpose</strong>: Creates AttrVisitor.inc, which is used when implementing
recursive AST visitors.</p>
</div>
<div class="section" id="clangattrtemplateinstantiate">
<h3><a class="toc-backref" href="#id30">ClangAttrTemplateInstantiate</a><a class="headerlink" href="#clangattrtemplateinstantiate" title="Permalink to this headline">¶</a></h3>
<p><strong>Purpose</strong>: Creates AttrTemplateInstantiate.inc, which implements the
<code class="docutils literal notranslate"><span class="pre">instantiateTemplateAttribute</span></code> function, used when instantiating a template
that requires an attribute to be cloned.</p>
</div>
<div class="section" id="clangattrparsedattrlist">
<h3><a class="toc-backref" href="#id31">ClangAttrParsedAttrList</a><a class="headerlink" href="#clangattrparsedattrlist" title="Permalink to this headline">¶</a></h3>
<p><strong>Purpose</strong>: Creates AttrParsedAttrList.inc, which is used to generate the
<code class="docutils literal notranslate"><span class="pre">AttributeList::Kind</span></code> parsed attribute enumeration.</p>
</div>
<div class="section" id="clangattrparsedattrimpl">
<h3><a class="toc-backref" href="#id32">ClangAttrParsedAttrImpl</a><a class="headerlink" href="#clangattrparsedattrimpl" title="Permalink to this headline">¶</a></h3>
<p><strong>Purpose</strong>: Creates AttrParsedAttrImpl.inc, which is used by
<code class="docutils literal notranslate"><span class="pre">AttributeList.cpp</span></code> to implement several functions on the <code class="docutils literal notranslate"><span class="pre">AttributeList</span></code>
class. This functionality is implemented via the <code class="docutils literal notranslate"><span class="pre">AttrInfoMap</span> <span class="pre">ParsedAttrInfo</span></code>
array, which contains one element per parsed attribute object.</p>
</div>
<div class="section" id="clangattrparsedattrkinds">
<h3><a class="toc-backref" href="#id33">ClangAttrParsedAttrKinds</a><a class="headerlink" href="#clangattrparsedattrkinds" title="Permalink to this headline">¶</a></h3>
<p><strong>Purpose</strong>: Creates AttrParsedAttrKinds.inc, which is used to implement the
<code class="docutils literal notranslate"><span class="pre">AttributeList::getKind</span></code> function, mapping a string (and syntax) to a parsed
attribute <code class="docutils literal notranslate"><span class="pre">AttributeList::Kind</span></code> enumeration.</p>
</div>
<div class="section" id="clangattrdump">
<h3><a class="toc-backref" href="#id34">ClangAttrDump</a><a class="headerlink" href="#clangattrdump" title="Permalink to this headline">¶</a></h3>
<p><strong>Purpose</strong>: Creates AttrDump.inc, which dumps information about an attribute.
It is used to implement <code class="docutils literal notranslate"><span class="pre">ASTDumper::dumpAttr</span></code>.</p>
</div>
<div class="section" id="clangdiagsdefs">
<h3><a class="toc-backref" href="#id35">ClangDiagsDefs</a><a class="headerlink" href="#clangdiagsdefs" title="Permalink to this headline">¶</a></h3>
<p>Generate Clang diagnostics definitions.</p>
</div>
<div class="section" id="clangdiaggroups">
<h3><a class="toc-backref" href="#id36">ClangDiagGroups</a><a class="headerlink" href="#clangdiaggroups" title="Permalink to this headline">¶</a></h3>
<p>Generate Clang diagnostic groups.</p>
</div>
<div class="section" id="clangdiagsindexname">
<h3><a class="toc-backref" href="#id37">ClangDiagsIndexName</a><a class="headerlink" href="#clangdiagsindexname" title="Permalink to this headline">¶</a></h3>
<p>Generate Clang diagnostic name index.</p>
</div>
<div class="section" id="clangcommentnodes">
<h3><a class="toc-backref" href="#id38">ClangCommentNodes</a><a class="headerlink" href="#clangcommentnodes" title="Permalink to this headline">¶</a></h3>
<p>Generate Clang AST comment nodes.</p>
</div>
<div class="section" id="clangdeclnodes">
<h3><a class="toc-backref" href="#id39">ClangDeclNodes</a><a class="headerlink" href="#clangdeclnodes" title="Permalink to this headline">¶</a></h3>
<p>Generate Clang AST declaration nodes.</p>
</div>
<div class="section" id="clangstmtnodes">
<h3><a class="toc-backref" href="#id40">ClangStmtNodes</a><a class="headerlink" href="#clangstmtnodes" title="Permalink to this headline">¶</a></h3>
<p>Generate Clang AST statement nodes.</p>
</div>
<div class="section" id="clangsacheckers">
<h3><a class="toc-backref" href="#id41">ClangSACheckers</a><a class="headerlink" href="#clangsacheckers" title="Permalink to this headline">¶</a></h3>
<p>Generate Clang Static Analyzer checkers.</p>
</div>
<div class="section" id="clangcommenthtmltags">
<h3><a class="toc-backref" href="#id42">ClangCommentHTMLTags</a><a class="headerlink" href="#clangcommenthtmltags" title="Permalink to this headline">¶</a></h3>
<p>Generate efficient matchers for HTML tag names that are used in documentation comments.</p>
</div>
<div class="section" id="clangcommenthtmltagsproperties">
<h3><a class="toc-backref" href="#id43">ClangCommentHTMLTagsProperties</a><a class="headerlink" href="#clangcommenthtmltagsproperties" title="Permalink to this headline">¶</a></h3>
<p>Generate efficient matchers for HTML tag properties.</p>
</div>
<div class="section" id="clangcommenthtmlnamedcharacterreferences">
<h3><a class="toc-backref" href="#id44">ClangCommentHTMLNamedCharacterReferences</a><a class="headerlink" href="#clangcommenthtmlnamedcharacterreferences" title="Permalink to this headline">¶</a></h3>
<p>Generate function to translate named character references to UTF-8 sequences.</p>
</div>
<div class="section" id="clangcommentcommandinfo">
<h3><a class="toc-backref" href="#id45">ClangCommentCommandInfo</a><a class="headerlink" href="#clangcommentcommandinfo" title="Permalink to this headline">¶</a></h3>
<p>Generate command properties for commands that are used in documentation comments.</p>
</div>
<div class="section" id="clangcommentcommandlist">
<h3><a class="toc-backref" href="#id46">ClangCommentCommandList</a><a class="headerlink" href="#clangcommentcommandlist" title="Permalink to this headline">¶</a></h3>
<p>Generate list of commands that are used in documentation comments.</p>
</div>
<div class="section" id="armneon">
<h3><a class="toc-backref" href="#id47">ArmNeon</a><a class="headerlink" href="#armneon" title="Permalink to this headline">¶</a></h3>
<p>Generate arm_neon.h for clang.</p>
</div>
<div class="section" id="armneonsema">
<h3><a class="toc-backref" href="#id48">ArmNeonSema</a><a class="headerlink" href="#armneonsema" title="Permalink to this headline">¶</a></h3>
<p>Generate ARM NEON sema support for clang.</p>
</div>
<div class="section" id="armneontest">
<h3><a class="toc-backref" href="#id49">ArmNeonTest</a><a class="headerlink" href="#armneontest" title="Permalink to this headline">¶</a></h3>
<p>Generate ARM NEON tests for clang.</p>
</div>
<div class="section" id="attrdocs">
<h3><a class="toc-backref" href="#id50">AttrDocs</a><a class="headerlink" href="#attrdocs" title="Permalink to this headline">¶</a></h3>
<p><strong>Purpose</strong>: Creates <code class="docutils literal notranslate"><span class="pre">AttributeReference.rst</span></code> from <code class="docutils literal notranslate"><span class="pre">AttrDocs.td</span></code>, and is
used for documenting user-facing attributes.</p>
</div>
</div>
<div class="section" id="general-backends">
<h2><a class="toc-backref" href="#id51">General BackEnds</a><a class="headerlink" href="#general-backends" title="Permalink to this headline">¶</a></h2>
<div class="section" id="print-records">
<h3><a class="toc-backref" href="#id52">Print Records</a><a class="headerlink" href="#print-records" title="Permalink to this headline">¶</a></h3>
<p>The TableGen command option <code class="docutils literal notranslate"><span class="pre">--print-records</span></code> invokes a simple backend
that prints all the classes and records defined in the source files. This is
the default backend option. See the <a class="reference internal" href="BackGuide.html"><span class="doc">TableGen Backend Developer’s Guide</span></a> for more information.</p>
</div>
<div class="section" id="print-detailed-records">
<h3><a class="toc-backref" href="#id53">Print Detailed Records</a><a class="headerlink" href="#print-detailed-records" title="Permalink to this headline">¶</a></h3>
<p>The TableGen command option <code class="docutils literal notranslate"><span class="pre">--print-detailed-records</span></code> invokes a backend
that prints all the global variables, classes, and records defined in the
source files, with more detail than the default record printer. See the
<a class="reference internal" href="BackGuide.html"><span class="doc">TableGen Backend Developer’s Guide</span></a> for more
information.</p>
</div>
<div class="section" id="json-reference">
<h3><a class="toc-backref" href="#id54">JSON Reference</a><a class="headerlink" href="#json-reference" title="Permalink to this headline">¶</a></h3>
<p><strong>Purpose</strong>: Output all the values in every <code class="docutils literal notranslate"><span class="pre">def</span></code>, as a JSON data
structure that can be easily parsed by a variety of languages. Useful
for writing custom backends without having to modify TableGen itself,
or for performing auxiliary analysis on the same TableGen data passed
to a built-in backend.</p>
<p><strong>Output</strong>:</p>
<p>The root of the output file is a JSON object (i.e. dictionary),
containing the following fixed keys:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">!tablegen_json_version</span></code>: a numeric version field that will
increase if an incompatible change is ever made to the structure of
this data. The format described here corresponds to version 1.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">!instanceof</span></code>: a dictionary whose keys are the class names defined
in the TableGen input. For each key, the corresponding value is an
array of strings giving the names of <code class="docutils literal notranslate"><span class="pre">def</span></code> records that derive
from that class. So <code class="docutils literal notranslate"><span class="pre">root["!instanceof"]["Instruction"]</span></code>, for
example, would list the names of all the records deriving from the
class <code class="docutils literal notranslate"><span class="pre">Instruction</span></code>.</p></li>
</ul>
<p>For each <code class="docutils literal notranslate"><span class="pre">def</span></code> record, the root object also has a key for the record
name. The corresponding value is a subsidiary object containing the
following fixed keys:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">!superclasses</span></code>: an array of strings giving the names of all the
classes that this record derives from.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">!fields</span></code>: an array of strings giving the names of all the variables
in this record that were defined with the <code class="docutils literal notranslate"><span class="pre">field</span></code> keyword.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">!name</span></code>: a string giving the name of the record. This is always
identical to the key in the JSON root object corresponding to this
record’s dictionary. (If the record is anonymous, the name is
arbitrary.)</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">!anonymous</span></code>: a boolean indicating whether the record’s name was
specified by the TableGen input (if it is <code class="docutils literal notranslate"><span class="pre">false</span></code>), or invented by
TableGen itself (if <code class="docutils literal notranslate"><span class="pre">true</span></code>).</p></li>
</ul>
<p>For each variable defined in a record, the <code class="docutils literal notranslate"><span class="pre">def</span></code> object for that
record also has a key for the variable name. The corresponding value
is a translation into JSON of the variable’s value, using the
conventions described below.</p>
<p>Some TableGen data types are translated directly into the
corresponding JSON type:</p>
<ul class="simple">
<li><p>A completely undefined value (e.g. for a variable declared without
initializer in some superclass of this record, and never initialized
by the record itself or any other superclass) is emitted as the JSON
<code class="docutils literal notranslate"><span class="pre">null</span></code> value.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">int</span></code> and <code class="docutils literal notranslate"><span class="pre">bit</span></code> values are emitted as numbers. Note that
TableGen <code class="docutils literal notranslate"><span class="pre">int</span></code> values are capable of holding integers too large to
be exactly representable in IEEE double precision. The integer
literal in the JSON output will show the full exact integer value.
So if you need to retrieve large integers with full precision, you
should use a JSON reader capable of translating such literals back
into 64-bit integers without losing precision, such as Python’s
standard <code class="docutils literal notranslate"><span class="pre">json</span></code> module.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">string</span></code> and <code class="docutils literal notranslate"><span class="pre">code</span></code> values are emitted as JSON strings.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">list<T></span></code> values, for any element type <code class="docutils literal notranslate"><span class="pre">T</span></code>, are emitted as JSON
arrays. Each element of the array is represented in turn using these
same conventions.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">bits</span></code> values are also emitted as arrays. A <code class="docutils literal notranslate"><span class="pre">bits</span></code> array is
ordered from least-significant bit to most-significant. So the
element with index <code class="docutils literal notranslate"><span class="pre">i</span></code> corresponds to the bit described as
<code class="docutils literal notranslate"><span class="pre">x{i}</span></code> in TableGen source. However, note that this means that
scripting languages are likely to <em>display</em> the array in the
opposite order from the way it appears in the TableGen source or in
the diagnostic <code class="docutils literal notranslate"><span class="pre">-print-records</span></code> output.</p></li>
</ul>
<p>All other TableGen value types are emitted as a JSON object,
containing two standard fields: <code class="docutils literal notranslate"><span class="pre">kind</span></code> is a discriminator describing
which kind of value the object represents, and <code class="docutils literal notranslate"><span class="pre">printable</span></code> is a
string giving the same representation of the value that would appear
in <code class="docutils literal notranslate"><span class="pre">-print-records</span></code>.</p>
<ul class="simple">
<li><p>A reference to a <code class="docutils literal notranslate"><span class="pre">def</span></code> object has <code class="docutils literal notranslate"><span class="pre">kind=="def"</span></code>, and has an
extra field <code class="docutils literal notranslate"><span class="pre">def</span></code> giving the name of the object referred to.</p></li>
<li><p>A reference to another variable in the same record has
<code class="docutils literal notranslate"><span class="pre">kind=="var"</span></code>, and has an extra field <code class="docutils literal notranslate"><span class="pre">var</span></code> giving the name of
the variable referred to.</p></li>
<li><p>A reference to a specific bit of a <code class="docutils literal notranslate"><span class="pre">bits</span></code>-typed variable in the
same record has <code class="docutils literal notranslate"><span class="pre">kind=="varbit"</span></code>, and has two extra fields:
<code class="docutils literal notranslate"><span class="pre">var</span></code> gives the name of the variable referred to, and <code class="docutils literal notranslate"><span class="pre">index</span></code>
gives the index of the bit.</p></li>
<li><p>A value of type <code class="docutils literal notranslate"><span class="pre">dag</span></code> has <code class="docutils literal notranslate"><span class="pre">kind=="dag"</span></code>, and has two extra
fields. <code class="docutils literal notranslate"><span class="pre">operator</span></code> gives the initial value after the opening
parenthesis of the dag initializer; <code class="docutils literal notranslate"><span class="pre">args</span></code> is an array giving the
following arguments. The elements of <code class="docutils literal notranslate"><span class="pre">args</span></code> are arrays of length
2, giving the value of each argument followed by its colon-suffixed
name (if any). For example, in the JSON representation of the dag
value <code class="docutils literal notranslate"><span class="pre">(Op</span> <span class="pre">22,</span> <span class="pre">"hello":$foo)</span></code> (assuming that <code class="docutils literal notranslate"><span class="pre">Op</span></code> is the name of
a record defined elsewhere with a <code class="docutils literal notranslate"><span class="pre">def</span></code> statement):</p>
<ul>
<li><p><code class="docutils literal notranslate"><span class="pre">operator</span></code> will be an object in which <code class="docutils literal notranslate"><span class="pre">kind=="def"</span></code> and
<code class="docutils literal notranslate"><span class="pre">def=="Op"</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">args</span></code> will be the array <code class="docutils literal notranslate"><span class="pre">[[22,</span> <span class="pre">null],</span> <span class="pre">["hello",</span> <span class="pre">"foo"]]</span></code>.</p></li>
</ul>
</li>
<li><p>If any other kind of value or complicated expression appears in the
output, it will have <code class="docutils literal notranslate"><span class="pre">kind=="complex"</span></code>, and no additional fields.
These values are not expected to be needed by backends. The standard
<code class="docutils literal notranslate"><span class="pre">printable</span></code> field can be used to extract a representation of them
in TableGen source syntax if necessary.</p></li>
</ul>
</div>
<div class="section" id="searchabletables-reference">
<h3><a class="toc-backref" href="#id55">SearchableTables Reference</a><a class="headerlink" href="#searchabletables-reference" title="Permalink to this headline">¶</a></h3>
<p>A TableGen include file, <code class="docutils literal notranslate"><span class="pre">SearchableTable.td</span></code>, provides classes for
generating C++ searchable tables. These tables are described in the
following sections. To generate the C++ code, run <code class="docutils literal notranslate"><span class="pre">llvm-tblgen</span></code> with the
<code class="docutils literal notranslate"><span class="pre">--gen-searchable-tables</span></code> option, which invokes the backend that generates
the tables from the records you provide.</p>
<p>Each of the data structures generated for searchable tables is guarded by an
<code class="docutils literal notranslate"><span class="pre">#ifdef</span></code>. This allows you to include the generated <code class="docutils literal notranslate"><span class="pre">.inc</span></code> file and select only
certain data structures for inclusion. The examples below show the macro
names used in these guards.</p>
<div class="section" id="generic-enumerated-types">
<h4><a class="toc-backref" href="#id56">Generic Enumerated Types</a><a class="headerlink" href="#generic-enumerated-types" title="Permalink to this headline">¶</a></h4>
<p>The <code class="docutils literal notranslate"><span class="pre">GenericEnum</span></code> class makes it easy to define a C++ enumerated type and
the enumerated <em>elements</em> of that type. To define the type, define a record
whose parent class is <code class="docutils literal notranslate"><span class="pre">GenericEnum</span></code> and whose name is the desired enum
type. This class provides three fields, which you can set in the record
using the <code class="docutils literal notranslate"><span class="pre">let</span></code> statement.</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">string</span> <span class="pre">FilterClass</span></code>. The enum type will have one element for each record
that derives from this class. These records are collected to assemble the
complete set of elements.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">string</span> <span class="pre">NameField</span></code>. The name of a field <em>in the collected records</em> that specifies
the name of the element. If a record has no such field, the record’s
name will be used.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">string</span> <span class="pre">ValueField</span></code>. The name of a field <em>in the collected records</em> that
specifies the numerical value of the element. If a record has no such
field, it will be assigned an integer value. Values are assigned in
alphabetical order starting with 0.</p></li>
</ul>
<p>Here is an example where the values of the elements are specified
explicitly, as a template argument to the <code class="docutils literal notranslate"><span class="pre">BEntry</span></code> class. The resulting
C++ code is shown.</p>
<div class="highlight-text notranslate"><div class="highlight"><pre><span></span>def BValues : GenericEnum {
let FilterClass = "BEntry";
let NameField = "Name";
let ValueField = "Encoding";
}
class BEntry<bits<16> enc> {
string Name = NAME;
bits<16> Encoding = enc;
}
def BFoo : BEntry<0xac>;
def BBar : BEntry<0x14>;
def BZoo : BEntry<0x80>;
def BSnork : BEntry<0x4c>;
</pre></div>
</div>
<div class="highlight-text notranslate"><div class="highlight"><pre><span></span>#ifdef GET_BValues_DECL
enum BValues {
BBar = 20,
BFoo = 172,
BSnork = 76,
BZoo = 128,
};
#endif
</pre></div>
</div>
<p>In the following example, the values of the elements are assigned
automatically. Note that values are assigned from 0, in alphabetical order
by element name.</p>
<div class="highlight-text notranslate"><div class="highlight"><pre><span></span>def CEnum : GenericEnum {
let FilterClass = "CEnum";
}
class CEnum;
def CFoo : CEnum;
def CBar : CEnum;
def CBaz : CEnum;
</pre></div>
</div>
<div class="highlight-text notranslate"><div class="highlight"><pre><span></span>#ifdef GET_CEnum_DECL
enum CEnum {
CBar = 0,
CBaz = 1,
CFoo = 2,
};
#endif
</pre></div>
</div>
</div>
<div class="section" id="generic-tables">
<h4><a class="toc-backref" href="#id57">Generic Tables</a><a class="headerlink" href="#generic-tables" title="Permalink to this headline">¶</a></h4>
<p>The <code class="docutils literal notranslate"><span class="pre">GenericTable</span></code> class is used to define a searchable generic table.
TableGen produces C++ code to define the table entries and also produces
the declaration and definition of a function to search the table based on a
primary key. To define the table, define a record whose parent class is
<code class="docutils literal notranslate"><span class="pre">GenericTable</span></code> and whose name is the name of the global table of entries.
This class provides six fields.</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">string</span> <span class="pre">FilterClass</span></code>. The table will have one entry for each record
that derives from this class.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">string</span> <span class="pre">CppTypeName</span></code>. The name of the C++ struct/class type of the
table that holds the entries. If unspecified, the <code class="docutils literal notranslate"><span class="pre">FilterClass</span></code> name is
used.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">list<string></span> <span class="pre">Fields</span></code>. A list of the names of the fields <em>in the
collected records</em> that contain the data for the table entries. The order of
this list determines the order of the values in the C++ initializers. See
below for information about the types of these fields.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">list<string></span> <span class="pre">PrimaryKey</span></code>. The list of fields that make up the
primary key.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">string</span> <span class="pre">PrimaryKeyName</span></code>. The name of the generated C++ function
that performs a lookup on the primary key.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">bit</span> <span class="pre">PrimaryKeyEarlyOut</span></code>. See the third example below.</p></li>
</ul>
<p>TableGen attempts to deduce the type of each of the table fields so that it
can format the C++ initializers in the emitted table. It can deduce <code class="docutils literal notranslate"><span class="pre">bit</span></code>,
<code class="docutils literal notranslate"><span class="pre">bits<n></span></code>, <code class="docutils literal notranslate"><span class="pre">string</span></code>, <code class="docutils literal notranslate"><span class="pre">Intrinsic</span></code>, and <code class="docutils literal notranslate"><span class="pre">Instruction</span></code>. These can be
used in the primary key. Any other field types must be specified
explicitly; this is done as shown in the second example below. Such fields
cannot be used in the primary key.</p>
<p>One special case of the field type has to do with code. Arbitrary code is
represented by a string, but has to be emitted as a C++ initializer without
quotes. If the code field was defined using a code literal (<code class="docutils literal notranslate"><span class="pre">[{...}]</span></code>),
then TableGen will know to emit it without quotes. However, if it was
defined using a string literal or complex string expression, then TableGen
will not know. In this case, you can force TableGen to treat the field as
code by including the following line in the <code class="docutils literal notranslate"><span class="pre">GenericTable</span></code> record, where
<em>xxx</em> is the code field name.</p>
<div class="highlight-text notranslate"><div class="highlight"><pre><span></span>string TypeOf_xxx = "code";
</pre></div>
</div>
<p>Here is an example where TableGen can deduce the field types. Note that the
table entry records are anonymous; the names of entry records are
irrelevant.</p>
<div class="highlight-text notranslate"><div class="highlight"><pre><span></span>def ATable : GenericTable {
let FilterClass = "AEntry";
let Fields = ["Str", "Val1", "Val2"];
let PrimaryKey = ["Val1", "Val2"];
let PrimaryKeyName = "lookupATableByValues";
}
class AEntry<string str, int val1, int val2> {
string Str = str;
bits<8> Val1 = val1;
bits<10> Val2 = val2;
}
def : AEntry<"Bob", 5, 3>;
def : AEntry<"Carol", 2, 6>;
def : AEntry<"Ted", 4, 4>;
def : AEntry<"Alice", 4, 5>;
def : AEntry<"Costa", 2, 1>;
</pre></div>
</div>
<p>Here is the generated C++ code. The declaration of <code class="docutils literal notranslate"><span class="pre">lookupATableByValues</span></code>
is guarded by <code class="docutils literal notranslate"><span class="pre">GET_ATable_DECL</span></code>, while the definitions are guarded by
<code class="docutils literal notranslate"><span class="pre">GET_ATable_IMPL</span></code>.</p>
<div class="highlight-text notranslate"><div class="highlight"><pre><span></span>#ifdef GET_ATable_DECL
const AEntry *lookupATableByValues(uint8_t Val1, uint16_t Val2);
#endif
#ifdef GET_ATable_IMPL
constexpr AEntry ATable[] = {
{ "Costa", 0x2, 0x1 }, // 0
{ "Carol", 0x2, 0x6 }, // 1
{ "Ted", 0x4, 0x4 }, // 2
{ "Alice", 0x4, 0x5 }, // 3
{ "Bob", 0x5, 0x3 }, // 4
};
const AEntry *lookupATableByValues(uint8_t Val1, uint16_t Val2) {
struct KeyType {
uint8_t Val1;
uint16_t Val2;
};
KeyType Key = { Val1, Val2 };
auto Table = makeArrayRef(ATable);
auto Idx = std::lower_bound(Table.begin(), Table.end(), Key,
[](const AEntry &LHS, const KeyType &RHS) {
if (LHS.Val1 < RHS.Val1)
return true;
if (LHS.Val1 > RHS.Val1)
return false;
if (LHS.Val2 < RHS.Val2)
return true;
if (LHS.Val2 > RHS.Val2)
return false;
return false;
});
if (Idx == Table.end() ||
Key.Val1 != Idx->Val1 ||
Key.Val2 != Idx->Val2)
return nullptr;
return &*Idx;
}
#endif
</pre></div>
</div>
<p>The table entries in <code class="docutils literal notranslate"><span class="pre">ATable</span></code> are sorted in order by <code class="docutils literal notranslate"><span class="pre">Val1</span></code>, and within
each of those values, by <code class="docutils literal notranslate"><span class="pre">Val2</span></code>. This allows a binary search of the table,
which is performed in the lookup function by <code class="docutils literal notranslate"><span class="pre">std::lower_bound</span></code>. The
lookup function returns a reference to the found table entry, or the null
pointer if no entry is found.</p>
<p>This example includes a field whose type TableGen cannot deduce. The <code class="docutils literal notranslate"><span class="pre">Kind</span></code>
field uses the enumerated type <code class="docutils literal notranslate"><span class="pre">CEnum</span></code> defined above. To inform TableGen
of the type, the record derived from <code class="docutils literal notranslate"><span class="pre">GenericTable</span></code> must include a string field
named <code class="docutils literal notranslate"><span class="pre">TypeOf_</span></code><em>field</em>, where <em>field</em> is the name of the field whose type
is required.</p>
<div class="highlight-text notranslate"><div class="highlight"><pre><span></span>def CTable : GenericTable {
let FilterClass = "CEntry";
let Fields = ["Name", "Kind", "Encoding"];
string TypeOf_Kind = "CEnum";
let PrimaryKey = ["Encoding"];
let PrimaryKeyName = "lookupCEntryByEncoding";
}
class CEntry<string name, CEnum kind, int enc> {
string Name = name;
CEnum Kind = kind;
bits<16> Encoding = enc;
}
def : CEntry<"Apple", CFoo, 10>;
def : CEntry<"Pear", CBaz, 15>;
def : CEntry<"Apple", CBar, 13>;
</pre></div>
</div>
<p>Here is the generated C++ code.</p>
<div class="highlight-text notranslate"><div class="highlight"><pre><span></span>#ifdef GET_CTable_DECL
const CEntry *lookupCEntryByEncoding(uint16_t Encoding);
#endif
#ifdef GET_CTable_IMPL
constexpr CEntry CTable[] = {
{ "Apple", CFoo, 0xA }, // 0
{ "Apple", CBar, 0xD }, // 1
{ "Pear", CBaz, 0xF }, // 2
};
const CEntry *lookupCEntryByEncoding(uint16_t Encoding) {
struct KeyType {
uint16_t Encoding;
};
KeyType Key = { Encoding };
auto Table = makeArrayRef(CTable);
auto Idx = std::lower_bound(Table.begin(), Table.end(), Key,
[](const CEntry &LHS, const KeyType &RHS) {
if (LHS.Encoding < RHS.Encoding)
return true;
if (LHS.Encoding > RHS.Encoding)
return false;
return false;
});
if (Idx == Table.end() ||
Key.Encoding != Idx->Encoding)
return nullptr;
return &*Idx;
}
</pre></div>
</div>
<p>The <code class="docutils literal notranslate"><span class="pre">PrimaryKeyEarlyOut</span></code> field, when set to 1, modifies the lookup
function so that it tests the first field of the primary key to determine
whether it is within the range of the collected records’ primary keys. If
not, the function returns the null pointer without performing the binary
search. This is useful for tables that provide data for only some of the
elements of a larger enum-based space. The first field of the primary key
must be an integral type; it cannot be a string.</p>
<p>Adding <code class="docutils literal notranslate"><span class="pre">let</span> <span class="pre">PrimaryKeyEarlyOut</span> <span class="pre">=</span> <span class="pre">1</span></code> to the <code class="docutils literal notranslate"><span class="pre">ATable</span></code> above:</p>
<div class="highlight-text notranslate"><div class="highlight"><pre><span></span>def ATable : GenericTable {
let FilterClass = "AEntry";
let Fields = ["Str", "Val1", "Val2"];
let PrimaryKey = ["Val1", "Val2"];
let PrimaryKeyName = "lookupATableByValues";
let PrimaryKeyEarlyOut = 1;
}
</pre></div>
</div>
<p>causes the lookup function to change as follows:</p>
<div class="highlight-text notranslate"><div class="highlight"><pre><span></span>const AEntry *lookupATableByValues(uint8_t Val1, uint16_t Val2) {
if ((Val1 < 0x2) ||
(Val1 > 0x5))
return nullptr;
struct KeyType {
...
</pre></div>
</div>
</div>
<div class="section" id="search-indexes">
<h4><a class="toc-backref" href="#id58">Search Indexes</a><a class="headerlink" href="#search-indexes" title="Permalink to this headline">¶</a></h4>
<p>The <code class="docutils literal notranslate"><span class="pre">SearchIndex</span></code> class is used to define additional lookup functions for
generic tables. To define an additional function, define a record whose parent
class is <code class="docutils literal notranslate"><span class="pre">SearchIndex</span></code> and whose name is the name of the desired lookup
function. This class provides three fields.</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">GenericTable</span> <span class="pre">Table</span></code>. The name of the table that is to receive another
lookup function.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">list<string></span> <span class="pre">Key</span></code>. The list of fields that make up the secondary key.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">bit</span> <span class="pre">EarlyOut</span></code>. See the third example in <a class="reference internal" href="#generic-tables">Generic Tables</a>.</p></li>
</ul>
<p>Here is an example of a secondary key added to the <code class="docutils literal notranslate"><span class="pre">CTable</span></code> above. The
generated function looks up entries based on the <code class="docutils literal notranslate"><span class="pre">Name</span></code> and <code class="docutils literal notranslate"><span class="pre">Kind</span></code> fields.</p>
<div class="highlight-text notranslate"><div class="highlight"><pre><span></span>def lookupCEntry : SearchIndex {
let Table = CTable;
let Key = ["Name", "Kind"];
}
</pre></div>
</div>
<p>This use of <code class="docutils literal notranslate"><span class="pre">SearchIndex</span></code> generates the following additional C++ code.</p>
<div class="highlight-text notranslate"><div class="highlight"><pre><span></span>const CEntry *lookupCEntry(StringRef Name, unsigned Kind);
...
const CEntry *lookupCEntryByName(StringRef Name, unsigned Kind) {
struct IndexType {
const char * Name;
unsigned Kind;
unsigned _index;
};
static const struct IndexType Index[] = {
{ "APPLE", CBar, 1 },
{ "APPLE", CFoo, 0 },
{ "PEAR", CBaz, 2 },
};
struct KeyType {
std::string Name;
unsigned Kind;
};
KeyType Key = { Name.upper(), Kind };
auto Table = makeArrayRef(Index);
auto Idx = std::lower_bound(Table.begin(), Table.end(), Key,
[](const IndexType &LHS, const KeyType &RHS) {
int CmpName = StringRef(LHS.Name).compare(RHS.Name);
if (CmpName < 0) return true;
if (CmpName > 0) return false;
if ((unsigned)LHS.Kind < (unsigned)RHS.Kind)
return true;
if ((unsigned)LHS.Kind > (unsigned)RHS.Kind)
return false;
return false;
});
if (Idx == Table.end() ||
Key.Name != Idx->Name ||
Key.Kind != Idx->Kind)
return nullptr;
return &CTable[Idx->_index];
}
</pre></div>
</div>
</div>
</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="BackGuide.html" title="1 TableGen Backend Developer’s Guide"
>next</a> |</li>
<li class="right" >
<a href="index.html" title="TableGen Overview"
>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="../UserGuides.html" >User Guides</a> »</li>
<li class="nav-item nav-item-2"><a href="index.html" >TableGen Overview</a> »</li>
<li class="nav-item nav-item-this"><a href="">TableGen BackEnds</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>
|