Skip to content

[SystemZ] Split SystemZInstPrinter to two classes based on Asm dialect #112975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Oct 22, 2024

Conversation

tltao
Copy link
Contributor

@tltao tltao commented Oct 18, 2024

In preparation for future work on separating the output of the GNU/HLASM ASM dialects, we first separate the SystemZInstPrinter classes to two versions, one for each ASM dialect.

The common code remains in a SystemZInstPrinterCommon class instead.

Copy link

github-actions bot commented Oct 18, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@tltao tltao force-pushed the split_instprinter branch from 80cdcf8 to da7ef03 Compare October 21, 2024 19:56
@tltao tltao marked this pull request as ready for review October 21, 2024 20:49
@tltao tltao requested review from uweigand and redstar and removed request for uweigand October 21, 2024 20:49
@llvmbot
Copy link
Member

llvmbot commented Oct 21, 2024

@llvm/pr-subscribers-backend-systemz

Author: None (tltao)

Changes

In preparation for future work on separating the output of the GNU/HLASM ASM dialects, we first separate the SystemZInstPrinter classes to two versions, one for each ASM dialect.

The common code remains in a SystemZInstPrinterCommon class instead.


Patch is 35.27 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/112975.diff

13 Files Affected:

  • (modified) llvm/lib/Target/SystemZ/AsmParser/SystemZAsmParser.cpp (+5-5)
  • (modified) llvm/lib/Target/SystemZ/CMakeLists.txt (+2-1)
  • (modified) llvm/lib/Target/SystemZ/MCTargetDesc/CMakeLists.txt (+3-1)
  • (added) llvm/lib/Target/SystemZ/MCTargetDesc/SystemZGNUInstPrinter.cpp (+33)
  • (added) llvm/lib/Target/SystemZ/MCTargetDesc/SystemZGNUInstPrinter.h (+46)
  • (added) llvm/lib/Target/SystemZ/MCTargetDesc/SystemZHLASMInstPrinter.cpp (+35)
  • (added) llvm/lib/Target/SystemZ/MCTargetDesc/SystemZHLASMInstPrinter.h (+45)
  • (removed) llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinter.cpp (-266)
  • (added) llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinterCommon.cpp (+246)
  • (renamed) llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinterCommon.h (+12-19)
  • (modified) llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCTargetDesc.cpp (+6-2)
  • (modified) llvm/lib/Target/SystemZ/SystemZ.td (+15)
  • (modified) llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp (+7-3)
diff --git a/llvm/lib/Target/SystemZ/AsmParser/SystemZAsmParser.cpp b/llvm/lib/Target/SystemZ/AsmParser/SystemZAsmParser.cpp
index f0a85645b86289..b8469a6ba70eaf 100644
--- a/llvm/lib/Target/SystemZ/AsmParser/SystemZAsmParser.cpp
+++ b/llvm/lib/Target/SystemZ/AsmParser/SystemZAsmParser.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "MCTargetDesc/SystemZInstPrinter.h"
+#include "MCTargetDesc/SystemZGNUInstPrinter.h"
 #include "MCTargetDesc/SystemZMCAsmInfo.h"
 #include "MCTargetDesc/SystemZMCTargetDesc.h"
 #include "SystemZTargetStreamer.h"
