Skip to content

Commit 3aeab92

Browse files
committed
MCSection: Remove SectionVariant
The object file format specific derived classes are used in context like MCStreamer and MCObjectTargetWriter where the type is statically known. We don't use isa/dyn_cast.
1 parent 3820206 commit 3aeab92

File tree

10 files changed

+21
-41
lines changed

10 files changed

+21
-41
lines changed

llvm/include/llvm/MC/MCSection.h

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -540,17 +540,6 @@ class LLVM_ABI MCSection {
540540
friend class MCFragment;
541541
static constexpr unsigned NonUniqueID = ~0U;
542542

543-
enum SectionVariant {
544-
SV_COFF = 0,
545-
SV_ELF,
546-
SV_GOFF,
547-
SV_MachO,
548-
SV_Wasm,
549-
SV_XCOFF,
550-
SV_SPIRV,
551-
SV_DXContainer,
552-
};
553-
554543
struct iterator {
555544
MCFragment *F = nullptr;
556545
iterator() = default;
@@ -606,10 +595,8 @@ class LLVM_ABI MCSection {
606595
protected:
607596
// TODO Make Name private when possible.
608597
StringRef Name;
609-
SectionVariant Variant;
610598

611-
MCSection(SectionVariant V, StringRef Name, bool IsText, bool IsBss,
612-
MCSymbol *Begin);
599+
MCSection(StringRef Name, bool IsText, bool IsBss, MCSymbol *Begin);
613600
// Protected non-virtual dtor prevents destroy through a base class pointer.
614601
~MCSection() {}
615602

@@ -620,8 +607,6 @@ class LLVM_ABI MCSection {
620607
StringRef getName() const { return Name; }
621608
bool isText() const { return IsText; }
622609

623-
SectionVariant getVariant() const { return Variant; }
624-
625610
MCSymbol *getBeginSymbol() { return Begin; }
626611
const MCSymbol *getBeginSymbol() const {
627612
return const_cast<MCSection *>(this)->getBeginSymbol();

llvm/include/llvm/MC/MCSectionCOFF.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class MCSectionCOFF final : public MCSection {
5555
MCSectionCOFF(StringRef Name, unsigned Characteristics,
5656
MCSymbol *COMDATSymbol, int Selection, unsigned UniqueID,
5757
MCSymbol *Begin)
58-
: MCSection(SV_COFF, Name, Characteristics & COFF::IMAGE_SCN_CNT_CODE,
58+
: MCSection(Name, Characteristics & COFF::IMAGE_SCN_CNT_CODE,
5959
Characteristics & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA,
6060
Begin),
6161
Characteristics(Characteristics), COMDATSymbol(COMDATSymbol),

llvm/include/llvm/MC/MCSectionDXContainer.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ class MCSectionDXContainer final : public MCSection {
2424
friend class MCContext;
2525

2626
MCSectionDXContainer(StringRef Name, SectionKind K, MCSymbol *Begin)
27-
: MCSection(SV_DXContainer, Name, K.isText(), /*IsVirtual=*/false,
28-
Begin) {}
27+
: MCSection(Name, K.isText(), /*IsVirtual=*/false, Begin) {}
2928

3029
public:
3130
void printSwitchToSection(const MCAsmInfo &, const Triple &, raw_ostream &,

llvm/include/llvm/MC/MCSectionELF.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ class MCSectionELF final : public MCSection {
5858
unsigned entrySize, const MCSymbolELF *group, bool IsComdat,
5959
unsigned UniqueID, MCSymbol *Begin,
6060
const MCSymbolELF *LinkedToSym)
61-
: MCSection(SV_ELF, Name, flags & ELF::SHF_EXECINSTR,
62-
type == ELF::SHT_NOBITS, Begin),
61+
: MCSection(Name, flags & ELF::SHF_EXECINSTR, type == ELF::SHT_NOBITS,
62+
Begin),
6363
Type(type), Flags(flags), UniqueID(UniqueID), EntrySize(entrySize),
6464
Group(group, IsComdat), LinkedToSym(LinkedToSym) {
6565
assert((!(Flags & ELF::SHF_GROUP) || Group.getPointer()) &&

llvm/include/llvm/MC/MCSectionGOFF.h

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,21 @@ class LLVM_ABI MCSectionGOFF final : public MCSection {
5656

5757
MCSectionGOFF(StringRef Name, SectionKind K, bool IsVirtual,
5858
GOFF::SDAttr SDAttributes, MCSectionGOFF *Parent)
59-
: MCSection(SV_GOFF, Name, K.isText(), IsVirtual, nullptr),
60-
Parent(Parent), SDAttributes(SDAttributes),
61-
SymbolType(GOFF::ESD_ST_SectionDefinition), IsBSS(K.isBSS()),
62-
RequiresNonZeroLength(0), Emitted(0) {}
59+
: MCSection(Name, K.isText(), IsVirtual, nullptr), Parent(Parent),
60+
SDAttributes(SDAttributes), SymbolType(GOFF::ESD_ST_SectionDefinition),
61+
IsBSS(K.isBSS()), RequiresNonZeroLength(0), Emitted(0) {}
6362

6463
MCSectionGOFF(StringRef Name, SectionKind K, bool IsVirtual,
6564
GOFF::EDAttr EDAttributes, MCSectionGOFF *Parent)
66-
: MCSection(SV_GOFF, Name, K.isText(), IsVirtual, nullptr),
67-
Parent(Parent), EDAttributes(EDAttributes),
68-
SymbolType(GOFF::ESD_ST_ElementDefinition), IsBSS(K.isBSS()),
69-
RequiresNonZeroLength(0), Emitted(0) {}
65+
: MCSection(Name, K.isText(), IsVirtual, nullptr), Parent(Parent),
66+
EDAttributes(EDAttributes), SymbolType(GOFF::ESD_ST_ElementDefinition),
67+
IsBSS(K.isBSS()), RequiresNonZeroLength(0), Emitted(0) {}
7068

7169
MCSectionGOFF(StringRef Name, SectionKind K, bool IsVirtual,
7270
GOFF::PRAttr PRAttributes, MCSectionGOFF *Parent)
73-
: MCSection(SV_GOFF, Name, K.isText(), IsVirtual, nullptr),
74-
Parent(Parent), PRAttributes(PRAttributes),
75-
SymbolType(GOFF::ESD_ST_PartReference), IsBSS(K.isBSS()),
76-
RequiresNonZeroLength(0), Emitted(0) {}
71+
: MCSection(Name, K.isText(), IsVirtual, nullptr), Parent(Parent),
72+
PRAttributes(PRAttributes), SymbolType(GOFF::ESD_ST_PartReference),
73+
IsBSS(K.isBSS()), RequiresNonZeroLength(0), Emitted(0) {}
7774

7875
public:
7976
void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,

llvm/include/llvm/MC/MCSectionSPIRV.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class MCSectionSPIRV final : public MCSection {
2424
friend class MCContext;
2525

2626
MCSectionSPIRV()
27-
: MCSection(SV_SPIRV, "", /*IsText=*/true, /*IsVirtual=*/false,
27+
: MCSection("", /*IsText=*/true, /*IsVirtual=*/false,
2828
/*Begin=*/nullptr) {}
2929
// TODO: Add StringRef Name to MCSectionSPIRV.
3030

llvm/include/llvm/MC/MCSectionWasm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class MCSectionWasm final : public MCSection {
5151
friend class MCContext;
5252
MCSectionWasm(StringRef Name, SectionKind K, unsigned SegmentFlags,
5353
const MCSymbolWasm *Group, unsigned UniqueID, MCSymbol *Begin)
54-
: MCSection(SV_Wasm, Name, K.isText(), /*IsVirtual=*/false, Begin),
54+
: MCSection(Name, K.isText(), /*IsVirtual=*/false, Begin),
5555
UniqueID(UniqueID), Group(Group),
5656
IsWasmData(K.isReadOnly() || K.isWriteable()),
5757
IsMetadata(K.isMetadata()), SegmentFlags(SegmentFlags) {}

llvm/include/llvm/MC/MCSectionXCOFF.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class MCSectionXCOFF final : public MCSection {
4646
XCOFF::SymbolType ST, SectionKind K, MCSymbolXCOFF *QualName,
4747
MCSymbol *Begin, StringRef SymbolTableName,
4848
bool MultiSymbolsAllowed)
49-
: MCSection(SV_XCOFF, Name, K.isText(),
49+
: MCSection(Name, K.isText(),
5050
/*IsVirtual=*/ST == XCOFF::XTY_CM && SMC != XCOFF::XMC_TD,
5151
Begin),
5252
CsectProp(XCOFF::CsectProperties(SMC, ST)), QualName(QualName),
@@ -77,7 +77,7 @@ class MCSectionXCOFF final : public MCSection {
7777
XCOFF::DwarfSectionSubtypeFlags DwarfSubtypeFlags,
7878
MCSymbol *Begin, StringRef SymbolTableName,
7979
bool MultiSymbolsAllowed)
80-
: MCSection(SV_XCOFF, Name, K.isText(), /*IsVirtual=*/false, Begin),
80+
: MCSection(Name, K.isText(), /*IsVirtual=*/false, Begin),
8181
QualName(QualName), SymbolTableName(SymbolTableName),
8282
DwarfSubtypeFlags(DwarfSubtypeFlags),
8383
MultiSymbolsAllowed(MultiSymbolsAllowed), Kind(K) {

llvm/lib/MC/MCSection.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@
1818

1919
using namespace llvm;
2020

21-
MCSection::MCSection(SectionVariant V, StringRef Name, bool IsText, bool IsBss,
22-
MCSymbol *Begin)
21+
MCSection::MCSection(StringRef Name, bool IsText, bool IsBss, MCSymbol *Begin)
2322
: Begin(Begin), HasInstructions(false), IsRegistered(false), IsText(IsText),
24-
IsBss(IsBss), LinkerRelaxable(false), Name(Name), Variant(V) {
23+
IsBss(IsBss), LinkerRelaxable(false), Name(Name) {
2524
DummyFragment.setParent(this);
2625
}
2726

llvm/lib/MC/MCSectionMachO.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ ENTRY("" /*FIXME*/, S_ATTR_LOC_RELOC)
9292
MCSectionMachO::MCSectionMachO(StringRef Segment, StringRef Section,
9393
unsigned TAA, unsigned reserved2, SectionKind K,
9494
MCSymbol *Begin)
95-
: MCSection(SV_MachO, Section, K.isText(),
95+
: MCSection(Section, K.isText(),
9696
MachO::isVirtualSection(TAA & MachO::SECTION_TYPE), Begin),
9797
TypeAndAttributes(TAA), Reserved2(reserved2) {
9898
assert(Segment.size() <= 16 && Section.size() <= 16 &&

0 commit comments

Comments
 (0)