[pypy-svn] r53059 - in pypy/branch/jit-hotpath/pypy/jit: hintannotator rainbow rainbow/test timeshifter

antocuni at codespeak.net antocuni at codespeak.net
Fri Mar 28 18:09:37 CET 2008


Author: antocuni
Date: Fri Mar 28 18:09:36 2008
New Revision: 53059

Modified:
   pypy/branch/jit-hotpath/pypy/jit/hintannotator/model.py
   pypy/branch/jit-hotpath/pypy/jit/rainbow/codewriter.py
   pypy/branch/jit-hotpath/pypy/jit/rainbow/interpreter.py
   pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_interpreter.py
   pypy/branch/jit-hotpath/pypy/jit/rainbow/typesystem.py
   pypy/branch/jit-hotpath/pypy/jit/timeshifter/rtimeshift.py
   pypy/branch/jit-hotpath/pypy/jit/timeshifter/rvalue.py
Log:
more ootype operations implemented



Modified: pypy/branch/jit-hotpath/pypy/jit/hintannotator/model.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/hintannotator/model.py	(original)
+++ pypy/branch/jit-hotpath/pypy/jit/hintannotator/model.py	Fri Mar 28 18:09:36 2008
@@ -26,6 +26,7 @@
                       oogetfield
                       oosetfield
                       oononnull
+                      ooisnull
                       ooupcast
                       oodowncast
                       oois

Modified: pypy/branch/jit-hotpath/pypy/jit/rainbow/codewriter.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/rainbow/codewriter.py	(original)
+++ pypy/branch/jit-hotpath/pypy/jit/rainbow/codewriter.py	Fri Mar 28 18:09:36 2008
@@ -462,9 +462,9 @@
                 srcopname, srcargs = self.trace_back_bool_var(
                     block, block.exitswitch)
                 if srcopname is not None:
-                    if srcopname == 'ptr_nonzero':
+                    if srcopname in ('ptr_nonzero', 'oononnull'):
                         reverse = False
-                    elif srcopname == 'ptr_iszero':
+                    elif srcopname in ('ptr_iszero', 'ooisnull'):
                         reverse = True
                 if reverse is not None:
                     ptrindex = self.serialize_oparg("red", srcargs[0])
@@ -960,6 +960,9 @@
         if srcopname in ('ptr_iszero', 'ptr_nonzero'):
             arg = self.serialize_oparg("red", srcargs[0])
             self.emit("learn_nonzeroness", arg, srcopname == "ptr_nonzero")
+        elif srcopname in ('ooisnull', 'oononnull'):
+            arg = self.serialize_oparg("red", srcargs[0])
+            self.emit("learn_nonzeroness", arg, srcopname == "oononnull")
 
     def serialize_op_direct_call(self, op):
         kind, withexc = self.guess_call_kind(op)

Modified: pypy/branch/jit-hotpath/pypy/jit/rainbow/interpreter.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/rainbow/interpreter.py	(original)
+++ pypy/branch/jit-hotpath/pypy/jit/rainbow/interpreter.py	Fri Mar 28 18:09:36 2008
@@ -542,7 +542,7 @@
 
     @arguments("red", "bool")
     def opimpl_learn_nonzeroness(self, redbox, boolval):
-        assert isinstance(redbox, rvalue.PtrRedBox)
+        assert isinstance(redbox, rvalue.AbstractPtrRedBox)
         redbox.learn_nonzeroness(self.jitstate, boolval)
 
     @arguments()
@@ -1032,6 +1032,9 @@
     def opimpl_red_oogetfield(self, structbox, fielddesc, deepfrozen):
         return rtimeshift.gengetfield(self.jitstate, deepfrozen, fielddesc,
                                       structbox)
+    @arguments("green", "fielddesc", returns="green")
+    def opimpl_green_oogetfield(self, gv_struct, fielddesc):
+        return fielddesc.perform_getfield(self.rgenop, gv_struct)
 
     @arguments("red", "fielddesc", "red")
     def opimpl_red_oosetfield(self, destbox, fielddesc, valuebox):
@@ -1042,6 +1045,14 @@
     def opimpl_red_new(self, structtypedesc):
         return structtypedesc.factory()
 
+    @arguments("red", returns="red")
+    def opimpl_red_oononnull(self, ptrbox):
+        return rtimeshift.genptrnonzero(self.jitstate, ptrbox, False)
+
+    @arguments("red", returns="red")
+    def opimpl_red_ooisnull(self, ptrbox):
+        return rtimeshift.genptrnonzero(self.jitstate, ptrbox, True)
+
 
 class DebugTrace(object):
     def __init__(self, *args):

Modified: pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_interpreter.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_interpreter.py	(original)
+++ pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_interpreter.py	Fri Mar 28 18:09:36 2008
@@ -105,6 +105,11 @@
         return S
 
     malloc = staticmethod(lltype.malloc)
+    nullptr = staticmethod(lltype.nullptr)
+
+    @staticmethod
+    def malloc_immortal(T):
+        return lltype.malloc(T, immortal=True)
 
     def setup_class(cls):
         cls.on_llgraph = cls.RGenOp is LLRGenOp
@@ -1365,12 +1370,14 @@
         assert count_depth(res) == 2
 
     def test_known_nonzero(self):
