Add VLIW packetizer to ReleaseNotes.html and CREDITS.TXT. Committing patch
[oota-llvm.git] / docs / TableGenFundamentals.html
index 7efdfbb7cec0113fecbfaafc87fa1e846a075084..b401c7a49f0967c4ac32d984e5cfc04db2d72ae0 100644 (file)
@@ -2,6 +2,7 @@
                       "http://www.w3.org/TR/html4/strict.dtd">
 <html>
 <head>
+  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
   <title>TableGen Fundamentals</title>
   <link rel="stylesheet" href="llvm.css" type="text/css">
 </head>
@@ -9,7 +10,7 @@
 
 <h1>TableGen Fundamentals</h1>
 
-<div class="doc_text">
+<div>
 <ul>
   <li><a href="#introduction">Introduction</a>
   <ol>
@@ -36,6 +37,7 @@
     <ol>
       <li><a href="#include">File inclusion</a></li>
       <li><a href="#globallet">'let' expressions</a></li>
+      <li><a href="#foreach">'foreach' blocks</a></li>
     </ol></li>
   </ol></li>
   <li><a href="#backends">TableGen backends</a>
@@ -53,7 +55,7 @@
 <h2><a name="introduction">Introduction</a></h2>
 <!-- *********************************************************************** -->
 
-<div class="doc_text">
+<div>
 
 <p>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 +74,10 @@ find an emacs "TableGen mode" and a vim language file in the
 <tt>llvm/utils/emacs</tt> and <tt>llvm/utils/vim</tt> directories of your LLVM
 distribution, respectively.</p>
 
-</div>
-
 <!-- ======================================================================= -->
 <h3><a name="concepts">Basic concepts</a></h3>
 
-<div class="doc_text">
+<div>
 
 <p>TableGen files consist of two key parts: 'classes' and 'definitions', both
 of which are considered 'records'.</p>
@@ -114,7 +114,7 @@ multiclass, as if they were declared in the current multiclass.</p>
 <!-- ======================================================================= -->
 <h3><a name="example">An example record</a></h3>
 
-<div class="doc_text">
+<div>
 
 <p>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
@@ -209,12 +209,20 @@ file, to factor out the common features that instructions of its class share.  A
 key feature of TableGen is that it allows the end-user to define the
 abstractions they prefer to use when describing their information.</p>
 
+<p>Each def record has a special entry called "NAME."  This is the
+name of the def ("ADD32rr" above).  In the general case def names can
+be formed from various kinds of string processing expressions and NAME
+resolves to the final value obtained after resolving all of those
+expressions.  The user may refer to NAME anywhere she desires to use
+the ultimate name of the def.  NAME should not be defined anywhere
+else in user code to avoid conflict problems.</p>
+
 </div>
 
 <!-- ======================================================================= -->
 <h3><a name="running">Running TableGen</a></h3>
 
-<div class="doc_text">
+<div>
 
 <p>TableGen runs just like any other LLVM tool.  The first (optional) argument
 specifies the file to read.  If a filename is not specified, <tt>tblgen</tt>
@@ -256,27 +264,28 @@ what you need and formats it in the appropriate way.</p>
 
 </div>
 
+</div>
 
 <!-- *********************************************************************** -->
 <h2><a name="syntax">TableGen syntax</a></h2>
 <!-- *********************************************************************** -->
 
-<div class="doc_text">
+<div>
 
 <p>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.
 </p>
 
-</div>
-
 <!-- ======================================================================= -->
 <h3><a name="primitives">TableGen primitives</a></h3>
 
+<div>
+
 <!-- -------------------------------------------------------------------------->
 <h4><a name="comments">TableGen comments</a></h4>
 
-<div class="doc_text">
+<div>
 
 <p>TableGen supports BCPL style "<tt>//</tt>" comments, which run to the end of
 the line, and it also supports <b>nestable</b> "<tt>/* */</tt>" comments.</p>
@@ -288,7 +297,7 @@ the line, and it also supports <b>nestable</b> "<tt>/* */</tt>" comments.</p>
   <a name="types">The TableGen type system</a>
 </h4>
 
-<div class="doc_text">
+<div>
 
 <p>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
@@ -348,7 +357,7 @@ needed.</p>
   <a name="values">TableGen values and expressions</a>
 </h4>
 
-<div class="doc_text">
+<div>
 
 <p>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
@@ -393,6 +402,14 @@ which case the user must specify it explicitly.</dd>
 <dt><tt>list[4-7,17,2-3]</tt></dt>
   <dd>A slice of the 'list' list, including elements 4,5,6,7,17,2, and 3 from
   it.  Elements may be included multiple times.</dd>
+<dt><tt>foreach &lt;var&gt; = &lt;list&gt; in { &lt;body&gt; }</tt></dt>
+<dt><tt>foreach &lt;var&gt; = &lt;list&gt; in &lt;def&gt;</tt></dt>
+  <dd> Replicate &lt;body&gt; or &lt;def&gt;, replacing instances of
+  &lt;var&gt; with each value in &lt;list&gt;.  &lt;var&gt; is scoped at the
+  level of the <tt>foreach</tt> loop and must not conflict with any other object
+  introduced in &lt;body&gt; or &lt;def&gt;.  Currently only <tt>def</tt>s are
+  expanded within &lt;body&gt;.
+  </dd>
 <dt><tt>(DEF a, b)</tt></dt>
   <dd>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
