[llvm] r327493 - TableGen: Allow ? in lists

Nicolai Haehnle via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 14 04:00:33 PDT 2018


Author: nha
Date: Wed Mar 14 04:00:33 2018
New Revision: 327493

URL: http://llvm.org/viewvc/llvm-project?rev=327493&view=rev
Log:
TableGen: Allow ? in lists

This makes using !dag more convenient in some cases.

Change-Id: I0a8c35e15ccd1ecec778fd1c8d64eee38d74517c

Differential revision: https://reviews.llvm.org/D44111

Modified:
    llvm/trunk/docs/TableGen/LangIntro.rst
    llvm/trunk/lib/TableGen/TGParser.cpp
    llvm/trunk/test/TableGen/dag-functional.td

Modified: llvm/trunk/docs/TableGen/LangIntro.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/TableGen/LangIntro.rst?rev=327493&r1=327492&r2=327493&view=diff
==============================================================================
--- llvm/trunk/docs/TableGen/LangIntro.rst (original)
+++ llvm/trunk/docs/TableGen/LangIntro.rst Wed Mar 14 04:00:33 2018
@@ -178,10 +178,10 @@ supported include:
     Due to limitations of the type system, 'children' must be a list of items
     of a common type. In practice, this means that they should either have the
     same type or be records with a common superclass. Mixing dag and non-dag
-    items is not possible.
+    items is not possible. However, '?' can be used.
 
-    Example: !dag(op, [a1, a2], ["name1", "name2"]) results in
-    (op a1:$name1, a2:$name2).
+    Example: !dag(op, [a1, a2, ?], ["name1", "name2", "name3"]) results in
+    (op a1:$name1, a2:$name2, ?:$name3).
 
 ``!listconcat(a, b, ...)``
     A list value that is the result of concatenating the 'a' and 'b' lists.

Modified: llvm/trunk/lib/TableGen/TGParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/TGParser.cpp?rev=327493&r1=327492&r2=327493&view=diff
==============================================================================
--- llvm/trunk/lib/TableGen/TGParser.cpp (original)
+++ llvm/trunk/lib/TableGen/TGParser.cpp Wed Mar 14 04:00:33 2018
@@ -1676,18 +1676,16 @@ Init *TGParser::ParseSimpleValue(Record
     RecTy *EltTy = nullptr;
     for (Init *V : Vals) {
       TypedInit *TArg = dyn_cast<TypedInit>(V);
-      if (!TArg) {
-        TokError("Untyped list element");
-        return nullptr;
-      }
-      if (EltTy) {
-        EltTy = resolveTypes(EltTy, TArg->getType());
-        if (!EltTy) {
-          TokError("Incompatible types in list elements");
-          return nullptr;
+      if (TArg) {
+        if (EltTy) {
+          EltTy = resolveTypes(EltTy, TArg->getType());
+          if (!EltTy) {
+            TokError("Incompatible types in list elements");
+            return nullptr;
+          }
+        } else {
+          EltTy = TArg->getType();
         }
-      } else {
-        EltTy = TArg->getType();
       }
     }
 

Modified: llvm/trunk/test/TableGen/dag-functional.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/TableGen/dag-functional.td?rev=327493&r1=327492&r2=327493&view=diff
==============================================================================
--- llvm/trunk/test/TableGen/dag-functional.td (original)
+++ llvm/trunk/test/TableGen/dag-functional.td Wed Mar 14 04:00:33 2018
@@ -8,7 +8,7 @@
 // CHECK: }
 
 // CHECK: def A1 {
-// CHECK:   dag ret = (ops 1:$a, 2:$b);
+// CHECK:   dag ret = (ops ?:$a, 1:$b, 2);
 // CHECK: }
 
 // CHECK: def A2 {
@@ -70,7 +70,7 @@ class B<list<Node> nodes> {
 }
 
 def A0 : Aint<[], []>;
-def A1 : Aint<[1, 2], ["a", "b"]>;
+def A1 : Aint<[?, 1, 2], ["a", "b", ?]>;
 
 def A2 : Adag<[(ops $name), (ops 1), (ops "foo")], ["a", "b", "c"]>;
 




More information about the llvm-commits mailing list