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 
17 
18 #include <cassert>
19 #include <type_traits>
20 
21 namespace llvm {
22 namespace orc {
23 
24 /// Represents the difference between two addresses in the executor process.
26 public:
27  ExecutorAddrDiff() = default;
29 
30  uint64_t getValue() const { return Value; }
31 
32 private:
33  int64_t Value = 0;
34 };
35 
36 /// Represents an address in the executor process.
38 public:
39  ExecutorAddress() = default;
40  explicit ExecutorAddress(uint64_t Addr) : Addr(Addr) {}
41 
42  /// Create an ExecutorAddress from the given pointer.
43  /// Warning: This should only be used when JITing in-process.
44  template <typename T> static ExecutorAddress fromPtr(T *Value) {
45  return ExecutorAddress(
46  static_cast<uint64_t>(reinterpret_cast<uintptr_t>(Value)));
47  }
48 
49  /// Cast this ExecutorAddress to a pointer of the given type.
50  /// Warning: This should only be esude when JITing in-process.
51  template <typename T> T toPtr() const {
52  static_assert(std::is_pointer<T>::value, "T must be a pointer type");
53  uintptr_t IntPtr = static_cast<uintptr_t>(Addr);
54  assert(IntPtr == Addr &&
55  "JITTargetAddress value out of range for uintptr_t");
56  return reinterpret_cast<T>(IntPtr);
57  }
58 
59  uint64_t getValue() const { return Addr; }
60  void setValue(uint64_t Addr) { this->Addr = Addr; }
61  bool isNull() const { return Addr == 0; }
62 
63  explicit operator bool() const { return Addr != 0; }
64 
65  friend bool operator==(const ExecutorAddress &LHS,
66  const ExecutorAddress &RHS) {
67  return LHS.Addr == RHS.Addr;
68  }
69 
70  friend bool operator!=(const ExecutorAddress &LHS,
71  const ExecutorAddress &RHS) {
72  return LHS.Addr != RHS.Addr;
73  }
74 
75  friend bool operator<(const ExecutorAddress &LHS,
76  const ExecutorAddress &RHS) {
77  return LHS.Addr < RHS.Addr;
78  }
79 
80  friend bool operator<=(const ExecutorAddress &LHS,
81  const ExecutorAddress &RHS) {
82  return LHS.Addr <= RHS.Addr;
83  }
84 
85  friend bool operator>(const ExecutorAddress &LHS,
86  const ExecutorAddress &RHS) {
87  return LHS.Addr > RHS.Addr;
88  }
89 
90  friend bool operator>=(const ExecutorAddress &LHS,
91  const ExecutorAddress &RHS) {
92  return LHS.Addr >= RHS.Addr;
93  }
94 
96  ++Addr;
97  return *this;
98  }
100  --Addr;
101  return *this;
102  }
103  ExecutorAddress operator++(int) { return ExecutorAddress(Addr++); }
104  ExecutorAddress operator--(int) { return ExecutorAddress(Addr++); }
105 
107  Addr += Delta.getValue();
108  return *this;
109  }
110 
112  Addr -= Delta.getValue();
113  return *this;
114  }
115 
116 private:
117  uint64_t Addr = 0;
118 };
119 
120 /// Subtracting two addresses yields an offset.
122  const ExecutorAddress &RHS) {
123  return ExecutorAddrDiff(LHS.getValue() - RHS.getValue());
124 }
125 
126 /// Adding an offset and an address yields an address.
128  const ExecutorAddrDiff &RHS) {
129  return ExecutorAddress(LHS.getValue() + RHS.getValue());
130 }
131 
132 /// Adding an address and an offset yields an address.
134  const ExecutorAddress &RHS) {
135  return ExecutorAddress(LHS.getValue() + RHS.getValue());
136 }
137 
138 /// Represents an address range in the exceutor process.
140  ExecutorAddressRange() = default;
143 
144  bool empty() const { return StartAddress == EndAddress; }
146 
149 };
150 
151 namespace shared {
152 
153 /// SPS serializatior for ExecutorAddress.
155 public:
156  static size_t size(const ExecutorAddress &EA) {
158  }
159 
160  static bool serialize(SPSOutputBuffer &BOB, const ExecutorAddress &EA) {
161  return SPSArgList<uint64_t>::serialize(BOB, EA.getValue());
162  }
163 
164  static bool deserialize(SPSInputBuffer &BIB, ExecutorAddress &EA) {
165  uint64_t Tmp;
166  if (!SPSArgList<uint64_t>::deserialize(BIB, Tmp))
167  return false;
168  EA = ExecutorAddress(Tmp);
169  return true;
170  }
171 };
172 
175 
176 /// Serialization traits for address ranges.
177 template <>
179 public:
180  static size_t size(const ExecutorAddressRange &Value) {
182  Value.StartAddress, Value.EndAddress);
183  }
184 
185  static bool serialize(SPSOutputBuffer &BOB,
186  const ExecutorAddressRange &Value) {
188  BOB, Value.StartAddress, Value.EndAddress);
189  }
190 
193  BIB, Value.StartAddress, Value.EndAddress);
194  }
195 };
196 
198 
199 } // End namespace shared.
200 } // End namespace orc.
201 } // End namespace llvm.
202 
203 #endif // LLVM_EXECUTIONENGINE_ORC_SHARED_EXECUTORADDRESS_H
llvm::orc::ExecutorAddrDiff
Represents the difference between two addresses in the executor process.
Definition: ExecutorAddress.h:25
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::orc::shared::SPSSequence
SPS tag type for sequences.
Definition: SimplePackedSerialization.h:193
llvm::orc::ExecutorAddress::operator+=
ExecutorAddress & operator+=(const ExecutorAddrDiff Delta)
Definition: ExecutorAddress.h:106
llvm::orc::ExecutorAddress
Represents an address in the executor process.
Definition: ExecutorAddress.h:37
llvm::orc::shared::SPSSerializationTraits
Specialize to describe how to serialize/deserialize to/from the given concrete type.
Definition: SimplePackedSerialization.h:103
llvm::orc::ExecutorAddress::operator>
friend bool operator>(const ExecutorAddress &LHS, const ExecutorAddress &RHS)
Definition: ExecutorAddress.h:85
llvm::orc::ExecutorAddress::operator-=
ExecutorAddress & operator-=(const ExecutorAddrDiff Delta)
Definition: ExecutorAddress.h:111
llvm::orc::shared::SPSOutputBuffer
Output char buffer with overflow check.
Definition: SimplePackedSerialization.h:53
llvm::orc::operator+
ExecutorAddress operator+(const ExecutorAddress &LHS, const ExecutorAddrDiff &RHS)
Adding an offset and an address yields an address.
Definition: ExecutorAddress.h:127
llvm::orc::shared::SPSExecutorAddressRange
SPSTuple< SPSExecutorAddress, SPSExecutorAddress > SPSExecutorAddressRange
Definition: ExecutorAddress.h:174
llvm::orc::ExecutorAddress::operator--
ExecutorAddress operator--(int)
Definition: ExecutorAddress.h:104
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::orc::shared::SPSInputBuffer
Input char buffer with underflow check.
Definition: SimplePackedSerialization.h:72
llvm::orc::shared::SPSTuple
SPS tag type for tuples.
Definition: SimplePackedSerialization.h:183
llvm::orc::ExecutorAddrDiff::ExecutorAddrDiff
ExecutorAddrDiff()=default
llvm::orc::shared::SPSSerializationTraits< SPSExecutorAddress, ExecutorAddress >::deserialize
static bool deserialize(SPSInputBuffer &BIB, ExecutorAddress &EA)
Definition: ExecutorAddress.h:164
llvm::orc::ExecutorAddress::operator!=
friend bool operator!=(const ExecutorAddress &LHS, const ExecutorAddress &RHS)
Definition: ExecutorAddress.h:70
llvm::orc::ExecutorAddressRange::EndAddress
ExecutorAddress EndAddress
Definition: ExecutorAddress.h:148
llvm::orc::ExecutorAddress::operator--
ExecutorAddress & operator--()
Definition: ExecutorAddress.h:99
llvm::orc::ExecutorAddressRange::ExecutorAddressRange
ExecutorAddressRange()=default
llvm::orc::ExecutorAddrDiff::getValue
uint64_t getValue() const
Definition: ExecutorAddress.h:30
llvm::orc::ExecutorAddressRange::empty
bool empty() const
Definition: ExecutorAddress.h:144
llvm::orc::ExecutorAddressRange::StartAddress
ExecutorAddress StartAddress
Definition: ExecutorAddress.h:147
uint64_t
llvm::orc::ExecutorAddress::operator==
friend bool operator==(const ExecutorAddress &LHS, const ExecutorAddress &RHS)
Definition: ExecutorAddress.h:65
Addr
uint64_t Addr
Definition: ELFObjHandler.cpp:80
llvm::orc::shared::SPSSerializationTraits< SPSExecutorAddressRange, ExecutorAddressRange >::deserialize
static bool deserialize(SPSInputBuffer &BIB, ExecutorAddressRange &Value)
Definition: ExecutorAddress.h:191
llvm::orc::ExecutorAddressRange
Represents an address range in the exceutor process.
Definition: ExecutorAddress.h:139
llvm::orc::ExecutorAddress::operator<=
friend bool operator<=(const ExecutorAddress &LHS, const ExecutorAddress &RHS)
Definition: ExecutorAddress.h:80
llvm::orc::operator-
ExecutorAddrDiff operator-(const ExecutorAddress &LHS, const ExecutorAddress &RHS)
Subtracting two addresses yields an offset.
Definition: ExecutorAddress.h:121
size
i< reg-> size
Definition: README.txt:166
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::orc::ExecutorAddress::isNull
bool isNull() const
Definition: ExecutorAddress.h:61
llvm::orc::ExecutorAddress::fromPtr
static ExecutorAddress fromPtr(T *Value)
Create an ExecutorAddress from the given pointer.
Definition: ExecutorAddress.h:44
SimplePackedSerialization.h
llvm::orc::ExecutorAddressRange::ExecutorAddressRange
ExecutorAddressRange(ExecutorAddress StartAddress, ExecutorAddress EndAddress)
Definition: ExecutorAddress.h:141
llvm::orc::ExecutorAddress::ExecutorAddress
ExecutorAddress(uint64_t Addr)
Definition: ExecutorAddress.h:40
llvm::orc::ExecutorAddress::ExecutorAddress
ExecutorAddress()=default
llvm::orc::ExecutorAddress::operator++
ExecutorAddress & operator++()
Definition: ExecutorAddress.h:95
llvm::orc::shared::SPSSerializationTraits< SPSExecutorAddressRange, ExecutorAddressRange >::size
static size_t size(const ExecutorAddressRange &Value)
Definition: ExecutorAddress.h:180
llvm::orc::ExecutorAddrDiff::ExecutorAddrDiff
ExecutorAddrDiff(uint64_t Value)
Definition: ExecutorAddress.h:28
llvm::orc::ExecutorAddress::operator++
ExecutorAddress operator++(int)
Definition: ExecutorAddress.h:103
llvm::orc::shared::SPSExecutorAddress
SPS tag type for executor addresseses.
Definition: SimplePackedSerialization.h:199
llvm::orc::ExecutorAddressRange::size
ExecutorAddrDiff size() const
Definition: ExecutorAddress.h:145
llvm::orc::ExecutorAddress::getValue
uint64_t getValue() const
Definition: ExecutorAddress.h:59
llvm::orc::ExecutorAddress::toPtr
T toPtr() const
Cast this ExecutorAddress to a pointer of the given type.
Definition: ExecutorAddress.h:51
llvm::orc::ExecutorAddress::setValue
void setValue(uint64_t Addr)
Definition: ExecutorAddress.h:60
llvm::orc::shared::SPSSerializationTraits< SPSExecutorAddress, ExecutorAddress >::serialize
static bool serialize(SPSOutputBuffer &BOB, const ExecutorAddress &EA)
Definition: ExecutorAddress.h:160
llvm::orc::shared::SPSSerializationTraits< SPSExecutorAddressRange, ExecutorAddressRange >::serialize
static bool serialize(SPSOutputBuffer &BOB, const ExecutorAddressRange &Value)
Definition: ExecutorAddress.h:185
llvm::orc::shared::SPSSerializationTraits< SPSExecutorAddress, ExecutorAddress >::size
static size_t size(const ExecutorAddress &EA)
Definition: ExecutorAddress.h:156
llvm::orc::ExecutorAddress::operator<
friend bool operator<(const ExecutorAddress &LHS, const ExecutorAddress &RHS)
Definition: ExecutorAddress.h:75
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
llvm::orc::shared::SPSArgList
A utility class for serializing to a blob from a variadic list.
Definition: SimplePackedSerialization.h:106
llvm::orc::ExecutorAddress::operator>=
friend bool operator>=(const ExecutorAddress &LHS, const ExecutorAddress &RHS)
Definition: ExecutorAddress.h:90