5#ifndef RUNTIME_VM_COMPILER_BACKEND_IL_SERIALIZER_H_
6#define RUNTIME_VM_COMPILER_BACKEND_IL_SERIALIZER_H_
8#if defined(DART_PRECOMPILED_RUNTIME)
9#error "AOT runtime should not use compiler sources (including header files)"
23class CatchBlockEntryInstr;
31class FunctionEntryInstr;
36class IndirectEntryInstr;
42class NonStreamingWriteStream;
45class ParallelMoveInstr;
50class TargetEntryInstr;
57class CallbackMarshaller;
59class NativeCallingConvention;
71#define IL_SERIALIZABLE_TYPE_LIST(V) \
73 V(const AbstractType&) \
74 V(const AbstractType*) \
77 V(const compiler::ffi::CallbackMarshaller&) \
78 V(const compiler::ffi::CallMarshaller&) \
79 V(const CallTargets&) \
99 V(const FunctionType&) \
101 V(const LocalVariable&) \
102 V(LocationSummary*) \
104 V(const MoveSchedule*) \
106 V(ParallelMoveInstr*) \
114 V(const compiler::TableSelector*) \
116 V(const TypeArguments&) \
117 V(const TypeParameters&) \
125#define IL_SERIALIZABLE_REF_TYPE_LIST(V) \
126 V(BlockEntryInstr*) \
127 V(CatchBlockEntryInstr*) \
129 V(FunctionEntryInstr*) \
130 V(IndirectEntryInstr*) \
169 template <
typename T,
class =
void>
174 template <
typename T>
178 const intptr_t
len =
x.length();
179 s->Write<intptr_t>(
len);
180 for (intptr_t
i = 0;
i <
len; ++
i) {
186 template <
typename T>
194 template <
typename T>
199 s->Write<intptr_t>(-1);
202 const intptr_t
len =
x->length();
203 s->Write<intptr_t>(
len);
204 for (intptr_t
i = 0;
i <
len; ++
i) {
205 s->Write<
T>((*x)[
i]);
210 template <
typename T>
219 template <
typename T>
221 std::enable_if_t<std::is_same_v<intptr_t, T> &&
222 !std::is_same_v<intptr_t, int32_t> &&
223 !std::is_same_v<intptr_t, int64_t>>> {
227 s->Write<int64_t>(
x);
229 s->Write<int32_t>(
x);
235 template <
typename T>
237 std::enable_if_t<std::is_same_v<uintptr_t, T> &&
238 !std::is_same_v<uintptr_t, uint32_t> &&
239 !std::is_same_v<uintptr_t, uint64_t>>> {
243 s->Write<uint64_t>(
x);
245 s->Write<uint32_t>(
x);
250#define DECLARE_WRITE_TRAIT(type) \
251 template <typename T> \
252 struct WriteTrait<T, std::enable_if_t<std::is_same_v<type, T>>> { \
253 using ArgType = type; \
254 static void Write(FlowGraphSerializer* s, type x); \
257#undef DECLARE_WRITE_TRAIT
259 template <
typename T>
274 template <
typename T,
class =
void>
277#define DECLARE_WRITE_REF_TRAIT(type) \
278 template <typename T> \
279 struct WriteRefTrait<T, std::enable_if_t<std::is_same_v<type, T>>> { \
280 static void WriteRef(FlowGraphSerializer* s, T x); \
283#undef DECLARE_WRITE_REF_TRAIT
285 template <
typename T>
290 template <
typename T>
293 Write<intptr_t>(
len);
294 for (intptr_t
i = 0;
i <
len; ++
i) {
295 WriteRef<T>(array[
i]);
307 void WriteObjectImpl(
const Object&
x, intptr_t
cid, intptr_t object_index);
308 bool IsWritten(
const Object& obj);
309 bool HasEnclosingTypes(
const Object& obj);
310 bool WriteObjectWithEnclosingTypes(
const Object&
type);
312 intptr_t num_free_fun_type_params);
319 intptr_t object_counter_ = 0;
320 bool can_write_refs_ =
false;
321 intptr_t num_free_fun_type_params_ =
kMaxInt;
350 ASSERT(blocks_[block_id] ==
nullptr);
351 blocks_[block_id] =
block;
355 Definition* def = definitions_[ssa_temp_index];
360 ASSERT(definitions_[ssa_temp_index] ==
nullptr);
361 definitions_[ssa_temp_index] = def;
376 template <
typename T,
class =
void>
379 template <
typename T>
382 const intptr_t
len =
d->Read<intptr_t>();
384 for (
int i = 0;
i <
len; ++
i) {
385 array.Add(
d->Read<
T>());
391 template <
typename T>
398 template <
typename T>
401 const intptr_t
len =
d->Read<intptr_t>();
406 for (
int i = 0;
i <
len; ++
i) {
407 array->
Add(
d->Read<
T>());
413 template <
typename T>
421 template <
typename T>
423 std::enable_if_t<std::is_same_v<intptr_t, T> &&
424 !std::is_same_v<intptr_t, int32_t> &&
425 !std::is_same_v<intptr_t, int64_t>>> {
428 return d->Read<int64_t>();
430 return d->Read<int32_t>();
436 template <
typename T>
438 std::enable_if_t<std::is_same_v<uintptr_t, T> &&
439 !std::is_same_v<uintptr_t, uint32_t> &&
440 !std::is_same_v<uintptr_t, uint64_t>>> {
443 return d->Read<uint64_t>();
445 return d->Read<uint32_t>();
450#define DECLARE_READ_TRAIT(type) \
451 template <typename T> \
452 struct ReadTrait<T, std::enable_if_t<std::is_same_v<type, T>>> { \
453 static type Read(FlowGraphDeserializer* d); \
456#undef DECLARE_READ_TRAIT
458 template <
typename T>
473 template <
typename T,
class =
void>
476#define DECLARE_READ_REF_TRAIT(type) \
477 template <typename T> \
478 struct ReadRefTrait<T, std::enable_if_t<std::is_same_v<type, T>>> { \
479 static T ReadRef(FlowGraphDeserializer* d); \
482#undef DECLARE_READ_REF_TRAIT
484 template <
typename T>
489 template <
typename T>
491 const intptr_t
len = Read<intptr_t>();
493 for (
int i = 0;
i <
len; ++
i) {
494 array.
Add(ReadRef<T>());
500 ClassPtr GetClassById(
classid_t id)
const;
501 const Object& ReadObjectImpl(intptr_t
cid, intptr_t object_index);
502 void SetObjectAt(intptr_t object_index,
const Object&
object);
503 const Object& ReadObjectWithEnclosingTypes();
517 intptr_t object_counter_ = 0;
GraphEntryInstr * graph_entry() const
void set_block(intptr_t block_id, BlockEntryInstr *block)
FlowGraph * ReadFlowGraph()
void set_graph_entry(GraphEntryInstr *entry)
FlowGraphDeserializer(const ParsedFunction &parsed_function, ReadStream *stream)
BlockEntryInstr * block(intptr_t block_id) const
IsolateGroup * isolate_group() const
Definition * definition(intptr_t ssa_temp_index) const
BlockEntryInstr * current_block() const
const ParsedFunction & parsed_function() const
void set_definition(intptr_t ssa_temp_index, Definition *def)
void set_current_block(BlockEntryInstr *block)
GrowableArray< T > ReadGrowableArrayOfRefs()
ReadStream * stream() const
IsolateGroup * isolate_group() const
void WriteGrowableArrayOfRefs(const GrowableArray< T > &array)
BaseWriteStream * stream() const
bool can_write_refs() const
void Write(typename WriteTrait< T >::ArgType x)
FlowGraphSerializer(NonStreamingWriteStream *stream)
void WriteFlowGraph(const FlowGraph &flow_graph, const ZoneGrowableArray< Definition * > &detached_defs)
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
#define DECLARE_READ_TRAIT(type)
#define IL_SERIALIZABLE_REF_TYPE_LIST(V)
#define DECLARE_WRITE_TRAIT(type)
#define DECLARE_READ_REF_TRAIT(type)
#define IL_SERIALIZABLE_TYPE_LIST(V)
#define DECLARE_WRITE_REF_TRAIT(type)
BlockEntryInstr * ReadRef(FlowGraphDeserializer *d)
static GrowableArray< T > Read(FlowGraphDeserializer *d)
static intptr_t Read(FlowGraphDeserializer *d)
static uintptr_t Read(FlowGraphDeserializer *d)
static ZoneGrowableArray< T > * Read(FlowGraphDeserializer *d)
static const GrowableArray< T > & Read(FlowGraphDeserializer *d)
static const ZoneGrowableArray< T > & Read(FlowGraphDeserializer *d)
const AbstractType * Read(FlowGraphDeserializer *d)
void WriteRef(FlowGraphSerializer *s, BlockEntryInstr *x)
static void Write(FlowGraphSerializer *s, ArgType x)
static void Write(FlowGraphSerializer *s, uintptr_t x)
static void Write(FlowGraphSerializer *s, intptr_t x)
static void Write(FlowGraphSerializer *s, ArgType x)
static void Write(FlowGraphSerializer *s, ArgType x)
static void Write(FlowGraphSerializer *s, ArgType x)
void Write(FlowGraphSerializer *s, const AbstractType *x)