[PATCH] D95308: [TableGen] Fix instantiating multiclass in foreach

Jyun-Yan You via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 24 02:16:58 PST 2021


jyyou.tw created this revision.
Herald added a subscriber: hiraditya.
jyyou.tw requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

If multiclass argument comes from loop varaible and argument is
record type, it will not recognize the type.

This patch ensures that loop variables are resolved correctly.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95308

Files:
  llvm/lib/TableGen/TGParser.cpp
  llvm/test/TableGen/foreach-multiclass.td


Index: llvm/test/TableGen/foreach-multiclass.td
===================================================================
--- llvm/test/TableGen/foreach-multiclass.td
+++ llvm/test/TableGen/foreach-multiclass.td
@@ -57,6 +57,9 @@
 // CHECK:     def F2_2_1
 // CHECK-NOT: def F2_2_2
 
+// CHECK: def G0
+// CHECK: def anonymous_0
+
 multiclass A<int x> {
   foreach i = [0, 1] in {
     def NAME#i {
@@ -116,3 +119,19 @@
 defm F0 : F<[]>;
 defm F1 : F<[0]>;
 defm F2 : F<[0, 1, 2]>;
+
+class G {
+  list<int> val = [10];
+}
+
+multiclass H<G g> {
+  foreach n = g.val in
+    def {
+      int val = n;
+    }
+}
+
+def G0 : G;
+
+foreach g = [G0] in
+  defm : H<g>;
Index: llvm/lib/TableGen/TGParser.cpp
===================================================================
--- llvm/lib/TableGen/TGParser.cpp
+++ llvm/lib/TableGen/TGParser.cpp
@@ -3524,8 +3524,8 @@
 
     Substs.emplace_back(QualifiedNameOfImplicitName(MC), DefmName);
 
-    if (resolve(MC->Entries, Substs, CurMultiClass == nullptr, &NewEntries,
-                &SubClassLoc))
+    if (resolve(MC->Entries, Substs, CurMultiClass == nullptr && Loops.empty(),
+                &NewEntries, &SubClassLoc))
       return true;
 
     if (!consume(tgtok::comma))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95308.318817.patch
Type: text/x-patch
Size: 1220 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210124/814ae86f/attachment.bin>


More information about the llvm-commits mailing list