Skip to content

[MC] Remove SectionKind from MCSection #96067

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions llvm/include/llvm/MC/MCContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,7 @@ class MCContext {
unsigned Instance);

MCSectionELF *createELFSectionImpl(StringRef Section, unsigned Type,
unsigned Flags, SectionKind K,
unsigned EntrySize,
unsigned Flags, unsigned EntrySize,
const MCSymbolELF *Group, bool IsComdat,
unsigned UniqueID,
const MCSymbolELF *LinkedToSym);
Expand Down Expand Up @@ -602,13 +601,11 @@ class MCContext {
MCSection *Parent, const MCExpr *SubsectionId);

MCSectionCOFF *getCOFFSection(StringRef Section, unsigned Characteristics,
SectionKind Kind, StringRef COMDATSymName,
int Selection,
StringRef COMDATSymName, int Selection,
unsigned UniqueID = GenericSectionID,
const char *BeginSymName = nullptr);

MCSectionCOFF *getCOFFSection(StringRef Section, unsigned Characteristics,
SectionKind Kind,
const char *BeginSymName = nullptr);

/// Gets or creates a section equivalent to Sec that is associated with the
Expand Down
7 changes: 4 additions & 3 deletions llvm/include/llvm/MC/MCSection.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ class MCSection {

bool IsRegistered : 1;

bool IsText : 1;

MCDummyFragment DummyFragment;

// Mapping from subsection number to fragment list. At layout time, the
Expand All @@ -124,17 +126,16 @@ class MCSection {
// TODO Make Name private when possible.
StringRef Name;
SectionVariant Variant;
SectionKind Kind;

MCSection(SectionVariant V, StringRef Name, SectionKind K, MCSymbol *Begin);
MCSection(SectionVariant V, StringRef Name, bool IsText, MCSymbol *Begin);
~MCSection();

public:
MCSection(const MCSection &) = delete;
MCSection &operator=(const MCSection &) = delete;

StringRef getName() const { return Name; }
SectionKind getKind() const { return Kind; }
bool isText() const { return IsText; }

SectionVariant getVariant() const { return Variant; }

Expand Down
10 changes: 6 additions & 4 deletions llvm/include/llvm/MC/MCSectionCOFF.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define LLVM_MC_MCSECTIONCOFF_H

#include "llvm/ADT/StringRef.h"
#include "llvm/BinaryFormat/COFF.h"
#include "llvm/MC/MCSection.h"
#include "llvm/MC/SectionKind.h"
#include <cassert>
Expand Down Expand Up @@ -50,10 +51,11 @@ class MCSectionCOFF final : public MCSection {
friend class MCContext;
// The storage of Name is owned by MCContext's COFFUniquingMap.
MCSectionCOFF(StringRef Name, unsigned Characteristics,
MCSymbol *COMDATSymbol, int Selection, SectionKind K,
MCSymbol *Begin)
: MCSection(SV_COFF, Name, K, Begin), Characteristics(Characteristics),
COMDATSymbol(COMDATSymbol), Selection(Selection) {
MCSymbol *COMDATSymbol, int Selection, MCSymbol *Begin)
: MCSection(SV_COFF, Name, Characteristics & COFF::IMAGE_SCN_CNT_CODE,
Begin),
Characteristics(Characteristics), COMDATSymbol(COMDATSymbol),
Selection(Selection) {
assert((Characteristics & 0x00F00000) == 0 &&
"alignment must not be set upon section creation");
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/MC/MCSectionDXContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class MCSectionDXContainer final : public MCSection {
friend class MCContext;

MCSectionDXContainer(StringRef Name, SectionKind K, MCSymbol *Begin)
: MCSection(SV_DXContainer, Name, K, Begin) {}
: MCSection(SV_DXContainer, Name, K.isText(), Begin) {}

public:
void printSwitchToSection(const MCAsmInfo &, const Triple &, raw_ostream &,
Expand Down
9 changes: 5 additions & 4 deletions llvm/include/llvm/MC/MCSectionELF.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include "llvm/ADT/PointerIntPair.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/BinaryFormat/ELF.h"
#include "llvm/MC/MCSection.h"
#include "llvm/MC/MCSymbolELF.h"
#include "llvm/MC/SectionKind.h"
Expand Down Expand Up @@ -49,13 +50,13 @@ class MCSectionELF final : public MCSection {
friend class MCContext;

// The storage of Name is owned by MCContext's ELFUniquingMap.
MCSectionELF(StringRef Name, unsigned type, unsigned flags, SectionKind K,
MCSectionELF(StringRef Name, unsigned type, unsigned flags,
unsigned entrySize, const MCSymbolELF *group, bool IsComdat,
unsigned UniqueID, MCSymbol *Begin,
const MCSymbolELF *LinkedToSym)
: MCSection(SV_ELF, Name, K, Begin), Type(type), Flags(flags),
UniqueID(UniqueID), EntrySize(entrySize), Group(group, IsComdat),
LinkedToSym(LinkedToSym) {
: MCSection(SV_ELF, Name, flags & ELF::SHF_EXECINSTR, Begin), Type(type),
Flags(flags), UniqueID(UniqueID), EntrySize(entrySize),
Group(group, IsComdat), LinkedToSym(LinkedToSym) {
if (Group.getPointer())
Group.getPointer()->setIsSignature();
}
Expand Down
3 changes: 2 additions & 1 deletion llvm/include/llvm/MC/MCSectionGOFF.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class MCSectionGOFF final : public MCSection {

friend class MCContext;
MCSectionGOFF(StringRef Name, SectionKind K, MCSection *P, const MCExpr *Sub)
: MCSection(SV_GOFF, Name, K, nullptr), Parent(P), SubsectionId(Sub) {}
: MCSection(SV_GOFF, Name, K.isText(), nullptr), Parent(P),
SubsectionId(Sub) {}

public:
void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/MC/MCSectionSPIRV.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class MCSymbol;
class MCSectionSPIRV final : public MCSection {
friend class MCContext;

MCSectionSPIRV(SectionKind K, MCSymbol *Begin)
: MCSection(SV_SPIRV, "", K, Begin) {}
MCSectionSPIRV()
: MCSection(SV_SPIRV, "", /*IsText=*/true, /*Begin=*/nullptr) {}
// TODO: Add StringRef Name to MCSectionSPIRV.

public:
Expand Down
15 changes: 9 additions & 6 deletions llvm/include/llvm/MC/MCSectionWasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,20 @@ class MCSectionWasm final : public MCSection {
// For data sections, whether to use a passive segment
bool IsPassive = false;

bool IsWasmData;

bool IsMetadata;

// For data sections, bitfield of WasmSegmentFlag
unsigned SegmentFlags;

// The storage of Name is owned by MCContext's WasmUniquingMap.
friend class MCContext;
MCSectionWasm(StringRef Name, SectionKind K, unsigned SegmentFlags,
const MCSymbolWasm *Group, unsigned UniqueID, MCSymbol *Begin)
: MCSection(SV_Wasm, Name, K, Begin), UniqueID(UniqueID), Group(Group),
SegmentFlags(SegmentFlags) {}
: MCSection(SV_Wasm, Name, K.isText(), Begin), UniqueID(UniqueID),
Group(Group), IsWasmData(K.isReadOnly() || K.isWriteable()),
IsMetadata(K.isMetadata()), SegmentFlags(SegmentFlags) {}

public:
/// Decides whether a '.section' directive should be printed before the
Expand All @@ -64,10 +69,8 @@ class MCSectionWasm final : public MCSection {
bool useCodeAlign() const override;
bool isVirtualSection() const override;

bool isWasmData() const {
return Kind.isGlobalWriteableData() || Kind.isReadOnly() ||
Kind.isThreadLocal();
}
bool isWasmData() const { return IsWasmData; }
bool isMetadata() const { return IsMetadata; }

bool isUnique() const { return UniqueID != ~0U; }
unsigned getUniqueID() const { return UniqueID; }
Expand Down
10 changes: 6 additions & 4 deletions llvm/include/llvm/MC/MCSectionXCOFF.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,18 @@ class MCSectionXCOFF final : public MCSection {
StringRef SymbolTableName;
std::optional<XCOFF::DwarfSectionSubtypeFlags> DwarfSubtypeFlags;
bool MultiSymbolsAllowed;
SectionKind Kind;
static constexpr unsigned DefaultAlignVal = 4;
static constexpr unsigned DefaultTextAlignVal = 32;

MCSectionXCOFF(StringRef Name, XCOFF::StorageMappingClass SMC,
XCOFF::SymbolType ST, SectionKind K, MCSymbolXCOFF *QualName,
MCSymbol *Begin, StringRef SymbolTableName,
bool MultiSymbolsAllowed)
: MCSection(SV_XCOFF, Name, K, Begin),
: MCSection(SV_XCOFF, Name, K.isText(), Begin),
CsectProp(XCOFF::CsectProperties(SMC, ST)), QualName(QualName),
SymbolTableName(SymbolTableName), DwarfSubtypeFlags(std::nullopt),
MultiSymbolsAllowed(MultiSymbolsAllowed) {
MultiSymbolsAllowed(MultiSymbolsAllowed), Kind(K) {
assert(
(ST == XCOFF::XTY_SD || ST == XCOFF::XTY_CM || ST == XCOFF::XTY_ER) &&
"Invalid or unhandled type for csect.");
Expand All @@ -72,9 +73,9 @@ class MCSectionXCOFF final : public MCSection {
XCOFF::DwarfSectionSubtypeFlags DwarfSubtypeFlags,
MCSymbol *Begin, StringRef SymbolTableName,
bool MultiSymbolsAllowed)
: MCSection(SV_XCOFF, Name, K, Begin), QualName(QualName),
: MCSection(SV_XCOFF, Name, K.isText(), Begin), QualName(QualName),
SymbolTableName(SymbolTableName), DwarfSubtypeFlags(DwarfSubtypeFlags),
MultiSymbolsAllowed(MultiSymbolsAllowed) {
MultiSymbolsAllowed(MultiSymbolsAllowed), Kind(K) {
assert(QualName != nullptr && "QualName is needed.");

// FIXME: use a more meaningful name for non csect sections.
Expand Down Expand Up @@ -125,6 +126,7 @@ class MCSectionXCOFF final : public MCSection {
std::optional<XCOFF::CsectProperties> getCsectProp() const {
return CsectProp;
}
SectionKind getKind() const { return Kind; }
};

} // end namespace llvm
Expand Down
9 changes: 4 additions & 5 deletions llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2415,8 +2415,7 @@ bool AsmPrinter::doFinalization(Module &M) {
SectionName,
COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
COFF::IMAGE_SCN_LNK_COMDAT,
SectionKind::getReadOnly(), Stub.first->getName(),
COFF::IMAGE_COMDAT_SELECT_ANY));
Stub.first->getName(), COFF::IMAGE_COMDAT_SELECT_ANY));
emitAlignment(Align(DL.getPointerSize()));
OutStreamer->emitSymbolAttribute(Stub.first, MCSA_Global);
OutStreamer->emitLabel(Stub.first);
Expand Down Expand Up @@ -2898,8 +2897,8 @@ bool AsmPrinter::emitSpecialLLVMGlobal(const GlobalVariable *GV) {
// For ARM64EC, print the table that maps between symbols and the
// corresponding thunks to translate between x64 and AArch64 code.
// This table is generated by AArch64Arm64ECCallLowering.
OutStreamer->switchSection(OutContext.getCOFFSection(
".hybmp$x", COFF::IMAGE_SCN_LNK_INFO, SectionKind::getMetadata()));
OutStreamer->switchSection(
OutContext.getCOFFSection(".hybmp$x", COFF::IMAGE_SCN_LNK_INFO));
auto *Arr = cast<ConstantArray>(GV->getInitializer());
for (auto &U : Arr->operands()) {
auto *C = cast<Constant>(U);
Expand Down Expand Up @@ -3158,7 +3157,7 @@ void AsmPrinter::emitAlignment(Align Alignment, const GlobalObject *GV,
if (Alignment == Align(1))
return; // 1-byte aligned: no need to emit alignment.

if (getCurrentSection()->getKind().isText()) {
if (getCurrentSection()->isText()) {
const MCSubtargetInfo *STI = nullptr;
if (this->MF)
STI = &getSubtargetInfo();
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2998,8 +2998,7 @@ void DwarfDebug::emitDebugARanges() {
if (SCU.Sym->isInSection()) {
// Make a note of this symbol and it's section.
MCSection *Section = &SCU.Sym->getSection();
if (!Section->getKind().isMetadata())
SectionMap[Section].push_back(SCU);
SectionMap[Section].push_back(SCU);
} else {
// Some symbols (e.g. common/bss on mach-o) can have no section but still
// appear in the output. This sucks as we rely on sections to build
Expand Down
40 changes: 16 additions & 24 deletions llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1696,7 +1696,7 @@ MCSection *TargetLoweringObjectFileCOFF::getExplicitSectionGlobal(
}
}

return getContext().getCOFFSection(Name, Characteristics, Kind, COMDATSymName,
return getContext().getCOFFSection(Name, Characteristics, COMDATSymName,
Selection);
}

Expand Down Expand Up @@ -1755,12 +1755,12 @@ MCSection *TargetLoweringObjectFileCOFF::SelectSectionForGlobal(
if (getContext().getTargetTriple().isWindowsGNUEnvironment())
raw_svector_ostream(Name) << '$' << ComdatGV->getName();

return getContext().getCOFFSection(Name, Characteristics, Kind,
COMDATSymName, Selection, UniqueID);
return getContext().getCOFFSection(Name, Characteristics, COMDATSymName,
Selection, UniqueID);
} else {
SmallString<256> TmpData;
getMangler().getNameWithPrefix(TmpData, GO, /*CannotUsePrivateLabel=*/true);
return getContext().getCOFFSection(Name, Characteristics, Kind, TmpData,
return getContext().getCOFFSection(Name, Characteristics, TmpData,
Selection, UniqueID);
}
}
Expand Down Expand Up @@ -1817,9 +1817,9 @@ MCSection *TargetLoweringObjectFileCOFF::getSectionForJumpTable(
Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
unsigned UniqueID = NextUniqueID++;

return getContext().getCOFFSection(
SecName, Characteristics, Kind, COMDATSymName,
COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE, UniqueID);
return getContext().getCOFFSection(SecName, Characteristics, COMDATSymName,
COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE,
UniqueID);
}

bool TargetLoweringObjectFileCOFF::shouldPutJumpTableInFunctionSection(
Expand All @@ -1846,10 +1846,8 @@ void TargetLoweringObjectFileCOFF::emitModuleMetadata(MCStreamer &Streamer,
GetObjCImageInfo(M, Version, Flags, Section);
if (!Section.empty()) {
auto &C = getContext();
auto *S = C.getCOFFSection(Section,
COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ,
SectionKind::getReadOnly());
auto *S = C.getCOFFSection(Section, COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ);
Streamer.switchSection(S);
Streamer.emitLabel(C.getOrCreateSymbol(StringRef("OBJC_IMAGE_INFO")));
Streamer.emitInt32(Version);
Expand Down Expand Up @@ -1929,21 +1927,17 @@ void TargetLoweringObjectFileCOFF::Initialize(MCContext &Ctx,
if (T.isWindowsMSVCEnvironment() || T.isWindowsItaniumEnvironment()) {
StaticCtorSection =
Ctx.getCOFFSection(".CRT$XCU", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ,
SectionKind::getReadOnly());
COFF::IMAGE_SCN_MEM_READ);
StaticDtorSection =
Ctx.getCOFFSection(".CRT$XTX", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ,
SectionKind::getReadOnly());
COFF::IMAGE_SCN_MEM_READ);
} else {
StaticCtorSection = Ctx.getCOFFSection(
".ctors", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
SectionKind::getData());
COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE);
StaticDtorSection = Ctx.getCOFFSection(
".dtors", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
SectionKind::getData());
COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE);
}
}

Expand Down Expand Up @@ -1981,8 +1975,7 @@ static MCSectionCOFF *getCOFFStaticStructorSection(MCContext &Ctx,
if (AddPrioritySuffix)
OS << format("%05u", Priority);
MCSectionCOFF *Sec = Ctx.getCOFFSection(
Name, COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
SectionKind::getReadOnly());
Name, COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ);
return Ctx.getAssociativeCOFFSection(Sec, KeySym, 0);
}

Expand All @@ -1993,8 +1986,7 @@ static MCSectionCOFF *getCOFFStaticStructorSection(MCContext &Ctx,
return Ctx.getAssociativeCOFFSection(
Ctx.getCOFFSection(Name, COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ |
COFF::IMAGE_SCN_MEM_WRITE,
SectionKind::getData()),
COFF::IMAGE_SCN_MEM_WRITE),
KeySym, 0);
}

Expand Down Expand Up @@ -2112,7 +2104,7 @@ MCSection *TargetLoweringObjectFileCOFF::getSectionForConstant(
}

if (!COMDATSymName.empty())
return getContext().getCOFFSection(".rdata", Characteristics, Kind,
return getContext().getCOFFSection(".rdata", Characteristics,
COMDATSymName,
COFF::IMAGE_COMDAT_SELECT_ANY);
}
Expand Down
Loading
Loading