Skip to content

Commit 5e23832

Browse files
authored
Enable aot compiler with llvm-14/15 (#1252)
Enable aot compiler and jit based on llvm-14.0 and llvm-15.0git, replace LLVMBuildLoad/LLVMBuildInBoundsGEP/LLVMBuildCall with LLVMBuildLoad2/LLVMBuildInBoundsGEP2/LLVMBuildCall2, and pass them with related types, so as to meet the requirements of opaque pointers. And fix several compilation errors for llvm-14.0/15.0git. Most spec cases and standalone cases are tested.
1 parent 2746d29 commit 5e23832

File tree

12 files changed

+431
-301
lines changed

12 files changed

+431
-301
lines changed

core/iwasm/compilation/aot_compiler.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2641,7 +2641,12 @@ apply_func_passes(AOTCompContext *comp_ctx)
26412641
LLVMAddLoopVectorizePass(pass_mgr);
26422642
LLVMAddSLPVectorizePass(pass_mgr);
26432643
LLVMAddLoopRotatePass(pass_mgr);
2644+
#if LLVM_VERSION_MAJOR < 15
26442645
LLVMAddLoopUnswitchPass(pass_mgr);
2646+
/* Binding disabled in LLVM 15, don't add the pass util we can either
2647+
add a binding to SimpleLoopUnswitchPass, or add it to
2648+
aot_llvm_extra.cpp */
2649+
#endif
26452650
LLVMAddInstructionCombiningPass(pass_mgr);
26462651
LLVMAddCFGSimplificationPass(pass_mgr);
26472652
if (!comp_ctx->enable_thread_mgr) {
@@ -2694,8 +2699,10 @@ apply_lto_passes(AOTCompContext *comp_ctx)
26942699
LLVMPassManagerBuilderSetOptLevel(pass_mgr_builder, comp_ctx->opt_level);
26952700
LLVMPassManagerBuilderPopulateModulePassManager(pass_mgr_builder,
26962701
common_pass_mgr);
2702+
#if LLVM_VERSION_MAJOR < 15
26972703
LLVMPassManagerBuilderPopulateLTOPassManager(pass_mgr_builder,
26982704
common_pass_mgr, true, true);
2705+
#endif
26992706

27002707
#if WASM_ENABLE_LAZY_JIT == 0
27012708
LLVMRunPassManager(common_pass_mgr, comp_ctx->module);

core/iwasm/compilation/aot_emit_const.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ aot_compile_op_f32_const(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
7272
aot_set_last_error("llvm build bitcast failed.");
7373
return false;
7474
}
75-
if (!(value = LLVMBuildLoad(comp_ctx->builder, alloca, ""))) {
75+
if (!(value =
76+
LLVMBuildLoad2(comp_ctx->builder, F32_TYPE, alloca, ""))) {
7677
aot_set_last_error("llvm build load failed.");
7778
return false;
7879
}
@@ -127,7 +128,8 @@ aot_compile_op_f64_const(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
127128
aot_set_last_error("llvm build bitcast failed.");
128129
return false;
129130
}
130-
if (!(value = LLVMBuildLoad(comp_ctx->builder, alloca, ""))) {
131+
if (!(value =
132+
LLVMBuildLoad2(comp_ctx->builder, F64_TYPE, alloca, ""))) {
131133
aot_set_last_error("llvm build load failed.");
132134
return false;
133135
}

core/iwasm/compilation/aot_emit_control.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -677,9 +677,9 @@ check_suspend_flags(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
677677
/* Offset of suspend_flags */
678678
offset = I32_FIVE;
679679

680-
if (!(terminate_addr =
681-
LLVMBuildInBoundsGEP(comp_ctx->builder, func_ctx->exec_env,
682-
&offset, 1, "terminate_addr"))) {
680+
if (!(terminate_addr = LLVMBuildInBoundsGEP2(
681+
comp_ctx->builder, OPQ_PTR_TYPE, func_ctx->exec_env, &offset, 1,
682+
"terminate_addr"))) {
683683
aot_set_last_error("llvm build in bounds gep failed");
684684
return false;
685685
}
@@ -690,8 +690,9 @@ check_suspend_flags(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
690690
return false;
691691
}
692692

693-
if (!(terminate_flags = LLVMBuildLoad(comp_ctx->builder, terminate_addr,
694-
"terminate_flags"))) {
693+
if (!(terminate_flags =
694+
LLVMBuildLoad2(comp_ctx->builder, I32_TYPE, terminate_addr,
695+
"terminate_flags"))) {
695696
aot_set_last_error("llvm build bit cast failed");
696697
return false;
697698
}

core/iwasm/compilation/aot_emit_exception.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ aot_emit_exception(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
9696
/* Call the aot_set_exception_with_id() function */
9797
param_values[0] = func_ctx->aot_inst;
9898
param_values[1] = func_ctx->exception_id_phi;
99-
if (!LLVMBuildCall(comp_ctx->builder, func, param_values, 2, "")) {
99+
if (!LLVMBuildCall2(comp_ctx->builder, func_type, func, param_values, 2,
100+
"")) {
100101
aot_set_last_error("llvm build call failed.");
101102
return false;
102103
}

0 commit comments

Comments
 (0)