From 2224f64c6df5c6a187501551981211fa179d8f2b Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 26 May 2015 02:17:21 +0000 Subject: [PATCH] Remove most uses of MCSectionData from MCAssembler. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238172 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/MC/MCAssembler.h | 16 +++---------- lib/MC/ELFObjectWriter.cpp | 6 ++--- lib/MC/MCAssembler.cpp | 23 +++++++++---------- lib/MC/MCELFStreamer.cpp | 2 +- lib/MC/MCMachOStreamer.cpp | 2 +- lib/MC/MachObjectWriter.cpp | 23 ++++++++----------- lib/MC/WinCOFFObjectWriter.cpp | 2 +- .../R600/MCTargetDesc/AMDGPUAsmBackend.cpp | 2 +- 8 files changed, 30 insertions(+), 46 deletions(-) diff --git a/include/llvm/MC/MCAssembler.h b/include/llvm/MC/MCAssembler.h index 95d27fb2e6e..38c8b9c01d2 100644 --- a/include/llvm/MC/MCAssembler.h +++ b/include/llvm/MC/MCAssembler.h @@ -535,7 +535,7 @@ public: // FIXME: This really doesn't belong here. See comments below. struct IndirectSymbolData { MCSymbol *Symbol; - MCSectionData *SectionData; + MCSection *Section; }; // FIXME: Ditto this. Purely so the Streamer and the ObjectWriter can talk @@ -679,7 +679,7 @@ private: /// \brief Perform one layout iteration of the given section and return true /// if any offsets were adjusted. - bool layoutSectionOnce(MCAsmLayout &Layout, MCSectionData &SD); + bool layoutSectionOnce(MCAsmLayout &Layout, MCSection &Sec); bool relaxInstruction(MCAsmLayout &Layout, MCRelaxableFragment &IF); @@ -715,7 +715,7 @@ public: bool isSymbolLinkerVisible(const MCSymbol &SD) const; /// Emit the section contents using the given object writer. - void writeSectionData(const MCSectionData *Section, + void writeSectionData(const MCSection *Section, const MCAsmLayout &Layout) const; /// Check whether a given symbol has been flagged with .thumb_func. @@ -884,16 +884,6 @@ public: /// \name Backend Data Access /// @{ - MCSectionData &getSectionData(MCSection &Section) { - assert(Sections.count(&Section) && "Unknown Seciton"); - return Section.getSectionData(); - } - - const MCSectionData &getSectionData(const MCSection &Section) const { - return const_cast(this) - ->getSectionData(const_cast(Section)); - } - MCSectionData &getOrCreateSectionData(MCSection &Section, bool *Created = nullptr) { bool C = Sections.insert(&Section); diff --git a/lib/MC/ELFObjectWriter.cpp b/lib/MC/ELFObjectWriter.cpp index 872d3bb2a05..18070864317 100644 --- a/lib/MC/ELFObjectWriter.cpp +++ b/lib/MC/ELFObjectWriter.cpp @@ -1150,7 +1150,7 @@ void ELFObjectWriter::writeSectionData(const MCAssembler &Asm, // for writing to arbitrary buffers) for little benefit. if (!Asm.getContext().getAsmInfo()->compressDebugSections() || !SectionName.startswith(".debug_") || SectionName == ".debug_frame") { - Asm.writeSectionData(&SD, Layout); + Asm.writeSectionData(&Section, Layout); return; } @@ -1164,12 +1164,12 @@ void ELFObjectWriter::writeSectionData(const MCAssembler &Asm, StringRef(UncompressedData.data(), UncompressedData.size()), CompressedContents); if (Success != zlib::StatusOK) { - Asm.writeSectionData(&SD, Layout); + Asm.writeSectionData(&Section, Layout); return; } if (!prependCompressionHeader(UncompressedData.size(), CompressedContents)) { - Asm.writeSectionData(&SD, Layout); + Asm.writeSectionData(&Section, Layout); return; } Asm.getContext().renameELFSection(&Section, diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index c56775ac560..187fd1fd547 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -768,16 +768,15 @@ static void writeFragment(const MCAssembler &Asm, const MCAsmLayout &Layout, "The stream should advance by fragment size"); } -void MCAssembler::writeSectionData(const MCSectionData *SD, +void MCAssembler::writeSectionData(const MCSection *Sec, const MCAsmLayout &Layout) const { // Ignore virtual sections. - const MCSection &Sec = SD->getSection(); - if (Sec.isVirtualSection()) { - assert(Layout.getSectionFileSize(&Sec) == 0 && "Invalid size for section!"); + if (Sec->isVirtualSection()) { + assert(Layout.getSectionFileSize(Sec) == 0 && "Invalid size for section!"); // Check that contents are only things legal inside a virtual section. - for (MCSectionData::const_iterator it = SD->begin(), - ie = SD->end(); it != ie; ++it) { + for (MCSectionData::const_iterator it = Sec->begin(), ie = Sec->end(); + it != ie; ++it) { switch (it->getKind()) { default: llvm_unreachable("Invalid fragment in virtual section!"); case MCFragment::FT_Data: { @@ -789,7 +788,7 @@ void MCAssembler::writeSectionData(const MCSectionData *SD, "Cannot have fixups in virtual section!"); for (unsigned i = 0, e = DF.getContents().size(); i != e; ++i) if (DF.getContents()[i]) { - if (auto *ELFSec = dyn_cast(&SD->getSection())) + if (auto *ELFSec = dyn_cast(Sec)) report_fatal_error("non-zero initializer found in section '" + ELFSec->getSectionName() + "'"); else @@ -818,12 +817,12 @@ void MCAssembler::writeSectionData(const MCSectionData *SD, uint64_t Start = getWriter().getStream().tell(); (void)Start; - for (MCSectionData::const_iterator it = SD->begin(), ie = SD->end(); + for (MCSectionData::const_iterator it = Sec->begin(), ie = Sec->end(); it != ie; ++it) writeFragment(*this, Layout, *it); assert(getWriter().getStream().tell() - Start == - Layout.getSectionAddressSize(&SD->getSection())); + Layout.getSectionAddressSize(Sec)); } std::pair MCAssembler::handleFixup(const MCAsmLayout &Layout, @@ -1033,7 +1032,7 @@ bool MCAssembler::relaxDwarfCallFrameFragment(MCAsmLayout &Layout, return OldSize != Data.size(); } -bool MCAssembler::layoutSectionOnce(MCAsmLayout &Layout, MCSectionData &SD) { +bool MCAssembler::layoutSectionOnce(MCAsmLayout &Layout, MCSection &Sec) { // Holds the first fragment which needed relaxing during this layout. It will // remain NULL if none were relaxed. // When a fragment is relaxed, all the fragments following it should get @@ -1041,7 +1040,7 @@ bool MCAssembler::layoutSectionOnce(MCAsmLayout &Layout, MCSectionData &SD) { MCFragment *FirstRelaxedFragment = nullptr; // Attempt to relax all the fragments in the section. - for (MCSectionData::iterator I = SD.begin(), IE = SD.end(); I != IE; ++I) { + for (MCSectionData::iterator I = Sec.begin(), IE = Sec.end(); I != IE; ++I) { // Check if this is a fragment that needs relaxation. bool RelaxedFrag = false; switch(I->getKind()) { @@ -1081,7 +1080,7 @@ bool MCAssembler::layoutOnce(MCAsmLayout &Layout) { bool WasRelaxed = false; for (iterator it = begin(), ie = end(); it != ie; ++it) { MCSection &Sec = *it; - while (layoutSectionOnce(Layout, Sec.getSectionData())) + while (layoutSectionOnce(Layout, Sec)) WasRelaxed = true; } diff --git a/lib/MC/MCELFStreamer.cpp b/lib/MC/MCELFStreamer.cpp index cad5d93e459..b6778c4ab83 100644 --- a/lib/MC/MCELFStreamer.cpp +++ b/lib/MC/MCELFStreamer.cpp @@ -204,7 +204,7 @@ bool MCELFStreamer::EmitSymbolAttribute(MCSymbol *Symbol, // important for matching the string table that 'as' generates. IndirectSymbolData ISD; ISD.Symbol = Symbol; - ISD.SectionData = getCurrentSectionData(); + ISD.Section = &getCurrentSectionData()->getSection(); getAssembler().getIndirectSymbols().push_back(ISD); return true; } diff --git a/lib/MC/MCMachOStreamer.cpp b/lib/MC/MCMachOStreamer.cpp index 8fb9711178a..204dccf02f6 100644 --- a/lib/MC/MCMachOStreamer.cpp +++ b/lib/MC/MCMachOStreamer.cpp @@ -287,7 +287,7 @@ bool MCMachOStreamer::EmitSymbolAttribute(MCSymbol *Symbol, // important for matching the string table that 'as' generates. IndirectSymbolData ISD; ISD.Symbol = Symbol; - ISD.SectionData = getCurrentSectionData(); + ISD.Section = &getCurrentSectionData()->getSection(); getAssembler().getIndirectSymbols().push_back(ISD); return true; } diff --git a/lib/MC/MachObjectWriter.cpp b/lib/MC/MachObjectWriter.cpp index 7a4200136d2..44685209285 100644 --- a/lib/MC/MachObjectWriter.cpp +++ b/lib/MC/MachObjectWriter.cpp @@ -478,8 +478,7 @@ void MachObjectWriter::BindIndirectSymbols(MCAssembler &Asm) { // or stub section. for (MCAssembler::indirect_symbol_iterator it = Asm.indirect_symbol_begin(), ie = Asm.indirect_symbol_end(); it != ie; ++it) { - const MCSectionMachO &Section = - cast(it->SectionData->getSection()); + const MCSectionMachO &Section = cast(*it->Section); if (Section.getType() != MachO::S_NON_LAZY_SYMBOL_POINTERS && Section.getType() != MachO::S_LAZY_SYMBOL_POINTERS && @@ -494,15 +493,13 @@ void MachObjectWriter::BindIndirectSymbols(MCAssembler &Asm) { unsigned IndirectIndex = 0; for (MCAssembler::indirect_symbol_iterator it = Asm.indirect_symbol_begin(), ie = Asm.indirect_symbol_end(); it != ie; ++it, ++IndirectIndex) { - const MCSectionMachO &Section = - cast(it->SectionData->getSection()); + const MCSectionMachO &Section = cast(*it->Section); if (Section.getType() != MachO::S_NON_LAZY_SYMBOL_POINTERS) continue; // Initialize the section indirect symbol base, if necessary. - IndirectSymBase.insert( - std::make_pair(&it->SectionData->getSection(), IndirectIndex)); + IndirectSymBase.insert(std::make_pair(it->Section, IndirectIndex)); Asm.getOrCreateSymbolData(*it->Symbol); } @@ -511,16 +508,14 @@ void MachObjectWriter::BindIndirectSymbols(MCAssembler &Asm) { IndirectIndex = 0; for (MCAssembler::indirect_symbol_iterator it = Asm.indirect_symbol_begin(), ie = Asm.indirect_symbol_end(); it != ie; ++it, ++IndirectIndex) { - const MCSectionMachO &Section = - cast(it->SectionData->getSection()); + const MCSectionMachO &Section = cast(*it->Section); if (Section.getType() != MachO::S_LAZY_SYMBOL_POINTERS && Section.getType() != MachO::S_SYMBOL_STUBS) continue; // Initialize the section indirect symbol base, if necessary. - IndirectSymBase.insert( - std::make_pair(&it->SectionData->getSection(), IndirectIndex)); + IndirectSymBase.insert(std::make_pair(it->Section, IndirectIndex)); // Set the symbol type to undefined lazy, but only on construction. // @@ -913,10 +908,10 @@ void MachObjectWriter::WriteObject(MCAssembler &Asm, // Write the actual section data. for (MCAssembler::const_iterator it = Asm.begin(), ie = Asm.end(); it != ie; ++it) { - const MCSectionData &SD = it->getSectionData(); - Asm.writeSectionData(&SD, Layout); + MCSection &Sec = *it; + Asm.writeSectionData(&Sec, Layout); - uint64_t Pad = getPaddingSize(&*it, Layout); + uint64_t Pad = getPaddingSize(&Sec, Layout); WriteZeros(Pad); } @@ -972,7 +967,7 @@ void MachObjectWriter::WriteObject(MCAssembler &Asm, // Indirect symbols in the non-lazy symbol pointer section have some // special handling. const MCSectionMachO &Section = - static_cast(it->SectionData->getSection()); + static_cast(*it->Section); if (Section.getType() == MachO::S_NON_LAZY_SYMBOL_POINTERS) { // If this symbol is defined and internal, mark it as such. if (it->Symbol->isDefined() && diff --git a/lib/MC/WinCOFFObjectWriter.cpp b/lib/MC/WinCOFFObjectWriter.cpp index b53dfa5da57..723290560b5 100644 --- a/lib/MC/WinCOFFObjectWriter.cpp +++ b/lib/MC/WinCOFFObjectWriter.cpp @@ -1034,7 +1034,7 @@ void WinCOFFObjectWriter::WriteObject(MCAssembler &Asm, WriteZeros(SectionDataPadding); - Asm.writeSectionData(&j->getSectionData(), Layout); + Asm.writeSectionData(&*j, Layout); } if ((*i)->Relocations.size() > 0) { diff --git a/lib/Target/R600/MCTargetDesc/AMDGPUAsmBackend.cpp b/lib/Target/R600/MCTargetDesc/AMDGPUAsmBackend.cpp index 9704457d1aa..2605ca52dfd 100644 --- a/lib/Target/R600/MCTargetDesc/AMDGPUAsmBackend.cpp +++ b/lib/Target/R600/MCTargetDesc/AMDGPUAsmBackend.cpp @@ -67,7 +67,7 @@ public: void AMDGPUMCObjectWriter::WriteObject(MCAssembler &Asm, const MCAsmLayout &Layout) { for (MCAssembler::iterator I = Asm.begin(), E = Asm.end(); I != E; ++I) { - Asm.writeSectionData(&I->getSectionData(), Layout); + Asm.writeSectionData(&*I, Layout); } } -- 2.34.1