Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions orc-rt/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ set(ORC_RT_HEADERS
orc-rt/ScopeExit.h
orc-rt/SimplePackedSerialization.h
orc-rt/SPSAllocAction.h
orc-rt/SPSMemoryFlags.h
orc-rt/SPSWrapperFunction.h
orc-rt/bind.h
orc-rt/bit.h
Expand Down
20 changes: 20 additions & 0 deletions orc-rt/include/orc-rt/MemoryFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,14 @@ enum class MemLifetime : unsigned {
Finalize
};

namespace detail {
struct AllocGroupInternals;
} // namespace detail

/// A pair of memory protections and lifetime policy.
class AllocGroup {
friend struct detail::AllocGroupInternals;

private:
static constexpr int NumProtBits = bitmask_enum_num_bits_v<MemProt>;
static constexpr int NumLifetimeBits = 1;
Expand Down Expand Up @@ -87,6 +93,20 @@ class AllocGroup {
underlying_type Id = 0;
};

namespace detail {
/// Helper for serializers that need access to the underlying representation of
/// AllocGroup.
struct AllocGroupInternals {
typedef AllocGroup::underlying_type underlying_type;
static underlying_type getId(const AllocGroup &AG) noexcept { return AG.Id; }
static AllocGroup fromId(underlying_type Id) noexcept {
AllocGroup AG;
AG.Id = Id;
return AG;
}
};
} // namespace detail

/// A specialized small-map for AllocGroups.
///
/// Iteration order is guaranteed to match key ordering.
Expand Down
49 changes: 49 additions & 0 deletions orc-rt/include/orc-rt/SPSMemoryFlags.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//===-- SPSMemoryFlags.h - SPS-serialization for MemoryFlags.h --*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// SPSSerialization for relevant types in MemoryFlags.h.
//
//===----------------------------------------------------------------------===//

#ifndef ORC_RT_SPSMEMORYFLAGS_H
#define ORC_RT_SPSMEMORYFLAGS_H

#include "orc-rt/MemoryFlags.h"
#include "orc-rt/SimplePackedSerialization.h"

namespace orc_rt {

struct SPSAllocGroup;

template <> class SPSSerializationTraits<SPSAllocGroup, AllocGroup> {
private:
typedef detail::AllocGroupInternals::underlying_type UT;

public:
static size_t size(const AllocGroup &AG) {
return SPSSerializationTraits<UT, UT>::size(
detail::AllocGroupInternals::getId(AG));
}

static bool serialize(SPSOutputBuffer &OB, const AllocGroup &AG) {
return SPSSerializationTraits<UT, UT>::serialize(
OB, detail::AllocGroupInternals::getId(AG));
}

static bool deserialize(SPSInputBuffer &IB, AllocGroup &AG) {
UT Id = 0;
if (!SPSSerializationTraits<UT, UT>::deserialize(IB, Id))
return false;
AG = detail::AllocGroupInternals::fromId(Id);
return true;
}
};

} // namespace orc_rt

#endif // ORC_RT_SPSMEMORYFLAGS_H
1 change: 1 addition & 0 deletions orc-rt/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ add_orc_rt_unittest(CoreTests
RTTITest.cpp
ScopeExitTest.cpp
SimplePackedSerializationTest.cpp
SPSMemoryFlagsTest.cpp
SPSWrapperFunctionTest.cpp
WrapperFunctionBufferTest.cpp
bind-test.cpp
Expand Down
35 changes: 35 additions & 0 deletions orc-rt/unittests/SPSMemoryFlagsTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//===-- SPSMemoryFlagsTest.cpp --------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Test SPS serialization for MemoryFlags APIs.
//
//===----------------------------------------------------------------------===//

#include "orc-rt/SPSMemoryFlags.h"

#include "SimplePackedSerializationTestUtils.h"
#include "gtest/gtest.h"

using namespace orc_rt;

TEST(SPSMemoryFlags, TestAllocGroupSerialization) {
for (bool Read : {false, true}) {
for (bool Write : {false, true}) {
for (bool Exec : {false, true}) {
for (bool FinalizeLifetime : {false, true}) {
AllocGroup AG((Read ? MemProt::Read : MemProt::None) |
(Write ? MemProt::Write : MemProt::None) |
(Exec ? MemProt::Exec : MemProt::None),
FinalizeLifetime ? MemLifetime::Finalize
: MemLifetime::Standard);
blobSerializationRoundTrip<SPSAllocGroup, AllocGroup>(AG);
}
}
}
}
}
Loading