From: Lang Hames Date: Sun, 12 Feb 2023 20:34:20 +0000 (-0800) Subject: [ORC] Add MachOPlatform::Create overload -- Pass ORC runtime as def generator. X-Git-Tag: upstream/17.0.6~17785 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=be2fc577c38921c95811715a1ba1b3a149ba5e73;p=platform%2Fupstream%2Fllvm.git [ORC] Add MachOPlatform::Create overload -- Pass ORC runtime as def generator. The existing Create method took a path to the ORC runtime and created a StaticLibraryDefinitionGenerator for it. The new overload takes a std::unique_ptr directly instead. This provides more flexibility when constructing MachOPlatforms. E.g. The runtime archive can be embedded in a special section in the ORC controller executable or library, rather than being on-disk. --- diff --git a/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h b/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h index ad7e3f5..a8b32f8 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h @@ -79,6 +79,12 @@ public: /// setting up all aliases (including the required ones). static Expected> Create(ExecutionSession &ES, ObjectLinkingLayer &ObjLinkingLayer, + JITDylib &PlatformJD, std::unique_ptr OrcRuntime, + std::optional RuntimeAliases = std::nullopt); + + /// Construct using a path to the ORC runtime. + static Expected> + Create(ExecutionSession &ES, ObjectLinkingLayer &ObjLinkingLayer, JITDylib &PlatformJD, const char *OrcRuntimePath, std::optional RuntimeAliases = std::nullopt); diff --git a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp index 7e6a71d..b23f3cd 100644 --- a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp +++ b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp @@ -254,7 +254,8 @@ namespace orc { Expected> MachOPlatform::Create(ExecutionSession &ES, ObjectLinkingLayer &ObjLinkingLayer, - JITDylib &PlatformJD, const char *OrcRuntimePath, + JITDylib &PlatformJD, + std::unique_ptr OrcRuntime, std::optional RuntimeAliases) { auto &EPC = ES.getExecutorProcessControl(); @@ -283,22 +284,32 @@ MachOPlatform::Create(ExecutionSession &ES, ObjectLinkingLayer &ObjLinkingLayer, JITSymbolFlags::Exported}}}))) return std::move(Err); - // Create a generator for the ORC runtime archive. - auto OrcRuntimeArchiveGenerator = StaticLibraryDefinitionGenerator::Load( - ObjLinkingLayer, OrcRuntimePath, EPC.getTargetTriple()); - if (!OrcRuntimeArchiveGenerator) - return OrcRuntimeArchiveGenerator.takeError(); - // Create the instance. Error Err = Error::success(); - auto P = std::unique_ptr( - new MachOPlatform(ES, ObjLinkingLayer, PlatformJD, - std::move(*OrcRuntimeArchiveGenerator), Err)); + auto P = std::unique_ptr(new MachOPlatform( + ES, ObjLinkingLayer, PlatformJD, std::move(OrcRuntime), Err)); if (Err) return std::move(Err); return std::move(P); } +Expected> +MachOPlatform::Create(ExecutionSession &ES, ObjectLinkingLayer &ObjLinkingLayer, + JITDylib &PlatformJD, const char *OrcRuntimePath, + std::optional RuntimeAliases) { + + // Create a generator for the ORC runtime archive. + auto OrcRuntimeArchiveGenerator = StaticLibraryDefinitionGenerator::Load( + ObjLinkingLayer, OrcRuntimePath, + ES.getExecutorProcessControl().getTargetTriple()); + if (!OrcRuntimeArchiveGenerator) + return OrcRuntimeArchiveGenerator.takeError(); + + return Create(ES, ObjLinkingLayer, PlatformJD, + std::move(*OrcRuntimeArchiveGenerator), + std::move(RuntimeAliases)); +} + Error MachOPlatform::setupJITDylib(JITDylib &JD) { if (auto Err = JD.define(std::make_unique( *this, MachOHeaderStartSymbol)))