X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=docs%2FTableGenFundamentals.html;h=e8fca325130b559a377e052cea4e9d4f3e3a05bc;hb=a69d998664ef2d537d93ca4c923cde1b728aa7e0;hp=8cc6f90eac904a248c76329d9d3280bf3a363f92;hpb=3f47c292bc8ddba46cd45a6900ff756a87e8ec36;p=oota-llvm.git diff --git a/docs/TableGenFundamentals.html b/docs/TableGenFundamentals.html index 8cc6f90eac9..e8fca325130 100644 --- a/docs/TableGenFundamentals.html +++ b/docs/TableGenFundamentals.html @@ -7,9 +7,9 @@ -
TableGen Fundamentals
+

TableGen Fundamentals

-
+
-
Introduction
+

Introduction

-
+

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.

-
- - +

Basic concepts

-
+

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.

- +

An example record

-
+

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.

- +

Running TableGen

-
+

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 syntax

-
+

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 primitives

+ +
- +

TableGen comments

-
+

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:

This type represents a nestable directed graph of elements.
code
-
This represents a big hunk of text. NOTE: I don't remember why this is - distinct from string!
+
This represents a big hunk of text. This is lexically distinct from + string values because it doesn't require escapeing double quotes and other + common characters that occur in code.

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,11 @@ supported include:

string value
[{ ... }]
code fragment
-
[ X, Y, Z ]
-
list value.
+
[ X, Y, Z ]<type>
+
list value. <type> is the type of the list +element and is usually optional. In rare cases, +TableGen is unable to deduce the element type in +which case the user must specify it explicitly.
{ a, b, c }
initializer for a "bits<3>" value
value
@@ -398,11 +399,31 @@ supported include:

!strconcat(a, b)
A string value that is the result of concatenating the 'a' and 'b' strings.
-
!nameconcat<type>(a, b)
-
A value that is the result of concatenating the 'a' and 'b' - strings and looking up the resulting name in the symbol table. The symbol type - determines the type of the resulting value. If the symbol is not found - or the symbol type does not match 'type,' TableGen emits an error and aborts.
+
!cast<type>(a)
+
A symbol of type type obtained by looking up the string 'a' in +the symbol table. If the type of 'a' does not match type, TableGen +aborts with an error. !cast<string> is a special case in that the argument must +be an object defined by a 'def' construct.
+
!subst(a, b, c)
+
If 'a' and 'b' are of string type or are symbol references, substitute +'b' for 'a' in 'c.' This operation is analogous to $(subst) in GNU make.
+
!foreach(a, b, c)
+
For each member 'b' of dag or list 'a' apply operator 'c.' 'b' is a +dummy variable that should be declared as a member variable of an instantiated +class. This operation is analogous to $(foreach) in GNU make.
+
!head(a)
+
The first element of list 'a.'
+
!tail(a)
+
The 2nd-N elements of list 'a.'
+
!empty(a)
+
An integer {0,1} indicating whether list 'a' is empty.
+
!if(a,b,c)
+
'b' if the result of 'int' or 'bit' operator 'a' is nonzero, + 'c' otherwise.
+
!eq(a,b)
+
'bit 1' if string a is equal to string b, 0 otherwise. This + only operates on string, int and bit objects. Use !cast<string> to + compare other types of objects.

Note that all of the values have rules specifying how they convert to values @@ -411,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 @@ -451,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 @@ -470,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 @@ -497,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 @@ -588,11 +609,11 @@ X86 backend.

- + -
+

While classes with template arguments are a good way to factor commonality @@ -663,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' @@ -690,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 @@ -730,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>;
+
+
+ +
+ +
+ + +

Code Generator backend info

+ + +
+ +

Expressions used by code generator to describe instructions and isel +patterns:

+ +
+
(implicit a)
+
an implicitly defined physical register. This tells the dag instruction + selection emitter the input pattern's extra definitions matches implicit + physical register definitions.
+
- +

TableGen backends

-
+

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. @@ -754,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
- LLVM Compiler Infrastructure
+ LLVM Compiler Infrastructure
Last modified: $Date$