Skip to content

Commit 5f6b8a1

Browse files
Generate memset and memmove intrinsics from ccalls (#43580)
1 parent 45d22df commit 5f6b8a1

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/ccall.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,6 +1714,42 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
17141714
return rt == (jl_value_t*)jl_nothing_type ? ghostValue(jl_nothing_type) :
17151715
mark_or_box_ccall_result(ctx, destp, retboxed, rt, unionall, static_rt);
17161716
}
1717+
else if (is_libjulia_func(memset) && (rt == (jl_value_t*)jl_nothing_type || jl_is_cpointer_type(rt))) {
1718+
const jl_cgval_t &dst = argv[0];
1719+
const jl_cgval_t &val = argv[1];
1720+
const jl_cgval_t &n = argv[2];
1721+
Value *destp = emit_unbox(ctx, T_size, dst, (jl_value_t*)jl_voidpointer_type);
1722+
Value *val32 = emit_unbox(ctx, T_int32, val, (jl_value_t*)jl_uint32_type);
1723+
Value *val8 = ctx.builder.CreateTrunc(val32, T_int8, "memset_val");
1724+
ctx.builder.CreateMemSet(
1725+
emit_inttoptr(ctx, destp, T_pint8),
1726+
val8,
1727+
emit_unbox(ctx, T_size, n, (jl_value_t*)jl_ulong_type),
1728+
MaybeAlign(1)
1729+
);
1730+
JL_GC_POP();
1731+
return rt == (jl_value_t*)jl_nothing_type ? ghostValue(jl_nothing_type) :
1732+
mark_or_box_ccall_result(ctx, destp, retboxed, rt, unionall, static_rt);
1733+
}
1734+
else if (is_libjulia_func(memmove) && (rt == (jl_value_t*)jl_nothing_type || jl_is_cpointer_type(rt))) {
1735+
const jl_cgval_t &dst = argv[0];
1736+
const jl_cgval_t &src = argv[1];
1737+
const jl_cgval_t &n = argv[2];
1738+
Value *destp = emit_unbox(ctx, T_size, dst, (jl_value_t*)jl_voidpointer_type);
1739+
1740+
ctx.builder.CreateMemMove(
1741+
emit_inttoptr(ctx, destp, T_pint8),
1742+
MaybeAlign(0),
1743+
emit_inttoptr(ctx,
1744+
emit_unbox(ctx, T_size, src, (jl_value_t*)jl_voidpointer_type),
1745+
T_pint8),
1746+
MaybeAlign(0),
1747+
emit_unbox(ctx, T_size, n, (jl_value_t*)jl_ulong_type),
1748+
false);
1749+
JL_GC_POP();
1750+
return rt == (jl_value_t*)jl_nothing_type ? ghostValue(jl_nothing_type) :
1751+
mark_or_box_ccall_result(ctx, destp, retboxed, rt, unionall, static_rt);
1752+
}
17171753
else if (is_libjulia_func(jl_object_id) && nccallargs == 1 &&
17181754
rt == (jl_value_t*)jl_ulong_type) {
17191755
jl_cgval_t val = argv[0];

0 commit comments

Comments
 (0)