summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/Kaleidoscope/BuildingAJIT/Chapter1/CMakeLists.txt1
-rw-r--r--examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h46
-rw-r--r--examples/Kaleidoscope/BuildingAJIT/Chapter2/CMakeLists.txt1
-rw-r--r--examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h54
-rw-r--r--examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h58
-rw-r--r--examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h59
-rw-r--r--examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h64
-rw-r--r--examples/Kaleidoscope/Chapter4/CMakeLists.txt1
-rw-r--r--examples/Kaleidoscope/Chapter5/CMakeLists.txt1
-rw-r--r--examples/Kaleidoscope/Chapter6/CMakeLists.txt1
-rw-r--r--examples/Kaleidoscope/Chapter7/CMakeLists.txt1
-rw-r--r--examples/Kaleidoscope/include/KaleidoscopeJIT.h38
12 files changed, 170 insertions, 155 deletions
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter1/CMakeLists.txt b/examples/Kaleidoscope/BuildingAJIT/Chapter1/CMakeLists.txt
index 657a14be87d..72c9668f7d3 100644
--- a/examples/Kaleidoscope/BuildingAJIT/Chapter1/CMakeLists.txt
+++ b/examples/Kaleidoscope/BuildingAJIT/Chapter1/CMakeLists.txt
@@ -4,6 +4,7 @@ set(LLVM_LINK_COMPONENTS
ExecutionEngine
InstCombine
Object
+ OrcJIT
RuntimeDyld
ScalarOpts
Support
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h b/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h
index ab675e3f742..91709433d93 100644
--- a/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h
+++ b/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h
@@ -38,6 +38,9 @@ namespace orc {
class KaleidoscopeJIT {
private:
+ SymbolStringPool SSP;
+ ExecutionSession ES;
+ std::shared_ptr<SymbolResolver> Resolver;
std::unique_ptr<TargetMachine> TM;
const DataLayout DL;
RTDyldObjectLinkingLayer ObjectLayer;
@@ -47,8 +50,24 @@ public:
using ModuleHandle = decltype(CompileLayer)::ModuleHandleT;
KaleidoscopeJIT()
- : TM(EngineBuilder().selectTarget()), DL(TM->createDataLayout()),
- ObjectLayer([]() { return std::make_shared<SectionMemoryManager>(); }),
+ : ES(SSP),
+ Resolver(createLegacyLookupResolver(
+ [this](const std::string &Name) -> JITSymbol {
+ if (auto Sym = CompileLayer.findSymbol(Name, false))
+ return Sym;
+ else if (auto Err = Sym.takeError())
+ return std::move(Err);
+ if (auto SymAddr =
+ RTDyldMemoryManager::getSymbolAddressInProcess(Name))
+ return JITSymbol(SymAddr, JITSymbolFlags::Exported);
+ return nullptr;
+ },
+ [](Error Err) { cantFail(std::move(Err), "lookupFlags failed"); })),
+ TM(EngineBuilder().selectTarget()), DL(TM->createDataLayout()),
+ ObjectLayer(
+ ES,
+ [](VModuleKey) { return std::make_shared<SectionMemoryManager>(); },
+ [this](VModuleKey K) { return Resolver; }),
CompileLayer(ObjectLayer, SimpleCompiler(*TM)) {
llvm::sys::DynamicLibrary::LoadLibraryPermanently(nullptr);
}
@@ -56,27 +75,8 @@ public:
TargetMachine &getTargetMachine() { return *TM; }
ModuleHandle addModule(std::unique_ptr<Module> M) {
- // Build our symbol resolver:
- // Lambda 1: Look back into the JIT itself to find symbols that are part of
- // the same "logical dylib".
- // Lambda 2: Search for external symbols in the host process.
- auto Resolver = createLambdaResolver(
- [&](const std::string &Name) {
- if (auto Sym = CompileLayer.findSymbol(Name, false))
- return Sym;
- return JITSymbol(nullptr);
- },
- [](const std::string &Name) {
- if (auto SymAddr =
- RTDyldMemoryManager::getSymbolAddressInProcess(Name))
- return JITSymbol(SymAddr, JITSymbolFlags::Exported);
- return JITSymbol(nullptr);
- });
-
- // Add the set to the JIT with the resolver we created above and a newly
- // created SectionMemoryManager.
- return cantFail(CompileLayer.addModule(std::move(M),
- std::move(Resolver)));
+ // Add the module to the JIT with a new VModuleKey.
+ return cantFail(CompileLayer.addModule(ES.allocateVModule(), std::move(M)));
}
JITSymbol findSymbol(const std::string Name) {
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter2/CMakeLists.txt b/examples/Kaleidoscope/BuildingAJIT/Chapter2/CMakeLists.txt
index ea5bc05fa00..ba6abd72d42 100644
--- a/examples/Kaleidoscope/BuildingAJIT/Chapter2/CMakeLists.txt
+++ b/examples/Kaleidoscope/BuildingAJIT/Chapter2/CMakeLists.txt
@@ -4,6 +4,7 @@ set(LLVM_LINK_COMPONENTS
ExecutionEngine
InstCombine
Object
+ OrcJIT
RuntimeDyld
ScalarOpts
Support
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h b/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h
index 9a295f1566c..4b7549391b9 100644
--- a/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h
+++ b/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h
@@ -42,6 +42,9 @@ namespace orc {
class KaleidoscopeJIT {
private:
+ SymbolStringPool SSP;
+ ExecutionSession ES;
+ std::shared_ptr<SymbolResolver> Resolver;
std::unique_ptr<TargetMachine> TM;
const DataLayout DL;
RTDyldObjectLinkingLayer ObjectLayer;
@@ -56,40 +59,37 @@ public:
using ModuleHandle = decltype(OptimizeLayer)::ModuleHandleT;
KaleidoscopeJIT()
- : TM(EngineBuilder().selectTarget()), DL(TM->createDataLayout()),
- ObjectLayer([]() { return std::make_shared<SectionMemoryManager>(); }),
+ : ES(SSP),
+ Resolver(createLegacyLookupResolver(
+ [this](const std::string &Name) -> JITSymbol {
+ if (auto Sym = OptimizeLayer.findSymbol(Name, false))
+ return Sym;
+ else if (auto Err = Sym.takeError())
+ return std::move(Err);
+ if (auto SymAddr =
+ RTDyldMemoryManager::getSymbolAddressInProcess(Name))
+ return JITSymbol(SymAddr, JITSymbolFlags::Exported);
+ return nullptr;
+ },
+ [](Error Err) { cantFail(std::move(Err), "lookupFlags failed"); })),
+ TM(EngineBuilder().selectTarget()), DL(TM->createDataLayout()),
+ ObjectLayer(
+ ES,
+ [](VModuleKey) { return std::make_shared<SectionMemoryManager>(); },
+ [this](VModuleKey K) { return Resolver; }),
CompileLayer(ObjectLayer, SimpleCompiler(*TM)),
- OptimizeLayer(CompileLayer,
- [this](std::shared_ptr<Module> M) {
- return optimizeModule(std::move(M));
- }) {
+ OptimizeLayer(CompileLayer, [this](std::shared_ptr<Module> M) {
+ return optimizeModule(std::move(M));
+ }) {
llvm::sys::DynamicLibrary::LoadLibraryPermanently(nullptr);
}
TargetMachine &getTargetMachine() { return *TM; }
ModuleHandle addModule(std::unique_ptr<Module> M) {
- // Build our symbol resolver:
- // Lambda 1: Look back into the JIT itself to find symbols that are part of
- // the same "logical dylib".
- // Lambda 2: Search for external symbols in the host process.
- auto Resolver = createLambdaResolver(
- [&](const std::string &Name) {
- if (auto Sym = OptimizeLayer.findSymbol(Name, false))
- return Sym;
- return JITSymbol(nullptr);
- },
- [](const std::string &Name) {
- if (auto SymAddr =
- RTDyldMemoryManager::getSymbolAddressInProcess(Name))
- return JITSymbol(SymAddr, JITSymbolFlags::Exported);
- return JITSymbol(nullptr);
- });
-
- // Add the set to the JIT with the resolver we created above and a newly
- // created SectionMemoryManager.
- return cantFail(OptimizeLayer.addModule(std::move(M),
- std::move(Resolver)));
+ // Add the module to the JIT with a new VModuleKey.
+ return cantFail(
+ OptimizeLayer.addModule(ES.allocateVModule(), std::move(M)));
}
JITSymbol findSymbol(const std::string Name) {
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h b/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h
index a03f5ce5e23..43de6d9ef56 100644
--- a/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h
+++ b/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h
@@ -17,15 +17,15 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/JITSymbol.h"
-#include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
-#include "llvm/ExecutionEngine/RuntimeDyld.h"
-#include "llvm/ExecutionEngine/SectionMemoryManager.h"
#include "llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h"
#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
#include "llvm/ExecutionEngine/Orc/IRTransformLayer.h"
#include "llvm/ExecutionEngine/Orc/LambdaResolver.h"
#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
+#include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
+#include "llvm/ExecutionEngine/RuntimeDyld.h"
+#include "llvm/ExecutionEngine/SectionMemoryManager.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Mangler.h"
@@ -35,6 +35,7 @@
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Scalar/GVN.h"
#include <algorithm>
+#include <map>
#include <memory>
#include <set>
#include <string>
@@ -45,6 +46,9 @@ namespace orc {
class KaleidoscopeJIT {
private:
+ SymbolStringPool SSP;
+ ExecutionSession ES;
+ std::map<VModuleKey, std::shared_ptr<SymbolResolver>> Resolvers;
std::unique_ptr<TargetMachine> TM;
const DataLayout DL;
RTDyldObjectLinkingLayer ObjectLayer;
@@ -62,8 +66,11 @@ public:
using ModuleHandle = decltype(CODLayer)::ModuleHandleT;
KaleidoscopeJIT()
- : TM(EngineBuilder().selectTarget()), DL(TM->createDataLayout()),
- ObjectLayer([]() { return std::make_shared<SectionMemoryManager>(); }),
+ : ES(SSP), TM(EngineBuilder().selectTarget()), DL(TM->createDataLayout()),
+ ObjectLayer(
+ ES,
+ [](VModuleKey) { return std::make_shared<SectionMemoryManager>(); },
+ [&](orc::VModuleKey K) { return Resolvers[K]; }),
CompileLayer(ObjectLayer, SimpleCompiler(*TM)),
OptimizeLayer(CompileLayer,
[this](std::shared_ptr<Module> M) {
@@ -71,37 +78,40 @@ public:
}),
CompileCallbackManager(
orc::createLocalCompileCallbackManager(TM->getTargetTriple(), 0)),
- CODLayer(OptimizeLayer,
- [](Function &F) { return std::set<Function*>({&F}); },
+ CODLayer(ES, OptimizeLayer,
+ [&](orc::VModuleKey K) { return Resolvers[K]; },
+ [&](orc::VModuleKey K, std::shared_ptr<SymbolResolver> R) {
+ Resolvers[K] = std::move(R);
+ },
+ [](Function &F) { return std::set<Function *>({&F}); },
*CompileCallbackManager,
orc::createLocalIndirectStubsManagerBuilder(
- TM->getTargetTriple())) {
+ TM->getTargetTriple())) {
llvm::sys::DynamicLibrary::LoadLibraryPermanently(nullptr);
}
TargetMachine &getTargetMachine() { return *TM; }
ModuleHandle addModule(std::unique_ptr<Module> M) {
- // Build our symbol resolver:
- // Lambda 1: Look back into the JIT itself to find symbols that are part of
- // the same "logical dylib".
- // Lambda 2: Search for external symbols in the host process.
- auto Resolver = createLambdaResolver(
- [&](const std::string &Name) {
- if (auto Sym = CODLayer.findSymbol(Name, false))
+ // Create a new VModuleKey.
+ VModuleKey K = ES.allocateVModule();
+
+ // Build a resolver and associate it with the new key.
+ Resolvers[K] = createLegacyLookupResolver(
+ [this](const std::string &Name) -> JITSymbol {
+ if (auto Sym = CompileLayer.findSymbol(Name, false))
return Sym;
- return JITSymbol(nullptr);
- },
- [](const std::string &Name) {
+ else if (auto Err = Sym.takeError())
+ return std::move(Err);
if (auto SymAddr =
- RTDyldMemoryManager::getSymbolAddressInProcess(Name))
+ RTDyldMemoryManager::getSymbolAddressInProcess(Name))
return JITSymbol(SymAddr, JITSymbolFlags::Exported);
- return JITSymbol(nullptr);
- });
+ return nullptr;
+ },
+ [](Error Err) { cantFail(std::move(Err), "lookupFlags failed"); });
- // Add the set to the JIT with the resolver we created above and a newly
- // created SectionMemoryManager.
- return cantFail(CODLayer.addModule(std::move(M), std::move(Resolver)));
+ // Add the module to the JIT with the new key.
+ return cantFail(CODLayer.addModule(K, std::move(M)));
}
JITSymbol findSymbol(const std::string Name) {
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h b/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h
index 841ea74fb98..a95efd4ba82 100644
--- a/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h
+++ b/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h
@@ -17,14 +17,14 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/JITSymbol.h"
-#include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
-#include "llvm/ExecutionEngine/SectionMemoryManager.h"
#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
-#include "llvm/ExecutionEngine/Orc/IndirectionUtils.h"
#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
#include "llvm/ExecutionEngine/Orc/IRTransformLayer.h"
+#include "llvm/ExecutionEngine/Orc/IndirectionUtils.h"
#include "llvm/ExecutionEngine/Orc/LambdaResolver.h"
#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
+#include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
+#include "llvm/ExecutionEngine/SectionMemoryManager.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Mangler.h"
@@ -37,6 +37,7 @@
#include <algorithm>
#include <cassert>
#include <cstdlib>
+#include <map>
#include <memory>
#include <string>
#include <vector>
@@ -71,6 +72,9 @@ namespace orc {
class KaleidoscopeJIT {
private:
+ SymbolStringPool SSP;
+ ExecutionSession ES;
+ std::shared_ptr<SymbolResolver> Resolver;
std::unique_ptr<TargetMachine> TM;
const DataLayout DL;
RTDyldObjectLinkingLayer ObjectLayer;
@@ -88,9 +92,26 @@ public:
using ModuleHandle = decltype(OptimizeLayer)::ModuleHandleT;
KaleidoscopeJIT()
- : TM(EngineBuilder().selectTarget()),
- DL(TM->createDataLayout()),
- ObjectLayer([]() { return std::make_shared<SectionMemoryManager>(); }),
+ : ES(SSP),
+ Resolver(createLegacyLookupResolver(
+ [this](const std::string &Name) -> JITSymbol {
+ if (auto Sym = IndirectStubsMgr->findStub(Name, false))
+ return Sym;
+ if (auto Sym = OptimizeLayer.findSymbol(Name, false))
+ return Sym;
+ else if (auto Err = Sym.takeError())
+ return std::move(Err);
+ if (auto SymAddr =
+ RTDyldMemoryManager::getSymbolAddressInProcess(Name))
+ return JITSymbol(SymAddr, JITSymbolFlags::Exported);
+ return nullptr;
+ },
+ [](Error Err) { cantFail(std::move(Err), "lookupFlags failed"); })),
+ TM(EngineBuilder().selectTarget()), DL(TM->createDataLayout()),
+ ObjectLayer(
+ ES,
+ [](VModuleKey) { return std::make_shared<SectionMemoryManager>(); },
+ [&](VModuleKey K) { return Resolver; }),
CompileLayer(ObjectLayer, SimpleCompiler(*TM)),
OptimizeLayer(CompileLayer,
[this](std::shared_ptr<Module> M) {
@@ -107,29 +128,9 @@ public:
TargetMachine &getTargetMachine() { return *TM; }
ModuleHandle addModule(std::unique_ptr<Module> M) {
- // Build our symbol resolver:
- // Lambda 1: Look back into the JIT itself to find symbols that are part of
- // the same "logical dylib".
- // Lambda 2: Search for external symbols in the host process.
- auto Resolver = createLambdaResolver(
- [&](const std::string &Name) {
- if (auto Sym = IndirectStubsMgr->findStub(Name, false))
- return Sym;
- if (auto Sym = OptimizeLayer.findSymbol(Name, false))
- return Sym;
- return JITSymbol(nullptr);
- },
- [](const std::string &Name) {
- if (auto SymAddr =
- RTDyldMemoryManager::getSymbolAddressInProcess(Name))
- return JITSymbol(SymAddr, JITSymbolFlags::Exported);
- return JITSymbol(nullptr);
- });
-
- // Add the set to the JIT with the resolver we created above and a newly
- // created SectionMemoryManager.
- return cantFail(OptimizeLayer.addModule(std::move(M),
- std::move(Resolver)));
+ // Add the module to the JIT with a new VModuleKey.
+ return cantFail(
+ OptimizeLayer.addModule(ES.allocateVModule(), std::move(M)));
}
Error addFunctionAST(std::unique_ptr<FunctionAST> FnAST) {
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h b/examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h
index 8990a67feb7..2e9f5c3b37f 100644
--- a/examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h
+++ b/examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h
@@ -15,18 +15,18 @@
#define LLVM_EXECUTIONENGINE_ORC_KALEIDOSCOPEJIT_H
#include "RemoteJITUtils.h"
-#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Triple.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/JITSymbol.h"
#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
-#include "llvm/ExecutionEngine/Orc/IndirectionUtils.h"
#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
#include "llvm/ExecutionEngine/Orc/IRTransformLayer.h"
+#include "llvm/ExecutionEngine/Orc/IndirectionUtils.h"
#include "llvm/ExecutionEngine/Orc/LambdaResolver.h"
-#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
#include "llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h"
+#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Mangler.h"
@@ -39,6 +39,7 @@
#include <algorithm>
#include <cassert>
#include <cstdlib>
+#include <map>
#include <memory>
#include <string>
#include <vector>
@@ -76,6 +77,9 @@ using MyRemote = remote::OrcRemoteTargetClient;
class KaleidoscopeJIT {
private:
+ SymbolStringPool SSP;
+ ExecutionSession ES;
+ std::shared_ptr<SymbolResolver> Resolver;
std::unique_ptr<TargetMachine> TM;
const DataLayout DL;
RTDyldObjectLinkingLayer ObjectLayer;
@@ -94,12 +98,28 @@ public:
using ModuleHandle = decltype(OptimizeLayer)::ModuleHandleT;
KaleidoscopeJIT(MyRemote &Remote)
- : TM(EngineBuilder().selectTarget(Triple(Remote.getTargetTriple()), "",
+ : ES(SSP),
+ Resolver(createLegacyLookupResolver(
+ [this](const std::string &Name) -> JITSymbol {
+ if (auto Sym = IndirectStubsMgr->findStub(Name, false))
+ return Sym;
+ if (auto Sym = OptimizeLayer.findSymbol(Name, false))
+ return Sym;
+ else if (auto Err = Sym.takeError())
+ return std::move(Err);
+ if (auto Addr = cantFail(this->Remote.getSymbolAddress(Name)))
+ return JITSymbol(Addr, JITSymbolFlags::Exported);
+ return nullptr;
+ },
+ [](Error Err) { cantFail(std::move(Err), "lookupFlags failed"); })),
+ TM(EngineBuilder().selectTarget(Triple(Remote.getTargetTriple()), "",
"", SmallVector<std::string, 0>())),
DL(TM->createDataLayout()),
- ObjectLayer([&Remote]() {
- return cantFail(Remote.createRemoteMemoryManager());
- }),
+ ObjectLayer(ES,
+ [&Remote](VModuleKey) {
+ return cantFail(Remote.createRemoteMemoryManager());
+ },
+ [this](VModuleKey) { return Resolver; }),
CompileLayer(ObjectLayer, SimpleCompiler(*TM)),
OptimizeLayer(CompileLayer,
[this](std::shared_ptr<Module> M) {
@@ -120,33 +140,9 @@ public:
TargetMachine &getTargetMachine() { return *TM; }
ModuleHandle addModule(std::unique_ptr<Module> M) {
- // Build our symbol resolver:
- // Lambda 1: Look back into the JIT itself to find symbols that are part of
- // the same "logical dylib".
- // Lambda 2: Search for external symbols in the host process.
- auto Resolver = createLambdaResolver(
- [&](const std::string &Name) {
- if (auto Sym = IndirectStubsMgr->findStub(Name, false))
- return Sym;
- if (auto Sym = OptimizeLayer.findSymbol(Name, false))
- return Sym;
- return JITSymbol(nullptr);
- },
- [&](const std::string &Name) {
- if (auto AddrOrErr = Remote.getSymbolAddress(Name))
- return JITSymbol(*AddrOrErr, JITSymbolFlags::Exported);
- else {
- logAllUnhandledErrors(AddrOrErr.takeError(), errs(),
- "Error resolving remote symbol:");
- exit(1);
- }
- return JITSymbol(nullptr);
- });
-
- // Add the set to the JIT with the resolver we created above and a newly
- // created SectionMemoryManager.
- return cantFail(OptimizeLayer.addModule(std::move(M),
- std::move(Resolver)));
+ // Add the module with a new VModuleKey.
+ return cantFail(
+ OptimizeLayer.addModule(ES.allocateVModule(), std::move(M)));
}
Error addFunctionAST(std::unique_ptr<FunctionAST> FnAST) {
diff --git a/examples/Kaleidoscope/Chapter4/CMakeLists.txt b/examples/Kaleidoscope/Chapter4/CMakeLists.txt
index 89feed143ad..fdc083e0768 100644
--- a/examples/Kaleidoscope/Chapter4/CMakeLists.txt
+++ b/examples/Kaleidoscope/Chapter4/CMakeLists.txt
@@ -4,6 +4,7 @@ set(LLVM_LINK_COMPONENTS
ExecutionEngine
InstCombine
Object
+ OrcJIT
RuntimeDyld
ScalarOpts
Support
diff --git a/examples/Kaleidoscope/Chapter5/CMakeLists.txt b/examples/Kaleidoscope/Chapter5/CMakeLists.txt
index c0ae70654c3..757d901ef52 100644
--- a/examples/Kaleidoscope/Chapter5/CMakeLists.txt
+++ b/examples/Kaleidoscope/Chapter5/CMakeLists.txt
@@ -4,6 +4,7 @@ set(LLVM_LINK_COMPONENTS
ExecutionEngine
InstCombine
Object
+ OrcJIT
RuntimeDyld
ScalarOpts
Support
diff --git a/examples/Kaleidoscope/Chapter6/CMakeLists.txt b/examples/Kaleidoscope/Chapter6/CMakeLists.txt
index 49627f07ddf..ad50928a346 100644
--- a/examples/Kaleidoscope/Chapter6/CMakeLists.txt
+++ b/examples/Kaleidoscope/Chapter6/CMakeLists.txt
@@ -4,6 +4,7 @@ set(LLVM_LINK_COMPONENTS
ExecutionEngine
InstCombine
Object
+ OrcJIT
RuntimeDyld
ScalarOpts
Support
diff --git a/examples/Kaleidoscope/Chapter7/CMakeLists.txt b/examples/Kaleidoscope/Chapter7/CMakeLists.txt
index 69e78be6a62..03220358ab7 100644
--- a/examples/Kaleidoscope/Chapter7/CMakeLists.txt
+++ b/examples/Kaleidoscope/Chapter7/CMakeLists.txt
@@ -4,6 +4,7 @@ set(LLVM_LINK_COMPONENTS
ExecutionEngine
InstCombine
Object
+ OrcJIT
RuntimeDyld
ScalarOpts
Support
diff --git a/examples/Kaleidoscope/include/KaleidoscopeJIT.h b/examples/Kaleidoscope/include/KaleidoscopeJIT.h
index 215ce03af99..a1cbe0267ba 100644
--- a/examples/Kaleidoscope/include/KaleidoscopeJIT.h
+++ b/examples/Kaleidoscope/include/KaleidoscopeJIT.h
@@ -14,22 +14,23 @@
#ifndef LLVM_EXECUTIONENGINE_ORC_KALEIDOSCOPEJIT_H
#define LLVM_EXECUTIONENGINE_ORC_KALEIDOSCOPEJIT_H
-#include "llvm/ADT/iterator_range.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/iterator_range.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/JITSymbol.h"
-#include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
-#include "llvm/ExecutionEngine/SectionMemoryManager.h"
#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
#include "llvm/ExecutionEngine/Orc/LambdaResolver.h"
#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
+#include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
+#include "llvm/ExecutionEngine/SectionMemoryManager.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/Mangler.h"
#include "llvm/Support/DynamicLibrary.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetMachine.h"
#include <algorithm>
+#include <map>
#include <memory>
#include <string>
#include <vector>
@@ -44,8 +45,17 @@ public:
using ModuleHandleT = CompileLayerT::ModuleHandleT;
KaleidoscopeJIT()
- : TM(EngineBuilder().selectTarget()), DL(TM->createDataLayout()),
- ObjectLayer([]() { return std::make_shared<SectionMemoryManager>(); }),
+ : ES(SSP),
+ Resolver(createLegacyLookupResolver(
+ [this](const std::string &Name) {
+ return ObjectLayer.findSymbol(Name, true);
+ },
+ [](Error Err) { cantFail(std::move(Err), "lookupFlags failed"); })),
+ TM(EngineBuilder().selectTarget()), DL(TM->createDataLayout()),
+ ObjectLayer(
+ ES,
+ [](VModuleKey) { return std::make_shared<SectionMemoryManager>(); },
+ [this](VModuleKey) { return Resolver; }),
CompileLayer(ObjectLayer, SimpleCompiler(*TM)) {
llvm::sys::DynamicLibrary::LoadLibraryPermanently(nullptr);
}
@@ -53,19 +63,8 @@ public:
TargetMachine &getTargetMachine() { return *TM; }
ModuleHandleT addModule(std::unique_ptr<Module> M) {
- // We need a memory manager to allocate memory and resolve symbols for this
- // new module. Create one that resolves symbols by looking back into the
- // JIT.
- auto Resolver = createLambdaResolver(
- [&](const std::string &Name) {
- if (auto Sym = findMangledSymbol(Name))
- return Sym;
- return JITSymbol(nullptr);
- },
- [](const std::string &S) { return nullptr; });
- auto H = cantFail(CompileLayer.addModule(std::move(M),
- std::move(Resolver)));
-
+ auto H =
+ cantFail(CompileLayer.addModule(ES.allocateVModule(), std::move(M)));
ModuleHandles.push_back(H);
return H;
}
@@ -127,6 +126,9 @@ private:
return nullptr;
}
+ SymbolStringPool SSP;
+ ExecutionSession ES;
+ std::shared_ptr<SymbolResolver> Resolver;
std::unique_ptr<TargetMachine> TM;
const DataLayout DL;
ObjLayerT ObjectLayer;