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

avoid passing pointers for known Type arguments #35347

Merged
merged 1 commit into from
Apr 6, 2020
Merged
Changes from all 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
53 changes: 48 additions & 5 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,36 @@ static bool type_is_ghost(Type *ty)
return (ty == T_void || ty->isEmptyTy());
}

// should agree with `Core.Compiler.hasuniquerep`
static bool type_has_unique_rep(jl_value_t *t)
{
if (t == (jl_value_t*)jl_typeofbottom_type)
return false;
if (t == jl_bottom_type)
return true;
if (jl_is_typevar(t))
return false;
if (!jl_is_kind(jl_typeof(t)))
return true;
if (jl_is_concrete_type(t))
return true;
if (jl_is_datatype(t)) {
jl_datatype_t *dt = (jl_datatype_t*)t;
if (dt->name != jl_tuple_typename && !jl_is_vararg_type(t)) {
for (size_t i = 0; i < jl_nparams(dt); i++)
if (!type_has_unique_rep(jl_tparam(dt, i)))
return false;
return true;
}
}
return false;
}

static bool is_uniquerep_Type(jl_value_t *t)
{
return jl_is_type_type(t) && type_has_unique_rep(jl_tparam0(t));
}

// global vars
static GlobalVariable *jlRTLD_DEFAULT_var;
#ifdef _OS_WINDOWS_
Expand Down Expand Up @@ -2633,6 +2663,8 @@ static jl_cgval_t emit_call_specfun_other(jl_codectx_t &ctx, jl_method_instance_

for (size_t i = 0; i < nargs; i++) {
jl_value_t *jt = jl_nth_slot_type(mi->specTypes, i);
if (is_uniquerep_Type(jt))
continue;
bool isboxed = deserves_argbox(jt);
Type *et = isboxed ? T_prjlvalue : julia_type_to_llvm(ctx, jt);
if (type_is_ghost(et))
Expand Down Expand Up @@ -3909,7 +3941,10 @@ static void emit_cfunc_invalidate(
jl_value_t *jt = jl_nth_slot_type(calltype, i);
bool isboxed = deserves_argbox(jt);
Type *et = isboxed ? T_prjlvalue : julia_type_to_llvm(ctx, jt);
if (type_is_ghost(et)) {
if (is_uniquerep_Type(jt)) {
myargs[i] = mark_julia_const(jl_tparam0(jt));
}
else if (type_is_ghost(et)) {
assert(jl_is_datatype(jt) && ((jl_datatype_t*)jt)->instance);
myargs[i] = mark_julia_const(((jl_datatype_t*)jt)->instance);
}
Expand Down Expand Up @@ -4343,7 +4378,10 @@ static Function* gen_cfun_wrapper(
jl_value_t *spect = jl_nth_slot_type(lam->specTypes, i);
bool isboxed = deserves_argbox(spect);
Type *T = isboxed ? T_prjlvalue : julia_type_to_llvm(ctx, spect);
if (isboxed) {
if (is_uniquerep_Type(spect)) {
continue;
}
else if (isboxed) {
arg = boxed(ctx, inputarg);
}
else if (type_is_ghost(T)) {
Expand Down Expand Up @@ -4826,7 +4864,7 @@ static Function *gen_invoke_wrapper(jl_method_instance_t *lam, jl_value_t *jlret
jl_value_t *ty = jl_nth_slot_type(lam->specTypes, i);
bool isboxed = deserves_argbox(ty);
Type *lty = isboxed ? T_prjlvalue : julia_type_to_llvm(ctx, ty);
if (type_is_ghost(lty))
if (type_is_ghost(lty) || is_uniquerep_Type(ty))
continue;
Value *theArg;
if (i == 0) {
Expand Down Expand Up @@ -4957,6 +4995,8 @@ static jl_returninfo_t get_specsig_function(jl_codectx_t &ctx, Module *M, String

for (size_t i = 0; i < jl_nparams(sig); i++) {
jl_value_t *jt = jl_tparam(sig, i);
if (is_uniquerep_Type(jt))
continue;
Type *ty = deserves_argbox(jt) ? T_prjlvalue : julia_type_to_llvm(ctx, jt);
if (type_is_ghost(ty))
continue;
Expand Down Expand Up @@ -5520,6 +5560,9 @@ static std::pair<std::unique_ptr<Module>, jl_llvm_functions_t>
if (type_is_ghost(llvmArgType)) { // this argument is not actually passed
theArg = ghostValue(argType);
}
else if (is_uniquerep_Type(argType)) {
theArg = mark_julia_const(jl_tparam0(argType));
}
else if (llvmArgType->isAggregateType()) {
Argument *Arg = &*AI; ++AI;
maybe_mark_argument_dereferenceable(Arg, argType);
Expand All @@ -5544,15 +5587,15 @@ static std::pair<std::unique_ptr<Module>, jl_llvm_functions_t>
bool isboxed = deserves_argbox(argType);
Type *llvmArgType = isboxed ? T_prjlvalue : julia_type_to_llvm(ctx, argType);
if (s == unused_sym) {
if (specsig && !type_is_ghost(llvmArgType))
if (specsig && !type_is_ghost(llvmArgType) && !is_uniquerep_Type(argType))
++AI;
continue;
}
jl_varinfo_t &vi = ctx.slots[i];
jl_cgval_t theArg;
if (s == unused_sym || vi.value.constant) {
assert(vi.boxroot == NULL);
if (specsig && !type_is_ghost(llvmArgType))
if (specsig && !type_is_ghost(llvmArgType) && !is_uniquerep_Type(argType))
++AI;
}
else {
Expand Down