CSKY: Migrate to the new relocation specifier representation
Use MCSpecifierExpr directly and remove the CSKYMCExpr subclass. Define printImpl within CSKYMCAsmInfo.
This commit is contained in:
@@ -8,7 +8,6 @@
|
||||
|
||||
#include "MCTargetDesc/CSKYInstPrinter.h"
|
||||
#include "MCTargetDesc/CSKYMCAsmInfo.h"
|
||||
#include "MCTargetDesc/CSKYMCExpr.h"
|
||||
#include "MCTargetDesc/CSKYMCTargetDesc.h"
|
||||
#include "MCTargetDesc/CSKYTargetStreamer.h"
|
||||
#include "TargetInfo/CSKYTargetInfo.h"
|
||||
@@ -849,11 +848,11 @@ bool CSKYAsmParser::processLRW(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out) {
|
||||
}
|
||||
} else {
|
||||
const MCExpr *AdjustExpr = nullptr;
|
||||
if (const CSKYMCExpr *CSKYExpr =
|
||||
dyn_cast<CSKYMCExpr>(Inst.getOperand(1).getExpr())) {
|
||||
if (CSKYExpr->getSpecifier() == CSKYMCExpr::VK_TLSGD ||
|
||||
CSKYExpr->getSpecifier() == CSKYMCExpr::VK_TLSIE ||
|
||||
CSKYExpr->getSpecifier() == CSKYMCExpr::VK_TLSLDM) {
|
||||
if (const auto *CSKYExpr =
|
||||
dyn_cast<MCSpecifierExpr>(Inst.getOperand(1).getExpr())) {
|
||||
if (CSKYExpr->getSpecifier() == CSKY::S_TLSGD ||
|
||||
CSKYExpr->getSpecifier() == CSKY::S_TLSIE ||
|
||||
CSKYExpr->getSpecifier() == CSKY::S_TLSLDM) {
|
||||
MCSymbol *Dot = getContext().createNamedTempSymbol();
|
||||
Out.emitLabel(Dot);
|
||||
AdjustExpr = MCSymbolRefExpr::create(Dot, getContext());
|
||||
@@ -1173,25 +1172,25 @@ ParseStatus CSKYAsmParser::parseCSKYSymbol(OperandVector &Operands) {
|
||||
if (getParser().parseIdentifier(Identifier))
|
||||
return Error(getLoc(), "unknown identifier");
|
||||
|
||||
CSKYMCExpr::Specifier Kind = CSKYMCExpr::VK_None;
|
||||
CSKY::Specifier Kind = CSKY::S_None;
|
||||
if (Identifier.consume_back("@GOT"))
|
||||
Kind = CSKYMCExpr::VK_GOT;
|
||||
Kind = CSKY::S_GOT;
|
||||
else if (Identifier.consume_back("@GOTOFF"))
|
||||
Kind = CSKYMCExpr::VK_GOTOFF;
|
||||
Kind = CSKY::S_GOTOFF;
|
||||
else if (Identifier.consume_back("@PLT"))
|
||||
Kind = CSKYMCExpr::VK_PLT;
|
||||
Kind = CSKY::S_PLT;
|
||||
else if (Identifier.consume_back("@GOTPC"))
|
||||
Kind = CSKYMCExpr::VK_GOTPC;
|
||||
Kind = CSKY::S_GOTPC;
|
||||
else if (Identifier.consume_back("@TLSGD32"))
|
||||
Kind = CSKYMCExpr::VK_TLSGD;
|
||||
Kind = CSKY::S_TLSGD;
|
||||
else if (Identifier.consume_back("@GOTTPOFF"))
|
||||
Kind = CSKYMCExpr::VK_TLSIE;
|
||||
Kind = CSKY::S_TLSIE;
|
||||
else if (Identifier.consume_back("@TPOFF"))
|
||||
Kind = CSKYMCExpr::VK_TLSLE;
|
||||
Kind = CSKY::S_TLSLE;
|
||||
else if (Identifier.consume_back("@TLSLDM32"))
|
||||
Kind = CSKYMCExpr::VK_TLSLDM;
|
||||
Kind = CSKY::S_TLSLDM;
|
||||
else if (Identifier.consume_back("@TLSLDO32"))
|
||||
Kind = CSKYMCExpr::VK_TLSLDO;
|
||||
Kind = CSKY::S_TLSLDO;
|
||||
|
||||
MCSymbol *Sym = getContext().getInlineAsmLabel(Identifier);
|
||||
|
||||
@@ -1211,8 +1210,8 @@ ParseStatus CSKYAsmParser::parseCSKYSymbol(OperandVector &Operands) {
|
||||
MCBinaryExpr::Opcode Opcode;
|
||||
switch (getLexer().getKind()) {
|
||||
default:
|
||||
if (Kind != CSKYMCExpr::VK_None)
|
||||
Res = CSKYMCExpr::create(Res, Kind, getContext());
|
||||
if (Kind != CSKY::S_None)
|
||||
Res = MCSpecifierExpr::create(Res, Kind, getContext());
|
||||
|
||||
Operands.push_back(CSKYOperand::createImm(Res, S, E));
|
||||
return ParseStatus::Success;
|
||||
@@ -1259,11 +1258,11 @@ ParseStatus CSKYAsmParser::parseDataSymbol(OperandVector &Operands) {
|
||||
if (getParser().parseIdentifier(Identifier))
|
||||
return Error(getLoc(), "unknown identifier " + Identifier);
|
||||
|
||||
CSKYMCExpr::Specifier Kind = CSKYMCExpr::VK_None;
|
||||
CSKY::Specifier Kind = CSKY::S_None;
|
||||
if (Identifier.consume_back("@GOT"))
|
||||
Kind = CSKYMCExpr::VK_GOT_IMM18_BY4;
|
||||
Kind = CSKY::S_GOT_IMM18_BY4;
|
||||
else if (Identifier.consume_back("@PLT"))
|
||||
Kind = CSKYMCExpr::VK_PLT_IMM18_BY4;
|
||||
Kind = CSKY::S_PLT_IMM18_BY4;
|
||||
|
||||
MCSymbol *Sym = getContext().getInlineAsmLabel(Identifier);
|
||||
|
||||
@@ -1289,8 +1288,8 @@ ParseStatus CSKYAsmParser::parseDataSymbol(OperandVector &Operands) {
|
||||
|
||||
getLexer().Lex(); // Eat ']'.
|
||||
|
||||
if (Kind != CSKYMCExpr::VK_None)
|
||||
Res = CSKYMCExpr::create(Res, Kind, getContext());
|
||||
if (Kind != CSKY::S_None)
|
||||
Res = MCSpecifierExpr::create(Res, Kind, getContext());
|
||||
|
||||
Operands.push_back(CSKYOperand::createConstpoolOp(Res, S, E));
|
||||
return ParseStatus::Success;
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#include "CSKYConstantPoolValue.h"
|
||||
#include "CSKYTargetMachine.h"
|
||||
#include "MCTargetDesc/CSKYInstPrinter.h"
|
||||
#include "MCTargetDesc/CSKYMCExpr.h"
|
||||
#include "MCTargetDesc/CSKYMCAsmInfo.h"
|
||||
#include "MCTargetDesc/CSKYTargetStreamer.h"
|
||||
#include "TargetInfo/CSKYTargetInfo.h"
|
||||
#include "llvm/ADT/Statistic.h"
|
||||
@@ -168,25 +168,24 @@ void CSKYAsmPrinter::emitInstruction(const MachineInstr *MI) {
|
||||
|
||||
// Convert a CSKY-specific constant pool modifier into the associated
|
||||
// MCSymbolRefExpr variant kind.
|
||||
static CSKYMCExpr::Specifier
|
||||
getModifierVariantKind(CSKYCP::CSKYCPModifier Modifier) {
|
||||
static CSKY::Specifier getModifierVariantKind(CSKYCP::CSKYCPModifier Modifier) {
|
||||
switch (Modifier) {
|
||||
case CSKYCP::NO_MOD:
|
||||
return CSKYMCExpr::VK_None;
|
||||
return CSKY::S_None;
|
||||
case CSKYCP::ADDR:
|
||||
return CSKYMCExpr::VK_ADDR;
|
||||
return CSKY::S_ADDR;
|
||||
case CSKYCP::GOT:
|
||||
return CSKYMCExpr::VK_GOT;
|
||||
return CSKY::S_GOT;
|
||||
case CSKYCP::GOTOFF:
|
||||
return CSKYMCExpr::VK_GOTOFF;
|
||||
return CSKY::S_GOTOFF;
|
||||
case CSKYCP::PLT:
|
||||
return CSKYMCExpr::VK_PLT;
|
||||
return CSKY::S_PLT;
|
||||
case CSKYCP::TLSGD:
|
||||
return CSKYMCExpr::VK_TLSGD;
|
||||
return CSKY::S_TLSGD;
|
||||
case CSKYCP::TLSLE:
|
||||
return CSKYMCExpr::VK_TLSLE;
|
||||
return CSKY::S_TLSLE;
|
||||
case CSKYCP::TLSIE:
|
||||
return CSKYMCExpr::VK_TLSIE;
|
||||
return CSKY::S_TLSIE;
|
||||
}
|
||||
llvm_unreachable("Invalid CSKYCPModifier!");
|
||||
}
|
||||
@@ -240,8 +239,8 @@ void CSKYAsmPrinter::emitMachineConstantPoolValue(
|
||||
}
|
||||
|
||||
// Create an MCSymbol for the reference.
|
||||
Expr = CSKYMCExpr::create(Expr, getModifierVariantKind(CCPV->getModifier()),
|
||||
OutContext);
|
||||
Expr = MCSpecifierExpr::create(
|
||||
Expr, getModifierVariantKind(CCPV->getModifier()), OutContext);
|
||||
|
||||
OutStreamer->emitValue(Expr, Size);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
#include "CSKYMCInstLower.h"
|
||||
#include "MCTargetDesc/CSKYBaseInfo.h"
|
||||
#include "MCTargetDesc/CSKYMCExpr.h"
|
||||
#include "MCTargetDesc/CSKYMCAsmInfo.h"
|
||||
#include "llvm/CodeGen/AsmPrinter.h"
|
||||
#include "llvm/MC/MCExpr.h"
|
||||
|
||||
@@ -36,38 +36,38 @@ void CSKYMCInstLower::Lower(const MachineInstr *MI, MCInst &OutMI) const {
|
||||
|
||||
MCOperand CSKYMCInstLower::lowerSymbolOperand(const MachineOperand &MO,
|
||||
MCSymbol *Sym) const {
|
||||
CSKYMCExpr::Specifier Spec;
|
||||
CSKY::Specifier Spec;
|
||||
MCContext &Ctx = Printer.OutContext;
|
||||
|
||||
switch (MO.getTargetFlags()) {
|
||||
default:
|
||||
llvm_unreachable("Unknown target flag.");
|
||||
case CSKYII::MO_None:
|
||||
Spec = CSKYMCExpr::VK_None;
|
||||
Spec = CSKY::S_None;
|
||||
break;
|
||||
case CSKYII::MO_GOT32:
|
||||
Spec = CSKYMCExpr::VK_GOT;
|
||||
Spec = CSKY::S_GOT;
|
||||
break;
|
||||
case CSKYII::MO_GOTOFF:
|
||||
Spec = CSKYMCExpr::VK_GOTOFF;
|
||||
Spec = CSKY::S_GOTOFF;
|
||||
break;
|
||||
case CSKYII::MO_ADDR32:
|
||||
Spec = CSKYMCExpr::VK_ADDR;
|
||||
Spec = CSKY::S_ADDR;
|
||||
break;
|
||||
case CSKYII::MO_PLT32:
|
||||
Spec = CSKYMCExpr::VK_PLT;
|
||||
Spec = CSKY::S_PLT;
|
||||
break;
|
||||
case CSKYII::MO_ADDR_HI16:
|
||||
Spec = CSKYMCExpr::VK_ADDR_HI16;
|
||||
Spec = CSKY::S_ADDR_HI16;
|
||||
break;
|
||||
case CSKYII::MO_ADDR_LO16:
|
||||
Spec = CSKYMCExpr::VK_ADDR_LO16;
|
||||
Spec = CSKY::S_ADDR_LO16;
|
||||
break;
|
||||
}
|
||||
const MCExpr *ME = MCSymbolRefExpr::create(Sym, Ctx);
|
||||
|
||||
if (Spec != CSKYMCExpr::VK_None)
|
||||
ME = CSKYMCExpr::create(ME, Spec, Ctx);
|
||||
if (Spec != CSKY::S_None)
|
||||
ME = MCSpecifierExpr::create(ME, Spec, Ctx);
|
||||
|
||||
return MCOperand::createExpr(ME);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ add_llvm_component_library(LLVMCSKYDesc
|
||||
CSKYELFStreamer.cpp
|
||||
CSKYInstPrinter.cpp
|
||||
CSKYMCAsmInfo.cpp
|
||||
CSKYMCExpr.cpp
|
||||
CSKYMCTargetDesc.cpp
|
||||
CSKYMCCodeEmitter.cpp
|
||||
CSKYTargetStreamer.cpp
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "CSKYFixupKinds.h"
|
||||
#include "CSKYMCExpr.h"
|
||||
#include "CSKYMCAsmInfo.h"
|
||||
#include "CSKYMCTargetDesc.h"
|
||||
#include "MCTargetDesc/CSKYMCExpr.h"
|
||||
#include "MCTargetDesc/CSKYMCAsmInfo.h"
|
||||
#include "llvm/MC/MCContext.h"
|
||||
#include "llvm/MC/MCELFObjectWriter.h"
|
||||
#include "llvm/MC/MCObjectWriter.h"
|
||||
@@ -43,11 +43,11 @@ unsigned CSKYELFObjectWriter::getRelocType(const MCFixup &Fixup,
|
||||
uint8_t Modifier = Target.getSpecifier();
|
||||
|
||||
switch (Target.getSpecifier()) {
|
||||
case CSKYMCExpr::VK_TLSIE:
|
||||
case CSKYMCExpr::VK_TLSLE:
|
||||
case CSKYMCExpr::VK_TLSGD:
|
||||
case CSKYMCExpr::VK_TLSLDM:
|
||||
case CSKYMCExpr::VK_TLSLDO:
|
||||
case CSKY::S_TLSIE:
|
||||
case CSKY::S_TLSLE:
|
||||
case CSKY::S_TLSGD:
|
||||
case CSKY::S_TLSLDM:
|
||||
case CSKY::S_TLSLDO:
|
||||
if (auto *SA = Target.getAddSym())
|
||||
cast<MCSymbolELF>(SA)->setType(ELF::STT_TLS);
|
||||
break;
|
||||
@@ -93,29 +93,29 @@ unsigned CSKYELFObjectWriter::getRelocType(const MCFixup &Fixup,
|
||||
reportError(Fixup.getLoc(), "2-byte data relocations not supported");
|
||||
return ELF::R_CKCORE_NONE;
|
||||
case FK_Data_4:
|
||||
if (Expr->getKind() == MCExpr::Target) {
|
||||
auto TK = cast<CSKYMCExpr>(Expr)->getSpecifier();
|
||||
if (TK == CSKYMCExpr::VK_ADDR)
|
||||
if (Expr->getKind() == MCExpr::Specifier) {
|
||||
auto TK = cast<MCSpecifierExpr>(Expr)->getSpecifier();
|
||||
if (TK == CSKY::S_ADDR)
|
||||
return ELF::R_CKCORE_ADDR32;
|
||||
if (TK == CSKYMCExpr::VK_GOT)
|
||||
if (TK == CSKY::S_GOT)
|
||||
return ELF::R_CKCORE_GOT32;
|
||||
if (TK == CSKYMCExpr::VK_GOTOFF)
|
||||
if (TK == CSKY::S_GOTOFF)
|
||||
return ELF::R_CKCORE_GOTOFF;
|
||||
if (TK == CSKYMCExpr::VK_PLT)
|
||||
if (TK == CSKY::S_PLT)
|
||||
return ELF::R_CKCORE_PLT32;
|
||||
if (TK == CSKYMCExpr::VK_TLSIE)
|
||||
if (TK == CSKY::S_TLSIE)
|
||||
return ELF::R_CKCORE_TLS_IE32;
|
||||
if (TK == CSKYMCExpr::VK_TLSLE)
|
||||
if (TK == CSKY::S_TLSLE)
|
||||
return ELF::R_CKCORE_TLS_LE32;
|
||||
if (TK == CSKYMCExpr::VK_TLSGD)
|
||||
if (TK == CSKY::S_TLSGD)
|
||||
return ELF::R_CKCORE_TLS_GD32;
|
||||
if (TK == CSKYMCExpr::VK_TLSLDM)
|
||||
if (TK == CSKY::S_TLSLDM)
|
||||
return ELF::R_CKCORE_TLS_LDM32;
|
||||
if (TK == CSKYMCExpr::VK_TLSLDO)
|
||||
if (TK == CSKY::S_TLSLDO)
|
||||
return ELF::R_CKCORE_TLS_LDO32;
|
||||
if (TK == CSKYMCExpr::VK_GOTPC)
|
||||
if (TK == CSKY::S_GOTPC)
|
||||
return ELF::R_CKCORE_GOTPC;
|
||||
if (TK == CSKYMCExpr::VK_None)
|
||||
if (TK == CSKY::S_None)
|
||||
return ELF::R_CKCORE_ADDR32;
|
||||
|
||||
LLVM_DEBUG(dbgs() << "Unknown FK_Data_4 TK = " << TK);
|
||||
@@ -125,19 +125,19 @@ unsigned CSKYELFObjectWriter::getRelocType(const MCFixup &Fixup,
|
||||
default:
|
||||
reportError(Fixup.getLoc(), "invalid fixup for 4-byte data relocation");
|
||||
return ELF::R_CKCORE_NONE;
|
||||
case CSKYMCExpr::VK_GOT:
|
||||
case CSKY::S_GOT:
|
||||
return ELF::R_CKCORE_GOT32;
|
||||
case CSKYMCExpr::VK_GOTOFF:
|
||||
case CSKY::S_GOTOFF:
|
||||
return ELF::R_CKCORE_GOTOFF;
|
||||
case CSKYMCExpr::VK_PLT:
|
||||
case CSKY::S_PLT:
|
||||
return ELF::R_CKCORE_PLT32;
|
||||
case CSKYMCExpr::VK_TLSGD:
|
||||
case CSKY::S_TLSGD:
|
||||
return ELF::R_CKCORE_TLS_GD32;
|
||||
case CSKYMCExpr::VK_TLSLDM:
|
||||
case CSKY::S_TLSLDM:
|
||||
return ELF::R_CKCORE_TLS_LDM32;
|
||||
case CSKYMCExpr::VK_TPOFF:
|
||||
case CSKY::S_TPOFF:
|
||||
return ELF::R_CKCORE_TLS_LE32;
|
||||
case CSKYMCExpr::VK_None:
|
||||
case CSKY::S_None:
|
||||
return ELF::R_CKCORE_ADDR32;
|
||||
}
|
||||
}
|
||||
@@ -167,8 +167,8 @@ unsigned CSKYELFObjectWriter::getRelocType(const MCFixup &Fixup,
|
||||
bool CSKYELFObjectWriter::needsRelocateWithSymbol(const MCValue &V,
|
||||
unsigned Type) const {
|
||||
switch (V.getSpecifier()) {
|
||||
case CSKYMCExpr::VK_PLT:
|
||||
case CSKYMCExpr::VK_GOT:
|
||||
case CSKY::S_PLT:
|
||||
case CSKY::S_GOT:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
#include "CSKYInstPrinter.h"
|
||||
#include "MCTargetDesc/CSKYBaseInfo.h"
|
||||
#include "MCTargetDesc/CSKYMCExpr.h"
|
||||
#include "MCTargetDesc/CSKYMCAsmInfo.h"
|
||||
#include "llvm/ADT/STLExtras.h"
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
#include "llvm/MC/MCAsmInfo.h"
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "CSKYMCAsmInfo.h"
|
||||
#include "MCTargetDesc/CSKYMCExpr.h"
|
||||
#include "MCTargetDesc/CSKYMCAsmInfo.h"
|
||||
#include "llvm/BinaryFormat/Dwarf.h"
|
||||
#include "llvm/MC/MCExpr.h"
|
||||
#include "llvm/MC/MCStreamer.h"
|
||||
@@ -19,9 +19,9 @@
|
||||
using namespace llvm;
|
||||
|
||||
const MCAsmInfo::AtSpecifier atSpecifiers[] = {
|
||||
{CSKYMCExpr::VK_GOT, "GOT"}, {CSKYMCExpr::VK_GOTOFF, "GOTOFF"},
|
||||
{CSKYMCExpr::VK_PLT, "PLT"}, {CSKYMCExpr::VK_TLSGD, "TLSGD"},
|
||||
{CSKYMCExpr::VK_TLSLDM, "TLSLDM"}, {CSKYMCExpr::VK_TPOFF, "TPOFF"},
|
||||
{CSKY::S_GOT, "GOT"}, {CSKY::S_GOTOFF, "GOTOFF"},
|
||||
{CSKY::S_PLT, "PLT"}, {CSKY::S_TLSGD, "TLSGD"},
|
||||
{CSKY::S_TLSLDM, "TLSLDM"}, {CSKY::S_TPOFF, "TPOFF"},
|
||||
};
|
||||
|
||||
void CSKYMCAsmInfo::anchor() {}
|
||||
@@ -38,3 +38,44 @@ CSKYMCAsmInfo::CSKYMCAsmInfo(const Triple &TargetTriple) {
|
||||
|
||||
initializeAtSpecifiers(atSpecifiers);
|
||||
}
|
||||
|
||||
static StringRef getVariantKindName(uint8_t Kind) {
|
||||
using namespace CSKY;
|
||||
switch (Kind) {
|
||||
default:
|
||||
llvm_unreachable("Invalid ELF symbol kind");
|
||||
case S_None:
|
||||
case S_ADDR:
|
||||
return "";
|
||||
case S_ADDR_HI16:
|
||||
return "@HI16";
|
||||
case S_ADDR_LO16:
|
||||
return "@LO16";
|
||||
case S_GOT_IMM18_BY4:
|
||||
case S_GOT:
|
||||
return "@GOT";
|
||||
case S_GOTPC:
|
||||
return "@GOTPC";
|
||||
case S_GOTOFF:
|
||||
return "@GOTOFF";
|
||||
case S_PLT_IMM18_BY4:
|
||||
case S_PLT:
|
||||
return "@PLT";
|
||||
case S_TLSLE:
|
||||
return "@TPOFF";
|
||||
case S_TLSIE:
|
||||
return "@GOTTPOFF";
|
||||
case S_TLSGD:
|
||||
return "@TLSGD32";
|
||||
case S_TLSLDO:
|
||||
return "@TLSLDO32";
|
||||
case S_TLSLDM:
|
||||
return "@TLSLDM32";
|
||||
}
|
||||
}
|
||||
|
||||
void CSKYMCAsmInfo::printSpecifierExpr(raw_ostream &OS,
|
||||
const MCSpecifierExpr &Expr) const {
|
||||
printExpr(OS, *Expr.getSubExpr());
|
||||
OS << getVariantKindName(Expr.getSpecifier());
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#define LLVM_LIB_TARGET_CSKY_MCTARGETDESC_CSKYMCASMINFO_H
|
||||
|
||||
#include "llvm/MC/MCAsmInfoELF.h"
|
||||
#include "llvm/MC/MCExpr.h"
|
||||
#include "llvm/MC/MCValue.h"
|
||||
|
||||
namespace llvm {
|
||||
class Triple;
|
||||
@@ -23,7 +25,33 @@ class CSKYMCAsmInfo : public MCAsmInfoELF {
|
||||
|
||||
public:
|
||||
explicit CSKYMCAsmInfo(const Triple &TargetTriple);
|
||||
void printSpecifierExpr(raw_ostream &OS,
|
||||
const MCSpecifierExpr &Expr) const override;
|
||||
};
|
||||
|
||||
namespace CSKY {
|
||||
using Specifier = uint8_t;
|
||||
enum {
|
||||
S_None,
|
||||
S_ADDR,
|
||||
S_ADDR_HI16,
|
||||
S_ADDR_LO16,
|
||||
S_PCREL,
|
||||
S_GOT,
|
||||
S_GOT_IMM18_BY4,
|
||||
S_GOTPC,
|
||||
S_GOTOFF,
|
||||
S_PLT,
|
||||
S_PLT_IMM18_BY4,
|
||||
S_TLSIE,
|
||||
S_TLSLE,
|
||||
S_TLSGD,
|
||||
S_TLSLDO,
|
||||
S_TLSLDM,
|
||||
S_TPOFF,
|
||||
S_Invalid
|
||||
};
|
||||
} // namespace CSKY
|
||||
} // namespace llvm
|
||||
|
||||
#endif // LLVM_LIB_TARGET_CSKY_MCTARGETDESC_CSKYMCASMINFO_H
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "CSKYMCCodeEmitter.h"
|
||||
#include "CSKYMCExpr.h"
|
||||
#include "CSKYMCAsmInfo.h"
|
||||
#include "MCTargetDesc/CSKYMCTargetDesc.h"
|
||||
#include "llvm/ADT/Statistic.h"
|
||||
#include "llvm/MC/MCInstBuilder.h"
|
||||
@@ -293,27 +293,27 @@ unsigned CSKYMCCodeEmitter::getImmJMPIX(const MCInst &MI, unsigned Idx,
|
||||
}
|
||||
|
||||
MCFixupKind CSKYMCCodeEmitter::getTargetFixup(const MCExpr *Expr) const {
|
||||
const CSKYMCExpr *CSKYExpr = cast<CSKYMCExpr>(Expr);
|
||||
const auto *CSKYExpr = cast<MCSpecifierExpr>(Expr);
|
||||
switch (CSKYExpr->getSpecifier()) {
|
||||
default:
|
||||
llvm_unreachable("Unhandled fixup kind!");
|
||||
case CSKYMCExpr::VK_ADDR:
|
||||
case CSKY::S_ADDR:
|
||||
return MCFixupKind(CSKY::fixup_csky_addr32);
|
||||
case CSKYMCExpr::VK_ADDR_HI16:
|
||||
case CSKY::S_ADDR_HI16:
|
||||
return MCFixupKind(CSKY::fixup_csky_addr_hi16);
|
||||
case CSKYMCExpr::VK_ADDR_LO16:
|
||||
case CSKY::S_ADDR_LO16:
|
||||
return MCFixupKind(CSKY::fixup_csky_addr_lo16);
|
||||
case CSKYMCExpr::VK_GOT:
|
||||
case CSKY::S_GOT:
|
||||
return MCFixupKind(CSKY::fixup_csky_got32);
|
||||
case CSKYMCExpr::VK_GOTPC:
|
||||
case CSKY::S_GOTPC:
|
||||
return MCFixupKind(CSKY::fixup_csky_gotpc);
|
||||
case CSKYMCExpr::VK_GOTOFF:
|
||||
case CSKY::S_GOTOFF:
|
||||
return MCFixupKind(CSKY::fixup_csky_gotoff);
|
||||
case CSKYMCExpr::VK_PLT:
|
||||
case CSKY::S_PLT:
|
||||
return MCFixupKind(CSKY::fixup_csky_plt32);
|
||||
case CSKYMCExpr::VK_PLT_IMM18_BY4:
|
||||
case CSKY::S_PLT_IMM18_BY4:
|
||||
return MCFixupKind(CSKY::fixup_csky_plt_imm18_scale4);
|
||||
case CSKYMCExpr::VK_GOT_IMM18_BY4:
|
||||
case CSKY::S_GOT_IMM18_BY4:
|
||||
return MCFixupKind(CSKY::fixup_csky_got_imm18_scale4);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#define LLVM_LIB_TARGET_CSKY_MCTARGETDESC_CSKYMCCODEEMITTER_H
|
||||
|
||||
#include "MCTargetDesc/CSKYFixupKinds.h"
|
||||
#include "MCTargetDesc/CSKYMCExpr.h"
|
||||
#include "MCTargetDesc/CSKYMCAsmInfo.h"
|
||||
#include "llvm/MC/MCCodeEmitter.h"
|
||||
#include "llvm/MC/MCContext.h"
|
||||
|
||||
@@ -107,7 +107,7 @@ public:
|
||||
assert(MO.isExpr() && "Unexpected MO type.");
|
||||
|
||||
MCFixupKind Kind = MCFixupKind(FIXUP);
|
||||
if (MO.getExpr()->getKind() == MCExpr::Target)
|
||||
if (MO.getExpr()->getKind() == MCExpr::Specifier)
|
||||
Kind = getTargetFixup(MO.getExpr());
|
||||
|
||||
Fixups.push_back(MCFixup::create(0, MO.getExpr(), Kind, MI.getLoc()));
|
||||
@@ -122,7 +122,7 @@ public:
|
||||
assert(MO.isExpr() && "Unexpected MO type.");
|
||||
|
||||
MCFixupKind Kind = MCFixupKind(FIXUP);
|
||||
if (MO.getExpr()->getKind() == MCExpr::Target)
|
||||
if (MO.getExpr()->getKind() == MCExpr::Specifier)
|
||||
Kind = getTargetFixup(MO.getExpr());
|
||||
|
||||
Fixups.push_back(MCFixup::create(0, MO.getExpr(), Kind, MI.getLoc()));
|
||||
@@ -137,7 +137,7 @@ public:
|
||||
assert(MO.isExpr() && "Unexpected MO type.");
|
||||
|
||||
MCFixupKind Kind = MCFixupKind(FIXUP);
|
||||
if (MO.getExpr()->getKind() == MCExpr::Target)
|
||||
if (MO.getExpr()->getKind() == MCExpr::Specifier)
|
||||
Kind = getTargetFixup(MO.getExpr());
|
||||
|
||||
Fixups.push_back(MCFixup::create(0, MO.getExpr(), Kind, MI.getLoc()));
|
||||
@@ -151,7 +151,7 @@ public:
|
||||
assert(MO.isExpr() && "Unexpected MO type.");
|
||||
|
||||
MCFixupKind Kind = MCFixupKind(CSKY::fixup_csky_pcrel_imm26_scale2);
|
||||
if (MO.getExpr()->getKind() == MCExpr::Target)
|
||||
if (MO.getExpr()->getKind() == MCExpr::Specifier)
|
||||
Kind = getTargetFixup(MO.getExpr());
|
||||
|
||||
Fixups.push_back(MCFixup::create(0, MO.getExpr(), Kind, MI.getLoc()));
|
||||
@@ -165,7 +165,7 @@ public:
|
||||
assert(MO.isExpr() && "Unexpected MO type.");
|
||||
|
||||
MCFixupKind Kind = MCFixupKind(CSKY::fixup_csky_pcrel_imm18_scale2);
|
||||
if (MO.getExpr()->getKind() == MCExpr::Target)
|
||||
if (MO.getExpr()->getKind() == MCExpr::Specifier)
|
||||
Kind = getTargetFixup(MO.getExpr());
|
||||
|
||||
Fixups.push_back(MCFixup::create(0, MO.getExpr(), Kind, MI.getLoc()));
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
//===-- CSKYMCExpr.cpp - CSKY 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "CSKYMCExpr.h"
|
||||
#include "CSKYFixupKinds.h"
|
||||
#include "MCTargetDesc/CSKYMCAsmInfo.h"
|
||||
#include "llvm/BinaryFormat/ELF.h"
|
||||
#include "llvm/MC/MCAssembler.h"
|
||||
#include "llvm/MC/MCContext.h"
|
||||
#include "llvm/MC/MCStreamer.h"
|
||||
#include "llvm/MC/MCSymbolELF.h"
|
||||
#include "llvm/Support/Casting.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
#define DEBUG_TYPE "csky-mc-expr"
|
||||
|
||||
const CSKYMCExpr *CSKYMCExpr::create(const MCExpr *Expr, Specifier Kind,
|
||||
MCContext &Ctx) {
|
||||
return new (Ctx) CSKYMCExpr(Expr, Kind);
|
||||
}
|
||||
|
||||
StringRef CSKYMCExpr::getVariantKindName(Specifier Kind) {
|
||||
switch (Kind) {
|
||||
default:
|
||||
llvm_unreachable("Invalid ELF symbol kind");
|
||||
case VK_None:
|
||||
case VK_ADDR:
|
||||
return "";
|
||||
case VK_ADDR_HI16:
|
||||
return "@HI16";
|
||||
case VK_ADDR_LO16:
|
||||
return "@LO16";
|
||||
case VK_GOT_IMM18_BY4:
|
||||
case VK_GOT:
|
||||
return "@GOT";
|
||||
case VK_GOTPC:
|
||||
return "@GOTPC";
|
||||
case VK_GOTOFF:
|
||||
return "@GOTOFF";
|
||||
case VK_PLT_IMM18_BY4:
|
||||
case VK_PLT:
|
||||
return "@PLT";
|
||||
case VK_TLSLE:
|
||||
return "@TPOFF";
|
||||
case VK_TLSIE:
|
||||
return "@GOTTPOFF";
|
||||
case VK_TLSGD:
|
||||
return "@TLSGD32";
|
||||
case VK_TLSLDO:
|
||||
return "@TLSLDO32";
|
||||
case VK_TLSLDM:
|
||||
return "@TLSLDM32";
|
||||
}
|
||||
}
|
||||
|
||||
void CSKYMCExpr::visitUsedExpr(MCStreamer &Streamer) const {
|
||||
Streamer.visitUsedExpr(*getSubExpr());
|
||||
}
|
||||
|
||||
void CSKYMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
|
||||
if (MAI)
|
||||
MAI->printExpr(OS, *Expr);
|
||||
OS << getVariantKindName(getSpecifier());
|
||||
}
|
||||
|
||||
bool CSKYMCExpr::evaluateAsRelocatableImpl(MCValue &Res,
|
||||
const MCAssembler *Asm) const {
|
||||
if (!getSubExpr()->evaluateAsRelocatable(Res, Asm))
|
||||
return false;
|
||||
Res.setSpecifier(specifier);
|
||||
return !Res.getSubSym();
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
//===-- CSKYMCExpr.h - CSKY 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_LANAI_MCTARGETDESC_LANAIMCEXPR_H
|
||||
#define LLVM_LIB_TARGET_LANAI_MCTARGETDESC_LANAIMCEXPR_H
|
||||
|
||||
#include "llvm/MC/MCExpr.h"
|
||||
#include "llvm/MC/MCValue.h"
|
||||
|
||||
namespace llvm {
|
||||
|
||||
class CSKYMCExpr : public MCTargetExpr {
|
||||
public:
|
||||
enum Specifier : uint8_t {
|
||||
VK_None,
|
||||
VK_ADDR = MCSymbolRefExpr::FirstTargetSpecifier,
|
||||
VK_ADDR_HI16,
|
||||
VK_ADDR_LO16,
|
||||
VK_PCREL,
|
||||
VK_GOT,
|
||||
VK_GOT_IMM18_BY4,
|
||||
VK_GOTPC,
|
||||
VK_GOTOFF,
|
||||
VK_PLT,
|
||||
VK_PLT_IMM18_BY4,
|
||||
VK_TLSIE,
|
||||
VK_TLSLE,
|
||||
VK_TLSGD,
|
||||
VK_TLSLDO,
|
||||
VK_TLSLDM,
|
||||
VK_TPOFF,
|
||||
VK_Invalid
|
||||
};
|
||||
|
||||
private:
|
||||
const MCExpr *Expr;
|
||||
const Specifier specifier;
|
||||
|
||||
explicit CSKYMCExpr(const MCExpr *Expr, Specifier S)
|
||||
: Expr(Expr), specifier(S) {}
|
||||
|
||||
public:
|
||||
static const CSKYMCExpr *create(const MCExpr *Expr, Specifier Kind,
|
||||
MCContext &Ctx);
|
||||
|
||||
// Returns the kind of this expression.
|
||||
Specifier getSpecifier() const { return specifier; }
|
||||
|
||||
// Returns the child of this expression.
|
||||
const MCExpr *getSubExpr() const { return Expr; }
|
||||
|
||||
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
|
||||
|
||||
bool evaluateAsRelocatableImpl(MCValue &Res,
|
||||
const MCAssembler *Asm) const override;
|
||||
void visitUsedExpr(MCStreamer &Streamer) const override;
|
||||
|
||||
MCFragment *findAssociatedFragment() const override {
|
||||
return getSubExpr()->findAssociatedFragment();
|
||||
}
|
||||
|
||||
static bool classof(const MCExpr *E) {
|
||||
return E->getKind() == MCExpr::Target;
|
||||
}
|
||||
|
||||
static StringRef getVariantKindName(Specifier Kind);
|
||||
};
|
||||
} // end namespace llvm
|
||||
|
||||
#endif
|
||||
@@ -7,6 +7,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "CSKYTargetStreamer.h"
|
||||
#include "MCTargetDesc/CSKYMCAsmInfo.h"
|
||||
#include "llvm/CodeGen/MachineFrameInfo.h"
|
||||
#include "llvm/CodeGen/TargetSubtargetInfo.h"
|
||||
#include "llvm/MC/MCContext.h"
|
||||
@@ -57,11 +58,11 @@ const MCExpr *CSKYConstantPool::addEntry(MCStreamer &Streamer,
|
||||
const auto SymRef = MCSymbolRefExpr::create(CPEntryLabel, Context);
|
||||
|
||||
if (AdjustExpr) {
|
||||
const CSKYMCExpr *CSKYExpr = cast<CSKYMCExpr>(Value);
|
||||
auto *CSKYExpr = cast<MCSpecifierExpr>(Value);
|
||||
|
||||
Value = MCBinaryExpr::createSub(AdjustExpr, SymRef, Context);
|
||||
Value = MCBinaryExpr::createSub(CSKYExpr->getSubExpr(), Value, Context);
|
||||
Value = CSKYMCExpr::create(Value, CSKYExpr->getSpecifier(), Context);
|
||||
Value = MCSpecifierExpr::create(Value, CSKYExpr->getSpecifier(), Context);
|
||||
}
|
||||
|
||||
Entries.push_back(ConstantPoolEntry(CPEntryLabel, Value, Size, Loc));
|
||||
@@ -84,12 +85,12 @@ CSKYTargetStreamer::CSKYTargetStreamer(MCStreamer &S)
|
||||
const MCExpr *
|
||||
CSKYTargetStreamer::addConstantPoolEntry(const MCExpr *Expr, SMLoc Loc,
|
||||
const MCExpr *AdjustExpr) {
|
||||
auto ELFRefKind = CSKYMCExpr::VK_Invalid;
|
||||
uint8_t ELFRefKind = CSKY::S_Invalid;
|
||||
ConstantCounter++;
|
||||
|
||||
const MCExpr *OrigExpr = Expr;
|
||||
|
||||
if (const CSKYMCExpr *CE = dyn_cast<CSKYMCExpr>(Expr)) {
|
||||
if (auto *CE = dyn_cast<MCSpecifierExpr>(Expr)) {
|
||||
Expr = CE->getSubExpr();
|
||||
ELFRefKind = CE->getSpecifier();
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#ifndef LLVM_LIB_TARGET_CSKY_CSKYTARGETSTREAMER_H
|
||||
#define LLVM_LIB_TARGET_CSKY_CSKYTARGETSTREAMER_H
|
||||
|
||||
#include "MCTargetDesc/CSKYMCExpr.h"
|
||||
#include "MCTargetDesc/CSKYMCAsmInfo.h"
|
||||
#include "llvm/MC/ConstantPools.h"
|
||||
#include "llvm/MC/MCStreamer.h"
|
||||
|
||||
@@ -46,7 +46,7 @@ class CSKYTargetStreamer : public MCTargetStreamer {
|
||||
public:
|
||||
typedef struct {
|
||||
const MCSymbol *sym;
|
||||
CSKYMCExpr::Specifier kind;
|
||||
CSKY::Specifier kind;
|
||||
} SymbolIndex;
|
||||
|
||||
protected:
|
||||
@@ -76,10 +76,10 @@ public:
|
||||
|
||||
template <> struct DenseMapInfo<CSKYTargetStreamer::SymbolIndex> {
|
||||
static inline CSKYTargetStreamer::SymbolIndex getEmptyKey() {
|
||||
return {nullptr, CSKYMCExpr::VK_Invalid};
|
||||
return {nullptr, CSKY::S_Invalid};
|
||||
}
|
||||
static inline CSKYTargetStreamer::SymbolIndex getTombstoneKey() {
|
||||
return {nullptr, CSKYMCExpr::VK_Invalid};
|
||||
return {nullptr, CSKY::S_Invalid};
|
||||
}
|
||||
static unsigned getHashValue(const CSKYTargetStreamer::SymbolIndex &V) {
|
||||
return hash_combine(DenseMapInfo<const MCSymbol *>::getHashValue(V.sym),
|
||||
|
||||
Reference in New Issue
Block a user