44 : Parent(Parent), G(G), AllocAddr(AllocAddr), Segs(
std::
move(Segs)) {}
48 for (
auto &KV : Segs) {
49 assert(KV.second.ContentSize <= std::numeric_limits<size_t>::max());
53 alignTo(KV.second.ContentSize + KV.second.ZeroFillSize,
54 Parent.ES.getExecutorProcessControl().getPageSize()),
55 {KV.second.WorkingMem,
static_cast<size_t>(KV.second.ContentSize)}});
62 [OnFinalize = std::move(OnFinalize), AllocAddr = this->AllocAddr](
66 return OnFinalize(InitializeKey.
takeError());
69 Parent.ES, Parent.B.Instance, FR);
74 Parent.B.Release(std::move(OnAbandoned), Parent.ES, Parent.B.Instance,
95 {{ES.intern(sps_ci::SimpleNativeMemoryMapInstanceName),
97 return std::move(Err);
104 return std::move(Err);
105 return std::make_unique<EPCGenericJITLinkMemoryManager>(ES, std::move(B));
110 return Create(ES.getBootstrapJITDylib());
119 ES.getExecutorProcessControl().getPageSize());
121 return OnAllocated(Pages.takeError());
124 [
this, BL = std::move(BL), OnAllocated = std::move(OnAllocated)](
127 return OnAllocated(AllocAddr.
takeError());
128 completeAllocation(*AllocAddr, std::move(BL), std::move(OnAllocated));
130 ES, B.Instance, Pages->total());
135 std::vector<ExecutorAddr> Bases;
136 Bases.reserve(Allocs.size());
137 for (
auto &
A : Allocs)
139 B.Release(std::move(OnDeallocated), ES, B.Instance, Bases);
140 for (
auto &
A : Allocs)
144void EPCGenericJITLinkMemoryManager::completeAllocation(
151 const auto &AG = KV.first;
152 auto &Seg = KV.second;
154 Seg.Addr = NextSegAddr;
160 auto &SegInfo = SegInfos[AG];
161 SegInfo.ContentSize = Seg.ContentSize;
162 SegInfo.ZeroFillSize = Seg.ZeroFillSize;
163 SegInfo.Addr = Seg.Addr;
164 SegInfo.WorkingMem = Seg.WorkingMem;
167 if (
auto Err = BL.
apply())
168 return OnAllocated(std::move(Err));
170 OnAllocated(std::make_unique<InFlightAlloc>(*
this, BL.
getGraph(), AllocAddr,
171 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.
static Expected< std::unique_ptr< EPCGenericJITLinkMemoryManager > > Create(JITDylib &JD)
Create an EPCGenericJITLinkMemoryManager for the ORC runtime's SimpleNativeMemoryMap interface,...
void allocate(const jitlink::JITLinkDylib *JD, jitlink::LinkGraph &G, OnAllocatedFunction OnAllocated) override
Start the allocation process.
An ExecutionSession represents a running JIT program.
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.
Represents a JIT'd dynamic library.
ExecutionSession & getExecutionSession() const
Get a reference to the ExecutionSession for this JITDylib.
ProxyInit< FnT > proxyInit(Proxy< FnT > *P, typename Proxy< FnT >::DispatchFn Dispatch, StringRef Name, SymbolLookupFlags LookupFlags=SymbolLookupFlags::RequiredSymbol)
Error buildProxies(JITDylib &JD)
buildProxies base case.
JITDylibSearchOrder makeJITDylibSearchOrder(ArrayRef< JITDylib * > JDs, JITDylibLookupFlags Flags=JITDylibLookupFlags::MatchExportedSymbolsOnly)
Convenience function for creating a search order from an ArrayRef of JITDylib*, all with the same fla...
uint64_t ExecutorAddrDiff
LLVM_ABI void lookupAndRecordAddrs(unique_function< void(Error)> OnRecorded, ExecutionSession &ES, LookupKind K, const JITDylibSearchOrder &SearchOrder, std::vector< std::pair< SymbolStringPtr, ExecutorAddr * > > Pairs, SymbolLookupFlags LookupFlags=SymbolLookupFlags::RequiredSymbol)
Record addresses of the given symbols in the given ExecutorAddrs.
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.
The resolved controller-side handle to an executor-side memory manager: the address of the allocator ...
std::vector< SegFinalizeRequest > Segments
shared::AllocActions Actions