[llvm] dcb71c0 - [MC] Simplify Sec.getFragmentList().insert(Sec.begin(), F). NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 8 15:51:48 PDT 2024
Author: Fangrui Song
Date: 2024-06-08T15:51:44-07:00
New Revision: dcb71c06c7b059e313f22e46bc9c41343a03f1eb
URL: https://github.com/llvm/llvm-project/commit/dcb71c06c7b059e313f22e46bc9c41343a03f1eb
DIFF: https://github.com/llvm/llvm-project/commit/dcb71c06c7b059e313f22e46bc9c41343a03f1eb.diff
LOG: [MC] Simplify Sec.getFragmentList().insert(Sec.begin(), F). NFC
Decrease the uses of getFragmentList() to make it easier to change the
fragment list representation.
Added:
Modified:
llvm/include/llvm/MC/MCSection.h
llvm/lib/MC/MCContext.cpp
llvm/lib/MC/MCFragment.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCSection.h b/llvm/include/llvm/MC/MCSection.h
index 90bc48ec185ca..ad41d4475047a 100644
--- a/llvm/include/llvm/MC/MCSection.h
+++ b/llvm/include/llvm/MC/MCSection.h
@@ -188,6 +188,8 @@ class MCSection {
iterator end() { return Fragments.end(); }
const_iterator end() const { return Fragments.end(); }
+ void addFragment(MCFragment &F) { Fragments.push_back(&F); }
+
MCSection::iterator getSubsectionInsertionPoint(unsigned Subsection);
void dump() const;
diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp
index f027eb65d700e..771ca9c6006ca 100644
--- a/llvm/lib/MC/MCContext.cpp
+++ b/llvm/lib/MC/MCContext.cpp
@@ -498,7 +498,7 @@ MCSectionELF *MCContext::createELFSectionImpl(StringRef Section, unsigned Type,
R, LinkedToSym);
auto *F = new MCDataFragment();
- Ret->getFragmentList().insert(Ret->begin(), F);
+ Ret->addFragment(*F);
F->setParent(Ret);
R->setFragment(F);
@@ -772,7 +772,7 @@ MCSectionWasm *MCContext::getWasmSection(const Twine &Section, SectionKind Kind,
Entry.second = Result;
auto *F = new MCDataFragment();
- Result->getFragmentList().insert(Result->begin(), F);
+ Result->addFragment(*F);
F->setParent(Result);
Begin->setFragment(F);
@@ -838,7 +838,7 @@ MCSectionXCOFF *MCContext::getXCOFFSection(
Entry.second = Result;
auto *F = new MCDataFragment();
- Result->getFragmentList().insert(Result->begin(), F);
+ Result->addFragment(*F);
F->setParent(Result);
if (Begin)
@@ -861,7 +861,7 @@ MCSectionSPIRV *MCContext::getSPIRVSection() {
MCSectionSPIRV(SectionKind::getText(), Begin);
auto *F = new MCDataFragment();
- Result->getFragmentList().insert(Result->begin(), F);
+ Result->addFragment(*F);
F->setParent(Result);
return Result;
@@ -884,7 +884,7 @@ MCSectionDXContainer *MCContext::getDXContainerSection(StringRef Section,
// The first fragment will store the header
auto *F = new MCDataFragment();
- MapIt->second->getFragmentList().insert(MapIt->second->begin(), F);
+ MapIt->second->addFragment(*F);
F->setParent(MapIt->second);
return MapIt->second;
diff --git a/llvm/lib/MC/MCFragment.cpp b/llvm/lib/MC/MCFragment.cpp
index a8da46dbd8727..7d0826802d0af 100644
--- a/llvm/lib/MC/MCFragment.cpp
+++ b/llvm/lib/MC/MCFragment.cpp
@@ -260,7 +260,7 @@ MCFragment::MCFragment(FragmentType Kind, bool HasInstructions,
: Parent(Parent), Atom(nullptr), Offset(~UINT64_C(0)), LayoutOrder(0),
Kind(Kind), IsBeingLaidOut(false), HasInstructions(HasInstructions) {
if (Parent && !isa<MCDummyFragment>(*this))
- Parent->getFragmentList().push_back(this);
+ Parent->addFragment(*this);
}
void MCFragment::destroy() {
More information about the llvm-commits
mailing list