Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6512a8d

Browse files
tltaoTony Tao
andauthoredOct 22, 2024··
[SystemZ] Split SystemZInstPrinter to two classes based on Asm dialect (#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]>
1 parent 6761b24 commit 6512a8d

13 files changed

+455
-297
lines changed
 

‎llvm/lib/Target/SystemZ/AsmParser/SystemZAsmParser.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "MCTargetDesc/SystemZInstPrinter.h"
9+
#include "MCTargetDesc/SystemZGNUInstPrinter.h"
1010
#include "MCTargetDesc/SystemZMCAsmInfo.h"
1111
#include "MCTargetDesc/SystemZMCTargetDesc.h"
1212
#include "SystemZTargetStreamer.h"
@@ -721,7 +721,7 @@ void SystemZOperand::print(raw_ostream &OS) const {
721721
OS << "Token:" << getToken();
722722
break;
723723
case KindReg:
724-
OS << "Reg:" << SystemZInstPrinter::getRegisterName(getReg());
724+
OS << "Reg:" << SystemZGNUInstPrinter::getRegisterName(getReg());
725725
break;
726726
case KindImm:
727727
OS << "Imm:";
@@ -743,10 +743,10 @@ void SystemZOperand::print(raw_ostream &OS) const {
743743
if (Op.MemKind == BDLMem)
744744
OS << *cast<MCConstantExpr>(Op.Length.Imm) << ",";
745745
else if (Op.MemKind == BDRMem)
746-
OS << SystemZInstPrinter::getRegisterName(Op.Length.Reg) << ",";
746+
OS << SystemZGNUInstPrinter::getRegisterName(Op.Length.Reg) << ",";
747747
if (Op.Index)
748-
OS << SystemZInstPrinter::getRegisterName(Op.Index) << ",";
749-
OS << SystemZInstPrinter::getRegisterName(Op.Base);
748+
OS << SystemZGNUInstPrinter::getRegisterName(Op.Index) << ",";
749+
OS << SystemZGNUInstPrinter::getRegisterName(Op.Base);
750750
OS << ")";
751751
}
752752
break;

‎llvm/lib/Target/SystemZ/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ add_llvm_component_group(SystemZ HAS_JIT)
33
set(LLVM_TARGET_DEFINITIONS SystemZ.td)
44

55
tablegen(LLVM SystemZGenAsmMatcher.inc -gen-asm-matcher)
6-
tablegen(LLVM SystemZGenAsmWriter.inc -gen-asm-writer)
6+
tablegen(LLVM SystemZGenGNUAsmWriter.inc -gen-asm-writer)
7+
tablegen(LLVM SystemZGenHLASMAsmWriter.inc -gen-asm-writer -asmwriternum=1)
78
tablegen(LLVM SystemZGenCallingConv.inc -gen-callingconv)
89
tablegen(LLVM SystemZGenDAGISel.inc -gen-dag-isel)
910
tablegen(LLVM SystemZGenDisassemblerTables.inc -gen-disassembler)

‎llvm/lib/Target/SystemZ/MCTargetDesc/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
add_llvm_component_library(LLVMSystemZDesc
22
SystemZELFObjectWriter.cpp
3+
SystemZGNUInstPrinter.cpp
34
SystemZGOFFObjectWriter.cpp
4-
SystemZInstPrinter.cpp
5+
SystemZHLASMInstPrinter.cpp
6+
SystemZInstPrinterCommon.cpp
57
SystemZMCAsmBackend.cpp
68
SystemZMCAsmInfo.cpp
79
SystemZMCCodeEmitter.cpp
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//===- SystemZGNUInstPrinter.cpp - Convert SystemZ MCInst to GNU assembly -===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "SystemZGNUInstPrinter.h"
10+
#include "llvm/MC/MCInst.h"
11+
#include "llvm/MC/MCRegister.h"
12+
#include "llvm/Support/raw_ostream.h"
13+
14+
using namespace llvm;
15+
16+
#define DEBUG_TYPE "asm-printer"
17+
18+
#include "SystemZGenGNUAsmWriter.inc"
19+
20+
void SystemZGNUInstPrinter::printFormattedRegName(const MCAsmInfo *MAI,
21+
MCRegister Reg,
22+
raw_ostream &O) const {
23+
const char *RegName = getRegisterName(Reg);
24+
markup(O, Markup::Register) << '%' << RegName;
25+
}
26+
27+
void SystemZGNUInstPrinter::printInst(const MCInst *MI, uint64_t Address,
28+
StringRef Annot,
29+
const MCSubtargetInfo &STI,
30+
raw_ostream &O) {
31+
printInstruction(MI, Address, O);
32+
printAnnotation(O, Annot);
33+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//=- SystemZGNUInstPrinter.h - Convert SystemZ MCInst to assembly -*- C++ -*-=//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This class prints a SystemZ MCInst to a .s file in GNU assembly format.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZGNUINSTPRINTER_H
14+
#define LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZGNUINSTPRINTER_H
15+
16+
#include "SystemZInstPrinterCommon.h"
17+
#include "llvm/MC/MCInstPrinter.h"
18+
#include <cstdint>
19+
20+
namespace llvm {
21+
22+
class MCOperand;
23+
24+
class SystemZGNUInstPrinter : public SystemZInstPrinterCommon {
25+
public:
26+
SystemZGNUInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII,
27+
const MCRegisterInfo &MRI)
28+
: SystemZInstPrinterCommon(MAI, MII, MRI) {}
29+
30+
// Automatically generated by tblgen.
31+
std::pair<const char *, uint64_t> getMnemonic(const MCInst *MI) override;
32+
void printInstruction(const MCInst *MI, uint64_t Address, raw_ostream &O);
33+
static const char *getRegisterName(MCRegister Reg);
34+
35+
// Override MCInstPrinter.
36+
void printInst(const MCInst *MI, uint64_t Address, StringRef Annot,
37+
const MCSubtargetInfo &STI, raw_ostream &O) override;
38+
39+
private:
40+
void printFormattedRegName(const MCAsmInfo *MAI, MCRegister Reg,
41+
raw_ostream &O) const override;
42+
};
43+
44+
} // end namespace llvm
45+
46+
#endif // LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZGNUINSTPRINTER_H
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//=- SystemZHLASMInstPrinter.cpp - Convert SystemZ MCInst to HLASM assembly -=//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "SystemZHLASMInstPrinter.h"
10+
#include "llvm/MC/MCInst.h"
11+
#include "llvm/MC/MCRegister.h"
12+
#include "llvm/Support/raw_ostream.h"
13+
14+
using namespace llvm;
15+
16+
#define DEBUG_TYPE "asm-printer"
17+
18+
#include "SystemZGenHLASMAsmWriter.inc"
19+
20+
void SystemZHLASMInstPrinter::printFormattedRegName(const MCAsmInfo *MAI,
21+
MCRegister Reg,
22+
raw_ostream &O) const {
23+
const char *RegName = getRegisterName(Reg);
24+
// Skip register prefix so that only register number is left
25+
assert(isalpha(RegName[0]) && isdigit(RegName[1]));
26+
markup(O, Markup::Register) << (RegName + 1);
27+
}
28+
29+
void SystemZHLASMInstPrinter::printInst(const MCInst *MI, uint64_t Address,
30+
StringRef Annot,
31+
const MCSubtargetInfo &STI,
32+
raw_ostream &O) {
33+
printInstruction(MI, Address, O);
34+
printAnnotation(O, Annot);
35+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//- SystemZHLASMInstPrinter.h - Convert SystemZ MCInst to assembly -*- C++ -*-//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This class prints a SystemZ MCInst to a .s file in HLASM assembly format.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZHLASMINSTPRINTER_H
14+
#define LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZHLASMINSTPRINTER_H
15+
16+
#include "SystemZInstPrinterCommon.h"
17+
#include "llvm/MC/MCInstPrinter.h"
18+
#include <cstdint>
19+
20+
namespace llvm {
21+
22+
class MCOperand;
23+
24+
class SystemZHLASMInstPrinter : public SystemZInstPrinterCommon {
25+
public:
26+
SystemZHLASMInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII,
27+
const MCRegisterInfo &MRI)
28+
: SystemZInstPrinterCommon(MAI, MII, MRI) {}
29+
30+
// Automatically generated by tblgen.
31+
std::pair<const char *, uint64_t> getMnemonic(const MCInst *MI) override;
32+
void printInstruction(const MCInst *MI, uint64_t Address, raw_ostream &O);
33+
static const char *getRegisterName(MCRegister Reg);
34+
35+
void printInst(const MCInst *MI, uint64_t Address, StringRef Annot,
36+
const MCSubtargetInfo &STI, raw_ostream &O) override;
37+
38+
private:
39+
void printFormattedRegName(const MCAsmInfo *MAI, MCRegister Reg,
40+
raw_ostream &O) const override;
41+
};
42+
43+
} // end namespace llvm
44+
45+
#endif // LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZHLASMINSTPRINTER_H

‎llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinter.cpp

Lines changed: 0 additions & 266 deletions
This file was deleted.
Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,246 @@
1+
//=- SystemZInstPrinterCommon.cpp - Common SystemZ MCInst to assembly funcs -=//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "SystemZInstPrinterCommon.h"
10+
#include "llvm/MC/MCExpr.h"
11+
#include "llvm/MC/MCInst.h"
12+
#include "llvm/MC/MCRegister.h"
13+
#include "llvm/MC/MCSymbol.h"
14+
#include "llvm/Support/Casting.h"
15+
#include "llvm/Support/ErrorHandling.h"
16+
#include "llvm/Support/MathExtras.h"
17+
#include "llvm/Support/raw_ostream.h"
18+
#include <cassert>
19+
#include <cstdint>
20+
21+
using namespace llvm;
22+
23+
#define DEBUG_TYPE "asm-printer"
24+
25+
void SystemZInstPrinterCommon::printAddress(const MCAsmInfo *MAI,
26+
MCRegister Base,
27+
const MCOperand &DispMO,
28+
MCRegister Index, raw_ostream &O) {
29+
printOperand(DispMO, MAI, O);
30+
if (Base || Index) {
31+
O << '(';
32+
if (Index) {
33+
printRegName(O, Index);
34+
O << ',';
35+
}
36+
if (Base)
37+
printRegName(O, Base);
38+
else
39+
O << '0';
40+
O << ')';
41+
}
42+
}
43+
44+
void SystemZInstPrinterCommon::printOperand(const MCOperand &MO,
45+
const MCAsmInfo *MAI,
46+
raw_ostream &O) {
47+
if (MO.isReg()) {
48+
if (!MO.getReg())
49+
O << '0';
50+
else
51+
printRegName(O, MO.getReg());
52+
} else if (MO.isImm())
53+
markup(O, Markup::Immediate) << MO.getImm();
54+
else if (MO.isExpr())
55+
MO.getExpr()->print(O, MAI);
56+
else
57+
llvm_unreachable("Invalid operand");
58+
}
59+
60+
void SystemZInstPrinterCommon::printRegName(raw_ostream &O,
61+
MCRegister Reg) const {
62+
printFormattedRegName(&MAI, Reg, O);
63+
}
64+
65+
template <unsigned N>
66+
void SystemZInstPrinterCommon::printUImmOperand(const MCInst *MI, int OpNum,
67+
raw_ostream &O) {
68+
const MCOperand &MO = MI->getOperand(OpNum);
69+
if (MO.isExpr()) {
70+
O << *MO.getExpr();
71+
return;
72+
}
73+
uint64_t Value = static_cast<uint64_t>(MO.getImm());
74+
assert(isUInt<N>(Value) && "Invalid uimm argument");
75+
markup(O, Markup::Immediate) << Value;
76+
}
77+
78+
template <unsigned N>
79+
void SystemZInstPrinterCommon::printSImmOperand(const MCInst *MI, int OpNum,
80+
raw_ostream &O) {
81+
const MCOperand &MO = MI->getOperand(OpNum);
82+
if (MO.isExpr()) {
83+
O << *MO.getExpr();
84+
return;
85+
}
86+
int64_t Value = MI->getOperand(OpNum).getImm();
87+
assert(isInt<N>(Value) && "Invalid simm argument");
88+
markup(O, Markup::Immediate) << Value;
89+
}
90+
91+
void SystemZInstPrinterCommon::printU1ImmOperand(const MCInst *MI, int OpNum,
92+
raw_ostream &O) {
93+
printUImmOperand<1>(MI, OpNum, O);
94+
}
95+
96+
void SystemZInstPrinterCommon::printU2ImmOperand(const MCInst *MI, int OpNum,
97+
raw_ostream &O) {
98+
printUImmOperand<2>(MI, OpNum, O);
99+
}
100+
101+
void SystemZInstPrinterCommon::printU3ImmOperand(const MCInst *MI, int OpNum,
102+
raw_ostream &O) {
103+
printUImmOperand<3>(MI, OpNum, O);
104+
}
105+
106+
void SystemZInstPrinterCommon::printU4ImmOperand(const MCInst *MI, int OpNum,
107+
raw_ostream &O) {
108+
printUImmOperand<4>(MI, OpNum, O);
109+
}
110+
111+
void SystemZInstPrinterCommon::printS8ImmOperand(const MCInst *MI, int OpNum,
112+
raw_ostream &O) {
113+
printSImmOperand<8>(MI, OpNum, O);
114+
}
115+
116+
void SystemZInstPrinterCommon::printU8ImmOperand(const MCInst *MI, int OpNum,
117+
raw_ostream &O) {
118+
printUImmOperand<8>(MI, OpNum, O);
119+
}
120+
121+
void SystemZInstPrinterCommon::printU12ImmOperand(const MCInst *MI, int OpNum,
122+
raw_ostream &O) {
123+
printUImmOperand<12>(MI, OpNum, O);
124+
}
125+
126+
void SystemZInstPrinterCommon::printS16ImmOperand(const MCInst *MI, int OpNum,
127+
raw_ostream &O) {
128+
printSImmOperand<16>(MI, OpNum, O);
129+
}
130+
131+
void SystemZInstPrinterCommon::printU16ImmOperand(const MCInst *MI, int OpNum,
132+
raw_ostream &O) {
133+
printUImmOperand<16>(MI, OpNum, O);
134+
}
135+
136+
void SystemZInstPrinterCommon::printS32ImmOperand(const MCInst *MI, int OpNum,
137+
raw_ostream &O) {
138+
printSImmOperand<32>(MI, OpNum, O);
139+
}
140+
141+
void SystemZInstPrinterCommon::printU32ImmOperand(const MCInst *MI, int OpNum,
142+
raw_ostream &O) {
143+
printUImmOperand<32>(MI, OpNum, O);
144+
}
145+
146+
void SystemZInstPrinterCommon::printU48ImmOperand(const MCInst *MI, int OpNum,
147+
raw_ostream &O) {
148+
printUImmOperand<48>(MI, OpNum, O);
149+
}
150+
151+
void SystemZInstPrinterCommon::printPCRelOperand(const MCInst *MI, int OpNum,
152+
raw_ostream &O) {
153+
const MCOperand &MO = MI->getOperand(OpNum);
154+
if (MO.isImm()) {
155+
WithMarkup M = markup(O, Markup::Immediate);
156+
O << "0x";
157+
O.write_hex(MO.getImm());
158+
} else
159+
MO.getExpr()->print(O, &MAI);
160+
}
161+
162+
void SystemZInstPrinterCommon::printPCRelTLSOperand(const MCInst *MI,
163+
uint64_t Address, int OpNum,
164+
raw_ostream &O) {
165+
// Output the PC-relative operand.
166+
printPCRelOperand(MI, OpNum, O);
167+
168+
// Output the TLS marker if present.
169+
if ((unsigned)OpNum + 1 < MI->getNumOperands()) {
170+
const MCOperand &MO = MI->getOperand(OpNum + 1);
171+
const MCSymbolRefExpr &refExp = cast<MCSymbolRefExpr>(*MO.getExpr());
172+
switch (refExp.getKind()) {
173+
case MCSymbolRefExpr::VK_TLSGD:
174+
O << ":tls_gdcall:";
175+
break;
176+
case MCSymbolRefExpr::VK_TLSLDM:
177+
O << ":tls_ldcall:";
178+
break;
179+
default:
180+
llvm_unreachable("Unexpected symbol kind");
181+
}
182+
O << refExp.getSymbol().getName();
183+
}
184+
}
185+
186+
void SystemZInstPrinterCommon::printOperand(const MCInst *MI, int OpNum,
187+
raw_ostream &O) {
188+
printOperand(MI->getOperand(OpNum), &MAI, O);
189+
}
190+
191+
void SystemZInstPrinterCommon::printBDAddrOperand(const MCInst *MI, int OpNum,
192+
raw_ostream &O) {
193+
printAddress(&MAI, MI->getOperand(OpNum).getReg(), MI->getOperand(OpNum + 1),
194+
0, O);
195+
}
196+
197+
void SystemZInstPrinterCommon::printBDXAddrOperand(const MCInst *MI, int OpNum,
198+
raw_ostream &O) {
199+
printAddress(&MAI, MI->getOperand(OpNum).getReg(), MI->getOperand(OpNum + 1),
200+
MI->getOperand(OpNum + 2).getReg(), O);
201+
}
202+
203+
void SystemZInstPrinterCommon::printBDLAddrOperand(const MCInst *MI, int OpNum,
204+
raw_ostream &O) {
205+
unsigned Base = MI->getOperand(OpNum).getReg();
206+
const MCOperand &DispMO = MI->getOperand(OpNum + 1);
207+
uint64_t Length = MI->getOperand(OpNum + 2).getImm();
208+
printOperand(DispMO, &MAI, O);
209+
O << '(' << Length;
210+
if (Base) {
211+
O << ",";
212+
printRegName(O, Base);
213+
}
214+
O << ')';
215+
}
216+
217+
void SystemZInstPrinterCommon::printBDRAddrOperand(const MCInst *MI, int OpNum,
218+
raw_ostream &O) {
219+
unsigned Base = MI->getOperand(OpNum).getReg();
220+
const MCOperand &DispMO = MI->getOperand(OpNum + 1);
221+
unsigned Length = MI->getOperand(OpNum + 2).getReg();
222+
printOperand(DispMO, &MAI, O);
223+
O << "(";
224+
printRegName(O, Length);
225+
if (Base) {
226+
O << ",";
227+
printRegName(O, Base);
228+
}
229+
O << ')';
230+
}
231+
232+
void SystemZInstPrinterCommon::printBDVAddrOperand(const MCInst *MI, int OpNum,
233+
raw_ostream &O) {
234+
printAddress(&MAI, MI->getOperand(OpNum).getReg(), MI->getOperand(OpNum + 1),
235+
MI->getOperand(OpNum + 2).getReg(), O);
236+
}
237+
238+
void SystemZInstPrinterCommon::printCond4Operand(const MCInst *MI, int OpNum,
239+
raw_ostream &O) {
240+
static const char *const CondNames[] = {"o", "h", "nle", "l", "nhe",
241+
"lh", "ne", "e", "nlh", "he",
242+
"nl", "le", "nh", "no"};
243+
uint64_t Imm = MI->getOperand(OpNum).getImm();
244+
assert(Imm > 0 && Imm < 15 && "Invalid condition");
245+
O << CondNames[Imm - 1];
246+
}

‎llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinter.h renamed to ‎llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinterCommon.h

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//==- SystemZInstPrinter.h - Convert SystemZ MCInst to assembly --*- C++ -*-==//
1+
//== SystemZInstPrinterCommon.h - Common SystemZ InstPrinter funcs *- C++ -*==//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -10,27 +10,23 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#ifndef LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZINSTPRINTER_H
14-
#define LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZINSTPRINTER_H
13+
#ifndef LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZINSTPRINTERCOMMON_H
14+
#define LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZINSTPRINTERCOMMON_H
1515

1616
#include "SystemZMCAsmInfo.h"
1717
#include "llvm/MC/MCInstPrinter.h"
18+
#include "llvm/MC/MCRegister.h"
1819
#include <cstdint>
1920

2021
namespace llvm {
2122

2223
class MCOperand;
2324

24-
class SystemZInstPrinter : public MCInstPrinter {
25+
class SystemZInstPrinterCommon : public MCInstPrinter {
2526
public:
26-
SystemZInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII,
27-
const MCRegisterInfo &MRI)
28-
: MCInstPrinter(MAI, MII, MRI) {}
29-
30-
// Automatically generated by tblgen.
31-
std::pair<const char *, uint64_t> getMnemonic(const MCInst *MI) override;
32-
void printInstruction(const MCInst *MI, uint64_t Address, raw_ostream &O);
33-
static const char *getRegisterName(MCRegister Reg);
27+
SystemZInstPrinterCommon(const MCAsmInfo &MAI, const MCInstrInfo &MII,
28+
const MCRegisterInfo &MRI)
29+
: MCInstPrinter(MAI, MII, MRI) {}
3430

3531
// Print an address with the given base, displacement and index.
3632
void printAddress(const MCAsmInfo *MAI, MCRegister Base,
@@ -39,16 +35,13 @@ class SystemZInstPrinter : public MCInstPrinter {
3935
// Print the given operand.
4036
void printOperand(const MCOperand &MO, const MCAsmInfo *MAI, raw_ostream &O);
4137

42-
void printFormattedRegName(const MCAsmInfo *MAI, MCRegister Reg,
43-
raw_ostream &O) const;
38+
virtual void printFormattedRegName(const MCAsmInfo *MAI, MCRegister Reg,
39+
raw_ostream &O) const {}
4440

4541
// Override MCInstPrinter.
4642
void printRegName(raw_ostream &O, MCRegister Reg) const override;
4743

48-
void printInst(const MCInst *MI, uint64_t Address, StringRef Annot,
49-
const MCSubtargetInfo &STI, raw_ostream &O) override;
50-
51-
private:
44+
protected:
5245
template <unsigned N>
5346
void printUImmOperand(const MCInst *MI, int OpNum, raw_ostream &O);
5447
template <unsigned N>
@@ -92,4 +85,4 @@ class SystemZInstPrinter : public MCInstPrinter {
9285

9386
} // end namespace llvm
9487

95-
#endif // LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZINSTPRINTER_H
88+
#endif // LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZINSTPRINTERCOMMON_H

‎llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCTargetDesc.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "SystemZMCTargetDesc.h"
10-
#include "SystemZInstPrinter.h"
10+
#include "SystemZGNUInstPrinter.h"
11+
#include "SystemZHLASMInstPrinter.h"
1112
#include "SystemZMCAsmInfo.h"
1213
#include "SystemZTargetStreamer.h"
1314
#include "TargetInfo/SystemZTargetInfo.h"
@@ -186,7 +187,10 @@ static MCInstPrinter *createSystemZMCInstPrinter(const Triple &T,
186187
const MCAsmInfo &MAI,
187188
const MCInstrInfo &MII,
188189
const MCRegisterInfo &MRI) {
189-
return new SystemZInstPrinter(MAI, MII, MRI);
190+
if (SyntaxVariant == AD_HLASM)
191+
return new SystemZHLASMInstPrinter(MAI, MII, MRI);
192+
193+
return new SystemZGNUInstPrinter(MAI, MII, MRI);
190194
}
191195

192196
void SystemZTargetStreamer::emitConstantPools() {

‎llvm/lib/Target/SystemZ/SystemZ.td

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,20 @@ def HLASMAsmParserVariant : AsmParserVariant {
8181
string Name = "hlasm";
8282
}
8383

84+
//===----------------------------------------------------------------------===//
85+
// Assembly writer
86+
//===----------------------------------------------------------------------===//
87+
88+
// The SystemZ target supports two different syntaxes for emitting machine code.
89+
def GNUAsmWriter : AsmWriter {
90+
string AsmWriterClassName = "GNUInstPrinter";
91+
int Variant = 0;
92+
}
93+
def HLASMAsmWriter : AsmWriter {
94+
string AsmWriterClassName = "HLASMInstPrinter";
95+
int Variant = 1;
96+
}
97+
8498
//===----------------------------------------------------------------------===//
8599
// Top-level target declaration
86100
//===----------------------------------------------------------------------===//
@@ -89,5 +103,6 @@ def SystemZ : Target {
89103
let InstructionSet = SystemZInstrInfo;
90104
let AssemblyParsers = [SystemZAsmParser];
91105
let AssemblyParserVariants = [GNUAsmParserVariant, HLASMAsmParserVariant];
106+
let AssemblyWriters = [GNUAsmWriter, HLASMAsmWriter];
92107
let AllowRegisterRenaming = 1;
93108
}

‎llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
//===----------------------------------------------------------------------===//
1313

1414
#include "SystemZAsmPrinter.h"
15-
#include "MCTargetDesc/SystemZInstPrinter.h"
15+
#include "MCTargetDesc/SystemZGNUInstPrinter.h"
16+
#include "MCTargetDesc/SystemZHLASMInstPrinter.h"
1617
#include "MCTargetDesc/SystemZMCExpr.h"
1718
#include "SystemZConstantPoolValue.h"
1819
#include "SystemZMCInstLower.h"
@@ -882,13 +883,16 @@ void SystemZAsmPrinter::emitMachineConstantPoolValue(
882883

883884
static void printFormattedRegName(const MCAsmInfo *MAI, unsigned RegNo,
884885
raw_ostream &OS) {
885-
const char *RegName = SystemZInstPrinter::getRegisterName(RegNo);
886+
const char *RegName;
886887
if (MAI->getAssemblerDialect() == AD_HLASM) {
888+
RegName = SystemZHLASMInstPrinter::getRegisterName(RegNo);
887889
// Skip register prefix so that only register number is left
888890
assert(isalpha(RegName[0]) && isdigit(RegName[1]));
889891
OS << (RegName + 1);
890-
} else
892+
} else {
893+
RegName = SystemZGNUInstPrinter::getRegisterName(RegNo);
891894
OS << '%' << RegName;
895+
}
892896
}
893897

894898
static void printReg(unsigned Reg, const MCAsmInfo *MAI, raw_ostream &OS) {

0 commit comments

Comments
 (0)
Please sign in to comment.