Skip to content

Commit 5b907c9

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 5b907c9

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/gf.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,15 @@ JL_DLLEXPORT void jl_update_codeinst(
667667
if ((const_flags & 1) != 0) {
668668
assert(codeinst->rettype_const);
669669
jl_atomic_store_release(&codeinst->invoke, jl_fptr_const_return);
670+
// Emit a `precompile` since this code's compilation is now complete. It was just inferred and it will require
671+
// no codegen since it returns a constant value.
672+
jl_method_instance_t *mi = jl_get_ci_mi(codeinst);
673+
if (jl_is_method(mi->def.value) && jl_isa_compileable_sig((jl_tupletype_t *)mi->specTypes, mi->sparam_vals, mi->def.method)) {
674+
// This isa_compileable_sig check is required because `precompile(...)` will reject the signature otherwise,
675+
// assuming it is too wide to compile to a good result. That happens even though we know a posteriori that
676+
// the signature compiles to a function with excellent performance (a const-return function).
677+
record_precompile_statement(mi, 0.0, 0);
678+
}
670679
}
671680
jl_atomic_store_release(&codeinst->inferred, inferred);
672681
jl_gc_wb(codeinst, inferred);

0 commit comments

Comments
 (0)