X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=docs%2FTableGenFundamentals.html;h=e8fca325130b559a377e052cea4e9d4f3e3a05bc;hb=b3c4e26dc574fff3697d61c4c6c08df39af4a906;hp=5d64a0895295438d8ec25e53127fd98543b3ddeb;hpb=0d973999f3a7973e680e12acdf6def9d769911b6;p=oota-llvm.git diff --git a/docs/TableGenFundamentals.html b/docs/TableGenFundamentals.html index 5d64a089529..e8fca325130 100644 --- a/docs/TableGenFundamentals.html +++ b/docs/TableGenFundamentals.html @@ -7,9 +7,9 @@
-TableGen's purpose is to help a human develop and maintain records of domain-specific information. Because there may be a large number of these @@ -72,12 +72,10 @@ find an emacs "TableGen mode" and a vim language file in the llvm/utils/emacs and llvm/utils/vim directories of your LLVM distribution, respectively.
-TableGen files consist of two key parts: 'classes' and 'definitions', both of which are considered 'records'.
@@ -112,9 +110,9 @@ multiclass, as if they were declared in the current multiclass.With no other arguments, TableGen parses the specified file and prints out all of the classes, then all of the definitions. This is a good way to see what @@ -144,18 +142,16 @@ file prints this (at the time of this writing):
bit mayLoad = 0; bit mayStore = 0; bit isImplicitDef = 0; - bit isTwoAddress = 1; bit isConvertibleToThreeAddress = 1; bit isCommutable = 1; bit isTerminator = 0; bit isReMaterializable = 0; bit isPredicable = 0; bit hasDelaySlot = 0; - bit usesCustomDAGSchedInserter = 0; + bit usesCustomInserter = 0; bit hasCtrlDep = 0; bit isNotDuplicable = 0; bit hasSideEffects = 0; - bit mayHaveSideEffects = 0; bit neverHasSideEffects = 0; InstrItinClass Itinerary = NoItinerary; string Constraints = ""; @@ -189,7 +185,7 @@ backend, and is only shown as an example.As you can see, a lot of information is needed for every instruction supported by the code generator, and specifying it all manually would be -unmaintainble, prone to bugs, and tiring to do in the first place. Because we +unmaintainable, prone to bugs, and tiring to do in the first place. Because we are using TableGen, all of the information was derived from the following definition:
@@ -214,9 +210,9 @@ abstractions they prefer to use when describing their information.TableGen runs just like any other LLVM tool. The first (optional) argument specifies the file to read. If a filename is not specified, tblgen @@ -258,27 +254,28 @@ what you need and formats it in the appropriate way.
TableGen doesn't care about the meaning of data (that is up to the backend to define), but it does care about syntax, and it enforces a simple type system. This section describes the syntax and the constructs allowed in a TableGen file.
-TableGen supports BCPL style "//" comments, which run to the end of the line, and it also supports nestable "/* */" comments.
@@ -286,11 +283,11 @@ the line, and it also supports nestable "/* */" comments.TableGen files are strongly typed, in a simple (but complete) type-system. These types are used to perform automatic conversions, check for errors, and to @@ -334,8 +331,9 @@ The TableGen types are:
To date, these types have been sufficient for describing things that @@ -345,11 +343,11 @@ needed.
TableGen allows for a pretty reasonable number of different expression forms when building up values. These forms allow the TableGen file to be written in a @@ -371,8 +369,8 @@ supported include:
Note that all of the values have rules specifying how they convert to values @@ -444,12 +432,14 @@ to a "bits<4>" value, for example.
As mentioned in the intro, classes and definitions (collectively known as 'records') in TableGen are the main high-level unit of @@ -484,14 +474,12 @@ between a group of records and isolating it in a single place. Also, classes permit the specification of default values for their subclasses, allowing the subclasses to override them as they wish.
-Value definitions define named entries in records. A value must be defined before it can be referred to as the operand for another value definition or @@ -503,11 +491,11 @@ equal sign. Value definitions require terminating semicolons.
A record-level let expression is used to change the value of a value definition in a record. This is primarily useful when a superclass defines a @@ -530,11 +518,11 @@ because the D class overrode its value.
TableGen permits the definition of parameterized classes as well as normal concrete classes. Parameterized TableGen classes specify a list of variable @@ -621,11 +609,11 @@ X86 backend.
While classes with template arguments are a good way to factor commonality @@ -696,19 +684,108 @@ Here is an example TableGen fragment that shows this idea:
+A defm can also be used inside a multiclass providing several levels of +multiclass instanciations. +
+ ++class Instruction<bits<4> opc, string Name> { + bits<4> opcode = opc; + string name = Name; +} + +multiclass basic_r<bits<4> opc> { + def rr : Instruction<opc, "rr">; + def rm : Instruction<opc, "rm">; +} + +multiclass basic_s<bits<4> opc> { + defm SS : basic_r<opc>; + defm SD : basic_r<opc>; + def X : Instruction<opc, "x">; +} + +multiclass basic_p<bits<4> opc> { + defm PS : basic_r<opc>; + defm PD : basic_r<opc>; + def Y : Instruction<opc, "y">; +} + +defm ADD : basic_s<0xf>, basic_p<0xf>; +... + +// Results +def ADDPDrm { ... +def ADDPDrr { ... +def ADDPSrm { ... +def ADDPSrr { ... +def ADDSDrm { ... +def ADDSDrr { ... +def ADDY { ... +def ADDX { ... ++
+defm declarations can inherit from classes too, the +rule to follow is that the class list must start after the +last multiclass, and there must be at least one multiclass +before them. +
+ ++class XD { bits<4> Prefix = 11; } +class XS { bits<4> Prefix = 12; } + +class I<bits<4> op> { + bits<4> opcode = op; +} + +multiclass R { + def rr : I<4>; + def rm : I<2>; +} + +multiclass Y { + defm SS : R, XD; + defm SD : R, XS; +} + +defm Instr : Y; + +// Results +def InstrSDrm { + bits<4> opcode = { 0, 0, 1, 0 }; + bits<4> Prefix = { 1, 1, 0, 0 }; +} +... +def InstrSSrr { + bits<4> opcode = { 0, 1, 0, 0 }; + bits<4> Prefix = { 1, 0, 1, 1 }; +} ++
TableGen supports the 'include' token, which textually substitutes the specified file in place of the include directive. The filename should be specified as a double quoted string immediately after the 'include' @@ -723,11 +800,11 @@ keyword. Example:
"Let" expressions at file scope are similar to "let" expressions within a record, except they can specify a value binding for @@ -763,13 +840,59 @@ examples:
need to be added to several records, and the records do not otherwise need to be opened, as in the case with the CALL* instructions above. +It's also possible to use "let" expressions inside multiclasses, providing +more ways to factor out commonality from the records, specially if using +several levels of multiclass instanciations. This also avoids the need of using +"let" expressions within subsequent records inside a multiclass.
+ ++multiclass basic_r<bits<4> opc> { + let Predicates = [HasSSE2] in { + def rr : Instruction<opc, "rr">; + def rm : Instruction<opc, "rm">; + } + let Predicates = [HasSSE3] in + def rx : Instruction<opc, "rx">; +} + +multiclass basic_ss<bits<4> opc> { + let IsDouble = 0 in + defm SS : basic_r<opc>; + + let IsDouble = 1 in + defm SD : basic_r<opc>; +} + +defm ADD : basic_ss<0xf>; ++
Expressions used by code generator to describe instructions and isel +patterns:
+ +TODO: How they work, how to write one. This section should not contain details about any particular backend, except maybe -print-enums as an example. @@ -787,7 +910,7 @@ This should highlight the APIs in TableGen/Record.h.
src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01"> Chris Lattner