xref: /aosp_15_r20/external/llvm/docs/TableGen/index.rst (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker========
2*9880d681SAndroid Build Coastguard WorkerTableGen
3*9880d681SAndroid Build Coastguard Worker========
4*9880d681SAndroid Build Coastguard Worker
5*9880d681SAndroid Build Coastguard Worker.. contents::
6*9880d681SAndroid Build Coastguard Worker   :local:
7*9880d681SAndroid Build Coastguard Worker
8*9880d681SAndroid Build Coastguard Worker.. toctree::
9*9880d681SAndroid Build Coastguard Worker   :hidden:
10*9880d681SAndroid Build Coastguard Worker
11*9880d681SAndroid Build Coastguard Worker   BackEnds
12*9880d681SAndroid Build Coastguard Worker   LangRef
13*9880d681SAndroid Build Coastguard Worker   LangIntro
14*9880d681SAndroid Build Coastguard Worker   Deficiencies
15*9880d681SAndroid Build Coastguard Worker
16*9880d681SAndroid Build Coastguard WorkerIntroduction
17*9880d681SAndroid Build Coastguard Worker============
18*9880d681SAndroid Build Coastguard Worker
19*9880d681SAndroid Build Coastguard WorkerTableGen's purpose is to help a human develop and maintain records of
20*9880d681SAndroid Build Coastguard Workerdomain-specific information.  Because there may be a large number of these
21*9880d681SAndroid Build Coastguard Workerrecords, it is specifically designed to allow writing flexible descriptions and
22*9880d681SAndroid Build Coastguard Workerfor common features of these records to be factored out.  This reduces the
23*9880d681SAndroid Build Coastguard Workeramount of duplication in the description, reduces the chance of error, and makes
24*9880d681SAndroid Build Coastguard Workerit easier to structure domain specific information.
25*9880d681SAndroid Build Coastguard Worker
26*9880d681SAndroid Build Coastguard WorkerThe core part of TableGen parses a file, instantiates the declarations, and
27*9880d681SAndroid Build Coastguard Workerhands the result off to a domain-specific `backend`_ for processing.
28*9880d681SAndroid Build Coastguard Worker
29*9880d681SAndroid Build Coastguard WorkerThe current major users of TableGen are :doc:`../CodeGenerator`
30*9880d681SAndroid Build Coastguard Workerand the
31*9880d681SAndroid Build Coastguard Worker`Clang diagnostics and attributes <http://clang.llvm.org/docs/UsersManual.html#controlling-errors-and-warnings>`_.
32*9880d681SAndroid Build Coastguard Worker
33*9880d681SAndroid Build Coastguard WorkerNote that if you work on TableGen much, and use emacs or vim, that you can find
34*9880d681SAndroid Build Coastguard Workeran emacs "TableGen mode" and a vim language file in the ``llvm/utils/emacs`` and
35*9880d681SAndroid Build Coastguard Worker``llvm/utils/vim`` directories of your LLVM distribution, respectively.
36*9880d681SAndroid Build Coastguard Worker
37*9880d681SAndroid Build Coastguard Worker.. _intro:
38*9880d681SAndroid Build Coastguard Worker
39*9880d681SAndroid Build Coastguard Worker
40*9880d681SAndroid Build Coastguard WorkerThe TableGen program
41*9880d681SAndroid Build Coastguard Worker====================
42*9880d681SAndroid Build Coastguard Worker
43*9880d681SAndroid Build Coastguard WorkerTableGen files are interpreted by the TableGen program: `llvm-tblgen` available
44*9880d681SAndroid Build Coastguard Workeron your build directory under `bin`. It is not installed in the system (or where
45*9880d681SAndroid Build Coastguard Workeryour sysroot is set to), since it has no use beyond LLVM's build process.
46*9880d681SAndroid Build Coastguard Worker
47*9880d681SAndroid Build Coastguard WorkerRunning TableGen
48*9880d681SAndroid Build Coastguard Worker----------------
49*9880d681SAndroid Build Coastguard Worker
50*9880d681SAndroid Build Coastguard WorkerTableGen runs just like any other LLVM tool.  The first (optional) argument
51*9880d681SAndroid Build Coastguard Workerspecifies the file to read.  If a filename is not specified, ``llvm-tblgen``
52*9880d681SAndroid Build Coastguard Workerreads from standard input.
53*9880d681SAndroid Build Coastguard Worker
54*9880d681SAndroid Build Coastguard WorkerTo be useful, one of the `backends`_ must be used.  These backends are
55*9880d681SAndroid Build Coastguard Workerselectable on the command line (type '``llvm-tblgen -help``' for a list).  For
56*9880d681SAndroid Build Coastguard Workerexample, to get a list of all of the definitions that subclass a particular type
57*9880d681SAndroid Build Coastguard Worker(which can be useful for building up an enum list of these records), use the
58*9880d681SAndroid Build Coastguard Worker``-print-enums`` option:
59*9880d681SAndroid Build Coastguard Worker
60*9880d681SAndroid Build Coastguard Worker.. code-block:: bash
61*9880d681SAndroid Build Coastguard Worker
62*9880d681SAndroid Build Coastguard Worker  $ llvm-tblgen X86.td -print-enums -class=Register
63*9880d681SAndroid Build Coastguard Worker  AH, AL, AX, BH, BL, BP, BPL, BX, CH, CL, CX, DH, DI, DIL, DL, DX, EAX, EBP, EBX,
64*9880d681SAndroid Build Coastguard Worker  ECX, EDI, EDX, EFLAGS, EIP, ESI, ESP, FP0, FP1, FP2, FP3, FP4, FP5, FP6, IP,
65*9880d681SAndroid Build Coastguard Worker  MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7, R10, R10B, R10D, R10W, R11, R11B, R11D,
66*9880d681SAndroid Build Coastguard Worker  R11W, R12, R12B, R12D, R12W, R13, R13B, R13D, R13W, R14, R14B, R14D, R14W, R15,
67*9880d681SAndroid Build Coastguard Worker  R15B, R15D, R15W, R8, R8B, R8D, R8W, R9, R9B, R9D, R9W, RAX, RBP, RBX, RCX, RDI,
68*9880d681SAndroid Build Coastguard Worker  RDX, RIP, RSI, RSP, SI, SIL, SP, SPL, ST0, ST1, ST2, ST3, ST4, ST5, ST6, ST7,
69*9880d681SAndroid Build Coastguard Worker  XMM0, XMM1, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, XMM2, XMM3, XMM4, XMM5,
70*9880d681SAndroid Build Coastguard Worker  XMM6, XMM7, XMM8, XMM9,
71*9880d681SAndroid Build Coastguard Worker
72*9880d681SAndroid Build Coastguard Worker  $ llvm-tblgen X86.td -print-enums -class=Instruction
73*9880d681SAndroid Build Coastguard Worker  ABS_F, ABS_Fp32, ABS_Fp64, ABS_Fp80, ADC32mi, ADC32mi8, ADC32mr, ADC32ri,
74*9880d681SAndroid Build Coastguard Worker  ADC32ri8, ADC32rm, ADC32rr, ADC64mi32, ADC64mi8, ADC64mr, ADC64ri32, ADC64ri8,
75*9880d681SAndroid Build Coastguard Worker  ADC64rm, ADC64rr, ADD16mi, ADD16mi8, ADD16mr, ADD16ri, ADD16ri8, ADD16rm,
76*9880d681SAndroid Build Coastguard Worker  ADD16rr, ADD32mi, ADD32mi8, ADD32mr, ADD32ri, ADD32ri8, ADD32rm, ADD32rr,
77*9880d681SAndroid Build Coastguard Worker  ADD64mi32, ADD64mi8, ADD64mr, ADD64ri32, ...
78*9880d681SAndroid Build Coastguard Worker
79*9880d681SAndroid Build Coastguard WorkerThe default backend prints out all of the records.
80*9880d681SAndroid Build Coastguard Worker
81*9880d681SAndroid Build Coastguard WorkerIf you plan to use TableGen, you will most likely have to write a `backend`_
82*9880d681SAndroid Build Coastguard Workerthat extracts the information specific to what you need and formats it in the
83*9880d681SAndroid Build Coastguard Workerappropriate way.
84*9880d681SAndroid Build Coastguard Worker
85*9880d681SAndroid Build Coastguard WorkerExample
86*9880d681SAndroid Build Coastguard Worker-------
87*9880d681SAndroid Build Coastguard Worker
88*9880d681SAndroid Build Coastguard WorkerWith no other arguments, `llvm-tblgen` parses the specified file and prints out all
89*9880d681SAndroid Build Coastguard Workerof the classes, then all of the definitions.  This is a good way to see what the
90*9880d681SAndroid Build Coastguard Workervarious definitions expand to fully.  Running this on the ``X86.td`` file prints
91*9880d681SAndroid Build Coastguard Workerthis (at the time of this writing):
92*9880d681SAndroid Build Coastguard Worker
93*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm
94*9880d681SAndroid Build Coastguard Worker
95*9880d681SAndroid Build Coastguard Worker  ...
96*9880d681SAndroid Build Coastguard Worker  def ADD32rr {   // Instruction X86Inst I
97*9880d681SAndroid Build Coastguard Worker    string Namespace = "X86";
98*9880d681SAndroid Build Coastguard Worker    dag OutOperandList = (outs GR32:$dst);
99*9880d681SAndroid Build Coastguard Worker    dag InOperandList = (ins GR32:$src1, GR32:$src2);
100*9880d681SAndroid Build Coastguard Worker    string AsmString = "add{l}\t{$src2, $dst|$dst, $src2}";
101*9880d681SAndroid Build Coastguard Worker    list<dag> Pattern = [(set GR32:$dst, (add GR32:$src1, GR32:$src2))];
102*9880d681SAndroid Build Coastguard Worker    list<Register> Uses = [];
103*9880d681SAndroid Build Coastguard Worker    list<Register> Defs = [EFLAGS];
104*9880d681SAndroid Build Coastguard Worker    list<Predicate> Predicates = [];
105*9880d681SAndroid Build Coastguard Worker    int CodeSize = 3;
106*9880d681SAndroid Build Coastguard Worker    int AddedComplexity = 0;
107*9880d681SAndroid Build Coastguard Worker    bit isReturn = 0;
108*9880d681SAndroid Build Coastguard Worker    bit isBranch = 0;
109*9880d681SAndroid Build Coastguard Worker    bit isIndirectBranch = 0;
110*9880d681SAndroid Build Coastguard Worker    bit isBarrier = 0;
111*9880d681SAndroid Build Coastguard Worker    bit isCall = 0;
112*9880d681SAndroid Build Coastguard Worker    bit canFoldAsLoad = 0;
113*9880d681SAndroid Build Coastguard Worker    bit mayLoad = 0;
114*9880d681SAndroid Build Coastguard Worker    bit mayStore = 0;
115*9880d681SAndroid Build Coastguard Worker    bit isImplicitDef = 0;
116*9880d681SAndroid Build Coastguard Worker    bit isConvertibleToThreeAddress = 1;
117*9880d681SAndroid Build Coastguard Worker    bit isCommutable = 1;
118*9880d681SAndroid Build Coastguard Worker    bit isTerminator = 0;
119*9880d681SAndroid Build Coastguard Worker    bit isReMaterializable = 0;
120*9880d681SAndroid Build Coastguard Worker    bit isPredicable = 0;
121*9880d681SAndroid Build Coastguard Worker    bit hasDelaySlot = 0;
122*9880d681SAndroid Build Coastguard Worker    bit usesCustomInserter = 0;
123*9880d681SAndroid Build Coastguard Worker    bit hasCtrlDep = 0;
124*9880d681SAndroid Build Coastguard Worker    bit isNotDuplicable = 0;
125*9880d681SAndroid Build Coastguard Worker    bit hasSideEffects = 0;
126*9880d681SAndroid Build Coastguard Worker    InstrItinClass Itinerary = NoItinerary;
127*9880d681SAndroid Build Coastguard Worker    string Constraints = "";
128*9880d681SAndroid Build Coastguard Worker    string DisableEncoding = "";
129*9880d681SAndroid Build Coastguard Worker    bits<8> Opcode = { 0, 0, 0, 0, 0, 0, 0, 1 };
130*9880d681SAndroid Build Coastguard Worker    Format Form = MRMDestReg;
131*9880d681SAndroid Build Coastguard Worker    bits<6> FormBits = { 0, 0, 0, 0, 1, 1 };
132*9880d681SAndroid Build Coastguard Worker    ImmType ImmT = NoImm;
133*9880d681SAndroid Build Coastguard Worker    bits<3> ImmTypeBits = { 0, 0, 0 };
134*9880d681SAndroid Build Coastguard Worker    bit hasOpSizePrefix = 0;
135*9880d681SAndroid Build Coastguard Worker    bit hasAdSizePrefix = 0;
136*9880d681SAndroid Build Coastguard Worker    bits<4> Prefix = { 0, 0, 0, 0 };
137*9880d681SAndroid Build Coastguard Worker    bit hasREX_WPrefix = 0;
138*9880d681SAndroid Build Coastguard Worker    FPFormat FPForm = ?;
139*9880d681SAndroid Build Coastguard Worker    bits<3> FPFormBits = { 0, 0, 0 };
140*9880d681SAndroid Build Coastguard Worker  }
141*9880d681SAndroid Build Coastguard Worker  ...
142*9880d681SAndroid Build Coastguard Worker
143*9880d681SAndroid Build Coastguard WorkerThis definition corresponds to the 32-bit register-register ``add`` instruction
144*9880d681SAndroid Build Coastguard Workerof the x86 architecture.  ``def ADD32rr`` defines a record named
145*9880d681SAndroid Build Coastguard Worker``ADD32rr``, and the comment at the end of the line indicates the superclasses
146*9880d681SAndroid Build Coastguard Workerof the definition.  The body of the record contains all of the data that
147*9880d681SAndroid Build Coastguard WorkerTableGen assembled for the record, indicating that the instruction is part of
148*9880d681SAndroid Build Coastguard Workerthe "X86" namespace, the pattern indicating how the instruction is selected by
149*9880d681SAndroid Build Coastguard Workerthe code generator, that it is a two-address instruction, has a particular
150*9880d681SAndroid Build Coastguard Workerencoding, etc.  The contents and semantics of the information in the record are
151*9880d681SAndroid Build Coastguard Workerspecific to the needs of the X86 backend, and are only shown as an example.
152*9880d681SAndroid Build Coastguard Worker
153*9880d681SAndroid Build Coastguard WorkerAs you can see, a lot of information is needed for every instruction supported
154*9880d681SAndroid Build Coastguard Workerby the code generator, and specifying it all manually would be unmaintainable,
155*9880d681SAndroid Build Coastguard Workerprone to bugs, and tiring to do in the first place.  Because we are using
156*9880d681SAndroid Build Coastguard WorkerTableGen, all of the information was derived from the following definition:
157*9880d681SAndroid Build Coastguard Worker
158*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm
159*9880d681SAndroid Build Coastguard Worker
160*9880d681SAndroid Build Coastguard Worker  let Defs = [EFLAGS],
161*9880d681SAndroid Build Coastguard Worker      isCommutable = 1,                  // X = ADD Y,Z --> X = ADD Z,Y
162*9880d681SAndroid Build Coastguard Worker      isConvertibleToThreeAddress = 1 in // Can transform into LEA.
163*9880d681SAndroid Build Coastguard Worker  def ADD32rr  : I<0x01, MRMDestReg, (outs GR32:$dst),
164*9880d681SAndroid Build Coastguard Worker                                     (ins GR32:$src1, GR32:$src2),
165*9880d681SAndroid Build Coastguard Worker                   "add{l}\t{$src2, $dst|$dst, $src2}",
166*9880d681SAndroid Build Coastguard Worker                   [(set GR32:$dst, (add GR32:$src1, GR32:$src2))]>;
167*9880d681SAndroid Build Coastguard Worker
168*9880d681SAndroid Build Coastguard WorkerThis definition makes use of the custom class ``I`` (extended from the custom
169*9880d681SAndroid Build Coastguard Workerclass ``X86Inst``), which is defined in the X86-specific TableGen file, to
170*9880d681SAndroid Build Coastguard Workerfactor out the common features that instructions of its class share.  A key
171*9880d681SAndroid Build Coastguard Workerfeature of TableGen is that it allows the end-user to define the abstractions
172*9880d681SAndroid Build Coastguard Workerthey prefer to use when describing their information.
173*9880d681SAndroid Build Coastguard Worker
174*9880d681SAndroid Build Coastguard WorkerEach ``def`` record has a special entry called "NAME".  This is the name of the
175*9880d681SAndroid Build Coastguard Workerrecord ("``ADD32rr``" above).  In the general case ``def`` names can be formed
176*9880d681SAndroid Build Coastguard Workerfrom various kinds of string processing expressions and ``NAME`` resolves to the
177*9880d681SAndroid Build Coastguard Workerfinal value obtained after resolving all of those expressions.  The user may
178*9880d681SAndroid Build Coastguard Workerrefer to ``NAME`` anywhere she desires to use the ultimate name of the ``def``.
179*9880d681SAndroid Build Coastguard Worker``NAME`` should not be defined anywhere else in user code to avoid conflicts.
180*9880d681SAndroid Build Coastguard Worker
181*9880d681SAndroid Build Coastguard WorkerSyntax
182*9880d681SAndroid Build Coastguard Worker======
183*9880d681SAndroid Build Coastguard Worker
184*9880d681SAndroid Build Coastguard WorkerTableGen has a syntax that is loosely based on C++ templates, with built-in
185*9880d681SAndroid Build Coastguard Workertypes and specification. In addition, TableGen's syntax introduces some
186*9880d681SAndroid Build Coastguard Workerautomation concepts like multiclass, foreach, let, etc.
187*9880d681SAndroid Build Coastguard Worker
188*9880d681SAndroid Build Coastguard WorkerBasic concepts
189*9880d681SAndroid Build Coastguard Worker--------------
190*9880d681SAndroid Build Coastguard Worker
191*9880d681SAndroid Build Coastguard WorkerTableGen files consist of two key parts: 'classes' and 'definitions', both of
192*9880d681SAndroid Build Coastguard Workerwhich are considered 'records'.
193*9880d681SAndroid Build Coastguard Worker
194*9880d681SAndroid Build Coastguard Worker**TableGen records** have a unique name, a list of values, and a list of
195*9880d681SAndroid Build Coastguard Workersuperclasses.  The list of values is the main data that TableGen builds for each
196*9880d681SAndroid Build Coastguard Workerrecord; it is this that holds the domain specific information for the
197*9880d681SAndroid Build Coastguard Workerapplication.  The interpretation of this data is left to a specific `backend`_,
198*9880d681SAndroid Build Coastguard Workerbut the structure and format rules are taken care of and are fixed by
199*9880d681SAndroid Build Coastguard WorkerTableGen.
200*9880d681SAndroid Build Coastguard Worker
201*9880d681SAndroid Build Coastguard Worker**TableGen definitions** are the concrete form of 'records'.  These generally do
202*9880d681SAndroid Build Coastguard Workernot have any undefined values, and are marked with the '``def``' keyword.
203*9880d681SAndroid Build Coastguard Worker
204*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm
205*9880d681SAndroid Build Coastguard Worker
206*9880d681SAndroid Build Coastguard Worker  def FeatureFPARMv8 : SubtargetFeature<"fp-armv8", "HasFPARMv8", "true",
207*9880d681SAndroid Build Coastguard Worker                                        "Enable ARMv8 FP">;
208*9880d681SAndroid Build Coastguard Worker
209*9880d681SAndroid Build Coastguard WorkerIn this example, FeatureFPARMv8 is ``SubtargetFeature`` record initialised
210*9880d681SAndroid Build Coastguard Workerwith some values. The names of the classes are defined via the
211*9880d681SAndroid Build Coastguard Workerkeyword `class` either on the same file or some other included. Most target
212*9880d681SAndroid Build Coastguard WorkerTableGen files include the generic ones in ``include/llvm/Target``.
213*9880d681SAndroid Build Coastguard Worker
214*9880d681SAndroid Build Coastguard Worker**TableGen classes** are abstract records that are used to build and describe
215*9880d681SAndroid Build Coastguard Workerother records.  These classes allow the end-user to build abstractions for
216*9880d681SAndroid Build Coastguard Workereither the domain they are targeting (such as "Register", "RegisterClass", and
217*9880d681SAndroid Build Coastguard Worker"Instruction" in the LLVM code generator) or for the implementor to help factor
218*9880d681SAndroid Build Coastguard Workerout common properties of records (such as "FPInst", which is used to represent
219*9880d681SAndroid Build Coastguard Workerfloating point instructions in the X86 backend).  TableGen keeps track of all of
220*9880d681SAndroid Build Coastguard Workerthe classes that are used to build up a definition, so the backend can find all
221*9880d681SAndroid Build Coastguard Workerdefinitions of a particular class, such as "Instruction".
222*9880d681SAndroid Build Coastguard Worker
223*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm
224*9880d681SAndroid Build Coastguard Worker
225*9880d681SAndroid Build Coastguard Worker class ProcNoItin<string Name, list<SubtargetFeature> Features>
226*9880d681SAndroid Build Coastguard Worker       : Processor<Name, NoItineraries, Features>;
227*9880d681SAndroid Build Coastguard Worker
228*9880d681SAndroid Build Coastguard WorkerHere, the class ProcNoItin, receiving parameters `Name` of type `string` and
229*9880d681SAndroid Build Coastguard Workera list of target features is specializing the class Processor by passing the
230*9880d681SAndroid Build Coastguard Workerarguments down as well as hard-coding NoItineraries.
231*9880d681SAndroid Build Coastguard Worker
232*9880d681SAndroid Build Coastguard Worker**TableGen multiclasses** are groups of abstract records that are instantiated
233*9880d681SAndroid Build Coastguard Workerall at once.  Each instantiation can result in multiple TableGen definitions.
234*9880d681SAndroid Build Coastguard WorkerIf a multiclass inherits from another multiclass, the definitions in the
235*9880d681SAndroid Build Coastguard Workersub-multiclass become part of the current multiclass, as if they were declared
236*9880d681SAndroid Build Coastguard Workerin the current multiclass.
237*9880d681SAndroid Build Coastguard Worker
238*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm
239*9880d681SAndroid Build Coastguard Worker
240*9880d681SAndroid Build Coastguard Worker  multiclass ro_signed_pats<string T, string Rm, dag Base, dag Offset, dag Extend,
241*9880d681SAndroid Build Coastguard Worker                          dag address, ValueType sty> {
242*9880d681SAndroid Build Coastguard Worker  def : Pat<(i32 (!cast<SDNode>("sextload" # sty) address)),
243*9880d681SAndroid Build Coastguard Worker            (!cast<Instruction>("LDRS" # T # "w_" # Rm # "_RegOffset")
244*9880d681SAndroid Build Coastguard Worker              Base, Offset, Extend)>;
245*9880d681SAndroid Build Coastguard Worker
246*9880d681SAndroid Build Coastguard Worker  def : Pat<(i64 (!cast<SDNode>("sextload" # sty) address)),
247*9880d681SAndroid Build Coastguard Worker            (!cast<Instruction>("LDRS" # T # "x_" # Rm # "_RegOffset")
248*9880d681SAndroid Build Coastguard Worker              Base, Offset, Extend)>;
249*9880d681SAndroid Build Coastguard Worker  }
250*9880d681SAndroid Build Coastguard Worker
251*9880d681SAndroid Build Coastguard Worker  defm : ro_signed_pats<"B", Rm, Base, Offset, Extend,
252*9880d681SAndroid Build Coastguard Worker                        !foreach(decls.pattern, address,
253*9880d681SAndroid Build Coastguard Worker                                 !subst(SHIFT, imm_eq0, decls.pattern)),
254*9880d681SAndroid Build Coastguard Worker                        i8>;
255*9880d681SAndroid Build Coastguard Worker
256*9880d681SAndroid Build Coastguard Worker
257*9880d681SAndroid Build Coastguard Worker
258*9880d681SAndroid Build Coastguard WorkerSee the :doc:`TableGen Language Introduction <LangIntro>` for more generic
259*9880d681SAndroid Build Coastguard Workerinformation on the usage of the language, and the
260*9880d681SAndroid Build Coastguard Worker:doc:`TableGen Language Reference <LangRef>` for more in-depth description
261*9880d681SAndroid Build Coastguard Workerof the formal language specification.
262*9880d681SAndroid Build Coastguard Worker
263*9880d681SAndroid Build Coastguard Worker.. _backend:
264*9880d681SAndroid Build Coastguard Worker.. _backends:
265*9880d681SAndroid Build Coastguard Worker
266*9880d681SAndroid Build Coastguard WorkerTableGen backends
267*9880d681SAndroid Build Coastguard Worker=================
268*9880d681SAndroid Build Coastguard Worker
269*9880d681SAndroid Build Coastguard WorkerTableGen files have no real meaning without a back-end. The default operation
270*9880d681SAndroid Build Coastguard Workerof running ``llvm-tblgen`` is to print the information in a textual format, but
271*9880d681SAndroid Build Coastguard Workerthat's only useful for debugging of the TableGen files themselves. The power
272*9880d681SAndroid Build Coastguard Workerin TableGen is, however, to interpret the source files into an internal
273*9880d681SAndroid Build Coastguard Workerrepresentation that can be generated into anything you want.
274*9880d681SAndroid Build Coastguard Worker
275*9880d681SAndroid Build Coastguard WorkerCurrent usage of TableGen is to create huge include files with tables that you
276*9880d681SAndroid Build Coastguard Workercan either include directly (if the output is in the language you're coding),
277*9880d681SAndroid Build Coastguard Workeror be used in pre-processing via macros surrounding the include of the file.
278*9880d681SAndroid Build Coastguard Worker
279*9880d681SAndroid Build Coastguard WorkerDirect output can be used if the back-end already prints a table in C format
280*9880d681SAndroid Build Coastguard Workeror if the output is just a list of strings (for error and warning messages).
281*9880d681SAndroid Build Coastguard WorkerPre-processed output should be used if the same information needs to be used
282*9880d681SAndroid Build Coastguard Workerin different contexts (like Instruction names), so your back-end should print
283*9880d681SAndroid Build Coastguard Workera meta-information list that can be shaped into different compile-time formats.
284*9880d681SAndroid Build Coastguard Worker
285*9880d681SAndroid Build Coastguard WorkerSee the `TableGen BackEnds <BackEnds.html>`_ for more information.
286*9880d681SAndroid Build Coastguard Worker
287*9880d681SAndroid Build Coastguard WorkerTableGen Deficiencies
288*9880d681SAndroid Build Coastguard Worker=====================
289*9880d681SAndroid Build Coastguard Worker
290*9880d681SAndroid Build Coastguard WorkerDespite being very generic, TableGen has some deficiencies that have been
291*9880d681SAndroid Build Coastguard Workerpointed out numerous times. The common theme is that, while TableGen allows
292*9880d681SAndroid Build Coastguard Workeryou to build Domain-Specific-Languages, the final languages that you create
293*9880d681SAndroid Build Coastguard Workerlack the power of other DSLs, which in turn increase considerably the size
294*9880d681SAndroid Build Coastguard Workerand complexity of TableGen files.
295*9880d681SAndroid Build Coastguard Worker
296*9880d681SAndroid Build Coastguard WorkerAt the same time, TableGen allows you to create virtually any meaning of
297*9880d681SAndroid Build Coastguard Workerthe basic concepts via custom-made back-ends, which can pervert the original
298*9880d681SAndroid Build Coastguard Workerdesign and make it very hard for newcomers to understand the evil TableGen
299*9880d681SAndroid Build Coastguard Workerfile.
300*9880d681SAndroid Build Coastguard Worker
301*9880d681SAndroid Build Coastguard WorkerThere are some in favour of extending the semantics even more, but making sure
302*9880d681SAndroid Build Coastguard Workerback-ends adhere to strict rules. Others are suggesting we should move to less,
303*9880d681SAndroid Build Coastguard Workermore powerful DSLs designed with specific purposes, or even re-using existing
304*9880d681SAndroid Build Coastguard WorkerDSLs.
305*9880d681SAndroid Build Coastguard Worker
306*9880d681SAndroid Build Coastguard WorkerEither way, this is a discussion that will likely span across several years,
307*9880d681SAndroid Build Coastguard Workerif not decades. You can read more in the `TableGen Deficiencies <Deficiencies.html>`_
308*9880d681SAndroid Build Coastguard Workerdocument.
309