[llvm] r325797 - TableGen: Fix type deduction for !foreach
Nicolai Haehnle via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 22 07:26:35 PST 2018
Author: nha
Date: Thu Feb 22 07:26:35 2018
New Revision: 325797
URL: http://llvm.org/viewvc/llvm-project?rev=325797&view=rev
Log:
TableGen: Fix type deduction for !foreach
Summary:
In the case of !foreach(id, input-list, transform) where the type of
input-list is list<A> and the type of transform is B, we now correctly
deduce list<B> as the type of the !foreach.
Change-Id: Ia19dd65eecc5991dd648280ba6a15f6a20fd61de
Reviewers: arsenm, craig.topper, tra, MartinO
Subscribers: wdng, llvm-commits
Differential Revision: https://reviews.llvm.org/D43555
Modified:
llvm/trunk/lib/TableGen/TGParser.cpp
llvm/trunk/test/TableGen/foreach.td
Modified: llvm/trunk/lib/TableGen/TGParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/TGParser.cpp?rev=325797&r1=325796&r2=325797&view=diff
==============================================================================
--- llvm/trunk/lib/TableGen/TGParser.cpp (original)
+++ llvm/trunk/lib/TableGen/TGParser.cpp Thu Feb 22 07:26:35 2018
@@ -1075,6 +1075,14 @@ Init *TGParser::ParseOperation(Record *C
return nullptr;
}
Type = MHSt->getType();
+ if (isa<ListRecTy>(Type)) {
+ TypedInit *RHSt = dyn_cast<TypedInit>(RHS);
+ if (!RHSt) {
+ TokError("could not get type of !foreach list elements");
+ return nullptr;
+ }
+ Type = RHSt->getType()->getListTy();
+ }
break;
}
case tgtok::XSubst: {
Modified: llvm/trunk/test/TableGen/foreach.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/TableGen/foreach.td?rev=325797&r1=325796&r2=325797&view=diff
==============================================================================
--- llvm/trunk/test/TableGen/foreach.td (original)
+++ llvm/trunk/test/TableGen/foreach.td Thu Feb 22 07:26:35 2018
@@ -7,12 +7,18 @@
// CHECK: "NAME"
// CHECK: Defs
+
+// CHECK: def DX {
+// CHECK: list<string> x = ["0", "1", "2"];
+// CHECK: }
+
// CHECK: Jr
// CHECK: Sr
// Variables for foreach
class decls {
string name;
+ int num;
}
def Decls : decls;
@@ -37,3 +43,9 @@ def Seniors : B<People.values>;
def Juniors : C<People.values>;
def Smiths : D<["NAME", "Jane Smith"]>;
def Unprocessed : D<People.values>;
+
+class X<list<int> a> {
+ list<string> x = !foreach(Decls.num, a, !cast<string>(Decls.num));
+}
+
+def DX : X<[0, 1, 2]>;
More information about the llvm-commits
mailing list