X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=docs%2FTableGenFundamentals.html;h=90836e91bda8462c73e1fd213438a42e7aaabc62;hb=d525f664c92bc285c80484015f7aaa8fc17c4cb3;hp=0542722100387e6d09eca82d6180cc9c05daba49;hpb=78b648c5e35f28382691ec32ec39ca3e1ede94c0;p=oota-llvm.git diff --git a/docs/TableGenFundamentals.html b/docs/TableGenFundamentals.html index 05427221003..90836e91bda 100644 --- a/docs/TableGenFundamentals.html +++ b/docs/TableGenFundamentals.html @@ -30,6 +30,7 @@
The core part of TableGen parses a file, instantiates the declarations, and hands the result off to a domain-specific "TableGen backend" for processing. The current major user -of TableGen is the LLVM code generator.
+of TableGen is the LLVM code generator.Note that if you work on TableGen much, and use emacs or vim, that you can find an emacs "TableGen mode" and a vim language file in @@ -78,7 +75,7 @@ distribution, respectively.
- +TableGen multiclasses are groups of abstract records that are +instantiated all at once. Each instantiation can result in multiple TableGen +definitions.
+Note that all of the values have rules specifying how they convert to values @@ -337,8 +343,8 @@ for different types. These rules allow you to assign a value like "7" to a (collectively known as 'records') in TableGen are the main high-level unit of information that TableGen collects. Records are defined with a def or class keyword, the record name, and an optional list of "template arguments". If the record has superclasses, -they are specified as a comma seperated list that starts with a colon character +href="#templateargs">template arguments". If the record has superclasses, +they are specified as a comma separated list that starts with a colon character (":"). If value definitions or let expressions are needed for the class, they are enclosed in curly braces ("{}"); otherwise, the record ends with a semicolon. Here is a simple TableGen @@ -464,16 +470,16 @@ running tblgen on the example prints the following definitions:
def bork { // Value - bit isMod = 1; - bit isRef = 0; + bit isMod = 1; + bit isRef = 0; } def hork { // Value - bit isMod = 1; - bit isRef = 1; + bit isMod = 1; + bit isRef = 1; } def zork { // Value - bit isMod = 0; - bit isRef = 1; + bit isMod = 0; + bit isRef = 1; }@@ -484,6 +490,78 @@ X86 backend. + + + +
+While classes with template arguments are a good way to factor commonality +between two instances of a definition, multiclasses allow a convenient notation +for defining multiple definitions at once (instances of implicitly constructed +classes). For example, consider an 3-address instruction set whose instructions +come in two forms: "reg = reg op reg" and "reg = reg op imm" (e.g. SPARC). In +this case, you'd like to specify in one place that this commonality exists, then +in a separate place indicate what all the ops are. +
+ ++Here is an example TableGen fragment that shows this idea: +
+ ++def ops; +def GPR; +def Imm; +class inst<int opc, string asmstr, dag operandlist>; + +multiclass ri_inst<int opc, string asmstr> { + def _rr : inst<opc, !strconcat(asmstr, " $dst, $src1, $src2"), + (ops GPR:$dst, GPR:$src1, GPR:$src2)>; + def _ri : inst<opc, !strconcat(asmstr, " $dst, $src1, $src2"), + (ops GPR:$dst, GPR:$src1, Imm:$src2)>; +} + +// Instantiations of the ri_inst multiclass. +defm ADD : ri_inst<0b111, "add">; +defm SUB : ri_inst<0b101, "sub">; +defm MUL : ri_inst<0b100, "mul">; +... ++ +
The name of the resultant definitions has the multidef fragment names + appended to them, so this defines ADD_rr, ADD_ri, SUB_rr, etc. Using a + multiclass this way is exactly equivalent to instantiating the + classes multiple times yourself, e.g. by writing:
+ ++def ops; +def GPR; +def Imm; +class inst<int opc, string asmstr, dag operandlist>; + +class rrinst<int opc, string asmstr> + : inst<opc, !strconcat(asmstr, " $dst, $src1, $src2"), + (ops GPR:$dst, GPR:$src1, GPR:$src2)>; + +class riinst<int opc, string asmstr> + : inst<opc, !strconcat(asmstr, " $dst, $src1, $src2"), + (ops GPR:$dst, GPR:$src1, Imm:$src2)>; + +// Instantiations of the ri_inst multiclass. +def ADD_rr : rrinst<0b111, "add">; +def ADD_ri : riinst<0b111, "add">; +def SUB_rr : rrinst<0b101, "sub">; +def SUB_ri : riinst<0b101, "sub">; +def MUL_rr : rrinst<0b100, "mul">; +def MUL_ri : riinst<0b100, "mul">; +... ++ +
File-scope "let" expressions take a comma-seperated list of bindings to +
File-scope "let" expressions take a comma-separated list of bindings to apply, and one of more records to bind the values in. Here are some examples:
@@ -550,18 +628,6 @@ about any particular backend, except maybe -print-enums as an example. This should highlight the APIs in TableGen/Record.h.This is just a temporary, convenient, place to put stuff about the code -generator before it gets its own document. This should describe all of the -tablegen backends used by the code generator and the classes/definitions they -expect.
-