summaryrefslogtreecommitdiff
path: root/llvm/lib/MC/MCSection.cpp
diff options
context:
space:
mode:
authorKoakuma <koachan@protonmail.com>2024-07-08 19:19:54 +0700
committerKoakuma <koachan@protonmail.com>2024-07-08 19:19:54 +0700
commit5c4fdc2fd5898ebd9e89999a4f4b8aa289ca637f (patch)
treef3b92a07f3dfc6e70f36d1000605f36a3c15af46 /llvm/lib/MC/MCSection.cpp
parentdbda8e2f2cd8764e0badd983915d62a2c3377f4d (diff)
parente9b8cd0c806db00f0981fb36717077c941426302 (diff)
Created using spr 1.3.5 [skip ci]
Diffstat (limited to 'llvm/lib/MC/MCSection.cpp')
-rw-r--r--llvm/lib/MC/MCSection.cpp102
1 files changed, 30 insertions, 72 deletions
diff --git a/llvm/lib/MC/MCSection.cpp b/llvm/lib/MC/MCSection.cpp
index ea3baf96b38e..c209c9715f47 100644
--- a/llvm/lib/MC/MCSection.cpp
+++ b/llvm/lib/MC/MCSection.cpp
@@ -20,11 +20,15 @@
using namespace llvm;
-MCSection::MCSection(SectionVariant V, StringRef Name, SectionKind K,
+MCSection::MCSection(SectionVariant V, StringRef Name, bool IsText,
MCSymbol *Begin)
: Begin(Begin), BundleGroupBeforeFirstInst(false), HasInstructions(false),
- IsRegistered(false), DummyFragment(this), Name(Name), Variant(V),
- Kind(K) {}
+ HasLayout(false), IsRegistered(false), IsText(IsText), Name(Name),
+ Variant(V) {
+ DummyFragment.setParent(this);
+ // The initial subsection number is 0. Create a fragment list.
+ CurFragList = &Subsections.emplace_back(0u, FragList{}).second;
+}
MCSymbol *MCSection::getEndSymbol(MCContext &Ctx) {
if (!End)
@@ -34,7 +38,14 @@ MCSymbol *MCSection::getEndSymbol(MCContext &Ctx) {
bool MCSection::hasEnded() const { return End && End->isInSection(); }
-MCSection::~MCSection() = default;
+MCSection::~MCSection() {
+ for (auto &[_, Chain] : Subsections) {
+ for (MCFragment *X = Chain.Head, *Y; X; X = Y) {
+ Y = X->Next;
+ X->destroy();
+ }
+ }
+}
void MCSection::setBundleLockState(BundleLockStateType NewState) {
if (NewState == NotBundleLocked) {
@@ -55,85 +66,32 @@ void MCSection::setBundleLockState(BundleLockStateType NewState) {
++BundleLockNestingDepth;
}
-MCSection::iterator
-MCSection::getSubsectionInsertionPoint(unsigned Subsection) {
- if (Subsection == 0 && SubsectionFragmentMap.empty())
- return end();
-
- SmallVectorImpl<std::pair<unsigned, MCFragment *>>::iterator MI = lower_bound(
- SubsectionFragmentMap, std::make_pair(Subsection, (MCFragment *)nullptr));
- bool ExactMatch = false;
- if (MI != SubsectionFragmentMap.end()) {
- ExactMatch = MI->first == Subsection;
- if (ExactMatch)
- ++MI;
- }
- iterator IP;
- if (MI == SubsectionFragmentMap.end())
- IP = end();
- else
- IP = MI->second->getIterator();
- if (!ExactMatch && Subsection != 0) {
- // The GNU as documentation claims that subsections have an alignment of 4,
- // although this appears not to be the case.
- MCFragment *F = new MCDataFragment();
- SubsectionFragmentMap.insert(MI, std::make_pair(Subsection, F));
- getFragmentList().insert(IP, F);
- F->setParent(this);
- F->setSubsectionNumber(Subsection);
- }
-
- return IP;
+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"; }
-void MCSection::addPendingLabel(MCSymbol *label, unsigned Subsection) {
- PendingLabels.push_back(PendingLabel(label, Subsection));
-}
-
-void MCSection::flushPendingLabels(MCFragment *F, uint64_t FOffset,
- unsigned Subsection) {
- // Set the fragment and fragment offset for all pending symbols in the
- // specified Subsection, and remove those symbols from the pending list.
- for (auto It = PendingLabels.begin(); It != PendingLabels.end(); ++It) {
- PendingLabel& Label = *It;
- if (Label.Subsection == Subsection) {
- Label.Sym->setFragment(F);
- Label.Sym->setOffset(FOffset);
- PendingLabels.erase(It--);
- }
- }
-}
-
-void MCSection::flushPendingLabels() {
- // Make sure all remaining pending labels point to data fragments, by
- // creating new empty data fragments for each Subsection with labels pending.
- while (!PendingLabels.empty()) {
- PendingLabel& Label = PendingLabels[0];
- iterator CurInsertionPoint =
- this->getSubsectionInsertionPoint(Label.Subsection);
- const MCSymbol *Atom = nullptr;
- if (CurInsertionPoint != begin())
- Atom = std::prev(CurInsertionPoint)->getAtom();
- MCFragment *F = new MCDataFragment();
- getFragmentList().insert(CurInsertionPoint, F);
- F->setParent(this);
- F->setAtom(Atom);
- flushPendingLabels(F, 0, Label.Subsection);
- }
-}
-
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void MCSection::dump() const {
raw_ostream &OS = errs();
OS << "<MCSection Name:" << getName();
OS << " Fragments:[\n ";
- for (auto it = begin(), ie = end(); it != ie; ++it) {
- if (it != begin())
+ bool First = true;
+ for (auto &F : *this) {
+ if (First)
+ First = false;
+ else
OS << ",\n ";
- it->dump();
+ F.dump();
}
OS << "]>";
}