Skip to content

Commit

Permalink
make sure precompile statements are printed even for const_return fun…
Browse files Browse the repository at this point in the history
…ctions
  • Loading branch information
JeffBezanson committed Dec 17, 2021
1 parent 2c0e1bc commit 3f6abcf
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
35 changes: 35 additions & 0 deletions src/gf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1931,6 +1931,36 @@ jl_code_instance_t *jl_method_compiled(jl_method_instance_t *mi, size_t world)
return NULL;
}

static void record_precompile_statement(jl_method_instance_t *mi)
{
static ios_t f_precompile;
static JL_STREAM* s_precompile = NULL;
jl_method_t *def = mi->def.method;
if (jl_options.trace_compile == NULL)
return;
if (!jl_is_method(def))
return;

if (s_precompile == NULL) {
const char *t = jl_options.trace_compile;
if (!strncmp(t, "stderr", 6)) {
s_precompile = JL_STDERR;
}
else {
if (ios_file(&f_precompile, t, 1, 1, 1, 1) == NULL)
jl_errorf("cannot open precompile statement file \"%s\" for writing", t);
s_precompile = (JL_STREAM*) &f_precompile;
}
}
if (!jl_has_free_typevars(mi->specTypes)) {
jl_printf(s_precompile, "precompile(");
jl_static_show(s_precompile, mi->specTypes);
jl_printf(s_precompile, ")\n");
if (s_precompile != JL_STDERR)
ios_flush(&f_precompile);
}
}

jl_code_instance_t *jl_compile_method_internal(jl_method_instance_t *mi, size_t world)
{
jl_code_instance_t *codeinst = jl_method_compiled(mi, world);
Expand Down Expand Up @@ -1962,6 +1992,7 @@ jl_code_instance_t *jl_compile_method_internal(jl_method_instance_t *mi, size_t
codeinst->rettype_const = unspec->rettype_const;
codeinst->invoke = unspec->invoke;
jl_mi_cache_insert(mi, codeinst);
record_precompile_statement(mi);
return codeinst;
}
}
Expand All @@ -1976,6 +2007,7 @@ jl_code_instance_t *jl_compile_method_internal(jl_method_instance_t *mi, size_t
0, 1, ~(size_t)0);
codeinst->invoke = jl_fptr_interpret_call;
jl_mi_cache_insert(mi, codeinst);
record_precompile_statement(mi);
return codeinst;
}
if (compile_option == JL_OPTIONS_COMPILE_OFF) {
Expand Down Expand Up @@ -2014,6 +2046,9 @@ jl_code_instance_t *jl_compile_method_internal(jl_method_instance_t *mi, size_t
codeinst->invoke = ucache->invoke;
jl_mi_cache_insert(mi, codeinst);
}
else {
record_precompile_statement(mi);
}
jl_atomic_store_relaxed(&codeinst->precompile, 1);
return codeinst;
}
Expand Down
24 changes: 0 additions & 24 deletions src/jitlayers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@ static jl_callptr_t _jl_compile_codeinst(
jl_code_info_t *src,
size_t world)
{
// TODO: Merge with jl_dump_compiles?
static ios_t f_precompile;
static JL_STREAM* s_precompile = NULL;

// caller must hold codegen_lock
// and have disabled finalizers
uint64_t start_time = 0;
Expand Down Expand Up @@ -182,26 +178,6 @@ static jl_callptr_t _jl_compile_codeinst(
// then dump the method-instance specialization type to the stream
jl_method_instance_t *mi = codeinst->def;
if (jl_is_method(mi->def.method)) {
if (jl_options.trace_compile != NULL) {
if (s_precompile == NULL) {
const char* t = jl_options.trace_compile;
if (!strncmp(t, "stderr", 6))
s_precompile = JL_STDERR;
else {
if (ios_file(&f_precompile, t, 1, 1, 1, 1) == NULL)
jl_errorf("cannot open precompile statement file \"%s\" for writing", t);
s_precompile = (JL_STREAM*) &f_precompile;
}
}
if (!jl_has_free_typevars(mi->specTypes)) {
jl_printf(s_precompile, "precompile(");
jl_static_show(s_precompile, mi->specTypes);
jl_printf(s_precompile, ")\n");

if (s_precompile != JL_STDERR)
ios_flush(&f_precompile);
}
}
if (dump_compiles_stream != NULL) {
jl_printf(dump_compiles_stream, "%" PRIu64 "\t\"", end_time - start_time);
jl_static_show(dump_compiles_stream, mi->specTypes);
Expand Down

0 comments on commit 3f6abcf

Please sign in to comment.