[pypy-svn] r70726 - in pypy/branch/direct-assembler-call/pypy/jit/metainterp: . test

fijal at codespeak.net fijal at codespeak.net
Wed Jan 20 14:30:54 CET 2010


Author: fijal
Date: Wed Jan 20 14:30:54 2010
New Revision: 70726

Modified:
   pypy/branch/direct-assembler-call/pypy/jit/metainterp/history.py
   pypy/branch/direct-assembler-call/pypy/jit/metainterp/pyjitpl.py
   pypy/branch/direct-assembler-call/pypy/jit/metainterp/test/test_history.py
   pypy/branch/direct-assembler-call/pypy/jit/metainterp/test/test_recursive.py
Log:
(pedronis, fijal) A bit of obscure interface, but pass the virtualizable test
of direct assembler call.


Modified: pypy/branch/direct-assembler-call/pypy/jit/metainterp/history.py
==============================================================================
--- pypy/branch/direct-assembler-call/pypy/jit/metainterp/history.py	(original)
+++ pypy/branch/direct-assembler-call/pypy/jit/metainterp/history.py	Wed Jan 20 14:30:54 2010
@@ -802,19 +802,30 @@
 
 
 class History(object):
-    def __init__(self, cpu):
-        self.cpu = cpu
+    def __init__(self):
         self.inputargs = None
         self.operations = []
+
     def record(self, opnum, argboxes, resbox, descr=None):
         op = ResOperation(opnum, argboxes, resbox, descr)
         self.operations.append(op)
         return op
+
     def substitute_operation(self, position, opnum, argboxes, descr=None):
         resbox = self.operations[position].result
         op = ResOperation(opnum, argboxes, resbox, descr)
         self.operations[position] = op
 
+    def slice_history_at(self, position):
+        """ a strange function that does this:
+        history : operation_at_position : rest
+        it'll kill operation_at_position, store everything before that
+        in history.operations and return rest
+        """
+        rest = self.operations[position + 1:]
+        del self.operations[position:]
+        return rest
+
 # ____________________________________________________________
 
 

Modified: pypy/branch/direct-assembler-call/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/direct-assembler-call/pypy/jit/metainterp/pyjitpl.py	(original)
+++ pypy/branch/direct-assembler-call/pypy/jit/metainterp/pyjitpl.py	Wed Jan 20 14:30:54 2010
@@ -675,6 +675,13 @@
         if token is not None:
             call_position = len(self.metainterp.history.operations)
         res = self.do_residual_call(varargs, descr=calldescr, exc=True)
+        # XXX fix the call position, <UGLY!>
+        while True:
+            op = self.metainterp.history.operations[call_position]
+            if op.opnum == rop.CALL or op.opnum == rop.CALL_MAY_FORCE:
+                break
+            call_position += 1
+        # </UGLY!>
         if token is not None:
             # this will substitute the residual call with assembler call
             self.metainterp.direct_assembler_call(varargs, token, call_position)
@@ -1357,7 +1364,7 @@
 
     def create_empty_history(self):
         warmrunnerstate = self.staticdata.state
-        self.history = history.History(self.cpu)
+        self.history = history.History()
         self.staticdata.stats.set_history(self.history)
 
     def _all_constants(self, *boxes):
@@ -1746,7 +1753,7 @@
         self.in_recursion = -1 # always one portal around
         inputargs_and_holes = self.cpu.make_boxes_from_latest_values(resumedescr)
         if must_compile:
-            self.history = history.History(self.cpu)
+            self.history = history.History()
             self.history.inputargs = [box for box in inputargs_and_holes if box]
             self.staticdata.profiler.start_tracing()
         else:
@@ -1958,6 +1965,23 @@
                                             abox, ConstInt(j), itembox)
             assert i + 1 == len(self.virtualizable_boxes)
 
