LLVM: lib/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManager.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
10
13
14#include
15
17
18namespace llvm {
19namespace orc {
20
23public:
24
25
26
27
28
37
39
42 : Parent(Parent), G(G), AllocAddr(AllocAddr), Segs(std::move(Segs)) {}
43
46 for (auto &KV : Segs) {
47 assert(KV.second.ContentSize <= std::numeric_limits<size_t>::max());
49 KV.first,
50 KV.second.Addr,
51 alignTo(KV.second.ContentSize + KV.second.ZeroFillSize,
52 Parent.EPC.getPageSize()),
53 {KV.second.WorkingMem, static_cast<size_t>(KV.second.ContentSize)}});
54 }
55
56
58
59 Parent.EPC.callSPSWrapperAsync<
61 Parent.SAs.Initialize,
62 [OnFinalize = std::move(OnFinalize), AllocAddr = this->AllocAddr](
63 Error SerializationErr,
65
66 if (SerializationErr) {
67 cantFail(InitializeKey.takeError());
68 OnFinalize(std::move(SerializationErr));
69 } else if (!InitializeKey)
70 OnFinalize(InitializeKey.takeError());
71 else
73 },
74 Parent.SAs.Allocator, std::move(FR));
75 }
76
78
79 Parent.EPC.callSPSWrapperAsync<
81 Parent.SAs.Release,
82 [OnAbandoned = std::move(OnAbandoned)](Error SerializationErr,
83 Error DeallocateErr) mutable {
84 if (SerializationErr) {
85 cantFail(std::move(DeallocateErr));
86 OnAbandoned(std::move(SerializationErr));
87 } else
88 OnAbandoned(std::move(DeallocateErr));
89 },
91 }
92
93private:
98};
99
104
106 if (!Pages)
107 return OnAllocated(Pages.takeError());
108
110 SAs.Reserve,
111 [this, BL = std::move(BL), OnAllocated = std::move(OnAllocated)](
113 if (SerializationErr) {
114 cantFail(AllocAddr.takeError());
115 return OnAllocated(std::move(SerializationErr));
116 }
117 if (!AllocAddr)
118 return OnAllocated(AllocAddr.takeError());
119
120 completeAllocation(*AllocAddr, std::move(BL), std::move(OnAllocated));
121 },
122 SAs.Allocator, Pages->total());
123}
124
128 SAs.Release,
129 [OnDeallocated = std::move(OnDeallocated)](Error SerErr,
130 Error DeallocErr) mutable {
131 if (SerErr) {
132 cantFail(std::move(DeallocErr));
133 OnDeallocated(std::move(SerErr));
134 } else
135 OnDeallocated(std::move(DeallocErr));
136 },
137 SAs.Allocator, Allocs);
138 for (auto &A : Allocs)
139 A.release();
140}
141
142void EPCGenericJITLinkMemoryManager::completeAllocation(
144
146
148 for (auto &KV : BL.segments()) {
149 const auto &AG = KV.first;
150 auto &Seg = KV.second;
151
152 Seg.Addr = NextSegAddr;
156
157 auto &SegInfo = SegInfos[AG];
158 SegInfo.ContentSize = Seg.ContentSize;
159 SegInfo.ZeroFillSize = Seg.ZeroFillSize;
160 SegInfo.Addr = Seg.Addr;
161 SegInfo.WorkingMem = Seg.WorkingMem;
162 }
163
164 if (auto Err = BL.apply())
165 return OnAllocated(std::move(Err));
166
167 OnAllocated(std::make_unique(*this, BL.getGraph(), AllocAddr,
168 std::move(SegInfos)));
169}
170
171}
172}
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.
Definition EPCGenericJITLinkMemoryManager.cpp:44
void abandon(OnAbandonedFunction OnAbandoned) override
Called prior to finalization if the allocation should be abandoned.
Definition EPCGenericJITLinkMemoryManager.cpp:77
InFlightAlloc(EPCGenericJITLinkMemoryManager &Parent, LinkGraph &G, ExecutorAddr AllocAddr, SegInfoMap Segs)
Definition EPCGenericJITLinkMemoryManager.cpp:40
AllocGroupSmallMap< SegInfo > SegInfoMap
Definition EPCGenericJITLinkMemoryManager.cpp:38
void deallocate(std::vector< FinalizedAlloc > Allocs, OnDeallocatedFunction OnDeallocated) override
Deallocate a list of allocation objects.
Definition EPCGenericJITLinkMemoryManager.cpp:125
void allocate(const jitlink::JITLinkDylib *JD, jitlink::LinkGraph &G, OnAllocatedFunction OnAllocated) override
Start the allocation process.
Definition EPCGenericJITLinkMemoryManager.cpp:100
EPCGenericJITLinkMemoryManager(ExecutorProcessControl &EPC, SymbolAddrs SAs)
Create an EPCGenericJITLinkMemoryManager instance from a given set of function addrs.
Represents an address in the executor process.
unsigned getPageSize() const
Get the page size for the target process.
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
uint64_t ExecutorAddrDiff
This is an optimization pass for GlobalISel generic memory operations.
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
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.
SegInfo()
Definition EPCGenericJITLinkMemoryManager.cpp:30
ExecutorAddr Addr
Definition EPCGenericJITLinkMemoryManager.cpp:33
uint64_t ZeroFillSize
Definition EPCGenericJITLinkMemoryManager.cpp:35
char * WorkingMem
Definition EPCGenericJITLinkMemoryManager.cpp:32
uint64_t ContentSize
Definition EPCGenericJITLinkMemoryManager.cpp:34
std::vector< SegFinalizeRequest > Segments
shared::AllocActions Actions