[llvm] 5046c5b - [TableGen] Fix instantiating multiclass in foreach

Paul C. Anagnostopoulos via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 29 07:26:09 PST 2021


Author: J-Y You
Date: 2021-01-29T10:25:33-05:00
New Revision: 5046c5be8459a9631eeb149337776dcbde0e2a0b

URL: https://github.com/llvm/llvm-project/commit/5046c5be8459a9631eeb149337776dcbde0e2a0b
DIFF: https://github.com/llvm/llvm-project/commit/5046c5be8459a9631eeb149337776dcbde0e2a0b.diff

LOG: [TableGen] Fix instantiating multiclass in foreach

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.

Differential Revision: https://reviews.llvm.org/D95308

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/TableGen/TGParser.cpp b/llvm/lib/TableGen/TGParser.cpp
index 24949f0b2b4d..1995477507c4 100644
--- a/llvm/lib/TableGen/TGParser.cpp
+++ b/llvm/lib/TableGen/TGParser.cpp
@@ -3524,8 +3524,8 @@ bool TGParser::ParseDefm(MultiClass *CurMultiClass) {
 
     Substs.emplace_back(QualifiedNameOfImplicitName(MC), DefmName);
 
-    if (resolve(MC->Entries, Substs, CurMultiClass == nullptr, &NewEntries,
-                &SubClassLoc))
+    if (resolve(MC->Entries, Substs, !CurMultiClass && Loops.empty(),
+                &NewEntries, &SubClassLoc))
       return true;
 
     if (!consume(tgtok::comma))

diff  --git a/llvm/test/TableGen/foreach-multiclass.td b/llvm/test/TableGen/foreach-multiclass.td
index d17d5bfa60da..1b8ad6a37e26 100644
--- a/llvm/test/TableGen/foreach-multiclass.td
+++ b/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 H0_G0_0
+
 multiclass A<int x> {
   foreach i = [0, 1] in {
     def NAME#i {
@@ -116,3 +119,20 @@ multiclass F<list<int> lst> {
 defm F0 : F<[]>;
 defm F1 : F<[0]>;
 defm F2 : F<[0, 1, 2]>;
+
+// If multiclass argument comes from loop variable,
+// and field of argument is placed at foreach statement,
+// the record field must be resolved correctly.
+class G {
+  list<int> val = [0];
+}
+
+multiclass H<G g> {
+  foreach n = g.val in
+    def _#g#_#n;
+}
+
+def G0 : G;
+
+foreach g = [G0] in
+  defm H0 : H<g>;


        


More information about the llvm-commits mailing list