aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2024-06-27 19:12:35 -0700
committerFangrui Song <i@maskray.me>2024-06-27 19:12:35 -0700
commit7423bf78eb53d81ce0c7b3a38e39a56341ca2a89 (patch)
tree1acd27dcfa21b6e190a232c463c1baca0572cc94 /llvm/lib
parent2dff96d37a8419dab7a6ec3e1f8de917c7adb4ea (diff)
downloadllvm-7423bf78eb53d81ce0c7b3a38e39a56341ca2a89.zip
llvm-7423bf78eb53d81ce0c7b3a38e39a56341ca2a89.tar.gz
llvm-7423bf78eb53d81ce0c7b3a38e39a56341ca2a89.tar.bz2
[MC] Ensure subsections have a MCDataFragment
Similar to 21fac2d1d060b0f9b11a746718e58d4cd1ee97e5 for sections. This makes it feasible to cache the current fragment in MCStreamer.
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/MC/MCAssembler.cpp3
-rw-r--r--llvm/lib/MC/MCObjectStreamer.cpp18
-rw-r--r--llvm/lib/MC/MCSection.cpp11
3 files changed, 16 insertions, 16 deletions
diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp
index 205a9b2..52374017 100644
--- a/llvm/lib/MC/MCAssembler.cpp
+++ b/llvm/lib/MC/MCAssembler.cpp
@@ -870,8 +870,7 @@ void MCAssembler::layout(MCAsmLayout &Layout) {
MCDummyFragment Dummy;
MCFragment *Tail = &Dummy;
for (auto &[_, List] : Sec->Subsections) {
- if (!List.Head)
- continue;
+ assert(List.Head);
Tail->Next = List.Head;
Tail = List.Tail;
}
diff --git a/llvm/lib/MC/MCObjectStreamer.cpp b/llvm/lib/MC/MCObjectStreamer.cpp
index fec1cce..2357203 100644
--- a/llvm/lib/MC/MCObjectStreamer.cpp
+++ b/llvm/lib/MC/MCObjectStreamer.cpp
@@ -294,9 +294,21 @@ bool MCObjectStreamer::changeSectionImpl(MCSection *Section,
assert(Section && "Cannot switch to a null section!");
getContext().clearDwarfLocSeen();
- bool Created = getAssembler().registerSection(*Section);
- Section->switchSubsection(Subsection);
- return Created;
+ auto &Subsections = Section->Subsections;
+ size_t I = 0, E = Subsections.size();
+ while (I != E && Subsections[I].first < Subsection)
+ ++I;
+ // If the subsection number is not in the sorted Subsections list, create a
+ // new fragment list.
+ if (I == E || Subsections[I].first != Subsection) {
+ auto *F = getContext().allocFragment<MCDataFragment>();
+ F->setParent(Section);
+ Subsections.insert(Subsections.begin() + I,
+ {Subsection, MCSection::FragList{F, F}});
+ }
+ Section->CurFragList = &Subsections[I].second;
+
+ return getAssembler().registerSection(*Section);
}
void MCObjectStreamer::emitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
diff --git a/llvm/lib/MC/MCSection.cpp b/llvm/lib/MC/MCSection.cpp
index 1e15b68..8c2ee56 100644
--- a/llvm/lib/MC/MCSection.cpp
+++ b/llvm/lib/MC/MCSection.cpp
@@ -66,17 +66,6 @@ void MCSection::setBundleLockState(BundleLockStateType NewState) {
++BundleLockNestingDepth;
}
-void MCSection::switchSubsection(unsigned Subsection) {
- size_t I = 0, E = Subsections.size();
- while (I != E && Subsections[I].first < Subsection)
- ++I;
- // If the subsection number is not in the sorted Subsections list, create a
- // new fragment list.
- if (I == E || Subsections[I].first != Subsection)
- Subsections.insert(Subsections.begin() + I, {Subsection, FragList{}});
- CurFragList = &Subsections[I].second;
-}
-
StringRef MCSection::getVirtualSectionKind() const { return "virtual"; }
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)