Skip to content

Commit

Permalink
codegen: use compiler trampoline closing over method-instance
Browse files Browse the repository at this point in the history
Replaces jlcall_api with inspection of the invoke closure
to see if it is a known entity
  • Loading branch information
vtjnash committed Mar 23, 2018
1 parent 44885c6 commit 0ad4b05
Show file tree
Hide file tree
Showing 21 changed files with 674 additions and 619 deletions.
6 changes: 3 additions & 3 deletions base/compiler/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ function optimize(me::InferenceState)

if proven_pure && !coverage_enabled()
# use constant calling convention
# Do not emit `jlcall_api == 2` if coverage is enabled
# Do not emit `jl_fptr_const_return` if coverage is enabled
# so that we don't need to add coverage support
# to the `jl_call_method_internal` fast path
# Still set pure flag to make sure `inference` tests pass
Expand Down Expand Up @@ -438,7 +438,7 @@ function finish(me::InferenceState)
end

# don't store inferred code if we've decided to interpret this function
if !already_inferred && me.linfo.jlcall_api != 4
if !already_inferred && invoke_api(me.linfo) != 4
const_flags = (me.const_ret) << 1 | me.const_api
if me.const_ret
if isa(me.bestguess, Const)
Expand Down Expand Up @@ -1320,7 +1320,7 @@ function inlineable(@nospecialize(f), @nospecialize(ft), e::Expr, atypes::Vector
isa(linfo, MethodInstance) || return invoke_NF(argexprs0, e.typ, atypes0, sv,
atype_unlimited, invoke_data)
linfo = linfo::MethodInstance
if linfo.jlcall_api == 2
if invoke_api(linfo) == 2
# in this case function can be inlined to a constant
add_backedge!(linfo, sv)
return inline_as_constant(linfo.inferred_const, argexprs, sv, invoke_data)
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/typeinfer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ function typeinf_code(linfo::MethodInstance, optimize::Bool, cached::Bool,
# so need to check whether the code itself is also inferred
if min_world(linfo) <= params.world <= max_world(linfo)
inf = linfo.inferred
if linfo.jlcall_api == 2
if invoke_api(linfo) == 2
method = linfo.def::Method
tree = ccall(:jl_new_code_info_uninit, Ref{CodeInfo}, ())
tree.code = Any[ Expr(:return, quoted(linfo.inferred_const)) ]
Expand Down
4 changes: 4 additions & 0 deletions base/compiler/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ end
# MethodInstance/CodeInfo #
###########################

function invoke_api(li::MethodInstance)
return ccall(:jl_invoke_api, Cint, (Any,), li)
end

function get_staged(li::MethodInstance)
try
# user code might throw errors – ignore them
Expand Down
2 changes: 1 addition & 1 deletion src/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ static jl_value_t *jl_invoke_julia_macro(jl_array_t *args, jl_module_t *inmodule
// unreachable
}
*ctx = mfunc->def.method->module;
result = jl_call_method_internal(mfunc, margs, nargs);
result = mfunc->invoke(mfunc, margs, nargs);
}
JL_CATCH {
if (jl_loaderror_type == NULL) {
Expand Down
6 changes: 3 additions & 3 deletions src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -1181,13 +1181,13 @@ static void add_builtin(const char *name, jl_value_t *v)
jl_set_const(jl_core_module, jl_symbol(name), v);
}

jl_fptr_t jl_get_builtin_fptr(jl_value_t *b)
jl_fptr_args_t jl_get_builtin_fptr(jl_value_t *b)
{
assert(jl_isa(b, (jl_value_t*)jl_builtin_type));
return jl_gf_mtable(b)->cache.leaf->func.linfo->fptr;
return jl_gf_mtable(b)->cache.leaf->func.linfo->specptr.fptr1;
}

static void add_builtin_func(const char *name, jl_fptr_t fptr)
static void add_builtin_func(const char *name, jl_fptr_args_t fptr)
{
jl_mk_builtin_func(NULL, name, fptr);
}
Expand Down
Loading

0 comments on commit 0ad4b05

Please sign in to comment.