[llvm] dfae1f9 - MCValue: Simplify code with getSubSym
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 23 12:22:49 PDT 2025
Author: Fangrui Song
Date: 2025-03-23T12:22:44-07:00
New Revision: dfae1f968e7498f0f8487b0539d5a1c322c1daf9
URL: https://github.com/llvm/llvm-project/commit/dfae1f968e7498f0f8487b0539d5a1c322c1daf9
DIFF: https://github.com/llvm/llvm-project/commit/dfae1f968e7498f0f8487b0539d5a1c322c1daf9.diff
LOG: MCValue: Simplify code with getSubSym
Added:
Modified:
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/lib/MC/MCAssembler.cpp
llvm/lib/MC/MCValue.cpp
llvm/lib/MC/XCOFFObjectWriter.cpp
llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.cpp
llvm/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 743551822a8fc..095daa36748b3 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -3879,9 +3879,9 @@ static void handleIndirectSymViaGOTPCRel(AsmPrinter &AP, const MCExpr **ME,
// Check for a valid base symbol
const MCSymbol *BaseSym = AP.getSymbol(BaseGV);
- const MCSymbolRefExpr *SymB = MV.getSymB();
+ const MCSymbol *SymB = MV.getSubSym();
- if (!SymB || BaseSym != &SymB->getSymbol())
+ if (!SymB || BaseSym != SymB)
return;
// Make sure to match:
diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp
index 59c0ecc291315..0e541ffa51716 100644
--- a/llvm/lib/MC/MCAssembler.cpp
+++ b/llvm/lib/MC/MCAssembler.cpp
@@ -488,10 +488,10 @@ static bool getSymbolOffsetImpl(const MCAssembler &Asm, const MCSymbol &S,
Offset += ValA;
}
- const MCSymbolRefExpr *B = Target.getSymB();
+ const MCSymbol *B = Target.getSubSym();
if (B) {
uint64_t ValB;
- if (!getSymbolOffsetImpl(Asm, B->getSymbol(), ReportError, ValB))
+ if (!getSymbolOffsetImpl(Asm, *B, ReportError, ValB))
return false;
Offset -= ValB;
}
@@ -523,11 +523,11 @@ const MCSymbol *MCAssembler::getBaseSymbol(const MCSymbol &Symbol) const {
return nullptr;
}
- const MCSymbolRefExpr *RefB = Value.getSymB();
- if (RefB) {
+ const MCSymbol *SymB = Value.getSubSym();
+ if (SymB) {
getContext().reportError(
Expr->getLoc(),
- Twine("symbol '") + RefB->getSymbol().getName() +
+ Twine("symbol '") + SymB->getName() +
"' could not be evaluated in a subtraction expression");
return nullptr;
}
diff --git a/llvm/lib/MC/MCValue.cpp b/llvm/lib/MC/MCValue.cpp
index b6bcec9b2ca07..a90ba4eaa5f7c 100644
--- a/llvm/lib/MC/MCValue.cpp
+++ b/llvm/lib/MC/MCValue.cpp
@@ -44,12 +44,6 @@ LLVM_DUMP_METHOD void MCValue::dump() const {
#endif
MCSymbolRefExpr::VariantKind MCValue::getAccessVariant() const {
- const MCSymbolRefExpr *B = getSymB();
- if (B) {
- if (B->getKind() != MCSymbolRefExpr::VK_None)
- llvm_unreachable("unsupported");
- }
-
const MCSymbolRefExpr *A = getSymA();
if (!A)
return MCSymbolRefExpr::VK_None;
diff --git a/llvm/lib/MC/XCOFFObjectWriter.cpp b/llvm/lib/MC/XCOFFObjectWriter.cpp
index 04ea8fa3511a7..cc150649f1139 100644
--- a/llvm/lib/MC/XCOFFObjectWriter.cpp
+++ b/llvm/lib/MC/XCOFFObjectWriter.cpp
@@ -782,10 +782,9 @@ void XCOFFWriter::recordRelocation(MCAssembler &Asm, const MCFragment *Fragment,
"Expected containing csect to exist in map.");
SectionMap[RelocationSec]->Relocations.push_back(Reloc);
- if (!Target.getSymB())
+ const MCSymbol *const SymB = Target.getSubSym();
+ if (!SymB)
return;
-
- const MCSymbol *const SymB = &Target.getSymB()->getSymbol();
if (SymA == SymB)
report_fatal_error("relocation for opposite term is not yet supported");
diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.cpp
index a5891c1c6928d..c9f68c33dd2d2 100644
--- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.cpp
+++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.cpp
@@ -155,9 +155,6 @@ bool AArch64AuthMCExpr::evaluateAsRelocatableImpl(
if (!getSubExpr()->evaluateAsRelocatable(Res, Asm))
return false;
- if (Res.getSymB())
- report_fatal_error("Auth relocation can't reference two symbols");
-
Res = MCValue::get(Res.getSymA(), nullptr, Res.getConstant(), getKind());
return true;
}
diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp
index a79444b056766..5ede746af768c 100644
--- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp
+++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp
@@ -213,11 +213,9 @@ void AArch64MachObjectWriter::recordRelocation(
// FIXME: x86_64 sets the type to a branch reloc here. Should we do
// something similar?
}
- } else if (Target.getSubSym()) { // A - B + constant
+ } else if (auto *B = Target.getSubSym()) { // A - B + constant
const MCSymbol *A = &Target.getSymA()->getSymbol();
const MCSymbol *A_Base = Writer->getAtom(*A);
-
- const MCSymbol *B = &Target.getSymB()->getSymbol();
const MCSymbol *B_Base = Writer->getAtom(*B);
// Check for "_foo at got - .", which comes through here as:
More information about the llvm-commits
mailing list