[ORC] Start migrating ORC layers to use the new ORC Core.h APIs.
In particular this patch switches RTDyldObjectLinkingLayer to use
orc::SymbolResolver and threads the requried changse (ExecutionSession
references and VModuleKeys) through the existing layer APIs.
The purpose of the new resolver interface is to improve query performance and
better support parallelism, both in JIT'd code and within the compiler itself.
The most visibile change is switch of the <Layer>::addModule signatures from:
Expected<Handle> addModule(std::shared_ptr<ModuleType> Mod,
std::shared_ptr<JITSymbolResolver> Resolver)
to:
Expected<Handle> addModule(VModuleKey K, std::shared_ptr<ModuleType> Mod);
Typical usage of addModule will now look like:
auto K = ES.allocateVModuleKey();
Resolvers[K] = createSymbolResolver(...);
Layer.addModule(K, std::move(Mod));
See the BuildingAJIT tutorial code for example usage.
llvm-svn: 324405
diff --git a/llvm/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp b/llvm/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp
index 8b25ede..3e7d3f6 100644
--- a/llvm/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp
@@ -12,6 +12,7 @@
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
#include "llvm/ExecutionEngine/Orc/LambdaResolver.h"
+#include "llvm/ExecutionEngine/Orc/Legacy.h"
#include "llvm/ExecutionEngine/Orc/NullResolver.h"
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
#include "llvm/IR/Constants.h"
@@ -66,7 +67,12 @@
bool DebugSectionSeen = false;
auto MM = std::make_shared<MemoryManagerWrapper>(DebugSectionSeen);
- RTDyldObjectLinkingLayer ObjLayer([&MM]() { return MM; });
+ SymbolStringPool SSP;
+ ExecutionSession ES(SSP);
+
+ RTDyldObjectLinkingLayer ObjLayer(
+ ES, [&MM](VModuleKey) { return MM; },
+ [](orc::VModuleKey) { return std::make_shared<NullResolver>(); });
LLVMContext Context;
auto M = llvm::make_unique<Module>("", Context);
@@ -92,18 +98,9 @@
std::make_shared<object::OwningBinary<object::ObjectFile>>(
SimpleCompiler(*TM)(*M));
- auto Resolver =
- createLambdaResolver(
- [](const std::string &Name) {
- return JITSymbol(nullptr);
- },
- [](const std::string &Name) {
- return JITSymbol(nullptr);
- });
-
{
// Test with ProcessAllSections = false (the default).
- auto H = cantFail(ObjLayer.addObject(Obj, Resolver));
+ auto H = cantFail(ObjLayer.addObject(ES.allocateVModule(), Obj));
cantFail(ObjLayer.emitAndFinalize(H));
EXPECT_EQ(DebugSectionSeen, false)
<< "Unexpected debug info section";
@@ -113,7 +110,7 @@
{
// Test with ProcessAllSections = true.
ObjLayer.setProcessAllSections(true);
- auto H = cantFail(ObjLayer.addObject(Obj, Resolver));
+ auto H = cantFail(ObjLayer.addObject(ES.allocateVModule(), Obj));
cantFail(ObjLayer.emitAndFinalize(H));
EXPECT_EQ(DebugSectionSeen, true)
<< "Expected debug info section not seen";
@@ -125,9 +122,22 @@
if (!TM)
return;
+ SymbolStringPool SSP;
+ ExecutionSession ES(SSP);
+
auto MM = std::make_shared<SectionMemoryManagerWrapper>();
- RTDyldObjectLinkingLayer ObjLayer([&MM]() { return MM; });
+ std::map<orc::VModuleKey, std::shared_ptr<orc::SymbolResolver>> Resolvers;
+
+ RTDyldObjectLinkingLayer ObjLayer(ES, [&MM](VModuleKey) { return MM; },
+ [&](VModuleKey K) {
+ auto I = Resolvers.find(K);
+ assert(I != Resolvers.end() &&
+ "Missing resolver");
+ auto R = std::move(I->second);
+ Resolvers.erase(I);
+ return R;
+ });
SimpleCompiler Compile(*TM);
// Create a pair of modules that will trigger recursive finalization:
@@ -170,19 +180,25 @@
std::make_shared<object::OwningBinary<object::ObjectFile>>(
Compile(*MB2.getModule()));
- auto Resolver =
- createLambdaResolver(
- [&](const std::string &Name) {
- if (auto Sym = ObjLayer.findSymbol(Name, true))
- return Sym;
- return JITSymbol(nullptr);
+ auto K1 = ES.allocateVModule();
+ Resolvers[K1] = std::make_shared<NullResolver>();
+ cantFail(ObjLayer.addObject(K1, std::move(Obj1)));
+
+ auto K2 = ES.allocateVModule();
+ auto LegacyLookup = [&](const std::string &Name) {
+ return ObjLayer.findSymbol(Name, true);
+ };
+
+ Resolvers[K2] = createSymbolResolver(
+ [&](SymbolFlagsMap &SymbolFlags, const SymbolNameSet &Symbols) {
+ return cantFail(
+ lookupFlagsWithLegacyFn(SymbolFlags, Symbols, LegacyLookup));
},
- [](const std::string &Name) {
- return JITSymbol(nullptr);
+ [&](AsynchronousSymbolQuery &Query, const SymbolNameSet &Symbols) {
+ return lookupWithLegacyFn(Query, Symbols, LegacyLookup);
});
- cantFail(ObjLayer.addObject(std::move(Obj1), Resolver));
- auto H = cantFail(ObjLayer.addObject(std::move(Obj2), Resolver));
+ auto H = cantFail(ObjLayer.addObject(K2, std::move(Obj2)));
cantFail(ObjLayer.emitAndFinalize(H));
cantFail(ObjLayer.removeObject(H));
@@ -196,9 +212,14 @@
if (!TM)
return;
+ SymbolStringPool SSP;
+ ExecutionSession ES(SSP);
+
auto MM = std::make_shared<SectionMemoryManagerWrapper>();
- RTDyldObjectLinkingLayer ObjLayer([&MM]() { return MM; });
+ RTDyldObjectLinkingLayer ObjLayer(
+ ES, [&MM](VModuleKey) { return MM; },
+ [](VModuleKey) { return std::make_shared<NullResolver>(); });
SimpleCompiler Compile(*TM);
// Create a pair of unrelated modules:
@@ -243,9 +264,8 @@
std::make_shared<object::OwningBinary<object::ObjectFile>>(
Compile(*MB2.getModule()));
- auto NR = std::make_shared<NullLegacyResolver>();
- auto H = cantFail(ObjLayer.addObject(std::move(Obj1), NR));
- cantFail(ObjLayer.addObject(std::move(Obj2), NR));
+ auto H = cantFail(ObjLayer.addObject(ES.allocateVModule(), std::move(Obj1)));
+ cantFail(ObjLayer.addObject(ES.allocateVModule(), std::move(Obj2)));
cantFail(ObjLayer.emitAndFinalize(H));
cantFail(ObjLayer.removeObject(H));
@@ -256,8 +276,11 @@
}
TEST_F(RTDyldObjectLinkingLayerExecutionTest, TestNotifyLoadedSignature) {
+ SymbolStringPool SSP;
+ ExecutionSession ES(SSP);
RTDyldObjectLinkingLayer ObjLayer(
- []() { return nullptr; },
+ ES, [](VModuleKey) { return nullptr; },
+ [](VModuleKey) { return std::make_shared<NullResolver>(); },
[](RTDyldObjectLinkingLayer::ObjHandleT,
const RTDyldObjectLinkingLayer::ObjectPtr &obj,
const RuntimeDyld::LoadedObjectInfo &info) {});