[PATCH] D15044: [TableGen] Fix bug in printing namespace for register altname indices in AsmWriterEmitter

Alex Bradbury via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 27 07:00:07 PST 2015


asb created this revision.
asb added reviewers: stoklund, grosbach.
asb added a subscriber: llvm-commits.

AsmWriterEmitter will generate a getRegisterName function with an alternate register name index as its second argument if the target makes use of them. The enum of these values is generated in RegisterInfoEmitter. The getRegisterName generator would assume the namespace could always be found by reading index 1 of the list of AltNameIndices, but this will fail if this list is sorted such that the NoRegAltName is at index 1. Because this list is sorted by record name (in CodeGenTarget::ReadRegAltNameIndices), you only run in to problems if your MyTargetRegisterInfo.td defines a single RegAltNameIndex that sorts lexically before NoRegAltName.

i.e. if a target has something like `def AnAltNameIndex : RegAltNameIndex` and defines RegAltNameIndices for some registers then without this patch, AsmWriterEmitter will generate references to `::AnAltNameIndex` and `::NoRegAltName`.

Adding Jakob Oleson (TableGen code owner) and Jim Grosbach (original author of the RegAltName code) as reviewers. This patch is relevant to D14994 the two patches are independent.

Patch by Alex Bradbury

http://reviews.llvm.org/D15044

Files:
  utils/TableGen/AsmWriterEmitter.cpp

Index: utils/TableGen/AsmWriterEmitter.cpp
===================================================================
--- utils/TableGen/AsmWriterEmitter.cpp
+++ utils/TableGen/AsmWriterEmitter.cpp
@@ -586,6 +586,8 @@
   const auto &Registers = Target.getRegBank().getRegisters();
   std::vector<Record*> AltNameIndices = Target.getRegAltNameIndices();
   bool hasAltNames = AltNameIndices.size() > 1;
+  std::string Namespace =
+      Registers.front().TheDef->getValueAsString("Namespace");
 
   O <<
   "\n\n/// getRegisterName - This method is automatically generated by tblgen\n"
@@ -610,9 +612,9 @@
     O << "  switch(AltIdx) {\n"
       << "  default: llvm_unreachable(\"Invalid register alt name index!\");\n";
     for (unsigned i = 0, e = AltNameIndices.size(); i < e; ++i) {
-      std::string Namespace = AltNameIndices[1]->getValueAsString("Namespace");
       std::string AltName(AltNameIndices[i]->getName());
-      O << "  case " << Namespace << "::" << AltName << ":\n"
+      std::string Prefix = Namespace.empty() ? Namespace + "::" : "";
+      O << "  case " << Prefix << AltName << ":\n"
         << "    assert(*(AsmStrs" << AltName << "+RegAsmOffset"
         << AltName << "[RegNo-1]) &&\n"
         << "           \"Invalid alt name index for register!\");\n"


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15044.41304.patch
Type: text/x-patch
Size: 1281 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151127/8875b63a/attachment.bin>


More information about the llvm-commits mailing list