[libc] Switch to using the generic `<gpuintrin.h>` implementations (#121810)
[llvm-project.git] / compiler-rt / lib / orc / executor_symbol_def.h
blob78c3c35e50b60d1c8d2ff62ef0930a30d7c5eae1
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.
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"
23 namespace orc_rt {
25 /// Flags for symbols in the JIT.
26 class JITSymbolFlags {
27 public:
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 {
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)
45 /// Default-construct a JITSymbolFlags instance.
46 JITSymbolFlags() = default;
48 /// Construct a JITSymbolFlags instance from the given flags and target
49 /// flags.
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; }
68 private:
69 TargetFlagsType TargetFlags = 0;
70 FlagNames Flags = None;
73 /// Represents a defining location for a JIT symbol.
74 class ExecutorSymbolDef {
75 public:
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();
90 private:
91 ExecutorAddr Addr;
92 JITSymbolFlags Flags;
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;
102 public:
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(),
109 F.getTargetFlags());
112 static bool deserialize(SPSInputBuffer &BIB, JITSymbolFlags &F) {
113 JITSymbolFlags::UnderlyingType RawFlags;
114 JITSymbolFlags::TargetFlagsType TargetFlags;
115 if (!FlagsArgList::deserialize(BIB, RawFlags, TargetFlags))
116 return false;
117 F = JITSymbolFlags{static_cast<JITSymbolFlags::FlagNames>(RawFlags),
118 TargetFlags};
119 return true;
123 using SPSExecutorSymbolDef = SPSTuple<SPSExecutorAddr, SPSJITSymbolFlags>;
125 /// SPS serializatior for ExecutorSymbolDef.
126 template <>
127 class SPSSerializationTraits<SPSExecutorSymbolDef, ExecutorSymbolDef> {
128 using DefArgList = SPSExecutorSymbolDef::AsArgList;
130 public:
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) {
140 ExecutorAddr Addr;
141 JITSymbolFlags Flags;
142 if (!DefArgList::deserialize(BIB, Addr, Flags))
143 return false;
144 ESD = ExecutorSymbolDef{Addr, Flags};
145 return true;
149 } // End namespace orc_rt
151 #endif // ORC_RT_EXECUTOR_SYMBOL_DEF_H