From: Craig Topper Date: Tue, 22 Sep 2015 05:37:12 +0000 (+0000) Subject: Use makeArrayRef and None to simplify some code in a tablegen register info file... X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=e32e1f4c62b39ad9cca2aa67d6612f21255163bb 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@248244 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/utils/TableGen/RegisterInfoEmitter.cpp b/utils/TableGen/RegisterInfoEmitter.cpp index 7c14febd494..f58a04a93af 100644 --- a/utils/TableGen/RegisterInfoEmitter.cpp +++ b/utils/TableGen/RegisterInfoEmitter.cpp @@ -1452,22 +1452,28 @@ RegisterInfoEmitter::runTargetDesc(raw_ostream &OS, CodeGenTarget &Target, OS << "ArrayRef " << 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(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 " << 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(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 *"