How AOT is implemented in LLVM
Compile everything with metadata structure and store in the struct comp_ctx.
Module
is the basic unit of compilation- Optimization
- Passes
- Dynamic Linking(Von Neumann Architecture)
- Auxiliary data structure
- StandAlone Linker and Loader Relocation for function library
How JIT is implemented in LLVM
ORCJIT is not a standalone JIT engine and do not have dynamic compilation with program synthesis optimization.
- Concurrent/Speculative/Eager compilation, compilation on lookup with reexport/linking/indirection support
- low compilation overhead
- may be slow first time call
- Remote execution & debugging support [4]
- Good for live migration
- not good mapping accross platform
- Have standalone comp_ctx struct update during runtime. You can store the runtime information in the struct through runtime API.
- Runtime
- Try-Catch
- Static Var Init
- dlopen
- TLS
- C ABI
- Auto memory management for JITed code
- dwarf debug info(refer to julia) [3]
- codecache
What's the implementation of AOT in WAMR
aot_loader.c
is the main entry point of AOTaot_runtime.c
gives the runtime export function for AOT that can hook for specific logic exportsaot_compile.c
you can export the logic and output the corresponding calls the runtime function. etc.aot_alloc_frame
andaot_free_frame
withaot_call_indirect
andaot_call
to call the function with--aot-dump-frame
on for wamrc option.aot_emit_*.c
is the instruction emmitter for every instruction in wasm which literally the same as interpretor but to LLVM backend.- checkpoint happens with LLVM passes that insert the
INT3
withfence
on top of the label. where the wasm stack is stateless of the LLVM state which we can snapshot all the corresponding state to wasm view. Restore happens to make the stateless wasm stack back to the LLVM state. which literally skip the logic that happens before the checkpoint.
References
- https://www.bilibili.com/video/BV13a41187NM/?spm_id_from=333.337.search-card.all.click
- https://dl.acm.org/doi/abs/10.1145/3603165.3607393
- https://ieeexplore.ieee.org/abstract/document/9912710
- https://link.springer.com/chapter/10.1007/978-3-319-39077-2_10
- https://github.com/llvm/llvm-project/trße/main/llvm/examples/OrcV2Examples