@@ -721,7 +721,7 @@ void SystemZOperand::print(raw_ostream &OS) const {
     OS << "Token:" << getToken();
     break;
   case KindReg:
-    OS << "Reg:" << SystemZInstPrinter::getRegisterName(getReg());
+    OS << "Reg:" << SystemZGNUInstPrinter::getRegisterName(getReg());
     break;
   case KindImm:
     OS << "Imm:";
@@ -743,10 +743,10 @@ void SystemZOperand::print(raw_ostream &OS) const {
       if (Op.MemKind == BDLMem)
         OS << *cast<MCConstantExpr>(Op.Length.Imm) << ",";
       else if (Op.MemKind == BDRMem)
-        OS << SystemZInstPrinter::getRegisterName(Op.Length.Reg) << ",";
+        OS << SystemZGNUInstPrinter::getRegisterName(Op.Length.Reg) << ",";
       if (Op.Index)
-        OS << SystemZInstPrinter::getRegisterName(Op.Index) << ",";
-      OS << SystemZInstPrinter::getRegisterName(Op.Base);
+        OS << SystemZGNUInstPrinter::getRegisterName(Op.Index) << ",";
+      OS << SystemZGNUInstPrinter::getRegisterName(Op.Base);
       OS << ")";
     }
     break;
diff --git a/llvm/lib/Target/SystemZ/CMakeLists.txt b/llvm/lib/Target/SystemZ/CMakeLists.txt
index 063e5bcd44171e..0d8f3eac6ee4f4 100644
--- a/llvm/lib/Target/SystemZ/CMakeLists.txt
+++ b/llvm/lib/Target/SystemZ/CMakeLists.txt
@@ -3,7 +3,8 @@ add_llvm_component_group(SystemZ HAS_JIT)
 set(LLVM_TARGET_DEFINITIONS SystemZ.td)
 
 tablegen(LLVM SystemZGenAsmMatcher.inc -gen-asm-matcher)
-tablegen(LLVM SystemZGenAsmWriter.inc -gen-asm-writer)
+tablegen(LLVM SystemZGenGNUAsmWriter.inc -gen-asm-writer)
+tablegen(LLVM SystemZGenHLASMAsmWriter.inc -gen-asm-writer -asmwriternum=1)
 tablegen(LLVM SystemZGenCallingConv.inc -gen-callingconv)
 tablegen(LLVM SystemZGenDAGISel.inc -gen-dag-isel)
 tablegen(LLVM SystemZGenDisassemblerTables.inc -gen-disassembler)
diff --git a/llvm/lib/Target/SystemZ/MCTargetDesc/CMakeLists.txt b/llvm/lib/Target/SystemZ/MCTargetDesc/CMakeLists.txt
index 6700d793697087..9c00706531b88f 100644
--- a/llvm/lib/Target/SystemZ/MCTargetDesc/CMakeLists.txt
+++ b/llvm/lib/Target/SystemZ/MCTargetDesc/CMakeLists.txt
@@ -1,7 +1,9 @@
 add_llvm_component_library(LLVMSystemZDesc
   SystemZELFObjectWriter.cpp
+  SystemZGNUInstPrinter.cpp
   SystemZGOFFObjectWriter.cpp
-  SystemZInstPrinter.cpp
+  SystemZHLASMInstPrinter.cpp
+  SystemZInstPrinterCommon.cpp
   SystemZMCAsmBackend.cpp
   SystemZMCAsmInfo.cpp
   SystemZMCCodeEmitter.cpp
diff --git a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZGNUInstPrinter.cpp b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZGNUInstPrinter.cpp
new file mode 100644
index 00000000000000..05113010794e0b
--- /dev/null
+++ b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZGNUInstPrinter.cpp
@@ -0,0 +1,33 @@
+//===- SystemZGNUInstPrinter.cpp - Convert SystemZ MCInst to GNU assembly -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "SystemZGNUInstPrinter.h"
+#include "llvm/MC/MCInst.h"
+#include "llvm/MC/MCRegister.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace llvm;
+
+#define DEBUG_TYPE "asm-printer"
+
+#include "SystemZGenGNUAsmWriter.inc"
+
+void SystemZGNUInstPrinter::printFormattedRegName(const MCAsmInfo *MAI,
+                                                  MCRegister Reg,
+                                                  raw_ostream &O) const {
+  const char *RegName = getRegisterName(Reg);
+  markup(O, Markup::Register) << '%' << RegName;
+}
+
+void SystemZGNUInstPrinter::printInst(const MCInst *MI, uint64_t Address,
+                                      StringRef Annot,
+                                      const MCSubtargetInfo &STI,
+                                      raw_ostream &O) {
+  printInstruction(MI, Address, O);
+  printAnnotation(O, Annot);
+}
diff --git a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZGNUInstPrinter.h b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZGNUInstPrinter.h
new file mode 100644
index 00000000000000..8f62ae0e16c006
--- /dev/null
+++ b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZGNUInstPrinter.h
@@ -0,0 +1,46 @@
+//=- SystemZGNUInstPrinter.h - Convert SystemZ MCInst to assembly -*- C++ -*-=//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This class prints a SystemZ MCInst to a .s file in GNU assembly format.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZGNUINSTPRINTER_H
+#define LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZGNUINSTPRINTER_H
+
+#include "SystemZInstPrinterCommon.h"
+#include "llvm/MC/MCInstPrinter.h"
+#include <cstdint>
+
+namespace llvm {
+
+class MCOperand;
+
+class SystemZGNUInstPrinter : public SystemZInstPrinterCommon {
+public:
+  SystemZGNUInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII,
+                        const MCRegisterInfo &MRI)
+      : SystemZInstPrinterCommon(MAI, MII, MRI) {}
+
+  // Automatically generated by tblgen.
+  std::pair<const char *, uint64_t> getMnemonic(const MCInst *MI) override;
+  void printInstruction(const MCInst *MI, uint64_t Address, raw_ostream &O);
+  static const char *getRegisterName(MCRegister Reg);
+
+  // Override MCInstPrinter.
+  void printInst(const MCInst *MI, uint64_t Address, StringRef Annot,
+                 const MCSubtargetInfo &STI, raw_ostream &O) override;
+
+private:
+  void printFormattedRegName(const MCAsmInfo *MAI, MCRegister Reg,
+                             raw_ostream &O) const override;
+};
+
+} // end namespace llvm
+
+#endif // LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZGNUINSTPRINTER_H
diff --git a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZHLASMInstPrinter.cpp b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZHLASMInstPrinter.cpp
new file mode 100644
index 00000000000000..ed7ff83a3c6df0
--- /dev/null
+++ b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZHLASMInstPrinter.cpp
@@ -0,0 +1,35 @@
+//=- SystemZHLASMInstPrinter.cpp - Convert SystemZ MCInst to HLASM assembly -=//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "SystemZHLASMInstPrinter.h"
+#include "llvm/MC/MCInst.h"
+#include "llvm/MC/MCRegister.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace llvm;
+
+#define DEBUG_TYPE "asm-printer"
+
+#include "SystemZGenHLASMAsmWriter.inc"
+
+void SystemZHLASMInstPrinter::printFormattedRegName(const MCAsmInfo *MAI,
+                                                    MCRegister Reg,
+                                                    raw_ostream &O) const {
+  const char *RegName = getRegisterName(Reg);
+  // Skip register prefix so that only register number is left
+  assert(isalpha(RegName[0]) && isdigit(RegName[1]));
+  markup(O, Markup::Register) << (RegName + 1);
+}
+
+void SystemZHLASMInstPrinter::printInst(const MCInst *MI, uint64_t Address,
+                                        StringRef Annot,
+                                        const MCSubtargetInfo &STI,
+                                        raw_ostream &O) {
+  printInstruction(MI, Address, O);
+  printAnnotation(O, Annot);
+}
diff --git a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZHLASMInstPrinter.h b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZHLASMInstPrinter.h
new file mode 100644
index 00000000000000..9a69e012c72942
--- /dev/null
+++ b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZHLASMInstPrinter.h
@@ -0,0 +1,45 @@
+//- SystemZHLASMInstPrinter.h - Convert SystemZ MCInst to assembly -*- C++ -*-//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This class prints a SystemZ MCInst to a .s file in HLASM assembly format.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZHLASMINSTPRINTER_H
+#define LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZHLASMINSTPRINTER_H
+
+#include "SystemZInstPrinterCommon.h"
+#include "llvm/MC/MCInstPrinter.h"
+#include <cstdint>
+
+namespace llvm {
+
+class MCOperand;
+
+class SystemZHLASMInstPrinter : public SystemZInstPrinterCommon {
+public:
+  SystemZHLASMInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII,
+                          const MCRegisterInfo &MRI)
+      : SystemZInstPrinterCommon(MAI, MII, MRI) {}
+
+  // Automatically generated by tblgen.
+  std::pair<const char *, uint64_t> getMnemonic(const MCInst *MI) override;
+  void printInstruction(const MCInst *MI, uint64_t Address, raw_ostream &O);
+  static const char *getRegisterName(MCRegister Reg);
+
+  void printInst(const MCInst *MI, uint64_t Address, StringRef Annot,
+                 const MCSubtargetInfo &STI, raw_ostream &O) override;
+
+private:
+  void printFormattedRegName(const MCAsmInfo *MAI, MCRegister Reg,
+                             raw_ostream &O) const override;
+};
+
+} // end namespace llvm
+
+#endif // LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZHLASMINSTPRINTER_H
diff --git a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinter.cpp b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinter.cpp
deleted file mode 100644
index fa534fadc32305..00000000000000
--- a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinter.cpp
+++ /dev/null
@@ -1,266 +0,0 @@
-//===- SystemZInstPrinter.cpp - Convert SystemZ MCInst to assembly syntax -===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "SystemZInstPrinter.h"
-#include "llvm/MC/MCExpr.h"
-#include "llvm/MC/MCInst.h"
-#include "llvm/MC/MCRegister.h"
-#include "llvm/MC/MCSymbol.h"
-#include "llvm/Support/Casting.h"
-#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/MathExtras.h"
-#include "llvm/Support/raw_ostream.h"
-#include <cassert>
-#include <cstdint>
-
-using namespace llvm;
-
-#define DEBUG_TYPE "asm-printer"
-
-#include "SystemZGenAsmWriter.inc"
-
-void SystemZInstPrinter::printAddress(const MCAsmInfo *MAI, MCRegister Base,
-                                      const MCOperand &DispMO, MCRegister Index,
-                                      raw_ostream &O) {
-  printOperand(DispMO, MAI, O);
-  if (Base || Index) {
-    O << '(';
-    if (Index) {
-      printFormattedRegName(MAI, Index, O);
-      O << ',';
-    }
-    if (Base)
-      printFormattedRegName(MAI, Base, O);
-    else
-      O << '0';
-    O << ')';
-  }
-}
-
-void SystemZInstPrinter::printOperand(const MCOperand &MO, const MCAsmInfo *MAI,
-                                      raw_ostream &O) {
-  if (MO.isReg()) {
-    if (!MO.getReg())
-      O << '0';
-    else
-      printFormattedRegName(MAI, MO.getReg(), O);
-  }
-  else if (MO.isImm())
-    markup(O, Markup::Immediate) << MO.getImm();
-  else if (MO.isExpr())
-    MO.getExpr()->print(O, MAI);
-  else
-    llvm_unreachable("Invalid operand");
-}
-
-void SystemZInstPrinter::printFormattedRegName(const MCAsmInfo *MAI,
-                                               MCRegister Reg,
-                                               raw_ostream &O) const {
-  const char *RegName = getRegisterName(Reg);
-  if (MAI->getAssemblerDialect() == AD_HLASM) {
-    // Skip register prefix so that only register number is left
-    assert(isalpha(RegName[0]) && isdigit(RegName[1]));
-    markup(O, Markup::Register) << (RegName + 1);
-  } else
-    markup(O, Markup::Register) << '%' << RegName;
-}
-
-void SystemZInstPrinter::printRegName(raw_ostream &O, MCRegister Reg) const {
-  printFormattedRegName(&MAI, Reg, O);
-}
-
-void SystemZInstPrinter::printInst(const MCInst *MI, uint64_t Address,
-                                   StringRef Annot, const MCSubtargetInfo &STI,
-                                   raw_ostream &O) {
-  printInstruction(MI, Address, O);
-  printAnnotation(O, Annot);
-}
-
-template <unsigned N>
-void SystemZInstPrinter::printUImmOperand(const MCInst *MI, int OpNum,
-                                          raw_ostream &O) {
-  const MCOperand &MO = MI->getOperand(OpNum);
-  if (MO.isExpr()) {
-    O << *MO.getExpr();
-    return;
-  }
-  uint64_t Value = static_cast<uint64_t>(MO.getImm());
-  assert(isUInt<N>(Value) && "Invalid uimm argument");
-  markup(O, Markup::Immediate) << Value;
-}
-
-template <unsigned N>
-void SystemZInstPrinter::printSImmOperand(const MCInst *MI, int OpNum,
-                                          raw_ostream &O) {
-  const MCOperand &MO = MI->getOperand(OpNum);
-  if (MO.isExpr()) {
-    O << *MO.getExpr();
-    return;
-  }
-  int64_t Value = MI->getOperand(OpNum).getImm();
-  assert(isInt<N>(Value) && "Invalid simm argument");
-  markup(O, Markup::Immediate) << Value;
-}
-
-void SystemZInstPrinter::printU1ImmOperand(const MCInst *MI, int OpNum,
-                                           raw_ostream &O) {
-  printUImmOperand<1>(MI, OpNum, O);
-}
-
-void SystemZInstPrinter::printU2ImmOperand(const MCInst *MI, int OpNum,
-                                           raw_ostream &O) {
-  printUImmOperand<2>(MI, OpNum, O);
-}
-
-void SystemZInstPrinter::printU3ImmOperand(const MCInst *MI, int OpNum,
-                                           raw_ostream &O) {
-  printUImmOperand<3>(MI, OpNum, O);
-}
-
-void SystemZInstPrinter::printU4ImmOperand(const MCInst *MI, int OpNum,
-                                           raw_ostream &O) {
-  printUImmOperand<4>(MI, OpNum, O);
-}
-
-void SystemZInstPrinter::printS8ImmOperand(const MCInst *MI, int OpNum,
-                                           raw_ostream &O) {
-  printSImmOperand<8>(MI, OpNum, O);
-}
-
-void SystemZInstPrinter::printU8ImmOperand(const MCInst *MI, int OpNum,
-                                           raw_ostream &O) {
-  printUImmOperand<8>(MI, OpNum, O);
-}
-
-void SystemZInstPrinter::printU12ImmOperand(const MCInst *MI, int OpNum,
-                                            raw_ostream &O) {
-  printUImmOperand<12>(MI, OpNum, O);
-}
-
-void SystemZInstPrinter::printS16ImmOperand(const MCInst *MI, int OpNum,
-                                            raw_ostream &O) {
-  printSImmOperand<16>(MI, OpNum, O);
-}
-
-void SystemZInstPrinter::printU16ImmOperand(const MCInst *MI, int OpNum,
-                                            raw_ostream &O) {
-  printUImmOperand<16>(MI, OpNum, O);
-}
-
-void SystemZInstPrinter::printS32ImmOperand(const MCInst *MI, int OpNum,
-                                            raw_ostream &O) {
-  printSImmOperand<32>(MI, OpNum, O);
-}
-
-void SystemZInstPrinter::printU32ImmOperand(const MCInst *MI, int OpNum,
-                                            raw_ostream &O) {
-  printUImmOperand<32>(MI, OpNum, O);
-}
-
-void SystemZInstPrinter::printU48ImmOperand(const MCInst *MI, int OpNum,
-                                            raw_ostream &O) {
-  printUImmOperand<48>(MI, OpNum, O);
-}
-
-void SystemZInstPrinter::printPCRelOperand(const MCInst *MI, int OpNum,
-                                           raw_ostream &O) {
-  const MCOperand &MO = MI->getOperand(OpNum);
-  if (MO.isImm()) {
-    WithMarkup M = markup(O, Markup::Immediate);
-    O << "0x";
-    O.write_hex(MO.getImm());
-  } else
-    MO.getExpr()->print(O, &MAI);
-}
-
-void SystemZInstPrinter::printPCRelTLSOperand(const MCInst *MI,
-                                              uint64_t Address, int OpNum,
-                                              raw_ostream &O) {
-  // Output the PC-relative operand.
-  printPCRelOperand(MI, OpNum, O);
-
-  // Output the TLS marker if present.
-  if ((unsigned)OpNum + 1 < MI->getNumOperands()) {
-    const MCOperand &MO = MI->getOperand(OpNum + 1);
-    const MCSymbolRefExpr &refExp = cast<MCSymbolRefExpr>(*MO.getExpr());
-    switch (refExp.getKind()) {
-      case MCSymbolRefExpr::VK_TLSGD:
-        O << ":tls_gdcall:";
-        break;
-      case MCSymbolRefExpr::VK_TLSLDM:
-        O << ":tls_ldcall:";
-        break;
-      default:
-        llvm_unreachable("Unexpected symbol kind");
-    }
-    O << refExp.getSymbol().getName();
-  }
-}
-
-void SystemZInstPrinter::printOperand(const MCInst *MI, int OpNum,
-                                      raw_ostream &O) {
-  printOperand(MI->getOperand(OpNum), &MAI, O);
-}
-
-void SystemZInstPrinter::printBDAddrOperand(const MCInst *MI, int OpNum,
-                                            raw_ostream &O) {
-  printAddress(&MAI, MI->getOperand(OpNum).getReg(), MI->getOperand(OpNum + 1),
-               0, O);
-}
-
-void SystemZInstPrinter::printBDXAddrOperand(const MCInst *MI, int OpNum,
-                                             raw_ostream &O) {
-  printAddress(&MAI, MI->getOperand(OpNum).getReg(), MI->getOperand(OpNum + 1),
-               MI->getOperand(OpNum + 2).getReg(), O);
-}
-
-void SystemZInstPrinter::printBDLAddrOperand(const MCInst *MI, int OpNum,
-                                             raw_ostream &O) {
-  unsigned Base = MI->getOperand(OpNum).getReg();
-  const MCOperand &DispMO = MI->getOperand(OpNum + 1);
-  uint64_t Length = MI->getOperand(OpNum + 2).getImm();
-  printOperand(DispMO, &MAI, O);
-  O << '(' << Length;
-  if (Base) {
-    O << ",";
-    printRegName(O, Base);
-  }
-  O << ')';
-}
-
-void SystemZInstPrinter::printBDRAddrOperand(const MCInst *MI, int OpNum,
-                                             raw_ostream &O) {
-  unsigned Base = MI->getOperand(OpNum).getReg();
-  const MCOperand &DispMO = MI->getOperand(OpNum + 1);
-  unsigned Length = MI->getOperand(OpNum + 2).getReg();
-  printOperand(DispMO, &MAI, O);
-  O << "(";
-  printRegName(O, Length);
-  if (Base) {
-    O << ",";
-    printRegName(O, Base);
-  }
-  O << ')';
-}
-
-void SystemZInstPrinter::printBDVAddrOperand(const MCInst *MI, int OpNum,
-                                             raw_ostream &O) {
-  printAddress(&MAI, MI->getOperand(OpNum).getReg(), MI->getOperand(OpNum + 1),
-               MI->getOperand(OpNum + 2).getReg(), O);
-}
-
-void SystemZInstPrinter::printCond4Operand(const MCInst *MI, int OpNum,
-                                           raw_ostream &O) {
-  static const char *const CondNames[] = {
-    "o", "h", "nle", "l", "nhe", "lh", "ne",
-    "e", "nlh", "he", "nl", "le", "nh", "no"
-  };
-  uint64_t Imm = MI->getOperand(OpNum).getImm();
-  assert(Imm > 0 && Imm < 15 && "Invalid condition");
-  O << CondNames[Imm - 1];
-}
diff --git a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinterCommon.cpp b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinterCommon.cpp
new file mode 100644
index 00000000000000..00560ab1f4b18d
--- /dev/null
+++ b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinterCommon.cpp
@@ -0,0 +1,246 @@
+//=- SystemZInstPrinterCommon.cpp - Common SystemZ MCInst to assembly funcs -=//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------==...
[truncated]

