Skip to content

Commit 7b128d2

Browse files
committed
add a toggle to enable extended const on wamrc (#4412)
1 parent 5b1ea53 commit 7b128d2

8 files changed

Lines changed: 28 additions & 13 deletions

File tree

core/iwasm/compilation/aot_emit_aot_file.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1960,13 +1960,15 @@ aot_emit_init_expr(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
19601960
case INIT_EXPR_TYPE_I64_ADD:
19611961
case INIT_EXPR_TYPE_I64_SUB:
19621962
case INIT_EXPR_TYPE_I64_MUL:
1963-
if (!aot_emit_init_expr(buf, buf_end, &offset, comp_ctx,
1964-
expr->u.binary.l_expr)) {
1965-
return false;
1966-
}
1967-
if (!aot_emit_init_expr(buf, buf_end, &offset, comp_ctx,
1968-
expr->u.binary.r_expr)) {
1969-
return false;
1963+
if (comp_ctx->enable_extended_const) {
1964+
if (!aot_emit_init_expr(buf, buf_end, &offset, comp_ctx,
1965+
expr->u.binary.l_expr)) {
1966+
return false;
1967+
}
1968+
if (!aot_emit_init_expr(buf, buf_end, &offset, comp_ctx,
1969+
expr->u.binary.r_expr)) {
1970+
return false;
1971+
}
19701972
}
19711973
break;
19721974
#endif

core/iwasm/compilation/aot_llvm.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2703,6 +2703,9 @@ aot_create_comp_context(const AOTCompData *comp_data, aot_comp_option_t option)
27032703
if (option->enable_shared_heap)
27042704
comp_ctx->enable_shared_heap = true;
27052705

2706+
if (option->enable_extended_const)
2707+
comp_ctx->enable_extended_const = true;
2708+
27062709
comp_ctx->opt_level = option->opt_level;
27072710
comp_ctx->size_level = option->size_level;
27082711

core/iwasm/compilation/aot_llvm.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,9 @@ typedef struct AOTCompContext {
457457
/* Enable LLVM PGO (Profile-Guided Optimization) */
458458
bool enable_llvm_pgo;
459459

460+
/* Enable extended constant expression */
461+
bool enable_extended_const;
462+
460463
/* Treat unknown import function as wasm-c-api import function
461464
and allow to directly invoke it from AOT/JIT code */
462465
bool quick_invoke_c_api_import;

core/iwasm/include/aot_comp_option.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ typedef struct AOTCompOption {
6868
bool enable_ref_types;
6969
bool enable_gc;
7070
bool enable_aux_stack_check;
71+
bool enable_extended_const;
7172
AOTStackFrameType aux_stack_frame_type;
7273
AOTCallStackFeatures call_stack_features;
7374
bool enable_perf_profiling;

doc/build_wamr.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,10 @@ Currently we only profile the memory consumption of module, module_instance and
293293
- **WAMR_BUILD_AOT_INTRINSICS**=1/0, enable the AOT intrinsic functions, default to enable if not set. These functions can be called from the AOT code when `--disable-llvm-intrinsics` flag or `--enable-builtin-intrinsics=<intr1,intr2,...>` flag is used by wamrc to generate the AOT file.
294294
> Note: See [Tuning the XIP intrinsic functions](./xip.md#tuning-the-xip-intrinsic-functions) for more details.
295295
296+
### **Enable extended constant expression**
297+
- **WAMR_BUILD_EXTENDED_CONST_EXPR**=1/0, default to disable if not set.
298+
> Note: See [Extended Constant Expressions](https://github.com/WebAssembly/extended-const/blob/main/proposals/extended-const/Overview.md) for more details.
299+
296300
### **Configurable memory access boundary check**
297301
- **WAMR_CONFIGURABLE_BOUNDS_CHECKS**=1/0, default to disable if not set
298302
> Note: If it is enabled, allow to run `iwasm --disable-bounds-checks` to disable the memory access boundary checks for interpreter mode.

tests/wamr-test-suites/spec-test-script/runtest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,9 @@ def compile_wasm_to_aot(wasm_tempfile, aot_tempfile, runner, opts, r, output = '
11601160
cmd.append("--enable-gc")
11611161
cmd.append("--enable-tail-call")
11621162

1163+
if opts.extended_const:
1164+
cmd.append("--enable-extended-const")
1165+
11631166
if output == 'object':
11641167
cmd.append("--format=object")
11651168
elif output == 'ir':

wamr-compiler/CMakeLists.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,6 @@ else()
3838
add_definitions(-DWASM_ENABLE_SIMD=1)
3939
endif()
4040

41-
if (WAMR_BUILD_EXTENDED_CONST_EXPR EQUAL 0)
42-
add_definitions(-DWASM_ENABLE_EXTENDED_CONST_EXPR=0)
43-
else()
44-
add_definitions(-DWASM_ENABLE_EXTENDED_CONST_EXPR=1)
45-
endif()
46-
4741
add_definitions(-DWASM_ENABLE_INTERP=1)
4842
add_definitions(-DWASM_ENABLE_WAMR_COMPILER=1)
4943
add_definitions(-DWASM_ENABLE_BULK_MEMORY=1)
@@ -59,6 +53,7 @@ add_definitions(-DWASM_ENABLE_PERF_PROFILING=1)
5953
add_definitions(-DWASM_ENABLE_LOAD_CUSTOM_SECTION=1)
6054
add_definitions(-DWASM_ENABLE_MODULE_INST_CONTEXT=1)
6155
add_definitions(-DWASM_ENABLE_MEMORY64=1)
56+
add_definitions(-DWASM_ENABLE_EXTENDED_CONST_EXPR=1)
6257

6358
add_definitions(-DWASM_ENABLE_GC=1)
6459

wamr-compiler/main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ main(int argc, char *argv[])
421421
option.enable_bulk_memory = true;
422422
option.enable_ref_types = true;
423423
option.enable_gc = false;
424+
option.enable_extended_const = false;
424425
aot_call_stack_features_init_default(&option.call_stack_features);
425426

426427
/* Process options */
@@ -534,6 +535,9 @@ main(int argc, char *argv[])
534535
else if (!strcmp(argv[0], "--disable-aux-stack-check")) {
535536
option.enable_aux_stack_check = false;
536537
}
538+
else if (!strcmp(argv[0], "--enable-extended-const")) {
539+
option.enable_extended_const = true;
540+
}
537541
else if (!strcmp(argv[0], "--enable-dump-call-stack")) {
538542
option.aux_stack_frame_type = AOT_STACK_FRAME_TYPE_STANDARD;
539543
}

0 commit comments

Comments
 (0)