Просмотр исходного кода

Emit SIMD flag to AOT file only if SIMD is actually used (#2911)

Huang Qi 2 лет назад
Родитель
Сommit
7de3170af4

+ 1 - 1
.github/workflows/compilation_on_android_ubuntu.yml

@@ -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"
 

+ 16 - 0
core/iwasm/compilation/aot_llvm.c

@@ -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"
@@ -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;
+    }
+#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 */

+ 4 - 0
core/iwasm/interpreter/wasm.h

@@ -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 {

+ 19 - 0
core/iwasm/interpreter/wasm_loader.c

@@ -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) */
@@ -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;
@@ -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,
@@ -13576,6 +13590,11 @@ re_scan:
             {
                 uint32 opcode1;
 
+#if WASM_ENABLE_WAMR_COMPILER != 0
+                /* Mark the SIMD instruction is used in this module */
+                module->is_simd_used = true;
+#endif
+
                 CHECK_BUF(p, p_end, 1);
                 opcode1 = read_uint8(p);
                 /* follow the order of enum WASMSimdEXTOpcode in wasm_opcode.h