Skip to content

Conversation

@lum1n0us
Copy link
Contributor

No description provided.

@lum1n0us lum1n0us force-pushed the feat/inst_linking_global branch from 92a6310 to eb6a1ef Compare November 24, 2024 23:18
@lum1n0us lum1n0us force-pushed the feat/inst_linking_global branch 2 times, most recently from bcb32d9 to f4b1f30 Compare December 7, 2024 05:16
@lum1n0us lum1n0us marked this pull request as ready for review December 7, 2024 11:28
@wenyongh
Copy link
Collaborator

@lum1n0us there are some conflict files in this PR, could you help resolve them so that I can read the code better? Thanks.

…d improve export retrieval logic

Remove me when meeting rebase conflication
@lum1n0us lum1n0us force-pushed the feat/inst_linking_global branch from a84546f to 36b8555 Compare December 12, 2024 08:01
aot_set_last_error("llvm build in bounds gep failed.");
return false;
}
global_ptr = get_global_value_addr(comp_ctx, func_ctx, global_idx);
Copy link
Collaborator

Choose a reason for hiding this comment

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

The original code directly gets the global offset at the compilation time and loads global one time in execution. Per my understanding, get_global_value_addr will get the global address by several loads, it will reduce the performance? It seems that it is only needed for import global and only needed when multi-module is enabled?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems that it is only needed for import global and only needed when multi-module is enabled?

In this case, multi-module means loading linking. By default, it is instantiation linking. Therefore, It always requires to prepare extra loading for an import global.

Yes. There are opportunities for optimization. Like:

  • to a local global.
  • to a built-in global.

I believe we should complete the functionality in this PR first. We can focus on optimization in a separate one.

Copy link
Collaborator

Choose a reason for hiding this comment

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

OK, since performance and code size are important for the developers, hope the new feature impacts them as less as we can.

import_globals[i].is_linked = false;
else
#endif
#endif /* WASM_ENABLE_MULTI_MODULE != 0 */
Copy link
Collaborator

Choose a reason for hiding this comment

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

When multi-module isn't enabled and libc-builtin is enabled, the global isn't linked by default, is it expected? Or will the iwasm's main.c link the global when instantiating?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

YES. only apply wasm_native_lookup_libc_builtin_global() when executing loading linking. Otherwise, core/iwasm/libraries/libc-builtin/spec_test_builtin_wrapper.c will take over

uint32 global_idx)
{
/* WASMModuleInstance->e */
uint32 e_offset_val = offsetof(WASMModuleInstance, e);
Copy link
Collaborator

Choose a reason for hiding this comment

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

The WASMModuleInstanceExtra structure is put at the end of WASMModuleInstance, we can use a fixed offset to get it and its fields, like offset_u32 = get_module_inst_extra_offset(comp_ctx) and then offset = offset_u32 + offsetof(AOTModuleInstanceExtra, globals) for AOT or offset = offset_u32 + offsetof(WASMModuleInstanceExtra, globals) for JIT. By this way, we can save one load operation, refer to create_shared_heap_info:
https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/core/iwasm/compilation/aot_llvm.c#L1528-L1545

LLVMValueRef e_ptr =
LLVMBuildBitCast(comp_ctx->builder, e_ptr_u8, OPQ_PTR_TYPE, "e_ptr");
LLVMValueRef e =
LLVMBuildLoad2(comp_ctx->builder, OPQ_PTR_TYPE, e_ptr, "e");
Copy link
Collaborator

Choose a reason for hiding this comment

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

had better check return value of e_offset, e_ptr_u8, e_ptr, e

Copy link
Collaborator

@wenyongh wenyongh left a comment

Choose a reason for hiding this comment

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

LGTM

@lum1n0us lum1n0us merged commit b18cb3b into bytecodealliance:dev/instantiate_linking Dec 19, 2024
383 checks passed
@lum1n0us lum1n0us deleted the feat/inst_linking_global branch December 19, 2024 08:52
lum1n0us added a commit to lum1n0us/wasm-micro-runtime that referenced this pull request Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants