13#ifndef LLVM_EXECUTIONENGINE_JITLINK_JITLINKMEMORYMANAGER_H
14#define LLVM_EXECUTIONENGINE_JITLINK_JITLINKMEMORYMANAGER_H
58 static constexpr auto InvalidAddr =
~uint64_t(0);
63 assert(
A.getValue() != InvalidAddr &&
64 "Explicitly creating an invalid allocation?");
68 Other.A.setValue(InvalidAddr);
72 assert(
A.getValue() == InvalidAddr &&
73 "Cannot overwrite active finalized allocation");
78 assert(
A.getValue() == InvalidAddr &&
79 "Finalized allocation was not deallocated");
84 explicit operator bool()
const {
return A.getValue() != InvalidAddr; }
95 A.setValue(InvalidAddr);
133 std::promise<MSVCPExpected<FinalizedAlloc>> FinalizeResultP;
134 auto FinalizeResultF = FinalizeResultP.get_future();
136 FinalizeResultP.set_value(std::move(Result));
138 return FinalizeResultF.get();
164 std::promise<MSVCPExpected<std::unique_ptr<InFlightAlloc>>> AllocResultP;
165 auto AllocResultF = AllocResultP.get_future();
167 AllocResultP.set_value(std::move(
Alloc));
169 return AllocResultF.get();
181 std::vector<FinalizedAlloc> Allocs;
182 Allocs.push_back(std::move(
Alloc));
183 deallocate(std::move(Allocs), std::move(OnDeallocated));
188 std::promise<MSVCPError> DeallocResultP;
189 auto DeallocResultF = DeallocResultP.get_future();
191 [&](
Error Err) { DeallocResultP.set_value(std::move(Err)); });
192 return DeallocResultF.get();
197 std::vector<FinalizedAlloc> Allocs;
198 Allocs.push_back(std::move(
Alloc));
226 NextWorkingMemOffset(0) {}
234 size_t NextWorkingMemOffset;
235 std::vector<Block *> ContentBlocks, ZeroFillBlocks;
271 return {Segments.
begin(), Segments.
end()};
338 Alloc->finalize(std::move(OnFinalized));
343 return Alloc->finalize();
348 std::unique_ptr<LinkGraph> G,
350 std::unique_ptr<JITLinkMemoryManager::InFlightAlloc> Alloc);
352 std::unique_ptr<LinkGraph> G;
354 std::unique_ptr<JITLinkMemoryManager::InFlightAlloc> Alloc;
383 struct FinalizedAllocInfo {
385 std::vector<orc::shared::WrapperFunctionCall> DeallocActions;
388 FinalizedAlloc createFinalizedAlloc(
390 std::vector<orc::shared::WrapperFunctionCall> DeallocActions);
393 std::mutex FinalizedAllocsMutex;
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)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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...
A range adaptor for a pair of iterators.
The Alignment, ContentSize and ZeroFillSize of each segment will be pre-filled from the Graph.
BasicLayout simplifies the implementation of JITLinkMemoryManagers.
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.
Error apply()
Apply the layout to the graph.
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.
A JITLinkMemoryManager that allocates in-process memory.
static Expected< std::unique_ptr< InProcessMemoryManager > > Create()
Attempts to auto-detect the host page size.
void deallocate(std::vector< FinalizedAlloc > Alloc, OnDeallocatedFunction OnDeallocated) override
Deallocate a list of allocation objects.
void allocate(const JITLinkDylib *JD, LinkGraph &G, OnAllocatedFunction OnAllocated) override
Start the allocation process.
InProcessMemoryManager(uint64_t PageSize)
Create an instance using the given page size.
Represents a finalized allocation.
FinalizedAlloc(orc::ExecutorAddr A)
FinalizedAlloc(const FinalizedAlloc &)=delete
FinalizedAlloc & operator=(const FinalizedAlloc &)=delete
FinalizedAlloc(FinalizedAlloc &&Other)
orc::ExecutorAddr release()
Returns the address associated with this finalized allocation and resets this object to the default s...
orc::ExecutorAddr getAddress() const
Returns the address associated with this finalized allocation.
FinalizedAlloc & operator=(FinalizedAlloc &&Other)
Represents an allocation which has not been finalized yet.
virtual void finalize(OnFinalizedFunction OnFinalized)=0
Called to transfer working memory to the target and apply finalization.
virtual void abandon(OnAbandonedFunction OnAbandoned)=0
Called prior to finalization if the allocation should be abandoned.
Expected< FinalizedAlloc > finalize()
Synchronous convenience version of finalize.
unique_function< void(Expected< FinalizedAlloc >)> OnFinalizedFunction
Manages allocations of JIT memory.
AllocResult allocate(const JITLinkDylib *JD, LinkGraph &G)
Convenience function for blocking allocation.
void deallocate(FinalizedAlloc Alloc, OnDeallocatedFunction OnDeallocated)
Convenience function for deallocation of a single alloc.
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.
Error deallocate(std::vector< FinalizedAlloc > Allocs)
Convenience function for blocking deallocation.
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.
unique_function< void(Error)> OnDeallocatedFunction
Called when deallocation has completed.
virtual ~JITLinkMemoryManager()
A utility class for making simple allocations using JITLinkMemoryManager.
SimpleSegmentAlloc(SimpleSegmentAlloc &&)
SegmentInfo getSegInfo(orc::AllocGroup AG)
Returns the SegmentInfo for the given group.
void finalize(OnFinalizedFunction OnFinalized)
Finalize all groups (async version).
Expected< JITLinkMemoryManager::FinalizedAlloc > finalize()
Finalize all groups.
SimpleSegmentAlloc & operator=(SimpleSegmentAlloc &&)
static void Create(JITLinkMemoryManager &MemMgr, 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.
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.
std::vector< AllocActionCallPair > AllocActions
A vector of allocation actions to be run for this allocation.
NodeAddr< BlockNode * > Block
This is an optimization pass for GlobalISel generic memory operations.
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.
Describes the segment working memory and executor address.
MutableArrayRef< char > WorkingMem
Describes a segment to be allocated.
Segment(size_t ContentSize, Align ContentAlign)