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

rxe at codespeak.net rxe at codespeak.net
Fri Nov 3 14:39:22 CET 2006


Author: rxe
Date: Fri Nov  3 14:39:20 2006
New Revision: 34101

Modified:
   pypy/dist/pypy/jit/hintannotator/annotator.py
   pypy/dist/pypy/jit/hintannotator/model.py
   pypy/dist/pypy/jit/hintannotator/test/test_annotator.py
Log:
add deepfreeze hint and a few ops.  (arigo, arre, rxe)

Modified: pypy/dist/pypy/jit/hintannotator/annotator.py
==============================================================================
--- pypy/dist/pypy/jit/hintannotator/annotator.py	(original)
+++ pypy/dist/pypy/jit/hintannotator/annotator.py	Fri Nov  3 14:39:20 2006
@@ -14,7 +14,7 @@
         self.base_translator = base_translator
         assert base_translator is not None      # None not supported any more
         self.exceptiontransformer = base_translator.getexceptiontransformer()
-
+        
     def build_types(self, origgraph, input_args_hs):
         desc = self.bookkeeper.getdesc(origgraph)
         flowgraph = desc.specialize(input_args_hs)
@@ -28,6 +28,8 @@
             vstructdef = self.bookkeeper.getvirtualcontainerdef(TYPE)
             return hintmodel.SomeLLAbstractContainer(vstructdef)
 
+    consider_op_zero_malloc = consider_op_malloc
+
     def consider_op_malloc_varsize(self, hs_TYPE, hs_length):
         TYPE = hs_TYPE.const
         if getattr(self.policy, 'novirtualcontainer', False):
@@ -36,6 +38,8 @@
             vcontainerdef = self.bookkeeper.getvirtualcontainerdef(TYPE)
             return hintmodel.SomeLLAbstractContainer(vcontainerdef)
 
+    consider_op_zero_malloc_varsize = consider_op_malloc_varsize
+
     def consider_op_zero_gc_pointers_inside(self, hs_v):
         pass
 

Modified: pypy/dist/pypy/jit/hintannotator/model.py
==============================================================================
--- pypy/dist/pypy/jit/hintannotator/model.py	(original)
+++ pypy/dist/pypy/jit/hintannotator/model.py	Fri Nov  3 14:39:20 2006
@@ -18,11 +18,12 @@
                       ptr_iszero""".split()
 
 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
+                       uint_add uint_sub uint_mul uint_mod uint_and uint_lshift uint_rshift uint_floordiv
                        char_gt char_lt char_le char_ge char_eq char_ne
                        int_gt int_lt int_le int_ge int_eq int_ne
-                       uint_gt uint_lt uint_le uint_ge uint_eq uint_ne
+                       uint_gt uint_lt uint_le uint_ge uint_eq uint_ne 
                        getarrayitem
+                       getarraysubstruct
                        ptr_eq ptr_ne""".split()
 
 class HintError(Exception):
@@ -132,7 +133,9 @@
 
 
 class SomeLLAbstractConstant(SomeLLAbstractValue):
-
+    " color: dont know yet.. "
+    deepfrozen = False
+    
     def __init__(self, T, origins, eager_concrete=False, myorigin=None):
         SomeLLAbstractValue.__init__(self, T)
         self.origins = origins
@@ -188,6 +191,7 @@
 
 
 class SomeLLAbstractVariable(SomeLLAbstractValue):
+    " color: hopelessly red"
     pass
 
 
@@ -262,7 +266,7 @@
             hs_concrete = SomeLLAbstractConstant(hs_v1.concretetype, {})
             hs_concrete.eager_concrete = True
             return hs_concrete 
-
+            
     def getfield(hs_v1, hs_fieldname):
         S = hs_v1.concretetype.TO
         FIELD_TYPE = getattr(S, hs_fieldname.const)
@@ -324,6 +328,11 @@
         if hs_flags.const.get('forget', False):
             assert isinstance(hs_c1, SomeLLAbstractConstant)
             return reorigin(hs_c1)
