Author: Maciej Fijalkowski <fij...@gmail.com>
Branch: resume-refactor
Changeset: r68722:fa61ebe921c8
Date: 2014-01-17 16:34 +0100
http://bitbucket.org/pypy/pypy/changeset/fa61ebe921c8/

Log:    (fijal, rguillebert) make resume_new tests pass

diff --git a/rpython/jit/codewriter/assembler.py 
b/rpython/jit/codewriter/assembler.py
--- a/rpython/jit/codewriter/assembler.py
+++ b/rpython/jit/codewriter/assembler.py
@@ -170,6 +170,7 @@
             elif isinstance(x, AbstractDescr):
                 if x not in self._descr_dict:
                     self._descr_dict[x] = len(self.descrs)
+                    x.global_descr_index = len(self.descrs)
                     self.descrs.append(x)
                 if isinstance(x, SwitchDictDescr):
                     self.switchdictdescrs.append(x)
diff --git a/rpython/jit/resume/backend.py b/rpython/jit/resume/backend.py
--- a/rpython/jit/resume/backend.py
+++ b/rpython/jit/resume/backend.py
@@ -2,7 +2,7 @@
 from rpython.jit.metainterp.resoperation import rop, ResOperation
 from rpython.jit.metainterp.history import ConstInt, Box, Const
 from rpython.jit.resume.rescode import ResumeBytecodeBuilder, TAGBOX,\
-     ResumeBytecode
+     ResumeBytecode, TAGVIRTUAL
 
             # if op.getopnum() == rop.ENTER_FRAME:
             #     descr = op.getdescr()
@@ -111,34 +111,40 @@
                     if box not in self.current_attachment:
                         self.current_attachment[box] = loc_pos
 
+    def get_box_pos(self, box):
+        if box in self.virtuals:
+            return TAGVIRTUAL | (self.virtuals[box] << 2)
+        if isinstance(box, Const):
+            return self.builder.encode_const(box)
+        try:
+            loc = self.regalloc.loc(box, 
must_exist=True).get_jitframe_position()
+            pos = self.builder.encode(TAGBOX, loc)
+            self.current_attachment[box] = pos
+            return pos
+        except KeyError:
+            raise
+
     def process(self, op):
         if op.getopnum() == rop.ENTER_FRAME:
             self.builder.enter_frame(op.getarg(0).getint(), op.getdescr())
         elif op.getopnum() == rop.RESUME_PUT:
             frame_pos = op.getarg(1).getint()
             pos_in_frame = op.getarg(2).getint()
-            box = op.getarg(0)
-            if box in self.virtuals:
-                xxx
-            if isinstance(box, Const):
-                pos = self.builder.encode_const(box)
-                self.builder.resume_put(pos, frame_pos, pos_in_frame)          
      
-                return
-            try:
-                loc = self.regalloc.loc(box, 
must_exist=True).get_jitframe_position()
-                pos = self.builder.encode(TAGBOX, loc)
-                self.builder.resume_put(pos, frame_pos, pos_in_frame) 
-            except KeyError:
-                xxx
-            self.current_attachment[box] = pos
-            self.frontend_pos[box] = (frame_pos, pos_in_frame)
+            pos = self.get_box_pos(op.getarg(0))
+            self.builder.resume_put(pos, frame_pos, pos_in_frame)
+            if pos & TAGBOX:
+                self.frontend_pos[op.getarg(0)] = (frame_pos, pos_in_frame)
         elif op.getopnum() == rop.LEAVE_FRAME:
             self.builder.leave_frame()
         elif op.getopnum() == rop.RESUME_NEW:
             v_pos = len(self.virtuals)
             self.virtuals[op.result] = v_pos
-            XXX
             self.builder.resume_new(v_pos, op.getdescr())
+        elif op.getopnum() == rop.RESUME_SETFIELD_GC:
+            structpos = self.get_box_pos(op.getarg(0))
+            fieldpos = self.get_box_pos(op.getarg(1))
+            descr = op.getdescr()
+            self.builder.resume_setfield_gc(structpos, fieldpos, descr)
         else:
             xxx
         return
diff --git a/rpython/jit/resume/reader.py b/rpython/jit/resume/reader.py
--- a/rpython/jit/resume/reader.py
+++ b/rpython/jit/resume/reader.py
@@ -71,6 +71,7 @@
         xxx
 
     def resume_new(self, box, descr):
+        xxx
         # XXX make it a list
         v = Virtual(len(self.virtual_list), descr)
         self.virtuals[box] = v
@@ -78,6 +79,7 @@
 
     def resume_setfield_gc(self, box, fieldbox, descr):
         # XXX optimize fields
+        xxx
         self.virtuals[box].fields[descr] = self.encode(fieldbox)
 
     def resume_clear(self, frame_no, frontend_position):
@@ -121,6 +123,18 @@
                 pos_in_frame = self.read(pos + 4)
                 self.resume_put(encoded, frame_pos, pos_in_frame)
                 pos += 5
