diff options
author | Lang Hames <lhames@gmail.com> | 2018-03-14 04:18:04 +0000 |
---|---|---|
committer | Lang Hames <lhames@gmail.com> | 2018-03-14 04:18:04 +0000 |
commit | 817f1f64d9848e44fd9b0aebe98dc5605f2ec03d (patch) | |
tree | bd1731f9c88fbf5748ca35fb9c2db0c3c5f69ce3 /llvm/unittests/ExecutionEngine | |
parent | 66b84079f93f068117c9fb3f9d520c2cc0904f72 (diff) | |
download | bcm5719-llvm-817f1f64d9848e44fd9b0aebe98dc5605f2ec03d.tar.gz bcm5719-llvm-817f1f64d9848e44fd9b0aebe98dc5605f2ec03d.zip |
[ORC] Add a 'lookup' convenience function for finding symbols in a list of VSOs.
The lookup function takes a list of VSOs, a set of symbol names (or just one
symbol name) and a materialization function object. It returns an
Expected<SymbolMap> (if given a set of names) or an Expected<JITEvaluatedSymbol>
(if given just one name). The lookup method constructs an
AsynchronousSymbolQuery for the given names, applies that query to each VSO in
the list in turn, and then blocks waiting for the query to complete. If
threading is enabled then the materialization function object can be used to
execute the materialization on different threads. If threading is disabled the
MaterializeOnCurrentThread utility must be used.
llvm-svn: 327474
Diffstat (limited to 'llvm/unittests/ExecutionEngine')
-rw-r--r-- | llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp b/llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp index a79f31fab0d..5a74246b1c3 100644 --- a/llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp +++ b/llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp @@ -12,6 +12,7 @@ #include "gtest/gtest.h" #include <set> +#include <thread> using namespace llvm; using namespace llvm::orc; @@ -325,4 +326,80 @@ TEST(CoreAPIsTest, TestLambdaSymbolResolver) { EXPECT_TRUE(OnResolvedRun) << "OnResolved was never run"; } +TEST(CoreAPIsTest, TestLookupWithUnthreadedMaterialization) { + constexpr JITTargetAddress FakeFooAddr = 0xdeadbeef; + JITEvaluatedSymbol FooSym(FakeFooAddr, JITSymbolFlags::Exported); + + SymbolStringPool SSP; + auto Foo = SSP.intern("foo"); + + auto Source = std::make_shared<SimpleSource>( + [&](VSO &V, SymbolNameSet Symbols) -> Error { + V.resolve({{Foo, FooSym}}); + V.finalize({Foo}); + return Error::success(); + }, + [](VSO &V, SymbolStringPtr Name) -> Error { + llvm_unreachable("Not expecting finalization"); + }); + + VSO V; + + SymbolFlagsMap InitialSymbols({{Foo, JITSymbolFlags::Exported}}); + cantFail(V.defineLazy(InitialSymbols, Source)); + + ExecutionSession ES(SSP); + auto FooLookupResult = + cantFail(lookup({&V}, Foo, MaterializeOnCurrentThread(ES))); + + EXPECT_EQ(FooLookupResult.getAddress(), FooSym.getAddress()) + << "lookup returned an incorrect address"; + EXPECT_EQ(FooLookupResult.getFlags(), FooSym.getFlags()) + << "lookup returned incorrect flags"; +} + +TEST(CoreAPIsTest, TestLookupWithThreadedMaterialization) { +#if LLVM_ENABLE_THREADS + constexpr JITTargetAddress FakeFooAddr = 0xdeadbeef; + JITEvaluatedSymbol FooSym(FakeFooAddr, JITSymbolFlags::Exported); + + SymbolStringPool SSP; + auto Foo = SSP.intern("foo"); + + auto Source = std::make_shared<SimpleSource>( + [&](VSO &V, SymbolNameSet Symbols) -> Error { + V.resolve({{Foo, FooSym}}); + V.finalize({Foo}); + return Error::success(); + }, + [](VSO &V, SymbolStringPtr Name) -> Error { + llvm_unreachable("Not expecting finalization"); + }); + + VSO V; + + SymbolFlagsMap InitialSymbols({{Foo, JITSymbolFlags::Exported}}); + cantFail(V.defineLazy(InitialSymbols, Source)); + + ExecutionSession ES(SSP); + + auto MaterializeOnNewThread = + [&ES](VSO &V, std::shared_ptr<SymbolSource> Source, SymbolNameSet Names) { + std::thread( + [&ES, &V, Source, Names]() { + if (auto Err = Source->materialize(V, std::move(Names))) + ES.reportError(std::move(Err)); + }).detach(); + }; + + auto FooLookupResult = + cantFail(lookup({&V}, Foo, MaterializeOnNewThread)); + + EXPECT_EQ(FooLookupResult.getAddress(), FooSym.getAddress()) + << "lookup returned an incorrect address"; + EXPECT_EQ(FooLookupResult.getFlags(), FooSym.getFlags()) + << "lookup returned incorrect flags"; +#endif +} + } // namespace |