[llvm] r323060 - [ORC] Add a lookupFlags method to VSO.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 20 19:20:39 PST 2018
Author: lhames
Date: Sat Jan 20 19:20:39 2018
New Revision: 323060
URL: http://llvm.org/viewvc/llvm-project?rev=323060&view=rev
Log:
[ORC] Add a lookupFlags method to VSO.
lookupFlags returns a SymbolFlagsMap for the requested symbols, along with a
set containing the SymbolStringPtr for any symbol not found in the VSO.
The JITSymbolFlags for each symbol will have been stripped of its transient
JIT-state flags (i.e. NotMaterialized, Materializing).
Calling lookupFlags does not trigger symbol materialization.
Modified:
llvm/trunk/include/llvm/ExecutionEngine/JITSymbol.h
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/JITSymbol.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/JITSymbol.h?rev=323060&r1=323059&r2=323060&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/JITSymbol.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/JITSymbol.h Sat Jan 20 19:20:39 2018
@@ -56,6 +56,11 @@ public:
Materializing = 1U << 6
};
+ static JITSymbolFlags stripTransientFlags(JITSymbolFlags Orig) {
+ return static_cast<FlagNames>(Orig.Flags &
+ ~(NotMaterialized | Materializing));
+ }
+
/// @brief Default-construct a JITSymbolFlags instance.
JITSymbolFlags() = default;
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=323060&r1=323059&r2=323060&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/Core.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/Core.h Sat Jan 20 19:20:39 2018
@@ -138,6 +138,11 @@ public:
std::map<SymbolStringPtr, RelativeLinkageStrength>;
using SourceWorkMap = std::map<SymbolSource *, SymbolNameSet>;
+ struct LookupFlagsResult {
+ SymbolFlagsMap SymbolFlags;
+ SymbolNameSet SymbolsNotFound;
+ };
+
struct LookupResult {
SourceWorkMap MaterializationWork;
SymbolNameSet UnresolvedSymbols;
@@ -175,6 +180,12 @@ public:
/// @brief Finalize the given symbols.
void finalize(SymbolNameSet SymbolsToFinalize);
+ /// @brief Look up the flags for the given symbols.
+ ///
+ /// Returns the flags for the give symbols, together with the set of symbols
+ /// not found.
+ LookupFlagsResult lookupFlags(SymbolNameSet Symbols);
+
/// @brief Apply the given query to the given symbols in this VSO.
///
/// For symbols in this VSO that have already been materialized, their address
Modified: llvm/trunk/lib/ExecutionEngine/Orc/Core.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/Core.cpp?rev=323060&r1=323059&r2=323060&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/Core.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/Orc/Core.cpp Sat Jan 20 19:20:39 2018
@@ -287,6 +287,26 @@ void VSO::finalize(SymbolNameSet Symbols
}
}
+VSO::LookupFlagsResult VSO::lookupFlags(SymbolNameSet Names) {
+ SymbolFlagsMap FlagsFound;
+
+ for (SymbolNameSet::iterator I = Names.begin(), E = Names.end(); I != E;) {
+ auto Tmp = I++;
+ auto SymI = Symbols.find(*Tmp);
+
+ // If the symbol isn't in this dylib then just continue.
+ if (SymI == Symbols.end())
+ continue;
+
+ Names.erase(Tmp);
+
+ FlagsFound[SymI->first] =
+ JITSymbolFlags::stripTransientFlags(SymI->second.getFlags());
+ }
+
+ return {std::move(FlagsFound), std::move(Names)};
+}
+
VSO::LookupResult VSO::lookup(AsynchronousSymbolQuery &Query,
SymbolNameSet Names) {
SourceWorkMap MaterializationWork;
Modified: llvm/trunk/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp?rev=323060&r1=323059&r2=323060&view=diff
==============================================================================
--- llvm/trunk/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp (original)
+++ llvm/trunk/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp Sat Jan 20 19:20:39 2018
@@ -130,6 +130,56 @@ TEST(CoreAPIsTest, SimpleAsynchronousSym
EXPECT_TRUE(OnReadyRun) << "OnReady was not run";
}
+TEST(CoreAPIsTest, LookupFlagsTest) {
+
+ // Test that lookupFlags works on a predefined symbol, and does not trigger
+ // materialization of a lazy symbol.
+
+ SymbolStringPool SP;
+ auto Foo = SP.intern("foo");
+ auto Bar = SP.intern("bar");
+ auto Baz = SP.intern("baz");
+
+ VSO V;
+
+ auto Source = std::make_shared<SimpleSource>(
+ [](VSO &V, SymbolNameSet Symbols) -> Error {
+ llvm_unreachable("Symbol materialized on flags lookup");
+ },
+ [](VSO &V, SymbolStringPtr Name) -> Error {
+ llvm_unreachable("Symbol finalized on flags lookup");
+ });
+
+ JITSymbolFlags FooFlags = JITSymbolFlags::Exported;
+ JITSymbolFlags BarFlags = static_cast<JITSymbolFlags::FlagNames>(
+ JITSymbolFlags::Exported | JITSymbolFlags::Weak);
+
+ SymbolMap InitialDefs;
+ InitialDefs[Foo] = JITEvaluatedSymbol(0xdeadbeef, FooFlags);
+ cantFail(V.define(std::move(InitialDefs)));
+
+ SymbolFlagsMap InitialLazyDefs({{Bar, BarFlags}});
+ cantFail(V.defineLazy(InitialLazyDefs, *Source));
+
+ SymbolNameSet Names({Foo, Bar, Baz});
+
+ auto LFR = V.lookupFlags(Names);
+
+ EXPECT_EQ(LFR.SymbolsNotFound.size(), 1U) << "Expected one not-found symbol";
+ EXPECT_EQ(*LFR.SymbolsNotFound.begin(), Baz)
+ << "Expected Baz to be not-found";
+ EXPECT_EQ(LFR.SymbolFlags.size(), 2U)
+ << "Returned symbol flags contains unexpected results";
+ EXPECT_EQ(LFR.SymbolFlags.count(Foo), 1U)
+ << "Missing lookupFlags result for Foo";
+ EXPECT_EQ(LFR.SymbolFlags[Foo], FooFlags)
+ << "Incorrect flags returned for Foo";
+ EXPECT_EQ(LFR.SymbolFlags.count(Bar), 1U)
+ << "Missing lookupFlags result for Bar";
+ EXPECT_EQ(LFR.SymbolFlags[Bar], BarFlags)
+ << "Incorrect flags returned for Bar";
+}
+
TEST(CoreAPIsTest, AddAndMaterializeLazySymbol) {
constexpr JITTargetAddress FakeFooAddr = 0xdeadbeef;
More information about the llvm-commits
mailing list