Skip to content

Commit 1a7a131

Browse files
authored
Emit safepoints at function entry (#41616)
* Emit safepoints at function entry * Make safepoint emission on function entry a codegen feature * Hoist signal page lookup outside fence * Update src/cgutils.cpp * Fix rebase
1 parent a1ecc80 commit 1a7a131

File tree

5 files changed

+17
-6
lines changed

5 files changed

+17
-6
lines changed

base/reflection.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,6 +1097,7 @@ struct CodegenParams
10971097
prefer_specsig::Cint
10981098
gnu_pubnames::Cint
10991099
debug_info_kind::Cint
1100+
safepoint_on_entry::Cint
11001101

11011102
lookup::Ptr{Cvoid}
11021103

@@ -1105,12 +1106,14 @@ struct CodegenParams
11051106
function CodegenParams(; track_allocations::Bool=true, code_coverage::Bool=true,
11061107
prefer_specsig::Bool=false,
11071108
gnu_pubnames=true, debug_info_kind::Cint = default_debug_info_kind(),
1109+
safepoint_on_entry::Bool=true,
11081110
lookup::Ptr{Cvoid}=cglobal(:jl_rettype_inferred),
11091111
generic_context = nothing)
11101112
return new(
11111113
Cint(track_allocations), Cint(code_coverage),
11121114
Cint(prefer_specsig),
11131115
Cint(gnu_pubnames), debug_info_kind,
1116+
Cint(safepoint_on_entry),
11141117
lookup, generic_context)
11151118
end
11161119
end

src/cgutils.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3890,7 +3890,6 @@ static Value *emit_defer_signal(jl_codectx_t &ctx)
38903890
return ctx.builder.CreateInBoundsGEP(ctx.types().T_sigatomic, ptls, ArrayRef<Value*>(offset), "jl_defer_signal");
38913891
}
38923892

3893-
38943893
#ifndef JL_NDEBUG
38953894
static int compare_cgparams(const jl_cgparams_t *a, const jl_cgparams_t *b)
38963895
{

src/codegen.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1209,6 +1209,7 @@ extern "C" {
12091209
1,
12101210
#endif
12111211
(int) DICompileUnit::DebugEmissionKind::FullDebug,
1212+
1,
12121213
jl_rettype_inferred, NULL };
12131214
}
12141215

@@ -7456,8 +7457,11 @@ static jl_llvm_functions_t
74567457

74577458
Instruction &prologue_end = ctx.builder.GetInsertBlock()->back();
74587459

7460+
// step 11a. Emit the entry safepoint
7461+
if (JL_FEAT_TEST(ctx, safepoint_on_entry))
7462+
emit_gc_safepoint(ctx.builder, get_current_ptls(ctx), ctx.tbaa().tbaa_const);
74597463

7460-
// step 11. Do codegen in control flow order
7464+
// step 11b. Do codegen in control flow order
74617465
std::vector<int> workstack;
74627466
std::map<int, BasicBlock*> BB;
74637467
std::map<size_t, BasicBlock*> come_from_bb;

src/julia.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2221,9 +2221,11 @@ typedef struct {
22212221

22222222
// controls the emission of debug-info. mirrors the clang options
22232223
int gnu_pubnames; // can we emit the gnu pubnames debuginfo
2224-
int debug_info_kind; // Enum for line-table-only, line-directives-only,
2224+
int debug_info_kind; // Enum for line-table-only, line-directives-only,
22252225
// limited, standalone
22262226

2227+
int safepoint_on_entry; // Emit a safepoint on entry to each function
2228+
22272229
// Cache access. Default: jl_rettype_inferred.
22282230
jl_codeinstance_lookup_t lookup;
22292231

test/compiler/codegen.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ function libjulia_codegen_name()
1515
is_debug_build ? "libjulia-codegen-debug" : "libjulia-codegen"
1616
end
1717

18-
# `_dump_function` might be more efficient but it doesn't really matter here...
19-
get_llvm(@nospecialize(f), @nospecialize(t), raw=true, dump_module=false, optimize=true) =
20-
sprint(code_llvm, f, t, raw, dump_module, optimize)
18+
# The tests below assume a certain format and safepoint_on_entry=true breaks that.
19+
function get_llvm(@nospecialize(f), @nospecialize(t), raw=true, dump_module=false, optimize=true)
20+
params = Base.CodegenParams(safepoint_on_entry=false)
21+
d = InteractiveUtils._dump_function(f, t, false, false, !raw, dump_module, :att, optimize, :none, false, params)
22+
sprint(print, d)
23+
end
2124

2225
if !is_debug_build && opt_level > 0
2326
# Make sure getptls call is removed at IR level with optimization on

0 commit comments

Comments
 (0)