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.
37 class ExecutorAddr {
38 public:
39  ExecutorAddr() = default;
40 
41  /// Create an ExecutorAddr from the given value.
42  explicit ExecutorAddr(uint64_t Addr) : Addr(Addr) {}
43 
44  /// Create an ExecutorAddr from the given pointer.
45  /// Warning: This should only be used when JITing in-process.
46  template <typename T> static ExecutorAddr fromPtr(T *Value) {
47  return ExecutorAddr(
48  static_cast<uint64_t>(reinterpret_cast<uintptr_t>(Value)));
49  }
50 
51  /// Cast this ExecutorAddr to a pointer of the given type.
52  /// Warning: This should only be used when JITing in-process.
53  template <typename T> T toPtr() const {
54  static_assert(std::is_pointer<T>::value, "T must be a pointer type");
55  uintptr_t IntPtr = static_cast<uintptr_t>(Addr);
56  assert(IntPtr == Addr && "ExecutorAddr value out of range for uintptr_t");
57  return reinterpret_cast<T>(IntPtr);
58  }
59 
60  uint64_t getValue() const { return Addr; }
61  void setValue(uint64_t Addr) { this->Addr = Addr; }
62  bool isNull() const { return Addr == 0; }
63 
64  explicit operator bool() const { return Addr != 0; }
65 
66  friend bool operator==(const ExecutorAddr &LHS, const ExecutorAddr &RHS) {
67  return LHS.Addr == RHS.Addr;
68  }
69 
70  friend bool operator!=(const ExecutorAddr &LHS, const ExecutorAddr &RHS) {
71  return LHS.Addr != RHS.Addr;
72  }
73 
74  friend bool operator<(const ExecutorAddr &LHS, const ExecutorAddr &RHS) {
75  return LHS.Addr < RHS.Addr;
76  }
77 
78  friend bool operator<=(const ExecutorAddr &LHS, const ExecutorAddr &RHS) {
79  return LHS.Addr <= RHS.Addr;
80  }
81 
82  friend bool operator>(const ExecutorAddr &LHS, const ExecutorAddr &RHS) {
83  return LHS.Addr > RHS.Addr;
84  }
85 
86  friend bool operator>=(const ExecutorAddr &LHS, const ExecutorAddr &RHS) {
87  return LHS.Addr >= RHS.Addr;
88  }
89 
91  ++Addr;
92  return *this;
93  }
95  --Addr;
96  return *this;
97  }
98  ExecutorAddr operator++(int) { return ExecutorAddr(Addr++); }
99  ExecutorAddr operator--(int) { return ExecutorAddr(Addr--); }
100 
102  Addr += Delta.getValue();
103  return *this;
104  }
105 
107  Addr -= Delta.getValue();
108  return *this;
109  }
110 
111 private:
112  uint64_t Addr = 0;
113 };
114 
115 /// Subtracting two addresses yields an offset.
117  const ExecutorAddr &RHS) {
118  return ExecutorAddrDiff(LHS.getValue() - RHS.getValue());
119 }
120 
121 /// Adding an offset and an address yields an address.
123  const ExecutorAddrDiff &RHS) {
124  return ExecutorAddr(LHS.getValue() + RHS.getValue());
125 }
126 
127 /// Adding an address and an offset yields an address.
129  const ExecutorAddr &RHS) {
130  return ExecutorAddr(LHS.getValue() + RHS.getValue());
131 }
132 
133 /// Represents an address range in the exceutor process.
135  ExecutorAddrRange() = default;
137  : Start(Start), End(End) {}
139  : Start(Start), End(Start + Size) {}
140 
141  bool empty() const { return Start == End; }
142  ExecutorAddrDiff size() const { return End - Start; }
143 
144  friend bool operator==(const ExecutorAddrRange &LHS,
145  const ExecutorAddrRange &RHS) {
146  return LHS.Start == RHS.Start && LHS.End == RHS.End;
147  }
148  friend bool operator!=(const ExecutorAddrRange &LHS,
149  const ExecutorAddrRange &RHS) {
150  return !(LHS == RHS);
151  }
152  bool contains(ExecutorAddr Addr) const { return Start <= Addr && Addr < End; }
153  bool overlaps(const ExecutorAddrRange &Other) {
154  return !(Other.End <= Start || End <= Other.Start);
155  }
156 
159 };
160 
161 namespace shared {
162 
164 
165 /// SPS serializatior for ExecutorAddr.
167 public:
168  static size_t size(const ExecutorAddr &EA) {
170  }
171 
172  static bool serialize(SPSOutputBuffer &BOB, const ExecutorAddr &EA) {
173  return SPSArgList<uint64_t>::serialize(BOB, EA.getValue());
174  }
175 
176  static bool deserialize(SPSInputBuffer &BIB, ExecutorAddr &EA) {
177  uint64_t Tmp;
178  if (!SPSArgList<uint64_t>::deserialize(BIB, Tmp))
179  return false;
180  EA = ExecutorAddr(Tmp);
181  return true;
182  }
183 };
184 
186 
187 /// Serialization traits for address ranges.
188 template <>
190 public:
191  static size_t size(const ExecutorAddrRange &Value) {
193  Value.End);
194  }
195 
196  static bool serialize(SPSOutputBuffer &BOB, const ExecutorAddrRange &Value) {
198  BOB, Value.Start, Value.End);
199  }
200 
203  BIB, Value.Start, Value.End);
204  }
205 };
206 
208 
209 } // End namespace shared.
210 } // End namespace orc.
211 } // End namespace llvm.
212 
213 #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:37
llvm::orc::ExecutorAddr::operator<=
friend bool operator<=(const ExecutorAddr &LHS, const ExecutorAddr &RHS)
Definition: ExecutorAddress.h:78
llvm::orc::ExecutorAddrDiff
Represents the difference between two addresses in the executor process.
Definition: ExecutorAddress.h:25
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:193
llvm::orc::shared::SPSSerializationTraits
Specialize to describe how to serialize/deserialize to/from the given concrete type.
Definition: SimplePackedSerialization.h:103
llvm::orc::shared::SPSOutputBuffer
Output char buffer with overflow check.
Definition: SimplePackedSerialization.h:53
llvm::orc::ExecutorAddr::getValue
uint64_t getValue() const
Definition: ExecutorAddress.h:60
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:72
llvm::orc::shared::SPSSerializationTraits< SPSExecutorAddr, ExecutorAddr >::serialize
static bool serialize(SPSOutputBuffer &BOB, const ExecutorAddr &EA)
Definition: ExecutorAddress.h:172
llvm::orc::shared::SPSTuple
SPS tag type for tuples.
Definition: SimplePackedSerialization.h:183
llvm::orc::shared::SPSSerializationTraits< SPSExecutorAddr, ExecutorAddr >::size
static size_t size(const ExecutorAddr &EA)
Definition: ExecutorAddress.h:168
llvm::orc::ExecutorAddrDiff::ExecutorAddrDiff
ExecutorAddrDiff()=default
llvm::orc::ExecutorAddr::operator>
friend bool operator>(const ExecutorAddr &LHS, const ExecutorAddr &RHS)
Definition: ExecutorAddress.h:82
llvm::orc::operator+
ExecutorAddr operator+(const ExecutorAddr &LHS, const ExecutorAddrDiff &RHS)
Adding an offset and an address yields an address.
Definition: ExecutorAddress.h:122
llvm::orc::ExecutorAddr::isNull
bool isNull() const
Definition: ExecutorAddress.h:62
llvm::orc::ExecutorAddr::operator-=
ExecutorAddr & operator-=(const ExecutorAddrDiff Delta)
Definition: ExecutorAddress.h:106
llvm::orc::operator-
ExecutorAddrDiff operator-(const ExecutorAddr &LHS, const ExecutorAddr &RHS)
Subtracting two addresses yields an offset.
Definition: ExecutorAddress.h:116
llvm::orc::ExecutorAddrDiff::getValue
uint64_t getValue() const
Definition: ExecutorAddress.h:30
llvm::orc::shared::SPSExecutorAddr
Definition: ExecutorAddress.h:163
llvm::orc::ExecutorAddrRange
Represents an address range in the exceutor process.
Definition: ExecutorAddress.h:134
llvm::orc::ExecutorAddr::setValue
void setValue(uint64_t Addr)
Definition: ExecutorAddress.h:61
llvm::orc::ExecutorAddr::fromPtr
static ExecutorAddr fromPtr(T *Value)
Create an ExecutorAddr from the given pointer.
Definition: ExecutorAddress.h:46
llvm::orc::ExecutorAddr::operator--
ExecutorAddr & operator--()
Definition: ExecutorAddress.h:94
llvm::orc::shared::SPSSerializationTraits< SPSExecutorAddrRange, ExecutorAddrRange >::serialize
static bool serialize(SPSOutputBuffer &BOB, const ExecutorAddrRange &Value)
Definition: ExecutorAddress.h:196
llvm::orc::ExecutorAddrRange::size
ExecutorAddrDiff size() const
Definition: ExecutorAddress.h:142
llvm::orc::ExecutorAddr::operator+=
ExecutorAddr & operator+=(const ExecutorAddrDiff Delta)
Definition: ExecutorAddress.h:101
llvm::orc::ExecutorAddrRange::End
ExecutorAddr End
Definition: ExecutorAddress.h:158
llvm::orc::shared::SPSSerializationTraits< SPSExecutorAddrRange, ExecutorAddrRange >::size
static size_t size(const ExecutorAddrRange &Value)
Definition: ExecutorAddress.h:191
uint64_t
llvm::orc::ExecutorAddrRange::ExecutorAddrRange
ExecutorAddrRange(ExecutorAddr Start, ExecutorAddr End)
Definition: ExecutorAddress.h:136
llvm::orc::shared::SPSSerializationTraits< SPSExecutorAddr, ExecutorAddr >::deserialize
static bool deserialize(SPSInputBuffer &BIB, ExecutorAddr &EA)
Definition: ExecutorAddress.h:176
Addr
uint64_t Addr
Definition: ELFObjHandler.cpp:80
size
i< reg-> size
Definition: README.txt:166
llvm::orc::ExecutorAddrRange::empty
bool empty() const
Definition: ExecutorAddress.h:141
llvm::orc::ExecutorAddr::operator++
ExecutorAddr & operator++()
Definition: ExecutorAddress.h:90
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::orc::ExecutorAddrRange::overlaps
bool overlaps(const ExecutorAddrRange &Other)
Definition: ExecutorAddress.h:153
llvm::orc::ExecutorAddrRange::Start
ExecutorAddr Start
Definition: ExecutorAddress.h:157
SimplePackedSerialization.h
llvm::orc::ExecutorAddr::operator!=
friend bool operator!=(const ExecutorAddr &LHS, const ExecutorAddr &RHS)
Definition: ExecutorAddress.h:70
llvm::orc::ExecutorAddr::operator++
ExecutorAddr operator++(int)
Definition: ExecutorAddress.h:98
llvm::orc::shared::SPSSerializationTraits< SPSExecutorAddrRange, ExecutorAddrRange >::deserialize
static bool deserialize(SPSInputBuffer &BIB, ExecutorAddrRange &Value)
Definition: ExecutorAddress.h:201
llvm::orc::ExecutorAddr::operator==
friend bool operator==(const ExecutorAddr &LHS, const ExecutorAddr &RHS)
Definition: ExecutorAddress.h:66
llvm::orc::ExecutorAddr::operator--
ExecutorAddr operator--(int)
Definition: ExecutorAddress.h:99
llvm::orc::ExecutorAddr::ExecutorAddr
ExecutorAddr()=default
llvm::orc::ExecutorAddrRange::operator!=
friend bool operator!=(const ExecutorAddrRange &LHS, const ExecutorAddrRange &RHS)
Definition: ExecutorAddress.h:148
llvm::orc::ExecutorAddrDiff::ExecutorAddrDiff
ExecutorAddrDiff(uint64_t Value)
Definition: ExecutorAddress.h:28
llvm::orc::ExecutorAddr::operator<
friend bool operator<(const ExecutorAddr &LHS, const ExecutorAddr &RHS)
Definition: ExecutorAddress.h:74
llvm::orc::ExecutorAddrRange::ExecutorAddrRange
ExecutorAddrRange(ExecutorAddr Start, ExecutorAddrDiff Size)
Definition: ExecutorAddress.h:138
llvm::orc::ExecutorAddrRange::operator==
friend bool operator==(const ExecutorAddrRange &LHS, const ExecutorAddrRange &RHS)
Definition: ExecutorAddress.h:144
llvm::orc::ExecutorAddr::toPtr
T toPtr() const
Cast this ExecutorAddr to a pointer of the given type.
Definition: ExecutorAddress.h:53
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:106
llvm::orc::ExecutorAddr::ExecutorAddr
ExecutorAddr(uint64_t Addr)
Create an ExecutorAddr from the given value.
Definition: ExecutorAddress.h:42
llvm::orc::ExecutorAddrRange::contains
bool contains(ExecutorAddr Addr) const
Definition: ExecutorAddress.h:152
Other
Optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:1195
llvm::orc::ExecutorAddr::operator>=
friend bool operator>=(const ExecutorAddr &LHS, const ExecutorAddr &RHS)
Definition: ExecutorAddress.h:86