1===================================
2TableGen Backend Developer's Guide
3===================================
4
5.. sectnum::
6
7.. contents::
8   :local:
9
10Introduction
11============
12
13The purpose of TableGen is to generate complex output files based on
14information from source files that are significantly easier to code than the
15output files would be, and also easier to maintain and modify over time. The
16information is coded in a declarative style involving classes and records,
17which are then processed by TableGen. The internalized records are passed on
18to various backends, which extract information from a subset of the records
19and generate an output file. These output files are typically ``.inc`` files
20for C++, but may be any type of file that the backend developer needs.
21
22This document is a guide to writing a backend for TableGen. It is not a
23complete reference manual, but rather a guide to using the facilities
24provided by TableGen for the backends. For a complete reference to the
25various data structures and functions involved, see the primary TableGen
26header file (``record.h``) and/or the Doxygen documentation.
27
28This document assumes that you have read the :doc:`TableGen Programmer's
29Reference <./ProgRef>`, which provides a detailed reference for coding
30TableGen source files. This document and the data structure comments will be
31improved over time.
32
33Data Structures
34===============
35
36The following sections describe the data structures that contain the classes
37and records that are collected from the TableGen source files by the
38TableGen parser. Note that the term *class* refers to an abstract record
39class, while the term *record* refers to a concrete record.
40
41Unless otherwise noted, functions associated with classes are instance
42functions.
43
44``RecordKeeper``
45----------------
46
47An instance of the ``RecordKeeper`` class acts as the container for all the
48classes and records parsed and collected by TableGen. The ``RecordKeeper``
49instance is passed to the backend when it is invoked by TableGen. This class
50is usually abbreviated ``RK``.
51
52There are two maps in the recordkeeper, one for classes and one for records
53(the latter often referred to as *defs*). Each map maps the class or record
54name to an instance of the ``Record`` class (see `Record`_), which contains
55all the information about that class or record.
56
57In addition to the two maps, the ``RecordKeeper`` instance contains:
58
59* A map that maps the names of global variables to their values.
60  Global variables are defined in TableGen files with outer
61  ``defvar`` statements.
62
63* A counter for naming anonymous records.
64
65The ``RecordKeeper`` class provides a few useful functions.
66
67* Functions to get the complete class and record maps.
68
69* Functions to get a subset of the records based on their parent classes.
70
71* Functions to get individual classes, records, and globals, by name.
72
73A ``RecordKeeper`` instance can be printed to an output stream with the ``<<``
74operator.
75
76``Record``
77----------
78
79Each class or record built by TableGen is represented by an instance of
80the ``Record`` class. The ``RecordKeeper`` instance contains one map for the
81classes and one for the records. The primary data members of a record are
82the record name, the vector of field names and their values, and the vector of
83superclasses of the record.
84
85The record name is stored as a pointer to an ``Init`` (see `Init`_), which
86is a class whose instances hold TableGen values (sometimes referred to as
87*initializers*). The field names and values are stored in a vector of
88``RecordVal`` instances (see `RecordVal`_), each of which contains both the
89field name and its value. The superclass vector contains a sequence of
90pairs, with each pair including the superclass record and its source
91file location.
92
93In addition to those members, a ``Record`` instance contains:
94
95* A vector of source file locations that includes the record definition
96  itself, plus the locations of any multiclasses involved in its definition.
97
98* For a class record, a vector of the class's template arguments.
99
100* An instance of ``DefInit`` (see `DefInit`_) corresponding to this record.
101
102* A unique record ID.
103
104* A boolean that specifies whether this is a class definition.
105
106* A boolean that specifies whether this is an anonymous record.
107
108The ``Record`` class provides many useful functions.
109
110* Functions to get the record name, fields, source file locations,
111  template arguments, and unique ID.
112
113* Functions to get all the record's superclasses or just its direct
114  superclasses.
115
116* Functions to get a particular field value by specifying its name in various
117  forms, and returning its value in various forms
118  (see `Getting Record Names and Fields`_).
119
120* Boolean functions to check the various attributes of the record.
121
122A ``Record`` instance can be printed to an output stream with the ``<<``
123operator.
124
125
126``RecordVal``
127-------------
128
129Each field of a record is stored in an instance of the ``RecordVal`` class.
130The ``Record`` instance includes a vector of these value instances. A
131``RecordVal`` instance contains the name of the field, stored in an ``Init``
132instance. It also contains the value of the field, likewise stored in an
133``Init``. (A better name for this class might be ``RecordField``.)
134
135In addition to those primary members, the ``RecordVal`` has other data members.
136
137* The source file location of the field definition.
138
139* The type of the field, stored as an instance
140  of the ``RecTy`` class (see `RecTy`_).
141
142The ``RecordVal`` class provides some useful functions.
143
144* Functions to get the name of the field in various forms.
145
146* A function to get the type of the field.
147
148* A function to get the value of the field.
149
150* A function to get the source file location.
151
152Note that field values are more easily obtained directly from the ``Record``
153instance (see `Record`_).
154
155A ``RecordVal`` instance can be printed to an output stream with the ``<<``
156operator.
157
158``RecTy``
159---------
160
161The ``RecTy`` class is used to represent the types of field values. It is
162the base class for a series of subclasses, one for each of the
163available field types. The ``RecTy`` class has one data member that is an
164enumerated type specifying the specific type of field value. (A better
165name for this class might be ``FieldTy``.)
166
167The ``RecTy`` class provides a few useful functions.
168
169* A virtual function to get the type name as a string.
170
171* A virtual function to check whether all the values of this type can
172  be converted to another given type.
173
174* A virtual function to check whether this type is a subtype of
175  another given type.
176
177* A function to get the corresponding ``list``
178  type for lists with elements of this type. For example, the function
179  returns the ``list<int>`` type when called with the ``int`` type.
180
181The subclasses that inherit from ``RecTy`` are
182``BitRecTy``,
183``BitsRecTy``,
184``CodeRecTy``,
185``DagRecTy``,
186``IntRecTy``,
187``ListRecTy``,
188``RecordRecTy``, and
189``StringRecTy``.
190Some of these classes have additional members that
191are described in the following subsections.
192
193*All* of the classes derived from ``RecTy`` provide the ``get()`` function.
194It returns an instance of ``Recty`` corresponding to the derived class.
195Some of the ``get()`` functions require an argument to
196specify which particular variant of the type is desired. These arguments are
197described in the following subsections.
198
199A ``RecTy`` instance can be printed to an output stream with the ``<<``
200operator.
201
202.. warning::
203  It is not specified whether there is a single ``RecTy`` instance of a
204  particular type or multiple instances.
205
206
207``BitsRecTy``
208~~~~~~~~~~~~~
209
210This class includes a data member with the size of the ``bits`` value and a
211function to get that size.
212
213The ``get()`` function takes the length of the sequence, *n*, and returns the
214``BitsRecTy`` type corresponding to ``bits<``\ *n*\ ``>``.
215
216``ListRecTy``
217~~~~~~~~~~~~~
218
219This class includes a data member that specifies the type of the list's
220elements and a function to get that type.
221
222The ``get()`` function takes the ``RecTy`` *type* of the list members and
223returns the ``ListRecTy`` type corresponding to ``list<``\ *type*\ ``>``.
224
225
226``RecordRecTy``
227~~~~~~~~~~~~~~~
228
229This class includes data members that contain the list of parent classes of
230this record. It also provides a function to obtain the array of classes and
231two functions to get the iterator ``begin()`` and ``end()`` values. The
232class defines a type for the return values of the latter two functions.
233
234.. code-block:: text
235
236  using const_record_iterator = Record * const *;
237
238The ``get()`` function takes an ``ArrayRef`` of pointers to the ``Record``
239instances of the *direct* superclasses of the record and returns the ``RecordRecTy``
240corresponding to the record inheriting from those superclasses.
241
242``Init``
243--------
244
245The ``Init`` class is used to represent TableGen values.  The name derives
246from *initialization value*. This class should not be confused with the
247``RecordVal`` class, which represents record fields, both their names and
248values. The ``Init`` class is the base class for a series of subclasses, one
249for each of the available value types. The primary data member of ``Init``
250is an enumerated type that represents the specific type of the value.
251
252The ``Init`` class provides a few useful functions.
253
254* A function to get the type enumerator.
255
256* A boolean virtual function to determine whether a value is completely
257  specified; that is, has no uninitialized subvalues.
258
259* Virtual functions to get the value as a string.
260
261* Virtual functions to cast the value to other types, implement the bit
262  range feature of TableGen, and implement the list slice feature.
263
264* A virtual function to get a particular bit of the value.
265
266The subclasses that inherit directly from ``Init`` are
267``UnsetInit`` and ``TypedInit``.
268
269An ``Init`` instance can be printed to an output stream with the ``<<``
270operator.
271
272.. warning::
273  It is not specified whether two separate initialization values with
274  the same underlying type and value (e.g., two strings with the value
275  "Hello") are represented by two ``Init``\ s or share the same ``Init``.
276
277``UnsetInit``
278~~~~~~~~~~~~~
279
280This class, a subclass of ``Init``, represents the unset (uninitialized)
281value. The static function ``get()`` can be used to obtain the singleton
282``Init`` of this type.
283
284
285``TypedInit``
286~~~~~~~~~~~~~
287
288This class, a subclass of ``Init``, acts as the parent class of the classes
289that represent specific value types (except for the unset value). These
290classes include ``BitInit``, ``BitsInit``, ``CodeInit``, ``DagInit``,
291``DefInit``, ``IntInit``, ``ListInit``, and ``StringInit``. (There are
292additional derived types used by the TableGen parser.)
293
294This class includes a data member that specifies the ``RecTy`` type of the
295value. It provides a function to get that ``RecTy`` type.
296
297``BitInit``
298~~~~~~~~~~~
299
300The ``BitInit`` class is a subclass of ``TypedInit``. Its instances
301represent the possible values of a bit: 0 or 1. It includes a data member
302that contains the bit.
303
304*All* of the classes derived from ``TypedInit`` provide the following functions.
305
306* A static function named ``get()`` that returns an ``Init`` representing
307  the specified value(s). In the case of ``BitInit``, ``get(true)`` returns
308  an instance of ``BitInit`` representing true, while ``get(false)`` returns
309  an instance
310  representing false. As noted above, it is not specified whether there
311  is exactly one or more than one ``BitInit`` representing true (or false).
312
313* A function named ``GetValue()`` that returns the value of the instance
314  in a more direct form, in this case as a ``bool``.
315
316``BitsInit``
317~~~~~~~~~~~~
318
319The ``BitsInit`` class is a subclass of ``TypedInit``. Its instances
320represent sequences of bits, from high-order to low-order. It includes a
321data member with the length of the sequence and a vector of pointers to
322``Init`` instances, one per bit.
323
324The class provides the usual ``get()`` function. It does not provide the
325``getValue()`` function.
326
327The class provides the following additional functions.
328
329* A function to get the number of bits in the sequence.
330
331* A function that gets a bit specified by an integer index.
332
333``CodeInit``
334~~~~~~~~~~~~
335
336The ``CodeInit`` class is a subclass of ``TypedInit``. Its instances
337represent arbitrary-length strings produced from ``code`` literals in the
338TableGen files. It includes a data member that contains a ``StringRef`` of
339the value. It also includes a data member specifying the source code
340location of the code string.
341
342The class provides the usual ``get()`` and ``getValue()`` functions. The
343latter function returns the ``StringRef``.
344
345The ``getLoc()`` function returns the source code location.
346
347
348``DagInit``
349~~~~~~~~~~~
350
351The ``DagInit`` class is a subclass of ``TypedInit``. Its instances
352represent the possible direct acyclic graphs (``dag``).
353
354The class includes a pointer to an ``Init`` for the DAG operator and a
355pointer to a ``StringInit`` for the operator name. It includes the count of
356DAG operands and the count of operand names. Finally, it includes a vector of
357pointers to ``Init`` instances for the operands and another to
358``StringInit`` instances for the operand names.
359(The DAG operands are also referred to as *arguments*.)
360
361The class provides two forms of the usual ``get()`` function. It does not
362provide the usual ``getValue()`` function.
363
364The class provides many additional functions:
365
366* Functions to get the operator in various forms and to get the
367  operator name in various forms.
368
369* Functions to determine whether there are any operands and to get the
370  number of operands.
371
372* Functions to the get the operands, both individually and together.
373
374* Functions to determine whether there are any names and to
375  get the number of names
376
377* Functions to the get the names, both individually and together.
378
379* Functions to get the operand iterator ``begin()`` and ``end()`` values.
380
381* Functions to get the name iterator ``begin()`` and ``end()`` values.
382
383The class defines two types for the return values of the operand and name
384iterators.
385
386.. code-block:: text
387
388  using const_arg_iterator = SmallVectorImpl<Init*>::const_iterator;
389  using const_name_iterator = SmallVectorImpl<StringInit*>::const_iterator;
390
391
392``DefInit``
393~~~~~~~~~~~
394
395The ``DefInit`` class is a subclass of ``TypedInit``. Its instances
396represent the records that were collected by TableGen. It includes a data
397member that is a pointer to the record's ``Record`` instance.
398
399The class provides the usual ``get()`` function. It does not provide
400``getValue()``. Instead, it provides ``getDef()``, which returns the
401``Record`` instance.
402
403``IntInit``
404~~~~~~~~~~~
405
406The ``IntInit`` class is a subclass of ``TypedInit``. Its instances
407represent the possible values of a 64-bit integer. It includes a data member
408that contains the integer.
409
410The class provides the usual ``get()`` and ``getValue()`` functions. The
411latter function returns the integer as an ``int64_t``.
412
413The class also provides a function, ``getBit()``, to obtain a specified bit
414of the integer value.
415
416``ListInit``
417~~~~~~~~~~~~
418
419The ``ListInit`` class is a subclass of ``TypedInit``. Its instances
420represent lists of elements of some type. It includes a data member with the
421length of the list and a vector of pointers to ``Init`` instances, one per
422element.
423
424The class provides the usual ``get()`` and ``getValues()`` functions. The
425latter function returns an ``ArrayRef`` of the vector of pointers to ``Init``
426instances.
427
428The class provides these additional functions.
429
430* A function to get the element type.
431
432* Functions to get the length of the vector and to determine whether
433  it is empty.
434
435* Functions to get an element specified by an integer index and return
436  it in various forms.
437
438* Functions to get the iterator ``begin()`` and ``end()`` values. The
439  class defines a type for the return type of these two functions.
440
441.. code-block:: text
442
443  using const_iterator = Init *const *;
444
445
446``StringInit``
447~~~~~~~~~~~~~~
448
449The ``StringInit`` class is a subclass of ``TypedInit``. Its instances
450represent arbitrary-length strings. It includes a data member
451that contains a ``StringRef`` of the value.
452
453The class provides the usual ``get()`` and ``getValue()`` functions. The
454latter function returns the ``StringRef``.
455
456Creating a New Backend
457======================
458
459The following steps are required to create a new backend for TableGen.
460
461#. Invent a name for your backend C++ file, say ``GenAddressModes``.
462
463#. Write the new backend, using the file ``TableGenBackendSkeleton.cpp``
464   as a starting point.
465
466#. Determine which instance of TableGen requires the new backend. There is
467   one instance for Clang and another for LLVM. Or you may be building
468   your own instance.
469
470#. Modify the selected ``tablegen.cpp`` to include your new backend.
471
472  a. Add the name to the enumerated type ``ActionType``.
473
474  #. Add a keyword to the ``ActionType`` command option using the
475     ``clEnumValN()`` function.
476
477  #. Add a case to the ``switch`` statement in the *xxx*\ ``TableGenMain()``
478     function. It should invoke the "main function" of your backend, which
479     in this case, according to convention, is named ``EmitAddressModes``.
480
4815. Add a declaration of your "main function" to the corresponding
482   ``TableGenBackends.h`` header file.
483
484#. Add your backend C++ file to the appropriate ``CMakeLists.txt`` file so
485   that it will be built.
486
487#. Add your C++ file to the system.
488
489The Backend Skeleton
490====================
491
492The file ``TableGenBackendSkeleton.cpp`` provides a skeleton C++ translation
493unit for writing a new TableGen backend. Here are a few notes on the file.
494
495* The list of includes is the minimal list required by most backends.
496
497* As with all LLVM C++ files, it has a ``using namespace llvm;`` statement.
498  It also has an anonymous namespace that contains all the file-specific
499  data structure definitions, along with the class embodying the emitter
500  data members and functions. Continuing with the ``GenAddressModes`` example,
501  this class is named ``AddressModesEmitter``.
502
503* The constructor for the emitter class accepts a ``RecordKeeper`` reference,
504  typically named ``RK``. The ``RecordKeeper`` reference is saved in a data
505  member so that records can be obtained from it. This data member is usually
506  named ``Records``.
507
508* One function is named ``run``. It is invoked by the backend's "main
509  function" to collect records and emit the output file. It accepts an instance
510  of the ``raw_ostream`` class, typically named ``OS``. The output file is
511  emitted by writing to this stream.
512
513* The ``run`` function should use the ``emitSourceFileHeader`` helper function
514  to include a standard header in the emitted file.
515
516* The only function in the ``llvm`` namespace is the backend "main function."
517  In this example, it is named ``EmitAddressModes``. It creates an instance
518  of the ``AddressModesEmitter`` class, passing the ``RecordKeeper``
519  instance, then invokes the ``run`` function, passing the ``raw_ostream``
520  instance.
521
522All the examples in the remainder of this document will assume the naming
523conventions used in the skeleton file.
524
525Getting Classes
526===============
527
528The ``RecordKeeper`` class provides two functions for getting the
529``Record`` instances for classes defined in the TableGen files.
530
531* ``getClasses()`` returns a ``RecordMap`` reference for all the classes.
532
533* ``getClass(``\ *name*\ ``)`` returns a ``Record`` reference for the named
534  class.
535
536If you need to iterate over all the class records:
537
538.. code-block:: text
539
540  for (auto ClassPair : Records.getClasses()) {
541    Record *ClassRec = ClassPair.second.get();
542    ...
543  }
544
545``ClassPair.second`` gets the class's ``unique_ptr``, then ``.get()`` gets the
546class ``Record`` itself.
547
548
549Getting Records
550===============
551
552The ``RecordKeeper`` class provides four functions for getting the
553``Record`` instances for concrete records defined in the TableGen files.
554
555* ``getDefs()`` returns a ``RecordMap`` reference for all the concrete
556  records.
557
558* ``getDef(``\ *name*\ ``)`` returns a ``Record`` reference for the named
559  concrete record.
560
561* ``getAllDerivedDefinitions(``\ *classname*\ ``)`` returns a vector of
562  ``Record`` references for the concrete records that derive from the
563  given class.
564
565* ``getAllDerivedDefinitions(``\ *classnames*\ ``)`` returns
566  a vector of ``Record`` references for the concrete records that derive from
567  *all* of the given classes.
568
569This statement obtains all the records that derive from the ``Attribute``
570class and iterates over them.
571
572.. code-block:: text
573
574  auto AttrRecords = Records.getAllDerivedDefinitions("Attribute");
575  for (Record *AttrRec : AttrRecords) {
576    ...
577  }
578
579Getting Record Names and Fields
580===============================
581
582As described above (see `Record`_), there are multiple functions that
583return the name of a record. One particularly useful one is
584``getNameInitAsString()``, which returns the name as a ``std::string``.
585
586There are also multiple functions that return the fields of a record. To
587obtain and iterate over all the fields:
588
589.. code-block:: text
590
591  for (const RecordVal &Field : SomeRec->getValues()) {
592    ...
593  }
594
595You will recall that ``RecordVal`` is the class whose instances contain
596information about the fields in records.
597
598The ``getValue()`` function returns the ``RecordVal`` instance for a field
599specified by name. There are multiple overloaded functions, some taking a
600``StringRef`` and others taking a ``const Init *``. Some functions return a
601``RecordVal *`` and others return a ``const RecordVal *``. If the field does
602not exist, a fatal error message is printed.
603
604More often than not, you are interested in the value of the field, not all
605the information in the ``RecordVal``. There is a large set of functions that
606take a field name in some form and return its value. One function,
607``getValueInit``, returns the value as an ``Init *``. Another function,
608``isValueUnset``, returns a boolean specifying whether the value is unset
609(uninitialized).
610
611Most of the functions return the value in some more useful form. For
612example:
613
614.. code-block:: text
615
616  std::vector<int64_t> RegCosts =
617      SomeRec->getValueAsListOfInts("RegCosts");
618
619The field ``RegCosts`` is assumed to be a list of integers. That list is
620returned as a ``std::vector`` of 64-bit integers. If the field is not a list
621of integers, a fatal error message is printed.
622
623Here is a function that returns a field value as a ``Record``, but returns
624null if the field does not exist.
625
626.. code-block:: text
627
628  if (Record *BaseRec = SomeRec->getValueAsOptionalDef(BaseFieldName)) {
629    ...
630  }
631
632The field is assumed to have another record as its value. That record is returned
633as a pointer to a ``Record``. If the field does not exist or is unset, the
634functions returns null.
635
636Getting Record Superclasses
637===========================
638
639The ``Record`` class provides a function to obtain the superclasses of a
640record. It is named ``getSuperClasses`` and returns an ``ArrayRef`` of an
641array of ``std::pair`` pairs. The superclasses are in post-order: the order
642in which the superclasses were visited while copying their fields into the
643record. Each pair consists of a pointer to the ``Record`` instance for a
644superclass record and an instance of the ``SMRange`` class. The range
645indicates the source file locations of the beginning and end of the class
646definition.
647
648This example obtains the superclasses of the ``Prototype`` record and then
649iterates over the pairs in the returned array.
650
651.. code-block:: text
652
653  ArrayRef<std::pair<Record *, SMRange>>
654      Superclasses = Prototype->getSuperClasses();
655  for (const auto &SuperPair : Superclasses) {
656    ...
657  }
658
659The ``Record`` class also provides a function, ``getDirectSuperClasses``, to
660append the *direct* superclasses of a record to a given vector of type
661``SmallVectorImpl<Record *>``.
662
663Emitting Text to the Output Stream
664==================================
665
666The ``run`` function is passed a ``raw_ostream`` to which it prints the
667output file. By convention, this stream is saved in the emitter class member
668named ``OS``, although some ``run`` functions are simple and just use the
669stream without saving it. The output can be produced by writing values
670directly to the output stream, or by using the ``std::format()`` or
671``llvm::formatv()`` functions.
672
673.. code-block:: text
674
675  OS << "#ifndef " << NodeName << "\n";
676
677  OS << format("0x%0*x, ", Digits, Value);
678
679Instances of the following classes can be printed using the ``<<`` operator:
680``RecordKeeper``,
681``Record``,
682``RecTy``,
683``RecordVal``, and
684``Init``.
685
686The helper function ``emitSourceFileHeader()`` prints the header comment
687that should be included at the top of every output file. A call to it is
688included in the skeleton backend file ``TableGenBackendSkeleton.cpp``.
689
690Printing Error Messages
691=======================
692
693TableGen records are often derived from multiple classes and also often
694defined through a sequence of multiclasses. Because of this, it can be
695difficult for backends to report clear error messages with accurate source
696file locations.  To make error reporting easier, five error reporting
697functions are provided, each with four overloads.
698
699* ``PrintWarning`` prints a message tagged as a warning.
700
701* ``PrintError`` prints a message tagged as an error.
702
703* ``PrintFatalError`` prints a message tagged as an error and then terminates.
704
705* ``PrintNote`` prints a note. It is often used after one of the previous
706  functions to provide more information.
707
708* ``PrintFatalNote`` prints a note and then terminates.
709
710Each of these five functions is overloaded four times.
711
712* ``PrintError(const Twine &Msg)``:
713  Prints the message with no source file location.
714
715* ``PrintError(ArrayRef<SMLoc> ErrorLoc, const Twine &Msg)``:
716  Prints the message followed by the specified source line,
717  along with a pointer to the item in error. The array of
718  source file locations is typically taken from a ``Record`` instance.
719
720* ``PrintError(const Record *Rec, const Twine &Msg)``:
721  Prints the message followed by the source line associated with the
722  specified record (see `Record`_).
723
724* ``PrintError(const RecordVal *RecVal, const Twine &Msg)``:
725  Prints the message followed by the source line associated with the
726  specified record field (see `RecordVal`_).
727
728Using these functions, the goal is to produce the most specific error report
729possible.
730
731Debugging Tools
732===============
733
734TableGen provides some tools to aid in debugging backends.
735
736The ``PrintRecords`` Backend
737----------------------------
738
739The TableGen command option ``--print-records`` invokes a simple backend
740that prints all the classes and records defined in the source files. This is
741the default backend option. The output looks like this:
742
743.. code-block:: text
744
745  ------------- Classes -----------------
746  ...
747  class XEntry<string XEntry:str = ?, int XEntry:val1 = ?> { // XBase
748    string Str = XEntry:str;
749    bits<8> Val1 = { !cast<bits<8>>(XEntry:val1){7}, ... };
750    bit Val3 = 1;
751  }
752  ...
753  ------------- Defs -----------------
754  def ATable {	// GenericTable
755    string FilterClass = "AEntry";
756    string CppTypeName = "AEntry";
757    list<string> Fields = ["Str", "Val1", "Val2"];
758    list<string> PrimaryKey = ["Val1", "Val2"];
759    string PrimaryKeyName = "lookupATableByValues";
760    bit PrimaryKeyEarlyOut = 0;
761  }
762  ...
763  def anonymous_0 {	// AEntry
764    string Str = "Bob";
765    bits<8> Val1 = { 0, 0, 0, 0, 0, 1, 0, 1 };
766    bits<10> Val2 = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 };
767  }
768
769Classes are shown with their template arguments, parent classes (following
770``//``), and fields. Records are shown with their parent classes and
771fields. Note that anonymous records are named ``anonymous_0``,
772``anonymous_1``, etc.
773
774The ``PrintDetailedRecords`` Backend
775------------------------------------
776
777The TableGen command option ``--print-detailed-records`` invokes a backend
778that prints all the global variables, classes, and records defined in the
779source files. The output looks like this.
780
781.. code-block:: text
782
783  DETAILED RECORDS for file llvm-project\llvm\lib\target\arc\arc.td
784
785  -------------------- Global Variables (5) --------------------
786
787  AMDGPUBufferIntrinsics = [int_amdgcn_buffer_load_format, ...
788  AMDGPUImageDimAtomicIntrinsics = [int_amdgcn_image_atomic_swap_1d, ...
789  ...
790  -------------------- Classes (758) --------------------
791
792  AMDGPUBufferLoad  |IntrinsicsAMDGPU.td:879|
793    Template args:
794      LLVMType AMDGPUBufferLoad:data_ty = llvm_any_ty  |IntrinsicsAMDGPU.td:879|
795    Superclasses: (SDPatternOperator) Intrinsic AMDGPURsrcIntrinsic
796    Fields:
797      list<SDNodeProperty> Properties = [SDNPMemOperand]  |Intrinsics.td:348|
798      string LLVMName = ""  |Intrinsics.td:343|
799  ...
800  -------------------- Records (12303) --------------------
801
802  AMDGPUSample_lz_o  |IntrinsicsAMDGPU.td:560|
803    Defm sequence: |IntrinsicsAMDGPU.td:584| |IntrinsicsAMDGPU.td:566|
804    Superclasses: AMDGPUSampleVariant
805    Fields:
806      string UpperCaseMod = "_LZ_O"  |IntrinsicsAMDGPU.td:542|
807      string LowerCaseMod = "_lz_o"  |IntrinsicsAMDGPU.td:543|
808  ...
809
810* Global variables defined with outer ``defvar`` statements are shown with
811  their values.
812
813* The classes are shown with their source location, template arguments,
814  superclasses, and fields.
815
816* The records are shown with their source location, ``defm`` sequence,
817  superclasses, and fields.
818
819Superclasses are shown in the order processed, with indirect superclasses in
820parentheses. Each field is shown with its value and the source location at
821which it was set.
822The ``defm`` sequence gives the locations of the ``defm`` statements that
823were involved in generating the record, in the order they were invoked.
824