[llvm] [ORC] Extract MemoryAccess from ExecutorProcessControl, break up header. (PR #145671)
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 25 03:56:16 PDT 2025
https://github.com/lhames created https://github.com/llvm/llvm-project/pull/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.
>From aaf73c2bb761580f490504c4693836fe6e01617c Mon Sep 17 00:00:00 2001
From: Lang Hames <lhames at gmail.com>
Date: Wed, 25 Jun 2025 20:44:09 +1000
Subject: [PATCH] [ORC] Extract MemoryAccess from ExecutorProcessControl, break
up header.
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.
---
.../BuildingAJIT/Chapter1/KaleidoscopeJIT.h | 1 +
.../BuildingAJIT/Chapter2/KaleidoscopeJIT.h | 1 +
.../BuildingAJIT/Chapter3/KaleidoscopeJIT.h | 1 +
.../BuildingAJIT/Chapter4/KaleidoscopeJIT.h | 1 +
.../Kaleidoscope/include/KaleidoscopeJIT.h | 1 +
.../LLJITWithExecutorProcessControl.cpp | 1 +
.../Orc/EPCGenericMemoryAccess.h | 2 +-
.../Orc/ExecutorProcessControl.h | 159 +------------
.../Orc/InProcessMemoryAccess.h | 47 ++++
.../llvm/ExecutionEngine/Orc/MemoryAccess.h | 101 ++++++++
.../Orc/SelfExecutorProcessControl.h | 76 ++++++
llvm/lib/ExecutionEngine/Orc/CMakeLists.txt | 2 +
.../Orc/ExecutorProcessControl.cpp | 218 +-----------------
.../Orc/InProcessMemoryAccess.cpp | 64 +++++
llvm/lib/ExecutionEngine/Orc/LLJIT.cpp | 1 +
.../Orc/SelfExecutorProcessControl.cpp | 172 ++++++++++++++
.../ExecutionEngine/Orc/SimpleRemoteEPC.cpp | 2 +-
llvm/tools/lli/lli.cpp | 1 +
llvm/tools/llvm-jitlink/llvm-jitlink.cpp | 1 +
.../EPCGenericJITLinkMemoryManagerTest.cpp | 1 +
.../Orc/EPCGenericMemoryAccessTest.cpp | 1 +
...ecutionSessionWrapperFunctionCallsTest.cpp | 1 +
.../ExecutionEngine/Orc/OrcTestCommon.h | 1 +
.../Orc/ReOptimizeLayerTest.cpp | 1 +
.../Orc/SharedMemoryMapperTest.cpp | 1 +
25 files changed, 486 insertions(+), 372 deletions(-)
create mode 100644 llvm/include/llvm/ExecutionEngine/Orc/InProcessMemoryAccess.h
create mode 100644 llvm/include/llvm/ExecutionEngine/Orc/MemoryAccess.h
create mode 100644 llvm/include/llvm/ExecutionEngine/Orc/SelfExecutorProcessControl.h
create mode 100644 llvm/lib/ExecutionEngine/Orc/InProcessMemoryAccess.cpp
create mode 100644 llvm/lib/ExecutionEngine/Orc/SelfExecutorProcessControl.cpp
diff --git a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h
index 73a7b5b38a385..7800dca5fd375 100644
--- a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h
+++ b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h
@@ -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"
diff --git a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h
index d2bedd2c7270f..1789ab1e20fef 100644
--- a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h
+++ b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.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"
diff --git a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h
index 09b87b0181f92..643c089b4ed8d 100644
--- a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h
+++ b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.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"
diff --git a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h
index 30c0e239a6cb4..0e2e9fe729bba 100644
--- a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h
+++ b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.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"
diff --git a/llvm/examples/Kaleidoscope/include/KaleidoscopeJIT.h b/llvm/examples/Kaleidoscope/include/KaleidoscopeJIT.h
index 65f94ed7a80d6..1fc89fca1e1da 100644
--- a/llvm/examples/Kaleidoscope/include/KaleidoscopeJIT.h
+++ b/llvm/examples/Kaleidoscope/include/KaleidoscopeJIT.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"
diff --git a/llvm/examples/OrcV2Examples/LLJITWithExecutorProcessControl/LLJITWithExecutorProcessControl.cpp b/llvm/examples/OrcV2Examples/LLJITWithExecutorProcessControl/LLJITWithExecutorProcessControl.cpp
index 043150f47d926..4f58d1aa82a65 100644
--- a/llvm/examples/OrcV2Examples/LLJITWithExecutorProcessControl/LLJITWithExecutorProcessControl.cpp
+++ b/llvm/examples/OrcV2Examples/LLJITWithExecutorProcessControl/LLJITWithExecutorProcessControl.cpp
@@ -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"
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/EPCGenericMemoryAccess.h b/llvm/include/llvm/ExecutionEngine/Orc/EPCGenericMemoryAccess.h
index bc1f5f0eb70cb..e1815e4d303ad 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/EPCGenericMemoryAccess.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/EPCGenericMemoryAccess.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 {
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/ExecutorProcessControl.h b/llvm/include/llvm/ExecutionEngine/Orc/ExecutorProcessControl.h
index 6fce74ddf72fe..90b0b4fbb2595 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/ExecutorProcessControl.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/ExecutorProcessControl.h
@@ -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 @@ class LLVM_ABI ExecutorProcessControl {
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 @@ class LLVM_ABI ExecutorProcessControl {
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
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/InProcessMemoryAccess.h b/llvm/include/llvm/ExecutionEngine/Orc/InProcessMemoryAccess.h
new file mode 100644
index 0000000000000..934f6f62ffab0
--- /dev/null
+++ b/llvm/include/llvm/ExecutionEngine/Orc/InProcessMemoryAccess.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
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/MemoryAccess.h b/llvm/include/llvm/ExecutionEngine/Orc/MemoryAccess.h
new file mode 100644
index 0000000000000..f4b34978f247c
--- /dev/null
+++ b/llvm/include/llvm/ExecutionEngine/Orc/MemoryAccess.h
@@ -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
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/SelfExecutorProcessControl.h b/llvm/include/llvm/ExecutionEngine/Orc/SelfExecutorProcessControl.h
new file mode 100644
index 0000000000000..805ac89aa9125
--- /dev/null
+++ b/llvm/include/llvm/ExecutionEngine/Orc/SelfExecutorProcessControl.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
diff --git a/llvm/lib/ExecutionEngine/Orc/CMakeLists.txt b/llvm/lib/ExecutionEngine/Orc/CMakeLists.txt
index 6c86f252bf7ea..f159d59fa3ace 100644
--- a/llvm/lib/ExecutionEngine/Orc/CMakeLists.txt
+++ b/llvm/lib/ExecutionEngine/Orc/CMakeLists.txt
@@ -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
diff --git a/llvm/lib/ExecutionEngine/Orc/ExecutorProcessControl.cpp b/llvm/lib/ExecutionEngine/Orc/ExecutorProcessControl.cpp
index 854e6d7135860..9b3bae4e6d2a4 100644
--- a/llvm/lib/ExecutionEngine/Orc/ExecutorProcessControl.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/ExecutorProcessControl.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
diff --git a/llvm/lib/ExecutionEngine/Orc/InProcessMemoryAccess.cpp b/llvm/lib/ExecutionEngine/Orc/InProcessMemoryAccess.cpp
new file mode 100644
index 0000000000000..c8b2f00bc199d
--- /dev/null
+++ b/llvm/lib/ExecutionEngine/Orc/InProcessMemoryAccess.cpp
@@ -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
diff --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
index f1a71e4acb46d..4e3c09e970cbe 100644
--- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
@@ -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"
diff --git a/llvm/lib/ExecutionEngine/Orc/SelfExecutorProcessControl.cpp b/llvm/lib/ExecutionEngine/Orc/SelfExecutorProcessControl.cpp
new file mode 100644
index 0000000000000..78045f1491f04
--- /dev/null
+++ b/llvm/lib/ExecutionEngine/Orc/SelfExecutorProcessControl.cpp
@@ -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
diff --git a/llvm/lib/ExecutionEngine/Orc/SimpleRemoteEPC.cpp b/llvm/lib/ExecutionEngine/Orc/SimpleRemoteEPC.cpp
index 3d816785cb76d..746b843499101 100644
--- a/llvm/lib/ExecutionEngine/Orc/SimpleRemoteEPC.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/SimpleRemoteEPC.cpp
@@ -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(
diff --git a/llvm/tools/lli/lli.cpp b/llvm/tools/lli/lli.cpp
index ed1a80d3c1bc9..ba628079170d5 100644
--- a/llvm/tools/lli/lli.cpp
+++ b/llvm/tools/lli/lli.cpp
@@ -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"
diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
index df356178b1168..de8dc16f2eba9 100644
--- a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
@@ -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"
diff --git a/llvm/unittests/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManagerTest.cpp b/llvm/unittests/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManagerTest.cpp
index 6c04ab774c2e9..d4b45ea0dca0b 100644
--- a/llvm/unittests/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManagerTest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManagerTest.cpp
@@ -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"
diff --git a/llvm/unittests/ExecutionEngine/Orc/EPCGenericMemoryAccessTest.cpp b/llvm/unittests/ExecutionEngine/Orc/EPCGenericMemoryAccessTest.cpp
index 3eec564ee629f..d54bcd4fd5218 100644
--- a/llvm/unittests/ExecutionEngine/Orc/EPCGenericMemoryAccessTest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/EPCGenericMemoryAccessTest.cpp
@@ -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;
diff --git a/llvm/unittests/ExecutionEngine/Orc/ExecutionSessionWrapperFunctionCallsTest.cpp b/llvm/unittests/ExecutionEngine/Orc/ExecutionSessionWrapperFunctionCallsTest.cpp
index 80b9c157f7623..908d9aa31c66d 100644
--- a/llvm/unittests/ExecutionEngine/Orc/ExecutionSessionWrapperFunctionCallsTest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/ExecutionSessionWrapperFunctionCallsTest.cpp
@@ -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"
diff --git a/llvm/unittests/ExecutionEngine/Orc/OrcTestCommon.h b/llvm/unittests/ExecutionEngine/Orc/OrcTestCommon.h
index 6675921c29eb4..469de2a3665a0 100644
--- a/llvm/unittests/ExecutionEngine/Orc/OrcTestCommon.h
+++ b/llvm/unittests/ExecutionEngine/Orc/OrcTestCommon.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"
diff --git a/llvm/unittests/ExecutionEngine/Orc/ReOptimizeLayerTest.cpp b/llvm/unittests/ExecutionEngine/Orc/ReOptimizeLayerTest.cpp
index 71fd255a68c8b..962277fb4a0cb 100644
--- a/llvm/unittests/ExecutionEngine/Orc/ReOptimizeLayerTest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/ReOptimizeLayerTest.cpp
@@ -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"
diff --git a/llvm/unittests/ExecutionEngine/Orc/SharedMemoryMapperTest.cpp b/llvm/unittests/ExecutionEngine/Orc/SharedMemoryMapperTest.cpp
index 0449ec6f7fbc0..700500f41d885 100644
--- a/llvm/unittests/ExecutionEngine/Orc/SharedMemoryMapperTest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/SharedMemoryMapperTest.cpp
@@ -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"
More information about the llvm-commits
mailing list