<li><a href="#valuedef">Value definitions</a></li>
<li><a href="#recordlet">'let' expressions</a></li>
<li><a href="#templateargs">Class template arguments</a></li>
+ <li><a href="#multiclass">Multiclass definitions and instances</a></li>
</ol></li>
<li><a href="#filescope">File scope entities</a>
<ol>
<ol>
<li><a href="#">todo</a></li>
</ol></li>
- <li><a href="#codegenerator">The LLVM code generator</a>
- <ol>
- <li><a href="#">todo</a></li>
- </ol></li>
</ul>
</div>
<p>The core part of TableGen <a href="#syntax">parses a file</a>, instantiates
the declarations, and hands the result off to a domain-specific "<a
href="#backends">TableGen backend</a>" for processing. The current major user
-of TableGen is the <a href="#codegenerator">LLVM code generator</a>.</p>
+of TableGen is the <a href="CodeGenerator.html">LLVM code generator</a>.</p>
<p>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
</div>
<!-- ======================================================================= -->
-<div class="doc_subsection"><a name="running">Basic concepts</a></div>
+<div class="doc_subsection"><a name="concepts">Basic concepts</a></div>
<div class="doc_text">
definition, so the backend can find all definitions of a particular class, such
as "Instruction".</p>
+<p><b>TableGen multiclasses</b> are groups of abstract records that are
+instantiated all at once. Each instantiation can result in multiple TableGen
+definitions.</p>
+
</div>
<!-- ======================================================================= -->
supported include:</p>
<ul>
-<li>? - Uninitialized field.</li>
-<li>0b1001011 - Binary integer value.</li>
-<li>07654321 - Octal integer value (indicated by a leading 0).</li>
-<li>7 - Decimal integer value.</li>
-<li>0x7F - Hexadecimal integer value.</li>
-<li>"foo" - String value.</li>
-<li>[{ .... }] - Code fragment.</li>
-<li>[ X, Y, Z ] - List value.</li>
-<li>{ a, b, c } - Initializer for a "bits<3>" value.</li>
-<li>value - Value reference.</li>
-<li>value{17} - Access to one or more bits of a value.</li>
-<li>DEF - Reference to a record definition.</li>
-<li>X.Y - Reference to the subfield of a value.</li>
-
-<li>(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.</li>
-
+<li><tt>?</tt> - uninitialized field</li>
+<li><tt>0b1001011</tt> - binary integer value</li>
+<li><tt>07654321</tt> - octal integer value (indicated by a leading 0)</li>
+<li><tt>7</tt> - decimal integer value</li>
+<li><tt>0x7F</tt> - hexadecimal integer value</li>
+<li><tt>"foo"</tt> - string value</li>
+<li><tt>[{ ... }]</tt> - code fragment</li>
+<li><tt>[ X, Y, Z ]</tt> - list value.</li>
+<li><tt>{ a, b, c }</tt> - initializer for a "bits<3>" value</li>
+<li><tt>value</tt> - value reference</li>
+<li><tt>value{17}</tt> - access to one bit of a value</li>
+<li><tt>value{15-17}</tt> - access to multiple bits of a value</li>
+<li><tt>DEF</tt> - reference to a record definition</li>
+<li><tt>CLASS<val list></tt> - reference to a new anonymous definition of
+ CLASS with the specified template arguments.</li>
+<li><tt>X.Y</tt> - reference to the subfield of a value</li>
+<li><tt>list[4-7,17,2-3]</tt> - A slice of the 'list' list, including elements
+4,5,6,7,17,2, and 3 from it. Elements may be included multiple times.</li>
+<li><tt>(DEF a, b)</tt> - 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 `<tt>dag</tt>' values.</li>
+<li><tt>!strconcat(a, b)</tt> - A string value that is the result of
+ concatenating the 'a' and 'b' strings.</li>
</ul>
<p>Note that all of the values have rules specifying how they convert to values
information that TableGen collects. Records are defined with a <tt>def</tt> or
<tt>class</tt> keyword, the record name, and an optional list of "<a
href="#templateargs">template arguments</a>". If the record has superclasses,
-they are specified as a comma seperated list that starts with a colon character
+they are specified as a comma separated list that starts with a colon character
(":"). If <a href="#valuedef">value definitions</a> or <a href="#recordlet">let
expressions</a> are needed for the class, they are enclosed in curly braces
("{}"); otherwise, the record ends with a semicolon. Here is a simple TableGen
<pre>
<b>def</b> bork { <i>// Value</i>
- bit isMod = 1;
- bit isRef = 0;
+ <b>bit</b> isMod = 1;
+ <b>bit</b> isRef = 0;
}
<b>def</b> hork { <i>// Value</i>
- bit isMod = 1;
- bit isRef = 1;
+ <b>bit</b> isMod = 1;
+ <b>bit</b> isRef = 1;
}
<b>def</b> zork { <i>// Value</i>
- bit isMod = 0;
- bit isRef = 1;
+ <b>bit</b> isMod = 0;
+ <b>bit</b> isRef = 1;
}
</pre>
</div>
+<!-- -------------------------------------------------------------------------->
+<div class="doc_subsubsection">
+ <a name="multiclass">Multiclass definitions and instances</a>
+</div>
+
+<div class="doc_text">
+
+<p>
+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.
+</p>
+
+<p>
+Here is an example TableGen fragment that shows this idea:
+</p>
+
+<pre>
+<b>def</b> ops;
+<b>def</b> GPR;
+<b>def</b> Imm;
+<b>class</b> inst<<b>int</b> opc, <b>string</b> asmstr, <b>dag</b> operandlist>;
+
+<b>multiclass</b> ri_inst<<b>int</b> opc, <b>string</b> 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.
+<b>defm</b> ADD : ri_inst<0b111, "add">;
+<b>defm</b> SUB : ri_inst<0b101, "sub">;
+<b>defm</b> MUL : ri_inst<0b100, "mul">;
+...
+</pre>
+
+<p>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:</p>
+
+<pre>
+<b>def</b> ops;
+<b>def</b> GPR;
+<b>def</b> Imm;
+<b>class</b> inst<<b>int</b> opc, <b>string</b> asmstr, <b>dag</b> operandlist>;
+
+<b>class</b> rrinst<<b>int</b> opc, <b>string</b> asmstr>
+ : inst<opc, !strconcat(asmstr, " $dst, $src1, $src2"),
+ (ops GPR:$dst, GPR:$src1, GPR:$src2)>;
+
+<b>class</b> riinst<<b>int</b> opc, <b>string</b> asmstr>
+ : inst<opc, !strconcat(asmstr, " $dst, $src1, $src2"),
+ (ops GPR:$dst, GPR:$src1, Imm:$src2)>;
+
+// Instantiations of the ri_inst multiclass.
+<b>def</b> ADD_rr : rrinst<0b111, "add">;
+<b>def</b> ADD_ri : riinst<0b111, "add">;
+<b>def</b> SUB_rr : rrinst<0b101, "sub">;
+<b>def</b> SUB_ri : riinst<0b101, "sub">;
+<b>def</b> MUL_rr : rrinst<0b100, "mul">;
+<b>def</b> MUL_ri : riinst<0b100, "mul">;
+...
+</pre>
+
+</div>
+
<!-- ======================================================================= -->
<div class="doc_subsection">
<a name="filescope">File scope entities</a>
File-scope let expressions are really just another way that TableGen allows the
end-user to factor out commonality from the records.</p>
-<p>File-scope "let" expressions take a comma-seperated list of bindings to
+<p>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:</p>
should highlight the APIs in <tt>TableGen/Record.h</tt>.</p>
</div>
-<!-- *********************************************************************** -->
-<div class="doc_section"><a name="codegenerator">The LLVM code generator</a>
-</div>
-<!-- *********************************************************************** -->
-
-<div class="doc_text">
-<p>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.</p>
-</div>
-
<!-- *********************************************************************** -->
<hr>
src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a>
<a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
- <a href="http://llvm.cs.uiuc.edu">LLVM Compiler Infrastructure</a><br>
+ <a href="http://llvm.org">LLVM Compiler Infrastructure</a><br>
Last modified: $Date$
</address>