blob: 993134386f76965299b5f64e269e19e687e881bc [file] [log] [blame]
Renato Golinca105642014-03-20 16:08:34 +00001=================
2TableGen BackEnds
3=================
4
5.. contents::
6 :local:
7
8Introduction
9============
10
11TableGen backends are at the core of TableGen's functionality. The source files
12provide the semantics to a generated (in memory) structure, but it's up to the
13backend to print this out in a way that is meaningful to the user (normally a
14C program including a file or a textual list of warnings, options and error
15messages).
16
17TableGen is used by both LLVM and Clang with very different goals. LLVM uses it
18as a way to automate the generation of massive amounts of information regarding
19instructions, schedules, cores and architecture features. Some backends generate
20output that is consumed by more than one source file, so they need to be created
21in a way that is easy to use pre-processor tricks. Some backends can also print
22C code structures, so that they can be directly included as-is.
23
24Clang, on the other hand, uses it mainly for diagnostic messages (errors,
25warnings, tips) and attributes, so more on the textual end of the scale.
26
27LLVM BackEnds
28=============
29
30.. warning::
31 This document is raw. Each section below needs three sub-sections: description
32 of its purpose with a list of users, output generated from generic input, and
33 finally why it needed a new backend (in case there's something similar).
34
Renato Golin1014ec32014-03-21 16:49:43 +000035Overall, each backend will take the same TableGen file type and transform into
36similar output for different targets/uses. There is an implicit contract between
37the TableGen files, the back-ends and their users.
Renato Golinca105642014-03-20 16:08:34 +000038
Renato Golin1014ec32014-03-21 16:49:43 +000039For instance, a global contract is that each back-end produces macro-guarded
40sections. Based on whether the file is included by a header or a source file,
41or even in which context of each file the include is being used, you have
42todefine a macro just before including it, to get the right output:
43
44.. code-block:: c++
45
46 #define GET_REGINFO_TARGET_DESC
47 #include "ARMGenRegisterInfo.inc"
48
49And just part of the generated file would be included. This is useful if
50you need the same information in multiple formats (instantiation, initialization,
51getter/setter functions, etc) from the same source TableGen file without having
52to re-compile the TableGen file multiple times.
53
54Sometimes, multiple macros might be defined before the same include file to
55output multiple blocks:
56
57.. code-block:: c++
58
59 #define GET_REGISTER_MATCHER
60 #define GET_SUBTARGET_FEATURE_NAME
61 #define GET_MATCHER_IMPLEMENTATION
62 #include "ARMGenAsmMatcher.inc"
63
64The macros will be undef'd automatically as they're used, in the include file.
65
66On all LLVM back-ends, the ``llvm-tblgen`` binary will be executed on the root
67TableGen file ``<Target>.td``, which should include all others. This guarantees
68that all information needed is accessible, and that no duplication is needed
Yunzhong Gao1a012872016-07-20 00:40:54 +000069in the TableGen files.
Renato Golin1014ec32014-03-21 16:49:43 +000070
71CodeEmitter
72-----------
73
74**Purpose**: CodeEmitterGen uses the descriptions of instructions and their fields to
75construct an automated code emitter: a function that, given a MachineInstr,
76returns the (currently, 32-bit unsigned) value of the instruction.
77
78**Output**: C++ code, implementing the target's CodeEmitter
79class by overriding the virtual functions as ``<Target>CodeEmitter::function()``.
80
Eric Christopher79cc1e32014-09-02 22:28:02 +000081**Usage**: Used to include directly at the end of ``<Target>MCCodeEmitter.cpp``.
Renato Golinca105642014-03-20 16:08:34 +000082
83RegisterInfo
84------------
85
Renato Golin1014ec32014-03-21 16:49:43 +000086**Purpose**: This tablegen backend is responsible for emitting a description of a target
87register file for a code generator. It uses instances of the Register,
88RegisterAliases, and RegisterClass classes to gather this information.
89
90**Output**: C++ code with enums and structures representing the register mappings,
91properties, masks, etc.
92
93**Usage**: Both on ``<Target>BaseRegisterInfo`` and ``<Target>MCTargetDesc`` (headers
94and source files) with macros defining in which they are for declaration vs.
95initialization issues.
Renato Golinca105642014-03-20 16:08:34 +000096
97InstrInfo
98---------
99
Renato Golin1014ec32014-03-21 16:49:43 +0000100**Purpose**: This tablegen backend is responsible for emitting a description of the target
101instruction set for the code generator. (what are the differences from CodeEmitter?)
102
Yunzhong Gao1a012872016-07-20 00:40:54 +0000103**Output**: C++ code with enums and structures representing the instruction mappings,
Renato Golin1014ec32014-03-21 16:49:43 +0000104properties, masks, etc.
105
106**Usage**: Both on ``<Target>BaseInstrInfo`` and ``<Target>MCTargetDesc`` (headers
107and source files) with macros defining in which they are for declaration vs.
Yunzhong Gao1a012872016-07-20 00:40:54 +0000108initialization issues.
Renato Golinca105642014-03-20 16:08:34 +0000109
110AsmWriter
111---------
112
Renato Golin1014ec32014-03-21 16:49:43 +0000113**Purpose**: Emits an assembly printer for the current target.
114
115**Output**: Implementation of ``<Target>InstPrinter::printInstruction()``, among
116other things.
117
118**Usage**: Included directly into ``InstPrinter/<Target>InstPrinter.cpp``.
Renato Golinca105642014-03-20 16:08:34 +0000119
120AsmMatcher
121----------
122
Renato Golin1014ec32014-03-21 16:49:43 +0000123**Purpose**: Emits a target specifier matcher for
124converting parsed assembly operands in the MCInst structures. It also
125emits a matcher for custom operand parsing. Extensive documentation is
126written on the ``AsmMatcherEmitter.cpp`` file.
127
128**Output**: Assembler parsers' matcher functions, declarations, etc.
129
130**Usage**: Used in back-ends' ``AsmParser/<Target>AsmParser.cpp`` for
131building the AsmParser class.
Renato Golinca105642014-03-20 16:08:34 +0000132
133Disassembler
134------------
135
Renato Golin1014ec32014-03-21 16:49:43 +0000136**Purpose**: Contains disassembler table emitters for various
137architectures. Extensive documentation is written on the
138``DisassemblerEmitter.cpp`` file.
139
140**Output**: Decoding tables, static decoding functions, etc.
141
142**Usage**: Directly included in ``Disassembler/<Target>Disassembler.cpp``
143to cater for all default decodings, after all hand-made ones.
Renato Golinca105642014-03-20 16:08:34 +0000144
145PseudoLowering
146--------------
147
Renato Golin1014ec32014-03-21 16:49:43 +0000148**Purpose**: Generate pseudo instruction lowering.
149
Yunzhong Gao1a012872016-07-20 00:40:54 +0000150**Output**: Implements ``<Target>AsmPrinter::emitPseudoExpansionLowering()``.
Renato Golin1014ec32014-03-21 16:49:43 +0000151
152**Usage**: Included directly into ``<Target>AsmPrinter.cpp``.
Renato Golinca105642014-03-20 16:08:34 +0000153
154CallingConv
155-----------
156
Renato Golin1014ec32014-03-21 16:49:43 +0000157**Purpose**: Responsible for emitting descriptions of the calling
158conventions supported by this target.
159
160**Output**: Implement static functions to deal with calling conventions
161chained by matching styles, returning false on no match.
162
163**Usage**: Used in ISelLowering and FastIsel as function pointers to
Yunzhong Gao1a012872016-07-20 00:40:54 +0000164implementation returned by a CC selection function.
Renato Golinca105642014-03-20 16:08:34 +0000165
166DAGISel
167-------
168
Renato Golin1014ec32014-03-21 16:49:43 +0000169**Purpose**: Generate a DAG instruction selector.
170
171**Output**: Creates huge functions for automating DAG selection.
172
173**Usage**: Included in ``<Target>ISelDAGToDAG.cpp`` inside the target's
174implementation of ``SelectionDAGISel``.
Renato Golinca105642014-03-20 16:08:34 +0000175
176DFAPacketizer
177-------------
178
Renato Golin1014ec32014-03-21 16:49:43 +0000179**Purpose**: This class parses the Schedule.td file and produces an API that
180can be used to reason about whether an instruction can be added to a packet
181on a VLIW architecture. The class internally generates a deterministic finite
182automaton (DFA) that models all possible mappings of machine instructions
183to functional units as instructions are added to a packet.
184
185**Output**: Scheduling tables for GPU back-ends (Hexagon, AMD).
186
187**Usage**: Included directly on ``<Target>InstrInfo.cpp``.
Renato Golinca105642014-03-20 16:08:34 +0000188
189FastISel
190--------
191
Renato Golin1014ec32014-03-21 16:49:43 +0000192**Purpose**: This tablegen backend emits code for use by the "fast"
193instruction selection algorithm. See the comments at the top of
194lib/CodeGen/SelectionDAG/FastISel.cpp for background. This file
195scans through the target's tablegen instruction-info files
196and extracts instructions with obvious-looking patterns, and it emits
197code to look up these instructions by type and operator.
198
199**Output**: Generates ``Predicate`` and ``FastEmit`` methods.
200
201**Usage**: Implements private methods of the targets' implementation
202of ``FastISel`` class.
Renato Golinca105642014-03-20 16:08:34 +0000203
204Subtarget
205---------
206
Renato Golin1014ec32014-03-21 16:49:43 +0000207**Purpose**: Generate subtarget enumerations.
208
209**Output**: Enums, globals, local tables for sub-target information.
210
211**Usage**: Populates ``<Target>Subtarget`` and
212``MCTargetDesc/<Target>MCTargetDesc`` files (both headers and source).
Renato Golinca105642014-03-20 16:08:34 +0000213
214Intrinsic
215---------
216
Renato Golin1014ec32014-03-21 16:49:43 +0000217**Purpose**: Generate (target) intrinsic information.
Renato Golinca105642014-03-20 16:08:34 +0000218
219OptParserDefs
220-------------
221
Renato Golin1014ec32014-03-21 16:49:43 +0000222**Purpose**: Print enum values for a class.
Renato Golinca105642014-03-20 16:08:34 +0000223
224CTags
225-----
226
Renato Golin1014ec32014-03-21 16:49:43 +0000227**Purpose**: This tablegen backend emits an index of definitions in ctags(1)
228format. A helper script, utils/TableGen/tdtags, provides an easier-to-use
229interface; run 'tdtags -H' for documentation.
Renato Golinca105642014-03-20 16:08:34 +0000230
Ayman Musa850fc972017-03-07 08:11:19 +0000231X86EVEX2VEX
232-----------
233
234**Purpose**: This X86 specific tablegen backend emits tables that map EVEX
235encoded instructions to their VEX encoded identical instruction.
236
Renato Golinca105642014-03-20 16:08:34 +0000237Clang BackEnds
238==============
239
240ClangAttrClasses
241----------------
242
Aaron Ballman422e1f12014-03-24 18:18:31 +0000243**Purpose**: Creates Attrs.inc, which contains semantic attribute class
244declarations for any attribute in ``Attr.td`` that has not set ``ASTNode = 0``.
245This file is included as part of ``Attr.h``.
Renato Golinca105642014-03-20 16:08:34 +0000246
247ClangAttrParserStringSwitches
248-----------------------------
249
Aaron Ballman422e1f12014-03-24 18:18:31 +0000250**Purpose**: Creates AttrParserStringSwitches.inc, which contains
251StringSwitch::Case statements for parser-related string switches. Each switch
252is given its own macro (such as ``CLANG_ATTR_ARG_CONTEXT_LIST``, or
253``CLANG_ATTR_IDENTIFIER_ARG_LIST``), which is expected to be defined before
254including AttrParserStringSwitches.inc, and undefined after.
Renato Golinca105642014-03-20 16:08:34 +0000255
256ClangAttrImpl
257-------------
258
Aaron Ballman422e1f12014-03-24 18:18:31 +0000259**Purpose**: Creates AttrImpl.inc, which contains semantic attribute class
260definitions for any attribute in ``Attr.td`` that has not set ``ASTNode = 0``.
261This file is included as part of ``AttrImpl.cpp``.
Renato Golinca105642014-03-20 16:08:34 +0000262
263ClangAttrList
264-------------
265
Aaron Ballman422e1f12014-03-24 18:18:31 +0000266**Purpose**: Creates AttrList.inc, which is used when a list of semantic
267attribute identifiers is required. For instance, ``AttrKinds.h`` includes this
268file to generate the list of ``attr::Kind`` enumeration values. This list is
269separated out into multiple categories: attributes, inheritable attributes, and
270inheritable parameter attributes. This categorization happens automatically
271based on information in ``Attr.td`` and is used to implement the ``classof``
272functionality required for ``dyn_cast`` and similar APIs.
Renato Golinca105642014-03-20 16:08:34 +0000273
274ClangAttrPCHRead
275----------------
276
Aaron Ballman422e1f12014-03-24 18:18:31 +0000277**Purpose**: Creates AttrPCHRead.inc, which is used to deserialize attributes
278in the ``ASTReader::ReadAttributes`` function.
Renato Golinca105642014-03-20 16:08:34 +0000279
280ClangAttrPCHWrite
281-----------------
282
Aaron Ballman422e1f12014-03-24 18:18:31 +0000283**Purpose**: Creates AttrPCHWrite.inc, which is used to serialize attributes in
284the ``ASTWriter::WriteAttributes`` function.
Renato Golinca105642014-03-20 16:08:34 +0000285
Aaron Ballman422e1f12014-03-24 18:18:31 +0000286ClangAttrSpellings
Renato Golinca105642014-03-20 16:08:34 +0000287---------------------
288
Aaron Ballman422e1f12014-03-24 18:18:31 +0000289**Purpose**: Creates AttrSpellings.inc, which is used to implement the
290``__has_attribute`` feature test macro.
Renato Golinca105642014-03-20 16:08:34 +0000291
292ClangAttrSpellingListIndex
293--------------------------
294
Aaron Ballman422e1f12014-03-24 18:18:31 +0000295**Purpose**: Creates AttrSpellingListIndex.inc, which is used to map parsed
296attribute spellings (including which syntax or scope was used) to an attribute
297spelling list index. These spelling list index values are internal
298implementation details exposed via
299``AttributeList::getAttributeSpellingListIndex``.
Renato Golinca105642014-03-20 16:08:34 +0000300
Aaron Ballman422e1f12014-03-24 18:18:31 +0000301ClangAttrVisitor
Renato Golinca105642014-03-20 16:08:34 +0000302-------------------
303
Aaron Ballman422e1f12014-03-24 18:18:31 +0000304**Purpose**: Creates AttrVisitor.inc, which is used when implementing
305recursive AST visitors.
Renato Golinca105642014-03-20 16:08:34 +0000306
307ClangAttrTemplateInstantiate
308----------------------------
309
Aaron Ballman422e1f12014-03-24 18:18:31 +0000310**Purpose**: Creates AttrTemplateInstantiate.inc, which implements the
311``instantiateTemplateAttribute`` function, used when instantiating a template
312that requires an attribute to be cloned.
Renato Golinca105642014-03-20 16:08:34 +0000313
314ClangAttrParsedAttrList
315-----------------------
316
Aaron Ballman422e1f12014-03-24 18:18:31 +0000317**Purpose**: Creates AttrParsedAttrList.inc, which is used to generate the
318``AttributeList::Kind`` parsed attribute enumeration.
Renato Golinca105642014-03-20 16:08:34 +0000319
320ClangAttrParsedAttrImpl
321-----------------------
322
Aaron Ballman422e1f12014-03-24 18:18:31 +0000323**Purpose**: Creates AttrParsedAttrImpl.inc, which is used by
324``AttributeList.cpp`` to implement several functions on the ``AttributeList``
325class. This functionality is implemented via the ``AttrInfoMap ParsedAttrInfo``
326array, which contains one element per parsed attribute object.
Renato Golinca105642014-03-20 16:08:34 +0000327
328ClangAttrParsedAttrKinds
329------------------------
330
Aaron Ballman422e1f12014-03-24 18:18:31 +0000331**Purpose**: Creates AttrParsedAttrKinds.inc, which is used to implement the
332``AttributeList::getKind`` function, mapping a string (and syntax) to a parsed
333attribute ``AttributeList::Kind`` enumeration.
Renato Golinca105642014-03-20 16:08:34 +0000334
335ClangAttrDump
336-------------
337
Aaron Ballman422e1f12014-03-24 18:18:31 +0000338**Purpose**: Creates AttrDump.inc, which dumps information about an attribute.
339It is used to implement ``ASTDumper::dumpAttr``.
Renato Golinca105642014-03-20 16:08:34 +0000340
341ClangDiagsDefs
342--------------
343
344Generate Clang diagnostics definitions.
345
346ClangDiagGroups
347---------------
348
349Generate Clang diagnostic groups.
350
351ClangDiagsIndexName
352-------------------
353
354Generate Clang diagnostic name index.
355
356ClangCommentNodes
357-----------------
358
359Generate Clang AST comment nodes.
360
361ClangDeclNodes
362--------------
363
364Generate Clang AST declaration nodes.
365
366ClangStmtNodes
367--------------
368
369Generate Clang AST statement nodes.
370
371ClangSACheckers
372---------------
373
374Generate Clang Static Analyzer checkers.
375
376ClangCommentHTMLTags
377--------------------
378
379Generate efficient matchers for HTML tag names that are used in documentation comments.
380
381ClangCommentHTMLTagsProperties
382------------------------------
383
384Generate efficient matchers for HTML tag properties.
385
386ClangCommentHTMLNamedCharacterReferences
387----------------------------------------
388
389Generate function to translate named character references to UTF-8 sequences.
390
391ClangCommentCommandInfo
392-----------------------
393
394Generate command properties for commands that are used in documentation comments.
395
396ClangCommentCommandList
397-----------------------
398
399Generate list of commands that are used in documentation comments.
400
401ArmNeon
402-------
403
404Generate arm_neon.h for clang.
405
406ArmNeonSema
407-----------
408
409Generate ARM NEON sema support for clang.
410
411ArmNeonTest
412-----------
413
414Generate ARM NEON tests for clang.
415
416AttrDocs
417--------
418
Aaron Ballman422e1f12014-03-24 18:18:31 +0000419**Purpose**: Creates ``AttributeReference.rst`` from ``AttrDocs.td``, and is
420used for documenting user-facing attributes.
Renato Golinca105642014-03-20 16:08:34 +0000421
422How to write a back-end
423=======================
424
425TODO.
426
427Until we get a step-by-step HowTo for writing TableGen backends, you can at
428least grab the boilerplate (build system, new files, etc.) from Clang's
429r173931.
430
431TODO: How they work, how to write one. This section should not contain details
432about any particular backend, except maybe ``-print-enums`` as an example. This
433should highlight the APIs in ``TableGen/Record.h``.
434