[pypy-svn] r74632 - in pypy/branch/blackhole-improvement/pypy/jit: codewriter codewriter/test metainterp

arigo at codespeak.net arigo at codespeak.net
Fri May 21 16:29:35 CEST 2010


Author: arigo
Date: Fri May 21 16:29:33 2010
New Revision: 74632

Modified:
   pypy/branch/blackhole-improvement/pypy/jit/codewriter/jitcode.py
   pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_codewriter.py
   pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_jitcode.py
   pypy/branch/blackhole-improvement/pypy/jit/metainterp/pyjitpl.py
   pypy/branch/blackhole-improvement/pypy/jit/metainterp/resume.py
Log:
Progress.


Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/jitcode.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/jitcode.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/jitcode.py	Fri May 21 16:29:33 2010
@@ -51,32 +51,21 @@
                             registers_i, registers_r, registers_f):
         # 'pc' gives a position in this bytecode.  This invokes
         # 'callback' for each variable that is live across the
-        # instruction which ends at 'pc'.  (It excludes the arguments
-        # of that instruction which are no longer used afterwards, and
-        # excludes the return value of that instruction.)  More precisely,
-        # this invokes 'callback(arg, box, index)' where 'box' comes from one
-        # of the three lists of registers and 'index' is 0, 1, 2...
-        # If the callback returns a box, then it is stored back.
+        # instruction boundary at 'pc'.  More precisely,
+        # this invokes 'callback(arg, box)' where 'box' comes from one
+        # of the three lists of registers.
         if not we_are_translated() and pc not in self.liveness:
             self._missing_liveness(pc)
         live_i, live_r, live_f = self.liveness[pc]    # XXX compactify!!
-        index = 0
         for c in live_i:
-            newbox = callback(arg, registers_i[ord(c)], index)
-            index += 1
-            if newbox is not None:
-                registers_i[ord(c)] = newbox
+            x = callback(arg, registers_i[ord(c)])
+            assert x is None
         for c in live_r:
-            newbox = callback(arg, registers_r[ord(c)], index)
-            index += 1
-            if newbox is not None:
-                registers_r[ord(c)] = newbox
+            x = callback(arg, registers_r[ord(c)])
+            assert x is None
         for c in live_f:
-            newbox = callback(arg, registers_f[ord(c)], index)
-            index += 1
-            if newbox is not None:
-                registers_f[ord(c)] = newbox
-        return index
+            x = callback(arg, registers_f[ord(c)])
+            assert x is None
     enumerate_live_vars._annspecialcase_ = 'specialize:arg(2)'
 
     def _live_vars(self, pc):
@@ -86,10 +75,8 @@
                 self.kind = kind
             def __getitem__(self, index):
                 return '%%%s%d' % (self.kind, index)
-        def callback(lst, reg, index):
-            lst.append(reg)
         lst = []
