diff options
author | Fangrui Song <i@maskray.me> | 2024-06-27 19:44:37 -0700 |
---|---|---|
committer | Fangrui Song <i@maskray.me> | 2024-06-27 19:44:37 -0700 |
commit | e48c4011ca80385573f1b92793c75dc98abb228f (patch) | |
tree | 8849ffba1ef2a7082653c0552c0582eb619a7c84 | |
parent | 874b880fce8522b06c6cf73a76612a844e2eaf1b (diff) | |
download | llvm-e48c4011ca80385573f1b92793c75dc98abb228f.zip llvm-e48c4011ca80385573f1b92793c75dc98abb228f.tar.gz llvm-e48c4011ca80385573f1b92793c75dc98abb228f.tar.bz2 |
[MC] Cache current fragment in MCStreamer
This eliminates indirection through `getCurrentSectionOnly()->curFragList()->Tail`.
-rw-r--r-- | llvm/include/llvm/MC/MCFragment.h | 2 | ||||
-rw-r--r-- | llvm/include/llvm/MC/MCObjectStreamer.h | 9 | ||||
-rw-r--r-- | llvm/include/llvm/MC/MCStreamer.h | 3 | ||||
-rw-r--r-- | llvm/lib/MC/MCAsmStreamer.cpp | 1 | ||||
-rw-r--r-- | llvm/lib/MC/MCObjectStreamer.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/MC/MCStreamer.cpp | 1 |
6 files changed, 16 insertions, 4 deletions
diff --git a/llvm/include/llvm/MC/MCFragment.h b/llvm/include/llvm/MC/MCFragment.h index 72db28c..c8832e6 100644 --- a/llvm/include/llvm/MC/MCFragment.h +++ b/llvm/include/llvm/MC/MCFragment.h @@ -24,6 +24,7 @@ namespace llvm { class MCAssembler; +class MCObjectStreamer; class MCSection; class MCSubtargetInfo; class MCSymbol; @@ -31,6 +32,7 @@ class MCSymbol; class MCFragment { friend class MCAsmLayout; friend class MCAssembler; + friend class MCObjectStreamer; friend class MCSection; public: diff --git a/llvm/include/llvm/MC/MCObjectStreamer.h b/llvm/include/llvm/MC/MCObjectStreamer.h index a816449..e6c07d5 100644 --- a/llvm/include/llvm/MC/MCObjectStreamer.h +++ b/llvm/include/llvm/MC/MCObjectStreamer.h @@ -88,9 +88,12 @@ public: MCFragment *getCurrentFragment() const; void insert(MCFragment *F) { - MCSection *CurSection = getCurrentSectionOnly(); - CurSection->addFragment(*F); - F->setParent(CurSection); + auto *Sec = CurFrag->getParent(); + F->setParent(Sec); + F->setLayoutOrder(CurFrag->getLayoutOrder() + 1); + CurFrag->Next = F; + CurFrag = F; + Sec->curFragList()->Tail = F; } /// Get a data fragment to write into, creating a new one if the current diff --git a/llvm/include/llvm/MC/MCStreamer.h b/llvm/include/llvm/MC/MCStreamer.h index 490b1a8..a8ca438 100644 --- a/llvm/include/llvm/MC/MCStreamer.h +++ b/llvm/include/llvm/MC/MCStreamer.h @@ -19,6 +19,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/MC/MCDirectives.h" #include "llvm/MC/MCDwarf.h" +#include "llvm/MC/MCFragment.h" #include "llvm/MC/MCLinkerOptimizationHint.h" #include "llvm/MC/MCPseudoProbe.h" #include "llvm/MC/MCWinEH.h" @@ -255,6 +256,8 @@ class MCStreamer { bool AllowAutoPadding = false; protected: + MCFragment *CurFrag = nullptr; + MCStreamer(MCContext &Ctx); virtual void emitCFIStartProcImpl(MCDwarfFrameInfo &Frame); diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp index 52719d1..ff240d1 100644 --- a/llvm/lib/MC/MCAsmStreamer.cpp +++ b/llvm/lib/MC/MCAsmStreamer.cpp @@ -512,6 +512,7 @@ void MCAsmStreamer::emitExplicitComments() { void MCAsmStreamer::changeSection(MCSection *Section, uint32_t Subsection) { assert(Section && "Cannot switch to a null section!"); + CurFrag = &Section->getDummyFragment(); if (MCTargetStreamer *TS = getTargetStreamer()) { TS->changeSection(getCurrentSectionOnly(), Section, Subsection, OS); } else { diff --git a/llvm/lib/MC/MCObjectStreamer.cpp b/llvm/lib/MC/MCObjectStreamer.cpp index 2357203..99ac7f4 100644 --- a/llvm/lib/MC/MCObjectStreamer.cpp +++ b/llvm/lib/MC/MCObjectStreamer.cpp @@ -143,7 +143,8 @@ void MCObjectStreamer::emitFrames(MCAsmBackend *MAB) { } MCFragment *MCObjectStreamer::getCurrentFragment() const { - return getCurrentSectionOnly()->curFragList()->Tail; + assert(CurFrag->getParent() == getCurrentSection().first); + return CurFrag; } static bool canReuseDataFragment(const MCDataFragment &F, @@ -307,6 +308,7 @@ bool MCObjectStreamer::changeSectionImpl(MCSection *Section, {Subsection, MCSection::FragList{F, F}}); } Section->CurFragList = &Subsections[I].second; + CurFrag = Section->CurFragList->Tail; return getAssembler().registerSection(*Section); } diff --git a/llvm/lib/MC/MCStreamer.cpp b/llvm/lib/MC/MCStreamer.cpp index 582b3a6..cfc27be 100644 --- a/llvm/lib/MC/MCStreamer.cpp +++ b/llvm/lib/MC/MCStreamer.cpp @@ -105,6 +105,7 @@ void MCStreamer::reset() { SymbolOrdering.clear(); SectionStack.clear(); SectionStack.push_back(std::pair<MCSectionSubPair, MCSectionSubPair>()); + CurFrag = nullptr; } raw_ostream &MCStreamer::getCommentOS() { |