LLVM: include/llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13#ifndef LLVM_EXECUTIONENGINE_ORC_SHARED_EXECUTORADDRESS_H
14#define LLVM_EXECUTIONENGINE_ORC_SHARED_EXECUTORADDRESS_H
15
21
22#include
23#if __has_feature(ptrauth_calls)
24#include <ptrauth.h>
25#endif
26#include <type_traits>
27
28namespace llvm {
29namespace orc {
30
32
33
35public:
36
38
39#if __has_feature(ptrauth_calls)
40 template class PtrauthSignDefault {
41 public:
42 constexpr T *operator()(T *P) {
43 if (std::is_function_v)
44 return ptrauth_sign_unauthenticated(P, ptrauth_key_function_pointer, 0);
45 else
46 return P;
47 }
48 };
49
50 template class PtrauthStripDefault {
51 public:
52 constexpr T *operator()(T *P) {
53 return ptrauth_strip(P, ptrauth_key_function_pointer);
54 }
55 };
56
57
58 template using defaultWrap = PtrauthSignDefault;
59
60
61 template using defaultUnwrap = PtrauthStripDefault;
62
63#else
64
65
67
68
70
71#endif
72
73
74
76 public:
77 constexpr Tag(uintptr_t TagValue, uintptr_t TagOffset)
78 : TagMask(TagValue << TagOffset) {}
79
81 return reinterpret_cast<T *>(reinterpret_cast<uintptr_t>(P) | TagMask);
82 }
83
84 private:
85 uintptr_t TagMask;
86 };
87
88
89
91 public:
92 constexpr Untag(uintptr_t TagLen, uintptr_t TagOffset)
93 : UntagMask(~(((uintptr_t(1) << TagLen) - 1) << TagOffset)) {}
94
96 return reinterpret_cast<T *>(reinterpret_cast<uintptr_t>(P) & UntagMask);
97 }
98
99 private:
100 uintptr_t UntagMask;
101 };
102
104
105
107
108
109
110 template <typename T, typename UnwrapFn = defaultUnwrap>
113 static_cast<uint64_t>(reinterpret_cast<uintptr_t>(Unwrap(Ptr))));
114 }
115
116
117
118 template <typename T, typename WrapFn = defaultWrap<std::remove_pointer_t>>
119 std::enable_if_t<std::is_pointer::value, T>
120 toPtr(WrapFn &&Wrap = WrapFn()) const {
121 uintptr_t IntPtr = static_cast<uintptr_t>(Addr);
122 assert(IntPtr == Addr && "ExecutorAddr value out of range for uintptr_t");
123 return Wrap(reinterpret_cast<T>(IntPtr));
124 }
125
126
127
128 template <typename T, typename WrapFn = defaultWrap>
129 std::enable_if_t<std::is_function::value, T *>
130 toPtr(WrapFn &&Wrap = WrapFn()) const {
131 uintptr_t IntPtr = static_cast<uintptr_t>(Addr);
132 assert(IntPtr == Addr && "ExecutorAddr value out of range for uintptr_t");
133 return Wrap(reinterpret_cast<T *>(IntPtr));
134 }
135
138 bool isNull() const { return Addr == 0; }
139
140 explicit operator bool() const { return Addr != 0; }
141
143 return LHS.Addr == RHS.Addr;
144 }
145
147 return LHS.Addr != RHS.Addr;
148 }
149
151 return LHS.Addr < RHS.Addr;
152 }
153
155 return LHS.Addr <= RHS.Addr;
156 }
157
159 return LHS.Addr > RHS.Addr;
160 }
161
163 return LHS.Addr >= RHS.Addr;
164 }
165
167 ++Addr;
168 return *this;
169 }
171 --Addr;
172 return *this;
173 }
176
178 Addr += Delta;
179 return *this;
180 }
181
183 Addr -= Delta;
184 return *this;
185 }
186
187private:
189};
190
191
196
197
202
203
208
209
214
215
220
221
228
229 template <typename T, typename UnwrapFn = ExecutorAddr::defaultUnwrap>
231 UnwrapFn &&Unwrap = UnwrapFn()) {
234 }
235
236 template <typename T, typename UnwrapFn = ExecutorAddr::defaultUnwrap>
238 UnwrapFn &&Unwrap = UnwrapFn()) {
240 }
241
244
247 return LHS.Start == RHS.Start && LHS.End == RHS.End;
248 }
252 }
255 return LHS.Start < RHS.Start ||
256 (LHS.Start == RHS.Start && LHS.End < RHS.End);
257 }
260 return LHS.Start < RHS.Start ||
261 (LHS.Start == RHS.Start && LHS.End <= RHS.End);
262 }
265 return LHS.Start > RHS.Start ||
266 (LHS.Start == RHS.Start && LHS.End > RHS.End);
267 }
270 return LHS.Start > RHS.Start ||
271 (LHS.Start == RHS.Start && LHS.End >= RHS.End);
272 }
273
281
284};
285
287 return OS << formatv("{0:x}", A.getValue());
288}
289
291 return OS << formatv("{0:x} -- {1:x}", R.Start.getValue(), R.End.getValue());
292}
293
294namespace shared {
295
297
298
300public:
304
308
312 return false;
314 return true;
315 }
316};
317
319
320
321template <>
339
341
342}
343}
344
345
363
364}
365
366#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
This file defines DenseMapInfo traits for DenseMap.
This file contains library features backported from future STL versions.
LLVM Value Representation.
constexpr Tag(uintptr_t TagValue, uintptr_t TagOffset)
Definition ExecutorAddress.h:77
constexpr T * operator()(T *P)
Definition ExecutorAddress.h:80
constexpr Untag(uintptr_t TagLen, uintptr_t TagOffset)
Definition ExecutorAddress.h:92
constexpr T * operator()(T *P)
Definition ExecutorAddress.h:95
Represents an address in the executor process.
Definition ExecutorAddress.h:34
ExecutorAddr & operator++()
Definition ExecutorAddress.h:166
friend bool operator==(const ExecutorAddr &LHS, const ExecutorAddr &RHS)
Definition ExecutorAddress.h:142
ExecutorAddr operator--(int)
Definition ExecutorAddress.h:175
ExecutorAddr & operator-=(const ExecutorAddrDiff &Delta)
Definition ExecutorAddress.h:182
rawPtr defaultUnwrap
Default unwrap function to use on this host.
Definition ExecutorAddress.h:69
uint64_t getValue() const
Definition ExecutorAddress.h:136
void setValue(uint64_t Addr)
Definition ExecutorAddress.h:137
llvm::identity rawPtr
A wrap/unwrap function that leaves pointers unmodified.
Definition ExecutorAddress.h:37
rawPtr defaultWrap
Default wrap function to use on this host.
Definition ExecutorAddress.h:66
std::enable_if_t< std::is_function< T >::value, T * > toPtr(WrapFn &&Wrap=WrapFn()) const
Cast this ExecutorAddr to a pointer of the given function type.
Definition ExecutorAddress.h:130
bool isNull() const
Definition ExecutorAddress.h:138
ExecutorAddr operator++(int)
Definition ExecutorAddress.h:174
friend bool operator>(const ExecutorAddr &LHS, const ExecutorAddr &RHS)
Definition ExecutorAddress.h:158
static ExecutorAddr fromPtr(T *Ptr, UnwrapFn &&Unwrap=UnwrapFn())
Create an ExecutorAddr from the given pointer.
Definition ExecutorAddress.h:111
friend bool operator>=(const ExecutorAddr &LHS, const ExecutorAddr &RHS)
Definition ExecutorAddress.h:162
ExecutorAddr & operator--()
Definition ExecutorAddress.h:170
constexpr ExecutorAddr(uint64_t Addr)
Create an ExecutorAddr from the given value.
Definition ExecutorAddress.h:106
friend bool operator<=(const ExecutorAddr &LHS, const ExecutorAddr &RHS)
Definition ExecutorAddress.h:154
friend bool operator<(const ExecutorAddr &LHS, const ExecutorAddr &RHS)
Definition ExecutorAddress.h:150
ExecutorAddr & operator+=(const ExecutorAddrDiff &Delta)
Definition ExecutorAddress.h:177
friend bool operator!=(const ExecutorAddr &LHS, const ExecutorAddr &RHS)
Definition ExecutorAddress.h:146
std::enable_if_t< std::is_pointer< T >::value, T > toPtr(WrapFn &&Wrap=WrapFn()) const
Cast this ExecutorAddr to a pointer of the given type.
Definition ExecutorAddress.h:120
This class implements an extremely fast bulk output stream that can only output to a stream.
ExecutorAddrDiff operator%(const ExecutorAddr &LHS, const ExecutorAddrDiff &RHS)
Taking the modulus of an address and a diff yields a diff.
Definition ExecutorAddress.h:216
ExecutorAddr operator+(const ExecutorAddr &LHS, const ExecutorAddrDiff &RHS)
Adding an offset and an address yields an address.
Definition ExecutorAddress.h:198
uint64_t ExecutorAddrDiff
Definition ExecutorAddress.h:31
LLVM_ABI raw_ostream & operator<<(raw_ostream &OS, const SymbolNameSet &Symbols)
Render a SymbolNameSet.
ExecutorAddrDiff operator-(const ExecutorAddr &LHS, const ExecutorAddr &RHS)
Subtracting two addresses yields an offset.
Definition ExecutorAddress.h:192
This is an optimization pass for GlobalISel generic memory operations.
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
static unsigned getHashValue(const orc::ExecutorAddr &Addr)
Definition ExecutorAddress.h:354
static bool isEqual(const orc::ExecutorAddr &LHS, const orc::ExecutorAddr &RHS)
Definition ExecutorAddress.h:358
static orc::ExecutorAddr getTombstoneKey()
Definition ExecutorAddress.h:350
static orc::ExecutorAddr getEmptyKey()
Definition ExecutorAddress.h:347
An information struct used to provide DenseMap with the various necessary components for a given valu...
Represents an address range in the exceutor process.
Definition ExecutorAddress.h:222
bool empty() const
Definition ExecutorAddress.h:242
friend bool operator==(const ExecutorAddrRange &LHS, const ExecutorAddrRange &RHS)
Definition ExecutorAddress.h:245
bool overlaps(const ExecutorAddrRange &Other)
Definition ExecutorAddress.h:278
ExecutorAddr Start
Definition ExecutorAddress.h:282
friend bool operator>=(const ExecutorAddrRange &LHS, const ExecutorAddrRange &RHS)
Definition ExecutorAddress.h:268
bool contains(const ExecutorAddrRange &Other)
Definition ExecutorAddress.h:275
ExecutorAddrRange(ExecutorAddr Start, ExecutorAddr End)
Definition ExecutorAddress.h:224
friend bool operator!=(const ExecutorAddrRange &LHS, const ExecutorAddrRange &RHS)
Definition ExecutorAddress.h:249
friend bool operator<(const ExecutorAddrRange &LHS, const ExecutorAddrRange &RHS)
Definition ExecutorAddress.h:253
ExecutorAddrRange(ExecutorAddr Start, ExecutorAddrDiff Size)
Definition ExecutorAddress.h:226
ExecutorAddrRange()=default
static ExecutorAddrRange fromPtrRange(T *Start, T *End, UnwrapFn &&Unwrap=UnwrapFn())
Definition ExecutorAddress.h:230
static ExecutorAddrRange fromPtrRange(T *Ptr, ExecutorAddrDiff Size, UnwrapFn &&Unwrap=UnwrapFn())
Definition ExecutorAddress.h:237
ExecutorAddrDiff size() const
Definition ExecutorAddress.h:243
friend bool operator<=(const ExecutorAddrRange &LHS, const ExecutorAddrRange &RHS)
Definition ExecutorAddress.h:258
ExecutorAddr End
Definition ExecutorAddress.h:283
bool contains(ExecutorAddr Addr) const
Definition ExecutorAddress.h:274
friend bool operator>(const ExecutorAddrRange &LHS, const ExecutorAddrRange &RHS)
Definition ExecutorAddress.h:263