[PATCH] D36260: [ARM] Use searchable-table for banked registers

Javed Absar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 3 20:41:28 PDT 2017


javed.absar updated this revision to Diff 109679.
javed.absar added a comment.

Revised based on review comments


https://reviews.llvm.org/D36260

Files:
  lib/Target/ARM/InstPrinter/ARMInstPrinter.cpp


Index: lib/Target/ARM/InstPrinter/ARMInstPrinter.cpp
===================================================================
--- lib/Target/ARM/InstPrinter/ARMInstPrinter.cpp
+++ lib/Target/ARM/InstPrinter/ARMInstPrinter.cpp
@@ -873,52 +873,16 @@
                                            const MCSubtargetInfo &STI,
                                            raw_ostream &O) {
   uint32_t Banked = MI->getOperand(OpNum).getImm();
-  uint32_t R = (Banked & 0x20) >> 5;
-  uint32_t SysM = Banked & 0x1f;
+  auto TheReg = ARMBankedReg::lookupBankedRegByEncoding(Banked);
+  assert(TheReg && "invalid banked register operand");
+  std::string Name = TheReg->Name;
 
   // Nothing much we can do about this, the encodings are specified in B9.2.3 of
   // the ARM ARM v7C, and are all over the shop.
-  if (R) {
-    O << "SPSR_";
-
-    switch (SysM) {
-    case 0x0e:
-      O << "fiq";
-      return;
-    case 0x10:
-      O << "irq";
-      return;
-    case 0x12:
-      O << "svc";
-      return;
-    case 0x14:
-      O << "abt";
-      return;
-    case 0x16:
-      O << "und";
-      return;
-    case 0x1c:
-      O << "mon";
-      return;
-    case 0x1e:
-      O << "hyp";
-      return;
-    default:
-      llvm_unreachable("Invalid banked SPSR register");
-    }
-  }
-
-  assert(!R && "should have dealt with SPSR regs");
-  const char *RegNames[] = {
-      "r8_usr", "r9_usr", "r10_usr", "r11_usr", "r12_usr", "sp_usr",  "lr_usr",
-      "",       "r8_fiq", "r9_fiq",  "r10_fiq", "r11_fiq", "r12_fiq", "sp_fiq",
-      "lr_fiq", "",       "lr_irq",  "sp_irq",  "lr_svc",  "sp_svc",  "lr_abt",
-      "sp_abt", "lr_und", "sp_und",  "",        "",        "",        "",
-      "lr_mon", "sp_mon", "elr_hyp", "sp_hyp"};
-  const char *Name = RegNames[SysM];
-  assert(Name[0] && "invalid banked register operand");
-
-  O << Name;
+  uint32_t R = (Banked & 0x20) >> 5;
+  if (R)
+    Name.replace(0, 4, "SPSR"); // convert 'spsr_' to 'SPSR_'
+  O << name;
 }
 
 void ARMInstPrinter::printPredicateOperand(const MCInst *MI, unsigned OpNum,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36260.109679.patch
Type: text/x-patch
Size: 2052 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170804/45ac1585/attachment.bin>


More information about the llvm-commits mailing list