[pypy-svn] r51373 - in pypy/branch/jit-refactoring/pypy/jit: rainbow rainbow/test timeshifter/test

cfbolz at codespeak.net cfbolz at codespeak.net
Sun Feb 10 17:47:25 CET 2008


Author: cfbolz
Date: Sun Feb 10 17:47:23 2008
New Revision: 51373

Added:
   pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_vdict.py
      - copied, changed from r51125, pypy/branch/jit-refactoring/pypy/jit/timeshifter/test/test_vdict.py
   pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_vlist.py
      - copied, changed from r51125, pypy/branch/jit-refactoring/pypy/jit/timeshifter/test/test_vlist.py
Removed:
   pypy/branch/jit-refactoring/pypy/jit/timeshifter/test/test_vdict.py
   pypy/branch/jit-refactoring/pypy/jit/timeshifter/test/test_vlist.py
Modified:
   pypy/branch/jit-refactoring/pypy/jit/rainbow/codewriter.py
   pypy/branch/jit-refactoring/pypy/jit/rainbow/interpreter.py
   pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_interpreter.py
   pypy/branch/jit-refactoring/pypy/jit/timeshifter/test/test_timeshift.py
Log:
some reshuffling of tests


Modified: pypy/branch/jit-refactoring/pypy/jit/rainbow/codewriter.py
==============================================================================
--- pypy/branch/jit-refactoring/pypy/jit/rainbow/codewriter.py	(original)
+++ pypy/branch/jit-refactoring/pypy/jit/rainbow/codewriter.py	Sun Feb 10 17:47:23 2008
@@ -456,7 +456,12 @@
             else:
                 self.register_redvar(result, self.redvar_position(arg))
             return
-        XXX
+        if "deepfreeze" in hints:
+            if self.varcolor(result) == "red":
+                self.register_redvar(result, self.redvar_position(arg))
+            else:
+                self.register_greenvar(result, self.green_position(arg))
+            return
 
     def args_of_call(self, args, colored_as):
         result = []
@@ -472,10 +477,10 @@
         pass
 
     def serialize_op_direct_call(self, op):
+        kind, exc = self.guess_call_kind(op)
         targets = dict(self.graphs_from(op))
         assert len(targets) == 1
         targetgraph, = targets.values()
-        kind, exc = self.guess_call_kind(op)
         if kind == "red" or kind == "gray":
             graphindex = self.graph_position(targetgraph)
             args = targetgraph.getargs()
@@ -642,6 +647,7 @@
         self.register_redvar(op.result)
 
     def serialize_op_getinteriorfield(self, op):
+        color = self.opcolor(op)
         structvar = op.args[0]
         PTRTYPE = structvar.concretetype
         # no virtualizable access read here
@@ -657,11 +663,14 @@
         indexes = []
         for arg in indices_v:
             indexes.append(self.serialize_oparg("red", arg))
-        self.emit("red_getinteriorfield", structindex, interiordescindex,
-                  deepfrozen)
+        self.emit("%s_getinteriorfield" % color, structindex,
+                  interiordescindex, deepfrozen)
         self.emit(len(indexes))
         self.emit(*indexes)
-        self.register_redvar(op.result)
+        if color == "red":
+            self.register_redvar(op.result)
+        else:
+            self.register_greenvar(op.result)
 
     def serialize_op_setinteriorfield(self, op):
         structvar = op.args[0]
@@ -688,10 +697,10 @@
         interiordescindex, indices_v = self.interiordesc(
                 op, PTRTYPE, len(op.args) - 1)
         assert interiordescindex != -1
-        structindex = self.serialize_oparg(color, structvar)
+        structindex = self.serialize_oparg("red", structvar)
         indexes = []
         for arg in indices_v:
-            indexes.append(self.serialize_oparg(color, arg))
+            indexes.append(self.serialize_oparg("red", arg))
         self.emit("%s_getinteriorarraysize" % color, structindex,
                   interiordescindex)
         self.emit(len(indexes))

