[llvm] 95f983f - [MC] Change Subsection parameters from const MCExpr * to uint32_t
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 22 21:48:16 PDT 2024
Author: Fangrui Song
Date: 2024-06-22T21:48:11-07:00
New Revision: 95f983f8239c071712cc42d0d54d3ebfa7c32a22
URL: https://github.com/llvm/llvm-project/commit/95f983f8239c071712cc42d0d54d3ebfa7c32a22
DIFF: https://github.com/llvm/llvm-project/commit/95f983f8239c071712cc42d0d54d3ebfa7c32a22.diff
LOG: [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.
Added:
Modified:
llvm/include/llvm/MC/MCContext.h
llvm/include/llvm/MC/MCELFStreamer.h
llvm/include/llvm/MC/MCObjectStreamer.h
llvm/include/llvm/MC/MCSection.h
llvm/include/llvm/MC/MCSectionCOFF.h
llvm/include/llvm/MC/MCSectionDXContainer.h
llvm/include/llvm/MC/MCSectionELF.h
llvm/include/llvm/MC/MCSectionGOFF.h
llvm/include/llvm/MC/MCSectionMachO.h
llvm/include/llvm/MC/MCSectionSPIRV.h
llvm/include/llvm/MC/MCSectionWasm.h
llvm/include/llvm/MC/MCSectionXCOFF.h
llvm/include/llvm/MC/MCStreamer.h
llvm/include/llvm/MC/MCWasmStreamer.h
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
llvm/lib/MC/MCAsmStreamer.cpp
llvm/lib/MC/MCContext.cpp
llvm/lib/MC/MCELFStreamer.cpp
llvm/lib/MC/MCMachOStreamer.cpp
llvm/lib/MC/MCObjectFileInfo.cpp
llvm/lib/MC/MCObjectStreamer.cpp
llvm/lib/MC/MCParser/ELFAsmParser.cpp
llvm/lib/MC/MCSectionCOFF.cpp
llvm/lib/MC/MCSectionDXContainer.cpp
llvm/lib/MC/MCSectionELF.cpp
llvm/lib/MC/MCSectionMachO.cpp
llvm/lib/MC/MCSectionWasm.cpp
llvm/lib/MC/MCSectionXCOFF.cpp
llvm/lib/MC/MCStreamer.cpp
llvm/lib/MC/MCWasmStreamer.cpp
llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp
llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
llvm/lib/Target/Hexagon/AsmParser/HexagonAsmParser.cpp
llvm/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp
llvm/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.h
llvm/lib/Target/Mips/MipsAsmPrinter.cpp
llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.cpp
llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.h
llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.h
llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVTargetStreamer.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCContext.h b/llvm/include/llvm/MC/MCContext.h
index 0f18ce5df1701..69a20587eecfb 100644
--- a/llvm/include/llvm/MC/MCContext.h
+++ b/llvm/include/llvm/MC/MCContext.h
@@ -600,7 +600,7 @@ class MCContext {
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 f96bddd736533..cad1661c6dfb8 100644
--- a/llvm/include/llvm/MC/MCELFStreamer.h
+++ b/llvm/include/llvm/MC/MCELFStreamer.h
@@ -46,7 +46,7 @@ class MCELFStreamer : public MCObjectStreamer {
/// @{
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 9f6e1aa95f352..a9c0c71ae88a7 100644
--- a/llvm/include/llvm/MC/MCObjectStreamer.h
+++ b/llvm/include/llvm/MC/MCObjectStreamer.h
@@ -101,7 +101,7 @@ class MCObjectStreamer : public MCStreamer {
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 @@ class MCObjectStreamer : public MCStreamer {
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 969f54cca2382..00cb64c4ac1db 100644
--- a/llvm/include/llvm/MC/MCSection.h
+++ b/llvm/include/llvm/MC/MCSection.h
@@ -211,7 +211,7 @@ class MCSection {
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 c99e7d405d001..922ad10467ad9 100644
--- a/llvm/include/llvm/MC/MCSectionCOFF.h
+++ b/llvm/include/llvm/MC/MCSectionCOFF.h
@@ -73,7 +73,7 @@ class MCSectionCOFF final : public MCSection {
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 4ef2f29d7e67d..627b10c3a721b 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 ff9240ff4e32d..59a8966bbf544 100644
--- a/llvm/include/llvm/MC/MCSectionELF.h
+++ b/llvm/include/llvm/MC/MCSectionELF.h
@@ -79,7 +79,7 @@ class MCSectionELF final : public MCSection {
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 1cc13757abb8d..abc379f1c87fa 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 @@ class MCSectionGOFF final : public MCSection {
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 e268562786b2f..9562db0f460c3 100644
--- a/llvm/include/llvm/MC/MCSectionMachO.h
+++ b/llvm/include/llvm/MC/MCSectionMachO.h
@@ -73,7 +73,7 @@ class MCSectionMachO final : public MCSection {
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 0b2b15b4e3dcd..9e93f1a66ba28 100644
--- a/llvm/include/llvm/MC/MCSectionSPIRV.h
+++ b/llvm/include/llvm/MC/MCSectionSPIRV.h
@@ -31,7 +31,7 @@ class MCSectionSPIRV final : public MCSection {
~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 a94397c37060c..3e89e7d320f6a 100644
--- a/llvm/include/llvm/MC/MCSectionWasm.h
+++ b/llvm/include/llvm/MC/MCSectionWasm.h
@@ -65,7 +65,7 @@ class MCSectionWasm final : public MCSection {
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 11bcfc8e63a6b..15155160fafbd 100644
--- a/llvm/include/llvm/MC/MCSectionXCOFF.h
+++ b/llvm/include/llvm/MC/MCSectionXCOFF.h
@@ -112,7 +112,7 @@ class MCSectionXCOFF final : public MCSection {
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 7faa077060fff..490b1a8dd7bc1 100644
--- a/llvm/include/llvm/MC/MCStreamer.h
+++ b/llvm/include/llvm/MC/MCStreamer.h
@@ -116,7 +116,7 @@ class MCTargetStreamer {
/// 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 @@ class MCStreamer {
///
/// 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 @@ class MCStreamer {
/// 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 6c9687f3ce442..77b5625efdfe8 100644
--- a/llvm/include/llvm/MC/MCWasmStreamer.h
+++ b/llvm/include/llvm/MC/MCWasmStreamer.h
@@ -40,7 +40,7 @@ class MCWasmStreamer : public MCObjectStreamer {
/// \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 b2c1750131a2f..957b2831d308d 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 f257d0d9e83f7..52719d1f8aeb6 100644
--- a/llvm/lib/MC/MCAsmStreamer.cpp
+++ b/llvm/lib/MC/MCAsmStreamer.cpp
@@ -144,7 +144,7 @@ class MCAsmStreamer final : public MCStreamer {
/// @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 e7fc8835240ba..5d1261a342ea9 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 a478856692657..bf3edcce2e05c 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 6b2e411b61505..c0a36ae525560 100644
--- a/llvm/lib/MC/MCMachOStreamer.cpp
+++ b/llvm/lib/MC/MCMachOStreamer.cpp
@@ -85,7 +85,7 @@ class MCMachOStreamer : public MCObjectStreamer {
/// @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<MCSectionMachO>(Section);
diff --git a/llvm/lib/MC/MCObjectFileInfo.cpp b/llvm/lib/MC/MCObjectFileInfo.cpp
index 35ac307519f47..b71805387bc0a 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 6257ad24b0458..25c576865bfe2 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 f1c36b20f6eb1..773fce5f102b7 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 ea0c5f0e4e551..9330c1c2e54df 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 065b506c21ce3..7eee59d5873db 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 6bbdef3dce32a..4f0b67bfd9c45 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 9b7d9bf08fc2b..1ac21951ce33c 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 e3761820bb4c3..d905f8ff320ed 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 609ef09629304..e63bc92ee82e2 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 4b86bc2d70a2e..582b3a6c95a94 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<MCConstantExpr>(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 4187de4d5eb8e..90039cb6300c2 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<MCSectionWasm>(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 f5bea3336cbf7..b28ff9e0fd872 100644
--- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp
+++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp
@@ -183,7 +183,7 @@ class AArch64ELFStreamer : public MCELFStreamer {
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 655492f245027..2114558ef56ed 100644
--- a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
+++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
@@ -479,7 +479,7 @@ class ARMELFStreamer : public MCELFStreamer {
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 092cccbcca9c4..6e5e2a61bd77d 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 e907e8d8a7002..f861268c00158 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 051806d2cfe8f..1e8042e88c9e3 100644
--- a/llvm/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.h
+++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.h
@@ -50,8 +50,7 @@ class MipsELFStreamer : public MCELFStreamer {
/// 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 dda33f9a18087..62dfa5f711065 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 15911f35b613c..fc207b1a8871a 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 b0d8978ee6857..ca0d84ee2079a 100644
--- a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.h
+++ b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.h
@@ -43,7 +43,7 @@ class NVPTXTargetStreamer : public MCTargetStreamer {
/// 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 ae7ce476fff22..87c5a756e0258 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 212d731889f1a..40c6b5ac3dcc8 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.h
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.h
@@ -32,7 +32,7 @@ class RISCVELFStreamer : public MCELFStreamer {
std::unique_ptr<MCCodeEmitter> 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 842958695e101..a6dd7138edf30 100644
--- a/llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVTargetStreamer.h
+++ b/llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVTargetStreamer.h
@@ -21,7 +21,7 @@ class SPIRVTargetStreamer : public MCTargetStreamer {
~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
More information about the llvm-commits
mailing list