Skip to content

Commit e52eff7

Browse files
vchuravykpamnany
authored andcommitted
Emit safepoints at function entry (JuliaLang#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 053070e commit e52eff7

File tree

5 files changed

+18
-6
lines changed

5 files changed

+18
-6
lines changed

base/reflection.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,7 @@ struct CodegenParams
10921092
prefer_specsig::Cint
10931093
gnu_pubnames::Cint
10941094
debug_info_kind::Cint
1095+
safepoint_on_entry::Cint
10951096

10961097
lookup::Ptr{Cvoid}
10971098

@@ -1100,12 +1101,14 @@ struct CodegenParams
11001101
function CodegenParams(; track_allocations::Bool=true, code_coverage::Bool=true,
11011102
prefer_specsig::Bool=false,
11021103
gnu_pubnames=true, debug_info_kind::Cint = default_debug_info_kind(),
1104+
safepoint_on_entry::Bool=true,
11031105
lookup::Ptr{Cvoid}=cglobal(:jl_rettype_inferred),
11041106
generic_context = nothing)
11051107
return new(
11061108
Cint(track_allocations), Cint(code_coverage),
11071109
Cint(prefer_specsig),
11081110
Cint(gnu_pubnames), debug_info_kind,
1111+
Cint(safepoint_on_entry),
11091112
lookup, generic_context)
11101113
end
11111114
end

src/cgutils.cpp

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

3936-
39373936
#ifndef JL_NDEBUG
39383937
static int compare_cgparams(const jl_cgparams_t *a, const jl_cgparams_t *b)
39393938
{

src/codegen.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1279,6 +1279,7 @@ extern "C" {
12791279
1,
12801280
#endif
12811281
(int) DICompileUnit::DebugEmissionKind::FullDebug,
1282+
1,
12821283
jl_rettype_inferred, NULL };
12831284
}
12841285

@@ -7805,7 +7806,11 @@ static jl_llvm_functions_t
78057806
ctx.builder.CreateAlignedStore(load_world, world_age_field, Align(sizeof(size_t)));
78067807
}
78077808

7808-
// step 11b. Do codegen in control flow order
7809+
// step 11b. Emit the entry safepoint
7810+
if (JL_FEAT_TEST(ctx, safepoint_on_entry))
7811+
emit_gc_safepoint(ctx.builder, get_current_ptls(ctx), ctx.tbaa().tbaa_const);
7812+
7813+
// step 11c. Do codegen in control flow order
78097814
std::vector<int> workstack;
78107815
std::map<int, BasicBlock*> BB;
78117816
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
@@ -2247,9 +2247,11 @@ typedef struct {
22472247

22482248
// controls the emission of debug-info. mirrors the clang options
22492249
int gnu_pubnames; // can we emit the gnu pubnames debuginfo
2250-
int debug_info_kind; // Enum for line-table-only, line-directives-only,
2250+
int debug_info_kind; // Enum for line-table-only, line-directives-only,
22512251
// limited, standalone
22522252

2253+
int safepoint_on_entry; // Emit a safepoint on entry to each function
2254+
22532255
// Cache access. Default: jl_rettype_inferred.
22542256
jl_codeinstance_lookup_t lookup;
22552257

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)