Skip to content

Commit c66f890

Browse files
committed
[ORC] Rename SearchOrder operations on JITDylib to LinkOrder.
Refering to the link order of a dylib better matches the terminology used in static compilation. As upcoming patches will increase the number of places where link order matters (for example when closing JITDylibs) it's better to get this name change out of the way early.
1 parent 75cbf6d commit c66f890

File tree

9 files changed

+77
-80
lines changed

9 files changed

+77
-80
lines changed

llvm/include/llvm/ExecutionEngine/Orc/Core.h

+26-27
Original file line numberDiff line numberDiff line change
@@ -825,47 +825,46 @@ class JITDylib {
825825
/// have been added and not yet removed).
826826
void removeGenerator(DefinitionGenerator &G);
827827

828-
/// Set the search order to be used when fixing up definitions in JITDylib.
829-
/// This will replace the previous search order, and apply to any symbol
828+
/// Set the link order to be used when fixing up definitions in JITDylib.
829+
/// This will replace the previous link order, and apply to any symbol
830830
/// resolutions made for definitions in this JITDylib after the call to
831-
/// setSearchOrder (even if the definition itself was added before the
831+
/// setLinkOrder (even if the definition itself was added before the
832832
/// call).
833833
///
834-
/// If SearchThisJITDylibFirst is set, which by default it is, then this
835-
/// JITDylib will add itself to the beginning of the SearchOrder (Clients
836-
/// should *not* put this JITDylib in the list in this case, to avoid
837-
/// redundant lookups).
834+
/// If LinkAgainstThisJITDylibFirst is true (the default) then this JITDylib
835+
/// will add itself to the beginning of the LinkOrder (Clients should not
836+
/// put this JITDylib in the list in this case, to avoid redundant lookups).
838837
///
839-
/// If SearchThisJITDylibFirst is false then the search order will be used as
840-
/// given. The main motivation for this feature is to support deliberate
838+
/// If LinkAgainstThisJITDylibFirst is false then the link order will be used
839+
/// as-is. The primary motivation for this feature is to support deliberate
841840
/// shadowing of symbols in this JITDylib by a facade JITDylib. For example,
842841
/// the facade may resolve function names to stubs, and the stubs may compile
843842
/// lazily by looking up symbols in this dylib. Adding the facade dylib
844-
/// as the first in the search order (instead of this dylib) ensures that
843+
/// as the first in the link order (instead of this dylib) ensures that
845844
/// definitions within this dylib resolve to the lazy-compiling stubs,
846845
/// rather than immediately materializing the definitions in this dylib.
847-
void setSearchOrder(JITDylibSearchOrder NewSearchOrder,
848-
bool SearchThisJITDylibFirst = true);
846+
void setLinkOrder(JITDylibSearchOrder NewSearchOrder,
847+
bool LinkAgainstThisJITDylibFirst = true);
849848

850-
/// Add the given JITDylib to the search order for definitions in this
849+
/// Add the given JITDylib to the link order for definitions in this
851850
/// JITDylib.
852-
void addToSearchOrder(JITDylib &JD,
853-
JITDylibLookupFlags JDLookupFlags =
854-
JITDylibLookupFlags::MatchExportedSymbolsOnly);
851+
void addToLinkOrder(JITDylib &JD,
852+
JITDylibLookupFlags JDLookupFlags =
853+
JITDylibLookupFlags::MatchExportedSymbolsOnly);
855854

856-
/// Replace OldJD with NewJD in the search order if OldJD is present.
855+
/// Replace OldJD with NewJD in the link order if OldJD is present.
857856
/// Otherwise this operation is a no-op.
858-
void replaceInSearchOrder(JITDylib &OldJD, JITDylib &NewJD,
859-
JITDylibLookupFlags JDLookupFlags =
860-
JITDylibLookupFlags::MatchExportedSymbolsOnly);
857+
void replaceInLinkOrder(JITDylib &OldJD, JITDylib &NewJD,
858+
JITDylibLookupFlags JDLookupFlags =
859+
JITDylibLookupFlags::MatchExportedSymbolsOnly);
861860

862-
/// Remove the given JITDylib from the search order for this JITDylib if it is
861+
/// Remove the given JITDylib from the link order for this JITDylib if it is
863862
/// present. Otherwise this operation is a no-op.
864-
void removeFromSearchOrder(JITDylib &JD);
863+
void removeFromLinkOrder(JITDylib &JD);
865864

866-
/// Do something with the search order (run under the session lock).
865+
/// Do something with the link order (run under the session lock).
867866
template <typename Func>
868-
auto withSearchOrderDo(Func &&F)
867+
auto withLinkOrderDo(Func &&F)
869868
-> decltype(F(std::declval<const JITDylibSearchOrder &>()));
870869

871870
/// Define all symbols provided by the materialization unit to be part of this
@@ -1049,7 +1048,7 @@ class JITDylib {
10491048
UnmaterializedInfosMap UnmaterializedInfos;
10501049
MaterializingInfosMap MaterializingInfos;
10511050
std::vector<std::unique_ptr<DefinitionGenerator>> DefGenerators;
1052-
JITDylibSearchOrder SearchOrder;
1051+
JITDylibSearchOrder LinkOrder;
10531052
};
10541053

10551054
/// Platforms set up standard symbols and mediate interactions between dynamic
@@ -1297,9 +1296,9 @@ GeneratorT &JITDylib::addGenerator(std::unique_ptr<GeneratorT> DefGenerator) {
12971296
}
12981297

12991298
template <typename Func>
1300-
auto JITDylib::withSearchOrderDo(Func &&F)
1299+
auto JITDylib::withLinkOrderDo(Func &&F)
13011300
-> decltype(F(std::declval<const JITDylibSearchOrder &>())) {
1302-
return ES.runSessionLocked([&]() { return F(SearchOrder); });
1301+
return ES.runSessionLocked([&]() { return F(LinkOrder); });
13031302
}
13041303

13051304
template <typename MaterializationUnitType>

llvm/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp

+14-15
Original file line numberDiff line numberDiff line change
@@ -179,21 +179,20 @@ CompileOnDemandLayer::getPerDylibResources(JITDylib &TargetD) {
179179
if (I == DylibResources.end()) {
180180
auto &ImplD =
181181
getExecutionSession().createBareJITDylib(TargetD.getName() + ".impl");
182-
JITDylibSearchOrder NewSearchOrder;
183-
TargetD.withSearchOrderDo(
184-
[&](const JITDylibSearchOrder &TargetSearchOrder) {
185-
NewSearchOrder = TargetSearchOrder;
186-
});
187-
188-
assert(
189-
!NewSearchOrder.empty() && NewSearchOrder.front().first == &TargetD &&
190-
NewSearchOrder.front().second == JITDylibLookupFlags::MatchAllSymbols &&
191-
"TargetD must be at the front of its own search order and match "
192-
"non-exported symbol");
193-
NewSearchOrder.insert(std::next(NewSearchOrder.begin()),
194-
{&ImplD, JITDylibLookupFlags::MatchAllSymbols});
195-
ImplD.setSearchOrder(NewSearchOrder, false);
196-
TargetD.setSearchOrder(std::move(NewSearchOrder), false);
182+
JITDylibSearchOrder NewLinkOrder;
183+
TargetD.withLinkOrderDo([&](const JITDylibSearchOrder &TargetLinkOrder) {
184+
NewLinkOrder = TargetLinkOrder;
185+
});
186+
187+
assert(!NewLinkOrder.empty() && NewLinkOrder.front().first == &TargetD &&
188+
NewLinkOrder.front().second ==
189+
JITDylibLookupFlags::MatchAllSymbols &&
190+
"TargetD must be at the front of its own search order and match "
191+
"non-exported symbol");
192+
NewLinkOrder.insert(std::next(NewLinkOrder.begin()),
193+
{&ImplD, JITDylibLookupFlags::MatchAllSymbols});
194+
ImplD.setLinkOrder(NewLinkOrder, false);
195+
TargetD.setLinkOrder(std::move(NewLinkOrder), false);
197196

198197
PerDylibResources PDR(ImplD, BuildIndirectStubsManager());
199198
I = DylibResources.insert(std::make_pair(&TargetD, std::move(PDR))).first;

llvm/lib/ExecutionEngine/Orc/Core.cpp

+20-21
Original file line numberDiff line numberDiff line change
@@ -1157,45 +1157,44 @@ void JITDylib::notifyFailed(FailedSymbolsWorklist Worklist) {
11571157
Q->handleFailed(make_error<FailedToMaterialize>(FailedSymbolsMap));
11581158
}
11591159

1160-
void JITDylib::setSearchOrder(JITDylibSearchOrder NewSearchOrder,
1161-
bool SearchThisJITDylibFirst) {
1160+
void JITDylib::setLinkOrder(JITDylibSearchOrder NewLinkOrder,
1161+
bool LinkAgainstThisJITDylibFirst) {
11621162
ES.runSessionLocked([&]() {
1163-
if (SearchThisJITDylibFirst) {
1164-
SearchOrder.clear();
1165-
if (NewSearchOrder.empty() || NewSearchOrder.front().first != this)
1166-
SearchOrder.push_back(
1163+
if (LinkAgainstThisJITDylibFirst) {
1164+
LinkOrder.clear();
1165+
if (NewLinkOrder.empty() || NewLinkOrder.front().first != this)
1166+
LinkOrder.push_back(
11671167
std::make_pair(this, JITDylibLookupFlags::MatchAllSymbols));
1168-
SearchOrder.insert(SearchOrder.end(), NewSearchOrder.begin(),
1169-
NewSearchOrder.end());
1168+
LinkOrder.insert(LinkOrder.end(), NewLinkOrder.begin(),
1169+
NewLinkOrder.end());
11701170
} else
1171-
SearchOrder = std::move(NewSearchOrder);
1171+
LinkOrder = std::move(NewLinkOrder);
11721172
});
11731173
}
11741174

1175-
void JITDylib::addToSearchOrder(JITDylib &JD,
1176-
JITDylibLookupFlags JDLookupFlags) {
1177-
ES.runSessionLocked([&]() { SearchOrder.push_back({&JD, JDLookupFlags}); });
1175+
void JITDylib::addToLinkOrder(JITDylib &JD, JITDylibLookupFlags JDLookupFlags) {
1176+
ES.runSessionLocked([&]() { LinkOrder.push_back({&JD, JDLookupFlags}); });
11781177
}
11791178

1180-
void JITDylib::replaceInSearchOrder(JITDylib &OldJD, JITDylib &NewJD,
1181-
JITDylibLookupFlags JDLookupFlags) {
1179+
void JITDylib::replaceInLinkOrder(JITDylib &OldJD, JITDylib &NewJD,
1180+
JITDylibLookupFlags JDLookupFlags) {
11821181
ES.runSessionLocked([&]() {
1183-
for (auto &KV : SearchOrder)
1182+
for (auto &KV : LinkOrder)
11841183
if (KV.first == &OldJD) {
11851184
KV = {&NewJD, JDLookupFlags};
11861185
break;
11871186
}
11881187
});
11891188
}
11901189

1191-
void JITDylib::removeFromSearchOrder(JITDylib &JD) {
1190+
void JITDylib::removeFromLinkOrder(JITDylib &JD) {
11921191
ES.runSessionLocked([&]() {
1193-
auto I = std::find_if(SearchOrder.begin(), SearchOrder.end(),
1192+
auto I = std::find_if(LinkOrder.begin(), LinkOrder.end(),
11941193
[&](const JITDylibSearchOrder::value_type &KV) {
11951194
return KV.first == &JD;
11961195
});
1197-
if (I != SearchOrder.end())
1198-
SearchOrder.erase(I);
1196+
if (I != LinkOrder.end())
1197+
LinkOrder.erase(I);
11991198
});
12001199
}
12011200

@@ -1529,7 +1528,7 @@ void JITDylib::dump(raw_ostream &OS) {
15291528
ES.runSessionLocked([&, this]() {
15301529
OS << "JITDylib \"" << JITDylibName << "\" (ES: "
15311530
<< format("0x%016" PRIx64, reinterpret_cast<uintptr_t>(&ES)) << "):\n"
1532-
<< "Search order: " << SearchOrder << "\n"
1531+
<< "Link order: " << LinkOrder << "\n"
15331532
<< "Symbol table:\n";
15341533

15351534
for (auto &KV : Symbols) {
@@ -1610,7 +1609,7 @@ JITDylib::MaterializingInfo::takeQueriesMeeting(SymbolState RequiredState) {
16101609

16111610
JITDylib::JITDylib(ExecutionSession &ES, std::string Name)
16121611
: ES(ES), JITDylibName(std::move(Name)) {
1613-
SearchOrder.push_back({this, JITDylibLookupFlags::MatchAllSymbols});
1612+
LinkOrder.push_back({this, JITDylibLookupFlags::MatchAllSymbols});
16141613
}
16151614

16161615
Error JITDylib::defineImpl(MaterializationUnit &MU) {

llvm/lib/ExecutionEngine/Orc/LLJIT.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,8 @@ class GenericLLVMIRPlatformSupport : public LLJIT::PlatformSupport {
374374
continue;
375375
Visited.insert(&NextJD);
376376
DFSLinkOrder.push_back(&NextJD);
377-
NextJD.withSearchOrderDo([&](const JITDylibSearchOrder &SearchOrder) {
378-
for (auto &KV : SearchOrder)
377+
NextJD.withLinkOrderDo([&](const JITDylibSearchOrder &LinkOrder) {
378+
for (auto &KV : LinkOrder)
379379
WorkStack.push_back(KV.first);
380380
});
381381
}

llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,8 @@ std::vector<JITDylib *> MachOPlatform::getDFSLinkOrder(JITDylib &JD) {
271271
continue;
272272
Visited.insert(NextJD);
273273
Result.push_back(NextJD);
274-
NextJD->withSearchOrderDo([&](const JITDylibSearchOrder &SO) {
275-
for (auto &KV : SO)
274+
NextJD->withLinkOrderDo([&](const JITDylibSearchOrder &LO) {
275+
for (auto &KV : LO)
276276
WorkStack.push_back(KV.first);
277277
});
278278
}

llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ class ObjectLinkingLayerJITLinkContext final : public JITLinkContext {
5050
void lookup(const LookupMap &Symbols,
5151
std::unique_ptr<JITLinkAsyncLookupContinuation> LC) override {
5252

53-
JITDylibSearchOrder SearchOrder;
54-
MR.getTargetJITDylib().withSearchOrderDo(
55-
[&](const JITDylibSearchOrder &O) { SearchOrder = O; });
53+
JITDylibSearchOrder LinkOrder;
54+
MR.getTargetJITDylib().withLinkOrderDo(
55+
[&](const JITDylibSearchOrder &LO) { LinkOrder = LO; });
5656

5757
auto &ES = Layer.getExecutionSession();
5858

@@ -90,7 +90,7 @@ class ObjectLinkingLayerJITLinkContext final : public JITLinkContext {
9090
MR.addDependencies(KV.first, InternalDeps);
9191
}
9292

93-
ES.lookup(LookupKind::Static, SearchOrder, std::move(LookupSet),
93+
ES.lookup(LookupKind::Static, LinkOrder, std::move(LookupSet),
9494
SymbolState::Resolved, std::move(OnResolve),
9595
[this](const SymbolDependenceMap &Deps) {
9696
registerDependencies(Deps);

llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ class JITDylibSearchOrderResolver : public JITSymbolResolver {
4747
MR.addDependenciesForAll(Deps);
4848
};
4949

50-
JITDylibSearchOrder SearchOrder;
51-
MR.getTargetJITDylib().withSearchOrderDo(
52-
[&](const JITDylibSearchOrder &JDs) { SearchOrder = JDs; });
53-
ES.lookup(LookupKind::Static, SearchOrder, InternedSymbols,
50+
JITDylibSearchOrder LinkOrder;
51+
MR.getTargetJITDylib().withLinkOrderDo(
52+
[&](const JITDylibSearchOrder &LO) { LinkOrder = LO; });
53+
ES.lookup(LookupKind::Static, LinkOrder, InternedSymbols,
5454
SymbolState::Resolved, std::move(OnResolvedWithUnwrap),
5555
RegisterDependencies);
5656
}

llvm/tools/lli/lli.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -942,8 +942,8 @@ int runOrcLazyJIT(const char *ProgName) {
942942
orc::JITDylib *JD = J->getJITDylibByName(*JDItr);
943943
if (!JD) {
944944
JD = &ExitOnErr(J->createJITDylib(*JDItr));
945-
J->getMainJITDylib().addToSearchOrder(*JD);
946-
JD->addToSearchOrder(J->getMainJITDylib());
945+
J->getMainJITDylib().addToLinkOrder(*JD);
946+
JD->addToLinkOrder(J->getMainJITDylib());
947947
}
948948
IdxToDylib[JITDylibs.getPosition(JDItr - JITDylibs.begin())] = JD;
949949
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -657,13 +657,13 @@ Error loadObjects(Session &S) {
657657
// Set every dylib to link against every other, in command line order.
658658
for (auto *JD : S.JDSearchOrder) {
659659
auto LookupFlags = JITDylibLookupFlags::MatchExportedSymbolsOnly;
660-
JITDylibSearchOrder O;
660+
JITDylibSearchOrder LinkOrder;
661661
for (auto *JD2 : S.JDSearchOrder) {
662662
if (JD2 == JD)
663663
continue;
664-
O.push_back(std::make_pair(JD2, LookupFlags));
664+
LinkOrder.push_back(std::make_pair(JD2, LookupFlags));
665665
}
666-
JD->setSearchOrder(std::move(O));
666+
JD->setLinkOrder(std::move(LinkOrder));
667667
}
668668
}
669669

0 commit comments

Comments
 (0)