Skip to content

Commit 3761029

Browse files
gbaraldiKristofferC
authored andcommitted
Add option to force emission of const return function (#57824)
This is mostly for GPUCompiler (cherry picked from commit e78cf6c)
1 parent bf76bab commit 3761029

File tree

5 files changed

+11
-9
lines changed

5 files changed

+11
-9
lines changed

base/reflection.jl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,23 +149,22 @@ struct CodegenParams
149149
use_jlplt::Cint
150150

151151
"""
152-
If enabled, only provably reachable code (from functions marked with `entrypoint`) is included
153-
in the output system image. Errors or warnings can be given for call sites too dynamic to handle.
154-
The option is disabled by default. (0=>disabled, 1=>safe (static errors), 2=>unsafe, 3=>unsafe plus warnings)
152+
If enabled emit LLVM IR for all functions even if wouldn't be compiled
153+
for some reason (i.e functions that return a constant value).
155154
"""
156-
trim::Cint
155+
force_emit_all::Cint
157156

158157
function CodegenParams(; track_allocations::Bool=true, code_coverage::Bool=true,
159158
prefer_specsig::Bool=false,
160159
gnu_pubnames::Bool=true, debug_info_kind::Cint = default_debug_info_kind(),
161160
debug_info_level::Cint = Cint(JLOptions().debug_level), safepoint_on_entry::Bool=true,
162-
gcstack_arg::Bool=true, use_jlplt::Bool=true, trim::Cint=Cint(0))
161+
gcstack_arg::Bool=true, use_jlplt::Bool=true, force_emit_all::Bool=false)
163162
return new(
164163
Cint(track_allocations), Cint(code_coverage),
165164
Cint(prefer_specsig),
166165
Cint(gnu_pubnames), debug_info_kind,
167166
debug_info_level, Cint(safepoint_on_entry),
168-
Cint(gcstack_arg), Cint(use_jlplt), Cint(trim))
167+
Cint(gcstack_arg), Cint(use_jlplt), Cint(force_emit_all))
169168
end
170169
end
171170

src/aotcompile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ void *jl_emit_native_impl(jl_array_t *codeinfos, LLVMOrcThreadSafeModuleRef llvm
775775
params.tsctx, clone.getModuleUnlocked()->getDataLayout(),
776776
Triple(clone.getModuleUnlocked()->getTargetTriple()));
777777
jl_llvm_functions_t decls;
778-
if (jl_atomic_load_relaxed(&codeinst->invoke) == jl_fptr_const_return_addr)
778+
if (!(params.params->force_emit_all) && jl_atomic_load_relaxed(&codeinst->invoke) == jl_fptr_const_return_addr)
779779
decls.functionObject = "jl_fptr_const_return";
780780
else
781781
decls = jl_emit_codeinst(result_m, codeinst, src, params);

src/cgutils.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4410,7 +4410,8 @@ static int compare_cgparams(const jl_cgparams_t *a, const jl_cgparams_t *b)
44104410
(a->debug_info_kind == b->debug_info_kind) &&
44114411
(a->safepoint_on_entry == b->safepoint_on_entry) &&
44124412
(a->gcstack_arg == b->gcstack_arg) &&
4413-
(a->use_jlplt == b->use_jlplt);
4413+
(a->use_jlplt == b->use_jlplt) &&
4414+
(a->force_emit_all == b->force_emit_all);
44144415
}
44154416
#endif
44164417

src/init.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,8 @@ JL_DLLEXPORT jl_cgparams_t jl_default_cgparams = {
739739
/* debug_info_level */ 0, // later jl_options.debug_level,
740740
/* safepoint_on_entry */ 1,
741741
/* gcstack_arg */ 1,
742-
/* use_jlplt*/ 1 };
742+
/* use_jlplt*/ 1 ,
743+
/*force_emit_all=*/ 0};
743744

744745
static void init_global_mutexes(void) {
745746
JL_MUTEX_INIT(&jl_modules_mutex, "jl_modules_mutex");

src/julia.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2727,6 +2727,7 @@ typedef struct {
27272727
int gcstack_arg; // Pass the ptls value as an argument with swiftself
27282728

27292729
int use_jlplt; // Whether to use the Julia PLT mechanism or emit symbols directly
2730+
int force_emit_all; // Force emission of code for const return functions
27302731
} jl_cgparams_t;
27312732
extern JL_DLLEXPORT int jl_default_debug_info_kind;
27322733
extern JL_DLLEXPORT jl_cgparams_t jl_default_cgparams;

0 commit comments

Comments
 (0)