diff options
| author | aengelke <engelke@in.tum.de> | 2024-06-20 10:52:49 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-20 10:52:49 +0200 |
| commit | 46beeaa3940ef8380ee99b9f666cd27b884f63e4 (patch) | |
| tree | 3109f60e7bc264ec8c2d62ca829c14e6ed5b6870 /llvm/lib/CodeGen | |
| parent | acf675b63f9426e61aac2155e29280f7d21f9421 (diff) | |
[MC] Remove SectionKind from MCSection (#96067)
There are only three actual uses of the section kind in MCSection:
isText(), XCOFF, and WebAssembly. Store isText() in the MCSection, and
store other info in the actual section variants where required.
ELF and COFF flags also encode all relevant information, so for these
two section variants, remove the SectionKind parameter entirely.
This allows to remove the string switch (which is unnecessary and
inaccurate) from createELFSectionImpl. This was introduced in
[D133456](https://reviews.llvm.org/D133456), but apparently, it was
never hit for non-writable sections anyway and the resulting kind was
never used.
Diffstat (limited to 'llvm/lib/CodeGen')
| -rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 9 | ||||
| -rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 3 | ||||
| -rw-r--r-- | llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 40 |
3 files changed, 21 insertions, 31 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 3580d484b7dd..766fb3633b28 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -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); @@ -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); @@ -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(); diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index 7d3ea9352bd6..dd7d9e5deac2 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -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 diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index 0fc915d89f6c..b2c1750131a2 100644 --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -1696,7 +1696,7 @@ MCSection *TargetLoweringObjectFileCOFF::getExplicitSectionGlobal( } } - return getContext().getCOFFSection(Name, Characteristics, Kind, COMDATSymName, + return getContext().getCOFFSection(Name, Characteristics, COMDATSymName, Selection); } @@ -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); } } @@ -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( @@ -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); @@ -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); } } @@ -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); } @@ -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); } @@ -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); } |
