[llvm] 46beeaa - [MC] Remove SectionKind from MCSection (#96067)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 20 01:52:53 PDT 2024


Author: aengelke
Date: 2024-06-20T10:52:49+02:00
New Revision: 46beeaa3940ef8380ee99b9f666cd27b884f63e4

URL: https://github.com/llvm/llvm-project/commit/46beeaa3940ef8380ee99b9f666cd27b884f63e4
DIFF: https://github.com/llvm/llvm-project/commit/46beeaa3940ef8380ee99b9f666cd27b884f63e4.diff

LOG: [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.

Added: 
    

Modified: 
    llvm/include/llvm/MC/MCContext.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/MCSectionSPIRV.h
    llvm/include/llvm/MC/MCSectionWasm.h
    llvm/include/llvm/MC/MCSectionXCOFF.h
    llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
    llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
    llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
    llvm/lib/MC/MCContext.cpp
    llvm/lib/MC/MCObjectFileInfo.cpp
    llvm/lib/MC/MCParser/COFFAsmParser.cpp
    llvm/lib/MC/MCParser/COFFMasmParser.cpp
    llvm/lib/MC/MCSection.cpp
    llvm/lib/MC/MCSectionCOFF.cpp
    llvm/lib/MC/MCSectionMachO.cpp
    llvm/lib/MC/MCStreamer.cpp
    llvm/lib/MC/WasmObjectWriter.cpp
    llvm/lib/MC/WinCOFFObjectWriter.cpp
    llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
    llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.cpp
    llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
    llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp
    llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/MC/MCContext.h b/llvm/include/llvm/MC/MCContext.h
index 7c70a29b243de..3fe4c2885f6b5 100644
--- a/llvm/include/llvm/MC/MCContext.h
+++ b/llvm/include/llvm/MC/MCContext.h
@@ -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);
@@ -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

diff  --git a/llvm/include/llvm/MC/MCSection.h b/llvm/include/llvm/MC/MCSection.h
index c7c0de60a411e..9b3df81324226 100644
--- a/llvm/include/llvm/MC/MCSection.h
+++ b/llvm/include/llvm/MC/MCSection.h
@@ -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
@@ -124,9 +126,8 @@ 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:
@@ -134,7 +135,7 @@ class MCSection {
   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; }
 

diff  --git a/llvm/include/llvm/MC/MCSectionCOFF.h b/llvm/include/llvm/MC/MCSectionCOFF.h
index 2faf84f0372cb..c99e7d405d001 100644
--- a/llvm/include/llvm/MC/MCSectionCOFF.h
+++ b/llvm/include/llvm/MC/MCSectionCOFF.h
@@ -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>
@@ -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");
   }

diff  --git a/llvm/include/llvm/MC/MCSectionDXContainer.h b/llvm/include/llvm/MC/MCSectionDXContainer.h
index 014684a935295..4ef2f29d7e67d 100644
--- a/llvm/include/llvm/MC/MCSectionDXContainer.h
+++ b/llvm/include/llvm/MC/MCSectionDXContainer.h
@@ -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 &,

diff  --git a/llvm/include/llvm/MC/MCSectionELF.h b/llvm/include/llvm/MC/MCSectionELF.h
index 3b5239394493c..ff9240ff4e32d 100644
--- a/llvm/include/llvm/MC/MCSectionELF.h
+++ b/llvm/include/llvm/MC/MCSectionELF.h
@@ -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"
@@ -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();
   }

diff  --git a/llvm/include/llvm/MC/MCSectionGOFF.h b/llvm/include/llvm/MC/MCSectionGOFF.h
index d866329461cea..1cc13757abb8d 100644
--- a/llvm/include/llvm/MC/MCSectionGOFF.h
+++ b/llvm/include/llvm/MC/MCSectionGOFF.h
@@ -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,

diff  --git a/llvm/include/llvm/MC/MCSectionSPIRV.h b/llvm/include/llvm/MC/MCSectionSPIRV.h
index 6534599d2091c..0b2b15b4e3dcd 100644
--- a/llvm/include/llvm/MC/MCSectionSPIRV.h
+++ b/llvm/include/llvm/MC/MCSectionSPIRV.h
@@ -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:

diff  --git a/llvm/include/llvm/MC/MCSectionWasm.h b/llvm/include/llvm/MC/MCSectionWasm.h
index 23eba093a3b21..a94397c37060c 100644
--- a/llvm/include/llvm/MC/MCSectionWasm.h
+++ b/llvm/include/llvm/MC/MCSectionWasm.h
@@ -40,6 +40,10 @@ 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;
 
@@ -47,8 +51,9 @@ class MCSectionWasm final : public MCSection {
   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
@@ -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; }

diff  --git a/llvm/include/llvm/MC/MCSectionXCOFF.h b/llvm/include/llvm/MC/MCSectionXCOFF.h
index 7b7a58f26bca3..11bcfc8e63a6b 100644
--- a/llvm/include/llvm/MC/MCSectionXCOFF.h
+++ b/llvm/include/llvm/MC/MCSectionXCOFF.h
@@ -37,6 +37,7 @@ 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;
 
@@ -44,10 +45,10 @@ class MCSectionXCOFF final : public MCSection {
                  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.");
@@ -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.
@@ -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

diff  --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 3580d484b7ddd..766fb3633b281 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 7d3ea9352bd6c..dd7d9e5deac2e 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 0fc915d89f6c0..b2c1750131a2f 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);
   }

