[llvm] 086af83 - [MC] Replace getSymA()->getSymbol() with getAddSym. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 5 13:23:19 PDT 2025
Author: Fangrui Song
Date: 2025-04-05T13:23:14-07:00
New Revision: 086af836889436baffc71c743c7c8259bad8ed60
URL: https://github.com/llvm/llvm-project/commit/086af836889436baffc71c743c7c8259bad8ed60
DIFF: https://github.com/llvm/llvm-project/commit/086af836889436baffc71c743c7c8259bad8ed60.diff
LOG: [MC] Replace getSymA()->getSymbol() with getAddSym. NFC
We will replace the MCSymbolRefExpr member in MCValue with MCSymbol.
This change reduces dependence on MCSymbolRefExpr.
Added:
Modified:
llvm/lib/MC/MCAssembler.cpp
llvm/lib/MC/MCExpr.cpp
llvm/lib/MC/MCObjectStreamer.cpp
llvm/lib/MC/WasmObjectWriter.cpp
llvm/lib/MC/WinCOFFObjectWriter.cpp
Removed:
################################################################################
diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp
index 39ff41e89f1e2..685fd1cbdea4d 100644
--- a/llvm/lib/MC/MCAssembler.cpp
+++ b/llvm/lib/MC/MCAssembler.cpp
@@ -164,14 +164,11 @@ bool MCAssembler::evaluateFixup(const MCFixup &Fixup, const MCFragment *DF,
bool IsPCRel = FixupFlags & MCFixupKindInfo::FKF_IsPCRel;
bool IsResolved = false;
if (IsPCRel) {
- if (Target.getSubSym()) {
- IsResolved = false;
- } else if (!Target.getSymA()) {
+ if (Target.getSubSym() || !Target.getAddSym()) {
IsResolved = false;
} else {
- const MCSymbolRefExpr *A = Target.getSymA();
- const MCSymbol &SA = A->getSymbol();
- if (A->getKind() != MCSymbolRefExpr::VK_None || SA.isUndefined()) {
+ auto &SA = *Target.getAddSym();
+ if (Target.getSymSpecifier() || SA.isUndefined()) {
IsResolved = false;
} else {
IsResolved = (FixupFlags & MCFixupKindInfo::FKF_Constant) ||
diff --git a/llvm/lib/MC/MCExpr.cpp b/llvm/lib/MC/MCExpr.cpp
index 1a7c4590c1219..b921b55950772 100644
--- a/llvm/lib/MC/MCExpr.cpp
+++ b/llvm/lib/MC/MCExpr.cpp
@@ -578,7 +578,7 @@ bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
break;
case MCUnaryExpr::Minus:
/// -(a - b + const) ==> (b - a - const)
- if (Value.getSymA() && !Value.getSubSym())
+ if (Value.getAddSym() && !Value.getSubSym())
return false;
// The cast avoids undefined behavior if the constant is INT64_MIN.
diff --git a/llvm/lib/MC/MCObjectStreamer.cpp b/llvm/lib/MC/MCObjectStreamer.cpp
index b6ee894f93c49..86232c1712dc5 100644
--- a/llvm/lib/MC/MCObjectStreamer.cpp
+++ b/llvm/lib/MC/MCObjectStreamer.cpp
@@ -676,8 +676,7 @@ MCObjectStreamer::emitRelocDirective(const MCExpr &Offset, StringRef Name,
return std::make_pair(false,
std::string(".reloc offset is not representable"));
- const MCSymbolRefExpr &SRE = cast<MCSymbolRefExpr>(*OffsetVal.getSymA());
- const MCSymbol &Symbol = SRE.getSymbol();
+ const MCSymbol &Symbol = *OffsetVal.getAddSym();
if (Symbol.isDefined()) {
uint32_t SymbolOffset = 0;
std::optional<std::pair<bool, std::string>> Error =
@@ -693,8 +692,7 @@ MCObjectStreamer::emitRelocDirective(const MCExpr &Offset, StringRef Name,
}
PendingFixups.emplace_back(
- &SRE.getSymbol(), DF,
- MCFixup::create(OffsetVal.getConstant(), Expr, Kind, Loc));
+ &Symbol, DF, MCFixup::create(OffsetVal.getConstant(), Expr, Kind, Loc));
return std::nullopt;
}
diff --git a/llvm/lib/MC/WasmObjectWriter.cpp b/llvm/lib/MC/WasmObjectWriter.cpp
index 9d5a290f70cad..b35ca704c519a 100644
--- a/llvm/lib/MC/WasmObjectWriter.cpp
+++ b/llvm/lib/MC/WasmObjectWriter.cpp
@@ -519,8 +519,7 @@ void WasmObjectWriter::recordRelocation(MCAssembler &Asm,
}
// We either rejected the fixup or folded B into C at this point.
- const MCSymbolRefExpr *RefA = Target.getSymA();
- const auto *SymA = cast<MCSymbolWasm>(&RefA->getSymbol());
+ const auto *SymA = cast<MCSymbolWasm>(Target.getAddSym());
// The .init_array isn't translated as data, so don't do relocations in it.
if (FixupSection.getName().starts_with(".init_array")) {
@@ -607,7 +606,7 @@ void WasmObjectWriter::recordRelocation(MCAssembler &Asm,
SymA->setUsedInReloc();
}
- switch (RefA->getKind()) {
+ switch (Target.getSymSpecifier()) {
case MCSymbolRefExpr::VK_GOT:
case MCSymbolRefExpr::VK_WASM_GOT_TLS:
SymA->setUsedInGOT();
diff --git a/llvm/lib/MC/WinCOFFObjectWriter.cpp b/llvm/lib/MC/WinCOFFObjectWriter.cpp
index ccf8a2d34c1b5..b7d05b864bb39 100644
--- a/llvm/lib/MC/WinCOFFObjectWriter.cpp
+++ b/llvm/lib/MC/WinCOFFObjectWriter.cpp
@@ -837,9 +837,9 @@ void WinCOFFWriter::recordRelocation(MCAssembler &Asm,
const MCFragment *Fragment,
const MCFixup &Fixup, MCValue Target,
uint64_t &FixedValue) {
- assert(Target.getSymA() && "Relocation must reference a symbol!");
+ assert(Target.getAddSym() && "Relocation must reference a symbol!");
- const MCSymbol &A = Target.getSymA()->getSymbol();
+ const MCSymbol &A = *Target.getAddSym();
if (!A.isRegistered()) {
Asm.getContext().reportError(Fixup.getLoc(), Twine("symbol '") +
A.getName() +
More information about the llvm-commits
mailing list