Skip to content

Commit d38d06e

Browse files
committed
[ORC] Don't create MaterializingInfo entries unnecessarily.
1 parent 49764dc commit d38d06e

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

llvm/lib/ExecutionEngine/Orc/Core.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -759,8 +759,6 @@ void JITDylib::addDependencies(const SymbolStringPtr &Name,
759759

760760
// If the dependency was not in the error state then add it to
761761
// our list of dependencies.
762-
assert(OtherJITDylib.MaterializingInfos.count(OtherSymbol) &&
763-
"No MaterializingInfo for dependency");
764762
auto &OtherMI = OtherJITDylib.MaterializingInfos[OtherSymbol];
765763

766764
if (OtherSymEntry.getState() == SymbolState::Emitted)
@@ -841,7 +839,11 @@ Error JITDylib::resolve(const SymbolMap &Resolved) {
841839
SymI->second.setFlags(ResolvedFlags);
842840
SymI->second.setState(SymbolState::Resolved);
843841

844-
auto &MI = MaterializingInfos[Name];
842+
auto MII = MaterializingInfos.find(Name);
843+
if (MII == MaterializingInfos.end())
844+
continue;
845+
846+
auto &MI = MII->second;
845847
for (auto &Q : MI.takeQueriesMeeting(SymbolState::Resolved)) {
846848
Q->notifySymbolMetRequiredState(Name, ResolvedSym);
847849
Q->removeQueryDependence(*this, Name);
@@ -909,8 +911,14 @@ Error JITDylib::emit(const SymbolFlagsMap &Emitted) {
909911
SymEntry.setState(SymbolState::Emitted);
910912

911913
auto MII = MaterializingInfos.find(Name);
912-
assert(MII != MaterializingInfos.end() &&
913-
"Missing MaterializingInfo entry");
914+
915+
// If this symbol has no MaterializingInfo then it's trivially ready.
916+
// Update its state and continue.
917+
if (MII == MaterializingInfos.end()) {
918+
SymEntry.setState(SymbolState::Ready);
919+
continue;
920+
}
921+
914922
auto &MI = MII->second;
915923

916924
// For each dependant, transfer this node's emitted dependencies to

llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,25 @@ TEST_F(CoreAPIsStandardTest, EmptyLookup) {
9191
EXPECT_TRUE(OnCompletionRun) << "OnCompletion was not run for empty query";
9292
}
9393

94+
TEST_F(CoreAPIsStandardTest, ResolveUnrequestedSymbol) {
95+
// Test that all symbols in a MaterializationUnit materialize corretly when
96+
// only a subset of symbols is looked up.
97+
// The aim here is to ensure that we're not relying on the query to set up
98+
// state needed to materialize the unrequested symbols.
99+
100+
cantFail(JD.define(std::make_unique<SimpleMaterializationUnit>(
101+
SymbolFlagsMap({{Foo, FooSym.getFlags()}, {Bar, BarSym.getFlags()}}),
102+
[this](MaterializationResponsibility R) {
103+
cantFail(R.notifyResolved({{Foo, FooSym}, {Bar, BarSym}}));
104+
cantFail(R.notifyEmitted());
105+
})));
106+
107+
auto Result =
108+
cantFail(ES.lookup(makeJITDylibSearchOrder(&JD), SymbolLookupSet({Foo})));
109+
EXPECT_EQ(Result.size(), 1U) << "Unexpected number of results";
110+
EXPECT_TRUE(Result.count(Foo)) << "Expected result for \"Foo\"";
111+
}
112+
94113
TEST_F(CoreAPIsStandardTest, RemoveSymbolsTest) {
95114
// Test that:
96115
// (1) Missing symbols generate a SymbolsNotFound error.

0 commit comments

Comments
 (0)