Commit Graph

193 Commits

Author SHA1 Message Date
Wenyong Huang
7c812ece9a
Enhance aot feature flags emit and load (#3048)
- Emit SIMD/ref-types/bulk-memory flags into AOT file only when the features
  are really used in wasm file
- Remove unused tail-call flag and stringref flag
- Add memoy64 flag and dynamic-linking flag
- Change WASM_FEATURE_THREADS to WASM_FEATURE_MULTI_THREAD
2024-01-23 16:15:04 +08:00
Wenyong Huang
4f0551ac25
Enable quick aot entry when GC is enabled (#3015)
- Set gc func type's quick_aot_entry
- Call quick_aot_entry when hw bound check is disabled
- Declare detailed aot func's prototype inside the quick aot entry
- Remove ret_type in the quick aot entry
- Update docker image
2024-01-18 18:28:17 +08:00
Wenyong Huang
644044522c Merge branch main into dev/gc_refactor 2024-01-12 18:40:47 +08:00
liang.he
9121db5671
Fix a bug when emit the custom name section to aot file (#2987)
The content in custom name section is changed after loaded since the strings
are adjusted with '\0' appended, the emitted AOT file then cannot be loaded.
The PR disables changing the content for AOT compiler to resolve it.

And disable emitting custom name section for `wamrc --enable-dump-call-stack`,
instead, use `wamrc --emit-custom-sections=name` to emit it.
2024-01-11 13:14:54 +08:00
Wenyong Huang
b21f17dd6d
Refine AOT/JIT code call wasm-c-api import process (#2982)
Allow to invoke the quick call entry wasm_runtime_quick_invoke_c_api_import to
call the wasm-c-api import functions to speedup the calling process, which reduces
the data copying.

Use `wamrc --invoke-c-api-import` to generate the optimized AOT code, and set
`jit_options->quick_invoke_c_api_import` true in wasm_engine_new when LLVM JIT
is enabled.
2024-01-10 18:37:02 +08:00
Wenyong Huang
7c7684819d
Register quick call entries to speedup the aot/jit func call process (#2978)
In some scenarios there may be lots of callings to AOT/JIT functions from the
host embedder, which expects good performance for the calling process, while
in the current implementation, runtime calls the wasm_runtime_invoke_native
to prepare the array of registers and stacks for the invokeNative assemble code,
and the latter then puts the elements in the array to physical registers and
native stacks and calls the AOT/JIT function, there may be many data copying
and handlings which impact the performance.

This PR registers some quick AOT/JIT entries for some simple wasm signatures,
and let runtime call the entry to directly invoke the AOT/JIT function instead of
calling wasm_runtime_invoke_native, which speedups the calling process.

We may extend the mechanism next to allow the developer to register his quick
AOT/JIT entries to speedup the calling process of invoking the AOT/JIT functions
for some specific signatures.
2024-01-10 16:44:09 +08:00
Wenyong Huang
d31455fc4e
Refactor aot stack frame commit (#2976)
- Commit locals, stacks and stack pointer to aot frame only when gc is enabled
- Commit instruction pointer to aot frame when stack frame is enabled
- Refine alloc/free aot frame when gc isn't enabled: use fixed frame size
- Support dump call stack with bytecode offset
2024-01-08 11:18:49 +08:00
Wenyong Huang
cc23a09d5e
Fix test script error and related wamrc and GC issues (#2975)
The wamrc execution errors were skipped in the runtest.py due to `sys.exit(1)`
was caught by upper try-catch sentence and ignored with ret_code 0 returned.

This PR fixed this script issue and fixed the related wamrc/GC issues found.
2024-01-08 09:41:56 +08:00
Xu Jun
f96257bade
Fix fast-interp polymorphic stack processing (#2974)
Fix issue #2951, #2952 and #2953.
2024-01-04 10:00:36 +08:00
Wenyong Huang
e6d210a67f Merge branch main into dev/gc_refactor 2024-01-03 12:11:57 +08:00
Wenyong Huang
1ee4767d97
Fix ref.func function declared check in wasm loader (#2972)
The forward-declare function reference in ref.func can be declared in table element segments,
no matter whether the segment mode is passive, active or declarative.

Reported in https://github.com/bytecodealliance/wasm-micro-runtime/issues/2944.
2024-01-03 11:43:03 +08:00
Xu Jun
d818672f62
Fix ref.is_null processing in fast-interp loader (#2971) 2024-01-02 18:10:01 +08:00
liang.he
5c3ad0279a
Enable AOT linux perf support (#2930)
And refactor the original perf support
- use WAMR_BUILD_LINUX_PERF as the cmake compilation control
- use WASM_ENABLE_LINUX_PERF as the compiler macro
- use `wamrc --enable-linux-perf` to generate aot file which contains fp operations
- use `iwasm --enable-linux-perf` to create perf map for `perf record`
2024-01-02 15:58:17 +08:00
Huang Qi
7de3170af4
Emit SIMD flag to AOT file only if SIMD is actually used (#2911) 2023-12-25 10:25:56 +08:00
Wenyong Huang
eab09a2af5 Merge branch main into dev/gc_refactor 2023-12-12 12:50:20 +08:00
Wenyong Huang
cf7350f069
Implement aot_alloc_frame/aot_free_frame with LLVM IRs (#2830) 2023-12-12 12:12:02 +08:00
Xu Jun
92176be7d6
Sync up with the latest GC MVP spec proposal (#2836) 2023-12-12 11:49:44 +08:00
Enrico Loparco
4aee3cf14e
Avoid memory import failure when wasi-threads is enabled (#2893)
According to the specification:
```
When instantiating a module which is expected to run
with `wasi-threads`, the WASI host must first allocate shared memories to
satisfy the module's imports.
```
Currently, if a test from the spec is executed while having the `multi-module`
feature enabled, WAMR fails with `WASM module load failed: unknown import`.
That happens because spec tests use memory like this:
  `(memory (export "memory") (import "foo" "bar") 1 1 shared)`
and WAMR tries to find a registered module named `foo`.

At the moment, there is no specific module name that can be used to identify
that the memory is imported because using WASI threads:
  https://github.com/WebAssembly/wasi-threads/issues/33,
so this PR only avoids treating the submodule dependency not being found
as a failure.
2023-12-11 22:17:31 +08:00
Enrico Loparco
6cb2ea4935
fix command-reactor: Look for _initialize only if _start not found (#2891)
A wasm module can be either a command or a reactor, so it can export
either `_start` or `_initialize`. Currently, if a command module is run,
`iwasm` still looks for `_initialize`, resulting in the warning:
  `can not find an export 0 named _initialize in the module`.

Change to look for `_initialize` only if `_start` not found to resolve the issue.
2023-12-11 10:10:26 +08:00
Xu Jun
53c3fa27d4
Fix block with type issue in fast interp (#2866)
Reported in https://github.com/bytecodealliance/wasm-micro-runtime/issues/2863.
2023-12-05 17:09:05 +08:00
Wenyong Huang
23c1343fb3
Fix wasm loader handle op_br_table and op_drop (#2864)
- Fix op_br_table arity type check when the dest block is loop block
- Fix op_drop issue when the stack is polymorphic and it is to drop
  an ANY type value in the stack
2023-12-05 16:59:13 +08:00
YAMAMOTO Takashi
73914caa9b
core/iwasm/interpreter/wasm_loader.c: remove an extra validation (#2845)
* Empty names are spec-wise valid.
* As we ignore unknown custom sections anyway, it's safe to
  accept empty names here.
* Currently, the problem is not exposed on our CI because
   the wabt version used there is a bit old.
2023-12-01 18:29:15 +08:00
liang.he
718f0671e7
Output warning and quit if import/export name contains '\00' (#2806)
Leave it as a limitation when import/export name contains '\00' in wasm file.
p.s. https://github.com/bytecodealliance/wasm-micro-runtime/issues/2789
2023-12-01 11:14:13 +08:00
Wenyong Huang
9c71ca6c46 Merge branch main into dev/gc_refactor 2023-11-29 09:23:00 +08:00
liang.he
8aa813f44a
Generate jitdump to support linux perf for LLVM JIT (#2788) 2023-11-27 15:42:00 +08:00
Xu Jun
77d27c9ff6
Enable stringref aot (#2816) 2023-11-27 10:50:12 +08:00
Huang Qi
e8c8f7fca6
Fix return type in wasm_loader_get_custom_section (#2794)
Should return NULL instead of false.
2023-11-20 10:36:15 +08:00
Wenyong Huang
943274e3b9
Fix GC struct field offset calculation in AOT compiler (#2746)
The struct field size and field offset of a wasm struct may vary
in 32-bit target and 64-bit target, the aot compiler should not
use the offset calculated in wasm loader. It re-calculates them
according to the target info and whether GC is enabled.

And set the alignment of sruct.get/set when field size is 2, 4, or 8.
2023-11-13 15:22:10 +08:00
Wenyong Huang
64e40c13a9
Fix more GC AOT/JIT issues (#2727)
Fix opcode translation for br_on_null/br_on_non_null/br_on_cast/br_on_cast_fail
Fix global data size/offset calculation for 32-bit/64-bit targets
Fix issues in AOT file emitting and AOT loader, refine AOT file format
Fix invalid table element address used for table.get/table.set
Fix invalid struct field offset used for struct.get/struct.set
Fix aot stack frame commit for function call/call_indirect/call_ref
Add GC AOT/JIT to CI test
2023-11-09 08:52:56 +08:00
Wenyong Huang
7f8292ffd1
Add more buffer boundary checks in wasm loader (#2734)
And fix exception not printed in `iwasm --repl` mode and resize the memory
data size to UINT32_MAX if the initial page number is 65536.
2023-11-09 08:42:05 +08:00
Wenyong Huang
348d82b923 Merge branch main into dev/gc_refactor 2023-11-03 15:39:28 +08:00
Wenyong Huang
4b1a6e5017
Fix repeatedly initialize shared memory data and protect the memory's fields (#2673)
Avoid repeatedly initializing the shared memory data when creating the child
thread in lib-pthread or lib-wasi-threads.

Add shared memory lock when accessing some fields of the memory instance
if the memory instance is shared.

Init shared memory's memory_data_size/memory_data_end fields according to
the current page count but not max page count.

Add wasm_runtime_set_mem_bound_check_bytes, and refine the error message
when shared memory flag is found but the feature isn't enabled.
2023-10-30 11:07:01 +08:00
Wenyong Huang
d6bba13e86
Fix fast-interp "pre-compiled label offset out of range" issue (#2659)
When labels-as-values is enabled in a target which doesn't support
unaligned address access, 16-bit offset is used to store the relative
offset between two opcode labels. But it is a little small and the loader
may report "pre-compiled label offset out of range" error.

Emitting 32-bit data instead to resolve the issue: emit label address in
32-bit target and emit 32-bit relative offset in 64-bit target.

See also:
https://github.com/bytecodealliance/wasm-micro-runtime/issues/2635
2023-10-24 10:47:17 +08:00
Su Yihan
2f45f12cd7
Support stringref proposal (#2651)
This PR implements the WebAssembly stringref proposal:
  https://github.com/WebAssembly/stringref

It adds cmake variable `WAMR_BUILD_STRINGREF` to build the feature,
which will enable GC automatically.

The stringref contains two parts:
- `part 1`: add new ref types in WasmGC, add opcode processing in loader and interpreter
- `part 2`: add a library for string representation/encoding/decoding and so on

To reduce the code size introduced to WAMR, this PR only includes `part 1`,
`part 2` can be provided by embedder, they may use their own implementation,
e.g., Wasmnizer-ts uses JSString from QuickJS to implement stringref:
https://github.com/intel/Wasmnizer-ts/blob/main/runtime-library/stringref/stringref_qjs.c

We will submit another PR of `part 2` and make it as a sample rather than WAMR core part.

Signed-off-by: Su Yihan <yihan.su@intel.com>
Co-authored-by: Xu Jun <jun1.xu@intel.com>
2023-10-23 12:45:37 +08:00
Huang Qi
06d46b0fb6
Fix some GC relative issues (#2656) 2023-10-23 10:03:09 +08:00
Xu Jun
872db7c22a
Make max table size configurable through macro (#2632) 2023-10-12 14:13:44 +08:00
Wenyong Huang
ae508e25fa Merge branch dev/aot_stack_frame into dev/gc_refactor 2023-10-09 14:21:39 +08:00
Wenyong Huang
85869ed604 Merge branch main into dev/gc_refactor 2023-10-08 10:53:13 +08:00
Wenyong Huang
7a9ed07411 Merge branch main into dev/aot_stack_frame 2023-10-08 10:01:45 +08:00
dongsheng28849455
79b27c1934
Support muti-module for AOT mode (#2482)
Support muti-module for AOT mode, currently only implement the
multi-module's function import feature for AOT, the memory/table/
global import are not implemented yet.

And update wamr-test-suites scripts, multi-module sample and some
CIs accordingly.
2023-09-28 08:56:11 +08:00
Wenyong Huang
6382162711
Fix loader push_pop_frame_ref_offset (#2590)
`wasm_loader_push_pop_frame_offset` may pop n operands by using
`loader_ctx->stack_cell_num` to check whether the operand can be
popped or not. While `loader_ctx->stack_cell_num` is updated in the
later `wasm_loader_push_pop_frame_ref`, the check may fail if the stack
is in polymorphic state and lead to `ctx->frame_offset` underflow.

Fix issue #2577 and #2586.
2023-09-26 10:17:54 +08:00
Wenyong Huang
4b09e283ef
Add option for JIT stack frame and update documents (#2565)
Allow `cmake -DWAMR_BUILD_JIT_STACK_FRAME=1` to enable stack frame
for JIT mode.

And fix some issues in doc/build_wamr.md.
2023-09-19 16:07:38 +08:00
Wenyong Huang
03155cf22b Merge branch main into dev/gc_refactor 2023-08-23 16:40:13 +08:00
Xu Jun
7baaed2fb8
Fix opcode overwrite issue in fast interp (#2476) 2023-08-17 19:49:35 +08:00
Xu Jun
0bd23ebd8c
Fix validation non-nullable locals (#2462) 2023-08-14 19:25:52 +08:00
Xu Jun
a051dd7051
Fix several memory leak issues (#2445) 2023-08-11 11:06:29 +08:00
Xu Jun
fb8dbc1555
Fix type checking for array.copy opcode (#2438) 2023-08-08 17:57:46 +08:00
Wenyong Huang
803597dc55 Merge branch main into dev/gc_refactor 2023-08-07 09:35:10 +08:00
Wenyong Huang
edea32b629
Fix result arity check on select_t opcode (#2406)
Typed select must have exactly one result. Reported in issue #2402.
2023-07-31 18:20:11 +08:00
Xu Jun
6a868173f8
Fix static code analyzing issues (#2371) 2023-07-21 07:59:30 +08:00