Skip to content

Commit 12f6bc2

Browse files
committed
Implement LLVM compile-on-demand
1 parent 2df84a9 commit 12f6bc2

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/jitlayers.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,7 @@ JuliaOJIT::JuliaOJIT()
986986
#endif
987987
GlobalJD(ES.createBareJITDylib("JuliaGlobals")),
988988
JD(ES.createBareJITDylib("JuliaOJIT")),
989+
LCTM(cantFail(orc::createLocalLazyCallThroughManager(TM->getTargetTriple(), ES, 0))),
989990
ContextPool([](){ return orc::ThreadSafeContext(std::make_unique<LLVMContext>()); }),
990991
#ifdef JL_USE_JITLINK
991992
// TODO: Port our memory management optimisations to JITLink instead of using the
@@ -1011,7 +1012,8 @@ JuliaOJIT::JuliaOJIT()
10111012
std::make_unique<PipelineT>(ObjectLayer, *TM, 2),
10121013
std::make_unique<PipelineT>(ObjectLayer, *TM, 3),
10131014
},
1014-
OptSelLayer(Pipelines)
1015+
OptSelLayer(Pipelines),
1016+
CODLayer(ES, OptSelLayer, *LCTM, orc::createLocalIndirectStubsManagerBuilder(TM->getTargetTriple()))
10151017
{
10161018
#ifdef JL_USE_JITLINK
10171019
# if defined(_OS_DARWIN_) && defined(LLVM_SHLIB)
@@ -1034,6 +1036,8 @@ JuliaOJIT::JuliaOJIT()
10341036
});
10351037
#endif
10361038

1039+
CODLayer.setPartitionFunction(CODLayerT::compileWholeModule);
1040+
10371041
// Make sure SectionMemoryManager::getSymbolAddressInProcess can resolve
10381042
// symbols in the program as well. The nullptr argument to the function
10391043
// tells DynamicLibrary to load the program, not a library.
@@ -1112,11 +1116,11 @@ void JuliaOJIT::addModule(orc::ThreadSafeModule TSM)
11121116
#endif
11131117
});
11141118
// TODO: what is the performance characteristics of this?
1115-
cantFail(OptSelLayer.add(JD, std::move(TSM)));
1116-
// force eager compilation (for now), due to memory management specifics
1117-
// (can't handle compilation recursion)
1118-
for (auto Name : NewExports)
1119-
cantFail(ES.lookup({&JD}, Name));
1119+
cantFail(CODLayer.add(JD, std::move(TSM)));
1120+
// // force eager compilation (for now), due to memory management specifics
1121+
// // (can't handle compilation recursion)
1122+
// for (auto Name : NewExports)
1123+
// cantFail(ES.lookup({&JD}, Name));
11201124

11211125
}
11221126

src/jitlayers.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <llvm/ExecutionEngine/Orc/IRCompileLayer.h>
1111
#include <llvm/ExecutionEngine/Orc/IRTransformLayer.h>
12+
#include <llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h>
1213
#include <llvm/ExecutionEngine/JITEventListener.h>
1314

1415
#include <llvm/Target/TargetMachine.h>
@@ -223,6 +224,7 @@ class JuliaOJIT {
223224
#endif
224225
typedef orc::IRCompileLayer CompileLayerT;
225226
typedef orc::IRTransformLayer OptimizeLayerT;
227+
typedef orc::CompileOnDemandLayer CODLayerT;
226228
typedef object::OwningBinary<object::ObjectFile> OwningObj;
227229
template
228230
<typename ResourceT, size_t max = 0,
@@ -409,6 +411,8 @@ class JuliaOJIT {
409411
orc::JITDylib &GlobalJD;
410412
orc::JITDylib &JD;
411413

414+
std::unique_ptr<orc::LazyCallThroughManager> LCTM;
415+
412416
ResourcePool<orc::ThreadSafeContext, 0, std::queue<orc::ThreadSafeContext>> ContextPool;
413417

414418
#ifndef JL_USE_JITLINK
@@ -417,6 +421,7 @@ class JuliaOJIT {
417421
ObjLayerT ObjectLayer;
418422
const std::array<std::unique_ptr<PipelineT>, 4> Pipelines;
419423
OptSelLayerT OptSelLayer;
424+
CODLayerT CODLayer;
420425

421426
//Map and inc are guarded by RLST_mutex
422427
DenseMap<void*, std::string> ReverseLocalSymbolTable;

0 commit comments

Comments
 (0)