Skip to content

Commit

Permalink
[MC] Remove getFragmentList uses. NFC
Browse files Browse the repository at this point in the history
  • Loading branch information
MaskRay committed Jun 11, 2024
1 parent 8e12f31 commit cb63abc
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 23 deletions.
1 change: 1 addition & 0 deletions llvm/include/llvm/MC/MCSection.h
Original file line number Diff line number Diff line change
Expand Up @@ -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); }

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/MC/MCAssembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++);
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/MC/MCObjectStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 6 additions & 3 deletions llvm/lib/MC/MCSection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 << "]>";
}
Expand Down
8 changes: 3 additions & 5 deletions llvm/lib/MC/MachObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
9 changes: 2 additions & 7 deletions llvm/lib/MC/WasmObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/MC/WinCOFFObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion llvm/tools/dsymutil/MachOUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit cb63abc

Please sign in to comment.