aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2024-07-01 18:04:27 -0700
committerFangrui Song <i@maskray.me>2024-07-01 18:04:27 -0700
commitbbb50369a149d9a7d1f91efaaabf75c260a220c7 (patch)
treea54fff7d19db79f1ebdccf3cbaed05750ff6fe0a
parente3e0df391c7116b519499aab2eba8990c647cdf5 (diff)
downloadllvm-bbb50369a149d9a7d1f91efaaabf75c260a220c7.zip
llvm-bbb50369a149d9a7d1f91efaaabf75c260a220c7.tar.gz
llvm-bbb50369a149d9a7d1f91efaaabf75c260a220c7.tar.bz2
[MC] Use a stub ctor for MCAsmLayout
and replace MCAssembler::Layout with a bool. This mostly completes "[MC] Start merging MCAsmLayout into MCAssembler".
-rw-r--r--llvm/include/llvm/MC/MCAsmLayout.h11
-rw-r--r--llvm/include/llvm/MC/MCAssembler.h5
-rw-r--r--llvm/lib/MC/MCAssembler.cpp10
-rw-r--r--llvm/lib/MC/MCExpr.cpp4
-rw-r--r--llvm/lib/Target/AVR/MCTargetDesc/AVRMCExpr.cpp2
-rw-r--r--llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.cpp2
6 files changed, 12 insertions, 22 deletions
diff --git a/llvm/include/llvm/MC/MCAsmLayout.h b/llvm/include/llvm/MC/MCAsmLayout.h
index 765cc1e..33fae0a 100644
--- a/llvm/include/llvm/MC/MCAsmLayout.h
+++ b/llvm/include/llvm/MC/MCAsmLayout.h
@@ -9,21 +9,12 @@
#ifndef LLVM_MC_MCASMLAYOUT_H
#define LLVM_MC_MCASMLAYOUT_H
-#include "llvm/ADT/DenseMap.h"
-#include "llvm/ADT/SmallVector.h"
-
namespace llvm {
class MCAssembler;
-class MCSection;
class MCAsmLayout {
- MCAssembler &Assembler;
-
public:
- MCAsmLayout(MCAssembler &Assembler);
-
- /// Get the assembler object this is a layout for.
- MCAssembler &getAssembler() const { return Assembler; }
+ MCAsmLayout(MCAssembler &) {}
};
} // end namespace llvm
diff --git a/llvm/include/llvm/MC/MCAssembler.h b/llvm/include/llvm/MC/MCAssembler.h
index 1e476ae6..df5ad0e 100644
--- a/llvm/include/llvm/MC/MCAssembler.h
+++ b/llvm/include/llvm/MC/MCAssembler.h
@@ -116,7 +116,7 @@ private:
std::unique_ptr<MCCodeEmitter> Emitter;
std::unique_ptr<MCObjectWriter> Writer;
- MCAsmLayout *Layout = nullptr;
+ bool HasLayout = false;
bool RelaxAll = false;
bool SubsectionsViaSymbols = false;
bool IncrementalLinkerCompatible = false;
@@ -354,8 +354,7 @@ public:
IncrementalLinkerCompatible = Value;
}
- MCAsmLayout *getLayout() const { return Layout; }
- bool hasLayout() const { return Layout; }
+ bool hasLayout() const { return HasLayout; }
bool getRelaxAll() const { return RelaxAll; }
void setRelaxAll(bool Value) { RelaxAll = Value; }
diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp
index 0a6bb52..6866a58 100644
--- a/llvm/lib/MC/MCAssembler.cpp
+++ b/llvm/lib/MC/MCAssembler.cpp
@@ -381,8 +381,6 @@ uint64_t MCAssembler::computeFragmentSize(const MCFragment &F) const {
llvm_unreachable("invalid fragment kind");
}
-MCAsmLayout::MCAsmLayout(MCAssembler &Asm) : Assembler(Asm) {}
-
// Compute the amount of padding required before the fragment \p F to
// obey bundling restrictions, where \p FOffset is the fragment's offset in
// its section and \p FSize is the fragment's size.
@@ -541,13 +539,14 @@ bool MCAssembler::getSymbolOffset(const MCSymbol &S, uint64_t &Val) const {
}
uint64_t MCAssembler::getSymbolOffset(const MCSymbol &S) const {
+ assert(HasLayout);
uint64_t Val;
getSymbolOffsetImpl(*this, S, true, Val);
return Val;
}
const MCSymbol *MCAssembler::getBaseSymbol(const MCSymbol &Symbol) const {
- assert(Layout);
+ assert(HasLayout);
if (!Symbol.isVariable())
return &Symbol;
@@ -584,6 +583,7 @@ const MCSymbol *MCAssembler::getBaseSymbol(const MCSymbol &Symbol) const {
}
uint64_t MCAssembler::getSectionAddressSize(const MCSection &Sec) const {
+ assert(HasLayout);
// The size is the last fragment's end offset.
const MCFragment &F = *Sec.curFragList()->Tail;
return getFragmentOffset(F) + computeFragmentSize(F);
@@ -968,7 +968,7 @@ void MCAssembler::layout(MCAsmLayout &Layout) {
}
// Layout until everything fits.
- this->Layout = &Layout;
+ this->HasLayout = true;
while (layoutOnce()) {
if (getContext().hadError())
return;
@@ -1081,7 +1081,7 @@ void MCAssembler::Finish() {
// Write the object file.
stats::ObjectBytes += getWriter().writeObject(*this);
- this->Layout = nullptr;
+ HasLayout = false;
}
bool MCAssembler::fixupNeedsRelaxation(const MCFixup &Fixup,
diff --git a/llvm/lib/MC/MCExpr.cpp b/llvm/lib/MC/MCExpr.cpp
index 8279539..0a175ade 100644
--- a/llvm/lib/MC/MCExpr.cpp
+++ b/llvm/lib/MC/MCExpr.cpp
@@ -626,7 +626,7 @@ static void AttemptToFoldSymbolOffsetDifference(
// separated by a linker-relaxable instruction. If the section contains
// instructions and InSet is false (not expressions in directive like
// .size/.fill), disable the fast path.
- const MCAsmLayout *Layout = Asm->getLayout();
+ bool Layout = Asm->hasLayout();
if (Layout && (InSet || !SecA.hasInstructions() ||
!(Asm->getContext().getTargetTriple().isRISCV() ||
Asm->getContext().getTargetTriple().isLoongArch()))) {
@@ -817,7 +817,6 @@ bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
const SectionAddrMap *Addrs,
bool InSet) const {
++stats::MCExprEvaluate;
- MCAsmLayout *Layout = Asm ? Asm->getLayout() : nullptr;
switch (getKind()) {
case Target:
return cast<MCTargetExpr>(this)->evaluateAsRelocatableImpl(Res, Asm, Fixup);
@@ -830,6 +829,7 @@ bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
const MCSymbolRefExpr *SRE = cast<MCSymbolRefExpr>(this);
const MCSymbol &Sym = SRE->getSymbol();
const auto Kind = SRE->getKind();
+ bool Layout = Asm && Asm->hasLayout();
// Evaluate recursively if this is a variable.
if (Sym.isVariable() && (Kind == MCSymbolRefExpr::VK_None || Layout) &&
diff --git a/llvm/lib/Target/AVR/MCTargetDesc/AVRMCExpr.cpp b/llvm/lib/Target/AVR/MCTargetDesc/AVRMCExpr.cpp
index 87355561..5386df7 100644
--- a/llvm/lib/Target/AVR/MCTargetDesc/AVRMCExpr.cpp
+++ b/llvm/lib/Target/AVR/MCTargetDesc/AVRMCExpr.cpp
@@ -79,7 +79,7 @@ bool AVRMCExpr::evaluateAsRelocatableImpl(MCValue &Result,
if (Value.isAbsolute()) {
Result = MCValue::get(evaluateAsInt64(Value.getConstant()));
} else {
- if (!Asm || !Asm->getLayout())
+ if (!Asm || !Asm->hasLayout())
return false;
MCContext &Context = Asm->getContext();
diff --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.cpp b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.cpp
index 05fc733..cc1d981 100644
--- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.cpp
+++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.cpp
@@ -122,7 +122,7 @@ bool PPCMCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
Res = MCValue::get(Result);
} else {
- if (!Asm || !Asm->getLayout())
+ if (!Asm || !Asm->hasLayout())
return false;
MCContext &Context = Asm->getContext();