Modified: pypy/branch/jit-refactoring/pypy/jit/rainbow/interpreter.py
==============================================================================
--- pypy/branch/jit-refactoring/pypy/jit/rainbow/interpreter.py	(original)
+++ pypy/branch/jit-refactoring/pypy/jit/rainbow/interpreter.py	Sun Feb 10 17:47:23 2008
@@ -163,6 +163,7 @@
         self.frame.local_boxes.append(box)
 
     def green_result(self, gv):
+        assert gv.is_const
         self.frame.local_green.append(gv)
 
     def newjitstate(self, newjitstate):
@@ -403,6 +404,16 @@
                                                      structbox, indexboxes)
         self.red_result(resultbox)
 
+    def opimpl_green_getinteriorfield(self):
+        structbox = self.get_redarg()
+        interiordesc = self.frame.bytecode.interiordescs[self.load_2byte()]
+        deepfrozen = self.load_bool()
+        indexboxes = self.get_red_varargs()
+        resultbox = interiordesc.gengetinteriorfield(self.jitstate, deepfrozen,
+                                                     structbox, indexboxes)
+        assert resultbox.is_constant()
+        self.green_result(resultbox.getgenvar(self.jitstate))
+
     def opimpl_red_setinteriorfield(self):
         destbox = self.get_redarg()
         interiordesc = self.frame.bytecode.interiordescs[self.load_2byte()]
@@ -419,12 +430,15 @@
         self.red_result(resultbox)
 
     def opimpl_green_getinteriorarraysize(self):
-        arraygenconst = self.get_greenarg()
+        # XXX make a green version that does not use the constant folding of
+        # the red one
+        arraybox = self.get_redarg()
         interiordesc = self.frame.bytecode.interiordescs[self.load_2byte()]
-        indexgenconsts = self.get_green_varargs()
+        indexboxes = self.get_red_varargs()
         resultbox = interiordesc.gengetinteriorarraysize(
             self.jitstate, arraybox, indexboxes)
-        self.red_result(resultbox)
+        assert resultbox.is_constant()
+        self.green_result(resultbox.getgenvar(self.jitstate))
     # ____________________________________________________________
     # construction-time interface
 

Modified: pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_interpreter.py
==============================================================================
--- pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_interpreter.py	(original)
+++ pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_interpreter.py	Sun Feb 10 17:47:23 2008
@@ -18,6 +18,8 @@
 from pypy.rlib.objectmodel import keepalive_until_here
 from pypy import conftest
 
+P_NOVIRTUAL = HintAnnotatorPolicy(novirtualcontainer=True)
+
 def getargtypes(annotator, values):
     return [annotation(annotator, x) for x in values]
 
@@ -47,7 +49,8 @@
         del cls._cache
         del cls._cache_order
 
-    def serialize(self, func, values, backendoptimize=False):
+    def serialize(self, func, values, policy=None,
+                  inline=None, backendoptimize=False):
         key = func, backendoptimize
         try:
             cache, argtypes = self._cache[key]
@@ -68,13 +71,18 @@
         rtyper = t.buildrtyper(type_system = self.type_system)
         rtyper.specialize()
         self.rtyper = rtyper
+        if inline:
+            from pypy.translator.backendopt.inline import auto_inlining
+            auto_inlining(t, threshold=inline)
         if backendoptimize:
             from pypy.translator.backendopt.all import backend_optimizations
             backend_optimizations(t)
         graph1 = graphof(t, func)
 
         # build hint annotator types
-        hannotator = HintAnnotator(base_translator=t, policy=P_OOPSPEC_NOVIRTUAL)
+        if policy is None:
+            policy = P_OOPSPEC_NOVIRTUAL
+        hannotator = HintAnnotator(base_translator=t, policy=policy)
         hs = hannotator.build_types(graph1, [SomeLLAbstractConstant(v.concretetype,
                                                                     {OriginFlags(): True})
                                              for v in graph1.getargs()])
