[llvm] b90a926 - MCExpr: Remove unused SectionAddrMap workaround
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 6 13:15:39 PDT 2025
Author: Fangrui Song
Date: 2025-04-06T13:15:33-07:00
New Revision: b90a92687f399df5afe3e1a2493b0d9c6295ac8c
URL: https://github.com/llvm/llvm-project/commit/b90a92687f399df5afe3e1a2493b0d9c6295ac8c
DIFF: https://github.com/llvm/llvm-project/commit/b90a92687f399df5afe3e1a2493b0d9c6295ac8c.diff
LOG: MCExpr: Remove unused SectionAddrMap workaround
Mach-O's ARM and X86 writers use MCExpr's `SectionAddrMap *Addrs`
argument to compute label differences, which was a bit of a hack.
The hack has been cleaned up by commit
1b7759de8e6979dda2d949b1ba1c742922e5c366.
Added:
Modified:
llvm/include/llvm/MC/MCExpr.h
llvm/include/llvm/MC/MCMachObjectWriter.h
llvm/lib/MC/MCExpr.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCExpr.h b/llvm/include/llvm/MC/MCExpr.h
index 8516f45e07fea..3d9113e92485d 100644
--- a/llvm/include/llvm/MC/MCExpr.h
+++ b/llvm/include/llvm/MC/MCExpr.h
@@ -28,8 +28,6 @@ class raw_ostream;
class StringRef;
class MCSymbolRefExpr;
-using SectionAddrMap = DenseMap<const MCSection *, uint64_t>;
-
/// Base class for the full range of assembler expressions which are
/// needed for parsing.
class MCExpr {
@@ -54,7 +52,7 @@ class MCExpr {
SMLoc Loc;
bool evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm,
- const SectionAddrMap *Addrs, bool InSet) const;
+ bool InSet) const;
protected:
explicit MCExpr(ExprKind Kind, SMLoc Loc, unsigned SubclassData = 0)
@@ -64,7 +62,7 @@ class MCExpr {
}
bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
- const SectionAddrMap *Addrs, bool InSet) const;
+ bool InSet) const;
unsigned getSubclassData() const { return SubclassData; }
@@ -98,8 +96,6 @@ class MCExpr {
///
/// \param Res - The absolute value, if evaluation succeeds.
/// \return - True on success.
- bool evaluateAsAbsolute(int64_t &Res, const MCAssembler &Asm,
- const SectionAddrMap &Addrs) const;
bool evaluateAsAbsolute(int64_t &Res) const;
bool evaluateAsAbsolute(int64_t &Res, const MCAssembler &Asm) const;
bool evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm) const;
@@ -132,9 +128,8 @@ class MCExpr {
/// @}
- static bool evaluateSymbolicAdd(const MCAssembler *, const SectionAddrMap *,
- bool, const MCValue &, const MCValue &,
- MCValue &);
+ static bool evaluateSymbolicAdd(const MCAssembler *, bool, const MCValue &,
+ const MCValue &, MCValue &);
};
inline raw_ostream &operator<<(raw_ostream &OS, const MCExpr &E) {
diff --git a/llvm/include/llvm/MC/MCMachObjectWriter.h b/llvm/include/llvm/MC/MCMachObjectWriter.h
index 77652c7ff53a3..77f305dad27f8 100644
--- a/llvm/include/llvm/MC/MCMachObjectWriter.h
+++ b/llvm/include/llvm/MC/MCMachObjectWriter.h
@@ -141,7 +141,7 @@ class MachObjectWriter final : public MCObjectWriter {
std::vector<DataRegionData> DataRegions;
- SectionAddrMap SectionAddress;
+ DenseMap<const MCSection *, uint64_t> SectionAddress;
// List of sections in layout order. Virtual sections are after non-virtual
// sections.
@@ -203,7 +203,6 @@ class MachObjectWriter final : public MCObjectWriter {
const llvm::SmallVectorImpl<MCSection *> &getSectionOrder() const {
return SectionOrder;
}
- SectionAddrMap &getSectionAddressMap() { return SectionAddress; }
MCLOHContainer &getLOHContainer() { return LOHContainer; }
uint64_t getSectionAddress(const MCSection *Sec) const {
diff --git a/llvm/lib/MC/MCExpr.cpp b/llvm/lib/MC/MCExpr.cpp
index 5293fa58c0381..9fbe395e294b8 100644
--- a/llvm/lib/MC/MCExpr.cpp
+++ b/llvm/lib/MC/MCExpr.cpp
@@ -254,30 +254,23 @@ void MCTargetExpr::anchor() {}
/* *** */
bool MCExpr::evaluateAsAbsolute(int64_t &Res) const {
- return evaluateAsAbsolute(Res, nullptr, nullptr, false);
-}
-
-bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler &Asm,
- const SectionAddrMap &Addrs) const {
- // Setting InSet causes us to absolutize
diff erences across sections and that
- // is what the MachO writer uses Addrs for.
- return evaluateAsAbsolute(Res, &Asm, &Addrs, true);
+ return evaluateAsAbsolute(Res, nullptr, false);
}
bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler &Asm) const {
- return evaluateAsAbsolute(Res, &Asm, nullptr, false);
+ return evaluateAsAbsolute(Res, &Asm, false);
}
bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm) const {
- return evaluateAsAbsolute(Res, Asm, nullptr, false);
+ return evaluateAsAbsolute(Res, Asm, false);
}
bool MCExpr::evaluateKnownAbsolute(int64_t &Res, const MCAssembler &Asm) const {
- return evaluateAsAbsolute(Res, &Asm, nullptr, true);
+ return evaluateAsAbsolute(Res, &Asm, true);
}
bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm,
- const SectionAddrMap *Addrs, bool InSet) const {
+ bool InSet) const {
MCValue Value;
// Fast path constants.
@@ -286,7 +279,7 @@ bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm,
return true;
}
- bool IsRelocatable = evaluateAsRelocatableImpl(Value, Asm, Addrs, InSet);
+ bool IsRelocatable = evaluateAsRelocatableImpl(Value, Asm, InSet);
Res = Value.getConstant();
// Value with RefKind (e.g. %hi(0xdeadbeef) in MIPS) is not considered
// absolute (the value is unknown at parse time), even if it might be resolved
@@ -296,7 +289,6 @@ bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm,
/// Helper method for \see EvaluateSymbolAdd().
static void attemptToFoldSymbolOffsetDifference(const MCAssembler *Asm,
- const SectionAddrMap *Addrs,
bool InSet, const MCSymbol *&A,
const MCSymbol *&B,
int64_t &Addend) {
@@ -324,7 +316,7 @@ static void attemptToFoldSymbolOffsetDifference(const MCAssembler *Asm,
const MCFragment *FB = SB.getFragment();
const MCSection &SecA = *FA->getParent();
const MCSection &SecB = *FB->getParent();
- if ((&SecA != &SecB) && !Addrs)
+ if (&SecA != &SecB)
return;
// When layout is available, we can generally compute the
diff erence using the
@@ -345,9 +337,6 @@ static void attemptToFoldSymbolOffsetDifference(const MCAssembler *Asm,
// Eagerly evaluate when layout is finalized.
Addend += Asm->getSymbolOffset(SA) - Asm->getSymbolOffset(SB);
- if (Addrs && (&SecA != &SecB))
- Addend += (Addrs->lookup(&SecA) - Addrs->lookup(&SecB));
-
FinalizeFolding();
} else {
// When layout is not finalized, our ability to resolve
diff erences between
@@ -434,8 +423,7 @@ static void attemptToFoldSymbolOffsetDifference(const MCAssembler *Asm,
// NOTE: This function can be used before layout is done (see the object
// streamer for example) and having the Asm argument lets us avoid relaxations
// early.
-bool MCExpr::evaluateSymbolicAdd(const MCAssembler *Asm,
- const SectionAddrMap *Addrs, bool InSet,
+bool MCExpr::evaluateSymbolicAdd(const MCAssembler *Asm, bool InSet,
const MCValue &LHS, const MCValue &RHS,
MCValue &Res) {
const MCSymbol *LHS_A = LHS.getAddSym();
@@ -456,12 +444,10 @@ bool MCExpr::evaluateSymbolicAdd(const MCAssembler *Asm,
// Result = (LHS_A - LHS_B + LHS_Cst) + (RHS_A - RHS_B + RHS_Cst).
// might bring more opportunities.
if (LHS_A && RHS_B) {
- attemptToFoldSymbolOffsetDifference(Asm, Addrs, InSet, LHS_A, RHS_B,
- Result_Cst);
+ attemptToFoldSymbolOffsetDifference(Asm, InSet, LHS_A, RHS_B, Result_Cst);
}
if (RHS_A && LHS_B) {
- attemptToFoldSymbolOffsetDifference(Asm, Addrs, InSet, RHS_A, LHS_B,
- Result_Cst);
+ attemptToFoldSymbolOffsetDifference(Asm, InSet, RHS_A, LHS_B, Result_Cst);
}
}
@@ -481,10 +467,10 @@ bool MCExpr::evaluateSymbolicAdd(const MCAssembler *Asm,
}
bool MCExpr::evaluateAsRelocatable(MCValue &Res, const MCAssembler *Asm) const {
- return evaluateAsRelocatableImpl(Res, Asm, nullptr, false);
+ return evaluateAsRelocatableImpl(Res, Asm, false);
}
bool MCExpr::evaluateAsValue(MCValue &Res, const MCAssembler &Asm) const {
- return evaluateAsRelocatableImpl(Res, &Asm, nullptr, true);
+ return evaluateAsRelocatableImpl(Res, &Asm, true);
}
static bool canExpand(const MCSymbol &Sym, bool InSet) {
if (Sym.isWeakExternal())
@@ -503,7 +489,6 @@ static bool canExpand(const MCSymbol &Sym, bool InSet) {
}
bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
- const SectionAddrMap *Addrs,
bool InSet) const {
++stats::MCExprEvaluate;
switch (getKind()) {
@@ -523,7 +508,7 @@ bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
if (Sym.isVariable() && (Kind == MCSymbolRefExpr::VK_None || Layout) &&
canExpand(Sym, InSet)) {
bool IsMachO = SRE->hasSubsectionsViaSymbols();
- if (Sym.getVariableValue()->evaluateAsRelocatableImpl(Res, Asm, Addrs,
+ if (Sym.getVariableValue()->evaluateAsRelocatableImpl(Res, Asm,
InSet || IsMachO)) {
if (Kind != MCSymbolRefExpr::VK_None) {
if (Res.isAbsolute()) {
@@ -566,7 +551,7 @@ bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
const MCUnaryExpr *AUE = cast<MCUnaryExpr>(this);
MCValue Value;
- if (!AUE->getSubExpr()->evaluateAsRelocatableImpl(Value, Asm, Addrs, InSet))
+ if (!AUE->getSubExpr()->evaluateAsRelocatableImpl(Value, Asm, InSet))
return false;
switch (AUE->getOpcode()) {
case MCUnaryExpr::LNot:
@@ -600,10 +585,8 @@ bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
const MCBinaryExpr *ABE = cast<MCBinaryExpr>(this);
MCValue LHSValue, RHSValue;
- if (!ABE->getLHS()->evaluateAsRelocatableImpl(LHSValue, Asm, Addrs,
- InSet) ||
- !ABE->getRHS()->evaluateAsRelocatableImpl(RHSValue, Asm, Addrs,
- InSet)) {
+ if (!ABE->getLHS()->evaluateAsRelocatableImpl(LHSValue, Asm, InSet) ||
+ !ABE->getRHS()->evaluateAsRelocatableImpl(RHSValue, Asm, InSet)) {
// Check if both are Target Expressions, see if we can compare them.
if (const MCTargetExpr *L = dyn_cast<MCTargetExpr>(ABE->getLHS())) {
if (const MCTargetExpr *R = dyn_cast<MCTargetExpr>(ABE->getRHS())) {
@@ -650,7 +633,7 @@ bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
return false;
if (RHSValue.SymB && RHSValue.Specifier)
return false;
- return evaluateSymbolicAdd(Asm, Addrs, InSet, LHSValue, RHSValue, Res);
+ return evaluateSymbolicAdd(Asm, InSet, LHSValue, RHSValue, Res);
}
}
More information about the llvm-commits
mailing list