Skip to content

Commit 19f6926

Browse files
authored
[NFC] minor refactorings on gf.c & codegen.cpp (#50645)
Improvements I made during I looked at the execution chain of top-level code.
1 parent e23e116 commit 19f6926

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

src/codegen.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8896,12 +8896,12 @@ jl_llvm_functions_t jl_emit_codeinst(
88968896
}
88978897
else if (jl_is_method(def)) {// don't delete toplevel code
88988898
if (// and there is something to delete (test this before calling jl_ir_inlining_cost)
8899-
inferred != jl_nothing &&
8900-
// don't delete inlineable code, unless it is constant
8901-
(jl_atomic_load_relaxed(&codeinst->invoke) == jl_fptr_const_return_addr ||
8902-
(jl_ir_inlining_cost(inferred) == UINT16_MAX)) &&
8903-
// don't delete code when generating a precompile file
8904-
!(params.imaging || jl_options.incremental)) {
8899+
inferred != jl_nothing &&
8900+
// don't delete inlineable code, unless it is constant
8901+
(jl_atomic_load_relaxed(&codeinst->invoke) == jl_fptr_const_return_addr ||
8902+
(jl_ir_inlining_cost(inferred) == UINT16_MAX)) &&
8903+
// don't delete code when generating a precompile file
8904+
!(params.imaging || jl_options.incremental)) {
89058905
// if not inlineable, code won't be needed again
89068906
jl_atomic_store_release(&codeinst->inferred, jl_nothing);
89078907
}

src/gf.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2316,8 +2316,10 @@ jl_code_instance_t *jl_method_compiled(jl_method_instance_t *mi, size_t world)
23162316
jl_code_instance_t *codeinst = jl_atomic_load_relaxed(&mi->cache);
23172317
while (codeinst) {
23182318
if (codeinst->min_world <= world && world <= codeinst->max_world) {
2319-
if (jl_atomic_load_relaxed(&codeinst->invoke) != NULL)
2319+
jl_callptr_t invoke = jl_atomic_load_acquire(&codeinst->invoke);
2320+
if (invoke != NULL) {
23202321
return codeinst;
2322+
}
23212323
}
23222324
codeinst = jl_atomic_load_relaxed(&codeinst->next);
23232325
}
@@ -2859,20 +2861,19 @@ STATIC_INLINE jl_value_t *verify_type(jl_value_t *v) JL_NOTSAFEPOINT
28592861
return v;
28602862
}
28612863

2864+
STATIC_INLINE jl_value_t *invoke_codeinst(jl_value_t *F, jl_value_t **args, uint32_t nargs, jl_code_instance_t *codeinst)
2865+
{
2866+
jl_callptr_t invoke = jl_atomic_load_acquire(&codeinst->invoke);
2867+
jl_value_t *res = invoke(F, args, nargs, codeinst);
2868+
return verify_type(res);
2869+
}
2870+
28622871
STATIC_INLINE jl_value_t *_jl_invoke(jl_value_t *F, jl_value_t **args, uint32_t nargs, jl_method_instance_t *mfunc, size_t world)
28632872
{
28642873
// manually inlined copy of jl_method_compiled
2865-
jl_code_instance_t *codeinst = jl_atomic_load_relaxed(&mfunc->cache);
2866-
while (codeinst) {
2867-
if (codeinst->min_world <= world && world <= codeinst->max_world) {
2868-
jl_callptr_t invoke = jl_atomic_load_acquire(&codeinst->invoke);
2869-
if (invoke != NULL) {
2870-
jl_value_t *res = invoke(F, args, nargs, codeinst);
2871-
return verify_type(res);
2872-
}
2873-
}
2874-
codeinst = jl_atomic_load_relaxed(&codeinst->next);
2875-
}
2874+
jl_code_instance_t *codeinst = jl_method_compiled(mfunc, world);
2875+
if (codeinst)
2876+
return invoke_codeinst(F, args, nargs, codeinst);
28762877
int64_t last_alloc = jl_options.malloc_log ? jl_gc_diff_total_bytes() : 0;
28772878
int last_errno = errno;
28782879
#ifdef _OS_WINDOWS_
@@ -2885,9 +2886,7 @@ STATIC_INLINE jl_value_t *_jl_invoke(jl_value_t *F, jl_value_t **args, uint32_t
28852886
errno = last_errno;
28862887
if (jl_options.malloc_log)
28872888
jl_gc_sync_total_bytes(last_alloc); // discard allocation count from compilation
2888-
jl_callptr_t invoke = jl_atomic_load_acquire(&codeinst->invoke);
2889-
jl_value_t *res = invoke(F, args, nargs, codeinst);
2890-
return verify_type(res);
2889+
return invoke_codeinst(F, args, nargs, codeinst);
28912890
}
28922891

28932892
JL_DLLEXPORT jl_value_t *jl_invoke(jl_value_t *F, jl_value_t **args, uint32_t nargs, jl_method_instance_t *mfunc)

0 commit comments

Comments
 (0)