Refactor LLVM JIT (#1613)
Refactor LLVM JIT for some purposes: - To simplify the source code of JIT compilation - To simplify the JIT modes - To align with LLVM latest changes - To prepare for the Multi-tier JIT compilation, refer to #1302 The changes mainly include: - Remove the MCJIT mode, replace it with ORC JIT eager mode - Remove the LLVM legacy pass manager (only keep the LLVM new pass manager) - Change the lazy mode's LLVM module/function binding: change each function in an individual LLVM module into all functions in a single LLVM module - Upgraded ORC JIT to ORCv2 JIT to enable lazy compilation Refer to #1468
This commit is contained in:
@ -20,20 +20,18 @@
|
||||
#include "llvm-c/Transforms/Vectorize.h"
|
||||
#include "llvm-c/Transforms/PassManagerBuilder.h"
|
||||
|
||||
#if WASM_ENABLE_LAZY_JIT != 0
|
||||
#include "llvm-c/Orc.h"
|
||||
#include "llvm-c/Error.h"
|
||||
#include "llvm-c/Support.h"
|
||||
#include "llvm-c/Initialization.h"
|
||||
#include "llvm-c/TargetMachine.h"
|
||||
#if LLVM_VERSION_MAJOR >= 12
|
||||
#include "llvm-c/LLJIT.h"
|
||||
#endif
|
||||
#endif
|
||||
#if WASM_ENABLE_DEBUG_AOT != 0
|
||||
#include "llvm-c/DebugInfo.h"
|
||||
#endif
|
||||
|
||||
#include "aot_orc_extra.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@ -52,6 +50,16 @@ extern "C" {
|
||||
#define OPQ_PTR_TYPE INT8_PTR_TYPE
|
||||
#endif
|
||||
|
||||
#ifndef NDEBUG
|
||||
#undef DEBUG_PASS
|
||||
#undef DUMP_MODULE
|
||||
// #define DEBUG_PASS
|
||||
// #define DUMP_MODULE
|
||||
#else
|
||||
#undef DEBUG_PASS
|
||||
#undef DUMP_MODULE
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Value in the WASM operation stack, each stack element
|
||||
* is an LLVM value
|
||||
@ -270,12 +278,6 @@ typedef struct AOTCompContext {
|
||||
|
||||
/* LLVM variables required to emit LLVM IR */
|
||||
LLVMContextRef context;
|
||||
#if WASM_ENABLE_LAZY_JIT == 0
|
||||
/* Create one module only for non LAZY JIT mode,
|
||||
for LAZY JIT mode, modules are created, each
|
||||
aot function has its own module */
|
||||
LLVMModuleRef module;
|
||||
#endif
|
||||
LLVMBuilderRef builder;
|
||||
#if WASM_ENABLE_DEBUG_AOT
|
||||
LLVMDIBuilderRef debug_builder;
|
||||
@ -290,19 +292,11 @@ typedef struct AOTCompContext {
|
||||
/* Hardware intrinsic compability flags */
|
||||
uint64 flags[8];
|
||||
|
||||
/* LLVM execution engine required by JIT */
|
||||
#if WASM_ENABLE_LAZY_JIT != 0
|
||||
LLVMOrcLLJITRef orc_lazyjit;
|
||||
LLVMOrcMaterializationUnitRef orc_material_unit;
|
||||
LLVMOrcLazyCallThroughManagerRef orc_call_through_mgr;
|
||||
LLVMOrcIndirectStubsManagerRef orc_indirect_stub_mgr;
|
||||
LLVMOrcCSymbolAliasMapPairs orc_symbol_map_pairs;
|
||||
/* required by JIT */
|
||||
LLVMOrcLLLazyJITRef orc_jit;
|
||||
LLVMOrcThreadSafeContextRef orc_thread_safe_context;
|
||||
/* Each aot function has its own module */
|
||||
LLVMModuleRef *modules;
|
||||
#else
|
||||
LLVMExecutionEngineRef exec_engine;
|
||||
#endif
|
||||
|
||||
LLVMModuleRef module;
|
||||
|
||||
bool is_jit_mode;
|
||||
|
||||
@ -361,6 +355,7 @@ typedef struct AOTCompContext {
|
||||
AOTLLVMConsts llvm_consts;
|
||||
|
||||
/* Function contexts */
|
||||
/* TODO: */
|
||||
AOTFuncContext **func_ctxes;
|
||||
uint32 func_ctx_count;
|
||||
char **custom_sections_wp;
|
||||
@ -503,24 +498,11 @@ void
|
||||
aot_add_simple_loop_unswitch_pass(LLVMPassManagerRef pass);
|
||||
|
||||
void
|
||||
aot_apply_llvm_new_pass_manager(AOTCompContext *comp_ctx);
|
||||
|
||||
#if WASM_ENABLE_LAZY_JIT != 0
|
||||
LLVMOrcJITTargetMachineBuilderRef
|
||||
LLVMOrcJITTargetMachineBuilderCreateFromTargetMachine(LLVMTargetMachineRef TM);
|
||||
|
||||
void
|
||||
LLVMOrcLLJITBuilderSetNumCompileThreads(LLVMOrcLLJITBuilderRef orcjit_builder,
|
||||
unsigned num_compile_threads);
|
||||
aot_apply_llvm_new_pass_manager(AOTCompContext *comp_ctx, LLVMModuleRef module);
|
||||
|
||||
void
|
||||
aot_handle_llvm_errmsg(const char *string, LLVMErrorRef err);
|
||||
|
||||
void *
|
||||
aot_lookup_orcjit_func(LLVMOrcLLJITRef orc_lazyjit, void *module_inst,
|
||||
uint32 func_idx);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* end of extern "C" */
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user