X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=docs%2FTableGenFundamentals.html;h=90836e91bda8462c73e1fd213438a42e7aaabc62;hb=636e5a216c8dab7567b5e5d8d1c7d982f507f7eb;hp=c63c5cef5fa8190c785bc8619fe9153a0b77fd4e;hpb=85234aca74411051406287a3b1991947feff6810;p=oota-llvm.git diff --git a/docs/TableGenFundamentals.html b/docs/TableGenFundamentals.html index c63c5cef5fa..90836e91bda 100644 --- a/docs/TableGenFundamentals.html +++ b/docs/TableGenFundamentals.html @@ -30,6 +30,7 @@
  • Value definitions
  • 'let' expressions
  • Class template arguments
  • +
  • Multiclass definitions and instances
  • File scope entities
      @@ -41,13 +42,13 @@
      1. todo
      -
    1. The LLVM code generator -
        -
      1. todo
      2. -
    2. +
      +

      Written by Chris Lattner

      +
      + @@ -64,7 +65,7 @@ makes it easier to structure domain specific information.

      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 @@ -74,7 +75,7 @@ distribution, respectively.

      - +
      @@ -102,6 +103,10 @@ TableGen keeps track of all of the classes that are used to build up a definition, so the backend can find all definitions of a particular class, such as "Instruction".

      +

      TableGen multiclasses are groups of abstract records that are +instantiated all at once. Each instantiation can result in multiple TableGen +definitions.

      +
      @@ -230,7 +235,8 @@ the line, and it also supports nestable "/* */" comments.

      -
      The TableGen type system +
      @@ -287,31 +293,37 @@ needed.

      TableGen values and expressions
      -
      +
      +

      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 natural syntax and flavor for the application. The current expression forms supported include:

        -
      • ? - Uninitialized field.
      • -
      • 0b1001011 - Binary integer value.
      • -
      • 07654321 - Octal integer value (indicated by a leading 0).
      • -
      • 7 - Decimal integer value.
      • -
      • 0x7F - Hexadecimal integer value.
      • -
      • "foo" - String value.
      • -
      • [{ .... }] - Code fragment.
      • -
      • [ X, Y, Z ] - List value.
      • -
      • { a, b, c } - Initializer for a "bits<3>" value.
      • -
      • value - Value reference.
      • -
      • value{17} - Access to one or more bits of a value.
      • -
      • DEF - Reference to a record definition.
      • -
      • X.Y - Reference to the subfield of a value.
      • - -
      • (DEF a, b) - A dag value. The first element is required to be a record -definition, the remaining elements in the list may be arbitrary other values, -including nested 'dag' values.
      • - +
      • ? - uninitialized field
      • +
      • 0b1001011 - binary integer value
      • +
      • 07654321 - octal integer value (indicated by a leading 0)
      • +
      • 7 - decimal integer value
      • +
      • 0x7F - hexadecimal integer value
      • +
      • "foo" - string value
      • +
      • [{ ... }] - code fragment
      • +
      • [ X, Y, Z ] - list value.
      • +
      • { a, b, c } - initializer for a "bits<3>" value
      • +
      • value - value reference
      • +
      • value{17} - access to one bit of a value
      • +
      • value{15-17} - access to multiple bits of a value
      • +
      • DEF - reference to a record definition
      • +
      • CLASS<val list> - reference to a new anonymous definition of + CLASS with the specified template arguments.
      • +
      • X.Y - reference to the subfield of a value
      • +
      • list[4-7,17,2-3] - A slice of the 'list' list, including elements +4,5,6,7,17,2, and 3 from it. Elements may be included multiple times.
      • +
      • (DEF a, b) - a dag value. The first element is required to be a +record definition, the remaining elements in the list may be arbitrary other +values, including nested `dag' values.
      • +
      • !strconcat(a, b) - A string value that is the result of + concatenating the 'a' and 'b' strings.

      Note that all of the values have rules specifying how they convert to values @@ -321,16 +333,18 @@ for different types. These rules allow you to assign a value like "7" to a

      -
      Classes and definitions + -
      +
      +

      As mentioned in the intro, classes and definitions (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 @@ -456,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;
       }
       
      @@ -476,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 entities @@ -510,7 +596,7 @@ multiple records at a time, and may be useful in certain other cases. File-scope let expressions are really just another way that TableGen allows the end-user to factor out commonality from the records.

      -

      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:

      @@ -542,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.

      -
      -
      @@ -564,7 +638,7 @@ expect.

      src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /> Chris Lattner
      - LLVM Compiler Infrastructure
      + LLVM Compiler Infrastructure
      Last modified: $Date$