@@ -117,7 +125,8 @@
             assert len(ll_function.convert_arguments) == len(values)
             values = [decoder(value) for decoder, value in zip(
                                         ll_function.convert_arguments, values)]
-        writer, jitcode, argcolors = self.serialize(ll_function, values)
+        writer, jitcode, argcolors = self.serialize(ll_function, values,
+                                                    **kwds)
         rgenop = writer.RGenOp()
         sigtoken = rgenop.sigToken(self.RESIDUAL_FUNCTYPE)
         builder, gv_generated, inputargs_gv = rgenop.newgraph(sigtoken, "generated")
@@ -697,8 +706,7 @@
         res = self.interpret(ll_function, [], [])
         assert res.x == 123
 
-    def test_plus_minus_all_inlined(self):
-        py.test.skip("arrays and structs are not working")
+    def test_plus_minus(self):
         def ll_plus_minus(s, x, y):
             acc = x
             n = len(s)
@@ -903,5 +911,169 @@
         assert res == True
         self.check_insns({'setfield': 2, 'getfield': 1})
 
+    def test_deepfrozen_interior(self):
+        T = lltype.Struct('T', ('x', lltype.Signed))
+        A = lltype.Array(T)
+        S = lltype.GcStruct('S', ('a', A))
+        s = lltype.malloc(S, 3, zero=True)
+        s.a[2].x = 42
+        def f(n):
+            s1 = hint(s, variable=True)
+            s1 = hint(s1, deepfreeze=True)
+            return s1.a[n].x
+
+        # malloc-remove the interior ptr
+        res = self.interpret(f, [2], [0], backendoptimize=True)
+        assert res == 42
+        self.check_insns({})
+
+    def test_compile_time_const_tuple(self):
+        py.test.skip("no clue what's wrong")
+        d = {(4, 5): 42, (6, 7): 12}
+        def f(a, b):
+            d1 = hint(d, deepfreeze=True)
+            return d1[a, b]
+
+        # malloc-remove the interior ptr
+        res = self.interpret(f, [4, 5], [0, 1],
+                             backendoptimize=True)
+        assert res == 42
+        self.check_insns({})
+
+    def test_residual_red_call(self):
+        py.test.skip("needs promote")
+        def g(x):
+            return x+1
+
+        def f(x):
+            return 2*g(x)
+
+        res = self.interpret(f, [20], [], policy=StopAtXPolicy(g))
+        assert res == 42
+        self.check_insns(int_add=0)
+
+    def test_residual_red_call_with_exc(self):
+        py.test.skip("needs promote")
+        def h(x):
+            if x > 0:
+                return x+1
+            else:
+                raise ValueError
+
+        def g(x):
+            return 2*h(x)
+
+        def f(x):
+            try:
+                return g(x)
+            except ValueError:
+                return 7
+
+        stop_at_h = StopAtXPolicy(h)
+        res = self.interpret(f, [20], [], policy=stop_at_h)
+        assert res == 42
+        self.check_insns(int_add=0)
+
+        res = self.interpret(f, [-20], [], policy=stop_at_h)
+        assert res == 7
+        self.check_insns(int_add=0)
+
+    def test_red_call_ignored_result(self):
+        def g(n):
+            return n * 7
+        def f(n, m):
+            g(n)   # ignore the result
+            return m
+
+        res = self.interpret(f, [4, 212], [], policy=P_NOVIRTUAL)
+        assert res == 212
+
+    def test_simple_meth(self):
+        py.test.skip("needs promote")
+        class Base(object):
+            def m(self):
+                raise NotImplementedError
+            pass  # for inspect.getsource() bugs
+
+        class Concrete(Base):
+            def m(self):
+                return 42
+            pass  # for inspect.getsource() bugs
+
+        def f(flag):
+            if flag:
+                o = Base()
+            else:
+                o = Concrete()
+            return o.m()
+
+        res = self.interpret(f, [0], [0], policy=P_NOVIRTUAL)
+        assert res == 42
+        self.check_insns({})
+
+        res = self.interpret(f, [0], [], policy=P_NOVIRTUAL)
+        assert res == 42
+        self.check_insns(indirect_call=0)
+
+    def test_simple_red_meth(self):
+        py.test.skip("needs promote")
+        class Base(object):
+            def m(self, n):
+                raise NotImplementedError
+            pass  # for inspect.getsource() bugs
+
+        class Concrete(Base):
+            def m(self, n):
+                return 21*n
+            pass  # for inspect.getsource() bugs
+
+        def f(flag, x):
+            if flag:
+                o = Base()
+            else:
+                o = Concrete()
+            return o.m(x)
+
+        res = self.interpret(f, [0, 2], [0], policy=P_NOVIRTUAL)
+        assert res == 42
+        self.check_insns({'int_mul': 1})
+
+    def test_simple_red_meth_vars_around(self):
+        py.test.skip("needs promote")
+        class Base(object):
+            def m(self, n):
+                raise NotImplementedError
+            pass  # for inspect.getsource() bugs
+
+        class Concrete(Base):
+            def m(self, n):
+                return 21*n
+            pass  # for inspect.getsource() bugs
+
+        def f(flag, x, y, z):
+            if flag:
+                o = Base()
+            else:
+                o = Concrete()
+            return (o.m(x)+y)-z
+
+        res = self.interpret(f, [0, 2, 7, 5], [0], policy=P_NOVIRTUAL)
+        assert res == 44
+        self.check_insns({'int_mul': 1, 'int_add': 1, 'int_sub': 1})
+
+    def test_green_red_mismatch_in_call(self):
+        #py.test.skip("WIP")
+        def add(a,b, u):
+            return a+b
+
+        def f(x, y, u):
+            r = add(x+1,y+1, u)
+            z = x+y
+            z = hint(z, concrete=True) + r   # this checks that 'r' is green
+            return hint(z, variable=True)
+
+        res = self.interpret(f, [4, 5, 0], [], policy=P_NOVIRTUAL)
+        assert res == 20
+
 class TestLLType(SimpleTests):
     type_system = "lltype"

