ruby-changes:51787
From: k0kubun <ko1@a...>
Date: Thu, 19 Jul 2018 22:25:29 +0900 (JST)
Subject: [ruby-changes:51787] k0kubun:r63999 (trunk): mjit_compile.c: reduce sp motion on JIT
k0kubun 2018-07-19 22:25:22 +0900 (Thu, 19 Jul 2018) New Revision: 63999 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63999 Log: mjit_compile.c: reduce sp motion on JIT This retries r62655, which was reverted at r63863 for r63763. tool/ruby_vm/views/_mjit_compile_insn.erb: revert the revert. tool/ruby_vm/views/_mjit_compile_insn_body.erb: ditto. tool/ruby_vm/views/_mjit_compile_pc_and_sp.erb: ditto. tool/ruby_vm/views/_mjit_compile_send.erb: ditto. tool/ruby_vm/views/mjit_compile.inc.erb: ditto. tool/ruby_vm/views/_insn_entry.erb: revert half of r63763. The commit was originally reverted since changing pc motion was bad for tracing, but changing sp motion was totally fine. For JIT, I wanna resurrect the sp motion change in r62051. tool/ruby_vm/models/bare_instructions.rb: ditto. insns.def: ditto. vm_insnhelper.c: ditto. vm_insnhelper.h: ditto. * benchmark $ benchmark-driver benchmark.yml --rbenv 'before;after;before --jit;after --jit' --repeat-count 12 -v before: ruby 2.6.0dev (2018-07-19 trunk 63998) [x86_64-linux] after: ruby 2.6.0dev (2018-07-19 add-sp 63998) [x86_64-linux] last_commit=mjit_compile.c: reduce sp motion on JIT before --jit: ruby 2.6.0dev (2018-07-19 trunk 63998) +JIT [x86_64-linux] after --jit: ruby 2.6.0dev (2018-07-19 add-sp 63998) +JIT [x86_64-linux] last_commit=mjit_compile.c: reduce sp motion on JIT Calculating ------------------------------------- before after before --jit after --jit Optcarrot Lan_Master.nes 51.354 50.238 70.010 72.139 fps Comparison: Optcarrot Lan_Master.nes after --jit: 72.1 fps before --jit: 70.0 fps - 1.03x slower before: 51.4 fps - 1.40x slower after: 50.2 fps - 1.44x slower Modified files: trunk/insns.def trunk/mjit_compile.c trunk/tool/ruby_vm/models/bare_instructions.rb trunk/tool/ruby_vm/views/_insn_entry.erb trunk/tool/ruby_vm/views/_mjit_compile_insn.erb trunk/tool/ruby_vm/views/_mjit_compile_insn_body.erb trunk/tool/ruby_vm/views/_mjit_compile_pc_and_sp.erb trunk/tool/ruby_vm/views/_mjit_compile_send.erb trunk/tool/ruby_vm/views/mjit_compile.inc.erb trunk/vm_insnhelper.c trunk/vm_insnhelper.h Index: vm_insnhelper.c =================================================================== --- vm_insnhelper.c (revision 63998) +++ vm_insnhelper.c (revision 63999) @@ -1237,11 +1237,11 @@ vm_throw(const rb_execution_context_t *e https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1237 } static inline void -vm_expandarray(rb_control_frame_t *cfp, VALUE ary, rb_num_t num, int flag) +vm_expandarray(VALUE *sp, VALUE ary, rb_num_t num, int flag) { int is_splat = flag & 0x01; rb_num_t space_size = num + is_splat; - VALUE *base = cfp->sp; + VALUE *base = sp - 1; const VALUE *ptr; rb_num_t len; const VALUE obj = ary; @@ -1256,8 +1256,6 @@ vm_expandarray(rb_control_frame_t *cfp, https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1256 len = (rb_num_t)RARRAY_LEN(ary); } - cfp->sp += space_size; - if (flag & 0x02) { /* post: ..., nil ,ary[-1], ..., ary[0..-num] # top */ rb_num_t i = 0, j; Index: vm_insnhelper.h =================================================================== --- vm_insnhelper.h (revision 63998) +++ vm_insnhelper.h (revision 63999) @@ -111,6 +111,8 @@ enum vm_regan_acttype { https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.h#L111 #define INC_SP(x) (VM_REG_SP += (COLLECT_USAGE_REGISTER_HELPER(SP, SET, (x)))) #define DEC_SP(x) (VM_REG_SP -= (COLLECT_USAGE_REGISTER_HELPER(SP, SET, (x)))) #define SET_SV(x) (*GET_SP() = (x)) + /* set current stack value as x */ +#define ADJ_SP(x) INC_SP(x) /* instruction sequence C struct */ #define GET_ISEQ() (GET_CFP()->iseq) Index: insns.def =================================================================== --- insns.def (revision 63998) +++ insns.def (revision 63999) @@ -43,6 +43,8 @@ https://github.com/ruby/ruby/blob/trunk/insns.def#L43 * sp_inc: Used to dynamically calculate sp increase in `insn_stack_increase`. + * handles_frame: If it is true, VM deals with sp in the insn. + - Attributes can access operands, but not stack (push/pop) variables. - An instruction's body is a pure C block, copied verbatimly into @@ -364,7 +366,6 @@ concatstrings https://github.com/ruby/ruby/blob/trunk/insns.def#L366 // attr rb_snum_t sp_inc = 1 - num; { val = rb_str_concat_literals(num, STACK_ADDR_FROM_TOP(num)); - POPN(num); } /* push the result of to_s. */ @@ -400,7 +401,6 @@ toregexp https://github.com/ruby/ruby/blob/trunk/insns.def#L401 const VALUE ary = rb_ary_tmp_new_from_values(0, cnt, STACK_ADDR_FROM_TOP(cnt)); val = rb_reg_new_ary(ary, (int)opt); rb_ary_clear(ary); - POPN(cnt); } /* intern str to Symbol and push it. */ @@ -422,7 +422,6 @@ newarray https://github.com/ruby/ruby/blob/trunk/insns.def#L422 // attr rb_snum_t sp_inc = 1 - num; { val = rb_ary_new4(num, STACK_ADDR_FROM_TOP(num)); - POPN(num); } /* dup array */ @@ -451,7 +450,7 @@ expandarray https://github.com/ruby/ruby/blob/trunk/insns.def#L450 (...) // attr rb_snum_t sp_inc = num - 1 + (flag & 1 ? 1 : 0); { - vm_expandarray(GET_CFP(), ary, num, (int)flag); + vm_expandarray(GET_SP(), ary, num, (int)flag); } /* concat two arrays */ @@ -488,7 +487,6 @@ newhash https://github.com/ruby/ruby/blob/trunk/insns.def#L487 if (num) { rb_hash_bulk_insert(num, STACK_ADDR_FROM_TOP(num), val); - POPN(num); } } @@ -538,7 +536,6 @@ dupn https://github.com/ruby/ruby/blob/trunk/insns.def#L536 void *dst = GET_SP(); void *src = STACK_ADDR_FROM_TOP(n); - INC_SP(n); /* alloca */ MEMCPY(dst, src, VALUE, n); } @@ -601,7 +598,7 @@ setn https://github.com/ruby/ruby/blob/trunk/insns.def#L598 (VALUE val) // attr rb_snum_t sp_inc = 0; { - TOPN(n - 1) = val; + TOPN(n) = val; } /* empty current stack */ @@ -612,7 +609,7 @@ adjuststack https://github.com/ruby/ruby/blob/trunk/insns.def#L609 (...) // attr rb_snum_t sp_inc = -(rb_snum_t)n; { - POPN(n); + /* none */ } /**********************************************************/ @@ -690,6 +687,7 @@ defineclass https://github.com/ruby/ruby/blob/trunk/insns.def#L687 (ID id, ISEQ class_iseq, rb_num_t flags) (VALUE cbase, VALUE super) (VALUE val) +// attr bool handles_frame = true; { VALUE klass = vm_find_or_create_class_by_id(id, flags, cbase, super); @@ -716,6 +714,7 @@ send https://github.com/ruby/ruby/blob/trunk/insns.def#L714 (CALL_INFO ci, CALL_CACHE cc, ISEQ blockiseq) (...) (VALUE val) +// attr bool handles_frame = true; // attr rb_snum_t sp_inc = - (int)(ci->orig_argc + ((ci->flag & VM_CALL_ARGS_BLOCKARG) ? 1 : 0)); { struct rb_calling_info calling; @@ -751,7 +750,6 @@ opt_newarray_max https://github.com/ruby/ruby/blob/trunk/insns.def#L750 // attr rb_snum_t sp_inc = 1 - num; { val = vm_opt_newarray_max(num, STACK_ADDR_FROM_TOP(num)); - POPN(num); } DEFINE_INSN @@ -762,7 +760,6 @@ opt_newarray_min https://github.com/ruby/ruby/blob/trunk/insns.def#L760 // attr rb_snum_t sp_inc = 1 - num; { val = vm_opt_newarray_min(num, STACK_ADDR_FROM_TOP(num)); - POPN(num); } /* Invoke method without block */ @@ -771,6 +768,7 @@ opt_send_without_block https://github.com/ruby/ruby/blob/trunk/insns.def#L768 (CALL_INFO ci, CALL_CACHE cc) (...) (VALUE val) +// attr bool handles_frame = true; // attr rb_snum_t sp_inc = -ci->orig_argc; { struct rb_calling_info calling; @@ -785,6 +783,7 @@ invokesuper https://github.com/ruby/ruby/blob/trunk/insns.def#L783 (CALL_INFO ci, CALL_CACHE cc, ISEQ blockiseq) (...) (VALUE val) +// attr bool handles_frame = true; // attr rb_snum_t sp_inc = - (int)(ci->orig_argc + ((ci->flag & VM_CALL_ARGS_BLOCKARG) ? 1 : 0)); { struct rb_calling_info calling; @@ -802,6 +801,7 @@ invokeblock https://github.com/ruby/ruby/blob/trunk/insns.def#L801 (CALL_INFO ci) (...) (VALUE val) +// attr bool handles_frame = true; // attr rb_snum_t sp_inc = 1 - ci->orig_argc; { struct rb_calling_info calling; @@ -828,6 +828,7 @@ leave https://github.com/ruby/ruby/blob/trunk/insns.def#L828 () (VALUE val) (VALUE val) +// attr bool handles_frame = true; { if (OPT_CHECKED_RUN) { const VALUE *const bp = vm_base_ptr(reg_cfp); @@ -989,8 +990,6 @@ opt_plus https://github.com/ruby/ruby/blob/trunk/insns.def#L990 val = vm_opt_plus(recv, obj); if (val == Qundef) { - PUSH(recv); - PUSH(obj); #ifndef MJIT_HEADER ADD_PC(-WIDTH_OF_opt_send_without_block); #endif @@ -1008,8 +1007,6 @@ opt_minus https://github.com/ruby/ruby/blob/trunk/insns.def#L1007 val = vm_opt_minus(recv, obj); if (val == Qundef) { - PUSH(recv); - PUSH(obj); #ifndef MJIT_HEADER ADD_PC(-WIDTH_OF_opt_send_without_block); #endif @@ -1027,8 +1024,6 @@ opt_mult https://github.com/ruby/ruby/blob/trunk/insns.def#L1024 val = vm_opt_mult(recv, obj); if (val == Qundef) { - PUSH(recv); - PUSH(obj); #ifndef MJIT_HEADER ADD_PC(-WIDTH_OF_opt_send_without_block); #endif @@ -1046,8 +1041,6 @@ opt_div https://github.com/ruby/ruby/blob/trunk/insns.def#L1041 val = vm_opt_div(recv, obj); if (val == Qundef) { - PUSH(recv); - PUSH(obj); #ifndef MJIT_HEADER ADD_PC(-WIDTH_OF_opt_send_without_block); #endif @@ -1065,8 +1058,6 @@ opt_mod https://github.com/ruby/ruby/blob/trunk/insns.def#L1058 val = vm_opt_mod(recv, obj); if (val == Qundef) { - PUSH(recv); - PUSH(obj); #ifndef MJIT_HEADER ADD_PC(-WIDTH_OF_opt_send_without_block); #endif @@ -1084,8 +1075,6 @@ opt_eq https://github.com/ruby/ruby/blob/trunk/insns.def#L1075 val = opt_eq_func(recv, obj, ci, cc); if (val == Qundef) { - PUSH(recv); - PUSH(obj); #ifndef MJIT_HEADER ADD_PC(-WIDTH_OF_opt_send_without_block); #endif @@ -1103,8 +1092,6 @@ opt_neq https://github.com/ruby/ruby/blob/trunk/insns.def#L1092 val = vm_opt_neq(ci, cc, ci_eq, cc_eq, recv, obj); if (val == Qundef) { - PUSH(recv); - PUSH(obj); #ifndef MJIT_HEADER ADD_PC(-WIDTH_OF_opt_send_without_block); #endif @@ -1122,8 +1109,6 @@ opt_lt https://github.com/ruby/ruby/blob/trunk/insns.def#L1109 val = vm_opt_lt(recv, obj); if (val == Qundef) { - PUSH(recv); - PUSH(obj); #ifndef MJIT_HEADER ADD_PC(-WIDTH_OF_opt_send_without_block); #endif @@ -1141,8 +1126,6 @@ opt_le https://github.com/ruby/ruby/blob/trunk/insns.def#L1126 val = vm_opt_le(recv, obj); if (val == Qundef) { - PUSH(recv); - PUSH(obj); #ifndef MJIT_HEADER ADD_PC(-WIDTH_OF_opt_send_without_block); #endif @@ -1160,8 +1143,6 @@ opt_gt https://github.com/ruby/ruby/blob/trunk/insns.def#L1143 val = vm_opt_gt(recv, obj); if (val == Qundef) { - PUSH(recv); - PUSH(obj); #ifndef MJIT_HEADER ADD_PC(-WIDTH_OF_opt_send_without_block); #endif @@ -1179,8 +1160,6 @@ opt_ge https://github.com/ruby/ruby/blob/trunk/insns.def#L1160 val = vm_opt_ge(recv, obj); if (val == Qundef) { - PUSH(recv); - PUSH(obj); #ifndef MJIT_HEADER ADD_PC(-WIDTH_OF_opt_send_without_block); #endif @@ -1198,8 +1177,6 @@ opt_ltlt https://github.com/ruby/ruby/blob/trunk/insns.def#L1177 val = vm_opt_ltlt(recv, obj); if (val == Qundef) { - PUSH(recv); - PUSH(obj); #ifndef MJIT_HEADER ADD_PC(-WIDTH_OF_opt_send_without_block); #endif @@ -1217,8 +1194,6 @@ opt_aref https://github.com/ruby/ruby/blob/trunk/insns.def#L1194 val = vm_opt_aref(recv, obj); if (val == Qundef) { - PUSH(recv); - PUSH(obj); #ifndef MJIT_HEADER ADD_PC(-WIDTH_OF_opt_send_without_block); #endif @@ -1236,9 +1211,6 @@ opt_aset https://github.com/ruby/ruby/blob/trunk/insns.def#L1211 val = vm_opt_aset(recv, obj, set); if (val == Qundef) { - PUSH(recv); - PUSH(obj); - PUSH(set); #ifndef MJIT_HEADER ADD_PC(-WIDTH_OF_opt_send_without_block); #endif @@ -1259,12 +1231,9 @@ opt_aset_with https://github.com/ruby/ruby/blob/trunk/insns.def#L1231 val = tmp; } else { - PUSH(recv); -#ifndef MJIT_HEADER - PUSH(rb_str_resurrect(key)); -#endif - PUSH(val); #ifndef MJIT_HEADER + TOPN(0) = rb_str_resurrect(key); + PUSH(val); ADD_PC(-WIDTH_OF_opt_send_without_block); #endif DISPATCH_ORIGINAL_INSN(opt_send_without_block); @@ -1281,9 +1250,8 @@ opt_aref_with https://github.com/ruby/ruby/blob/trunk/insns.def#L1250 val = vm_opt_aref_with(recv, key); if (val == Qundef) { - PUSH(recv); #ifndef MJIT_HEADER - PUSH(rb_str_resurrect(key)); + PUSH(rb_str_resurrect(key)); ADD_PC(-WIDTH_OF_opt_send_without_block); #endif DISPATCH_ORIGINAL_INSN(opt_send_without_block); @@ -1300,7 +1268,6 @@ opt_length https://github.com/ruby/ruby/blob/trunk/insns.def#L1268 val = vm_opt_length(recv, BOP_LENGTH); if (val == Qundef) { - PUSH(recv); #ifndef MJIT_HEADER ADD_PC(-WIDTH_OF_opt_send_without_block); #endif @@ -1318,7 +1285,6 @@ opt_size https://github.com/ruby/ruby/blob/trunk/insns.def#L1285 val = vm_opt_length(recv, BOP_SIZE); if (val == Qundef) { - PUSH(recv); #ifndef MJIT_HEADER ADD_PC(-WIDTH_OF_opt_send_without_block); #endif @@ -1336,7 +1302,6 @@ opt_empty_p https://github.com/ruby/ruby/blob/trunk/insns.def#L1302 val = vm_opt_empty_p(recv); if (val == Qundef) { - PUSH(recv); #ifndef MJIT_HEADER ADD_PC(-WIDTH_OF_opt_send_without_block); #endif @@ -1354,7 +1319,6 @@ opt_succ https://github.com/ruby/ruby/blob/trunk/insns.def#L1319 val = vm_opt_succ(recv); if (val == Qundef) { - PUSH(recv); #ifndef MJIT_HEADER ADD_PC(-WIDTH_OF_opt_send_without_block); #endif @@ -1372,7 +1336,6 @@ opt_not https://github.com/ruby/ruby/blob/trunk/insns.def#L1336 val = vm_opt_not(ci, cc, recv); if (val == Qundef) { - PUSH(recv); #ifndef MJIT_HEADER ADD_PC(-WIDTH_OF_opt_send_without_block); #endif @@ -1400,8 +1363,6 @@ opt_regexpmatch2 https://github.com/ruby/ruby/blob/trunk/insns.def#L1363 val = vm_opt_regexpmatch2(obj2, obj1); if (val == Qundef) { - PUSH(obj2); - PUSH(obj1); #ifndef MJIT_HEADER ADD_PC(-WIDTH_OF_opt_send_without_block); #endif @@ -1415,6 +1376,7 @@ opt_call_c_function https://github.com/ruby/ruby/blob/trunk/insns.def#L1376 (rb_insn_func_t funcptr) () () +// attr bool handles_frame = true; { reg_cfp = (funcptr)(ec, reg_cfp); Index: mjit_compile.c =================================================================== --- mjit_compile.c (revision 63998) +++ mjit_compile.c (revision 63999) @@ -24,6 +24,9 @@ https://github.com/ruby/ruby/blob/trunk/mjit_compile.c#L24 struct compile_status { int success; /* has TRUE if compilation has had no issue */ int *stack_size_for_pos; /* stack_size_for_pos[pos] has stack size for the position (otherwise -1) */ + /* If TRUE, JIT-ed code will use local variables to store pushed values instead of + using VM's stack and moving stack pointer. */ + int local_stack_p; }; /* Storage to keep data which is consistent in each conditional branch. @@ -172,7 +175,13 @@ compile_insns(FILE *f, const struct rb_i https://github.com/ruby/ruby/blob/trunk/mjit_compile.c#L175 static void compile_cancel_handler(FILE *f, const struct rb_iseq_constant_body *body, struct compile_status *status) { + unsigned int i; fprintf(f, "\ncancel:\n"); + if (status->local_stack_p) { + for (i = 0; i < body->stack_max; i++) { + fprintf(f, " *((VALUE *)reg_cfp->bp + %d) = stack[%d];\n", i + 1, i); + } + } fprintf(f, " return Qundef;\n"); } @@ -182,6 +191,7 @@ mjit_compile(FILE *f, const struct rb_is https://github.com/ruby/ruby/blob/trunk/mjit_compile.c#L191 { struct compile_status status; status.success = TRUE; + status.local_stack_p = !body->catch_except_p; status.stack_size_for_pos = ALLOC_N(int, body->iseq_size); memset(status.stack_size_for_pos, NOT_COMPILED_STACK_SIZE, sizeof(int) * body->iseq_size); @@ -195,7 +205,12 @@ mjit_compile(FILE *f, const struct rb_is https://github.com/ruby/ruby/blob/trunk/mjit_compile.c#L205 fprintf(f, "__declspec(dllexport)\n"); #endif fprintf(f, "VALUE\n%s(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp)\n{\n", funcname); - fprintf(f, " VALUE *stack = reg_cfp->sp;\n"); + if (status.local_stack_p) { + fprintf(f, " VALUE stack[%d];\n", body->stack_max); + } + else { + fprintf(f, " VALUE *stack = reg_cfp->sp;\n"); + } fprintf(f, " static const VALUE *const original_body_iseq = (VALUE *)0x%"PRIxVALUE";\n", (VALUE)body->iseq_encoded); Index: tool/ruby_vm/models/bare_instructions.rb =================================================================== --- tool/ruby_vm/models/bare_instructions.rb (revision 63998) +++ tool/ruby_vm/models/bare_instructions.rb (revision 63999) @@ -101,6 +101,10 @@ class RubyVM::BareInstructions https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/models/bare_instructions.rb#L101 }.join end + def handles_frame? + /\b(false|0)\b/ !~ @attrs['handles_frame'].expr.expr + end + def inspect sprintf "#<%s %s@%s:%d>", self.class.name, @name, @loc[0], @loc[1] end @@ -125,6 +129,7 @@ class RubyVM::BareInstructions https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/models/bare_instructions.rb#L129 generate_attribute 'rb_num_t', 'retn', rets.size generate_attribute 'rb_num_t', 'width', width generate_attribute 'rb_snum_t', 'sp_inc', rets.size - pops.size + generate_attribute 'bool', 'handles_frame', false end def typesplit a Index: tool/ruby_vm/views/_insn_entry.erb =================================================================== --- tool/ruby_vm/views/_insn_entry.erb (revision 63998) +++ tool/ruby_vm/views/_insn_entry.erb (revision 63999) @@ -30,16 +30,25 @@ INSN_ENTRY(<%= insn.name %>) https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/views/_insn_entry.erb#L30 % end DEBUG_ENTER_INSN(INSN_ATTR(name)); ADD_PC(INSN_ATTR(width)); +% if insn.handles_frame? POPN(INSN_ATTR(popn)); +% end COLLECT_USAGE_INSN(INSN_ATTR(bin)); % insn.opes.each_with_index do |ope, i| COLLECT_USAGE_OPERAND(INSN_ATTR(bin), <%= i %>, <%= ope[:name] %>); % end <%= render_c_expr insn.expr -%> CHECK_VM_STACK_OVERFLOW_FOR_INSN(VM_REG_CFP, INSN_ATTR(retn)); -% insn.rets.each do |ret| +% if insn.handles_frame? +% insn.rets.reverse_each do |ret| PUSH(<%= insn.cast_to_VALUE ret %>); % end +% else + ADJ_SP(INSN_ATTR(sp_inc)); +% insn.rets.reverse_each.with_index do |ret, i| + TOPN(<%= i %>) = <%= insn.cast_to_VALUE ret %>; +% end +% end END_INSN(<%= insn.name %>); # undef INSN_ATTR # undef NAME_OF_CURRENT_INSN Index: tool/ruby_vm/views/_mjit_compile_insn.erb =================================================================== --- tool/ruby_vm/views/_mjit_compile_insn.erb (revision 63998) +++ tool/ruby_vm/views/_mjit_compile_insn.erb (revision 63999) @@ -20,6 +20,11 @@ https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/views/_mjit_compile_insn.erb#L20 MAYBE_UNUSED(<%= ope.fetch(:decl) %>) = (<%= ope.fetch(:type) %>)operands[<%= i %>]; % end % +% # JIT: Declare stack_size to be used in some macro of _mjit_compile_insn_body.erb + if (status->local_stack_p) { + fprintf(f, " MAYBE_UNUSED(unsigned int) stack_size = %u;\n", b->stack_size); + } +% % # JIT: Declare variables for operands, popped values and return values % insn.declarations.each do |decl| fprintf(f, " <%= decl %>;\n"); Index: tool/ruby_vm/views/_mjit_compile_insn_body.erb =================================================================== --- tool/ruby_vm/views/_mjit_compile_insn_body.erb (revision 63998) +++ tool/ruby_vm/views/_mjit_compile_insn_body.erb (revision 63999) @@ -69,9 +69,37 @@ https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/views/_mjit_compile_insn_body.erb#L69 % end % when /\A\s+DISPATCH_ORIGINAL_INSN\([^)]+\);\s+\z/ % # For `opt_xxx`'s fallbacks. + if (status->local_stack_p) { + fprintf(f, " reg_cfp->sp = (VALUE *)reg_cfp->bp + %d;\n", b->stack_size + 1); + } fprintf(f, " reg_cfp->pc = original_body_iseq + %d;\n", pos); fprintf(f, " goto cancel;\n"); % else +% if insn.handles_frame? +% # If insn.handles_frame? is true, cfp->sp might be changed inside insns (like vm_caller_setup_arg_block) +% # and thus we need to use cfp->sp, even when local_stack_p is TRUE. When insn.handles_frame? is true, +% # cfp->sp should be available too because _mjit_compile_pc_and_sp.erb sets it. fprintf(f, <%= to_cstr.call(line) %>); +% else +% # If local_stack_p is TRUE and insn.handles_frame? is false, stack values are only available in local variables +% # for stack. So we need to replace those macros if local_stack_p is TRUE here. +% case line +% when /\bGET_SP\(\)/ +% # reg_cfp->sp + fprintf(f, <%= to_cstr.call(line.sub(/\bGET_SP\(\)/, '%s')) %>, (status->local_stack_p ? "(stack + stack_size)" : "GET_SP()")); +% when /\bSTACK_ADDR_FROM_TOP\((?<num>[^)]+)\)/ +% # #define STACK_ADDR_FROM_TOP(n) (GET_SP()-(n)) +% num = Regexp.last_match[:num] + fprintf(f, <%= to_cstr.call(line.sub(/\bSTACK_ADDR_FROM_TOP\(([^)]+)\)/, '%s')) %>, + (status->local_stack_p ? "stack + (stack_size - (<%= num %>))" : "STACK_ADDR_FROM_TOP(<%= num %>)")); +% when /\bTOPN\((?<num>[^)]+)\)/ +% # #define TOPN(n) (*(GET_SP()-(n)-1)) +% num = Regexp.last_match[:num] + fprintf(f, <%= to_cstr.call(line.sub(/\bTOPN\(([^)]+)\)/, '%s')) %>, + (status->local_stack_p ? "*(stack + (stack_size - (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/