Skip to content

Commit

Permalink
Make safepoint emission on function entry a codegen feature
Browse files Browse the repository at this point in the history
  • Loading branch information
vchuravy committed Jul 23, 2021
1 parent 472f7f5 commit 6f06a98
Show file tree
Hide file tree
Showing 4 changed files with 15 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 @@ -1063,6 +1063,7 @@ struct CodegenParams
prefer_specsig::Cint
gnu_pubnames::Cint
debug_info_kind::Cint
safepoint_on_entry::Cint

lookup::Ptr{Cvoid}

Expand All @@ -1071,12 +1072,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
5 changes: 3 additions & 2 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ extern "C" {
#else
1,
#endif
jl_default_debug_info_kind,
jl_default_debug_info_kind, 1,
jl_rettype_inferred, NULL };
}

Expand Down Expand Up @@ -6893,7 +6893,8 @@ static std::pair<std::unique_ptr<Module>, jl_llvm_functions_t>
Instruction &prologue_end = ctx.builder.GetInsertBlock()->back();

// step 11a. Emit the entry safepoint
emit_safepoint(ctx);
if (JL_FEAT_TEST(ctx, safepoint_on_entry))
emit_safepoint(ctx);

// step 11b. Do codegen in control flow order
std::vector<int> workstack;
Expand Down
4 changes: 3 additions & 1 deletion src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -2167,9 +2167,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 @@ -9,9 +9,12 @@ const opt_level = Base.JLOptions().opt_level
const coverage = (Base.JLOptions().code_coverage > 0) || (Base.JLOptions().malloc_log > 0)
const Iptr = sizeof(Int) == 8 ? "i64" : "i32"

# `_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 opt_level > 0
# Make sure getptls call is removed at IR level with optimization on
Expand Down

0 comments on commit 6f06a98

Please sign in to comment.