Copy link
Member

@uweigand uweigand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@tltao tltao merged commit 6512a8d into llvm:main Oct 22, 2024
11 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Oct 22, 2024

LLVM Buildbot has detected a new failure on builder lld-x86_64-win running on as-worker-93 while building llvm at step 7 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/146/builds/1434

Here is the relevant piece of the build log for the reference
Step 7 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'LLVM-Unit :: Support/./SupportTests.exe/35/87' FAILED ********************
Script(shard):
--
GTEST_OUTPUT=json:C:\a\lld-x86_64-win\build\unittests\Support\.\SupportTests.exe-LLVM-Unit-15928-35-87.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=87 GTEST_SHARD_INDEX=35 C:\a\lld-x86_64-win\build\unittests\Support\.\SupportTests.exe
--

Script:
--
C:\a\lld-x86_64-win\build\unittests\Support\.\SupportTests.exe --gtest_filter=ProgramEnvTest.CreateProcessLongPath
--
C:\a\lld-x86_64-win\llvm-project\llvm\unittests\Support\ProgramTest.cpp(160): error: Expected equality of these values:
  0
  RC
    Which is: -2

C:\a\lld-x86_64-win\llvm-project\llvm\unittests\Support\ProgramTest.cpp(163): error: fs::remove(Twine(LongPath)): did not return errc::success.
error number: 13
error message: permission denied



