Skip to content

Commit e48c401

Browse files
committed
[MC] Cache current fragment in MCStreamer
This eliminates indirection through `getCurrentSectionOnly()->curFragList()->Tail`.
1 parent 874b880 commit e48c401

File tree

6 files changed

+16
-4
lines changed

6 files changed

+16
-4
lines changed

llvm/include/llvm/MC/MCFragment.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@
2424
namespace llvm {
2525

2626
class MCAssembler;
27+
class MCObjectStreamer;
2728
class MCSection;
2829
class MCSubtargetInfo;
2930
class MCSymbol;
3031

3132
class MCFragment {
3233
friend class MCAsmLayout;
3334
friend class MCAssembler;
35+
friend class MCObjectStreamer;
3436
friend class MCSection;
3537

3638
public:

llvm/include/llvm/MC/MCObjectStreamer.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,12 @@ class MCObjectStreamer : public MCStreamer {
8888
MCFragment *getCurrentFragment() const;
8989

9090
void insert(MCFragment *F) {
91-
MCSection *CurSection = getCurrentSectionOnly();
92-
CurSection->addFragment(*F);
93-
F->setParent(CurSection);
91+
auto *Sec = CurFrag->getParent();
92+
F->setParent(Sec);
93+
F->setLayoutOrder(CurFrag->getLayoutOrder() + 1);
94+
CurFrag->Next = F;
95+
CurFrag = F;
96+
Sec->curFragList()->Tail = F;
9497
}
9598

9699
/// Get a data fragment to write into, creating a new one if the current

llvm/include/llvm/MC/MCStreamer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "llvm/ADT/StringRef.h"
2020
#include "llvm/MC/MCDirectives.h"
2121
#include "llvm/MC/MCDwarf.h"
22+
#include "llvm/MC/MCFragment.h"
2223
#include "llvm/MC/MCLinkerOptimizationHint.h"
2324
#include "llvm/MC/MCPseudoProbe.h"
2425
#include "llvm/MC/MCWinEH.h"
@@ -255,6 +256,8 @@ class MCStreamer {
255256
bool AllowAutoPadding = false;
256257

257258
protected:
259+
MCFragment *CurFrag = nullptr;
260+
258261
MCStreamer(MCContext &Ctx);
259262

260263
virtual void emitCFIStartProcImpl(MCDwarfFrameInfo &Frame);

llvm/lib/MC/MCAsmStreamer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ void MCAsmStreamer::emitExplicitComments() {
512512

513513
void MCAsmStreamer::changeSection(MCSection *Section, uint32_t Subsection) {
514514
assert(Section && "Cannot switch to a null section!");
515+
CurFrag = &Section->getDummyFragment();
515516
if (MCTargetStreamer *TS = getTargetStreamer()) {
516517
TS->changeSection(getCurrentSectionOnly(), Section, Subsection, OS);
517518
} else {

llvm/lib/MC/MCObjectStreamer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ void MCObjectStreamer::emitFrames(MCAsmBackend *MAB) {
143143
}
144144

145145
MCFragment *MCObjectStreamer::getCurrentFragment() const {
146-
return getCurrentSectionOnly()->curFragList()->Tail;
146+
assert(CurFrag->getParent() == getCurrentSection().first);
147+
return CurFrag;
147148
}
148149

149150
static bool canReuseDataFragment(const MCDataFragment &F,
@@ -307,6 +308,7 @@ bool MCObjectStreamer::changeSectionImpl(MCSection *Section,
307308
{Subsection, MCSection::FragList{F, F}});
308309
}
309310
Section->CurFragList = &Subsections[I].second;
311+
CurFrag = Section->CurFragList->Tail;
310312

311313
return getAssembler().registerSection(*Section);
312314
}

llvm/lib/MC/MCStreamer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ void MCStreamer::reset() {
105105
SymbolOrdering.clear();
106106
SectionStack.clear();
107107
SectionStack.push_back(std::pair<MCSectionSubPair, MCSectionSubPair>());
108+
CurFrag = nullptr;
108109
}
109110

110111
raw_ostream &MCStreamer::getCommentOS() {

0 commit comments

Comments
 (0)