Skip to content

Commit f130858

Browse files
committed
gf.c: include const-return methods in --trace-compile
Code that returns a constant value never ends up compiled by LLVM, but we want to log them since they are inferred / compiled by our own Compiler. These can sometimes include methods that speculatively end up 'compiled' with a non-'compileable' signature, since inference eagerly explores widened signatures that JIT / codegen normally would not. That's not work that we can log here since `precompile(...)` will reject the widened signature, but that's probably fine, since the JIT doesn't know to look for these widened signatures anyway.
1 parent f8ece05 commit f130858

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/gf.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,8 @@ JL_DLLEXPORT jl_code_instance_t *jl_new_codeinst(
645645
return codeinst;
646646
}
647647

648+
static void record_precompile_statement(jl_method_instance_t *mi, double compilation_time, int is_recompile);
649+
648650
JL_DLLEXPORT void jl_update_codeinst(
649651
jl_code_instance_t *codeinst, jl_value_t *inferred,
650652
int32_t const_flags, size_t min_world, size_t max_world,
@@ -667,6 +669,15 @@ JL_DLLEXPORT void jl_update_codeinst(
667669
if ((const_flags & 1) != 0) {
668670
assert(codeinst->rettype_const);
669671
jl_atomic_store_release(&codeinst->invoke, jl_fptr_const_return);
672+
// Emit a `precompile` since this code's compilation is now complete. It was just inferred and it will require
673+
// no codegen since it returns a constant value.
674+
jl_method_instance_t *mi = jl_get_ci_mi(codeinst);
675+
if (jl_is_method(mi->def.value) && jl_isa_compileable_sig((jl_tupletype_t *)mi->specTypes, mi->sparam_vals, mi->def.method)) {
676+
// This isa_compileable_sig check is required because `precompile(...)` will reject the signature otherwise,
677+
// assuming it is too wide to compile to a good result. That happens even though we know a posteriori that
678+
// the signature compiles to a function with excellent performance (a const-return function).
679+
record_precompile_statement(mi, 0.0, 0);
680+
}
670681
}
671682
jl_atomic_store_release(&codeinst->inferred, inferred);
672683
jl_gc_wb(codeinst, inferred);

0 commit comments

Comments
 (0)