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:
parent
b3a65c883a
commit
8472c15440
2 changed files with 27 additions and 20 deletions
|
@ -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>
|
Thu Mar 17 21:52:09 2016 Yusuke Endoh <mame@ruby-lang.org>
|
||||||
|
|
||||||
* array.c, enum.c: make rdoc format consistent.
|
* array.c, enum.c: make rdoc format consistent.
|
||||||
|
|
42
compile.c
42
compile.c
|
@ -2283,6 +2283,28 @@ insn_set_specialized_instruction(rb_iseq_t *iseq, INSN *iobj, int insn_id)
|
||||||
static int
|
static int
|
||||||
iseq_specialized_instruction(rb_iseq_t *iseq, INSN *iobj)
|
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)) {
|
if (iobj->insn_id == BIN(send)) {
|
||||||
struct rb_call_info *ci = (struct rb_call_info *)OPERAND_AT(iobj, 0);
|
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);
|
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;
|
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_QCALL:
|
||||||
case NODE_FCALL:
|
case NODE_FCALL:
|
||||||
case NODE_VCALL:{ /* VCALL: variable or call */
|
case NODE_VCALL:{ /* VCALL: variable or call */
|
||||||
|
|
Loading…
Reference in a new issue