You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> Then you will see a new file named _out.folded.translated_ which contains the translated folded stacks.
192
192
> All wasm functions are translated to its original names with a prefix like "[Wasm]"
193
+
194
+
## 8. Refine the calling processes between host native and wasm application
195
+
196
+
In some scenarios, there may be lots of callings between host native and wasm application, e.g. frequent callings to AOT/JIT functions from host native or frequent callings to host native from AOT/JIT functions. It is important to refine these calling processes to speedup them, WAMR provides several methods:
197
+
198
+
### 8.1 Refine callings to native APIs registered by `wasm_runtime_register_natives` from AOT code
199
+
200
+
When wamrc compiles the wasm file to AOT code, it may generate LLVM IR to call the native API from an AOT function, and if it doesn't know the native API's signature, the generated LLVM IR has to call the runtime API `aot_invoke_native` to invoke the native API, which is a relatively slow way. If developer registers native APIs during execution by calling `wasm_runtime_register_natives` or by `iwasm --native-lib=<lib>`, then developer can also register native APIs with the same signatures to the AOT compiler by `wamrc --native-lib=<lib>`, so as to let the AOT compiler pre-know the native API's signature, and generate optimized LLVM IR to quickly call to the native API.
201
+
202
+
The below sample registers an API `int test_add(int, int)` to the AOT compiler:
203
+
204
+
```C
205
+
/* test_add.c */
206
+
207
+
#include "wasm_export.h"
208
+
209
+
static int
210
+
test_add_wrapper(wasm_exec_env_t exec_env, int x, int y) {
> Note: no need to do anything for LLVM JIT since the native APIs must have been registered before execution and JIT compiler already knows the native APIs' signatures.
237
+
238
+
### 8.2 Refine callings to native APIs registered by wasm-c-api `wasm_instance_new` from AOT code
239
+
240
+
In wasm-c-api mode, when the native APIs are registered by `wasm_instance_new(..., imports, ...)`, developer can use `wamrc --invoke-c-api-import` option to generate the AOT file, which treats the unknown import function as wasm-c-api import function and generates optimized LLVM IR to speedup the calling process.
241
+
242
+
> Note: no need to do anything for LLVM JIT since the similar flag has been set to JIT compiler in wasm-c-api `wasm_engine_new` when LLVM JIT is enabled.
243
+
244
+
### 8.3 Refine callings to AOT/JIT functions from host native
245
+
246
+
Currently by default WAMR runtime has registered many quick AOT/JIT entries to speedup the calling processes to call AOT/JIT functions from host native, as long as developer doesn't disable it by using `cmake -DWAMR_BUILD_QUICK_AOT_ENTRY=0` or setting the compiler macro `WASM_ENABLE_QUICK_AOT_ENTRY` to 0 in the makefile. These quick AOT/JIT entries include:
247
+
248
+
1. wasm function contains 0 to 4 arguments and 0 to 1 results, with the type of each argument is i32 or i64 and the type of result is i32, i64 or void. These functions are like:
2. wasm function contains 5 arguments and 0 to 1 results, with the type of each argument is i32 and the type of result is i32, i64 or void. These functions are like:
266
+
267
+
```C
268
+
i32 foo(i32, i32, i32, i32, i32)
269
+
i64 foo(i32, i32, i32, i32, i32)
270
+
void foo(i32, i32, i32, i32, i32)
271
+
```
272
+
273
+
To speedup the calling processes, developer had better ensure that the signatures of the wasm functions to expose are like above, or add some conversions to achieve it. For example, if a wasm function to call is `f32 foo(f32)`, developer can define a new function `i32 foo1(i32)` like below and export it:
0 commit comments