[pypy-svn] r22837 - in pypy/dist/pypy/jit: . test

pedronis at codespeak.net pedronis at codespeak.net
Sun Jan 29 14:33:44 CET 2006


Author: pedronis
Date: Sun Jan 29 14:33:42 2006
New Revision: 22837

Modified:
   pypy/dist/pypy/jit/hintannotator.py
   pypy/dist/pypy/jit/hintmodel.py
   pypy/dist/pypy/jit/test/test_hint_annotation.py
Log:
(arigo, pedronis)

correct dep tracking for getarrayitem



Modified: pypy/dist/pypy/jit/hintannotator.py
==============================================================================
--- pypy/dist/pypy/jit/hintannotator.py	(original)
+++ pypy/dist/pypy/jit/hintannotator.py	Sun Jan 29 14:33:42 2006
@@ -5,8 +5,8 @@
 
 class HintAnnotator(RPythonAnnotator):
 
-    def __init__(self, policy=None):
-        RPythonAnnotator.__init__(self, policy=policy)
+    def __init__(self, translator, policy=None):
+        RPythonAnnotator.__init__(self, translator, policy=policy)
         self.bookkeeper = HintBookkeeper(self) # XXX
 
     def consider_op_malloc(self, hs_TYPE):

Modified: pypy/dist/pypy/jit/hintmodel.py
==============================================================================
--- pypy/dist/pypy/jit/hintmodel.py	(original)
+++ pypy/dist/pypy/jit/hintmodel.py	Sun Jan 29 14:33:42 2006
@@ -3,7 +3,7 @@
 from pypy.jit.hintbookkeeper import getbookkeeper
 from pypy.rpython.lltypesystem import lltype
 
-UNARY_OPERATIONS = """same_as hint getfield setfield getsubstruct getarraysize getarrayitem setarrayitem
+UNARY_OPERATIONS = """same_as hint getfield setfield getsubstruct getarraysize setarrayitem
                       cast_pointer
                       direct_call
                       int_is_true int_neg
