summaryrefslogtreecommitdiffstats
path: root/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3
diff options
context:
space:
mode:
authorLang Hames <lhames@gmail.com>2018-02-06 21:25:11 +0000
committerLang Hames <lhames@gmail.com>2018-02-06 21:25:11 +0000
commit4b546c91452c5735ada1430f8a6943328e4dba4e (patch)
tree633421ee6cc4d06fce9ce73f625992e7dbedc6fe /llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3
parentffe72034a6d688efcd7035fe9caf5964f00037c0 (diff)
downloadbcm5719-llvm-4b546c91452c5735ada1430f8a6943328e4dba4e.tar.gz
bcm5719-llvm-4b546c91452c5735ada1430f8a6943328e4dba4e.zip
[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
Diffstat (limited to 'llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3')
-rw-r--r--llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h58
1 files changed, 34 insertions, 24 deletions
diff --git a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h
index a03f5ce5e23..43de6d9ef56 100644
--- a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h
+++ b/llvm/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) {
OpenPOWER on IntegriCloud