Skip to content

Commit 6ec5388

Browse files
authored
Implement setivar with a plain old function call (#34)
* Implement setivar with a plain old function call * Remove return
1 parent d8b015f commit 6ec5388

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

vm_insnhelper.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,6 +1300,12 @@ vm_setinstancevariable(const rb_iseq_t *iseq, VALUE obj, ID id, VALUE val, IVC i
13001300
vm_setivar(obj, id, val, iseq, ic, 0, 0);
13011301
}
13021302

1303+
void
1304+
rb_vm_setinstancevariable(const rb_iseq_t *iseq, VALUE obj, ID id, VALUE val, IVC ic)
1305+
{
1306+
vm_setinstancevariable(iseq, obj, id, val, ic);
1307+
}
1308+
13031309
static VALUE
13041310
vm_throw_continue(const rb_execution_context_t *ec, VALUE err)
13051311
{

yjit_codegen.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,7 @@ enum {
857857
SEND_MAX_DEPTH = 5, // up to 5 different classes
858858
};
859859

860+
/*
860861
// Codegen for setting an instance variable.
861862
// Preconditions:
862863
// - receiver is in REG0
@@ -967,6 +968,7 @@ gen_set_ivar(jitstate_t *jit, ctx_t *ctx, const int max_chain_depth, VALUE compt
967968
GEN_COUNTER_INC(cb, setivar_name_not_mapped);
968969
return YJIT_CANT_COMPILE;
969970
}
971+
*/
970972

971973
// Codegen for getting an instance variable.
972974
// Preconditions:
@@ -1116,9 +1118,36 @@ gen_getinstancevariable(jitstate_t *jit, ctx_t *ctx)
11161118
return gen_get_ivar(jit, ctx, GETIVAR_MAX_DEPTH, comptime_val, ivar_name, OPND_SELF, side_exit);
11171119
}
11181120

1121+
void rb_vm_setinstancevariable(const rb_iseq_t *iseq, VALUE obj, ID id, VALUE val, IVC ic);
1122+
11191123
static codegen_status_t
11201124
gen_setinstancevariable(jitstate_t* jit, ctx_t* ctx)
11211125
{
1126+
ID id = (ID)jit_get_arg(jit, 0);
1127+
IVC ic = (IVC)jit_get_arg(jit, 1);
1128+
1129+
// Save the PC and SP because the callee may allocate
1130+
// Note that this modifies REG_SP, which is why we do it first
1131+
jit_save_pc(jit, REG0);
1132+
jit_save_sp(jit, ctx);
1133+
1134+
// Get the operands from the stack
1135+
x86opnd_t val_opnd = ctx_stack_pop(ctx, 1);
1136+
1137+
// Call rb_vm_setinstancevariable(iseq, obj, id, val, ic);
1138+
// Out of order because we're going to corrupt REG_SP and REG_CFP
1139+
yjit_save_regs(cb);
1140+
mov(cb, C_ARG_REGS[1], member_opnd(REG_CFP, rb_control_frame_t, self));
1141+
mov(cb, C_ARG_REGS[3], val_opnd);
1142+
mov(cb, C_ARG_REGS[2], imm_opnd(id));
1143+
mov(cb, C_ARG_REGS[4], const_ptr_opnd(ic));
1144+
jit_mov_gc_ptr(jit, cb, C_ARG_REGS[0], (VALUE)jit->iseq);
1145+
call_ptr(cb, REG0, (void *)rb_vm_setinstancevariable);
1146+
yjit_load_regs(cb);
1147+
1148+
return YJIT_KEEP_COMPILING;
1149+
1150+
/*
11221151
// Defer compilation so we can specialize on a runtime `self`
11231152
if (!jit_at_current_insn(jit)) {
11241153
defer_compilation(jit->block, jit->insn_idx, ctx);
@@ -1140,6 +1169,7 @@ gen_setinstancevariable(jitstate_t* jit, ctx_t* ctx)
11401169
jit_guard_known_klass(jit, ctx, comptime_val_klass, OPND_SELF, GETIVAR_MAX_DEPTH, side_exit);
11411170
11421171
return gen_set_ivar(jit, ctx, GETIVAR_MAX_DEPTH, comptime_val, ivar_name, OPND_SELF, side_exit);
1172+
*/
11431173
}
11441174

11451175
static void

0 commit comments

Comments
 (0)