Skip to content

Commit dcb71c0

Browse files
committed
[MC] Simplify Sec.getFragmentList().insert(Sec.begin(), F). NFC
Decrease the uses of getFragmentList() to make it easier to change the fragment list representation.
1 parent 2e482b2 commit dcb71c0

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

llvm/include/llvm/MC/MCSection.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ class MCSection {
188188
iterator end() { return Fragments.end(); }
189189
const_iterator end() const { return Fragments.end(); }
190190

191+
void addFragment(MCFragment &F) { Fragments.push_back(&F); }
192+
191193
MCSection::iterator getSubsectionInsertionPoint(unsigned Subsection);
192194

193195
void dump() const;

llvm/lib/MC/MCContext.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ MCSectionELF *MCContext::createELFSectionImpl(StringRef Section, unsigned Type,
498498
R, LinkedToSym);
499499

500500
auto *F = new MCDataFragment();
501-
Ret->getFragmentList().insert(Ret->begin(), F);
501+
Ret->addFragment(*F);
502502
F->setParent(Ret);
503503
R->setFragment(F);
504504

@@ -772,7 +772,7 @@ MCSectionWasm *MCContext::getWasmSection(const Twine &Section, SectionKind Kind,
772772
Entry.second = Result;
773773

774774
auto *F = new MCDataFragment();
775-
Result->getFragmentList().insert(Result->begin(), F);
775+
Result->addFragment(*F);
776776
F->setParent(Result);
777777
Begin->setFragment(F);
778778

@@ -838,7 +838,7 @@ MCSectionXCOFF *MCContext::getXCOFFSection(
838838
Entry.second = Result;
839839

840840
auto *F = new MCDataFragment();
841-
Result->getFragmentList().insert(Result->begin(), F);
841+
Result->addFragment(*F);
842842
F->setParent(Result);
843843

844844
if (Begin)
@@ -861,7 +861,7 @@ MCSectionSPIRV *MCContext::getSPIRVSection() {
861861
MCSectionSPIRV(SectionKind::getText(), Begin);
862862

863863
auto *F = new MCDataFragment();
864-
Result->getFragmentList().insert(Result->begin(), F);
864+
Result->addFragment(*F);
865865
F->setParent(Result);
866866

867867
return Result;
@@ -884,7 +884,7 @@ MCSectionDXContainer *MCContext::getDXContainerSection(StringRef Section,
884884

885885
// The first fragment will store the header
886886
auto *F = new MCDataFragment();
887-
MapIt->second->getFragmentList().insert(MapIt->second->begin(), F);
887+
MapIt->second->addFragment(*F);
888888
F->setParent(MapIt->second);
889889

890890
return MapIt->second;

llvm/lib/MC/MCFragment.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ MCFragment::MCFragment(FragmentType Kind, bool HasInstructions,
260260
: Parent(Parent), Atom(nullptr), Offset(~UINT64_C(0)), LayoutOrder(0),
261261
Kind(Kind), IsBeingLaidOut(false), HasInstructions(HasInstructions) {
262262
if (Parent && !isa<MCDummyFragment>(*this))
263-
Parent->getFragmentList().push_back(this);
263+
Parent->addFragment(*this);
264264
}
265265

266266
void MCFragment::destroy() {

0 commit comments

Comments
 (0)