mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-05-14 13:41:31 +00:00
Fix wamrc build issues with LLVM 13 and LLVM 16 (#2313)
Fix some build errors when building wamrc with LLVM-13, reported in #2311 Fix some build warnings when building wamrc with LLVM-16: ``` core/iwasm/compilation/aot_llvm_extra2.cpp:26:26: warning: ‘llvm::None’ is deprecated: Use std::nullopt instead. [-Wdeprecated-declarations] 26 | return llvm::None; ``` Fix a maybe-uninitialized compile warning: ``` core/iwasm/compilation/aot_llvm.c:413:9: warning: ‘update_top_block’ may be used uninitialized in this function [-Wmaybe-uninitialized] 413 | LLVMPositionBuilderAtEnd(b, update_top_block); ```
This commit is contained in:
parent
f5c5a83331
commit
ea78b89965
|
@ -242,11 +242,11 @@ aot_add_precheck_function(AOTCompContext *comp_ctx, LLVMModuleRef module,
|
||||||
LLVMTypeRef func_type, LLVMValueRef wrapped_func)
|
LLVMTypeRef func_type, LLVMValueRef wrapped_func)
|
||||||
{
|
{
|
||||||
LLVMValueRef precheck_func;
|
LLVMValueRef precheck_func;
|
||||||
LLVMBasicBlockRef begin;
|
LLVMBasicBlockRef begin = NULL;
|
||||||
LLVMBasicBlockRef check_top_block;
|
LLVMBasicBlockRef check_top_block = NULL;
|
||||||
LLVMBasicBlockRef update_top_block;
|
LLVMBasicBlockRef update_top_block = NULL;
|
||||||
LLVMBasicBlockRef stack_bound_check_block;
|
LLVMBasicBlockRef stack_bound_check_block = NULL;
|
||||||
LLVMBasicBlockRef call_wrapped_func_block;
|
LLVMBasicBlockRef call_wrapped_func_block = NULL;
|
||||||
LLVMValueRef *params = NULL;
|
LLVMValueRef *params = NULL;
|
||||||
|
|
||||||
precheck_func =
|
precheck_func =
|
||||||
|
@ -385,6 +385,8 @@ aot_add_precheck_function(AOTCompContext *comp_ctx, LLVMModuleRef module,
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bh_assert(update_top_block);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* update native_stack_top_min if
|
* update native_stack_top_min if
|
||||||
* new_sp = sp - size < native_stack_top_min
|
* new_sp = sp - size < native_stack_top_min
|
||||||
|
@ -412,7 +414,7 @@ aot_add_precheck_function(AOTCompContext *comp_ctx, LLVMModuleRef module,
|
||||||
*/
|
*/
|
||||||
LLVMPositionBuilderAtEnd(b, update_top_block);
|
LLVMPositionBuilderAtEnd(b, update_top_block);
|
||||||
LLVMValueRef new_sp_ptr =
|
LLVMValueRef new_sp_ptr =
|
||||||
LLVMBuildIntToPtr(b, new_sp, OPQ_PTR_TYPE, "new_sp_ptr");
|
LLVMBuildIntToPtr(b, new_sp, INT8_PTR_TYPE, "new_sp_ptr");
|
||||||
if (!new_sp_ptr) {
|
if (!new_sp_ptr) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -1376,25 +1378,33 @@ static bool
|
||||||
aot_create_stack_sizes(const AOTCompData *comp_data, AOTCompContext *comp_ctx)
|
aot_create_stack_sizes(const AOTCompData *comp_data, AOTCompContext *comp_ctx)
|
||||||
{
|
{
|
||||||
const char *stack_sizes_name = "stack_sizes";
|
const char *stack_sizes_name = "stack_sizes";
|
||||||
LLVMTypeRef stack_sizes_type =
|
LLVMValueRef stack_sizes, *values, array, alias;
|
||||||
LLVMArrayType(I32_TYPE, comp_data->func_count);
|
LLVMTypeRef stack_sizes_type;
|
||||||
|
#if LLVM_VERSION_MAJOR <= 13
|
||||||
|
LLVMTypeRef alias_type;
|
||||||
|
#endif
|
||||||
|
uint64 size;
|
||||||
|
uint32 i;
|
||||||
|
|
||||||
|
stack_sizes_type = LLVMArrayType(I32_TYPE, comp_data->func_count);
|
||||||
if (!stack_sizes_type) {
|
if (!stack_sizes_type) {
|
||||||
aot_set_last_error("failed to create stack_sizes type.");
|
aot_set_last_error("failed to create stack_sizes type.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
LLVMValueRef stack_sizes =
|
|
||||||
|
stack_sizes =
|
||||||
LLVMAddGlobal(comp_ctx->module, stack_sizes_type, stack_sizes_name);
|
LLVMAddGlobal(comp_ctx->module, stack_sizes_type, stack_sizes_name);
|
||||||
if (!stack_sizes) {
|
if (!stack_sizes) {
|
||||||
aot_set_last_error("failed to create stack_sizes global.");
|
aot_set_last_error("failed to create stack_sizes global.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
LLVMValueRef *values;
|
|
||||||
uint64 size = sizeof(LLVMValueRef) * comp_data->func_count;
|
size = sizeof(LLVMValueRef) * comp_data->func_count;
|
||||||
if (size >= UINT32_MAX || !(values = wasm_runtime_malloc((uint32)size))) {
|
if (size >= UINT32_MAX || !(values = wasm_runtime_malloc((uint32)size))) {
|
||||||
aot_set_last_error("allocate memory failed.");
|
aot_set_last_error("allocate memory failed.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
uint32 i;
|
|
||||||
for (i = 0; i < comp_data->func_count; i++) {
|
for (i = 0; i < comp_data->func_count; i++) {
|
||||||
/*
|
/*
|
||||||
* This value is a placeholder, which will be replaced
|
* This value is a placeholder, which will be replaced
|
||||||
|
@ -1405,23 +1415,35 @@ aot_create_stack_sizes(const AOTCompData *comp_data, AOTCompContext *comp_ctx)
|
||||||
*/
|
*/
|
||||||
values[i] = I32_NEG_ONE;
|
values[i] = I32_NEG_ONE;
|
||||||
}
|
}
|
||||||
LLVMValueRef array =
|
|
||||||
LLVMConstArray(I32_TYPE, values, comp_data->func_count);
|
array = LLVMConstArray(I32_TYPE, values, comp_data->func_count);
|
||||||
wasm_runtime_free(values);
|
wasm_runtime_free(values);
|
||||||
if (!array) {
|
if (!array) {
|
||||||
aot_set_last_error("failed to create stack_sizes initializer.");
|
aot_set_last_error("failed to create stack_sizes initializer.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
LLVMSetInitializer(stack_sizes, array);
|
LLVMSetInitializer(stack_sizes, array);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* create an alias so that aot_resolve_stack_sizes can find it.
|
* create an alias so that aot_resolve_stack_sizes can find it.
|
||||||
*/
|
*/
|
||||||
LLVMValueRef alias = LLVMAddAlias2(comp_ctx->module, stack_sizes_type, 0,
|
#if LLVM_VERSION_MAJOR > 13
|
||||||
stack_sizes, aot_stack_sizes_name);
|
alias = LLVMAddAlias2(comp_ctx->module, stack_sizes_type, 0, stack_sizes,
|
||||||
|
aot_stack_sizes_name);
|
||||||
|
#else
|
||||||
|
alias_type = LLVMPointerType(stack_sizes_type, 0);
|
||||||
|
if (!alias_type) {
|
||||||
|
aot_set_last_error("failed to create alias type.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
alias = LLVMAddAlias(comp_ctx->module, alias_type, stack_sizes,
|
||||||
|
aot_stack_sizes_name);
|
||||||
|
#endif
|
||||||
if (!alias) {
|
if (!alias) {
|
||||||
aot_set_last_error("failed to create stack_sizes alias.");
|
aot_set_last_error("failed to create stack_sizes alias.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* make the original symbol internal. we mainly use this version to
|
* make the original symbol internal. we mainly use this version to
|
||||||
* avoid creating extra relocations in the precheck functions.
|
* avoid creating extra relocations in the precheck functions.
|
||||||
|
|
|
@ -235,7 +235,11 @@ aot_apply_llvm_new_pass_manager(AOTCompContext *comp_ctx, LLVMModuleRef module)
|
||||||
PTO.SLPVectorization = true;
|
PTO.SLPVectorization = true;
|
||||||
PTO.LoopUnrolling = true;
|
PTO.LoopUnrolling = true;
|
||||||
|
|
||||||
Optional<PGOOptions> PGO = None;
|
#if LLVM_VERSION_MAJOR >= 16
|
||||||
|
Optional<PGOOptions> PGO = std::nullopt;
|
||||||
|
#else
|
||||||
|
Optional<PGOOptions> PGO = llvm::None;
|
||||||
|
#endif
|
||||||
if (comp_ctx->enable_llvm_pgo) {
|
if (comp_ctx->enable_llvm_pgo) {
|
||||||
/* Disable static counter allocation for value profiler,
|
/* Disable static counter allocation for value profiler,
|
||||||
it will be allocated by runtime */
|
it will be allocated by runtime */
|
||||||
|
|
|
@ -23,7 +23,11 @@ convert(LLVMRelocMode reloc_mode)
|
||||||
{
|
{
|
||||||
switch (reloc_mode) {
|
switch (reloc_mode) {
|
||||||
case LLVMRelocDefault:
|
case LLVMRelocDefault:
|
||||||
|
#if LLVM_VERSION_MAJOR >= 16
|
||||||
|
return std::nullopt;
|
||||||
|
#else
|
||||||
return llvm::None;
|
return llvm::None;
|
||||||
|
#endif
|
||||||
case LLVMRelocStatic:
|
case LLVMRelocStatic:
|
||||||
return llvm::Reloc::Static;
|
return llvm::Reloc::Static;
|
||||||
case LLVMRelocPIC:
|
case LLVMRelocPIC:
|
||||||
|
@ -38,7 +42,11 @@ convert(LLVMRelocMode reloc_mode)
|
||||||
return llvm::Reloc::ROPI_RWPI;
|
return llvm::Reloc::ROPI_RWPI;
|
||||||
}
|
}
|
||||||
bh_assert(0);
|
bh_assert(0);
|
||||||
|
#if LLVM_VERSION_MAJOR >= 16
|
||||||
|
return std::nullopt;
|
||||||
|
#else
|
||||||
return llvm::None;
|
return llvm::None;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static llvm::CodeGenOpt::Level
|
static llvm::CodeGenOpt::Level
|
||||||
|
@ -64,10 +72,18 @@ convert(LLVMCodeModel code_model, bool *jit)
|
||||||
*jit = false;
|
*jit = false;
|
||||||
switch (code_model) {
|
switch (code_model) {
|
||||||
case LLVMCodeModelDefault:
|
case LLVMCodeModelDefault:
|
||||||
|
#if LLVM_VERSION_MAJOR >= 16
|
||||||
|
return std::nullopt;
|
||||||
|
#else
|
||||||
return llvm::None;
|
return llvm::None;
|
||||||
|
#endif
|
||||||
case LLVMCodeModelJITDefault:
|
case LLVMCodeModelJITDefault:
|
||||||
*jit = true;
|
*jit = true;
|
||||||
|
#if LLVM_VERSION_MAJOR >= 16
|
||||||
|
return std::nullopt;
|
||||||
|
#else
|
||||||
return llvm::None;
|
return llvm::None;
|
||||||
|
#endif
|
||||||
case LLVMCodeModelTiny:
|
case LLVMCodeModelTiny:
|
||||||
return llvm::CodeModel::Tiny;
|
return llvm::CodeModel::Tiny;
|
||||||
case LLVMCodeModelSmall:
|
case LLVMCodeModelSmall:
|
||||||
|
@ -80,7 +96,11 @@ convert(LLVMCodeModel code_model, bool *jit)
|
||||||
return llvm::CodeModel::Large;
|
return llvm::CodeModel::Large;
|
||||||
}
|
}
|
||||||
bh_assert(0);
|
bh_assert(0);
|
||||||
|
#if LLVM_VERSION_MAJOR >= 16
|
||||||
|
return std::nullopt;
|
||||||
|
#else
|
||||||
return llvm::None;
|
return llvm::None;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
LLVMTargetMachineRef
|
LLVMTargetMachineRef
|
||||||
|
|
|
@ -112,10 +112,16 @@ MyCompiler::operator()(llvm::Module &M)
|
||||||
PM.run(M);
|
PM.run(M);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if LLVM_VERSION_MAJOR > 13
|
||||||
auto ObjBuffer = std::make_unique<llvm::SmallVectorMemoryBuffer>(
|
auto ObjBuffer = std::make_unique<llvm::SmallVectorMemoryBuffer>(
|
||||||
std::move(ObjBufferSV),
|
std::move(ObjBufferSV),
|
||||||
M.getModuleIdentifier() + "-jitted-objectbuffer",
|
M.getModuleIdentifier() + "-jitted-objectbuffer",
|
||||||
/*RequiresNullTerminator=*/false);
|
/*RequiresNullTerminator=*/false);
|
||||||
|
#else
|
||||||
|
auto ObjBuffer = std::make_unique<llvm::SmallVectorMemoryBuffer>(
|
||||||
|
std::move(ObjBufferSV),
|
||||||
|
M.getModuleIdentifier() + "-jitted-objectbuffer");
|
||||||
|
#endif
|
||||||
|
|
||||||
return std::move(ObjBuffer);
|
return std::move(ObjBuffer);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user