diff --git a/base/reflection.jl b/base/reflection.jl index a5aaf0ad20d4a6..1adc69291934e8 100644 --- a/base/reflection.jl +++ b/base/reflection.jl @@ -1092,6 +1092,7 @@ struct CodegenParams prefer_specsig::Cint gnu_pubnames::Cint debug_info_kind::Cint + safepoint_on_entry::Cint lookup::Ptr{Cvoid} @@ -1100,12 +1101,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 diff --git a/src/cgutils.cpp b/src/cgutils.cpp index c091111f31617f..8ce84acb309017 100644 --- a/src/cgutils.cpp +++ b/src/cgutils.cpp @@ -3933,7 +3933,6 @@ static Value *emit_defer_signal(jl_codectx_t &ctx) return ctx.builder.CreateInBoundsGEP(ctx.types().T_sigatomic, ptls, ArrayRef(offset), "jl_defer_signal"); } - #ifndef JL_NDEBUG static int compare_cgparams(const jl_cgparams_t *a, const jl_cgparams_t *b) { diff --git a/src/codegen.cpp b/src/codegen.cpp index 6bd0b0d16865a7..a4773acb3fbeae 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -1279,6 +1279,7 @@ extern "C" { 1, #endif (int) DICompileUnit::DebugEmissionKind::FullDebug, + 1, jl_rettype_inferred, NULL }; } @@ -7805,7 +7806,11 @@ static jl_llvm_functions_t ctx.builder.CreateAlignedStore(load_world, world_age_field, Align(sizeof(size_t))); } - // step 11b. Do codegen in control flow order + // step 11b. 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 11c. Do codegen in control flow order std::vector workstack; std::map BB; std::map come_from_bb; diff --git a/src/julia.h b/src/julia.h index bb747a77a518d7..a34c1f06d0cc14 100644 --- a/src/julia.h +++ b/src/julia.h @@ -2247,9 +2247,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; diff --git a/test/compiler/codegen.jl b/test/compiler/codegen.jl index e4e107351c57f0..4c9c7e97a710b1 100644 --- a/test/compiler/codegen.jl +++ b/test/compiler/codegen.jl @@ -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