From 112d959e32dd1691182f063c989832201cafe8e9 Mon Sep 17 00:00:00 2001 From: David Greene Date: Wed, 5 Oct 2011 22:42:49 +0000 Subject: [PATCH] Document Multidefs Provide documentation for multidefs, explaining in detail how they work. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@141236 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/TableGenFundamentals.html | 59 ++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/docs/TableGenFundamentals.html b/docs/TableGenFundamentals.html index e8fca325130..c5e8d9a1e43 100644 --- a/docs/TableGenFundamentals.html +++ b/docs/TableGenFundamentals.html @@ -769,6 +769,65 @@ before them. +

+A special "multidef" may be used inside a multiclass to generate +several defs given a list of values. +

+ +
+
+class Base<int i> {
+  int value = i;
+}
+
+multiclass Multi<list<int> values> {
+  def ONE : Base<values[0]>;
+  def TWO : Base<values[1]>;
+
+  multidef COUNT<values, int v, 2> : Base<:v>;
+}
+
+defm List : Multi<[1, 2, 3, 4, 5, 6]<;
+...
+
+// Results
+def ListCOUNT {
+  int v = ?;
+  int value = v;
+  list Multi::values = [1, 2, 3, 4, 5, 6];
+}
+def ListONE {
+  int value = 1;
+}
+def ListTWO {
+  int value = 2;
+}
+def MD2.ListCOUNT {
+  int value = 3;
+}
+def MD3.ListCOUNT {
+  int value = 4;
+}
+def MD4.ListCOUNT {
+  int value = 5;
+}
+def MD5.ListCOUNT {
+  int value = 6;
+}
+
+
+ +

+A multidef takes three "arguments" in the <> notation after the multidef +name. The first is a list of items to process. The second is a declaration. +This declaration creates a temporary name used as an iterator. It picks up the +value of each processed list item as TableGen generates defs from the multidef. +This temporary may be named and passed into the multidef body as shown in the +example above. This provides a powerful way to generate defs with various +values from a single multidef. The final "argument" is an integer value +indicating where in the list to begin processing. In the above example we +chose to begin list processing with the third item (index 2). +