LLVM  15.0.0git
ExecutorAddress.h
Go to the documentation of this file.
1 //===------ ExecutorAddress.h - Executing process address -------*- 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 an address in the executing program.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_EXECUTIONENGINE_ORC_SHARED_EXECUTORADDRESS_H
14 #define LLVM_EXECUTIONENGINE_ORC_SHARED_EXECUTORADDRESS_H
15 
16 #include "llvm/ADT/DenseMapInfo.h"
20 
21 #include <cassert>
22 #include <type_traits>
23 
24 namespace llvm {
25 namespace orc {
26 
28 
29 /// Represents an address in the executor process.
30 class ExecutorAddr {
31 public:
32  ExecutorAddr() = default;
33 
34  /// Create an ExecutorAddr from the given value.
35  explicit constexpr ExecutorAddr(uint64_t Addr) : Addr(Addr) {}
36 
37  /// Create an ExecutorAddr from the given pointer.
38  /// Warning: This should only be used when JITing in-process.
39  template <typename T> static ExecutorAddr fromPtr(T *Value) {
40  return ExecutorAddr(
41  static_cast<uint64_t>(reinterpret_cast<uintptr_t>(Value)));
42  }
43 
44  /// Cast this ExecutorAddr to a pointer of the given type.
45  /// Warning: This should only be used when JITing in-process.
46  template <typename T>
47  std::enable_if_t<std::is_pointer<T>::value, T> toPtr() const {
48  uintptr_t IntPtr = static_cast<uintptr_t>(Addr);
49  assert(IntPtr == Addr && "ExecutorAddr value out of range for uintptr_t");
50  return reinterpret_cast<T>(IntPtr);
51  }
52 
53  /// Cast this ExecutorAddr to a pointer of the given function type.
54  /// Warning: This should only be used when JITing in-process.
55  template <typename T>
56  std::enable_if_t<std::is_function<T>::value, T *> toPtr() const {
57  uintptr_t IntPtr = static_cast<uintptr_t>(Addr);
58  assert(IntPtr == Addr && "ExecutorAddr value out of range for uintptr_t");
59  return reinterpret_cast<T *>(IntPtr);
60  }
61 
62  uint64_t getValue() const { return Addr; }
63  void setValue(uint64_t Addr) { this->Addr = Addr; }
64  bool isNull() const { return Addr == 0; }
65 
66  explicit operator bool() const { return Addr != 0; }
67 
68  friend bool operator==(const ExecutorAddr &LHS, const ExecutorAddr &RHS) {
69  return LHS.Addr == RHS.Addr;
70  }
71 
72  friend bool operator!=(const ExecutorAddr &LHS, const ExecutorAddr &RHS) {
73  return LHS.Addr != RHS.Addr;
74  }
75 
76  friend bool operator<(const ExecutorAddr &LHS, const ExecutorAddr &RHS) {
77  return LHS.Addr < RHS.Addr;
78  }
79 
80  friend bool operator<=(const ExecutorAddr &LHS, const ExecutorAddr &RHS) {
81  return LHS.Addr <= RHS.Addr;
82  }
83 
84  friend bool operator>(const ExecutorAddr &LHS, const ExecutorAddr &RHS) {
85  return LHS.Addr > RHS.Addr;
86  }
87 
88  friend bool operator>=(const ExecutorAddr &LHS, const ExecutorAddr &RHS) {
89  return LHS.Addr >= RHS.Addr;
90  }
91 
93  ++Addr;
94  return *this;
95  }
97  --Addr;
98  return *this;
99  }
100  ExecutorAddr operator++(int) { return ExecutorAddr(Addr++); }
101  ExecutorAddr operator--(int) { return ExecutorAddr(Addr--); }
102 
104  Addr += Delta;
105  return *this;
106  }
107 
109  Addr -= Delta;
110  return *this;
111  }
112 
113 private:
114  uint64_t Addr = 0;
115 };
116 
117 /// Subtracting two addresses yields an offset.
119  const ExecutorAddr &RHS) {
120  return ExecutorAddrDiff(LHS.getValue() - RHS.getValue());
121 }
122 
123 /// Adding an offset and an address yields an address.
125  const ExecutorAddrDiff &RHS) {
126  return ExecutorAddr(LHS.getValue() + RHS);
127 }
128 
129 /// Adding an address and an offset yields an address.
131  const ExecutorAddr &RHS) {
132  return ExecutorAddr(LHS + RHS.getValue());
133 }
134 
135 /// Subtracting an offset from an address yields an address.
137  const ExecutorAddrDiff &RHS) {
138  return ExecutorAddr(LHS.getValue() - RHS);
139 }
140 
141 /// Taking the modulus of an address and a diff yields a diff.
143  const ExecutorAddrDiff &RHS) {
144  return ExecutorAddrDiff(LHS.getValue() % RHS);
145 }
146 
147 /// Represents an address range in the exceutor process.
149  ExecutorAddrRange() = default;
151  : Start(Start), End(End) {}
153  : Start(Start), End(Start + Size) {}
154 
155  bool empty() const { return Start == End; }
156  ExecutorAddrDiff size() const { return End - Start; }
157 
158  friend bool operator==(const ExecutorAddrRange &LHS,
159  const ExecutorAddrRange &RHS) {
160  return LHS.Start == RHS.Start && LHS.End == RHS.End;
161  }
162  friend bool operator!=(const ExecutorAddrRange &LHS,
163  const ExecutorAddrRange &RHS) {
164  return !(LHS == RHS);
165  }
166  bool contains(ExecutorAddr Addr) const { return Start <= Addr && Addr < End; }
167  bool overlaps(const ExecutorAddrRange &Other) {
168  return !(Other.End <= Start || End <= Other.Start);
169  }
170 
173 };
174 
176  return OS << formatv("{0:x}", A.getValue());
177 }
178 
180  return OS << formatv("{0:x} -- {1:x}", R.Start.getValue(), R.End.getValue());
181 }
182 
183 namespace shared {
184 
186 
187 /// SPS serializatior for ExecutorAddr.
189 public:
190  static size_t size(const ExecutorAddr &EA) {
192  }
193 
194  static bool serialize(SPSOutputBuffer &BOB, const ExecutorAddr &EA) {
195  return SPSArgList<uint64_t>::serialize(BOB, EA.getValue());
196  }
197 
198  static bool deserialize(SPSInputBuffer &BIB, ExecutorAddr &EA) {
199  uint64_t Tmp;
200  if (!SPSArgList<uint64_t>::deserialize(BIB, Tmp))
201  return false;
202  EA = ExecutorAddr(Tmp);
203  return true;
204  }
205 };
206 
208 
209 /// Serialization traits for address ranges.
210 template <>
212 public:
213  static size_t size(const ExecutorAddrRange &Value) {
215  Value.End);
216  }
217 
218  static bool serialize(SPSOutputBuffer &BOB, const ExecutorAddrRange &Value) {
220  BOB, Value.Start, Value.End);
221  }
222 
225  BIB, Value.Start, Value.End);
226  }
227 };
228 
230 
231 } // End namespace shared.
232 } // End namespace orc.
233 
234 // Provide DenseMapInfo for ExecutorAddrs.
235 template <> struct DenseMapInfo<orc::ExecutorAddr> {
236  static inline orc::ExecutorAddr getEmptyKey() {
238  }
241  }
242 
243  static unsigned getHashValue(const orc::ExecutorAddr &Addr) {
244  return DenseMapInfo<uint64_t>::getHashValue(Addr.getValue());
245  }
246 
247  static bool isEqual(const orc::ExecutorAddr &LHS,
248  const orc::ExecutorAddr &RHS) {
249  return DenseMapInfo<uint64_t>::isEqual(LHS.getValue(), RHS.getValue());
250  }
251 };
252 
253 } // End namespace llvm.
254 
255 #endif // LLVM_EXECUTIONENGINE_ORC_SHARED_EXECUTORADDRESS_H
llvm::orc::ExecutorAddr
Represents an address in the executor process.
Definition: ExecutorAddress.h:30
llvm::orc::ExecutorAddr::operator<=
friend bool operator<=(const ExecutorAddr &LHS, const ExecutorAddr &RHS)
Definition: ExecutorAddress.h:80
llvm::orc::operator<<
raw_ostream & operator<<(raw_ostream &OS, const SymbolStringPtr &Sym)
Render a SymbolStringPtr.
Definition: DebugUtils.cpp:141
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::orc::shared::SPSSequence
SPS tag type for sequences.
Definition: SimplePackedSerialization.h:204
llvm::orc::shared::SPSSerializationTraits
Specialize to describe how to serialize/deserialize to/from the given concrete type.
Definition: SimplePackedSerialization.h:104
llvm::orc::shared::SPSOutputBuffer
Output char buffer with overflow check.
Definition: SimplePackedSerialization.h:54
llvm::orc::ExecutorAddr::getValue
uint64_t getValue() const
Definition: ExecutorAddress.h:62
llvm::orc::ExecutorAddrRange::ExecutorAddrRange
ExecutorAddrRange()=default
llvm::orc::ExecutorAddr::toPtr
std::enable_if_t< std::is_pointer< T >::value, T > toPtr() const
Cast this ExecutorAddr to a pointer of the given type.
Definition: ExecutorAddress.h:47
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::orc::shared::SPSInputBuffer
Input char buffer with underflow check.
Definition: SimplePackedSerialization.h:73
RHS
Value * RHS
Definition: X86PartialReduction.cpp:76
llvm::orc::shared::SPSSerializationTraits< SPSExecutorAddr, ExecutorAddr >::serialize
static bool serialize(SPSOutputBuffer &BOB, const ExecutorAddr &EA)
Definition: ExecutorAddress.h:194
llvm::orc::shared::SPSTuple
SPS tag type for tuples.
Definition: SimplePackedSerialization.h:194
llvm::orc::shared::SPSSerializationTraits< SPSExecutorAddr, ExecutorAddr >::size
static size_t size(const ExecutorAddr &EA)
Definition: ExecutorAddress.h:190
llvm::orc::ExecutorAddr::toPtr
std::enable_if_t< std::is_function< T >::value, T * > toPtr() const
Cast this ExecutorAddr to a pointer of the given function type.
Definition: ExecutorAddress.h:56
llvm::orc::ExecutorAddr::operator>
friend bool operator>(const ExecutorAddr &LHS, const ExecutorAddr &RHS)
Definition: ExecutorAddress.h:84
llvm::orc::operator+
ExecutorAddr operator+(const ExecutorAddr &LHS, const ExecutorAddrDiff &RHS)
Adding an offset and an address yields an address.
Definition: ExecutorAddress.h:124
LHS
Value * LHS
Definition: X86PartialReduction.cpp:75
llvm::formatv
auto formatv(const char *Fmt, Ts &&... Vals) -> formatv_object< decltype(std::make_tuple(detail::build_format_adapter(std::forward< Ts >(Vals))...))>
Definition: FormatVariadic.h:251
llvm::DenseMapInfo
An information struct used to provide DenseMap with the various necessary components for a given valu...
Definition: APInt.h:34
llvm::orc::ExecutorAddr::isNull
bool isNull() const
Definition: ExecutorAddress.h:64
llvm::orc::operator-
ExecutorAddrDiff operator-(const ExecutorAddr &LHS, const ExecutorAddr &RHS)
Subtracting two addresses yields an offset.
Definition: ExecutorAddress.h:118
llvm::orc::shared::SPSExecutorAddr
Definition: ExecutorAddress.h:185
llvm::orc::ExecutorAddrDiff
uint64_t ExecutorAddrDiff
Definition: ExecutorAddress.h:27
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:54
llvm::orc::ExecutorAddrRange
Represents an address range in the exceutor process.
Definition: ExecutorAddress.h:148
llvm::orc::ExecutorAddr::setValue
void setValue(uint64_t Addr)
Definition: ExecutorAddress.h:63
llvm::orc::ExecutorAddr::fromPtr
static ExecutorAddr fromPtr(T *Value)
Create an ExecutorAddr from the given pointer.
Definition: ExecutorAddress.h:39
FormatVariadic.h
llvm::DenseMapInfo< orc::ExecutorAddr >::isEqual
static bool isEqual(const orc::ExecutorAddr &LHS, const orc::ExecutorAddr &RHS)
Definition: ExecutorAddress.h:247
llvm::orc::ExecutorAddr::operator--
ExecutorAddr & operator--()
Definition: ExecutorAddress.h:96
llvm::orc::shared::SPSSerializationTraits< SPSExecutorAddrRange, ExecutorAddrRange >::serialize
static bool serialize(SPSOutputBuffer &BOB, const ExecutorAddrRange &Value)
Definition: ExecutorAddress.h:218
llvm::orc::ExecutorAddrRange::size
ExecutorAddrDiff size() const
Definition: ExecutorAddress.h:156
llvm::orc::ExecutorAddrRange::End
ExecutorAddr End
Definition: ExecutorAddress.h:172
llvm::orc::shared::SPSSerializationTraits< SPSExecutorAddrRange, ExecutorAddrRange >::size
static size_t size(const ExecutorAddrRange &Value)
Definition: ExecutorAddress.h:213
uint64_t
llvm::orc::ExecutorAddrRange::ExecutorAddrRange
ExecutorAddrRange(ExecutorAddr Start, ExecutorAddr End)
Definition: ExecutorAddress.h:150
llvm::DenseMapInfo< orc::ExecutorAddr >::getHashValue
static unsigned getHashValue(const orc::ExecutorAddr &Addr)
Definition: ExecutorAddress.h:243
llvm::orc::shared::SPSSerializationTraits< SPSExecutorAddr, ExecutorAddr >::deserialize
static bool deserialize(SPSInputBuffer &BIB, ExecutorAddr &EA)
Definition: ExecutorAddress.h:198
Addr
uint64_t Addr
Definition: ELFObjHandler.cpp:78
size
i< reg-> size
Definition: README.txt:166
llvm::orc::ExecutorAddrRange::empty
bool empty() const
Definition: ExecutorAddress.h:155
llvm::orc::ExecutorAddr::operator++
ExecutorAddr & operator++()
Definition: ExecutorAddress.h:92
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::orc::ExecutorAddr::operator+=
ExecutorAddr & operator+=(const ExecutorAddrDiff &Delta)
Definition: ExecutorAddress.h:103
llvm::orc::ExecutorAddrRange::overlaps
bool overlaps(const ExecutorAddrRange &Other)
Definition: ExecutorAddress.h:167
llvm::orc::ExecutorAddrRange::Start
ExecutorAddr Start
Definition: ExecutorAddress.h:171
SimplePackedSerialization.h
llvm::orc::ExecutorAddr::ExecutorAddr
constexpr ExecutorAddr(uint64_t Addr)
Create an ExecutorAddr from the given value.
Definition: ExecutorAddress.h:35
llvm::orc::ExecutorAddr::operator!=
friend bool operator!=(const ExecutorAddr &LHS, const ExecutorAddr &RHS)
Definition: ExecutorAddress.h:72
llvm::orc::ExecutorAddr::operator++
ExecutorAddr operator++(int)
Definition: ExecutorAddress.h:100
llvm::orc::shared::SPSSerializationTraits< SPSExecutorAddrRange, ExecutorAddrRange >::deserialize
static bool deserialize(SPSInputBuffer &BIB, ExecutorAddrRange &Value)
Definition: ExecutorAddress.h:223
llvm::orc::ExecutorAddr::operator==
friend bool operator==(const ExecutorAddr &LHS, const ExecutorAddr &RHS)
Definition: ExecutorAddress.h:68
llvm::orc::ExecutorAddr::operator--
ExecutorAddr operator--(int)
Definition: ExecutorAddress.h:101
llvm::orc::ExecutorAddr::ExecutorAddr
ExecutorAddr()=default
llvm::orc::ExecutorAddrRange::operator!=
friend bool operator!=(const ExecutorAddrRange &LHS, const ExecutorAddrRange &RHS)
Definition: ExecutorAddress.h:162
llvm::DenseMapInfo< orc::ExecutorAddr >::getTombstoneKey
static orc::ExecutorAddr getTombstoneKey()
Definition: ExecutorAddress.h:239
llvm::orc::ExecutorAddr::operator-=
ExecutorAddr & operator-=(const ExecutorAddrDiff &Delta)
Definition: ExecutorAddress.h:108
llvm::orc::ExecutorAddr::operator<
friend bool operator<(const ExecutorAddr &LHS, const ExecutorAddr &RHS)
Definition: ExecutorAddress.h:76
isEqual
static bool isEqual(const Function &Caller, const Function &Callee)
Definition: Attributes.cpp:1869
llvm::orc::ExecutorAddrRange::ExecutorAddrRange
ExecutorAddrRange(ExecutorAddr Start, ExecutorAddrDiff Size)
Definition: ExecutorAddress.h:152
llvm::orc::operator%
ExecutorAddrDiff operator%(const ExecutorAddr &LHS, const ExecutorAddrDiff &RHS)
Taking the modulus of an address and a diff yields a diff.
Definition: ExecutorAddress.h:142
DenseMapInfo.h
llvm::orc::ExecutorAddrRange::operator==
friend bool operator==(const ExecutorAddrRange &LHS, const ExecutorAddrRange &RHS)
Definition: ExecutorAddress.h:158
raw_ostream.h
llvm::DenseMapInfo< orc::ExecutorAddr >::getEmptyKey
static orc::ExecutorAddr getEmptyKey()
Definition: ExecutorAddress.h:236
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::orc::shared::SPSArgList
A utility class for serializing to a blob from a variadic list.
Definition: SimplePackedSerialization.h:107
llvm::orc::ExecutorAddrRange::contains
bool contains(ExecutorAddr Addr) const
Definition: ExecutorAddress.h:166
Other
Optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:1236
llvm::orc::ExecutorAddr::operator>=
friend bool operator>=(const ExecutorAddr &LHS, const ExecutorAddr &RHS)
Definition: ExecutorAddress.h:88