ruby-changes:42082
From: nobu <ko1@a...>
Date: Thu, 17 Mar 2016 22:08:40 +0900 (JST)
Subject: [ruby-changes:42082] nobu:r54156 (trunk): compile.c: move newarray specialization
nobu 2016-03-17 22:08:35 +0900 (Thu, 17 Mar 2016) New Revision: 54156 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54156 Log: compile.c: move newarray specialization * compile.c (iseq_specialized_instruction): move specialization for opt_newarray_max/min from translation phase. Modified files: trunk/ChangeLog trunk/compile.c Index: ChangeLog =================================================================== --- ChangeLog (revision 54155) +++ ChangeLog (revision 54156) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Mar 17 22:08:33 2016 Nobuyoshi Nakada <nobu@r...> + + * compile.c (iseq_specialized_instruction): move specialization + for opt_newarray_max/min from translation phase. + Thu Mar 17 21:52:09 2016 Yusuke Endoh <mame@r...> * array.c, enum.c: make rdoc format consistent. Index: compile.c =================================================================== --- compile.c (revision 54155) +++ compile.c (revision 54156) @@ -2283,6 +2283,28 @@ insn_set_specialized_instruction(rb_iseq https://github.com/ruby/ruby/blob/trunk/compile.c#L2283 static int iseq_specialized_instruction(rb_iseq_t *iseq, INSN *iobj) { + if (iobj->insn_id == BIN(newarray)) { + /* + * [a, b, ...].max/min -> a, b, c, opt_newarray_max/min + */ + INSN *niobj = (INSN *)get_next_insn(iobj); + if (niobj && niobj->insn_id == BIN(send)) { + struct rb_call_info *ci = (struct rb_call_info *)OPERAND_AT(niobj, 0); + if ((ci->flag & VM_CALL_ARGS_SIMPLE) && ci->orig_argc == 0) { + switch (ci->mid) { + case idMax: + iobj->insn_id = BIN(opt_newarray_max); + REMOVE_ELEM(&niobj->link); + return COMPILE_OK; + case idMin: + iobj->insn_id = BIN(opt_newarray_min); + REMOVE_ELEM(&niobj->link); + return COMPILE_OK; + } + } + } + } + if (iobj->insn_id == BIN(send)) { struct rb_call_info *ci = (struct rb_call_info *)OPERAND_AT(iobj, 0); const rb_iseq_t *blockiseq = (rb_iseq_t *)OPERAND_AT(iobj, 2); @@ -4914,26 +4936,6 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ https://github.com/ruby/ruby/blob/trunk/compile.c#L4936 if (poped) { ADD_INSN(ret, line, pop); } - break; - } - /* optimization shortcut - * [a, b, ...].max/min -> a, b, c, opt_newarray_max/min - */ - if (node->nd_recv && nd_type(node->nd_recv) == NODE_ARRAY && - (node->nd_mid == idMax || node->nd_mid == idMin) && node->nd_args == NULL && - ISEQ_COMPILE_DATA(iseq)->current_block == NULL && - ISEQ_COMPILE_DATA(iseq)->option->specialized_instruction) { - COMPILE(ret, "recv", node->nd_recv); - if (((INSN*)ret->last)->insn_id == BIN(newarray)) { - ((INSN*)ret->last)->insn_id = - node->nd_mid == idMax ? BIN(opt_newarray_max) : BIN(opt_newarray_min); - } - else { - ADD_SEND(ret, line, node->nd_mid, INT2FIX(0)); - } - if (poped) { - ADD_INSN(ret, line, pop); - } break; } case NODE_QCALL: -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/