C:\a\lld-x86_64-win\llvm-project\llvm\unittests\Support\ProgramTest.cpp:160
Expected equality of these values:
  0
  RC
    Which is: -2

C:\a\lld-x86_64-win\llvm-project\llvm\unittests\Support\ProgramTest.cpp:163
fs::remove(Twine(LongPath)): did not return errc::success.
error number: 13
error message: permission denied




********************


@tltao
Copy link
Contributor Author

tltao commented Oct 22, 2024

LLVM Buildbot has detected a new failure on builder lld-x86_64-win running on as-worker-93 while building llvm at step 7 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/146/builds/1434

Here is the relevant piece of the build log for the reference

This failure does not look related to this PR and appears to be a machine issue.

chapuni added a commit that referenced this pull request Oct 23, 2024
tltao added a commit that referenced this pull request Oct 23, 2024
… tests (#113369)

Now that the GNU and HLASM `InstPrinter` paths are separated in
#112975, differentiate between
them in `SystemZInstrFormats.td`.

The main difference are:
- Tabs converted to space
- Remove space after comma for instruction operands

---------

Co-authored-by: Tony Tao <[email protected]>
NoumanAmir657 pushed a commit to NoumanAmir657/llvm-project that referenced this pull request Nov 4, 2024
… tests (llvm#113369)

Now that the GNU and HLASM `InstPrinter` paths are separated in
llvm#112975, differentiate between
them in `SystemZInstrFormats.td`.

The main difference are:
- Tabs converted to space
- Remove space after comma for instruction operands

---------

Co-authored-by: Tony Tao <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants