Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions core/iwasm/compilation/aot_compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,19 @@ check_type_compatible(uint8 src_type, uint8 dst_type)
} \
} while (0)

/* if val is a constant integer and its value is not undef or poison */
static inline bool
LLVMIsEfficientConstInt(LLVMValueRef val)
{
return LLVMIsConstant(val)
&& LLVMGetValueKind(val) == LLVMConstantIntValueKind
&& !LLVMIsUndef(val)
#if LLVM_VERSION_NUMBER >= 12
&& !LLVMIsPoison(addr)
#endif
;
}

bool
aot_compile_wasm(AOTCompContext *comp_ctx);

Expand Down
7 changes: 4 additions & 3 deletions core/iwasm/compilation/aot_emit_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

#include "aot_emit_control.h"
#include "aot_compiler.h"
#include "aot_emit_exception.h"
#include "../aot/aot_runtime.h"
#include "../interpreter/wasm_loader.h"
Expand Down Expand Up @@ -469,7 +470,7 @@ aot_compile_op_block(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
p_frame_ip);
}

if (!LLVMIsConstant(value)) {
if (!LLVMIsEfficientConstInt(value)) {
/* Compare value is not constant, create condition br IR */
/* Create entry block */
format_block_name(name, sizeof(name), block->block_index,
Expand Down Expand Up @@ -835,7 +836,7 @@ aot_compile_op_br_if(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
return aot_handle_next_reachable_block(comp_ctx, func_ctx, p_frame_ip);
}

if (!LLVMIsConstant(value_cmp)) {
if (!LLVMIsEfficientConstInt(value_cmp)) {
/* Compare value is not constant, create condition br IR */
if (!(block_dst = get_target_block(func_ctx, br_depth))) {
return false;
Expand Down Expand Up @@ -972,7 +973,7 @@ aot_compile_op_br_table(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
return aot_handle_next_reachable_block(comp_ctx, func_ctx, p_frame_ip);
}

if (!LLVMIsConstant(value_cmp)) {
if (!LLVMIsEfficientConstInt(value_cmp)) {
/* Compare value is not constant, create switch IR */
for (i = 0; i <= br_count; i++) {
target_block = get_target_block(func_ctx, br_depths[i]);
Expand Down
13 changes: 3 additions & 10 deletions core/iwasm/compilation/aot_emit_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

#include "aot_emit_memory.h"
#include "aot_compiler.h"
#include "aot_emit_exception.h"
#include "../aot/aot_runtime.h"
#include "aot_intrinsic.h"
Expand Down Expand Up @@ -145,11 +146,7 @@ aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
* have been thrown when converting float to integer before
*/
/* return addres directly if constant offset and inside memory space */
if (LLVMIsConstant(addr) && !LLVMIsUndef(addr)
#if LLVM_VERSION_NUMBER >= 12
&& !LLVMIsPoison(addr)
#endif
) {
if (LLVMIsEfficientConstInt(addr)) {
uint64 mem_offset =
(uint64)LLVMConstIntGetZExtValue(addr) + (uint64)offset;
uint32 num_bytes_per_page =
Expand Down Expand Up @@ -911,11 +908,7 @@ check_bulk_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
* have been thrown when converting float to integer before
*/
/* return addres directly if constant offset and inside memory space */
if (!LLVMIsUndef(offset) && !LLVMIsUndef(bytes)
#if LLVM_VERSION_NUMBER >= 12
&& !LLVMIsPoison(offset) && !LLVMIsPoison(bytes)
#endif
&& LLVMIsConstant(offset) && LLVMIsConstant(bytes)) {
if (LLVMIsEfficientConstInt(offset) && LLVMIsEfficientConstInt(bytes)) {
uint64 mem_offset = (uint64)LLVMConstIntGetZExtValue(offset);
uint64 mem_len = (uint64)LLVMConstIntGetZExtValue(bytes);
uint32 num_bytes_per_page =
Expand Down
10 changes: 5 additions & 5 deletions core/iwasm/compilation/aot_emit_numberic.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@
} while (0)

#if LLVM_VERSION_NUMBER >= 12
#define IS_CONST_ZERO(val) \
(!LLVMIsUndef(val) && !LLVMIsPoison(val) && LLVMIsConstant(val) \
&& ((is_i32 && (int32)LLVMConstIntGetZExtValue(val) == 0) \
#define IS_CONST_ZERO(val) \
(LLVMIsEfficientConstInt(val) \
&& ((is_i32 && (int32)LLVMConstIntGetZExtValue(val) == 0) \
|| (!is_i32 && (int64)LLVMConstIntGetSExtValue(val) == 0)))
#else
#define IS_CONST_ZERO(val) \
(!LLVMIsUndef(val) && LLVMIsConstant(val) \
(LLVMIsEfficientConstInt(val) \
&& ((is_i32 && (int32)LLVMConstIntGetZExtValue(val) == 0) \
|| (!is_i32 && (int64)LLVMConstIntGetSExtValue(val) == 0)))
#endif
Expand Down Expand Up @@ -473,7 +473,7 @@ compile_int_div(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
return aot_handle_next_reachable_block(comp_ctx, func_ctx, p_frame_ip);
}

if (LLVMIsConstant(right)) {
if (LLVMIsEfficientConstInt(right)) {
int64 right_val = (int64)LLVMConstIntGetSExtValue(right);
switch (right_val) {
case 0:
Expand Down