-        self.enumerate_live_vars(pc, callback, lst,
+        self.enumerate_live_vars(pc, list.append, lst,
                                  Names('i'), Names('r'), Names('f'))
         lst.sort()
         return ' '.join(lst)

Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_codewriter.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_codewriter.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_codewriter.py	Fri May 21 16:29:33 2010
@@ -86,4 +86,4 @@
     blackholeinterp.setarg_i(0, 6)
     blackholeinterp.setarg_i(1, 100)
     blackholeinterp.run()
-    assert blackholeinterp.get_result_i() == 100+6+5+4+3
+    assert blackholeinterp.final_result_i() == 100+6+5+4+3

Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_jitcode.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_jitcode.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_jitcode.py	Fri May 21 16:29:33 2010
@@ -23,13 +23,12 @@
     assert not j.has_liveness_info(4)
     #
     seen = []
-    def callback(arg, value, index):
+    def callback(arg, value):
         assert arg == "foo"
-        seen.append((value, index))
+        seen.append(value)
     #
-    total = j.enumerate_live_vars(5, callback, "foo",
-                                  {ord(" "): "i10", ord("A"): "i20"},
-                                  {ord("b"): "r30"},
-                                  {ord("C"): "f40", ord("D"): "f50"})
-    assert total == 5
-    assert seen == [("i10", 0), ("i20", 1), ("r30", 2), ("f40", 3), ("f50", 4)]
+    j.enumerate_live_vars(5, callback, "foo",
+                          {ord(" "): "i10", ord("A"): "i20"},
+                          {ord("b"): "r30"},
+                          {ord("C"): "f40", ord("D"): "f50"})
+    assert seen == ["i10", "i20", "r30", "f40", "f50"]

Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/pyjitpl.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/pyjitpl.py	Fri May 21 16:29:33 2010
@@ -102,24 +102,43 @@
             outvalue[startindex+i] = reg
     prepare_list_of_boxes._annspecialcase_ = 'specialize:arg(4)'
 
-    def get_list_of_active_boxes(self):
+    def get_list_of_active_boxes(self, in_a_call):
+        if in_a_call:
+            # If we are not the topmost frame, self._result_argcode contains
+            # the type of the result of the call instruction in the bytecode.
+            # We use it to clear the box that will hold the result: this box
+            # is not defined yet.
+            argcode = self._result_argcode
+            index = ord(self.bytecode[self.pc - 1])
+            if   argcode == 'i': self.registers_i[index] = None
+            elif argcode == 'r': self.registers_r[index] = None
+            elif argcode == 'f': self.registers_f[index] = None
+        #
+        self._tmp_count = 0
         count = self.jitcode.enumerate_live_vars(
-            self.pc, MIFrame._count_boxes, None,
+            self.pc, MIFrame._count_boxes, self,
             self.registers_i, self.registers_r, self.registers_f)
-        env = [None] * count
+        #
+        self._tmp_env = [None] * self._tmp_count
+        self._tmp_count = 0
         self.jitcode.enumerate_live_vars(
-            self.pc, MIFrame._store_in_env, env,
+            self.pc, MIFrame._store_in_env, self,
             self.registers_i, self.registers_r, self.registers_f)
+        #
+        env = self._tmp_env
+        self._tmp_env = None
         make_sure_not_resized(env)
         return env
 
-    @staticmethod
-    def _count_boxes(_, box, index):
-        pass    # just used to count how many boxes there are
-
-    @staticmethod
-    def _store_in_env(env, box, index):
-        env[index] = box
+    def _count_boxes(self, box):
+        if box is not None:       # just used to count how many boxes there are
+            self._tmp_count += 1
+
+    def _store_in_env(self, box):
+        if box is not None:
+            index = self._tmp_count
+            self._tmp_env[index] = box
+            self._tmp_count = index + 1
 
     def replace_active_box_in_frame(self, oldbox, newbox):
         if isinstance(oldbox, history.BoxInt):
@@ -2033,7 +2052,14 @@
         num_return_args = len(argcodes) - next_argcode
         assert num_return_args == 0 or num_return_args == 2
         if num_return_args:
+            # Save the type of the resulting box.  This is needed if the
+            # operation is an inlined call and we need to get the list of
+            # all alive boxes in it, to know that the result box was not
+            # written yet.
+            self._result_argcode = argcodes[next_argcode + 1]
             position += 1
+        else:
+            self._result_argcode = 'v'
         self.pc = position
         #
         if not we_are_translated():

Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/resume.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/resume.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/resume.py	Fri May 21 16:29:33 2010
@@ -42,7 +42,7 @@
                                          back.pc)
     target.parent_resumedata_snapshot = Snapshot(
                                          back.parent_resumedata_snapshot,
-                                         back.get_list_of_active_boxes())
+                                         back.get_list_of_active_boxes(True))
 
 def capture_resumedata(framestack, virtualizable_boxes, virtualref_boxes,
                        storage):
@@ -53,7 +53,7 @@
                                 top.jitcode, top.pc)
     storage.rd_frame_info_list = frame_info_list
     snapshot = Snapshot(top.parent_resumedata_snapshot,
-                        top.get_list_of_active_boxes())
+                        top.get_list_of_active_boxes(False))
     snapshot = Snapshot(snapshot, virtualref_boxes[:]) # xxx for now
     if virtualizable_boxes is not None:
         snapshot = Snapshot(snapshot, virtualizable_boxes[:]) # xxx for now



More information about the Pypy-commit mailing list