[ORC] Extract MemoryAccess from ExecutorProcessControl, break up header. (#145671)
This moves the MemoryAccess interface out of the ExecutorProcessControl class and splits implementation classes InProcessMemoryManager and SelfExecutorProcessControl out of ExecutorProcessControl.h and into their own headers.
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
|
||||
#include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
|
||||
#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
|
||||
#include "llvm/ExecutionEngine/Orc/SelfExecutorProcessControl.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Shared/ExecutorSymbolDef.h"
|
||||
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
|
||||
#include "llvm/IR/DataLayout.h"
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "llvm/ExecutionEngine/Orc/IRTransformLayer.h"
|
||||
#include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
|
||||
#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
|
||||
#include "llvm/ExecutionEngine/Orc/SelfExecutorProcessControl.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Shared/ExecutorSymbolDef.h"
|
||||
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
|
||||
#include "llvm/IR/DataLayout.h"
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "llvm/ExecutionEngine/Orc/IRTransformLayer.h"
|
||||
#include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
|
||||
#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
|
||||
#include "llvm/ExecutionEngine/Orc/SelfExecutorProcessControl.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Shared/ExecutorSymbolDef.h"
|
||||
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
|
||||
#include "llvm/IR/DataLayout.h"
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "llvm/ExecutionEngine/Orc/IRTransformLayer.h"
|
||||
#include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
|
||||
#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
|
||||
#include "llvm/ExecutionEngine/Orc/SelfExecutorProcessControl.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Shared/ExecutorSymbolDef.h"
|
||||
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
|
||||
#include "llvm/IR/DataLayout.h"
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
|
||||
#include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
|
||||
#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
|
||||
#include "llvm/ExecutionEngine/Orc/SelfExecutorProcessControl.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Shared/ExecutorSymbolDef.h"
|
||||
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
|
||||
#include "llvm/IR/DataLayout.h"
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "llvm/ExecutionEngine/Orc/LLJIT.h"
|
||||
#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
|
||||
#include "llvm/ExecutionEngine/Orc/OrcABISupport.h"
|
||||
#include "llvm/ExecutionEngine/Orc/SelfExecutorProcessControl.h"
|
||||
#include "llvm/Support/InitLLVM.h"
|
||||
#include "llvm/Support/TargetSelect.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
namespace llvm {
|
||||
namespace orc {
|
||||
|
||||
class EPCGenericMemoryAccess : public ExecutorProcessControl::MemoryAccess {
|
||||
class EPCGenericMemoryAccess : public MemoryAccess {
|
||||
public:
|
||||
/// Function addresses for memory access.
|
||||
struct FuncAddrs {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h"
|
||||
#include "llvm/ExecutionEngine/Orc/DylibManager.h"
|
||||
#include "llvm/ExecutionEngine/Orc/MemoryAccess.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h"
|
||||
@@ -23,15 +24,13 @@
|
||||
#include "llvm/ExecutionEngine/Orc/TargetProcess/UnwindInfoManager.h"
|
||||
#include "llvm/ExecutionEngine/Orc/TaskDispatch.h"
|
||||
#include "llvm/Support/Compiler.h"
|
||||
#include "llvm/Support/MSVCErrorWorkarounds.h"
|
||||
#include "llvm/TargetParser/Triple.h"
|
||||
|
||||
#include <future>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
namespace llvm {
|
||||
namespace orc {
|
||||
namespace llvm::orc {
|
||||
|
||||
class ExecutionSession;
|
||||
|
||||
@@ -98,81 +97,6 @@ public:
|
||||
TaskDispatcher &D;
|
||||
};
|
||||
|
||||
/// APIs for manipulating memory in the target process.
|
||||
class LLVM_ABI MemoryAccess {
|
||||
public:
|
||||
/// Callback function for asynchronous writes.
|
||||
using WriteResultFn = unique_function<void(Error)>;
|
||||
|
||||
virtual ~MemoryAccess();
|
||||
|
||||
virtual void writeUInt8sAsync(ArrayRef<tpctypes::UInt8Write> Ws,
|
||||
WriteResultFn OnWriteComplete) = 0;
|
||||
|
||||
virtual void writeUInt16sAsync(ArrayRef<tpctypes::UInt16Write> Ws,
|
||||
WriteResultFn OnWriteComplete) = 0;
|
||||
|
||||
virtual void writeUInt32sAsync(ArrayRef<tpctypes::UInt32Write> Ws,
|
||||
WriteResultFn OnWriteComplete) = 0;
|
||||
|
||||
virtual void writeUInt64sAsync(ArrayRef<tpctypes::UInt64Write> Ws,
|
||||
WriteResultFn OnWriteComplete) = 0;
|
||||
|
||||
virtual void writeBuffersAsync(ArrayRef<tpctypes::BufferWrite> Ws,
|
||||
WriteResultFn OnWriteComplete) = 0;
|
||||
|
||||
virtual void writePointersAsync(ArrayRef<tpctypes::PointerWrite> Ws,
|
||||
WriteResultFn OnWriteComplete) = 0;
|
||||
|
||||
Error writeUInt8s(ArrayRef<tpctypes::UInt8Write> Ws) {
|
||||
std::promise<MSVCPError> ResultP;
|
||||
auto ResultF = ResultP.get_future();
|
||||
writeUInt8sAsync(Ws,
|
||||
[&](Error Err) { ResultP.set_value(std::move(Err)); });
|
||||
return ResultF.get();
|
||||
}
|
||||
|
||||
Error writeUInt16s(ArrayRef<tpctypes::UInt16Write> Ws) {
|
||||
std::promise<MSVCPError> ResultP;
|
||||
auto ResultF = ResultP.get_future();
|
||||
writeUInt16sAsync(Ws,
|
||||
[&](Error Err) { ResultP.set_value(std::move(Err)); });
|
||||
return ResultF.get();
|
||||
}
|
||||
|
||||
Error writeUInt32s(ArrayRef<tpctypes::UInt32Write> Ws) {
|
||||
std::promise<MSVCPError> ResultP;
|
||||
auto ResultF = ResultP.get_future();
|
||||
writeUInt32sAsync(Ws,
|
||||
[&](Error Err) { ResultP.set_value(std::move(Err)); });
|
||||
return ResultF.get();
|
||||
}
|
||||
|
||||
Error writeUInt64s(ArrayRef<tpctypes::UInt64Write> Ws) {
|
||||
std::promise<MSVCPError> ResultP;
|
||||
auto ResultF = ResultP.get_future();
|
||||
writeUInt64sAsync(Ws,
|
||||
[&](Error Err) { ResultP.set_value(std::move(Err)); });
|
||||
return ResultF.get();
|
||||
}
|
||||
|
||||
Error writeBuffers(ArrayRef<tpctypes::BufferWrite> Ws) {
|
||||
std::promise<MSVCPError> ResultP;
|
||||
auto ResultF = ResultP.get_future();
|
||||
writeBuffersAsync(Ws,
|
||||
[&](Error Err) { ResultP.set_value(std::move(Err)); });
|
||||
return ResultF.get();
|
||||
}
|
||||
|
||||
Error writePointers(ArrayRef<tpctypes::PointerWrite> Ws) {
|
||||
std::promise<MSVCPError> ResultP;
|
||||
auto ResultF = ResultP.get_future();
|
||||
writePointersAsync(Ws,
|
||||
[&](Error Err) { ResultP.set_value(std::move(Err)); });
|
||||
return ResultF.get();
|
||||
}
|
||||
};
|
||||
|
||||
/// Contains the address of the dispatch function and context that the ORC
|
||||
/// runtime can use to call functions in the JIT.
|
||||
struct JITDispatchInfo {
|
||||
@@ -398,83 +322,6 @@ protected:
|
||||
StringMap<ExecutorAddr> BootstrapSymbols;
|
||||
};
|
||||
|
||||
class LLVM_ABI InProcessMemoryAccess
|
||||
: public ExecutorProcessControl::MemoryAccess {
|
||||
public:
|
||||
InProcessMemoryAccess(bool IsArch64Bit) : IsArch64Bit(IsArch64Bit) {}
|
||||
void writeUInt8sAsync(ArrayRef<tpctypes::UInt8Write> Ws,
|
||||
WriteResultFn OnWriteComplete) override;
|
||||
|
||||
void writeUInt16sAsync(ArrayRef<tpctypes::UInt16Write> Ws,
|
||||
WriteResultFn OnWriteComplete) override;
|
||||
|
||||
void writeUInt32sAsync(ArrayRef<tpctypes::UInt32Write> Ws,
|
||||
WriteResultFn OnWriteComplete) override;
|
||||
|
||||
void writeUInt64sAsync(ArrayRef<tpctypes::UInt64Write> Ws,
|
||||
WriteResultFn OnWriteComplete) override;
|
||||
|
||||
void writeBuffersAsync(ArrayRef<tpctypes::BufferWrite> Ws,
|
||||
WriteResultFn OnWriteComplete) override;
|
||||
|
||||
void writePointersAsync(ArrayRef<tpctypes::PointerWrite> Ws,
|
||||
WriteResultFn OnWriteComplete) override;
|
||||
|
||||
private:
|
||||
bool IsArch64Bit;
|
||||
};
|
||||
|
||||
/// A ExecutorProcessControl implementation targeting the current process.
|
||||
class LLVM_ABI SelfExecutorProcessControl : public ExecutorProcessControl,
|
||||
private InProcessMemoryAccess,
|
||||
private DylibManager {
|
||||
public:
|
||||
SelfExecutorProcessControl(
|
||||
std::shared_ptr<SymbolStringPool> SSP, std::unique_ptr<TaskDispatcher> D,
|
||||
Triple TargetTriple, unsigned PageSize,
|
||||
std::unique_ptr<jitlink::JITLinkMemoryManager> MemMgr);
|
||||
|
||||
/// Create a SelfExecutorProcessControl with the given symbol string pool and
|
||||
/// memory manager.
|
||||
/// If no symbol string pool is given then one will be created.
|
||||
/// If no memory manager is given a jitlink::InProcessMemoryManager will
|
||||
/// be created and used by default.
|
||||
static Expected<std::unique_ptr<SelfExecutorProcessControl>>
|
||||
Create(std::shared_ptr<SymbolStringPool> SSP = nullptr,
|
||||
std::unique_ptr<TaskDispatcher> D = nullptr,
|
||||
std::unique_ptr<jitlink::JITLinkMemoryManager> MemMgr = nullptr);
|
||||
|
||||
Expected<int32_t> runAsMain(ExecutorAddr MainFnAddr,
|
||||
ArrayRef<std::string> Args) override;
|
||||
|
||||
Expected<int32_t> runAsVoidFunction(ExecutorAddr VoidFnAddr) override;
|
||||
|
||||
Expected<int32_t> runAsIntFunction(ExecutorAddr IntFnAddr, int Arg) override;
|
||||
|
||||
void callWrapperAsync(ExecutorAddr WrapperFnAddr,
|
||||
IncomingWFRHandler OnComplete,
|
||||
ArrayRef<char> ArgBuffer) override;
|
||||
|
||||
Error disconnect() override;
|
||||
|
||||
private:
|
||||
static shared::CWrapperFunctionResult
|
||||
jitDispatchViaWrapperFunctionManager(void *Ctx, const void *FnTag,
|
||||
const char *Data, size_t Size);
|
||||
|
||||
Expected<tpctypes::DylibHandle> loadDylib(const char *DylibPath) override;
|
||||
|
||||
void lookupSymbolsAsync(ArrayRef<LookupRequest> Request,
|
||||
SymbolLookupCompleteFn F) override;
|
||||
|
||||
std::unique_ptr<jitlink::JITLinkMemoryManager> OwnedMemMgr;
|
||||
#ifdef __APPLE__
|
||||
std::unique_ptr<UnwindInfoManager> UnwindInfoMgr;
|
||||
#endif // __APPLE__
|
||||
char GlobalManglingPrefix = 0;
|
||||
};
|
||||
|
||||
} // end namespace orc
|
||||
} // end namespace llvm
|
||||
} // namespace llvm::orc
|
||||
|
||||
#endif // LLVM_EXECUTIONENGINE_ORC_EXECUTORPROCESSCONTROL_H
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
//===-- InProcessMemoryAccess.h - Direct, in-process mem access -*- C++ -*-===//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Accesses memory in the current process.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_EXECUTIONENGINE_ORC_INPROCESSMEMORYACCESS_H
|
||||
#define LLVM_EXECUTIONENGINE_ORC_INPROCESSMEMORYACCESS_H
|
||||
|
||||
#include "llvm/ExecutionEngine/Orc/MemoryAccess.h"
|
||||
|
||||
namespace llvm::orc {
|
||||
|
||||
class LLVM_ABI InProcessMemoryAccess : public MemoryAccess {
|
||||
public:
|
||||
InProcessMemoryAccess(bool IsArch64Bit) : IsArch64Bit(IsArch64Bit) {}
|
||||
void writeUInt8sAsync(ArrayRef<tpctypes::UInt8Write> Ws,
|
||||
WriteResultFn OnWriteComplete) override;
|
||||
|
||||
void writeUInt16sAsync(ArrayRef<tpctypes::UInt16Write> Ws,
|
||||
WriteResultFn OnWriteComplete) override;
|
||||
|
||||
void writeUInt32sAsync(ArrayRef<tpctypes::UInt32Write> Ws,
|
||||
WriteResultFn OnWriteComplete) override;
|
||||
|
||||
void writeUInt64sAsync(ArrayRef<tpctypes::UInt64Write> Ws,
|
||||
WriteResultFn OnWriteComplete) override;
|
||||
|
||||
void writeBuffersAsync(ArrayRef<tpctypes::BufferWrite> Ws,
|
||||
WriteResultFn OnWriteComplete) override;
|
||||
|
||||
void writePointersAsync(ArrayRef<tpctypes::PointerWrite> Ws,
|
||||
WriteResultFn OnWriteComplete) override;
|
||||
|
||||
private:
|
||||
bool IsArch64Bit;
|
||||
};
|
||||
|
||||
} // namespace llvm::orc
|
||||
|
||||
#endif // LLVM_EXECUTIONENGINE_ORC_INPROCESSMEMORYACCESS_H
|
||||
101
llvm/include/llvm/ExecutionEngine/Orc/MemoryAccess.h
Normal file
101
llvm/include/llvm/ExecutionEngine/Orc/MemoryAccess.h
Normal file
@@ -0,0 +1,101 @@
|
||||
//===------- MemoryAccess.h - Executor memory access APIs -------*- C++ -*-===//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Utilities for accessing memory in the executor processes.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_EXECUTIONENGINE_ORC_MEMORYACCESS_H
|
||||
#define LLVM_EXECUTIONENGINE_ORC_MEMORYACCESS_H
|
||||
|
||||
#include "llvm/ADT/ArrayRef.h"
|
||||
#include "llvm/ADT/FunctionExtras.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h"
|
||||
#include "llvm/Support/MSVCErrorWorkarounds.h"
|
||||
|
||||
#include <future>
|
||||
|
||||
namespace llvm::orc {
|
||||
|
||||
/// APIs for manipulating memory in the target process.
|
||||
class LLVM_ABI MemoryAccess {
|
||||
public:
|
||||
/// Callback function for asynchronous writes.
|
||||
using WriteResultFn = unique_function<void(Error)>;
|
||||
|
||||
virtual ~MemoryAccess();
|
||||
|
||||
virtual void writeUInt8sAsync(ArrayRef<tpctypes::UInt8Write> Ws,
|
||||
WriteResultFn OnWriteComplete) = 0;
|
||||
|
||||
virtual void writeUInt16sAsync(ArrayRef<tpctypes::UInt16Write> Ws,
|
||||
WriteResultFn OnWriteComplete) = 0;
|
||||
|
||||
virtual void writeUInt32sAsync(ArrayRef<tpctypes::UInt32Write> Ws,
|
||||
WriteResultFn OnWriteComplete) = 0;
|
||||
|
||||
virtual void writeUInt64sAsync(ArrayRef<tpctypes::UInt64Write> Ws,
|
||||
WriteResultFn OnWriteComplete) = 0;
|
||||
|
||||
virtual void writeBuffersAsync(ArrayRef<tpctypes::BufferWrite> Ws,
|
||||
WriteResultFn OnWriteComplete) = 0;
|
||||
|
||||
virtual void writePointersAsync(ArrayRef<tpctypes::PointerWrite> Ws,
|
||||
WriteResultFn OnWriteComplete) = 0;
|
||||
|
||||
Error writeUInt8s(ArrayRef<tpctypes::UInt8Write> Ws) {
|
||||
std::promise<MSVCPError> ResultP;
|
||||
auto ResultF = ResultP.get_future();
|
||||
writeUInt8sAsync(Ws, [&](Error Err) { ResultP.set_value(std::move(Err)); });
|
||||
return ResultF.get();
|
||||
}
|
||||
|
||||
Error writeUInt16s(ArrayRef<tpctypes::UInt16Write> Ws) {
|
||||
std::promise<MSVCPError> ResultP;
|
||||
auto ResultF = ResultP.get_future();
|
||||
writeUInt16sAsync(Ws,
|
||||
[&](Error Err) { ResultP.set_value(std::move(Err)); });
|
||||
return ResultF.get();
|
||||
}
|
||||
|
||||
Error writeUInt32s(ArrayRef<tpctypes::UInt32Write> Ws) {
|
||||
std::promise<MSVCPError> ResultP;
|
||||
auto ResultF = ResultP.get_future();
|
||||
writeUInt32sAsync(Ws,
|
||||
[&](Error Err) { ResultP.set_value(std::move(Err)); });
|
||||
return ResultF.get();
|
||||
}
|
||||
|
||||
Error writeUInt64s(ArrayRef<tpctypes::UInt64Write> Ws) {
|
||||
std::promise<MSVCPError> ResultP;
|
||||
auto ResultF = ResultP.get_future();
|
||||
writeUInt64sAsync(Ws,
|
||||
[&](Error Err) { ResultP.set_value(std::move(Err)); });
|
||||
return ResultF.get();
|
||||
}
|
||||
|
||||
Error writeBuffers(ArrayRef<tpctypes::BufferWrite> Ws) {
|
||||
std::promise<MSVCPError> ResultP;
|
||||
auto ResultF = ResultP.get_future();
|
||||
writeBuffersAsync(Ws,
|
||||
[&](Error Err) { ResultP.set_value(std::move(Err)); });
|
||||
return ResultF.get();
|
||||
}
|
||||
|
||||
Error writePointers(ArrayRef<tpctypes::PointerWrite> Ws) {
|
||||
std::promise<MSVCPError> ResultP;
|
||||
auto ResultF = ResultP.get_future();
|
||||
writePointersAsync(Ws,
|
||||
[&](Error Err) { ResultP.set_value(std::move(Err)); });
|
||||
return ResultF.get();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace llvm::orc
|
||||
|
||||
#endif // LLVM_EXECUTIONENGINE_ORC_MEMORYACCESS_H
|
||||
@@ -0,0 +1,76 @@
|
||||
//===-- SelfExecutorProcessControl.h - EPC for in-process JITs --*- C++ -*-===//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Executor process control implementation for JITs that run JIT'd code in the
|
||||
// same process.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_EXECUTIONENGINE_ORC_SELFEXECUTORPROCESSCONTROL_H
|
||||
#define LLVM_EXECUTIONENGINE_ORC_SELFEXECUTORPROCESSCONTROL_H
|
||||
|
||||
#include "llvm/ExecutionEngine/Orc/ExecutorProcessControl.h"
|
||||
#include "llvm/ExecutionEngine/Orc/InProcessMemoryAccess.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace llvm::orc {
|
||||
|
||||
/// A ExecutorProcessControl implementation targeting the current process.
|
||||
class LLVM_ABI SelfExecutorProcessControl : public ExecutorProcessControl,
|
||||
private DylibManager {
|
||||
public:
|
||||
SelfExecutorProcessControl(
|
||||
std::shared_ptr<SymbolStringPool> SSP, std::unique_ptr<TaskDispatcher> D,
|
||||
Triple TargetTriple, unsigned PageSize,
|
||||
std::unique_ptr<jitlink::JITLinkMemoryManager> MemMgr);
|
||||
|
||||
/// Create a SelfExecutorProcessControl with the given symbol string pool and
|
||||
/// memory manager.
|
||||
/// If no symbol string pool is given then one will be created.
|
||||
/// If no memory manager is given a jitlink::InProcessMemoryManager will
|
||||
/// be created and used by default.
|
||||
static Expected<std::unique_ptr<SelfExecutorProcessControl>>
|
||||
Create(std::shared_ptr<SymbolStringPool> SSP = nullptr,
|
||||
std::unique_ptr<TaskDispatcher> D = nullptr,
|
||||
std::unique_ptr<jitlink::JITLinkMemoryManager> MemMgr = nullptr);
|
||||
|
||||
Expected<int32_t> runAsMain(ExecutorAddr MainFnAddr,
|
||||
ArrayRef<std::string> Args) override;
|
||||
|
||||
Expected<int32_t> runAsVoidFunction(ExecutorAddr VoidFnAddr) override;
|
||||
|
||||
Expected<int32_t> runAsIntFunction(ExecutorAddr IntFnAddr, int Arg) override;
|
||||
|
||||
void callWrapperAsync(ExecutorAddr WrapperFnAddr,
|
||||
IncomingWFRHandler OnComplete,
|
||||
ArrayRef<char> ArgBuffer) override;
|
||||
|
||||
Error disconnect() override;
|
||||
|
||||
private:
|
||||
static shared::CWrapperFunctionResult
|
||||
jitDispatchViaWrapperFunctionManager(void *Ctx, const void *FnTag,
|
||||
const char *Data, size_t Size);
|
||||
|
||||
Expected<tpctypes::DylibHandle> loadDylib(const char *DylibPath) override;
|
||||
|
||||
void lookupSymbolsAsync(ArrayRef<LookupRequest> Request,
|
||||
SymbolLookupCompleteFn F) override;
|
||||
|
||||
std::unique_ptr<jitlink::JITLinkMemoryManager> OwnedMemMgr;
|
||||
#ifdef __APPLE__
|
||||
std::unique_ptr<UnwindInfoManager> UnwindInfoMgr;
|
||||
#endif // __APPLE__
|
||||
char GlobalManglingPrefix = 0;
|
||||
InProcessMemoryAccess IPMA;
|
||||
};
|
||||
|
||||
} // namespace llvm::orc
|
||||
|
||||
#endif // LLVM_EXECUTIONENGINE_ORC_SELFEXECUTORPROCESSCONTROL_H
|
||||
@@ -27,6 +27,7 @@ add_llvm_component_library(LLVMOrcJIT
|
||||
ObjectFileInterface.cpp
|
||||
GetDylibInterface.cpp
|
||||
IndirectionUtils.cpp
|
||||
InProcessMemoryAccess.cpp
|
||||
IRCompileLayer.cpp
|
||||
IRTransformLayer.cpp
|
||||
IRPartitionLayer.cpp
|
||||
@@ -52,6 +53,7 @@ add_llvm_component_library(LLVMOrcJIT
|
||||
OrcV2CBindings.cpp
|
||||
RTDyldObjectLinkingLayer.cpp
|
||||
SectCreate.cpp
|
||||
SelfExecutorProcessControl.cpp
|
||||
SimpleRemoteEPC.cpp
|
||||
Speculation.cpp
|
||||
SpeculateAnalyses.cpp
|
||||
|
||||
@@ -7,223 +7,13 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/ExecutionEngine/Orc/ExecutorProcessControl.h"
|
||||
#include "llvm/ExecutionEngine/Orc/DylibManager.h"
|
||||
#include "llvm/ExecutionEngine/Orc/MemoryAccess.h"
|
||||
|
||||
#include "llvm/ExecutionEngine/Orc/Core.h"
|
||||
#include "llvm/ExecutionEngine/Orc/TargetProcess/DefaultHostBootstrapValues.h"
|
||||
#include "llvm/ExecutionEngine/Orc/TargetProcess/TargetExecutionUtils.h"
|
||||
#include "llvm/Support/DynamicLibrary.h"
|
||||
#include "llvm/Support/Process.h"
|
||||
#include "llvm/TargetParser/Host.h"
|
||||
|
||||
#define DEBUG_TYPE "orc"
|
||||
|
||||
namespace llvm {
|
||||
namespace orc {
|
||||
namespace llvm::orc {
|
||||
|
||||
DylibManager::~DylibManager() = default;
|
||||
|
||||
ExecutorProcessControl::MemoryAccess::~MemoryAccess() = default;
|
||||
|
||||
ExecutorProcessControl::~ExecutorProcessControl() = default;
|
||||
|
||||
SelfExecutorProcessControl::SelfExecutorProcessControl(
|
||||
std::shared_ptr<SymbolStringPool> SSP, std::unique_ptr<TaskDispatcher> D,
|
||||
Triple TargetTriple, unsigned PageSize,
|
||||
std::unique_ptr<jitlink::JITLinkMemoryManager> MemMgr)
|
||||
: ExecutorProcessControl(std::move(SSP), std::move(D)),
|
||||
InProcessMemoryAccess(TargetTriple.isArch64Bit()) {
|
||||
|
||||
OwnedMemMgr = std::move(MemMgr);
|
||||
if (!OwnedMemMgr)
|
||||
OwnedMemMgr = std::make_unique<jitlink::InProcessMemoryManager>(
|
||||
sys::Process::getPageSizeEstimate());
|
||||
|
||||
this->TargetTriple = std::move(TargetTriple);
|
||||
this->PageSize = PageSize;
|
||||
this->MemMgr = OwnedMemMgr.get();
|
||||
this->MemAccess = this;
|
||||
this->DylibMgr = this;
|
||||
this->JDI = {ExecutorAddr::fromPtr(jitDispatchViaWrapperFunctionManager),
|
||||
ExecutorAddr::fromPtr(this)};
|
||||
|
||||
if (this->TargetTriple.isOSBinFormatMachO())
|
||||
GlobalManglingPrefix = '_';
|
||||
|
||||
addDefaultBootstrapValuesForHostProcess(BootstrapMap, BootstrapSymbols);
|
||||
|
||||
#ifdef __APPLE__
|
||||
// FIXME: Don't add an UnwindInfoManager by default -- it's redundant when
|
||||
// the ORC runtime is loaded. We'll need a way to document this and
|
||||
// allow clients to choose.
|
||||
if (UnwindInfoManager::TryEnable())
|
||||
UnwindInfoManager::addBootstrapSymbols(this->BootstrapSymbols);
|
||||
#endif // __APPLE__
|
||||
}
|
||||
|
||||
Expected<std::unique_ptr<SelfExecutorProcessControl>>
|
||||
SelfExecutorProcessControl::Create(
|
||||
std::shared_ptr<SymbolStringPool> SSP,
|
||||
std::unique_ptr<TaskDispatcher> D,
|
||||
std::unique_ptr<jitlink::JITLinkMemoryManager> MemMgr) {
|
||||
|
||||
if (!SSP)
|
||||
SSP = std::make_shared<SymbolStringPool>();
|
||||
|
||||
if (!D)
|
||||
D = std::make_unique<InPlaceTaskDispatcher>();
|
||||
|
||||
auto PageSize = sys::Process::getPageSize();
|
||||
if (!PageSize)
|
||||
return PageSize.takeError();
|
||||
|
||||
Triple TT(sys::getProcessTriple());
|
||||
|
||||
return std::make_unique<SelfExecutorProcessControl>(
|
||||
std::move(SSP), std::move(D), std::move(TT), *PageSize,
|
||||
std::move(MemMgr));
|
||||
}
|
||||
|
||||
Expected<tpctypes::DylibHandle>
|
||||
SelfExecutorProcessControl::loadDylib(const char *DylibPath) {
|
||||
std::string ErrMsg;
|
||||
auto Dylib = sys::DynamicLibrary::getPermanentLibrary(DylibPath, &ErrMsg);
|
||||
if (!Dylib.isValid())
|
||||
return make_error<StringError>(std::move(ErrMsg), inconvertibleErrorCode());
|
||||
return ExecutorAddr::fromPtr(Dylib.getOSSpecificHandle());
|
||||
}
|
||||
|
||||
void SelfExecutorProcessControl::lookupSymbolsAsync(
|
||||
ArrayRef<LookupRequest> Request,
|
||||
DylibManager::SymbolLookupCompleteFn Complete) {
|
||||
std::vector<tpctypes::LookupResult> R;
|
||||
|
||||
for (auto &Elem : Request) {
|
||||
sys::DynamicLibrary Dylib(Elem.Handle.toPtr<void *>());
|
||||
R.push_back(std::vector<ExecutorSymbolDef>());
|
||||
for (auto &KV : Elem.Symbols) {
|
||||
auto &Sym = KV.first;
|
||||
std::string Tmp((*Sym).data() + !!GlobalManglingPrefix,
|
||||
(*Sym).size() - !!GlobalManglingPrefix);
|
||||
void *Addr = Dylib.getAddressOfSymbol(Tmp.c_str());
|
||||
if (!Addr && KV.second == SymbolLookupFlags::RequiredSymbol) {
|
||||
// FIXME: Collect all failing symbols before erroring out.
|
||||
SymbolNameVector MissingSymbols;
|
||||
MissingSymbols.push_back(Sym);
|
||||
return Complete(
|
||||
make_error<SymbolsNotFound>(SSP, std::move(MissingSymbols)));
|
||||
}
|
||||
// FIXME: determine accurate JITSymbolFlags.
|
||||
R.back().push_back(
|
||||
{ExecutorAddr::fromPtr(Addr), JITSymbolFlags::Exported});
|
||||
}
|
||||
}
|
||||
|
||||
Complete(std::move(R));
|
||||
}
|
||||
|
||||
Expected<int32_t>
|
||||
SelfExecutorProcessControl::runAsMain(ExecutorAddr MainFnAddr,
|
||||
ArrayRef<std::string> Args) {
|
||||
using MainTy = int (*)(int, char *[]);
|
||||
return orc::runAsMain(MainFnAddr.toPtr<MainTy>(), Args);
|
||||
}
|
||||
|
||||
Expected<int32_t>
|
||||
SelfExecutorProcessControl::runAsVoidFunction(ExecutorAddr VoidFnAddr) {
|
||||
using VoidTy = int (*)();
|
||||
return orc::runAsVoidFunction(VoidFnAddr.toPtr<VoidTy>());
|
||||
}
|
||||
|
||||
Expected<int32_t>
|
||||
SelfExecutorProcessControl::runAsIntFunction(ExecutorAddr IntFnAddr, int Arg) {
|
||||
using IntTy = int (*)(int);
|
||||
return orc::runAsIntFunction(IntFnAddr.toPtr<IntTy>(), Arg);
|
||||
}
|
||||
|
||||
void SelfExecutorProcessControl::callWrapperAsync(ExecutorAddr WrapperFnAddr,
|
||||
IncomingWFRHandler SendResult,
|
||||
ArrayRef<char> ArgBuffer) {
|
||||
using WrapperFnTy =
|
||||
shared::CWrapperFunctionResult (*)(const char *Data, size_t Size);
|
||||
auto *WrapperFn = WrapperFnAddr.toPtr<WrapperFnTy>();
|
||||
SendResult(WrapperFn(ArgBuffer.data(), ArgBuffer.size()));
|
||||
}
|
||||
|
||||
Error SelfExecutorProcessControl::disconnect() {
|
||||
D->shutdown();
|
||||
return Error::success();
|
||||
}
|
||||
|
||||
void InProcessMemoryAccess::writeUInt8sAsync(ArrayRef<tpctypes::UInt8Write> Ws,
|
||||
WriteResultFn OnWriteComplete) {
|
||||
for (auto &W : Ws)
|
||||
*W.Addr.toPtr<uint8_t *>() = W.Value;
|
||||
OnWriteComplete(Error::success());
|
||||
}
|
||||
|
||||
void InProcessMemoryAccess::writeUInt16sAsync(
|
||||
ArrayRef<tpctypes::UInt16Write> Ws, WriteResultFn OnWriteComplete) {
|
||||
for (auto &W : Ws)
|
||||
*W.Addr.toPtr<uint16_t *>() = W.Value;
|
||||
OnWriteComplete(Error::success());
|
||||
}
|
||||
|
||||
void InProcessMemoryAccess::writeUInt32sAsync(
|
||||
ArrayRef<tpctypes::UInt32Write> Ws, WriteResultFn OnWriteComplete) {
|
||||
for (auto &W : Ws)
|
||||
*W.Addr.toPtr<uint32_t *>() = W.Value;
|
||||
OnWriteComplete(Error::success());
|
||||
}
|
||||
|
||||
void InProcessMemoryAccess::writeUInt64sAsync(
|
||||
ArrayRef<tpctypes::UInt64Write> Ws, WriteResultFn OnWriteComplete) {
|
||||
for (auto &W : Ws)
|
||||
*W.Addr.toPtr<uint64_t *>() = W.Value;
|
||||
OnWriteComplete(Error::success());
|
||||
}
|
||||
|
||||
void InProcessMemoryAccess::writeBuffersAsync(
|
||||
ArrayRef<tpctypes::BufferWrite> Ws, WriteResultFn OnWriteComplete) {
|
||||
for (auto &W : Ws)
|
||||
memcpy(W.Addr.toPtr<char *>(), W.Buffer.data(), W.Buffer.size());
|
||||
OnWriteComplete(Error::success());
|
||||
}
|
||||
|
||||
void InProcessMemoryAccess::writePointersAsync(
|
||||
ArrayRef<tpctypes::PointerWrite> Ws, WriteResultFn OnWriteComplete) {
|
||||
if (IsArch64Bit) {
|
||||
for (auto &W : Ws)
|
||||
*W.Addr.toPtr<uint64_t *>() = W.Value.getValue();
|
||||
} else {
|
||||
for (auto &W : Ws)
|
||||
*W.Addr.toPtr<uint32_t *>() = static_cast<uint32_t>(W.Value.getValue());
|
||||
}
|
||||
|
||||
OnWriteComplete(Error::success());
|
||||
}
|
||||
|
||||
shared::CWrapperFunctionResult
|
||||
SelfExecutorProcessControl::jitDispatchViaWrapperFunctionManager(
|
||||
void *Ctx, const void *FnTag, const char *Data, size_t Size) {
|
||||
|
||||
LLVM_DEBUG({
|
||||
dbgs() << "jit-dispatch call with tag " << FnTag << " and " << Size
|
||||
<< " byte payload.\n";
|
||||
});
|
||||
|
||||
std::promise<shared::WrapperFunctionResult> ResultP;
|
||||
auto ResultF = ResultP.get_future();
|
||||
static_cast<SelfExecutorProcessControl *>(Ctx)
|
||||
->getExecutionSession()
|
||||
.runJITDispatchHandler(
|
||||
[ResultP = std::move(ResultP)](
|
||||
shared::WrapperFunctionResult Result) mutable {
|
||||
ResultP.set_value(std::move(Result));
|
||||
},
|
||||
ExecutorAddr::fromPtr(FnTag), {Data, Size});
|
||||
|
||||
return ResultF.get().release();
|
||||
}
|
||||
|
||||
} // end namespace orc
|
||||
} // end namespace llvm
|
||||
} // namespace llvm::orc
|
||||
|
||||
64
llvm/lib/ExecutionEngine/Orc/InProcessMemoryAccess.cpp
Normal file
64
llvm/lib/ExecutionEngine/Orc/InProcessMemoryAccess.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
//===------ InProcessMemoryAccess.cpp - Direct, in-process mem access -----===//
|
||||
//
|
||||
// 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 "llvm/ExecutionEngine/Orc/InProcessMemoryAccess.h"
|
||||
|
||||
#define DEBUG_TYPE "orc"
|
||||
|
||||
namespace llvm::orc {
|
||||
|
||||
MemoryAccess::~MemoryAccess() = default;
|
||||
|
||||
void InProcessMemoryAccess::writeUInt8sAsync(ArrayRef<tpctypes::UInt8Write> Ws,
|
||||
WriteResultFn OnWriteComplete) {
|
||||
for (auto &W : Ws)
|
||||
*W.Addr.toPtr<uint8_t *>() = W.Value;
|
||||
OnWriteComplete(Error::success());
|
||||
}
|
||||
|
||||
void InProcessMemoryAccess::writeUInt16sAsync(
|
||||
ArrayRef<tpctypes::UInt16Write> Ws, WriteResultFn OnWriteComplete) {
|
||||
for (auto &W : Ws)
|
||||
*W.Addr.toPtr<uint16_t *>() = W.Value;
|
||||
OnWriteComplete(Error::success());
|
||||
}
|
||||
|
||||
void InProcessMemoryAccess::writeUInt32sAsync(
|
||||
ArrayRef<tpctypes::UInt32Write> Ws, WriteResultFn OnWriteComplete) {
|
||||
for (auto &W : Ws)
|
||||
*W.Addr.toPtr<uint32_t *>() = W.Value;
|
||||
OnWriteComplete(Error::success());
|
||||
}
|
||||
|
||||
void InProcessMemoryAccess::writeUInt64sAsync(
|
||||
ArrayRef<tpctypes::UInt64Write> Ws, WriteResultFn OnWriteComplete) {
|
||||
for (auto &W : Ws)
|
||||
*W.Addr.toPtr<uint64_t *>() = W.Value;
|
||||
OnWriteComplete(Error::success());
|
||||
}
|
||||
|
||||
void InProcessMemoryAccess::writeBuffersAsync(
|
||||
ArrayRef<tpctypes::BufferWrite> Ws, WriteResultFn OnWriteComplete) {
|
||||
for (auto &W : Ws)
|
||||
memcpy(W.Addr.toPtr<char *>(), W.Buffer.data(), W.Buffer.size());
|
||||
OnWriteComplete(Error::success());
|
||||
}
|
||||
|
||||
void InProcessMemoryAccess::writePointersAsync(
|
||||
ArrayRef<tpctypes::PointerWrite> Ws, WriteResultFn OnWriteComplete) {
|
||||
if (IsArch64Bit) {
|
||||
for (auto &W : Ws)
|
||||
*W.Addr.toPtr<uint64_t *>() = W.Value.getValue();
|
||||
} else {
|
||||
for (auto &W : Ws)
|
||||
*W.Addr.toPtr<uint32_t *>() = static_cast<uint32_t>(W.Value.getValue());
|
||||
}
|
||||
|
||||
OnWriteComplete(Error::success());
|
||||
}
|
||||
} // end namespace llvm::orc
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
|
||||
#include "llvm/ExecutionEngine/Orc/ObjectTransformLayer.h"
|
||||
#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
|
||||
#include "llvm/ExecutionEngine/Orc/SelfExecutorProcessControl.h"
|
||||
#include "llvm/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.h"
|
||||
#include "llvm/ExecutionEngine/Orc/UnwindInfoRegistrationPlugin.h"
|
||||
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
|
||||
|
||||
172
llvm/lib/ExecutionEngine/Orc/SelfExecutorProcessControl.cpp
Normal file
172
llvm/lib/ExecutionEngine/Orc/SelfExecutorProcessControl.cpp
Normal file
@@ -0,0 +1,172 @@
|
||||
//===------ SelfExecutorProcessControl.cpp -- EPC for in-process JITs -----===//
|
||||
//
|
||||
// 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 "llvm/ExecutionEngine/Orc/SelfExecutorProcessControl.h"
|
||||
|
||||
#include "llvm/ExecutionEngine/Orc/Core.h"
|
||||
#include "llvm/ExecutionEngine/Orc/TargetProcess/DefaultHostBootstrapValues.h"
|
||||
#include "llvm/ExecutionEngine/Orc/TargetProcess/TargetExecutionUtils.h"
|
||||
#include "llvm/Support/DynamicLibrary.h"
|
||||
#include "llvm/Support/Process.h"
|
||||
#include "llvm/TargetParser/Host.h"
|
||||
|
||||
#define DEBUG_TYPE "orc"
|
||||
|
||||
namespace llvm::orc {
|
||||
|
||||
SelfExecutorProcessControl::SelfExecutorProcessControl(
|
||||
std::shared_ptr<SymbolStringPool> SSP, std::unique_ptr<TaskDispatcher> D,
|
||||
Triple TargetTriple, unsigned PageSize,
|
||||
std::unique_ptr<jitlink::JITLinkMemoryManager> MemMgr)
|
||||
: ExecutorProcessControl(std::move(SSP), std::move(D)),
|
||||
IPMA(TargetTriple.isArch64Bit()) {
|
||||
|
||||
OwnedMemMgr = std::move(MemMgr);
|
||||
if (!OwnedMemMgr)
|
||||
OwnedMemMgr = std::make_unique<jitlink::InProcessMemoryManager>(
|
||||
sys::Process::getPageSizeEstimate());
|
||||
|
||||
this->TargetTriple = std::move(TargetTriple);
|
||||
this->PageSize = PageSize;
|
||||
this->MemMgr = OwnedMemMgr.get();
|
||||
this->MemAccess = &IPMA;
|
||||
this->DylibMgr = this;
|
||||
this->JDI = {ExecutorAddr::fromPtr(jitDispatchViaWrapperFunctionManager),
|
||||
ExecutorAddr::fromPtr(this)};
|
||||
|
||||
if (this->TargetTriple.isOSBinFormatMachO())
|
||||
GlobalManglingPrefix = '_';
|
||||
|
||||
addDefaultBootstrapValuesForHostProcess(BootstrapMap, BootstrapSymbols);
|
||||
|
||||
#ifdef __APPLE__
|
||||
// FIXME: Don't add an UnwindInfoManager by default -- it's redundant when
|
||||
// the ORC runtime is loaded. We'll need a way to document this and
|
||||
// allow clients to choose.
|
||||
if (UnwindInfoManager::TryEnable())
|
||||
UnwindInfoManager::addBootstrapSymbols(this->BootstrapSymbols);
|
||||
#endif // __APPLE__
|
||||
}
|
||||
|
||||
Expected<std::unique_ptr<SelfExecutorProcessControl>>
|
||||
SelfExecutorProcessControl::Create(
|
||||
std::shared_ptr<SymbolStringPool> SSP, std::unique_ptr<TaskDispatcher> D,
|
||||
std::unique_ptr<jitlink::JITLinkMemoryManager> MemMgr) {
|
||||
|
||||
if (!SSP)
|
||||
SSP = std::make_shared<SymbolStringPool>();
|
||||
|
||||
if (!D)
|
||||
D = std::make_unique<InPlaceTaskDispatcher>();
|
||||
|
||||
auto PageSize = sys::Process::getPageSize();
|
||||
if (!PageSize)
|
||||
return PageSize.takeError();
|
||||
|
||||
Triple TT(sys::getProcessTriple());
|
||||
|
||||
return std::make_unique<SelfExecutorProcessControl>(
|
||||
std::move(SSP), std::move(D), std::move(TT), *PageSize,
|
||||
std::move(MemMgr));
|
||||
}
|
||||
|
||||
Expected<tpctypes::DylibHandle>
|
||||
SelfExecutorProcessControl::loadDylib(const char *DylibPath) {
|
||||
std::string ErrMsg;
|
||||
auto Dylib = sys::DynamicLibrary::getPermanentLibrary(DylibPath, &ErrMsg);
|
||||
if (!Dylib.isValid())
|
||||
return make_error<StringError>(std::move(ErrMsg), inconvertibleErrorCode());
|
||||
return ExecutorAddr::fromPtr(Dylib.getOSSpecificHandle());
|
||||
}
|
||||
|
||||
void SelfExecutorProcessControl::lookupSymbolsAsync(
|
||||
ArrayRef<LookupRequest> Request,
|
||||
DylibManager::SymbolLookupCompleteFn Complete) {
|
||||
std::vector<tpctypes::LookupResult> R;
|
||||
|
||||
for (auto &Elem : Request) {
|
||||
sys::DynamicLibrary Dylib(Elem.Handle.toPtr<void *>());
|
||||
R.push_back(std::vector<ExecutorSymbolDef>());
|
||||
for (auto &KV : Elem.Symbols) {
|
||||
auto &Sym = KV.first;
|
||||
std::string Tmp((*Sym).data() + !!GlobalManglingPrefix,
|
||||
(*Sym).size() - !!GlobalManglingPrefix);
|
||||
void *Addr = Dylib.getAddressOfSymbol(Tmp.c_str());
|
||||
if (!Addr && KV.second == SymbolLookupFlags::RequiredSymbol) {
|
||||
// FIXME: Collect all failing symbols before erroring out.
|
||||
SymbolNameVector MissingSymbols;
|
||||
MissingSymbols.push_back(Sym);
|
||||
return Complete(
|
||||
make_error<SymbolsNotFound>(SSP, std::move(MissingSymbols)));
|
||||
}
|
||||
// FIXME: determine accurate JITSymbolFlags.
|
||||
R.back().push_back(
|
||||
{ExecutorAddr::fromPtr(Addr), JITSymbolFlags::Exported});
|
||||
}
|
||||
}
|
||||
|
||||
Complete(std::move(R));
|
||||
}
|
||||
|
||||
Expected<int32_t>
|
||||
SelfExecutorProcessControl::runAsMain(ExecutorAddr MainFnAddr,
|
||||
ArrayRef<std::string> Args) {
|
||||
using MainTy = int (*)(int, char *[]);
|
||||
return orc::runAsMain(MainFnAddr.toPtr<MainTy>(), Args);
|
||||
}
|
||||
|
||||
Expected<int32_t>
|
||||
SelfExecutorProcessControl::runAsVoidFunction(ExecutorAddr VoidFnAddr) {
|
||||
using VoidTy = int (*)();
|
||||
return orc::runAsVoidFunction(VoidFnAddr.toPtr<VoidTy>());
|
||||
}
|
||||
|
||||
Expected<int32_t>
|
||||
SelfExecutorProcessControl::runAsIntFunction(ExecutorAddr IntFnAddr, int Arg) {
|
||||
using IntTy = int (*)(int);
|
||||
return orc::runAsIntFunction(IntFnAddr.toPtr<IntTy>(), Arg);
|
||||
}
|
||||
|
||||
void SelfExecutorProcessControl::callWrapperAsync(ExecutorAddr WrapperFnAddr,
|
||||
IncomingWFRHandler SendResult,
|
||||
ArrayRef<char> ArgBuffer) {
|
||||
using WrapperFnTy =
|
||||
shared::CWrapperFunctionResult (*)(const char *Data, size_t Size);
|
||||
auto *WrapperFn = WrapperFnAddr.toPtr<WrapperFnTy>();
|
||||
SendResult(WrapperFn(ArgBuffer.data(), ArgBuffer.size()));
|
||||
}
|
||||
|
||||
Error SelfExecutorProcessControl::disconnect() {
|
||||
D->shutdown();
|
||||
return Error::success();
|
||||
}
|
||||
|
||||
shared::CWrapperFunctionResult
|
||||
SelfExecutorProcessControl::jitDispatchViaWrapperFunctionManager(
|
||||
void *Ctx, const void *FnTag, const char *Data, size_t Size) {
|
||||
|
||||
LLVM_DEBUG({
|
||||
dbgs() << "jit-dispatch call with tag " << FnTag << " and " << Size
|
||||
<< " byte payload.\n";
|
||||
});
|
||||
|
||||
std::promise<shared::WrapperFunctionResult> ResultP;
|
||||
auto ResultF = ResultP.get_future();
|
||||
static_cast<SelfExecutorProcessControl *>(Ctx)
|
||||
->getExecutionSession()
|
||||
.runJITDispatchHandler(
|
||||
[ResultP = std::move(ResultP)](
|
||||
shared::WrapperFunctionResult Result) mutable {
|
||||
ResultP.set_value(std::move(Result));
|
||||
},
|
||||
ExecutorAddr::fromPtr(FnTag), {Data, Size});
|
||||
|
||||
return ResultF.get().release();
|
||||
}
|
||||
|
||||
} // namespace llvm::orc
|
||||
@@ -224,7 +224,7 @@ SimpleRemoteEPC::createDefaultMemoryManager(SimpleRemoteEPC &SREPC) {
|
||||
return std::make_unique<EPCGenericJITLinkMemoryManager>(SREPC, SAs);
|
||||
}
|
||||
|
||||
Expected<std::unique_ptr<ExecutorProcessControl::MemoryAccess>>
|
||||
Expected<std::unique_ptr<MemoryAccess>>
|
||||
SimpleRemoteEPC::createDefaultMemoryAccess(SimpleRemoteEPC &SREPC) {
|
||||
EPCGenericMemoryAccess::FuncAddrs FAs;
|
||||
if (auto Err = SREPC.getBootstrapSymbols(
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include "llvm/ExecutionEngine/Orc/LLJIT.h"
|
||||
#include "llvm/ExecutionEngine/Orc/ObjectTransformLayer.h"
|
||||
#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
|
||||
#include "llvm/ExecutionEngine/Orc/SelfExecutorProcessControl.h"
|
||||
#include "llvm/ExecutionEngine/Orc/SimpleRemoteEPC.h"
|
||||
#include "llvm/ExecutionEngine/Orc/SymbolStringPool.h"
|
||||
#include "llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h"
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#include "llvm/ExecutionEngine/Orc/MapperJITLinkMemoryManager.h"
|
||||
#include "llvm/ExecutionEngine/Orc/ObjectFileInterface.h"
|
||||
#include "llvm/ExecutionEngine/Orc/SectCreate.h"
|
||||
#include "llvm/ExecutionEngine/Orc/SelfExecutorProcessControl.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h"
|
||||
#include "llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h"
|
||||
#include "llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderPerf.h"
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "llvm/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManager.h"
|
||||
|
||||
#include "llvm/ADT/DenseMap.h"
|
||||
#include "llvm/ExecutionEngine/Orc/SelfExecutorProcessControl.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h"
|
||||
#include "llvm/Support/FormatVariadic.h"
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "OrcTestCommon.h"
|
||||
|
||||
#include "llvm/ExecutionEngine/Orc/EPCGenericMemoryAccess.h"
|
||||
#include "llvm/ExecutionEngine/Orc/SelfExecutorProcessControl.h"
|
||||
#include "llvm/Testing/Support/Error.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "llvm/ExecutionEngine/Orc/AbsoluteSymbols.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Core.h"
|
||||
#include "llvm/ExecutionEngine/Orc/ExecutorProcessControl.h"
|
||||
#include "llvm/ExecutionEngine/Orc/SelfExecutorProcessControl.h"
|
||||
#include "llvm/Support/MSVCErrorWorkarounds.h"
|
||||
#include "llvm/Testing/Support/Error.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "llvm/ExecutionEngine/JITSymbol.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Core.h"
|
||||
#include "llvm/ExecutionEngine/Orc/ExecutorProcessControl.h"
|
||||
#include "llvm/ExecutionEngine/Orc/InProcessMemoryAccess.h"
|
||||
#include "llvm/ExecutionEngine/Orc/IndirectionUtils.h"
|
||||
#include "llvm/IR/Function.h"
|
||||
#include "llvm/IR/IRBuilder.h"
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
|
||||
#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
|
||||
#include "llvm/ExecutionEngine/Orc/ObjectTransformLayer.h"
|
||||
#include "llvm/ExecutionEngine/Orc/SelfExecutorProcessControl.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h"
|
||||
#include "llvm/IR/IRBuilder.h"
|
||||
#include "llvm/Support/CodeGen.h"
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "OrcTestCommon.h"
|
||||
#include "llvm/Config/llvm-config.h" // for LLVM_ON_UNIX
|
||||
#include "llvm/ExecutionEngine/Orc/MemoryMapper.h"
|
||||
#include "llvm/ExecutionEngine/Orc/SelfExecutorProcessControl.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h"
|
||||
#include "llvm/ExecutionEngine/Orc/TargetProcess/ExecutorSharedMemoryMapperService.h"
|
||||
#include "llvm/Testing/Support/Error.h"
|
||||
|
||||
Reference in New Issue
Block a user