[llvm] 21db4cc - [SystemZ][z/OS] Remove register prefixes when printing out the register.

Anirudh Prasad via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 27 10:47:38 PDT 2021


Author: Anirudh Prasad
Date: 2021-04-27T13:47:32-04:00
New Revision: 21db4cc2ea1518900b4a4c8235c4e1131fa0e613

URL: https://github.com/llvm/llvm-project/commit/21db4cc2ea1518900b4a4c8235c4e1131fa0e613
DIFF: https://github.com/llvm/llvm-project/commit/21db4cc2ea1518900b4a4c8235c4e1131fa0e613.diff

LOG: [SystemZ][z/OS] Remove register prefixes when printing out the register.

- This patch is the first part in enforcing prefix-less registers for the HLASM dialect in z/OS
- This patch removes the "%[r|f|v]" prefix while printing registers
- To achieve this, the `AssemblerDialect` field of MAI was used
- There is also a bit of refactoring done to ensure code repetition is reduced.
- Currently the LLVM assembler for SystemZ/z/OS accepts both prefixed registers and prefix-less registers. A subsequent follow-up patch will restrict the SystemZAsmParser to only accept prefix-less registers.

Crediting @kianm as an author as well.

Reviewed By: uweigand, abhina.sreeskantharajan

Differential Revision: https://reviews.llvm.org/D101308

Added: 
    

Modified: 
    llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinter.cpp
    llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinter.h
    llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinter.cpp b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinter.cpp
index fac363cae713b..f3f3f096da339 100644
--- a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinter.cpp
+++ b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinter.cpp
@@ -23,18 +23,19 @@ using namespace llvm;
 
 #include "SystemZGenAsmWriter.inc"
 
