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

Remove arraylist_t from external native code APIs. #56693

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
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
56 changes: 39 additions & 17 deletions src/aotcompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,33 +95,55 @@ void jl_get_function_id_impl(void *native_code, jl_code_instance_t *codeinst,
}
}

extern "C" JL_DLLEXPORT_CODEGEN
void jl_get_llvm_mis_impl(void *native_code, arraylist_t* MIs)
extern "C" JL_DLLEXPORT_CODEGEN void
jl_get_llvm_mis_impl(void *native_code, size_t *num_elements, jl_method_instance_t **data)
{
jl_native_code_desc_t *data = (jl_native_code_desc_t*)native_code;
auto map = data->jl_fvar_map;
jl_native_code_desc_t *desc = (jl_native_code_desc_t *)native_code;
auto &map = desc->jl_fvar_map;

if (data == NULL) {
*num_elements = map.size();
return;
}

assert(*num_elements == map.size());
size_t i = 0;
for (auto &ci : map) {
jl_method_instance_t *mi = ci.first->def;
arraylist_push(MIs, mi);
data[i++] = ci.first->def;
}
}

extern "C" JL_DLLEXPORT_CODEGEN
void jl_get_llvm_gvs_impl(void *native_code, arraylist_t *gvs)
extern "C" JL_DLLEXPORT_CODEGEN void jl_get_llvm_gvs_impl(void *native_code,
size_t *num_elements, void **data)
{
// map a memory location (jl_value_t or jl_binding_t) to a GlobalVariable
jl_native_code_desc_t *data = (jl_native_code_desc_t*)native_code;
arraylist_grow(gvs, data->jl_value_to_llvm.size());
memcpy(gvs->items, data->jl_value_to_llvm.data(), gvs->len * sizeof(void*));
jl_native_code_desc_t *desc = (jl_native_code_desc_t *)native_code;
auto &value_map = desc->jl_value_to_llvm;

if (data == NULL) {
*num_elements = value_map.size();
return;
}

assert(*num_elements == value_map.size());
memcpy(data, value_map.data(), *num_elements * sizeof(void *));
}

extern "C" JL_DLLEXPORT_CODEGEN
void jl_get_llvm_external_fns_impl(void *native_code, arraylist_t *external_fns)
extern "C" JL_DLLEXPORT_CODEGEN void jl_get_llvm_external_fns_impl(void *native_code,
size_t *num_elements,
jl_code_instance_t *data)
{
jl_native_code_desc_t *data = (jl_native_code_desc_t*)native_code;
arraylist_grow(external_fns, data->jl_external_to_llvm.size());
memcpy(external_fns->items, data->jl_external_to_llvm.data(),
external_fns->len * sizeof(jl_code_instance_t*));
jl_native_code_desc_t *desc = (jl_native_code_desc_t *)native_code;
auto &external_map = desc->jl_external_to_llvm;

if (data == NULL) {
*num_elements = external_map.size();
return;
}

assert(*num_elements == external_map.size());
memcpy((void *)data, (const void *)external_map.data(),
*num_elements * sizeof(jl_code_instance_t *));
}

extern "C" JL_DLLEXPORT_CODEGEN
Expand Down
8 changes: 5 additions & 3 deletions src/julia_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -1951,13 +1951,15 @@ JL_DLLIMPORT void *jl_create_native(jl_array_t *methods, LLVMOrcThreadSafeModule
JL_DLLIMPORT void jl_dump_native(void *native_code,
const char *bc_fname, const char *unopt_bc_fname, const char *obj_fname, const char *asm_fname,
ios_t *z, ios_t *s, jl_emission_params_t *params);
JL_DLLIMPORT void jl_get_llvm_gvs(void *native_code, arraylist_t *gvs);
JL_DLLIMPORT void jl_get_llvm_external_fns(void *native_code, arraylist_t *gvs);
JL_DLLIMPORT void jl_get_llvm_gvs(void *native_code, size_t *num_els, void **gvs);
JL_DLLIMPORT void jl_get_llvm_external_fns(void *native_code, size_t *num_els,
jl_code_instance_t *gvs);
JL_DLLIMPORT void jl_get_function_id(void *native_code, jl_code_instance_t *ncode,
int32_t *func_idx, int32_t *specfunc_idx);
JL_DLLIMPORT void jl_register_fptrs(uint64_t image_base, const struct _jl_image_fptrs_t *fptrs,
jl_method_instance_t **linfos, size_t n);
JL_DLLIMPORT void jl_get_llvm_mis(void *native_code, arraylist_t* MIs);
JL_DLLIMPORT void jl_get_llvm_mis(void *native_code, size_t *num_els,
jl_method_instance_t *MIs);
JL_DLLIMPORT void jl_init_codegen(void);
JL_DLLIMPORT void jl_teardown_codegen(void) JL_NOTSAFEPOINT;
JL_DLLIMPORT int jl_getFunctionInfo(jl_frame_t **frames, uintptr_t pointer, int skipC, int noInline) JL_NOTSAFEPOINT;
Expand Down
18 changes: 14 additions & 4 deletions src/staticdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -2896,10 +2896,20 @@ static void jl_save_system_image_to_stream(ios_t *f, jl_array_t *mod_array,

int en = jl_gc_enable(0);
if (native_functions) {
jl_get_llvm_gvs(native_functions, &gvars);
jl_get_llvm_external_fns(native_functions, &external_fns);
if (jl_options.trim)
jl_get_llvm_mis(native_functions, &MIs);
size_t num_gvars, num_external_fns;
jl_get_llvm_gvs(native_functions, &num_gvars, NULL);
arraylist_grow(&gvars, num_gvars);
jl_get_llvm_gvs(native_functions, &num_gvars, gvars.items);
jl_get_llvm_external_fns(native_functions, &num_external_fns, NULL);
arraylist_grow(&external_fns, num_external_fns);
jl_get_llvm_external_fns(native_functions, &num_external_fns,
(jl_code_instance_t *)external_fns.items);
if (jl_options.trim) {
size_t num_mis;
jl_get_llvm_mis(native_functions, &num_mis, NULL);
arraylist_grow(&MIs, num_mis);
jl_get_llvm_mis(native_functions, &num_mis, (jl_method_instance_t *)MIs.items);
}
}
if (jl_options.trim) {
jl_rebuild_methtables(&MIs, &new_methtables);
Expand Down