-        S = lltype.GcStruct('s', ('x', lltype.Signed))
-        global_s = lltype.malloc(S, immortal=True)
+        S = self.GcStruct('s', ('x', lltype.Signed))
+        malloc = self.malloc
+        nullptr = self.nullptr
+        global_s = self.malloc_immortal(S)
         global_s.x = 100
 
         def h():
-            s = lltype.malloc(S)
+            s = malloc(S)
             s.x = 50
             return s
         def g(s, y):
@@ -1382,11 +1389,11 @@
             hint(None, global_merge_point=True)
             x = hint(x, concrete=True)
             if x == 1:
-                return g(lltype.nullptr(S), y)
+                return g(nullptr(S), y)
             elif x == 2:
                 return g(global_s, y)
             elif x == 3:
-                s = lltype.malloc(S)
+                s = malloc(S)
                 s.x = y
                 return g(s, y)
             elif x == 4:
@@ -1998,6 +2005,11 @@
         return I
 
     malloc = staticmethod(ootype.new)
+    nullptr = staticmethod(ootype.null)
+
+    @staticmethod
+    def malloc_immortal(T):
+        return ootype.new(T)
 
     def translate_insns(self, insns):
         replace = {

Modified: pypy/branch/jit-hotpath/pypy/jit/rainbow/typesystem.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/rainbow/typesystem.py	(original)
+++ pypy/branch/jit-hotpath/pypy/jit/rainbow/typesystem.py	Fri Mar 28 18:09:36 2008
@@ -32,6 +32,12 @@
     def genop_malloc_fixedsize(self, builder, alloctoken):
         return builder.genop_malloc_fixedsize(alloctoken)
 
+    def genop_ptr_iszero(self, builder, argbox, gv_addr):
+        return builder.genop_ptr_iszero(argbox.kind, gv_addr)
+
+    def genop_ptr_nonzero(self, builder, argbox, gv_addr):
+        return builder.genop_ptr_nonzero(argbox.kind, gv_addr)
+
 class OOTypeHelper(TypeSystemHelper):
 
     name = 'ootype'
@@ -43,6 +49,12 @@
     def genop_malloc_fixedsize(self, builder, alloctoken):
         return builder.genop_new(alloctoken)
 
+    def genop_ptr_iszero(self, builder, argbox, gv_addr):
+        return builder.genop_ooisnull(argbox.kind, gv_addr)
+
+    def genop_ptr_nonzero(self, builder, argbox, gv_addr):
+        return builder.genop_oononnull(argbox.kind, gv_addr)
+
 
 llhelper = LLTypeHelper()
 oohelper = OOTypeHelper()

Modified: pypy/branch/jit-hotpath/pypy/jit/timeshifter/rtimeshift.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/timeshifter/rtimeshift.py	(original)
+++ pypy/branch/jit-hotpath/pypy/jit/timeshifter/rtimeshift.py	Fri Mar 28 18:09:36 2008
@@ -238,9 +238,9 @@
     return rvalue.IntRedBox(fielddesc.indexkind, genvar)
 
 def genptrnonzero(jitstate, argbox, reverse):
-    assert isinstance(argbox, rvalue.PtrRedBox)
+    assert isinstance(argbox, rvalue.AbstractPtrRedBox)
     if argbox.is_constant():
-        addr = rvalue.ll_getvalue(argbox, llmemory.Address)
+        addr = rvalue.ll_getvalue(argbox, jitstate.ts.ROOT_TYPE)
         return rvalue.ll_fromvalue(jitstate, bool(addr) ^ reverse)
     builder = jitstate.curbuilder
     if argbox.known_nonzero:
@@ -248,9 +248,9 @@
     else:
         gv_addr = argbox.getgenvar(jitstate)
         if reverse:
-            gv_res = builder.genop_ptr_iszero(argbox.kind, gv_addr)
+            gv_res = jitstate.ts.genop_ptr_iszero(builder, argbox, gv_addr)
         else:
-            gv_res = builder.genop_ptr_nonzero(argbox.kind, gv_addr)
+            gv_res = jitstate.ts.genop_ptr_nonzero(builder, argbox, gv_addr)
     return rvalue.IntRedBox(builder.rgenop.kindToken(lltype.Bool), gv_res)
 
 def genptreq(jitstate, argbox0, argbox1, reverse):

Modified: pypy/branch/jit-hotpath/pypy/jit/timeshifter/rvalue.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/timeshifter/rvalue.py	(original)
+++ pypy/branch/jit-hotpath/pypy/jit/timeshifter/rvalue.py	Fri Mar 28 18:09:36 2008
@@ -110,7 +110,10 @@
         return redboxbuilder_ptr
     elif TYPE is lltype.Float:
         return redboxbuilder_dbl
-    elif isinstance(TYPE, ootype.Instance) or isinstance(TYPE, ootype.Record):
+    elif (isinstance(TYPE, ootype.Instance) or
+          isinstance(TYPE, ootype.Record) or 
+          isinstance(TYPE, ootype.StaticMethod)):
+        # XXX: probably it won't translate, because we can't mix these types
         return redboxbuilder_inst
     else:
         assert isinstance(TYPE, lltype.Primitive)


More information about the pypy-svn mailing list