[ORC] Rename MaterializationResponsibility::delegate to replace and add a new
delegate method (and unit test).
The name 'replace' better captures what the old delegate method did: it
returned materialization responsibility for a set of symbols to the VSO.
The new delegate method delegates responsibility for a set of symbols to a new
MaterializationResponsibility instance. This can be used to split responsibility
between multiple threads, or multiple materialization methods.
llvm-svn: 336603
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/Core.h b/llvm/include/llvm/ExecutionEngine/Orc/Core.h
index 9d08b2a..5a37e5d 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/Core.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/Core.h
@@ -149,7 +149,12 @@
/// materializers to break up work based on run-time information (e.g.
/// by introspecting which symbols have actually been looked up and
/// materializing only those).
- void delegate(std::unique_ptr<MaterializationUnit> MU);
+ void replace(std::unique_ptr<MaterializationUnit> MU);
+
+ /// Delegates responsibility for the given symbols to the returned
+ /// materialization responsibility. Useful for breaking up work between
+ /// threads, or different kinds of materialization processes.
+ MaterializationResponsibility delegate(const SymbolNameSet &Symbols);
/// Add dependencies for the symbols in this dylib.
void addDependencies(const SymbolDependenceMap &Dependencies);
diff --git a/llvm/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp b/llvm/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp
index e8d24f9..ebd8d43 100644
--- a/llvm/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp
@@ -68,7 +68,7 @@
}
}
- R.delegate(symbolAliases(std::move(Aliases)));
+ R.replace(symbolAliases(std::move(Aliases)));
}
static std::unique_ptr<Module>
@@ -199,7 +199,7 @@
DelegatedSymbolToDefinition.size() &&
"SymbolFlags and SymbolToDefinition should have the same number "
"of entries");
- R.delegate(llvm::make_unique<ExtractingIRMaterializationUnit>(
+ R.replace(llvm::make_unique<ExtractingIRMaterializationUnit>(
std::move(M), std::move(DelegatedSymbolFlags),
std::move(DelegatedSymbolToDefinition), Parent, BackingResolver));
}
diff --git a/llvm/lib/ExecutionEngine/Orc/Core.cpp b/llvm/lib/ExecutionEngine/Orc/Core.cpp
index 717f2f0..820eb10 100644
--- a/llvm/lib/ExecutionEngine/Orc/Core.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/Core.cpp
@@ -309,7 +309,7 @@
SymbolFlags.clear();
}
-void MaterializationResponsibility::delegate(
+void MaterializationResponsibility::replace(
std::unique_ptr<MaterializationUnit> MU) {
for (auto &KV : MU->getSymbols())
SymbolFlags.erase(KV.first);
@@ -317,6 +317,23 @@
V.replace(std::move(MU));
}
+MaterializationResponsibility
+MaterializationResponsibility::delegate(const SymbolNameSet &Symbols) {
+ SymbolFlagsMap DelegatedFlags;
+
+ for (auto &Name : Symbols) {
+ auto I = SymbolFlags.find(Name);
+ assert(I != SymbolFlags.end() &&
+ "Symbol is not tracked by this MaterializationResponsibility "
+ "instance");
+
+ DelegatedFlags[Name] = std::move(I->second);
+ SymbolFlags.erase(I);
+ }
+
+ return MaterializationResponsibility(V, std::move(DelegatedFlags));
+}
+
void MaterializationResponsibility::addDependencies(
const SymbolDependenceMap &Dependencies) {
V.addDependencies(SymbolFlags, Dependencies);
diff --git a/llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp b/llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp
index 5b85ffa..7c4eccc 100644
--- a/llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp
@@ -834,7 +834,7 @@
#endif
}
-TEST(CoreAPIsTest, TestGetRequestedSymbolsAndDelegate) {
+TEST(CoreAPIsTest, TestGetRequestedSymbolsAndReplace) {
ExecutionSession ES;
auto Foo = ES.getSymbolStringPool().intern("foo");
auto Bar = ES.getSymbolStringPool().intern("bar");
@@ -862,7 +862,7 @@
BarMaterialized = true;
});
- R.delegate(std::move(NewMU));
+ R.replace(std::move(NewMU));
R.resolve(SymbolMap({{Foo, FooSym}}));
R.finalize();
@@ -890,6 +890,40 @@
EXPECT_TRUE(BarMaterialized) << "Bar should be materialized now";
}
+TEST(CoreAPIsTest, TestMaterializationResponsibilityDelegation) {
+ ExecutionSession ES;
+
+ auto Foo = ES.getSymbolStringPool().intern("Foo");
+ auto Bar = ES.getSymbolStringPool().intern("Bar");
+
+ JITEvaluatedSymbol FooSym(0xdeadbeef, JITSymbolFlags::Exported);
+ JITEvaluatedSymbol BarSym(0xcafef00d, JITSymbolFlags::Exported);
+
+ auto MU = llvm::make_unique<SimpleMaterializationUnit>(
+ SymbolFlagsMap({{Foo, FooSym.getFlags()}, {Bar, BarSym.getFlags()}}),
+ [&](MaterializationResponsibility R) {
+ auto R2 = R.delegate({Bar});
+
+ R.resolve({{Foo, FooSym}});
+ R.finalize();
+ R2.resolve({{Bar, BarSym}});
+ R2.finalize();
+ });
+
+ auto &V = ES.createVSO("V");
+ cantFail(V.define(MU));
+
+ auto Result = lookup({&V}, {Foo, Bar});
+
+ EXPECT_TRUE(!!Result) << "Result should be a success value";
+ EXPECT_EQ(Result->count(Foo), 1U) << "\"Foo\" entry missing";
+ EXPECT_EQ(Result->count(Bar), 1U) << "\"Bar\" entry missing";
+ EXPECT_EQ((*Result)[Foo].getAddress(), FooSym.getAddress())
+ << "Address mismatch for \"Foo\"";
+ EXPECT_EQ((*Result)[Bar].getAddress(), BarSym.getAddress())
+ << "Address mismatch for \"Bar\"";
+}
+
TEST(CoreAPIsTest, TestMaterializeWeakSymbol) {
// Confirm that once a weak definition is selected for materialization it is
// treated as strong.