[llvm] bbb5036 - [MC] Use a stub ctor for MCAsmLayout
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 1 18:04:33 PDT 2024
Author: Fangrui Song
Date: 2024-07-01T18:04:27-07:00
New Revision: bbb50369a149d9a7d1f91efaaabf75c260a220c7
URL: https://github.com/llvm/llvm-project/commit/bbb50369a149d9a7d1f91efaaabf75c260a220c7
DIFF: https://github.com/llvm/llvm-project/commit/bbb50369a149d9a7d1f91efaaabf75c260a220c7.diff
LOG: [MC] Use a stub ctor for MCAsmLayout
and replace MCAssembler::Layout with a bool.
This mostly completes "[MC] Start merging MCAsmLayout into MCAssembler".
Added:
Modified:
llvm/include/llvm/MC/MCAsmLayout.h
llvm/include/llvm/MC/MCAssembler.h
llvm/lib/MC/MCAssembler.cpp
llvm/lib/MC/MCExpr.cpp
llvm/lib/Target/AVR/MCTargetDesc/AVRMCExpr.cpp
llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCAsmLayout.h b/llvm/include/llvm/MC/MCAsmLayout.h
index 765cc1ebb7c79..33fae0a0f9766 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 1e476ae61dec6..df5ad0e7bdf4b 100644
--- a/llvm/include/llvm/MC/MCAssembler.h
+++ b/llvm/include/llvm/MC/MCAssembler.h
@@ -116,7 +116,7 @@ class MCAssembler {
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 @@ class MCAssembler {
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 0a6bb52a3b8f4..6866a58ecde59 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 82795399900c2..0a175ade68d78 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 87355561c1cb5..5386df7f4afcd 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 05fc733825113..cc1d98105b0cb 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();
More information about the llvm-commits
mailing list