From 44899bf7a947c0a291be7c8139e4a4637e1a3598 Mon Sep 17 00:00:00 2001 From: gbaraldi Date: Tue, 18 Mar 2025 17:41:35 -0300 Subject: [PATCH 1/2] Add option to force emission of const return function --- base/reflection.jl | 10 ++++------ src/aotcompile.cpp | 2 +- src/julia.h | 1 + 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/base/reflection.jl b/base/reflection.jl index 50b4413f01b59..2574fd16af29e 100644 --- a/base/reflection.jl +++ b/base/reflection.jl @@ -149,23 +149,21 @@ struct CodegenParams use_jlplt::Cint """ - If enabled, only provably reachable code (from functions marked with `entrypoint`) is included - in the output system image. Errors or warnings can be given for call sites too dynamic to handle. - The option is disabled by default. (0=>disabled, 1=>safe (static errors), 2=>unsafe, 3=>unsafe plus warnings) + If enabled emit LLVM IR even for functions with constant return values. """ - trim::Cint + force_emit_const::Cint function CodegenParams(; track_allocations::Bool=true, code_coverage::Bool=true, prefer_specsig::Bool=false, gnu_pubnames::Bool=true, debug_info_kind::Cint = default_debug_info_kind(), debug_info_level::Cint = Cint(JLOptions().debug_level), safepoint_on_entry::Bool=true, - gcstack_arg::Bool=true, use_jlplt::Bool=true, trim::Cint=Cint(0)) + gcstack_arg::Bool=true, use_jlplt::Bool=true, force_emit_const::Bool=false) return new( Cint(track_allocations), Cint(code_coverage), Cint(prefer_specsig), Cint(gnu_pubnames), debug_info_kind, debug_info_level, Cint(safepoint_on_entry), - Cint(gcstack_arg), Cint(use_jlplt), Cint(trim)) + Cint(gcstack_arg), Cint(use_jlplt), Cint(force_emit_const)) end end diff --git a/src/aotcompile.cpp b/src/aotcompile.cpp index 30cf1d8b60420..903099070b017 100644 --- a/src/aotcompile.cpp +++ b/src/aotcompile.cpp @@ -775,7 +775,7 @@ void *jl_emit_native_impl(jl_array_t *codeinfos, LLVMOrcThreadSafeModuleRef llvm params.tsctx, clone.getModuleUnlocked()->getDataLayout(), Triple(clone.getModuleUnlocked()->getTargetTriple())); jl_llvm_functions_t decls; - if (jl_atomic_load_relaxed(&codeinst->invoke) == jl_fptr_const_return_addr) + if (!(params.params->force_emit_const) && jl_atomic_load_relaxed(&codeinst->invoke) == jl_fptr_const_return_addr) decls.functionObject = "jl_fptr_const_return"; else decls = jl_emit_codeinst(result_m, codeinst, src, params); diff --git a/src/julia.h b/src/julia.h index 5255eba13d681..1d0a93dd55fa1 100644 --- a/src/julia.h +++ b/src/julia.h @@ -2723,6 +2723,7 @@ typedef struct { int gcstack_arg; // Pass the ptls value as an argument with swiftself int use_jlplt; // Whether to use the Julia PLT mechanism or emit symbols directly + int force_emit_const; // Force emission of code for const return functions } jl_cgparams_t; extern JL_DLLEXPORT int jl_default_debug_info_kind; extern JL_DLLEXPORT jl_cgparams_t jl_default_cgparams; From 69f47e7943009d00fd5e3acc3ff7e5e68871b143 Mon Sep 17 00:00:00 2001 From: gbaraldi Date: Wed, 19 Mar 2025 15:08:48 -0300 Subject: [PATCH 2/2] Change name to force_emit_all --- base/reflection.jl | 9 +++++---- src/aotcompile.cpp | 2 +- src/cgutils.cpp | 3 ++- src/init.c | 3 ++- src/julia.h | 2 +- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/base/reflection.jl b/base/reflection.jl index 2574fd16af29e..528202a9196ba 100644 --- a/base/reflection.jl +++ b/base/reflection.jl @@ -149,21 +149,22 @@ struct CodegenParams use_jlplt::Cint """ - If enabled emit LLVM IR even for functions with constant return values. + If enabled emit LLVM IR for all functions even if wouldn't be compiled + for some reason (i.e functions that return a constant value). """ - force_emit_const::Cint + force_emit_all::Cint function CodegenParams(; track_allocations::Bool=true, code_coverage::Bool=true, prefer_specsig::Bool=false, gnu_pubnames::Bool=true, debug_info_kind::Cint = default_debug_info_kind(), debug_info_level::Cint = Cint(JLOptions().debug_level), safepoint_on_entry::Bool=true, - gcstack_arg::Bool=true, use_jlplt::Bool=true, force_emit_const::Bool=false) + gcstack_arg::Bool=true, use_jlplt::Bool=true, force_emit_all::Bool=false) return new( Cint(track_allocations), Cint(code_coverage), Cint(prefer_specsig), Cint(gnu_pubnames), debug_info_kind, debug_info_level, Cint(safepoint_on_entry), - Cint(gcstack_arg), Cint(use_jlplt), Cint(force_emit_const)) + Cint(gcstack_arg), Cint(use_jlplt), Cint(force_emit_all)) end end diff --git a/src/aotcompile.cpp b/src/aotcompile.cpp index 903099070b017..7cc645c1d79ad 100644 --- a/src/aotcompile.cpp +++ b/src/aotcompile.cpp @@ -775,7 +775,7 @@ void *jl_emit_native_impl(jl_array_t *codeinfos, LLVMOrcThreadSafeModuleRef llvm params.tsctx, clone.getModuleUnlocked()->getDataLayout(), Triple(clone.getModuleUnlocked()->getTargetTriple())); jl_llvm_functions_t decls; - if (!(params.params->force_emit_const) && jl_atomic_load_relaxed(&codeinst->invoke) == jl_fptr_const_return_addr) + if (!(params.params->force_emit_all) && jl_atomic_load_relaxed(&codeinst->invoke) == jl_fptr_const_return_addr) decls.functionObject = "jl_fptr_const_return"; else decls = jl_emit_codeinst(result_m, codeinst, src, params); diff --git a/src/cgutils.cpp b/src/cgutils.cpp index fb4c9aa8cb415..742f3d0d18408 100644 --- a/src/cgutils.cpp +++ b/src/cgutils.cpp @@ -4423,7 +4423,8 @@ static int compare_cgparams(const jl_cgparams_t *a, const jl_cgparams_t *b) (a->debug_info_kind == b->debug_info_kind) && (a->safepoint_on_entry == b->safepoint_on_entry) && (a->gcstack_arg == b->gcstack_arg) && - (a->use_jlplt == b->use_jlplt); + (a->use_jlplt == b->use_jlplt) && + (a->force_emit_all == b->force_emit_all); } #endif diff --git a/src/init.c b/src/init.c index 80f4b59acdc01..6d5212cf8d370 100644 --- a/src/init.c +++ b/src/init.c @@ -740,7 +740,8 @@ JL_DLLEXPORT jl_cgparams_t jl_default_cgparams = { /* debug_info_level */ 0, // later jl_options.debug_level, /* safepoint_on_entry */ 1, /* gcstack_arg */ 1, - /* use_jlplt*/ 1 }; + /* use_jlplt*/ 1 , + /*force_emit_all=*/ 0}; static void init_global_mutexes(void) { JL_MUTEX_INIT(&jl_modules_mutex, "jl_modules_mutex"); diff --git a/src/julia.h b/src/julia.h index 1d0a93dd55fa1..02c6c11917c1e 100644 --- a/src/julia.h +++ b/src/julia.h @@ -2723,7 +2723,7 @@ typedef struct { int gcstack_arg; // Pass the ptls value as an argument with swiftself int use_jlplt; // Whether to use the Julia PLT mechanism or emit symbols directly - int force_emit_const; // Force emission of code for const return functions + int force_emit_all; // Force emission of code for const return functions } jl_cgparams_t; extern JL_DLLEXPORT int jl_default_debug_info_kind; extern JL_DLLEXPORT jl_cgparams_t jl_default_cgparams;