1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

compile.c: move newarray specialization

* compile.c (iseq_specialized_instruction): move specialization
  for opt_newarray_max/min from translation phase.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54156 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2016-03-17 13:08:35 +00:00
parent b3a65c883a
commit 8472c15440
2 changed files with 27 additions and 20 deletions

View file

@ -1,3 +1,8 @@
Thu Mar 17 22:08:33 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
* 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@ruby-lang.org>
* array.c, enum.c: make rdoc format consistent.

View file

@ -2283,6 +2283,28 @@ insn_set_specialized_instruction(rb_iseq_t *iseq, INSN *iobj, int insn_id)
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);
@ -4916,26 +4938,6 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
}
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:
case NODE_FCALL:
case NODE_VCALL:{ /* VCALL: variable or call */