13#ifndef LLVM_EXECUTIONENGINE_JITLINK_JITLINKMEMORYMANAGER_H
14#define LLVM_EXECUTIONENGINE_JITLINK_JITLINKMEMORYMANAGER_H
60 static constexpr auto InvalidAddr =
~uint64_t(0);
65 assert(
A.getValue() != InvalidAddr &&
66 "Explicitly creating an invalid allocation?");
70 Other.A.setValue(InvalidAddr);
74 assert(
A.getValue() == InvalidAddr &&
75 "Cannot overwrite active finalized allocation");
80 assert(
A.getValue() == InvalidAddr &&
81 "Finalized allocation was not deallocated");
86 explicit operator bool()
const {
return A.getValue() != InvalidAddr; }
97 A.setValue(InvalidAddr);
135 std::promise<MSVCPExpected<FinalizedAlloc>> FinalizeResultP;
136 auto FinalizeResultF = FinalizeResultP.get_future();
138 FinalizeResultP.set_value(std::move(Result));
140 return FinalizeResultF.get();
166 std::promise<MSVCPExpected<std::unique_ptr<InFlightAlloc>>> AllocResultP;
167 auto AllocResultF = AllocResultP.get_future();
169 AllocResultP.set_value(std::move(
Alloc));
171 return AllocResultF.get();
183 std::vector<FinalizedAlloc> Allocs;
184 Allocs.push_back(std::move(
Alloc));
185 deallocate(std::move(Allocs), std::move(OnDeallocated));
190 std::promise<MSVCPError> DeallocResultP;
191 auto DeallocResultF = DeallocResultP.get_future();
193 [&](
Error Err) { DeallocResultP.set_value(std::move(Err)); });
194 return DeallocResultF.get();
199 std::vector<FinalizedAlloc> Allocs;
200 Allocs.push_back(std::move(
Alloc));
228 NextWorkingMemOffset(0) {}
236 size_t NextWorkingMemOffset;
237 std::vector<Block *> ContentBlocks, ZeroFillBlocks;
273 return {Segments.
begin(), Segments.
end()};
325 std::shared_ptr<orc::SymbolStringPool> SSP,
331 std::shared_ptr<orc::SymbolStringPool> SSP,
const JITLinkDylib *JD,
343 Alloc->finalize(std::move(OnFinalized));
348 return Alloc->finalize();
353 std::unique_ptr<LinkGraph> G,
355 std::unique_ptr<JITLinkMemoryManager::InFlightAlloc> Alloc);
357 std::unique_ptr<LinkGraph> G;
359 std::unique_ptr<JITLinkMemoryManager::InFlightAlloc> Alloc;
390 struct FinalizedAllocInfo {
392 std::vector<orc::shared::WrapperFunctionCall> DeallocActions;
395 FinalizedAlloc createFinalizedAlloc(
397 std::vector<orc::shared::WrapperFunctionCall> DeallocActions);
400 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, std::shared_ptr< orc::SymbolStringPool > SSP, 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.
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.
Describes the segment working memory and executor address.
MutableArrayRef< char > WorkingMem
Describes a segment to be allocated.
Segment(size_t ContentSize, Align ContentAlign)