Skip to content

Commit b591f6d

Browse files
committed
SystemZ: Migrate to newer relocation specifier representation
z/OS creates SystemZMCExpr objects (https://reviews.llvm.org/D153788) while ELF doesn't. Define the SystemZMCAsmInfoGOFF hooks instead of the legacy MCSpecifierExpr:: hooks.
1 parent d64ee2c commit b591f6d

File tree

9 files changed

+48
-108
lines changed

9 files changed

+48
-108
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include "MCTargetDesc/SystemZGNUInstPrinter.h"
1010
#include "MCTargetDesc/SystemZMCAsmInfo.h"
11-
#include "MCTargetDesc/SystemZMCExpr.h"
1211
#include "MCTargetDesc/SystemZMCTargetDesc.h"
1312
#include "MCTargetDesc/SystemZTargetStreamer.h"
1413
#include "TargetInfo/SystemZTargetInfo.h"
@@ -1707,7 +1706,7 @@ ParseStatus SystemZAsmParser::parsePCRel(OperandVector &Operands,
17071706
if (Parser.getTok().isNot(AsmToken::Identifier))
17081707
return Error(Parser.getTok().getLoc(), "unexpected token");
17091708

1710-
SystemZMCExpr::Specifier Kind = SystemZ::S_None;
1709+
auto Kind = SystemZ::S_None;
17111710
StringRef Name = Parser.getTok().getString();
17121711
if (Name == "tls_gdcall")
17131712
Kind = SystemZ::S_TLSGD;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ add_llvm_component_library(LLVMSystemZDesc
88
SystemZMCAsmBackend.cpp
99
SystemZMCAsmInfo.cpp
1010
SystemZMCCodeEmitter.cpp
11-
SystemZMCExpr.cpp
1211
SystemZMCTargetDesc.cpp
1312
SystemZTargetStreamer.cpp
1413

llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmInfo.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "SystemZMCAsmInfo.h"
10-
#include "MCTargetDesc/SystemZMCExpr.h"
1110
#include "llvm/MC/MCContext.h"
1211
#include "llvm/MC/MCExpr.h"
12+
#include "llvm/MC/MCValue.h"
1313

1414
using namespace llvm;
1515

@@ -58,3 +58,31 @@ SystemZMCAsmInfoGOFF::SystemZMCAsmInfoGOFF(const Triple &TT) {
5858
bool SystemZMCAsmInfoGOFF::isAcceptableChar(char C) const {
5959
return MCAsmInfo::isAcceptableChar(C) || C == '#';
6060
}
61+
62+
void SystemZMCAsmInfoGOFF::printSpecifierExpr(
63+
raw_ostream &OS, const MCSpecifierExpr &Expr) const {
64+
switch (Expr.getSpecifier()) {
65+
case SystemZ::S_None:
66+
OS << "A";
67+
break;
68+
case SystemZ::S_RCon:
69+
OS << "R";
70+
break;
71+
case SystemZ::S_VCon:
72+
OS << "V";
73+
break;
74+
default:
75+
llvm_unreachable("Invalid kind");
76+
}
77+
OS << '(';
78+
printExpr(OS, *Expr.getSubExpr());
79+
OS << ')';
80+
}
81+
82+
bool SystemZMCAsmInfoGOFF::evaluateAsRelocatableImpl(
83+
const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const {
84+
if (!Expr.getSubExpr()->evaluateAsRelocatable(Res, Asm))
85+
return false;
86+
Res.setSpecifier(Expr.getSpecifier());
87+
return true;
88+
}

llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmInfo.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ class SystemZMCAsmInfoGOFF : public MCAsmInfoGOFF {
2626
public:
2727
explicit SystemZMCAsmInfoGOFF(const Triple &TT);
2828
bool isAcceptableChar(char C) const override;
29+
void printSpecifierExpr(raw_ostream &OS,
30+
const MCSpecifierExpr &Expr) const override;
31+
bool evaluateAsRelocatableImpl(const MCSpecifierExpr &Expr, MCValue &Res,
32+
const MCAssembler *Asm) const override;
2933
};
3034

3135
namespace SystemZ {

llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCExpr.cpp

Lines changed: 0 additions & 47 deletions
This file was deleted.

llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCExpr.h

Lines changed: 0 additions & 38 deletions
This file was deleted.

llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,23 +1139,20 @@ void SystemZAsmPrinter::emitADASection() {
11391139
// imported functions, that are placed in the ADA to be 8 byte aligned.
11401140
EMIT_COMMENT("function descriptor of");
11411141
OutStreamer->emitValue(
1142-
SystemZMCExpr::create(SystemZ::S_RCon,
1143-
MCSymbolRefExpr::create(Sym, OutContext),
1144-
OutContext),
1142+
MCSpecifierExpr::create(MCSymbolRefExpr::create(Sym, OutContext),
1143+
SystemZ::S_RCon, OutContext),
11451144
PointerSize);
11461145
OutStreamer->emitValue(
1147-
SystemZMCExpr::create(SystemZ::S_VCon,
1148-
MCSymbolRefExpr::create(Sym, OutContext),
1149-
OutContext),
1146+
MCSpecifierExpr::create(MCSymbolRefExpr::create(Sym, OutContext),
1147+
SystemZ::S_VCon, OutContext),
11501148
PointerSize);
11511149
EmittedBytes += PointerSize * 2;
11521150
break;
11531151
case SystemZII::MO_ADA_DATA_SYMBOL_ADDR:
11541152
EMIT_COMMENT("pointer to data symbol");
11551153
OutStreamer->emitValue(
1156-
SystemZMCExpr::create(SystemZ::S_None,
1157-
MCSymbolRefExpr::create(Sym, OutContext),
1158-
OutContext),
1154+
MCSpecifierExpr::create(MCSymbolRefExpr::create(Sym, OutContext),
1155+
SystemZ::S_None, OutContext),
11591156
PointerSize);
11601157
EmittedBytes += PointerSize;
11611158
break;
@@ -1168,9 +1165,8 @@ void SystemZAsmPrinter::emitADASection() {
11681165

11691166
EMIT_COMMENT("pointer to function descriptor");
11701167
OutStreamer->emitValue(
1171-
SystemZMCExpr::create(SystemZ::S_VCon,
1172-
MCSymbolRefExpr::create(Alias, OutContext),
1173-
OutContext),
1168+
MCSpecifierExpr::create(MCSymbolRefExpr::create(Alias, OutContext),
1169+
SystemZ::S_VCon, OutContext),
11741170
PointerSize);
11751171
EmittedBytes += PointerSize;
11761172
break;

llvm/lib/Target/SystemZ/SystemZMCInstLower.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
using namespace llvm;
1818

19-
// Return the VK_* enumeration for MachineOperand target flags Flags.
20-
static SystemZMCExpr::Specifier getSpecifierForTFlags(unsigned Flags) {
19+
// Return the S_* enumeration for MachineOperand target flags Flags.
20+
static SystemZ::Specifier getSpecifierForTFlags(unsigned Flags) {
2121
switch (Flags & SystemZII::MO_SYMBOL_MODIFIER) {
2222
case 0:
2323
return SystemZ::S_None;
@@ -34,7 +34,7 @@ SystemZMCInstLower::SystemZMCInstLower(MCContext &ctx,
3434
: Ctx(ctx), AsmPrinter(asmprinter) {}
3535

3636
const MCExpr *SystemZMCInstLower::getExpr(const MachineOperand &MO,
37-
SystemZMCExpr::Specifier Spec) const {
37+
SystemZ::Specifier Spec) const {
3838
const MCSymbol *Symbol;
3939
bool HasOffset = true;
4040
switch (MO.getType()) {
@@ -85,7 +85,7 @@ MCOperand SystemZMCInstLower::lowerOperand(const MachineOperand &MO) const {
8585
return MCOperand::createImm(MO.getImm());
8686

8787
default: {
88-
SystemZMCExpr::Specifier Kind = getSpecifierForTFlags(MO.getTargetFlags());
88+
auto Kind = getSpecifierForTFlags(MO.getTargetFlags());
8989
return MCOperand::createExpr(getExpr(MO, Kind));
9090
}
9191
}

llvm/lib/Target/SystemZ/SystemZMCInstLower.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#ifndef LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZMCINSTLOWER_H
1010
#define LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZMCINSTLOWER_H
1111

12-
#include "MCTargetDesc/SystemZMCExpr.h"
12+
#include "MCTargetDesc/SystemZMCAsmInfo.h"
1313
#include "llvm/MC/MCExpr.h"
1414
#include "llvm/Support/Compiler.h"
1515
#include "llvm/Support/DataTypes.h"
@@ -35,8 +35,7 @@ class LLVM_LIBRARY_VISIBILITY SystemZMCInstLower {
3535
MCOperand lowerOperand(const MachineOperand& MO) const;
3636

3737
// Return an MCExpr for symbolic operand MO with variant kind Kind.
38-
const MCExpr *getExpr(const MachineOperand &MO,
39-
SystemZMCExpr::Specifier) const;
38+
const MCExpr *getExpr(const MachineOperand &MO, SystemZ::Specifier) const;
4039
};
4140
} // end namespace llvm
4241

0 commit comments

Comments
 (0)