Skip to content

Commit

Permalink
YJIT: Prefer an overloaded cme if available (#9913)
Browse files Browse the repository at this point in the history
YJIT: Prefer an overloaded cme if applicable
  • Loading branch information
k0kubun committed Feb 12, 2024
1 parent 94bc5ad commit e4d3e65
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions vm_insnhelper.c
Expand Up @@ -2032,7 +2032,7 @@ vm_ccs_verify(struct rb_class_cc_entries *ccs, ID mid, VALUE klass)
}
#endif

static const rb_callable_method_entry_t *check_overloaded_cme(const rb_callable_method_entry_t *cme, const struct rb_callinfo * const ci);
const rb_callable_method_entry_t *rb_check_overloaded_cme(const rb_callable_method_entry_t *cme, const struct rb_callinfo * const ci);

static const struct rb_callcache *
vm_search_cc(const VALUE klass, const struct rb_callinfo * const ci)
Expand Down Expand Up @@ -2118,7 +2118,7 @@ vm_search_cc(const VALUE klass, const struct rb_callinfo * const ci)
}
}

cme = check_overloaded_cme(cme, ci);
cme = rb_check_overloaded_cme(cme, ci);

const struct rb_callcache *cc = vm_cc_new(klass, cme, vm_call_general, cc_type_normal);
vm_ccs_push(klass, ccs, ci, cc);
Expand Down
4 changes: 2 additions & 2 deletions vm_method.c
Expand Up @@ -1063,8 +1063,8 @@ get_overloaded_cme(const rb_callable_method_entry_t *cme)
}
}

static const rb_callable_method_entry_t *
check_overloaded_cme(const rb_callable_method_entry_t *cme, const struct rb_callinfo * const ci)
const rb_callable_method_entry_t *
rb_check_overloaded_cme(const rb_callable_method_entry_t *cme, const struct rb_callinfo * const ci)
{
if (UNLIKELY(cme->def->iseq_overload) &&
(vm_ci_flag(ci) & (VM_CALL_ARGS_SIMPLE)) &&
Expand Down
4 changes: 4 additions & 0 deletions yjit/src/codegen.rs
Expand Up @@ -7679,6 +7679,10 @@ fn gen_send_general(
return None;
}

// Load an overloaded cme if applicable. See vm_search_cc().
// It allows you to use a faster ISEQ if possible.
cme = unsafe { rb_check_overloaded_cme(cme, ci) };

let visi = unsafe { METHOD_ENTRY_VISI(cme) };
match visi {
METHOD_VISI_PUBLIC => {
Expand Down
4 changes: 4 additions & 0 deletions yjit/src/cruby.rs
Expand Up @@ -112,6 +112,10 @@ pub use autogened::*;
// Use bindgen for functions that are defined in headers or in yjit.c.
#[cfg_attr(test, allow(unused))] // We don't link against C code when testing
extern "C" {
pub fn rb_check_overloaded_cme(
me: *const rb_callable_method_entry_t,
ci: *const rb_callinfo,
) -> *const rb_callable_method_entry_t;
pub fn rb_hash_empty_p(hash: VALUE) -> VALUE;
pub fn rb_vm_splat_array(flag: VALUE, ary: VALUE) -> VALUE;
pub fn rb_vm_concat_array(ary1: VALUE, ary2st: VALUE) -> VALUE;
Expand Down

0 comments on commit e4d3e65

Please sign in to comment.