Skip to content

Commit

Permalink
compile.c: tailcall before specialize
Browse files Browse the repository at this point in the history
* compile.c (iseq_tailcall_optimize): apply tail call optimization
  before conversion to specialized instructions.  when looking
  back from `leave` instruction, `send` instructions have been
  translated already.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52663 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Nov 19, 2015
1 parent 01a54cf commit 3e86720
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
7 changes: 7 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Thu Nov 19 14:12:12 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>

* compile.c (iseq_tailcall_optimize): apply tail call optimization
before conversion to specialized instructions. when looking
back from `leave` instruction, `send` instructions have been
translated already.

Thu Nov 19 13:57:58 2015 NAKAMURA Usaku <usa@ruby-lang.org>

* win32/win32.c (finish_overlapped_socket): ignore EMSGSIZE when input,
Expand Down
32 changes: 25 additions & 7 deletions compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -2100,21 +2100,39 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal
}
}

if (do_tailcallopt && iobj->insn_id == BIN(leave)) {
if (do_tailcallopt &&
(iobj->insn_id == BIN(send) ||
iobj->insn_id == BIN(invokesuper))) {
/*
* send ...
* leave
* =>
* send ..., ... | VM_CALL_TAILCALL, ...
* leave # unreachable
*/
INSN *piobj = (INSN *)get_prev_insn(iobj);
enum ruby_vminsn_type previ = piobj->insn_id;
INSN *piobj = NULL;
if (iobj->link.next) {
LINK_ELEMENT *next = iobj->link.next;
do {
if (next->type != ISEQ_ELEMENT_INSN) {
next = next->next;
continue;
}
switch (INSN_OF(next)) {
case BIN(nop):
/*case BIN(trace):*/
next = next->next;
break;
case BIN(leave):
piobj = iobj;
default:
next = NULL;
break;
}
} while (next);
}

if (previ == BIN(send) || previ == BIN(opt_send_without_block) ||
previ == BIN(invokesuper) ||
previ == BIN(opt_aref) || previ == BIN(opt_aref_with) ||
previ == BIN(opt_aset) || previ == BIN(opt_aset_with)) {
if (piobj) {
struct rb_call_info *ci = (struct rb_call_info *)piobj->operands[0];
rb_iseq_t *blockiseq = (rb_iseq_t *)piobj->operands[1];
if (blockiseq == 0) {
Expand Down

0 comments on commit 3e86720

Please sign in to comment.