10 #ifndef LLVM_EXECUTIONENGINE_ORC_RPCSERIALIZATION_H
11 #define LLVM_EXECUTIONENGINE_ORC_RPCSERIALIZATION_H
31 template <
typename OStream>
32 OStream &operator<<(OStream &OS, const RPCTypeNameSequence<> &V) {
37 template <
typename OStream,
typename ArgT>
38 OStream &operator<<(OStream &OS, const RPCTypeNameSequence<ArgT> &V) {
44 template <
typename OStream,
typename ArgT1,
typename ArgT2,
typename... ArgTs>
55 static const char*
getName() {
return "void"; }
61 static const char*
getName() {
return "int8_t"; }
67 static const char*
getName() {
return "uint8_t"; }
73 static const char*
getName() {
return "int16_t"; }
79 static const char*
getName() {
return "uint16_t"; }
85 static const char*
getName() {
return "int32_t"; }
91 static const char*
getName() {
return "uint32_t"; }
97 static const char*
getName() {
return "int64_t"; }
103 static const char*
getName() {
return "uint64_t"; }
109 static const char*
getName() {
return "bool"; }
115 static const char*
getName() {
return "std::string"; }
121 static const char*
getName() {
return "Error"; }
124 template <
typename T>
128 std::lock_guard<std::mutex>
Lock(NameMutex);
137 static std::mutex NameMutex;
138 static std::string
Name;
141 template <
typename T>
142 std::mutex RPCTypeName<Expected<T>>::NameMutex;
144 template <
typename T>
145 std::string RPCTypeName<Expected<T>>
::Name;
147 template <
typename T1,
typename T2>
151 std::lock_guard<std::mutex>
Lock(NameMutex);
158 static std::mutex NameMutex;
159 static std::string
Name;
162 template <
typename T1,
typename T2>
163 std::mutex RPCTypeName<std::pair<T1, T2>>::NameMutex;
164 template <
typename T1,
typename T2>
165 std::string RPCTypeName<std::pair<T1, T2>>
::Name;
167 template <
typename... ArgTs>
171 std::lock_guard<std::mutex>
Lock(NameMutex);
178 static std::mutex NameMutex;
179 static std::string
Name;
182 template <
typename... ArgTs>
183 std::mutex RPCTypeName<std::tuple<ArgTs...>>::NameMutex;
184 template <
typename... ArgTs>
185 std::string RPCTypeName<std::tuple<ArgTs...>>
::Name;
187 template <
typename T>
191 std::lock_guard<std::mutex>
Lock(NameMutex);
199 static std::mutex NameMutex;
200 static std::string
Name;
203 template <
typename T>
204 std::mutex RPCTypeName<std::vector<T>>::NameMutex;
205 template <
typename T>
206 std::string RPCTypeName<std::vector<T>>
::Name;
241 template <
typename ChannelT,
typename WireType,
242 typename ConcreteType = WireType,
typename =
void>
245 template <
typename ChannelT>
261 template <
typename ChannelT,
typename... ArgTs>
264 template <
typename ChannelT>
271 template <
typename ChannelT,
typename ArgT>
275 template <
typename CArgT>
278 typename std::decay<CArgT>::type>::
279 serialize(C, std::forward<CArgT>(CArg));
282 template <
typename CArgT>
288 template <
typename ChannelT,
typename ArgT,
typename... ArgTs>
292 template <
typename CArgT,
typename... CArgTs>
294 CArgTs &&... CArgs) {
297 serialize(C, std::forward<CArgT>(CArg)))
302 serialize(C, std::forward<CArgTs>(CArgs)...);
305 template <
typename CArgT,
typename... CArgTs>
317 template <
typename ChannelT,
typename... ArgTs>
320 serialize(C, std::forward<ArgTs>(
Args)...);
323 template <
typename ChannelT,
typename... ArgTs>
328 template <
typename ChannelT>
333 std::function<Error(ChannelT &C, const ErrorInfoBase&)>;
336 std::function<Error(ChannelT &C, Error &Err)>;
338 template <
typename ErrorInfoT,
typename SerializeFtor,
339 typename DeserializeFtor>
341 DeserializeFtor Deserialize) {
343 "The empty string is reserved for the Success value");
345 const std::string *KeyName =
nullptr;
351 std::lock_guard<std::recursive_mutex>
Lock(DeserializersMutex);
353 Deserializers.insert(Deserializers.begin(),
354 std::make_pair(std::move(Name),
355 std::move(Deserialize)));
360 assert(KeyName !=
nullptr &&
"No keyname pointer");
361 std::lock_guard<std::recursive_mutex>
Lock(SerializersMutex);
363 Serializers[ErrorInfoT::classID()] =
365 assert(EIB.dynamicClassID() == ErrorInfoT::classID() &&
366 "Serializer called for wrong error type");
369 return Serialize(C, static_cast<const ErrorInfoT&>(EIB));
375 std::lock_guard<std::recursive_mutex>
Lock(SerializersMutex);
383 if (
SI == Serializers.end())
384 return serializeAsStringError(C, EIB);
385 return (
SI->second)(
C, EIB);
390 std::lock_guard<std::recursive_mutex>
Lock(DeserializersMutex);
402 auto DI = Deserializers.find(Key);
403 assert(DI != Deserializers.end() &&
"No deserializer for error type");
404 return (DI->second)(
C, Err);
413 EIB.
log(ErrMsgStream);
415 return serialize(C, make_error<StringError>(std::move(ErrMsg),
419 static std::recursive_mutex SerializersMutex;
420 static std::recursive_mutex DeserializersMutex;
421 static std::map<const void*, WrappedErrorSerializer> Serializers;
422 static std::map<std::string, WrappedErrorDeserializer> Deserializers;
425 template <
typename ChannelT>
426 std::recursive_mutex SerializationTraits<ChannelT, Error>::SerializersMutex;
428 template <
typename ChannelT>
429 std::recursive_mutex SerializationTraits<ChannelT, Error>::DeserializersMutex;
431 template <
typename ChannelT>
432 std::map<
const void*,
434 SerializationTraits<ChannelT, Error>::Serializers;
436 template <
typename ChannelT>
437 std::map<std::string,
439 SerializationTraits<ChannelT, Error>::Deserializers;
443 template <
typename ChannelT,
typename ErrorInfoT,
typename SerializeFtor,
444 typename DeserializeFtor>
446 DeserializeFtor &&Deserialize) {
449 std::forward<SerializeFtor>(Serialize),
450 std::forward<DeserializeFtor>(Deserialize));
454 template <
typename ChannelT>
456 static bool AlreadyRegistered =
false;
457 if (!AlreadyRegistered) {
458 registerErrorSerialization<ChannelT, StringError>(
469 make_error<StringError>(std::move(Msg),
474 AlreadyRegistered =
true;
479 template <
typename ChannelT,
typename T1,
typename T2>
504 ValOrErr = std::move(Err);
510 template <
typename ChannelT,
typename T1,
typename T2>
520 template <
typename ChannelT,
typename T>
530 template <
typename ChannelT,
typename T1,
typename T2>
543 template <
typename ChannelT,
typename... ArgTs>
559 template <
size_t... Is>
560 static Error serializeTupleHelper(ChannelT &C,
const std::tuple<ArgTs...> &V,
566 template <
size_t... Is>
567 static Error deserializeTupleHelper(ChannelT &C, std::tuple<ArgTs...> &V,
574 template <
typename ChannelT,
typename T>
580 if (
auto Err =
serializeSeq(C, static_cast<uint64_t>(V.size())))
583 for (
const auto &
E : V)
609 #endif // LLVM_EXECUTIONENGINE_ORC_RPCSERIALIZATION_H
Error handleErrors(Error E, HandlerTs &&...Hs)
Pass the ErrorInfo(s) contained in E to their respective handlers.
Error serializeSeq(ChannelT &C, ArgTs &&...Args)
static const char * getName()
static Error deserialize(ChannelT &C, std::vector< T > &V)
Deserialize a std::vector<T> to a std::vector<T>.
static const char * getName()
Helper for Expected<T>s used as out-parameters.
static Error serialize(ChannelT &C, const std::pair< T1, T2 > &V)
static Error serialize(ChannelT &C, Error &&Err)
static Error serialize(ChannelT &C)
Base class for error info classes.
static Error serialize(ChannelT &C, CArgT &&CArg, CArgTs &&...CArgs)
static const char * getName()
static const char * getName()
std::function< Error(ChannelT &C, Error &Err)> WrappedErrorDeserializer
std::error_code orcError(OrcErrorCode ErrCode)
static const char * getName()
virtual void log(raw_ostream &OS) const =0
Print an error message to an output stream.
static StringRef getName(Value *V)
Tagged union holding either a T or a Error.
static const char * getName()
Alias for the common case of a sequence of size_ts.
static Error emitSeparator(ChannelT &C)
static Error deserialize(ChannelT &C, CArgT &CArg, CArgTs &...CArgs)
static const char * getName()
void registerStringError()
Registers serialization/deserialization for StringError.
virtual const void * dynamicClassID() const =0
static Error deserialize(ChannelT &C)
void registerErrorSerialization(std::string Name, SerializeFtor &&Serialize, DeserializeFtor &&Deserialize)
Registers a serializer and deserializer for the given error type on the given channel type...
static const char * getName()
The SerializationTraits<ChannelT, T> class describes how to serialize and deserialize an instance of ...
static Error deserialize(ChannelT &C, std::pair< T1, T2 > &V)
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
static const char * getName()
static const char * getName()
static Error serialize(ChannelT &C, const std::tuple< ArgTs...> &V)
RPC channel serialization for std::tuple.
OStream & operator<<(OStream &OS, const RPCTypeNameSequence<> &V)
Render an empty TypeNameSequence to an ostream.
static ErrorSuccess success()
Create a success value.
static void registerErrorType(std::string Name, SerializeFtor Serialize, DeserializeFtor Deserialize)
static const char * getName()
Creates a compile-time integer sequence for a parameter pack.
static const char * getName()
static const char * getName()
static const char * getName()
static Error deserialize(ChannelT &C, Expected< T2 > &ValOrErr)
Helper for Errors used as out-parameters.
static const char * getName()
Error deserializeSeq(ChannelT &C, ArgTs &...Args)
static Error deserialize(ChannelT &C, Error &Err)
This class wraps a string in an Error.
static Error serialize(ChannelT &C, const std::vector< T > &V)
Serialize a std::vector<T> from std::vector<T>.
TypeNameSequence is a utility for rendering sequences of types to a string by rendering each type...
std::function< Error(ChannelT &C, const ErrorInfoBase &)> WrappedErrorSerializer
static Error serialize(ChannelT &C, Error &&Err)
Utility class for serializing sequences of values of varying types.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A raw_ostream that writes to an std::string.
static Error deserialize(ChannelT &C, CArgT &CArg)
Lightweight error class with error context and mandatory checking.
static Error serialize(ChannelT &C, CArgT &&CArg)
static Error serialize(ChannelT &C, T2 &&Val)
static const char * getName()
static Error serialize(ChannelT &C, Expected< T2 > &&ValOrErr)
static Error consumeSeparator(ChannelT &C)
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
static Error deserialize(ChannelT &C, std::tuple< ArgTs...> &V)
RPC channel deserialization for std::tuple.