forked from OSchip/llvm-project
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. llvm-svn: 248244
This commit is contained in:
parent
adb99821bc
commit
859adfaf5e
|
@ -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";
|
||||
if (!CSRSets.empty()) {
|
||||
OS << " static const uint32_t *const 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";
|
||||
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";
|
||||
if (!CSRSets.empty()) {
|
||||
OS << " static const char *const 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";
|
||||
OS << " };\n";
|
||||
OS << " return makeArrayRef(Names);\n";
|
||||
} else {
|
||||
OS << " return None;\n";
|
||||
}
|
||||
OS << "}\n\n";
|
||||
|
||||
OS << "const " << TargetName << "FrameLowering *"
|
||||
|
|
Loading…
Reference in New Issue