24 "orc_rt_SimpleNativeMemoryMap_Instance",
25 "orc_rt_SimpleNativeMemoryMap_reserve_sps_wrapper",
26 "orc_rt_SimpleNativeMemoryMap_initialize_sps_wrapper",
27 "orc_rt_SimpleNativeMemoryMap_deinitializeMultiple_sps_wrapper",
28 "orc_rt_SimpleNativeMemoryMap_releaseMultiple_sps_wrapper",
52 : Parent(Parent), G(G), AllocAddr(AllocAddr), Segs(
std::
move(Segs)) {}
56 for (
auto &KV : Segs) {
57 assert(KV.second.ContentSize <= std::numeric_limits<size_t>::max());
61 alignTo(KV.second.ContentSize + KV.second.ZeroFillSize,
62 Parent.EPC.getPageSize()),
63 {KV.second.WorkingMem,
static_cast<size_t>(KV.second.ContentSize)}});
69 Parent.EPC.callSPSWrapperAsync<
71 Parent.SAs.Initialize,
72 [OnFinalize = std::move(OnFinalize), AllocAddr = this->AllocAddr](
73 Error SerializationErr,
76 if (SerializationErr) {
78 OnFinalize(std::move(SerializationErr));
79 }
else if (!InitializeKey)
80 OnFinalize(InitializeKey.takeError());
84 Parent.SAs.Allocator, std::move(FR));
89 Parent.EPC.callSPSWrapperAsync<
92 [OnAbandoned = std::move(OnAbandoned)](
Error SerializationErr,
93 Error DeallocateErr)
mutable {
94 if (SerializationErr) {
96 OnAbandoned(std::move(SerializationErr));
98 OnAbandoned(std::move(DeallocateErr));
124 return std::make_unique<EPCGenericJITLinkMemoryManager>(
125 ES.getExecutorProcessControl(), SAs);
140 return OnAllocated(Pages.takeError());
144 [
this, BL = std::move(BL), OnAllocated = std::move(OnAllocated)](
146 if (SerializationErr) {
148 return OnAllocated(std::move(SerializationErr));
151 return OnAllocated(AllocAddr.takeError());
153 completeAllocation(*AllocAddr, std::move(BL), std::move(OnAllocated));
155 SAs.Allocator, Pages->total());
162 [OnDeallocated = std::move(OnDeallocated)](
Error SerErr,
163 Error DeallocErr)
mutable {
166 OnDeallocated(std::move(SerErr));
168 OnDeallocated(std::move(DeallocErr));
170 SAs.Allocator, Allocs);
171 for (
auto &
A : Allocs)
175void EPCGenericJITLinkMemoryManager::completeAllocation(
182 const auto &AG = KV.first;
183 auto &Seg = KV.second;
185 Seg.Addr = NextSegAddr;
190 auto &SegInfo = SegInfos[AG];
191 SegInfo.ContentSize = Seg.ContentSize;
192 SegInfo.ZeroFillSize = Seg.ZeroFillSize;
193 SegInfo.Addr = Seg.Addr;
194 SegInfo.WorkingMem = Seg.WorkingMem;
197 if (
auto Err = BL.
apply())
198 return OnAllocated(std::move(Err));
200 OnAllocated(std::make_unique<InFlightAlloc>(*
this, BL.
getGraph(), AllocAddr,
201 std::move(SegInfos)));
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
Lightweight error class with error context and mandatory checking.
Tagged union holding either a T or a 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 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
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.
EPCGenericJITLinkMemoryManager(ExecutorProcessControl &EPC, SymbolAddrs SAs)
Create an EPCGenericJITLinkMemoryManager instance from a given set of function addrs.
static const SymbolNames orc_rt_SimpleNativeMemoryMapSPSSymbols
Default symbol names for the ORC runtime's SimpleNativeMemoryMap SPS interface.
static Expected< std::unique_ptr< EPCGenericJITLinkMemoryManager > > Create(JITDylib &JD, SymbolNames SNs=orc_rt_SimpleNativeMemoryMapSPSSymbols)
Create an EPCGenericJITLinkMemoryManager using the given implementation symbol names.
An ExecutionSession represents a running JIT program.
JITDylib & getBootstrapJITDylib()
Returns a reference to the bootstrap JITDylib.
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.
shared::SPSExpected< shared::SPSExecutorAddr >(shared::SPSExecutorAddr, uint64_t) SPSSimpleExecutorMemoryManagerReserveSignature
shared::SPSExpected< shared::SPSExecutorAddr >(shared::SPSExecutorAddr, shared::SPSFinalizeRequest) SPSSimpleExecutorMemoryManagerInitializeSignature
shared::SPSError( shared::SPSExecutorAddr, shared::SPSSequence< shared::SPSExecutorAddr >) SPSSimpleExecutorMemoryManagerReleaseSignature
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.
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
ArrayRef(const T &OneElt) -> ArrayRef< T >
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.
Symbol addresses for memory management implementation.
Symbol names for memory management implementation.
StringRef DeinitializeName
std::vector< SegFinalizeRequest > Segments
shared::AllocActions Actions