+            elif op == rescode.RESUME_NEW:
+                tag, v_pos = self.decode(self.read_short(pos + 1))
+                assert tag == rescode.TAGVIRTUAL
+                descr = self.staticdata.opcode_descrs[self.read_short(pos + 3)]
+                self.resume_new(v_pos, descr)
+                pos += 5
+            elif op == rescode.RESUME_SETFIELD_GC:
+                structpos = self.read_short(pos + 1)
+                fieldpos = self.read_short(pos + 3)
+                descr = self.staticdata.opcode_descrs[self.read_short(pos + 5)]
+                self.resume_setfield_gc(structpos, fieldpos, descr)
+                pos += 7
             else:
                 xxx
         self.bytecode = None
@@ -141,5 +155,14 @@
         self.l.append("resume_put (%d, %d) %d %d" % (tag, index, frame_pos,
                                                      pos_in_frame))
 
+    def resume_new(self, v_pos, descr):
+        self.l.append("%d = resume_new %d" % (v_pos, descr.global_descr_index))
+
+    def resume_setfield_gc(self, structpos, fieldpos, descr):
+        stag, sindex = self.decode(structpos)
+        ftag, findex = self.decode(fieldpos)
+        self.l.append("resume_setfield_gc (%d, %d) (%d, %d) %d" % (
+            stag, sindex, ftag, findex, descr.global_descr_index))
+
     def finish(self):
         return "\n".join(self.l)
diff --git a/rpython/jit/resume/rescode.py b/rpython/jit/resume/rescode.py
--- a/rpython/jit/resume/rescode.py
+++ b/rpython/jit/resume/rescode.py
@@ -1,7 +1,8 @@
 
 from rpython.jit.metainterp.history import ConstInt
 
-UNUSED, ENTER_FRAME, LEAVE_FRAME, RESUME_PUT = range(4)
+(UNUSED, ENTER_FRAME, LEAVE_FRAME, RESUME_PUT,
+ RESUME_NEW, RESUME_SETFIELD_GC) = range(6)
 
 TAGCONST = 0x0
 TAGVIRTUAL = 0x2
@@ -64,3 +65,14 @@
         self.write_short(pos)
         self.write(frame_pos)
         self.write(pos_in_frame)
+
+    def resume_new(self, v_pos, descr):
+        self.write(RESUME_NEW)
+        self.write_short(self.encode(TAGVIRTUAL, v_pos))
+        self.write_short(descr.global_descr_index)
+
+    def resume_setfield_gc(self, structpos, fieldpos, descr):
+        self.write(RESUME_SETFIELD_GC)
+        self.write_short(structpos)
+        self.write_short(fieldpos)
+        self.write_short(descr.global_descr_index)
diff --git a/rpython/jit/resume/test/test_backend.py 
b/rpython/jit/resume/test/test_backend.py
--- a/rpython/jit/resume/test/test_backend.py
+++ b/rpython/jit/resume/test/test_backend.py
@@ -20,8 +20,9 @@
         return 'MockJitCode(%d)' % self.no
 
 class MockStaticData(object):
-    def __init__(self, *jitcodes):
-        self.alljitcodes = list(jitcodes)
+    def __init__(self, jitcodes, descrs):
+        self.alljitcodes = jitcodes
+        self.opcode_descrs = descrs
 
 def preparse(inp):
     return "\n".join([s.strip() for s in inp.split("\n") if s.strip()])
@@ -46,7 +47,7 @@
                               looptoken)
         descr = loop.operations[3].getdescr()
         assert descr.rd_bytecode_position == 15
-        staticdata = MockStaticData(None, jitcode)
+        staticdata = MockStaticData([None, jitcode], [])
         res = descr.rd_resume_bytecode.dump(staticdata,
                                             descr.rd_bytecode_position)
         expected_resume = preparse("""
@@ -62,7 +63,9 @@
         jitcode.setup(num_regs_i=1, num_regs_r=0, num_regs_f=0)
         S = lltype.GcStruct('S', ('field', lltype.Signed))
         structdescr = self.cpu.sizeof(S)
+        structdescr.global_descr_index = 0
         fielddescr = self.cpu.fielddescrof(S, 'field')
+        fielddescr.global_descr_index = 1
         namespace = {'jitcode':jitcode, 'structdescr':structdescr,
                      'fielddescr':fielddescr}
         loop = parse("""
@@ -79,18 +82,17 @@
         looptoken = JitCellToken()
         self.cpu.compile_loop(None, loop.inputargs, loop.operations,
                               looptoken)
-        xxx
+        staticdata = MockStaticData([None, jitcode], [structdescr, fielddescr])
+        descr = loop.operations[5].getdescr()
+        res = descr.rd_resume_bytecode.dump(staticdata,
+                                            descr.rd_bytecode_position)
         expected_resume = preparse("""
-        enter_frame -1 frame-1
-        p0 = resume_new(descr=structdescr)
-        resume_setfield_gc(p0, i0, descr=fielddescr)
-        resume_put(p0, 0, 0)
-        leave_frame()
-        """, namespace=namespace)
-        descr = loop.operations[-3].getdescr()
-        assert descr.rd_bytecode_position == 4
-        equaloplists(descr.rd_resume_bytecode.opcodes,
-                     expected_resume.operations)
+        enter_frame -1 name
+        0 = resume_new 0
+        resume_setfield_gc (2, 0) (3, 28) 1
+        resume_put (2, 0) 0 0
+        """)
+        assert res == expected_resume
 
     def test_spill(self):
         jitcode = JitCode("name")
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to