Skip to content

Commit

Permalink
Put C-callable functions in to jl_sysimg_fvars.
Browse files Browse the repository at this point in the history
  • Loading branch information
maleadt committed Sep 15, 2020
1 parent 6610867 commit 8064e00
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
9 changes: 7 additions & 2 deletions src/aotcompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,13 @@ void *jl_create_native(jl_array_t *methods, const jl_cgparams_t cgparams, int _p
// to compile, or an svec(rettype, sig) describing a C-callable alias to create.
jl_value_t *item = jl_array_ptr_ref(methods, i);
if (jl_is_simplevector(item)) {
if (worlds == 1)
jl_compile_extern_c(clone.get(), &params, NULL, jl_svecref(item, 0), jl_svecref(item, 1));
if (worlds == 1) {
Function *F = (Function *)jl_compile_extern_c(clone.get(), &params,
NULL, jl_svecref(item, 0),
jl_svecref(item, 1));
assert(F);
data->jl_sysimg_fvars.push_back(F);
}
continue;
}
mi = (jl_method_instance_t*)item;
Expand Down
9 changes: 6 additions & 3 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5369,7 +5369,8 @@ static jl_cgval_t emit_cfunction(jl_codectx_t &ctx, jl_value_t *output_type, con

// do codegen to create a C-callable alias/wrapper, or if sysimg_handle is set,
// restore one from a loaded system image.
void jl_generate_ccallable(void *llvmmod, void *sysimg_handle, jl_value_t *declrt, jl_value_t *sigt, jl_codegen_params_t &params)
Function *jl_generate_ccallable(void *llvmmod, void *sysimg_handle, jl_value_t *declrt,
jl_value_t *sigt, jl_codegen_params_t &params)
{
jl_datatype_t *ft = (jl_datatype_t*)jl_tparam0(sigt);
jl_value_t *ff = ft->instance;
Expand All @@ -5393,6 +5394,7 @@ void jl_generate_ccallable(void *llvmmod, void *sysimg_handle, jl_value_t *declr
}
jl_value_t *err;
{ // scope block for sig
Function *F = NULL;
function_sig_t sig("cfunction", lcrt, crt, toboxed,
argtypes, NULL, false, CallingConv::C, false, &params);
if (sig.err_msg.empty()) {
Expand All @@ -5408,10 +5410,11 @@ void jl_generate_ccallable(void *llvmmod, void *sysimg_handle, jl_value_t *declr
}
else {
jl_method_instance_t *lam = jl_get_specialization1((jl_tupletype_t*)sigt, world, &min_valid, &max_valid, 0);
gen_cfun_wrapper((Module*)llvmmod, params, sig, ff, name, declrt, lam, NULL, NULL, NULL);
F = gen_cfun_wrapper((Module *)llvmmod, params, sig, ff, name, declrt, lam,
NULL, NULL, NULL);
}
JL_GC_POP();
return;
return F;
}
err = jl_get_exceptionf(jl_errorexception_type, "%s", sig.err_msg.c_str());
}
Expand Down
10 changes: 6 additions & 4 deletions src/jitlayers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,12 @@ static jl_callptr_t _jl_compile_codeinst(
return fptr;
}

void jl_generate_ccallable(void *llvmmod, void *sysimg_handle, jl_value_t *declrt, jl_value_t *sigt, jl_codegen_params_t &params);
Function *jl_generate_ccallable(void *llvmmod, void *sysimg_handle, jl_value_t *declrt,
jl_value_t *sigt, jl_codegen_params_t &params);

// compile a C-callable alias
extern "C" JL_DLLEXPORT
void jl_compile_extern_c(void *llvmmod, void *p, void *sysimg, jl_value_t *declrt, jl_value_t *sigt)
extern "C" JL_DLLEXPORT void *jl_compile_extern_c(void *llvmmod, void *p, void *sysimg,
jl_value_t *declrt, jl_value_t *sigt)
{
JL_LOCK(&codegen_lock);
jl_codegen_params_t params;
Expand All @@ -217,7 +218,7 @@ void jl_compile_extern_c(void *llvmmod, void *p, void *sysimg, jl_value_t *declr
Module *into = (Module*)llvmmod;
if (into == NULL)
into = jl_create_llvm_module("cextern");
jl_generate_ccallable(into, sysimg, declrt, sigt, *pparams);
Function *F = jl_generate_ccallable(into, sysimg, declrt, sigt, *pparams);
if (!sysimg) {
if (p == NULL) {
jl_jit_globals(params.globals);
Expand All @@ -229,6 +230,7 @@ void jl_compile_extern_c(void *llvmmod, void *p, void *sysimg, jl_value_t *declr
jl_add_to_ee(std::unique_ptr<Module>(into));
}
JL_UNLOCK(&codegen_lock);
return F;
}

bool jl_type_mappable_to_c(jl_value_t *ty);
Expand Down
3 changes: 2 additions & 1 deletion src/julia_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,8 @@ jl_binding_t *jl_get_module_binding(jl_module_t *m JL_PROPAGATES_ROOT, jl_sym_t
void jl_binding_deprecation_warning(jl_module_t *m, jl_binding_t *b);
extern jl_array_t *jl_module_init_order JL_GLOBALLY_ROOTED;
extern htable_t jl_current_modules JL_GLOBALLY_ROOTED;
JL_DLLEXPORT void jl_compile_extern_c(void *llvmmod, void *params, void *sysimg, jl_value_t *declrt, jl_value_t *sigt);
JL_DLLEXPORT void *jl_compile_extern_c(void *llvmmod, void *params, void *sysimg,
jl_value_t *declrt, jl_value_t *sigt);

// Each tuple can exist in one of 4 Vararg states:
// NONE: no vararg Tuple{Int,Float32}
Expand Down

0 comments on commit 8064e00

Please sign in to comment.