From 38d16f509a3faff3c545da5bfd5a8bcbd234ff24 Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Tue, 21 Feb 2023 21:22:28 -0800 Subject: [ORC] Drop StaticLibraryDefinitionGenerator Load/Create overloads with triples. We can get the triple from the ExecutionSession, so clients shouldn't have to provide it. --- .../llvm/ExecutionEngine/Orc/ExecutionUtils.h | 20 ++-------- llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp | 4 +- llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp | 43 ++++++++-------------- llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp | 4 +- llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp | 28 ++++---------- llvm/tools/lli/lli.cpp | 2 +- llvm/tools/llvm-jitlink/llvm-jitlink.cpp | 3 +- 7 files changed, 32 insertions(+), 72 deletions(-) (limited to 'llvm') diff --git a/llvm/include/llvm/ExecutionEngine/Orc/ExecutionUtils.h b/llvm/include/llvm/ExecutionEngine/Orc/ExecutionUtils.h index 4d2b228..6f3af2b 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/ExecutionUtils.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/ExecutionUtils.h @@ -271,18 +271,10 @@ public: /// Try to create a StaticLibraryDefinitionGenerator from the given path. /// /// This call will succeed if the file at the given path is a static library - /// is a valid archive, otherwise it will return an error. - static Expected> - Load(ObjectLayer &L, const char *FileName, - GetObjectFileInterface GetObjFileInterface = GetObjectFileInterface()); - - /// Try to create a StaticLibraryDefinitionGenerator from the given path. - /// - /// This call will succeed if the file at the given path is a static library /// or a MachO universal binary containing a static library that is compatible - /// with the given triple. Otherwise it will return an error. + /// with the ExecutionSession's triple. Otherwise it will return an error. static Expected> - Load(ObjectLayer &L, const char *FileName, const Triple &TT, + Load(ObjectLayer &L, const char *FileName, GetObjectFileInterface GetObjFileInterface = GetObjectFileInterface()); /// Try to create a StaticLibrarySearchGenerator from the given memory buffer @@ -295,18 +287,12 @@ public: /// Try to create a StaticLibrarySearchGenerator from the given memory buffer. /// This call will succeed if the buffer contains a valid archive, otherwise /// it will return an error. - static Expected> - Create(ObjectLayer &L, std::unique_ptr ArchiveBuffer, - GetObjectFileInterface GetObjFileInterface = GetObjectFileInterface()); - - /// Try to create a StaticLibrarySearchGenerator from the given memory buffer. /// /// This call will succeed if the buffer contains a valid static library or a /// MachO universal binary containing a static library that is compatible - /// with the given triple. Otherwise it will return an error. + /// with the ExecutionSession's triple. Otherwise it will return an error. static Expected> Create(ObjectLayer &L, std::unique_ptr ArchiveBuffer, - const Triple &TT, GetObjectFileInterface GetObjFileInterface = GetObjectFileInterface()); /// Returns a list of filenames of dynamic libraries that this archive has diff --git a/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp b/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp index cbf0788..cd78105 100644 --- a/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp +++ b/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp @@ -152,8 +152,8 @@ ELFNixPlatform::Create(ExecutionSession &ES, std::optional RuntimeAliases) { // Create a generator for the ORC runtime archive. - auto OrcRuntimeArchiveGenerator = StaticLibraryDefinitionGenerator::Load( - ObjLinkingLayer, OrcRuntimePath, ES.getTargetTriple()); + auto OrcRuntimeArchiveGenerator = + StaticLibraryDefinitionGenerator::Load(ObjLinkingLayer, OrcRuntimePath); if (!OrcRuntimeArchiveGenerator) return OrcRuntimeArchiveGenerator.takeError(); diff --git a/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp b/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp index b6fb769..7795bac 100644 --- a/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp +++ b/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp @@ -274,32 +274,26 @@ Expected> StaticLibraryDefinitionGenerator::Load( ObjectLayer &L, const char *FileName, GetObjectFileInterface GetObjFileInterface) { - auto ArchiveBuffer = MemoryBuffer::getFile(FileName); - - if (!ArchiveBuffer) - return createFileError(FileName, ArchiveBuffer.getError()); - - return Create(L, std::move(*ArchiveBuffer), std::move(GetObjFileInterface)); -} - -Expected> -StaticLibraryDefinitionGenerator::Load( - ObjectLayer &L, const char *FileName, const Triple &TT, - GetObjectFileInterface GetObjFileInterface) { auto B = object::createBinary(FileName); if (!B) return createFileError(FileName, B.takeError()); // If this is a regular archive then create an instance from it. - if (isa(B->getBinary())) - return Create(L, std::move(B->takeBinary().second), + if (isa(B->getBinary())) { + auto [Archive, ArchiveBuffer] = B->takeBinary(); + return Create(L, std::move(ArchiveBuffer), + std::unique_ptr( + static_cast(Archive.release())), std::move(GetObjFileInterface)); + } // If this is a universal binary then search for a slice matching the given // Triple. if (auto *UB = cast(B->getBinary())) { + const auto &TT = L.getExecutionSession().getTargetTriple(); + auto SliceRange = getSliceRangeForArch(*UB, TT); if (!SliceRange) return SliceRange.takeError(); @@ -346,30 +340,23 @@ StaticLibraryDefinitionGenerator::Create( ObjectLayer &L, std::unique_ptr ArchiveBuffer, GetObjectFileInterface GetObjFileInterface) { - auto Archive = object::Archive::create(ArchiveBuffer->getMemBufferRef()); - if (!Archive) - return Archive.takeError(); - - return Create(L, std::move(ArchiveBuffer), std::move(*Archive), - std::move(GetObjFileInterface)); -} - -Expected> -StaticLibraryDefinitionGenerator::Create( - ObjectLayer &L, std::unique_ptr ArchiveBuffer, - const Triple &TT, GetObjectFileInterface GetObjFileInterface) { - auto B = object::createBinary(ArchiveBuffer->getMemBufferRef()); if (!B) return B.takeError(); // If this is a regular archive then create an instance from it. if (isa(*B)) - return Create(L, std::move(ArchiveBuffer), std::move(GetObjFileInterface)); + return Create(L, std::move(ArchiveBuffer), + std::unique_ptr( + static_cast(B->release())), + std::move(GetObjFileInterface)); // If this is a universal binary then search for a slice matching the given // Triple. if (auto *UB = cast(B->get())) { + + const auto &TT = L.getExecutionSession().getTargetTriple(); + auto SliceRange = getSliceRangeForArch(*UB, TT); if (!SliceRange) return SliceRange.takeError(); diff --git a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp index f21cb71..abc1e0a 100644 --- a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp +++ b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp @@ -298,8 +298,8 @@ MachOPlatform::Create(ExecutionSession &ES, ObjectLinkingLayer &ObjLinkingLayer, std::optional RuntimeAliases) { // Create a generator for the ORC runtime archive. - auto OrcRuntimeArchiveGenerator = StaticLibraryDefinitionGenerator::Load( - ObjLinkingLayer, OrcRuntimePath, ES.getTargetTriple()); + auto OrcRuntimeArchiveGenerator = + StaticLibraryDefinitionGenerator::Load(ObjLinkingLayer, OrcRuntimePath); if (!OrcRuntimeArchiveGenerator) return OrcRuntimeArchiveGenerator.takeError(); diff --git a/llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp b/llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp index b823197..945e9ce 100644 --- a/llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp +++ b/llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp @@ -741,31 +741,19 @@ LLVMErrorRef LLVMOrcCreateDynamicLibrarySearchGeneratorForPath( LLVMErrorRef LLVMOrcCreateStaticLibrarySearchGeneratorForPath( LLVMOrcDefinitionGeneratorRef *Result, LLVMOrcObjectLayerRef ObjLayer, - const char *FileName, const char *TargetTriple) { + const char *FileName) { assert(Result && "Result can not be null"); assert(FileName && "Filename can not be null"); assert(ObjLayer && "ObjectLayer can not be null"); - if (TargetTriple) { - auto TT = Triple(TargetTriple); - auto LibrarySymsGenerator = - StaticLibraryDefinitionGenerator::Load(*unwrap(ObjLayer), FileName, TT); - if (!LibrarySymsGenerator) { - *Result = nullptr; - return wrap(LibrarySymsGenerator.takeError()); - } - *Result = wrap(LibrarySymsGenerator->release()); - return LLVMErrorSuccess; - } else { - auto LibrarySymsGenerator = - StaticLibraryDefinitionGenerator::Load(*unwrap(ObjLayer), FileName); - if (!LibrarySymsGenerator) { - *Result = nullptr; - return wrap(LibrarySymsGenerator.takeError()); - } - *Result = wrap(LibrarySymsGenerator->release()); - return LLVMErrorSuccess; + auto LibrarySymsGenerator = + StaticLibraryDefinitionGenerator::Load(*unwrap(ObjLayer), FileName); + if (!LibrarySymsGenerator) { + *Result = nullptr; + return wrap(LibrarySymsGenerator.takeError()); } + *Result = wrap(LibrarySymsGenerator->release()); + return LLVMErrorSuccess; } LLVMOrcThreadSafeContextRef LLVMOrcCreateNewThreadSafeContext(void) { diff --git a/llvm/tools/lli/lli.cpp b/llvm/tools/lli/lli.cpp index 37132d1..808ec88 100644 --- a/llvm/tools/lli/lli.cpp +++ b/llvm/tools/lli/lli.cpp @@ -1058,7 +1058,7 @@ int runOrcJIT(const char *ProgName) { auto JDItr = std::prev(IdxToDylib.lower_bound(EAIdx)); auto &JD = *JDItr->second; JD.addGenerator(ExitOnErr(orc::StaticLibraryDefinitionGenerator::Load( - J->getObjLinkingLayer(), EAItr->c_str(), *TT))); + J->getObjLinkingLayer(), EAItr->c_str()))); } } diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp index ed5d15b..be0fe17 100644 --- a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp +++ b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp @@ -1631,8 +1631,7 @@ static Error addLibraries(Session &S, break; } auto G = StaticLibraryDefinitionGenerator::Load( - S.ObjLayer, Path, S.ES.getTargetTriple(), - std::move(GetObjFileInterface)); + S.ObjLayer, Path, std::move(GetObjFileInterface)); if (!G) return G.takeError(); -- cgit v1.1