Skip to content

Commit bbb5036

Browse files
committed
[MC] Use a stub ctor for MCAsmLayout
and replace MCAssembler::Layout with a bool. This mostly completes "[MC] Start merging MCAsmLayout into MCAssembler".
1 parent e3e0df3 commit bbb5036

File tree

6 files changed

+12
-22
lines changed

6 files changed

+12
-22
lines changed

llvm/include/llvm/MC/MCAsmLayout.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,12 @@
99
#ifndef LLVM_MC_MCASMLAYOUT_H
1010
#define LLVM_MC_MCASMLAYOUT_H
1111

12-
#include "llvm/ADT/DenseMap.h"
13-
#include "llvm/ADT/SmallVector.h"
14-
1512
namespace llvm {
1613
class MCAssembler;
17-
class MCSection;
1814

1915
class MCAsmLayout {
20-
MCAssembler &Assembler;
21-
2216
public:
23-
MCAsmLayout(MCAssembler &Assembler);
24-
25-
/// Get the assembler object this is a layout for.
26-
MCAssembler &getAssembler() const { return Assembler; }
17+
MCAsmLayout(MCAssembler &) {}
2718
};
2819

2920
} // end namespace llvm

llvm/include/llvm/MC/MCAssembler.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class MCAssembler {
116116
std::unique_ptr<MCCodeEmitter> Emitter;
117117
std::unique_ptr<MCObjectWriter> Writer;
118118

119-
MCAsmLayout *Layout = nullptr;
119+
bool HasLayout = false;
120120
bool RelaxAll = false;
121121
bool SubsectionsViaSymbols = false;
122122
bool IncrementalLinkerCompatible = false;
@@ -354,8 +354,7 @@ class MCAssembler {
354354
IncrementalLinkerCompatible = Value;
355355
}
356356

357-
MCAsmLayout *getLayout() const { return Layout; }
358-
bool hasLayout() const { return Layout; }
357+
bool hasLayout() const { return HasLayout; }
359358
bool getRelaxAll() const { return RelaxAll; }
360359
void setRelaxAll(bool Value) { RelaxAll = Value; }
361360

llvm/lib/MC/MCAssembler.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,6 @@ uint64_t MCAssembler::computeFragmentSize(const MCFragment &F) const {
381381
llvm_unreachable("invalid fragment kind");
382382
}
383383

384-
MCAsmLayout::MCAsmLayout(MCAssembler &Asm) : Assembler(Asm) {}
385-
386384
// Compute the amount of padding required before the fragment \p F to
387385
// obey bundling restrictions, where \p FOffset is the fragment's offset in
388386
// its section and \p FSize is the fragment's size.
@@ -541,13 +539,14 @@ bool MCAssembler::getSymbolOffset(const MCSymbol &S, uint64_t &Val) const {
541539
}
542540

543541
uint64_t MCAssembler::getSymbolOffset(const MCSymbol &S) const {
542+
assert(HasLayout);
544543
uint64_t Val;
545544
getSymbolOffsetImpl(*this, S, true, Val);
546545
return Val;
547546
}
548547

549548
const MCSymbol *MCAssembler::getBaseSymbol(const MCSymbol &Symbol) const {
550-
assert(Layout);
549+
assert(HasLayout);
551550
if (!Symbol.isVariable())
552551
return &Symbol;
553552

@@ -584,6 +583,7 @@ const MCSymbol *MCAssembler::getBaseSymbol(const MCSymbol &Symbol) const {
584583
}
585584

586585
uint64_t MCAssembler::getSectionAddressSize(const MCSection &Sec) const {
586+
assert(HasLayout);
587587
// The size is the last fragment's end offset.
588588
const MCFragment &F = *Sec.curFragList()->Tail;
589589
return getFragmentOffset(F) + computeFragmentSize(F);
@@ -968,7 +968,7 @@ void MCAssembler::layout(MCAsmLayout &Layout) {
968968
}
969969

970970
// Layout until everything fits.
971-
this->Layout = &Layout;
971+
this->HasLayout = true;
972972
while (layoutOnce()) {
973973
if (getContext().hadError())
974974
return;
@@ -1081,7 +1081,7 @@ void MCAssembler::Finish() {
10811081
// Write the object file.
10821082
stats::ObjectBytes += getWriter().writeObject(*this);
10831083

1084-
this->Layout = nullptr;
1084+
HasLayout = false;
10851085
}
10861086

10871087
bool MCAssembler::fixupNeedsRelaxation(const MCFixup &Fixup,

llvm/lib/MC/MCExpr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ static void AttemptToFoldSymbolOffsetDifference(
626626
// separated by a linker-relaxable instruction. If the section contains
627627
// instructions and InSet is false (not expressions in directive like
628628
// .size/.fill), disable the fast path.
629-
const MCAsmLayout *Layout = Asm->getLayout();
629+
bool Layout = Asm->hasLayout();
630630
if (Layout && (InSet || !SecA.hasInstructions() ||
631631
!(Asm->getContext().getTargetTriple().isRISCV() ||
632632
Asm->getContext().getTargetTriple().isLoongArch()))) {
@@ -817,7 +817,6 @@ bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
817817
const SectionAddrMap *Addrs,
818818
bool InSet) const {
819819
++stats::MCExprEvaluate;
820-
MCAsmLayout *Layout = Asm ? Asm->getLayout() : nullptr;
821820
switch (getKind()) {
822821
case Target:
823822
return cast<MCTargetExpr>(this)->evaluateAsRelocatableImpl(Res, Asm, Fixup);
@@ -830,6 +829,7 @@ bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
830829
const MCSymbolRefExpr *SRE = cast<MCSymbolRefExpr>(this);
831830
const MCSymbol &Sym = SRE->getSymbol();
832831
const auto Kind = SRE->getKind();
832+
bool Layout = Asm && Asm->hasLayout();
833833

834834
// Evaluate recursively if this is a variable.
835835
if (Sym.isVariable() && (Kind == MCSymbolRefExpr::VK_None || Layout) &&

llvm/lib/Target/AVR/MCTargetDesc/AVRMCExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ bool AVRMCExpr::evaluateAsRelocatableImpl(MCValue &Result,
7979
if (Value.isAbsolute()) {
8080
Result = MCValue::get(evaluateAsInt64(Value.getConstant()));
8181
} else {
82-
if (!Asm || !Asm->getLayout())
82+
if (!Asm || !Asm->hasLayout())
8383
return false;
8484

8585
MCContext &Context = Asm->getContext();

llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ bool PPCMCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
122122

123123
Res = MCValue::get(Result);
124124
} else {
125-
if (!Asm || !Asm->getLayout())
125+
if (!Asm || !Asm->hasLayout())
126126
return false;
127127

128128
MCContext &Context = Asm->getContext();

0 commit comments

Comments
 (0)