aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLang Hames <lhames@gmail.com>2023-02-21 21:22:28 -0800
committerLang Hames <lhames@gmail.com>2023-03-01 15:37:09 -0800
commit38d16f509a3faff3c545da5bfd5a8bcbd234ff24 (patch)
tree796c040be72ae29eaf3de608068916eca5a366f3
parenteffd56b0a03080d3d5460036efc425796bfc8882 (diff)
downloadllvm-38d16f509a3faff3c545da5bfd5a8bcbd234ff24.zip
llvm-38d16f509a3faff3c545da5bfd5a8bcbd234ff24.tar.gz
llvm-38d16f509a3faff3c545da5bfd5a8bcbd234ff24.tar.bz2
[ORC] Drop StaticLibraryDefinitionGenerator Load/Create overloads with triples.
We can get the triple from the ExecutionSession, so clients shouldn't have to provide it.
-rw-r--r--llvm/include/llvm/ExecutionEngine/Orc/ExecutionUtils.h20
-rw-r--r--llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp4
-rw-r--r--llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp43
-rw-r--r--llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp4
-rw-r--r--llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp28
-rw-r--r--llvm/tools/lli/lli.cpp2
-rw-r--r--llvm/tools/llvm-jitlink/llvm-jitlink.cpp3
7 files changed, 32 insertions, 72 deletions
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<std::unique_ptr<StaticLibraryDefinitionGenerator>>
- 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<std::unique_ptr<StaticLibraryDefinitionGenerator>>
- 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<std::unique_ptr<StaticLibraryDefinitionGenerator>>
- Create(ObjectLayer &L, std::unique_ptr<MemoryBuffer> 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<std::unique_ptr<StaticLibraryDefinitionGenerator>>
Create(ObjectLayer &L, std::unique_ptr<MemoryBuffer> 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<SymbolAliasMap> 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<std::unique_ptr<StaticLibraryDefinitionGenerator>>
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<std::unique_ptr<StaticLibraryDefinitionGenerator>>
-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<object::Archive>(B->getBinary()))
- return Create(L, std::move(B->takeBinary().second),
+ if (isa<object::Archive>(B->getBinary())) {
+ auto [Archive, ArchiveBuffer] = B->takeBinary();
+ return Create(L, std::move(ArchiveBuffer),
+ std::unique_ptr<object::Archive>(
+ static_cast<object::Archive *>(Archive.release())),
std::move(GetObjFileInterface));
+ }
// If this is a universal binary then search for a slice matching the given
// Triple.
if (auto *UB = cast<object::MachOUniversalBinary>(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<MemoryBuffer> 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<std::unique_ptr<StaticLibraryDefinitionGenerator>>
-StaticLibraryDefinitionGenerator::Create(
- ObjectLayer &L, std::unique_ptr<MemoryBuffer> 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<object::Archive>(*B))
- return Create(L, std::move(ArchiveBuffer), std::move(GetObjFileInterface));
+ return Create(L, std::move(ArchiveBuffer),
+ std::unique_ptr<object::Archive>(
+ static_cast<object::Archive *>(B->release())),
+ std::move(GetObjFileInterface));
// If this is a universal binary then search for a slice matching the given
// Triple.
if (auto *UB = cast<object::MachOUniversalBinary>(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<SymbolAliasMap> 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();