[PATCH] D29049: TableGen: Fix infinite recursion in RegisterBankEmitter
Tom Stellard via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 27 13:44:56 PST 2017
tstellarAMD updated this revision to Diff 86113.
tstellarAMD added a comment.
Herald added a subscriber: tpr.
Keep track of visited register class and make sure that equivalent register
classes are both added to the CoverageData.
https://reviews.llvm.org/D29049
Files:
test/TableGen/RegisterBankEmitter.td
utils/TableGen/RegisterBankEmitter.cpp
Index: utils/TableGen/RegisterBankEmitter.cpp
===================================================================
--- utils/TableGen/RegisterBankEmitter.cpp
+++ 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);
Index: test/TableGen/RegisterBankEmitter.td
===================================================================
--- /dev/null
+++ 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]>;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29049.86113.patch
Type: text/x-patch
Size: 2460 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170127/473fdf29/attachment.bin>
More information about the llvm-commits
mailing list