From 68e7d22de4ab083cc65202e362c868f1214fc5f0 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Mon, 25 May 2015 23:48:22 +0000 Subject: [PATCH] Store a MCSection in MCFragment. Part of the work to merge MCSectionData into MCSection. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238160 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/MC/MCAssembler.h | 58 +++++++++++++++--------------- include/llvm/MC/MCObjectStreamer.h | 2 +- lib/MC/MCAssembler.cpp | 6 ++-- lib/MC/MCELFStreamer.cpp | 5 +-- lib/MC/MCMachOStreamer.cpp | 5 +-- lib/MC/MCObjectStreamer.cpp | 2 +- lib/MC/WinCOFFStreamer.cpp | 6 ++-- 7 files changed, 44 insertions(+), 40 deletions(-) diff --git a/include/llvm/MC/MCAssembler.h b/include/llvm/MC/MCAssembler.h index 427c1099d58..2c0a0fd157d 100644 --- a/include/llvm/MC/MCAssembler.h +++ b/include/llvm/MC/MCAssembler.h @@ -67,8 +67,8 @@ public: private: FragmentType Kind; - /// Parent - The data for the section this fragment is in. - MCSectionData *Parent; + /// The data for the section this fragment is in. + MCSection *Parent; /// Atom - The atom this fragment is in, as represented by it's defining /// symbol. @@ -89,7 +89,7 @@ private: /// @} protected: - MCFragment(FragmentType Kind, MCSectionData *Parent = nullptr); + MCFragment(FragmentType Kind, MCSection *Parent = nullptr); public: // Only for sentinel. @@ -98,8 +98,10 @@ public: FragmentType getKind() const { return Kind; } - MCSectionData *getParent() const { return Parent; } - void setParent(MCSectionData *Value) { Parent = Value; } + MCSectionData *getParent() const { + return &Parent->getSectionData(); + } + void setParent(MCSection *Value) { Parent = Value; } const MCSymbol *getAtom() const { return Atom; } void setAtom(const MCSymbol *Value) { Atom = Value; } @@ -138,8 +140,8 @@ class MCEncodedFragment : public MCFragment { uint8_t BundlePadding; public: - MCEncodedFragment(MCFragment::FragmentType FType, MCSectionData *SD = nullptr) - : MCFragment(FType, SD), BundlePadding(0) {} + MCEncodedFragment(MCFragment::FragmentType FType, MCSection *Sec = nullptr) + : MCFragment(FType, Sec), BundlePadding(0) {} ~MCEncodedFragment() override; virtual SmallVectorImpl &getContents() = 0; @@ -170,8 +172,8 @@ class MCEncodedFragmentWithFixups : public MCEncodedFragment { public: MCEncodedFragmentWithFixups(MCFragment::FragmentType FType, - MCSectionData *SD = nullptr) - : MCEncodedFragment(FType, SD) {} + MCSection *Sec = nullptr) + : MCEncodedFragment(FType, Sec) {} ~MCEncodedFragmentWithFixups() override; @@ -209,8 +211,8 @@ class MCDataFragment : public MCEncodedFragmentWithFixups { SmallVector Fixups; public: - MCDataFragment(MCSectionData *SD = nullptr) - : MCEncodedFragmentWithFixups(FT_Data, SD), HasInstructions(false), + MCDataFragment(MCSection *Sec = nullptr) + : MCEncodedFragmentWithFixups(FT_Data, Sec), HasInstructions(false), AlignToBundleEnd(false) {} SmallVectorImpl &getContents() override { return Contents; } @@ -251,8 +253,9 @@ class MCCompactEncodedInstFragment : public MCEncodedFragment { SmallVector Contents; public: - MCCompactEncodedInstFragment(MCSectionData *SD = nullptr) - : MCEncodedFragment(FT_CompactEncodedInst, SD), AlignToBundleEnd(false) {} + MCCompactEncodedInstFragment(MCSection *Sec = nullptr) + : MCEncodedFragment(FT_CompactEncodedInst, Sec), AlignToBundleEnd(false) { + } bool hasInstructions() const override { return true; } @@ -289,8 +292,8 @@ class MCRelaxableFragment : public MCEncodedFragmentWithFixups { public: MCRelaxableFragment(const MCInst &Inst, const MCSubtargetInfo &STI, - MCSectionData *SD = nullptr) - : MCEncodedFragmentWithFixups(FT_Relaxable, SD), Inst(Inst), STI(STI) {} + MCSection *Sec = nullptr) + : MCEncodedFragmentWithFixups(FT_Relaxable, Sec), Inst(Inst), STI(STI) {} SmallVectorImpl &getContents() override { return Contents; } const SmallVectorImpl &getContents() const override { return Contents; } @@ -340,8 +343,8 @@ class MCAlignFragment : public MCFragment { public: MCAlignFragment(unsigned Alignment, int64_t Value, unsigned ValueSize, - unsigned MaxBytesToEmit, MCSectionData *SD = nullptr) - : MCFragment(FT_Align, SD), Alignment(Alignment), Value(Value), + unsigned MaxBytesToEmit, MCSection *Sec = nullptr) + : MCFragment(FT_Align, Sec), Alignment(Alignment), Value(Value), ValueSize(ValueSize), MaxBytesToEmit(MaxBytesToEmit), EmitNops(false) {} /// \name Accessors @@ -380,8 +383,8 @@ class MCFillFragment : public MCFragment { public: MCFillFragment(int64_t Value, unsigned ValueSize, uint64_t Size, - MCSectionData *SD = nullptr) - : MCFragment(FT_Fill, SD), Value(Value), ValueSize(ValueSize), + MCSection *Sec = nullptr) + : MCFragment(FT_Fill, Sec), Value(Value), ValueSize(ValueSize), Size(Size) { assert((!ValueSize || (Size % ValueSize) == 0) && "Fill size must be a multiple of the value size!"); @@ -413,8 +416,8 @@ class MCOrgFragment : public MCFragment { int8_t Value; public: - MCOrgFragment(const MCExpr &Offset, int8_t Value, MCSectionData *SD = nullptr) - : MCFragment(FT_Org, SD), Offset(&Offset), Value(Value) {} + MCOrgFragment(const MCExpr &Offset, int8_t Value, MCSection *Sec = nullptr) + : MCFragment(FT_Org, Sec), Offset(&Offset), Value(Value) {} /// \name Accessors /// @{ @@ -442,9 +445,8 @@ class MCLEBFragment : public MCFragment { SmallString<8> Contents; public: - MCLEBFragment(const MCExpr &Value_, bool IsSigned_, - MCSectionData *SD = nullptr) - : MCFragment(FT_LEB, SD), Value(&Value_), IsSigned(IsSigned_) { + MCLEBFragment(const MCExpr &Value_, bool IsSigned_, MCSection *Sec = nullptr) + : MCFragment(FT_LEB, Sec), Value(&Value_), IsSigned(IsSigned_) { Contents.push_back(0); } @@ -480,8 +482,8 @@ class MCDwarfLineAddrFragment : public MCFragment { public: MCDwarfLineAddrFragment(int64_t LineDelta, const MCExpr &AddrDelta, - MCSectionData *SD = nullptr) - : MCFragment(FT_Dwarf, SD), LineDelta(LineDelta), AddrDelta(&AddrDelta) { + MCSection *Sec = nullptr) + : MCFragment(FT_Dwarf, Sec), LineDelta(LineDelta), AddrDelta(&AddrDelta) { Contents.push_back(0); } @@ -512,8 +514,8 @@ class MCDwarfCallFrameFragment : public MCFragment { SmallString<8> Contents; public: - MCDwarfCallFrameFragment(const MCExpr &AddrDelta, MCSectionData *SD = nullptr) - : MCFragment(FT_DwarfFrame, SD), AddrDelta(&AddrDelta) { + MCDwarfCallFrameFragment(const MCExpr &AddrDelta, MCSection *Sec = nullptr) + : MCFragment(FT_DwarfFrame, Sec), AddrDelta(&AddrDelta) { Contents.push_back(0); } diff --git a/include/llvm/MC/MCObjectStreamer.h b/include/llvm/MC/MCObjectStreamer.h index 71edf589b02..b35eb862991 100644 --- a/include/llvm/MC/MCObjectStreamer.h +++ b/include/llvm/MC/MCObjectStreamer.h @@ -74,7 +74,7 @@ protected: void insert(MCFragment *F) { flushPendingLabels(F); CurSectionData->getFragmentList().insert(CurInsertionPoint, F); - F->setParent(CurSectionData); + F->setParent(&CurSectionData->getSection()); } /// Get a data fragment to write into, creating a new one if the current diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index fe4e22d2104..1d8f70309a1 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -272,7 +272,7 @@ MCFragment::MCFragment() : Kind(FragmentType(~0)) { MCFragment::~MCFragment() { } -MCFragment::MCFragment(FragmentType Kind, MCSectionData *Parent) +MCFragment::MCFragment(FragmentType Kind, MCSection *Parent) : Kind(Kind), Parent(Parent), Atom(nullptr), Offset(~UINT64_C(0)) { if (Parent) Parent->getFragmentList().push_back(this); @@ -317,7 +317,7 @@ MCSectionData::getSubsectionInsertionPoint(unsigned Subsection) { MCFragment *F = new MCDataFragment(); SubsectionFragmentMap.insert(MI, std::make_pair(Subsection, F)); getFragmentList().insert(IP, F); - F->setParent(this); + F->setParent(&getSection()); } return IP; @@ -859,7 +859,7 @@ void MCAssembler::Finish() { // Create dummy fragments to eliminate any empty sections, this simplifies // layout. if (it->getFragmentList().empty()) - new MCDataFragment(&it->getSectionData()); + new MCDataFragment(&*it); it->setOrdinal(SectionIndex++); } diff --git a/lib/MC/MCELFStreamer.cpp b/lib/MC/MCELFStreamer.cpp index 23546cc085d..cad5d93e459 100644 --- a/lib/MC/MCELFStreamer.cpp +++ b/lib/MC/MCELFStreamer.cpp @@ -644,9 +644,10 @@ void MCELFStreamer::Flush() { MCSection &Section = Symbol.getSection(); MCSectionData &SectData = getAssembler().getOrCreateSectionData(Section); - new MCAlignFragment(ByteAlignment, 0, 1, ByteAlignment, &SectData); + new MCAlignFragment(ByteAlignment, 0, 1, ByteAlignment, + &SectData.getSection()); - MCFragment *F = new MCFillFragment(0, 0, Size, &SectData); + MCFragment *F = new MCFillFragment(0, 0, Size, &SectData.getSection()); Symbol.getData().setFragment(F); // Update the maximum alignment of the section if necessary. diff --git a/lib/MC/MCMachOStreamer.cpp b/lib/MC/MCMachOStreamer.cpp index 3742a733d26..8fb9711178a 100644 --- a/lib/MC/MCMachOStreamer.cpp +++ b/lib/MC/MCMachOStreamer.cpp @@ -418,9 +418,10 @@ void MCMachOStreamer::EmitZerofill(MCSection *Section, MCSymbol *Symbol, // Emit an align fragment if necessary. if (ByteAlignment != 1) - new MCAlignFragment(ByteAlignment, 0, 0, ByteAlignment, &SectData); + new MCAlignFragment(ByteAlignment, 0, 0, ByteAlignment, + &SectData.getSection()); - MCFragment *F = new MCFillFragment(0, 0, Size, &SectData); + MCFragment *F = new MCFillFragment(0, 0, Size, &SectData.getSection()); SD.setFragment(F); AssignSection(Symbol, Section); diff --git a/lib/MC/MCObjectStreamer.cpp b/lib/MC/MCObjectStreamer.cpp index 8584a79a8d1..e6fd7adbfa9 100644 --- a/lib/MC/MCObjectStreamer.cpp +++ b/lib/MC/MCObjectStreamer.cpp @@ -43,7 +43,7 @@ void MCObjectStreamer::flushPendingLabels(MCFragment *F, uint64_t FOffset) { if (!F) { F = new MCDataFragment(); CurSectionData->getFragmentList().insert(CurInsertionPoint, F); - F->setParent(CurSectionData); + F->setParent(&CurSectionData->getSection()); } for (MCSymbolData *SD : PendingLabels) { SD->setFragment(F); diff --git a/lib/MC/WinCOFFStreamer.cpp b/lib/MC/WinCOFFStreamer.cpp index 20c909db84a..eb98eba1711 100644 --- a/lib/MC/WinCOFFStreamer.cpp +++ b/lib/MC/WinCOFFStreamer.cpp @@ -231,10 +231,10 @@ void MCWinCOFFStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, if (ByteAlignment != 1) new MCAlignFragment(ByteAlignment, /*Value=*/0, /*ValueSize=*/0, - ByteAlignment, &SectionData); + ByteAlignment, &SectionData.getSection()); - MCFillFragment *Fragment = - new MCFillFragment(/*Value=*/0, /*ValueSize=*/0, Size, &SectionData); + MCFillFragment *Fragment = new MCFillFragment( + /*Value=*/0, /*ValueSize=*/0, Size, &SectionData.getSection()); SD.setFragment(Fragment); } -- 2.34.1