Skip to content

Commit

Permalink
Remove some duplicates from emitted compilation traces (#53774)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kpamnany authored Mar 19, 2024
1 parent 9df47f2 commit 5c891de
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/codegen-stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ JL_DLLEXPORT void jl_generate_fptr_for_unspecialized_fallback(jl_code_instance_t
jl_atomic_store_release(&unspec->invoke, &jl_fptr_interpret_call);
}

JL_DLLEXPORT void jl_compile_codeinst_fallback(jl_code_instance_t *unspec)
JL_DLLEXPORT int jl_compile_codeinst_fallback(jl_code_instance_t *unspec)
{
// Do nothing. The caller will notice that we failed to provide a an ->invoke and trigger
// appropriate fallbacks.
return 0;
}

JL_DLLEXPORT uint32_t jl_get_LLVM_VERSION_fallback(void)
Expand Down
4 changes: 2 additions & 2 deletions src/gf.c
Original file line number Diff line number Diff line change
Expand Up @@ -2568,12 +2568,12 @@ jl_code_instance_t *jl_compile_method_internal(jl_method_instance_t *mi, size_t
}

JL_GC_PUSH1(&codeinst);
jl_compile_codeinst(codeinst);
int did_compile = jl_compile_codeinst(codeinst);

if (jl_atomic_load_relaxed(&codeinst->invoke) == NULL) {
// Something went wrong. Bail to the fallback path.
codeinst = NULL;
} else {
} else if (did_compile) {
record_precompile_statement(mi);
}
JL_GC_POP();
Expand Down
7 changes: 5 additions & 2 deletions src/jitlayers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,19 +461,22 @@ void jl_extern_c_impl(jl_value_t *declrt, jl_tupletype_t *sigt)
}

extern "C" JL_DLLEXPORT_CODEGEN
void jl_compile_codeinst_impl(jl_code_instance_t *ci)
int jl_compile_codeinst_impl(jl_code_instance_t *ci)
{
int newly_compiled = 0;
if (jl_atomic_load_relaxed(&ci->invoke) != NULL) {
return;
return newly_compiled;
}
JL_LOCK(&jl_codegen_lock);
if (jl_atomic_load_relaxed(&ci->invoke) == NULL) {
++SpecFPtrCount;
uint64_t start = jl_typeinf_timing_begin();
_jl_compile_codeinst(ci, NULL, *jl_ExecutionEngine->getContext());
jl_typeinf_timing_end(start, 0);
newly_compiled = 1;
}
JL_UNLOCK(&jl_codegen_lock); // Might GC
return newly_compiled;
}

extern "C" JL_DLLEXPORT_CODEGEN
Expand Down
2 changes: 1 addition & 1 deletion src/julia_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -1727,7 +1727,7 @@ JL_DLLEXPORT uint32_t jl_crc32c(uint32_t crc, const char *buf, size_t len);
#define IR_FLAG_INBOUNDS 0x01

JL_DLLIMPORT void jl_generate_fptr_for_unspecialized(jl_code_instance_t *unspec);
JL_DLLIMPORT void jl_compile_codeinst(jl_code_instance_t *unspec);
JL_DLLIMPORT int jl_compile_codeinst(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);

typedef struct {
Expand Down

0 comments on commit 5c891de

Please sign in to comment.