LLVM: include/llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13#ifndef LLVM_EXECUTIONENGINE_JITLINK_JITLINKMEMORYMANAGER_H
14#define LLVM_EXECUTIONENGINE_JITLINK_JITLINKMEMORYMANAGER_H
15
30
31#include
32#include
33#include
34#include
35
36namespace llvm {
38
42
43
44
45
46
48public:
49
50
51
52
53
54
55
56
57
58
61
62 static constexpr auto InvalidAddr = ~uint64_t(0);
63
64 public:
67 assert(A.getValue() != InvalidAddr &&
68 "Explicitly creating an invalid allocation?");
69 }
72 Other.A.setValue(InvalidAddr);
73 }
76 assert(A.getValue() == InvalidAddr &&
77 "Cannot overwrite active finalized allocation");
79 return *this;
80 }
82 assert(A.getValue() == InvalidAddr &&
83 "Finalized allocation was not deallocated");
84 }
85
86
87
88 explicit operator bool() const { return A.getValue() != InvalidAddr; }
89
90
91
93
94
95
96
102
103 private:
105 };
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
123 public:
126
128
129
131
132
134
135
137 std::promise<MSVCPExpected> FinalizeResultP;
138 auto FinalizeResultF = FinalizeResultP.get_future();
140 FinalizeResultP.set_value(std::move(Result));
141 });
142 return FinalizeResultF.get();
143 }
144 };
145
146
148
149
151
152
154
156
157
158
159
160
161
162
165
166
168 std::promise<MSVCPExpected<std::unique_ptr>> AllocResultP;
169 auto AllocResultF = AllocResultP.get_future();
171 AllocResultP.set_value(std::move(Alloc));
172 });
173 return AllocResultF.get();
174 }
175
176
177
178
179
180 virtual void deallocate(std::vector Allocs,
182
183
185 std::vector Allocs;
186 Allocs.push_back(std::move(Alloc));
187 deallocate(std::move(Allocs), std::move(OnDeallocated));
188 }
189
190
192 std::promise DeallocResultP;
193 auto DeallocResultF = DeallocResultP.get_future();
195 [&](Error Err) { DeallocResultP.set_value(std::move(Err)); });
196 return DeallocResultF.get();
197 }
198
199
201 std::vector Allocs;
202 Allocs.push_back(std::move(Alloc));
203 return deallocate(std::move(Allocs));
204 }
205};
206
207
208
209
210
211
212
213
215public:
216
217
218
219
220
221
222
223
226
227 public:
234
235 private:
236 size_t NextWorkingMemOffset = 0;
237 std::vector<Block *> ContentBlocks, ZeroFillBlocks;
238 };
239
240
241
242
249
250private:
252
253public:
255
256
258
259
260
261
262
263
264
265
266
267
270
271
273 return {Segments.begin(), Segments.end()};
274 }
275
276
278
279
280
281
283
284private:
286 SegmentMap Segments;
287};
288
289
290
291
292
293
294
295
296
297
298
300public:
301
310
311
316
318
320
323
325 std::shared_ptrorc::SymbolStringPool SSP,
328
331 std::shared_ptrorc::SymbolStringPool SSP, Triple TT,
333
337
338
340
341
343 Alloc->finalize(std::move(OnFinalized));
344 }
345
346
348 return Alloc->finalize();
349 }
350
351private:
353 std::unique_ptr G,
355 std::unique_ptrJITLinkMemoryManager::InFlightAlloc Alloc);
356
357 std::unique_ptr G;
359 std::unique_ptrJITLinkMemoryManager::InFlightAlloc Alloc;
360};
361
362
364public:
366
367
369
370
374
376 OnAllocatedFunction OnAllocated) override;
377
378
380
381 void deallocate(std::vector Alloc,
382 OnDeallocatedFunction OnDeallocated) override;
383
384
386
387private:
388
389
390 struct FinalizedAllocInfo {
392 std::vectororc::shared::WrapperFunctionCall DeallocActions;
393 };
394
395 FinalizedAlloc createFinalizedAlloc(
397 std::vectororc::shared::WrapperFunctionCall DeallocActions);
398
400 std::mutex FinalizedAllocsMutex;
402};
403
404}
405}
406
407#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the BumpPtrAllocator interface.
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static cl::opt< int > PageSize("imp-null-check-page-size", cl::desc("The page size of the target in bytes"), cl::init(4096), cl::Hidden)
This file defines the SmallVector class.
Lightweight error class with error context and mandatory checking.
Tagged union holding either a T or a Error.
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
RecyclingAllocator - This class wraps an Allocator, adding the functionality of recycling deleted obj...
Triple - Helper class for working with autoconf configuration names.
A range adaptor for a pair of iterators.
char * WorkingMem
Definition JITLinkMemoryManager.h:233
size_t ContentSize
Definition JITLinkMemoryManager.h:230
orc::ExecutorAddr Addr
Definition JITLinkMemoryManager.h:232
friend class BasicLayout
Definition JITLinkMemoryManager.h:225
uint64_t ZeroFillSize
Definition JITLinkMemoryManager.h:231
Align Alignment
Definition JITLinkMemoryManager.h:229
LLVM_ABI orc::shared::AllocActions & graphAllocActions()
Returns a reference to the AllocActions in the graph.
LinkGraph & getGraph()
Return a reference to the graph this allocation was created from.
Definition JITLinkMemoryManager.h:257
LLVM_ABI Error apply()
Apply the layout to the graph.
LLVM_ABI Expected< ContiguousPageBasedLayoutSizes > getContiguousPageBasedLayoutSizes(uint64_t PageSize)
Returns the total number of required to allocate all segments (with each segment padded out to page s...
iterator_range< SegmentMap::iterator > segments()
Returns an iterator over the segments of the layout.
Definition JITLinkMemoryManager.h:272
LLVM_ABI BasicLayout(LinkGraph &G)
An Addressable with content and edges.
static Expected< std::unique_ptr< InProcessMemoryManager > > Create()
Attempts to auto-detect the host page size.
InProcessMemoryManager(uint64_t PageSize)
Create an instance using the given page size.
Definition JITLinkMemoryManager.h:371
Represents a finalized allocation.
Definition JITLinkMemoryManager.h:59
FinalizedAlloc(orc::ExecutorAddr A)
Definition JITLinkMemoryManager.h:66
FinalizedAlloc(const FinalizedAlloc &)=delete
FinalizedAlloc & operator=(const FinalizedAlloc &)=delete
FinalizedAlloc(FinalizedAlloc &&Other)
Definition JITLinkMemoryManager.h:71
~FinalizedAlloc()
Definition JITLinkMemoryManager.h:81
orc::ExecutorAddr release()
Returns the address associated with this finalized allocation and resets this object to the default s...
Definition JITLinkMemoryManager.h:97
orc::ExecutorAddr getAddress() const
Returns the address associated with this finalized allocation.
Definition JITLinkMemoryManager.h:92
FinalizedAlloc & operator=(FinalizedAlloc &&Other)
Definition JITLinkMemoryManager.h:75
friend class JITLinkMemoryManager
Definition JITLinkMemoryManager.h:60
Represents an allocation which has not been finalized yet.
Definition JITLinkMemoryManager.h:122
virtual void finalize(OnFinalizedFunction OnFinalized)=0
Called to transfer working memory to the target and apply finalization.
unique_function< void(Error)> OnAbandonedFunction
Definition JITLinkMemoryManager.h:125
virtual void abandon(OnAbandonedFunction OnAbandoned)=0
Called prior to finalization if the allocation should be abandoned.
Expected< FinalizedAlloc > finalize()
Synchronous convenience version of finalize.
Definition JITLinkMemoryManager.h:136
unique_function< void(Expected< FinalizedAlloc >)> OnFinalizedFunction
Definition JITLinkMemoryManager.h:124
Manages allocations of JIT memory.
Definition JITLinkMemoryManager.h:47
AllocResult allocate(const JITLinkDylib *JD, LinkGraph &G)
Convenience function for blocking allocation.
Definition JITLinkMemoryManager.h:167
void deallocate(FinalizedAlloc Alloc, OnDeallocatedFunction OnDeallocated)
Convenience function for deallocation of a single alloc.
Definition JITLinkMemoryManager.h:184
virtual void allocate(const JITLinkDylib *JD, LinkGraph &G, OnAllocatedFunction OnAllocated)=0
Start the allocation process.
Error deallocate(FinalizedAlloc Alloc)
Convenience function for blocking deallocation of a single alloc.
Definition JITLinkMemoryManager.h:200
Error deallocate(std::vector< FinalizedAlloc > Allocs)
Convenience function for blocking deallocation.
Definition JITLinkMemoryManager.h:191
virtual void deallocate(std::vector< FinalizedAlloc > Allocs, OnDeallocatedFunction OnDeallocated)=0
Deallocate a list of allocation objects.
unique_function< void(AllocResult)> OnAllocatedFunction
Called when allocation has been completed.
Definition JITLinkMemoryManager.h:150
unique_function< void(Error)> OnDeallocatedFunction
Called when deallocation has completed.
Definition JITLinkMemoryManager.h:153
virtual ~JITLinkMemoryManager()
Expected< std::unique_ptr< InFlightAlloc > > AllocResult
Typedef for the argument to be passed to OnAllocatedFunction.
Definition JITLinkMemoryManager.h:147
Represents an object file section.
unique_function< void(Expected< SimpleSegmentAlloc >)> OnCreatedFunction
Definition JITLinkMemoryManager.h:319
LLVM_ABI ~SimpleSegmentAlloc()
orc::AllocGroupSmallMap< Segment > SegmentMap
Definition JITLinkMemoryManager.h:317
LLVM_ABI SimpleSegmentAlloc(SimpleSegmentAlloc &&)
LLVM_ABI SegmentInfo getSegInfo(orc::AllocGroup AG)
Returns the SegmentInfo for the given group.
void finalize(OnFinalizedFunction OnFinalized)
Finalize all groups (async version).
Definition JITLinkMemoryManager.h:342
Expected< JITLinkMemoryManager::FinalizedAlloc > finalize()
Finalize all groups.
Definition JITLinkMemoryManager.h:347
LLVM_ABI SimpleSegmentAlloc & operator=(SimpleSegmentAlloc &&)
JITLinkMemoryManager::InFlightAlloc::OnFinalizedFunction OnFinalizedFunction
Definition JITLinkMemoryManager.h:321
static LLVM_ABI void Create(JITLinkMemoryManager &MemMgr, std::shared_ptr< orc::SymbolStringPool > SSP, Triple TT, const JITLinkDylib *JD, SegmentMap Segments, OnCreatedFunction OnCreated)
A specialized small-map for AllocGroups.
A pair of memory protections and allocation policies.
Represents an address in the executor process.
void setValue(uint64_t Addr)
This class encapsulates the notion of a memory block which has an address and a size.
unique_function is a type-erasing functor similar to std::function.
This is an optimization pass for GlobalISel generic memory operations.
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
This struct is a compact representation of a valid (non-zero power of two) alignment.
A convenience class that further groups segments based on memory deallocation policy.
Definition JITLinkMemoryManager.h:243
uint64_t FinalizeSegs
Definition JITLinkMemoryManager.h:245
uint64_t total() const
Definition JITLinkMemoryManager.h:247
uint64_t StandardSegs
Definition JITLinkMemoryManager.h:244
Describes the segment working memory and executor address.
Definition JITLinkMemoryManager.h:312
orc::ExecutorAddr Addr
Definition JITLinkMemoryManager.h:313
MutableArrayRef< char > WorkingMem
Definition JITLinkMemoryManager.h:314
Align ContentAlign
Definition JITLinkMemoryManager.h:308
size_t ContentSize
Definition JITLinkMemoryManager.h:307
Segment(size_t ContentSize, Align ContentAlign)
Definition JITLinkMemoryManager.h:304