[llvm] cb63abc - [MC] Remove getFragmentList uses. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 10 18:27:39 PDT 2024
Author: Fangrui Song
Date: 2024-06-10T18:27:34-07:00
New Revision: cb63abca27e1813ae58ded466cd81ba3952ab888
URL: https://github.com/llvm/llvm-project/commit/cb63abca27e1813ae58ded466cd81ba3952ab888
DIFF: https://github.com/llvm/llvm-project/commit/cb63abca27e1813ae58ded466cd81ba3952ab888.diff
LOG: [MC] Remove getFragmentList uses. NFC
Added:
Modified:
llvm/include/llvm/MC/MCSection.h
llvm/lib/MC/MCAssembler.cpp
llvm/lib/MC/MCObjectStreamer.cpp
llvm/lib/MC/MCSection.cpp
llvm/lib/MC/MachObjectWriter.cpp
llvm/lib/MC/WasmObjectWriter.cpp
llvm/lib/MC/WinCOFFObjectWriter.cpp
llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
llvm/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp
llvm/tools/dsymutil/MachOUtils.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCSection.h b/llvm/include/llvm/MC/MCSection.h
index aa648e97e2238..217b9b4b5bc52 100644
--- a/llvm/include/llvm/MC/MCSection.h
+++ b/llvm/include/llvm/MC/MCSection.h
@@ -189,6 +189,7 @@ class MCSection {
iterator end() { return Fragments.end(); }
const_iterator end() const { return Fragments.end(); }
+ bool empty() const { return Fragments.empty(); }
void addFragment(MCFragment &F) { Fragments.push_back(&F); }
diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp
index a7157e7a37b43..8490853eda87c 100644
--- a/llvm/lib/MC/MCAssembler.cpp
+++ b/llvm/lib/MC/MCAssembler.cpp
@@ -820,7 +820,7 @@ void MCAssembler::layout(MCAsmLayout &Layout) {
for (MCSection &Sec : *this) {
// Create dummy fragments to eliminate any empty sections, this simplifies
// layout.
- if (Sec.getFragmentList().empty())
+ if (Sec.empty())
new MCDataFragment(&Sec);
Sec.setOrdinal(SectionIndex++);
diff --git a/llvm/lib/MC/MCObjectStreamer.cpp b/llvm/lib/MC/MCObjectStreamer.cpp
index 8d3873bed9efd..ae4e6915fa294 100644
--- a/llvm/lib/MC/MCObjectStreamer.cpp
+++ b/llvm/lib/MC/MCObjectStreamer.cpp
@@ -202,7 +202,7 @@ void MCObjectStreamer::emitFrames(MCAsmBackend *MAB) {
MCFragment *MCObjectStreamer::getCurrentFragment() const {
assert(getCurrentSectionOnly() && "No current section!");
- if (CurInsertionPoint != getCurrentSectionOnly()->getFragmentList().begin())
+ if (CurInsertionPoint != getCurrentSectionOnly()->begin())
return &*std::prev(CurInsertionPoint);
return nullptr;
diff --git a/llvm/lib/MC/MCSection.cpp b/llvm/lib/MC/MCSection.cpp
index 12e69f70537b7..9848d7fafe764 100644
--- a/llvm/lib/MC/MCSection.cpp
+++ b/llvm/lib/MC/MCSection.cpp
@@ -130,10 +130,13 @@ LLVM_DUMP_METHOD void MCSection::dump() const {
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 << "]>";
}
diff --git a/llvm/lib/MC/MachObjectWriter.cpp b/llvm/lib/MC/MachObjectWriter.cpp
index d17e6e125d872..de8bde4211b49 100644
--- a/llvm/lib/MC/MachObjectWriter.cpp
+++ b/llvm/lib/MC/MachObjectWriter.cpp
@@ -767,11 +767,9 @@ uint64_t MachObjectWriter::writeObject(MCAssembler &Asm,
if (!Asm.CGProfile.empty()) {
MCSection *CGProfileSection = Asm.getContext().getMachOSection(
"__LLVM", "__cg_profile", 0, SectionKind::getMetadata());
- MCDataFragment *Frag = dyn_cast_or_null<MCDataFragment>(
- &*CGProfileSection->getFragmentList().begin());
- assert(Frag && "call graph profile section not reserved");
- Frag->getContents().clear();
- raw_svector_ostream OS(Frag->getContents());
+ auto &Frag = cast<MCDataFragment>(*CGProfileSection->begin());
+ Frag.getContents().clear();
+ raw_svector_ostream OS(Frag.getContents());
for (const MCAssembler::CGProfileEntry &CGPE : Asm.CGProfile) {
uint32_t FromIndex = CGPE.From->getSymbol().getIndex();
uint32_t ToIndex = CGPE.To->getSymbol().getIndex();
diff --git a/llvm/lib/MC/WasmObjectWriter.cpp b/llvm/lib/MC/WasmObjectWriter.cpp
index 788e92f94b268..451269608f179 100644
--- a/llvm/lib/MC/WasmObjectWriter.cpp
+++ b/llvm/lib/MC/WasmObjectWriter.cpp
@@ -1857,14 +1857,9 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm,
report_fatal_error(".fini_array sections are unsupported");
if (!WS.getName().starts_with(".init_array"))
continue;
- if (WS.getFragmentList().empty())
- continue;
-
- // init_array is expected to contain a single non-empty data fragment
- if (WS.getFragmentList().size() != 3)
- report_fatal_error("only one .init_array section fragment supported");
-
auto IT = WS.begin();
+ if (IT == WS.end())
+ continue;
const MCFragment &EmptyFrag = *IT;
if (EmptyFrag.getKind() != MCFragment::FT_Data)
report_fatal_error(".init_array section should be aligned");
diff --git a/llvm/lib/MC/WinCOFFObjectWriter.cpp b/llvm/lib/MC/WinCOFFObjectWriter.cpp
index 3c9ff71b6b062..a2b6c4e5c3a5c 100644
--- a/llvm/lib/MC/WinCOFFObjectWriter.cpp
+++ b/llvm/lib/MC/WinCOFFObjectWriter.cpp
@@ -354,7 +354,7 @@ void WinCOFFWriter::defineSection(const MCSectionCOFF &MCSec,
Section->MCSection = &MCSec;
SectionMap[&MCSec] = Section;
- if (UseOffsetLabels && !MCSec.getFragmentList().empty()) {
+ if (UseOffsetLabels && !MCSec.empty()) {
const uint32_t Interval = 1 << OffsetLabelIntervalBits;
uint32_t N = 1;
for (uint32_t Off = Interval, E = Layout.getSectionAddressSize(&MCSec);
diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
index de7449a400a74..b6cecccf3572d 100644
--- a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
+++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
@@ -329,7 +329,7 @@ void ARMELFObjectWriter::addTargetSectionFlags(MCContext &Ctx,
MCSectionELF *TextSection =
static_cast<MCSectionELF *>(Ctx.getObjectFileInfo()->getTextSection());
if (Sec.getKind().isExecuteOnly() && !TextSection->hasInstructions()) {
- for (auto &F : TextSection->getFragmentList())
+ for (auto &F : *TextSection)
if (auto *DF = dyn_cast<MCDataFragment>(&F))
if (!DF->getContents().empty())
return;
diff --git a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp
index f9a0ba3608e6d..3b6ea81cdf10e 100644
--- a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp
+++ b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp
@@ -713,15 +713,14 @@ class HexagonAsmBackend : public MCAsmBackend {
void finishLayout(MCAssembler const &Asm,
MCAsmLayout &Layout) const override {
for (auto *I : Layout.getSectionOrder()) {
- auto &Fragments = I->getFragmentList();
- for (auto &J : Fragments) {
+ for (auto &J : *I) {
switch (J.getKind()) {
default:
break;
case MCFragment::FT_Align: {
auto Size = Asm.computeFragmentSize(Layout, J);
for (auto K = J.getIterator();
- K != Fragments.begin() && Size >= HEXAGON_PACKET_SIZE;) {
+ K != I->begin() && Size >= HEXAGON_PACKET_SIZE;) {
--K;
switch (K->getKind()) {
default:
diff --git a/llvm/tools/dsymutil/MachOUtils.cpp b/llvm/tools/dsymutil/MachOUtils.cpp
index 8e144d640ed01..b52ab1ce6d294 100644
--- a/llvm/tools/dsymutil/MachOUtils.cpp
+++ b/llvm/tools/dsymutil/MachOUtils.cpp
@@ -630,7 +630,7 @@ bool generateDsymCompanion(
// Emit the Dwarf sections contents.
for (const MCSection &Sec : MCAsm) {
- if (Sec.begin() == Sec.end())
+ if (Sec.empty())
continue;
uint64_t Pos = OutFile.tell();
More information about the llvm-commits
mailing list