@@ -400,6 +417,10 @@ which case the user must specify it explicitly.</dd>
 <dt><tt>!strconcat(a, b)</tt></dt>
   <dd>A string value that is the result of concatenating the 'a' and 'b'
   strings.</dd>
+<dt><tt>str1#str2</tt></dt>
+  <dd>"#" (paste) is a shorthand for !strconcat.  It may concatenate
+  things that are not quoted strings, in which case an implicit
+  !cast&lt;string&gt; is done on the operand of the paste.</dd>
 <dt><tt>!cast&lt;type&gt;(a)</tt></dt>
   <dd>A symbol of type <em>type</em> obtained by looking up the string 'a' in
 the symbol table.  If the type of 'a' does not match <em>type</em>, TableGen
@@ -433,12 +454,14 @@ to a "<tt>bits&lt;4&gt;</tt>" value, for example.</p>
 
 </div>
 
+</div>
+
 <!-- ======================================================================= -->
 <h3>
   <a name="classesdefs">Classes and definitions</a>
 </h3>
 
-<div class="doc_text">
+<div>
 
 <p>As mentioned in the <a href="#concepts">intro</a>, classes and definitions
 (collectively known as 'records') in TableGen are the main high-level unit of
@@ -473,14 +496,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.</p>
 
-</div>
-
 <!---------------------------------------------------------------------------->
 <h4>
   <a name="valuedef">Value definitions</a>
 </h4>
 
-<div class="doc_text">
+<div>
 
 <p>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
@@ -496,7 +517,7 @@ equal sign.  Value definitions require terminating semicolons.</p>
   <a name="recordlet">'let' expressions</a>
 </h4>
 
-<div class="doc_text">
+<div>
 
 <p>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
@@ -523,7 +544,7 @@ because the <tt>D</tt> class overrode its value.</p>
   <a name="templateargs">Class template arguments</a>
 </h4>
 
-<div class="doc_text">
+<div>
 
 <p>TableGen permits the definition of parameterized classes as well as normal
 concrete classes.  Parameterized TableGen classes specify a list of variable
@@ -614,7 +635,7 @@ X86 backend.</p>
   <a name="multiclass">Multiclass definitions and instances</a>
 </h4>
 
-<div class="doc_text">
+<div>
 
 <p>
 While classes with template arguments are a good way to factor commonality
@@ -772,17 +793,21 @@ before them.
 
 </div>
 
+</div>
+
 <!-- ======================================================================= -->
 <h3>
   <a name="filescope">File scope entities</a>
 </h3>
 
+<div>
+
 <!-- -------------------------------------------------------------------------->
 <h4>
   <a name="include">File inclusion</a>
 </h4>
 
-<div class="doc_text">
+<div>
 <p>TableGen supports the '<tt>include</tt>' 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 '<tt>include</tt>'
@@ -801,7 +826,7 @@ keyword.  Example:</p>
   <a name="globallet">'let' expressions</a>
 </h4>
 
-<div class="doc_text">
+<div>
 
 <p>"Let" expressions at file scope are similar to <a href="#recordlet">"let"
 expressions within a record</a>, except they can specify a value binding for
@@ -864,11 +889,48 @@ several levels of multiclass instanciations. This also avoids the need of using
 </pre>
 </div>
 
+<!-- -------------------------------------------------------------------------->
+<h4>
+  <a name="foreach">Looping</a>
+</h4>
+
+<div>
+<p>TableGen supports the '<tt>foreach</tt>' block, which textually replicates
+the loop body, substituting iterator values for iterator references in the
+body.  Example:</p>
+
+<div class="doc_code">
+<pre>
+<b>foreach</b> i = [0, 1, 2, 3] in {
+  <b>def</b> R#i : Register&lt;...&gt;;
+  <b>def</b> F#i : Register&lt;...&gt;;
+}
+</pre>
+</div>
+
+<p>This will create objects <tt>R0</tt>, <tt>R1</tt>, <tt>R2</tt> and
+<tt>R3</tt>.  <tt>foreach</tt> blocks may be nested. If there is only
+one item in the body the braces may be elided:</p>
+
+<div class="doc_code">
+<pre>
+<b>foreach</b> i = [0, 1, 2, 3] in
+  <b>def</b> R#i : Register&lt;...&gt;;
+
+</pre>
+</div>
+
+</div>
+
+</div>
+
+</div>
+
 <!-- *********************************************************************** -->
 <h2><a name="codegen">Code Generator backend info</a></h2>
 <!-- *********************************************************************** -->
 
-<div class="doc_text">
+<div>
 
 <p>Expressions used by code generator to describe instructions and isel
 patterns:</p>
@@ -885,7 +947,7 @@ patterns:</p>
 <h2><a name="backends">TableGen backends</a></h2>
 <!-- *********************************************************************** -->
 
-<div class="doc_text">
+<div>
 
 <p>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.