[pypy-svn] r64707 - in pypy/branch/pyjitpl5/pypy/jit: backend backend/llgraph backend/test metainterp metainterp/test

arigo at codespeak.net arigo at codespeak.net
Sun Apr 26 20:26:09 CEST 2009


Author: arigo
Date: Sun Apr 26 20:26:08 2009
New Revision: 64707

Modified:
   pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/llimpl.py
   pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/runner.py
   pypy/branch/pyjitpl5/pypy/jit/backend/model.py
   pypy/branch/pyjitpl5/pypy/jit/backend/test/runner.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_recursive.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/warmspot.py
Log:
Use a custom interface to set the initial values to
cpu.execute_operations(), which is set_future_value_xxx(); this is
similar to the custom interface to fetch the values returned by a FAIL
operation, which is get_latest_value_xxx().

This allows us to remove the call to changevalue_xxx() in warmspot.py.


Modified: pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/llimpl.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/llimpl.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/llimpl.py	Sun Apr 26 20:26:08 2009
@@ -774,26 +774,30 @@
         frame = Frame(memocast)
     return _to_opaque(frame)
 
+_future_values = []
+
 def frame_clear(frame, loop):
     frame = _from_opaque(frame)
     loop = _from_opaque(loop)
     frame.loop = loop
     frame.env = {}
+    for i in range(len(loop.inputargs)):
+        frame.env[loop.inputargs[i]] = _future_values[i]
 
-def frame_add_int(frame, value):
-    frame = _from_opaque(frame)
-    i = len(frame.env)
-    frame.env[frame.loop.inputargs[i]] = value
-
-def frame_add_ptr(frame, value):
-    frame = _from_opaque(frame)
-    i = len(frame.env)
-    frame.env[frame.loop.inputargs[i]] = value
-
-def frame_add_obj(frame, value):
-    frame = _from_opaque(frame)
-    i = len(frame.env)
-    frame.env[frame.loop.inputargs[i]] = value
+def set_future_value_int(index, value):
+    del _future_values[index:]
+    assert len(_future_values) == index
+    _future_values.append(value)
+
+def set_future_value_ptr(index, value):
+    del _future_values[index:]
+    assert len(_future_values) == index
+    _future_values.append(value)
+
+def set_future_value_obj(index, value):
+    del _future_values[index:]
+    assert len(_future_values) == index
+    _future_values.append(value)
 
 def frame_execute(frame):
     frame = _from_opaque(frame)
@@ -1155,9 +1159,9 @@
 
 setannotation(new_frame, s_Frame)
 setannotation(frame_clear, annmodel.s_None)
-setannotation(frame_add_int, annmodel.s_None)
-setannotation(frame_add_ptr, annmodel.s_None)
-setannotation(frame_add_obj, annmodel.s_None)
+setannotation(set_future_value_int, annmodel.s_None)
+setannotation(set_future_value_ptr, annmodel.s_None)
+setannotation(set_future_value_obj, annmodel.s_None)
 setannotation(frame_execute, annmodel.SomeInteger())
 setannotation(frame_int_getvalue, annmodel.SomeInteger())
 setannotation(frame_ptr_getvalue, annmodel.SomePtr(llmemory.GCREF))

Modified: pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/runner.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/runner.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/runner.py	Sun Apr 26 20:26:08 2009
@@ -82,6 +82,7 @@
         llimpl._llinterp = LLInterpreter(self.rtyper)
         if translate_support_code:
             self.mixlevelann = annmixlevel
