summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-05-21 04:46:51 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-05-21 04:46:51 +0000
commitaffa7430b70336b53cd496496d889c2544d41322 ()
tree5a1ed8dee97b8ee1c9a78aa83abd8f566246f1a3
parent696cbbd7a6c364687522cc41992b0896f3c0507b (diff)
* compile.c, vm_macro.def: support tail call optimization
(on default, this feature is not enabled). * iseq.c, compile.c, vm_opts.h: add "tailcall_optimization" option. * sample/test.rb (test_ok): fix to adjust tailcall stack layout. * insns.def, vm.c, compile.c, yarvcore.c, yarvcore.h: add opt_gt, opt_le instructions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12304 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog13
-rw-r--r--compile.c54
-rw-r--r--insns.def70
-rw-r--r--iseq.c11
-rw-r--r--sample/test.rb2
-rw-r--r--version.h6
-rw-r--r--vm.c2
-rw-r--r--vm.h2
-rw-r--r--vm_macro.def41
-rw-r--r--vm_opts.h3
-rw-r--r--yarvcore.c4
-rw-r--r--yarvcore.h3
12 files changed, 174 insertions, 37 deletions
@@ -1,3 +1,16 @@
Mon May 21 03:34:06 2007 Minero Aoki <[email protected]>
* lib/net/smtp.rb: CRAM-MD5 authentication did not work.
@@ -1347,7 +1347,7 @@ get_prev_insn(INSN *iobj)
}
static int
-iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list)
{
INSN *iobj = (INSN *)list;
again:
@@ -1367,6 +1367,12 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list)
niobj = (INSN *)get_next_insn(iobj);
if (diobj == niobj) {
REMOVE_ELEM(&iobj->link);
}
else if (iobj != diobj && diobj->insn_id == BIN(jump)) {
@@ -1374,11 +1380,23 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list)
goto again;
}
else if (diobj->insn_id == BIN(leave)) {
INSN *eiobj = new_insn_core(iseq, iobj->line_no, BIN(leave),
diobj->operand_size,
diobj->operands);
/* replace */
REPLACE_ELEM((LINK_ELEMENT *)iobj, (LINK_ELEMENT *)eiobj);
}
/*
* useless jump elimination (if/unless destination):
@@ -1405,6 +1423,7 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list)
}
}
}
if (iobj->insn_id == BIN(branchif) ||
iobj->insn_id == BIN(branchunless)) {
/*
@@ -1421,14 +1440,20 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list)
}
}
- if (iobj->insn_id == BIN(leave)) {
INSN *piobj = (INSN *)get_prev_insn((INSN *)list);
- if (piobj->insn_id == BIN(send)) {
- /* TODO: tail call optimization */
- if (piobj->operands[2] == 0) {
- /* piobj->operands[3] = INT2FIX(FIX2INT(piobj->operands[3]) | VM_CALL_TAILCALL_BIT); */
- /* piobj->operands[3] = INT2FIX(FIX2INT(piobj->operands[3]) | VM_CALL_TAILRECURSION_BIT); */
- }
}
}
return COMPILE_OK;
@@ -1489,6 +1514,12 @@ iseq_specialized_instruction(rb_iseq_t *iseq, INSN *iobj)
else if (mid == idLE) {
insn_set_specialized_instruction(iobj, BIN(opt_le));
}
else if (mid == idLTLT) {
insn_set_specialized_instruction(iobj, BIN(opt_ltlt));
}
@@ -1510,15 +1541,16 @@ static int
iseq_optimize(rb_iseq_t *iseq, LINK_ANCHOR *anchor)
{
LINK_ELEMENT *list;
- const int do_peephole = iseq->compile_data->option->peephole_optimization;
const int do_si = iseq->compile_data->option->specialized_instruction;
const int do_ou = iseq->compile_data->option->operands_unification;
list = FIRST_ELEMENT(anchor);
while (list) {
if (list->type == ISEQ_ELEMENT_INSN) {
- if (do_peephole) {
- iseq_peephole_optimize(iseq, list);
}
if (do_si) {
iseq_specialized_instruction(iseq, (INSN *)list);
@@ -2139,6 +2139,76 @@ opt_le
/**
@c optimize
@e <<
@j <<
*/
@@ -196,11 +196,12 @@ cleanup_iseq_build(rb_iseq_t *iseq)
static rb_compile_option_t COMPILE_OPTION_DEFAULT = {
OPT_INLINE_CONST_CACHE, /* int inline_const_cache; */
OPT_PEEPHOLE_OPTIMIZATION, /* int peephole_optimization; */
OPT_SPECIALISED_INSTRUCTION, /* int specialized_instruction; */
OPT_OPERANDS_UNIFICATION, /* int operands_unification; */
OPT_INSTRUCTIONS_UNIFICATION, /* int instructions_unification; */
OPT_STACK_CACHING, /* int stack_caching; */
- OPT_TRACE_INSTRUCTION,
};
static const rb_compile_option_t COMPILE_OPTION_FALSE;
@@ -217,13 +218,16 @@ make_compile_option(rb_compile_option_t *option, VALUE opt)
memset(option, 1, sizeof(rb_compile_option_t));
}
else if (CLASS_OF(opt) == rb_cHash) {
#define SET_COMPILE_OPTION(o, h, mem) \
- { VALUE flag = rb_hash_aref(h, ID2SYM(rb_intern(#mem))); dp(flag);\
if (flag == Qtrue) { o->mem = 1; } \
- if (flag == Qfalse) { o->mem = 0; } \
}
SET_COMPILE_OPTION(option, opt, inline_const_cache);
SET_COMPILE_OPTION(option, opt, peephole_optimization);
SET_COMPILE_OPTION(option, opt, specialized_instruction);
SET_COMPILE_OPTION(option, opt, operands_unification);
SET_COMPILE_OPTION(option, opt, instructions_unification);
@@ -245,6 +249,7 @@ make_compile_option_value(rb_compile_option_t *option)
{
SET_COMPILE_OPTION(option, opt, inline_const_cache);
SET_COMPILE_OPTION(option, opt, peephole_optimization);
SET_COMPILE_OPTION(option, opt, specialized_instruction);
SET_COMPILE_OPTION(option, opt, operands_unification);
SET_COMPILE_OPTION(option, opt, instructions_unification);
@@ -17,7 +17,7 @@ def test_ok(cond,n=1)
if cond
printf "ok %d\n", $testnum
else
- where = caller(n)[0]
printf "not ok %s %d -- %s\n", $what, $testnum, where
$failed+=1
end
@@ -1,7 +1,7 @@
#define RUBY_VERSION "1.9.0"
-#define RUBY_RELEASE_DATE "2007-05-19"
#define RUBY_VERSION_CODE 190
-#define RUBY_RELEASE_CODE 20070519
#define RUBY_LEVEL 0
#define RUBY_VERSION_MAJOR 1
@@ -9,7 +9,7 @@
#define RUBY_VERSION_TEENY 0
#define RUBY_RELEASE_YEAR 2007
#define RUBY_RELEASE_MONTH 5
-#define RUBY_RELEASE_DAY 19
#ifdef RUBY_EXTERN
RUBY_EXTERN const char ruby_version[];
@@ -1480,6 +1480,8 @@ yarv_init_redefined_flag(void)
idASET, BOP_ASET, rb_cArray, rb_cHash, 0,
idLength, BOP_LENGTH, rb_cArray, rb_cString, rb_cHash, 0,
idSucc, BOP_SUCC, rb_cFixnum, rb_cString, rb_cTime, 0,
0,
};
VALUE *ptr = register_info;
@@ -283,5 +283,7 @@ default: \
#define BOP_ASET 0x400
#define BOP_LENGTH 0x800
#define BOP_SUCC 0x1000
#endif /* _VM_H_INCLUDED_ */
@@ -198,33 +198,38 @@ MACRO macro_eval_invoke_func(niseqval, recv, klass, blockptr, num)
rb_exc_raise(sysstack_error);
}
- for (i = 0; i < clear_local_size; i++) {
- *sp++ = Qnil;
- }
- if (0 && (flag & VM_CALL_TAILCALL_BIT)) {
- th->cfp++;
- push_frame(th, niseq, FRAME_MAGIC_METHOD,
- recv, (VALUE) blockptr,
niseq->iseq_encoded + opt_pc, sp, 0, 0);
}
- else if (0 &&
- (flag & VM_CALL_TAILRECURSION_BIT) && niseq == GET_ISEQ()) {
- /* do nothing */
- GET_CFP()->self = recv;
- SET_LFP(sp);
- SET_DFP(sp);
- *sp++ = (VALUE) blockptr;
- reg_cfp->sp = sp;
- reg_cfp->bp = sp;
- SET_PC(niseq->iseq_encoded + opt_pc);
- }
else {
push_frame(th, niseq,
FRAME_MAGIC_METHOD, recv, (VALUE) blockptr,
niseq->iseq_encoded + opt_pc, sp, 0, 0);
reg_cfp->sp = rsp;
}
RESTORE_REGS();
}
@@ -22,10 +22,11 @@
/* VM running option */
#define OPT_CHECKED_RUN 1
-#define OPT_TRACE_INSTRUCTION 1
/* at compile */
#define OPT_INLINE_CONST_CACHE 1
#define OPT_PEEPHOLE_OPTIMIZATION 1
#define OPT_SPECIALISED_INSTRUCTION 1
@@ -31,6 +31,8 @@ ID idMOD;
ID idLT;
ID idLTLT;
ID idLE;
ID idEq;
ID idEqq;
ID idBackquote;
@@ -495,6 +497,8 @@ Init_VM(void)
idLT = rb_intern("<");
idLTLT = rb_intern("<<");
idLE = rb_intern("<=");
idEq = rb_intern("==");
idEqq = rb_intern("===");
idBackquote = rb_intern("`");
@@ -109,6 +109,8 @@ extern ID idMOD;
extern ID idLT;
extern ID idLTLT;
extern ID idLE;
extern ID idEq;
extern ID idEqq;
extern ID idBackquote;
@@ -182,6 +184,7 @@ struct iseq_compile_data_ensure_node_stack;
typedef struct rb_compile_option_struct {
int inline_const_cache;
int peephole_optimization;
int specialized_instruction;
int operands_unification;
int instructions_unification;