[llvm] d3d9f7c - [ORC][JITLink] Move MemoryFlags.h (MemProt, AllocGroup,...) from JITLink to ORC.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 3 19:35:58 PDT 2022


Author: Lang Hames
Date: 2022-10-03T19:35:34-07:00
New Revision: d3d9f7caf96680dad4ef0fd108e64ca044a0a113

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

LOG: [ORC][JITLink] Move MemoryFlags.h (MemProt, AllocGroup,...) from JITLink to ORC.

Moving these types to OrcShared eliminates the need for the separate
WireProtectionFlags type.

Added: 
    llvm/include/llvm/ExecutionEngine/Orc/Shared/MemoryFlags.h

Modified: 
    llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
    llvm/include/llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h
    llvm/include/llvm/ExecutionEngine/JITLink/aarch64.h
    llvm/include/llvm/ExecutionEngine/JITLink/x86_64.h
    llvm/include/llvm/ExecutionEngine/Orc/EPCGenericRTDyldMemoryManager.h
    llvm/include/llvm/ExecutionEngine/Orc/MemoryMapper.h
    llvm/include/llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h
    llvm/lib/ExecutionEngine/JITLink/CMakeLists.txt
    llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.cpp
    llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h
    llvm/lib/ExecutionEngine/JITLink/ELF_aarch64.cpp
    llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
    llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp
    llvm/lib/ExecutionEngine/JITLink/JITLinkMemoryManager.cpp
    llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp
    llvm/lib/ExecutionEngine/Orc/COFFPlatform.cpp
    llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp
    llvm/lib/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManager.cpp
    llvm/lib/ExecutionEngine/Orc/EPCGenericRTDyldMemoryManager.cpp
    llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp
    llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
    llvm/lib/ExecutionEngine/Orc/MapperJITLinkMemoryManager.cpp
    llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp
    llvm/lib/ExecutionEngine/Orc/TargetProcess/ExecutorSharedMemoryMapperService.cpp
    llvm/lib/ExecutionEngine/Orc/TargetProcess/SimpleExecutorMemoryManager.cpp
    llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp
    llvm/unittests/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManagerTest.cpp
    llvm/unittests/ExecutionEngine/Orc/MapperJITLinkMemoryManagerTest.cpp
    llvm/unittests/ExecutionEngine/Orc/MemoryMapperTest.cpp
    llvm/unittests/ExecutionEngine/Orc/SharedMemoryMapperTest.cpp
    llvm/unittests/ExecutionEngine/Orc/SimpleExecutorMemoryManagerTest.cpp

Removed: 
    llvm/include/llvm/ExecutionEngine/JITLink/MemoryFlags.h
    llvm/lib/ExecutionEngine/JITLink/MemoryFlags.cpp


################################################################################
diff  --git a/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h b/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
index 89644994bc1d8..7f8dd7303050f 100644
--- a/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
+++ b/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
@@ -19,8 +19,8 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/Triple.h"
 #include "llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h"
-#include "llvm/ExecutionEngine/JITLink/MemoryFlags.h"
 #include "llvm/ExecutionEngine/JITSymbol.h"
+#include "llvm/ExecutionEngine/Orc/Shared/MemoryFlags.h"
 #include "llvm/Support/Allocator.h"
 #include "llvm/Support/Endian.h"
 #include "llvm/Support/Error.h"
