[PATCH] D29049: TableGen: Fix infinite recursion in RegisterBankEmitter

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 30 07:18:23 PST 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL293483: TableGen: Fix infinite recursion in RegisterBankEmitter (authored by tstellar).

Changed prior to commit:
  https://reviews.llvm.org/D29049?vs=86113&id=86284#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29049

Files:
  llvm/trunk/test/TableGen/RegisterBankEmitter.td
  llvm/trunk/utils/TableGen/RegisterBankEmitter.cpp


Index: llvm/trunk/test/TableGen/RegisterBankEmitter.td
===================================================================
--- llvm/trunk/test/TableGen/RegisterBankEmitter.td
+++ llvm/trunk/test/TableGen/RegisterBankEmitter.td
@@ -0,0 +1,15 @@
+// RUN: llvm-tblgen -gen-register-bank -I %p/../../include %s | FileCheck %s
+
+include "llvm/Target/Target.td"
+
+def MyTarget : Target;
+def R0 : Register<"r0">;
+let Size = 32 in {
+  def ClassA : RegisterClass<"MyTarget", [i32], 32, (add R0)>;
+  def ClassB : RegisterClass<"MyTarget", [i1], 32, (add ClassA)>;
+}
+
+// CHECK: GPRRegBankCoverageData
+// CHECK: MyTarget::ClassARegClassID
+// CHECK: MyTarget::ClassBRegClassID
+def GPRRegBank : RegisterBank<"GPR", [ClassA]>;
Index: llvm/trunk/utils/TableGen/RegisterBankEmitter.cpp
===================================================================
--- llvm/trunk/utils/TableGen/RegisterBankEmitter.cpp
+++ llvm/trunk/utils/TableGen/RegisterBankEmitter.cpp
@@ -168,7 +168,14 @@
 static void visitRegisterBankClasses(
     CodeGenRegBank &RegisterClassHierarchy, const CodeGenRegisterClass *RC,
     const Twine Kind,
-    std::function<void(const CodeGenRegisterClass *, StringRef)> VisitFn) {
+    std::function<void(const CodeGenRegisterClass *, StringRef)> VisitFn,
+    SmallPtrSetImpl<const CodeGenRegisterClass *> &VisitedRCs) {
+
+  // Make sure we only visit each class once to avoid infinite loops.
+  if (VisitedRCs.count(RC))
+    return;
+  VisitedRCs.insert(RC);
+
   // Visit each explicitly named class.
   VisitFn(RC, Kind.str());
 
@@ -180,7 +187,7 @@
     if (RC != &PossibleSubclass && RC->hasSubClass(&PossibleSubclass))
       visitRegisterBankClasses(RegisterClassHierarchy, &PossibleSubclass,
                                TmpKind + " " + RC->getName() + " subclass",
-                               VisitFn);
+                               VisitFn, VisitedRCs);
 
     // Visit each class that contains only subregisters of RC with a common
     // subregister-index.
@@ -273,6 +280,7 @@
 
   std::vector<RegisterBank> Banks;
   for (const auto &V : Records.getAllDerivedDefinitions("RegisterBank")) {
+    SmallPtrSet<const CodeGenRegisterClass *, 8> VisitedRCs;
     RegisterBank Bank(*V);
 
     for (const CodeGenRegisterClass *RC :
@@ -282,7 +290,7 @@
           [&Bank](const CodeGenRegisterClass *RC, StringRef Kind) {
             DEBUG(dbgs() << "Added " << RC->getName() << "(" << Kind << ")\n");
             Bank.addRegisterClass(RC);
-          });
+          }, VisitedRCs);
     }
 
     Banks.push_back(Bank);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29049.86284.patch
Type: text/x-patch
Size: 2553 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170130/a45376d8/attachment.bin>


More information about the llvm-commits mailing list