Skip to content

Commit 7423bf7

Browse files
committed
[MC] Ensure subsections have a MCDataFragment
Similar to 21fac2d for sections. This makes it feasible to cache the current fragment in MCStreamer.
1 parent 2dff96d commit 7423bf7

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

llvm/include/llvm/MC/MCSection.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class MCAsmInfo;
2626
class MCAssembler;
2727
class MCContext;
2828
class MCExpr;
29+
class MCObjectStreamer;
2930
class MCSymbol;
3031
class raw_ostream;
3132
class Triple;
@@ -35,6 +36,7 @@ class Triple;
3536
class MCSection {
3637
public:
3738
friend MCAssembler;
39+
friend MCObjectStreamer;
3840
static constexpr unsigned NonUniqueID = ~0U;
3941

4042
enum SectionVariant {
@@ -208,8 +210,6 @@ class MCSection {
208210
CurFragList->Tail = &F;
209211
}
210212

211-
void switchSubsection(unsigned Subsection);
212-
213213
void dump() const;
214214

215215
virtual void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,

llvm/lib/MC/MCAssembler.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -870,8 +870,7 @@ void MCAssembler::layout(MCAsmLayout &Layout) {
870870
MCDummyFragment Dummy;
871871
MCFragment *Tail = &Dummy;
872872
for (auto &[_, List] : Sec->Subsections) {
873-
if (!List.Head)
874-
continue;
873+
assert(List.Head);
875874
Tail->Next = List.Head;
876875
Tail = List.Tail;
877876
}

llvm/lib/MC/MCObjectStreamer.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,21 @@ bool MCObjectStreamer::changeSectionImpl(MCSection *Section,
294294
assert(Section && "Cannot switch to a null section!");
295295
getContext().clearDwarfLocSeen();
296296

297-
bool Created = getAssembler().registerSection(*Section);
298-
Section->switchSubsection(Subsection);
299-
return Created;
297+
auto &Subsections = Section->Subsections;
298+
size_t I = 0, E = Subsections.size();
299+
while (I != E && Subsections[I].first < Subsection)
300+
++I;
301+
// If the subsection number is not in the sorted Subsections list, create a
302+
// new fragment list.
303+
if (I == E || Subsections[I].first != Subsection) {
304+
auto *F = getContext().allocFragment<MCDataFragment>();
305+
F->setParent(Section);
306+
Subsections.insert(Subsections.begin() + I,
307+
{Subsection, MCSection::FragList{F, F}});
308+
}
309+
Section->CurFragList = &Subsections[I].second;
310+
311+
return getAssembler().registerSection(*Section);
300312
}
301313

302314
void MCObjectStreamer::emitAssignment(MCSymbol *Symbol, const MCExpr *Value) {

llvm/lib/MC/MCSection.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,6 @@ void MCSection::setBundleLockState(BundleLockStateType NewState) {
6666
++BundleLockNestingDepth;
6767
}
6868

69-
void MCSection::switchSubsection(unsigned Subsection) {
70-
size_t I = 0, E = Subsections.size();
71-
while (I != E && Subsections[I].first < Subsection)
72-
++I;
73-
// If the subsection number is not in the sorted Subsections list, create a
74-
// new fragment list.
75-
if (I == E || Subsections[I].first != Subsection)
76-
Subsections.insert(Subsections.begin() + I, {Subsection, FragList{}});
77-
CurFragList = &Subsections[I].second;
78-
}
79-
8069
StringRef MCSection::getVirtualSectionKind() const { return "virtual"; }
8170

8271
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)

0 commit comments

Comments
 (0)