[llvm] f3e6473 - MCValue: reduce getSymB uses
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 4 22:17:26 PDT 2025
Author: Fangrui Song
Date: 2025-04-04T22:17:22-07:00
New Revision: f3e6473df46fd920e09e06e57a5549eb8e3a8bd3
URL: https://github.com/llvm/llvm-project/commit/f3e6473df46fd920e09e06e57a5549eb8e3a8bd3
DIFF: https://github.com/llvm/llvm-project/commit/f3e6473df46fd920e09e06e57a5549eb8e3a8bd3.diff
LOG: MCValue: reduce getSymB uses
The MCValue::SymB MCSymbolRefExpr member might be replaced with a
MCSymbol in the future. Reduce direct access.
Added:
Modified:
llvm/lib/MC/MCAssembler.cpp
llvm/lib/MC/MCValue.cpp
llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
Removed:
################################################################################
diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp
index 835fa8af4cf8f..2c9cd0e5b626e 100644
--- a/llvm/lib/MC/MCAssembler.cpp
+++ b/llvm/lib/MC/MCAssembler.cpp
@@ -201,11 +201,9 @@ bool MCAssembler::evaluateFixup(const MCFixup &Fixup, const MCFragment *DF,
if (Sym.isDefined())
Value += getSymbolOffset(Sym);
}
- if (const MCSymbolRefExpr *B = Target.getSymB()) {
- const MCSymbol &Sym = B->getSymbol();
- if (Sym.isDefined())
- Value -= getSymbolOffset(Sym);
- }
+ if (const MCSymbol *Sub = Target.getSubSym())
+ if (Sub->isDefined())
+ Value -= getSymbolOffset(*Sub);
bool ShouldAlignPC = FixupFlags & MCFixupKindInfo::FKF_IsAlignedDownTo32Bits;
assert((ShouldAlignPC ? IsPCRel : true) &&
diff --git a/llvm/lib/MC/MCValue.cpp b/llvm/lib/MC/MCValue.cpp
index a90ba4eaa5f7c..8b2edc9ac57ec 100644
--- a/llvm/lib/MC/MCValue.cpp
+++ b/llvm/lib/MC/MCValue.cpp
@@ -9,6 +9,7 @@
#include "llvm/MC/MCValue.h"
#include "llvm/Config/llvm-config.h"
#include "llvm/MC/MCExpr.h"
+#include "llvm/MC/MCSymbol.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
@@ -28,9 +29,9 @@ void MCValue::print(raw_ostream &OS) const {
OS << *getSymA();
- if (getSymB()) {
+ if (auto *B = getSubSym()) {
OS << " - ";
- OS << *getSymB();
+ B->print(OS, nullptr);
}
if (getConstant())
diff --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
index c83a18746e060..f22b208f8dffc 100644
--- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
+++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
@@ -498,7 +498,8 @@ bool LoongArchAsmBackend::handleAddSubRelocations(const MCAssembler &Asm,
llvm_unreachable("unsupported fixup size");
}
MCValue A = MCValue::get(Target.getSymA(), nullptr, Target.getConstant());
- MCValue B = MCValue::get(Target.getSymB());
+ MCValue B = MCValue::get(
+ MCSymbolRefExpr::create(Target.getSubSym(), Asm.getContext()));
auto FA = MCFixup::create(Fixup.getOffset(), nullptr, std::get<0>(FK));
auto FB = MCFixup::create(Fixup.getOffset(), nullptr, std::get<1>(FK));
auto &Assembler = const_cast<MCAssembler &>(Asm);
diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
index 6c246176a05e8..a8922c3f9f2e8 100644
--- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -2806,7 +2806,7 @@ bool RISCVAsmParser::isSymbolDiff(const MCExpr *Expr) {
MCValue Res;
if (Expr->evaluateAsRelocatable(Res, nullptr)) {
return Res.getRefKind() == RISCVMCExpr::VK_None && Res.getSymA() &&
- Res.getSymB();
+ Res.getSubSym();
}
return false;
}
diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
index ac0f7421664c5..f208618814142 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
@@ -657,7 +657,8 @@ bool RISCVAsmBackend::handleAddSubRelocations(const MCAssembler &Asm,
llvm_unreachable("unsupported fixup size");
}
MCValue A = MCValue::get(Target.getSymA(), nullptr, Target.getConstant());
- MCValue B = MCValue::get(Target.getSymB());
+ MCValue B = MCValue::get(
+ MCSymbolRefExpr::create(Target.getSubSym(), Asm.getContext()));
auto FA = MCFixup::create(
Fixup.getOffset(), nullptr,
static_cast<MCFixupKind>(FirstLiteralRelocationKind + TA));
More information about the llvm-commits
mailing list