Skip to content

Commit f80a407

Browse files
committed
Revert "[MC] Use a stub ctor for MCAsmLayout"
This reverts commit bbb5036. This breaks BOLT.
1 parent ac0b48a commit f80a407

File tree

6 files changed

+22
-12
lines changed

6 files changed

+22
-12
lines changed

llvm/include/llvm/MC/MCAsmLayout.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,21 @@
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+
1215
namespace llvm {
1316
class MCAssembler;
17+
class MCSection;
1418

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

2029
} // end namespace llvm

llvm/include/llvm/MC/MCAssembler.h

Lines changed: 3 additions & 2 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-
bool HasLayout = false;
119+
MCAsmLayout *Layout = nullptr;
120120
bool RelaxAll = false;
121121
bool SubsectionsViaSymbols = false;
122122
bool IncrementalLinkerCompatible = false;
@@ -354,7 +354,8 @@ class MCAssembler {
354354
IncrementalLinkerCompatible = Value;
355355
}
356356

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

llvm/lib/MC/MCAssembler.cpp

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

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

541543
uint64_t MCAssembler::getSymbolOffset(const MCSymbol &S) const {
542-
assert(HasLayout);
543544
uint64_t Val;
544545
getSymbolOffsetImpl(*this, S, true, Val);
545546
return Val;
546547
}
547548

548549
const MCSymbol *MCAssembler::getBaseSymbol(const MCSymbol &Symbol) const {
549-
assert(HasLayout);
550+
assert(Layout);
550551
if (!Symbol.isVariable())
551552
return &Symbol;
552553

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

585586
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->HasLayout = true;
971+
this->Layout = &Layout;
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-
HasLayout = false;
1084+
this->Layout = nullptr;
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-
bool Layout = Asm->hasLayout();
629+
const MCAsmLayout *Layout = Asm->getLayout();
630630
if (Layout && (InSet || !SecA.hasInstructions() ||
631631
!(Asm->getContext().getTargetTriple().isRISCV() ||
632632
Asm->getContext().getTargetTriple().isLoongArch()))) {
@@ -817,6 +817,7 @@ 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;
820821
switch (getKind()) {
821822
case Target:
822823
return cast<MCTargetExpr>(this)->evaluateAsRelocatableImpl(Res, Asm, Fixup);
@@ -829,7 +830,6 @@ bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
829830
const MCSymbolRefExpr *SRE = cast<MCSymbolRefExpr>(this);
830831
const MCSymbol &Sym = SRE->getSymbol();
831832
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->hasLayout())
82+
if (!Asm || !Asm->getLayout())
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->hasLayout())
125+
if (!Asm || !Asm->getLayout())
126126
return false;
127127

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

0 commit comments

Comments
 (0)