Author: Maciej Fijalkowski <fij...@gmail.com> Branch: resume-refactor Changeset: r68705:f3e813611a53 Date: 2014-01-16 15:39 +0100 http://bitbucket.org/pypy/pypy/changeset/f3e813611a53/
Log: (fijal, rguillebert) implement setfield and forced virtuals on resume diff --git a/rpython/jit/metainterp/optimizeopt/optimizer.py b/rpython/jit/metainterp/optimizeopt/optimizer.py --- a/rpython/jit/metainterp/optimizeopt/optimizer.py +++ b/rpython/jit/metainterp/optimizeopt/optimizer.py @@ -59,6 +59,9 @@ self.make_constant(box) # invariant: box is a Const if and only if level == LEVEL_CONSTANT + def get_resume_box(self): + return self.box + def make_len_gt(self, mode, descr, val): if self.lenbound: assert self.lenbound.mode == mode diff --git a/rpython/jit/metainterp/optimizeopt/resumeopt.py b/rpython/jit/metainterp/optimizeopt/resumeopt.py --- a/rpython/jit/metainterp/optimizeopt/resumeopt.py +++ b/rpython/jit/metainterp/optimizeopt/resumeopt.py @@ -8,7 +8,7 @@ self.pc = pc assert isinstance(jitcode, JitCode) self.jitcode = jitcode - self.boxes = [None] * jitcode.num_regs() + self.values = [None] * jitcode.num_regs() class OptResumeBuilder(object): def __init__(self, opt): @@ -46,11 +46,10 @@ op.getarg(1), op.getarg(2)], None) self.opt._newoperations.append(op) + no = op.getarg(2).getint() + self.framestack[op.getarg(1).getint()].values[no] = value else: self.opt.emit_operation(op) - #no = op.getarg(2).getint() - #box = self.opt.getvalue(op.getarg(0)).box - #self.framestack[op.getarg(1).getint()].boxes[no] = box def new_virtual(self, box): xxx @@ -62,6 +61,18 @@ op = ResOperation(rop.RESUME_NEW, [], newbox, descr=structdescr) self.opt._newoperations.append(op) + def setfield(self, box, fieldbox, descr): + op = ResOperation(rop.RESUME_SETFIELD_GC, [box, fieldbox], None, + descr=descr) + self.opt._newoperations.append(op) + def guard_seen(self, op, pendingfields): - #xxx - pass + for frame_pos, frame in enumerate(self.framestack): + for pos_in_frame, value in enumerate(frame.values): + if value is not None and value.is_forced_virtual(): + op = ResOperation(rop.RESUME_PUT, [value.get_resume_box(), + ConstInt(frame_pos), + ConstInt(pos_in_frame)], + None) + self.opt._newoperations.append(op) + frame.values[pos_in_frame] = None diff --git a/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py b/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py --- a/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py +++ b/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py @@ -454,27 +454,6 @@ """ self.optimize_loop(ops, expected) - def test_virtual_resume_info(self): - ops = """ - [i0] - enter_frame(-1, descr=jitcode) - p0 = new(descr=ssize) - resume_put(p0, 0, 0) - guard_true(i0) - leave_frame() - finish() - """ - expected = """ - [i0] - enter_frame(-1, descr=jitcode) - p0 = resume_new(descr=ssize) - resume_put(p0, 0, 0) - guard_true(i0) - leave_frame() - finish() - """ - self.optimize_loop(ops, expected) - def test_ooisnull_oononnull_via_virtual(self): ops = """ [p0] @@ -5139,3 +5118,78 @@ class TestLLtype(BaseTestOptimizeBasic, LLtypeMixin): pass + +class TestOptimizeResume(BaseTestBasic, LLtypeMixin): + def test_virtual_resume_info(self): + ops = """ + [i0] + enter_frame(-1, descr=jitcode) + p0 = new(descr=ssize) + resume_put(p0, 0, 0) + guard_true(i0) + leave_frame() + finish() + """ + expected = """ + [i0] + enter_frame(-1, descr=jitcode) + p0 = resume_new(descr=ssize) + resume_put(p0, 0, 0) + guard_true(i0) + leave_frame() + finish() + """ + self.optimize_loop(ops, expected) + + def test_virtual_resume_info_field(self): + ops = """ + [i0] + enter_frame(-1, descr=jitcode) + p0 = new(descr=ssize) + setfield_gc(p0, 3, descr=valuedescr) + resume_put(p0, 0, 0) + guard_true(i0) + leave_frame() + finish() + """ + expected = """ + [i0] + enter_frame(-1, descr=jitcode) + p0 = resume_new(descr=ssize) + resume_setfield_gc(p0, 3, descr=valuedescr) + resume_put(p0, 0, 0) + guard_true(i0) + leave_frame() + finish() + """ + self.optimize_loop(ops, expected) + + def test_forced_virtual(self): + ops = """ + [i0, i1] + enter_frame(-1, descr=jitcode) + p0 = new(descr=ssize) + setfield_gc(p0, 3, descr=valuedescr) + resume_put(p0, 0, 0) + guard_true(i0) + escape(p0) + guard_true(i1) + leave_frame() + finish() + """ + expected = """ + [i0, i1] + enter_frame(-1, descr=jitcode) + p0 = resume_new(descr=ssize) + resume_setfield_gc(p0, 3, descr=valuedescr) + resume_put(p0, 0, 0) + guard_true(i0) + p1 = new(descr=ssize) + setfield_gc(p1, 3, descr=valuedescr) + escape(p1) + resume_put(p1, 0, 0) + guard_true(i1) + leave_frame() + finish() + """ + self.optimize_loop(ops, expected) diff --git a/rpython/jit/metainterp/optimizeopt/virtualize.py b/rpython/jit/metainterp/optimizeopt/virtualize.py --- a/rpython/jit/metainterp/optimizeopt/virtualize.py +++ b/rpython/jit/metainterp/optimizeopt/virtualize.py @@ -19,6 +19,7 @@ level = optimizer.LEVEL_NONNULL is_about_raw = False _cached_vinfo = None + resume_box = None def __init__(self, keybox, source_op=None): self.keybox = keybox # only used as a key in dictionaries @@ -28,6 +29,11 @@ def is_forced_virtual(self): return self.box is not None + def get_resume_box(self): + if self.is_forced_virtual(): + return self.box + return self.resume_box + def get_key_box(self): if self.box is None: return self.keybox @@ -655,6 +661,9 @@ if value.is_virtual(): fieldvalue = self.getvalue(op.getarg(1)) + self.optimizer.resumebuilder.setfield(value.resume_box, + fieldvalue.get_resume_box(), + op.getdescr()) value.setfield(op.getdescr(), fieldvalue) else: value.ensure_nonnull() diff --git a/rpython/jit/metainterp/test/test_resume2.py b/rpython/jit/metainterp/test/test_resume2.py --- a/rpython/jit/metainterp/test/test_resume2.py +++ b/rpython/jit/metainterp/test/test_resume2.py @@ -156,7 +156,6 @@ assert f.registers_i[1].getint() == 2 + 3 def test_new(self): - py.test.skip("finish") jitcode1 = JitCode("jitcode") jitcode1.setup(num_regs_i=1, num_regs_r=0, num_regs_f=0) base = parse(""" @@ -167,6 +166,7 @@ backend_put(12, leave_frame() """, namespace={'jitcode':jitcode1}) + XXX def test_reconstructing_resume_reader(self): jitcode1 = JitCode("jitcode") _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit