Files
clang-p2996/llvm/lib/ExecutionEngine/Orc/TargetProcess/OrcRTBootstrap.cpp
Lang Hames 78b083dbb7 [ORC] Add finalization & deallocation actions, SimpleExecutorMemoryManager class
Finalization and deallocation actions are a key part of the upcoming
JITLinkMemoryManager redesign: They generalize the existing finalization and
deallocate concepts (basically "copy-and-mprotect", and "munmap") to include
support for arbitrary registration and deregistration of parts of JIT linked
code. This allows us to register and deregister eh-frames, TLV sections,
language metadata, etc. using regular memory management calls with no additional
IPC/RPC overhead, which should both improve JIT performance and simplify
interactions between ORC and the ORC runtime.

The SimpleExecutorMemoryManager class provides executor-side support for memory
management operations, including finalization and deallocation actions.

This support is being added in advance of the rest of the memory manager
redesign as it will simplify the introduction of an EPC based
RuntimeDyld::MemoryManager (since eh-frame registration/deregistration will be
expressible as actions). The new RuntimeDyld::MemoryManager will in turn allow
us to remove older remote allocators that are blocking the rest of the memory
manager changes.
2021-09-17 09:55:45 +10:00

80 lines
3.0 KiB
C++

//===------------------------ OrcRTBootstrap.cpp --------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "OrcRTBootstrap.h"
#include "llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h"
#include "llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h"
#include "llvm/ExecutionEngine/Orc/TargetProcess/TargetExecutionUtils.h"
#define DEBUG_TYPE "orc"
using namespace llvm::orc::shared;
namespace llvm {
namespace orc {
namespace rt_bootstrap {
template <typename WriteT, typename SPSWriteT>
static llvm::orc::shared::detail::CWrapperFunctionResult
writeUIntsWrapper(const char *ArgData, size_t ArgSize) {
return WrapperFunction<void(SPSSequence<SPSWriteT>)>::handle(
ArgData, ArgSize,
[](std::vector<WriteT> Ws) {
for (auto &W : Ws)
*jitTargetAddressToPointer<decltype(W.Value) *>(W.Address) =
W.Value;
})
.release();
}
static llvm::orc::shared::detail::CWrapperFunctionResult
writeBuffersWrapper(const char *ArgData, size_t ArgSize) {
return WrapperFunction<void(SPSSequence<SPSMemoryAccessBufferWrite>)>::handle(
ArgData, ArgSize,
[](std::vector<tpctypes::BufferWrite> Ws) {
for (auto &W : Ws)
memcpy(jitTargetAddressToPointer<char *>(W.Address),
W.Buffer.data(), W.Buffer.size());
})
.release();
}
static llvm::orc::shared::detail::CWrapperFunctionResult
runAsMainWrapper(const char *ArgData, size_t ArgSize) {
return WrapperFunction<rt::SPSRunAsMainSignature>::handle(
ArgData, ArgSize,
[](ExecutorAddress MainAddr,
std::vector<std::string> Args) -> int64_t {
return runAsMain(MainAddr.toPtr<int (*)(int, char *[])>(), Args);
})
.release();
}
void addTo(StringMap<ExecutorAddress> &M) {
M[rt::MemoryWriteUInt8sWrapperName] = ExecutorAddress::fromPtr(
&writeUIntsWrapper<tpctypes::UInt8Write,
shared::SPSMemoryAccessUInt8Write>);
M[rt::MemoryWriteUInt16sWrapperName] = ExecutorAddress::fromPtr(
&writeUIntsWrapper<tpctypes::UInt16Write,
shared::SPSMemoryAccessUInt16Write>);
M[rt::MemoryWriteUInt32sWrapperName] = ExecutorAddress::fromPtr(
&writeUIntsWrapper<tpctypes::UInt32Write,
shared::SPSMemoryAccessUInt32Write>);
M[rt::MemoryWriteUInt64sWrapperName] = ExecutorAddress::fromPtr(
&writeUIntsWrapper<tpctypes::UInt64Write,
shared::SPSMemoryAccessUInt64Write>);
M[rt::MemoryWriteBuffersWrapperName] =
ExecutorAddress::fromPtr(&writeBuffersWrapper);
M[rt::RunAsMainWrapperName] = ExecutorAddress::fromPtr(&runAsMainWrapper);
}
} // end namespace rt_bootstrap
} // end namespace orc
} // end namespace llvm