Use makeArrayRef and None to simplify some code in a tablegen register info file...
authorCraig Topper <craig.topper@gmail.com>
Tue, 22 Sep 2015 05:37:12 +0000 (05:37 +0000)
committerCraig Topper <craig.topper@gmail.com>
Tue, 22 Sep 2015 05:37:12 +0000 (05:37 +0000)
Previously the code added an extra nullptr entry to a static array and then created an ArrayRef with a size one less than the static array. If there were no other entries the array would just contain the nullptr and the ArrayRef would be crated with size 0.

Instead, put the right number of entries in the array and explicitly emit 'None' if the size would be 0. This allows the static array constructor of makeArrayRef to be used.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@248244 91177308-0d34-0410-b5e6-96231b3b80d8

utils/TableGen/RegisterInfoEmitter.cpp

index 7c14febd494e11b273e6b681d75accb4a6507e21..f58a04a93afe40f55f5ead5618bf842fae9dc9a0 100644 (file)
@@ -1452,22 +1452,28 @@ RegisterInfoEmitter::runTargetDesc(raw_ostream &OS, CodeGenTarget &Target,
 
   OS << "ArrayRef<const uint32_t *> " << ClassName
      << "::getRegMasks() const {\n";
-  OS << "  static const uint32_t *Masks[] = {\n";
-  for (Record *CSRSet : CSRSets)
-    OS << "    " << CSRSet->getName() << "_RegMask, \n";
-  OS << "    nullptr\n  };\n";
-  OS << "  return ArrayRef<const uint32_t *>(Masks, (size_t)" << CSRSets.size()
-     << ");\n";
+  if (!CSRSets.empty()) {
+    OS << "  static const uint32_t *const Masks[] = {\n";
+    for (Record *CSRSet : CSRSets)
+      OS << "    " << CSRSet->getName() << "_RegMask,\n";
+    OS << "  };\n";
+    OS << "  return makeArrayRef(Masks);\n";
+  } else {
+    OS << "  return None;\n";
+  }
   OS << "}\n\n";
 
   OS << "ArrayRef<const char *> " << ClassName
      << "::getRegMaskNames() const {\n";
-  OS << "  static const char *Names[] = {\n";
-  for (Record *CSRSet : CSRSets)
-    OS << "    " << '"' << CSRSet->getName() << '"' << ",\n";
-  OS << "    nullptr\n  };\n";
-  OS << "  return ArrayRef<const char *>(Names, (size_t)" << CSRSets.size()
-     << ");\n";
+  if (!CSRSets.empty()) {
+  OS << "  static const char *const Names[] = {\n";
+    for (Record *CSRSet : CSRSets)
+      OS << "    " << '"' << CSRSet->getName() << '"' << ",\n";
+    OS << "  };\n";
+    OS << "  return makeArrayRef(Names);\n";
+  } else {
+    OS << "  return None;\n";
+  }
   OS << "}\n\n";
 
   OS << "const " << TargetName << "FrameLowering *"