Răsfoiți Sursa

GC AOT: Change func_types to types in AOTModule (#2217)

Huang Qi 2 ani în urmă
părinte
comite
e189dcbc9f

+ 14 - 14
core/iwasm/aot/aot_loader.c

@@ -1111,14 +1111,14 @@ load_func_types(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
     uint32 i;
 
     /* Allocate memory */
-    size = sizeof(AOTFuncType *) * (uint64)module->func_type_count;
-    if (!(module->func_types = func_types =
+    size = sizeof(AOTFuncType *) * (uint64)module->type_count;
+    if (!(module->types = func_types =
               loader_malloc(size, error_buf, error_buf_size))) {
         return false;
     }
 
     /* Create each function type */
-    for (i = 0; i < module->func_type_count; i++) {
+    for (i = 0; i < module->type_count; i++) {
         uint32 param_count, result_count;
         uint32 param_cell_num, ret_cell_num;
         uint64 size1;
@@ -1167,10 +1167,10 @@ load_func_type_info(const uint8 **p_buf, const uint8 *buf_end,
 {
     const uint8 *buf = *p_buf;
 
-    read_uint32(buf, buf_end, module->func_type_count);
+    read_uint32(buf, buf_end, module->type_count);
 
     /* load function type */
-    if (module->func_type_count > 0
+    if (module->type_count > 0
         && !load_func_types(&buf, buf_end, module, error_buf, error_buf_size))
         return false;
 
@@ -1373,12 +1373,12 @@ load_import_funcs(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
     /* Create each import func */
     for (i = 0; i < module->import_func_count; i++) {
         read_uint16(buf, buf_end, import_funcs[i].func_type_index);
-        if (import_funcs[i].func_type_index >= module->func_type_count) {
+        if (import_funcs[i].func_type_index >= module->type_count) {
             set_error_buf(error_buf, error_buf_size, "unknown type");
             return false;
         }
         import_funcs[i].func_type =
-            module->func_types[import_funcs[i].func_type_index];
+            module->types[import_funcs[i].func_type_index];
         read_string(buf, buf_end, import_funcs[i].module_name);
         read_string(buf, buf_end, import_funcs[i].func_name);
 
@@ -1721,7 +1721,7 @@ load_function_section(const uint8 *buf, const uint8 *buf_end, AOTModule *module,
 
     for (i = 0; i < module->func_count; i++) {
         read_uint32(p, p_end, module->func_type_indexes[i]);
-        if (module->func_type_indexes[i] >= module->func_type_count) {
+        if (module->func_type_indexes[i] >= module->type_count) {
             set_error_buf(error_buf, error_buf_size, "unknown type");
             return false;
         }
@@ -2553,7 +2553,7 @@ load_from_sections(AOTModule *module, AOTSection *sections,
             if (!strcmp(exports[i].name, "malloc")) {
                 func_index = exports[i].index - module->import_func_count;
                 func_type_index = module->func_type_indexes[func_index];
-                func_type = module->func_types[func_type_index];
+                func_type = module->types[func_type_index];
                 if (func_type->param_count == 1 && func_type->result_count == 1
                     && func_type->types[0] == VALUE_TYPE_I32
                     && func_type->types[1] == VALUE_TYPE_I32) {
@@ -2566,7 +2566,7 @@ load_from_sections(AOTModule *module, AOTSection *sections,
             else if (!strcmp(exports[i].name, "__new")) {
                 func_index = exports[i].index - module->import_func_count;
                 func_type_index = module->func_type_indexes[func_index];
-                func_type = module->func_types[func_type_index];
+                func_type = module->types[func_type_index];
                 if (func_type->param_count == 2 && func_type->result_count == 1
                     && func_type->types[0] == VALUE_TYPE_I32
                     && func_type->types[1] == VALUE_TYPE_I32
@@ -2590,7 +2590,7 @@ load_from_sections(AOTModule *module, AOTSection *sections,
                                 export_tmp->index - module->import_func_count;
                             func_type_index =
                                 module->func_type_indexes[func_index];
-                            func_type = module->func_types[func_type_index];
+                            func_type = module->types[func_type_index];
                             if (func_type->param_count == 1
                                 && func_type->result_count == 1
                                 && func_type->types[0] == VALUE_TYPE_I32
@@ -2618,7 +2618,7 @@ load_from_sections(AOTModule *module, AOTSection *sections,
                      || (!strcmp(exports[i].name, "__unpin"))) {
                 func_index = exports[i].index - module->import_func_count;
                 func_type_index = module->func_type_indexes[func_index];
-                func_type = module->func_types[func_type_index];
+                func_type = module->types[func_type_index];
                 if (func_type->param_count == 1 && func_type->result_count == 0
                     && func_type->types[0] == VALUE_TYPE_I32) {
                     bh_assert(module->free_func_index == (uint32)-1);
@@ -2938,8 +2938,8 @@ aot_unload(AOTModule *module)
         destroy_table_init_data_list(module->table_init_data_list,
                                      module->table_init_data_count);
 
-    if (module->func_types)
-        destroy_func_types(module->func_types, module->func_type_count);
+    if (module->types)
+        destroy_func_types(module->types, module->type_count);
 
     if (module->import_globals)
         destroy_import_globals(module->import_globals);

+ 7 - 8
core/iwasm/aot/aot_runtime.c

@@ -862,8 +862,7 @@ create_export_funcs(AOTModuleInstance *module_inst, AOTModule *module,
                     func_index =
                         export_func->func_index - module->import_func_count;
                     ftype_index = module->func_type_indexes[func_index];
-                    export_func->u.func.func_type =
-                        module->func_types[ftype_index];
+                    export_func->u.func.func_type = module->types[ftype_index];
                     export_func->u.func.func_ptr =
                         module->func_ptrs[func_index];
                 }
@@ -1028,7 +1027,7 @@ execute_post_instantiate_functions(AOTModuleInstance *module_inst,
         start_func.is_import_func = false;
         func_type_idx = module->func_type_indexes[module->start_func_index
                                                   - module->import_func_count];
-        start_func.u.func.func_type = module->func_types[func_type_idx];
+        start_func.u.func.func_type = module->types[func_type_idx];
         start_func.u.func.func_ptr = module->start_function;
         if (!aot_call_function(exec_env, &start_func, 0, NULL)) {
             goto fail;
@@ -1949,7 +1948,7 @@ aot_invoke_native(WASMExecEnv *exec_env, uint32 func_idx, uint32 argc,
             : NULL;
     uint32 *func_type_indexes = module_inst->func_type_indexes;
     uint32 func_type_idx = func_type_indexes[func_idx];
-    AOTFuncType *func_type = aot_module->func_types[func_type_idx];
+    AOTFuncType *func_type = aot_module->types[func_type_idx];
     void **func_ptrs = module_inst->func_ptrs;
     void *func_ptr = func_ptrs[func_idx];
     AOTImportFunc *import_func;
@@ -2051,7 +2050,7 @@ aot_call_indirect(WASMExecEnv *exec_env, uint32 tbl_idx, uint32 table_elem_idx,
 #endif
 
     func_type_idx = func_type_indexes[func_idx];
-    func_type = aot_module->func_types[func_type_idx];
+    func_type = aot_module->types[func_type_idx];
 
     if (func_idx >= aot_module->import_func_count) {
         /* func pointer was looked up previously */
@@ -2339,9 +2338,9 @@ aot_get_module_mem_consumption(const AOTModule *module,
 
     mem_conspn->module_struct_size = sizeof(AOTModule);
 
-    mem_conspn->types_size = sizeof(AOTFuncType *) * module->func_type_count;
-    for (i = 0; i < module->func_type_count; i++) {
-        AOTFuncType *type = module->func_types[i];
+    mem_conspn->types_size = sizeof(AOTFuncType *) * module->type_count;
+    for (i = 0; i < module->type_count; i++) {
+        AOTFuncType *type = (AOTFuncType *)module->types[i];
         size = offsetof(AOTFuncType, types)
                + sizeof(uint8) * (type->param_count + type->result_count);
         mem_conspn->types_size += size;

+ 5 - 2
core/iwasm/aot/aot_runtime.h

@@ -10,6 +10,9 @@
 #include "../common/wasm_runtime_common.h"
 #include "../interpreter/wasm_runtime.h"
 #include "../compilation/aot.h"
+#if WASM_ENABLE_GC != 0
+#include "gc_export.h"
+#endif
 
 #if WASM_ENABLE_WASI_NN != 0
 #include "../libraries/wasi-nn/src/wasi_nn_private.h"
@@ -139,8 +142,8 @@ typedef struct AOTModule {
     AOTTableInitData **table_init_data_list;
 
     /* function type info */
-    uint32 func_type_count;
-    AOTFuncType **func_types;
+    uint32 type_count;
+    AOTFuncType **types;
 
     /* import global variable info */
     uint32 import_global_count;

+ 3 - 3
core/iwasm/common/wasm_c_api.c

@@ -3010,9 +3010,9 @@ wasm_func_new_internal(wasm_store_t *store, uint16 func_idx_rt,
         }
         else {
             type_rt =
-                module_aot->func_types[module_aot->func_type_indexes
-                                           [func_idx_rt
-                                            - module_aot->import_func_count]];
+                module_aot
+                    ->types[module_aot->func_type_indexes
+                                [func_idx_rt - module_aot->import_func_count]];
         }
     }
 #endif

+ 5 - 5
core/iwasm/common/wasm_runtime_common.c

@@ -5258,13 +5258,13 @@ wasm_runtime_get_export_func_type(const WASMModuleCommon *module_comm,
         AOTModule *module = (AOTModule *)module_comm;
 
         if (export->index < module->import_func_count) {
-            *out = module->func_types[module->import_funcs[export->index]
-                                          .func_type_index];
+            *out = module->types[module->import_funcs[export->index]
+                                     .func_type_index];
         }
         else {
-            *out = module->func_types
-                       [module->func_type_indexes[export->index
-                                                  - module->import_func_count]];
+            *out =
+                module->types[module->func_type_indexes
+                                  [export->index - module->import_func_count]];
         }
         return true;
     }

+ 1 - 0
core/iwasm/compilation/aot.h

@@ -20,6 +20,7 @@ extern "C" {
 #endif
 
 typedef InitializerExpression AOTInitExpr;
+typedef WASMType AOTType;
 typedef WASMFuncType AOTFuncType;
 typedef WASMExport AOTExport;