diff  --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp
index f12a3bc0e56f5..432ff5e7a7c28 100644
--- a/llvm/lib/MC/MCContext.cpp
+++ b/llvm/lib/MC/MCContext.cpp
@@ -479,7 +479,7 @@ MCSectionMachO *MCContext::getMachOSection(StringRef Segment, StringRef Section,
 }
 
 MCSectionELF *MCContext::createELFSectionImpl(StringRef Section, unsigned Type,
-                                              unsigned Flags, SectionKind K,
+                                              unsigned Flags,
                                               unsigned EntrySize,
                                               const MCSymbolELF *Group,
                                               bool Comdat, unsigned UniqueID,
@@ -502,9 +502,8 @@ MCSectionELF *MCContext::createELFSectionImpl(StringRef Section, unsigned Type,
   R->setBinding(ELF::STB_LOCAL);
   R->setType(ELF::STT_SECTION);
 
-  auto *Ret = new (ELFAllocator.Allocate())
-      MCSectionELF(Section, Type, Flags, K, EntrySize, Group, Comdat, UniqueID,
-                   R, LinkedToSym);
+  auto *Ret = new (ELFAllocator.Allocate()) MCSectionELF(
+      Section, Type, Flags, EntrySize, Group, Comdat, UniqueID, R, LinkedToSym);
 
   auto *F = allocInitialFragment(*Ret);
   R->setFragment(F);
@@ -520,8 +519,8 @@ MCContext::createELFRelSection(const Twine &Name, unsigned Type, unsigned Flags,
   std::tie(I, Inserted) = RelSecNames.insert(std::make_pair(Name.str(), true));
 
   return createELFSectionImpl(
-      I->getKey(), Type, Flags, SectionKind::getReadOnly(), EntrySize, Group,
-      true, true, cast<MCSymbolELF>(RelInfoSection->getBeginSymbol()));
+      I->getKey(), Type, Flags, EntrySize, Group, true, true,
+      cast<MCSymbolELF>(RelInfoSection->getBeginSymbol()));
 }
 
 MCSectionELF *MCContext::getELFNamedSection(const Twine &Prefix,
@@ -591,47 +590,8 @@ MCSectionELF *MCContext::getELFSection(const Twine &Section, unsigned Type,
 
   StringRef CachedName = EntryNewPair.first->getKey().take_front(SectionLen);
 
-  SectionKind Kind;
-  if (Flags & ELF::SHF_ARM_PURECODE)
-    Kind = SectionKind::getExecuteOnly();
-  else if (Flags & ELF::SHF_EXECINSTR)
-    Kind = SectionKind::getText();
-  else if (~Flags & ELF::SHF_WRITE)
-    Kind = SectionKind::getReadOnly();
-  else if (Flags & ELF::SHF_TLS)
-    Kind = (Type & ELF::SHT_NOBITS) ? SectionKind::getThreadBSS()
-                                    : SectionKind::getThreadData();
-  else
-    // Default to `SectionKind::getText()`. This is the default for gas as
-    // well. The condition that falls into this case is where we do not have any
-    // section flags and must infer a classification rather than where we have
-    // section flags (i.e. this is not that SHF_EXECINSTR is unset bur rather it
-    // is unknown).
-    Kind = llvm::StringSwitch<SectionKind>(CachedName)
-               .Case(".bss", SectionKind::getBSS())
-               .StartsWith(".bss.", SectionKind::getBSS())
-               .StartsWith(".gnu.linkonce.b.", SectionKind::getBSS())
-               .StartsWith(".llvm.linkonce.b.", SectionKind::getBSS())
-               .Case(".data", SectionKind::getData())
-               .Case(".data1", SectionKind::getData())
-               .Case(".data.rel.ro", SectionKind::getReadOnlyWithRel())
-               .StartsWith(".data.", SectionKind::getData())
-               .Case(".rodata", SectionKind::getReadOnly())
-               .Case(".rodata1", SectionKind::getReadOnly())
-               .StartsWith(".rodata.", SectionKind::getReadOnly())
-               .Case(".tbss", SectionKind::getThreadBSS())
-               .StartsWith(".tbss.", SectionKind::getThreadData())
-               .StartsWith(".gnu.linkonce.tb.", SectionKind::getThreadData())
-               .StartsWith(".llvm.linkonce.tb.", SectionKind::getThreadData())
-               .Case(".tdata", SectionKind::getThreadData())
-               .StartsWith(".tdata.", SectionKind::getThreadData())
-               .StartsWith(".gnu.linkonce.td.", SectionKind::getThreadData())
-               .StartsWith(".llvm.linkonce.td.", SectionKind::getThreadData())
-               .StartsWith(".debug_", SectionKind::getMetadata())
-               .Default(SectionKind::getReadOnly());
-
   MCSectionELF *Result =
-      createELFSectionImpl(CachedName, Type, Flags, Kind, EntrySize, GroupSym,
+      createELFSectionImpl(CachedName, Type, Flags, EntrySize, GroupSym,
                            IsComdat, UniqueID, LinkedToSym);
   EntryNewPair.first->second = Result;
 
@@ -643,8 +603,7 @@ MCSectionELF *MCContext::getELFSection(const Twine &Section, unsigned Type,
 
 MCSectionELF *MCContext::createELFGroupSection(const MCSymbolELF *Group,
                                                bool IsComdat) {
-  return createELFSectionImpl(".group", ELF::SHT_GROUP, 0,
-                              SectionKind::getReadOnly(), 4, Group, IsComdat,
+  return createELFSectionImpl(".group", ELF::SHT_GROUP, 0, 4, Group, IsComdat,
                               MCSection::NonUniqueID, nullptr);
 }
 
@@ -707,7 +666,6 @@ MCSectionGOFF *MCContext::getGOFFSection(StringRef Section, SectionKind Kind,
 
 MCSectionCOFF *MCContext::getCOFFSection(StringRef Section,
                                          unsigned Characteristics,
-                                         SectionKind Kind,
                                          StringRef COMDATSymName, int Selection,
                                          unsigned UniqueID,
                                          const char *BeginSymName) {
@@ -730,7 +688,7 @@ MCSectionCOFF *MCContext::getCOFFSection(StringRef Section,
 
   StringRef CachedName = Iter->first.SectionName;
   MCSectionCOFF *Result = new (COFFAllocator.Allocate()) MCSectionCOFF(
-      CachedName, Characteristics, COMDATSymbol, Selection, Kind, Begin);
+      CachedName, Characteristics, COMDATSymbol, Selection, Begin);
 
   Iter->second = Result;
   return Result;
@@ -738,9 +696,8 @@ MCSectionCOFF *MCContext::getCOFFSection(StringRef Section,
 
 MCSectionCOFF *MCContext::getCOFFSection(StringRef Section,
                                          unsigned Characteristics,
-                                         SectionKind Kind,
                                          const char *BeginSymName) {
-  return getCOFFSection(Section, Characteristics, Kind, "", 0, GenericSectionID,
+  return getCOFFSection(Section, Characteristics, "", 0, GenericSectionID,
                         BeginSymName);
 }
 
@@ -756,13 +713,11 @@ MCSectionCOFF *MCContext::getAssociativeCOFFSection(MCSectionCOFF *Sec,
   unsigned Characteristics = Sec->getCharacteristics();
   if (KeySym) {
     Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
-    return getCOFFSection(Sec->getName(), Characteristics, Sec->getKind(),
-                          KeySym->getName(),
+    return getCOFFSection(Sec->getName(), Characteristics, KeySym->getName(),
                           COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE, UniqueID);
   }
 
-  return getCOFFSection(Sec->getName(), Characteristics, Sec->getKind(), "", 0,
-                        UniqueID);
+  return getCOFFSection(Sec->getName(), Characteristics, "", 0, UniqueID);
 }
 
 MCSectionWasm *MCContext::getWasmSection(const Twine &Section, SectionKind K,
@@ -882,9 +837,7 @@ MCSectionXCOFF *MCContext::getXCOFFSection(
 }
 
 MCSectionSPIRV *MCContext::getSPIRVSection() {
-  MCSymbol *Begin = nullptr;
-  MCSectionSPIRV *Result = new (SPIRVAllocator.Allocate())
-      MCSectionSPIRV(SectionKind::getText(), Begin);
+  MCSectionSPIRV *Result = new (SPIRVAllocator.Allocate()) MCSectionSPIRV();
 
   allocInitialFragment(*Result);
   return Result;

diff  --git a/llvm/lib/MC/MCObjectFileInfo.cpp b/llvm/lib/MC/MCObjectFileInfo.cpp
index 045b566aae783..35ac307519f47 100644
--- a/llvm/lib/MC/MCObjectFileInfo.cpp
+++ b/llvm/lib/MC/MCObjectFileInfo.cpp
@@ -570,8 +570,7 @@ void MCObjectFileInfo::initGOFFMCObjectFileInfo(const Triple &T) {
 void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple &T) {
   EHFrameSection =
       Ctx->getCOFFSection(".eh_frame", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
-                                           COFF::IMAGE_SCN_MEM_READ,
-                          SectionKind::getData());
+                                           COFF::IMAGE_SCN_MEM_READ);
 
   // Set the `IMAGE_SCN_MEM_16BIT` flag when compiling for thumb mode.  This is
   // used to indicate to the linker that the text segment contains thumb instructions
@@ -581,21 +580,18 @@ void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple &T) {
   // COFF
   BSSSection = Ctx->getCOFFSection(
       ".bss", COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
-                  COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
-      SectionKind::getBSS());
+                  COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE);
   TextSection = Ctx->getCOFFSection(
       ".text",
       (IsThumb ? COFF::IMAGE_SCN_MEM_16BIT : (COFF::SectionCharacteristics)0) |
           COFF::IMAGE_SCN_CNT_CODE | COFF::IMAGE_SCN_MEM_EXECUTE |
-          COFF::IMAGE_SCN_MEM_READ,
-      SectionKind::getText());
+          COFF::IMAGE_SCN_MEM_READ);
   DataSection = Ctx->getCOFFSection(
       ".data", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
-                   COFF::IMAGE_SCN_MEM_WRITE,
-      SectionKind::getData());
-  ReadOnlySection = Ctx->getCOFFSection(
-      ".rdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
-      SectionKind::getReadOnly());
+                   COFF::IMAGE_SCN_MEM_WRITE);
+  ReadOnlySection =
+      Ctx->getCOFFSection(".rdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
+                                        COFF::IMAGE_SCN_MEM_READ);
 
   if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::aarch64 ||
       T.getArch() == Triple::arm || T.getArch() == Triple::thumb) {
@@ -604,247 +600,226 @@ void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple &T) {
   } else {
     LSDASection = Ctx->getCOFFSection(".gcc_except_table",
                                       COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
-                                          COFF::IMAGE_SCN_MEM_READ,
-                                      SectionKind::getReadOnly());
+                                          COFF::IMAGE_SCN_MEM_READ);
   }
 
   // Debug info.
   COFFDebugSymbolsSection =
       Ctx->getCOFFSection(".debug$S", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
                                        COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
-                                       COFF::IMAGE_SCN_MEM_READ),
-                          SectionKind::getMetadata());
+                                       COFF::IMAGE_SCN_MEM_READ));
   COFFDebugTypesSection =
       Ctx->getCOFFSection(".debug$T", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
                                        COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
-                                       COFF::IMAGE_SCN_MEM_READ),
-                          SectionKind::getMetadata());
-  COFFGlobalTypeHashesSection = Ctx->getCOFFSection(
-      ".debug$H",
-      (COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
-       COFF::IMAGE_SCN_MEM_READ),
-      SectionKind::getMetadata());
+                                       COFF::IMAGE_SCN_MEM_READ));
+  COFFGlobalTypeHashesSection =
+      Ctx->getCOFFSection(".debug$H", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
+                                       COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
+                                       COFF::IMAGE_SCN_MEM_READ));
 
   DwarfAbbrevSection = Ctx->getCOFFSection(
       ".debug_abbrev",
       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
           COFF::IMAGE_SCN_MEM_READ,
-      SectionKind::getMetadata(), "section_abbrev");
+      "section_abbrev");
   DwarfInfoSection = Ctx->getCOFFSection(
       ".debug_info",
       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
           COFF::IMAGE_SCN_MEM_READ,
-      SectionKind::getMetadata(), "section_info");
+      "section_info");
   DwarfLineSection = Ctx->getCOFFSection(
       ".debug_line",
       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
           COFF::IMAGE_SCN_MEM_READ,
-      SectionKind::getMetadata(), "section_line");
+      "section_line");
   DwarfLineStrSection = Ctx->getCOFFSection(
       ".debug_line_str",
       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
           COFF::IMAGE_SCN_MEM_READ,
-      SectionKind::getMetadata(), "section_line_str");
+      "section_line_str");
   DwarfFrameSection = Ctx->getCOFFSection(
-      ".debug_frame",
-      COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
-          COFF::IMAGE_SCN_MEM_READ,
-      SectionKind::getMetadata());
+      ".debug_frame", COFF::IMAGE_SCN_MEM_DISCARDABLE |
+                          COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
+                          COFF::IMAGE_SCN_MEM_READ);
   DwarfPubNamesSection = Ctx->getCOFFSection(
-      ".debug_pubnames",
-      COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
-          COFF::IMAGE_SCN_MEM_READ,
-      SectionKind::getMetadata());
+      ".debug_pubnames", COFF::IMAGE_SCN_MEM_DISCARDABLE |
+                             COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
+                             COFF::IMAGE_SCN_MEM_READ);
   DwarfPubTypesSection = Ctx->getCOFFSection(
-      ".debug_pubtypes",
-      COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
-          COFF::IMAGE_SCN_MEM_READ,
-      SectionKind::getMetadata());
+      ".debug_pubtypes", COFF::IMAGE_SCN_MEM_DISCARDABLE |
+                             COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
+                             COFF::IMAGE_SCN_MEM_READ);
   DwarfGnuPubNamesSection = Ctx->getCOFFSection(
-      ".debug_gnu_pubnames",
-      COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
-          COFF::IMAGE_SCN_MEM_READ,
-      SectionKind::getMetadata());
+      ".debug_gnu_pubnames", COFF::IMAGE_SCN_MEM_DISCARDABLE |
+                                 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
+                                 COFF::IMAGE_SCN_MEM_READ);
   DwarfGnuPubTypesSection = Ctx->getCOFFSection(
-      ".debug_gnu_pubtypes",
-      COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
-          COFF::IMAGE_SCN_MEM_READ,
-      SectionKind::getMetadata());
+      ".debug_gnu_pubtypes", COFF::IMAGE_SCN_MEM_DISCARDABLE |
+                                 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
+                                 COFF::IMAGE_SCN_MEM_READ);
   DwarfStrSection = Ctx->getCOFFSection(
       ".debug_str",
       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
           COFF::IMAGE_SCN_MEM_READ,
-      SectionKind::getMetadata(), "info_string");
+      "info_string");
   DwarfStrOffSection = Ctx->getCOFFSection(
       ".debug_str_offsets",
       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
           COFF::IMAGE_SCN_MEM_READ,
-      SectionKind::getMetadata(), "section_str_off");
+      "section_str_off");
   DwarfLocSection = Ctx->getCOFFSection(
       ".debug_loc",
       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
           COFF::IMAGE_SCN_MEM_READ,
-      SectionKind::getMetadata(), "section_debug_loc");
+      "section_debug_loc");
   DwarfLoclistsSection = Ctx->getCOFFSection(
       ".debug_loclists",
       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
           COFF::IMAGE_SCN_MEM_READ,
-      SectionKind::getMetadata(), "section_debug_loclists");
+      "section_debug_loclists");
   DwarfARangesSection = Ctx->getCOFFSection(
-      ".debug_aranges",
-      COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
-          COFF::IMAGE_SCN_MEM_READ,
-      SectionKind::getMetadata());
+      ".debug_aranges", COFF::IMAGE_SCN_MEM_DISCARDABLE |
+                            COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
+                            COFF::IMAGE_SCN_MEM_READ);
   DwarfRangesSection = Ctx->getCOFFSection(
       ".debug_ranges",
       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
           COFF::IMAGE_SCN_MEM_READ,
-      SectionKind::getMetadata(), "debug_range");
+      "debug_range");
   DwarfRnglistsSection = Ctx->getCOFFSection(
       ".debug_rnglists",
       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
           COFF::IMAGE_SCN_MEM_READ,
-      SectionKind::getMetadata(), "debug_rnglists");
+      "debug_rnglists");
   DwarfMacinfoSection = Ctx->getCOFFSection(
       ".debug_macinfo",
       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
           COFF::IMAGE_SCN_MEM_READ,
-      SectionKind::getMetadata(), "debug_macinfo");
+      "debug_macinfo");
   DwarfMacroSection = Ctx->getCOFFSection(
       ".debug_macro",
       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
           COFF::IMAGE_SCN_MEM_READ,
-      SectionKind::getMetadata(), "debug_macro");
+      "debug_macro");
   DwarfMacinfoDWOSection = Ctx->getCOFFSection(
       ".debug_macinfo.dwo",
       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
           COFF::IMAGE_SCN_MEM_READ,
-      SectionKind::getMetadata(), "debug_macinfo.dwo");
+      "debug_macinfo.dwo");
   DwarfMacroDWOSection = Ctx->getCOFFSection(
       ".debug_macro.dwo",
       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
           COFF::IMAGE_SCN_MEM_READ,
-      SectionKind::getMetadata(), "debug_macro.dwo");
+      "debug_macro.dwo");
   DwarfInfoDWOSection = Ctx->getCOFFSection(
       ".debug_info.dwo",
       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
           COFF::IMAGE_SCN_MEM_READ,
-      SectionKind::getMetadata(), "section_info_dwo");
+      "section_info_dwo");
   DwarfTypesDWOSection = Ctx->getCOFFSection(
       ".debug_types.dwo",
       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
           COFF::IMAGE_SCN_MEM_READ,
-      SectionKind::getMetadata(), "section_types_dwo");
+      "section_types_dwo");
   DwarfAbbrevDWOSection = Ctx->getCOFFSection(
       ".debug_abbrev.dwo",
       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
           COFF::IMAGE_SCN_MEM_READ,
-      SectionKind::getMetadata(), "section_abbrev_dwo");
+      "section_abbrev_dwo");
   DwarfStrDWOSection = Ctx->getCOFFSection(
       ".debug_str.dwo",
       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
           COFF::IMAGE_SCN_MEM_READ,
-      SectionKind::getMetadata(), "skel_string");
+      "skel_string");
   DwarfLineDWOSection = Ctx->getCOFFSection(
-      ".debug_line.dwo",
-      COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
-          COFF::IMAGE_SCN_MEM_READ,
-      SectionKind::getMetadata());
+      ".debug_line.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
+                             COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
+                             COFF::IMAGE_SCN_MEM_READ);
   DwarfLocDWOSection = Ctx->getCOFFSection(
       ".debug_loc.dwo",
       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
           COFF::IMAGE_SCN_MEM_READ,
-      SectionKind::getMetadata(), "skel_loc");
+      "skel_loc");
   DwarfStrOffDWOSection = Ctx->getCOFFSection(
       ".debug_str_offsets.dwo",
       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
           COFF::IMAGE_SCN_MEM_READ,
-      SectionKind::getMetadata(), "section_str_off_dwo");
+      "section_str_off_dwo");
   DwarfAddrSection = Ctx->getCOFFSection(
       ".debug_addr",
       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
           COFF::IMAGE_SCN_MEM_READ,
-      SectionKind::getMetadata(), "addr_sec");
+      "addr_sec");
   DwarfCUIndexSection = Ctx->getCOFFSection(
-      ".debug_cu_index",
-      COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
-          COFF::IMAGE_SCN_MEM_READ,
-      SectionKind::getMetadata());
+      ".debug_cu_index", COFF::IMAGE_SCN_MEM_DISCARDABLE |
+                             COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
+                             COFF::IMAGE_SCN_MEM_READ);
   DwarfTUIndexSection = Ctx->getCOFFSection(
-      ".debug_tu_index",
-      COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
-          COFF::IMAGE_SCN_MEM_READ,
-      SectionKind::getMetadata());
+      ".debug_tu_index", COFF::IMAGE_SCN_MEM_DISCARDABLE |
+                             COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
+                             COFF::IMAGE_SCN_MEM_READ);
   DwarfDebugNamesSection = Ctx->getCOFFSection(
       ".debug_names",
       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
           COFF::IMAGE_SCN_MEM_READ,
-      SectionKind::getMetadata(), "debug_names_begin");
+      "debug_names_begin");
   DwarfAccelNamesSection = Ctx->getCOFFSection(
       ".apple_names",
       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
           COFF::IMAGE_SCN_MEM_READ,
-      SectionKind::getMetadata(), "names_begin");
+      "names_begin");
   DwarfAccelNamespaceSection = Ctx->getCOFFSection(
       ".apple_namespaces",
       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
           COFF::IMAGE_SCN_MEM_READ,
-      SectionKind::getMetadata(), "namespac_begin");
+      "namespac_begin");
   DwarfAccelTypesSection = Ctx->getCOFFSection(
       ".apple_types",
       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
           COFF::IMAGE_SCN_MEM_READ,
-      SectionKind::getMetadata(), "types_begin");
+      "types_begin");
   DwarfAccelObjCSection = Ctx->getCOFFSection(
       ".apple_objc",
       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
           COFF::IMAGE_SCN_MEM_READ,
-      SectionKind::getMetadata(), "objc_begin");
+      "objc_begin");
 
   DrectveSection = Ctx->getCOFFSection(
-      ".drectve", COFF::IMAGE_SCN_LNK_INFO | COFF::IMAGE_SCN_LNK_REMOVE,
-      SectionKind::getMetadata());
+      ".drectve", COFF::IMAGE_SCN_LNK_INFO | COFF::IMAGE_SCN_LNK_REMOVE);
 