+    def gen_load_from_other_virtualizable(self, vbox):
+        vinfo = self.staticdata.virtualizable_info
+        boxes = []
+        assert vinfo is not None
+        for i in range(vinfo.num_static_extra_boxes):
+            descr = vinfo.static_field_descrs[i]
+            boxes.append(self.execute_and_record(rop.GETFIELD_GC, descr, vbox))
+        virtualizable = vinfo.unwrap_virtualizable_box(vbox)
+        for k in range(vinfo.num_arrays):
+            descr = vinfo.array_field_descrs[k]
+            abox = self.execute_and_record(rop.GETFIELD_GC, descr, vbox)
+            descr = vinfo.array_descrs[k]
+            for j in range(vinfo.get_array_length(virtualizable, k)):
+                boxes.append(self.execute_and_record(rop.GETARRAYITEM_GC, descr,
+                                                     abox, ConstInt(j)))
+        return boxes
+
     def replace_box(self, oldbox, newbox):
         for frame in self.framestack:
             boxes = frame.env
@@ -2003,10 +2027,15 @@
         """
         assert not self.is_blackholing() # XXX
         num_green_args = self.staticdata.num_green_args
-        assert self.staticdata.virtualizable_info is None # XXX
         args = varargs[num_green_args + 1:]
-        self.history.substitute_operation(call_position, rop.CALL_ASSEMBLER,
-                                          args, descr=token)
+        resbox = self.history.operations[call_position].result
+        rest = self.history.slice_history_at(call_position)
+        if self.staticdata.virtualizable_info is not None:
+            vindex = self.staticdata.virtualizable_info.index_of_virtualizable
+            vbox = args[vindex - num_green_args]
+            args += self.gen_load_from_other_virtualizable(vbox)
+        self.history.record(rop.CALL_ASSEMBLER, args, resbox, descr=token)
+        self.history.operations += rest
 
 class GenerateMergePoint(Exception):
     def __init__(self, args, target_loop_token):

Modified: pypy/branch/direct-assembler-call/pypy/jit/metainterp/test/test_history.py
==============================================================================
--- pypy/branch/direct-assembler-call/pypy/jit/metainterp/test/test_history.py	(original)
+++ pypy/branch/direct-assembler-call/pypy/jit/metainterp/test/test_history.py	Wed Jan 20 14:30:54 2010
@@ -9,3 +9,10 @@
     s = lltype.cast_pointer(lltype.Ptr(S), t)
     const = ConstPtr(lltype.cast_opaque_ptr(llmemory.GCREF, s))
     assert const._getrepr_() == "*T"
+
+def test_slicing():
+    h = History()
+    h.operations = [1, 2, 3, 4, 5]
+    rest = h.slice_history_at(2)
+    assert rest == [4, 5]
+    assert h.operations == [1, 2]

Modified: pypy/branch/direct-assembler-call/pypy/jit/metainterp/test/test_recursive.py
==============================================================================
--- pypy/branch/direct-assembler-call/pypy/jit/metainterp/test/test_recursive.py	(original)
+++ pypy/branch/direct-assembler-call/pypy/jit/metainterp/test/test_recursive.py	Wed Jan 20 14:30:54 2010
@@ -736,8 +736,36 @@
         res = self.meta_interp(portal, [2, 0], inline=True)
         assert res == portal(2, 0)
 
+    def test_directly_call_assembler_virtualizable(self):
+        class Thing(object):
+            def __init__(self, val):
+                self.val = val
+        
+        class Frame(object):
+            _virtualizable2_ = ['thing']
+        
+        driver = JitDriver(greens = ['codeno'], reds = ['frame'],
+                           virtualizables = ['frame'],
+                           get_printable_location = lambda codeno : str(codeno),
+                           can_inline = lambda codeno : False)
+
+        def portal(codeno):
+            frame = Frame()
+            frame.thing = Thing(0)
+            while frame.thing.val < 10:
+                driver.can_enter_jit(frame=frame, codeno=codeno)
+                driver.jit_merge_point(frame=frame, codeno=codeno)
+                if codeno == 0:
+                    subframe = Frame()
+                    subframe.thing = Thing(frame.thing.val)
+                    portal(1)
+                frame.thing = Thing(frame.thing.val + 1)
+
+        self.meta_interp(portal, [0], inline=True)
+
 class TestLLtype(RecursiveTests, LLJitMixin):
     pass
 
 class TestOOtype(RecursiveTests, OOJitMixin):
     pass
+    



More information about the Pypy-commit mailing list