From 95f983f8239c071712cc42d0d54d3ebfa7c32a22 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sat, 22 Jun 2024 21:48:11 -0700 Subject: [MC] Change Subsection parameters from const MCExpr * to uint32_t Follow-up to 05ba5c0648ae5e80d5afce270495bf3b1eef9af4. uint32_t is preferred over const MCExpr * in the section stack uses because it should only be evaluated once. Change the paramter type to match. --- llvm/include/llvm/MC/MCContext.h | 2 +- llvm/include/llvm/MC/MCELFStreamer.h | 2 +- llvm/include/llvm/MC/MCObjectStreamer.h | 4 +- llvm/include/llvm/MC/MCSection.h | 2 +- llvm/include/llvm/MC/MCSectionCOFF.h | 2 +- llvm/include/llvm/MC/MCSectionDXContainer.h | 2 +- llvm/include/llvm/MC/MCSectionELF.h | 2 +- llvm/include/llvm/MC/MCSectionGOFF.h | 10 ++-- llvm/include/llvm/MC/MCSectionMachO.h | 2 +- llvm/include/llvm/MC/MCSectionSPIRV.h | 2 +- llvm/include/llvm/MC/MCSectionWasm.h | 2 +- llvm/include/llvm/MC/MCSectionXCOFF.h | 2 +- llvm/include/llvm/MC/MCStreamer.h | 11 ++-- llvm/include/llvm/MC/MCWasmStreamer.h | 2 +- llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 5 +- llvm/lib/MC/MCAsmStreamer.cpp | 5 +- llvm/lib/MC/MCContext.cpp | 4 +- llvm/lib/MC/MCELFStreamer.cpp | 3 +- llvm/lib/MC/MCMachOStreamer.cpp | 5 +- llvm/lib/MC/MCObjectFileInfo.cpp | 25 +++------ llvm/lib/MC/MCObjectStreamer.cpp | 11 +--- llvm/lib/MC/MCParser/ELFAsmParser.cpp | 3 +- llvm/lib/MC/MCSectionCOFF.cpp | 2 +- llvm/lib/MC/MCSectionDXContainer.cpp | 2 +- llvm/lib/MC/MCSectionELF.cpp | 11 ++-- llvm/lib/MC/MCSectionMachO.cpp | 2 +- llvm/lib/MC/MCSectionWasm.cpp | 15 ++--- llvm/lib/MC/MCSectionXCOFF.cpp | 2 +- llvm/lib/MC/MCStreamer.cpp | 65 ++++++++-------------- llvm/lib/MC/MCWasmStreamer.cpp | 3 +- .../AArch64/MCTargetDesc/AArch64ELFStreamer.cpp | 2 +- .../lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp | 2 +- .../Target/Hexagon/AsmParser/HexagonAsmParser.cpp | 3 +- .../Target/Mips/MCTargetDesc/MipsELFStreamer.cpp | 3 +- .../lib/Target/Mips/MCTargetDesc/MipsELFStreamer.h | 3 +- llvm/lib/Target/Mips/MipsAsmPrinter.cpp | 2 +- .../NVPTX/MCTargetDesc/NVPTXTargetStreamer.cpp | 3 +- .../NVPTX/MCTargetDesc/NVPTXTargetStreamer.h | 2 +- .../Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp | 3 +- .../Target/RISCV/MCTargetDesc/RISCVELFStreamer.h | 2 +- .../SPIRV/MCTargetDesc/SPIRVTargetStreamer.h | 2 +- 41 files changed, 95 insertions(+), 142 deletions(-) (limited to 'llvm') diff --git a/llvm/include/llvm/MC/MCContext.h b/llvm/include/llvm/MC/MCContext.h index 0f18ce5..69a2058 100644 --- a/llvm/include/llvm/MC/MCContext.h +++ b/llvm/include/llvm/MC/MCContext.h @@ -600,7 +600,7 @@ public: unsigned EntrySize); MCSectionGOFF *getGOFFSection(StringRef Section, SectionKind Kind, - MCSection *Parent, const MCExpr *SubsectionId); + MCSection *Parent, uint32_t Subsection = 0); MCSectionCOFF *getCOFFSection(StringRef Section, unsigned Characteristics, StringRef COMDATSymName, int Selection, diff --git a/llvm/include/llvm/MC/MCELFStreamer.h b/llvm/include/llvm/MC/MCELFStreamer.h index f96bddd7..cad1661 100644 --- a/llvm/include/llvm/MC/MCELFStreamer.h +++ b/llvm/include/llvm/MC/MCELFStreamer.h @@ -46,7 +46,7 @@ public: /// @{ void initSections(bool NoExecStack, const MCSubtargetInfo &STI) override; - void changeSection(MCSection *Section, const MCExpr *Subsection) override; + void changeSection(MCSection *Section, uint32_t Subsection) override; void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override; void emitLabelAtPos(MCSymbol *Symbol, SMLoc Loc, MCDataFragment &F, uint64_t Offset) override; diff --git a/llvm/include/llvm/MC/MCObjectStreamer.h b/llvm/include/llvm/MC/MCObjectStreamer.h index 9f6e1aa9..a9c0c71 100644 --- a/llvm/include/llvm/MC/MCObjectStreamer.h +++ b/llvm/include/llvm/MC/MCObjectStreamer.h @@ -101,7 +101,7 @@ public: MCDataFragment *getOrCreateDataFragment(const MCSubtargetInfo* STI = nullptr); protected: - bool changeSectionImpl(MCSection *Section, const MCExpr *Subsection); + bool changeSectionImpl(MCSection *Section, uint32_t Subsection); public: void visitUsedSymbol(const MCSymbol &Sym) override; @@ -122,7 +122,7 @@ public: void emitULEB128Value(const MCExpr *Value) override; void emitSLEB128Value(const MCExpr *Value) override; void emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override; - void changeSection(MCSection *Section, const MCExpr *Subsection) override; + void changeSection(MCSection *Section, uint32_t Subsection) override; void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override; /// Emit an instruction to a special fragment, because this instruction diff --git a/llvm/include/llvm/MC/MCSection.h b/llvm/include/llvm/MC/MCSection.h index 969f54c..00cb64c 100644 --- a/llvm/include/llvm/MC/MCSection.h +++ b/llvm/include/llvm/MC/MCSection.h @@ -211,7 +211,7 @@ public: virtual void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T, raw_ostream &OS, - const MCExpr *Subsection) const = 0; + uint32_t Subsection) const = 0; /// Return true if a .align directive should use "optimized nops" to fill /// instead of 0s. diff --git a/llvm/include/llvm/MC/MCSectionCOFF.h b/llvm/include/llvm/MC/MCSectionCOFF.h index c99e7d4..922ad10 100644 --- a/llvm/include/llvm/MC/MCSectionCOFF.h +++ b/llvm/include/llvm/MC/MCSectionCOFF.h @@ -73,7 +73,7 @@ public: void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T, raw_ostream &OS, - const MCExpr *Subsection) const override; + uint32_t Subsection) const override; bool useCodeAlign() const override; bool isVirtualSection() const override; StringRef getVirtualSectionKind() const override; diff --git a/llvm/include/llvm/MC/MCSectionDXContainer.h b/llvm/include/llvm/MC/MCSectionDXContainer.h index 4ef2f29..627b10c 100644 --- a/llvm/include/llvm/MC/MCSectionDXContainer.h +++ b/llvm/include/llvm/MC/MCSectionDXContainer.h @@ -28,7 +28,7 @@ class MCSectionDXContainer final : public MCSection { public: void printSwitchToSection(const MCAsmInfo &, const Triple &, raw_ostream &, - const MCExpr *) const override; + uint32_t) const override; bool useCodeAlign() const override { return false; } bool isVirtualSection() const override { return false; } }; diff --git a/llvm/include/llvm/MC/MCSectionELF.h b/llvm/include/llvm/MC/MCSectionELF.h index ff9240f..59a8966 100644 --- a/llvm/include/llvm/MC/MCSectionELF.h +++ b/llvm/include/llvm/MC/MCSectionELF.h @@ -79,7 +79,7 @@ public: void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T, raw_ostream &OS, - const MCExpr *Subsection) const override; + uint32_t Subsection) const override; bool useCodeAlign() const override; bool isVirtualSection() const override; StringRef getVirtualSectionKind() const override; diff --git a/llvm/include/llvm/MC/MCSectionGOFF.h b/llvm/include/llvm/MC/MCSectionGOFF.h index 1cc1375..abc379f 100644 --- a/llvm/include/llvm/MC/MCSectionGOFF.h +++ b/llvm/include/llvm/MC/MCSectionGOFF.h @@ -26,17 +26,17 @@ class MCExpr; class MCSectionGOFF final : public MCSection { private: MCSection *Parent; - const MCExpr *SubsectionId; + uint32_t Subsection; friend class MCContext; - MCSectionGOFF(StringRef Name, SectionKind K, MCSection *P, const MCExpr *Sub) + MCSectionGOFF(StringRef Name, SectionKind K, MCSection *P, uint32_t Sub) : MCSection(SV_GOFF, Name, K.isText(), nullptr), Parent(P), - SubsectionId(Sub) {} + Subsection(Sub) {} public: void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T, raw_ostream &OS, - const MCExpr *Subsection) const override { + uint32_t /*Subsection*/) const override { OS << "\t.section\t\"" << getName() << "\"\n"; } @@ -45,7 +45,7 @@ public: bool isVirtualSection() const override { return false; } MCSection *getParent() const { return Parent; } - const MCExpr *getSubsectionId() const { return SubsectionId; } + uint32_t getSubsection() const { return Subsection; } static bool classof(const MCSection *S) { return S->getVariant() == SV_GOFF; } }; diff --git a/llvm/include/llvm/MC/MCSectionMachO.h b/llvm/include/llvm/MC/MCSectionMachO.h index e268562..9562db0 100644 --- a/llvm/include/llvm/MC/MCSectionMachO.h +++ b/llvm/include/llvm/MC/MCSectionMachO.h @@ -73,7 +73,7 @@ public: void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T, raw_ostream &OS, - const MCExpr *Subsection) const override; + uint32_t Subsection) const override; bool useCodeAlign() const override; bool isVirtualSection() const override; diff --git a/llvm/include/llvm/MC/MCSectionSPIRV.h b/llvm/include/llvm/MC/MCSectionSPIRV.h index 0b2b15b..9e93f1a 100644 --- a/llvm/include/llvm/MC/MCSectionSPIRV.h +++ b/llvm/include/llvm/MC/MCSectionSPIRV.h @@ -31,7 +31,7 @@ public: ~MCSectionSPIRV() = default; void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T, raw_ostream &OS, - const MCExpr *Subsection) const override {} + uint32_t Subsection) const override {} bool useCodeAlign() const override { return false; } bool isVirtualSection() const override { return false; } }; diff --git a/llvm/include/llvm/MC/MCSectionWasm.h b/llvm/include/llvm/MC/MCSectionWasm.h index a94397c..3e89e7d 100644 --- a/llvm/include/llvm/MC/MCSectionWasm.h +++ b/llvm/include/llvm/MC/MCSectionWasm.h @@ -65,7 +65,7 @@ public: void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T, raw_ostream &OS, - const MCExpr *Subsection) const override; + uint32_t Subsection) const override; bool useCodeAlign() const override; bool isVirtualSection() const override; diff --git a/llvm/include/llvm/MC/MCSectionXCOFF.h b/llvm/include/llvm/MC/MCSectionXCOFF.h index 11bcfc8..1515516 100644 --- a/llvm/include/llvm/MC/MCSectionXCOFF.h +++ b/llvm/include/llvm/MC/MCSectionXCOFF.h @@ -112,7 +112,7 @@ public: void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T, raw_ostream &OS, - const MCExpr *Subsection) const override; + uint32_t Subsection) const override; bool useCodeAlign() const override; bool isVirtualSection() const override; StringRef getSymbolTableName() const { return SymbolTableName; } diff --git a/llvm/include/llvm/MC/MCStreamer.h b/llvm/include/llvm/MC/MCStreamer.h index 7faa077..490b1a8 100644 --- a/llvm/include/llvm/MC/MCStreamer.h +++ b/llvm/include/llvm/MC/MCStreamer.h @@ -116,7 +116,7 @@ public: /// This is called by popSection and switchSection, if the current /// section changes. virtual void changeSection(const MCSection *CurSection, MCSection *Section, - const MCExpr *SubSection, raw_ostream &OS); + uint32_t SubSection, raw_ostream &OS); virtual void emitValue(const MCExpr *Value); @@ -411,7 +411,7 @@ public: /// /// This is called by popSection and switchSection, if the current /// section changes. - virtual void changeSection(MCSection *, const MCExpr *); + virtual void changeSection(MCSection *, uint32_t); /// Save the current and previous section on the section stack. void pushSection() { @@ -425,15 +425,12 @@ public: /// Returns false if the stack was empty. bool popSection(); - bool subSection(const MCExpr *Subsection); - /// Set the current section where code is being emitted to \p Section. This /// is required to update CurSection. /// /// This corresponds to assembler directives like .section, .text, etc. - virtual void switchSection(MCSection *Section, - const MCExpr *Subsection = nullptr); - void switchSection(MCSection *Section, uint32_t Subsec); + virtual void switchSection(MCSection *Section, uint32_t Subsec = 0); + bool switchSection(MCSection *Section, const MCExpr *); /// Set the current section where code is being emitted to \p Section. /// This is required to update CurSection. This version does not call diff --git a/llvm/include/llvm/MC/MCWasmStreamer.h b/llvm/include/llvm/MC/MCWasmStreamer.h index 6c9687f..77b5625 100644 --- a/llvm/include/llvm/MC/MCWasmStreamer.h +++ b/llvm/include/llvm/MC/MCWasmStreamer.h @@ -40,7 +40,7 @@ public: /// \name MCStreamer Interface /// @{ - void changeSection(MCSection *Section, const MCExpr *Subsection) override; + void changeSection(MCSection *Section, uint32_t Subsection) override; void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override; void emitLabelAtPos(MCSymbol *Symbol, SMLoc Loc, MCDataFragment &F, uint64_t Offset) override; diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index b2c1750..957b283 100644 --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -2725,8 +2725,7 @@ MCSection *TargetLoweringObjectFileGOFF::getExplicitSectionGlobal( MCSection *TargetLoweringObjectFileGOFF::getSectionForLSDA( const Function &F, const MCSymbol &FnSym, const TargetMachine &TM) const { std::string Name = ".gcc_exception_table." + F.getName().str(); - return getContext().getGOFFSection(Name, SectionKind::getData(), nullptr, - nullptr); + return getContext().getGOFFSection(Name, SectionKind::getData(), nullptr, 0); } MCSection *TargetLoweringObjectFileGOFF::SelectSectionForGlobal( @@ -2734,7 +2733,7 @@ MCSection *TargetLoweringObjectFileGOFF::SelectSectionForGlobal( auto *Symbol = TM.getSymbol(GO); if (Kind.isBSS()) return getContext().getGOFFSection(Symbol->getName(), SectionKind::getBSS(), - nullptr, nullptr); + nullptr, 0); return getContext().getObjectFileInfo()->getTextSection(); } diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp index f257d0d..52719d1 100644 --- a/llvm/lib/MC/MCAsmStreamer.cpp +++ b/llvm/lib/MC/MCAsmStreamer.cpp @@ -144,7 +144,7 @@ public: /// @name MCStreamer Interface /// @{ - void changeSection(MCSection *Section, const MCExpr *Subsection) override; + void changeSection(MCSection *Section, uint32_t Subsection) override; void emitELFSymverDirective(const MCSymbol *OriginalSym, StringRef Name, bool KeepOriginalSym) override; @@ -510,8 +510,7 @@ void MCAsmStreamer::emitExplicitComments() { ExplicitCommentToEmit.clear(); } -void MCAsmStreamer::changeSection(MCSection *Section, - const MCExpr *Subsection) { +void MCAsmStreamer::changeSection(MCSection *Section, uint32_t Subsection) { assert(Section && "Cannot switch to a null section!"); if (MCTargetStreamer *TS = getTargetStreamer()) { TS->changeSection(getCurrentSectionOnly(), Section, Subsection, OS); diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp index e7fc883..5d1261a 100644 --- a/llvm/lib/MC/MCContext.cpp +++ b/llvm/lib/MC/MCContext.cpp @@ -660,7 +660,7 @@ MCContext::getELFUniqueIDForEntsize(StringRef SectionName, unsigned Flags, MCSectionGOFF *MCContext::getGOFFSection(StringRef Section, SectionKind Kind, MCSection *Parent, - const MCExpr *SubsectionId) { + uint32_t Subsection) { // Do the lookup. If we don't have a hit, return a new section. auto IterBool = GOFFUniquingMap.insert(std::make_pair(Section.str(), nullptr)); @@ -670,7 +670,7 @@ MCSectionGOFF *MCContext::getGOFFSection(StringRef Section, SectionKind Kind, StringRef CachedName = Iter->first; MCSectionGOFF *GOFFSection = new (GOFFAllocator.Allocate()) - MCSectionGOFF(CachedName, Kind, Parent, SubsectionId); + MCSectionGOFF(CachedName, Kind, Parent, Subsection); Iter->second = GOFFSection; return GOFFSection; diff --git a/llvm/lib/MC/MCELFStreamer.cpp b/llvm/lib/MC/MCELFStreamer.cpp index a478856..bf3edcc 100644 --- a/llvm/lib/MC/MCELFStreamer.cpp +++ b/llvm/lib/MC/MCELFStreamer.cpp @@ -106,8 +106,7 @@ static void setSectionAlignmentForBundling(const MCAssembler &Assembler, Section->ensureMinAlignment(Align(Assembler.getBundleAlignSize())); } -void MCELFStreamer::changeSection(MCSection *Section, - const MCExpr *Subsection) { +void MCELFStreamer::changeSection(MCSection *Section, uint32_t Subsection) { MCSection *CurSection = getCurrentSectionOnly(); if (CurSection && isBundleLocked()) report_fatal_error("Unterminated .bundle_lock when changing a section"); diff --git a/llvm/lib/MC/MCMachOStreamer.cpp b/llvm/lib/MC/MCMachOStreamer.cpp index 6b2e411..c0a36ae 100644 --- a/llvm/lib/MC/MCMachOStreamer.cpp +++ b/llvm/lib/MC/MCMachOStreamer.cpp @@ -85,7 +85,7 @@ public: /// @name MCStreamer Interface /// @{ - void changeSection(MCSection *Sect, const MCExpr *Subsect) override; + void changeSection(MCSection *Sect, uint32_t Subsect) override; void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override; void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override; void emitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol) override; @@ -163,8 +163,7 @@ static bool canGoAfterDWARF(const MCSectionMachO &MSec) { return false; } -void MCMachOStreamer::changeSection(MCSection *Section, - const MCExpr *Subsection) { +void MCMachOStreamer::changeSection(MCSection *Section, uint32_t Subsection) { // Change the section normally. bool Created = changeSectionImpl(Section, Subsection); const MCSectionMachO &MSec = *cast(Section); diff --git a/llvm/lib/MC/MCObjectFileInfo.cpp b/llvm/lib/MC/MCObjectFileInfo.cpp index 35ac307..b718053 100644 --- a/llvm/lib/MC/MCObjectFileInfo.cpp +++ b/llvm/lib/MC/MCObjectFileInfo.cpp @@ -546,25 +546,18 @@ void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) { } void MCObjectFileInfo::initGOFFMCObjectFileInfo(const Triple &T) { - TextSection = - Ctx->getGOFFSection(".text", SectionKind::getText(), nullptr, nullptr); - BSSSection = - Ctx->getGOFFSection(".bss", SectionKind::getBSS(), nullptr, nullptr); - PPA1Section = - Ctx->getGOFFSection(".ppa1", SectionKind::getMetadata(), TextSection, - MCConstantExpr::create(GOFF::SK_PPA1, *Ctx)); - PPA2Section = - Ctx->getGOFFSection(".ppa2", SectionKind::getMetadata(), TextSection, - MCConstantExpr::create(GOFF::SK_PPA2, *Ctx)); + TextSection = Ctx->getGOFFSection(".text", SectionKind::getText(), nullptr); + BSSSection = Ctx->getGOFFSection(".bss", SectionKind::getBSS(), nullptr); + PPA1Section = Ctx->getGOFFSection(".ppa1", SectionKind::getMetadata(), + TextSection, GOFF::SK_PPA1); + PPA2Section = Ctx->getGOFFSection(".ppa2", SectionKind::getMetadata(), + TextSection, GOFF::SK_PPA2); PPA2ListSection = - Ctx->getGOFFSection(".ppa2list", SectionKind::getData(), - nullptr, nullptr); + Ctx->getGOFFSection(".ppa2list", SectionKind::getData(), nullptr); - ADASection = - Ctx->getGOFFSection(".ada", SectionKind::getData(), nullptr, nullptr); - IDRLSection = - Ctx->getGOFFSection("B_IDRL", SectionKind::getData(), nullptr, nullptr); + ADASection = Ctx->getGOFFSection(".ada", SectionKind::getData(), nullptr); + IDRLSection = Ctx->getGOFFSection("B_IDRL", SectionKind::getData(), nullptr); } void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple &T) { diff --git a/llvm/lib/MC/MCObjectStreamer.cpp b/llvm/lib/MC/MCObjectStreamer.cpp index 6257ad2..25c5768 100644 --- a/llvm/lib/MC/MCObjectStreamer.cpp +++ b/llvm/lib/MC/MCObjectStreamer.cpp @@ -285,22 +285,17 @@ void MCObjectStreamer::emitWeakReference(MCSymbol *Alias, report_fatal_error("This file format doesn't support weak aliases."); } -void MCObjectStreamer::changeSection(MCSection *Section, - const MCExpr *Subsection) { +void MCObjectStreamer::changeSection(MCSection *Section, uint32_t Subsection) { changeSectionImpl(Section, Subsection); } bool MCObjectStreamer::changeSectionImpl(MCSection *Section, - const MCExpr *SubsecExpr) { + uint32_t Subsection) { assert(Section && "Cannot switch to a null section!"); getContext().clearDwarfLocSeen(); bool Created = getAssembler().registerSection(*Section); - - int64_t Subsec = 0; - if (SubsecExpr) - (void)SubsecExpr->evaluateAsAbsolute(Subsec, getAssemblerPtr()); - CurSubsectionIdx = uint32_t(Subsec); + CurSubsectionIdx = Subsection; Section->switchSubsection(CurSubsectionIdx); return Created; } diff --git a/llvm/lib/MC/MCParser/ELFAsmParser.cpp b/llvm/lib/MC/MCParser/ELFAsmParser.cpp index f1c36b2..773fce5 100644 --- a/llvm/lib/MC/MCParser/ELFAsmParser.cpp +++ b/llvm/lib/MC/MCParser/ELFAsmParser.cpp @@ -927,7 +927,8 @@ bool ELFAsmParser::ParseDirectiveSubsection(StringRef, SMLoc) { Lex(); - return getStreamer().subSection(Subsection); + return getStreamer().switchSection(getStreamer().getCurrentSectionOnly(), + Subsection); } bool ELFAsmParser::ParseDirectiveCGProfile(StringRef S, SMLoc Loc) { diff --git a/llvm/lib/MC/MCSectionCOFF.cpp b/llvm/lib/MC/MCSectionCOFF.cpp index ea0c5f0..9330c1c 100644 --- a/llvm/lib/MC/MCSectionCOFF.cpp +++ b/llvm/lib/MC/MCSectionCOFF.cpp @@ -36,7 +36,7 @@ void MCSectionCOFF::setSelection(int Selection) const { void MCSectionCOFF::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T, raw_ostream &OS, - const MCExpr *Subsection) const { + uint32_t Subsection) const { // standard sections don't require the '.section' if (shouldOmitSectionDirective(getName(), MAI)) { OS << '\t' << getName() << '\n'; diff --git a/llvm/lib/MC/MCSectionDXContainer.cpp b/llvm/lib/MC/MCSectionDXContainer.cpp index 065b506..7eee59d 100644 --- a/llvm/lib/MC/MCSectionDXContainer.cpp +++ b/llvm/lib/MC/MCSectionDXContainer.cpp @@ -12,4 +12,4 @@ using namespace llvm; void MCSectionDXContainer::printSwitchToSection(const MCAsmInfo &, const Triple &, raw_ostream &, - const MCExpr *) const {} + uint32_t) const {} diff --git a/llvm/lib/MC/MCSectionELF.cpp b/llvm/lib/MC/MCSectionELF.cpp index 6bbdef3..4f0b67b 100644 --- a/llvm/lib/MC/MCSectionELF.cpp +++ b/llvm/lib/MC/MCSectionELF.cpp @@ -52,13 +52,11 @@ static void printName(raw_ostream &OS, StringRef Name) { void MCSectionELF::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T, raw_ostream &OS, - const MCExpr *Subsection) const { + uint32_t Subsection) const { if (shouldOmitSectionDirective(getName(), MAI)) { OS << '\t' << getName(); - if (Subsection) { - OS << '\t'; - Subsection->print(OS, &MAI); - } + if (Subsection) + OS << '\t' << Subsection; OS << '\n'; return; } @@ -203,8 +201,7 @@ void MCSectionELF::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T, OS << '\n'; if (Subsection) { - OS << "\t.subsection\t"; - Subsection->print(OS, &MAI); + OS << "\t.subsection\t" << Subsection; OS << '\n'; } } diff --git a/llvm/lib/MC/MCSectionMachO.cpp b/llvm/lib/MC/MCSectionMachO.cpp index 9b7d9bf..1ac2195 100644 --- a/llvm/lib/MC/MCSectionMachO.cpp +++ b/llvm/lib/MC/MCSectionMachO.cpp @@ -106,7 +106,7 @@ MCSectionMachO::MCSectionMachO(StringRef Segment, StringRef Section, void MCSectionMachO::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T, raw_ostream &OS, - const MCExpr *Subsection) const { + uint32_t Subsection) const { OS << "\t.section\t" << getSegmentName() << ',' << getName(); // Get the section type and attributes. diff --git a/llvm/lib/MC/MCSectionWasm.cpp b/llvm/lib/MC/MCSectionWasm.cpp index e376182..d905f8f 100644 --- a/llvm/lib/MC/MCSectionWasm.cpp +++ b/llvm/lib/MC/MCSectionWasm.cpp @@ -46,14 +46,12 @@ static void printName(raw_ostream &OS, StringRef Name) { void MCSectionWasm::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T, raw_ostream &OS, - const MCExpr *Subsection) const { + uint32_t Subsection) const { if (shouldOmitSectionDirective(getName(), MAI)) { OS << '\t' << getName(); - if (Subsection) { - OS << '\t'; - Subsection->print(OS, &MAI); - } + if (Subsection) + OS << '\t' << Subsection; OS << '\n'; return; } @@ -96,11 +94,8 @@ void MCSectionWasm::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T, OS << '\n'; - if (Subsection) { - OS << "\t.subsection\t"; - Subsection->print(OS, &MAI); - OS << '\n'; - } + if (Subsection) + OS << "\t.subsection\t" << Subsection << '\n'; } bool MCSectionWasm::useCodeAlign() const { return false; } diff --git a/llvm/lib/MC/MCSectionXCOFF.cpp b/llvm/lib/MC/MCSectionXCOFF.cpp index 609ef09..e63bc92 100644 --- a/llvm/lib/MC/MCSectionXCOFF.cpp +++ b/llvm/lib/MC/MCSectionXCOFF.cpp @@ -25,7 +25,7 @@ void MCSectionXCOFF::printCsectDirective(raw_ostream &OS) const { void MCSectionXCOFF::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T, raw_ostream &OS, - const MCExpr *Subsection) const { + uint32_t Subsection) const { if (getKind().isText()) { if (getMappingClass() != XCOFF::XMC_PR) report_fatal_error("Unhandled storage-mapping class for .text csect"); diff --git a/llvm/lib/MC/MCStreamer.cpp b/llvm/lib/MC/MCStreamer.cpp index 4b86bc2..582b3a6 100644 --- a/llvm/lib/MC/MCStreamer.cpp +++ b/llvm/lib/MC/MCStreamer.cpp @@ -57,8 +57,7 @@ void MCTargetStreamer::finish() {} void MCTargetStreamer::emitConstantPools() {} void MCTargetStreamer::changeSection(const MCSection *CurSection, - MCSection *Section, - const MCExpr *Subsection, + MCSection *Section, uint32_t Subsection, raw_ostream &OS) { Section->printSwitchToSection(*Streamer.getContext().getAsmInfo(), Streamer.getContext().getTargetTriple(), OS, @@ -1218,7 +1217,7 @@ void MCStreamer::emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, Align ByteAlignment) {} void MCStreamer::emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size, Align ByteAlignment) {} -void MCStreamer::changeSection(MCSection *, const MCExpr *) {} +void MCStreamer::changeSection(MCSection *, uint32_t) {} void MCStreamer::emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) {} void MCStreamer::emitBytes(StringRef Data) {} void MCStreamer::emitBinaryData(StringRef Data) { emitBytes(Data); } @@ -1252,47 +1251,18 @@ bool MCStreamer::popSection() { MCSectionSubPair NewSec = I->first; if (NewSec.first && OldSec != NewSec) - changeSection(NewSec.first, NewSec.second ? MCConstantExpr::create( - NewSec.second, getContext()) - : nullptr); + changeSection(NewSec.first, NewSec.second); SectionStack.pop_back(); return true; } -bool MCStreamer::subSection(const MCExpr *SubsecExpr) { - if (SectionStack.empty()) - return true; - - int64_t Subsec; - if (!SubsecExpr->evaluateAsAbsolute(Subsec, getAssemblerPtr())) { - getContext().reportError(SubsecExpr->getLoc(), - "cannot evaluate subsection number"); - return true; - } - if (!isUInt<31>(Subsec)) { - getContext().reportError(SubsecExpr->getLoc(), - "subsection number " + Twine(Subsec) + - " is not within [0,2147483647]"); - return true; - } - - MCSectionSubPair CurPair = SectionStack.back().first; - SectionStack.back().second = CurPair; - SectionStack.back().first.second = Subsec; - changeSection(CurPair.first, SubsecExpr); - return false; -} - -void MCStreamer::switchSection(MCSection *Section, const MCExpr *SubsecExpr) { +void MCStreamer::switchSection(MCSection *Section, uint32_t Subsection) { assert(Section && "Cannot switch to a null section!"); MCSectionSubPair curSection = SectionStack.back().first; SectionStack.back().second = curSection; - uint32_t Subsec = 0; - if (SubsecExpr) - Subsec = cast(SubsecExpr)->getValue(); - if (MCSectionSubPair(Section, Subsec) != curSection) { - changeSection(Section, SubsecExpr); - SectionStack.back().first = MCSectionSubPair(Section, Subsec); + if (MCSectionSubPair(Section, Subsection) != curSection) { + changeSection(Section, Subsection); + SectionStack.back().first = MCSectionSubPair(Section, Subsection); assert(!Section->hasEnded() && "Section already ended"); MCSymbol *Sym = Section->getBeginSymbol(); if (Sym && !Sym->isInSection()) @@ -1300,10 +1270,23 @@ void MCStreamer::switchSection(MCSection *Section, const MCExpr *SubsecExpr) { } } -void MCStreamer::switchSection(MCSection *Section, uint32_t Subsec) { - switchSection(Section, Subsec == 0 - ? nullptr - : MCConstantExpr::create(Subsec, getContext())); +bool MCStreamer::switchSection(MCSection *Section, const MCExpr *SubsecExpr) { + int64_t Subsec = 0; + if (SubsecExpr) { + if (!SubsecExpr->evaluateAsAbsolute(Subsec, getAssemblerPtr())) { + getContext().reportError(SubsecExpr->getLoc(), + "cannot evaluate subsection number"); + return true; + } + if (!isUInt<31>(Subsec)) { + getContext().reportError(SubsecExpr->getLoc(), + "subsection number " + Twine(Subsec) + + " is not within [0,2147483647]"); + return true; + } + } + switchSection(Section, Subsec); + return false; } MCSymbol *MCStreamer::endSection(MCSection *Section) { diff --git a/llvm/lib/MC/MCWasmStreamer.cpp b/llvm/lib/MC/MCWasmStreamer.cpp index 4187de4..90039cb 100644 --- a/llvm/lib/MC/MCWasmStreamer.cpp +++ b/llvm/lib/MC/MCWasmStreamer.cpp @@ -68,8 +68,7 @@ void MCWasmStreamer::emitAssemblerFlag(MCAssemblerFlag Flag) { llvm_unreachable("invalid assembler flag!"); } -void MCWasmStreamer::changeSection(MCSection *Section, - const MCExpr *Subsection) { +void MCWasmStreamer::changeSection(MCSection *Section, uint32_t Subsection) { MCAssembler &Asm = getAssembler(); auto *SectionWasm = cast(Section); const MCSymbol *Grp = SectionWasm->getGroup(); diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp index f5bea33..b28ff9e 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp @@ -183,7 +183,7 @@ public: std::move(Emitter)), MappingSymbolCounter(0), LastEMS(EMS_None) {} - void changeSection(MCSection *Section, const MCExpr *Subsection) override { + void changeSection(MCSection *Section, uint32_t Subsection) override { // We have to keep track of the mapping symbol state of any sections we // use. Each one should start off as EMS_None, which is provided as the // default constructor by DenseMap::lookup. diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp index 655492f..2114558 100644 --- a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp +++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp @@ -479,7 +479,7 @@ public: MCObjectStreamer::emitFill(NumBytes, FillValue, Loc); } - void changeSection(MCSection *Section, const MCExpr *Subsection) override { + void changeSection(MCSection *Section, uint32_t Subsection) override { LastMappingSymbols[getCurrentSection().first] = std::move(LastEMSInfo); MCELFStreamer::changeSection(Section, Subsection); auto LastMappingSymbol = LastMappingSymbols.find(Section); diff --git a/llvm/lib/Target/Hexagon/AsmParser/HexagonAsmParser.cpp b/llvm/lib/Target/Hexagon/AsmParser/HexagonAsmParser.cpp index 092cccb..6e5e2a6 100644 --- a/llvm/lib/Target/Hexagon/AsmParser/HexagonAsmParser.cpp +++ b/llvm/lib/Target/Hexagon/AsmParser/HexagonAsmParser.cpp @@ -748,7 +748,8 @@ bool HexagonAsmParser::ParseDirectiveSubsection(SMLoc L) { Subsection = HexagonMCExpr::create( MCConstantExpr::create(8192 + Res, getContext()), getContext()); - getStreamer().subSection(Subsection); + getStreamer().switchSection(getStreamer().getCurrentSectionOnly(), + Subsection); return false; } diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp b/llvm/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp index e907e8d..f861268 100644 --- a/llvm/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp +++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp @@ -90,8 +90,7 @@ void MipsELFStreamer::emitLabel(MCSymbol *Symbol, SMLoc Loc) { Labels.push_back(Symbol); } -void MipsELFStreamer::switchSection(MCSection *Section, - const MCExpr *Subsection) { +void MipsELFStreamer::switchSection(MCSection *Section, uint32_t Subsection) { MCELFStreamer::switchSection(Section, Subsection); Labels.clear(); } diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.h b/llvm/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.h index 051806d..1e8042e 100644 --- a/llvm/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.h +++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.h @@ -50,8 +50,7 @@ public: /// Overriding this function allows us to dismiss all labels that are /// candidates for marking as microMIPS when .section directive is processed. - void switchSection(MCSection *Section, - const MCExpr *Subsection = nullptr) override; + void switchSection(MCSection *Section, uint32_t Subsection = 0) override; /// Overriding these functions allows us to dismiss all labels that are /// candidates for marking as microMIPS when .word/.long/.4byte etc diff --git a/llvm/lib/Target/Mips/MipsAsmPrinter.cpp b/llvm/lib/Target/Mips/MipsAsmPrinter.cpp index dda33f9..62dfa5f 100644 --- a/llvm/lib/Target/Mips/MipsAsmPrinter.cpp +++ b/llvm/lib/Target/Mips/MipsAsmPrinter.cpp @@ -1014,7 +1014,7 @@ void MipsAsmPrinter::EmitFPCallStub( MCSectionELF *M = OutContext.getELFSection( ".mips16.call.fp." + std::string(Symbol), ELF::SHT_PROGBITS, ELF::SHF_ALLOC | ELF::SHF_EXECINSTR); - OutStreamer->switchSection(M, nullptr); + OutStreamer->switchSection(M); // // .align 2 // diff --git a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.cpp b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.cpp index 15911f3..fc207b1 100644 --- a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.cpp +++ b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.cpp @@ -83,8 +83,7 @@ static bool isDwarfSection(const MCObjectFileInfo *FI, } void NVPTXTargetStreamer::changeSection(const MCSection *CurSection, - MCSection *Section, - const MCExpr *SubSection, + MCSection *Section, uint32_t SubSection, raw_ostream &OS) { assert(!SubSection && "SubSection is not null!"); const MCObjectFileInfo *FI = getStreamer().getContext().getObjectFileInfo(); diff --git a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.h b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.h index b0d8978..ca0d84e 100644 --- a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.h +++ b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.h @@ -43,7 +43,7 @@ public: /// functions. void emitDwarfFileDirective(StringRef Directive) override; void changeSection(const MCSection *CurSection, MCSection *Section, - const MCExpr *SubSection, raw_ostream &OS) override; + uint32_t SubSection, raw_ostream &OS) override; /// Emit the bytes in \p Data into the output. /// /// This is used to emit bytes in \p Data as sequence of .byte directives. diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp index ae7ce47..87c5a75 100644 --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp @@ -159,8 +159,7 @@ void RISCVELFStreamer::emitMappingSymbol(StringRef Name) { Symbol->setBinding(ELF::STB_LOCAL); } -void RISCVELFStreamer::changeSection(MCSection *Section, - const MCExpr *Subsection) { +void RISCVELFStreamer::changeSection(MCSection *Section, uint32_t Subsection) { // We have to keep track of the mapping symbol state of any sections we // use. Each one should start off as EMS_None, which is provided as the // default constructor by DenseMap::lookup. diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.h b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.h index 212d731..40c6b5a 100644 --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.h +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.h @@ -32,7 +32,7 @@ public: std::unique_ptr MCE) : MCELFStreamer(C, std::move(MAB), std::move(MOW), std::move(MCE)) {} - void changeSection(MCSection *Section, const MCExpr *Subsection) override; + void changeSection(MCSection *Section, uint32_t Subsection) override; void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override; void emitBytes(StringRef Data) override; void emitFill(const MCExpr &NumBytes, uint64_t FillValue, SMLoc Loc) override; diff --git a/llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVTargetStreamer.h b/llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVTargetStreamer.h index 8429586..a6dd713 100644 --- a/llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVTargetStreamer.h +++ b/llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVTargetStreamer.h @@ -21,7 +21,7 @@ public: ~SPIRVTargetStreamer() override; void changeSection(const MCSection *CurSection, MCSection *Section, - const MCExpr *SubSection, raw_ostream &OS) override {} + uint32_t SubSection, raw_ostream &OS) override {} }; } // namespace llvm -- cgit v1.1