Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ class LLVM_ABI EPCGenericJITLinkMemoryManager
struct SymbolAddrs {
ExecutorAddr Allocator;
ExecutorAddr Reserve;
ExecutorAddr Finalize;
ExecutorAddr Deallocate;
ExecutorAddr Initialize;
ExecutorAddr Deinitialize;
ExecutorAddr Release;
};

/// Create an EPCGenericJITLinkMemoryManager instance from a given set of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class LLVM_ABI EPCGenericRTDyldMemoryManager
struct SymbolAddrs {
ExecutorAddr Instance;
ExecutorAddr Reserve;
ExecutorAddr Finalize;
ExecutorAddr Deallocate;
ExecutorAddr Initialize;
ExecutorAddr Release;
ExecutorAddr RegisterEHFrame;
ExecutorAddr DeregisterEHFrame;
};
Expand Down
26 changes: 21 additions & 5 deletions llvm/include/llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ LLVM_ABI extern const char *SimpleExecutorDylibManagerResolveWrapperName;

LLVM_ABI extern const char *SimpleExecutorMemoryManagerInstanceName;
LLVM_ABI extern const char *SimpleExecutorMemoryManagerReserveWrapperName;
LLVM_ABI extern const char *SimpleExecutorMemoryManagerFinalizeWrapperName;
LLVM_ABI extern const char *SimpleExecutorMemoryManagerDeallocateWrapperName;
LLVM_ABI extern const char *SimpleExecutorMemoryManagerInitializeWrapperName;
LLVM_ABI extern const char *SimpleExecutorMemoryManagerDeinitializeWrapperName;
LLVM_ABI extern const char *SimpleExecutorMemoryManagerReleaseWrapperName;