-void SystemZInstPrinter::printAddress(unsigned Base, int64_t Disp,
-                                      unsigned Index, raw_ostream &O) {
+void SystemZInstPrinter::printAddress(const MCAsmInfo *MAI, unsigned Base,
+                                      int64_t Disp, unsigned Index,
+                                      raw_ostream &O) {
   O << Disp;
   if (Base || Index) {
     O << '(';
     if (Index) {
-      O << '%' << getRegisterName(Index);
+      printFormattedRegName(MAI, Index, O);
       if (Base)
         O << ',';
     }
     if (Base)
-      O << '%' << getRegisterName(Base);
+      printFormattedRegName(MAI, Base, O);
     O << ')';
   }
 }
@@ -45,7 +46,7 @@ void SystemZInstPrinter::printOperand(const MCOperand &MO, const MCAsmInfo *MAI,
     if (!MO.getReg())
       O << '0';
     else
-      O << '%' << getRegisterName(MO.getReg());
+      printFormattedRegName(MAI, MO.getReg(), O);
   }
   else if (MO.isImm())
     O << MO.getImm();
@@ -55,6 +56,17 @@ void SystemZInstPrinter::printOperand(const MCOperand &MO, const MCAsmInfo *MAI,
     llvm_unreachable("Invalid operand");
 }
 
+void SystemZInstPrinter::printFormattedRegName(const MCAsmInfo *MAI,
+                                               unsigned RegNo, raw_ostream &O) {
+  const char *RegName = getRegisterName(RegNo);
+  if (MAI->getAssemblerDialect() == AD_HLASM) {
+    // Skip register prefix so that only register number is left
+    assert(isalpha(RegName[0]) && isdigit(RegName[1]));
+    O << (RegName + 1);
+  } else
+    O << '%' << RegName;
+}
+
 void SystemZInstPrinter::printInst(const MCInst *MI, uint64_t Address,
                                    StringRef Annot, const MCSubtargetInfo &STI,
                                    raw_ostream &O) {
@@ -62,10 +74,6 @@ void SystemZInstPrinter::printInst(const MCInst *MI, uint64_t Address,
   printAnnotation(O, Annot);
 }
 
-void SystemZInstPrinter::printRegName(raw_ostream &O, unsigned RegNo) const {
-  O << '%' << getRegisterName(RegNo);
-}
-
 template <unsigned N>
 static void printUImmOperand(const MCInst *MI, int OpNum, raw_ostream &O) {
   int64_t Value = MI->getOperand(OpNum).getImm();
@@ -186,13 +194,13 @@ void SystemZInstPrinter::printOperand(const MCInst *MI, int OpNum,
 
 void SystemZInstPrinter::printBDAddrOperand(const MCInst *MI, int OpNum,
                                             raw_ostream &O) {
-  printAddress(MI->getOperand(OpNum).getReg(),
+  printAddress(&MAI, MI->getOperand(OpNum).getReg(),
                MI->getOperand(OpNum + 1).getImm(), 0, O);
 }
 
 void SystemZInstPrinter::printBDXAddrOperand(const MCInst *MI, int OpNum,
                                              raw_ostream &O) {
-  printAddress(MI->getOperand(OpNum).getReg(),
+  printAddress(&MAI, MI->getOperand(OpNum).getReg(),
                MI->getOperand(OpNum + 1).getImm(),
                MI->getOperand(OpNum + 2).getReg(), O);
 }
@@ -203,8 +211,10 @@ void SystemZInstPrinter::printBDLAddrOperand(const MCInst *MI, int OpNum,
   uint64_t Disp = MI->getOperand(OpNum + 1).getImm();
   uint64_t Length = MI->getOperand(OpNum + 2).getImm();
   O << Disp << '(' << Length;
-  if (Base)
-    O << ",%" << getRegisterName(Base);
+  if (Base) {
+    O << ",";
+    printRegName(O, Base);
+  }
   O << ')';
 }
 
@@ -213,15 +223,18 @@ void SystemZInstPrinter::printBDRAddrOperand(const MCInst *MI, int OpNum,
   unsigned Base = MI->getOperand(OpNum).getReg();
   uint64_t Disp = MI->getOperand(OpNum + 1).getImm();
   unsigned Length = MI->getOperand(OpNum + 2).getReg();
-  O << Disp << "(%" << getRegisterName(Length);
-  if (Base)
-    O << ",%" << getRegisterName(Base);
+  O << Disp << "(";
+  printRegName(O, Length);
+  if (Base) {
+    O << ",";
+    printRegName(O, Base);
+  }
   O << ')';
 }
 
 void SystemZInstPrinter::printBDVAddrOperand(const MCInst *MI, int OpNum,
                                              raw_ostream &O) {
-  printAddress(MI->getOperand(OpNum).getReg(),
+  printAddress(&MAI, MI->getOperand(OpNum).getReg(),
                MI->getOperand(OpNum + 1).getImm(),
                MI->getOperand(OpNum + 2).getReg(), O);
 }

diff  --git a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinter.h b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinter.h
index 0db7279a06c13..0a57ca0082e61 100644
--- a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinter.h
+++ b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinter.h
@@ -13,6 +13,7 @@
 #ifndef LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZINSTPRINTER_H
 #define LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZINSTPRINTER_H
 
+#include "SystemZMCAsmInfo.h"
 #include "llvm/MC/MCInstPrinter.h"
 #include <cstdint>
 
@@ -32,15 +33,21 @@ class SystemZInstPrinter : public MCInstPrinter {
   static const char *getRegisterName(unsigned RegNo);
 
   // Print an address with the given base, displacement and index.
-  static void printAddress(unsigned Base, int64_t Disp, unsigned Index,
-                           raw_ostream &O);
+  static void printAddress(const MCAsmInfo *MAI, unsigned Base, int64_t Disp,
+                           unsigned Index, raw_ostream &O);
 
   // Print the given operand.
   static void printOperand(const MCOperand &MO, const MCAsmInfo *MAI,
                            raw_ostream &O);
 
+  static void printFormattedRegName(const MCAsmInfo *MAI, unsigned RegNo,
+                                    raw_ostream &O);
+
   // Override MCInstPrinter.
-  void printRegName(raw_ostream &O, unsigned RegNo) const override;
+  inline void printRegName(raw_ostream &O, unsigned RegNo) const override {
+    printFormattedRegName(&MAI, RegNo, O);
+  }
+
   void printInst(const MCInst *MI, uint64_t Address, StringRef Annot,
                  const MCSubtargetInfo &STI, raw_ostream &O) override;
 

diff  --git a/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp b/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
index ea5c3cbc32117..a9d0ed030e5ae 100644
--- a/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
@@ -739,7 +739,7 @@ bool SystemZAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
                                               unsigned OpNo,
                                               const char *ExtraCode,
                                               raw_ostream &OS) {
-  SystemZInstPrinter::printAddress(MI->getOperand(OpNo).getReg(),
+  SystemZInstPrinter::printAddress(MAI, MI->getOperand(OpNo).getReg(),
                                    MI->getOperand(OpNo + 1).getImm(),
                                    MI->getOperand(OpNo + 2).getReg(), OS);
   return false;


        


More information about the llvm-commits mailing list