1 ===============================
2 TableGen Programmer's Reference
3 ===============================
13 The purpose of TableGen is to generate complex output files based on
14 information from source files that are significantly easier to code than the
15 output files would be, and also easier to maintain and modify over time. The
16 information is coded in a declarative style involving classes and records,
17 which are then processed by TableGen. The internalized records are passed on
18 to various *backends*, which extract information from a subset of the records
19 and generate one or more output files. These output files are typically
20 ``.inc`` files for C++, but may be any type of file that the backend
23 This document describes the LLVM TableGen facility in detail. It is intended
24 for the programmer who is using TableGen to produce code for a project. If
25 you are looking for a simple overview, check out the :doc:`TableGen Overview
26 <./index>`. The various ``*-tblgen`` commands used to invoke TableGen are
27 described in :doc:`tblgen Family - Description to C++
28 Code<../CommandGuide/tblgen>`.
30 An example of a backend is ``RegisterInfo``, which generates the register
31 file information for a particular target machine, for use by the LLVM
32 target-independent code generator. See :doc:`TableGen Backends <./BackEnds>`
33 for a description of the LLVM TableGen backends, and :doc:`TableGen
34 Backend Developer's Guide <./BackGuide>` for a guide to writing a new
37 Here are a few of the things backends can do.
39 * Generate the register file information for a particular target machine.
41 * Generate the instruction definitions for a target.
43 * Generate the patterns that the code generator uses to match instructions
44 to intermediate representation (IR) nodes.
46 * Generate semantic attribute identifiers for Clang.
48 * Generate abstract syntax tree (AST) declaration node definitions for Clang.
50 * Generate AST statement node definitions for Clang.
56 TableGen source files contain two primary items: *abstract records* and
57 *concrete records*. In this and other TableGen documents, abstract records
58 are called *classes.* (These classes are different from C++ classes and do
59 not map onto them.) In addition, concrete records are usually just called
60 records, although sometimes the term *record* refers to both classes and
61 concrete records. The distinction should be clear in context.
63 Classes and concrete records have a unique *name*, either chosen by
64 the programmer or generated by TableGen. Associated with that name
65 is a list of *fields* with values and an optional list of *parent classes*
66 (sometimes called base or super classes). The fields are the primary data that
67 backends will process. Note that TableGen assigns no meanings to fields; the
68 meanings are entirely up to the backends and the programs that incorporate
69 the output of those backends.
73 The term "parent class" can refer to a class that is a parent of another
74 class, and also to a class from which a concrete record inherits. This
75 nonstandard use of the term arises because TableGen treats classes and
76 concrete records similarly.
78 A backend processes some subset of the concrete records built by the
79 TableGen parser and emits the output files. These files are usually C++
80 ``.inc`` files that are included by the programs that require the data in
81 those records. However, a backend can produce any type of output files. For
82 example, it could produce a data file containing messages tagged with
83 identifiers and substitution parameters. In a complex use case such as the
84 LLVM code generator, there can be many concrete records and some of them can
85 have an unexpectedly large number of fields, resulting in large output files.
87 In order to reduce the complexity of TableGen files, classes are used to
88 abstract out groups of record fields. For example, a few classes may
89 abstract the concept of a machine register file, while other classes may
90 abstract the instruction formats, and still others may abstract the
91 individual instructions. TableGen allows an arbitrary hierarchy of classes,
92 so that the abstract classes for two concepts can share a third superclass that
93 abstracts common "sub-concepts" from the two original concepts.
95 In order to make classes more useful, a concrete record (or another class)
96 can request a class as a parent class and pass *template arguments* to it.
97 These template arguments can be used in the fields of the parent class to
98 initialize them in a custom manner. That is, record or class ``A`` can
99 request parent class ``S`` with one set of template arguments, while record or class
100 ``B`` can request ``S`` with a different set of arguments. Without template
101 arguments, many more classes would be required, one for each combination of
102 the template arguments.
104 Both classes and concrete records can include fields that are uninitialized.
105 The uninitialized "value" is represented by a question mark (``?``). Classes
106 often have uninitialized fields that are expected to be filled in when those
107 classes are inherited by concrete records. Even so, some fields of concrete
108 records may remain uninitialized.
110 TableGen provides *multiclasses* to collect a group of record definitions in
111 one place. A multiclass is a sort of macro that can be "invoked" to define
112 multiple concrete records all at once. A multiclass can inherit from other
113 multiclasses, which means that the multiclass inherits all the definitions
114 from its parent multiclasses.
116 `Appendix C: Sample Record`_ illustrates a complex record in the Intel X86
117 target and the simple way in which it is defined.
122 TableGen source files are plain ASCII text files. The files can contain
123 statements, comments, and blank lines (see `Lexical Analysis`_). The standard file
124 extension for TableGen files is ``.td``.
126 TableGen files can grow quite large, so there is an include mechanism that
127 allows one file to include the content of another file (see `Include
128 Files`_). This allows large files to be broken up into smaller ones, and
129 also provides a simple library mechanism where multiple source files can
130 include the same library file.
132 TableGen supports a simple preprocessor that can be used to conditionalize
133 portions of ``.td`` files. See `Preprocessing Facilities`_ for more
139 The lexical and syntax notation used here is intended to imitate
140 `Python's`_ notation. In particular, for lexical definitions, the productions
141 operate at the character level and there is no implied whitespace between
142 elements. The syntax definitions operate at the token level, so there is
143 implied whitespace between tokens.
145 .. _`Python's`: http://docs.python.org/py3k/reference/introduction.html#notation
147 TableGen supports BCPL-style comments (``// ...``) and nestable C-style
148 comments (``/* ... */``).
149 TableGen also provides simple `Preprocessing Facilities`_.
151 Formfeed characters may be used freely in files to produce page breaks when
152 the file is printed for review.
154 The following are the basic punctuation tokens::
156 - + [ ] { } ( ) < > : ; . ... = ? #
161 Numeric literals take one of the following forms:
164 TokInteger: `DecimalInteger` | `HexInteger` | `BinInteger`
165 DecimalInteger: ["+" | "-"] ("0"..."9")+
166 HexInteger: "0x" ("0"..."9" | "a"..."f" | "A"..."F")+
167 BinInteger: "0b" ("0" | "1")+
169 Observe that the :token:`DecimalInteger` token includes the optional ``+``
170 or ``-`` sign, unlike most languages where the sign would be treated as a
173 TableGen has two kinds of string literals:
176 TokString: '"' (non-'"' characters and escapes) '"'
177 TokCode: "[{" (shortest text not containing "}]") "}]"
179 A :token:`TokCode` is nothing more than a multi-line string literal
180 delimited by ``[{`` and ``}]``. It can break across lines and the
181 line breaks are retained in the string.
183 The current implementation accepts the following escape sequences::
190 TableGen has name- and identifier-like tokens, which are case-sensitive.
193 ualpha: "a"..."z" | "A"..."Z" | "_"
194 TokIdentifier: ("0"..."9")* `ualpha` (`ualpha` | "0"..."9")*
195 TokVarName: "$" `ualpha` (`ualpha` | "0"..."9")*
197 Note that, unlike most languages, TableGen allows :token:`TokIdentifier` to
198 begin with an integer. In case of ambiguity, a token is interpreted as a
199 numeric literal rather than an identifier.
201 TableGen has the following reserved keywords, which cannot be used as
204 assert bit bits class code
205 dag def else false foreach
206 defm defset defvar field if
207 in include int let list
208 multiclass string then true
211 The ``field`` reserved word is deprecated, except when used with the
212 CodeEmitterGen backend where it's used to distinguish normal record
213 fields from encoding fields.
218 TableGen provides "bang operators" that have a wide variety of uses:
222 : !add !and !cast !con !dag
223 : !div !empty !eq !exists !filter
224 : !find !foldl !foreach !ge !getdagarg
225 : !getdagname !getdagop !gt !head !if
226 : !interleave !isa !le !listconcat !listremove
227 : !listsplat !logtwo !lt !mul !ne
228 : !not !or !range !setdagarg !setdagname
229 : !setdagop !shl !size !sra !srl
230 : !strconcat !sub !subst !substr !tail
231 : !tolower !toupper !xor
233 The ``!cond`` operator has a slightly different
234 syntax compared to other bang operators, so it is defined separately:
239 See `Appendix A: Bang Operators`_ for a description of each bang operator.
244 TableGen has an include mechanism. The content of the included file
245 lexically replaces the ``include`` directive and is then parsed as if it was
246 originally in the main file.
249 IncludeDirective: "include" `TokString`
251 Portions of the main file and included files can be conditionalized using
252 preprocessor directives.
255 PreprocessorDirective: "#define" | "#ifdef" | "#ifndef"
260 The TableGen language is statically typed, using a simple but complete type
261 system. Types are used to check for errors, to perform implicit conversions,
262 and to help interface designers constrain the allowed input. Every value is
263 required to have an associated type.
265 TableGen supports a mixture of low-level types (e.g., ``bit``) and
266 high-level types (e.g., ``dag``). This flexibility allows you to describe a
267 wide range of records conveniently and compactly.
270 Type: "bit" | "int" | "string" | "dag"
271 :| "bits" "<" `TokInteger` ">"
272 :| "list" "<" `Type` ">"
274 ClassID: `TokIdentifier`
277 A ``bit`` is a boolean value that can be 0 or 1.
280 The ``int`` type represents a simple 64-bit integer value, such as 5 or
284 The ``string`` type represents an ordered sequence of characters of arbitrary
287 ``bits<``\ *n*\ ``>``
288 The ``bits`` type is a fixed-sized integer of arbitrary length *n* that
289 is treated as separate bits. These bits can be accessed individually.
290 A field of this type is useful for representing an instruction operation
291 code, register number, or address mode/register/displacement. The bits of
292 the field can be set individually or as subfields. For example, in an
293 instruction address, the addressing mode, base register number, and
294 displacement can be set separately.
296 ``list<``\ *type*\ ``>``
297 This type represents a list whose elements are of the *type* specified in
298 angle brackets. The element type is arbitrary; it can even be another
299 list type. List elements are indexed from 0.
302 This type represents a nestable directed acyclic graph (DAG) of nodes.
303 Each node has an *operator* and zero or more *arguments* (or *operands*).
305 another ``dag`` object, allowing an arbitrary tree of nodes and edges.
306 As an example, DAGs are used to represent code patterns for use by
307 the code generator instruction selection algorithms. See `Directed
308 acyclic graphs (DAGs)`_ for more details;
311 Specifying a class name in a type context indicates
312 that the type of the defined value must
313 be a subclass of the specified class. This is useful in conjunction with
314 the ``list`` type; for example, to constrain the elements of the list to a
315 common base class (e.g., a ``list<Register>`` can only contain definitions
316 derived from the ``Register`` class).
317 The :token:`ClassID` must name a class that has been previously
321 Values and Expressions
322 ======================
324 There are many contexts in TableGen statements where a value is required. A
325 common example is in the definition of a record, where each field is
326 specified by a name and an optional value. TableGen allows for a reasonable
327 number of different forms when building up value expressions. These forms
328 allow the TableGen file to be written in a syntax that is natural for the
331 Note that all of the values have rules for converting them from one type to
332 another. For example, these rules allow you to assign a value like ``7``
333 to an entity of type ``bits<4>``.
336 Value: `SimpleValue` `ValueSuffix`*
337 :| `Value` "#" [`Value`]
338 ValueSuffix: "{" `RangeList` "}"
339 :| "[" `SliceElements` "]"
340 :| "." `TokIdentifier`
341 RangeList: `RangePiece` ("," `RangePiece`)*
342 RangePiece: `TokInteger`
343 :| `TokInteger` "..." `TokInteger`
344 :| `TokInteger` "-" `TokInteger`
345 :| `TokInteger` `TokInteger`
346 SliceElements: (`SliceElement` ",")* `SliceElement` ","?
347 SliceElement: `Value`
348 :| `Value` "..." `Value`
349 :| `Value` "-" `Value`
350 :| `Value` `TokInteger`
353 The peculiar last form of :token:`RangePiece` and :token:`SliceElement` is
354 due to the fact that the "``-``" is included in the :token:`TokInteger`,
355 hence ``1-5`` gets lexed as two consecutive tokens, with values ``1`` and
356 ``-5``, instead of "1", "-", and "5".
357 The use of hyphen as the range punctuation is deprecated.
362 The :token:`SimpleValue` has a number of forms.
365 SimpleValue: `TokInteger` | `TokString`+ | `TokCode`
367 A value can be an integer literal, a string literal, or a code literal.
368 Multiple adjacent string literals are concatenated as in C/C++; the simple
369 value is the concatenation of the strings. Code literals become strings and
370 are then indistinguishable from them.
373 SimpleValue2: "true" | "false"
375 The ``true`` and ``false`` literals are essentially syntactic sugar for the
376 integer values 1 and 0. They improve the readability of TableGen files when
377 boolean values are used in field initializations, bit sequences, ``if``
378 statements, etc. When parsed, these literals are converted to integers.
382 Although ``true`` and ``false`` are literal names for 1 and 0, we
383 recommend as a stylistic rule that you use them for boolean
389 A question mark represents an uninitialized value.
392 SimpleValue4: "{" [`ValueList`] "}"
393 ValueList: `ValueListNE`
394 ValueListNE: `Value` ("," `Value`)*
396 This value represents a sequence of bits, which can be used to initialize a
397 ``bits<``\ *n*\ ``>`` field (note the braces). When doing so, the values
398 must represent a total of *n* bits.
401 SimpleValue5: "[" `ValueList` "]" ["<" `Type` ">"]
403 This value is a list initializer (note the brackets). The values in brackets
404 are the elements of the list. The optional :token:`Type` can be used to
405 indicate a specific element type; otherwise the element type is inferred
406 from the given values. TableGen can usually infer the type, although
407 sometimes not when the value is the empty list (``[]``).
410 SimpleValue6: "(" `DagArg` [`DagArgList`] ")"
411 DagArgList: `DagArg` ("," `DagArg`)*
412 DagArg: `Value` [":" `TokVarName`] | `TokVarName`
414 This represents a DAG initializer (note the parentheses). The first
415 :token:`DagArg` is called the "operator" of the DAG and must be a record.
416 See `Directed acyclic graphs (DAGs)`_ for more details.
419 SimpleValue7: `TokIdentifier`
421 The resulting value is the value of the entity named by the identifier. The
422 possible identifiers are described here, but the descriptions will make more
423 sense after reading the remainder of this guide.
425 .. The code for this is exceptionally abstruse. These examples are a
428 * A template argument of a ``class``, such as the use of ``Bar`` in::
430 class Foo <int Bar> {
434 * The implicit template argument ``NAME`` in a ``class`` or ``multiclass``
435 definition (see `NAME`_).
437 * A field local to a ``class``, such as the use of ``Bar`` in::
444 * The name of a record definition, such as the use of ``Bar`` in the
445 definition of ``Foo``::
447 def Bar : SomeClass {
455 * A field local to a record definition, such as the use of ``Bar`` in::
462 Fields inherited from the record's parent classes can be accessed the same way.
464 * A template argument of a ``multiclass``, such as the use of ``Bar`` in::
466 multiclass Foo <int Bar> {
467 def : SomeClass<Bar>;
470 * A variable defined with the ``defvar`` or ``defset`` statements.
472 * The iteration variable of a ``foreach``, such as the use of ``i`` in::
478 SimpleValue8: `ClassID` "<" `ArgValueList` ">"
480 This form creates a new anonymous record definition (as would be created by an
481 unnamed ``def`` inheriting from the given class with the given template
482 arguments; see `def`_) and the value is that record. A field of the record can be
483 obtained using a suffix; see `Suffixed Values`_.
485 Invoking a class in this manner can provide a simple subroutine facility.
486 See `Using Classes as Subroutines`_ for more information.
489 SimpleValue9: `BangOperator` ["<" `Type` ">"] "(" `ValueListNE` ")"
490 :| `CondOperator` "(" `CondClause` ("," `CondClause`)* ")"
491 CondClause: `Value` ":" `Value`
493 The bang operators provide functions that are not available with the other
494 simple values. Except in the case of ``!cond``, a bang operator takes a list
495 of arguments enclosed in parentheses and performs some function on those
496 arguments, producing a value for that bang operator. The ``!cond`` operator
497 takes a list of pairs of arguments separated by colons. See `Appendix A:
498 Bang Operators`_ for a description of each bang operator.
504 The :token:`SimpleValue` values described above can be specified with
505 certain suffixes. The purpose of a suffix is to obtain a subvalue of the
506 primary value. Here are the possible suffixes for some primary *value*.
509 The final value is bit 17 of the integer *value* (note the braces).
511 *value*\ ``{8...15}``
512 The final value is bits 8--15 of the integer *value*. The order of the
513 bits can be reversed by specifying ``{15...8}``.
516 The final value is element `i` of the list *value* (note the brackets).
517 In other words, the brackets act as a subscripting operator on the list.
518 This is the case only when a single element is specified.
521 The final value is a list that contains a single element `i` of the list.
522 In short, a list slice with a single element.
524 *value*\ ``[4...7,17,2...3,4]``
525 The final value is a new list that is a slice of the list *value*.
526 The new list contains elements 4, 5, 6, 7, 17, 2, 3, and 4.
527 Elements may be included multiple times and in any order. This is the result
528 only when more than one element is specified.
530 *value*\ ``[i,m...n,j,ls]``
531 Each element may be an expression (variables, bang operators).
532 The type of `m` and `n` should be `int`.
533 The type of `i`, `j`, and `ls` should be either `int` or `list<int>`.
535 *value*\ ``.``\ *field*
536 The final value is the value of the specified *field* in the specified
542 The paste operator (``#``) is the only infix operator available in TableGen
543 expressions. It allows you to concatenate strings or lists, but has a few
546 The paste operator can be used when specifying the record name in a
547 :token:`Def` or :token:`Defm` statement, in which case it must construct a
548 string. If an operand is an undefined name (:token:`TokIdentifier`) or the
549 name of a global :token:`Defvar` or :token:`Defset`, it is treated as a
550 verbatim string of characters. The value of a global name is not used.
552 The paste operator can be used in all other value expressions, in which case
553 it can construct a string or a list. Rather oddly, but consistent with the
554 previous case, if the *right-hand-side* operand is an undefined name or a
555 global name, it is treated as a verbatim string of characters. The
556 left-hand-side operand is treated normally.
558 Values can have a trailing paste operator, in which case the left-hand-side
559 operand is concatenated to an empty string.
561 `Appendix B: Paste Operator Examples`_ presents examples of the behavior of
567 The following statements may appear at the top level of TableGen source
571 TableGenFile: (`Statement` | `IncludeDirective`
572 :| `PreprocessorDirective`)*
573 Statement: `Assert` | `Class` | `Def` | `Defm` | `Defset` | `Defvar`
574 :| `Foreach` | `If` | `Let` | `MultiClass`
576 The following sections describe each of these top-level statements.
579 ``class`` --- define an abstract record class
580 ---------------------------------------------
582 A ``class`` statement defines an abstract record class from which other
583 classes and records can inherit.
586 Class: "class" `ClassID` [`TemplateArgList`] `RecordBody`
587 TemplateArgList: "<" `TemplateArgDecl` ("," `TemplateArgDecl`)* ">"
588 TemplateArgDecl: `Type` `TokIdentifier` ["=" `Value`]
590 A class can be parameterized by a list of "template arguments," whose values
591 can be used in the class's record body. These template arguments are
592 specified each time the class is inherited by another class or record.
594 If a template argument is not assigned a default value with ``=``, it is
595 uninitialized (has the "value" ``?``) and must be specified in the template
596 argument list when the class is inherited (required argument). If an
597 argument is assigned a default value, then it need not be specified in the
598 argument list (optional argument). In the declaration, all required template
599 arguments must precede any optional arguments. The template argument default
600 values are evaluated from left to right.
602 The :token:`RecordBody` is defined below. It can include a list of
603 parent classes from which the current class inherits, along with field
604 definitions and other statements. When a class ``C`` inherits from another
605 class ``D``, the fields of ``D`` are effectively merged into the fields of
608 A given class can only be defined once. A ``class`` statement is
609 considered to define the class if *any* of the following are true (the
610 :token:`RecordBody` elements are described below).
612 * The :token:`TemplateArgList` is present, or
613 * The :token:`ParentClassList` in the :token:`RecordBody` is present, or
614 * The :token:`Body` in the :token:`RecordBody` is present and not empty.
616 You can declare an empty class by specifying an empty :token:`TemplateArgList`
617 and an empty :token:`RecordBody`. This can serve as a restricted form of
618 forward declaration. Note that records derived from a forward-declared
619 class will inherit no fields from it, because those records are built when
620 their declarations are parsed, and thus before the class is finally defined.
624 Every class has an implicit template argument named ``NAME`` (uppercase),
625 which is bound to the name of the :token:`Def` or :token:`Defm` inheriting
626 from the class. If the class is inherited by an anonymous record, the name
627 is unspecified but globally unique.
629 See `Examples: classes and records`_ for examples.
634 Record bodies appear in both class and record definitions. A record body can
635 include a parent class list, which specifies the classes from which the
636 current class or record inherits fields. Such classes are called the
637 parent classes of the class or record. The record body also
638 includes the main body of the definition, which contains the specification
639 of the fields of the class or record.
642 RecordBody: `ParentClassList` `Body`
643 ParentClassList: [":" `ParentClassListNE`]
644 ParentClassListNE: `ClassRef` ("," `ClassRef`)*
645 ClassRef: (`ClassID` | `MultiClassID`) ["<" [`ArgValueList`] ">"]
646 ArgValueList: `PostionalArgValueList` [","] `NamedArgValueList`
647 PostionalArgValueList: [`Value` {"," `Value`}*]
648 NamedArgValueList: [`NameValue` "=" `Value` {"," `NameValue` "=" `Value`}*]
650 A :token:`ParentClassList` containing a :token:`MultiClassID` is valid only
651 in the class list of a ``defm`` statement. In that case, the ID must be the
652 name of a multiclass.
654 The argument values can be specified in two forms:
656 * Positional argument (``value``). The value is assigned to the argument in the
657 corresponding position. For ``Foo<a0, a1>``, ``a0`` will be assigned to first
658 argument and ``a1`` will be assigned to second argument.
659 * Named argument (``name=value``). The value is assigned to the argument with
660 the specified name. For ``Foo<a=a0, b=a1>``, ``a0`` will be assigned to the
661 argument with name ``a`` and ``a1`` will be assigned to the argument with
664 Required arguments can alse be specified as named argument.
666 Note that the argument can only be specified once regardless of the way (named
667 or positional) to specify and positional arguments should be put before named
671 Body: ";" | "{" `BodyItem`* "}"
672 BodyItem: (`Type` | "code") `TokIdentifier` ["=" `Value`] ";"
673 :| "let" `TokIdentifier` ["{" `RangeList` "}"] "=" `Value` ";"
674 :| "defvar" `TokIdentifier` "=" `Value` ";"
677 A field definition in the body specifies a field to be included in the class
678 or record. If no initial value is specified, then the field's value is
679 uninitialized. The type must be specified; TableGen will not infer it from
680 the value. The keyword ``code`` may be used to emphasize that the field
681 has a string value that is code.
683 The ``let`` form is used to reset a field to a new value. This can be done
684 for fields defined directly in the body or fields inherited from parent
685 classes. A :token:`RangeList` can be specified to reset certain bits in a
688 The ``defvar`` form defines a variable whose value can be used in other
689 value expressions within the body. The variable is not a field: it does not
690 become a field of the class or record being defined. Variables are provided
691 to hold temporary values while processing the body. See `Defvar in a Record
692 Body`_ for more details.
694 When class ``C2`` inherits from class ``C1``, it acquires all the field
695 definitions of ``C1``. As those definitions are merged into class ``C2``, any
696 template arguments passed to ``C1`` by ``C2`` are substituted into the
697 definitions. In other words, the abstract record fields defined by ``C1`` are
698 expanded with the template arguments before being merged into ``C2``.
703 ``def`` --- define a concrete record
704 ------------------------------------
706 A ``def`` statement defines a new concrete record.
709 Def: "def" [`NameValue`] `RecordBody`
710 NameValue: `Value` (parsed in a special mode)
712 The name value is optional. If specified, it is parsed in a special mode
713 where undefined (unrecognized) identifiers are interpreted as literal
714 strings. In particular, global identifiers are considered unrecognized.
715 These include global variables defined by ``defvar`` and ``defset``. A
716 record name can be the null string.
718 If no name value is given, the record is *anonymous*. The final name of an
719 anonymous record is unspecified but globally unique.
721 Special handling occurs if a ``def`` appears inside a ``multiclass``
722 statement. See the ``multiclass`` section below for details.
724 A record can inherit from one or more classes by specifying the
725 :token:`ParentClassList` clause at the beginning of its record body. All of
726 the fields in the parent classes are added to the record. If two or more
727 parent classes provide the same field, the record ends up with the field value
728 of the last parent class.
730 As a special case, the name of a record can be passed as a template argument
731 to that record's parent classes. For example:
739 def rec1 : A<(ops rec1)>;
741 The DAG ``(ops rec1)`` is passed as a template argument to class ``A``. Notice
742 that the DAG includes ``rec1``, the record being defined.
744 The steps taken to create a new record are somewhat complex. See `How
747 See `Examples: classes and records`_ for examples.
750 Examples: classes and records
751 -----------------------------
753 Here is a simple TableGen file with one class and two record definitions.
764 string Greeting = "Hello!";
767 First, the abstract class ``C`` is defined. It has one field named ``V``
768 that is a bit initialized to true.
770 Next, two records are defined, derived from class ``C``; that is, with ``C``
771 as their parent class. Thus they both inherit the ``V`` field. Record ``Y``
772 also defines another string field, ``Greeting``, which is initialized to
773 ``"Hello!"``. In addition, ``Y`` overrides the inherited ``V`` field,
776 A class is useful for isolating the common features of multiple records in
777 one place. A class can initialize common fields to default values, but
778 records inheriting from that class can override the defaults.
780 TableGen supports the definition of parameterized classes as well as
781 nonparameterized ones. Parameterized classes specify a list of variable
782 declarations, which may optionally have defaults, that are bound when the
783 class is specified as a parent class of another class or record.
787 class FPFormat <bits<3> val> {
791 def NotFP : FPFormat<0>;
792 def ZeroArgFP : FPFormat<1>;
793 def OneArgFP : FPFormat<2>;
794 def OneArgFPRW : FPFormat<3>;
795 def TwoArgFP : FPFormat<4>;
796 def CompareFP : FPFormat<5>;
797 def CondMovFP : FPFormat<6>;
798 def SpecialFP : FPFormat<7>;
800 The purpose of the ``FPFormat`` class is to act as a sort of enumerated
801 type. It provides a single field, ``Value``, which holds a 3-bit number. Its
802 template argument, ``val``, is used to set the ``Value`` field. Each of the
803 eight records is defined with ``FPFormat`` as its parent class. The
804 enumeration value is passed in angle brackets as the template argument. Each
805 record will inherent the ``Value`` field with the appropriate enumeration
808 Here is a more complex example of classes with template arguments. First, we
809 define a class similar to the ``FPFormat`` class above. It takes a template
810 argument and uses it to initialize a field named ``Value``. Then we define
811 four records that inherit the ``Value`` field with its four different
816 class ModRefVal <bits<2> val> {
820 def None : ModRefVal<0>;
821 def Mod : ModRefVal<1>;
822 def Ref : ModRefVal<2>;
823 def ModRef : ModRefVal<3>;
825 This is somewhat contrived, but let's say we would like to examine the two
826 bits of the ``Value`` field independently. We can define a class that
827 accepts a ``ModRefVal`` record as a template argument and splits up its
828 value into two fields, one bit each. Then we can define records that inherit from
829 ``ModRefBits`` and so acquire two fields from it, one for each bit in the
830 ``ModRefVal`` record passed as the template argument.
834 class ModRefBits <ModRefVal mrv> {
835 // Break the value up into its bits, which can provide a nice
836 // interface to the ModRefVal values.
837 bit isMod = mrv.Value{0};
838 bit isRef = mrv.Value{1};
842 def foo : ModRefBits<Mod>;
843 def bar : ModRefBits<Ref>;
844 def snork : ModRefBits<ModRef>;
846 This illustrates how one class can be defined to reorganize the
847 fields in another class, thus hiding the internal representation of that
850 Running ``llvm-tblgen`` on the example prints the following definitions:
867 ``let`` --- override fields in classes or records
868 -------------------------------------------------
870 A ``let`` statement collects a set of field values (sometimes called
871 *bindings*) and applies them to all the classes and records defined by
872 statements within the scope of the ``let``.
875 Let: "let" `LetList` "in" "{" `Statement`* "}"
876 :| "let" `LetList` "in" `Statement`
877 LetList: `LetItem` ("," `LetItem`)*
878 LetItem: `TokIdentifier` ["<" `RangeList` ">"] "=" `Value`
880 The ``let`` statement establishes a scope, which is a sequence of statements
881 in braces or a single statement with no braces. The bindings in the
882 :token:`LetList` apply to the statements in that scope.
884 The field names in the :token:`LetList` must name fields in classes inherited by
885 the classes and records defined in the statements. The field values are
886 applied to the classes and records *after* the records inherit all the fields from
887 their parent classes. So the ``let`` acts to override inherited field
888 values. A ``let`` cannot override the value of a template argument.
890 Top-level ``let`` statements are often useful when a few fields need to be
891 overridden in several records. Here are two examples. Note that ``let``
892 statements can be nested.
896 let isTerminator = true, isReturn = true, isBarrier = true, hasCtrlDep = true in
897 def RET : I<0xC3, RawFrm, (outs), (ins), "ret", [(X86retflag 0)]>;
900 // All calls clobber the non-callee saved registers...
901 let Defs = [EAX, ECX, EDX, FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0,
902 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7, XMM0, XMM1, XMM2,
903 XMM3, XMM4, XMM5, XMM6, XMM7, EFLAGS] in {
904 def CALLpcrel32 : Ii32<0xE8, RawFrm, (outs), (ins i32imm:$dst, variable_ops),
905 "call\t${dst:call}", []>;
906 def CALL32r : I<0xFF, MRM2r, (outs), (ins GR32:$dst, variable_ops),
907 "call\t{*}$dst", [(X86call GR32:$dst)]>;
908 def CALL32m : I<0xFF, MRM2m, (outs), (ins i32mem:$dst, variable_ops),
909 "call\t{*}$dst", []>;
912 Note that a top-level ``let`` will not override fields defined in the classes or records
916 ``multiclass`` --- define multiple records
917 ------------------------------------------
919 While classes with template arguments are a good way to factor out commonality
920 between multiple records, multiclasses allow a convenient method for
921 defining many records at once. For example, consider a 3-address
922 instruction architecture whose instructions come in two formats: ``reg = reg
923 op reg`` and ``reg = reg op imm`` (e.g., SPARC). We would like to specify in
924 one place that these two common formats exist, then in a separate place
925 specify what all the operations are. The ``multiclass`` and ``defm``
926 statements accomplish this goal. You can think of a multiclass as a macro or
927 template that expands into multiple records.
930 MultiClass: "multiclass" `TokIdentifier` [`TemplateArgList`]
932 : "{" `MultiClassStatement`+ "}"
933 MultiClassID: `TokIdentifier`
934 MultiClassStatement: `Assert` | `Def` | `Defm` | `Defvar` | `Foreach` | `If` | `Let`
936 As with regular classes, the multiclass has a name and can accept template
937 arguments. A multiclass can inherit from other multiclasses, which causes
938 the other multiclasses to be expanded and contribute to the record
939 definitions in the inheriting multiclass. The body of the multiclass
940 contains a series of statements that define records, using :token:`Def` and
941 :token:`Defm`. In addition, :token:`Defvar`, :token:`Foreach`, and
942 :token:`Let` statements can be used to factor out even more common elements.
943 The :token:`If` and :token:`Assert` statements can also be used.
945 Also as with regular classes, the multiclass has the implicit template
946 argument ``NAME`` (see NAME_). When a named (non-anonymous) record is
947 defined in a multiclass and the record's name does not include a use of the
948 template argument ``NAME``, such a use is automatically *prepended*
949 to the name. That is, the following are equivalent inside a multiclass::
954 The records defined in a multiclass are created when the multiclass is
955 "instantiated" or "invoked" by a ``defm`` statement outside the multiclass
956 definition. Each ``def`` statement in the multiclass produces a record. As
957 with top-level ``def`` statements, these definitions can inherit from
958 multiple parent classes.
960 See `Examples: multiclasses and defms`_ for examples.
963 ``defm`` --- invoke multiclasses to define multiple records
964 -----------------------------------------------------------
966 Once multiclasses have been defined, you use the ``defm`` statement to
967 "invoke" them and process the multiple record definitions in those
968 multiclasses. Those record definitions are specified by ``def``
969 statements in the multiclasses, and indirectly by ``defm`` statements.
972 Defm: "defm" [`NameValue`] `ParentClassList` ";"
974 The optional :token:`NameValue` is formed in the same way as the name of a
975 ``def``. The :token:`ParentClassList` is a colon followed by a list of at
976 least one multiclass and any number of regular classes. The multiclasses
977 must precede the regular classes. Note that the ``defm`` does not have a
980 This statement instantiates all the records defined in all the specified
981 multiclasses, either directly by ``def`` statements or indirectly by
982 ``defm`` statements. These records also receive the fields defined in any
983 regular classes included in the parent class list. This is useful for adding
984 a common set of fields to all the records created by the ``defm``.
986 The name is parsed in the same special mode used by ``def``. If the name is
987 not included, an unspecified but globally unique name is provided. That is,
988 the following examples end up with different names::
990 defm : SomeMultiClass<...>; // A globally unique name.
991 defm "" : SomeMultiClass<...>; // An empty name.
993 The ``defm`` statement can be used in a multiclass body. When this occurs,
994 the second variant is equivalent to::
996 defm NAME : SomeMultiClass<...>;
998 More generally, when ``defm`` occurs in a multiclass and its name does not
999 include a use of the implicit template argument ``NAME``, then ``NAME`` will
1000 be prepended automatically. That is, the following are equivalent inside a
1003 defm Foo : SomeMultiClass<...>;
1004 defm NAME # Foo : SomeMultiClass<...>;
1006 See `Examples: multiclasses and defms`_ for examples.
1008 Examples: multiclasses and defms
1009 --------------------------------
1011 Here is a simple example using ``multiclass`` and ``defm``. Consider a
1012 3-address instruction architecture whose instructions come in two formats:
1013 ``reg = reg op reg`` and ``reg = reg op imm`` (immediate). The SPARC is an
1014 example of such an architecture.
1016 .. code-block:: text
1021 class inst <int opc, string asmstr, dag operandlist>;
1023 multiclass ri_inst <int opc, string asmstr> {
1024 def _rr : inst<opc, !strconcat(asmstr, " $dst, $src1, $src2"),
1025 (ops GPR:$dst, GPR:$src1, GPR:$src2)>;
1026 def _ri : inst<opc, !strconcat(asmstr, " $dst, $src1, $src2"),
1027 (ops GPR:$dst, GPR:$src1, Imm:$src2)>;
1030 // Define records for each instruction in the RR and RI formats.
1031 defm ADD : ri_inst<0b111, "add">;
1032 defm SUB : ri_inst<0b101, "sub">;
1033 defm MUL : ri_inst<0b100, "mul">;
1035 Each use of the ``ri_inst`` multiclass defines two records, one with the
1036 ``_rr`` suffix and one with ``_ri``. Recall that the name of the ``defm``
1037 that uses a multiclass is prepended to the names of the records defined in
1038 that multiclass. So the resulting definitions are named::
1044 Without the ``multiclass`` feature, the instructions would have to be
1047 .. code-block:: text
1052 class inst <int opc, string asmstr, dag operandlist>;
1054 class rrinst <int opc, string asmstr>
1055 : inst<opc, !strconcat(asmstr, " $dst, $src1, $src2"),
1056 (ops GPR:$dst, GPR:$src1, GPR:$src2)>;
1058 class riinst <int opc, string asmstr>
1059 : inst<opc, !strconcat(asmstr, " $dst, $src1, $src2"),
1060 (ops GPR:$dst, GPR:$src1, Imm:$src2)>;
1062 // Define records for each instruction in the RR and RI formats.
1063 def ADD_rr : rrinst<0b111, "add">;
1064 def ADD_ri : riinst<0b111, "add">;
1065 def SUB_rr : rrinst<0b101, "sub">;
1066 def SUB_ri : riinst<0b101, "sub">;
1067 def MUL_rr : rrinst<0b100, "mul">;
1068 def MUL_ri : riinst<0b100, "mul">;
1070 A ``defm`` can be used in a multiclass to "invoke" other multiclasses and
1071 create the records defined in those multiclasses in addition to the records
1072 defined in the current multiclass. In the following example, the ``basic_s``
1073 and ``basic_p`` multiclasses contain ``defm`` statements that refer to the
1074 ``basic_r`` multiclass. The ``basic_r`` multiclass contains only ``def``
1077 .. code-block:: text
1079 class Instruction <bits<4> opc, string Name> {
1080 bits<4> opcode = opc;
1084 multiclass basic_r <bits<4> opc> {
1085 def rr : Instruction<opc, "rr">;
1086 def rm : Instruction<opc, "rm">;
1089 multiclass basic_s <bits<4> opc> {
1090 defm SS : basic_r<opc>;
1091 defm SD : basic_r<opc>;
1092 def X : Instruction<opc, "x">;
1095 multiclass basic_p <bits<4> opc> {
1096 defm PS : basic_r<opc>;
1097 defm PD : basic_r<opc>;
1098 def Y : Instruction<opc, "y">;
1101 defm ADD : basic_s<0xf>, basic_p<0xf>;
1103 The final ``defm`` creates the following records, five from the ``basic_s``
1104 multiclass and five from the ``basic_p`` multiclass::
1113 A ``defm`` statement, both at top level and in a multiclass, can inherit
1114 from regular classes in addition to multiclasses. The rule is that the
1115 regular classes must be listed after the multiclasses, and there must be at least
1118 .. code-block:: text
1121 bits<4> Prefix = 11;
1124 bits<4> Prefix = 12;
1126 class I <bits<4> op> {
1127 bits<4> opcode = op;
1136 defm SS : R, XD; // First multiclass R, then regular class XD.
1142 This example will create four records, shown here in alphabetical order with
1145 .. code-block:: text
1148 bits<4> opcode = { 0, 0, 1, 0 };
1149 bits<4> Prefix = { 1, 1, 0, 0 };
1153 bits<4> opcode = { 0, 1, 0, 0 };
1154 bits<4> Prefix = { 1, 1, 0, 0 };
1158 bits<4> opcode = { 0, 0, 1, 0 };
1159 bits<4> Prefix = { 1, 0, 1, 1 };
1163 bits<4> opcode = { 0, 1, 0, 0 };
1164 bits<4> Prefix = { 1, 0, 1, 1 };
1167 It's also possible to use ``let`` statements inside multiclasses, providing
1168 another way to factor out commonality from the records, especially when
1169 using several levels of multiclass instantiations.
1171 .. code-block:: text
1173 multiclass basic_r <bits<4> opc> {
1174 let Predicates = [HasSSE2] in {
1175 def rr : Instruction<opc, "rr">;
1176 def rm : Instruction<opc, "rm">;
1178 let Predicates = [HasSSE3] in
1179 def rx : Instruction<opc, "rx">;
1182 multiclass basic_ss <bits<4> opc> {
1183 let IsDouble = false in
1184 defm SS : basic_r<opc>;
1186 let IsDouble = true in
1187 defm SD : basic_r<opc>;
1190 defm ADD : basic_ss<0xf>;
1193 ``defset`` --- create a definition set
1194 --------------------------------------
1196 The ``defset`` statement is used to collect a set of records into a global
1200 Defset: "defset" `Type` `TokIdentifier` "=" "{" `Statement`* "}"
1202 All records defined inside the braces via ``def`` and ``defm`` are defined
1203 as usual, and they are also collected in a global list of the given name
1204 (:token:`TokIdentifier`).
1206 The specified type must be ``list<``\ *class*\ ``>``, where *class* is some
1207 record class. The ``defset`` statement establishes a scope for its
1208 statements. It is an error to define a record in the scope of the
1209 ``defset`` that is not of type *class*.
1211 The ``defset`` statement can be nested. The inner ``defset`` adds the
1212 records to its own set, and all those records are also added to the outer
1215 Anonymous records created inside initialization expressions using the
1216 ``ClassID<...>`` syntax are not collected in the set.
1219 ``defvar`` --- define a variable
1220 --------------------------------
1222 A ``defvar`` statement defines a global variable. Its value can be used
1223 throughout the statements that follow the definition.
1226 Defvar: "defvar" `TokIdentifier` "=" `Value` ";"
1228 The identifier on the left of the ``=`` is defined to be a global variable
1229 whose value is given by the value expression on the right of the ``=``. The
1230 type of the variable is automatically inferred.
1232 Once a variable has been defined, it cannot be set to another value.
1234 Variables defined in a top-level ``foreach`` go out of scope at the end of
1235 each loop iteration, so their value in one iteration is not available in
1236 the next iteration. The following ``defvar`` will not work::
1238 defvar i = !add(i, 1);
1240 Variables can also be defined with ``defvar`` in a record body. See
1241 `Defvar in a Record Body`_ for more details.
1243 ``foreach`` --- iterate over a sequence of statements
1244 -----------------------------------------------------
1246 The ``foreach`` statement iterates over a series of statements, varying a
1247 variable over a sequence of values.
1250 Foreach: "foreach" `ForeachIterator` "in" "{" `Statement`* "}"
1251 :| "foreach" `ForeachIterator` "in" `Statement`
1252 ForeachIterator: `TokIdentifier` "=" ("{" `RangeList` "}" | `RangePiece` | `Value`)
1254 The body of the ``foreach`` is a series of statements in braces or a
1255 single statement with no braces. The statements are re-evaluated once for
1256 each value in the range list, range piece, or single value. On each
1257 iteration, the :token:`TokIdentifier` variable is set to the value and can
1258 be used in the statements.
1260 The statement list establishes an inner scope. Variables local to a
1261 ``foreach`` go out of scope at the end of each loop iteration, so their
1262 values do not carry over from one iteration to the next. Foreach loops may
1265 .. Note that the productions involving RangeList and RangePiece have precedence
1266 over the more generic value parsing based on the first token.
1268 .. code-block:: text
1270 foreach i = [0, 1, 2, 3] in {
1271 def R#i : Register<...>;
1272 def F#i : Register<...>;
1275 This loop defines records named ``R0``, ``R1``, ``R2``, and ``R3``, along
1276 with ``F0``, ``F1``, ``F2``, and ``F3``.
1279 ``if`` --- select statements based on a test
1280 --------------------------------------------
1282 The ``if`` statement allows one of two statement groups to be selected based
1283 on the value of an expression.
1286 If: "if" `Value` "then" `IfBody`
1287 :| "if" `Value` "then" `IfBody` "else" `IfBody`
1288 IfBody: "{" `Statement`* "}" | `Statement`
1290 The value expression is evaluated. If it evaluates to true (in the same
1291 sense used by the bang operators), then the statements following the
1292 ``then`` reserved word are processed. Otherwise, if there is an ``else``
1293 reserved word, the statements following the ``else`` are processed. If the
1294 value is false and there is no ``else`` arm, no statements are processed.
1296 Because the braces around the ``then`` statements are optional, this grammar rule
1297 has the usual ambiguity with "dangling else" clauses, and it is resolved in
1298 the usual way: in a case like ``if v1 then if v2 then {...} else {...}``, the
1299 ``else`` associates with the inner ``if`` rather than the outer one.
1301 The :token:`IfBody` of the then and else arms of the ``if`` establish an
1302 inner scope. Any ``defvar`` variables defined in the bodies go out of scope
1303 when the bodies are finished (see `Defvar in a Record Body`_ for more details).
1305 The ``if`` statement can also be used in a record :token:`Body`.
1308 ``assert`` --- check that a condition is true
1309 ---------------------------------------------
1311 The ``assert`` statement checks a boolean condition to be sure that it is true
1312 and prints an error message if it is not.
1315 Assert: "assert" `condition` "," `message` ";"
1317 If the boolean condition is true, the statement does nothing. If the
1318 condition is false, it prints a nonfatal error message. The **message**, which
1319 can be an arbitrary string expression, is included in the error message as a
1320 note. The exact behavior of the ``assert`` statement depends on its
1323 * At top level, the assertion is checked immediately.
1325 * In a record definition, the statement is saved and all assertions are
1326 checked after the record is completely built.
1328 * In a class definition, the assertions are saved and inherited by all
1329 the subclasses and records that inherit from the class. The assertions are
1330 then checked when the records are completely built.
1332 * In a multiclass definition, the assertions are saved with the other
1333 components of the multiclass and then checked each time the multiclass
1334 is instantiated with ``defm``.
1336 Using assertions in TableGen files can simplify record checking in TableGen
1337 backends. Here is an example of an ``assert`` in two class definitions.
1339 .. code-block:: text
1341 class PersonName<string name> {
1342 assert !le(!size(name), 32), "person name is too long: " # name;
1346 class Person<string name, int age> : PersonName<name> {
1347 assert !and(!ge(age, 1), !le(age, 120)), "person age is invalid: " # age;
1351 def Rec20 : Person<"Donald Knuth", 60> {
1359 Directed acyclic graphs (DAGs)
1360 ------------------------------
1362 A directed acyclic graph can be represented directly in TableGen using the
1363 ``dag`` datatype. A DAG node consists of an operator and zero or more
1364 arguments (or operands). Each argument can be of any desired type. By using
1365 another DAG node as an argument, an arbitrary graph of DAG nodes can be
1368 The syntax of a ``dag`` instance is:
1370 ``(`` *operator* *argument1*\ ``,`` *argument2*\ ``,`` ... ``)``
1372 The operator must be present and must be a record. There can be zero or more
1373 arguments, separated by commas. The operator and arguments can have three
1376 ====================== =============================================
1378 ====================== =============================================
1379 *value* argument value
1380 *value*\ ``:``\ *name* argument value and associated name
1381 *name* argument name with unset (uninitialized) value
1382 ====================== =============================================
1384 The *value* can be any TableGen value. The *name*, if present, must be a
1385 :token:`TokVarName`, which starts with a dollar sign (``$``). The purpose of
1386 a name is to tag an operator or argument in a DAG with a particular meaning,
1387 or to associate an argument in one DAG with a like-named argument in another
1390 The following bang operators are useful for working with DAGs:
1391 ``!con``, ``!dag``, ``!empty``, ``!foreach``, ``!getdagarg``, ``!getdagname``,
1392 ``!getdagop``, ``!setdagarg``, ``!setdagname``, ``!setdagop``, ``!size``.
1394 Defvar in a record body
1395 -----------------------
1397 In addition to defining global variables, the ``defvar`` statement can
1398 be used inside the :token:`Body` of a class or record definition to define
1399 local variables. Template arguments of ``class`` or ``multiclass`` can be
1400 used in the value expression. The scope of the variable extends from the
1401 ``defvar`` statement to the end of the body. It cannot be set to a different
1402 value within its scope. The ``defvar`` statement can also be used in the statement
1403 list of a ``foreach``, which establishes a scope.
1405 A variable named ``V`` in an inner scope shadows (hides) any variables ``V``
1406 in outer scopes. In particular, there are several cases:
1408 * ``V`` in a record body shadows a global ``V``.
1410 * ``V`` in a record body shadows template argument ``V``.
1412 * ``V`` in template arguments shadows a global ``V``.
1414 * ``V`` in a ``foreach`` statement list shadows any ``V`` in surrounding record or
1417 Variables defined in a ``foreach`` go out of scope at the end of
1418 each loop iteration, so their value in one iteration is not available in
1419 the next iteration. The following ``defvar`` will not work::
1421 defvar i = !add(i, 1)
1423 How records are built
1424 ---------------------
1426 The following steps are taken by TableGen when a record is built. Classes are simply
1427 abstract records and so go through the same steps.
1429 1. Build the record name (:token:`NameValue`) and create an empty record.
1431 2. Parse the parent classes in the :token:`ParentClassList` from left to
1432 right, visiting each parent class's ancestor classes from top to bottom.
1434 a. Add the fields from the parent class to the record.
1435 b. Substitute the template arguments into those fields.
1436 c. Add the parent class to the record's list of inherited classes.
1438 3. Apply any top-level ``let`` bindings to the record. Recall that top-level
1439 bindings only apply to inherited fields.
1441 4. Parse the body of the record.
1443 * Add any fields to the record.
1444 * Modify the values of fields according to local ``let`` statements.
1445 * Define any ``defvar`` variables.
1447 5. Make a pass over all the fields to resolve any inter-field references.
1449 6. Add the record to the final record list.
1451 Because references between fields are resolved (step 5) after ``let`` bindings are
1452 applied (step 3), the ``let`` statement has unusual power. For example:
1454 .. code-block:: text
1458 int Yplus1 = !add(Y, 1);
1459 int xplus1 = !add(x, 1);
1471 In both cases, one where a top-level ``let`` is used to bind ``Y`` and one
1472 where a local ``let`` does the same thing, the results are:
1474 .. code-block:: text
1487 ``Yplus1`` is 11 because the ``let Y`` is performed before the ``!add(Y,
1488 1)`` is resolved. Use this power wisely.
1491 Using Classes as Subroutines
1492 ============================
1494 As described in `Simple values`_, a class can be invoked in an expression
1495 and passed template arguments. This causes TableGen to create a new anonymous
1496 record inheriting from that class. As usual, the record receives all the
1497 fields defined in the class.
1499 This feature can be employed as a simple subroutine facility. The class can
1500 use the template arguments to define various variables and fields, which end
1501 up in the anonymous record. Those fields can then be retrieved in the
1502 expression invoking the class as follows. Assume that the field ``ret``
1503 contains the final value of the subroutine.
1505 .. code-block:: text
1507 int Result = ... CalcValue<arg>.ret ...;
1509 The ``CalcValue`` class is invoked with the template argument ``arg``. It
1510 calculates a value for the ``ret`` field, which is then retrieved at the
1511 "point of call" in the initialization for the Result field. The anonymous
1512 record created in this example serves no other purpose than to carry the
1515 Here is a practical example. The class ``isValidSize`` determines whether a
1516 specified number of bytes represents a valid data size. The bit ``ret`` is
1517 set appropriately. The field ``ValidSize`` obtains its initial value by
1518 invoking ``isValidSize`` with the data size and retrieving the ``ret`` field
1519 from the resulting anonymous record.
1521 .. code-block:: text
1523 class isValidSize<int size> {
1524 bit ret = !cond(!eq(size, 1): 1,
1534 bit ValidSize = isValidSize<Size>.ret;
1537 Preprocessing Facilities
1538 ========================
1540 The preprocessor embedded in TableGen is intended only for simple
1541 conditional compilation. It supports the following directives, which are
1542 specified somewhat informally.
1545 LineBegin: beginning of line
1546 LineEnd: newline | return | EOF
1547 WhiteSpace: space | tab
1548 CComment: "/*" ... "*/"
1549 BCPLComment: "//" ... `LineEnd`
1550 WhiteSpaceOrCComment: `WhiteSpace` | `CComment`
1551 WhiteSpaceOrAnyComment: `WhiteSpace` | `CComment` | `BCPLComment`
1552 MacroName: `ualpha` (`ualpha` | "0"..."9")*
1553 PreDefine: `LineBegin` (`WhiteSpaceOrCComment`)*
1554 : "#define" (`WhiteSpace`)+ `MacroName`
1555 : (`WhiteSpaceOrAnyComment`)* `LineEnd`
1556 PreIfdef: `LineBegin` (`WhiteSpaceOrCComment`)*
1557 : ("#ifdef" | "#ifndef") (`WhiteSpace`)+ `MacroName`
1558 : (`WhiteSpaceOrAnyComment`)* `LineEnd`
1559 PreElse: `LineBegin` (`WhiteSpaceOrCComment`)*
1560 : "#else" (`WhiteSpaceOrAnyComment`)* `LineEnd`
1561 PreEndif: `LineBegin` (`WhiteSpaceOrCComment`)*
1562 : "#endif" (`WhiteSpaceOrAnyComment`)* `LineEnd`
1565 PreRegContentException: `PreIfdef` | `PreElse` | `PreEndif` | EOF
1566 PreRegion: .* - `PreRegContentException`
1573 A :token:`MacroName` can be defined anywhere in a TableGen file. The name has
1574 no value; it can only be tested to see whether it is defined.
1576 A macro test region begins with an ``#ifdef`` or ``#ifndef`` directive. If
1577 the macro name is defined (``#ifdef``) or undefined (``#ifndef``), then the
1578 source code between the directive and the corresponding ``#else`` or
1579 ``#endif`` is processed. If the test fails but there is an ``#else``
1580 clause, the source code between the ``#else`` and the ``#endif`` is
1581 processed. If the test fails and there is no ``#else`` clause, then no
1582 source code in the test region is processed.
1584 Test regions may be nested, but they must be properly nested. A region
1585 started in a file must end in that file; that is, must have its
1586 ``#endif`` in the same file.
1588 A :token:`MacroName` may be defined externally using the ``-D`` option on the
1589 ``*-tblgen`` command line::
1591 llvm-tblgen self-reference.td -Dmacro1 -Dmacro3
1593 Appendix A: Bang Operators
1594 ==========================
1596 Bang operators act as functions in value expressions. A bang operator takes
1597 one or more arguments, operates on them, and produces a result. If the
1598 operator produces a boolean result, the result value will be 1 for true or 0
1599 for false. When an operator tests a boolean argument, it interprets 0 as false
1603 The ``!getop`` and ``!setop`` bang operators are deprecated in favor of
1604 ``!getdagop`` and ``!setdagop``.
1606 ``!add(``\ *a*\ ``,`` *b*\ ``, ...)``
1607 This operator adds *a*, *b*, etc., and produces the sum.
1609 ``!and(``\ *a*\ ``,`` *b*\ ``, ...)``
1610 This operator does a bitwise AND on *a*, *b*, etc., and produces the
1611 result. A logical AND can be performed if all the arguments are either
1614 ``!cast<``\ *type*\ ``>(``\ *a*\ ``)``
1615 This operator performs a cast on *a* and produces the result.
1616 If *a* is not a string, then a straightforward cast is performed, say
1617 between an ``int`` and a ``bit``, or between record types. This allows
1618 casting a record to a class. If a record is cast to ``string``, the
1619 record's name is produced.
1621 If *a* is a string, then it is treated as a record name and looked up in
1622 the list of all defined records. The resulting record is expected to be of
1623 the specified *type*.
1625 For example, if ``!cast<``\ *type*\ ``>(``\ *name*\ ``)``
1626 appears in a multiclass definition, or in a
1627 class instantiated inside a multiclass definition, and the *name* does not
1628 reference any template arguments of the multiclass, then a record by
1629 that name must have been instantiated earlier
1630 in the source file. If *name* does reference
1631 a template argument, then the lookup is delayed until ``defm`` statements
1632 instantiating the multiclass (or later, if the defm occurs in another
1633 multiclass and template arguments of the inner multiclass that are
1634 referenced by *name* are substituted by values that themselves contain
1635 references to template arguments of the outer multiclass).
1637 If the type of *a* does not match *type*, TableGen raises an error.
1639 ``!con(``\ *a*\ ``,`` *b*\ ``, ...)``
1640 This operator concatenates the DAG nodes *a*, *b*, etc. Their operations
1643 ``!con((op a1:$name1, a2:$name2), (op b1:$name3))``
1645 results in the DAG node ``(op a1:$name1, a2:$name2, b1:$name3)``.
1647 ``!cond(``\ *cond1* ``:`` *val1*\ ``,`` *cond2* ``:`` *val2*\ ``, ...,`` *condn* ``:`` *valn*\ ``)``
1648 This operator tests *cond1* and returns *val1* if the result is true.
1649 If false, the operator tests *cond2* and returns *val2* if the result is
1650 true. And so forth. An error is reported if no conditions are true.
1652 This example produces the sign word for an integer::
1654 !cond(!lt(x, 0) : "negative", !eq(x, 0) : "zero", true : "positive")
1656 ``!dag(``\ *op*\ ``,`` *arguments*\ ``,`` *names*\ ``)``
1657 This operator creates a DAG node with the given operator and
1658 arguments. The *arguments* and *names* arguments must be lists
1659 of equal length or uninitialized (``?``). The *names* argument
1660 must be of type ``list<string>``.
1662 Due to limitations of the type system, *arguments* must be a list of items
1663 of a common type. In practice, this means that they should either have the
1664 same type or be records with a common parent class. Mixing ``dag`` and
1665 non-``dag`` items is not possible. However, ``?`` can be used.
1667 Example: ``!dag(op, [a1, a2, ?], ["name1", "name2", "name3"])`` results in
1668 ``(op a1-value:$name1, a2-value:$name2, ?:$name3)``.
1670 ``!div(``\ *a*\ ``,`` *b*\ ``)``
1671 This operator performs signed division of *a* by *b*, and produces the quotient.
1672 Division by 0 produces an error. Division of INT64_MIN by -1 produces an error.
1674 ``!empty(``\ *a*\ ``)``
1675 This operator produces 1 if the string, list, or DAG *a* is empty; 0 otherwise.
1676 A dag is empty if it has no arguments; the operator does not count.
1678 ``!eq(`` *a*\ `,` *b*\ ``)``
1679 This operator produces 1 if *a* is equal to *b*; 0 otherwise.
1680 The arguments must be ``bit``, ``bits``, ``int``, ``string``, or
1681 record values. Use ``!cast<string>`` to compare other types of objects.
1683 ``!exists<``\ *type*\ ``>(``\ *name*\ ``)``
1684 This operator produces 1 if a record of the given *type* whose name is *name*
1685 exists; 0 otherwise. *name* should be of type *string*.
1687 ``!filter(``\ *var*\ ``,`` *list*\ ``,`` *predicate*\ ``)``
1689 This operator creates a new ``list`` by filtering the elements in
1690 *list*. To perform the filtering, TableGen binds the variable *var* to each
1691 element and then evaluates the *predicate* expression, which presumably
1692 refers to *var*. The predicate must
1693 produce a boolean value (``bit``, ``bits``, or ``int``). The value is
1694 interpreted as with ``!if``:
1695 if the value is 0, the element is not included in the new list. If the value
1696 is anything else, the element is included.
1698 ``!find(``\ *string1*\ ``,`` *string2*\ [``,`` *start*]\ ``)``
1699 This operator searches for *string2* in *string1* and produces its
1700 position. The starting position of the search may be specified by *start*,
1701 which can range between 0 and the length of *string1*; the default is 0.
1702 If the string is not found, the result is -1.
1704 ``!foldl(``\ *init*\ ``,`` *list*\ ``,`` *acc*\ ``,`` *var*\ ``,`` *expr*\ ``)``
1705 This operator performs a left-fold over the items in *list*. The
1706 variable *acc* acts as the accumulator and is initialized to *init*.
1707 The variable *var* is bound to each element in the *list*. The
1708 expression is evaluated for each element and presumably uses *acc* and
1709 *var* to calculate the accumulated value, which ``!foldl`` stores back in
1710 *acc*. The type of *acc* is the same as *init*; the type of *var* is the
1711 same as the elements of *list*; *expr* must have the same type as *init*.
1713 The following example computes the total of the ``Number`` field in the
1714 list of records in ``RecList``::
1716 int x = !foldl(0, RecList, total, rec, !add(total, rec.Number));
1718 If your goal is to filter the list and produce a new list that includes only
1719 some of the elements, see ``!filter``.
1721 ``!foreach(``\ *var*\ ``,`` *sequence*\ ``,`` *expr*\ ``)``
1722 This operator creates a new ``list``/``dag`` in which each element is a
1723 function of the corresponding element in the *sequence* ``list``/``dag``.
1724 To perform the function, TableGen binds the variable *var* to an element
1725 and then evaluates the expression. The expression presumably refers
1726 to the variable *var* and calculates the result value.
1728 If you simply want to create a list of a certain length containing
1729 the same value repeated multiple times, see ``!listsplat``.
1731 ``!ge(``\ *a*\ `,` *b*\ ``)``
1732 This operator produces 1 if *a* is greater than or equal to *b*; 0 otherwise.
1733 The arguments must be ``bit``, ``bits``, ``int``, or ``string`` values.
1735 ``!getdagarg<``\ *type*\ ``>(``\ *dag*\ ``,``\ *key*\ ``)``
1736 This operator retrieves the argument from the given *dag* node by the
1737 specified *key*, which is either an integer index or a string name. If that
1738 argument is not convertible to the specified *type*, ``?`` is returned.
1740 ``!getdagname(``\ *dag*\ ``,``\ *index*\ ``)``
1741 This operator retrieves the argument name from the given *dag* node by the
1742 specified *index*. If that argument has no name associated, ``?`` is
1745 ``!getdagop(``\ *dag*\ ``)`` --or-- ``!getdagop<``\ *type*\ ``>(``\ *dag*\ ``)``
1746 This operator produces the operator of the given *dag* node.
1747 Example: ``!getdagop((foo 1, 2))`` results in ``foo``. Recall that
1748 DAG operators are always records.
1750 The result of ``!getdagop`` can be used directly in a context where
1751 any record class at all is acceptable (typically placing it into
1752 another dag value). But in other contexts, it must be explicitly
1753 cast to a particular class. The ``<``\ *type*\ ``>`` syntax is
1754 provided to make this easy.
1756 For example, to assign the result to a value of type ``BaseClass``, you
1757 could write either of these::
1759 BaseClass b = !getdagop<BaseClass>(someDag);
1760 BaseClass b = !cast<BaseClass>(!getdagop(someDag));
1762 But to create a new DAG node that reuses the operator from another, no
1765 dag d = !dag(!getdagop(someDag), args, names);
1767 ``!gt(``\ *a*\ `,` *b*\ ``)``
1768 This operator produces 1 if *a* is greater than *b*; 0 otherwise.
1769 The arguments must be ``bit``, ``bits``, ``int``, or ``string`` values.
1771 ``!head(``\ *a*\ ``)``
1772 This operator produces the zeroth element of the list *a*.
1773 (See also ``!tail``.)
1775 ``!if(``\ *test*\ ``,`` *then*\ ``,`` *else*\ ``)``
1776 This operator evaluates the *test*, which must produce a ``bit`` or
1777 ``int``. If the result is not 0, the *then* expression is produced; otherwise
1778 the *else* expression is produced.
1780 ``!interleave(``\ *list*\ ``,`` *delim*\ ``)``
1781 This operator concatenates the items in the *list*, interleaving the
1782 *delim* string between each pair, and produces the resulting string.
1783 The list can be a list of string, int, bits, or bit. An empty list
1784 results in an empty string. The delimiter can be the empty string.
1786 ``!isa<``\ *type*\ ``>(``\ *a*\ ``)``
1787 This operator produces 1 if the type of *a* is a subtype of the given *type*; 0
1790 ``!le(``\ *a*\ ``,`` *b*\ ``)``
1791 This operator produces 1 if *a* is less than or equal to *b*; 0 otherwise.
1792 The arguments must be ``bit``, ``bits``, ``int``, or ``string`` values.
1794 ``!listconcat(``\ *list1*\ ``,`` *list2*\ ``, ...)``
1795 This operator concatenates the list arguments *list1*, *list2*, etc., and
1796 produces the resulting list. The lists must have the same element type.
1798 ``!listremove(``\ *list1*\ ``,`` *list2*\ ``)``
1799 This operator returns a copy of *list1* removing all elements that also occur in
1800 *list2*. The lists must have the same element type.
1802 ``!listsplat(``\ *value*\ ``,`` *count*\ ``)``
1803 This operator produces a list of length *count* whose elements are all
1804 equal to the *value*. For example, ``!listsplat(42, 3)`` results in
1807 ``!logtwo(``\ *a*\ ``)``
1808 This operator produces the base 2 log of *a* and produces the integer
1809 result. The log of 0 or a negative number produces an error. This
1810 is a flooring operation.
1812 ``!lt(``\ *a*\ `,` *b*\ ``)``
1813 This operator produces 1 if *a* is less than *b*; 0 otherwise.
1814 The arguments must be ``bit``, ``bits``, ``int``, or ``string`` values.
1816 ``!mul(``\ *a*\ ``,`` *b*\ ``, ...)``
1817 This operator multiplies *a*, *b*, etc., and produces the product.
1819 ``!ne(``\ *a*\ `,` *b*\ ``)``
1820 This operator produces 1 if *a* is not equal to *b*; 0 otherwise.
1821 The arguments must be ``bit``, ``bits``, ``int``, ``string``,
1822 or record values. Use ``!cast<string>`` to compare other types of objects.
1824 ``!not(``\ *a*\ ``)``
1825 This operator performs a logical NOT on *a*, which must be
1826 an integer. The argument 0 results in 1 (true); any other
1827 argument results in 0 (false).
1829 ``!or(``\ *a*\ ``,`` *b*\ ``, ...)``
1830 This operator does a bitwise OR on *a*, *b*, etc., and produces the
1831 result. A logical OR can be performed if all the arguments are either
1834 ``!range([``\ *start*\ ``,]`` *end*\ ``[, ``\ *step*\ ``])``
1835 This operator produces half-open range sequence ``[start : end : step)`` as
1836 ``list<int>``. *start* is ``0`` and *step* is ``1`` by default. *step* can
1837 be negative and cannot be 0. If *start* ``<`` *end* and *step* is negative,
1838 or *start* ``>`` *end* and *step* is positive, the result is an empty list
1843 * ``!range(4)`` is equivalent to ``!range(0, 4, 1)`` and the result is
1845 * ``!range(1, 4)`` is equivalent to ``!range(1, 4, 1)`` and the result is
1847 * The result of ``!range(0, 4, 2)`` is `[0, 2]`.
1848 * The results of ``!range(0, 4, -1)`` and ``!range(4, 0, 1)`` are empty.
1850 ``!range(``\ *list*\ ``)``
1851 Equivalent to ``!range(0, !size(list))``.
1853 ``!setdagarg(``\ *dag*\ ``,``\ *key*\ ``,``\ *arg*\ ``)``
1854 This operator produces a DAG node with the same operator and arguments as
1855 *dag*, but replacing the value of the argument specified by the *key* with
1856 *arg*. That *key* could be either an integer index or a string name.
1858 ``!setdagname(``\ *dag*\ ``,``\ *key*\ ``,``\ *name*\ ``)``
1859 This operator produces a DAG node with the same operator and arguments as
1860 *dag*, but replacing the name of the argument specified by the *key* with
1861 *name*. That *key* could be either an integer index or a string name.
1863 ``!setdagop(``\ *dag*\ ``,`` *op*\ ``)``
1864 This operator produces a DAG node with the same arguments as *dag*, but with its
1865 operator replaced with *op*.
1867 Example: ``!setdagop((foo 1, 2), bar)`` results in ``(bar 1, 2)``.
1869 ``!shl(``\ *a*\ ``,`` *count*\ ``)``
1870 This operator shifts *a* left logically by *count* bits and produces the resulting
1871 value. The operation is performed on a 64-bit integer; the result
1872 is undefined for shift counts outside 0...63.
1874 ``!size(``\ *a*\ ``)``
1875 This operator produces the size of the string, list, or dag *a*.
1876 The size of a DAG is the number of arguments; the operator does not count.
1878 ``!sra(``\ *a*\ ``,`` *count*\ ``)``
1879 This operator shifts *a* right arithmetically by *count* bits and produces the resulting
1880 value. The operation is performed on a 64-bit integer; the result
1881 is undefined for shift counts outside 0...63.
1883 ``!srl(``\ *a*\ ``,`` *count*\ ``)``
1884 This operator shifts *a* right logically by *count* bits and produces the resulting
1885 value. The operation is performed on a 64-bit integer; the result
1886 is undefined for shift counts outside 0...63.
1888 ``!strconcat(``\ *str1*\ ``,`` *str2*\ ``, ...)``
1889 This operator concatenates the string arguments *str1*, *str2*, etc., and
1890 produces the resulting string.
1892 ``!sub(``\ *a*\ ``,`` *b*\ ``)``
1893 This operator subtracts *b* from *a* and produces the arithmetic difference.
1895 ``!subst(``\ *target*\ ``,`` *repl*\ ``,`` *value*\ ``)``
1896 This operator replaces all occurrences of the *target* in the *value* with
1897 the *repl* and produces the resulting value. The *value* can
1898 be a string, in which case substring substitution is performed.
1900 The *value* can be a record name, in which case the operator produces the *repl*
1901 record if the *target* record name equals the *value* record name; otherwise it
1902 produces the *value*.
1904 ``!substr(``\ *string*\ ``,`` *start*\ [``,`` *length*]\ ``)``
1905 This operator extracts a substring of the given *string*. The starting
1906 position of the substring is specified by *start*, which can range
1907 between 0 and the length of the string. The length of the substring
1908 is specified by *length*; if not specified, the rest of the string is
1909 extracted. The *start* and *length* arguments must be integers.
1911 ``!tail(``\ *a*\ ``)``
1912 This operator produces a new list with all the elements
1913 of the list *a* except for the zeroth one. (See also ``!head``.)
1915 ``!tolower(``\ *a*\ ``)``
1916 This operator converts a string input *a* to lower case.
1918 ``!toupper(``\ *a*\ ``)``
1919 This operator converts a string input *a* to upper case.
1921 ``!xor(``\ *a*\ ``,`` *b*\ ``, ...)``
1922 This operator does a bitwise EXCLUSIVE OR on *a*, *b*, etc., and produces
1923 the result. A logical XOR can be performed if all the arguments are either
1926 Appendix B: Paste Operator Examples
1927 ===================================
1929 Here is an example illustrating the use of the paste operator in record names.
1931 .. code-block:: text
1933 defvar suffix = "_suffstring";
1934 defvar some_ints = [0, 1, 2, 3];
1939 foreach i = [1, 2] in {
1944 The first ``def`` does not use the value of the ``suffix`` variable. The
1945 second def does use the value of the ``i`` iterator variable, because it is not a
1946 global name. The following records are produced.
1948 .. code-block:: text
1957 Here is a second example illustrating the paste operator in field value expressions.
1959 .. code-block:: text
1962 string strings = suffix # suffix;
1963 list<int> integers = some_ints # [4, 5, 6];
1966 The ``strings`` field expression uses ``suffix`` on both sides of the paste
1967 operator. It is evaluated normally on the left hand side, but taken verbatim
1968 on the right hand side. The ``integers`` field expression uses the value of
1969 the ``some_ints`` variable and a literal list. The following record is
1972 .. code-block:: text
1975 string strings = "_suffstringsuffix";
1976 list<int> ints = [0, 1, 2, 3, 4, 5, 6];
1980 Appendix C: Sample Record
1981 =========================
1983 One target machine supported by LLVM is the Intel x86. The following output
1984 from TableGen shows the record that is created to represent the 32-bit
1985 register-to-register ADD instruction.
1987 .. code-block:: text
1989 def ADD32rr { // InstructionEncoding Instruction X86Inst I ITy Sched BinOpRR BinOpRR_RF
1991 string DecoderNamespace = "";
1992 list<Predicate> Predicates = [];
1993 string DecoderMethod = "";
1994 bit hasCompleteDecoder = 1;
1995 string Namespace = "X86";
1996 dag OutOperandList = (outs GR32:$dst);
1997 dag InOperandList = (ins GR32:$src1, GR32:$src2);
1998 string AsmString = "add{l} {$src2, $src1|$src1, $src2}";
1999 EncodingByHwMode EncodingInfos = ?;
2000 list<dag> Pattern = [(set GR32:$dst, EFLAGS, (X86add_flag GR32:$src1, GR32:$src2))];
2001 list<Register> Uses = [];
2002 list<Register> Defs = [EFLAGS];
2004 int AddedComplexity = 0;
2005 bit isPreISelOpcode = 0;
2008 bit isEHScopeReturn = 0;
2009 bit isIndirectBranch = 0;
2019 bit canFoldAsLoad = 0;
2022 bit mayRaiseFPException = 0;
2023 bit isConvertibleToThreeAddress = 1;
2024 bit isCommutable = 1;
2025 bit isTerminator = 0;
2026 bit isReMaterializable = 0;
2027 bit isPredicable = 0;
2028 bit isUnpredicable = 0;
2029 bit hasDelaySlot = 0;
2030 bit usesCustomInserter = 0;
2031 bit hasPostISelHook = 0;
2033 bit isNotDuplicable = 0;
2034 bit isConvergent = 0;
2035 bit isAuthenticated = 0;
2036 bit isAsCheapAsAMove = 0;
2037 bit hasExtraSrcRegAllocReq = 0;
2038 bit hasExtraDefRegAllocReq = 0;
2039 bit isRegSequence = 0;
2041 bit isExtractSubreg = 0;
2042 bit isInsertSubreg = 0;
2043 bit variadicOpsAreDefs = 0;
2044 bit hasSideEffects = ?;
2045 bit isCodeGenOnly = 0;
2046 bit isAsmParserOnly = 0;
2047 bit hasNoSchedulingInfo = 0;
2048 InstrItinClass Itinerary = NoItinerary;
2049 list<SchedReadWrite> SchedRW = [WriteALU];
2050 string Constraints = "$src1 = $dst";
2051 string DisableEncoding = "";
2052 string PostEncoderMethod = "";
2053 bits<64> TSFlags = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0 };
2054 string AsmMatchConverter = "";
2055 string TwoOperandAliasConstraint = "";
2056 string AsmVariantName = "";
2057 bit UseNamedOperandTable = 0;
2058 bit FastISelShouldIgnore = 0;
2059 bits<8> Opcode = { 0, 0, 0, 0, 0, 0, 0, 1 };
2060 Format Form = MRMDestReg;
2061 bits<7> FormBits = { 0, 1, 0, 1, 0, 0, 0 };
2062 ImmType ImmT = NoImm;
2063 bit ForceDisassemble = 0;
2064 OperandSize OpSize = OpSize32;
2065 bits<2> OpSizeBits = { 1, 0 };
2066 AddressSize AdSize = AdSizeX;
2067 bits<2> AdSizeBits = { 0, 0 };
2068 Prefix OpPrefix = NoPrfx;
2069 bits<3> OpPrefixBits = { 0, 0, 0 };
2071 bits<3> OpMapBits = { 0, 0, 0 };
2072 bit hasREX_WPrefix = 0;
2073 FPFormat FPForm = NotFP;
2074 bit hasLockPrefix = 0;
2075 Domain ExeDomain = GenericDomain;
2076 bit hasREPPrefix = 0;
2077 Encoding OpEnc = EncNormal;
2078 bits<2> OpEncBits = { 0, 0 };
2080 bit IgnoresVEX_W = 0;
2081 bit EVEX_W1_VEX_W0 = 0;
2084 bit ignoresVEX_L = 0;
2089 bits<3> CD8_Form = { 0, 0, 0 };
2090 int CD8_EltSize = 0;
2092 bit hasNoTrackPrefix = 0;
2093 bits<7> VectSize = { 0, 0, 1, 0, 0, 0, 0 };
2094 bits<7> CD8_Scale = { 0, 0, 0, 0, 0, 0, 0 };
2095 string FoldGenRegForm = ?;
2096 string EVEX2VEXOverride = ?;
2097 bit isMemoryFoldable = 1;
2098 bit notEVEX2VEXConvertible = 0;
2101 On the first line of the record, you can see that the ``ADD32rr`` record
2102 inherited from eight classes. Although the inheritance hierarchy is complex,
2103 using parent classes is much simpler than specifying the 109 individual
2104 fields for each instruction.
2106 Here is the code fragment used to define ``ADD32rr`` and multiple other
2107 ``ADD`` instructions:
2109 .. code-block:: text
2111 defm ADD : ArithBinOp_RF<0x00, 0x02, 0x04, "add", MRM0r, MRM0m,
2112 X86add_flag, add, 1, 1, 1>;
2114 The ``defm`` statement tells TableGen that ``ArithBinOp_RF`` is a
2115 multiclass, which contains multiple concrete record definitions that inherit
2116 from ``BinOpRR_RF``. That class, in turn, inherits from ``BinOpRR``, which
2117 inherits from ``ITy`` and ``Sched``, and so forth. The fields are inherited
2118 from all the parent classes; for example, ``IsIndirectBranch`` is inherited
2119 from the ``Instruction`` class.