ruby-changes:68985
From: Alan <ko1@a...>
Date: Thu, 21 Oct 2021 08:19:35 +0900 (JST)
Subject: [ruby-changes:68985] 8c68f112d8 (master): Delay and be selective about when to discard local types
https://git.ruby-lang.org/ruby.git/commit/?id=8c68f112d8 From 8c68f112d8ec9f5a9a416fc69602855bf43c4dd6 Mon Sep 17 00:00:00 2001 From: Alan Wu <XrXr@u...> Date: Wed, 16 Jun 2021 16:55:13 -0400 Subject: Delay and be selective about when to discard local types jit_rb_obj_not() wants to access the type information of the receiver, but we were discarding type info of locals before jit_rb_obj_not() runs unncessarily. There are also cases we are unncessarily discarding local type info. For example, ivar reader and setter methods can never change local variables. --- yjit_codegen.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/yjit_codegen.c b/yjit_codegen.c index b0973cb2a7..3a6f6c5cdc 100644 --- a/yjit_codegen.c +++ b/yjit_codegen.c @@ -2503,6 +2503,9 @@ gen_send_cfunc(jitstate_t *jit, ctx_t *ctx, const struct rb_callinfo *ci, const https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L2503 imm_opnd(sizeof(rb_control_frame_t)) ); + // cfunc calls may corrupt types + ctx_clear_local_types(ctx); + // Note: gen_oswb_iseq() jumps to the next instruction with ctx->sp_offset == 0 // after the call, while this does not. This difference prevents // the two call types from sharing the same successor. @@ -2670,6 +2673,9 @@ gen_send_iseq(jitstate_t *jit, ctx_t *ctx, const struct rb_callinfo *ci, const r https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L2673 x86opnd_t stack_ret = ctx_stack_push(ctx, TYPE_UNKNOWN); mov(cb, stack_ret, RAX); + // Note: assuming that the leaf builtin doesn't change local variables here. + // Seems like a safe assumption. + return YJIT_KEEP_COMPILING; } @@ -2770,6 +2776,9 @@ gen_send_iseq(jitstate_t *jit, ctx_t *ctx, const struct rb_callinfo *ci, const r https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L2776 val_type_t recv_type = ctx_get_opnd_type(ctx, OPND_STACK(argc)); ctx_set_opnd_type(&callee_ctx, OPND_SELF, recv_type); + // The callee might change locals through Kernel#binding and other means. + ctx_clear_local_types(ctx); + // Pop arguments and receiver in return context, push the return value // After the return, the JIT and interpreter SP will match up ctx_t return_ctx = *ctx; @@ -2889,9 +2898,6 @@ gen_send_general(jitstate_t *jit, ctx_t *ctx, struct rb_call_data *cd, rb_iseq_t https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L2898 RUBY_ASSERT(cme->called_id == mid); assume_method_lookup_stable(comptime_recv_klass, cme, jit->block); - // Method calls may corrupt types - ctx_clear_local_types(ctx); - // To handle the aliased method case (VM_METHOD_TYPE_ALIAS) while (true) { // switch on the method type -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/