[llvm] 87c73f4 - Move MCSection::printSwitchToSection to MCAsmInfo
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 26 15:42:10 PDT 2025
Author: Fangrui Song
Date: 2025-07-26T15:42:05-07:00
New Revision: 87c73f498d3e98c7b6471f81e25b7e08106053fe
URL: https://github.com/llvm/llvm-project/commit/87c73f498d3e98c7b6471f81e25b7e08106053fe
DIFF: https://github.com/llvm/llvm-project/commit/87c73f498d3e98c7b6471f81e25b7e08106053fe.diff
LOG: Move MCSection::printSwitchToSection to MCAsmInfo
This removes the only virtual function of MCSection.
NVPTXTargetStreamer::changeSection uses the MCSectionELF print method.
Change it to just print the section name.
Added:
Modified:
llvm/include/llvm/MC/MCAsmInfo.h
llvm/include/llvm/MC/MCAsmInfoCOFF.h
llvm/include/llvm/MC/MCAsmInfoDarwin.h
llvm/include/llvm/MC/MCAsmInfoELF.h
llvm/include/llvm/MC/MCAsmInfoGOFF.h
llvm/include/llvm/MC/MCAsmInfoWasm.h
llvm/include/llvm/MC/MCAsmInfoXCOFF.h
llvm/include/llvm/MC/MCSection.h
llvm/include/llvm/MC/MCSectionCOFF.h
llvm/include/llvm/MC/MCSectionELF.h
llvm/include/llvm/MC/MCSectionGOFF.h
llvm/include/llvm/MC/MCSectionMachO.h
llvm/include/llvm/MC/MCSectionWasm.h
llvm/include/llvm/MC/MCSectionXCOFF.h
llvm/include/llvm/MC/MCSymbolELF.h
llvm/lib/MC/MCAsmInfoCOFF.cpp
llvm/lib/MC/MCAsmInfoELF.cpp
llvm/lib/MC/MCAsmInfoGOFF.cpp
llvm/lib/MC/MCAsmInfoWasm.cpp
llvm/lib/MC/MCAsmInfoXCOFF.cpp
llvm/lib/MC/MCAsmStreamer.cpp
llvm/lib/MC/MCSectionMachO.cpp
llvm/lib/MC/MCStreamer.cpp
llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp
llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.h
llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.cpp
llvm/lib/Target/SystemZ/MCTargetDesc/SystemZHLASMAsmStreamer.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCAsmInfo.h b/llvm/include/llvm/MC/MCAsmInfo.h
index 402e12a3b2d65..6c12cd347901a 100644
--- a/llvm/include/llvm/MC/MCAsmInfo.h
+++ b/llvm/include/llvm/MC/MCAsmInfo.h
@@ -35,6 +35,7 @@ class MCStreamer;
class MCSubtargetInfo;
class MCSymbol;
class MCValue;
+class Triple;
class raw_ostream;
namespace WinEH {
@@ -485,6 +486,9 @@ class LLVM_ABI MCAsmInfo {
/// syntactically correct.
virtual bool isValidUnquotedName(StringRef Name) const;
+ virtual void printSwitchToSection(const MCSection &, uint32_t Subsection,
+ const Triple &, raw_ostream &) const {}
+
/// Return true if the .section directive should be omitted when
/// emitting \p SectionName. For example:
///
diff --git a/llvm/include/llvm/MC/MCAsmInfoCOFF.h b/llvm/include/llvm/MC/MCAsmInfoCOFF.h
index 631b5493b59dd..dc7832c2f9e0b 100644
--- a/llvm/include/llvm/MC/MCAsmInfoCOFF.h
+++ b/llvm/include/llvm/MC/MCAsmInfoCOFF.h
@@ -15,6 +15,8 @@ namespace llvm {
class MCAsmInfoCOFF : public MCAsmInfo {
virtual void anchor();
+ void printSwitchToSection(const MCSection &, uint32_t, const Triple &,
+ raw_ostream &) const final;
bool useCodeAlign(const MCSection &Sec) const final;
protected:
diff --git a/llvm/include/llvm/MC/MCAsmInfoDarwin.h b/llvm/include/llvm/MC/MCAsmInfoDarwin.h
index 9bc5dd7ab2f8d..12bc3e97cdae1 100644
--- a/llvm/include/llvm/MC/MCAsmInfoDarwin.h
+++ b/llvm/include/llvm/MC/MCAsmInfoDarwin.h
@@ -21,6 +21,8 @@ namespace llvm {
class MCAsmInfoDarwin : public MCAsmInfo {
public:
explicit MCAsmInfoDarwin();
+ void printSwitchToSection(const MCSection &, uint32_t, const Triple &,
+ raw_ostream &) const final;
bool useCodeAlign(const MCSection &Sec) const final;
/// True if the section is atomized using the symbols in it.
diff --git a/llvm/include/llvm/MC/MCAsmInfoELF.h b/llvm/include/llvm/MC/MCAsmInfoELF.h
index 80cbf5c16ea94..c05e4ad78ecd1 100644
--- a/llvm/include/llvm/MC/MCAsmInfoELF.h
+++ b/llvm/include/llvm/MC/MCAsmInfoELF.h
@@ -16,6 +16,8 @@ namespace llvm {
class MCAsmInfoELF : public MCAsmInfo {
virtual void anchor();
MCSection *getNonexecutableStackSection(MCContext &Ctx) const final;
+ void printSwitchToSection(const MCSection &, uint32_t, const Triple &,
+ raw_ostream &) const final;
bool useCodeAlign(const MCSection &Sec) const final;
protected:
diff --git a/llvm/include/llvm/MC/MCAsmInfoGOFF.h b/llvm/include/llvm/MC/MCAsmInfoGOFF.h
index 1f3b26311b37e..e62d2ae31ed71 100644
--- a/llvm/include/llvm/MC/MCAsmInfoGOFF.h
+++ b/llvm/include/llvm/MC/MCAsmInfoGOFF.h
@@ -19,7 +19,8 @@
namespace llvm {
class MCAsmInfoGOFF : public MCAsmInfo {
- virtual void anchor();
+ void printSwitchToSection(const MCSection &, uint32_t, const Triple &,
+ raw_ostream &) const final;
protected:
MCAsmInfoGOFF();
diff --git a/llvm/include/llvm/MC/MCAsmInfoWasm.h b/llvm/include/llvm/MC/MCAsmInfoWasm.h
index 3afc610b8b07b..d98de6c30d9cf 100644
--- a/llvm/include/llvm/MC/MCAsmInfoWasm.h
+++ b/llvm/include/llvm/MC/MCAsmInfoWasm.h
@@ -13,7 +13,8 @@
namespace llvm {
class MCAsmInfoWasm : public MCAsmInfo {
- virtual void anchor();
+ void printSwitchToSection(const MCSection &, uint32_t, const Triple &,
+ raw_ostream &) const final;
protected:
MCAsmInfoWasm();
diff --git a/llvm/include/llvm/MC/MCAsmInfoXCOFF.h b/llvm/include/llvm/MC/MCAsmInfoXCOFF.h
index 06a3fed505a8d..fd1ae82095659 100644
--- a/llvm/include/llvm/MC/MCAsmInfoXCOFF.h
+++ b/llvm/include/llvm/MC/MCAsmInfoXCOFF.h
@@ -16,6 +16,8 @@ namespace llvm {
class MCAsmInfoXCOFF : public MCAsmInfo {
protected:
MCAsmInfoXCOFF();
+ void printSwitchToSection(const MCSection &, uint32_t, const Triple &,
+ raw_ostream &) const final;
bool useCodeAlign(const MCSection &Sec) const final;
public:
diff --git a/llvm/include/llvm/MC/MCSection.h b/llvm/include/llvm/MC/MCSection.h
index 6ee2ed1e0982b..7989310e5a8f2 100644
--- a/llvm/include/llvm/MC/MCSection.h
+++ b/llvm/include/llvm/MC/MCSection.h
@@ -597,8 +597,6 @@ class LLVM_ABI MCSection {
StringRef Name;
MCSection(StringRef Name, bool IsText, bool IsBss, MCSymbol *Begin);
- // Protected non-virtual dtor prevents destroy through a base class pointer.
- ~MCSection() {}
public:
MCSection(const MCSection &) = delete;
@@ -648,10 +646,6 @@ class LLVM_ABI MCSection {
void dump(DenseMap<const MCFragment *, SmallVector<const MCSymbol *, 0>>
*FragToSyms = nullptr) const;
- virtual void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
- raw_ostream &OS,
- uint32_t Subsection) const {}
-
/// Check whether this section is "virtual", that is has no actual object
/// file contents.
bool isBssSection() const { return IsBss; }
diff --git a/llvm/include/llvm/MC/MCSectionCOFF.h b/llvm/include/llvm/MC/MCSectionCOFF.h
index 8df54a4477c74..71efc4191c286 100644
--- a/llvm/include/llvm/MC/MCSectionCOFF.h
+++ b/llvm/include/llvm/MC/MCSectionCOFF.h
@@ -51,6 +51,7 @@ class MCSectionCOFF final : public MCSection {
private:
friend class MCContext;
+ friend class MCAsmInfoCOFF;
// The storage of Name is owned by MCContext's COFFUniquingMap.
MCSectionCOFF(StringRef Name, unsigned Characteristics,
MCSymbol *COMDATSymbol, int Selection, unsigned UniqueID,
@@ -67,7 +68,7 @@ class MCSectionCOFF final : public MCSection {
public:
/// Decides whether a '.section' directive should be printed before the
/// section name
- bool shouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
+ bool shouldOmitSectionDirective(StringRef Name) const;
unsigned getCharacteristics() const { return Characteristics; }
MCSymbol *getCOMDATSymbol() const { return COMDATSymbol; }
@@ -78,10 +79,6 @@ class MCSectionCOFF final : public MCSection {
bool isUnique() const { return UniqueID != NonUniqueID; }
unsigned getUniqueID() const { return UniqueID; }
- void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
- raw_ostream &OS,
- uint32_t Subsection) const override;
-
unsigned getOrAssignWinCFISectionID(unsigned *NextID) const {
if (WinCFISectionID == ~0U)
WinCFISectionID = (*NextID)++;
diff --git a/llvm/include/llvm/MC/MCSectionELF.h b/llvm/include/llvm/MC/MCSectionELF.h
index 287b57cf6b186..f089dd9ea5af8 100644
--- a/llvm/include/llvm/MC/MCSectionELF.h
+++ b/llvm/include/llvm/MC/MCSectionELF.h
@@ -52,6 +52,7 @@ class MCSectionELF final : public MCSection {
private:
friend class MCContext;
+ friend class MCAsmInfoELF;
// The storage of Name is owned by MCContext's ELFUniquingMap.
MCSectionELF(StringRef Name, unsigned type, unsigned flags,
@@ -69,10 +70,6 @@ class MCSectionELF final : public MCSection {
}
public:
- /// Decides whether a '.section' directive should be printed before the
- /// section name
- bool shouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
-
unsigned getType() const { return Type; }
unsigned getFlags() const { return Flags; }
unsigned getEntrySize() const { return EntrySize; }
@@ -80,10 +77,6 @@ class MCSectionELF final : public MCSection {
const MCSymbolELF *getGroup() const { return Group.getPointer(); }
bool isComdat() const { return Group.getInt(); }
- void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
- raw_ostream &OS,
- uint32_t Subsection) const override;
-
bool isUnique() const { return UniqueID != NonUniqueID; }
unsigned getUniqueID() const { return UniqueID; }
diff --git a/llvm/include/llvm/MC/MCSectionGOFF.h b/llvm/include/llvm/MC/MCSectionGOFF.h
index 491e56be09cb6..2136148368fbd 100644
--- a/llvm/include/llvm/MC/MCSectionGOFF.h
+++ b/llvm/include/llvm/MC/MCSectionGOFF.h
@@ -52,6 +52,7 @@ class LLVM_ABI MCSectionGOFF final : public MCSection {
mutable unsigned Emitted : 1;
friend class MCContext;
+ friend class MCAsmInfoGOFF;
friend class MCSymbolGOFF;
MCSectionGOFF(StringRef Name, SectionKind K, bool IsVirtual,
@@ -73,10 +74,6 @@ class LLVM_ABI MCSectionGOFF final : public MCSection {
IsBSS(K.isBSS()), RequiresNonZeroLength(0), Emitted(0) {}
public:
- void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
- raw_ostream &OS,
- uint32_t Subsection) const override;
-
// Return the parent section.
MCSectionGOFF *getParent() const { return Parent; }
diff --git a/llvm/include/llvm/MC/MCSectionMachO.h b/llvm/include/llvm/MC/MCSectionMachO.h
index 1588847e450e5..a65d7e0b47874 100644
--- a/llvm/include/llvm/MC/MCSectionMachO.h
+++ b/llvm/include/llvm/MC/MCSectionMachO.h
@@ -23,6 +23,8 @@ namespace llvm {
/// This represents a section on a Mach-O system (used by Mac OS X). On a Mac
/// system, these are also described in /usr/include/mach-o/loader.h.
class LLVM_ABI MCSectionMachO final : public MCSection {
+ friend class MCContext;
+ friend class MCAsmInfoDarwin;
char SegmentName[16]; // Not necessarily null terminated!
/// This is the SECTION_TYPE and SECTION_ATTRIBUTES field of a section, drawn
@@ -42,7 +44,6 @@ class LLVM_ABI MCSectionMachO final : public MCSection {
MCSectionMachO(StringRef Segment, StringRef Section, unsigned TAA,
unsigned reserved2, SectionKind K, MCSymbol *Begin);
- friend class MCContext;
public:
StringRef getSegmentName() const {
@@ -76,10 +77,6 @@ class LLVM_ABI MCSectionMachO final : public MCSection {
bool &TAAParsed, // Out.
unsigned &StubSize); // Out.
- void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
- raw_ostream &OS,
- uint32_t Subsection) const override;
-
void allocAtoms();
const MCSymbol *getAtom(size_t I) const;
void setAtom(size_t I, const MCSymbol *Sym);
diff --git a/llvm/include/llvm/MC/MCSectionWasm.h b/llvm/include/llvm/MC/MCSectionWasm.h
index 86f1418f2aca9..5ec01edf196cd 100644
--- a/llvm/include/llvm/MC/MCSectionWasm.h
+++ b/llvm/include/llvm/MC/MCSectionWasm.h
@@ -49,6 +49,7 @@ class MCSectionWasm final : public MCSection {
// The storage of Name is owned by MCContext's WasmUniquingMap.
friend class MCContext;
+ friend class MCAsmInfoWasm;
MCSectionWasm(StringRef Name, SectionKind K, unsigned SegmentFlags,
const MCSymbolWasm *Group, unsigned UniqueID, MCSymbol *Begin)
: MCSection(Name, K.isText(), /*IsVirtual=*/false, Begin),
@@ -57,17 +58,9 @@ class MCSectionWasm final : public MCSection {
IsMetadata(K.isMetadata()), SegmentFlags(SegmentFlags) {}
public:
- /// Decides whether a '.section' directive should be printed before the
- /// section name
- bool shouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
-
const MCSymbolWasm *getGroup() const { return Group; }
unsigned getSegmentFlags() const { return SegmentFlags; }
- void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
- raw_ostream &OS,
- uint32_t Subsection) const override;
-
bool isWasmData() const { return IsWasmData; }
bool isMetadata() const { return IsMetadata; }
diff --git a/llvm/include/llvm/MC/MCSectionXCOFF.h b/llvm/include/llvm/MC/MCSectionXCOFF.h
index ca0946c849b61..0571f95d9be21 100644
--- a/llvm/include/llvm/MC/MCSectionXCOFF.h
+++ b/llvm/include/llvm/MC/MCSectionXCOFF.h
@@ -31,6 +31,7 @@ namespace llvm {
// implemented yet.
class MCSectionXCOFF final : public MCSection {
friend class MCContext;
+ friend class MCAsmInfoXCOFF;
std::optional<XCOFF::CsectProperties> CsectProp;
MCSymbolXCOFF *const QualName;
@@ -111,9 +112,6 @@ class MCSectionXCOFF final : public MCSection {
}
MCSymbolXCOFF *getQualNameSymbol() const { return QualName; }
- void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
- raw_ostream &OS,
- uint32_t Subsection) const override;
StringRef getSymbolTableName() const { return SymbolTableName; }
void setSymbolTableName(StringRef STN) { SymbolTableName = STN; }
bool isMultiSymbolsAllowed() const { return MultiSymbolsAllowed; }
diff --git a/llvm/include/llvm/MC/MCSymbolELF.h b/llvm/include/llvm/MC/MCSymbolELF.h
index eba99647de939..7c271e777012f 100644
--- a/llvm/include/llvm/MC/MCSymbolELF.h
+++ b/llvm/include/llvm/MC/MCSymbolELF.h
@@ -13,6 +13,7 @@
namespace llvm {
class MCSymbolELF : public MCSymbol {
+ friend class MCAsmInfoELF;
/// An expression describing how to calculate the size of a symbol. If a
/// symbol has no size this field will be NULL.
const MCExpr *SymbolSize = nullptr;
diff --git a/llvm/lib/MC/MCAsmInfoCOFF.cpp b/llvm/lib/MC/MCAsmInfoCOFF.cpp
index 1abe7e1d994b8..54717df6c2760 100644
--- a/llvm/lib/MC/MCAsmInfoCOFF.cpp
+++ b/llvm/lib/MC/MCAsmInfoCOFF.cpp
@@ -75,10 +75,7 @@ MCAsmInfoGNUCOFF::MCAsmInfoGNUCOFF() {
HasCOFFComdatConstants = false;
}
-// shouldOmitSectionDirective - Decides whether a '.section' directive
-// should be printed before the section name
-bool MCSectionCOFF::shouldOmitSectionDirective(StringRef Name,
- const MCAsmInfo &MAI) const {
+bool MCSectionCOFF::shouldOmitSectionDirective(StringRef Name) const {
if (COMDATSymbol || isUnique())
return false;
@@ -95,49 +92,50 @@ void MCSectionCOFF::setSelection(int Selection) const {
Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
}
-void MCSectionCOFF::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
- raw_ostream &OS,
- uint32_t Subsection) const {
+void MCAsmInfoCOFF::printSwitchToSection(const MCSection &Section, uint32_t,
+ const Triple &T,
+ raw_ostream &OS) const {
+ auto &Sec = static_cast<const MCSectionCOFF &>(Section);
// standard sections don't require the '.section'
- if (shouldOmitSectionDirective(getName(), MAI)) {
- OS << '\t' << getName() << '\n';
+ if (Sec.shouldOmitSectionDirective(Sec.getName())) {
+ OS << '\t' << Sec.getName() << '\n';
return;
}
- OS << "\t.section\t" << getName() << ",\"";
- if (getCharacteristics() & COFF::IMAGE_SCN_CNT_INITIALIZED_DATA)
+ OS << "\t.section\t" << Sec.getName() << ",\"";
+ if (Sec.getCharacteristics() & COFF::IMAGE_SCN_CNT_INITIALIZED_DATA)
OS << 'd';
- if (getCharacteristics() & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA)
+ if (Sec.getCharacteristics() & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA)
OS << 'b';
- if (getCharacteristics() & COFF::IMAGE_SCN_MEM_EXECUTE)
+ if (Sec.getCharacteristics() & COFF::IMAGE_SCN_MEM_EXECUTE)
OS << 'x';
- if (getCharacteristics() & COFF::IMAGE_SCN_MEM_WRITE)
+ if (Sec.getCharacteristics() & COFF::IMAGE_SCN_MEM_WRITE)
OS << 'w';
- else if (getCharacteristics() & COFF::IMAGE_SCN_MEM_READ)
+ else if (Sec.getCharacteristics() & COFF::IMAGE_SCN_MEM_READ)
OS << 'r';
else
OS << 'y';
- if (getCharacteristics() & COFF::IMAGE_SCN_LNK_REMOVE)
+ if (Sec.getCharacteristics() & COFF::IMAGE_SCN_LNK_REMOVE)
OS << 'n';
- if (getCharacteristics() & COFF::IMAGE_SCN_MEM_SHARED)
+ if (Sec.getCharacteristics() & COFF::IMAGE_SCN_MEM_SHARED)
OS << 's';
- if ((getCharacteristics() & COFF::IMAGE_SCN_MEM_DISCARDABLE) &&
- !isImplicitlyDiscardable(getName()))
+ if ((Sec.getCharacteristics() & COFF::IMAGE_SCN_MEM_DISCARDABLE) &&
+ !Sec.isImplicitlyDiscardable(Sec.getName()))
OS << 'D';
- if (getCharacteristics() & COFF::IMAGE_SCN_LNK_INFO)
+ if (Sec.getCharacteristics() & COFF::IMAGE_SCN_LNK_INFO)
OS << 'i';
OS << '"';
// unique should be tail of .section directive.
- if (isUnique() && !COMDATSymbol)
- OS << ",unique," << UniqueID;
+ if (Sec.isUnique() && !Sec.COMDATSymbol)
+ OS << ",unique," << Sec.UniqueID;
- if (getCharacteristics() & COFF::IMAGE_SCN_LNK_COMDAT) {
- if (COMDATSymbol)
+ if (Sec.getCharacteristics() & COFF::IMAGE_SCN_LNK_COMDAT) {
+ if (Sec.COMDATSymbol)
OS << ",";
else
OS << "\n\t.linkonce\t";
- switch (Selection) {
+ switch (Sec.Selection) {
case COFF::IMAGE_COMDAT_SELECT_NODUPLICATES:
OS << "one_only";
break;
@@ -163,14 +161,14 @@ void MCSectionCOFF::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
assert(false && "unsupported COFF selection type");
break;
}
- if (COMDATSymbol) {
+ if (Sec.COMDATSymbol) {
OS << ",";
- COMDATSymbol->print(OS, &MAI);
+ Sec.COMDATSymbol->print(OS, this);
}
}
- if (isUnique() && COMDATSymbol)
- OS << ",unique," << UniqueID;
+ if (Sec.isUnique() && Sec.COMDATSymbol)
+ OS << ",unique," << Sec.UniqueID;
OS << '\n';
}
diff --git a/llvm/lib/MC/MCAsmInfoELF.cpp b/llvm/lib/MC/MCAsmInfoELF.cpp
index 7f0ed815267bd..cdae9d7860f33 100644
--- a/llvm/lib/MC/MCAsmInfoELF.cpp
+++ b/llvm/lib/MC/MCAsmInfoELF.cpp
@@ -46,16 +46,6 @@ MCAsmInfoELF::MCAsmInfoELF() {
PrivateLabelPrefix = ".L";
}
-// Decides whether a '.section' directive
-// should be printed before the section name.
-bool MCSectionELF::shouldOmitSectionDirective(StringRef Name,
- const MCAsmInfo &MAI) const {
- if (isUnique())
- return false;
-
- return MAI.shouldOmitSectionDirective(Name);
-}
-
static void printName(raw_ostream &OS, StringRef Name) {
if (Name.find_first_not_of("0123456789_."
"abcdefghijklmnopqrstuvwxyz"
@@ -79,11 +69,12 @@ static void printName(raw_ostream &OS, StringRef Name) {
OS << '"';
}
-void MCSectionELF::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
- raw_ostream &OS,
- uint32_t Subsection) const {
- if (shouldOmitSectionDirective(getName(), MAI)) {
- OS << '\t' << getName();
+void MCAsmInfoELF::printSwitchToSection(const MCSection &Section,
+ uint32_t Subsection, const Triple &T,
+ raw_ostream &OS) const {
+ auto &Sec = static_cast<const MCSectionELF &>(Section);
+ if (!Sec.isUnique() && shouldOmitSectionDirective(Sec.getName())) {
+ OS << '\t' << Sec.getName();
if (Subsection)
OS << '\t' << Subsection;
OS << '\n';
@@ -91,69 +82,69 @@ void MCSectionELF::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
}
OS << "\t.section\t";
- printName(OS, getName());
+ printName(OS, Sec.getName());
// Handle the weird solaris syntax if desired.
- if (MAI.usesSunStyleELFSectionSwitchSyntax() && !(Flags & ELF::SHF_MERGE)) {
- if (Flags & ELF::SHF_ALLOC)
+ if (usesSunStyleELFSectionSwitchSyntax() && !(Sec.Flags & ELF::SHF_MERGE)) {
+ if (Sec.Flags & ELF::SHF_ALLOC)
OS << ",#alloc";
- if (Flags & ELF::SHF_EXECINSTR)
+ if (Sec.Flags & ELF::SHF_EXECINSTR)
OS << ",#execinstr";
- if (Flags & ELF::SHF_WRITE)
+ if (Sec.Flags & ELF::SHF_WRITE)
OS << ",#write";
- if (Flags & ELF::SHF_EXCLUDE)
+ if (Sec.Flags & ELF::SHF_EXCLUDE)
OS << ",#exclude";
- if (Flags & ELF::SHF_TLS)
+ if (Sec.Flags & ELF::SHF_TLS)
OS << ",#tls";
OS << '\n';
return;
}
OS << ",\"";
- if (Flags & ELF::SHF_ALLOC)
+ if (Sec.Flags & ELF::SHF_ALLOC)
OS << 'a';
- if (Flags & ELF::SHF_EXCLUDE)
+ if (Sec.Flags & ELF::SHF_EXCLUDE)
OS << 'e';
- if (Flags & ELF::SHF_EXECINSTR)
+ if (Sec.Flags & ELF::SHF_EXECINSTR)
OS << 'x';
- if (Flags & ELF::SHF_WRITE)
+ if (Sec.Flags & ELF::SHF_WRITE)
OS << 'w';
- if (Flags & ELF::SHF_MERGE)
+ if (Sec.Flags & ELF::SHF_MERGE)
OS << 'M';
- if (Flags & ELF::SHF_STRINGS)
+ if (Sec.Flags & ELF::SHF_STRINGS)
OS << 'S';
- if (Flags & ELF::SHF_TLS)
+ if (Sec.Flags & ELF::SHF_TLS)
OS << 'T';
- if (Flags & ELF::SHF_LINK_ORDER)
+ if (Sec.Flags & ELF::SHF_LINK_ORDER)
OS << 'o';
- if (Flags & ELF::SHF_GROUP)
+ if (Sec.Flags & ELF::SHF_GROUP)
OS << 'G';
- if (Flags & ELF::SHF_GNU_RETAIN)
+ if (Sec.Flags & ELF::SHF_GNU_RETAIN)
OS << 'R';
// If there are os-specific flags, print them.
if (T.isOSSolaris())
- if (Flags & ELF::SHF_SUNW_NODISCARD)
+ if (Sec.Flags & ELF::SHF_SUNW_NODISCARD)
OS << 'R';
- // If there are target-specific flags, print them.
+ // If there are tarSec.get-specific flags, print them.
Triple::ArchType Arch = T.getArch();
if (Arch == Triple::xcore) {
- if (Flags & ELF::XCORE_SHF_CP_SECTION)
+ if (Sec.Flags & ELF::XCORE_SHF_CP_SECTION)
OS << 'c';
- if (Flags & ELF::XCORE_SHF_DP_SECTION)
+ if (Sec.Flags & ELF::XCORE_SHF_DP_SECTION)
OS << 'd';
} else if (T.isARM() || T.isThumb()) {
- if (Flags & ELF::SHF_ARM_PURECODE)
+ if (Sec.Flags & ELF::SHF_ARM_PURECODE)
OS << 'y';
} else if (T.isAArch64()) {
- if (Flags & ELF::SHF_AARCH64_PURECODE)
+ if (Sec.Flags & ELF::SHF_AARCH64_PURECODE)
OS << 'y';
} else if (Arch == Triple::hexagon) {
- if (Flags & ELF::SHF_HEX_GPREL)
+ if (Sec.Flags & ELF::SHF_HEX_GPREL)
OS << 's';
} else if (Arch == Triple::x86_64) {
- if (Flags & ELF::SHF_X86_64_LARGE)
+ if (Sec.Flags & ELF::SHF_X86_64_LARGE)
OS << 'l';
}
@@ -162,74 +153,75 @@ void MCSectionELF::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
OS << ',';
// If comment string is '@', e.g. as on ARM - use '%' instead
- if (MAI.getCommentString()[0] == '@')
+ if (getCommentString()[0] == '@')
OS << '%';
else
OS << '@';
- if (Type == ELF::SHT_INIT_ARRAY)
+ if (Sec.Type == ELF::SHT_INIT_ARRAY)
OS << "init_array";
- else if (Type == ELF::SHT_FINI_ARRAY)
+ else if (Sec.Type == ELF::SHT_FINI_ARRAY)
OS << "fini_array";
- else if (Type == ELF::SHT_PREINIT_ARRAY)
+ else if (Sec.Type == ELF::SHT_PREINIT_ARRAY)
OS << "preinit_array";
- else if (Type == ELF::SHT_NOBITS)
+ else if (Sec.Type == ELF::SHT_NOBITS)
OS << "nobits";
- else if (Type == ELF::SHT_NOTE)
+ else if (Sec.Type == ELF::SHT_NOTE)
OS << "note";
- else if (Type == ELF::SHT_PROGBITS)
+ else if (Sec.Type == ELF::SHT_PROGBITS)
OS << "progbits";
- else if (Type == ELF::SHT_X86_64_UNWIND)
+ else if (Sec.Type == ELF::SHT_X86_64_UNWIND)
OS << "unwind";
- else if (Type == ELF::SHT_MIPS_DWARF)
+ else if (Sec.Type == ELF::SHT_MIPS_DWARF)
// Print hex value of the flag while we do not have
// any standard symbolic representation of the flag.
OS << "0x7000001e";
- else if (Type == ELF::SHT_LLVM_ODRTAB)
+ else if (Sec.Type == ELF::SHT_LLVM_ODRTAB)
OS << "llvm_odrtab";
- else if (Type == ELF::SHT_LLVM_LINKER_OPTIONS)
+ else if (Sec.Type == ELF::SHT_LLVM_LINKER_OPTIONS)
OS << "llvm_linker_options";
- else if (Type == ELF::SHT_LLVM_CALL_GRAPH_PROFILE)
+ else if (Sec.Type == ELF::SHT_LLVM_CALL_GRAPH_PROFILE)
OS << "llvm_call_graph_profile";
- else if (Type == ELF::SHT_LLVM_DEPENDENT_LIBRARIES)
+ else if (Sec.Type == ELF::SHT_LLVM_DEPENDENT_LIBRARIES)
OS << "llvm_dependent_libraries";
- else if (Type == ELF::SHT_LLVM_SYMPART)
+ else if (Sec.Type == ELF::SHT_LLVM_SYMPART)
OS << "llvm_sympart";
- else if (Type == ELF::SHT_LLVM_BB_ADDR_MAP)
+ else if (Sec.Type == ELF::SHT_LLVM_BB_ADDR_MAP)
OS << "llvm_bb_addr_map";
- else if (Type == ELF::SHT_LLVM_OFFLOADING)
+ else if (Sec.Type == ELF::SHT_LLVM_OFFLOADING)
OS << "llvm_offloading";
- else if (Type == ELF::SHT_LLVM_LTO)
+ else if (Sec.Type == ELF::SHT_LLVM_LTO)
OS << "llvm_lto";
- else if (Type == ELF::SHT_LLVM_JT_SIZES)
+ else if (Sec.Type == ELF::SHT_LLVM_JT_SIZES)
OS << "llvm_jt_sizes";
- else if (Type == ELF::SHT_LLVM_CFI_JUMP_TABLE)
+ else if (Sec.Type == ELF::SHT_LLVM_CFI_JUMP_TABLE)
OS << "llvm_cfi_jump_table";
else
- OS << "0x" << Twine::utohexstr(Type);
+ OS << "0x" << Twine::utohexstr(Sec.Type);
- if (EntrySize) {
- assert((Flags & ELF::SHF_MERGE) || Type == ELF::SHT_LLVM_CFI_JUMP_TABLE);
- OS << "," << EntrySize;
+ if (Sec.EntrySize) {
+ assert((Sec.Flags & ELF::SHF_MERGE) ||
+ Sec.Type == ELF::SHT_LLVM_CFI_JUMP_TABLE);
+ OS << "," << Sec.EntrySize;
}
- if (Flags & ELF::SHF_LINK_ORDER) {
+ if (Sec.Flags & ELF::SHF_LINK_ORDER) {
OS << ",";
- if (LinkedToSym)
- printName(OS, LinkedToSym->getName());
+ if (Sec.LinkedToSym)
+ printName(OS, Sec.LinkedToSym->getName());
else
OS << '0';
}
- if (Flags & ELF::SHF_GROUP) {
+ if (Sec.Flags & ELF::SHF_GROUP) {
OS << ",";
- printName(OS, Group.getPointer()->getName());
- if (isComdat())
+ printName(OS, Sec.Group.getPointer()->getName());
+ if (Sec.isComdat())
OS << ",comdat";
}
- if (isUnique())
- OS << ",unique," << UniqueID;
+ if (Sec.isUnique())
+ OS << ",unique," << Sec.UniqueID;
OS << '\n';
diff --git a/llvm/lib/MC/MCAsmInfoGOFF.cpp b/llvm/lib/MC/MCAsmInfoGOFF.cpp
index ebb13ee68b467..0a5d1927b1a22 100644
--- a/llvm/lib/MC/MCAsmInfoGOFF.cpp
+++ b/llvm/lib/MC/MCAsmInfoGOFF.cpp
@@ -19,8 +19,6 @@
using namespace llvm;
-void MCAsmInfoGOFF::anchor() {}
-
MCAsmInfoGOFF::MCAsmInfoGOFF() {
Data64bitsDirective = "\t.quad\t";
HasDotTypeDotSizeDirective = false;
@@ -117,41 +115,44 @@ static void emitXATTR(raw_ostream &OS, StringRef Name,
OS << '\n';
}
-void MCSectionGOFF::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
- raw_ostream &OS,
- uint32_t Subsection) const {
- switch (SymbolType) {
+void MCAsmInfoGOFF::printSwitchToSection(const MCSection &Section,
+ uint32_t Subsection, const Triple &T,
+ raw_ostream &OS) const {
+ auto &Sec =
+ const_cast<MCSectionGOFF &>(static_cast<const MCSectionGOFF &>(Section));
+ switch (Sec.SymbolType) {
case GOFF::ESD_ST_SectionDefinition: {
- OS << Name << " CSECT\n";
- Emitted = true;
+ OS << Sec.getName() << " CSECT\n";
+ Sec.Emitted = true;
break;
}
case GOFF::ESD_ST_ElementDefinition: {
- getParent()->printSwitchToSection(MAI, T, OS, Subsection);
- if (!Emitted) {
- emitCATTR(OS, Name, EDAttributes.Rmode, EDAttributes.Alignment,
- EDAttributes.LoadBehavior, GOFF::ESD_EXE_Unspecified,
- EDAttributes.IsReadOnly, 0, EDAttributes.FillByteValue,
- StringRef());
- Emitted = true;
+ printSwitchToSection(*Sec.getParent(), Subsection, T, OS);
+ if (!Sec.Emitted) {
+ emitCATTR(OS, Sec.getName(), Sec.EDAttributes.Rmode,
+ Sec.EDAttributes.Alignment, Sec.EDAttributes.LoadBehavior,
+ GOFF::ESD_EXE_Unspecified, Sec.EDAttributes.IsReadOnly, 0,
+ Sec.EDAttributes.FillByteValue, StringRef());
+ Sec.Emitted = true;
} else
- OS << Name << " CATTR\n";
+ OS << Sec.getName() << " CATTR\n";
break;
}
case GOFF::ESD_ST_PartReference: {
- MCSectionGOFF *ED = getParent();
- ED->getParent()->printSwitchToSection(MAI, T, OS, Subsection);
- if (!Emitted) {
+ MCSectionGOFF *ED = Sec.getParent();
+ printSwitchToSection(*ED->getParent(), Subsection, T, OS);
+ if (!Sec.Emitted) {
emitCATTR(OS, ED->getName(), ED->getEDAttributes().Rmode,
ED->EDAttributes.Alignment, ED->EDAttributes.LoadBehavior,
- PRAttributes.Executable, ED->EDAttributes.IsReadOnly,
- PRAttributes.SortKey, ED->EDAttributes.FillByteValue, Name);
- emitXATTR(OS, Name, PRAttributes.Linkage, PRAttributes.Executable,
- PRAttributes.BindingScope);
+ Sec.PRAttributes.Executable, ED->EDAttributes.IsReadOnly,
+ Sec.PRAttributes.SortKey, ED->EDAttributes.FillByteValue,
+ Sec.getName());
+ emitXATTR(OS, Sec.getName(), Sec.PRAttributes.Linkage,
+ Sec.PRAttributes.Executable, Sec.PRAttributes.BindingScope);
ED->Emitted = true;
- Emitted = true;
+ Sec.Emitted = true;
} else
- OS << ED->getName() << " CATTR PART(" << Name << ")\n";
+ OS << ED->getName() << " CATTR PART(" << Sec.getName() << ")\n";
break;
}
default:
diff --git a/llvm/lib/MC/MCAsmInfoWasm.cpp b/llvm/lib/MC/MCAsmInfoWasm.cpp
index ab03b09aa1cc7..5e44f48c3c082 100644
--- a/llvm/lib/MC/MCAsmInfoWasm.cpp
+++ b/llvm/lib/MC/MCAsmInfoWasm.cpp
@@ -12,13 +12,11 @@
//===----------------------------------------------------------------------===//
#include "llvm/MC/MCAsmInfoWasm.h"
-#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCSectionWasm.h"
#include "llvm/MC/MCSymbolWasm.h"
#include "llvm/Support/raw_ostream.h"
-using namespace llvm;
-void MCAsmInfoWasm::anchor() {}
+using namespace llvm;
MCAsmInfoWasm::MCAsmInfoWasm() {
HasIdentDirective = true;
@@ -28,13 +26,6 @@ MCAsmInfoWasm::MCAsmInfoWasm() {
PrivateLabelPrefix = ".L";
}
-// Decides whether a '.section' directive
-// should be printed before the section name.
-bool MCSectionWasm::shouldOmitSectionDirective(StringRef Name,
- const MCAsmInfo &MAI) const {
- return MAI.shouldOmitSectionDirective(Name);
-}
-
static void printName(raw_ostream &OS, StringRef Name) {
if (Name.find_first_not_of("0123456789_."
"abcdefghijklmnopqrstuvwxyz"
@@ -58,12 +49,12 @@ static void printName(raw_ostream &OS, StringRef Name) {
OS << '"';
}
-void MCSectionWasm::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
- raw_ostream &OS,
- uint32_t Subsection) const {
-
- if (shouldOmitSectionDirective(getName(), MAI)) {
- OS << '\t' << getName();
+void MCAsmInfoWasm::printSwitchToSection(const MCSection &Section,
+ uint32_t Subsection, const Triple &T,
+ raw_ostream &OS) const {
+ auto &Sec = static_cast<const MCSectionWasm &>(Section);
+ if (shouldOmitSectionDirective(Sec.getName())) {
+ OS << '\t' << Sec.getName();
if (Subsection)
OS << '\t' << Subsection;
OS << '\n';
@@ -71,18 +62,18 @@ void MCSectionWasm::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
}
OS << "\t.section\t";
- printName(OS, getName());
+ printName(OS, Sec.getName());
OS << ",\"";
- if (IsPassive)
+ if (Sec.IsPassive)
OS << 'p';
- if (Group)
+ if (Sec.Group)
OS << 'G';
- if (SegmentFlags & wasm::WASM_SEG_FLAG_STRINGS)
+ if (Sec.SegmentFlags & wasm::WASM_SEG_FLAG_STRINGS)
OS << 'S';
- if (SegmentFlags & wasm::WASM_SEG_FLAG_TLS)
+ if (Sec.SegmentFlags & wasm::WASM_SEG_FLAG_TLS)
OS << 'T';
- if (SegmentFlags & wasm::WASM_SEG_FLAG_RETAIN)
+ if (Sec.SegmentFlags & wasm::WASM_SEG_FLAG_RETAIN)
OS << 'R';
OS << '"';
@@ -90,21 +81,21 @@ void MCSectionWasm::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
OS << ',';
// If comment string is '@', e.g. as on ARM - use '%' instead
- if (MAI.getCommentString()[0] == '@')
+ if (getCommentString()[0] == '@')
OS << '%';
else
OS << '@';
// TODO: Print section type.
- if (Group) {
+ if (Sec.Group) {
OS << ",";
- printName(OS, Group->getName());
+ printName(OS, Sec.Group->getName());
OS << ",comdat";
}
- if (isUnique())
- OS << ",unique," << UniqueID;
+ if (Sec.isUnique())
+ OS << ",unique," << Sec.UniqueID;
OS << '\n';
diff --git a/llvm/lib/MC/MCAsmInfoXCOFF.cpp b/llvm/lib/MC/MCAsmInfoXCOFF.cpp
index 768fa6da00833..0403b4409f2ec 100644
--- a/llvm/lib/MC/MCAsmInfoXCOFF.cpp
+++ b/llvm/lib/MC/MCAsmInfoXCOFF.cpp
@@ -69,50 +69,51 @@ void MCSectionXCOFF::printCsectDirective(raw_ostream &OS) const {
OS << "\t.csect " << QualName->getName() << "," << Log2(getAlign()) << '\n';
}
-void MCSectionXCOFF::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
- raw_ostream &OS,
- uint32_t Subsection) const {
- if (getKind().isText()) {
- if (getMappingClass() != XCOFF::XMC_PR)
+void MCAsmInfoXCOFF::printSwitchToSection(const MCSection &Section, uint32_t,
+ const Triple &T,
+ raw_ostream &OS) const {
+ auto &Sec = static_cast<const MCSectionXCOFF &>(Section);
+ if (Sec.getKind().isText()) {
+ if (Sec.getMappingClass() != XCOFF::XMC_PR)
report_fatal_error("Unhandled storage-mapping class for .text csect");
- printCsectDirective(OS);
+ Sec.printCsectDirective(OS);
return;
}
- if (getKind().isReadOnly()) {
- if (getMappingClass() != XCOFF::XMC_RO &&
- getMappingClass() != XCOFF::XMC_TD)
+ if (Sec.getKind().isReadOnly()) {
+ if (Sec.getMappingClass() != XCOFF::XMC_RO &&
+ Sec.getMappingClass() != XCOFF::XMC_TD)
report_fatal_error("Unhandled storage-mapping class for .rodata csect.");
- printCsectDirective(OS);
+ Sec.printCsectDirective(OS);
return;
}
- if (getKind().isReadOnlyWithRel()) {
- if (getMappingClass() != XCOFF::XMC_RW &&
- getMappingClass() != XCOFF::XMC_RO &&
- getMappingClass() != XCOFF::XMC_TD)
+ if (Sec.getKind().isReadOnlyWithRel()) {
+ if (Sec.getMappingClass() != XCOFF::XMC_RW &&
+ Sec.getMappingClass() != XCOFF::XMC_RO &&
+ Sec.getMappingClass() != XCOFF::XMC_TD)
report_fatal_error(
"Unexepected storage-mapping class for ReadOnlyWithRel kind");
- printCsectDirective(OS);
+ Sec.printCsectDirective(OS);
return;
}
// Initialized TLS data.
- if (getKind().isThreadData()) {
+ if (Sec.getKind().isThreadData()) {
// We only expect XMC_TL here for initialized TLS data.
- if (getMappingClass() != XCOFF::XMC_TL)
+ if (Sec.getMappingClass() != XCOFF::XMC_TL)
report_fatal_error("Unhandled storage-mapping class for .tdata csect.");
- printCsectDirective(OS);
+ Sec.printCsectDirective(OS);
return;
}
- if (getKind().isData()) {
- switch (getMappingClass()) {
+ if (Sec.getKind().isData()) {
+ switch (Sec.getMappingClass()) {
case XCOFF::XMC_RW:
case XCOFF::XMC_DS:
case XCOFF::XMC_TD:
- printCsectDirective(OS);
+ Sec.printCsectDirective(OS);
break;
case XCOFF::XMC_TC:
case XCOFF::XMC_TE:
@@ -126,50 +127,50 @@ void MCSectionXCOFF::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
return;
}
- if (isCsect() && getMappingClass() == XCOFF::XMC_TD) {
- // Common csect type (uninitialized storage) does not have to print csect
- // directive for section switching unless it is local.
- if (getKind().isCommon() && !getKind().isBSSLocal())
+ if (Sec.isCsect() && Sec.getMappingClass() == XCOFF::XMC_TD) {
+ // Common csect type (uninitialized storage) does not have to print
+ // csect directive for section switching unless it is local.
+ if (Sec.getKind().isCommon() && !Sec.getKind().isBSSLocal())
return;
- assert(getKind().isBSS() && "Unexpected section kind for toc-data");
- printCsectDirective(OS);
+ assert(Sec.getKind().isBSS() && "Unexpected section kind for toc-data");
+ Sec.printCsectDirective(OS);
return;
}
// Common csect type (uninitialized storage) does not have to print csect
// directive for section switching.
- if (isCsect() && getCSectType() == XCOFF::XTY_CM) {
- assert((getMappingClass() == XCOFF::XMC_RW ||
- getMappingClass() == XCOFF::XMC_BS ||
- getMappingClass() == XCOFF::XMC_UL) &&
+ if (Sec.isCsect() && Sec.getCSectType() == XCOFF::XTY_CM) {
+ assert((Sec.getMappingClass() == XCOFF::XMC_RW ||
+ Sec.getMappingClass() == XCOFF::XMC_BS ||
+ Sec.getMappingClass() == XCOFF::XMC_UL) &&
"Generated a storage-mapping class for a common/bss/tbss csect we "
"don't "
"understand how to switch to.");
// Common symbols and local zero-initialized symbols for TLS and Non-TLS are
- // eligible for .bss/.tbss csect, getKind().isThreadBSS() is used to cover
- // TLS common and zero-initialized local symbols since linkage type (in the
- // GlobalVariable) is not accessible in this class.
- assert((getKind().isBSSLocal() || getKind().isCommon() ||
- getKind().isThreadBSS()) &&
+ // eligible for .bss/.tbss csect, getKind().isThreadBSS() is used to
+ // cover TLS common and zero-initialized local symbols since linkage type
+ // (in the GlobalVariable) is not accessible in this class.
+ assert((Sec.getKind().isBSSLocal() || Sec.getKind().isCommon() ||
+ Sec.getKind().isThreadBSS()) &&
"wrong symbol type for .bss/.tbss csect");
- // Don't have to print a directive for switching to section for commons and
- // zero-initialized TLS data. The '.comm' and '.lcomm' directives of the
+ // Don't have to print a directive for switching to section for commons
+ // and zero-initialized TLS data. The '.comm' and '.lcomm' directives of the
// variable will create the needed csect.
return;
}
// Zero-initialized TLS data with weak or external linkage are not eligible to
// be put into common csect.
- if (getKind().isThreadBSS()) {
- printCsectDirective(OS);
+ if (Sec.getKind().isThreadBSS()) {
+ Sec.printCsectDirective(OS);
return;
}
// XCOFF debug sections.
- if (getKind().isMetadata() && isDwarfSect()) {
- OS << "\n\t.dwsect " << format("0x%" PRIx32, *getDwarfSubtypeFlags())
+ if (Sec.getKind().isMetadata() && Sec.isDwarfSect()) {
+ OS << "\n\t.dwsect " << format("0x%" PRIx32, *Sec.getDwarfSubtypeFlags())
<< '\n';
- OS << getName() << ':' << '\n';
+ OS << Sec.getName() << ':' << '\n';
return;
}
diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp
index 05b386c007115..da51da4ee233d 100644
--- a/llvm/lib/MC/MCAsmStreamer.cpp
+++ b/llvm/lib/MC/MCAsmStreamer.cpp
@@ -532,8 +532,8 @@ void MCAsmStreamer::switchSection(MCSection *Section, uint32_t Subsection) {
if (MCTargetStreamer *TS = getTargetStreamer()) {
TS->changeSection(Cur.first, Section, Subsection, OS);
} else {
- Section->printSwitchToSection(*MAI, getContext().getTargetTriple(), OS,
- Subsection);
+ MAI->printSwitchToSection(*Section, Subsection,
+ getContext().getTargetTriple(), OS);
}
}
MCStreamer::switchSection(Section, Subsection);
@@ -543,7 +543,7 @@ bool MCAsmStreamer::popSection() {
if (!MCStreamer::popSection())
return false;
auto [Sec, Subsec] = getCurrentSection();
- Sec->printSwitchToSection(*MAI, getContext().getTargetTriple(), OS, Subsec);
+ MAI->printSwitchToSection(*Sec, Subsec, getContext().getTargetTriple(), OS);
return true;
}
diff --git a/llvm/lib/MC/MCSectionMachO.cpp b/llvm/lib/MC/MCSectionMachO.cpp
index 205313e0bdbf4..67c82353b2b90 100644
--- a/llvm/lib/MC/MCSectionMachO.cpp
+++ b/llvm/lib/MC/MCSectionMachO.cpp
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/MC/MCSectionMachO.h"
+#include "llvm/MC/MCAsmInfoDarwin.h"
#include "llvm/MC/SectionKind.h"
#include "llvm/Support/raw_ostream.h"
@@ -105,19 +106,20 @@ MCSectionMachO::MCSectionMachO(StringRef Segment, StringRef Section,
}
}
-void MCSectionMachO::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
- raw_ostream &OS,
- uint32_t Subsection) const {
- OS << "\t.section\t" << getSegmentName() << ',' << getName();
+void MCAsmInfoDarwin::printSwitchToSection(const MCSection &Section, uint32_t,
+ const Triple &T,
+ raw_ostream &OS) const {
+ auto &Sec = static_cast<const MCSectionMachO &>(Section);
+ OS << "\t.section\t" << Sec.getSegmentName() << ',' << Sec.getName();
// Get the section type and attributes.
- unsigned TAA = getTypeAndAttributes();
+ unsigned TAA = Sec.getTypeAndAttributes();
if (TAA == 0) {
OS << '\n';
return;
}
- MachO::SectionType SectionType = getType();
+ MachO::SectionType SectionType = Sec.getType();
assert(SectionType <= MachO::LAST_KNOWN_SECTION_TYPE &&
"Invalid SectionType specified!");
@@ -135,8 +137,8 @@ void MCSectionMachO::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
if (SectionAttrs == 0) {
// If we have a S_SYMBOL_STUBS size specified, print it along with 'none' as
// the attribute specifier.
- if (Reserved2 != 0)
- OS << ",none," << Reserved2;
+ if (Sec.Reserved2 != 0)
+ OS << ",none," << Sec.Reserved2;
OS << '\n';
return;
}
@@ -164,8 +166,8 @@ void MCSectionMachO::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
assert(SectionAttrs == 0 && "Unknown section attributes!");
// If we have a S_SYMBOL_STUBS size specified, print it.
- if (Reserved2 != 0)
- OS << ',' << Reserved2;
+ if (Sec.Reserved2 != 0)
+ OS << ',' << Sec.Reserved2;
OS << '\n';
}
diff --git a/llvm/lib/MC/MCStreamer.cpp b/llvm/lib/MC/MCStreamer.cpp
index add021bda5ba4..bc7398120096e 100644
--- a/llvm/lib/MC/MCStreamer.cpp
+++ b/llvm/lib/MC/MCStreamer.cpp
@@ -56,12 +56,11 @@ void MCTargetStreamer::finish() {}
void MCTargetStreamer::emitConstantPools() {}
-void MCTargetStreamer::changeSection(const MCSection *CurSection,
- MCSection *Section, uint32_t Subsection,
- raw_ostream &OS) {
- Section->printSwitchToSection(*Streamer.getContext().getAsmInfo(),
- Streamer.getContext().getTargetTriple(), OS,
- Subsection);
+void MCTargetStreamer::changeSection(const MCSection *, MCSection *Sec,
+ uint32_t Subsection, raw_ostream &OS) {
+ auto &MAI = *Streamer.getContext().getAsmInfo();
+ MAI.printSwitchToSection(*Sec, Subsection,
+ Streamer.getContext().getTargetTriple(), OS);
}
void MCTargetStreamer::emitDwarfFileDirective(StringRef Directive) {
diff --git a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp
index 614b3214fd275..ce9cd12e26a4a 100644
--- a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp
+++ b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp
@@ -15,8 +15,6 @@
using namespace llvm;
-void NVPTXMCAsmInfo::anchor() {}
-
NVPTXMCAsmInfo::NVPTXMCAsmInfo(const Triple &TheTriple,
const MCTargetOptions &Options) {
if (TheTriple.getArch() == Triple::nvptx64) {
diff --git a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.h b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.h
index 77c4daea2b6ab..f071406764462 100644
--- a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.h
+++ b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.h
@@ -19,8 +19,6 @@ namespace llvm {
class Triple;
class NVPTXMCAsmInfo : public MCAsmInfo {
- virtual void anchor();
-
public:
explicit NVPTXMCAsmInfo(const Triple &TheTriple,
const MCTargetOptions &Options);
diff --git a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.cpp b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.cpp
index 9f911436ff4aa..329e3b564c348 100644
--- a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.cpp
+++ b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.cpp
@@ -97,10 +97,7 @@ void NVPTXTargetStreamer::changeSection(const MCSection *CurSection,
if (isDwarfSection(FI, Section)) {
// Emit DWARF .file directives in the outermost scope.
outputDwarfFileDirectives();
- OS << "\t.section";
- Section->printSwitchToSection(*getStreamer().getContext().getAsmInfo(),
- getStreamer().getContext().getTargetTriple(),
- OS, SubSection);
+ OS << "\t.section\t" << Section->getName() << '\n';
// DWARF sections are enclosed into braces - emit the open one.
OS << "\t{\n";
HasSections = true;
diff --git a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZHLASMAsmStreamer.cpp b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZHLASMAsmStreamer.cpp
index 3ef6030ba5183..72bb37265259e 100644
--- a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZHLASMAsmStreamer.cpp
+++ b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZHLASMAsmStreamer.cpp
@@ -69,8 +69,8 @@ void SystemZHLASMAsmStreamer::EmitEOL() {
void SystemZHLASMAsmStreamer::changeSection(MCSection *Section,
uint32_t Subsection) {
- Section->printSwitchToSection(*MAI, getContext().getTargetTriple(), OS,
- Subsection);
+ MAI->printSwitchToSection(*Section, Subsection,
+ getContext().getTargetTriple(), OS);
MCStreamer::changeSection(Section, Subsection);
}
More information about the llvm-commits
mailing list