[llvm] r338764 - [ORC] Add a re-exports fallback definition generator.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 2 13:13:58 PDT 2018
Author: lhames
Date: Thu Aug 2 13:13:58 2018
New Revision: 338764
URL: http://llvm.org/viewvc/llvm-project?rev=338764&view=rev
Log:
[ORC] Add a re-exports fallback definition generator.
An instance of ReexportsFallbackDefinitionGenerator can be attached to a VSO
(via setFallbackDefinitionGenerator) to re-export symbols on demandy from a
backing VSO.
Modified:
llvm/trunk/include/llvm/ExecutionEngine/Orc/Core.h
llvm/trunk/lib/ExecutionEngine/Orc/Core.cpp
llvm/trunk/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp
Modified: llvm/trunk/include/llvm/ExecutionEngine/Orc/Core.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/Core.h?rev=338764&r1=338763&r2=338764&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/Core.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/Core.h Thu Aug 2 13:13:58 2018
@@ -344,6 +344,17 @@ reexports(VSO &SourceV, SymbolAliasMap A
Expected<SymbolAliasMap>
buildSimpleReexportsAliasMap(VSO &SourceV, const SymbolNameSet &Symbols);
+class ReexportsFallbackDefinitionGenerator {
+public:
+ using SymbolPredicate = std::function<bool(SymbolStringPtr)>;
+ ReexportsFallbackDefinitionGenerator(VSO &BackingVSO, SymbolPredicate Allow);
+ SymbolNameSet operator()(VSO &V, const SymbolNameSet &Names);
+
+private:
+ VSO &BackingVSO;
+ SymbolPredicate Allow;
+};
+
/// Base utilities for ExecutionSession.
class ExecutionSessionBase {
// FIXME: Remove this when we remove the old ORC layers.
Modified: llvm/trunk/lib/ExecutionEngine/Orc/Core.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/Core.cpp?rev=338764&r1=338763&r2=338764&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/Core.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/Orc/Core.cpp Thu Aug 2 13:13:58 2018
@@ -886,6 +886,30 @@ buildSimpleReexportsAliasMap(VSO &Source
return Result;
}
+ReexportsFallbackDefinitionGenerator::ReexportsFallbackDefinitionGenerator(
+ VSO &BackingVSO, SymbolPredicate Allow)
+ : BackingVSO(BackingVSO), Allow(std::move(Allow)) {}
+
+SymbolNameSet ReexportsFallbackDefinitionGenerator::
+operator()(VSO &V, const SymbolNameSet &Names) {
+ orc::SymbolNameSet Added;
+ orc::SymbolAliasMap AliasMap;
+
+ auto Flags = BackingVSO.lookupFlags(Names);
+
+ for (auto &KV : Flags) {
+ if (!Allow(KV.first))
+ continue;
+ AliasMap[KV.first] = SymbolAliasMapEntry(KV.first, KV.second);
+ Added.insert(KV.first);
+ }
+
+ if (!Added.empty())
+ cantFail(V.define(reexports(BackingVSO, AliasMap)));
+
+ return Added;
+}
+
Error VSO::defineMaterializing(const SymbolFlagsMap &SymbolFlags) {
return ES.runSessionLocked([&]() -> Error {
std::vector<SymbolMap::iterator> AddedSyms;
Modified: llvm/trunk/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp?rev=338764&r1=338763&r2=338764&view=diff
==============================================================================
--- llvm/trunk/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp (original)
+++ llvm/trunk/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp Thu Aug 2 13:13:58 2018
@@ -273,6 +273,28 @@ TEST_F(CoreAPIsStandardTest, TestThatReE
EXPECT_FALSE(BarMaterialized) << "Bar should not have been materialized";
}
+TEST_F(CoreAPIsStandardTest, TestReexportsFallbackGenerator) {
+ // Test that a re-exports fallback generator can dynamically generate
+ // reexports.
+
+ auto &V2 = ES.createVSO("V2");
+ cantFail(V2.define(absoluteSymbols({{Foo, FooSym}, {Bar, BarSym}})));
+
+ auto Filter = [this](SymbolStringPtr Name) { return Name != Bar; };
+
+ V.setFallbackDefinitionGenerator(
+ ReexportsFallbackDefinitionGenerator(V2, Filter));
+
+ auto Flags = V.lookupFlags({Foo, Bar, Baz});
+ EXPECT_EQ(Flags.size(), 1U) << "Unexpected number of results";
+ EXPECT_EQ(Flags[Foo], FooSym.getFlags()) << "Unexpected flags for Foo";
+
+ auto Result = cantFail(lookup({&V}, Foo));
+
+ EXPECT_EQ(Result.getAddress(), FooSym.getAddress())
+ << "Incorrect reexported symbol address";
+}
+
TEST_F(CoreAPIsStandardTest, TestTrivialCircularDependency) {
Optional<MaterializationResponsibility> FooR;
auto FooMU = llvm::make_unique<SimpleMaterializationUnit>(
More information about the llvm-commits
mailing list