diff --git a/src/builtins.c b/src/builtins.c index f9f68b852ddca..8f1025fde865a 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -1156,7 +1156,7 @@ static void add_intrinsic_properties(enum intrinsic f, unsigned nargs, void (*pf static void add_intrinsic(jl_module_t *inm, const char *name, enum intrinsic f) { - jl_value_t *i = jl_box32(jl_intrinsic_type, (int32_t)f); + jl_value_t *i = jl_permbox32(jl_intrinsic_type, (int32_t)f); jl_sym_t *sym = jl_symbol(name); jl_set_const(inm, sym, i); jl_module_export(inm, sym); diff --git a/src/cgutils.cpp b/src/cgutils.cpp index 1024e97bb2273..6521f27a87f17 100644 --- a/src/cgutils.cpp +++ b/src/cgutils.cpp @@ -1979,17 +1979,10 @@ static jl_value_t *static_constant_instance(Constant *constant, jl_value_t *jt) return tpl; } -static Value *call_with_signed(jl_codectx_t &ctx, Function *sfunc, Value *v) +static Value *call_with_attrs(jl_codectx_t &ctx, Function *func, Value *v) { - CallInst *Call = ctx.builder.CreateCall(prepare_call(sfunc), v); - Call->addAttribute(1, Attribute::SExt); - return Call; -} - -static Value *call_with_unsigned(jl_codectx_t &ctx, Function *ufunc, Value *v) -{ - CallInst *Call = ctx.builder.CreateCall(prepare_call(ufunc), v); - Call->addAttribute(1, Attribute::ZExt); + CallInst *Call = ctx.builder.CreateCall(prepare_call(func), v); + Call->setAttributes(func->getAttributes()); return Call; } @@ -2024,34 +2017,34 @@ static Value *_boxed_special(jl_codectx_t &ctx, const jl_cgval_t &vinfo, Type *t assert(jl_is_datatype(jb)); Value *box = NULL; if (jb == jl_int8_type) - box = call_with_signed(ctx, box_int8_func, as_value(ctx, t, vinfo)); + box = call_with_attrs(ctx, box_int8_func, as_value(ctx, t, vinfo)); else if (jb == jl_int16_type) - box = call_with_signed(ctx, box_int16_func, as_value(ctx, t, vinfo)); + box = call_with_attrs(ctx, box_int16_func, as_value(ctx, t, vinfo)); else if (jb == jl_int32_type) - box = call_with_signed(ctx, box_int32_func, as_value(ctx, t, vinfo)); + box = call_with_attrs(ctx, box_int32_func, as_value(ctx, t, vinfo)); else if (jb == jl_int64_type) - box = call_with_signed(ctx, box_int64_func, as_value(ctx, t, vinfo)); + box = call_with_attrs(ctx, box_int64_func, as_value(ctx, t, vinfo)); else if (jb == jl_float32_type) box = ctx.builder.CreateCall(prepare_call(box_float32_func), as_value(ctx, t, vinfo)); //if (jb == jl_float64_type) // box = ctx.builder.CreateCall(box_float64_func, as_value(ctx, t, vinfo); // for Float64, fall through to generic case below, to inline alloc & init of Float64 box. cheap, I know. else if (jb == jl_uint8_type) - box = call_with_unsigned(ctx, box_uint8_func, as_value(ctx, t, vinfo)); + box = call_with_attrs(ctx, box_uint8_func, as_value(ctx, t, vinfo)); else if (jb == jl_uint16_type) - box = call_with_unsigned(ctx, box_uint16_func, as_value(ctx, t, vinfo)); + box = call_with_attrs(ctx, box_uint16_func, as_value(ctx, t, vinfo)); else if (jb == jl_uint32_type) - box = call_with_unsigned(ctx, box_uint32_func, as_value(ctx, t, vinfo)); + box = call_with_attrs(ctx, box_uint32_func, as_value(ctx, t, vinfo)); else if (jb == jl_uint64_type) - box = call_with_unsigned(ctx, box_uint64_func, as_value(ctx, t, vinfo)); + box = call_with_attrs(ctx, box_uint64_func, as_value(ctx, t, vinfo)); else if (jb == jl_char_type) - box = call_with_unsigned(ctx, box_char_func, as_value(ctx, t, vinfo)); + box = call_with_attrs(ctx, box_char_func, as_value(ctx, t, vinfo)); else if (jb == jl_ssavalue_type) { unsigned zero = 0; Value *v = as_value(ctx, t, vinfo); assert(v->getType() == jl_ssavalue_type->struct_decl); v = ctx.builder.CreateExtractValue(v, makeArrayRef(&zero, 1)); - box = call_with_unsigned(ctx, box_ssavalue_func, v); + box = call_with_attrs(ctx, box_ssavalue_func, v); } else if (!jb->abstract && jl_datatype_nbits(jb) == 0) { // singleton diff --git a/src/codegen.cpp b/src/codegen.cpp index 05978c785ea98..e2fe4a96e4805 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -320,10 +320,6 @@ static Function *box_uint64_func; static Function *box_float32_func; static Function *box_float64_func; static Function *box_ssavalue_func; -static Function *box8_func; -static Function *box16_func; -static Function *box32_func; -static Function *box64_func; static Function *expect_func; static Function *jldlsym_func; static Function *jltypeassert_func; @@ -7503,22 +7499,14 @@ extern "C" void jl_init_codegen(void) Module *m = (Module *)jl_init_llvm(); init_julia_llvm_env(m); - BOX_F(int8,int8); UBOX_F(uint8,uint8); - BOX_F(int16,int16); UBOX_F(uint16,uint16); - BOX_F(int32,int32); UBOX_F(uint32,uint32); - BOX_F(int64,int64); UBOX_F(uint64,uint64); - BOX_F(float32,float32); BOX_F(float64,float64); - BOX_F(char,char); + SBOX_F_PERM(int8,int8); UBOX_F_PERM(uint8,uint8); + SBOX_F(int16,int16); UBOX_F(uint16,uint16); + SBOX_F(int32,int32); UBOX_F(uint32,uint32); + SBOX_F(int64,int64); UBOX_F(uint64,uint64); + BOX_F(float32,float32,T_prjlvalue); BOX_F(float64,float64,T_prjlvalue); + UBOX_F(char,char); UBOX_F(ssavalue,size); - box8_func = boxfunc_llvm(ft2arg(T_pjlvalue, T_pjlvalue, T_int8), - "jl_box8", &jl_box8, m); - box16_func = boxfunc_llvm(ft2arg(T_pjlvalue, T_pjlvalue, T_int16), - "jl_box16", &jl_box16, m); - box32_func = boxfunc_llvm(ft2arg(T_pjlvalue, T_pjlvalue, T_int32), - "jl_box32", &jl_box32, m); - box64_func = boxfunc_llvm(ft2arg(T_pjlvalue, T_pjlvalue, T_int64), - "jl_box64", &jl_box64, m); jl_init_intrinsic_functions_codegen(m); } diff --git a/src/datatype.c b/src/datatype.c index 2b8b25cd18812..14a7b5cfbd097 100644 --- a/src/datatype.c +++ b/src/datatype.c @@ -588,16 +588,7 @@ void jl_assign_bits(void *dest, jl_value_t *bits) } } -#define BOXN_FUNC(nb,nw) \ - JL_DLLEXPORT jl_value_t *jl_box##nb(jl_datatype_t *t, int##nb##_t x) \ - { \ - jl_ptls_t ptls = jl_get_ptls_states(); \ - assert(jl_isbits(t)); \ - assert(jl_datatype_size(t) == sizeof(x)); \ - jl_value_t *v = jl_gc_alloc(ptls, nw * sizeof(void*), t); \ - *(int##nb##_t*)jl_data_ptr(v) = x; \ - return v; \ - } \ +#define PERMBOXN_FUNC(nb,nw) \ jl_value_t *jl_permbox##nb(jl_datatype_t *t, int##nb##_t x) \ { \ assert(jl_isbits(t)); \ @@ -606,13 +597,13 @@ void jl_assign_bits(void *dest, jl_value_t *bits) *(int##nb##_t*)jl_data_ptr(v) = x; \ return v; \ } -BOXN_FUNC(8, 1) -BOXN_FUNC(16, 1) -BOXN_FUNC(32, 1) +PERMBOXN_FUNC(8, 1) +PERMBOXN_FUNC(16, 1) +PERMBOXN_FUNC(32, 1) #ifdef _P64 -BOXN_FUNC(64, 1) +PERMBOXN_FUNC(64, 1) #else -BOXN_FUNC(64, 2) +PERMBOXN_FUNC(64, 2) #endif #define UNBOX_FUNC(j_type,c_type) \ diff --git a/src/intrinsics.cpp b/src/intrinsics.cpp index b84262f973397..f22ee03aad003 100644 --- a/src/intrinsics.cpp +++ b/src/intrinsics.cpp @@ -1306,12 +1306,14 @@ static Value *emit_untyped_intrinsic(jl_codectx_t &ctx, intrinsic f, Value **arg assert(0 && "unreachable"); } -#define BOX_F(ct,jl_ct) \ - box_##ct##_func = boxfunc_llvm(ft1arg(T_prjlvalue, T_##jl_ct), \ +#define BOX_F(ct,jl_ct,rt) \ + box_##ct##_func = boxfunc_llvm(ft1arg(rt, T_##jl_ct), \ "jl_box_"#ct, &jl_box_##ct, m); -#define SBOX_F(ct,jl_ct) BOX_F(ct,jl_ct); box_##ct##_func->addAttribute(1, Attribute::SExt); -#define UBOX_F(ct,jl_ct) BOX_F(ct,jl_ct); box_##ct##_func->addAttribute(1, Attribute::ZExt); +#define SBOX_F(ct,jl_ct) BOX_F(ct,jl_ct,T_prjlvalue); box_##ct##_func->addAttribute(1, Attribute::SExt); +#define UBOX_F(ct,jl_ct) BOX_F(ct,jl_ct,T_prjlvalue); box_##ct##_func->addAttribute(1, Attribute::ZExt); +#define SBOX_F_PERM(ct,jl_ct) BOX_F(ct,jl_ct,T_pjlvalue); box_##ct##_func->addAttribute(1, Attribute::SExt); +#define UBOX_F_PERM(ct,jl_ct) BOX_F(ct,jl_ct,T_pjlvalue); box_##ct##_func->addAttribute(1, Attribute::ZExt); template static Function *boxfunc_llvm(FunctionType *ft, const std::string &cname, diff --git a/src/julia.h b/src/julia.h index a21d4e9a20959..ea7c339945533 100644 --- a/src/julia.h +++ b/src/julia.h @@ -1156,10 +1156,6 @@ JL_DLLEXPORT jl_value_t *jl_box_float64(double x); JL_DLLEXPORT jl_value_t *jl_box_voidpointer(void *x); JL_DLLEXPORT jl_value_t *jl_box_ssavalue(size_t x); JL_DLLEXPORT jl_value_t *jl_box_slotnumber(size_t x); -JL_DLLEXPORT jl_value_t *jl_box8 (jl_datatype_t *t, int8_t x); -JL_DLLEXPORT jl_value_t *jl_box16(jl_datatype_t *t, int16_t x); -JL_DLLEXPORT jl_value_t *jl_box32(jl_datatype_t *t, int32_t x); -JL_DLLEXPORT jl_value_t *jl_box64(jl_datatype_t *t, int64_t x); JL_DLLEXPORT int8_t jl_unbox_bool(jl_value_t *v) JL_NOTSAFEPOINT; JL_DLLEXPORT int8_t jl_unbox_int8(jl_value_t *v) JL_NOTSAFEPOINT; JL_DLLEXPORT uint8_t jl_unbox_uint8(jl_value_t *v) JL_NOTSAFEPOINT;