Commit Graph

113 Commits

Author SHA1 Message Date
Wenyong Huang
e70c5219c0 Merge branch main into dev/gc_refactor 2024-01-26 16:43:51 +08:00
Xu Jun
1977ad23ef
fast-interp: Fix dynamic offset error issue in else branch (#3058)
Reported in https://github.com/bytecodealliance/wasm-micro-runtime/issues/3026.
2024-01-19 19:58:12 +08:00
Wenyong Huang
644044522c Merge branch main into dev/gc_refactor 2024-01-12 18:40:47 +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
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
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
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
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
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
348d82b923 Merge branch main into dev/gc_refactor 2023-11-03 15:39:28 +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
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
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
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
Wenyong Huang
366b3b7683 Merge branch main into dev/gc_refactor 2023-06-05 14:13:45 +08:00
Wenyong Huang
76be848ec3
Implement the segue optimization for LLVM AOT/JIT (#2230)
Segue is an optimization technology which uses x86 segment register to store
the WebAssembly linear memory base address, so as to remove most of the cost
of SFI (Software-based Fault Isolation) base addition and free up a general
purpose register, by this way it may:
- Improve the performance of JIT/AOT
- Reduce the footprint of JIT/AOT, the JIT/AOT code generated is smaller
- Reduce the compilation time of JIT/AOT

This PR uses the x86-64 GS segment register to apply the optimization, currently
it supports linux and linux-sgx platforms on x86-64 target. By default it is disabled,
developer can use the option below to enable it for wamrc and iwasm(with LLVM
JIT enabled):
```bash
wamrc --enable-segue=[<flags>] -o output_file wasm_file
iwasm --enable-segue=[<flags>] wasm_file [args...]
```
`flags` can be:
    i32.load, i64.load, f32.load, f64.load, v128.load,
    i32.store, i64.store, f32.store, f64.store, v128.store
Use comma to separate them, e.g. `--enable-segue=i32.load,i64.store`,
and `--enable-segue` means all flags are added.

Acknowledgement:
Many thanks to Intel Labs, UC San Diego and UT Austin teams for introducing this
technology and the great support and guidance!

Signed-off-by: Wenyong Huang <wenyong.huang@intel.com>
Co-authored-by: Vahldiek-oberwagner, Anjo Lucas <anjo.lucas.vahldiek-oberwagner@intel.com>
2023-05-26 10:13:33 +08:00
Huang Qi
035cca062f
Add --enable-gc option to wamrc (#2190)
The runtime instance memory layout changed when GC was enabled. With this patch
the GC is enabled for wamrc, but it keeps the compatibility with iwasm no matter GC
is enabled for it or not.

It may waste some memory for iwasm without GC support since the GC relative fields
for the table instance are always here, let's optimization it after AOT fully supports GC.
2023-05-15 14:32:57 +08:00
Huang Qi
02f0156475
GC: Change table_elem_type_t to pointer width to simplify the related handlings (#2178) 2023-05-09 11:10:40 +08:00
Wenyong Huang
3d327e2067
Merge branch main into dev/gc_refactor (#2114) 2023-04-07 12:01:45 +08:00
Wenyong Huang
e1d0c27ef9
Fix ref.func forward-declared function check (#2099)
When ref.func opcode refers to a function whose function index no smaller than
current function, the destination func should be forward-declared: it is declared
in the table element segments, or is declared in the export list.
2023-04-03 15:55:24 +08:00
Wenyong Huang
605c8b07dc
Fix issue of Multi-tier JIT (#2056) 2023-03-25 11:15:05 +08:00
Wenyong Huang
5d44ec501d Merge branch main into dev/gc_refactor 2023-03-09 20:07:57 +08:00
Wenyong Huang
80e2f3dd7f
Refactor GC feature (#1956)
The latest GC spec proposal has changed a lot since we implemented the feature,
refactor it based on the main branch. Part of the spec cases were tested.
2023-02-16 17:02:08 +08:00
Enrico Loparco
216dc43ab4
Use shared memory lock for threads generated from same module (#1960)
Multiple threads generated from the same module should use the same
lock to protect the atomic operations.

Before this PR, each thread used a different lock to protect atomic
operations (e.g. atomic add), making the lock ineffective.

Fix #1958.
2023-02-16 11:54:19 +08:00
Wenyong Huang
40a14b51c5
Enable running mode control for runtime and module instance (#1923)
Enable setting running mode when executing a wasm bytecode file
- Four running modes are supported: interpreter, fast-jit, llvm-jit and multi-tier-jit
- Add APIs to set/get the default running mode of the runtime
- Add APIs to set/get the running mode of a wasm module instance
- Add running mode options for iwasm command line tool

And add size/opt level options for LLVM JIT
2023-02-02 18:16:01 +08:00
YAMAMOTO Takashi
7d3b2a8773
Make memory profiling show native stack usage (#1917) 2023-02-01 11:52:15 +08:00
Wenyong Huang
0090d3e3fc
Fix issue of resolving func name in custom name section (#1849)
Should use import_function_count but not import_count to calculate
the func_index in handle_name_section when custom name section
feature is enabled.

And clear the compile warnings of mini loader.
2022-12-30 14:37:04 +08:00
Wenyong Huang
14288f59b0
Implement Multi-tier JIT (#1774)
Implement 2-level Multi-tier JIT engine: tier-up from Fast JIT to LLVM JIT to
get quick cold startup by Fast JIT and better performance by gradually
switching to LLVM JIT when the LLVM JIT functions are compiled by the
backend threads.

Refer to:
https://github.com/bytecodealliance/wasm-micro-runtime/issues/1302
2022-12-19 11:24:46 +08:00
Wenyong Huang
1652f22a77
Fix issues reported by Coverity (#1775)
Fix some issues reported by Coverity and fix windows exception
check with guard page issue
2022-12-01 19:24:13 +08:00
Wenyong Huang
96570cca22
Remove unused LLVM JIT wapper functions (#1747)
Only create the necessary wrapper functions for LLVM JIT
2022-11-25 11:26:08 +08:00
Wenyong Huang
da7117a092
Refine the stack frame size check in interpreter (#1730)
Limit max_stack_cell_num/max_csp_num to be no larger than UINT16_MAX,
and don't check all_cell_num in interpreter again.

And refine some codes in interpreter.
2022-11-22 15:32:48 +08:00
Wenyong Huang
c70e1ebc3d
Avoid generating some unused LLVM IRs (#1696)
Refine the generated LLVM IRs at the beginning of each LLVM AOT/JIT function
to fasten the LLVM IR optimization:
- Only create argv_buf if there are func calls in this function
- Only create native stack bound if stack bound check is enabled
- Only create aux stack info if there is opcode set_global_aux_stack
- Only create native symbol if indirect_mode is enabled
- Only create memory info if there are memory operations
- Only create func_type_indexes if there is opcode call_indirect
2022-11-14 14:32:35 +08:00