-  PDataSection = Ctx->getCOFFSection(
-      ".pdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
-      SectionKind::getData());
+  PDataSection =
+      Ctx->getCOFFSection(".pdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
+                                        COFF::IMAGE_SCN_MEM_READ);
 
-  XDataSection = Ctx->getCOFFSection(
-      ".xdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
-      SectionKind::getData());
+  XDataSection =
+      Ctx->getCOFFSection(".xdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
+                                        COFF::IMAGE_SCN_MEM_READ);
 
-  SXDataSection = Ctx->getCOFFSection(".sxdata", COFF::IMAGE_SCN_LNK_INFO,
-                                      SectionKind::getMetadata());
+  SXDataSection = Ctx->getCOFFSection(".sxdata", COFF::IMAGE_SCN_LNK_INFO);
 
-  GEHContSection = Ctx->getCOFFSection(".gehcont$y",
-                                       COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
-                                           COFF::IMAGE_SCN_MEM_READ,
-                                       SectionKind::getMetadata());
+  GEHContSection =
+      Ctx->getCOFFSection(".gehcont$y", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
+                                            COFF::IMAGE_SCN_MEM_READ);
 
-  GFIDsSection = Ctx->getCOFFSection(".gfids$y",
-                                     COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
-                                         COFF::IMAGE_SCN_MEM_READ,
-                                     SectionKind::getMetadata());
+  GFIDsSection =
+      Ctx->getCOFFSection(".gfids$y", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
+                                          COFF::IMAGE_SCN_MEM_READ);
 
