Skip to content

Commit ec15d70

Browse files
committed
Add overall description, file comments, some structure
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204479 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent a1d28f6 commit ec15d70

File tree

1 file changed

+138
-23
lines changed

1 file changed

+138
-23
lines changed

docs/TableGen/BackEnds.rst

Lines changed: 138 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,86 +32,201 @@ LLVM BackEnds
3232
of its purpose with a list of users, output generated from generic input, and
3333
finally why it needed a new backend (in case there's something similar).
3434

35-
Emitter
36-
-------
35+
Overall, each backend will take the same TableGen file type and transform into
36+
similar output for different targets/uses. There is an implicit contract between
37+
the TableGen files, the back-ends and their users.
38+
39+
For instance, a global contract is that each back-end produces macro-guarded
40+
sections. Based on whether the file is included by a header or a source file,
41+
or even in which context of each file the include is being used, you have
42+
todefine 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+
49+
And just part of the generated file would be included. This is useful if
50+
you need the same information in multiple formats (instantiation, initialization,
51+
getter/setter functions, etc) from the same source TableGen file without having
52+
to re-compile the TableGen file multiple times.
53+
54+
Sometimes, multiple macros might be defined before the same include file to
55+
output 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+
64+
The macros will be undef'd automatically as they're used, in the include file.
65+
66+
On all LLVM back-ends, the ``llvm-tblgen`` binary will be executed on the root
67+
TableGen file ``<Target>.td``, which should include all others. This guarantees
68+
that all information needed is accessible, and that no duplication is needed
69+
in the TbleGen files.
3770

38-
Generate machine code emitter.
71+
CodeEmitter
72+
-----------
73+
74+
**Purpose**: CodeEmitterGen uses the descriptions of instructions and their fields to
75+
construct an automated code emitter: a function that, given a MachineInstr,
76+
returns the (currently, 32-bit unsigned) value of the instruction.
77+
78+
**Output**: C++ code, implementing the target's CodeEmitter
79+
class by overriding the virtual functions as ``<Target>CodeEmitter::function()``.
80+
81+
**Usage**: Used to include directly at the end of ``<Target>CodeEmitter.cpp``, and
82+
with option `-mc-emitter` to be included in ``<Target>MCCodeEmitter.cpp``.
3983

4084
RegisterInfo
4185
------------
4286

43-
Generate registers and register classes info.
87+
**Purpose**: This tablegen backend is responsible for emitting a description of a target
88+
register file for a code generator. It uses instances of the Register,
89+
RegisterAliases, and RegisterClass classes to gather this information.
90+
91+
**Output**: C++ code with enums and structures representing the register mappings,
92+
properties, masks, etc.
93+
94+
**Usage**: Both on ``<Target>BaseRegisterInfo`` and ``<Target>MCTargetDesc`` (headers
95+
and source files) with macros defining in which they are for declaration vs.
96+
initialization issues.
4497

4598
InstrInfo
4699
---------
47100

48-
Generate instruction descriptions.
101+
**Purpose**: This tablegen backend is responsible for emitting a description of the target
102+
instruction set for the code generator. (what are the differences from CodeEmitter?)
103+
104+
**Output**: C++ code with enums and structures representing the register mappings,
105+
properties, masks, etc.
106+
107+
**Usage**: Both on ``<Target>BaseInstrInfo`` and ``<Target>MCTargetDesc`` (headers
108+
and source files) with macros defining in which they are for declaration vs.
49109

50110
AsmWriter
51111
---------
52112

53-
Generate calling convention descriptions.
113+
**Purpose**: Emits an assembly printer for the current target.
114+
115+
**Output**: Implementation of ``<Target>InstPrinter::printInstruction()``, among
116+
other things.
117+
118+
**Usage**: Included directly into ``InstPrinter/<Target>InstPrinter.cpp``.
54119

55120
AsmMatcher
56121
----------
57122

58-
Generate assembly writer.
123+
**Purpose**: Emits a target specifier matcher for
124+
converting parsed assembly operands in the MCInst structures. It also
125+
emits a matcher for custom operand parsing. Extensive documentation is
126+
written 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
131+
building the AsmParser class.
59132

60133
Disassembler
61134
------------
62135

63-
Generate disassembler.
136+
**Purpose**: Contains disassembler table emitters for various
137+
architectures. 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``
143+
to cater for all default decodings, after all hand-made ones.
64144

65145
PseudoLowering
66146
--------------
67147

68-
Generate pseudo instruction lowering.
148+
**Purpose**: Generate pseudo instruction lowering.
149+
150+
**Output**: Implements ``ARMAsmPrinter::emitPseudoExpansionLowering()``.
151+
152+
**Usage**: Included directly into ``<Target>AsmPrinter.cpp``.
69153

70154
CallingConv
71155
-----------
72156

73-
Generate assembly instruction matcher.
157+
**Purpose**: Responsible for emitting descriptions of the calling
158+
conventions supported by this target.
159+
160+
**Output**: Implement static functions to deal with calling conventions
161+
chained by matching styles, returning false on no match.
162+
163+
**Usage**: Used in ISelLowering and FastIsel as function pointers to
164+
implementation returned by a CC sellection function.
74165

75166
DAGISel
76167
-------
77168

78-
Generate a DAG instruction selector.
169+
**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
174+
implementation of ``SelectionDAGISel``.
79175

80176
DFAPacketizer
81177
-------------
82178

83-
Generate DFA Packetizer for VLIW targets.
179+
**Purpose**: This class parses the Schedule.td file and produces an API that
180+
can be used to reason about whether an instruction can be added to a packet
181+
on a VLIW architecture. The class internally generates a deterministic finite
182+
automaton (DFA) that models all possible mappings of machine instructions
183+
to 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``.
84188

85189
FastISel
86190
--------
87191

88-
Generate a "fast" instruction selector.
192+
**Purpose**: This tablegen backend emits code for use by the "fast"
193+
instruction selection algorithm. See the comments at the top of
194+
lib/CodeGen/SelectionDAG/FastISel.cpp for background. This file
195+
scans through the target's tablegen instruction-info files
196+
and extracts instructions with obvious-looking patterns, and it emits
197+
code 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
202+
of ``FastISel`` class.
89203

90204
Subtarget
91205
---------
92206

93-
Generate subtarget enumerations.
207+
**Purpose**: Generate subtarget enumerations.
94208

95-
Intrinsic
96-
---------
209+
**Output**: Enums, globals, local tables for sub-target information.
97210

98-
Generate intrinsic information.
211+
**Usage**: Populates ``<Target>Subtarget`` and
212+
``MCTargetDesc/<Target>MCTargetDesc`` files (both headers and source).
99213

100-
TgtIntrinsic
101-
------------
214+
Intrinsic
215+
---------
102216

103-
Generate target intrinsic information.
217+
**Purpose**: Generate (target) intrinsic information.
104218

105219
OptParserDefs
106220
-------------
107221

108-
Print enum values for a class.
222+
**Purpose**: Print enum values for a class.
109223

110224
CTags
111225
-----
112226

113-
Generate ctags-compatible index.
114-
227+
**Purpose**: This tablegen backend emits an index of definitions in ctags(1)
228+
format. A helper script, utils/TableGen/tdtags, provides an easier-to-use
229+
interface; run 'tdtags -H' for documentation.
115230

116231
Clang BackEnds
117232
==============

0 commit comments

Comments
 (0)