Skip to content

Commit

Permalink
[SystemZ] Split SystemZInstPrinter to two classes based on Asm dialect (
Browse files Browse the repository at this point in the history
#112975)

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.

---------

Co-authored-by: Tony Tao <[email protected]>
  • Loading branch information
tltao and Tony Tao authored Oct 22, 2024
1 parent 6761b24 commit 6512a8d
Show file tree
Hide file tree
Showing 13 changed files with 455 additions and 297 deletions.
10 changes: 5 additions & 5 deletions llvm/lib/Target/SystemZ/AsmParser/SystemZAsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//

#include "MCTargetDesc/SystemZInstPrinter.h"
#include "MCTargetDesc/SystemZGNUInstPrinter.h"
#include "MCTargetDesc/SystemZMCAsmInfo.h"
#include "MCTargetDesc/SystemZMCTargetDesc.h"
#include "SystemZTargetStreamer.h"
Expand Down Expand Up @@ -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:";
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/Target/SystemZ/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion llvm/lib/Target/SystemZ/MCTargetDesc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
33 changes: 33 additions & 0 deletions llvm/lib/Target/SystemZ/MCTargetDesc/SystemZGNUInstPrinter.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
46 changes: 46 additions & 0 deletions llvm/lib/Target/SystemZ/MCTargetDesc/SystemZGNUInstPrinter.h
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions llvm/lib/Target/SystemZ/MCTargetDesc/SystemZHLASMInstPrinter.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
45 changes: 45 additions & 0 deletions llvm/lib/Target/SystemZ/MCTargetDesc/SystemZHLASMInstPrinter.h
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 6512a8d

Please sign in to comment.