-  GIATsSection = Ctx->getCOFFSection(".giats$y",
-                                     COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
-                                         COFF::IMAGE_SCN_MEM_READ,
-                                     SectionKind::getMetadata());
+  GIATsSection =
+      Ctx->getCOFFSection(".giats$y", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
+                                          COFF::IMAGE_SCN_MEM_READ);
 
-  GLJMPSection = Ctx->getCOFFSection(".gljmp$y",
-                                     COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
-                                         COFF::IMAGE_SCN_MEM_READ,
-                                     SectionKind::getMetadata());
+  GLJMPSection =
+      Ctx->getCOFFSection(".gljmp$y", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
+                                          COFF::IMAGE_SCN_MEM_READ);
 
   TLSDataSection = Ctx->getCOFFSection(
       ".tls$", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
-                   COFF::IMAGE_SCN_MEM_WRITE,
-      SectionKind::getData());
+                   COFF::IMAGE_SCN_MEM_WRITE);
 
   StackMapSection = Ctx->getCOFFSection(".llvm_stackmaps",
                                         COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
-                                            COFF::IMAGE_SCN_MEM_READ,
-                                        SectionKind::getReadOnly());
+                                            COFF::IMAGE_SCN_MEM_READ);
 }
 
 void MCObjectFileInfo::initSPIRVMCObjectFileInfo(const Triple &T) {

diff  --git a/llvm/lib/MC/MCParser/COFFAsmParser.cpp b/llvm/lib/MC/MCParser/COFFAsmParser.cpp
index bfded36da7ab9..a69276c36c56b 100644
--- a/llvm/lib/MC/MCParser/COFFAsmParser.cpp
+++ b/llvm/lib/MC/MCParser/COFFAsmParser.cpp
@@ -36,13 +36,10 @@ class COFFAsmParser : public MCAsmParserExtension {
     getParser().addDirectiveHandler(Directive, Handler);
   }
 
-  bool ParseSectionSwitch(StringRef Section,
-                          unsigned Characteristics,
-                          SectionKind Kind);
+  bool ParseSectionSwitch(StringRef Section, unsigned Characteristics);
 
   bool ParseSectionSwitch(StringRef Section, unsigned Characteristics,
-                          SectionKind Kind, StringRef COMDATSymName,
-                          COFF::COMDATType Type);
+                          StringRef COMDATSymName, COFF::COMDATType Type);
 
   bool ParseSectionName(StringRef &SectionName);
   bool ParseSectionFlags(StringRef SectionName, StringRef FlagsString,
@@ -96,26 +93,21 @@ class COFFAsmParser : public MCAsmParserExtension {
   }
 
   bool ParseSectionDirectiveText(StringRef, SMLoc) {
-    return ParseSectionSwitch(".text",
-                              COFF::IMAGE_SCN_CNT_CODE
-                            | COFF::IMAGE_SCN_MEM_EXECUTE
-                            | COFF::IMAGE_SCN_MEM_READ,
-                              SectionKind::getText());
+    return ParseSectionSwitch(".text", COFF::IMAGE_SCN_CNT_CODE |
+                                           COFF::IMAGE_SCN_MEM_EXECUTE |
+                                           COFF::IMAGE_SCN_MEM_READ);
   }
 
   bool ParseSectionDirectiveData(StringRef, SMLoc) {
     return ParseSectionSwitch(".data", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
                                            COFF::IMAGE_SCN_MEM_READ |
-                                           COFF::IMAGE_SCN_MEM_WRITE,
-                              SectionKind::getData());
+                                           COFF::IMAGE_SCN_MEM_WRITE);
   }
 
   bool ParseSectionDirectiveBSS(StringRef, SMLoc) {
-    return ParseSectionSwitch(".bss",
-                              COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA
-                            | COFF::IMAGE_SCN_MEM_READ
-                            | COFF::IMAGE_SCN_MEM_WRITE,
-                              SectionKind::getBSS());
+    return ParseSectionSwitch(".bss", COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
+                                          COFF::IMAGE_SCN_MEM_READ |
+                                          COFF::IMAGE_SCN_MEM_WRITE);
   }
 
   bool ParseDirectiveSection(StringRef, SMLoc);
