From 26aa25d647c5a546951080af59686e2d7dfe5863 Mon Sep 17 00:00:00 2001 From: 0xacc Date: Mon, 5 Jun 2023 04:56:37 +0000 Subject: [PATCH] [to #50012708] eagerly init LLVM in PL LLVM helper --- src/objit/include/objit/ob_llvm_helper.h | 1 + src/objit/src/ob_llvm_helper.cpp | 53 +++++++++++++++++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/objit/include/objit/ob_llvm_helper.h b/src/objit/include/objit/ob_llvm_helper.h index b58d5076b4..c5a3ca4d01 100644 --- a/src/objit/include/objit/ob_llvm_helper.h +++ b/src/objit/include/objit/ob_llvm_helper.h @@ -449,6 +449,7 @@ public: private: int check_insert_point(bool &is_valid); + static int init_llvm(); private: common::ObIAllocator &allocator_; diff --git a/src/objit/src/ob_llvm_helper.cpp b/src/objit/src/ob_llvm_helper.cpp index 18518e91cf..94d3689aa5 100644 --- a/src/objit/src/ob_llvm_helper.cpp +++ b/src/objit/src/ob_llvm_helper.cpp @@ -22,6 +22,7 @@ #include "llvm/Support/TargetSelect.h" #include "llvm/Support/DynamicLibrary.h" +#include "share/ob_define.h" #include "objit/ob_llvm_helper.h" #include "objit/ob_llvm_di_helper.h" #include "lib/oblog/ob_log_module.h" @@ -52,6 +53,13 @@ typedef llvm::IRBuilder<> ObIRBuilder; typedef llvm::Module ObIRModule; typedef llvm::ExecutionEngine ObLLVMExecEngine; +#if !defined(__aarch64__) +namespace llvm { + struct X86MemoryFoldTableEntry; + extern const X86MemoryFoldTableEntry* lookupUnfoldTable(unsigned MemOp); +} +#endif + namespace oceanbase { using namespace common; @@ -521,10 +529,53 @@ void ObLLVMHelper::final() int ObLLVMHelper::initialize() { + int ret = OB_SUCCESS; + llvm::InitializeNativeTarget(); llvm::InitializeNativeTargetAsmPrinter(); llvm::InitializeNativeTargetAsmParser(); - return OB_SUCCESS; + +#if !defined(__aarch64__) + // initialize LLVM X86 unfold table + llvm::lookupUnfoldTable(0); +#endif + + OZ (init_llvm()); + + return ret; +} + +int ObLLVMHelper::init_llvm() { + int ret = OB_SUCCESS; + + ObArenaAllocator alloc("PlJit", OB_MALLOC_NORMAL_BLOCK_SIZE, MTL_ID()); + ObLLVMHelper helper(alloc); + ObLLVMDIHelper di_helper(alloc); + static char init_func_name[] = "pl_init_func"; + + OZ (helper.init()); + OZ (di_helper.init(helper.get_jc())); + + ObSEArray arg_types; + ObLLVMType int64_type; + ObLLVMFunction init_func; + ObLLVMFunctionType ft; + ObLLVMBasicBlock block; + ObLLVMValue magic; + + OZ (helper.get_llvm_type(ObIntType, int64_type)); + OZ (arg_types.push_back(int64_type)); + OZ (ObLLVMFunctionType::get(int64_type, arg_types, ft)); + OZ (helper.create_function(init_func_name, ft, init_func)); + OZ (helper.create_block("entry", init_func, block)); + OZ (helper.set_insert_point(block)); + OZ (helper.get_int64(OB_SUCCESS, magic)); + OZ (helper.create_ret(magic)); + + OX (helper.compile_module()); + OX (helper.get_function_address(init_func_name)); + + return ret; } void ObLLVMHelper::compile_module(bool optimization)