[llvm] 1e5e1be - [ORC] Add std::tuple support to SimplePackedSerialization.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 21 18:36:20 PDT 2021
Author: Lang Hames
Date: 2021-08-22T11:17:04+10:00
New Revision: 1e5e1bee49251de36ec07a3dc64d98236fcd1f2b
URL: https://github.com/llvm/llvm-project/commit/1e5e1bee49251de36ec07a3dc64d98236fcd1f2b
DIFF: https://github.com/llvm/llvm-project/commit/1e5e1bee49251de36ec07a3dc64d98236fcd1f2b.diff
LOG: [ORC] Add std::tuple support to SimplePackedSerialization.
Added:
Modified:
llvm/include/llvm/ExecutionEngine/Orc/Shared/SimplePackedSerialization.h
llvm/unittests/ExecutionEngine/Orc/SimplePackedSerializationTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/Shared/SimplePackedSerialization.h b/llvm/include/llvm/ExecutionEngine/Orc/Shared/SimplePackedSerialization.h
index ea8630472846..dfa2307b2f20 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/Shared/SimplePackedSerialization.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/Shared/SimplePackedSerialization.h
@@ -337,6 +337,44 @@ class SPSSerializationTraits<SPSSequence<SPSElementTagT>, SequenceT,
}
};
+/// 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/llvm/unittests/ExecutionEngine/Orc/SimplePackedSerializationTest.cpp b/llvm/unittests/ExecutionEngine/Orc/SimplePackedSerializationTest.cpp
index d40317c16945..b5455e6580bd 100644
--- a/llvm/unittests/ExecutionEngine/Orc/SimplePackedSerializationTest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/SimplePackedSerializationTest.cpp
@@ -128,6 +128,11 @@ TEST(SimplePackedSerializationTest, StringViewCharSequenceSerialization) {
spsSerializationRoundTrip<SPSString>(StringRef(HW));
}
+TEST(SimplePackedSerializationTest, StdTupleSerialization) {
+ std::tuple<int32_t, std::string, bool> P(42, "foo", true);
+ spsSerializationRoundTrip<SPSTuple<int32_t, SPSString, bool>>(P);
+}
+
TEST(SimplePackedSerializationTest, StdPairSerialization) {
std::pair<int32_t, std::string> P(42, "foo");
spsSerializationRoundTrip<SPSTuple<int32_t, SPSString>>(P);
More information about the llvm-commits
mailing list