Skip to content

Commit f3e6473

Browse files
committed
MCValue: reduce getSymB uses
The MCValue::SymB MCSymbolRefExpr member might be replaced with a MCSymbol in the future. Reduce direct access.
1 parent a1935fd commit f3e6473

File tree

5 files changed

+11
-10
lines changed

5 files changed

+11
-10
lines changed

llvm/lib/MC/MCAssembler.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,9 @@ bool MCAssembler::evaluateFixup(const MCFixup &Fixup, const MCFragment *DF,
201201
if (Sym.isDefined())
202202
Value += getSymbolOffset(Sym);
203203
}
204-
if (const MCSymbolRefExpr *B = Target.getSymB()) {
205-
const MCSymbol &Sym = B->getSymbol();
206-
if (Sym.isDefined())
207-
Value -= getSymbolOffset(Sym);
208-
}
204+
if (const MCSymbol *Sub = Target.getSubSym())
205+
if (Sub->isDefined())
206+
Value -= getSymbolOffset(*Sub);
209207

210208
bool ShouldAlignPC = FixupFlags & MCFixupKindInfo::FKF_IsAlignedDownTo32Bits;
211209
assert((ShouldAlignPC ? IsPCRel : true) &&

llvm/lib/MC/MCValue.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "llvm/MC/MCValue.h"
1010
#include "llvm/Config/llvm-config.h"
1111
#include "llvm/MC/MCExpr.h"
12+
#include "llvm/MC/MCSymbol.h"
1213
#include "llvm/Support/Debug.h"
1314
#include "llvm/Support/ErrorHandling.h"
1415
#include "llvm/Support/raw_ostream.h"
@@ -28,9 +29,9 @@ void MCValue::print(raw_ostream &OS) const {
2829

2930
OS << *getSymA();
3031

31-
if (getSymB()) {
32+
if (auto *B = getSubSym()) {
3233
OS << " - ";
33-
OS << *getSymB();
34+
B->print(OS, nullptr);
3435
}
3536

3637
if (getConstant())

llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,8 @@ bool LoongArchAsmBackend::handleAddSubRelocations(const MCAssembler &Asm,
498498
llvm_unreachable("unsupported fixup size");
499499
}
500500
MCValue A = MCValue::get(Target.getSymA(), nullptr, Target.getConstant());
501-
MCValue B = MCValue::get(Target.getSymB());
501+
MCValue B = MCValue::get(
502+
MCSymbolRefExpr::create(Target.getSubSym(), Asm.getContext()));
502503
auto FA = MCFixup::create(Fixup.getOffset(), nullptr, std::get<0>(FK));
503504
auto FB = MCFixup::create(Fixup.getOffset(), nullptr, std::get<1>(FK));
504505
auto &Assembler = const_cast<MCAssembler &>(Asm);

llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2806,7 +2806,7 @@ bool RISCVAsmParser::isSymbolDiff(const MCExpr *Expr) {
28062806
MCValue Res;
28072807
if (Expr->evaluateAsRelocatable(Res, nullptr)) {
28082808
return Res.getRefKind() == RISCVMCExpr::VK_None && Res.getSymA() &&
2809-
Res.getSymB();
2809+
Res.getSubSym();
28102810
}
28112811
return false;
28122812
}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,8 @@ bool RISCVAsmBackend::handleAddSubRelocations(const MCAssembler &Asm,
657657
llvm_unreachable("unsupported fixup size");
658658
}
659659
MCValue A = MCValue::get(Target.getSymA(), nullptr, Target.getConstant());
660-
MCValue B = MCValue::get(Target.getSymB());
660+
MCValue B = MCValue::get(
661+
MCSymbolRefExpr::create(Target.getSubSym(), Asm.getContext()));
661662
auto FA = MCFixup::create(
662663
Fixup.getOffset(), nullptr,
663664
static_cast<MCFixupKind>(FirstLiteralRelocationKind + TA));

0 commit comments

Comments
 (0)