+        if hs_flags.const.get('deepfreeze', False):
+            hs_concrete = SomeLLAbstractConstant(hs_c1.concretetype,
+                                                 hs_c1.origins)
+            hs_concrete.deepfrozen = True
+            return hs_concrete 
         return SomeLLAbstractValue.hint(hs_c1, hs_flags)
 
     def direct_call(hs_f1, *args_hs):
@@ -359,12 +368,14 @@
     def getfield(hs_c1, hs_fieldname):
         S = hs_c1.concretetype.TO
         FIELD_TYPE = getattr(S, hs_fieldname.const)
-        if S._hints.get('immutable', False):
+        if S._hints.get('immutable', False) or hs_c1.deepfrozen:
             origin = getbookkeeper().myorigin()
             d = setadd(hs_c1.origins, origin)
-            return SomeLLAbstractConstant(FIELD_TYPE, d,
-                                          eager_concrete=hs_c1.eager_concrete,
-                                          myorigin=origin)
+            res = SomeLLAbstractConstant(FIELD_TYPE, d,
+                                         eager_concrete=hs_c1.eager_concrete,
+                                         myorigin=origin)
+            res.deepfrozen = hs_c1.deepfrozen
+            return res
         else:
             return SomeLLAbstractVariable(FIELD_TYPE)
 
@@ -373,8 +384,10 @@
         SUB_TYPE = getattr(S, hs_fieldname.const)
         origin = getbookkeeper().myorigin()
         d = setadd(hs_c1.origins, origin)
-        return SomeLLAbstractConstant(lltype.Ptr(SUB_TYPE), d, myorigin=origin)
-
+        res = SomeLLAbstractConstant(lltype.Ptr(SUB_TYPE), d, myorigin=origin)
+        res.deepfrozen = hs_c1.deepfrozen
+        return res
+    
 
 class __extend__(SomeLLAbstractContainer):
 
@@ -441,15 +454,18 @@
                                                        hs_c2.eager_concrete,
                                       myorigin = myorigin)
 
+
     def getarrayitem((hs_c1, hs_index)):
         A = hs_c1.concretetype.TO
         READ_TYPE = A.OF
-        if A._hints.get('immutable', False):
+        if A._hints.get('immutable', False) or hs_c1.deepfrozen:
             origin = getbookkeeper().myorigin()
             d = newset(hs_c1.origins, hs_index.origins, {origin: True})
-            return SomeLLAbstractConstant(READ_TYPE, d,
-                                          eager_concrete=hs_c1.eager_concrete,
-                                          myorigin=origin)
+            res = SomeLLAbstractConstant(READ_TYPE, d,
+                                         eager_concrete=hs_c1.eager_concrete,
+                                         myorigin=origin)
+            res.deepfrozen = hs_c1.deepfrozen
+            return res
         else:
             return SomeLLAbstractVariable(READ_TYPE)
 

Modified: pypy/dist/pypy/jit/hintannotator/test/test_annotator.py
==============================================================================
--- pypy/dist/pypy/jit/hintannotator/test/test_annotator.py	(original)
+++ pypy/dist/pypy/jit/hintannotator/test/test_annotator.py	Fri Nov  3 14:39:20 2006
@@ -32,6 +32,7 @@
         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=policy)
     hs = hannotator.build_types(graph1, [SomeLLAbstractConstant(v.concretetype,
@@ -79,6 +80,22 @@
     assert isinstance(hs, SomeLLAbstractConstant)
     assert hs.eager_concrete
     assert hs.concretetype == lltype.Signed
+
+def test_deepfreeze():
+
+    A = lltype.GcArray(lltype.Signed)
+    
+    def ll_function(a, i):
+        a = hint(a, deepfreeze=True)
+        res = a[i]
+        res = hint(res, concrete=True)
+        
+        res = hint(res, variable=True)
+        return res
+
+    hs = hannotate(ll_function, [annmodel.SomePtr(lltype.Ptr(A)), int])
+    assert type(hs) is SomeLLAbstractVariable
+    assert hs.concretetype == lltype.Signed
   
 def test_simple_hint_origins():
     def ll_function(cond, x,y):



More information about the Pypy-commit mailing list