mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 20:51:52 +01:00
[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. llvm-svn: 338764
This commit is contained in:
parent
d33befca30
commit
54d28c92f1
@ -344,6 +344,17 @@ reexports(VSO &SourceV, SymbolAliasMap Aliases) {
|
||||
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.
|
||||
|
@ -886,6 +886,30 @@ buildSimpleReexportsAliasMap(VSO &SourceV, const SymbolNameSet &Symbols) {
|
||||
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;
|
||||
|
@ -273,6 +273,28 @@ TEST_F(CoreAPIsStandardTest, TestThatReExportsDontUnnecessarilyMaterialize) {
|
||||
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>(
|
||||
|
Loading…
x
Reference in New Issue
Block a user