25 std::vector<MemoryMapper::AllocInfo::SegInfo> Segs)
26 : Parent(Parent),
G(
G), AllocAddr(AllocAddr), Segs(
std::
move(Segs)) {}
35 Parent.Mapper->initialize(AI, [OnFinalize = std::move(OnFinalize)](
38 OnFinalize(
Result.takeError());
47 Parent.Mapper->release({AllocAddr}, std::move(OnFinalize));
54 std::vector<MemoryMapper::AllocInfo::SegInfo> Segs;
58 size_t ReservationGranularity, std::unique_ptr<MemoryMapper> Mapper)
59 : ReservationUnits(ReservationGranularity), AvailableMemory(AMAllocator),
67 auto SegsSizes = BL.getContiguousPageBasedLayoutSizes(Mapper->getPageSize());
69 OnAllocated(SegsSizes.takeError());
73 auto TotalSize = SegsSizes->total();
75 auto CompleteAllocation = [
this, &
G, BL = std::move(BL),
76 OnAllocated = std::move(OnAllocated)](
80 return OnAllocated(
Result.takeError());
83 auto NextSegAddr =
Result->Start;
85 std::vector<MemoryMapper::AllocInfo::SegInfo> SegInfos;
87 for (
auto &KV : BL.segments()) {
89 auto &Seg = KV.second;
91 auto TotalSize = Seg.ContentSize + Seg.ZeroFillSize;
93 Seg.Addr = NextSegAddr;
94 Seg.WorkingMem = Mapper->prepare(NextSegAddr, TotalSize);
96 NextSegAddr +=
alignTo(TotalSize, Mapper->getPageSize());
99 SI.Offset = Seg.Addr -
Result->Start;
100 SI.ContentSize = Seg.ContentSize;
101 SI.ZeroFillSize = Seg.ZeroFillSize;
103 SI.WorkingMem = Seg.WorkingMem;
105 SegInfos.push_back(SI);
108 UsedMemory.insert({
Result->Start, NextSegAddr -
Result->Start});
110 if (NextSegAddr < Result->
End) {
112 AvailableMemory.insert(NextSegAddr,
Result->End - 1,
true);
116 if (
auto Err = BL.apply()) {
117 OnAllocated(std::move(Err));
121 OnAllocated(std::make_unique<InFlightAlloc>(*
this,
G,
Result->Start,
122 std::move(SegInfos)));
131 It != AvailableMemory.end(); It++) {
132 if (It.stop() - It.start() + 1 >= TotalSize) {
139 if (SelectedRange.empty()) {
140 auto TotalAllocation =
alignTo(TotalSize, ReservationUnits);
141 Mapper->reserve(TotalAllocation, std::move(CompleteAllocation));
143 CompleteAllocation(SelectedRange);
149 std::vector<ExecutorAddr> Bases;
150 Bases.reserve(Allocs.size());
151 for (
auto &FA : Allocs) {
153 Bases.push_back(
Addr);
156 Mapper->deinitialize(Bases, [
this, Allocs = std::move(Allocs),
157 OnDeallocated = std::move(OnDeallocated)](
164 for (
auto &FA : Allocs)
166 OnDeallocated(std::move(Err));
171 std::lock_guard<std::mutex> Lock(
Mutex);
173 for (
auto &FA : Allocs) {
177 UsedMemory.erase(
Addr);
Provides a library for accessing information about this process and other processes on the operating ...
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
BasicLayout simplifies the implementation of JITLinkMemoryManagers.
Represents a finalized allocation.
Represents an allocation which has not been finalized yet.
orc::shared::AllocActions & allocActions()
Accessor for the AllocActions object for this graph.
Represents an address in the executor process.
InFlightAlloc(MapperJITLinkMemoryManager &Parent, LinkGraph &G, ExecutorAddr AllocAddr, std::vector< MemoryMapper::AllocInfo::SegInfo > Segs)
void finalize(OnFinalizedFunction OnFinalize) override
Called to transfer working memory to the target and apply finalization.
void abandon(OnAbandonedFunction OnFinalize) override
Called prior to finalization if the allocation should be abandoned.
void deallocate(std::vector< FinalizedAlloc > Allocs, OnDeallocatedFunction OnDeallocated) override
Deallocate a list of allocation objects.
MapperJITLinkMemoryManager(size_t ReservationGranularity, std::unique_ptr< MemoryMapper > Mapper)
void allocate(const jitlink::JITLinkDylib *JD, jitlink::LinkGraph &G, OnAllocatedFunction OnAllocated) override
Start the allocation process.
unique_function is a type-erasing functor similar to std::function.
This is an optimization pass for GlobalISel generic memory operations.
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.
Represents an address range in the exceutor process.
Represents a single allocation containing multiple segments and initialization and deinitialization a...
std::vector< SegInfo > Segments
shared::AllocActions Actions