Skip to content

Commit cb63abc

Browse files
committed
[MC] Remove getFragmentList uses. NFC
1 parent 8e12f31 commit cb63abc

File tree

10 files changed

+19
-23
lines changed

10 files changed

+19
-23
lines changed

llvm/include/llvm/MC/MCSection.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ class MCSection {
189189

190190
iterator end() { return Fragments.end(); }
191191
const_iterator end() const { return Fragments.end(); }
192+
bool empty() const { return Fragments.empty(); }
192193

193194
void addFragment(MCFragment &F) { Fragments.push_back(&F); }
194195

llvm/lib/MC/MCAssembler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ void MCAssembler::layout(MCAsmLayout &Layout) {
820820
for (MCSection &Sec : *this) {
821821
// Create dummy fragments to eliminate any empty sections, this simplifies
822822
// layout.
823-
if (Sec.getFragmentList().empty())
823+
if (Sec.empty())
824824
new MCDataFragment(&Sec);
825825

826826
Sec.setOrdinal(SectionIndex++);

llvm/lib/MC/MCObjectStreamer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ void MCObjectStreamer::emitFrames(MCAsmBackend *MAB) {
202202
MCFragment *MCObjectStreamer::getCurrentFragment() const {
203203
assert(getCurrentSectionOnly() && "No current section!");
204204

205-
if (CurInsertionPoint != getCurrentSectionOnly()->getFragmentList().begin())
205+
if (CurInsertionPoint != getCurrentSectionOnly()->begin())
206206
return &*std::prev(CurInsertionPoint);
207207

208208
return nullptr;

llvm/lib/MC/MCSection.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,13 @@ LLVM_DUMP_METHOD void MCSection::dump() const {
130130

131131
OS << "<MCSection Name:" << getName();
132132
OS << " Fragments:[\n ";
133-
for (auto it = begin(), ie = end(); it != ie; ++it) {
134-
if (it != begin())
133+
bool First = true;
134+
for (auto &F : *this) {
135+
if (First)
136+
First = false;
137+
else
135138
OS << ",\n ";
136-
it->dump();
139+
F.dump();
137140
}
138141
OS << "]>";
139142
}

llvm/lib/MC/MachObjectWriter.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -767,11 +767,9 @@ uint64_t MachObjectWriter::writeObject(MCAssembler &Asm,
767767
if (!Asm.CGProfile.empty()) {
768768
MCSection *CGProfileSection = Asm.getContext().getMachOSection(
769769
"__LLVM", "__cg_profile", 0, SectionKind::getMetadata());
770-
MCDataFragment *Frag = dyn_cast_or_null<MCDataFragment>(
771-
&*CGProfileSection->getFragmentList().begin());
772-
assert(Frag && "call graph profile section not reserved");
773-
Frag->getContents().clear();
774-
raw_svector_ostream OS(Frag->getContents());
770+
auto &Frag = cast<MCDataFragment>(*CGProfileSection->begin());
771+
Frag.getContents().clear();
772+
raw_svector_ostream OS(Frag.getContents());
775773
for (const MCAssembler::CGProfileEntry &CGPE : Asm.CGProfile) {
776774
uint32_t FromIndex = CGPE.From->getSymbol().getIndex();
777775
uint32_t ToIndex = CGPE.To->getSymbol().getIndex();

llvm/lib/MC/WasmObjectWriter.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1857,14 +1857,9 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm,
18571857
report_fatal_error(".fini_array sections are unsupported");
18581858
if (!WS.getName().starts_with(".init_array"))
18591859
continue;
1860-
if (WS.getFragmentList().empty())
1861-
continue;
1862-
1863-
// init_array is expected to contain a single non-empty data fragment
1864-
if (WS.getFragmentList().size() != 3)
1865-
report_fatal_error("only one .init_array section fragment supported");
1866-
18671860
auto IT = WS.begin();
1861+
if (IT == WS.end())
1862+
continue;
18681863
const MCFragment &EmptyFrag = *IT;
18691864
if (EmptyFrag.getKind() != MCFragment::FT_Data)
18701865
report_fatal_error(".init_array section should be aligned");

llvm/lib/MC/WinCOFFObjectWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ void WinCOFFWriter::defineSection(const MCSectionCOFF &MCSec,
354354
Section->MCSection = &MCSec;
355355
SectionMap[&MCSec] = Section;
356356

357-
if (UseOffsetLabels && !MCSec.getFragmentList().empty()) {
357+
if (UseOffsetLabels && !MCSec.empty()) {
358358
const uint32_t Interval = 1 << OffsetLabelIntervalBits;
359359
uint32_t N = 1;
360360
for (uint32_t Off = Interval, E = Layout.getSectionAddressSize(&MCSec);

llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ void ARMELFObjectWriter::addTargetSectionFlags(MCContext &Ctx,
329329
MCSectionELF *TextSection =
330330
static_cast<MCSectionELF *>(Ctx.getObjectFileInfo()->getTextSection());
331331
if (Sec.getKind().isExecuteOnly() && !TextSection->hasInstructions()) {
332-
for (auto &F : TextSection->getFragmentList())
332+
for (auto &F : *TextSection)
333333
if (auto *DF = dyn_cast<MCDataFragment>(&F))
334334
if (!DF->getContents().empty())
335335
return;

llvm/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -713,15 +713,14 @@ class HexagonAsmBackend : public MCAsmBackend {
713713
void finishLayout(MCAssembler const &Asm,
714714
MCAsmLayout &Layout) const override {
715715
for (auto *I : Layout.getSectionOrder()) {
716-
auto &Fragments = I->getFragmentList();
717-
for (auto &J : Fragments) {
716+
for (auto &J : *I) {
718717
switch (J.getKind()) {
719718
default:
720719
break;
721720
case MCFragment::FT_Align: {
722721
auto Size = Asm.computeFragmentSize(Layout, J);
723722
for (auto K = J.getIterator();
724-
K != Fragments.begin() && Size >= HEXAGON_PACKET_SIZE;) {
723+
K != I->begin() && Size >= HEXAGON_PACKET_SIZE;) {
725724
--K;
726725
switch (K->getKind()) {
727726
default:

llvm/tools/dsymutil/MachOUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ bool generateDsymCompanion(
630630

631631
// Emit the Dwarf sections contents.
632632
for (const MCSection &Sec : MCAsm) {
633-
if (Sec.begin() == Sec.end())
633+
if (Sec.empty())
634634
continue;
635635

636636
uint64_t Pos = OutFile.tell();

0 commit comments

Comments
 (0)