1//===--------- ExecutorSymbolDef.h - (Addr, Flags) pair ---------*- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9// Represents a defining location for a symbol in the executing program.
10//
11// This file was derived from
12// llvm/include/llvm/ExecutionEngine/Orc/Shared/ExecutorSymbolDef.h.
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef ORC_RT_EXECUTOR_SYMBOL_DEF_H
17#define ORC_RT_EXECUTOR_SYMBOL_DEF_H
18
19#include "bitmask_enum.h"
20#include "executor_address.h"
21#include "simple_packed_serialization.h"
22
23namespace __orc_rt {
24
25/// Flags for symbols in the JIT.
26class JITSymbolFlags {
27public:
28 using UnderlyingType = uint8_t;
29 using TargetFlagsType = uint8_t;
30
31 /// These values must be kept in sync with \c JITSymbolFlags in the JIT.
32 enum FlagNames : UnderlyingType {
33 None = 0,
34 HasError = 1U << 0,
35 Weak = 1U << 1,
36 Common = 1U << 2,
37 Absolute = 1U << 3,
38 Exported = 1U << 4,
39 Callable = 1U << 5,
40 MaterializationSideEffectsOnly = 1U << 6,
41 ORC_RT_MARK_AS_BITMASK_ENUM( // LargestValue =
42 MaterializationSideEffectsOnly)
43 };
44
45 /// Default-construct a JITSymbolFlags instance.
46 JITSymbolFlags() = default;
47
48 /// Construct a JITSymbolFlags instance from the given flags and target
49 /// flags.
50 JITSymbolFlags(FlagNames Flags, TargetFlagsType TargetFlags)
51 : TargetFlags(TargetFlags), Flags(Flags) {}
52
53 bool operator==(const JITSymbolFlags &RHS) const {
54 return Flags == RHS.Flags && TargetFlags == RHS.TargetFlags;
55 }
56
57 /// Get the underlying flags value as an integer.
58 UnderlyingType getRawFlagsValue() const {
59 return static_cast<UnderlyingType>(Flags);
60 }
61
62 /// Return a reference to the target-specific flags.
63 TargetFlagsType &getTargetFlags() { return TargetFlags; }
64
65 /// Return a reference to the target-specific flags.
66 const TargetFlagsType &getTargetFlags() const { return TargetFlags; }
67
68private:
69 TargetFlagsType TargetFlags = 0;
70 FlagNames Flags = None;
71};
72
73/// Represents a defining location for a JIT symbol.
74class ExecutorSymbolDef {
75public:
76 ExecutorSymbolDef() = default;
77 ExecutorSymbolDef(ExecutorAddr Addr, JITSymbolFlags Flags)
78 : Addr(Addr), Flags(Flags) {}
79
80 const ExecutorAddr &getAddress() const { return Addr; }
81
82 const JITSymbolFlags &getFlags() const { return Flags; }
83
84 friend bool operator==(const ExecutorSymbolDef &LHS,
85 const ExecutorSymbolDef &RHS) {
86 return LHS.getAddress() == RHS.getAddress() &&
87 LHS.getFlags() == RHS.getFlags();
88 }
89
90private:
91 ExecutorAddr Addr;
92 JITSymbolFlags Flags;
93};
94
95using SPSJITSymbolFlags =
96 SPSTuple<JITSymbolFlags::UnderlyingType, JITSymbolFlags::TargetFlagsType>;
97
98/// SPS serializatior for JITSymbolFlags.
99template <> class SPSSerializationTraits<SPSJITSymbolFlags, JITSymbolFlags> {
100 using FlagsArgList = SPSJITSymbolFlags::AsArgList;
101
102public:
103 static size_t size(const JITSymbolFlags &F) {
104 return FlagsArgList::size(Arg: F.getRawFlagsValue(), Args: F.getTargetFlags());
105 }
106
107 static bool serialize(SPSOutputBuffer &BOB, const JITSymbolFlags &F) {
108 return FlagsArgList::serialize(OB&: BOB, Arg: F.getRawFlagsValue(),
109 Args: F.getTargetFlags());
110 }
111
112 static bool deserialize(SPSInputBuffer &BIB, JITSymbolFlags &F) {
113 JITSymbolFlags::UnderlyingType RawFlags;
114 JITSymbolFlags::TargetFlagsType TargetFlags;
115 if (!FlagsArgList::deserialize(IB&: BIB, Arg&: RawFlags, Args&: TargetFlags))
116 return false;
117 F = JITSymbolFlags{static_cast<JITSymbolFlags::FlagNames>(RawFlags),
118 TargetFlags};
119 return true;
120 }
121};
122
123using SPSExecutorSymbolDef = SPSTuple<SPSExecutorAddr, SPSJITSymbolFlags>;
124
125/// SPS serializatior for ExecutorSymbolDef.
126template <>
127class SPSSerializationTraits<SPSExecutorSymbolDef, ExecutorSymbolDef> {
128 using DefArgList = SPSExecutorSymbolDef::AsArgList;
129
130public:
131 static size_t size(const ExecutorSymbolDef &ESD) {
132 return DefArgList::size(Arg: ESD.getAddress(), Args: ESD.getFlags());
133 }
134
135 static bool serialize(SPSOutputBuffer &BOB, const ExecutorSymbolDef &ESD) {
136 return DefArgList::serialize(OB&: BOB, Arg: ESD.getAddress(), Args: ESD.getFlags());
137 }
138
139 static bool deserialize(SPSInputBuffer &BIB, ExecutorSymbolDef &ESD) {
140 ExecutorAddr Addr;
141 JITSymbolFlags Flags;
142 if (!DefArgList::deserialize(IB&: BIB, Arg&: Addr, Args&: Flags))
143 return false;
144 ESD = ExecutorSymbolDef{Addr, Flags};
145 return true;
146 }
147};
148
149} // End namespace __orc_rt
150
151#endif // ORC_RT_EXECUTOR_SYMBOL_DEF_H
152

source code of compiler-rt/lib/orc/executor_symbol_def.h