[llvm] f1aa49a - [Orc] Use MapperJITLinkMemoryManager with SharedMemoryMapper in llvm-jitlink tool
Anubhab Ghosh via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 28 02:28:20 PDT 2022
Author: Anubhab Ghosh
Date: 2022-08-28T14:29:53+05:30
New Revision: f1aa49ad34cea553884a036d029ab4c7148f42bd
URL: https://github.com/llvm/llvm-project/commit/f1aa49ad34cea553884a036d029ab4c7148f42bd
DIFF: https://github.com/llvm/llvm-project/commit/f1aa49ad34cea553884a036d029ab4c7148f42bd.diff
LOG: [Orc] Use MapperJITLinkMemoryManager with SharedMemoryMapper in llvm-jitlink tool
MapperJITLinkMemoryManager combined with SharedMemoryMapper can be
used in place of EPCGenericJITLinkMemoryManager when running on top of
same physical memory. This commit enables it when --use-shared-memory is
passed.
Differential Revision: https://reviews.llvm.org/D132369
Added:
Modified:
llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp
llvm/tools/llvm-jitlink/llvm-jitlink.cpp
Removed:
################################################################################
diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp
index 34246ca4a39a5..71c83f2badb8f 100644
--- a/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp
@@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/ADT/StringRef.h"
+#include "llvm/ExecutionEngine/Orc/TargetProcess/ExecutorSharedMemoryMapperService.h"
#include "llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h"
#include "llvm/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.h"
#include "llvm/ExecutionEngine/Orc/TargetProcess/SimpleExecutorMemoryManager.h"
@@ -164,6 +165,9 @@ int main(int argc, char *argv[]) {
SimpleRemoteEPCServer::defaultBootstrapSymbols();
S.services().push_back(
std::make_unique<rt_bootstrap::SimpleExecutorMemoryManager>());
+ S.services().push_back(
+ std::make_unique<
+ rt_bootstrap::ExecutorSharedMemoryMapperService>());
return Error::success();
},
InFD, OutFD));
diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
index 117d02f7bff9f..53c708fd77e24 100644
--- a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
@@ -28,6 +28,7 @@
#include "llvm/ExecutionEngine/Orc/MachOPlatform.h"
#include "llvm/ExecutionEngine/Orc/MapperJITLinkMemoryManager.h"
#include "llvm/ExecutionEngine/Orc/ObjectFileInterface.h"
+#include "llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h"
#include "llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h"
#include "llvm/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.h"
#include "llvm/MC/MCAsmInfo.h"
@@ -237,6 +238,11 @@ static cl::opt<bool>
cl::desc("Show FailedToMaterialize errors"),
cl::init(false), cl::cat(JITLinkCategory));
+static cl::opt<bool> UseSharedMemory(
+ "use-shared-memory",
+ cl::desc("Use shared memory to transfer generated code and data"),
+ cl::init(false), cl::cat(JITLinkCategory));
+
static ExitOnError ExitOnErr;
static LLVM_ATTRIBUTE_USED void linkComponents() {
@@ -814,6 +820,35 @@ static std::unique_ptr<JITLinkMemoryManager> createInProcessMemoryManager() {
#endif
}
+Expected<std::unique_ptr<jitlink::JITLinkMemoryManager>>
+createSharedMemoryManager(SimpleRemoteEPC &SREPC) {
+ SharedMemoryMapper::SymbolAddrs SAs;
+ if (auto Err = SREPC.getBootstrapSymbols(
+ {{SAs.Instance, rt::ExecutorSharedMemoryMapperServiceInstanceName},
+ {SAs.Reserve,
+ rt::ExecutorSharedMemoryMapperServiceReserveWrapperName},
+ {SAs.Initialize,
+ rt::ExecutorSharedMemoryMapperServiceInitializeWrapperName},
+ {SAs.Deinitialize,
+ rt::ExecutorSharedMemoryMapperServiceDeinitializeWrapperName},
+ {SAs.Release,
+ rt::ExecutorSharedMemoryMapperServiceReleaseWrapperName}}))
+ return std::move(Err);
+
+#ifdef _WIN32
+ size_t SlabSize = 1024 * 1024;
+#else
+ size_t SlabSize = 1024 * 1024 * 1024;
+#endif
+
+ if (!SlabAllocateSizeString.empty())
+ SlabSize = ExitOnErr(getSlabAllocSize(SlabAllocateSizeString));
+
+ return MapperJITLinkMemoryManager::CreateWithMapper<SharedMemoryMapper>(
+ SlabSize, SREPC, SAs);
+} size_t SlabSize = 1024 * 1024 * 1024;
+
+
static Expected<MaterializationUnit::Interface>
getTestObjectFileInterface(Session &S, MemoryBufferRef O) {
@@ -970,9 +1005,13 @@ static Expected<std::unique_ptr<ExecutorProcessControl>> launchExecutor() {
close(ToExecutor[ReadEnd]);
close(FromExecutor[WriteEnd]);
+ auto S = SimpleRemoteEPC::Setup();
+ if (UseSharedMemory)
+ S.CreateMemoryManager = createSharedMemoryManager;
+
return SimpleRemoteEPC::Create<FDSimpleRemoteEPCTransport>(
- std::make_unique<DynamicThreadPoolTaskDispatcher>(),
- SimpleRemoteEPC::Setup(), FromExecutor[ReadEnd], ToExecutor[WriteEnd]);
+ std::make_unique<DynamicThreadPoolTaskDispatcher>(), std::move(S),
+ FromExecutor[ReadEnd], ToExecutor[WriteEnd]);
#endif
}
@@ -1056,9 +1095,13 @@ static Expected<std::unique_ptr<ExecutorProcessControl>> connectToExecutor() {
if (!SockFD)
return SockFD.takeError();
+ auto S = SimpleRemoteEPC::Setup();
+ if (UseSharedMemory)
+ S.CreateMemoryManager = createSharedMemoryManager;
+
return SimpleRemoteEPC::Create<FDSimpleRemoteEPCTransport>(
std::make_unique<DynamicThreadPoolTaskDispatcher>(),
- SimpleRemoteEPC::Setup(), *SockFD, *SockFD);
+ std::move(S), *SockFD, *SockFD);
#endif
}
More information about the llvm-commits
mailing list