+        self._future_values = []
 
     def compile_operations(self, loop):
         """In a real assembler backend, this should assemble the given
@@ -152,34 +153,28 @@
             llimpl.compile_add_fail(c, len(self.fail_ops))
             self.fail_ops.append(op)
 
-    def execute_operations(self, loop, valueboxes):
+    def execute_operations(self, loop):
         """Calls the assembler generated for the given loop.
         Returns the ResOperation that failed, of type rop.FAIL.
         """
         frame = llimpl.new_frame(self.memo_cast, self.is_oo)
         # setup the frame
         llimpl.frame_clear(frame, loop._compiled_version)
-        for box in valueboxes:
-            if isinstance(box, history.BoxInt):
-                llimpl.frame_add_int(frame, box.value)
-            elif isinstance(box, history.BoxPtr):
-                llimpl.frame_add_ptr(frame, box.value)
-            elif self.is_oo and isinstance(box, history.BoxObj):
-                llimpl.frame_add_obj(frame, box.value)
-            elif isinstance(box, history.ConstInt):
-                llimpl.frame_add_int(frame, box.value)
-            elif isinstance(box, history.ConstPtr):
-                llimpl.frame_add_ptr(frame, box.value)
-            elif self.is_oo and isinstance(box, history.ConstObj):
-                llimpl.frame_add_obj(frame, box.value)
-            else:
-                raise Exception("bad box in valueboxes: %r" % (box,))
         # run the loop
         fail_index = llimpl.frame_execute(frame)
         # we hit a FAIL operation.
         self.latest_frame = frame
         return self.fail_ops[fail_index]
 
+    def set_future_value_int(self, index, intvalue):
+        llimpl.set_future_value_int(index, intvalue)
+
+    def set_future_value_ptr(self, index, ptrvalue):
+        llimpl.set_future_value_ptr(index, ptrvalue)
+
+    def set_future_value_obj(self, index, objvalue):
+        llimpl.set_future_value_obj(index, objvalue)
+
     def get_latest_value_int(self, index):
         return llimpl.frame_int_getvalue(self.latest_frame, index)
 

Modified: pypy/branch/pyjitpl5/pypy/jit/backend/model.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/model.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/model.py	Sun Apr 26 20:26:08 2009
@@ -4,12 +4,25 @@
         """Assemble the given list of operations."""
         raise NotImplementedError
 
-    def execute_operations(self, loop, valueboxes):
+    def execute_operations(self, loop):
         """Calls the assembler generated for the given loop.
         Returns the ResOperation that failed, of type rop.FAIL.
+        Use set_future_value_xxx() before, and get_latest_value_xxx() after.
         """
         raise NotImplementedError
 
+    def set_future_value_int(self, index, intvalue):
+        """Set the value for the index'th argument for the loop to run."""
+        raise NotImplementedError
+
+    def set_future_value_ptr(self, index, ptrvalue):
+        """Set the value for the index'th argument for the loop to run."""
+        raise NotImplementedError
+
+    def set_future_value_obj(self, index, objvalue):
+        """Set the value for the index'th argument for the loop to run."""
+        raise NotImplementedError
+
     def get_latest_value_int(self, index):
         """Returns the value for the index'th argument to the
         lastest rop.FAIL.  Returns an int."""

Modified: pypy/branch/pyjitpl5/pypy/jit/backend/test/runner.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/test/runner.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/test/runner.py	Sun Apr 26 20:26:08 2009
@@ -23,8 +23,18 @@
     def execute_operation(self, opname, valueboxes, result_type, descr=None):
         loop = self.get_compiled_single_operation(opname, result_type,
                                                   valueboxes, descr)
-        boxes = [box for box in valueboxes if isinstance(box, Box)]
-        res = self.cpu.execute_operations(loop, boxes)
+        j = 0
+        for box in valueboxes:
+            if isinstance(box, BoxInt):
+                self.cpu.set_future_value_int(j, box.getint())
+                j += 1
+            elif isinstance(box, BoxPtr):
+                self.cpu.set_future_value_ptr(j, box.getptr_base())
+                j += 1
+            elif isinstance(box, BoxObj):
+                self.cpu.set_future_value_obj(j, box.getobj())
+                j += 1
+        res = self.cpu.execute_operations(loop)
         if res is loop.operations[-1]:
             self.guard_failed = False
         else:
