Skip to content

Commit 1c47b73

Browse files
committed
Fix up some git status
1 parent 7232ab1 commit 1c47b73

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

src/jitlayers.cpp

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,6 @@ const char *jl_generate_ccallable(LLVMOrcThreadSafeModuleRef llvmmod, void *sysi
295295
extern "C" JL_DLLEXPORT
296296
int jl_compile_extern_c_impl(LLVMOrcThreadSafeModuleRef llvmmod, void *p, void *sysimg, jl_value_t *declrt, jl_value_t *sigt)
297297
{
298-
JL_LOCK(&jl_codegen_lock);
299298
auto ct = jl_current_task;
300299
ct->reentrant_codegen++;
301300
uint64_t compiler_start_time = 0;
@@ -313,6 +312,7 @@ int jl_compile_extern_c_impl(LLVMOrcThreadSafeModuleRef llvmmod, void *p, void *
313312
backing = jl_create_llvm_module("cextern", pparams ? pparams->tsctx : ctx, pparams ? pparams->imaging : imaging_default());
314313
into = &backing;
315314
}
315+
JL_LOCK(&jl_codegen_lock);
316316
jl_codegen_params_t params(into->getContext());
317317
if (pparams == NULL)
318318
pparams = &params;
@@ -332,13 +332,12 @@ int jl_compile_extern_c_impl(LLVMOrcThreadSafeModuleRef llvmmod, void *p, void *
332332
if (success && llvmmod == NULL)
333333
jl_ExecutionEngine->addModule(std::move(*into));
334334
}
335-
if (ct->reentrant_codegen == 1 && measure_compile_time_enabled)
335+
JL_UNLOCK(&jl_codegen_lock);
336+
if (!--ct->reentrant_codegen && measure_compile_time_enabled)
336337
jl_atomic_fetch_add_relaxed(&jl_cumulative_compile_time, (jl_hrtime() - compiler_start_time));
337338
if (ctx.getContext()) {
338339
jl_ExecutionEngine->releaseContext(std::move(ctx));
339340
}
340-
ct->reentrant_codegen--;
341-
JL_UNLOCK(&jl_codegen_lock);
342341
return success;
343342
}
344343

@@ -389,7 +388,6 @@ void jl_extern_c_impl(jl_value_t *declrt, jl_tupletype_t *sigt)
389388
extern "C" JL_DLLEXPORT
390389
jl_code_instance_t *jl_generate_fptr_impl(jl_method_instance_t *mi JL_PROPAGATES_ROOT, size_t world)
391390
{
392-
JL_LOCK(&jl_codegen_lock); // also disables finalizers, to prevent any unexpected recursion
393391
auto ct = jl_current_task;
394392
ct->reentrant_codegen++;
395393
uint64_t compiler_start_time = 0;
@@ -400,6 +398,7 @@ jl_code_instance_t *jl_generate_fptr_impl(jl_method_instance_t *mi JL_PROPAGATES
400398
// if we don't have any decls already, try to generate it now
401399
jl_code_info_t *src = NULL;
402400
JL_GC_PUSH1(&src);
401+
JL_LOCK(&jl_codegen_lock); // also disables finalizers, to prevent any unexpected recursion
403402
jl_value_t *ci = jl_rettype_inferred(mi, world, world);
404403
jl_code_instance_t *codeinst = (ci == jl_nothing ? NULL : (jl_code_instance_t*)ci);
405404
if (codeinst) {
@@ -442,14 +441,13 @@ jl_code_instance_t *jl_generate_fptr_impl(jl_method_instance_t *mi JL_PROPAGATES
442441
else {
443442
codeinst = NULL;
444443
}
445-
if (ct->reentrant_codegen == 1 && measure_compile_time_enabled) {
444+
JL_UNLOCK(&jl_codegen_lock);
445+
if (!--ct->reentrant_codegen && measure_compile_time_enabled) {
446446
uint64_t t_comp = jl_hrtime() - compiler_start_time;
447447
if (is_recompile)
448448
jl_atomic_fetch_add_relaxed(&jl_cumulative_recompile_time, t_comp);
449449
jl_atomic_fetch_add_relaxed(&jl_cumulative_compile_time, t_comp);
450450
}
451-
ct->reentrant_codegen--;
452-
JL_UNLOCK(&jl_codegen_lock);
453451
JL_GC_POP();
454452
return codeinst;
455453
}
@@ -460,13 +458,13 @@ void jl_generate_fptr_for_unspecialized_impl(jl_code_instance_t *unspec)
460458
if (jl_atomic_load_relaxed(&unspec->invoke) != NULL) {
461459
return;
462460
}
463-
JL_LOCK(&jl_codegen_lock);
464461
auto ct = jl_current_task;
465462
ct->reentrant_codegen++;
466463
uint64_t compiler_start_time = 0;
467464
uint8_t measure_compile_time_enabled = jl_atomic_load_relaxed(&jl_measure_compile_time_enabled);
468465
if (measure_compile_time_enabled)
469466
compiler_start_time = jl_hrtime();
467+
JL_LOCK(&jl_codegen_lock);
470468
if (jl_atomic_load_relaxed(&unspec->invoke) == NULL) {
471469
jl_code_info_t *src = NULL;
472470
JL_GC_PUSH1(&src);
@@ -494,10 +492,9 @@ void jl_generate_fptr_for_unspecialized_impl(jl_code_instance_t *unspec)
494492
}
495493
JL_GC_POP();
496494
}
497-
if (ct->reentrant_codegen == 1 && measure_compile_time_enabled)
498-
jl_atomic_fetch_add_relaxed(&jl_cumulative_compile_time, (jl_hrtime() - compiler_start_time));
499-
ct->reentrant_codegen--;
500495
JL_UNLOCK(&jl_codegen_lock); // Might GC
496+
if (!--ct->reentrant_codegen && measure_compile_time_enabled)
497+
jl_atomic_fetch_add_relaxed(&jl_cumulative_compile_time, (jl_hrtime() - compiler_start_time));
501498
}
502499

503500

@@ -517,13 +514,13 @@ jl_value_t *jl_dump_method_asm_impl(jl_method_instance_t *mi, size_t world,
517514
// normally we prevent native code from being generated for these functions,
518515
// (using sentinel value `1` instead)
519516
// so create an exception here so we can print pretty our lies
520-
JL_LOCK(&jl_codegen_lock); // also disables finalizers, to prevent any unexpected recursion
521517
auto ct = jl_current_task;
522-
ct->reentrant_codegen--;
518+
ct->reentrant_codegen++;
523519
uint64_t compiler_start_time = 0;
524520
uint8_t measure_compile_time_enabled = jl_atomic_load_relaxed(&jl_measure_compile_time_enabled);
525521
if (measure_compile_time_enabled)
526522
compiler_start_time = jl_hrtime();
523+
JL_LOCK(&jl_codegen_lock); // also disables finalizers, to prevent any unexpected recursion
527524
specfptr = (uintptr_t)jl_atomic_load_relaxed(&codeinst->specptr.fptr);
528525
if (specfptr == 0) {
529526
jl_code_info_t *src = jl_type_infer(mi, world, 0);
@@ -547,9 +544,8 @@ jl_value_t *jl_dump_method_asm_impl(jl_method_instance_t *mi, size_t world,
547544
}
548545
JL_GC_POP();
549546
}
550-
if (ct->reentrant_codegen == 1 && measure_compile_time_enabled)
547+
if (!--ct->reentrant_codegen && measure_compile_time_enabled)
551548
jl_atomic_fetch_add_relaxed(&jl_cumulative_compile_time, (jl_hrtime() - compiler_start_time));
552-
ct->reentrant_codegen--;
553549
JL_UNLOCK(&jl_codegen_lock);
554550
}
555551
if (specfptr != 0)

0 commit comments

Comments
 (0)