summaryrefslogtreecommitdiff
path: root/yjit_codegen.c
diff options
context:
space:
mode:
authorAlan Wu <[email protected]>2021-06-16 16:55:13 -0400
committerAlan Wu <[email protected]>2021-10-20 18:19:36 -0400
commit8c68f112d8ec9f5a9a416fc69602855bf43c4dd6 (patch)
tree064223240bafa8a76cb1700906c2aa50031c06b0 /yjit_codegen.c
parent936ee5556280162da3016bf62ebe74ef07caf882 (diff)
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.
Diffstat (limited to 'yjit_codegen.c')
-rw-r--r--yjit_codegen.c12
1 files 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
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
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
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
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