Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to force emission of const return function #57824

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/aotcompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down