1 //===--------- ExecutorSymbolDef.h - (Addr, Flags) pair ---------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // Represents a defining location for a symbol in the executing program.
11 // This file was derived from
12 // llvm/include/llvm/ExecutionEngine/Orc/Shared/ExecutorSymbolDef.h.
14 //===----------------------------------------------------------------------===//
16 #ifndef ORC_RT_EXECUTOR_SYMBOL_DEF_H
17 #define ORC_RT_EXECUTOR_SYMBOL_DEF_H
19 #include "bitmask_enum.h"
20 #include "executor_address.h"
21 #include "simple_packed_serialization.h"
25 /// Flags for symbols in the JIT.
26 class JITSymbolFlags
{
28 using UnderlyingType
= uint8_t;
29 using TargetFlagsType
= uint8_t;
31 /// These values must be kept in sync with \c JITSymbolFlags in the JIT.
32 enum FlagNames
: UnderlyingType
{
40 MaterializationSideEffectsOnly
= 1U << 6,
41 ORC_RT_MARK_AS_BITMASK_ENUM( // LargestValue =
42 MaterializationSideEffectsOnly
)
45 /// Default-construct a JITSymbolFlags instance.
46 JITSymbolFlags() = default;
48 /// Construct a JITSymbolFlags instance from the given flags and target
50 JITSymbolFlags(FlagNames Flags
, TargetFlagsType TargetFlags
)
51 : TargetFlags(TargetFlags
), Flags(Flags
) {}
53 bool operator==(const JITSymbolFlags
&RHS
) const {
54 return Flags
== RHS
.Flags
&& TargetFlags
== RHS
.TargetFlags
;
57 /// Get the underlying flags value as an integer.
58 UnderlyingType
getRawFlagsValue() const {
59 return static_cast<UnderlyingType
>(Flags
);
62 /// Return a reference to the target-specific flags.
63 TargetFlagsType
&getTargetFlags() { return TargetFlags
; }
65 /// Return a reference to the target-specific flags.
66 const TargetFlagsType
&getTargetFlags() const { return TargetFlags
; }
69 TargetFlagsType TargetFlags
= 0;
70 FlagNames Flags
= None
;
73 /// Represents a defining location for a JIT symbol.
74 class ExecutorSymbolDef
{
76 ExecutorSymbolDef() = default;
77 ExecutorSymbolDef(ExecutorAddr Addr
, JITSymbolFlags Flags
)
78 : Addr(Addr
), Flags(Flags
) {}
80 const ExecutorAddr
&getAddress() const { return Addr
; }
82 const JITSymbolFlags
&getFlags() const { return Flags
; }
84 friend bool operator==(const ExecutorSymbolDef
&LHS
,
85 const ExecutorSymbolDef
&RHS
) {
86 return LHS
.getAddress() == RHS
.getAddress() &&
87 LHS
.getFlags() == RHS
.getFlags();
95 using SPSJITSymbolFlags
=
96 SPSTuple
<JITSymbolFlags::UnderlyingType
, JITSymbolFlags::TargetFlagsType
>;
98 /// SPS serializatior for JITSymbolFlags.
99 template <> class SPSSerializationTraits
<SPSJITSymbolFlags
, JITSymbolFlags
> {
100 using FlagsArgList
= SPSJITSymbolFlags::AsArgList
;
103 static size_t size(const JITSymbolFlags
&F
) {
104 return FlagsArgList::size(F
.getRawFlagsValue(), F
.getTargetFlags());
107 static bool serialize(SPSOutputBuffer
&BOB
, const JITSymbolFlags
&F
) {
108 return FlagsArgList::serialize(BOB
, F
.getRawFlagsValue(),
112 static bool deserialize(SPSInputBuffer
&BIB
, JITSymbolFlags
&F
) {
113 JITSymbolFlags::UnderlyingType RawFlags
;
114 JITSymbolFlags::TargetFlagsType TargetFlags
;
115 if (!FlagsArgList::deserialize(BIB
, RawFlags
, TargetFlags
))
117 F
= JITSymbolFlags
{static_cast<JITSymbolFlags::FlagNames
>(RawFlags
),
123 using SPSExecutorSymbolDef
= SPSTuple
<SPSExecutorAddr
, SPSJITSymbolFlags
>;
125 /// SPS serializatior for ExecutorSymbolDef.
127 class SPSSerializationTraits
<SPSExecutorSymbolDef
, ExecutorSymbolDef
> {
128 using DefArgList
= SPSExecutorSymbolDef::AsArgList
;
131 static size_t size(const ExecutorSymbolDef
&ESD
) {
132 return DefArgList::size(ESD
.getAddress(), ESD
.getFlags());
135 static bool serialize(SPSOutputBuffer
&BOB
, const ExecutorSymbolDef
&ESD
) {
136 return DefArgList::serialize(BOB
, ESD
.getAddress(), ESD
.getFlags());
139 static bool deserialize(SPSInputBuffer
&BIB
, ExecutorSymbolDef
&ESD
) {
141 JITSymbolFlags Flags
;
142 if (!DefArgList::deserialize(BIB
, Addr
, Flags
))
144 ESD
= ExecutorSymbolDef
{Addr
, Flags
};
149 } // End namespace orc_rt
151 #endif // ORC_RT_EXECUTOR_SYMBOL_DEF_H