@@ -155,15 +147,6 @@ class COFFAsmParser : public MCAsmParserExtension {
 
 } // end anonymous namespace.
 
-static SectionKind computeSectionKind(unsigned Flags) {
-  if (Flags & COFF::IMAGE_SCN_MEM_EXECUTE)
-    return SectionKind::getText();
-  if (Flags & COFF::IMAGE_SCN_MEM_READ &&
-      (Flags & COFF::IMAGE_SCN_MEM_WRITE) == 0)
-    return SectionKind::getReadOnly();
-  return SectionKind::getData();
-}
-
 bool COFFAsmParser::ParseSectionFlags(StringRef SectionName,
                                       StringRef FlagsString, unsigned *Flags) {
   enum {
@@ -321,14 +304,12 @@ bool COFFAsmParser::ParseDirectiveCGProfile(StringRef S, SMLoc Loc) {
 }
 
 bool COFFAsmParser::ParseSectionSwitch(StringRef Section,
-                                       unsigned Characteristics,
-                                       SectionKind Kind) {
-  return ParseSectionSwitch(Section, Characteristics, Kind, "", (COFF::COMDATType)0);
+                                       unsigned Characteristics) {
+  return ParseSectionSwitch(Section, Characteristics, "", (COFF::COMDATType)0);
 }
 
 bool COFFAsmParser::ParseSectionSwitch(StringRef Section,
                                        unsigned Characteristics,
-                                       SectionKind Kind,
                                        StringRef COMDATSymName,
                                        COFF::COMDATType Type) {
   if (getLexer().isNot(AsmToken::EndOfStatement))
@@ -336,7 +317,7 @@ bool COFFAsmParser::ParseSectionSwitch(StringRef Section,
   Lex();
 
   getStreamer().switchSection(getContext().getCOFFSection(
-      Section, Characteristics, Kind, COMDATSymName, Type));
+      Section, Characteristics, COMDATSymName, Type));
 
   return false;
 }
@@ -419,13 +400,12 @@ bool COFFAsmParser::parseSectionArguments(StringRef, SMLoc) {
   if (getLexer().isNot(AsmToken::EndOfStatement))
     return TokError("unexpected token in directive");
 
-  SectionKind Kind = computeSectionKind(Flags);
-  if (Kind.isText()) {
+  if (Flags & COFF::IMAGE_SCN_CNT_CODE) {
     const Triple &T = getContext().getTargetTriple();
     if (T.getArch() == Triple::arm || T.getArch() == Triple::thumb)
       Flags |= COFF::IMAGE_SCN_MEM_16BIT;
   }
-  ParseSectionSwitch(SectionName, Flags, Kind, COMDATSymName, Type);
+  ParseSectionSwitch(SectionName, Flags, COMDATSymName, Type);
   return false;
 }
 

diff  --git a/llvm/lib/MC/MCParser/COFFMasmParser.cpp b/llvm/lib/MC/MCParser/COFFMasmParser.cpp
index 8adb0dcddb16a..912e2b996792f 100644
--- a/llvm/lib/MC/MCParser/COFFMasmParser.cpp
+++ b/llvm/lib/MC/MCParser/COFFMasmParser.cpp
@@ -35,12 +35,11 @@ class COFFMasmParser : public MCAsmParserExtension {
     getParser().addDirectiveHandler(Directive, Handler);
   }
 
-  bool ParseSectionSwitch(StringRef SectionName, unsigned Characteristics,
-                          SectionKind Kind);
+  bool ParseSectionSwitch(StringRef SectionName, unsigned Characteristics);
 
   bool ParseSectionSwitch(StringRef SectionName, unsigned Characteristics,
-                          SectionKind Kind, StringRef COMDATSymName,
-                          COFF::COMDATType Type, Align Alignment);
+                          StringRef COMDATSymName, COFF::COMDATType Type,
+                          Align Alignment);
 
   bool ParseDirectiveProc(StringRef, SMLoc);
   bool ParseDirectiveEndProc(StringRef, SMLoc);
@@ -184,27 +183,21 @@ class COFFMasmParser : public MCAsmParserExtension {
   }
 
   bool ParseSectionDirectiveCode(StringRef, SMLoc) {
-    return ParseSectionSwitch(".text",
-                              COFF::IMAGE_SCN_CNT_CODE
-                            | COFF::IMAGE_SCN_MEM_EXECUTE
-                            | COFF::IMAGE_SCN_MEM_READ,
-                              SectionKind::getText());
+    return ParseSectionSwitch(".text", COFF::IMAGE_SCN_CNT_CODE |
+                                           COFF::IMAGE_SCN_MEM_EXECUTE |
+                                           COFF::IMAGE_SCN_MEM_READ);
   }
 
   bool ParseSectionDirectiveInitializedData(StringRef, SMLoc) {
-    return ParseSectionSwitch(".data",
-                              COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
-                            | COFF::IMAGE_SCN_MEM_READ
-                            | COFF::IMAGE_SCN_MEM_WRITE,
-                              SectionKind::getData());
+    return ParseSectionSwitch(".data", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
+                                           COFF::IMAGE_SCN_MEM_READ |
+                                           COFF::IMAGE_SCN_MEM_WRITE);
   }
 
   bool ParseSectionDirectiveUninitializedData(StringRef, SMLoc) {
-    return ParseSectionSwitch(".bss",
-                              COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA
-                            | COFF::IMAGE_SCN_MEM_READ
-                            | COFF::IMAGE_SCN_MEM_WRITE,
-                              SectionKind::getBSS());
+    return ParseSectionSwitch(".bss", COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
+                                          COFF::IMAGE_SCN_MEM_READ |
+                                          COFF::IMAGE_SCN_MEM_WRITE);
   }
 
   /// Stack of active procedure definitions.
@@ -218,21 +211,22 @@ class COFFMasmParser : public MCAsmParserExtension {
 } // end anonymous namespace.
 
 bool COFFMasmParser::ParseSectionSwitch(StringRef SectionName,
-                                        unsigned Characteristics,
-                                        SectionKind Kind) {
-  return ParseSectionSwitch(SectionName, Characteristics, Kind, "",
+                                        unsigned Characteristics) {
+  return ParseSectionSwitch(SectionName, Characteristics, "",
                             (COFF::COMDATType)0, Align(16));
 }
 
-bool COFFMasmParser::ParseSectionSwitch(
-    StringRef SectionName, unsigned Characteristics, SectionKind Kind,
-    StringRef COMDATSymName, COFF::COMDATType Type, Align Alignment) {
+bool COFFMasmParser::ParseSectionSwitch(StringRef SectionName,
+                                        unsigned Characteristics,
+                                        StringRef COMDATSymName,
+                                        COFF::COMDATType Type,
+                                        Align Alignment) {
   if (getLexer().isNot(AsmToken::EndOfStatement))
     return TokError("unexpected token in section switching directive");
   Lex();
 
   MCSection *Section = getContext().getCOFFSection(SectionName, Characteristics,
-                                                   Kind, COMDATSymName, Type);
+                                                   COMDATSymName, Type);
   Section->setAlignment(Alignment);
   getStreamer().switchSection(Section);
 
@@ -364,7 +358,7 @@ bool COFFMasmParser::ParseDirectiveSegment(StringRef Directive, SMLoc Loc) {
     Flags &= ~COFF::IMAGE_SCN_MEM_WRITE;
   }
 
-  MCSection *Section = getContext().getCOFFSection(SectionName, Flags, Kind, "",
+  MCSection *Section = getContext().getCOFFSection(SectionName, Flags, "",
                                                    (COFF::COMDATType)(0));
   if (Alignment != 0) {
     Section->setAlignment(Align(Alignment));
@@ -394,10 +388,9 @@ bool COFFMasmParser::ParseDirectiveIncludelib(StringRef Directive, SMLoc Loc) {
     return TokError("expected identifier in includelib directive");
 
   unsigned Flags = COFF::IMAGE_SCN_MEM_PRELOAD | COFF::IMAGE_SCN_MEM_16BIT;
-  SectionKind Kind = SectionKind::getData();
   getStreamer().pushSection();
   getStreamer().switchSection(getContext().getCOFFSection(
-      ".drectve", Flags, Kind, "", (COFF::COMDATType)(0)));
+      ".drectve", Flags, "", (COFF::COMDATType)(0)));
   getStreamer().emitBytes("/DEFAULTLIB:");
   getStreamer().emitBytes(Lib);
   getStreamer().emitBytes(" ");

diff  --git a/llvm/lib/MC/MCSection.cpp b/llvm/lib/MC/MCSection.cpp
index 3a7a8a0898c5b..85f6492af20f5 100644
--- a/llvm/lib/MC/MCSection.cpp
+++ b/llvm/lib/MC/MCSection.cpp
@@ -20,11 +20,11 @@
 
 using namespace llvm;
 
-MCSection::MCSection(SectionVariant V, StringRef Name, SectionKind K,
+MCSection::MCSection(SectionVariant V, StringRef Name, bool IsText,
                      MCSymbol *Begin)
     : Begin(Begin), BundleGroupBeforeFirstInst(false), HasInstructions(false),
-      HasLayout(false), IsRegistered(false), DummyFragment(this), Name(Name),
-      Variant(V), Kind(K) {
+      HasLayout(false), IsRegistered(false), IsText(IsText),
+      DummyFragment(this), Name(Name), Variant(V) {
   // The initial subsection number is 0. Create a fragment list.
   CurFragList = &Subsections.emplace_back(0u, FragList{}).second;
 }

diff  --git a/llvm/lib/MC/MCSectionCOFF.cpp b/llvm/lib/MC/MCSectionCOFF.cpp
index 02979c966ca79..ea0c5f0e4e551 100644
--- a/llvm/lib/MC/MCSectionCOFF.cpp
+++ b/llvm/lib/MC/MCSectionCOFF.cpp
@@ -106,7 +106,7 @@ void MCSectionCOFF::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
   OS << '\n';
 }
 
-bool MCSectionCOFF::useCodeAlign() const { return getKind().isText(); }
+bool MCSectionCOFF::useCodeAlign() const { return isText(); }
 
 bool MCSectionCOFF::isVirtualSection() const {
   return getCharacteristics() & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA;

diff  --git a/llvm/lib/MC/MCSectionMachO.cpp b/llvm/lib/MC/MCSectionMachO.cpp
index 53b76663084e8..9b7d9bf08fc2b 100644
--- a/llvm/lib/MC/MCSectionMachO.cpp
+++ b/llvm/lib/MC/MCSectionMachO.cpp
@@ -92,7 +92,7 @@ ENTRY("" /*FIXME*/,          S_ATTR_LOC_RELOC)
 MCSectionMachO::MCSectionMachO(StringRef Segment, StringRef Section,
                                unsigned TAA, unsigned reserved2, SectionKind K,
                                MCSymbol *Begin)
-    : MCSection(SV_MachO, Section, K, Begin), TypeAndAttributes(TAA),
+    : MCSection(SV_MachO, Section, K.isText(), Begin), TypeAndAttributes(TAA),
       Reserved2(reserved2) {
   assert(Segment.size() <= 16 && Section.size() <= 16 &&
          "Segment or section string too long");

diff  --git a/llvm/lib/MC/MCStreamer.cpp b/llvm/lib/MC/MCStreamer.cpp
index 199d865ea3496..680b0567c1493 100644
--- a/llvm/lib/MC/MCStreamer.cpp
+++ b/llvm/lib/MC/MCStreamer.cpp
@@ -841,10 +841,10 @@ static MCSection *getWinCFISection(MCContext &Context, unsigned *NextWinCFIID,
       std::string SectionName = (MainCFISecCOFF->getName() + "$" +
                                  TextSecCOFF->getName().split('$').second)
                                     .str();
-      return Context.getCOFFSection(
-          SectionName,
-          MainCFISecCOFF->getCharacteristics() | COFF::IMAGE_SCN_LNK_COMDAT,
-          MainCFISecCOFF->getKind(), "", COFF::IMAGE_COMDAT_SELECT_ANY);
+      return Context.getCOFFSection(SectionName,
+                                    MainCFISecCOFF->getCharacteristics() |
+                                        COFF::IMAGE_SCN_LNK_COMDAT,
+                                    "", COFF::IMAGE_COMDAT_SELECT_ANY);
     }
   }
 

diff  --git a/llvm/lib/MC/WasmObjectWriter.cpp b/llvm/lib/MC/WasmObjectWriter.cpp
index 522e268156aa3..186497c664106 100644
--- a/llvm/lib/MC/WasmObjectWriter.cpp
+++ b/llvm/lib/MC/WasmObjectWriter.cpp
@@ -499,7 +499,7 @@ void WasmObjectWriter::recordRelocation(MCAssembler &Asm,
 
     const auto &SymB = cast<MCSymbolWasm>(RefB->getSymbol());
 
-    if (FixupSection.getKind().isText()) {
+    if (FixupSection.isText()) {
       Ctx.reportError(Fixup.getLoc(),
                       Twine("symbol '") + SymB.getName() +
                           "' unsupported subtraction expression used in "
@@ -561,13 +561,13 @@ void WasmObjectWriter::recordRelocation(MCAssembler &Asm,
     // later gets changed again to a func symbol?] or it can be a real
     // function symbol, in which case it can be left as-is.
 
-    if (!FixupSection.getKind().isMetadata())
+    if (!FixupSection.isMetadata())
       report_fatal_error("relocations for function or section offsets are "
                          "only supported in metadata sections");
 
     const MCSymbol *SectionSymbol = nullptr;
     const MCSection &SecA = SymA->getSection();
-    if (SecA.getKind().isText()) {
+    if (SecA.isText()) {
       auto SecSymIt = SectionFunctions.find(&SecA);
       if (SecSymIt == SectionFunctions.end())
         report_fatal_error("section doesn\'t have defining symbol");
@@ -627,9 +627,9 @@ void WasmObjectWriter::recordRelocation(MCAssembler &Asm,
 
   if (FixupSection.isWasmData()) {
     DataRelocations.push_back(Rec);
-  } else if (FixupSection.getKind().isText()) {
+  } else if (FixupSection.isText()) {
     CodeRelocations.push_back(Rec);
-  } else if (FixupSection.getKind().isMetadata()) {
+  } else if (FixupSection.isMetadata()) {
     CustomSectionsRelocations[&FixupSection].push_back(Rec);
   } else {
     llvm_unreachable("unexpected section type");
@@ -1498,7 +1498,7 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm,
       continue;
 
     // Code is handled separately
-    if (Section.getKind().isText())
+    if (Section.isText())
       continue;
 
     if (Section.isWasmData()) {
@@ -1524,7 +1524,7 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm,
       }
     } else {
       // Create custom sections
-      assert(Sec.getKind().isMetadata());
+      assert(Section.isMetadata());
 
       StringRef Name = SectionName;
 

diff  --git a/llvm/lib/MC/WinCOFFObjectWriter.cpp b/llvm/lib/MC/WinCOFFObjectWriter.cpp
index e877bf88df81b..8313c897d4130 100644
--- a/llvm/lib/MC/WinCOFFObjectWriter.cpp
+++ b/llvm/lib/MC/WinCOFFObjectWriter.cpp
@@ -1211,15 +1211,13 @@ void WinCOFFObjectWriter::executePostLayoutBinding(MCAssembler &Asm,
                                                    const MCAsmLayout &Layout) {
   if (EmitAddrsigSection) {
     ObjWriter->AddrsigSection = Asm.getContext().getCOFFSection(
-        ".llvm_addrsig", COFF::IMAGE_SCN_LNK_REMOVE,
-        SectionKind::getMetadata());
+        ".llvm_addrsig", COFF::IMAGE_SCN_LNK_REMOVE);
     Asm.registerSection(*ObjWriter->AddrsigSection);
   }
 
   if (!Asm.CGProfile.empty()) {
     ObjWriter->CGProfileSection = Asm.getContext().getCOFFSection(
-        ".llvm.call-graph-profile", COFF::IMAGE_SCN_LNK_REMOVE,
-        SectionKind::getMetadata());
+        ".llvm.call-graph-profile", COFF::IMAGE_SCN_LNK_REMOVE);
     Asm.registerSection(*ObjWriter->CGProfileSection);
   }
 

diff  --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
index b6cecccf3572d..50a59ce767630 100644
--- a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
+++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
@@ -328,7 +328,8 @@ void ARMELFObjectWriter::addTargetSectionFlags(MCContext &Ctx,
   // execute-only section in the object.
   MCSectionELF *TextSection =
       static_cast<MCSectionELF *>(Ctx.getObjectFileInfo()->getTextSection());
-  if (Sec.getKind().isExecuteOnly() && !TextSection->hasInstructions()) {
+  bool IsExecOnly = Sec.getFlags() & ELF::SHF_ARM_PURECODE;
+  if (IsExecOnly && !TextSection->hasInstructions()) {
     for (auto &F : *TextSection)
       if (auto *DF = dyn_cast<MCDataFragment>(&F))
         if (!DF->getContents().empty())

diff  --git a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.cpp b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.cpp
index 1aff608cfffbe..15911f35b613c 100644
--- a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.cpp
+++ b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.cpp
@@ -46,8 +46,7 @@ static bool isDwarfSection(const MCObjectFileInfo *FI,
                            const MCSection *Section) {
   // FIXME: the checks for the DWARF sections are very fragile and should be
   // fixed up in a followup patch.
-  if (!Section || Section->getKind().isText() ||
-      Section->getKind().isWriteable())
+  if (!Section || Section->isText())
     return false;
   return Section == FI->getDwarfAbbrevSection() ||
          Section == FI->getDwarfInfoSection() ||

diff  --git a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
index f5bc584ac4e1a..3cc2cc0e830f1 100644
--- a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
+++ b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
@@ -757,7 +757,7 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
   bool CheckDataSection() {
     if (CurrentState != DataSection) {
       auto WS = cast<MCSectionWasm>(getStreamer().getCurrentSection().first);
-      if (WS && WS->getKind().isText())
+      if (WS && WS->isText())
         return error("data directive must occur in a data segment: ",
                      Lexer.getTok());
     }
@@ -1074,7 +1074,7 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
   void doBeforeLabelEmit(MCSymbol *Symbol, SMLoc IDLoc) override {
     // Code below only applies to labels in text sections.
     auto CWS = cast<MCSectionWasm>(getStreamer().getCurrentSection().first);
-    if (!CWS || !CWS->getKind().isText())
+    if (!CWS || !CWS->isText())
       return;
 
     auto WasmSym = cast<MCSymbolWasm>(Symbol);

diff  --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp
index 43c67b4b4749b..b76179b1cf6e8 100644
--- a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp
+++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp
@@ -122,7 +122,7 @@ unsigned WebAssemblyWasmObjectWriter::getRelocType(
     return wasm::R_WASM_MEMORY_ADDR_LEB64;
   case FK_Data_4:
     if (SymA.isFunction()) {
-      if (FixupSection.getKind().isMetadata())
+      if (FixupSection.isMetadata())
         return wasm::R_WASM_FUNCTION_OFFSET_I32;
       assert(FixupSection.isWasmData());
       return wasm::R_WASM_TABLE_INDEX_I32;
@@ -131,7 +131,7 @@ unsigned WebAssemblyWasmObjectWriter::getRelocType(
       return wasm::R_WASM_GLOBAL_INDEX_I32;
     if (auto Section = static_cast<const MCSectionWasm *>(
             getTargetSection(Fixup.getValue()))) {
-      if (Section->getKind().isText())
+      if (Section->isText())
         return wasm::R_WASM_FUNCTION_OFFSET_I32;
       else if (!Section->isWasmData())
         return wasm::R_WASM_SECTION_OFFSET_I32;
@@ -140,7 +140,7 @@ unsigned WebAssemblyWasmObjectWriter::getRelocType(
                     : wasm::R_WASM_MEMORY_ADDR_I32;
   case FK_Data_8:
     if (SymA.isFunction()) {
-      if (FixupSection.getKind().isMetadata())
+      if (FixupSection.isMetadata())
         return wasm::R_WASM_FUNCTION_OFFSET_I64;
       return wasm::R_WASM_TABLE_INDEX_I64;
     }
@@ -148,7 +148,7 @@ unsigned WebAssemblyWasmObjectWriter::getRelocType(
       llvm_unreachable("unimplemented R_WASM_GLOBAL_INDEX_I64");
     if (auto Section = static_cast<const MCSectionWasm *>(
             getTargetSection(Fixup.getValue()))) {
-      if (Section->getKind().isText())
+      if (Section->isText())
         return wasm::R_WASM_FUNCTION_OFFSET_I64;
       else if (!Section->isWasmData())
         llvm_unreachable("unimplemented R_WASM_SECTION_OFFSET_I64");

diff  --git a/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
index 02d0aac4fed41..c2188d206b5f6 100644
--- a/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
+++ b/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
@@ -480,7 +480,7 @@ bool X86AsmBackend::canPadBranches(MCObjectStreamer &OS) const {
   assert(allowAutoPadding() && "incorrect initialization!");
 
   // We only pad in text section.
-  if (!OS.getCurrentSectionOnly()->getKind().isText())
+  if (!OS.getCurrentSectionOnly()->isText())
     return false;
 
   // To be Done: Currently don't deal with Bundle cases.
@@ -878,7 +878,7 @@ void X86AsmBackend::finishLayout(MCAssembler const &Asm,
     LabeledFragments.insert(S.getFragment(false));
 
   for (MCSection &Sec : Asm) {
-    if (!Sec.getKind().isText())
+    if (!Sec.isText())
       continue;
 
     SmallVector<MCRelaxableFragment *, 4> Relaxable;


        


More information about the llvm-commits mailing list