Implement XIP feature and enable ARC target support (#694)
Implement XIP (Execution In Place) feature for AOT mode to enable running the AOT code inside AOT file directly, without memory mapping the executable memory for AOT code and applying relocations for text section. Developer can use wamrc with "--enable-indirect-mode --disable-llvm-intrinsics" flags to generate the AOT file and run iwasm with "--xip" flag. Known issues: there might still be some relocations in the text section which access the ".rodata" like sections. And also enable ARC target support for both interpreter mode and AOT mode. Signed-off-by: Wenyong Huang <wenyong.huang@intel.com>
This commit is contained in:
@ -7,6 +7,7 @@
|
||||
#include "aot_emit_exception.h"
|
||||
#include "aot_emit_control.h"
|
||||
#include "../aot/aot_runtime.h"
|
||||
#include "../aot/aot_intrinsic.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
@ -138,6 +139,7 @@
|
||||
/* Call llvm constrained floating-point intrinsic */
|
||||
static LLVMValueRef
|
||||
call_llvm_float_experimental_constrained_intrinsic(AOTCompContext *comp_ctx,
|
||||
AOTFuncContext *func_ctx,
|
||||
bool is_f32,
|
||||
const char *intrinsic,
|
||||
...)
|
||||
@ -145,14 +147,18 @@ call_llvm_float_experimental_constrained_intrinsic(AOTCompContext *comp_ctx,
|
||||
va_list param_value_list;
|
||||
LLVMValueRef ret;
|
||||
LLVMTypeRef param_types[4], ret_type = is_f32 ? F32_TYPE : F64_TYPE;
|
||||
int param_count = ((comp_ctx->disable_llvm_intrinsics == false)
|
||||
|| aot_intrinsic_check_capability(comp_ctx, intrinsic))
|
||||
? 4 : 2;
|
||||
|
||||
param_types[0] = param_types[1] = ret_type;
|
||||
param_types[2] = param_types[3] = MD_TYPE;
|
||||
|
||||
va_start(param_value_list, intrinsic);
|
||||
|
||||
ret = aot_call_llvm_intrinsic_v(comp_ctx, intrinsic, ret_type, param_types,
|
||||
4, param_value_list);
|
||||
ret =
|
||||
aot_call_llvm_intrinsic_v(comp_ctx, func_ctx, intrinsic, ret_type,
|
||||
param_types, param_count, param_value_list);
|
||||
|
||||
va_end(param_value_list);
|
||||
|
||||
@ -162,6 +168,7 @@ call_llvm_float_experimental_constrained_intrinsic(AOTCompContext *comp_ctx,
|
||||
/* Call llvm constrained libm-equivalent intrinsic */
|
||||
static LLVMValueRef
|
||||
call_llvm_libm_experimental_constrained_intrinsic(AOTCompContext *comp_ctx,
|
||||
AOTFuncContext *func_ctx,
|
||||
bool is_f32,
|
||||
const char *intrinsic,
|
||||
...)
|
||||
@ -175,7 +182,7 @@ call_llvm_libm_experimental_constrained_intrinsic(AOTCompContext *comp_ctx,
|
||||
|
||||
va_start(param_value_list, intrinsic);
|
||||
|
||||
ret = aot_call_llvm_intrinsic_v(comp_ctx, intrinsic, ret_type, param_types,
|
||||
ret = aot_call_llvm_intrinsic_v(comp_ctx, func_ctx, intrinsic, ret_type, param_types,
|
||||
3, param_value_list);
|
||||
|
||||
va_end(param_value_list);
|
||||
@ -185,6 +192,7 @@ call_llvm_libm_experimental_constrained_intrinsic(AOTCompContext *comp_ctx,
|
||||
|
||||
static LLVMValueRef
|
||||
compile_op_float_min_max(AOTCompContext *comp_ctx,
|
||||
AOTFuncContext *func_ctx,
|
||||
bool is_f32,
|
||||
LLVMValueRef left,
|
||||
LLVMValueRef right,
|
||||
@ -230,8 +238,9 @@ compile_op_float_min_max(AOTCompContext *comp_ctx,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(cmp = aot_call_llvm_intrinsic(comp_ctx, intrinsic, ret_type,
|
||||
param_types, 2, left, right)))
|
||||
if (!(cmp =
|
||||
aot_call_llvm_intrinsic(comp_ctx, func_ctx, intrinsic, ret_type,
|
||||
param_types, 2, left, right)))
|
||||
return NULL;
|
||||
|
||||
if (!(cmp = LLVMBuildSelect(comp_ctx->builder,
|
||||
@ -266,13 +275,14 @@ typedef enum BitCountType {
|
||||
POP_CNT64
|
||||
} BitCountType;
|
||||
|
||||
static char *bit_cnt_llvm_intrinsic[] = { "llvm.ctlz.i32",
|
||||
"llvm.ctlz.i64",
|
||||
"llvm.cttz.i32",
|
||||
"llvm.cttz.i64",
|
||||
"llvm.ctpop.i32",
|
||||
"llvm.ctpop.i64",
|
||||
};
|
||||
static char *bit_cnt_llvm_intrinsic[] = {
|
||||
"llvm.ctlz.i32",
|
||||
"llvm.ctlz.i64",
|
||||
"llvm.cttz.i32",
|
||||
"llvm.cttz.i64",
|
||||
"llvm.ctpop.i32",
|
||||
"llvm.ctpop.i64",
|
||||
};
|
||||
|
||||
static bool
|
||||
aot_compile_int_bit_count(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||
@ -290,6 +300,7 @@ aot_compile_int_bit_count(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||
/* Call the LLVM intrinsic function */
|
||||
if (type < POP_CNT32)
|
||||
DEF_INT_UNARY_OP(aot_call_llvm_intrinsic(comp_ctx,
|
||||
func_ctx,
|
||||
bit_cnt_llvm_intrinsic[type],
|
||||
ret_type,
|
||||
param_types,
|
||||
@ -299,6 +310,7 @@ aot_compile_int_bit_count(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||
NULL);
|
||||
else
|
||||
DEF_INT_UNARY_OP(aot_call_llvm_intrinsic(comp_ctx,
|
||||
func_ctx,
|
||||
bit_cnt_llvm_intrinsic[type],
|
||||
ret_type,
|
||||
param_types,
|
||||
@ -823,6 +835,7 @@ compile_op_float_arithmetic(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||
else
|
||||
DEF_FP_BINARY_OP(call_llvm_float_experimental_constrained_intrinsic(
|
||||
comp_ctx,
|
||||
func_ctx,
|
||||
is_f32,
|
||||
(is_f32
|
||||
? "llvm.experimental.constrained.fadd.f32"
|
||||
@ -840,6 +853,7 @@ compile_op_float_arithmetic(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||
else
|
||||
DEF_FP_BINARY_OP(call_llvm_float_experimental_constrained_intrinsic(
|
||||
comp_ctx,
|
||||
func_ctx,
|
||||
is_f32,
|
||||
(is_f32
|
||||
? "llvm.experimental.constrained.fsub.f32"
|
||||
@ -857,6 +871,7 @@ compile_op_float_arithmetic(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||
else
|
||||
DEF_FP_BINARY_OP(call_llvm_float_experimental_constrained_intrinsic(
|
||||
comp_ctx,
|
||||
func_ctx,
|
||||
is_f32,
|
||||
(is_f32
|
||||
? "llvm.experimental.constrained.fmul.f32"
|
||||
@ -874,6 +889,7 @@ compile_op_float_arithmetic(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||
else
|
||||
DEF_FP_BINARY_OP(call_llvm_float_experimental_constrained_intrinsic(
|
||||
comp_ctx,
|
||||
func_ctx,
|
||||
is_f32,
|
||||
(is_f32
|
||||
? "llvm.experimental.constrained.fdiv.f32"
|
||||
@ -886,6 +902,7 @@ compile_op_float_arithmetic(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||
return true;
|
||||
case FLOAT_MIN:
|
||||
DEF_FP_BINARY_OP(compile_op_float_min_max(comp_ctx,
|
||||
func_ctx,
|
||||
is_f32,
|
||||
left,
|
||||
right,
|
||||
@ -894,6 +911,7 @@ compile_op_float_arithmetic(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||
return true;
|
||||
case FLOAT_MAX:
|
||||
DEF_FP_BINARY_OP(compile_op_float_min_max(comp_ctx,
|
||||
func_ctx,
|
||||
is_f32,
|
||||
left,
|
||||
right,
|
||||
@ -912,6 +930,7 @@ fail:
|
||||
|
||||
static LLVMValueRef
|
||||
call_llvm_float_math_intrinsic(AOTCompContext *comp_ctx,
|
||||
AOTFuncContext *func_ctx,
|
||||
bool is_f32,
|
||||
const char *intrinsic,
|
||||
...)
|
||||
@ -924,8 +943,8 @@ call_llvm_float_math_intrinsic(AOTCompContext *comp_ctx,
|
||||
|
||||
va_start(param_value_list, intrinsic);
|
||||
|
||||
ret = aot_call_llvm_intrinsic_v(comp_ctx, intrinsic, ret_type, ¶m_type,
|
||||
1, param_value_list);
|
||||
ret = aot_call_llvm_intrinsic_v(comp_ctx, func_ctx, intrinsic, ret_type,
|
||||
¶m_type, 1, param_value_list);
|
||||
|
||||
va_end(param_value_list);
|
||||
|
||||
@ -939,6 +958,7 @@ compile_op_float_math(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||
switch (math_op) {
|
||||
case FLOAT_ABS:
|
||||
DEF_FP_UNARY_OP(call_llvm_float_math_intrinsic(comp_ctx,
|
||||
func_ctx,
|
||||
is_f32,
|
||||
is_f32 ? "llvm.fabs.f32" :
|
||||
"llvm.fabs.f64",
|
||||
@ -952,6 +972,7 @@ compile_op_float_math(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||
|
||||
case FLOAT_CEIL:
|
||||
DEF_FP_UNARY_OP(call_llvm_float_math_intrinsic(comp_ctx,
|
||||
func_ctx,
|
||||
is_f32,
|
||||
is_f32 ? "llvm.ceil.f32" :
|
||||
"llvm.ceil.f64",
|
||||
@ -960,6 +981,7 @@ compile_op_float_math(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||
return true;
|
||||
case FLOAT_FLOOR:
|
||||
DEF_FP_UNARY_OP(call_llvm_float_math_intrinsic(comp_ctx,
|
||||
func_ctx,
|
||||
is_f32,
|
||||
is_f32 ? "llvm.floor.f32":
|
||||
"llvm.floor.f64",
|
||||
@ -968,6 +990,7 @@ compile_op_float_math(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||
return true;
|
||||
case FLOAT_TRUNC:
|
||||
DEF_FP_UNARY_OP(call_llvm_float_math_intrinsic(comp_ctx,
|
||||
func_ctx,
|
||||
is_f32,
|
||||
is_f32 ? "llvm.trunc.f32" :
|
||||
"llvm.trunc.f64",
|
||||
@ -976,6 +999,7 @@ compile_op_float_math(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||
return true;
|
||||
case FLOAT_NEAREST:
|
||||
DEF_FP_UNARY_OP(call_llvm_float_math_intrinsic(comp_ctx,
|
||||
func_ctx,
|
||||
is_f32,
|
||||
is_f32 ? "llvm.rint.f32" :
|
||||
"llvm.rint.f64",
|
||||
@ -983,8 +1007,10 @@ compile_op_float_math(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||
NULL);
|
||||
return true;
|
||||
case FLOAT_SQRT:
|
||||
if (is_targeting_soft_float(comp_ctx, is_f32))
|
||||
if (is_targeting_soft_float(comp_ctx, is_f32)
|
||||
|| comp_ctx->disable_llvm_intrinsics)
|
||||
DEF_FP_UNARY_OP(call_llvm_float_math_intrinsic(comp_ctx,
|
||||
func_ctx,
|
||||
is_f32,
|
||||
is_f32 ? "llvm.sqrt.f32" :
|
||||
"llvm.sqrt.f64",
|
||||
@ -993,6 +1019,7 @@ compile_op_float_math(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||
else
|
||||
DEF_FP_UNARY_OP(call_llvm_libm_experimental_constrained_intrinsic(
|
||||
comp_ctx,
|
||||
func_ctx,
|
||||
is_f32,
|
||||
(is_f32
|
||||
? "llvm.experimental.constrained.sqrt.f32"
|
||||
@ -1022,6 +1049,7 @@ compile_float_copysign(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||
param_types[0] = param_types[1] = ret_type = is_f32 ? F32_TYPE : F64_TYPE;
|
||||
|
||||
DEF_FP_BINARY_OP(aot_call_llvm_intrinsic(comp_ctx,
|
||||
func_ctx,
|
||||
is_f32 ? "llvm.copysign.f32" :
|
||||
"llvm.copysign.f64",
|
||||
ret_type,
|
||||
|
||||
Reference in New Issue
Block a user