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

AOT: Change func_types to types in AOTModule #2217

Merged
merged 1 commit into from
May 17, 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
28 changes: 14 additions & 14 deletions core/iwasm/aot/aot_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 7 additions & 8 deletions core/iwasm/aot/aot_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions core/iwasm/aot/aot_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -139,8 +142,8 @@ typedef struct AOTModule {
AOTTableInitData **table_init_data_list;

/* function type info */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should change the comment in the future

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

uint32 func_type_count;
AOTFuncType **func_types;
uint32 type_count;
AOTFuncType **types;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will change AOTFuncType to AOTType in the future, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'll do it in next PR


/* import global variable info */
uint32 import_global_count;
Expand Down
6 changes: 3 additions & 3 deletions core/iwasm/common/wasm_c_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions core/iwasm/common/wasm_runtime_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions core/iwasm/compilation/aot.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ extern "C" {
#endif

typedef InitializerExpression AOTInitExpr;
typedef WASMType AOTType;
typedef WASMFuncType AOTFuncType;
typedef WASMExport AOTExport;

Expand Down