24 std::vector<MemoryMapper::AllocInfo::SegInfo> Segs)
25 : Parent(Parent),
G(
G), AllocAddr(AllocAddr), Segs(
std::
move(Segs)) {}
34 Parent.Mapper->initialize(AI, [OnFinalize = std::move(OnFinalize)](
37 OnFinalize(
Result.takeError());
46 Parent.Mapper->release({AllocAddr}, std::move(OnFinalize));
53 std::vector<MemoryMapper::AllocInfo::SegInfo> Segs;
57 size_t ReservationGranularity, std::unique_ptr<MemoryMapper> Mapper)
58 : ReservationUnits(ReservationGranularity), AvailableMemory(AMAllocator),
66 auto SegsSizes = BL.getContiguousPageBasedLayoutSizes(Mapper->getPageSize());
68 OnAllocated(SegsSizes.takeError());
72 auto TotalSize = SegsSizes->total();
74 auto CompleteAllocation = [
this, &
G, BL = std::move(BL),
75 OnAllocated = std::move(OnAllocated)](
79 return OnAllocated(
Result.takeError());
82 auto NextSegAddr =
Result->Start;
84 std::vector<MemoryMapper::AllocInfo::SegInfo> SegInfos;
86 for (
auto &KV : BL.segments()) {
88 auto &Seg = KV.second;
90 auto TotalSize = Seg.ContentSize + Seg.ZeroFillSize;
92 Seg.Addr = NextSegAddr;
93 Seg.WorkingMem = Mapper->prepare(NextSegAddr, TotalSize);
95 NextSegAddr +=
alignTo(TotalSize, Mapper->getPageSize());
98 SI.Offset = Seg.Addr -
Result->Start;
99 SI.ContentSize = Seg.ContentSize;
100 SI.ZeroFillSize = Seg.ZeroFillSize;
102 SI.WorkingMem = Seg.WorkingMem;
104 SegInfos.push_back(SI);
107 UsedMemory.insert({
Result->Start, NextSegAddr -
Result->Start});
109 if (NextSegAddr < Result->
End) {
111 AvailableMemory.insert(NextSegAddr,
Result->End - 1,
true);
115 if (
auto Err = BL.apply()) {
116 OnAllocated(std::move(Err));
120 OnAllocated(std::make_unique<InFlightAlloc>(*
this,
G,
Result->Start,
121 std::move(SegInfos)));
130 It != AvailableMemory.end(); It++) {
131 if (It.stop() - It.start() + 1 >= TotalSize) {
138 if (SelectedRange.empty()) {
139 auto TotalAllocation =
alignTo(TotalSize, ReservationUnits);
140 Mapper->reserve(TotalAllocation, std::move(CompleteAllocation));
142 CompleteAllocation(SelectedRange);
148 std::vector<ExecutorAddr> Bases;
149 Bases.reserve(Allocs.size());
150 for (
auto &FA : Allocs) {
152 Bases.push_back(
Addr);
155 Mapper->deinitialize(Bases, [
this, Allocs = std::move(Allocs),
156 OnDeallocated = std::move(OnDeallocated)](
163 for (
auto &FA : Allocs)
165 OnDeallocated(std::move(Err));
170 std::lock_guard<std::mutex> Lock(
Mutex);
172 for (
auto &FA : Allocs) {
176 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