@@ -859,6 +859,7 @@ enum {
859859 SEND_MAX_DEPTH = 5 , // up to 5 different classes
860860};
861861
862+ /*
862863// Codegen for setting an instance variable.
863864// Preconditions:
864865// - receiver is in REG0
@@ -969,6 +970,7 @@ gen_set_ivar(jitstate_t *jit, ctx_t *ctx, const int max_chain_depth, VALUE compt
969970 GEN_COUNTER_INC(cb, setivar_name_not_mapped);
970971 return YJIT_CANT_COMPILE;
971972}
973+ */
972974
973975// Codegen for getting an instance variable.
974976// Preconditions:
@@ -1118,9 +1120,36 @@ gen_getinstancevariable(jitstate_t *jit, ctx_t *ctx)
11181120 return gen_get_ivar (jit , ctx , GETIVAR_MAX_DEPTH , comptime_val , ivar_name , OPND_SELF , side_exit );
11191121}
11201122
1123+ void rb_vm_setinstancevariable (const rb_iseq_t * iseq , VALUE obj , ID id , VALUE val , IVC ic );
1124+
11211125static codegen_status_t
11221126gen_setinstancevariable (jitstate_t * jit , ctx_t * ctx )
11231127{
1128+ ID id = (ID )jit_get_arg (jit , 0 );
1129+ IVC ic = (IVC )jit_get_arg (jit , 1 );
1130+
1131+ // Save the PC and SP because the callee may allocate
1132+ // Note that this modifies REG_SP, which is why we do it first
1133+ jit_save_pc (jit , REG0 );
1134+ jit_save_sp (jit , ctx );
1135+
1136+ // Get the operands from the stack
1137+ x86opnd_t val_opnd = ctx_stack_pop (ctx , 1 );
1138+
1139+ // Call rb_vm_setinstancevariable(iseq, obj, id, val, ic);
1140+ // Out of order because we're going to corrupt REG_SP and REG_CFP
1141+ yjit_save_regs (cb );
1142+ mov (cb , C_ARG_REGS [1 ], member_opnd (REG_CFP , rb_control_frame_t , self ));
1143+ mov (cb , C_ARG_REGS [3 ], val_opnd );
1144+ mov (cb , C_ARG_REGS [2 ], imm_opnd (id ));
1145+ mov (cb , C_ARG_REGS [4 ], const_ptr_opnd (ic ));
1146+ jit_mov_gc_ptr (jit , cb , C_ARG_REGS [0 ], (VALUE )jit -> iseq );
1147+ call_ptr (cb , REG0 , (void * )rb_vm_setinstancevariable );
1148+ yjit_load_regs (cb );
1149+
1150+ return YJIT_KEEP_COMPILING ;
1151+
1152+ /*
11241153 // Defer compilation so we can specialize on a runtime `self`
11251154 if (!jit_at_current_insn(jit)) {
11261155 defer_compilation(jit->block, jit->insn_idx, ctx);
@@ -1142,6 +1171,7 @@ gen_setinstancevariable(jitstate_t* jit, ctx_t* ctx)
11421171 jit_guard_known_klass(jit, ctx, comptime_val_klass, OPND_SELF, GETIVAR_MAX_DEPTH, side_exit);
11431172
11441173 return gen_set_ivar(jit, ctx, GETIVAR_MAX_DEPTH, comptime_val, ivar_name, OPND_SELF, side_exit);
1174+ */
11451175}
11461176
11471177static void
0 commit comments