[compiler-rt] 7138fab - [ORC-RT] Add SPS serialization for std::tuple.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 27 09:49:04 PST 2023
Author: Lang Hames
Date: 2023-11-27T09:48:56-08:00
New Revision: 7138fabfbcdfedfe7e9271ee8355774101dfcfed
URL: https://github.com/llvm/llvm-project/commit/7138fabfbcdfedfe7e9271ee8355774101dfcfed
DIFF: https://github.com/llvm/llvm-project/commit/7138fabfbcdfedfe7e9271ee8355774101dfcfed.diff
LOG: [ORC-RT] Add SPS serialization for std::tuple.
This will be used in upcoming changes to macho_platform.
Added:
Modified:
compiler-rt/lib/orc/simple_packed_serialization.h
compiler-rt/lib/orc/tests/unit/simple_packed_serialization_test.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/orc/simple_packed_serialization.h b/compiler-rt/lib/orc/simple_packed_serialization.h
index 9cebbeadee0263a..f24ebae6cbee440 100644
--- a/compiler-rt/lib/orc/simple_packed_serialization.h
+++ b/compiler-rt/lib/orc/simple_packed_serialization.h
@@ -385,6 +385,44 @@ template <> class SPSSerializationTraits<SPSSequence<char>, span<const char>> {
}
};
+/// SPSTuple serialization for std::tuple.
+template <typename... SPSTagTs, typename... Ts>
+class SPSSerializationTraits<SPSTuple<SPSTagTs...>, std::tuple<Ts...>> {
+private:
+ using TupleArgList = typename SPSTuple<SPSTagTs...>::AsArgList;
+ using ArgIndices = std::make_index_sequence<sizeof...(Ts)>;
+
+ template <std::size_t... I>
+ static size_t size(const std::tuple<Ts...> &T, std::index_sequence<I...>) {
+ return TupleArgList::size(std::get<I>(T)...);
+ }
+
+ template <std::size_t... I>
+ static bool serialize(SPSOutputBuffer &OB, const std::tuple<Ts...> &T,
+ std::index_sequence<I...>) {
+ return TupleArgList::serialize(OB, std::get<I>(T)...);
+ }
+
+ template <std::size_t... I>
+ static bool deserialize(SPSInputBuffer &IB, std::tuple<Ts...> &T,
+ std::index_sequence<I...>) {
+ return TupleArgList::deserialize(IB, std::get<I>(T)...);
+ }
+
+public:
+ static size_t size(const std::tuple<Ts...> &T) {
+ return size(T, ArgIndices{});
+ }
+
+ static bool serialize(SPSOutputBuffer &OB, const std::tuple<Ts...> &T) {
+ return serialize(OB, T, ArgIndices{});
+ }
+
+ static bool deserialize(SPSInputBuffer &IB, std::tuple<Ts...> &T) {
+ return deserialize(IB, T, ArgIndices{});
+ }
+};
+
/// SPSTuple serialization for std::pair.
template <typename SPSTagT1, typename SPSTagT2, typename T1, typename T2>
class SPSSerializationTraits<SPSTuple<SPSTagT1, SPSTagT2>, std::pair<T1, T2>> {
diff --git a/compiler-rt/lib/orc/tests/unit/simple_packed_serialization_test.cpp b/compiler-rt/lib/orc/tests/unit/simple_packed_serialization_test.cpp
index 5577ef919fc6abd..e7a78062b210e20 100644
--- a/compiler-rt/lib/orc/tests/unit/simple_packed_serialization_test.cpp
+++ b/compiler-rt/lib/orc/tests/unit/simple_packed_serialization_test.cpp
@@ -154,6 +154,11 @@ TEST(SimplePackedSerializationTest, SpanSerialization) {
EXPECT_EQ(InS.data(), Buffer.get() + sizeof(uint64_t));
}
+TEST(SimplePackedSerializationTest, StdTupleSerialization) {
+ std::tuple<int32_t, std::string, bool> P(42, "foo", true);
+ blobSerializationRoundTrip<SPSTuple<int32_t, SPSString, bool>>(P);
+}
+
TEST(SimplePackedSerializationTest, StdPairSerialization) {
std::pair<int32_t, std::string> P(42, "foo");
blobSerializationRoundTrip<SPSTuple<int32_t, SPSString>,
More information about the llvm-commits
mailing list