xip: Lookup float constants from table to reduce relocations (#894)

Lookup float/double constants from exec_env->native_symbol table
but not construct them with LLVMBuildConst if XIP mode is enabled,
these constants are introduced by f32/f64.const opcodes and some
float/double conversion opcodes, and make wamrc generate some
relocations in text section of AOT XIP file. This patch eliminates such
relocations when "--enable-indirect-mode" is added to wamrc.
This commit is contained in:
Wenyong Huang
2021-12-16 21:39:23 +08:00
committed by GitHub
parent f2d87ec02e
commit 5be427bfa2
6 changed files with 287 additions and 45 deletions

View File

@ -348,14 +348,37 @@ aot_compile_op_i32_trunc_f32(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
POP_F32(value);
if (sign) {
min_value = F32_CONST(-2147483904.0f);
max_value = F32_CONST(2147483648.0f);
if (!comp_ctx->is_indirect_mode) {
if (sign) {
min_value = F32_CONST(-2147483904.0f);
max_value = F32_CONST(2147483648.0f);
}
else {
min_value = F32_CONST(-1.0f);
max_value = F32_CONST(4294967296.0f);
}
}
else {
min_value = F32_CONST(-1.0f);
max_value = F32_CONST(4294967296.0f);
WASMValue wasm_value;
if (sign) {
wasm_value.f32 = -2147483904.0f;
min_value = aot_load_const_from_table(
comp_ctx, func_ctx->native_symbol, &wasm_value, VALUE_TYPE_F32);
wasm_value.f32 = 2147483648.0f;
max_value = aot_load_const_from_table(
comp_ctx, func_ctx->native_symbol, &wasm_value, VALUE_TYPE_F32);
}
else {
wasm_value.f32 = -1.0f;
min_value = aot_load_const_from_table(
comp_ctx, func_ctx->native_symbol, &wasm_value, VALUE_TYPE_F32);
wasm_value.f32 = 4294967296.0f;
max_value = aot_load_const_from_table(
comp_ctx, func_ctx->native_symbol, &wasm_value, VALUE_TYPE_F32);
}
}
CHECK_LLVM_CONST(min_value);
CHECK_LLVM_CONST(max_value);
if (!saturating)
return trunc_float_to_int(
@ -378,14 +401,37 @@ aot_compile_op_i32_trunc_f64(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
POP_F64(value);
if (sign) {
min_value = F64_CONST(-2147483649.0);
max_value = F64_CONST(2147483648.0);
if (!comp_ctx->is_indirect_mode) {
if (sign) {
min_value = F64_CONST(-2147483649.0);
max_value = F64_CONST(2147483648.0);
}
else {
min_value = F64_CONST(-1.0);
max_value = F64_CONST(4294967296.0);
}
}
else {
min_value = F64_CONST(-1.0);
max_value = F64_CONST(4294967296.0);
WASMValue wasm_value;
if (sign) {
wasm_value.f64 = -2147483649.0;
min_value = aot_load_const_from_table(
comp_ctx, func_ctx->native_symbol, &wasm_value, VALUE_TYPE_F64);
wasm_value.f64 = 2147483648.0;
max_value = aot_load_const_from_table(
comp_ctx, func_ctx->native_symbol, &wasm_value, VALUE_TYPE_F64);
}
else {
wasm_value.f64 = -1.0;
min_value = aot_load_const_from_table(
comp_ctx, func_ctx->native_symbol, &wasm_value, VALUE_TYPE_F64);
wasm_value.f64 = 4294967296.0;
max_value = aot_load_const_from_table(
comp_ctx, func_ctx->native_symbol, &wasm_value, VALUE_TYPE_F64);
}
}
CHECK_LLVM_CONST(min_value);
CHECK_LLVM_CONST(max_value);
if (!saturating)
return trunc_float_to_int(
@ -509,14 +555,37 @@ aot_compile_op_i64_trunc_f32(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
POP_F32(value);
if (sign) {
min_value = F32_CONST(-9223373136366403584.0f);
max_value = F32_CONST(9223372036854775808.0f);
if (!comp_ctx->is_indirect_mode) {
if (sign) {
min_value = F32_CONST(-9223373136366403584.0f);
max_value = F32_CONST(9223372036854775808.0f);
}
else {
min_value = F32_CONST(-1.0f);
max_value = F32_CONST(18446744073709551616.0f);
}
}
else {
min_value = F32_CONST(-1.0f);
max_value = F32_CONST(18446744073709551616.0f);
WASMValue wasm_value;
if (sign) {
wasm_value.f32 = -9223373136366403584.0f;
min_value = aot_load_const_from_table(
comp_ctx, func_ctx->native_symbol, &wasm_value, VALUE_TYPE_F32);
wasm_value.f32 = 9223372036854775808.0f;
max_value = aot_load_const_from_table(
comp_ctx, func_ctx->native_symbol, &wasm_value, VALUE_TYPE_F32);
}
else {
wasm_value.f32 = -1.0f;
min_value = aot_load_const_from_table(
comp_ctx, func_ctx->native_symbol, &wasm_value, VALUE_TYPE_F32);
wasm_value.f32 = 18446744073709551616.0f;
max_value = aot_load_const_from_table(
comp_ctx, func_ctx->native_symbol, &wasm_value, VALUE_TYPE_F32);
}
}
CHECK_LLVM_CONST(min_value);
CHECK_LLVM_CONST(max_value);
if (!saturating)
return trunc_float_to_int(
@ -539,14 +608,37 @@ aot_compile_op_i64_trunc_f64(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
POP_F64(value);
if (sign) {
min_value = F64_CONST(-9223372036854777856.0);
max_value = F64_CONST(9223372036854775808.0);
if (!comp_ctx->is_indirect_mode) {
if (sign) {
min_value = F64_CONST(-9223372036854777856.0);
max_value = F64_CONST(9223372036854775808.0);
}
else {
min_value = F64_CONST(-1.0);
max_value = F64_CONST(18446744073709551616.0);
}
}
else {
min_value = F64_CONST(-1.0);
max_value = F64_CONST(18446744073709551616.0);
WASMValue wasm_value;
if (sign) {
wasm_value.f64 = -9223372036854777856.0;
min_value = aot_load_const_from_table(
comp_ctx, func_ctx->native_symbol, &wasm_value, VALUE_TYPE_F64);
wasm_value.f64 = 9223372036854775808.0;
max_value = aot_load_const_from_table(
comp_ctx, func_ctx->native_symbol, &wasm_value, VALUE_TYPE_F64);
}
else {
wasm_value.f64 = -1.0;
min_value = aot_load_const_from_table(
comp_ctx, func_ctx->native_symbol, &wasm_value, VALUE_TYPE_F64);
wasm_value.f64 = 18446744073709551616.0;
max_value = aot_load_const_from_table(
comp_ctx, func_ctx->native_symbol, &wasm_value, VALUE_TYPE_F64);
}
}
CHECK_LLVM_CONST(min_value);
CHECK_LLVM_CONST(max_value);
if (!saturating)
return trunc_float_to_int(