Tags: None
State: None
Code
Design Overview
- emulates linking and symbol resolution resolution
- allows ORC to jit arbitary LLVM IR
ExecutionEngine
https://llvm.org/docs/ORCv2.html#how-to-add-process-and-library-symbols-to-jitdylibs
Experiments
Running Program as a REPL
Design:
- Aim to execute code arbitrarily in running process, with access to memory, etc.
- Shared API for memory
Other thoughts:
- We could probably
Compile to LLVM IR with clang
-
Code /Users/miguelmartin/repos/langdev/repl-tests
- main program
- shared api
- shared api to hold state defns
- repl api
- given a string => execute it in the main process
-
Commands to Execute
Tutorial
https://llvm.org/docs/ORCv2.html
Chapter 1
https://llvm.org/docs/tutorial/BuildingAJIT1.html
Bare bones JIT API has just two functions:
- addModule(Unique<Module>)
- makes the given IR module available for execution
- Expected<JITEvaluatedSymbol> lookup()
- searches for pointers to symbols
KaleidoscopeJIT class has the following members:
- ExecutionSession (ES)
- context for running JIT'd code, includes a:
- string pool, global mutex and error reporting
- context for running JIT'd code, includes a:
- RTDyldObjectLinkingLayer (ObjectLayer)
- Can be used to add object files to the JIT
- Not used directly
- IRCompileLayer (CompileLayer)
- Add LLVM modules to the JIT
- DataLayout (DL)
- MangleAndInterner (Mangle)
- symbol and mangle layout
- ThreadSafeContext (Ctx)
- Used when building IR files
JITTargetMachineBuilder, used by DataLayout & IRCompileLayer
Talks
2018 Meeting
Implementing LLJit
Construct:
- ExecutionSession, contains:
- String pool
- Session mutex
- Error reporting
- RTDylibObjectLinkingLayer
- adds object files to JITDylib
- ConcurrentIRCompiler
- Compiles LLVM IR to asm
- For lazy:
- ComplieOnDemandLayer
- For multi-threaded:
- ES.setDispatchMaterialization
- <insert code to execute on a thread pool / seperate thread>
- ES.setDispatchMaterialization
Layers wrap compilers MaterializationUnits wrap program representations MaterializationResponsibility tracks compiler responsibilities
2021 ORCv2
JITLink
- LinkGraph
- object file
- LinkGraph builder
- LinkGraph
- JITLinker
- Linking Context
- Pass pipeline modification
- Add passes, any callable of Error(LinkGraph& G)
- Phases:
- pre-prune
- mark elements alive before dead-stripping
- post-prune
- add/remove content (GOT, PLT entries). Global Offset Table entries, Procedure Linkage Table entries
- post-alloc
- respond to assinged addressed for defined symbols
- use-cases: internal book-keeping
- pre-fixup
- access final addresses, e.g. for instruction optimization
- post-fixup
- react to linked content after fixups have been applied
- pre-prune
Error interpoFunctions(LinkGraph& G) { for(auto *B: G.blocks()) { for(auto& E : B->edges()) { E.setTarget(getStubeFor(E.getTarget())); } } return Error::success(); }
Can do many things:
- Instruction stream optimization
- Redirect calls and branches
- Insert instrumentation