Skip to content

Commit

Permalink
Generate memset and memmove intrinsics from ccalls (JuliaLang#43580)
Browse files Browse the repository at this point in the history
  • Loading branch information
pchintalapudi authored and LilithHafner committed Mar 8, 2022
1 parent a462f40 commit ecbe274
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1714,6 +1714,42 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
return rt == (jl_value_t*)jl_nothing_type ? ghostValue(jl_nothing_type) :
mark_or_box_ccall_result(ctx, destp, retboxed, rt, unionall, static_rt);
}
else if (is_libjulia_func(memset) && (rt == (jl_value_t*)jl_nothing_type || jl_is_cpointer_type(rt))) {
const jl_cgval_t &dst = argv[0];
const jl_cgval_t &val = argv[1];
const jl_cgval_t &n = argv[2];
Value *destp = emit_unbox(ctx, T_size, dst, (jl_value_t*)jl_voidpointer_type);
Value *val32 = emit_unbox(ctx, T_int32, val, (jl_value_t*)jl_uint32_type);
Value *val8 = ctx.builder.CreateTrunc(val32, T_int8, "memset_val");
ctx.builder.CreateMemSet(
emit_inttoptr(ctx, destp, T_pint8),
val8,
emit_unbox(ctx, T_size, n, (jl_value_t*)jl_ulong_type),
MaybeAlign(1)
);
JL_GC_POP();
return rt == (jl_value_t*)jl_nothing_type ? ghostValue(jl_nothing_type) :
mark_or_box_ccall_result(ctx, destp, retboxed, rt, unionall, static_rt);
}
else if (is_libjulia_func(memmove) && (rt == (jl_value_t*)jl_nothing_type || jl_is_cpointer_type(rt))) {
const jl_cgval_t &dst = argv[0];
const jl_cgval_t &src = argv[1];
const jl_cgval_t &n = argv[2];
Value *destp = emit_unbox(ctx, T_size, dst, (jl_value_t*)jl_voidpointer_type);

ctx.builder.CreateMemMove(
emit_inttoptr(ctx, destp, T_pint8),
MaybeAlign(0),
emit_inttoptr(ctx,
emit_unbox(ctx, T_size, src, (jl_value_t*)jl_voidpointer_type),
T_pint8),
MaybeAlign(0),
emit_unbox(ctx, T_size, n, (jl_value_t*)jl_ulong_type),
false);
JL_GC_POP();
return rt == (jl_value_t*)jl_nothing_type ? ghostValue(jl_nothing_type) :
mark_or_box_ccall_result(ctx, destp, retboxed, rt, unionall, static_rt);
}
else if (is_libjulia_func(jl_object_id) && nccallargs == 1 &&
rt == (jl_value_t*)jl_ulong_type) {
jl_cgval_t val = argv[0];
Expand Down

0 comments on commit ecbe274

Please sign in to comment.