Skip to content

Commit

Permalink
Remove some duplicates from emitted compilation traces for Julia 1.10 (
Browse files Browse the repository at this point in the history
…#53776)

When multiple threads concurrently attempt to compile the same method,
`--trace-compile` could emit duplicate `precompile` statements. This
small tweak eliminates one source of these duplicates.

Backported to 1.10 from #53774.
  • Loading branch information
kpamnany authored Mar 20, 2024
1 parent 7536f35 commit f6a3c5f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/codegen-stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ JL_DLLEXPORT void jl_register_fptrs_fallback(uint64_t image_base, const struct _
(void)image_base; (void)fptrs; (void)linfos; (void)n;
}

JL_DLLEXPORT jl_code_instance_t *jl_generate_fptr_fallback(jl_method_instance_t *mi JL_PROPAGATES_ROOT, size_t world)
JL_DLLEXPORT jl_code_instance_t *jl_generate_fptr_fallback(jl_method_instance_t *mi JL_PROPAGATES_ROOT, size_t world, int *did_compile)
{
return NULL;
}
Expand Down
5 changes: 3 additions & 2 deletions src/gf.c
Original file line number Diff line number Diff line change
Expand Up @@ -2477,7 +2477,8 @@ jl_code_instance_t *jl_compile_method_internal(jl_method_instance_t *mi, size_t
}
}

codeinst = jl_generate_fptr(mi, world);
int did_compile = 0;
codeinst = jl_generate_fptr(mi, world, &did_compile);
if (!codeinst) {
jl_method_instance_t *unspec = jl_get_unspecialized_from_mi(mi);
jl_code_instance_t *ucache = jl_get_method_inferred(unspec, (jl_value_t*)jl_any_type, 1, ~(size_t)0);
Expand Down Expand Up @@ -2517,7 +2518,7 @@ jl_code_instance_t *jl_compile_method_internal(jl_method_instance_t *mi, size_t
jl_atomic_store_release(&codeinst->invoke, ucache_invoke);
jl_mi_cache_insert(mi, codeinst);
}
else {
else if (did_compile) {
record_precompile_statement(mi);
}
jl_atomic_store_relaxed(&codeinst->precompile, 1);
Expand Down
8 changes: 6 additions & 2 deletions src/jitlayers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,10 @@ void jl_extern_c_impl(jl_value_t *declrt, jl_tupletype_t *sigt)

// this compiles li and emits fptr
extern "C" JL_DLLEXPORT_CODEGEN
jl_code_instance_t *jl_generate_fptr_impl(jl_method_instance_t *mi JL_PROPAGATES_ROOT, size_t world)
jl_code_instance_t *jl_generate_fptr_impl(jl_method_instance_t *mi JL_PROPAGATES_ROOT, size_t world, int *did_compile)
{
if (did_compile != NULL)
*did_compile = 0;
auto ct = jl_current_task;
bool timed = (ct->reentrant_timing & 1) == 0;
if (timed)
Expand Down Expand Up @@ -518,6 +520,8 @@ jl_code_instance_t *jl_generate_fptr_impl(jl_method_instance_t *mi JL_PROPAGATES
_jl_compile_codeinst(codeinst, src, world, *jl_ExecutionEngine->getContext(), is_recompile);
if (jl_atomic_load_relaxed(&codeinst->invoke) == NULL)
codeinst = NULL;
else if (did_compile != NULL)
*did_compile = 1;
}
else {
codeinst = NULL;
Expand Down Expand Up @@ -605,7 +609,7 @@ jl_value_t *jl_dump_method_asm_impl(jl_method_instance_t *mi, size_t world,
char emit_mc, char getwrapper, const char* asm_variant, const char *debuginfo, char binary)
{
// printing via disassembly
jl_code_instance_t *codeinst = jl_generate_fptr(mi, world);
jl_code_instance_t *codeinst = jl_generate_fptr(mi, world, NULL);
if (codeinst) {
uintptr_t fptr = (uintptr_t)jl_atomic_load_acquire(&codeinst->invoke);
if (getwrapper)
Expand Down
2 changes: 1 addition & 1 deletion src/julia_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -1661,7 +1661,7 @@ JL_DLLEXPORT uint32_t jl_crc32c(uint32_t crc, const char *buf, size_t len);

// -- exports from codegen -- //

JL_DLLIMPORT jl_code_instance_t *jl_generate_fptr(jl_method_instance_t *mi JL_PROPAGATES_ROOT, size_t world);
JL_DLLIMPORT jl_code_instance_t *jl_generate_fptr(jl_method_instance_t *mi JL_PROPAGATES_ROOT, size_t world, int *did_compile);
JL_DLLIMPORT void jl_generate_fptr_for_unspecialized(jl_code_instance_t *unspec);
JL_DLLIMPORT void jl_generate_fptr_for_oc_wrapper(jl_code_instance_t *unspec);
JL_DLLIMPORT int jl_compile_extern_c(LLVMOrcThreadSafeModuleRef llvmmod, void *params, void *sysimg, jl_value_t *declrt, jl_value_t *sigt);
Expand Down

0 comments on commit f6a3c5f

Please sign in to comment.