Skip to content

Commit

Permalink
Emit safepoints at function entry (#41616)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
vchuravy authored Oct 25, 2022
1 parent a1ecc80 commit 1a7a131
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
3 changes: 3 additions & 0 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,7 @@ struct CodegenParams
prefer_specsig::Cint
gnu_pubnames::Cint
debug_info_kind::Cint
safepoint_on_entry::Cint

lookup::Ptr{Cvoid}

Expand All @@ -1105,12 +1106,14 @@ struct CodegenParams
function CodegenParams(; track_allocations::Bool=true, code_coverage::Bool=true,
prefer_specsig::Bool=false,
gnu_pubnames=true, debug_info_kind::Cint = default_debug_info_kind(),
safepoint_on_entry::Bool=true,
lookup::Ptr{Cvoid}=cglobal(:jl_rettype_inferred),
generic_context = nothing)
return new(
Cint(track_allocations), Cint(code_coverage),
Cint(prefer_specsig),
Cint(gnu_pubnames), debug_info_kind,
Cint(safepoint_on_entry),
lookup, generic_context)
end
end
Expand Down
1 change: 0 additions & 1 deletion src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3890,7 +3890,6 @@ static Value *emit_defer_signal(jl_codectx_t &ctx)
return ctx.builder.CreateInBoundsGEP(ctx.types().T_sigatomic, ptls, ArrayRef<Value*>(offset), "jl_defer_signal");
}


#ifndef JL_NDEBUG
static int compare_cgparams(const jl_cgparams_t *a, const jl_cgparams_t *b)
{
Expand Down
6 changes: 5 additions & 1 deletion src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,7 @@ extern "C" {
1,
#endif
(int) DICompileUnit::DebugEmissionKind::FullDebug,
1,
jl_rettype_inferred, NULL };
}

Expand Down Expand Up @@ -7456,8 +7457,11 @@ static jl_llvm_functions_t

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

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

// step 11. Do codegen in control flow order
// step 11b. Do codegen in control flow order
std::vector<int> workstack;
std::map<int, BasicBlock*> BB;
std::map<size_t, BasicBlock*> come_from_bb;
Expand Down
4 changes: 3 additions & 1 deletion src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -2221,9 +2221,11 @@ typedef struct {

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

int safepoint_on_entry; // Emit a safepoint on entry to each function

// Cache access. Default: jl_rettype_inferred.
jl_codeinstance_lookup_t lookup;

Expand Down
9 changes: 6 additions & 3 deletions test/compiler/codegen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ function libjulia_codegen_name()
is_debug_build ? "libjulia-codegen-debug" : "libjulia-codegen"
end

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

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

2 comments on commit 1a7a131

@vtjnash
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nanosoldier runbenchmarks(ALL, vs="@a1ecc8081980b15867c1ce8e8270c21c11b6118f")

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here.

Please sign in to comment.