Modified: pypy/branch/jit-refactoring/pypy/jit/timeshifter/test/test_timeshift.py
==============================================================================
--- pypy/branch/jit-refactoring/pypy/jit/timeshifter/test/test_timeshift.py	(original)
+++ pypy/branch/jit-refactoring/pypy/jit/timeshifter/test/test_timeshift.py	Sun Feb 10 17:47:23 2008
@@ -468,165 +468,6 @@
         assert res == f(True, -1000)
         self.check_insns({'int_ge': 2, 'int_add': 1})
 
-    def test_simple_meth(self):
-        class Base(object):
-            def m(self):
-                raise NotImplementedError
-            pass  # for inspect.getsource() bugs
-
-        class Concrete(Base):
-            def m(self):
-                return 42
-            pass  # for inspect.getsource() bugs
-
-        def f(flag):
-            if flag:
-                o = Base()
-            else:
-                o = Concrete()
-            return o.m()
-
-        res = self.timeshift(f, [0], [0], policy=P_NOVIRTUAL)
-        assert res == 42
-        self.check_insns({})
-
-        res = self.timeshift(f, [0], [], policy=P_NOVIRTUAL)
-        assert res == 42
-        self.check_insns(indirect_call=0)
-
-    def test_simple_red_meth(self):
-        class Base(object):
-            def m(self, n):
-                raise NotImplementedError
-            pass  # for inspect.getsource() bugs
-
-        class Concrete(Base):
-            def m(self, n):
-                return 21*n
-            pass  # for inspect.getsource() bugs
-
-        def f(flag, x):
-            if flag:
-                o = Base()
-            else:
-                o = Concrete()
-            return o.m(x)
-
-        res = self.timeshift(f, [0, 2], [0], policy=P_NOVIRTUAL)
-        assert res == 42
-        self.check_insns({'int_mul': 1})
-
-    def test_simple_red_meth_vars_around(self):
-        class Base(object):
-            def m(self, n):
-                raise NotImplementedError
-            pass  # for inspect.getsource() bugs
-
-        class Concrete(Base):
-            def m(self, n):
-                return 21*n
-            pass  # for inspect.getsource() bugs
-
-        def f(flag, x, y, z):
-            if flag:
-                o = Base()
-            else:
-                o = Concrete()
-            return (o.m(x)+y)-z
-
-        res = self.timeshift(f, [0, 2, 7, 5], [0], policy=P_NOVIRTUAL)
-        assert res == 44
-        self.check_insns({'int_mul': 1, 'int_add': 1, 'int_sub': 1})
-
-    def test_deepfrozen_interior(self):
-        T = lltype.Struct('T', ('x', lltype.Signed))
-        A = lltype.Array(T)
-        S = lltype.GcStruct('S', ('a', A))
-        s = lltype.malloc(S, 3, zero=True)
-        s.a[2].x = 42
-        def f(n):
-            s1 = hint(s, variable=True)
-            s1 = hint(s1, deepfreeze=True)
-            return s1.a[n].x
-
-        # malloc-remove the interior ptr
-        res = self.timeshift(f, [2], [0], policy=P_NOVIRTUAL,
-                             backendoptimize=True)
-        assert res == 42
-        self.check_insns({})
-
-    def test_compile_time_const_tuple(self):
-        d = {(4, 5): 42, (6, 7): 12}
-        def f(a, b):
-            d1 = hint(d, deepfreeze=True)
-            return d1[a, b]
-
-        # malloc-remove the interior ptr
-        res = self.timeshift(f, [4, 5], [0, 1], policy=P_NOVIRTUAL,
-                             backendoptimize=True)
-        assert res == 42
-        self.check_insns({})
-
-    def test_green_red_mismatch_in_call(self):
-        #py.test.skip("WIP")
-        def add(a,b, u):
-            return a+b
-
-        def f(x, y, u):
-            r = add(x+1,y+1, u)
-            z = x+y
-            z = hint(z, concrete=True) + r   # this checks that 'r' is green
-            return hint(z, variable=True)
-
-        res = self.timeshift(f, [4, 5, 0], [], policy=P_NOVIRTUAL)
-        assert res == 20
-
-    def test_residual_red_call(self):
-        def g(x):
-            return x+1
-
-        def f(x):
-            return 2*g(x)
-
-        res = self.timeshift(f, [20], [], policy=StopAtXPolicy(g))
-        assert res == 42
-        self.check_insns(int_add=0)
-
-    def test_residual_red_call_with_exc(self):
-        def h(x):
-            if x > 0:
-                return x+1
-            else:
-                raise ValueError
-
-        def g(x):
-            return 2*h(x)
-
-        def f(x):
-            try:
-                return g(x)
-            except ValueError:
-                return 7
-
-        stop_at_h = StopAtXPolicy(h)
-        res = self.timeshift(f, [20], [], policy=stop_at_h)
-        assert res == 42
-        self.check_insns(int_add=0)
-
-        res = self.timeshift(f, [-20], [], policy=stop_at_h)
-        assert res == 7
-        self.check_insns(int_add=0)
-
-    def test_red_call_ignored_result(self):
-        def g(n):
-            return n * 7
-        def f(n, m):
-            g(n)   # ignore the result
-            return m
-
-        res = self.timeshift(f, [4, 212], [], policy=P_NOVIRTUAL)
-        assert res == 212
-
     def test_green_char_at_merge(self):
         def f(c, x):
             c = chr(c)



More information about the Pypy-commit mailing list