Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate memset and memmove intrinsics from ccalls #43580

Merged
merged 4 commits into from
Jan 8, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1718,6 +1718,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(1),
pchintalapudi marked this conversation as resolved.
Show resolved Hide resolved
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