summaryrefslogtreecommitdiffstats
path: root/llvm/examples/Kaleidoscope/Orc
diff options
context:
space:
mode:
authorLang Hames <lhames@gmail.com>2015-05-04 22:03:10 +0000
committerLang Hames <lhames@gmail.com>2015-05-04 22:03:10 +0000
commita68970dfd58dab5443707efc13ed682d6fbd076c (patch)
tree4a664eb98590f969cb1c9c0acfea1a8f6451ebd9 /llvm/examples/Kaleidoscope/Orc
parent19ffc26c5e375ae6682a3877a959d195dbcf7524 (diff)
downloadbcm5719-llvm-a68970dfd58dab5443707efc13ed682d6fbd076c.tar.gz
bcm5719-llvm-a68970dfd58dab5443707efc13ed682d6fbd076c.zip
[Orc] Refactor the compile-on-demand layer to make module partitioning lazy,
and avoid cloning unused decls into every partition. Module partitioning showed up as a source of significant overhead when I profiled some trivial test cases. Avoiding the overhead of partitionging for uncalled functions helps to mitigate this. This change also means that it is no longer necessary to have a LazyEmittingLayer underneath the CompileOnDemand layer, since the CompileOnDemandLayer will not extract or emit function bodies until they are called. llvm-svn: 236465
Diffstat (limited to 'llvm/examples/Kaleidoscope/Orc')
-rw-r--r--llvm/examples/Kaleidoscope/Orc/fully_lazy/toy.cpp22
1 files changed, 14 insertions, 8 deletions
diff --git a/llvm/examples/Kaleidoscope/Orc/fully_lazy/toy.cpp b/llvm/examples/Kaleidoscope/Orc/fully_lazy/toy.cpp
index b5822921b40..93de33353da 100644
--- a/llvm/examples/Kaleidoscope/Orc/fully_lazy/toy.cpp
+++ b/llvm/examples/Kaleidoscope/Orc/fully_lazy/toy.cpp
@@ -1214,11 +1214,11 @@ public:
void removeModule(ModuleHandleT H) { LazyEmitLayer.removeModuleSet(H); }
JITSymbol findSymbol(const std::string &Name) {
- return LazyEmitLayer.findSymbol(Name, true);
+ return LazyEmitLayer.findSymbol(Name, false);
}
JITSymbol findSymbolIn(ModuleHandleT H, const std::string &Name) {
- return LazyEmitLayer.findSymbolIn(H, Name, true);
+ return LazyEmitLayer.findSymbolIn(H, Name, false);
}
JITSymbol findUnmangledSymbol(const std::string &Name) {
@@ -1276,7 +1276,7 @@ private:
makeStub(*F, *FunctionBodyPointer);
// Step 4) Add the module containing the stub to the JIT.
- auto H = addModule(C.takeM());
+ auto StubH = addModule(C.takeM());
// Step 5) Set the compile and update actions.
//
@@ -1289,14 +1289,20 @@ private:
// The update action will update FunctionBodyPointer to point at the newly
// compiled function.
std::shared_ptr<FunctionAST> Fn = std::move(FnAST);
- CallbackInfo.setCompileAction([this, Fn]() {
+ CallbackInfo.setCompileAction([this, Fn, BodyPtrName, StubH]() {
auto H = addModule(IRGen(Session, *Fn));
- return findUnmangledSymbolIn(H, Fn->Proto->Name).getAddress();
+ auto BodySym = findUnmangledSymbolIn(H, Fn->Proto->Name);
+ auto BodyPtrSym = findUnmangledSymbolIn(StubH, BodyPtrName);
+ assert(BodySym && "Missing function body.");
+ assert(BodyPtrSym && "Missing function pointer.");
+ auto BodyAddr = BodySym.getAddress();
+ auto BodyPtr = reinterpret_cast<void*>(
+ static_cast<uintptr_t>(BodyPtrSym.getAddress()));
+ memcpy(BodyPtr, &BodyAddr, sizeof(uintptr_t));
+ return BodyAddr;
});
- CallbackInfo.setUpdateAction(
- getLocalFPUpdater(LazyEmitLayer, H, mangle(BodyPtrName)));
- return H;
+ return StubH;
}
SessionContext &Session;
OpenPOWER on IntegriCloud