[pypy-svn] pypy jit-short-preamble: fixed tests and translation

hakanardo commits-noreply at bitbucket.org
Fri Jan 21 17:45:53 CET 2011


Author: Hakan Ardo <hakan at debian.org>
Branch: jit-short-preamble
Changeset: r41163:082d582b3617
Date: 2011-01-21 17:28 +0100
http://bitbucket.org/pypy/pypy/changeset/082d582b3617/

Log:	fixed tests and translation

diff --git a/pypy/jit/metainterp/optimizeopt/unroll.py b/pypy/jit/metainterp/optimizeopt/unroll.py
--- a/pypy/jit/metainterp/optimizeopt/unroll.py
+++ b/pypy/jit/metainterp/optimizeopt/unroll.py
@@ -167,6 +167,7 @@
 
             new_snapshot_args = []
             start_resumedescr = loop.preamble.start_resumedescr.clone_if_mutable()
+            assert isinstance(start_resumedescr, ResumeGuardDescr)
             snapshot_args = start_resumedescr.rd_snapshot.prev.boxes 
             for a in snapshot_args:
                 if not isinstance(a, Const):
@@ -195,19 +196,23 @@
                 short_loop.inputargs = loop.preamble.inputargs[:]
                 short_loop.operations = short
 
+                try:
+                    # Clone ops and boxes to get private versions and 
+                    newargs = [a.clonebox() for a in short_loop.inputargs]
+                    inliner = Inliner(short_loop.inputargs, newargs)
+                    short_loop.inputargs = newargs
+                    ops = [inliner.inline_op(op) for op in short_loop.operations]
+                    short_loop.operations = ops
+                except KeyError:
+                    debug_print("failed to clone short preamble, killing it instead")
+                    return
+
                 assert isinstance(loop.preamble.token, LoopToken)
                 if loop.preamble.token.short_preamble:
                     loop.preamble.token.short_preamble.append(short_loop)
                 else:
                     loop.preamble.token.short_preamble = [short_loop]
 
-                # Clone ops and boxes to get private versions and 
-                newargs = [a.clonebox() for a in short_loop.inputargs]
-                inliner = Inliner(short_loop.inputargs, newargs)
-                short_loop.inputargs = newargs
-                ops = [inliner.inline_op(op) for op in short_loop.operations]
-                short_loop.operations = ops
-
                 # Forget the values to allow them to be freed
                 for box in short_loop.inputargs:
                     box.forget_value()
@@ -215,38 +220,6 @@
                     if op.result:
                         op.result.forget_value()
                 
-                if False:
-                    boxmap = {}
-                    for i in range(len(short_loop.inputargs)):
-                        box = short_loop.inputargs[i]
-                        newbox = box.clonebox()
-                        boxmap[box] = newbox
-                        newbox.forget_value()
-                        short_loop.inputargs[i] = newbox
-                    for i in range(len(short)):
-                        oldop = short[i]
-                        op = oldop.clone()
-                        args = []
-                        for a in op.getarglist():
-                            if not isinstance(a, Const):
-                                a = boxmap[a]
-                            args.append(a)
-                        op.initarglist(args)
-                        if op.is_guard():
-                            args = []
-                            for a in op.getfailargs():
-                                if not isinstance(a, Const):
-                                    a = boxmap[a]
-                                args.append(a)
-                            op.setfailargs(args)
-                        box = op.result
-                        if box:
-                            newbox = box.clonebox()
-                            boxmap[box] = newbox
-                            newbox.forget_value()
-                            op.result = newbox
-                        short[i] = op
-                
 
     def inline(self, loop_operations, loop_args, jump_args):
         self.inliner = inliner = Inliner(loop_args, jump_args)
@@ -400,7 +373,10 @@
         for box in preamble.inputargs:
             seen[box] = True
         for op in short_preamble:
-            for box in op.getarglist():
+            args = op.getarglist()
+            if op.is_guard():
+                args = args + op.getfailargs()
+            for box in args:
                 if isinstance(box, Const):
                     continue
                 if box not in seen:

diff --git a/pypy/jit/metainterp/test/test_optimizeopt.py b/pypy/jit/metainterp/test/test_optimizeopt.py
--- a/pypy/jit/metainterp/test/test_optimizeopt.py
+++ b/pypy/jit/metainterp/test/test_optimizeopt.py
@@ -176,6 +176,13 @@
             metainterp_sd.virtualref_info = self.vrefinfo
         if hasattr(self, 'callinfocollection'):
             metainterp_sd.callinfocollection = self.callinfocollection
+        class FakeDescr(AbstractDescr):
+            class rd_snapshot:
+                class prev:
+                    boxes = []
+            def clone_if_mutable(self):
+                return self
+        loop.preamble.start_resumedescr = FakeDescr()
         optimize_loop_1(metainterp_sd, loop)
         #
 

diff --git a/pypy/jit/metainterp/test/test_compile.py b/pypy/jit/metainterp/test/test_compile.py
--- a/pypy/jit/metainterp/test/test_compile.py
+++ b/pypy/jit/metainterp/test/test_compile.py
@@ -86,7 +86,7 @@
     metainterp.history.inputargs = loop.inputargs[:]
     #
     loop_tokens = []
-    loop_token = compile_new_loop(metainterp, loop_tokens, [], 0)
+    loop_token = compile_new_loop(metainterp, loop_tokens, [], 0, None)
     assert loop_tokens == [loop_token]
     assert loop_token.number == 1
     assert staticdata.globaldata.loopnumbering == 2
@@ -102,7 +102,7 @@
     metainterp.history.operations = loop.operations[:]
     metainterp.history.inputargs = loop.inputargs[:]
     #
-    loop_token_2 = compile_new_loop(metainterp, loop_tokens, [], 0)
+    loop_token_2 = compile_new_loop(metainterp, loop_tokens, [], 0, None)
     assert loop_token_2 is loop_token
     assert loop_tokens == [loop_token]
     assert len(cpu.seen) == 0


More information about the Pypy-commit mailing list