Skip to content

Commit 4a6b4d3

Browse files
committed
RISCVMCExpr: Migrate to MCSpecifierExpr
1 parent beaa98b commit 4a6b4d3

File tree

4 files changed

+8
-43
lines changed

4 files changed

+8
-43
lines changed

llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ RISCVELFObjectWriter::~RISCVELFObjectWriter() = default;
4848
unsigned RISCVELFObjectWriter::getRelocType(const MCFixup &Fixup,
4949
const MCValue &Target,
5050
bool IsPCRel) const {
51-
const MCExpr *Expr = Fixup.getValue();
5251
unsigned Kind = Fixup.getTargetKind();
5352
auto Spec = RISCVMCExpr::Specifier(Target.getSpecifier());
5453
switch (Spec) {
@@ -119,14 +118,11 @@ unsigned RISCVELFObjectWriter::getRelocType(const MCFixup &Fixup,
119118
reportError(Fixup.getLoc(), "2-byte data relocations not supported");
120119
return ELF::R_RISCV_NONE;
121120
case FK_Data_4:
122-
if (Expr->getKind() == MCExpr::Target) {
123-
auto Spec = cast<RISCVMCExpr>(Expr)->getSpecifier();
124-
switch (Spec) {
125-
case ELF::R_RISCV_32_PCREL:
126-
case ELF::R_RISCV_GOT32_PCREL:
127-
case ELF::R_RISCV_PLT32:
128-
return Spec;
129-
}
121+
switch (Spec) {
122+
case ELF::R_RISCV_32_PCREL:
123+
case ELF::R_RISCV_GOT32_PCREL:
124+
case ELF::R_RISCV_PLT32:
125+
return Spec;
130126
}
131127
return ELF::R_RISCV_32;
132128
case FK_Data_8:

llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ uint64_t RISCVMCCodeEmitter::getImmOpValue(const MCInst &MI, unsigned OpNo,
565565
MCExpr::ExprKind Kind = Expr->getKind();
566566
unsigned FixupKind = RISCV::fixup_riscv_invalid;
567567
bool RelaxCandidate = false;
568-
if (Kind == MCExpr::Target) {
568+
if (Kind == MCExpr::Specifier) {
569569
const RISCVMCExpr *RVExpr = cast<RISCVMCExpr>(Expr);
570570
FixupKind = RVExpr->getSpecifier();
571571
switch (RVExpr->getSpecifier()) {

llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,6 @@ const MCFixup *RISCVMCExpr::getPCRelHiFixup(const MCFragment **DFOut) const {
8787
return nullptr;
8888
}
8989

90-
bool RISCVMCExpr::evaluateAsRelocatableImpl(MCValue &Res,
91-
const MCAssembler *Asm) const {
92-
if (!getSubExpr()->evaluateAsRelocatable(Res, Asm))
93-
return false;
94-
Res.setSpecifier(specifier);
95-
96-
// Custom fixup types are not valid with symbol difference expressions.
97-
return !Res.getSubSym();
98-
}
99-
100-
void RISCVMCExpr::visitUsedExpr(MCStreamer &Streamer) const {
101-
Streamer.visitUsedExpr(*getSubExpr());
102-
}
103-
10490
std::optional<RISCVMCExpr::Specifier>
10591
RISCVMCExpr::getSpecifierForName(StringRef name) {
10692
return StringSwitch<std::optional<RISCVMCExpr::Specifier>>(name)

llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.h

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace llvm {
2121

2222
class StringRef;
2323

24-
class RISCVMCExpr : public MCTargetExpr {
24+
class RISCVMCExpr : public MCSpecifierExpr {
2525
public:
2626
using Specifier = uint16_t;
2727
// Specifiers mapping to relocation types below FirstTargetFixupKind are
@@ -38,20 +38,13 @@ class RISCVMCExpr : public MCTargetExpr {
3838
};
3939

4040
private:
41-
const MCExpr *Expr;
42-
const Specifier specifier;
43-
4441
explicit RISCVMCExpr(const MCExpr *Expr, Specifier S)
45-
: Expr(Expr), specifier(S) {}
42+
: MCSpecifierExpr(Expr, S) {}
4643

4744
public:
4845
static const RISCVMCExpr *create(const MCExpr *Expr, Specifier S,
4946
MCContext &Ctx);
5047

51-
Specifier getSpecifier() const { return specifier; }
52-
53-
const MCExpr *getSubExpr() const { return Expr; }
54-
5548
/// Get the corresponding PC-relative HI fixup that a VK_PCREL_LO
5649
/// points to, and optionally the fragment containing it.
5750
///
@@ -60,16 +53,6 @@ class RISCVMCExpr : public MCTargetExpr {
6053
const MCFixup *getPCRelHiFixup(const MCFragment **DFOut) const;
6154

6255
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
63-
bool evaluateAsRelocatableImpl(MCValue &Res,
64-
const MCAssembler *Asm) const override;
65-
void visitUsedExpr(MCStreamer &Streamer) const override;
66-
MCFragment *findAssociatedFragment() const override {
67-
return getSubExpr()->findAssociatedFragment();
68-
}
69-
70-
static bool classof(const MCExpr *E) {
71-
return E->getKind() == MCExpr::Target;
72-
}
7356

7457
static std::optional<Specifier> getSpecifierForName(StringRef name);
7558
static StringRef getSpecifierName(Specifier Kind);

0 commit comments

Comments
 (0)