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.
This commit is contained in:
@@ -8,7 +8,6 @@
|
||||
|
||||
#include "MCTargetDesc/SystemZGNUInstPrinter.h"
|
||||
#include "MCTargetDesc/SystemZMCAsmInfo.h"
|
||||
#include "MCTargetDesc/SystemZMCExpr.h"
|
||||
#include "MCTargetDesc/SystemZMCTargetDesc.h"
|
||||
#include "MCTargetDesc/SystemZTargetStreamer.h"
|
||||
#include "TargetInfo/SystemZTargetInfo.h"
|
||||
@@ -1707,7 +1706,7 @@ ParseStatus SystemZAsmParser::parsePCRel(OperandVector &Operands,
|
||||
if (Parser.getTok().isNot(AsmToken::Identifier))
|
||||
return Error(Parser.getTok().getLoc(), "unexpected token");
|
||||
|
||||
SystemZMCExpr::Specifier Kind = SystemZ::S_None;
|
||||
auto Kind = SystemZ::S_None;
|
||||
StringRef Name = Parser.getTok().getString();
|
||||
if (Name == "tls_gdcall")
|
||||
Kind = SystemZ::S_TLSGD;
|
||||
|
||||
@@ -8,7 +8,6 @@ add_llvm_component_library(LLVMSystemZDesc
|
||||
SystemZMCAsmBackend.cpp
|
||||
SystemZMCAsmInfo.cpp
|
||||
SystemZMCCodeEmitter.cpp
|
||||
SystemZMCExpr.cpp
|
||||
SystemZMCTargetDesc.cpp
|
||||
SystemZTargetStreamer.cpp
|
||||
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "SystemZMCAsmInfo.h"
|
||||
#include "MCTargetDesc/SystemZMCExpr.h"
|
||||
#include "llvm/MC/MCContext.h"
|
||||
#include "llvm/MC/MCExpr.h"
|
||||
#include "llvm/MC/MCValue.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
@@ -58,3 +58,31 @@ SystemZMCAsmInfoGOFF::SystemZMCAsmInfoGOFF(const Triple &TT) {
|
||||
bool SystemZMCAsmInfoGOFF::isAcceptableChar(char C) const {
|
||||
return MCAsmInfo::isAcceptableChar(C) || C == '#';
|
||||
}
|
||||
|
||||
void SystemZMCAsmInfoGOFF::printSpecifierExpr(
|
||||
raw_ostream &OS, const MCSpecifierExpr &Expr) const {
|
||||
switch (Expr.getSpecifier()) {
|
||||
case SystemZ::S_None:
|
||||
OS << "A";
|
||||
break;
|
||||
case SystemZ::S_RCon:
|
||||
OS << "R";
|
||||
break;
|
||||
case SystemZ::S_VCon:
|
||||
OS << "V";
|
||||
break;
|
||||
default:
|
||||
llvm_unreachable("Invalid kind");
|
||||
}
|
||||
OS << '(';
|
||||
printExpr(OS, *Expr.getSubExpr());
|
||||
OS << ')';
|
||||
}
|
||||
|
||||
bool SystemZMCAsmInfoGOFF::evaluateAsRelocatableImpl(
|
||||
const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const {
|
||||
if (!Expr.getSubExpr()->evaluateAsRelocatable(Res, Asm))
|
||||
return false;
|
||||
Res.setSpecifier(Expr.getSpecifier());
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,10 @@ class SystemZMCAsmInfoGOFF : public MCAsmInfoGOFF {
|
||||
public:
|
||||
explicit SystemZMCAsmInfoGOFF(const Triple &TT);
|
||||
bool isAcceptableChar(char C) const override;
|
||||
void printSpecifierExpr(raw_ostream &OS,
|
||||
const MCSpecifierExpr &Expr) const override;
|
||||
bool evaluateAsRelocatableImpl(const MCSpecifierExpr &Expr, MCValue &Res,
|
||||
const MCAssembler *Asm) const override;
|
||||
};
|
||||
|
||||
namespace SystemZ {
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
//===-- SystemZMCExpr.cpp - SystemZ specific MC expression classes --------===//
|
||||
//
|
||||
// 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 "SystemZMCExpr.h"
|
||||
#include "SystemZMCAsmInfo.h"
|
||||
#include "llvm/MC/MCAsmInfo.h"
|
||||
#include "llvm/MC/MCContext.h"
|
||||
using namespace llvm;
|
||||
|
||||
#define DEBUG_TYPE "systemzmcexpr"
|
||||
|
||||
const SystemZMCExpr *SystemZMCExpr::create(MCSpecifierExpr::Spec S,
|
||||
const MCExpr *Expr, MCContext &Ctx) {
|
||||
return new (Ctx) SystemZMCExpr(Expr, S);
|
||||
}
|
||||
|
||||
StringRef SystemZMCExpr::getVariantKindName() const {
|
||||
switch (getSpecifier()) {
|
||||
case SystemZ::S_None:
|
||||
return "A";
|
||||
case SystemZ::S_RCon:
|
||||
return "R";
|
||||
case SystemZ::S_VCon:
|
||||
return "V";
|
||||
default:
|
||||
llvm_unreachable("Invalid kind");
|
||||
}
|
||||
}
|
||||
|
||||
void SystemZMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
|
||||
OS << getVariantKindName() << '(';
|
||||
MAI->printExpr(OS, *Expr);
|
||||
OS << ')';
|
||||
}
|
||||
|
||||
bool SystemZMCExpr::evaluateAsRelocatableImpl(MCValue &Res,
|
||||
const MCAssembler *Asm) const {
|
||||
if (!getSubExpr()->evaluateAsRelocatable(Res, Asm))
|
||||
return false;
|
||||
Res.setSpecifier(specifier);
|
||||
return true;
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
//===-- SystemZMCExpr.h - SystemZ specific MC expression classes -*- 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZMCEXPR_H
|
||||
#define LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZMCEXPR_H
|
||||
|
||||
#include "llvm/MC/MCExpr.h"
|
||||
#include "llvm/MC/MCStreamer.h"
|
||||
#include "llvm/MC/MCValue.h"
|
||||
|
||||
namespace llvm {
|
||||
|
||||
class SystemZMCExpr : public MCSpecifierExpr {
|
||||
public:
|
||||
using Specifier = Spec;
|
||||
|
||||
private:
|
||||
explicit SystemZMCExpr(const MCExpr *Expr, Spec S)
|
||||
: MCSpecifierExpr(Expr, S) {}
|
||||
|
||||
public:
|
||||
static const SystemZMCExpr *create(Spec Kind, const MCExpr *Expr,
|
||||
MCContext &Ctx);
|
||||
|
||||
StringRef getVariantKindName() const;
|
||||
|
||||
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
|
||||
bool evaluateAsRelocatableImpl(MCValue &Res,
|
||||
const MCAssembler *Asm) const override;
|
||||
};
|
||||
} // end namespace llvm
|
||||
|
||||
#endif
|
||||
@@ -1139,23 +1139,20 @@ void SystemZAsmPrinter::emitADASection() {
|
||||
// imported functions, that are placed in the ADA to be 8 byte aligned.
|
||||
EMIT_COMMENT("function descriptor of");
|
||||
OutStreamer->emitValue(
|
||||
SystemZMCExpr::create(SystemZ::S_RCon,
|
||||
MCSymbolRefExpr::create(Sym, OutContext),
|
||||
OutContext),
|
||||
MCSpecifierExpr::create(MCSymbolRefExpr::create(Sym, OutContext),
|
||||
SystemZ::S_RCon, OutContext),
|
||||
PointerSize);
|
||||
OutStreamer->emitValue(
|
||||
SystemZMCExpr::create(SystemZ::S_VCon,
|
||||
MCSymbolRefExpr::create(Sym, OutContext),
|
||||
OutContext),
|
||||
MCSpecifierExpr::create(MCSymbolRefExpr::create(Sym, OutContext),
|
||||
SystemZ::S_VCon, OutContext),
|
||||
PointerSize);
|
||||
EmittedBytes += PointerSize * 2;
|
||||
break;
|
||||
case SystemZII::MO_ADA_DATA_SYMBOL_ADDR:
|
||||
EMIT_COMMENT("pointer to data symbol");
|
||||
OutStreamer->emitValue(
|
||||
SystemZMCExpr::create(SystemZ::S_None,
|
||||
MCSymbolRefExpr::create(Sym, OutContext),
|
||||
OutContext),
|
||||
MCSpecifierExpr::create(MCSymbolRefExpr::create(Sym, OutContext),
|
||||
SystemZ::S_None, OutContext),
|
||||
PointerSize);
|
||||
EmittedBytes += PointerSize;
|
||||
break;
|
||||
@@ -1168,9 +1165,8 @@ void SystemZAsmPrinter::emitADASection() {
|
||||
|
||||
EMIT_COMMENT("pointer to function descriptor");
|
||||
OutStreamer->emitValue(
|
||||
SystemZMCExpr::create(SystemZ::S_VCon,
|
||||
MCSymbolRefExpr::create(Alias, OutContext),
|
||||
OutContext),
|
||||
MCSpecifierExpr::create(MCSymbolRefExpr::create(Alias, OutContext),
|
||||
SystemZ::S_VCon, OutContext),
|
||||
PointerSize);
|
||||
EmittedBytes += PointerSize;
|
||||
break;
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
// Return the VK_* enumeration for MachineOperand target flags Flags.
|
||||
static SystemZMCExpr::Specifier getSpecifierForTFlags(unsigned Flags) {
|
||||
// Return the S_* enumeration for MachineOperand target flags Flags.
|
||||
static SystemZ::Specifier getSpecifierForTFlags(unsigned Flags) {
|
||||
switch (Flags & SystemZII::MO_SYMBOL_MODIFIER) {
|
||||
case 0:
|
||||
return SystemZ::S_None;
|
||||
@@ -34,7 +34,7 @@ SystemZMCInstLower::SystemZMCInstLower(MCContext &ctx,
|
||||
: Ctx(ctx), AsmPrinter(asmprinter) {}
|
||||
|
||||
const MCExpr *SystemZMCInstLower::getExpr(const MachineOperand &MO,
|
||||
SystemZMCExpr::Specifier Spec) const {
|
||||
SystemZ::Specifier Spec) const {
|
||||
const MCSymbol *Symbol;
|
||||
bool HasOffset = true;
|
||||
switch (MO.getType()) {
|
||||
@@ -85,7 +85,7 @@ MCOperand SystemZMCInstLower::lowerOperand(const MachineOperand &MO) const {
|
||||
return MCOperand::createImm(MO.getImm());
|
||||
|
||||
default: {
|
||||
SystemZMCExpr::Specifier Kind = getSpecifierForTFlags(MO.getTargetFlags());
|
||||
auto Kind = getSpecifierForTFlags(MO.getTargetFlags());
|
||||
return MCOperand::createExpr(getExpr(MO, Kind));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#ifndef LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZMCINSTLOWER_H
|
||||
#define LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZMCINSTLOWER_H
|
||||
|
||||
#include "MCTargetDesc/SystemZMCExpr.h"
|
||||
#include "MCTargetDesc/SystemZMCAsmInfo.h"
|
||||
#include "llvm/MC/MCExpr.h"
|
||||
#include "llvm/Support/Compiler.h"
|
||||
#include "llvm/Support/DataTypes.h"
|
||||
@@ -35,8 +35,7 @@ public:
|
||||
MCOperand lowerOperand(const MachineOperand& MO) const;
|
||||
|
||||
// Return an MCExpr for symbolic operand MO with variant kind Kind.
|
||||
const MCExpr *getExpr(const MachineOperand &MO,
|
||||
SystemZMCExpr::Specifier) const;
|
||||
const MCExpr *getExpr(const MachineOperand &MO, SystemZ::Specifier) const;
|
||||
};
|
||||
} // end namespace llvm
|
||||
|
||||
|
||||
Reference in New Issue
Block a user