LLVM_ABI extern const char *ExecutorSharedMemoryMapperServiceInstanceName;
LLVM_ABI extern const char *ExecutorSharedMemoryMapperServiceReserveWrapperName;
Expand Down Expand Up @@ -73,9 +74,12 @@ using SPSSimpleExecutorDylibManagerResolveSignature = shared::SPSExpected<
using SPSSimpleExecutorMemoryManagerReserveSignature =
shared::SPSExpected<shared::SPSExecutorAddr>(shared::SPSExecutorAddr,
uint64_t);
using SPSSimpleExecutorMemoryManagerFinalizeSignature =
shared::SPSError(shared::SPSExecutorAddr, shared::SPSFinalizeRequest);
using SPSSimpleExecutorMemoryManagerDeallocateSignature = shared::SPSError(
using SPSSimpleExecutorMemoryManagerInitializeSignature =
shared::SPSExpected<shared::SPSExecutorAddr>(shared::SPSExecutorAddr,
shared::SPSFinalizeRequest);
using SPSSimpleExecutorMemoryManagerDeinitializeSignature = shared::SPSError(
shared::SPSExecutorAddr, shared::SPSSequence<shared::SPSExecutorAddr>);
using SPSSimpleExecutorMemoryManagerReleaseSignature = shared::SPSError(
shared::SPSExecutorAddr, shared::SPSSequence<shared::SPSExecutorAddr>);

// ExecutorSharedMemoryMapperService
Expand All @@ -93,6 +97,18 @@ using SPSExecutorSharedMemoryMapperServiceDeinitializeSignature =
using SPSExecutorSharedMemoryMapperServiceReleaseSignature = shared::SPSError(
shared::SPSExecutorAddr, shared::SPSSequence<shared::SPSExecutorAddr>);

// SimpleNativeMemoryMap APIs.
using SPSSimpleRemoteMemoryMapReserveSignature =
shared::SPSExpected<shared::SPSExecutorAddr>(shared::SPSExecutorAddr,
uint64_t);
using SPSSimpleRemoteMemoryMapInitializeSignature =
shared::SPSExpected<shared::SPSExecutorAddr>(shared::SPSExecutorAddr,
shared::SPSFinalizeRequest);
using SPSSimpleRemoteMemoryMapDeinitializeSignature = shared::SPSError(
shared::SPSExecutorAddr, shared::SPSSequence<shared::SPSExecutorAddr>);
using SPSSimpleRemoteMemoryMapReleaseSignature = shared::SPSError(
shared::SPSExecutorAddr, shared::SPSSequence<shared::SPSExecutorAddr>);

using SPSRunAsMainSignature = int64_t(shared::SPSExecutorAddr,
shared::SPSSequence<shared::SPSString>);
using SPSRunAsVoidFunctionSignature = int32_t(shared::SPSExecutorAddr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,34 +34,65 @@ class LLVM_ABI SimpleExecutorMemoryManager : public ExecutorBootstrapService {
public:
virtual ~SimpleExecutorMemoryManager();

Expected<ExecutorAddr> allocate(uint64_t Size);
Error finalize(tpctypes::FinalizeRequest &FR);
Error deallocate(const std::vector<ExecutorAddr> &Bases);
Expected<ExecutorAddr> reserve(uint64_t Size);
Expected<ExecutorAddr> initialize(tpctypes::FinalizeRequest &FR);
Error deinitialize(const std::vector<ExecutorAddr> &InitKeys);
Error release(const std::vector<ExecutorAddr> &Bases);

Error shutdown() override;
void addBootstrapSymbols(StringMap<ExecutorAddr> &M) override;

private:
struct Allocation {
struct RegionInfo {
size_t Size = 0;
std::vector<shared::WrapperFunctionCall> DeallocationActions;
std::vector<shared::WrapperFunctionCall> DeallocActions;
};

using AllocationsMap = DenseMap<void *, Allocation>;
struct SlabInfo {
using RegionMap = std::map<ExecutorAddr, RegionInfo>;
size_t Size = 0;
RegionMap Regions;
};

using SlabMap = std::map<void *, SlabInfo>;

/// Get a reference to the slab information for the slab containing the given
/// address.
Expected<SlabInfo &> getSlabInfo(ExecutorAddr A, StringRef Context);

/// Get a reference to the slab information for the slab *covering* the given
/// range. The given range must be a subrange of e(possibly equal to) the
/// range of the slab itself.
Expected<SlabInfo &> getSlabInfo(ExecutorAddrRange R, StringRef Context);

Error deallocateImpl(void *Base, Allocation &A);
/// Create a RegionInfo for the given range, which must not overlap any
/// existing region.
Expected<RegionInfo &> createRegionInfo(ExecutorAddrRange R,
StringRef Context);

/// Get a reference to the region information for the given address. This
/// address must represent the start of an existing initialized region.
Expected<RegionInfo &> getRegionInfo(SlabInfo &Slab, ExecutorAddr A,
StringRef Context);

/// Get a reference to the region information for the given address. This
/// address must represent the start of an existing initialized region.
Expected<RegionInfo &> getRegionInfo(ExecutorAddr A, StringRef Context);

static llvm::orc::shared::CWrapperFunctionResult
reserveWrapper(const char *ArgData, size_t ArgSize);

static llvm::orc::shared::CWrapperFunctionResult
finalizeWrapper(const char *ArgData, size_t ArgSize);
initializeWrapper(const char *ArgData, size_t ArgSize);

static llvm::orc::shared::CWrapperFunctionResult
deinitializeWrapper(const char *ArgData, size_t ArgSize);

static llvm::orc::shared::CWrapperFunctionResult
deallocateWrapper(const char *ArgData, size_t ArgSize);
releaseWrapper(const char *ArgData, size_t ArgSize);

std::mutex M;
AllocationsMap Allocations;
SlabMap Slabs;
};

} // end namespace rt_bootstrap
Expand Down
22 changes: 11 additions & 11 deletions llvm/lib/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,17 @@ class EPCGenericJITLinkMemoryManager::InFlightAlloc
std::swap(FR.Actions, G.allocActions());

Parent.EPC.callSPSWrapperAsync<
rt::SPSSimpleExecutorMemoryManagerFinalizeSignature>(
Parent.SAs.Finalize,
rt::SPSSimpleExecutorMemoryManagerInitializeSignature>(
Parent.SAs.Initialize,
[OnFinalize = std::move(OnFinalize), AllocAddr = this->AllocAddr](
Error SerializationErr, Error FinalizeErr) mutable {
Error SerializationErr,
Expected<ExecutorAddr> InitializeKey) mutable {
// FIXME: Release abandoned alloc.
if (SerializationErr) {
cantFail(std::move(FinalizeErr));
cantFail(InitializeKey.takeError());
OnFinalize(std::move(SerializationErr));
} else if (FinalizeErr)
OnFinalize(std::move(FinalizeErr));
} else if (!InitializeKey)
OnFinalize(InitializeKey.takeError());
else
OnFinalize(FinalizedAlloc(AllocAddr));
},
Expand All @@ -76,8 +77,8 @@ class EPCGenericJITLinkMemoryManager::InFlightAlloc
void abandon(OnAbandonedFunction OnAbandoned) override {
// FIXME: Return memory to pool instead.
Parent.EPC.callSPSWrapperAsync<
rt::SPSSimpleExecutorMemoryManagerDeallocateSignature>(
Parent.SAs.Deallocate,
rt::SPSSimpleExecutorMemoryManagerReleaseSignature>(
Parent.SAs.Release,
[OnAbandoned = std::move(OnAbandoned)](Error SerializationErr,
Error DeallocateErr) mutable {
if (SerializationErr) {
Expand Down Expand Up @@ -123,9 +124,8 @@ void EPCGenericJITLinkMemoryManager::allocate(const JITLinkDylib *JD,

void EPCGenericJITLinkMemoryManager::deallocate(
std::vector<FinalizedAlloc> Allocs, OnDeallocatedFunction OnDeallocated) {
EPC.callSPSWrapperAsync<
rt::SPSSimpleExecutorMemoryManagerDeallocateSignature>(
SAs.Deallocate,
EPC.callSPSWrapperAsync<rt::SPSSimpleExecutorMemoryManagerReleaseSignature>(
SAs.Release,
[OnDeallocated = std::move(OnDeallocated)](Error SerErr,
Error DeallocErr) mutable {
if (SerErr) {
Expand Down
18 changes: 9 additions & 9 deletions llvm/lib/ExecutionEngine/Orc/EPCGenericRTDyldMemoryManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ EPCGenericRTDyldMemoryManager::CreateWithDefaultBootstrapSymbols(
if (auto Err = EPC.getBootstrapSymbols(
{{SAs.Instance, rt::SimpleExecutorMemoryManagerInstanceName},
{SAs.Reserve, rt::SimpleExecutorMemoryManagerReserveWrapperName},
{SAs.Finalize, rt::SimpleExecutorMemoryManagerFinalizeWrapperName},
{SAs.Deallocate,
rt::SimpleExecutorMemoryManagerDeallocateWrapperName},
{SAs.Initialize,
rt::SimpleExecutorMemoryManagerInitializeWrapperName},
{SAs.Release, rt::SimpleExecutorMemoryManagerReleaseWrapperName},
{SAs.RegisterEHFrame, rt::RegisterEHFrameSectionAllocActionName},
{SAs.DeregisterEHFrame,
rt::DeregisterEHFrameSectionAllocActionName}}))
Expand All @@ -48,7 +48,7 @@ EPCGenericRTDyldMemoryManager::~EPCGenericRTDyldMemoryManager() {

Error Err = Error::success();
if (auto Err2 = EPC.callSPSWrapper<
rt::SPSSimpleExecutorMemoryManagerDeallocateSignature>(
rt::SPSSimpleExecutorMemoryManagerReleaseSignature>(
SAs.Reserve, Err, SAs.Instance, FinalizedAllocs)) {
// FIXME: Report errors through EPC once that functionality is available.
logAllUnhandledErrors(std::move(Err2), errs(), "");
Expand Down Expand Up @@ -267,20 +267,20 @@ bool EPCGenericRTDyldMemoryManager::finalizeMemory(std::string *ErrMsg) {

// We'll also need to make an extra allocation for the eh-frame wrapper call
// arguments.
Error FinalizeErr = Error::success();
Expected<ExecutorAddr> InitializeKey((ExecutorAddr()));
if (auto Err = EPC.callSPSWrapper<
rt::SPSSimpleExecutorMemoryManagerFinalizeSignature>(
SAs.Finalize, FinalizeErr, SAs.Instance, std::move(FR))) {
rt::SPSSimpleExecutorMemoryManagerInitializeSignature>(
SAs.Initialize, InitializeKey, SAs.Instance, std::move(FR))) {
std::lock_guard<std::mutex> Lock(M);
this->ErrMsg = toString(std::move(Err));
dbgs() << "Serialization error: " << this->ErrMsg << "\n";
if (ErrMsg)
*ErrMsg = this->ErrMsg;
return true;
}
if (FinalizeErr) {
if (!InitializeKey) {
std::lock_guard<std::mutex> Lock(M);
this->ErrMsg = toString(std::move(FinalizeErr));
this->ErrMsg = toString(InitializeKey.takeError());
dbgs() << "Finalization error: " << this->ErrMsg << "\n";
if (ErrMsg)
*ErrMsg = this->ErrMsg;
Expand Down
10 changes: 6 additions & 4 deletions llvm/lib/ExecutionEngine/Orc/Shared/OrcRTBridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ const char *SimpleExecutorMemoryManagerInstanceName =
"__llvm_orc_SimpleExecutorMemoryManager_Instance";
const char *SimpleExecutorMemoryManagerReserveWrapperName =
"__llvm_orc_SimpleExecutorMemoryManager_reserve_wrapper";
const char *SimpleExecutorMemoryManagerFinalizeWrapperName =
"__llvm_orc_SimpleExecutorMemoryManager_finalize_wrapper";
const char *SimpleExecutorMemoryManagerDeallocateWrapperName =
"__llvm_orc_SimpleExecutorMemoryManager_deallocate_wrapper";
const char *SimpleExecutorMemoryManagerInitializeWrapperName =
"__llvm_orc_SimpleExecutorMemoryManager_initialize_wrapper";
const char *SimpleExecutorMemoryManagerDeinitializeWrapperName =
"__llvm_orc_SimpleExecutorMemoryManager_deinitialize_wrapper";
const char *SimpleExecutorMemoryManagerReleaseWrapperName =
"__llvm_orc_SimpleExecutorMemoryManager_release_wrapper";

const char *ExecutorSharedMemoryMapperServiceInstanceName =
"__llvm_orc_ExecutorSharedMemoryMapperService_Instance";
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/ExecutionEngine/Orc/SimpleRemoteEPC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ SimpleRemoteEPC::createDefaultMemoryManager(SimpleRemoteEPC &SREPC) {
if (auto Err = SREPC.getBootstrapSymbols(
{{SAs.Allocator, rt::SimpleExecutorMemoryManagerInstanceName},
{SAs.Reserve, rt::SimpleExecutorMemoryManagerReserveWrapperName},
{SAs.Finalize, rt::SimpleExecutorMemoryManagerFinalizeWrapperName},
{SAs.Deallocate,
rt::SimpleExecutorMemoryManagerDeallocateWrapperName}}))
{SAs.Initialize,
rt::SimpleExecutorMemoryManagerInitializeWrapperName},
{SAs.Release, rt::SimpleExecutorMemoryManagerReleaseWrapperName}}))
return std::move(Err);

return std::make_unique<EPCGenericJITLinkMemoryManager>(SREPC, SAs);
Expand Down
Loading