aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-17 13:08:35 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-17 13:08:35 +0000
commit8472c15440b1aaa4bbb5e5eb5a939ef02612c9b5 (patch)
tree469cbc27fe974c3ddce20c36eeafbd0766268f9d
parentb3a65c883aa2351865c3502a0e2d85ed8febcf75 (diff)
downloadruby-8472c15440b1aaa4bbb5e5eb5a939ef02612c9b5.tar.gz
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
-rw-r--r--ChangeLog5
-rw-r--r--compile.c42
2 files changed, 27 insertions, 20 deletions
diff --git a/ChangeLog b/ChangeLog
index 0655745183..c6f38747e2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/compile.c b/compile.c
index 767e2b1772..2518697eab 100644
--- a/compile.c
+++ b/compile.c
@@ -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 */