Renato Golin | 1625937 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 1 | ================= |
| 2 | TableGen BackEnds |
| 3 | ================= |
| 4 | |
| 5 | .. contents:: |
| 6 | :local: |
| 7 | |
| 8 | Introduction |
| 9 | ============ |
| 10 | |
| 11 | TableGen backends are at the core of TableGen's functionality. The source files |
| 12 | provide the semantics to a generated (in memory) structure, but it's up to the |
| 13 | backend to print this out in a way that is meaningful to the user (normally a |
| 14 | C program including a file or a textual list of warnings, options and error |
| 15 | messages). |
| 16 | |
| 17 | TableGen is used by both LLVM and Clang with very different goals. LLVM uses it |
| 18 | as a way to automate the generation of massive amounts of information regarding |
| 19 | instructions, schedules, cores and architecture features. Some backends generate |
| 20 | output that is consumed by more than one source file, so they need to be created |
| 21 | in a way that is easy to use pre-processor tricks. Some backends can also print |
| 22 | C code structures, so that they can be directly included as-is. |
| 23 | |
| 24 | Clang, on the other hand, uses it mainly for diagnostic messages (errors, |
| 25 | warnings, tips) and attributes, so more on the textual end of the scale. |
| 26 | |
| 27 | LLVM 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 Golin | ec15d70 | 2014-03-21 16:49:43 +0000 | [diff] [blame] | 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. |
Renato Golin | 1625937 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 38 | |
Renato Golin | ec15d70 | 2014-03-21 16:49:43 +0000 | [diff] [blame] | 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 |
Yunzhong Gao | 30f6cf7 | 2016-07-20 00:40:54 +0000 | [diff] [blame] | 69 | in the TableGen files. |
Renato Golin | ec15d70 | 2014-03-21 16:49:43 +0000 | [diff] [blame] | 70 | |
| 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 | |
Eric Christopher | d5dd8ce | 2014-09-02 22:28:02 +0000 | [diff] [blame] | 81 | **Usage**: Used to include directly at the end of ``<Target>MCCodeEmitter.cpp``. |
Renato Golin | 1625937 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 82 | |
| 83 | RegisterInfo |
| 84 | ------------ |
| 85 | |
Renato Golin | ec15d70 | 2014-03-21 16:49:43 +0000 | [diff] [blame] | 86 | **Purpose**: This tablegen backend is responsible for emitting a description of a target |
| 87 | register file for a code generator. It uses instances of the Register, |
| 88 | RegisterAliases, and RegisterClass classes to gather this information. |
| 89 | |
| 90 | **Output**: C++ code with enums and structures representing the register mappings, |
| 91 | properties, masks, etc. |
| 92 | |
| 93 | **Usage**: Both on ``<Target>BaseRegisterInfo`` and ``<Target>MCTargetDesc`` (headers |
| 94 | and source files) with macros defining in which they are for declaration vs. |
| 95 | initialization issues. |
Renato Golin | 1625937 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 96 | |
| 97 | InstrInfo |
| 98 | --------- |
| 99 | |
Renato Golin | ec15d70 | 2014-03-21 16:49:43 +0000 | [diff] [blame] | 100 | **Purpose**: This tablegen backend is responsible for emitting a description of the target |
| 101 | instruction set for the code generator. (what are the differences from CodeEmitter?) |
| 102 | |
Yunzhong Gao | 30f6cf7 | 2016-07-20 00:40:54 +0000 | [diff] [blame] | 103 | **Output**: C++ code with enums and structures representing the instruction mappings, |
Renato Golin | ec15d70 | 2014-03-21 16:49:43 +0000 | [diff] [blame] | 104 | properties, masks, etc. |
| 105 | |
| 106 | **Usage**: Both on ``<Target>BaseInstrInfo`` and ``<Target>MCTargetDesc`` (headers |
| 107 | and source files) with macros defining in which they are for declaration vs. |
Yunzhong Gao | 30f6cf7 | 2016-07-20 00:40:54 +0000 | [diff] [blame] | 108 | initialization issues. |
Renato Golin | 1625937 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 109 | |
| 110 | AsmWriter |
| 111 | --------- |
| 112 | |
Renato Golin | ec15d70 | 2014-03-21 16:49:43 +0000 | [diff] [blame] | 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``. |
Renato Golin | 1625937 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 119 | |
| 120 | AsmMatcher |
| 121 | ---------- |
| 122 | |
Renato Golin | ec15d70 | 2014-03-21 16:49:43 +0000 | [diff] [blame] | 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. |
Renato Golin | 1625937 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 132 | |
| 133 | Disassembler |
| 134 | ------------ |
| 135 | |
Renato Golin | ec15d70 | 2014-03-21 16:49:43 +0000 | [diff] [blame] | 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. |
Renato Golin | 1625937 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 144 | |
| 145 | PseudoLowering |
| 146 | -------------- |
| 147 | |
Renato Golin | ec15d70 | 2014-03-21 16:49:43 +0000 | [diff] [blame] | 148 | **Purpose**: Generate pseudo instruction lowering. |
| 149 | |
Yunzhong Gao | 30f6cf7 | 2016-07-20 00:40:54 +0000 | [diff] [blame] | 150 | **Output**: Implements ``<Target>AsmPrinter::emitPseudoExpansionLowering()``. |
Renato Golin | ec15d70 | 2014-03-21 16:49:43 +0000 | [diff] [blame] | 151 | |
| 152 | **Usage**: Included directly into ``<Target>AsmPrinter.cpp``. |
Renato Golin | 1625937 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 153 | |
| 154 | CallingConv |
| 155 | ----------- |
| 156 | |
Renato Golin | ec15d70 | 2014-03-21 16:49:43 +0000 | [diff] [blame] | 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 |
Yunzhong Gao | 30f6cf7 | 2016-07-20 00:40:54 +0000 | [diff] [blame] | 164 | implementation returned by a CC selection function. |
Renato Golin | 1625937 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 165 | |
| 166 | DAGISel |
| 167 | ------- |
| 168 | |
Renato Golin | ec15d70 | 2014-03-21 16:49:43 +0000 | [diff] [blame] | 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``. |
Renato Golin | 1625937 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 175 | |
| 176 | DFAPacketizer |
| 177 | ------------- |
| 178 | |
Renato Golin | ec15d70 | 2014-03-21 16:49:43 +0000 | [diff] [blame] | 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``. |
Renato Golin | 1625937 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 188 | |
| 189 | FastISel |
| 190 | -------- |
| 191 | |
Renato Golin | ec15d70 | 2014-03-21 16:49:43 +0000 | [diff] [blame] | 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. |
Renato Golin | 1625937 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 203 | |
| 204 | Subtarget |
| 205 | --------- |
| 206 | |
Renato Golin | ec15d70 | 2014-03-21 16:49:43 +0000 | [diff] [blame] | 207 | **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 Golin | 1625937 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 213 | |
| 214 | Intrinsic |
| 215 | --------- |
| 216 | |
Renato Golin | ec15d70 | 2014-03-21 16:49:43 +0000 | [diff] [blame] | 217 | **Purpose**: Generate (target) intrinsic information. |
Renato Golin | 1625937 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 218 | |
| 219 | OptParserDefs |
| 220 | ------------- |
| 221 | |
Renato Golin | ec15d70 | 2014-03-21 16:49:43 +0000 | [diff] [blame] | 222 | **Purpose**: Print enum values for a class. |
Renato Golin | 1625937 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 223 | |
Nicolai Haehnle | 2b1cd51 | 2018-06-21 13:36:22 +0000 | [diff] [blame] | 224 | SearchableTables |
| 225 | ---------------- |
| 226 | |
| 227 | **Purpose**: Generate custom searchable tables. |
| 228 | |
| 229 | **Output**: Enums, global tables and lookup helper functions. |
| 230 | |
| 231 | **Usage**: This backend allows generating free-form, target-specific tables |
| 232 | from TableGen records. The ARM and AArch64 targets use this backend to generate |
| 233 | tables of system registers; the AMDGPU target uses it to generate meta-data |
| 234 | about complex image and memory buffer instructions. |
| 235 | |
| 236 | More documentation is available in ``include/llvm/TableGen/SearchableTable.td``, |
| 237 | which also contains the definitions of TableGen classes which must be |
| 238 | instantiated in order to define the enums and tables emitted by this backend. |
| 239 | |
Renato Golin | 1625937 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 240 | CTags |
| 241 | ----- |
| 242 | |
Renato Golin | ec15d70 | 2014-03-21 16:49:43 +0000 | [diff] [blame] | 243 | **Purpose**: This tablegen backend emits an index of definitions in ctags(1) |
| 244 | format. A helper script, utils/TableGen/tdtags, provides an easier-to-use |
| 245 | interface; run 'tdtags -H' for documentation. |
Renato Golin | 1625937 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 246 | |
Ayman Musa | b59d804 | 2017-03-07 08:11:19 +0000 | [diff] [blame] | 247 | X86EVEX2VEX |
| 248 | ----------- |
| 249 | |
| 250 | **Purpose**: This X86 specific tablegen backend emits tables that map EVEX |
| 251 | encoded instructions to their VEX encoded identical instruction. |
| 252 | |
Renato Golin | 1625937 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 253 | Clang BackEnds |
| 254 | ============== |
| 255 | |
| 256 | ClangAttrClasses |
| 257 | ---------------- |
| 258 | |
Aaron Ballman | 9f00cd9 | 2014-03-24 18:18:31 +0000 | [diff] [blame] | 259 | **Purpose**: Creates Attrs.inc, which contains semantic attribute class |
| 260 | declarations for any attribute in ``Attr.td`` that has not set ``ASTNode = 0``. |
| 261 | This file is included as part of ``Attr.h``. |
Renato Golin | 1625937 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 262 | |
| 263 | ClangAttrParserStringSwitches |
| 264 | ----------------------------- |
| 265 | |
Aaron Ballman | 9f00cd9 | 2014-03-24 18:18:31 +0000 | [diff] [blame] | 266 | **Purpose**: Creates AttrParserStringSwitches.inc, which contains |
| 267 | StringSwitch::Case statements for parser-related string switches. Each switch |
| 268 | is given its own macro (such as ``CLANG_ATTR_ARG_CONTEXT_LIST``, or |
| 269 | ``CLANG_ATTR_IDENTIFIER_ARG_LIST``), which is expected to be defined before |
| 270 | including AttrParserStringSwitches.inc, and undefined after. |
Renato Golin | 1625937 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 271 | |
| 272 | ClangAttrImpl |
| 273 | ------------- |
| 274 | |
Aaron Ballman | 9f00cd9 | 2014-03-24 18:18:31 +0000 | [diff] [blame] | 275 | **Purpose**: Creates AttrImpl.inc, which contains semantic attribute class |
| 276 | definitions for any attribute in ``Attr.td`` that has not set ``ASTNode = 0``. |
| 277 | This file is included as part of ``AttrImpl.cpp``. |
Renato Golin | 1625937 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 278 | |
| 279 | ClangAttrList |
| 280 | ------------- |
| 281 | |
Aaron Ballman | 9f00cd9 | 2014-03-24 18:18:31 +0000 | [diff] [blame] | 282 | **Purpose**: Creates AttrList.inc, which is used when a list of semantic |
| 283 | attribute identifiers is required. For instance, ``AttrKinds.h`` includes this |
| 284 | file to generate the list of ``attr::Kind`` enumeration values. This list is |
| 285 | separated out into multiple categories: attributes, inheritable attributes, and |
| 286 | inheritable parameter attributes. This categorization happens automatically |
| 287 | based on information in ``Attr.td`` and is used to implement the ``classof`` |
| 288 | functionality required for ``dyn_cast`` and similar APIs. |
Renato Golin | 1625937 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 289 | |
| 290 | ClangAttrPCHRead |
| 291 | ---------------- |
| 292 | |
Aaron Ballman | 9f00cd9 | 2014-03-24 18:18:31 +0000 | [diff] [blame] | 293 | **Purpose**: Creates AttrPCHRead.inc, which is used to deserialize attributes |
| 294 | in the ``ASTReader::ReadAttributes`` function. |
Renato Golin | 1625937 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 295 | |
| 296 | ClangAttrPCHWrite |
| 297 | ----------------- |
| 298 | |
Aaron Ballman | 9f00cd9 | 2014-03-24 18:18:31 +0000 | [diff] [blame] | 299 | **Purpose**: Creates AttrPCHWrite.inc, which is used to serialize attributes in |
| 300 | the ``ASTWriter::WriteAttributes`` function. |
Renato Golin | 1625937 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 301 | |
Aaron Ballman | 9f00cd9 | 2014-03-24 18:18:31 +0000 | [diff] [blame] | 302 | ClangAttrSpellings |
Renato Golin | 1625937 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 303 | --------------------- |
| 304 | |
Aaron Ballman | 9f00cd9 | 2014-03-24 18:18:31 +0000 | [diff] [blame] | 305 | **Purpose**: Creates AttrSpellings.inc, which is used to implement the |
| 306 | ``__has_attribute`` feature test macro. |
Renato Golin | 1625937 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 307 | |
| 308 | ClangAttrSpellingListIndex |
| 309 | -------------------------- |
| 310 | |
Aaron Ballman | 9f00cd9 | 2014-03-24 18:18:31 +0000 | [diff] [blame] | 311 | **Purpose**: Creates AttrSpellingListIndex.inc, which is used to map parsed |
| 312 | attribute spellings (including which syntax or scope was used) to an attribute |
| 313 | spelling list index. These spelling list index values are internal |
| 314 | implementation details exposed via |
| 315 | ``AttributeList::getAttributeSpellingListIndex``. |
Renato Golin | 1625937 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 316 | |
Aaron Ballman | 9f00cd9 | 2014-03-24 18:18:31 +0000 | [diff] [blame] | 317 | ClangAttrVisitor |
Renato Golin | 1625937 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 318 | ------------------- |
| 319 | |
Aaron Ballman | 9f00cd9 | 2014-03-24 18:18:31 +0000 | [diff] [blame] | 320 | **Purpose**: Creates AttrVisitor.inc, which is used when implementing |
| 321 | recursive AST visitors. |
Renato Golin | 1625937 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 322 | |
| 323 | ClangAttrTemplateInstantiate |
| 324 | ---------------------------- |
| 325 | |
Aaron Ballman | 9f00cd9 | 2014-03-24 18:18:31 +0000 | [diff] [blame] | 326 | **Purpose**: Creates AttrTemplateInstantiate.inc, which implements the |
| 327 | ``instantiateTemplateAttribute`` function, used when instantiating a template |
| 328 | that requires an attribute to be cloned. |
Renato Golin | 1625937 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 329 | |
| 330 | ClangAttrParsedAttrList |
| 331 | ----------------------- |
| 332 | |
Aaron Ballman | 9f00cd9 | 2014-03-24 18:18:31 +0000 | [diff] [blame] | 333 | **Purpose**: Creates AttrParsedAttrList.inc, which is used to generate the |
| 334 | ``AttributeList::Kind`` parsed attribute enumeration. |
Renato Golin | 1625937 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 335 | |
| 336 | ClangAttrParsedAttrImpl |
| 337 | ----------------------- |
| 338 | |
Aaron Ballman | 9f00cd9 | 2014-03-24 18:18:31 +0000 | [diff] [blame] | 339 | **Purpose**: Creates AttrParsedAttrImpl.inc, which is used by |
| 340 | ``AttributeList.cpp`` to implement several functions on the ``AttributeList`` |
| 341 | class. This functionality is implemented via the ``AttrInfoMap ParsedAttrInfo`` |
| 342 | array, which contains one element per parsed attribute object. |
Renato Golin | 1625937 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 343 | |
| 344 | ClangAttrParsedAttrKinds |
| 345 | ------------------------ |
| 346 | |
Aaron Ballman | 9f00cd9 | 2014-03-24 18:18:31 +0000 | [diff] [blame] | 347 | **Purpose**: Creates AttrParsedAttrKinds.inc, which is used to implement the |
| 348 | ``AttributeList::getKind`` function, mapping a string (and syntax) to a parsed |
| 349 | attribute ``AttributeList::Kind`` enumeration. |
Renato Golin | 1625937 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 350 | |
| 351 | ClangAttrDump |
| 352 | ------------- |
| 353 | |
Aaron Ballman | 9f00cd9 | 2014-03-24 18:18:31 +0000 | [diff] [blame] | 354 | **Purpose**: Creates AttrDump.inc, which dumps information about an attribute. |
| 355 | It is used to implement ``ASTDumper::dumpAttr``. |
Renato Golin | 1625937 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 356 | |
| 357 | ClangDiagsDefs |
| 358 | -------------- |
| 359 | |
| 360 | Generate Clang diagnostics definitions. |
| 361 | |
| 362 | ClangDiagGroups |
| 363 | --------------- |
| 364 | |
| 365 | Generate Clang diagnostic groups. |
| 366 | |
| 367 | ClangDiagsIndexName |
| 368 | ------------------- |
| 369 | |
| 370 | Generate Clang diagnostic name index. |
| 371 | |
| 372 | ClangCommentNodes |
| 373 | ----------------- |
| 374 | |
| 375 | Generate Clang AST comment nodes. |
| 376 | |
| 377 | ClangDeclNodes |
| 378 | -------------- |
| 379 | |
| 380 | Generate Clang AST declaration nodes. |
| 381 | |
| 382 | ClangStmtNodes |
| 383 | -------------- |
| 384 | |
| 385 | Generate Clang AST statement nodes. |
| 386 | |
| 387 | ClangSACheckers |
| 388 | --------------- |
| 389 | |
| 390 | Generate Clang Static Analyzer checkers. |
| 391 | |
| 392 | ClangCommentHTMLTags |
| 393 | -------------------- |
| 394 | |
| 395 | Generate efficient matchers for HTML tag names that are used in documentation comments. |
| 396 | |
| 397 | ClangCommentHTMLTagsProperties |
| 398 | ------------------------------ |
| 399 | |
| 400 | Generate efficient matchers for HTML tag properties. |
| 401 | |
| 402 | ClangCommentHTMLNamedCharacterReferences |
| 403 | ---------------------------------------- |
| 404 | |
| 405 | Generate function to translate named character references to UTF-8 sequences. |
| 406 | |
| 407 | ClangCommentCommandInfo |
| 408 | ----------------------- |
| 409 | |
| 410 | Generate command properties for commands that are used in documentation comments. |
| 411 | |
| 412 | ClangCommentCommandList |
| 413 | ----------------------- |
| 414 | |
| 415 | Generate list of commands that are used in documentation comments. |
| 416 | |
| 417 | ArmNeon |
| 418 | ------- |
| 419 | |
| 420 | Generate arm_neon.h for clang. |
| 421 | |
| 422 | ArmNeonSema |
| 423 | ----------- |
| 424 | |
| 425 | Generate ARM NEON sema support for clang. |
| 426 | |
| 427 | ArmNeonTest |
| 428 | ----------- |
| 429 | |
| 430 | Generate ARM NEON tests for clang. |
| 431 | |
| 432 | AttrDocs |
| 433 | -------- |
| 434 | |
Aaron Ballman | 9f00cd9 | 2014-03-24 18:18:31 +0000 | [diff] [blame] | 435 | **Purpose**: Creates ``AttributeReference.rst`` from ``AttrDocs.td``, and is |
| 436 | used for documenting user-facing attributes. |
Renato Golin | 1625937 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 437 | |
Simon Tatham | 9cfd4e5 | 2018-07-11 08:40:19 +0000 | [diff] [blame] | 438 | General BackEnds |
| 439 | ================ |
| 440 | |
| 441 | JSON |
| 442 | ---- |
| 443 | |
| 444 | **Purpose**: Output all the values in every ``def``, as a JSON data |
| 445 | structure that can be easily parsed by a variety of languages. Useful |
| 446 | for writing custom backends without having to modify TableGen itself, |
| 447 | or for performing auxiliary analysis on the same TableGen data passed |
| 448 | to a built-in backend. |
| 449 | |
| 450 | **Output**: |
| 451 | |
| 452 | The root of the output file is a JSON object (i.e. dictionary), |
| 453 | containing the following fixed keys: |
| 454 | |
| 455 | * ``!tablegen_json_version``: a numeric version field that will |
| 456 | increase if an incompatible change is ever made to the structure of |
| 457 | this data. The format described here corresponds to version 1. |
| 458 | |
| 459 | * ``!instanceof``: a dictionary whose keys are the class names defined |
| 460 | in the TableGen input. For each key, the corresponding value is an |
| 461 | array of strings giving the names of ``def`` records that derive |
| 462 | from that class. So ``root["!instanceof"]["Instruction"]``, for |
| 463 | example, would list the names of all the records deriving from the |
| 464 | class ``Instruction``. |
| 465 | |
| 466 | For each ``def`` record, the root object also has a key for the record |
| 467 | name. The corresponding value is a subsidiary object containing the |
| 468 | following fixed keys: |
| 469 | |
| 470 | * ``!superclasses``: an array of strings giving the names of all the |
| 471 | classes that this record derives from. |
| 472 | |
| 473 | * ``!fields``: an array of strings giving the names of all the variables |
| 474 | in this record that were defined with the ``field`` keyword. |
| 475 | |
| 476 | * ``!name``: a string giving the name of the record. This is always |
| 477 | identical to the key in the JSON root object corresponding to this |
| 478 | record's dictionary. (If the record is anonymous, the name is |
| 479 | arbitrary.) |
| 480 | |
| 481 | * ``!anonymous``: a boolean indicating whether the record's name was |
| 482 | specified by the TableGen input (if it is ``false``), or invented by |
| 483 | TableGen itself (if ``true``). |
| 484 | |
| 485 | For each variable defined in a record, the ``def`` object for that |
| 486 | record also has a key for the variable name. The corresponding value |
| 487 | is a translation into JSON of the variable's value, using the |
| 488 | conventions described below. |
| 489 | |
| 490 | Some TableGen data types are translated directly into the |
| 491 | corresponding JSON type: |
| 492 | |
| 493 | * A completely undefined value (e.g. for a variable declared without |
| 494 | initializer in some superclass of this record, and never initialized |
| 495 | by the record itself or any other superclass) is emitted as the JSON |
| 496 | ``null`` value. |
| 497 | |
| 498 | * ``int`` and ``bit`` values are emitted as numbers. Note that |
| 499 | TableGen ``int`` values are capable of holding integers too large to |
| 500 | be exactly representable in IEEE double precision. The integer |
| 501 | literal in the JSON output will show the full exact integer value. |
| 502 | So if you need to retrieve large integers with full precision, you |
| 503 | should use a JSON reader capable of translating such literals back |
| 504 | into 64-bit integers without losing precision, such as Python's |
| 505 | standard ``json`` module. |
| 506 | |
| 507 | * ``string`` and ``code`` values are emitted as JSON strings. |
| 508 | |
| 509 | * ``list<T>`` values, for any element type ``T``, are emitted as JSON |
| 510 | arrays. Each element of the array is represented in turn using these |
| 511 | same conventions. |
| 512 | |
| 513 | * ``bits`` values are also emitted as arrays. A ``bits`` array is |
| 514 | ordered from least-significant bit to most-significant. So the |
| 515 | element with index ``i`` corresponds to the bit described as |
| 516 | ``x{i}`` in TableGen source. However, note that this means that |
| 517 | scripting languages are likely to *display* the array in the |
| 518 | opposite order from the way it appears in the TableGen source or in |
| 519 | the diagnostic ``-print-records`` output. |
| 520 | |
| 521 | All other TableGen value types are emitted as a JSON object, |
| 522 | containing two standard fields: ``kind`` is a discriminator describing |
| 523 | which kind of value the object represents, and ``printable`` is a |
| 524 | string giving the same representation of the value that would appear |
| 525 | in ``-print-records``. |
| 526 | |
| 527 | * A reference to a ``def`` object has ``kind=="def"``, and has an |
| 528 | extra field ``def`` giving the name of the object referred to. |
| 529 | |
| 530 | * A reference to another variable in the same record has |
| 531 | ``kind=="var"``, and has an extra field ``var`` giving the name of |
| 532 | the variable referred to. |
| 533 | |
| 534 | * A reference to a specific bit of a ``bits``-typed variable in the |
| 535 | same record has ``kind=="varbit"``, and has two extra fields: |
| 536 | ``var`` gives the name of the variable referred to, and ``index`` |
| 537 | gives the index of the bit. |
| 538 | |
| 539 | * A value of type ``dag`` has ``kind=="dag"``, and has two extra |
| 540 | fields. ``operator`` gives the initial value after the opening |
| 541 | parenthesis of the dag initializer; ``args`` is an array giving the |
| 542 | following arguments. The elements of ``args`` are arrays of length |
| 543 | 2, giving the value of each argument followed by its colon-suffixed |
| 544 | name (if any). For example, in the JSON representation of the dag |
| 545 | value ``(Op 22, "hello":$foo)`` (assuming that ``Op`` is the name of |
| 546 | a record defined elsewhere with a ``def`` statement): |
| 547 | |
| 548 | * ``operator`` will be an object in which ``kind=="def"`` and |
| 549 | ``def=="Op"`` |
| 550 | |
| 551 | * ``args`` will be the array ``[[22, null], ["hello", "foo"]]``. |
| 552 | |
| 553 | * If any other kind of value or complicated expression appears in the |
| 554 | output, it will have ``kind=="complex"``, and no additional fields. |
| 555 | These values are not expected to be needed by backends. The standard |
| 556 | ``printable`` field can be used to extract a representation of them |
| 557 | in TableGen source syntax if necessary. |
| 558 | |
Renato Golin | 1625937 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 559 | How to write a back-end |
| 560 | ======================= |
| 561 | |
| 562 | TODO. |
| 563 | |
| 564 | Until we get a step-by-step HowTo for writing TableGen backends, you can at |
| 565 | least grab the boilerplate (build system, new files, etc.) from Clang's |
| 566 | r173931. |
| 567 | |
| 568 | TODO: How they work, how to write one. This section should not contain details |
| 569 | about any particular backend, except maybe ``-print-enums`` as an example. This |
| 570 | should highlight the APIs in ``TableGen/Record.h``. |
| 571 | |