[llvm] b19b6d9 - Move SystemZ-specific MCSymbolRefExpr::VariantKind to SystemZMCExpr::Specifier
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 22 18:05:45 PDT 2025
Author: Fangrui Song
Date: 2025-03-22T18:05:40-07:00
New Revision: b19b6d9fab0bd9a1650ea1a1d631fc31d0f7fbae
URL: https://github.com/llvm/llvm-project/commit/b19b6d9fab0bd9a1650ea1a1d631fc31d0f7fbae
DIFF: https://github.com/llvm/llvm-project/commit/b19b6d9fab0bd9a1650ea1a1d631fc31d0f7fbae.diff
LOG: Move SystemZ-specific MCSymbolRefExpr::VariantKind to SystemZMCExpr::Specifier
Similar to previous migration done for other targets (PowerPC, X86, ARM,
etc). Switch from the confusing VariantKind to Specifier, which aligns
with Arm and IBM AIX's documentation.
In addition, rename *MCExpr::getKind, which confusingly shadows the base class getKind.
In the future, relocation specifiers should be encoded as part of
SystemZMCExpr instead of MCSymbolRefExpr.
Added:
Modified:
llvm/include/llvm/MC/MCExpr.h
llvm/lib/MC/ELFObjectWriter.cpp
llvm/lib/Target/SystemZ/AsmParser/SystemZAsmParser.cpp
llvm/lib/Target/SystemZ/MCTargetDesc/SystemZELFObjectWriter.cpp
llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinterCommon.cpp
llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmInfo.cpp
llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCExpr.cpp
llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCExpr.h
llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
llvm/lib/Target/SystemZ/SystemZMCInstLower.cpp
llvm/lib/Target/SystemZ/SystemZMCInstLower.h
llvm/lib/Target/SystemZ/SystemZTargetObjectFile.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCExpr.h b/llvm/include/llvm/MC/MCExpr.h
index a9dea1f42ddf6..69a8a49e7b32e 100644
--- a/llvm/include/llvm/MC/MCExpr.h
+++ b/llvm/include/llvm/MC/MCExpr.h
@@ -197,20 +197,14 @@ class MCSymbolRefExpr : public MCExpr {
VK_None,
VK_GOT,
- VK_GOTENT,
VK_GOTOFF,
VK_GOTPCREL,
VK_GOTTPOFF,
- VK_INDNTPOFF,
- VK_NTPOFF,
VK_PLT,
VK_TLSGD,
VK_TLSLD,
VK_TLSLDM,
VK_TPOFF,
- VK_DTPOFF,
- VK_TLSCALL, // symbol(tlscall)
- VK_TLSDESC, // symbol(tlsdesc)
VK_TLVP, // Mach-O thread local variable relocations
VK_TLVPPAGE,
VK_TLVPPAGEOFF,
diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp
index 884633ea0d79a..ef600ded3b077 100644
--- a/llvm/lib/MC/ELFObjectWriter.cpp
+++ b/llvm/lib/MC/ELFObjectWriter.cpp
@@ -1523,15 +1523,10 @@ void ELFObjectWriter::fixSymbolsInTLSFixups(MCAssembler &Asm,
default:
return;
case MCSymbolRefExpr::VK_GOTTPOFF:
- case MCSymbolRefExpr::VK_INDNTPOFF:
- case MCSymbolRefExpr::VK_NTPOFF:
- case MCSymbolRefExpr::VK_TLSCALL:
- case MCSymbolRefExpr::VK_TLSDESC:
case MCSymbolRefExpr::VK_TLSGD:
case MCSymbolRefExpr::VK_TLSLD:
case MCSymbolRefExpr::VK_TLSLDM:
case MCSymbolRefExpr::VK_TPOFF:
- case MCSymbolRefExpr::VK_DTPOFF:
break;
}
Asm.registerSymbol(symRef.getSymbol());
diff --git a/llvm/lib/Target/SystemZ/AsmParser/SystemZAsmParser.cpp b/llvm/lib/Target/SystemZ/AsmParser/SystemZAsmParser.cpp
index 3781cca6e2c14..4fa5f026602ef 100644
--- a/llvm/lib/Target/SystemZ/AsmParser/SystemZAsmParser.cpp
+++ b/llvm/lib/Target/SystemZ/AsmParser/SystemZAsmParser.cpp
@@ -8,6 +8,7 @@
#include "MCTargetDesc/SystemZGNUInstPrinter.h"
#include "MCTargetDesc/SystemZMCAsmInfo.h"
+#include "MCTargetDesc/SystemZMCExpr.h"
#include "MCTargetDesc/SystemZMCTargetDesc.h"
#include "MCTargetDesc/SystemZTargetStreamer.h"
#include "TargetInfo/SystemZTargetInfo.h"
@@ -1668,12 +1669,12 @@ ParseStatus SystemZAsmParser::parsePCRel(OperandVector &Operands,
if (Parser.getTok().isNot(AsmToken::Identifier))
return Error(Parser.getTok().getLoc(), "unexpected token");
- MCSymbolRefExpr::VariantKind Kind = MCSymbolRefExpr::VK_None;
+ SystemZMCExpr::Specifier Kind = SystemZMCExpr::VK_None;
StringRef Name = Parser.getTok().getString();
if (Name == "tls_gdcall")
- Kind = MCSymbolRefExpr::VK_TLSGD;
+ Kind = SystemZMCExpr::VK_TLSGD;
else if (Name == "tls_ldcall")
- Kind = MCSymbolRefExpr::VK_TLSLDM;
+ Kind = SystemZMCExpr::VK_TLSLDM;
else
return Error(Parser.getTok().getLoc(), "unknown TLS tag");
Parser.Lex();
diff --git a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZELFObjectWriter.cpp b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZELFObjectWriter.cpp
index e44b4a5236915..cfec53bd5dec9 100644
--- a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZELFObjectWriter.cpp
+++ b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZELFObjectWriter.cpp
@@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//
+#include "MCTargetDesc/SystemZMCExpr.h"
#include "MCTargetDesc/SystemZMCFixups.h"
#include "MCTargetDesc/SystemZMCTargetDesc.h"
#include "llvm/BinaryFormat/ELF.h"
@@ -33,6 +34,8 @@ class SystemZELFObjectWriter : public MCELFObjectTargetWriter {
// Override MCELFObjectTargetWriter.
unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
const MCFixup &Fixup, bool IsPCRel) const override;
+ bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym,
+ unsigned Type) const override;
};
} // end anonymous namespace
@@ -155,43 +158,57 @@ unsigned SystemZELFObjectWriter::getRelocType(MCContext &Ctx,
unsigned Kind = Fixup.getKind();
if (Kind >= FirstLiteralRelocationKind)
return Kind - FirstLiteralRelocationKind;
- MCSymbolRefExpr::VariantKind Modifier = Target.getAccessVariant();
- switch (Modifier) {
- case MCSymbolRefExpr::VK_None:
+ auto Specifier = SystemZMCExpr::Specifier(Target.getAccessVariant());
+ switch (Specifier) {
+ case SystemZMCExpr::VK_INDNTPOFF:
+ case SystemZMCExpr::VK_NTPOFF:
+ case SystemZMCExpr::VK_TLSGD:
+ case SystemZMCExpr::VK_TLSLD:
+ case SystemZMCExpr::VK_TLSLDM:
+ case SystemZMCExpr::VK_DTPOFF:
+ if (auto *S = Target.getSymA())
+ cast<MCSymbolELF>(S->getSymbol()).setType(ELF::STT_TLS);
+ break;
+ default:
+ break;
+ }
+
+ switch (Specifier) {
+ case SystemZMCExpr::VK_None:
if (IsPCRel)
return getPCRelReloc(Ctx, Loc, Kind);
return getAbsoluteReloc(Ctx, Loc, Kind);
- case MCSymbolRefExpr::VK_NTPOFF:
+ case SystemZMCExpr::VK_NTPOFF:
assert(!IsPCRel && "NTPOFF shouldn't be PC-relative");
return getTLSLEReloc(Ctx, Loc, Kind);
- case MCSymbolRefExpr::VK_INDNTPOFF:
+ case SystemZMCExpr::VK_INDNTPOFF:
if (IsPCRel && Kind == SystemZ::FK_390_PC32DBL)
return ELF::R_390_TLS_IEENT;
Ctx.reportError(Loc, "Only PC-relative INDNTPOFF accesses are supported for now");
return 0;
- case MCSymbolRefExpr::VK_DTPOFF:
+ case SystemZMCExpr::VK_DTPOFF:
assert(!IsPCRel && "DTPOFF shouldn't be PC-relative");
return getTLSLDOReloc(Ctx, Loc, Kind);
- case MCSymbolRefExpr::VK_TLSLDM:
+ case SystemZMCExpr::VK_TLSLDM:
assert(!IsPCRel && "TLSLDM shouldn't be PC-relative");
return getTLSLDMReloc(Ctx, Loc, Kind);
- case MCSymbolRefExpr::VK_TLSGD:
+ case SystemZMCExpr::VK_TLSGD:
assert(!IsPCRel && "TLSGD shouldn't be PC-relative");
return getTLSGDReloc(Ctx, Loc, Kind);
- case MCSymbolRefExpr::VK_GOT:
- case MCSymbolRefExpr::VK_GOTENT:
+ case SystemZMCExpr::VK_GOT:
+ case SystemZMCExpr::VK_GOTENT:
if (IsPCRel && Kind == SystemZ::FK_390_PC32DBL)
return ELF::R_390_GOTENT;
Ctx.reportError(Loc, "Only PC-relative GOT accesses are supported for now");
return 0;
- case MCSymbolRefExpr::VK_PLT:
+ case SystemZMCExpr::VK_PLT:
assert(IsPCRel && "@PLT shouldn't be PC-relative");
return getPLTReloc(Ctx, Loc, Kind);
@@ -200,6 +217,18 @@ unsigned SystemZELFObjectWriter::getRelocType(MCContext &Ctx,
}
}
+bool SystemZELFObjectWriter::needsRelocateWithSymbol(const MCValue &V,
+ const MCSymbol &Sym,
+ unsigned Type) const {
+ switch (getSpecifier(V.getSymA())) {
+ case SystemZMCExpr::VK_GOT:
+ case SystemZMCExpr::VK_PLT:
+ return true;
+ default:
+ return false;
+ }
+}
+
std::unique_ptr<MCObjectTargetWriter>
llvm::createSystemZELFObjectWriter(uint8_t OSABI) {
return std::make_unique<SystemZELFObjectWriter>(OSABI);
diff --git a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinterCommon.cpp b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinterCommon.cpp
index 85366dfa6c4bd..80391a5266532 100644
--- a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinterCommon.cpp
+++ b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinterCommon.cpp
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "SystemZInstPrinterCommon.h"
+#include "MCTargetDesc/SystemZMCExpr.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCInst.h"
#include "llvm/MC/MCRegister.h"
@@ -168,11 +169,11 @@ void SystemZInstPrinterCommon::printPCRelTLSOperand(const MCInst *MI,
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:
+ switch (getSpecifier(&refExp)) {
+ case SystemZMCExpr::VK_TLSGD:
O << ":tls_gdcall:";
break;
- case MCSymbolRefExpr::VK_TLSLDM:
+ case SystemZMCExpr::VK_TLSLDM:
O << ":tls_ldcall:";
break;
default:
diff --git a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmInfo.cpp b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmInfo.cpp
index be909bc419c36..27272cdbbd230 100644
--- a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmInfo.cpp
+++ b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmInfo.cpp
@@ -7,21 +7,22 @@
//===----------------------------------------------------------------------===//
#include "SystemZMCAsmInfo.h"
+#include "MCTargetDesc/SystemZMCExpr.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCExpr.h"
using namespace llvm;
const MCAsmInfo::VariantKindDesc variantKindDescs[] = {
- {MCSymbolRefExpr::VK_DTPOFF, "DTPOFF"},
- {MCSymbolRefExpr::VK_GOT, "GOT"},
- {MCSymbolRefExpr::VK_GOTENT, "GOTENT"},
- {MCSymbolRefExpr::VK_INDNTPOFF, "INDNTPOFF"},
- {MCSymbolRefExpr::VK_NTPOFF, "NTPOFF"},
- {MCSymbolRefExpr::VK_PLT, "PLT"},
- {MCSymbolRefExpr::VK_TLSGD, "TLSGD"},
- {MCSymbolRefExpr::VK_TLSLD, "TLSLD"},
- {MCSymbolRefExpr::VK_TLSLDM, "TLSLDM"},
+ {SystemZMCExpr::VK_DTPOFF, "DTPOFF"},
+ {SystemZMCExpr::VK_GOT, "GOT"},
+ {SystemZMCExpr::VK_GOTENT, "GOTENT"},
+ {SystemZMCExpr::VK_INDNTPOFF, "INDNTPOFF"},
+ {SystemZMCExpr::VK_NTPOFF, "NTPOFF"},
+ {SystemZMCExpr::VK_PLT, "PLT"},
+ {SystemZMCExpr::VK_TLSGD, "TLSGD"},
+ {SystemZMCExpr::VK_TLSLD, "TLSLD"},
+ {SystemZMCExpr::VK_TLSLDM, "TLSLDM"},
};
SystemZMCAsmInfoELF::SystemZMCAsmInfoELF(const Triple &TT) {
diff --git a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCExpr.cpp b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCExpr.cpp
index b83f085aabc1e..e7bc2652428e0 100644
--- a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCExpr.cpp
+++ b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCExpr.cpp
@@ -12,14 +12,14 @@ using namespace llvm;
#define DEBUG_TYPE "systemzmcexpr"
-const SystemZMCExpr *SystemZMCExpr::create(VariantKind Kind, const MCExpr *Expr,
- MCContext &Ctx) {
+const SystemZMCExpr *SystemZMCExpr::create(SystemZMCExpr::Specifier Kind,
+ const MCExpr *Expr, MCContext &Ctx) {
return new (Ctx) SystemZMCExpr(Kind, Expr);
}
StringRef SystemZMCExpr::getVariantKindName() const {
- switch (static_cast<uint32_t>(getKind())) {
- case VK_SystemZ_None:
+ switch (getSpecifier()) {
+ case VK_None:
return "A";
case VK_SystemZ_RCon:
return "R";
@@ -41,8 +41,8 @@ bool SystemZMCExpr::evaluateAsRelocatableImpl(MCValue &Res,
if (!getSubExpr()->evaluateAsRelocatable(Res, Asm))
return false;
- Res =
- MCValue::get(Res.getSymA(), Res.getSymB(), Res.getConstant(), getKind());
+ Res = MCValue::get(Res.getSymA(), Res.getSymB(), Res.getConstant(),
+ getSpecifier());
return true;
}
diff --git a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCExpr.h b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCExpr.h
index d6785222b8e56..39b8ea14de0d8 100644
--- a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCExpr.h
+++ b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCExpr.h
@@ -17,29 +17,37 @@ namespace llvm {
class SystemZMCExpr : public MCTargetExpr {
public:
-// HLASM docs for address constants:
-// https://www.ibm.com/docs/en/hla-and-tf/1.6?topic=value-address-constants
- enum VariantKind {
- VK_SystemZ_None,
- VK_SystemZ_RCon, // Address of ADA of symbol.
- VK_SystemZ_VCon, // Address of external function symbol.
+ enum Specifier : uint8_t {
+ VK_None,
+
+ VK_DTPOFF = MCSymbolRefExpr::FirstTargetSpecifier,
+ VK_GOT,
+ VK_GOTENT,
+ VK_INDNTPOFF,
+ VK_NTPOFF,
+ VK_PLT,
+ VK_TLSGD,
+ VK_TLSLD,
+ VK_TLSLDM,
+
+ // HLASM docs for address constants:
+ // https://www.ibm.com/docs/en/hla-and-tf/1.6?topic=value-address-constants
+ VK_SystemZ_RCon, // Address of ADA of symbol.
+ VK_SystemZ_VCon, // Address of external function symbol.
};
private:
- const VariantKind Kind;
+ const Specifier specifier;
const MCExpr *Expr;
- explicit SystemZMCExpr(VariantKind Kind, const MCExpr *Expr)
- : Kind(Kind), Expr(Expr) {}
+ explicit SystemZMCExpr(Specifier S, const MCExpr *Expr)
+ : specifier(S), Expr(Expr) {}
public:
- static const SystemZMCExpr *create(VariantKind Kind, const MCExpr *Expr,
+ static const SystemZMCExpr *create(Specifier Kind, const MCExpr *Expr,
MCContext &Ctx);
- /// getOpcode - Get the kind of this expression.
- VariantKind getKind() const { return Kind; }
-
- /// getSubExpr - Get the child of this expression.
+ Specifier getSpecifier() const { return specifier; }
const MCExpr *getSubExpr() const { return Expr; }
StringRef getVariantKindName() const;
@@ -58,6 +66,11 @@ class SystemZMCExpr : public MCTargetExpr {
return E->getKind() == MCExpr::Target;
}
};
+
+static inline SystemZMCExpr::Specifier
+getSpecifier(const MCSymbolRefExpr *SRE) {
+ return SystemZMCExpr::Specifier(SRE->getKind());
+}
} // end namespace llvm
#endif
diff --git a/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp b/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
index 448753fa43dc1..b3efa579dfe0c 100644
--- a/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
@@ -79,8 +79,7 @@ static MCInst lowerRIEfLow(const MachineInstr *MI, unsigned Opcode) {
static const MCSymbolRefExpr *getTLSGetOffset(MCContext &Context) {
StringRef Name = "__tls_get_offset";
return MCSymbolRefExpr::create(Context.getOrCreateSymbol(Name),
- MCSymbolRefExpr::VK_PLT,
- Context);
+ SystemZMCExpr::VK_PLT, Context);
}
static const MCSymbolRefExpr *getGlobalOffsetTable(MCContext &Context) {
@@ -301,11 +300,11 @@ void SystemZAsmPrinter::emitInstruction(const MachineInstr *MI) {
break;
case SystemZ::CallBRASL_XPLINK64:
- EmitToStreamer(*OutStreamer,
- MCInstBuilder(SystemZ::BRASL)
- .addReg(SystemZ::R7D)
- .addExpr(Lower.getExpr(MI->getOperand(0),
- MCSymbolRefExpr::VK_PLT)));
+ EmitToStreamer(
+ *OutStreamer,
+ MCInstBuilder(SystemZ::BRASL)
+ .addReg(SystemZ::R7D)
+ .addExpr(Lower.getExpr(MI->getOperand(0), SystemZMCExpr::VK_PLT)));
emitCallInformation(CallType::BRASL7);
return;
@@ -362,9 +361,10 @@ void SystemZAsmPrinter::emitInstruction(const MachineInstr *MI) {
return;
}
case SystemZ::CallBRASL:
- LoweredMI = MCInstBuilder(SystemZ::BRASL)
- .addReg(SystemZ::R14D)
- .addExpr(Lower.getExpr(MI->getOperand(0), MCSymbolRefExpr::VK_PLT));
+ LoweredMI =
+ MCInstBuilder(SystemZ::BRASL)
+ .addReg(SystemZ::R14D)
+ .addExpr(Lower.getExpr(MI->getOperand(0), SystemZMCExpr::VK_PLT));
break;
case SystemZ::CallBASR:
@@ -374,15 +374,17 @@ void SystemZAsmPrinter::emitInstruction(const MachineInstr *MI) {
break;
case SystemZ::CallJG:
- LoweredMI = MCInstBuilder(SystemZ::JG)
- .addExpr(Lower.getExpr(MI->getOperand(0), MCSymbolRefExpr::VK_PLT));
+ LoweredMI =
+ MCInstBuilder(SystemZ::JG)
+ .addExpr(Lower.getExpr(MI->getOperand(0), SystemZMCExpr::VK_PLT));
break;
case SystemZ::CallBRCL:
- LoweredMI = MCInstBuilder(SystemZ::BRCL)
- .addImm(MI->getOperand(0).getImm())
- .addImm(MI->getOperand(1).getImm())
- .addExpr(Lower.getExpr(MI->getOperand(2), MCSymbolRefExpr::VK_PLT));
+ LoweredMI =
+ MCInstBuilder(SystemZ::BRCL)
+ .addImm(MI->getOperand(0).getImm())
+ .addImm(MI->getOperand(1).getImm())
+ .addExpr(Lower.getExpr(MI->getOperand(2), SystemZMCExpr::VK_PLT));
break;
case SystemZ::CallBR:
@@ -470,17 +472,19 @@ void SystemZAsmPrinter::emitInstruction(const MachineInstr *MI) {
break;
case SystemZ::TLS_GDCALL:
- LoweredMI = MCInstBuilder(SystemZ::BRASL)
- .addReg(SystemZ::R14D)
- .addExpr(getTLSGetOffset(MF->getContext()))
- .addExpr(Lower.getExpr(MI->getOperand(0), MCSymbolRefExpr::VK_TLSGD));
+ LoweredMI =
+ MCInstBuilder(SystemZ::BRASL)
+ .addReg(SystemZ::R14D)
+ .addExpr(getTLSGetOffset(MF->getContext()))
+ .addExpr(Lower.getExpr(MI->getOperand(0), SystemZMCExpr::VK_TLSGD));
break;
case SystemZ::TLS_LDCALL:
LoweredMI = MCInstBuilder(SystemZ::BRASL)
- .addReg(SystemZ::R14D)
- .addExpr(getTLSGetOffset(MF->getContext()))
- .addExpr(Lower.getExpr(MI->getOperand(0), MCSymbolRefExpr::VK_TLSLDM));
+ .addReg(SystemZ::R14D)
+ .addExpr(getTLSGetOffset(MF->getContext()))
+ .addExpr(Lower.getExpr(MI->getOperand(0),
+ SystemZMCExpr::VK_TLSLDM));
break;
case SystemZ::GOT:
@@ -766,7 +770,7 @@ void SystemZAsmPrinter::LowerFENTRY_CALL(const MachineInstr &MI,
MCSymbol *fentry = Ctx.getOrCreateSymbol("__fentry__");
const MCSymbolRefExpr *Op =
- MCSymbolRefExpr::create(fentry, MCSymbolRefExpr::VK_PLT, Ctx);
+ MCSymbolRefExpr::create(fentry, SystemZMCExpr::VK_PLT, Ctx);
OutStreamer->emitInstruction(
MCInstBuilder(SystemZ::BRASL).addReg(SystemZ::R0D).addExpr(Op),
getSubtargetInfo());
@@ -848,7 +852,7 @@ void SystemZAsmPrinter::LowerPATCHPOINT(const MachineInstr &MI,
EncodedBytes += 2;
}
} else if (CalleeMO.isGlobal()) {
- const MCExpr *Expr = Lower.getExpr(CalleeMO, MCSymbolRefExpr::VK_PLT);
+ const MCExpr *Expr = Lower.getExpr(CalleeMO, SystemZMCExpr::VK_PLT);
EmitToStreamer(*OutStreamer, MCInstBuilder(SystemZ::BRASL)
.addReg(SystemZ::R14D)
.addExpr(Expr));
@@ -895,7 +899,7 @@ void SystemZAsmPrinter::LowerPATCHABLE_FUNCTION_ENTER(
MCInstBuilder(SystemZ::BRASL)
.addReg(SystemZ::R14D)
.addExpr(MCSymbolRefExpr::create(
- FuncEntry, MCSymbolRefExpr::VK_PLT, OutContext)));
+ FuncEntry, SystemZMCExpr::VK_PLT, OutContext)));
OutStreamer->emitLabel(EndOfSled);
recordSled(BeginOfSled, MI, SledKind::FUNCTION_ENTER, 2);
}
@@ -938,7 +942,7 @@ void SystemZAsmPrinter::LowerPATCHABLE_RET(const MachineInstr &MI,
EmitToStreamer(*OutStreamer,
MCInstBuilder(SystemZ::J)
.addExpr(MCSymbolRefExpr::create(
- FuncExit, MCSymbolRefExpr::VK_PLT, OutContext)));
+ FuncExit, SystemZMCExpr::VK_PLT, OutContext)));
if (FallthroughLabel)
OutStreamer->emitLabel(FallthroughLabel);
recordSled(BeginOfSled, MI, SledKind::FUNCTION_EXIT, 2);
@@ -956,14 +960,17 @@ void SystemZAsmPrinter::emitAttributes(Module &M) {
}
// Convert a SystemZ-specific constant pool modifier into the associated
-// MCSymbolRefExpr variant kind.
-static MCSymbolRefExpr::VariantKind
-getModifierVariantKind(SystemZCP::SystemZCPModifier Modifier) {
+// specifier.
+static uint8_t getSpecifierFromModifier(SystemZCP::SystemZCPModifier Modifier) {
switch (Modifier) {
- case SystemZCP::TLSGD: return MCSymbolRefExpr::VK_TLSGD;
- case SystemZCP::TLSLDM: return MCSymbolRefExpr::VK_TLSLDM;
- case SystemZCP::DTPOFF: return MCSymbolRefExpr::VK_DTPOFF;
- case SystemZCP::NTPOFF: return MCSymbolRefExpr::VK_NTPOFF;
+ case SystemZCP::TLSGD:
+ return SystemZMCExpr::VK_TLSGD;
+ case SystemZCP::TLSLDM:
+ return SystemZMCExpr::VK_TLSLDM;
+ case SystemZCP::DTPOFF:
+ return SystemZMCExpr::VK_DTPOFF;
+ case SystemZCP::NTPOFF:
+ return SystemZMCExpr::VK_NTPOFF;
}
llvm_unreachable("Invalid SystemCPModifier!");
}
@@ -972,10 +979,9 @@ void SystemZAsmPrinter::emitMachineConstantPoolValue(
MachineConstantPoolValue *MCPV) {
auto *ZCPV = static_cast<SystemZConstantPoolValue*>(MCPV);
- const MCExpr *Expr =
- MCSymbolRefExpr::create(getSymbol(ZCPV->getGlobalValue()),
- getModifierVariantKind(ZCPV->getModifier()),
- OutContext);
+ const MCExpr *Expr = MCSymbolRefExpr::create(
+ getSymbol(ZCPV->getGlobalValue()),
+ getSpecifierFromModifier(ZCPV->getModifier()), OutContext);
uint64_t Size = getDataLayout().getTypeAllocSize(ZCPV->getType());
OutStreamer->emitValue(Expr, Size);
@@ -1125,7 +1131,7 @@ void SystemZAsmPrinter::emitADASection() {
case SystemZII::MO_ADA_DATA_SYMBOL_ADDR:
EMIT_COMMENT("pointer to data symbol");
OutStreamer->emitValue(
- SystemZMCExpr::create(SystemZMCExpr::VK_SystemZ_None,
+ SystemZMCExpr::create(SystemZMCExpr::VK_None,
MCSymbolRefExpr::create(Sym, OutContext),
OutContext),
PointerSize);
diff --git a/llvm/lib/Target/SystemZ/SystemZMCInstLower.cpp b/llvm/lib/Target/SystemZ/SystemZMCInstLower.cpp
index d2932de5a6ea1..1aa71618082fb 100644
--- a/llvm/lib/Target/SystemZ/SystemZMCInstLower.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZMCInstLower.cpp
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "SystemZMCInstLower.h"
+#include "MCTargetDesc/SystemZMCExpr.h"
#include "SystemZAsmPrinter.h"
#include "llvm/IR/Mangler.h"
#include "llvm/MC/MCExpr.h"
@@ -16,14 +17,14 @@
using namespace llvm;
// Return the VK_* enumeration for MachineOperand target flags Flags.
-static MCSymbolRefExpr::VariantKind getVariantKind(unsigned Flags) {
+static SystemZMCExpr::Specifier getSpecifierForTFlags(unsigned Flags) {
switch (Flags & SystemZII::MO_SYMBOL_MODIFIER) {
case 0:
- return MCSymbolRefExpr::VK_None;
+ return SystemZMCExpr::VK_None;
case SystemZII::MO_GOT:
- return MCSymbolRefExpr::VK_GOT;
+ return SystemZMCExpr::VK_GOT;
case SystemZII::MO_INDNTPOFF:
- return MCSymbolRefExpr::VK_INDNTPOFF;
+ return SystemZMCExpr::VK_INDNTPOFF;
}
llvm_unreachable("Unrecognised MO_ACCESS_MODEL");
}
@@ -32,9 +33,8 @@ SystemZMCInstLower::SystemZMCInstLower(MCContext &ctx,
SystemZAsmPrinter &asmprinter)
: Ctx(ctx), AsmPrinter(asmprinter) {}
-const MCExpr *
-SystemZMCInstLower::getExpr(const MachineOperand &MO,
- MCSymbolRefExpr::VariantKind Kind) const {
+const MCExpr *SystemZMCInstLower::getExpr(const MachineOperand &MO,
+ SystemZMCExpr::Specifier Spec) const {
const MCSymbol *Symbol;
bool HasOffset = true;
switch (MO.getType()) {
@@ -67,7 +67,7 @@ SystemZMCInstLower::getExpr(const MachineOperand &MO,
default:
llvm_unreachable("unknown operand type");
}
- const MCExpr *Expr = MCSymbolRefExpr::create(Symbol, Kind, Ctx);
+ const MCExpr *Expr = MCSymbolRefExpr::create(Symbol, Spec, Ctx);
if (HasOffset)
if (int64_t Offset = MO.getOffset()) {
const MCExpr *OffsetExpr = MCConstantExpr::create(Offset, Ctx);
@@ -85,7 +85,7 @@ MCOperand SystemZMCInstLower::lowerOperand(const MachineOperand &MO) const {
return MCOperand::createImm(MO.getImm());
default: {
- MCSymbolRefExpr::VariantKind Kind = getVariantKind(MO.getTargetFlags());
+ SystemZMCExpr::Specifier Kind = getSpecifierForTFlags(MO.getTargetFlags());
return MCOperand::createExpr(getExpr(MO, Kind));
}
}
diff --git a/llvm/lib/Target/SystemZ/SystemZMCInstLower.h b/llvm/lib/Target/SystemZ/SystemZMCInstLower.h
index eb09033d1850c..90526882c8535 100644
--- a/llvm/lib/Target/SystemZ/SystemZMCInstLower.h
+++ b/llvm/lib/Target/SystemZ/SystemZMCInstLower.h
@@ -9,6 +9,7 @@
#ifndef LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZMCINSTLOWER_H
#define LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZMCINSTLOWER_H
+#include "MCTargetDesc/SystemZMCExpr.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/DataTypes.h"
@@ -35,7 +36,7 @@ class LLVM_LIBRARY_VISIBILITY SystemZMCInstLower {
// Return an MCExpr for symbolic operand MO with variant kind Kind.
const MCExpr *getExpr(const MachineOperand &MO,
- MCSymbolRefExpr::VariantKind Kind) const;
+ SystemZMCExpr::Specifier) const;
};
} // end namespace llvm
diff --git a/llvm/lib/Target/SystemZ/SystemZTargetObjectFile.cpp b/llvm/lib/Target/SystemZ/SystemZTargetObjectFile.cpp
index beecedd8ad426..7d22c26ff9a86 100644
--- a/llvm/lib/Target/SystemZ/SystemZTargetObjectFile.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZTargetObjectFile.cpp
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "SystemZTargetObjectFile.h"
+#include "MCTargetDesc/SystemZMCExpr.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/Target/TargetMachine.h"
@@ -14,5 +15,5 @@ using namespace llvm;
const MCExpr *SystemZELFTargetObjectFile::getDebugThreadLocalSymbol(
const MCSymbol *Sym) const {
- return MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_DTPOFF, getContext());
+ return MCSymbolRefExpr::create(Sym, SystemZMCExpr::VK_DTPOFF, getContext());
}
More information about the llvm-commits
mailing list