From 22641f585372dd228bf668bcf0c0e171f6ff26c3 Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Sun, 5 Sep 2021 18:29:05 +1000 Subject: [PATCH] [ORC] Use EPC for EPCGeneric MemoryAccess / JITLinkMemoryManager construction. This allows these classes to be created during EPC construction, before an ExecutionSession is available. --- .../Orc/EPCGenericJITLinkMemoryManager.h | 6 +++--- .../ExecutionEngine/Orc/EPCGenericMemoryAccess.h | 6 +++--- .../Orc/EPCGenericJITLinkMemoryManager.cpp | 21 +++++++++++-------- .../ExecutionEngine/Orc/EPCGenericMemoryAccess.cpp | 24 ++++++++++++---------- 4 files changed, 31 insertions(+), 26 deletions(-) diff --git a/llvm/include/llvm/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManager.h b/llvm/include/llvm/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManager.h index 6ad2351..0dd1e6a 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManager.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManager.h @@ -38,10 +38,10 @@ public: EPCGenericJITLinkMemoryManager(ExecutorProcessControl &EPC, FuncAddrs FAs) : EPC(EPC), FAs(FAs) {} - /// Create using the standard memory access function names from the ORC - /// runtime. + /// Create using the standard memory allocation function names from the + /// ORCTargetProcess library. static Expected> - CreateUsingOrcRTFuncs(ExecutionSession &ES, JITDylib &OrcRuntimeJD); + CreateUsingOrcRTFuncs(ExecutorProcessControl &EPC); Expected> allocate(const jitlink::JITLinkDylib *JD, diff --git a/llvm/include/llvm/ExecutionEngine/Orc/EPCGenericMemoryAccess.h b/llvm/include/llvm/ExecutionEngine/Orc/EPCGenericMemoryAccess.h index 20a4784..fe9d1c1 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/EPCGenericMemoryAccess.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/EPCGenericMemoryAccess.h @@ -39,10 +39,10 @@ public: EPCGenericMemoryAccess(ExecutorProcessControl &EPC, FuncAddrs FAs) : EPC(EPC), FAs(FAs) {} - /// Create using the standard memory access function names from the ORC - /// runtime. + /// Create using the standard memory access function names from the + /// ORCTargetProcess library. static Expected> - CreateUsingOrcRTFuncs(ExecutionSession &ES, JITDylib &OrcRuntimeJD); + CreateUsingOrcRTFuncs(ExecutorProcessControl &EPC); void writeUInt8sAsync(ArrayRef Ws, WriteResultFn OnWriteComplete) override { diff --git a/llvm/lib/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManager.cpp b/llvm/lib/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManager.cpp index 012ff73..ac6de22 100644 --- a/llvm/lib/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManager.cpp +++ b/llvm/lib/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManager.cpp @@ -88,25 +88,28 @@ private: /// Create from a ExecutorProcessControl instance. Expected> -EPCGenericJITLinkMemoryManager::CreateUsingOrcRTFuncs(ExecutionSession &ES, - JITDylib &OrcRuntimeJD) { +EPCGenericJITLinkMemoryManager::CreateUsingOrcRTFuncs( + ExecutorProcessControl &EPC) { + + auto H = EPC.loadDylib(""); + if (!H) + return H.takeError(); StringRef GlobalPrefix = ""; - if (ES.getExecutorProcessControl().getTargetTriple().isOSBinFormatMachO()) + if (EPC.getTargetTriple().isOSBinFormatMachO()) GlobalPrefix = "_"; FuncAddrs FAs; if (auto Err = lookupAndRecordAddrs( - ES, LookupKind::Static, makeJITDylibSearchOrder(&OrcRuntimeJD), - {{ES.intern((GlobalPrefix + "__orc_rt_reserve").str()), &FAs.Reserve}, - {ES.intern((GlobalPrefix + "__orc_rt_finalize").str()), + EPC, *H, + {{EPC.intern((GlobalPrefix + "__orc_rt_reserve").str()), &FAs.Reserve}, + {EPC.intern((GlobalPrefix + "__orc_rt_finalize").str()), &FAs.Finalize}, - {ES.intern((GlobalPrefix + "__orc_rt_deallocate").str()), + {EPC.intern((GlobalPrefix + "__orc_rt_deallocate").str()), &FAs.Deallocate}})) return std::move(Err); - return std::make_unique( - ES.getExecutorProcessControl(), FAs); + return std::make_unique(EPC, std::move(FAs)); } Expected> diff --git a/llvm/lib/ExecutionEngine/Orc/EPCGenericMemoryAccess.cpp b/llvm/lib/ExecutionEngine/Orc/EPCGenericMemoryAccess.cpp index 319909f..e4ecd47 100644 --- a/llvm/lib/ExecutionEngine/Orc/EPCGenericMemoryAccess.cpp +++ b/llvm/lib/ExecutionEngine/Orc/EPCGenericMemoryAccess.cpp @@ -14,30 +14,32 @@ namespace orc { /// Create from a ExecutorProcessControl instance. Expected> -EPCGenericMemoryAccess::CreateUsingOrcRTFuncs(ExecutionSession &ES, - JITDylib &OrcRuntimeJD) { +EPCGenericMemoryAccess::CreateUsingOrcRTFuncs(ExecutorProcessControl &EPC) { + + auto H = EPC.loadDylib(""); + if (!H) + return H.takeError(); StringRef GlobalPrefix = ""; - if (ES.getExecutorProcessControl().getTargetTriple().isOSBinFormatMachO()) + if (EPC.getTargetTriple().isOSBinFormatMachO()) GlobalPrefix = "_"; FuncAddrs FAs; if (auto Err = lookupAndRecordAddrs( - ES, LookupKind::Static, makeJITDylibSearchOrder(&OrcRuntimeJD), - {{ES.intern((GlobalPrefix + "__orc_rt_write_uint8s_wrapper").str()), + EPC, *H, + {{EPC.intern((GlobalPrefix + "__orc_rt_write_uint8s_wrapper").str()), &FAs.WriteUInt8s}, - {ES.intern((GlobalPrefix + "__orc_rt_write_uint16s_wrapper").str()), + {EPC.intern((GlobalPrefix + "__orc_rt_write_uint16s_wrapper").str()), &FAs.WriteUInt16s}, - {ES.intern((GlobalPrefix + "__orc_rt_write_uint32s_wrapper").str()), + {EPC.intern((GlobalPrefix + "__orc_rt_write_uint32s_wrapper").str()), &FAs.WriteUInt32s}, - {ES.intern((GlobalPrefix + "__orc_rt_write_uint64s_wrapper").str()), + {EPC.intern((GlobalPrefix + "__orc_rt_write_uint64s_wrapper").str()), &FAs.WriteUInt64s}, - {ES.intern((GlobalPrefix + "__orc_rt_write_buffers_wrapper").str()), + {EPC.intern((GlobalPrefix + "__orc_rt_write_buffers_wrapper").str()), &FAs.WriteBuffers}})) return std::move(Err); - return std::make_unique( - ES.getExecutorProcessControl(), FAs); + return std::make_unique(EPC, std::move(FAs)); } } // end namespace orc -- 2.7.4