Skip to content

Commit 7bcd808

Browse files
committed
Remove some duplicates from emitted compilation traces
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.
1 parent a9611ce commit 7bcd808

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

src/codegen-stubs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ JL_DLLEXPORT void jl_generate_fptr_for_unspecialized_fallback(jl_code_instance_t
4343
jl_atomic_store_release(&unspec->invoke, &jl_fptr_interpret_call);
4444
}
4545

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

5253
JL_DLLEXPORT uint32_t jl_get_LLVM_VERSION_fallback(void)

src/gf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2568,12 +2568,12 @@ jl_code_instance_t *jl_compile_method_internal(jl_method_instance_t *mi, size_t
25682568
}
25692569

25702570
JL_GC_PUSH1(&codeinst);
2571-
jl_compile_codeinst(codeinst);
2571+
int did_compile = jl_compile_codeinst(codeinst);
25722572

25732573
if (jl_atomic_load_relaxed(&codeinst->invoke) == NULL) {
25742574
// Something went wrong. Bail to the fallback path.
25752575
codeinst = NULL;
2576-
} else {
2576+
} else if (did_compile) {
25772577
record_precompile_statement(mi);
25782578
}
25792579
JL_GC_POP();

src/jitlayers.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,19 +461,22 @@ void jl_extern_c_impl(jl_value_t *declrt, jl_tupletype_t *sigt)
461461
}
462462

463463
extern "C" JL_DLLEXPORT_CODEGEN
464-
void jl_compile_codeinst_impl(jl_code_instance_t *ci)
464+
int jl_compile_codeinst_impl(jl_code_instance_t *ci)
465465
{
466+
int r = 0;
466467
if (jl_atomic_load_relaxed(&ci->invoke) != NULL) {
467-
return;
468+
return r;
468469
}
469470
JL_LOCK(&jl_codegen_lock);
470471
if (jl_atomic_load_relaxed(&ci->invoke) == NULL) {
471472
++SpecFPtrCount;
472473
uint64_t start = jl_typeinf_timing_begin();
473474
_jl_compile_codeinst(ci, NULL, *jl_ExecutionEngine->getContext());
474475
jl_typeinf_timing_end(start, 0);
476+
r = 1;
475477
}
476478
JL_UNLOCK(&jl_codegen_lock); // Might GC
479+
return r;
477480
}
478481

479482
extern "C" JL_DLLEXPORT_CODEGEN

src/julia_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1727,7 +1727,7 @@ JL_DLLEXPORT uint32_t jl_crc32c(uint32_t crc, const char *buf, size_t len);
17271727
#define IR_FLAG_INBOUNDS 0x01
17281728

17291729
JL_DLLIMPORT void jl_generate_fptr_for_unspecialized(jl_code_instance_t *unspec);
1730-
JL_DLLIMPORT void jl_compile_codeinst(jl_code_instance_t *unspec);
1730+
JL_DLLIMPORT int jl_compile_codeinst(jl_code_instance_t *unspec);
17311731
JL_DLLIMPORT int jl_compile_extern_c(LLVMOrcThreadSafeModuleRef llvmmod, void *params, void *sysimg, jl_value_t *declrt, jl_value_t *sigt);
17321732

17331733
typedef struct {

0 commit comments

Comments
 (0)