@@ -209,7 +219,9 @@
             loop.inputargs = [v1, v2]
             self.cpu.compile_operations(loop)
             for x, y, z in testcases:
-                op = self.cpu.execute_operations(loop, [BoxInt(x), BoxInt(y)])
+                self.cpu.set_future_value_int(0, x)
+                self.cpu.set_future_value_int(1, y)
+                op = self.cpu.execute_operations(loop)
                 if z == boom:
                     assert op is ops[1].suboperations[0]
                 else:

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py	Sun Apr 26 20:26:08 2009
@@ -1105,7 +1105,20 @@
         num_green_args = self.staticdata.num_green_args
         residual_args = self.get_residual_args(loop,
                                                gmp.argboxes[num_green_args:])
-        return (loop, residual_args)
+        j = 0
+        cpu = self.cpu
+        for box in residual_args:
+            if isinstance(box, BoxInt) or isinstance(box, ConstInt):
+                cpu.set_future_value_int(j, box.getint())
+            elif isinstance(box, BoxPtr) or isinstance(box, ConstPtr):
+                cpu.set_future_value_ptr(j, box.getptr_base())
+            elif cpu.is_oo and (isinstance(box, BoxObj) or
+                                isinstance(box, ConstObj)):
+                cpu.set_future_value_obj(j, box.getobj())
+            else:
+                assert False
+            j += 1
+        return loop
 
     def prepare_resume_from_failure(self, opnum):
         if opnum == rop.GUARD_TRUE:     # a goto_if_not that jumps only now

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_recursive.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_recursive.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_recursive.py	Sun Apr 26 20:26:08 2009
@@ -1,6 +1,7 @@
 import py
 from pypy.rlib.jit import JitDriver
 from pypy.jit.metainterp.test.test_basic import LLJitMixin
+from pypy.jit.metainterp.simple_optimize import Optimizer
 
 
 class RecursiveTests:
@@ -20,7 +21,7 @@
                 return f(n+1)
             else:
                 return 1
-        res = self.meta_interp(main, [20])
+        res = self.meta_interp(main, [20], optimizer=Optimizer)
         assert res == main(20)
 
     def test_recursion_three_times(self):
@@ -43,7 +44,7 @@
         print
         for i in range(1, 11):
             print '%3d %9d' % (i, f(i))
-        res = self.meta_interp(main, [10])
+        res = self.meta_interp(main, [10], optimizer=Optimizer)
         assert res == main(10)
         self.check_enter_count_at_most(10)
 

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/warmspot.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/warmspot.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/warmspot.py	Sun Apr 26 20:26:08 2009
@@ -204,11 +204,14 @@
         args = op.args[2:]
         ALLARGS = []
         self.green_args_spec = []
+        self.red_args_types = []
         for i, v in enumerate(args):
             TYPE = v.concretetype
             ALLARGS.append(TYPE)
             if i < len(self.jitdriver.greens):
                 self.green_args_spec.append(TYPE)
+            else:
+                self.red_args_types.append(history.getkind(TYPE)[0])
         RESTYPE = graph.getreturnvar().concretetype
         (self.JIT_ENTER_FUNCTYPE,
          self.PTR_JIT_ENTER_FUNCTYPE) = self.ts.get_FuncType(ALLARGS, lltype.Void)
@@ -442,7 +445,7 @@
     warmrunnerdesc.num_green_args = num_green_args
     green_args_spec = unrolling_iterable(warmrunnerdesc.green_args_spec)
     green_args_names = unrolling_iterable(jitdriver.greens)
-    red_args_index = unrolling_iterable(range(len(jitdriver.reds)))
+    red_args_types = unrolling_iterable(warmrunnerdesc.red_args_types)
     if num_green_args:
         MAX_HASH_TABLE_BITS = 28
     else:
@@ -470,24 +473,22 @@
                     return False
                 i = i + 1
             return True
-        def fill_boxes(self, *redargs):
-            boxes = self.bridge.inputargs
-            for j in red_args_index:
+        def set_future_values(self, cpu, *redargs):
+            j = 0
+            for typecode in red_args_types:
                 value = redargs[j]
