Eliminate a call instruction on JIT cancel path

by calling combined functions specialized for each cancel type.

I'm hoping to improve locality of hot code, but this patch's impact should
be insignificant.
This commit is contained in:
Takashi Kokubun 2020-05-26 22:49:55 -07:00
Родитель 4cabd77e33
Коммит 61b14bb32b
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 6FFC433B12EE23DD
3 изменённых файлов: 42 добавлений и 11 удалений

36
mjit.c
Просмотреть файл

@ -455,8 +455,8 @@ rb_mjit_iseq_compile_info(const struct rb_iseq_constant_body *body)
return &body->jit_unit->compile_info;
}
void
rb_mjit_recompile_iseq(const rb_iseq_t *iseq)
static void
mjit_recompile(const rb_iseq_t *iseq)
{
if ((uintptr_t)iseq->body->jit_func <= (uintptr_t)LAST_JIT_ISEQ_FUNC)
return;
@ -476,6 +476,38 @@ rb_mjit_recompile_iseq(const rb_iseq_t *iseq)
}
}
// Recompile iseq, disabling send optimization
void
rb_mjit_recompile_send(const rb_iseq_t *iseq)
{
rb_mjit_iseq_compile_info(iseq->body)->disable_send_cache = true;
mjit_recompile(iseq);
}
// Recompile iseq, disabling ivar optimization
void
rb_mjit_recompile_ivar(const rb_iseq_t *iseq)
{
rb_mjit_iseq_compile_info(iseq->body)->disable_ivar_cache = true;
mjit_recompile(iseq);
}
// Recompile iseq, disabling exivar optimization
void
rb_mjit_recompile_exivar(const rb_iseq_t *iseq)
{
rb_mjit_iseq_compile_info(iseq->body)->disable_exivar_cache = true;
mjit_recompile(iseq);
}
// Recompile iseq, disabling method inlining
void
rb_mjit_recompile_inlining(const rb_iseq_t *iseq)
{
rb_mjit_iseq_compile_info(iseq->body)->disable_inlining = true;
mjit_recompile(iseq);
}
extern VALUE ruby_archlibdir_path, ruby_prefix_path;
// Initialize header_file, pch_file, libruby_pathflag. Return true on success.

5
mjit.h
Просмотреть файл

@ -80,7 +80,10 @@ RUBY_EXTERN bool mjit_call_p;
extern void rb_mjit_add_iseq_to_process(const rb_iseq_t *iseq);
extern VALUE rb_mjit_wait_call(rb_execution_context_t *ec, struct rb_iseq_constant_body *body);
extern struct rb_mjit_compile_info* rb_mjit_iseq_compile_info(const struct rb_iseq_constant_body *body);
extern void rb_mjit_recompile_iseq(const rb_iseq_t *iseq);
extern void rb_mjit_recompile_send(const rb_iseq_t *iseq);
extern void rb_mjit_recompile_ivar(const rb_iseq_t *iseq);
extern void rb_mjit_recompile_exivar(const rb_iseq_t *iseq);
extern void rb_mjit_recompile_inlining(const rb_iseq_t *iseq);
RUBY_SYMBOL_EXPORT_END
extern bool mjit_compile(FILE *f, const rb_iseq_t *iseq, const char *funcname, int id);

Просмотреть файл

@ -241,8 +241,7 @@ compile_inlined_cancel_handler(FILE *f, const struct rb_iseq_constant_body *body
{
fprintf(f, "\ncancel:\n");
fprintf(f, " RB_DEBUG_COUNTER_INC(mjit_cancel);\n");
fprintf(f, " rb_mjit_iseq_compile_info(original_iseq->body)->disable_inlining = true;\n");
fprintf(f, " rb_mjit_recompile_iseq(original_iseq);\n");
fprintf(f, " rb_mjit_recompile_inlining(original_iseq);\n");
// Swap pc/sp set on cancel with original pc/sp.
fprintf(f, " const VALUE *current_pc = reg_cfp->pc;\n");
@ -282,20 +281,17 @@ compile_cancel_handler(FILE *f, const struct rb_iseq_constant_body *body, struct
fprintf(f, "\nsend_cancel:\n");
fprintf(f, " RB_DEBUG_COUNTER_INC(mjit_cancel_send_inline);\n");
fprintf(f, " rb_mjit_iseq_compile_info(original_iseq->body)->disable_send_cache = true;\n");
fprintf(f, " rb_mjit_recompile_iseq(original_iseq);\n");
fprintf(f, " rb_mjit_recompile_send(original_iseq);\n");
fprintf(f, " goto cancel;\n");
fprintf(f, "\nivar_cancel:\n");
fprintf(f, " RB_DEBUG_COUNTER_INC(mjit_cancel_ivar_inline);\n");
fprintf(f, " rb_mjit_iseq_compile_info(original_iseq->body)->disable_ivar_cache = true;\n");
fprintf(f, " rb_mjit_recompile_iseq(original_iseq);\n");
fprintf(f, " rb_mjit_recompile_ivar(original_iseq);\n");
fprintf(f, " goto cancel;\n");
fprintf(f, "\nexivar_cancel:\n");
fprintf(f, " RB_DEBUG_COUNTER_INC(mjit_cancel_exivar_inline);\n");
fprintf(f, " rb_mjit_iseq_compile_info(original_iseq->body)->disable_exivar_cache = true;\n");
fprintf(f, " rb_mjit_recompile_iseq(original_iseq);\n");
fprintf(f, " rb_mjit_recompile_exivar(original_iseq);\n");
fprintf(f, " goto cancel;\n");
fprintf(f, "\ncancel:\n");