@@ -667,7 +667,7 @@ class Section {
   friend class LinkGraph;
 
 private:
-  Section(StringRef Name, MemProt Prot, SectionOrdinal SecOrdinal)
+  Section(StringRef Name, orc::MemProt Prot, SectionOrdinal SecOrdinal)
       : Name(Name), Prot(Prot), SecOrdinal(SecOrdinal) {}
 
   using SymbolSet = DenseSet<Symbol *>;
@@ -692,16 +692,16 @@ class Section {
   StringRef getName() const { return Name; }
 
   /// Returns the protection flags for this section.
-  MemProt getMemProt() const { return Prot; }
+  orc::MemProt getMemProt() const { return Prot; }
 
   /// Set the protection flags for this section.
-  void setMemProt(MemProt Prot) { this->Prot = Prot; }
+  void setMemProt(orc::MemProt Prot) { this->Prot = Prot; }
 
   /// Get the deallocation policy for this section.
-  MemDeallocPolicy getMemDeallocPolicy() const { return MDP; }
+  orc::MemDeallocPolicy getMemDeallocPolicy() const { return MDP; }
 
   /// Set the deallocation policy for this section.
-  void setMemDeallocPolicy(MemDeallocPolicy MDP) { this->MDP = MDP; }
+  void setMemDeallocPolicy(orc::MemDeallocPolicy MDP) { this->MDP = MDP; }
 
   /// Returns the ordinal for this section.
   SectionOrdinal getOrdinal() const { return SecOrdinal; }
@@ -765,8 +765,8 @@ class Section {
   }
 
   StringRef Name;
-  MemProt Prot;
-  MemDeallocPolicy MDP = MemDeallocPolicy::Standard;
+  orc::MemProt Prot;
+  orc::MemDeallocPolicy MDP = orc::MemDeallocPolicy::Standard;
   SectionOrdinal SecOrdinal = 0;
   BlockSet Blocks;
   SymbolSet Symbols;
@@ -1003,7 +1003,7 @@ class LinkGraph {
   }
 
   /// Create a section with the given name, protection flags, and alignment.
-  Section &createSection(StringRef Name, MemProt Prot) {
+  Section &createSection(StringRef Name, orc::MemProt Prot) {
     assert(llvm::none_of(Sections,
                          [&](std::unique_ptr<Section> &Sec) {
                            return Sec->getName() == Name;

diff  --git a/llvm/include/llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h b/llvm/include/llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h
index abfeafe798e79..6ef4a0bd0c982 100644
--- a/llvm/include/llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h
+++ b/llvm/include/llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h
@@ -16,9 +16,9 @@
 #include "llvm/ADT/FunctionExtras.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ExecutionEngine/JITLink/JITLinkDylib.h"
-#include "llvm/ExecutionEngine/JITLink/MemoryFlags.h"
 #include "llvm/ExecutionEngine/Orc/Shared/AllocationActions.h"
 #include "llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h"
+#include "llvm/ExecutionEngine/Orc/Shared/MemoryFlags.h"
 #include "llvm/Support/Allocator.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/MSVCErrorWorkarounds.h"
@@ -246,7 +246,7 @@ class BasicLayout {
   };
 
 private:
-  using SegmentMap = AllocGroupSmallMap<Segment>;
+  using SegmentMap = orc::AllocGroupSmallMap<Segment>;
 
 public:
   BasicLayout(LinkGraph &G);
@@ -309,7 +309,7 @@ class SimpleSegmentAlloc {
     MutableArrayRef<char> WorkingMem;
   };
 
-  using SegmentMap = AllocGroupSmallMap<Segment>;
+  using SegmentMap = orc::AllocGroupSmallMap<Segment>;
 
   using OnCreatedFunction = unique_function<void(Expected<SimpleSegmentAlloc>)>;
 
@@ -328,7 +328,7 @@ class SimpleSegmentAlloc {
   ~SimpleSegmentAlloc();
 
   /// Returns the SegmentInfo for the given group.
-  SegmentInfo getSegInfo(AllocGroup AG);
+  SegmentInfo getSegInfo(orc::AllocGroup AG);
 
   /// Finalize all groups (async version).
   void finalize(OnFinalizedFunction OnFinalized) {
@@ -342,11 +342,12 @@ class SimpleSegmentAlloc {
 
 private:
   SimpleSegmentAlloc(
-      std::unique_ptr<LinkGraph> G, AllocGroupSmallMap<Block *> ContentBlocks,
+      std::unique_ptr<LinkGraph> G,
+      orc::AllocGroupSmallMap<Block *> ContentBlocks,
       std::unique_ptr<JITLinkMemoryManager::InFlightAlloc> Alloc);
 
   std::unique_ptr<LinkGraph> G;
-  AllocGroupSmallMap<Block *> ContentBlocks;
+  orc::AllocGroupSmallMap<Block *> ContentBlocks;
   std::unique_ptr<JITLinkMemoryManager::InFlightAlloc> Alloc;
 };
 

diff  --git a/llvm/include/llvm/ExecutionEngine/JITLink/aarch64.h b/llvm/include/llvm/ExecutionEngine/JITLink/aarch64.h
index 11fbbbd579d00..76aaadd8816f6 100644
--- a/llvm/include/llvm/ExecutionEngine/JITLink/aarch64.h
+++ b/llvm/include/llvm/ExecutionEngine/JITLink/aarch64.h
@@ -15,7 +15,7 @@
 
 #include "TableManager.h"
 #include "llvm/ExecutionEngine/JITLink/JITLink.h"
-#include "llvm/ExecutionEngine/JITLink/MemoryFlags.h"
+#include "llvm/ExecutionEngine/Orc/Shared/MemoryFlags.h"
 
 namespace llvm {
 namespace jitlink {
@@ -309,8 +309,8 @@ class GOTTableManager : public TableManager<GOTTableManager> {
 private:
   Section &getGOTSection(LinkGraph &G) {
     if (!GOTSection)
-      GOTSection =
-          &G.createSection(getSectionName(), MemProt::Read | MemProt::Exec);
+      GOTSection = &G.createSection(getSectionName(),
+                                    orc::MemProt::Read | orc::MemProt::Exec);
     return *GOTSection;
   }
 
@@ -354,8 +354,8 @@ class PLTTableManager : public TableManager<PLTTableManager> {
 public:
   Section &getStubsSection(LinkGraph &G) {
     if (!StubsSection)
-      StubsSection =
-          &G.createSection(getSectionName(), MemProt::Read | MemProt::Exec);
+      StubsSection = &G.createSection(getSectionName(),
+                                      orc::MemProt::Read | orc::MemProt::Exec);
     return *StubsSection;
   }
 

diff  --git a/llvm/include/llvm/ExecutionEngine/JITLink/x86_64.h b/llvm/include/llvm/ExecutionEngine/JITLink/x86_64.h
index 2de949f21656d..8e1fbba4e173a 100644
--- a/llvm/include/llvm/ExecutionEngine/JITLink/x86_64.h
+++ b/llvm/include/llvm/ExecutionEngine/JITLink/x86_64.h
@@ -607,7 +607,7 @@ class GOTTableManager : public TableManager<GOTTableManager> {
 private:
   Section &getGOTSection(LinkGraph &G) {
     if (!GOTSection)
-      GOTSection = &G.createSection(getSectionName(), MemProt::Read);
+      GOTSection = &G.createSection(getSectionName(), orc::MemProt::Read);
     return *GOTSection;
   }
 
@@ -645,8 +645,8 @@ class PLTTableManager : public TableManager<PLTTableManager> {
 public:
   Section &getStubsSection(LinkGraph &G) {
     if (!PLTSection)
-      PLTSection =
-          &G.createSection(getSectionName(), MemProt::Read | MemProt::Exec);
+      PLTSection = &G.createSection(getSectionName(),
+                                    orc::MemProt::Read | orc::MemProt::Exec);
     return *PLTSection;
   }
 

diff  --git a/llvm/include/llvm/ExecutionEngine/Orc/EPCGenericRTDyldMemoryManager.h b/llvm/include/llvm/ExecutionEngine/Orc/EPCGenericRTDyldMemoryManager.h
index 29d282372b1f6..8fa1a4cd6355a 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/EPCGenericRTDyldMemoryManager.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/EPCGenericRTDyldMemoryManager.h
@@ -77,9 +77,9 @@ class EPCGenericRTDyldMemoryManager : public RuntimeDyld::MemoryManager {
   bool finalizeMemory(std::string *ErrMsg = nullptr) override;
 
 private:
-  struct Alloc {
+  struct SectionAlloc {
   public:
-    Alloc(uint64_t Size, unsigned Align)
+    SectionAlloc(uint64_t Size, unsigned Align)
         : Size(Size), Align(Align),
           Contents(std::make_unique<uint8_t[]>(Size + Align - 1)) {}
 
@@ -92,30 +92,31 @@ class EPCGenericRTDyldMemoryManager : public RuntimeDyld::MemoryManager {
   // Group of section allocations to be allocated together in the executor. The
   // RemoteCodeAddr will stand in as the id of the group for deallocation
   // purposes.
-  struct AllocGroup {
-    AllocGroup() = default;
-    AllocGroup(const AllocGroup &) = delete;
-    AllocGroup &operator=(const AllocGroup &) = delete;
-    AllocGroup(AllocGroup &&) = default;
-    AllocGroup &operator=(AllocGroup &&) = default;
+  struct SectionAllocGroup {
+    SectionAllocGroup() = default;
+    SectionAllocGroup(const SectionAllocGroup &) = delete;
+    SectionAllocGroup &operator=(const SectionAllocGroup &) = delete;
+    SectionAllocGroup(SectionAllocGroup &&) = default;
+    SectionAllocGroup &operator=(SectionAllocGroup &&) = default;
 
     ExecutorAddrRange RemoteCode;
     ExecutorAddrRange RemoteROData;
     ExecutorAddrRange RemoteRWData;
     std::vector<ExecutorAddrRange> UnfinalizedEHFrames;
-    std::vector<Alloc> CodeAllocs, RODataAllocs, RWDataAllocs;
+    std::vector<SectionAlloc> CodeAllocs, RODataAllocs, RWDataAllocs;
   };
 
-  // Maps all allocations in Allocs to aligned blocks
-  void mapAllocsToRemoteAddrs(RuntimeDyld &Dyld, std::vector<Alloc> &Allocs,
+  // Maps all allocations in SectionAllocs to aligned blocks
+  void mapAllocsToRemoteAddrs(RuntimeDyld &Dyld,
+                              std::vector<SectionAlloc> &SecAllocs,
                               ExecutorAddr NextAddr);
 
   ExecutorProcessControl &EPC;
   SymbolAddrs SAs;
 
   std::mutex M;
-  std::vector<AllocGroup> Unmapped;
-  std::vector<AllocGroup> Unfinalized;
+  std::vector<SectionAllocGroup> Unmapped;
+  std::vector<SectionAllocGroup> Unfinalized;
   std::vector<ExecutorAddr> FinalizedAllocs;
   std::string ErrMsg;
 };

diff  --git a/llvm/include/llvm/ExecutionEngine/Orc/MemoryMapper.h b/llvm/include/llvm/ExecutionEngine/Orc/MemoryMapper.h
index 17072d2fa5b12..9f9ff06b2c2f6 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/MemoryMapper.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/MemoryMapper.h
@@ -14,6 +14,7 @@
 #define LLVM_EXECUTIONENGINE_ORC_MEMORYMAPPER_H
 
 #include "llvm/ExecutionEngine/Orc/Core.h"
+#include "llvm/ExecutionEngine/Orc/Shared/MemoryFlags.h"
 #include "llvm/Support/Process.h"
 
 #include <mutex>
@@ -32,7 +33,7 @@ class MemoryMapper {
       const char *WorkingMem;
       size_t ContentSize;
       size_t ZeroFillSize;
-      unsigned Prot;
+      AllocGroup AG;
     };
 
     ExecutorAddr MappingBase;

diff  --git a/llvm/include/llvm/ExecutionEngine/JITLink/MemoryFlags.h b/llvm/include/llvm/ExecutionEngine/Orc/Shared/MemoryFlags.h
similarity index 77%
rename from llvm/include/llvm/ExecutionEngine/JITLink/MemoryFlags.h
rename to llvm/include/llvm/ExecutionEngine/Orc/Shared/MemoryFlags.h
index a18098e5a1a92..2642e6c241b6e 100644
--- a/llvm/include/llvm/ExecutionEngine/JITLink/MemoryFlags.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/Shared/MemoryFlags.h
@@ -11,8 +11,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_EXECUTIONENGINE_JITLINK_MEMORYFLAGS_H
-#define LLVM_EXECUTIONENGINE_JITLINK_MEMORYFLAGS_H
+#ifndef LLVM_EXECUTIONENGINE_ORC_SHARED_MEMORYFLAGS_H
+#define LLVM_EXECUTIONENGINE_ORC_SHARED_MEMORYFLAGS_H
 
 #include "llvm/ADT/BitmaskEnum.h"
 #include "llvm/ADT/DenseMapInfo.h"
@@ -21,7 +21,7 @@
 #include "llvm/Support/raw_ostream.h"
 
 namespace llvm {
-namespace jitlink {
+namespace orc {
 
 /// Describes Read/Write/Exec permissions for memory.
 enum class MemProt {
@@ -33,7 +33,11 @@ enum class MemProt {
 };
 
 /// Print a MemProt as an RWX triple.
-raw_ostream &operator<<(raw_ostream &OS, MemProt MP);
+inline raw_ostream &operator<<(raw_ostream &OS, MemProt MP) {
+  return OS << (((MP & MemProt::Read) != MemProt::None) ? 'R' : '-')
+            << (((MP & MemProt::Write) != MemProt::None) ? 'W' : '-')
+            << (((MP & MemProt::Exec) != MemProt::None) ? 'X' : '-');
+}
 
 /// Convert a MemProt value to a corresponding sys::Memory::ProtectionFlags
 /// value.
@@ -79,7 +83,9 @@ enum class MemDeallocPolicy {
 };
 
 /// Print a MemDeallocPolicy.
-raw_ostream &operator<<(raw_ostream &OS, MemDeallocPolicy MDP);
+inline raw_ostream &operator<<(raw_ostream &OS, MemDeallocPolicy MDP) {
+  return OS << (MDP == MemDeallocPolicy::Standard ? "standard" : "finalize");
+}
 
 /// A pair of memory protections and allocation policies.
 ///
@@ -179,44 +185,42 @@ template <typename T> class AllocGroupSmallMap {
 };
 
 /// Print an AllocGroup.
-raw_ostream &operator<<(raw_ostream &OS, AllocGroup AG);
+inline raw_ostream &operator<<(raw_ostream &OS, AllocGroup AG) {
+  return OS << '(' << AG.getMemProt() << ", " << AG.getMemDeallocPolicy()
+            << ')';
+}
 
-} // end namespace jitlink
+} // end namespace orc
 
-template <> struct DenseMapInfo<jitlink::MemProt> {
-  static inline jitlink::MemProt getEmptyKey() {
-    return jitlink::MemProt(~uint8_t(0));
-  }
-  static inline jitlink::MemProt getTombstoneKey() {
-    return jitlink::MemProt(~uint8_t(0) - 1);
+template <> struct DenseMapInfo<orc::MemProt> {
+  static inline orc::MemProt getEmptyKey() { return orc::MemProt(~uint8_t(0)); }
+  static inline orc::MemProt getTombstoneKey() {
+    return orc::MemProt(~uint8_t(0) - 1);
   }
-  static unsigned getHashValue(const jitlink::MemProt &Val) {
-    using UT = std::underlying_type_t<jitlink::MemProt>;
+  static unsigned getHashValue(const orc::MemProt &Val) {
+    using UT = std::underlying_type_t<orc::MemProt>;
     return DenseMapInfo<UT>::getHashValue(static_cast<UT>(Val));
   }
-  static bool isEqual(const jitlink::MemProt &LHS,
-                      const jitlink::MemProt &RHS) {
+  static bool isEqual(const orc::MemProt &LHS, const orc::MemProt &RHS) {
     return LHS == RHS;
   }
 };
 
-template <> struct DenseMapInfo<jitlink::AllocGroup> {
-  static inline jitlink::AllocGroup getEmptyKey() {
-    return jitlink::AllocGroup(~uint8_t(0));
+template <> struct DenseMapInfo<orc::AllocGroup> {
+  static inline orc::AllocGroup getEmptyKey() {
+    return orc::AllocGroup(~uint8_t(0));
   }
-  static inline jitlink::AllocGroup getTombstoneKey() {
-    return jitlink::AllocGroup(~uint8_t(0) - 1);
+  static inline orc::AllocGroup getTombstoneKey() {
+    return orc::AllocGroup(~uint8_t(0) - 1);
   }
-  static unsigned getHashValue(const jitlink::AllocGroup &Val) {
-    return DenseMapInfo<jitlink::AllocGroup::underlying_type>::getHashValue(
-        Val.Id);
+  static unsigned getHashValue(const orc::AllocGroup &Val) {
+    return DenseMapInfo<orc::AllocGroup::underlying_type>::getHashValue(Val.Id);
   }
-  static bool isEqual(const jitlink::AllocGroup &LHS,
-                      const jitlink::AllocGroup &RHS) {
+  static bool isEqual(const orc::AllocGroup &LHS, const orc::AllocGroup &RHS) {
     return LHS == RHS;
   }
 };
 
 } // end namespace llvm
 
-#endif // LLVM_EXECUTIONENGINE_JITLINK_MEMORYFLAGS_H
+#endif // LLVM_EXECUTIONENGINE_ORC_SHARED_MEMORYFLAGS_H

diff  --git a/llvm/include/llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h b/llvm/include/llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h
index 502c7c1f70694..4096366d2e36e 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h
@@ -19,6 +19,7 @@
 #include "llvm/ExecutionEngine/JITSymbol.h"
 #include "llvm/ExecutionEngine/Orc/Shared/AllocationActions.h"
 #include "llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h"
+#include "llvm/ExecutionEngine/Orc/Shared/MemoryFlags.h"
 #include "llvm/ExecutionEngine/Orc/Shared/SimplePackedSerialization.h"
 #include "llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h"
 #include "llvm/Support/Memory.h"
@@ -29,49 +30,8 @@ namespace llvm {
 namespace orc {
 namespace tpctypes {
 
-enum WireProtectionFlags : uint8_t {
-  WPF_None = 0,
-  WPF_Read = 1U << 0,
-  WPF_Write = 1U << 1,
-  WPF_Exec = 1U << 2,
-  LLVM_MARK_AS_BITMASK_ENUM(WPF_Exec)
-};
-
-/// Convert from sys::Memory::ProtectionFlags
-inline WireProtectionFlags
-toWireProtectionFlags(sys::Memory::ProtectionFlags PF) {
-  WireProtectionFlags WPF = WPF_None;
-  if (PF & sys::Memory::MF_READ)
-    WPF |= WPF_Read;
-  if (PF & sys::Memory::MF_WRITE)
-    WPF |= WPF_Write;
-  if (PF & sys::Memory::MF_EXEC)
-    WPF |= WPF_Exec;
-  return WPF;
-}
-
-inline sys::Memory::ProtectionFlags
-fromWireProtectionFlags(WireProtectionFlags WPF) {
-  int PF = 0;
-  if (WPF & WPF_Read)
-    PF |= sys::Memory::MF_READ;
-  if (WPF & WPF_Write)
-    PF |= sys::Memory::MF_WRITE;
-  if (WPF & WPF_Exec)
-    PF |= sys::Memory::MF_EXEC;
-  return static_cast<sys::Memory::ProtectionFlags>(PF);
-}
-
-inline std::string getWireProtectionFlagsStr(WireProtectionFlags WPF) {
-  std::string Result;
-  Result += (WPF & WPF_Read) ? 'R' : '-';
-  Result += (WPF & WPF_Write) ? 'W' : '-';
-  Result += (WPF & WPF_Exec) ? 'X' : '-';
-  return Result;
-}
-
 struct SegFinalizeRequest {
-  WireProtectionFlags Prot;
+  AllocGroup AG;
   ExecutorAddr Addr;
   uint64_t Size;
   ArrayRef<char> Content;
@@ -83,7 +43,7 @@ struct FinalizeRequest {
 };
 
 struct SharedMemorySegFinalizeRequest {
-  WireProtectionFlags Prot;
+  AllocGroup AG;
   ExecutorAddr Addr;
   uint64_t Size;
 };
@@ -133,17 +93,16 @@ using LookupResult = std::vector<JITTargetAddress>;
 
 namespace shared {
 
-class SPSMemoryProtectionFlags {};
+class SPSAllocGroup {};
 
 using SPSSegFinalizeRequest =
-    SPSTuple<SPSMemoryProtectionFlags, SPSExecutorAddr, uint64_t,
-             SPSSequence<char>>;
+    SPSTuple<SPSAllocGroup, SPSExecutorAddr, uint64_t, SPSSequence<char>>;
 
 using SPSFinalizeRequest = SPSTuple<SPSSequence<SPSSegFinalizeRequest>,
                                     SPSSequence<SPSAllocActionCallPair>>;
 
 using SPSSharedMemorySegFinalizeRequest =
-    SPSTuple<SPSMemoryProtectionFlags, SPSExecutorAddr, uint64_t>;
+    SPSTuple<SPSAllocGroup, SPSExecutorAddr, uint64_t>;
 
 using SPSSharedMemoryFinalizeRequest =
     SPSTuple<SPSSequence<SPSSharedMemorySegFinalizeRequest>,
@@ -159,25 +118,47 @@ using SPSMemoryAccessUInt64Write = SPSMemoryAccessUIntWrite<uint64_t>;
 
 using SPSMemoryAccessBufferWrite = SPSTuple<SPSExecutorAddr, SPSSequence<char>>;
 
-template <>
-class SPSSerializationTraits<SPSMemoryProtectionFlags,
-                             tpctypes::WireProtectionFlags> {
+template <> class SPSSerializationTraits<SPSAllocGroup, AllocGroup> {
+  enum WireBits {
+    ReadBit = 1 << 0,
+    WriteBit = 1 << 1,
+    ExecBit = 1 << 2,
+    FinalizeBit = 1 << 3
+  };
+
 public:
-  static size_t size(const tpctypes::WireProtectionFlags &WPF) {
-    return SPSArgList<uint8_t>::size(static_cast<uint8_t>(WPF));
+  static size_t size(const AllocGroup &AG) {
+    // All AllocGroup values encode to the same size.
+    return SPSArgList<uint8_t>::size(uint8_t(0));
   }
 
-  static bool serialize(SPSOutputBuffer &OB,
-                        const tpctypes::WireProtectionFlags &WPF) {
-    return SPSArgList<uint8_t>::serialize(OB, static_cast<uint8_t>(WPF));
+  static bool serialize(SPSOutputBuffer &OB, const AllocGroup &AG) {
+    uint8_t WireValue = 0;
+    if ((AG.getMemProt() & MemProt::Read) != MemProt::None)
+      WireValue |= ReadBit;
+    if ((AG.getMemProt() & MemProt::Write) != MemProt::None)
+      WireValue |= WriteBit;
+    if ((AG.getMemProt() & MemProt::Exec) != MemProt::None)
+      WireValue |= ExecBit;
+    if (AG.getMemDeallocPolicy() == MemDeallocPolicy::Finalize)
+      WireValue |= FinalizeBit;
+    return SPSArgList<uint8_t>::serialize(OB, WireValue);
   }
 
-  static bool deserialize(SPSInputBuffer &IB,
-                          tpctypes::WireProtectionFlags &WPF) {
+  static bool deserialize(SPSInputBuffer &IB, AllocGroup &AG) {
     uint8_t Val;
     if (!SPSArgList<uint8_t>::deserialize(IB, Val))
       return false;
-    WPF = static_cast<tpctypes::WireProtectionFlags>(Val);
+    MemProt MP = MemProt::None;
+    if (Val & ReadBit)
+      MP |= MemProt::Read;
+    if (Val & WriteBit)
+      MP |= MemProt::Write;
+    if (Val & ExecBit)
+      MP |= MemProt::Exec;
+    MemDeallocPolicy MDP = (Val & FinalizeBit) ? MemDeallocPolicy::Finalize
+                                               : MemDeallocPolicy::Standard;
+    AG = AllocGroup(MP, MDP);
     return true;
   }
 };
@@ -189,17 +170,17 @@ class SPSSerializationTraits<SPSSegFinalizeRequest,
 
 public:
   static size_t size(const tpctypes::SegFinalizeRequest &SFR) {
-    return SFRAL::size(SFR.Prot, SFR.Addr, SFR.Size, SFR.Content);
+    return SFRAL::size(SFR.AG, SFR.Addr, SFR.Size, SFR.Content);
   }
 
   static bool serialize(SPSOutputBuffer &OB,
                         const tpctypes::SegFinalizeRequest &SFR) {
-    return SFRAL::serialize(OB, SFR.Prot, SFR.Addr, SFR.Size, SFR.Content);
+    return SFRAL::serialize(OB, SFR.AG, SFR.Addr, SFR.Size, SFR.Content);
   }
 
   static bool deserialize(SPSInputBuffer &IB,
                           tpctypes::SegFinalizeRequest &SFR) {
-    return SFRAL::deserialize(IB, SFR.Prot, SFR.Addr, SFR.Size, SFR.Content);
+    return SFRAL::deserialize(IB, SFR.AG, SFR.Addr, SFR.Size, SFR.Content);
   }
 };
 
@@ -229,17 +210,17 @@ class SPSSerializationTraits<SPSSharedMemorySegFinalizeRequest,
 
 public:
   static size_t size(const tpctypes::SharedMemorySegFinalizeRequest &SFR) {
-    return SFRAL::size(SFR.Prot, SFR.Addr, SFR.Size);
+    return SFRAL::size(SFR.AG, SFR.Addr, SFR.Size);
   }
 
   static bool serialize(SPSOutputBuffer &OB,
                         const tpctypes::SharedMemorySegFinalizeRequest &SFR) {
-    return SFRAL::serialize(OB, SFR.Prot, SFR.Addr, SFR.Size);
+    return SFRAL::serialize(OB, SFR.AG, SFR.Addr, SFR.Size);
   }
 
   static bool deserialize(SPSInputBuffer &IB,
                           tpctypes::SharedMemorySegFinalizeRequest &SFR) {
-    return SFRAL::deserialize(IB, SFR.Prot, SFR.Addr, SFR.Size);
+    return SFRAL::deserialize(IB, SFR.AG, SFR.Addr, SFR.Size);
   }
 };
 

diff  --git a/llvm/lib/ExecutionEngine/JITLink/CMakeLists.txt b/llvm/lib/ExecutionEngine/JITLink/CMakeLists.txt
index 8e165c8c64fc1..f10e70925898b 100644
--- a/llvm/lib/ExecutionEngine/JITLink/CMakeLists.txt
+++ b/llvm/lib/ExecutionEngine/JITLink/CMakeLists.txt
@@ -8,7 +8,6 @@ add_llvm_component_library(LLVMJITLink
   JITLink.cpp
   JITLinkGeneric.cpp
   JITLinkMemoryManager.cpp
-  MemoryFlags.cpp
 
   # Formats:
 

diff  --git a/llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.cpp b/llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.cpp
index 24c122b35c619..a5bbe4625b50e 100644
--- a/llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.cpp
@@ -71,8 +71,8 @@ bool COFFLinkGraphBuilder::isComdatSection(
 
 Section &COFFLinkGraphBuilder::getCommonSection() {
   if (!CommonSection)
-    CommonSection =
-        &G->createSection(CommonSectionName, MemProt::Read | MemProt::Write);
+    CommonSection = &G->createSection(CommonSectionName,
+                                      orc::MemProt::Read | orc::MemProt::Write);
   return *CommonSection;
 }
 
@@ -142,13 +142,13 @@ Error COFFLinkGraphBuilder::graphifySections() {
     });
 
     // Get the section's memory protection flags.
-    MemProt Prot = MemProt::Read;
+    orc::MemProt Prot = orc::MemProt::Read;
     if ((*Sec)->Characteristics & COFF::IMAGE_SCN_MEM_EXECUTE)
-      Prot |= MemProt::Exec;
+      Prot |= orc::MemProt::Exec;
     if ((*Sec)->Characteristics & COFF::IMAGE_SCN_MEM_READ)
-      Prot |= MemProt::Read;
+      Prot |= orc::MemProt::Read;
     if ((*Sec)->Characteristics & COFF::IMAGE_SCN_MEM_WRITE)
-      Prot |= MemProt::Write;
+      Prot |= orc::MemProt::Write;
 
     // Look for existing sections first.
     auto *GraphSec = G->findSectionByName(SectionName);

diff  --git a/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h b/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h
index d21dd606dc197..7f881966bcba2 100644
--- a/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h
+++ b/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h
@@ -37,8 +37,8 @@ class ELFLinkGraphBuilderBase {
 
   Section &getCommonSection() {
     if (!CommonSection)
-      CommonSection =
-          &G->createSection(CommonSectionName, MemProt::Read | MemProt::Write);
+      CommonSection = &G->createSection(
+          CommonSectionName, orc::MemProt::Read | orc::MemProt::Write);
     return *CommonSection;
   }
 
@@ -310,11 +310,11 @@ template <typename ELFT> Error ELFLinkGraphBuilder<ELFT>::graphifySections() {
     });
 
     // Get the section's memory protection flags.
-    MemProt Prot;
+    orc::MemProt Prot;
     if (Sec.sh_flags & ELF::SHF_EXECINSTR)
-      Prot = MemProt::Read | MemProt::Exec;
+      Prot = orc::MemProt::Read | orc::MemProt::Exec;
     else
-      Prot = MemProt::Read | MemProt::Write;
+      Prot = orc::MemProt::Read | orc::MemProt::Write;
 
     // Look for existing sections first.
     auto *GraphSec = G->findSectionByName(*Name);

diff  --git a/llvm/lib/ExecutionEngine/JITLink/ELF_aarch64.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF_aarch64.cpp
index b1fe9c1624e84..da998140a3fa5 100644
--- a/llvm/lib/ExecutionEngine/JITLink/ELF_aarch64.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/ELF_aarch64.cpp
@@ -413,7 +413,7 @@ class TLSInfoTableManager_ELF_aarch64
 private:
   Section &getTLSInfoSection(LinkGraph &G) {
     if (!TLSInfoTable)
-      TLSInfoTable = &G.createSection(getSectionName(), MemProt::Read);
+      TLSInfoTable = &G.createSection(getSectionName(), orc::MemProt::Read);
     return *TLSInfoTable;
   }
 
@@ -481,7 +481,7 @@ class TLSDescTableManager_ELF_aarch64
 private:
   Section &getTLSDescSection(LinkGraph &G) {
     if (!GOTSection)
-      GOTSection = &G.createSection(getSectionName(), MemProt::Read);
+      GOTSection = &G.createSection(getSectionName(), orc::MemProt::Read);
     return *GOTSection;
   }
 

diff  --git a/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
index c7596efe2bb8c..36c736835a83c 100644
--- a/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
@@ -82,14 +82,14 @@ class PerGraphGOTAndPLTStubsBuilder_ELF_riscv
 private:
   Section &getGOTSection() const {
     if (!GOTSection)
-      GOTSection = &G.createSection("$__GOT", MemProt::Read);
+      GOTSection = &G.createSection("$__GOT", orc::MemProt::Read);
     return *GOTSection;
   }
 
   Section &getStubsSection() const {
     if (!StubsSection)
       StubsSection =
-          &G.createSection("$__STUBS", MemProt::Read | MemProt::Exec);
+          &G.createSection("$__STUBS", orc::MemProt::Read | orc::MemProt::Exec);
     return *StubsSection;
   }
 

diff  --git a/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp
index 60d44d5f0ce6e..a0d559b10bfbe 100644
--- a/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp
@@ -68,7 +68,8 @@ class TLSInfoTableManager_ELF_x86_64
 private:
   Section &getTLSInfoSection(LinkGraph &G) {
     if (!TLSInfoTable)
-      TLSInfoTable = &G.createSection(ELFTLSInfoSectionName, MemProt::Read);
+      TLSInfoTable =
+          &G.createSection(ELFTLSInfoSectionName, orc::MemProt::Read);
     return *TLSInfoTable;
   }
 

diff  --git a/llvm/lib/ExecutionEngine/JITLink/JITLinkMemoryManager.cpp b/llvm/lib/ExecutionEngine/JITLink/JITLinkMemoryManager.cpp
index 6bf2381fd571d..bd44b86f30819 100644
--- a/llvm/lib/ExecutionEngine/JITLink/JITLinkMemoryManager.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/JITLinkMemoryManager.cpp
@@ -89,7 +89,7 @@ BasicLayout::getContiguousPageBasedLayoutSizes(uint64_t PageSize) {
                                      inconvertibleErrorCode());
 
     uint64_t SegSize = alignTo(Seg.ContentSize + Seg.ZeroFillSize, PageSize);
-    if (AG.getMemDeallocPolicy() == MemDeallocPolicy::Standard)
+    if (AG.getMemDeallocPolicy() == orc::MemDeallocPolicy::Standard)
       SegsSizes.StandardSegs += SegSize;
     else
       SegsSizes.FinalizeSegs += SegSize;
@@ -146,7 +146,7 @@ void SimpleSegmentAlloc::Create(JITLinkMemoryManager &MemMgr,
                                 const JITLinkDylib *JD, SegmentMap Segments,
                                 OnCreatedFunction OnCreated) {
 
-  static_assert(AllocGroup::NumGroups == 16,
+  static_assert(orc::AllocGroup::NumGroups == 16,
                 "AllocGroup has changed. Section names below must be updated");
   StringRef AGSectionNames[] = {
       "__---.standard", "__R--.standard", "__-W-.standard", "__RW-.standard",
@@ -156,7 +156,7 @@ void SimpleSegmentAlloc::Create(JITLinkMemoryManager &MemMgr,
 
   auto G =
       std::make_unique<LinkGraph>("", Triple(), 0, support::native, nullptr);
-  AllocGroupSmallMap<Block *> ContentBlocks;
+  orc::AllocGroupSmallMap<Block *> ContentBlocks;
 
   orc::ExecutorAddr NextAddr(0x100000);
   for (auto &KV : Segments) {
@@ -213,7 +213,8 @@ SimpleSegmentAlloc &
 SimpleSegmentAlloc::operator=(SimpleSegmentAlloc &&) = default;
 SimpleSegmentAlloc::~SimpleSegmentAlloc() = default;
 
-SimpleSegmentAlloc::SegmentInfo SimpleSegmentAlloc::getSegInfo(AllocGroup AG) {
+SimpleSegmentAlloc::SegmentInfo
+SimpleSegmentAlloc::getSegInfo(orc::AllocGroup AG) {
   auto I = ContentBlocks.find(AG);
   if (I != ContentBlocks.end()) {
     auto &B = *I->second;
@@ -223,7 +224,8 @@ SimpleSegmentAlloc::SegmentInfo SimpleSegmentAlloc::getSegInfo(AllocGroup AG) {
 }
 
 SimpleSegmentAlloc::SimpleSegmentAlloc(
-    std::unique_ptr<LinkGraph> G, AllocGroupSmallMap<Block *> ContentBlocks,
+    std::unique_ptr<LinkGraph> G,
+    orc::AllocGroupSmallMap<Block *> ContentBlocks,
     std::unique_ptr<JITLinkMemoryManager::InFlightAlloc> Alloc)
     : G(std::move(G)), ContentBlocks(std::move(ContentBlocks)),
       Alloc(std::move(Alloc)) {}
@@ -394,9 +396,10 @@ void InProcessMemoryManager::allocate(const JITLinkDylib *JD, LinkGraph &G,
     auto &AG = KV.first;
     auto &Seg = KV.second;
 
-    auto &SegAddr = (AG.getMemDeallocPolicy() == MemDeallocPolicy::Standard)
-                        ? NextStandardSegAddr
-                        : NextFinalizeSegAddr;
+    auto &SegAddr =
+        (AG.getMemDeallocPolicy() == orc::MemDeallocPolicy::Standard)
+            ? NextStandardSegAddr
+            : NextFinalizeSegAddr;
 
     Seg.WorkingMem = SegAddr.toPtr<char *>();
     Seg.Addr = SegAddr;

diff  --git a/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp b/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp
index ff3ecf9af6ddd..d16259bc31cd6 100644
--- a/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp
@@ -111,8 +111,8 @@ MachOLinkGraphBuilder::getEndianness(const object::MachOObjectFile &Obj) {
 
 Section &MachOLinkGraphBuilder::getCommonSection() {
   if (!CommonSection)
-    CommonSection =
-        &G->createSection(CommonSectionName, MemProt::Read | MemProt::Write);
+    CommonSection = &G->createSection(CommonSectionName,
+                                      orc::MemProt::Read | orc::MemProt::Write);
   return *CommonSection;
 }
 
@@ -177,11 +177,11 @@ Error MachOLinkGraphBuilder::createNormalizedSections() {
     // Get prot flags.
     // FIXME: Make sure this test is correct (it's probably missing cases
     // as-is).
-    MemProt Prot;
+    orc::MemProt Prot;
     if (NSec.Flags & MachO::S_ATTR_PURE_INSTRUCTIONS)
-      Prot = MemProt::Read | MemProt::Exec;
+      Prot = orc::MemProt::Read | orc::MemProt::Exec;
     else
-      Prot = MemProt::Read | MemProt::Write;
+      Prot = orc::MemProt::Read | orc::MemProt::Write;
 
     auto FullyQualifiedName =
         G->allocateString(StringRef(NSec.SegName) + "," + NSec.SectName);

diff  --git a/llvm/lib/ExecutionEngine/JITLink/MemoryFlags.cpp b/llvm/lib/ExecutionEngine/JITLink/MemoryFlags.cpp
deleted file mode 100644
index b73a310b2910d..0000000000000
--- a/llvm/lib/ExecutionEngine/JITLink/MemoryFlags.cpp
+++ /dev/null
@@ -1,33 +0,0 @@
-//===------------- MemoryFlags.cpp - Memory allocation flags --------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/ExecutionEngine/JITLink/MemoryFlags.h"
-
-#define DEBUG_TYPE "jitlink"
-
-namespace llvm {
-namespace jitlink {
-
-raw_ostream &operator<<(raw_ostream &OS, MemProt MP) {
-  return OS << (((MP & MemProt::Read) != MemProt::None) ? 'R' : '-')
-            << (((MP & MemProt::Write) != MemProt::None) ? 'W' : '-')
-            << (((MP & MemProt::Exec) != MemProt::None) ? 'X' : '-');
-}
-
-raw_ostream &operator<<(raw_ostream &OS, MemDeallocPolicy MDP) {
-  return OS << (MDP == MemDeallocPolicy::Standard ? "standard" : "finalize");
-}
-
-raw_ostream &operator<<(raw_ostream &OS, AllocGroup AG) {
-  return OS << '(' << AG.getMemProt() << ", " << AG.getMemDeallocPolicy()
-            << ')';
-}
-
-} // end namespace jitlink
-} // end namespace llvm

diff  --git a/llvm/lib/ExecutionEngine/Orc/COFFPlatform.cpp b/llvm/lib/ExecutionEngine/Orc/COFFPlatform.cpp
index 8bd9c294c4c92..642aa74bd4849 100644
--- a/llvm/lib/ExecutionEngine/Orc/COFFPlatform.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/COFFPlatform.cpp
@@ -69,7 +69,7 @@ class COFFHeaderMaterializationUnit : public MaterializationUnit {
     auto G = std::make_unique<jitlink::LinkGraph>(
         "<COFFHeaderMU>", TT, PointerSize, Endianness,
         jitlink::getGenericEdgeKindName);
-    auto &HeaderSection = G->createSection("__header", jitlink::MemProt::Read);
+    auto &HeaderSection = G->createSection("__header", MemProt::Read);
     auto &HeaderBlock = createHeaderBlock(*G, HeaderSection);
 
     // Init symbol is __ImageBase symbol.

diff  --git a/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp b/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp
index e7ca636c83e95..0a90847db221e 100644
--- a/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp
@@ -62,7 +62,7 @@ class DSOHandleMaterializationUnit : public MaterializationUnit {
         "<DSOHandleMU>", TT, PointerSize, Endianness,
         jitlink::getGenericEdgeKindName);
     auto &DSOHandleSection =
-        G->createSection(".data.__dso_handle", jitlink::MemProt::Read);
+        G->createSection(".data.__dso_handle", MemProt::Read);
     auto &DSOHandleBlock = G->createContentBlock(
         DSOHandleSection, getDSOHandleContent(PointerSize), orc::ExecutorAddr(),
         8, 0);

diff  --git a/llvm/lib/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManager.cpp b/llvm/lib/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManager.cpp
index 75cc30753f416..a3d857c3bfc4e 100644
--- a/llvm/lib/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManager.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManager.cpp
@@ -47,8 +47,7 @@ class EPCGenericJITLinkMemoryManager::InFlightAlloc
     for (auto &KV : Segs) {
       assert(KV.second.ContentSize <= std::numeric_limits<size_t>::max());
       FR.Segments.push_back(tpctypes::SegFinalizeRequest{
-          tpctypes::toWireProtectionFlags(
-              toSysMemoryProtectionFlags(KV.first.getMemProt())),
+          KV.first,
           KV.second.Addr,
           alignTo(KV.second.ContentSize + KV.second.ZeroFillSize,
                   Parent.EPC.getPageSize()),

diff  --git a/llvm/lib/ExecutionEngine/Orc/EPCGenericRTDyldMemoryManager.cpp b/llvm/lib/ExecutionEngine/Orc/EPCGenericRTDyldMemoryManager.cpp
index cdac367e11a32..62f906657ffe6 100644
--- a/llvm/lib/ExecutionEngine/Orc/EPCGenericRTDyldMemoryManager.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/EPCGenericRTDyldMemoryManager.cpp
@@ -142,7 +142,7 @@ void EPCGenericRTDyldMemoryManager::reserveAllocationSpace(
   }
 
   std::lock_guard<std::mutex> Lock(M);
-  Unmapped.push_back(AllocGroup());
+  Unmapped.push_back(SectionAllocGroup());
   Unmapped.back().RemoteCode = {
       *TargetAllocAddr, ExecutorAddrDiff(alignTo(CodeSize, EPC.getPageSize()))};
   Unmapped.back().RemoteROData = {
@@ -170,10 +170,11 @@ void EPCGenericRTDyldMemoryManager::registerEHFrames(uint8_t *Addr,
     return;
 
   ExecutorAddr LA(LoadAddr);
-  for (auto &Alloc : llvm::reverse(Unfinalized)) {
-    if (Alloc.RemoteCode.contains(LA) || Alloc.RemoteROData.contains(LA) ||
-        Alloc.RemoteRWData.contains(LA)) {
-      Alloc.UnfinalizedEHFrames.push_back({LA, Size});
+  for (auto &SecAllocGroup : llvm::reverse(Unfinalized)) {
+    if (SecAllocGroup.RemoteCode.contains(LA) ||
+        SecAllocGroup.RemoteROData.contains(LA) ||
+        SecAllocGroup.RemoteRWData.contains(LA)) {
+      SecAllocGroup.UnfinalizedEHFrames.push_back({LA, Size});
       return;
     }
   }
@@ -204,35 +205,29 @@ bool EPCGenericRTDyldMemoryManager::finalizeMemory(std::string *ErrMsg) {
   LLVM_DEBUG(dbgs() << "Allocator " << (void *)this << " finalizing:\n");
 
   // If there's an error then bail out here.
-  std::vector<AllocGroup> Allocs;
+  std::vector<SectionAllocGroup> SecAllocGroups;
   {
     std::lock_guard<std::mutex> Lock(M);
     if (ErrMsg && !this->ErrMsg.empty()) {
       *ErrMsg = std::move(this->ErrMsg);
       return true;
     }
-    std::swap(Allocs, Unfinalized);
+    std::swap(SecAllocGroups, Unfinalized);
   }
 
   // Loop over unfinalized objects to make finalization requests.
-  for (auto &ObjAllocs : Allocs) {
+  for (auto &SecAllocGroup : SecAllocGroups) {
 
-    tpctypes::WireProtectionFlags SegProts[3] = {
-        tpctypes::toWireProtectionFlags(
-            static_cast<sys::Memory::ProtectionFlags>(sys::Memory::MF_READ |
-                                                      sys::Memory::MF_EXEC)),
-        tpctypes::toWireProtectionFlags(sys::Memory::MF_READ),
-        tpctypes::toWireProtectionFlags(
-            static_cast<sys::Memory::ProtectionFlags>(sys::Memory::MF_READ |
-                                                      sys::Memory::MF_WRITE))};
+    MemProt SegMemProts[3] = {MemProt::Read | MemProt::Exec, MemProt::Read,
+                              MemProt::Read | MemProt::Write};
 
-    ExecutorAddrRange *RemoteAddrs[3] = {&ObjAllocs.RemoteCode,
-                                         &ObjAllocs.RemoteROData,
-                                         &ObjAllocs.RemoteRWData};
+    ExecutorAddrRange *RemoteAddrs[3] = {&SecAllocGroup.RemoteCode,
+                                         &SecAllocGroup.RemoteROData,
+                                         &SecAllocGroup.RemoteRWData};
 
-    std::vector<Alloc> *SegSections[3] = {&ObjAllocs.CodeAllocs,
-                                          &ObjAllocs.RODataAllocs,
-                                          &ObjAllocs.RWDataAllocs};
+    std::vector<SectionAlloc> *SegSections[3] = {&SecAllocGroup.CodeAllocs,
+                                                 &SecAllocGroup.RODataAllocs,
+                                                 &SecAllocGroup.RWDataAllocs};
 
     tpctypes::FinalizeRequest FR;
     std::unique_ptr<char[]> AggregateContents[3];
@@ -240,7 +235,7 @@ bool EPCGenericRTDyldMemoryManager::finalizeMemory(std::string *ErrMsg) {
     for (unsigned I = 0; I != 3; ++I) {
       FR.Segments.push_back({});
       auto &Seg = FR.Segments.back();
-      Seg.Prot = SegProts[I];
+      Seg.AG = SegMemProts[I];
       Seg.Addr = RemoteAddrs[I]->Start;
       for (auto &SecAlloc : *SegSections[I]) {
         Seg.Size = alignTo(Seg.Size, SecAlloc.Align);
@@ -261,7 +256,7 @@ bool EPCGenericRTDyldMemoryManager::finalizeMemory(std::string *ErrMsg) {
       Seg.Content = {AggregateContents[I].get(), SecOffset};
     }
 
-    for (auto &Frame : ObjAllocs.UnfinalizedEHFrames)
+    for (auto &Frame : SecAllocGroup.UnfinalizedEHFrames)
       FR.Actions.push_back(
           {cantFail(
                WrapperFunctionCall::Create<SPSArgList<SPSExecutorAddrRange>>(
@@ -297,7 +292,8 @@ bool EPCGenericRTDyldMemoryManager::finalizeMemory(std::string *ErrMsg) {
 }
 
 void EPCGenericRTDyldMemoryManager::mapAllocsToRemoteAddrs(
-    RuntimeDyld &Dyld, std::vector<Alloc> &Allocs, ExecutorAddr NextAddr) {
+    RuntimeDyld &Dyld, std::vector<SectionAlloc> &Allocs,
+    ExecutorAddr NextAddr) {
   for (auto &Alloc : Allocs) {
     NextAddr.setValue(alignTo(NextAddr.getValue(), Alloc.Align));
     LLVM_DEBUG({

diff  --git a/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp b/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp
index 2577318e83263..377a59993eb0e 100644
--- a/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp
@@ -517,8 +517,8 @@ DLLImportDefinitionGenerator::createStubsGraph(const SymbolMap &Resolved) {
   auto G = std::make_unique<jitlink::LinkGraph>(
       "<DLLIMPORT_STUBS>", TT, *PointerSize, *Endianness,
       jitlink::getGenericEdgeKindName);
-  jitlink::Section &Sec = G->createSection(
-      getSectionName(), jitlink::MemProt::Read | jitlink::MemProt::Exec);
+  jitlink::Section &Sec =
+      G->createSection(getSectionName(), MemProt::Read | MemProt::Exec);
 
   for (auto &KV : Resolved) {
     jitlink::Symbol &Target = G->addAbsoluteSymbol(

diff  --git a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
index e92986f1d0506..01a4c3b9837d8 100644
--- a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
@@ -85,7 +85,7 @@ class MachOHeaderMaterializationUnit : public MaterializationUnit {
     auto G = std::make_unique<jitlink::LinkGraph>(
         "<MachOHeaderMU>", TT, PointerSize, Endianness,
         jitlink::getGenericEdgeKindName);
-    auto &HeaderSection = G->createSection("__header", jitlink::MemProt::Read);
+    auto &HeaderSection = G->createSection("__header", MemProt::Read);
     auto &HeaderBlock = createHeaderBlock(*G, HeaderSection);
 
     // Init symbol is header-start symbol.

diff  --git a/llvm/lib/ExecutionEngine/Orc/MapperJITLinkMemoryManager.cpp b/llvm/lib/ExecutionEngine/Orc/MapperJITLinkMemoryManager.cpp
index eb3a5acb06cc1..d099a251232e7 100644
--- a/llvm/lib/ExecutionEngine/Orc/MapperJITLinkMemoryManager.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/MapperJITLinkMemoryManager.cpp
@@ -99,7 +99,7 @@ void MapperJITLinkMemoryManager::allocate(const JITLinkDylib *JD, LinkGraph &G,
       SI.Offset = Seg.Addr - Result->Start;
       SI.ContentSize = Seg.ContentSize;
       SI.ZeroFillSize = Seg.ZeroFillSize;
-      SI.Prot = toSysMemoryProtectionFlags(AG.getMemProt());
+      SI.AG = AG;
       SI.WorkingMem = Seg.WorkingMem;
 
       SegInfos.push_back(SI);

diff  --git a/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp b/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp
index 384b5ae14e21d..7389d1e72562e 100644
--- a/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp
@@ -64,6 +64,7 @@ void InProcessMemoryMapper::initialize(MemoryMapper::AllocInfo &AI,
   ExecutorAddr MinAddr(~0ULL);
   ExecutorAddr MaxAddr(0);
 
+  // FIXME: Release finalize lifetime segments.
   for (auto &Segment : AI.Segments) {
     auto Base = AI.MappingBase + Segment.Offset;
     auto Size = Segment.ContentSize + Segment.ZeroFillSize;
@@ -77,11 +78,12 @@ void InProcessMemoryMapper::initialize(MemoryMapper::AllocInfo &AI,
     std::memset((Base + Segment.ContentSize).toPtr<void *>(), 0,
                 Segment.ZeroFillSize);
 
-    if (auto EC = sys::Memory::protectMappedMemory({Base.toPtr<void *>(), Size},
-                                                   Segment.Prot)) {
+    if (auto EC = sys::Memory::protectMappedMemory(
+            {Base.toPtr<void *>(), Size},
+            toSysMemoryProtectionFlags(Segment.AG.getMemProt()))) {
       return OnInitialized(errorCodeToError(EC));
     }
-    if (Segment.Prot & sys::Memory::MF_EXEC)
+    if ((Segment.AG.getMemProt() & MemProt::Exec) == MemProt::Exec)
       sys::Memory::InvalidateInstructionCache(Base.toPtr<void *>(), Size);
   }
 
@@ -320,8 +322,7 @@ void SharedMemoryMapper::initialize(MemoryMapper::AllocInfo &AI,
     std::memset(Base + Segment.ContentSize, 0, Segment.ZeroFillSize);
 
     tpctypes::SharedMemorySegFinalizeRequest SegReq;
-    SegReq.Prot = tpctypes::toWireProtectionFlags(
-        static_cast<sys::Memory::ProtectionFlags>(Segment.Prot));
+    SegReq.AG = Segment.AG;
     SegReq.Addr = AI.MappingBase + Segment.Offset;
     SegReq.Size = Segment.ContentSize + Segment.ZeroFillSize;
 

diff  --git a/llvm/lib/ExecutionEngine/Orc/TargetProcess/ExecutorSharedMemoryMapperService.cpp b/llvm/lib/ExecutionEngine/Orc/TargetProcess/ExecutorSharedMemoryMapperService.cpp
index a8d5dc5a94e42..d876c717881d5 100644
--- a/llvm/lib/ExecutionEngine/Orc/TargetProcess/ExecutorSharedMemoryMapperService.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/TargetProcess/ExecutorSharedMemoryMapperService.cpp
@@ -137,11 +137,11 @@ Expected<ExecutorAddr> ExecutorSharedMemoryMapperService::initialize(
 #if defined(LLVM_ON_UNIX)
 
     int NativeProt = 0;
-    if (Segment.Prot & tpctypes::WPF_Read)
+    if ((Segment.AG.getMemProt() & MemProt::Read) == MemProt::Read)
       NativeProt |= PROT_READ;
-    if (Segment.Prot & tpctypes::WPF_Write)
+    if ((Segment.AG.getMemProt() & MemProt::Write) == MemProt::Write)
       NativeProt |= PROT_WRITE;
-    if (Segment.Prot & tpctypes::WPF_Exec)
+    if ((Segment.AG.getMemProt() & MemProt::Exec) == MemProt::Exec)
       NativeProt |= PROT_EXEC;
 
     if (mprotect(Segment.Addr.toPtr<void *>(), Segment.Size, NativeProt))
@@ -158,7 +158,7 @@ Expected<ExecutorAddr> ExecutorSharedMemoryMapperService::initialize(
 
 #endif
 
-    if (Segment.Prot & tpctypes::WPF_Exec)
+    if ((Segment.AG.getMemProt() & MemProt::Exec) == MemProt::Exec)
       sys::Memory::InvalidateInstructionCache(Segment.Addr.toPtr<void *>(),
                                               Segment.Size);
   }

diff  --git a/llvm/lib/ExecutionEngine/Orc/TargetProcess/SimpleExecutorMemoryManager.cpp b/llvm/lib/ExecutionEngine/Orc/TargetProcess/SimpleExecutorMemoryManager.cpp
index c848dd65fa7e4..ce94bf1e039aa 100644
--- a/llvm/lib/ExecutionEngine/Orc/TargetProcess/SimpleExecutorMemoryManager.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/TargetProcess/SimpleExecutorMemoryManager.cpp
@@ -132,9 +132,9 @@ Error SimpleExecutorMemoryManager::finalize(tpctypes::FinalizeRequest &FR) {
     assert(Seg.Size <= std::numeric_limits<size_t>::max());
     if (auto EC = sys::Memory::protectMappedMemory(
             {Mem, static_cast<size_t>(Seg.Size)},
-            tpctypes::fromWireProtectionFlags(Seg.Prot)))
+            toSysMemoryProtectionFlags(Seg.AG.getMemProt())))
       return BailOut(errorCodeToError(EC));
-    if (Seg.Prot & tpctypes::WPF_Exec)
+    if ((Seg.AG.getMemProt() & MemProt::Exec) == MemProt::Exec)
       sys::Memory::InvalidateInstructionCache(Mem, Seg.Size);
   }
 

diff  --git a/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp b/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp
index 63b161ed73e0b..bbb93ceb4b243 100644
--- a/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp
+++ b/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp
@@ -75,7 +75,8 @@ TEST(LinkGraphTest, AddressAccess) {
   LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little,
               getGenericEdgeKindName);
 
-  auto &Sec1 = G.createSection("__data.1", MemProt::Read | MemProt::Write);
+  auto &Sec1 =
+      G.createSection("__data.1", orc::MemProt::Read | orc::MemProt::Write);
   orc::ExecutorAddr B1Addr(0x1000);
   auto &B1 = G.createContentBlock(Sec1, BlockContent, B1Addr, 8, 0);
   auto &S1 = G.addDefinedSymbol(B1, 4, "S1", 4, Linkage::Strong, Scope::Default,
@@ -92,7 +93,8 @@ TEST(LinkGraphTest, BlockAndSymbolIteration) {
   // Check that we can iterate over blocks within Sections and across sections.
   LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little,
               getGenericEdgeKindName);
-  auto &Sec1 = G.createSection("__data.1", MemProt::Read | MemProt::Write);
+  auto &Sec1 =
+      G.createSection("__data.1", orc::MemProt::Read | orc::MemProt::Write);
   orc::ExecutorAddr B1Addr(0x1000);
   auto &B1 = G.createContentBlock(Sec1, BlockContent, B1Addr, 8, 0);
   orc::ExecutorAddr B2Addr(0x2000);
@@ -102,7 +104,8 @@ TEST(LinkGraphTest, BlockAndSymbolIteration) {
   auto &S2 = G.addDefinedSymbol(B2, 4, "S2", 4, Linkage::Strong, Scope::Default,
                                 false, false);
 
-  auto &Sec2 = G.createSection("__data.2", MemProt::Read | MemProt::Write);
+  auto &Sec2 =
+      G.createSection("__data.2", orc::MemProt::Read | orc::MemProt::Write);
   orc::ExecutorAddr B3Addr(0x3000);
   auto &B3 = G.createContentBlock(Sec2, BlockContent, B3Addr, 8, 0);
   orc::ExecutorAddr B4Addr(0x4000);
@@ -143,7 +146,8 @@ TEST(LinkGraphTest, ContentAccessAndUpdate) {
   // Check that we can make a defined symbol external.
   LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little,
               getGenericEdgeKindName);
-  auto &Sec = G.createSection("__data", MemProt::Read | MemProt::Write);
+  auto &Sec =
+      G.createSection("__data", orc::MemProt::Read | orc::MemProt::Write);
 
   // Create an initial block.
   orc::ExecutorAddr BAddr(0x1000);
@@ -212,7 +216,8 @@ TEST(LinkGraphTest, MakeExternal) {
   // Check that we can make defined and absolute symbols external.
   LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little,
               getGenericEdgeKindName);
-  auto &Sec = G.createSection("__data", MemProt::Read | MemProt::Write);
+  auto &Sec =
+      G.createSection("__data", orc::MemProt::Read | orc::MemProt::Write);
 
   // Create an initial block.
   auto &B1 =
@@ -281,7 +286,8 @@ TEST(LinkGraphTest, MakeAbsolute) {
   // Check that we can make defined and external symbols absolute.
   LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little,
               getGenericEdgeKindName);
-  auto &Sec = G.createSection("__data", MemProt::Read | MemProt::Write);
+  auto &Sec =
+      G.createSection("__data", orc::MemProt::Read | orc::MemProt::Write);
 
   // Create an initial block.
   auto &B1 =
@@ -349,7 +355,8 @@ TEST(LinkGraphTest, MakeDefined) {
   // Check that we can make an external symbol defined.
   LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little,
               getGenericEdgeKindName);
-  auto &Sec = G.createSection("__data", MemProt::Read | MemProt::Write);
+  auto &Sec =
+      G.createSection("__data", orc::MemProt::Read | orc::MemProt::Write);
 
   // Create an initial block.
   orc::ExecutorAddr B1Addr(0x1000);
@@ -396,7 +403,8 @@ TEST(LinkGraphTest, TransferDefinedSymbol) {
   // Check that we can transfer a defined symbol from one block to another.
   LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little,
               getGenericEdgeKindName);
-  auto &Sec = G.createSection("__data", MemProt::Read | MemProt::Write);
+  auto &Sec =
+      G.createSection("__data", orc::MemProt::Read | orc::MemProt::Write);
 
   // Create initial blocks.
   orc::ExecutorAddr B1Addr(0x1000);
@@ -430,8 +438,10 @@ TEST(LinkGraphTest, TransferDefinedSymbolAcrossSections) {
   // section to another.
   LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little,
               getGenericEdgeKindName);
-  auto &Sec1 = G.createSection("__data.1", MemProt::Read | MemProt::Write);
-  auto &Sec2 = G.createSection("__data.2", MemProt::Read | MemProt::Write);
+  auto &Sec1 =
+      G.createSection("__data.1", orc::MemProt::Read | orc::MemProt::Write);
+  auto &Sec2 =
+      G.createSection("__data.2", orc::MemProt::Read | orc::MemProt::Write);
 
   // Create blocks in each section.
   orc::ExecutorAddr B1Addr(0x1000);
@@ -462,8 +472,10 @@ TEST(LinkGraphTest, TransferBlock) {
   // section to another.
   LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little,
               getGenericEdgeKindName);
-  auto &Sec1 = G.createSection("__data.1", MemProt::Read | MemProt::Write);
-  auto &Sec2 = G.createSection("__data.2", MemProt::Read | MemProt::Write);
+  auto &Sec1 =
+      G.createSection("__data.1", orc::MemProt::Read | orc::MemProt::Write);
+  auto &Sec2 =
+      G.createSection("__data.2", orc::MemProt::Read | orc::MemProt::Write);
 
   // Create an initial block.
   orc::ExecutorAddr B1Addr(0x1000);
@@ -508,9 +520,12 @@ TEST(LinkGraphTest, MergeSections) {
   // section to another.
   LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little,
               getGenericEdgeKindName);
-  auto &Sec1 = G.createSection("__data.1", MemProt::Read | MemProt::Write);
-  auto &Sec2 = G.createSection("__data.2", MemProt::Read | MemProt::Write);
-  auto &Sec3 = G.createSection("__data.3", MemProt::Read | MemProt::Write);
+  auto &Sec1 =
+      G.createSection("__data.1", orc::MemProt::Read | orc::MemProt::Write);
+  auto &Sec2 =
+      G.createSection("__data.2", orc::MemProt::Read | orc::MemProt::Write);
+  auto &Sec3 =
+      G.createSection("__data.3", orc::MemProt::Read | orc::MemProt::Write);
 
   // Create an initial block.
   orc::ExecutorAddr B1Addr(0x1000);
@@ -591,7 +606,8 @@ TEST(LinkGraphTest, SplitBlock) {
   // Check that the LinkGraph::splitBlock test works as expected.
   LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little,
               getGenericEdgeKindName);
-  auto &Sec = G.createSection("__data", MemProt::Read | MemProt::Write);
+  auto &Sec =
+      G.createSection("__data", orc::MemProt::Read | orc::MemProt::Write);
 
   // Create the block to split.
   orc::ExecutorAddr B1Addr(0x1000);

diff  --git a/llvm/unittests/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManagerTest.cpp b/llvm/unittests/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManagerTest.cpp
index ff326e0782f35..7a34dfc9e2304 100644
--- a/llvm/unittests/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManagerTest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManagerTest.cpp
@@ -46,9 +46,9 @@ class SimpleAllocator {
       assert(Seg.Size <= std::numeric_limits<size_t>::max());
       if (auto EC = sys::Memory::protectMappedMemory(
               {Mem, static_cast<size_t>(Seg.Size)},
-              tpctypes::fromWireProtectionFlags(Seg.Prot)))
+              toSysMemoryProtectionFlags(Seg.AG.getMemProt())))
         return errorCodeToError(EC);
-      if (Seg.Prot & tpctypes::WPF_Exec)
+      if ((Seg.AG.getMemProt() & MemProt::Exec) != MemProt::Exec)
         sys::Memory::InvalidateInstructionCache(Mem, Seg.Size);
     }
     return Error::success();
@@ -117,9 +117,9 @@ TEST(EPCGenericJITLinkMemoryManagerTest, AllocFinalizeFree) {
 
   StringRef Hello = "hello";
   auto SSA = jitlink::SimpleSegmentAlloc::Create(
-      *MemMgr, nullptr, {{jitlink::MemProt::Read, {Hello.size(), Align(1)}}});
+      *MemMgr, nullptr, {{MemProt::Read, {Hello.size(), Align(1)}}});
   EXPECT_THAT_EXPECTED(SSA, Succeeded());
-  auto SegInfo = SSA->getSegInfo(jitlink::MemProt::Read);
+  auto SegInfo = SSA->getSegInfo(MemProt::Read);
   memcpy(SegInfo.WorkingMem.data(), Hello.data(), Hello.size());
 
   auto FA = SSA->finalize();

diff  --git a/llvm/unittests/ExecutionEngine/Orc/MapperJITLinkMemoryManagerTest.cpp b/llvm/unittests/ExecutionEngine/Orc/MapperJITLinkMemoryManagerTest.cpp
index 94a7b4e2526e1..46e558aad0d00 100644
--- a/llvm/unittests/ExecutionEngine/Orc/MapperJITLinkMemoryManagerTest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/MapperJITLinkMemoryManagerTest.cpp
@@ -76,13 +76,13 @@ TEST(MapperJITLinkMemoryManagerTest, InProcess) {
 
   StringRef Hello = "hello";
   auto SSA1 = jitlink::SimpleSegmentAlloc::Create(
-      *MemMgr, nullptr, {{jitlink::MemProt::Read, {Hello.size(), Align(1)}}});
+      *MemMgr, nullptr, {{MemProt::Read, {Hello.size(), Align(1)}}});
   EXPECT_THAT_EXPECTED(SSA1, Succeeded());
 
   EXPECT_EQ(Counter->ReserveCount, 1);
   EXPECT_EQ(Counter->InitCount, 0);
 
-  auto SegInfo1 = SSA1->getSegInfo(jitlink::MemProt::Read);
+  auto SegInfo1 = SSA1->getSegInfo(MemProt::Read);
   memcpy(SegInfo1.WorkingMem.data(), Hello.data(), Hello.size());
 
   auto FA1 = SSA1->finalize();
@@ -92,14 +92,14 @@ TEST(MapperJITLinkMemoryManagerTest, InProcess) {
   EXPECT_EQ(Counter->InitCount, 1);
 
   auto SSA2 = jitlink::SimpleSegmentAlloc::Create(
-      *MemMgr, nullptr, {{jitlink::MemProt::Read, {Hello.size(), Align(1)}}});
+      *MemMgr, nullptr, {{MemProt::Read, {Hello.size(), Align(1)}}});
   EXPECT_THAT_EXPECTED(SSA2, Succeeded());
 
   // last reservation should be reused
   EXPECT_EQ(Counter->ReserveCount, 1);
   EXPECT_EQ(Counter->InitCount, 1);
 
-  auto SegInfo2 = SSA2->getSegInfo(jitlink::MemProt::Read);
+  auto SegInfo2 = SSA2->getSegInfo(MemProt::Read);
   memcpy(SegInfo2.WorkingMem.data(), Hello.data(), Hello.size());
   auto FA2 = SSA2->finalize();
   EXPECT_THAT_EXPECTED(FA2, Succeeded());
@@ -137,15 +137,15 @@ TEST(MapperJITLinkMemoryManagerTest, Coalescing) {
                                                              std::move(Mapper));
 
   auto SSA1 = jitlink::SimpleSegmentAlloc::Create(
-      *MemMgr, nullptr, {{jitlink::MemProt::Read, {1024, Align(1)}}});
+      *MemMgr, nullptr, {{MemProt::Read, {1024, Align(1)}}});
   EXPECT_THAT_EXPECTED(SSA1, Succeeded());
-  auto SegInfo1 = SSA1->getSegInfo(jitlink::MemProt::Read);
+  auto SegInfo1 = SSA1->getSegInfo(MemProt::Read);
   ExecutorAddr TargetAddr1(SegInfo1.Addr);
   auto FA1 = SSA1->finalize();
   EXPECT_THAT_EXPECTED(FA1, Succeeded());
 
   auto SSA2 = jitlink::SimpleSegmentAlloc::Create(
-      *MemMgr, nullptr, {{jitlink::MemProt::Read, {1024, Align(1)}}});
+      *MemMgr, nullptr, {{MemProt::Read, {1024, Align(1)}}});
   EXPECT_THAT_EXPECTED(SSA2, Succeeded());
   auto FA2 = SSA2->finalize();
   EXPECT_THAT_EXPECTED(FA2, Succeeded());
@@ -157,10 +157,10 @@ TEST(MapperJITLinkMemoryManagerTest, Coalescing) {
   EXPECT_THAT_ERROR(std::move(Err3), Succeeded());
 
   auto SSA3 = jitlink::SimpleSegmentAlloc::Create(
-      *MemMgr, nullptr, {{jitlink::MemProt::Read, {2048, Align(1)}}});
+      *MemMgr, nullptr, {{MemProt::Read, {2048, Align(1)}}});
   EXPECT_THAT_EXPECTED(SSA3, Succeeded());
 
-  auto SegInfo3 = SSA3->getSegInfo(jitlink::MemProt::Read);
+  auto SegInfo3 = SSA3->getSegInfo(MemProt::Read);
   ExecutorAddr TargetAddr3(SegInfo3.Addr);
 
   auto FA3 = SSA3->finalize();

diff  --git a/llvm/unittests/ExecutionEngine/Orc/MemoryMapperTest.cpp b/llvm/unittests/ExecutionEngine/Orc/MemoryMapperTest.cpp
index 57a9fac77d84c..e015bd09d354b 100644
--- a/llvm/unittests/ExecutionEngine/Orc/MemoryMapperTest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/MemoryMapperTest.cpp
@@ -92,7 +92,7 @@ TEST(MemoryMapperTest, InitializeDeinitialize) {
       Seg1.Offset = 0;
       Seg1.ContentSize = HW.size();
       Seg1.ZeroFillSize = PageSize - Seg1.ContentSize;
-      Seg1.Prot = sys::Memory::MF_READ | sys::Memory::MF_WRITE;
+      Seg1.AG = MemProt::Read | MemProt::Write;
 
       Alloc1.MappingBase = Mem1->Start;
       Alloc1.Segments.push_back(Seg1);
@@ -116,7 +116,7 @@ TEST(MemoryMapperTest, InitializeDeinitialize) {
       Seg2.Offset = PageSize;
       Seg2.ContentSize = HW.size();
       Seg2.ZeroFillSize = PageSize - Seg2.ContentSize;
-      Seg2.Prot = sys::Memory::MF_READ | sys::Memory::MF_WRITE;
+      Seg2.AG = MemProt::Read | MemProt::Write;
 
       Alloc2.MappingBase = Mem1->Start;
       Alloc2.Segments.push_back(Seg2);
@@ -168,7 +168,7 @@ TEST(MemoryMapperTest, InitializeDeinitialize) {
         Seg3.Offset = 0;
         Seg3.ContentSize = HW.size();
         Seg3.ZeroFillSize = PageSize - Seg3.ContentSize;
-        Seg3.Prot = sys::Memory::MF_READ | sys::Memory::MF_WRITE;
+        Seg3.AG = MemProt::Read | MemProt::Write;
 
         Alloc3.MappingBase = Mem2->Start;
         Alloc3.Segments.push_back(Seg3);

diff  --git a/llvm/unittests/ExecutionEngine/Orc/SharedMemoryMapperTest.cpp b/llvm/unittests/ExecutionEngine/Orc/SharedMemoryMapperTest.cpp
index 9f44184ccc77b..0fcc863c207d5 100644
--- a/llvm/unittests/ExecutionEngine/Orc/SharedMemoryMapperTest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/SharedMemoryMapperTest.cpp
@@ -81,7 +81,7 @@ TEST(SharedMemoryMapperTest, MemReserveInitializeDeinitializeRelease) {
         SI.Offset = 0;
         SI.ContentSize = TestString.size() + 1;
         SI.ZeroFillSize = PageSize - SI.ContentSize;
-        SI.Prot = sys::Memory::MF_READ | sys::Memory::MF_WRITE;
+        SI.AG = MemProt::Read | MemProt::Write;
 
         AI.MappingBase = Reservation.Start;
         AI.Segments.push_back(SI);

diff  --git a/llvm/unittests/ExecutionEngine/Orc/SimpleExecutorMemoryManagerTest.cpp b/llvm/unittests/ExecutionEngine/Orc/SimpleExecutorMemoryManagerTest.cpp
index f127e7713c5eb..cb42bca3690b9 100644
--- a/llvm/unittests/ExecutionEngine/Orc/SimpleExecutorMemoryManagerTest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/SimpleExecutorMemoryManagerTest.cpp
@@ -45,7 +45,7 @@ TEST(SimpleExecutorMemoryManagerTest, AllocFinalizeFree) {
 
   tpctypes::FinalizeRequest FR;
   FR.Segments.push_back(
-      tpctypes::SegFinalizeRequest{tpctypes::WPF_Read | tpctypes::WPF_Write,
+      tpctypes::SegFinalizeRequest{MemProt::Read | MemProt::Write,
                                    *Mem,
                                    AllocSize,
                                    {HW.data(), HW.size() + 1}});


        


More information about the llvm-commits mailing list