LLVM  14.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> T toPtr() const {
47  static_assert(std::is_pointer<T>::value, "T must be a pointer type");
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  uint64_t getValue() const { return Addr; }
54  void setValue(uint64_t Addr) { this->Addr = Addr; }
55  bool isNull() const { return Addr == 0; }
56 
57  explicit operator bool() const { return Addr != 0; }
58 
59  friend bool operator==(const ExecutorAddr &LHS, const ExecutorAddr &RHS) {
60  return LHS.Addr == RHS.Addr;
61  }
62 
63  friend bool operator!=(const ExecutorAddr &LHS, const ExecutorAddr &RHS) {
64  return LHS.Addr != RHS.Addr;
65  }
66 
67  friend bool operator<(const ExecutorAddr &LHS, const ExecutorAddr &RHS) {
68  return LHS.Addr < RHS.Addr;
69  }
70 
71  friend bool operator<=(const ExecutorAddr &LHS, const ExecutorAddr &RHS) {
72  return LHS.Addr <= RHS.Addr;
73  }
74 
75  friend bool operator>(const ExecutorAddr &LHS, const ExecutorAddr &RHS) {
76  return LHS.Addr > RHS.Addr;
77  }
78 
79  friend bool operator>=(const ExecutorAddr &LHS, const ExecutorAddr &RHS) {
80  return LHS.Addr >= RHS.Addr;
81  }
82 
84  ++Addr;
85  return *this;
86  }
88  --Addr;
89  return *this;
90  }
91  ExecutorAddr operator++(int) { return ExecutorAddr(Addr++); }
92  ExecutorAddr operator--(int) { return ExecutorAddr(Addr--); }
93 
95  Addr += Delta;
96  return *this;
97  }
98 
100  Addr -= Delta;
101  return *this;
102  }
103 
104 private:
105  uint64_t Addr = 0;
106 };
107 
108 /// Subtracting two addresses yields an offset.
110  const ExecutorAddr &RHS) {
111  return ExecutorAddrDiff(LHS.getValue() - RHS.getValue());
112 }
113 
114 /// Adding an offset and an address yields an address.
116  const ExecutorAddrDiff &RHS) {
117  return ExecutorAddr(LHS.getValue() + RHS);
118 }
119 
120 /// Adding an address and an offset yields an address.
122  const ExecutorAddr &RHS) {
123  return ExecutorAddr(LHS + RHS.getValue());
124 }
125 
126 /// Subtracting an offset from an address yields an address.
128  const ExecutorAddrDiff &RHS) {
129  return ExecutorAddr(LHS.getValue() - RHS);
130 }
131 
132 /// Taking the modulus of an address and a diff yields a diff.
134  const ExecutorAddrDiff &RHS) {
135  return ExecutorAddrDiff(LHS.getValue() % RHS);
136 }
137 
138 /// Represents an address range in the exceutor process.
140  ExecutorAddrRange() = default;
142  : Start(Start), End(End) {}
144  : Start(Start), End(Start + Size) {}
145 
146  bool empty() const { return Start == End; }
147  ExecutorAddrDiff size() const { return End - Start; }
148 
149  friend bool operator==(const ExecutorAddrRange &LHS,
150  const ExecutorAddrRange &RHS) {
151  return LHS.Start == RHS.Start && LHS.End == RHS.End;
152  }
153  friend bool operator!=(const ExecutorAddrRange &LHS,
154  const ExecutorAddrRange &RHS) {
155  return !(LHS == RHS);
156  }
157  bool contains(ExecutorAddr Addr) const { return Start <= Addr && Addr < End; }
158  bool overlaps(const ExecutorAddrRange &Other) {
159  return !(Other.End <= Start || End <= Other.Start);
160  }
161 
164 };
165 
167  return OS << formatv("{0:x}", A.getValue());
168 }
169 
171  return OS << formatv("{0:x} -- {1:x}", R.Start.getValue(), R.End.getValue());
172 }
173 
174 namespace shared {
175 
177 
178 /// SPS serializatior for ExecutorAddr.
180 public:
181  static size_t size(const ExecutorAddr &EA) {
183  }
184 
185  static bool serialize(SPSOutputBuffer &BOB, const ExecutorAddr &EA) {
186  return SPSArgList<uint64_t>::serialize(BOB, EA.getValue());
187  }
188 
189  static bool deserialize(SPSInputBuffer &BIB, ExecutorAddr &EA) {
190  uint64_t Tmp;
191  if (!SPSArgList<uint64_t>::deserialize(BIB, Tmp))
192  return false;
193  EA = ExecutorAddr(Tmp);
194  return true;
195  }
196 };
197 
199 
200 /// Serialization traits for address ranges.
201 template <>
203 public:
204  static size_t size(const ExecutorAddrRange &Value) {
206  Value.End);
207  }
208 
209  static bool serialize(SPSOutputBuffer &BOB, const ExecutorAddrRange &Value) {
211  BOB, Value.Start, Value.End);
212  }
213 
216  BIB, Value.Start, Value.End);
217  }
218 };
219 
221 
222 } // End namespace shared.
223 } // End namespace orc.
224 
225 // Provide DenseMapInfo for ExecutorAddrs.
226 template <> struct DenseMapInfo<orc::ExecutorAddr> {
227  static inline orc::ExecutorAddr getEmptyKey() {
229  }
232  }
233 
234  static unsigned getHashValue(const orc::ExecutorAddr &Addr) {
235  return DenseMapInfo<uint64_t>::getHashValue(Addr.getValue());
236  }
237 
238  static bool isEqual(const orc::ExecutorAddr &LHS,
239  const orc::ExecutorAddr &RHS) {
240  return DenseMapInfo<uint64_t>::isEqual(LHS.getValue(), RHS.getValue());
241  }
242 };
243 
244 } // End namespace llvm.
245 
246 #endif // LLVM_EXECUTIONENGINE_ORC_SHARED_EXECUTORADDRESS_H
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
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:71
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: AllocatorList.h:23
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:53
llvm::orc::ExecutorAddrRange::ExecutorAddrRange
ExecutorAddrRange()=default
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:74
llvm::orc::shared::SPSSerializationTraits< SPSExecutorAddr, ExecutorAddr >::serialize
static bool serialize(SPSOutputBuffer &BOB, const ExecutorAddr &EA)
Definition: ExecutorAddress.h:185
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:181
llvm::orc::ExecutorAddr::operator>
friend bool operator>(const ExecutorAddr &LHS, const ExecutorAddr &RHS)
Definition: ExecutorAddress.h:75
llvm::orc::operator+
ExecutorAddr operator+(const ExecutorAddr &LHS, const ExecutorAddrDiff &RHS)
Adding an offset and an address yields an address.
Definition: ExecutorAddress.h:115
LHS
Value * LHS
Definition: X86PartialReduction.cpp:73
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:250
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:55
llvm::orc::operator-
ExecutorAddrDiff operator-(const ExecutorAddr &LHS, const ExecutorAddr &RHS)
Subtracting two addresses yields an offset.
Definition: ExecutorAddress.h:109
llvm::orc::shared::SPSExecutorAddr
Definition: ExecutorAddress.h:176
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:53
llvm::orc::ExecutorAddrRange
Represents an address range in the exceutor process.
Definition: ExecutorAddress.h:139
llvm::orc::ExecutorAddr::setValue
void setValue(uint64_t Addr)
Definition: ExecutorAddress.h:54
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:238
llvm::orc::ExecutorAddr::operator--
ExecutorAddr & operator--()
Definition: ExecutorAddress.h:87
llvm::orc::shared::SPSSerializationTraits< SPSExecutorAddrRange, ExecutorAddrRange >::serialize
static bool serialize(SPSOutputBuffer &BOB, const ExecutorAddrRange &Value)
Definition: ExecutorAddress.h:209
llvm::orc::ExecutorAddrRange::size
ExecutorAddrDiff size() const
Definition: ExecutorAddress.h:147
llvm::orc::ExecutorAddrRange::End
ExecutorAddr End
Definition: ExecutorAddress.h:163
llvm::orc::shared::SPSSerializationTraits< SPSExecutorAddrRange, ExecutorAddrRange >::size
static size_t size(const ExecutorAddrRange &Value)
Definition: ExecutorAddress.h:204
uint64_t
llvm::orc::ExecutorAddrRange::ExecutorAddrRange
ExecutorAddrRange(ExecutorAddr Start, ExecutorAddr End)
Definition: ExecutorAddress.h:141
llvm::DenseMapInfo< orc::ExecutorAddr >::getHashValue
static unsigned getHashValue(const orc::ExecutorAddr &Addr)
Definition: ExecutorAddress.h:234
llvm::orc::shared::SPSSerializationTraits< SPSExecutorAddr, ExecutorAddr >::deserialize
static bool deserialize(SPSInputBuffer &BIB, ExecutorAddr &EA)
Definition: ExecutorAddress.h:189
Addr
uint64_t Addr
Definition: ELFObjHandler.cpp:79
size
i< reg-> size
Definition: README.txt:166
llvm::orc::ExecutorAddrRange::empty
bool empty() const
Definition: ExecutorAddress.h:146
llvm::orc::ExecutorAddr::operator++
ExecutorAddr & operator++()
Definition: ExecutorAddress.h:83
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::orc::ExecutorAddr::operator+=
ExecutorAddr & operator+=(const ExecutorAddrDiff &Delta)
Definition: ExecutorAddress.h:94
llvm::orc::ExecutorAddrRange::overlaps
bool overlaps(const ExecutorAddrRange &Other)
Definition: ExecutorAddress.h:158
llvm::orc::ExecutorAddrRange::Start
ExecutorAddr Start
Definition: ExecutorAddress.h:162
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:63
llvm::orc::ExecutorAddr::operator++
ExecutorAddr operator++(int)
Definition: ExecutorAddress.h:91
llvm::orc::shared::SPSSerializationTraits< SPSExecutorAddrRange, ExecutorAddrRange >::deserialize
static bool deserialize(SPSInputBuffer &BIB, ExecutorAddrRange &Value)
Definition: ExecutorAddress.h:214
llvm::orc::ExecutorAddr::operator==
friend bool operator==(const ExecutorAddr &LHS, const ExecutorAddr &RHS)
Definition: ExecutorAddress.h:59
llvm::orc::ExecutorAddr::operator--
ExecutorAddr operator--(int)
Definition: ExecutorAddress.h:92
llvm::orc::ExecutorAddr::ExecutorAddr
ExecutorAddr()=default
llvm::orc::ExecutorAddrRange::operator!=
friend bool operator!=(const ExecutorAddrRange &LHS, const ExecutorAddrRange &RHS)
Definition: ExecutorAddress.h:153
llvm::DenseMapInfo< orc::ExecutorAddr >::getTombstoneKey
static orc::ExecutorAddr getTombstoneKey()
Definition: ExecutorAddress.h:230
llvm::orc::ExecutorAddr::operator-=
ExecutorAddr & operator-=(const ExecutorAddrDiff &Delta)
Definition: ExecutorAddress.h:99
llvm::orc::ExecutorAddr::operator<
friend bool operator<(const ExecutorAddr &LHS, const ExecutorAddr &RHS)
Definition: ExecutorAddress.h:67
isEqual
static bool isEqual(const Function &Caller, const Function &Callee)
Definition: Attributes.cpp:1863
llvm::orc::ExecutorAddrRange::ExecutorAddrRange
ExecutorAddrRange(ExecutorAddr Start, ExecutorAddrDiff Size)
Definition: ExecutorAddress.h:143
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:133
DenseMapInfo.h
llvm::orc::ExecutorAddrRange::operator==
friend bool operator==(const ExecutorAddrRange &LHS, const ExecutorAddrRange &RHS)
Definition: ExecutorAddress.h:149
llvm::orc::ExecutorAddr::toPtr
T toPtr() const
Cast this ExecutorAddr to a pointer of the given type.
Definition: ExecutorAddress.h:46
raw_ostream.h
llvm::DenseMapInfo< orc::ExecutorAddr >::getEmptyKey
static orc::ExecutorAddr getEmptyKey()
Definition: ExecutorAddress.h:227
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:157
Other
Optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:1198
llvm::orc::ExecutorAddr::operator>=
friend bool operator>=(const ExecutorAddr &LHS, const ExecutorAddr &RHS)
Definition: ExecutorAddress.h:79