@@ -17,7 +17,8 @@
 BINARY_OPERATIONS = """int_add int_sub int_mul int_mod int_and int_rshift int_floordiv
                        uint_add uint_sub uint_mul uint_mod uint_and uint_rshift uint_floordiv
                        int_gt int_lt int_le int_ge int_eq int_ne
-                       uint_gt uint_lt uint_le uint_ge uint_eq uint_ne""".split()
+                       uint_gt uint_lt uint_le uint_ge uint_eq uint_ne
+                       getarrayitem""".split()
 
 class OriginTreeNode(object):
 
@@ -50,20 +51,12 @@
         self.concretetype = T
         assert self.__class__ != SomeLLAbstractValue
 
-    def reorigin(self, bookkeeper):
-        return self
-
 class SomeLLAbstractConstant(SomeLLAbstractValue):
 
     def __init__(self, T, origins):
         SomeLLAbstractValue.__init__(self, T)
         self.origins = origins
 
-    def reorigin(self, bookkeeper):
-        origin = bookkeeper.myorigin()
-        origin.merge(self.origins)
-        return SomeLLAbstractConstant(self.concretetype, {origin: True})
-
 class SomeLLConcreteValue(SomeLLAbstractValue):
     pass
 
@@ -76,6 +69,17 @@
         self.contentdef = contentdef
         self.concretetype = lltype.Ptr(contentdef.T)
 
+def reorigin(hs_v1, *deps_hs):
+    if isinstance(hs_v1, SomeLLAbstractConstant):
+        origin = getbookkeeper().myorigin()
+        origin.merge(hs_v1.origins)
+        for hs_dep in deps_hs:
+            if isinstance(hs_v1, SomeLLAbstractConstant):
+                origin.merge(hs_dep.origins)
+        return SomeLLAbstractConstant(hs_v1.concretetype, {origin: True})
+    else:
+        return hs_v1
+
 # ____________________________________________________________
 # operations
 
@@ -105,16 +109,6 @@
         else:
             return SomeLLAbstractVariable(FIELD_TYPE)
 
-    def getarrayitem(hs_c1, hs_index):
-        A = hs_c1.concretetype.TO
-        READ_TYPE = A.OF
-        if A._hints.get('immutable', False):
-            origin = getbookkeeper().myorigin()
-            origin.merge(hs_c1.origins)
-            return SomeLLAbstractConstant(READ_TYPE, {origin: True})
-        else:
-            return SomeLLAbstractVariable(READ_TYPE)
-
     def getsubstruct(hs_c1, hs_fieldname):
         S = hs_c1.concretetype.TO
         SUB_TYPE = getattr(S, hs_fieldname.const)
@@ -147,10 +141,7 @@
         hs_res = bookkeeper.annotator.recursivecall(fnobj.graph,
                                                     bookkeeper.position_key,
                                                     args_hs)
-        if isinstance(hs_res, SomeLLAbstractValue):
-            hs_res = hs_res.reorigin(bookkeeper)
-        #else: it's a SomeImpossibleValue
-        return hs_res
+        return reorigin(hs_res)
 
     def unary_char(hs_c1):
         origin = getbookkeeper().myorigin()
@@ -206,9 +197,6 @@
     def setarrayitem(hs_a1, hs_index, hs_value):
         hs_a1.contentdef.generalize_item(hs_value)
 
-    def getarrayitem(hs_a1, hs_index):
-        return hs_a1.contentdef.read_item()
-
     def getarraysize(hs_a1):
         origin = getbookkeeper().myorigin()
         return SomeLLAbstractConstant(lltype.Signed, {origin: True})
@@ -226,6 +214,9 @@
     def int_add((hs_v1, hs_v2)):
         return SomeLLAbstractVariable(lltype.Signed)
 
+    def getarrayitem((hs_v1, hs_v2)):
+        return SomeLLAbstractVariable(hs_v1.concretetype.TO.OF)
+
     def union((hs_v1, hs_v2)):
         raise annmodel.UnionError("%s %s don't mix" % (hs_v1, hs_v2))
 
@@ -268,6 +259,17 @@
         origins = annmodel.setunion(hs_c1.origins, hs_c2.origins)
         return SomeLLAbstractConstant(hs_c1.concretetype, origins)
 
+    def getarrayitem((hs_c1, hs_index)):
+        A = hs_c1.concretetype.TO
+        READ_TYPE = A.OF
+        if A._hints.get('immutable', False):
+            origin = getbookkeeper().myorigin()
+            origin.merge(hs_c1.origins)
+            origin.merge(hs_index.origins)
+            return SomeLLAbstractConstant(READ_TYPE, {origin: True})
+        else:
+            return SomeLLAbstractVariable(READ_TYPE)
+
 class __extend__(pairtype(SomeLLAbstractConstant, SomeLLConcreteValue),
                  pairtype(SomeLLConcreteValue, SomeLLAbstractConstant),
                  pairtype(SomeLLConcreteValue, SomeLLConcreteValue)):
@@ -288,6 +290,9 @@
     int_lt = int_le = int_ge = int_ne = int_gt = int_eq
     uint_lt = uint_le = uint_ge = uint_ne = uint_gt = uint_eq = int_eq
 
+    def getarrayitem((hs_c1, hs_index)):
+        return SomeLLConcreteValue(hs_c1.concretetype.TO.OF)
+
 class __extend__(pairtype(SomeLLConcreteValue, SomeLLAbstractConstant),
                  pairtype(SomeLLAbstractConstant, SomeLLConcreteValue)):
 
@@ -303,6 +308,13 @@
     def union((hs_cont1, hs_cont2)):
         return SomeLLAbstractContainer(hs_cont1.contentdef.union(hs_cont2.contentdef))
 
+class __extend__(pairtype(SomeLLAbstractContainer, SomeLLAbstractConstant)):
+
+    def getarrayitem((hs_a1, hs_index)):
+        hs_res = hs_a1.contentdef.read_item()
+        return reorigin(hs_res, hs_index)
+
+
 # ____________________________________________________________
 
 def handle_highlevel_operation(bookkeeper, ll_func, *args_hs):

Modified: pypy/dist/pypy/jit/test/test_hint_annotation.py
==============================================================================
--- pypy/dist/pypy/jit/test/test_hint_annotation.py	(original)
+++ pypy/dist/pypy/jit/test/test_hint_annotation.py	Sun Jan 29 14:33:42 2006
@@ -11,7 +11,7 @@
 P_OOPSPEC = AnnotatorPolicy()
 P_OOPSPEC.oopspec = True
 
-def hannotate(func, argtypes, policy=None):
+def hannotate(func, argtypes, policy=None, annotator=False):
     # build the normal ll graphs for ll_function
     t = TranslationContext()
     a = t.buildannotator()
@@ -20,13 +20,16 @@
     rtyper.specialize()
     graph1 = graphof(t, func)
     # build hint annotator types
-    hannotator = HintAnnotator(policy=policy)
+    hannotator = HintAnnotator(t, policy=policy)
     hs = hannotator.build_graph_types(graph1, [SomeLLAbstractConstant(v.concretetype,
                                                                       {OriginTreeNode(): True})
                                                for v in graph1.getargs()])
     #hannotator.translator.graphs.append(graph1)
     #hannotator.translator.view()
-    return hs
+    if annotator:
+        return hs, hannotator
+    else:
+        return hs
 
 def test_simple():
     def ll_function(x, y):
@@ -262,7 +265,32 @@
     assert isinstance(hs, SomeLLAbstractContainer)
     assert hs.concretetype == PGCS2
 
-
+def test_getarrayitem():
+    A = lltype.GcArray(lltype.Signed, hints={'immutable': True})
+    a = lltype.malloc(A, 10)
+    def ll1(n):
+        v = a[n]
+        v = hint(v, concrete=True)
+        return v
+    hs, ha = hannotate(ll1, [int], annotator=True)
+    assert isinstance(hs, SomeLLConcreteValue)
+    g1 = graphof(ha.translator, ll1)
+    hs_n = ha.binding(g1.getargs()[0])
+    assert hs_n.origins.keys()[0].fixed
+
+def test_getvarrayitem():
+    A = lltype.GcArray(lltype.Signed, hints={'immutable': True})
+    def ll1(n):
+        a = lltype.malloc(A, 10)
+        v = a[n]
+        v = hint(v, concrete=True)
+        return v
+    hs, ha = hannotate(ll1, [int], annotator=True)
+    assert isinstance(hs, SomeLLConcreteValue)
+    g1 = graphof(ha.translator, ll1)
+    hs_n = ha.binding(g1.getargs()[0])
+    assert hs_n.origins.keys()[0].fixed
+ 
 def test_hannotate_tl():
     from pypy.jit import tl
 



More information about the Pypy-commit mailing list