-                box = boxes[j]
-                TYPE = lltype.typeOf(value)
-                if isinstance(TYPE, lltype.Ptr):
-                    assert isinstance(box, history.BoxPtr)
-                    box.changevalue_ptr(lltype.cast_opaque_ptr(llmemory.GCREF, value))
-                elif isinstance(TYPE, ootype.OOType):
-                    assert isinstance(box, history.BoxObj)
-                    box.changevalue_obj(ootype.cast_to_object(value))
-                elif TYPE == lltype.Signed:
-                    assert isinstance(box, history.BoxInt)
-                    box.changevalue_int(value)
+                if typecode == 'p':
+                    ptrvalue = lltype.cast_opaque_ptr(llmemory.GCREF, value)
+                    cpu.set_future_value_ptr(j, ptrvalue)
+                elif typecode == 'o':
+                    objvalue = ootype.cast_to_object(value)
+                    cpu.set_future_value_obj(j, objvalue)
+                elif typecode == 'i':
+                    intvalue = lltype.cast_primitive(lltype.Signed, value)
+                    cpu.set_future_value_int(j, intvalue)
                 else:
-                    raise AssertionError("box is: %s" % (box,))
-            return boxes
+                    assert False
+                j = j + 1
 
     class WarmEnterState:
         def __init__(self):
@@ -534,27 +535,26 @@
                 #interp.debug_trace("jit_compile", *greenargs)
                 metainterp_sd = warmrunnerdesc.metainterp_sd
                 metainterp = MetaInterp(metainterp_sd)
-                loop, boxes = metainterp.compile_and_run_once(*args)
+                loop = metainterp.compile_and_run_once(*args)
             else:
                 # machine code was already compiled for these greenargs
                 # (or we have a hash collision)
                 assert isinstance(cell, MachineCodeEntryPoint)
                 if not cell.equalkey(*greenargs):
                     # hash collision
-                    loop, boxes = self.handle_hash_collision(cell, argshash,
-                                                             *args)
+                    loop = self.handle_hash_collision(cell, argshash, *args)
                     if loop is None:
                         return
                 else:
                     # get the assembler and fill in the boxes
+                    cpu = warmrunnerdesc.metainterp_sd.cpu
+                    cell.set_future_values(cpu, *args[num_green_args:])
                     loop = cell.bridge
-                    boxes = cell.fill_boxes(*args[num_green_args:])
             # ---------- execute assembler ----------
             while True:     # until interrupted by an exception
                 metainterp_sd = warmrunnerdesc.metainterp_sd
-                fail_op = metainterp_sd.cpu.execute_operations(loop, boxes)
-                loop, boxes = fail_op.descr.handle_fail_op(metainterp_sd,
-                                                           fail_op)
+                fail_op = metainterp_sd.cpu.execute_operations(loop)
+                loop = fail_op.descr.handle_fail_op(metainterp_sd, fail_op)
         maybe_compile_and_run._dont_inline_ = True
 
         def handle_hash_collision(self, cell, argshash, *args):
@@ -567,15 +567,16 @@
                     cell.next = next.next
                     next.next = self.cells[argshash]
                     self.cells[argshash] = next
-                    return (next.bridge,
-                            next.fill_boxes(*args[num_green_args:]))
+                    cpu = warmrunnerdesc.metainterp_sd.cpu
+                    next.set_future_values(cpu, *args[num_green_args:])
+                    return next.bridge
                 cell = next
                 next = cell.next
             # not found at all, do profiling
             n = next.counter + 1
             if n < self.threshold:
                 cell.next = Counter(n)
-                return (None, None)
+                return None
             metainterp_sd = warmrunnerdesc.metainterp_sd
             metainterp = MetaInterp(metainterp_sd)
             return metainterp.compile_and_run_once(*args)



More information about the Pypy-commit mailing list