Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit SIMD flags to AOT file if SIMD actually used #2911

Merged
merged 1 commit into from
Dec 25, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/compilation_on_android_ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ env:
SIMD_TEST_OPTIONS: "-s spec -b -S -P"
THREADS_TEST_OPTIONS: "-s spec -b -p -P"
X86_32_TARGET_TEST_OPTIONS: "-m x86_32 -P"
WASI_TEST_OPTIONS: "-s wasi_certification -w -S"
WASI_TEST_OPTIONS: "-s wasi_certification -w"
WAMR_COMPILER_TEST_OPTIONS: "-s wamr_compiler -S -b -P"
GC_TEST_OPTIONS: "-s spec -G -b -P"

Expand Down
16 changes: 16 additions & 0 deletions core/iwasm/compilation/aot_llvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "aot_emit_table.h"
#include "../aot/aot_runtime.h"
#include "../aot/aot_intrinsic.h"
#include "../interpreter/wasm_runtime.h"

#if WASM_ENABLE_DEBUG_AOT != 0
#include "debug/dwarf_extractor.h"
Expand Down Expand Up @@ -3068,6 +3069,21 @@ aot_create_comp_context(const AOTCompData *comp_data, aot_comp_option_t option)
}
LLVMDisposeMessage(triple);

#if WASM_ENABLE_WAMR_COMPILER != 0
/* Return error if SIMD is disabled by command line but SIMD instructions
* are used */
if (!option->enable_simd
&& ((WASMModule *)comp_data->wasm_module)->is_simd_used) {
aot_set_last_error("SIMD is disabled by --disable-simd but SIMD "
"instructions are used in this module");
goto fail;
}

if (!((WASMModule *)comp_data->wasm_module)->is_simd_used) {
option->enable_simd = false;
wenyongh marked this conversation as resolved.
Show resolved Hide resolved
}
#endif

if (option->enable_simd && strcmp(comp_ctx->target_arch, "x86_64") != 0
&& strncmp(comp_ctx->target_arch, "aarch64", 7) != 0) {
/* Disable simd if it isn't supported by target arch */
Expand Down
4 changes: 4 additions & 0 deletions core/iwasm/interpreter/wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,10 @@ struct WASMModule {
functions in that group */
uint32 fast_jit_ready_groups;
#endif

#if WASM_ENABLE_WAMR_COMPILER != 0
bool is_simd_used;
#endif
};

typedef struct BlockType {
Expand Down
19 changes: 19 additions & 0 deletions core/iwasm/interpreter/wasm_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,10 @@ load_init_expr(WASMModule *module, const uint8 **p_buf, const uint8 *buf_end,
#endif
&cur_value, error_buf, error_buf_size))
goto fail;
#if WASM_ENABLE_WAMR_COMPILER != 0
/* If any init_expr is v128.const, mark SIMD used */
module->is_simd_used = true;
#endif
break;
}
#endif /* end of (WASM_ENABLE_WAMR_COMPILER != 0) || (WASM_ENABLE_JIT != 0) */
Expand Down Expand Up @@ -1471,6 +1475,11 @@ resolve_value_type(const uint8 **p_buf, const uint8 *buf_end,
}
ref_type->ref_type = type;
*p_need_ref_type_map = false;
#if WASM_ENABLE_WAMR_COMPILER != 0
/* If any value's type is v128, mark the module as SIMD used */
if (type == VALUE_TYPE_V128)
module->is_simd_used = true;
#endif
}

*p_buf = p;
Expand Down Expand Up @@ -3376,6 +3385,11 @@ load_function_section(const uint8 *buf, const uint8 *buf_end,
/* 0x7F/0x7E/0x7D/0x7C */
type = read_uint8(p_code);
local_count += sub_local_count;
#if WASM_ENABLE_WAMR_COMPILER != 0
/* If any value's type is v128, mark the module as SIMD used */
if (type == VALUE_TYPE_V128)
module->is_simd_used = true;
#endif
#else
if (!resolve_value_type(&p_code, buf_code_end, module,
&need_ref_type_map, &ref_type, false,
Expand Down Expand Up @@ -13576,6 +13590,11 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
{
uint32 opcode1;

#if WASM_ENABLE_WAMR_COMPILER != 0
/* Mark the SIMD instruction is used in this module */
module->is_simd_used = true;
no1wudi marked this conversation as resolved.
Show resolved Hide resolved
#endif

CHECK_BUF(p, p_end, 1);
opcode1 = read_uint8(p);
/* follow the order of enum WASMSimdEXTOpcode in wasm_opcode.h
Expand Down
Loading