Skip to content

Commit 472f7f5

Browse files
committed
Emit safepoints at function entry
1 parent 20e260a commit 472f7f5

3 files changed

Lines changed: 12 additions & 5 deletions

File tree

src/ccall.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,10 +1457,7 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
14571457
assert(lrt == T_void);
14581458
assert(!isVa && !llvmcall && nccallargs == 0);
14591459
JL_GC_POP();
1460-
ctx.builder.CreateCall(prepare_call(gcroot_flush_func));
1461-
emit_signal_fence(ctx);
1462-
ctx.builder.CreateLoad(T_size, get_current_signal_page(ctx), true);
1463-
emit_signal_fence(ctx);
1460+
emit_safepoint(ctx);
14641461
return ghostValue(jl_nothing_type);
14651462
}
14661463
else if (is_libjulia_func("jl_get_ptls_states")) {

src/cgutils.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3448,6 +3448,14 @@ static Value *emit_defer_signal(jl_codectx_t &ctx)
34483448
return ctx.builder.CreateInBoundsGEP(T_sigatomic, ptls, ArrayRef<Value*>(offset), "jl_defer_signal");
34493449
}
34503450

3451+
static void emit_safepoint(jl_codectx_t &ctx)
3452+
{
3453+
ctx.builder.CreateCall(prepare_call(gcroot_flush_func));
3454+
emit_signal_fence(ctx);
3455+
ctx.builder.CreateLoad(T_size, get_current_signal_page(ctx), true);
3456+
emit_signal_fence(ctx);
3457+
}
3458+
34513459
#ifndef NDEBUG
34523460
static int compare_cgparams(const jl_cgparams_t *a, const jl_cgparams_t *b)
34533461
{

src/codegen.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6892,8 +6892,10 @@ static std::pair<std::unique_ptr<Module>, jl_llvm_functions_t>
68926892

68936893
Instruction &prologue_end = ctx.builder.GetInsertBlock()->back();
68946894

6895+
// step 11a. Emit the entry safepoint
6896+
emit_safepoint(ctx);
68956897

6896-
// step 11. Do codegen in control flow order
6898+
// step 11b. Do codegen in control flow order
68976899
std::vector<int> workstack;
68986900
std::map<int, BasicBlock*> BB;
68996901
std::map<size_t, BasicBlock*> come_from_bb;

0 commit comments

Comments
 (0)