Skip to content

Commit 38d16f5

Browse files
committed
[ORC] Drop StaticLibraryDefinitionGenerator Load/Create overloads with triples.
We can get the triple from the ExecutionSession, so clients shouldn't have to provide it.
1 parent effd56b commit 38d16f5

File tree

7 files changed

+32
-72
lines changed

7 files changed

+32
-72
lines changed

llvm/include/llvm/ExecutionEngine/Orc/ExecutionUtils.h

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -268,21 +268,13 @@ class StaticLibraryDefinitionGenerator : public DefinitionGenerator {
268268
unique_function<Expected<MaterializationUnit::Interface>(
269269
ExecutionSession &ES, MemoryBufferRef ObjBuffer)>;
270270

271-
/// Try to create a StaticLibraryDefinitionGenerator from the given path.
272-
///
273-
/// This call will succeed if the file at the given path is a static library
274-
/// is a valid archive, otherwise it will return an error.
275-
static Expected<std::unique_ptr<StaticLibraryDefinitionGenerator>>
276-
Load(ObjectLayer &L, const char *FileName,
277-
GetObjectFileInterface GetObjFileInterface = GetObjectFileInterface());
278-
279271
/// Try to create a StaticLibraryDefinitionGenerator from the given path.
280272
///
281273
/// This call will succeed if the file at the given path is a static library
282274
/// or a MachO universal binary containing a static library that is compatible
283-
/// with the given triple. Otherwise it will return an error.
275+
/// with the ExecutionSession's triple. Otherwise it will return an error.
284276
static Expected<std::unique_ptr<StaticLibraryDefinitionGenerator>>
285-
Load(ObjectLayer &L, const char *FileName, const Triple &TT,
277+
Load(ObjectLayer &L, const char *FileName,
286278
GetObjectFileInterface GetObjFileInterface = GetObjectFileInterface());
287279

288280
/// Try to create a StaticLibrarySearchGenerator from the given memory buffer
@@ -295,18 +287,12 @@ class StaticLibraryDefinitionGenerator : public DefinitionGenerator {
295287
/// Try to create a StaticLibrarySearchGenerator from the given memory buffer.
296288
/// This call will succeed if the buffer contains a valid archive, otherwise
297289
/// it will return an error.
298-
static Expected<std::unique_ptr<StaticLibraryDefinitionGenerator>>
299-
Create(ObjectLayer &L, std::unique_ptr<MemoryBuffer> ArchiveBuffer,
300-
GetObjectFileInterface GetObjFileInterface = GetObjectFileInterface());
301-
302-
/// Try to create a StaticLibrarySearchGenerator from the given memory buffer.
303290
///
304291
/// This call will succeed if the buffer contains a valid static library or a
305292
/// MachO universal binary containing a static library that is compatible
306-
/// with the given triple. Otherwise it will return an error.
293+
/// with the ExecutionSession's triple. Otherwise it will return an error.
307294
static Expected<std::unique_ptr<StaticLibraryDefinitionGenerator>>
308295
Create(ObjectLayer &L, std::unique_ptr<MemoryBuffer> ArchiveBuffer,
309-
const Triple &TT,
310296
GetObjectFileInterface GetObjFileInterface = GetObjectFileInterface());
311297

312298
/// Returns a list of filenames of dynamic libraries that this archive has

llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ ELFNixPlatform::Create(ExecutionSession &ES,
152152
std::optional<SymbolAliasMap> RuntimeAliases) {
153153

154154
// Create a generator for the ORC runtime archive.
155-
auto OrcRuntimeArchiveGenerator = StaticLibraryDefinitionGenerator::Load(
156-
ObjLinkingLayer, OrcRuntimePath, ES.getTargetTriple());
155+
auto OrcRuntimeArchiveGenerator =
156+
StaticLibraryDefinitionGenerator::Load(ObjLinkingLayer, OrcRuntimePath);
157157
if (!OrcRuntimeArchiveGenerator)
158158
return OrcRuntimeArchiveGenerator.takeError();
159159

llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -274,32 +274,26 @@ Expected<std::unique_ptr<StaticLibraryDefinitionGenerator>>
274274
StaticLibraryDefinitionGenerator::Load(
275275
ObjectLayer &L, const char *FileName,
276276
GetObjectFileInterface GetObjFileInterface) {
277-
auto ArchiveBuffer = MemoryBuffer::getFile(FileName);
278-
279-
if (!ArchiveBuffer)
280-
return createFileError(FileName, ArchiveBuffer.getError());
281-
282-
return Create(L, std::move(*ArchiveBuffer), std::move(GetObjFileInterface));
283-
}
284-
285-
Expected<std::unique_ptr<StaticLibraryDefinitionGenerator>>
286-
StaticLibraryDefinitionGenerator::Load(
287-
ObjectLayer &L, const char *FileName, const Triple &TT,
288-
GetObjectFileInterface GetObjFileInterface) {
289277

290278
auto B = object::createBinary(FileName);
291279
if (!B)
292280
return createFileError(FileName, B.takeError());
293281

294282
// If this is a regular archive then create an instance from it.
295-
if (isa<object::Archive>(B->getBinary()))
296-
return Create(L, std::move(B->takeBinary().second),
283+
if (isa<object::Archive>(B->getBinary())) {
284+
auto [Archive, ArchiveBuffer] = B->takeBinary();
285+
return Create(L, std::move(ArchiveBuffer),
286+
std::unique_ptr<object::Archive>(
287+
static_cast<object::Archive *>(Archive.release())),
297288
std::move(GetObjFileInterface));
289+
}
298290

299291
// If this is a universal binary then search for a slice matching the given
300292
// Triple.
301293
if (auto *UB = cast<object::MachOUniversalBinary>(B->getBinary())) {
302294

295+
const auto &TT = L.getExecutionSession().getTargetTriple();
296+
303297
auto SliceRange = getSliceRangeForArch(*UB, TT);
304298
if (!SliceRange)
305299
return SliceRange.takeError();
@@ -346,30 +340,23 @@ StaticLibraryDefinitionGenerator::Create(
346340
ObjectLayer &L, std::unique_ptr<MemoryBuffer> ArchiveBuffer,
347341
GetObjectFileInterface GetObjFileInterface) {
348342

349-
auto Archive = object::Archive::create(ArchiveBuffer->getMemBufferRef());
350-
if (!Archive)
351-
return Archive.takeError();
352-
353-
return Create(L, std::move(ArchiveBuffer), std::move(*Archive),
354-
std::move(GetObjFileInterface));
355-
}
356-
357-
Expected<std::unique_ptr<StaticLibraryDefinitionGenerator>>
358-
StaticLibraryDefinitionGenerator::Create(
359-
ObjectLayer &L, std::unique_ptr<MemoryBuffer> ArchiveBuffer,
360-
const Triple &TT, GetObjectFileInterface GetObjFileInterface) {
361-
362343
auto B = object::createBinary(ArchiveBuffer->getMemBufferRef());
363344
if (!B)
364345
return B.takeError();
365346

366347
// If this is a regular archive then create an instance from it.
367348
if (isa<object::Archive>(*B))
368-
return Create(L, std::move(ArchiveBuffer), std::move(GetObjFileInterface));
349+
return Create(L, std::move(ArchiveBuffer),
350+
std::unique_ptr<object::Archive>(
351+
static_cast<object::Archive *>(B->release())),
352+
std::move(GetObjFileInterface));
369353

370354
// If this is a universal binary then search for a slice matching the given
371355
// Triple.
372356
if (auto *UB = cast<object::MachOUniversalBinary>(B->get())) {
357+
358+
const auto &TT = L.getExecutionSession().getTargetTriple();
359+
373360
auto SliceRange = getSliceRangeForArch(*UB, TT);
374361
if (!SliceRange)
375362
return SliceRange.takeError();

llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,8 @@ MachOPlatform::Create(ExecutionSession &ES, ObjectLinkingLayer &ObjLinkingLayer,
298298
std::optional<SymbolAliasMap> RuntimeAliases) {
299299

300300
// Create a generator for the ORC runtime archive.
301-
auto OrcRuntimeArchiveGenerator = StaticLibraryDefinitionGenerator::Load(
302-
ObjLinkingLayer, OrcRuntimePath, ES.getTargetTriple());
301+
auto OrcRuntimeArchiveGenerator =
302+
StaticLibraryDefinitionGenerator::Load(ObjLinkingLayer, OrcRuntimePath);
303303
if (!OrcRuntimeArchiveGenerator)
304304
return OrcRuntimeArchiveGenerator.takeError();
305305

llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -741,31 +741,19 @@ LLVMErrorRef LLVMOrcCreateDynamicLibrarySearchGeneratorForPath(
741741

742742
LLVMErrorRef LLVMOrcCreateStaticLibrarySearchGeneratorForPath(
743743
LLVMOrcDefinitionGeneratorRef *Result, LLVMOrcObjectLayerRef ObjLayer,
744-
const char *FileName, const char *TargetTriple) {
744+
const char *FileName) {
745745
assert(Result && "Result can not be null");
746746
assert(FileName && "Filename can not be null");
747747
assert(ObjLayer && "ObjectLayer can not be null");
748748

749-
if (TargetTriple) {
750-
auto TT = Triple(TargetTriple);
751-
auto LibrarySymsGenerator =
752-
StaticLibraryDefinitionGenerator::Load(*unwrap(ObjLayer), FileName, TT);
753-
if (!LibrarySymsGenerator) {
754-
*Result = nullptr;
755-
return wrap(LibrarySymsGenerator.takeError());
756-
}
757-
*Result = wrap(LibrarySymsGenerator->release());
758-
return LLVMErrorSuccess;
759-
} else {
760-
auto LibrarySymsGenerator =
761-
StaticLibraryDefinitionGenerator::Load(*unwrap(ObjLayer), FileName);
762-
if (!LibrarySymsGenerator) {
763-
*Result = nullptr;
764-
return wrap(LibrarySymsGenerator.takeError());
765-
}
766-
*Result = wrap(LibrarySymsGenerator->release());
767-
return LLVMErrorSuccess;
749+
auto LibrarySymsGenerator =
750+
StaticLibraryDefinitionGenerator::Load(*unwrap(ObjLayer), FileName);
751+
if (!LibrarySymsGenerator) {
752+
*Result = nullptr;
753+
return wrap(LibrarySymsGenerator.takeError());
768754
}
755+
*Result = wrap(LibrarySymsGenerator->release());
756+
return LLVMErrorSuccess;
769757
}
770758

771759
LLVMOrcThreadSafeContextRef LLVMOrcCreateNewThreadSafeContext(void) {

llvm/tools/lli/lli.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ int runOrcJIT(const char *ProgName) {
10581058
auto JDItr = std::prev(IdxToDylib.lower_bound(EAIdx));
10591059
auto &JD = *JDItr->second;
10601060
JD.addGenerator(ExitOnErr(orc::StaticLibraryDefinitionGenerator::Load(
1061-
J->getObjLinkingLayer(), EAItr->c_str(), *TT)));
1061+
J->getObjLinkingLayer(), EAItr->c_str())));
10621062
}
10631063
}
10641064

llvm/tools/llvm-jitlink/llvm-jitlink.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,8 +1631,7 @@ static Error addLibraries(Session &S,
16311631
break;
16321632
}
16331633
auto G = StaticLibraryDefinitionGenerator::Load(
1634-
S.ObjLayer, Path, S.ES.getTargetTriple(),
1635-
std::move(GetObjFileInterface));
1634+
S.ObjLayer, Path, std::move(GetObjFileInterface));
16361635
if (!G)
16371636
return G.takeError();
16381637

0 commit comments

Comments
 (0)