41 : Parent(Parent), G(G), AllocAddr(AllocAddr), Segs(
std::
move(Segs)) {}
45 for (
auto &KV : Segs) {
46 assert(KV.second.ContentSize <= std::numeric_limits<size_t>::max());
50 alignTo(KV.second.ContentSize + KV.second.ZeroFillSize,
51 Parent.ES.getExecutorProcessControl().getPageSize()),
52 {KV.second.WorkingMem,
static_cast<size_t>(KV.second.ContentSize)}});
59 [OnFinalize = std::move(OnFinalize), AllocAddr = this->AllocAddr](
63 return OnFinalize(InitializeKey.
takeError());
66 Parent.ES, Parent.B.Instance, FR);
71 Parent.B.Release(std::move(OnAbandoned), Parent.ES, Parent.B.Instance,
88 ES.getExecutorProcessControl().getPageSize());
90 return OnAllocated(Pages.takeError());
93 [
this, BL = std::move(BL), OnAllocated = std::move(OnAllocated)](
96 return OnAllocated(AllocAddr.
takeError());
97 completeAllocation(*AllocAddr, std::move(BL), std::move(OnAllocated));
99 ES, B.Instance, Pages->total());
104 std::vector<ExecutorAddr> Bases;
105 Bases.reserve(Allocs.size());
106 for (
auto &
A : Allocs)
108 B.Release(std::move(OnDeallocated), ES, B.Instance, Bases);
109 for (
auto &
A : Allocs)
113void EPCGenericJITLinkMemoryManager::completeAllocation(
120 const auto &AG = KV.first;
121 auto &Seg = KV.second;
123 Seg.Addr = NextSegAddr;
129 auto &SegInfo = SegInfos[AG];
130 SegInfo.ContentSize = Seg.ContentSize;
131 SegInfo.ZeroFillSize = Seg.ZeroFillSize;
132 SegInfo.Addr = Seg.Addr;
133 SegInfo.WorkingMem = Seg.WorkingMem;
136 if (
auto Err = BL.
apply())
137 return OnAllocated(std::move(Err));
139 OnAllocated(std::make_unique<InFlightAlloc>(*
this, BL.
getGraph(), AllocAddr,
140 std::move(SegInfos)));
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
BasicLayout simplifies the implementation of JITLinkMemoryManagers.
LinkGraph & getGraph()
Return a reference to the graph this allocation was created from.
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.
Represents a JITDylib as seen by JITLink.
Represents a finalized allocation.
Represents an allocation which has not been finalized yet.
unique_function< void(Error)> OnAbandonedFunction
unique_function< void(Expected< FinalizedAlloc >)> OnFinalizedFunction
unique_function< void(AllocResult)> OnAllocatedFunction
Called when allocation has been completed.
unique_function< void(Error)> OnDeallocatedFunction
Called when deallocation has completed.
MutableArrayRef< char > allocateBuffer(size_t Size)
Allocate a mutable buffer of the given size using the LinkGraph's allocator.
A specialized small-map for AllocGroups.
void finalize(OnFinalizedFunction OnFinalize) override
Called to transfer working memory to the target and apply finalization.
void abandon(OnAbandonedFunction OnAbandoned) override
Called prior to finalization if the allocation should be abandoned.
InFlightAlloc(EPCGenericJITLinkMemoryManager &Parent, LinkGraph &G, ExecutorAddr AllocAddr, SegInfoMap Segs)
AllocGroupSmallMap< SegInfo > SegInfoMap
EPCGenericJITLinkMemoryManager(ExecutionSession &ES, Bindings B)
Create an EPCGenericJITLinkMemoryManager instance from a given set of memory-manager bindings.
void deallocate(std::vector< FinalizedAlloc > Allocs, OnDeallocatedFunction OnDeallocated) override
Deallocate a list of allocation objects.
void allocate(const jitlink::JITLinkDylib *JD, jitlink::LinkGraph &G, OnAllocatedFunction OnAllocated) override
Start the allocation process.
ExecutorProcessControl & getExecutorProcessControl()
Get the ExecutorProcessControl object associated with this ExecutionSession.
Represents an address in the executor process.
unsigned getPageSize() const
Get the page size for the target process.
uint64_t ExecutorAddrDiff
This is an optimization pass for GlobalISel generic memory operations.
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Implement std::hash so that hash_code can be used in STL containers.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
std::vector< SegFinalizeRequest > Segments
shared::AllocActions Actions