Skip to content

Commit cff2fdc

Browse files
authored
[orc-rt] Add SPS serialization for ExecutorAddr. (llvm#157242)
1 parent 3250349 commit cff2fdc

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

orc-rt/include/orc-rt/SimplePackedSerialization.h

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#define ORC_RT_SIMPLEPACKEDSERIALIZATION_H
3636

3737
#include "orc-rt/Error.h"
38+
#include "orc-rt/ExecutorAddress.h"
3839
#include "orc-rt/bit.h"
3940
#include "orc-rt/span.h"
4041

@@ -174,9 +175,6 @@ class SPSSerializationTraits<
174175
/// Any empty placeholder suitable as a substitute for void when deserializing
175176
class SPSEmpty {};
176177

177-
/// Represents an address in the executor.
178-
class SPSExecutorAddr {};
179-
180178
/// SPS tag type for tuples.
181179
///
182180
/// A blob tuple should be serialized by serializing each of the elements in
@@ -511,9 +509,31 @@ template <> class SPSSerializationTraits<SPSString, std::string_view> {
511509
}
512510
};
513511

512+
/// Represents an address in the executor.
513+
class SPSExecutorAddr {};
514+
514515
/// SPS tag type for errors.
515516
class SPSError;
516517

518+
template <> class SPSSerializationTraits<SPSExecutorAddr, ExecutorAddr> {
519+
public:
520+
static size_t size(const ExecutorAddr &A) {
521+
return SPSArgList<uint64_t>::size(A.getValue());
522+
}
523+
524+
static bool serialize(SPSOutputBuffer &OB, const ExecutorAddr &A) {
525+
return SPSArgList<uint64_t>::serialize(OB, A.getValue());
526+
}
527+
528+
static bool deserialize(SPSInputBuffer &IB, ExecutorAddr &A) {
529+
uint64_t Value;
530+
if (!SPSArgList<uint64_t>::deserialize(IB, Value))
531+
return false;
532+
A = ExecutorAddr(Value);
533+
return true;
534+
}
535+
};
536+
517537
/// Helper type for serializing Errors.
518538
///
519539
/// llvm::Errors are move-only, and not inspectable except by consuming them.

orc-rt/unittests/SimplePackedSerializationTest.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ TEST(SimplePackedSerializationTest, SequenceSerialization) {
108108
blobSerializationRoundTrip<SPSSequence<int32_t>, std::vector<int32_t>>(V);
109109
}
110110

111+
TEST(SimplePackedSerializationTest, ExecutorAddr) {
112+
int X = 42;
113+
auto A = ExecutorAddr::fromPtr(&X);
114+
blobSerializationRoundTrip<SPSExecutorAddr>(A);
115+
}
116+
111117
TEST(SimplePackedSerializationTest, StringViewCharSequenceSerialization) {
112118
const char *HW = "Hello, world!";
113119
blobSerializationRoundTrip<SPSString, std::string_view>(std::string_view(HW));

0 commit comments

Comments
 (0)