[llvm] r248244 - Use makeArrayRef and None to simplify some code in a tablegen register info file. Additionally const correct a couple static array.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 21 22:37:12 PDT 2015


Author: ctopper
Date: Tue Sep 22 00:37:12 2015
New Revision: 248244

URL: http://llvm.org/viewvc/llvm-project?rev=248244&view=rev
Log:
Use makeArrayRef and None to simplify some code in a tablegen register info file. Additionally const correct a couple static array.

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.

Modified:
    llvm/trunk/utils/TableGen/RegisterInfoEmitter.cpp

Modified: llvm/trunk/utils/TableGen/RegisterInfoEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/RegisterInfoEmitter.cpp?rev=248244&r1=248243&r2=248244&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/RegisterInfoEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/RegisterInfoEmitter.cpp Tue Sep 22 00:37:12 2015
@@ -1452,22 +1452,28 @@ RegisterInfoEmitter::runTargetDesc(raw_o
 
   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 *"




More information about the llvm-commits mailing list