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

pedronis at codespeak.net pedronis at codespeak.net
Wed Feb 1 21:10:49 CET 2006


Author: pedronis
Date: Wed Feb  1 21:10:47 2006
New Revision: 22932

Modified:
   pypy/dist/pypy/jit/hintmodel.py
   pypy/dist/pypy/jit/test/test_hint_annotation.py
Log:
use a flag eager_concrete instead of a separate annotation for the hint(concrete) results. Simplifies things a bit.
Should make easier to  refactor propagation rules.



Modified: pypy/dist/pypy/jit/hintmodel.py
==============================================================================
--- pypy/dist/pypy/jit/hintmodel.py	(original)
+++ pypy/dist/pypy/jit/hintmodel.py	Wed Feb  1 21:10:47 2006
@@ -54,9 +54,10 @@
 
 class SomeLLAbstractConstant(SomeLLAbstractValue):
 
-    def __init__(self, T, origins):
+    def __init__(self, T, origins, eager_concrete=False):
         SomeLLAbstractValue.__init__(self, T)
         self.origins = origins
+        self.eager_concrete = eager_concrete
 
     def fmt_origins(self, origins):
         counts = {}
@@ -84,15 +85,14 @@
         """Compute the color of the variables with this annotation
         for the pygame viewer
         """
-        if self.is_fixed():
+        if self.eager_concrete:
+            return (0,100,0)
+        elif self.is_fixed():
             return (50,140,0)
         else:
             return None
     annotationcolor = property(annotationcolor)
 
-class SomeLLConcreteValue(SomeLLAbstractValue):
-    annotationcolor = (0,100,0)
-
 class SomeLLAbstractVariable(SomeLLAbstractValue):
     pass
 
@@ -127,7 +127,7 @@
                         if isinstance(hs_dep, SomeLLAbstractConstant)]
         d = newset({getbookkeeper().myorigin(): True},
                    *deps_origins)
-        return SomeLLAbstractConstant(hs_v1.concretetype, d)
+        return SomeLLAbstractConstant(hs_v1.concretetype, d, eager_concrete=hs_v1.eager_concrete)
     else:
         return hs_v1
 
@@ -147,7 +147,9 @@
         if hs_flags.const.get('concrete', False):
             for o in hs_c1.origins:
                 o.set_fixed()
-            return SomeLLConcreteValue(hs_c1.concretetype)
+            hs_concrete = reorigin(hs_c1)
+            hs_concrete.eager_concrete = True
+            return hs_concrete 
         else:
             assert hs_flags.const['forget']
             assert isinstance(hs_c1, SomeLLAbstractConstant)
@@ -180,8 +182,8 @@
             key = []
             specialize = False
             for i, arg_hs in enumerate(args_hs):
-                if isinstance(arg_hs, SomeLLConcreteValue):
-                    key.append('C')
+                if isinstance(arg_hs, SomeLLAbstractConstant) and arg_hs.eager_concrete:
+                    key.append('E')
                     specialize = True
                 else:
                     key.append('x')
@@ -242,28 +244,15 @@
     def define_unary(TYPE):
         def const_unary(hs_c1):
             d = setadd(hs_c1.origins, getbookkeeper().myorigin())
-            return SomeLLAbstractConstant(TYPE, d)
+            return SomeLLAbstractConstant(TYPE, d, eager_concrete=hs_c1.eager_concrete)
         return const_unary
 
     cast_int_to_char = define_unary(lltype.Char)
     
     cast_uint_to_int = cast_bool_to_int = cast_char_to_int = int_neg = define_unary(lltype.Signed)
 
-    uint_is_true = int_is_true = define_unary(lltype.Bool)
-
-class __extend__(SomeLLConcreteValue):
-
-    def define_unary(TYPE):
-        def concrete_unary(hs_cv1):
-            return SomeLLConcreteValue(TYPE)
-        return concrete_unary
-
     cast_int_to_uint = define_unary(lltype.Unsigned)
 
-    cast_uint_to_int = cast_bool_to_int = cast_char_to_int = int_neg = define_unary(lltype.Signed)
-
-    cast_int_to_char = define_unary(lltype.Char)
- 
     uint_is_true = int_is_true = define_unary(lltype.Bool)
     
 class __extend__(SomeLLAbstractContainer):
@@ -307,6 +296,8 @@
 
     def union((hs_v1, hs_v2)):
         assert hs_v1.concretetype == hs_v2.concretetype
+        if getattr(hs_v1, 'eager_concrete', False) or getattr(hs_v2, 'eager_concrete', False):
+            raise annmodel.UnionError("%s %s don't mix" % (hs_v1, hs_v2))
         return SomeLLAbstractVariable(hs_v1.concretetype)
 
 class __extend__(pairtype(SomeLLAbstractConstant, SomeLLAbstractConstant)):
@@ -315,7 +306,7 @@
         def const_binary((hs_c1, hs_c2)):
             d = newset(hs_c1.origins, hs_c2.origins,
                        {getbookkeeper().myorigin(): True})
-            return SomeLLAbstractConstant(TYPE, d)
+            return SomeLLAbstractConstant(TYPE, d, eager_concrete= hs_c1.eager_concrete or hs_c2.eager_concrete)
         return const_binary
             
     int_mul = int_mod = int_sub = int_add = define_binary(lltype.Signed)
@@ -330,7 +321,7 @@
     def union((hs_c1, hs_c2)):
         assert hs_c1.concretetype == hs_c2.concretetype
         d = newset(hs_c1.origins, hs_c2.origins)
-        return SomeLLAbstractConstant(hs_c1.concretetype, d)
+        return SomeLLAbstractConstant(hs_c1.concretetype, d, eager_concrete=hs_c1.eager_concrete and hs_c2.eager_concrete)
 
     def getarrayitem((hs_c1, hs_index)):
         A = hs_c1.concretetype.TO
@@ -338,41 +329,10 @@
         if A._hints.get('immutable', False):
             d = newset(hs_c1.origins, hs_index.origins,
                        {getbookkeeper().myorigin(): True})
-            return SomeLLAbstractConstant(READ_TYPE, d)
+            return SomeLLAbstractConstant(READ_TYPE, d, eager_concrete=hs_c1.eager_concrete)
         else:
             return SomeLLAbstractVariable(READ_TYPE)
 
-class __extend__(pairtype(SomeLLAbstractConstant, SomeLLConcreteValue),
-                 pairtype(SomeLLConcreteValue, SomeLLAbstractConstant),
-                 pairtype(SomeLLConcreteValue, SomeLLConcreteValue)):
-
-    def define_binary(TYPE):
-        def concrete_binary((hs_c1, hs_c2)):
-            return SomeLLConcreteValue(TYPE)
-        return concrete_binary
-
-    int_mul = int_mod = int_sub = int_add = define_binary(lltype.Signed)
-    int_floordiv = int_rshift = int_and = int_add
-
-    uint_mul = uint_mod = uint_sub = uint_add = define_binary(lltype.Unsigned)
-    uint_floordiv = uint_rshift = uint_and = uint_add
-
-    int_lt = int_le = int_ge = int_ne = int_gt = int_eq = define_binary(lltype.Bool)
-    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)):
-
-    def union((hs_c1, hs_c2)):
-        assert hs_c1.concretetype == hs_c2.concretetype
-        #if hasattr(hs_c1, 'const') or hasattr(hs_c2, 'const'):
-        return SomeLLAbstractConstant(hs_c1.concretetype, {}) # MAYBE
-        #else:
-        #raise annmodel.UnionError("%s %s don't mix, unless the constant is constant" % (hs_c1, hs_c2))
-
 class __extend__(pairtype(SomeLLAbstractContainer, SomeLLAbstractContainer)):
 
     def union((hs_cont1, hs_cont2)):

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	Wed Feb  1 21:10:47 2006
@@ -62,7 +62,8 @@
         z = hint(z, concrete=True)
         return z
     hs = hannotate(ll_function, [bool, int, int])
-    assert isinstance(hs, SomeLLConcreteValue)
+    assert isinstance(hs, SomeLLAbstractConstant)
+    assert hs.eager_concrete
     assert hs.concretetype == lltype.Signed
   
 def test_simple_hint_origins():
@@ -97,13 +98,14 @@
         x = hint(x, concrete=True)
         return x + y
     hs = hannotate(ll_function, [int, int])
-    assert type(hs) is SomeLLConcreteValue
+    assert type(hs) is SomeLLAbstractConstant
+    assert hs.eager_concrete
     assert hs.concretetype == lltype.Signed
 
 def test_union():
     unionof = annmodel.unionof
     av1, av2 = SomeLLAbstractVariable(lltype.Signed), SomeLLAbstractVariable(lltype.Signed)
-    cv1, cv2 = SomeLLConcreteValue(lltype.Signed), SomeLLConcreteValue(lltype.Signed)
+    cv1, cv2 = SomeLLAbstractConstant(lltype.Signed, {}, eager_concrete=True), SomeLLAbstractConstant(lltype.Signed, {}, eager_concrete=True)
     ac1, ac2 = SomeLLAbstractConstant(lltype.Signed, {}), SomeLLAbstractConstant(lltype.Signed, {})
     ac3 = SomeLLAbstractConstant(lltype.Signed, {})
     ac3.const = 3
@@ -136,13 +138,14 @@
         HintBookkeeper(None).enter(None)
         return pair(hs1, hs2).int_add()
     av1, av2 = SomeLLAbstractVariable(lltype.Signed), SomeLLAbstractVariable(lltype.Signed)
-    cv1, cv2 = SomeLLConcreteValue(lltype.Signed), SomeLLConcreteValue(lltype.Signed)
+    cv1, cv2 = SomeLLAbstractConstant(lltype.Signed, {}, True), SomeLLAbstractConstant(lltype.Signed, {}, True)
     ac1, ac2 = SomeLLAbstractConstant(lltype.Signed, {}), SomeLLAbstractConstant(lltype.Signed, {})
     assert meet(av1, av2) == av1
-    assert meet(cv1, cv2) == cv2
+    res = meet(cv1, cv2)
+    assert res.eager_concrete
     assert isinstance(meet(ac1, ac2), SomeLLAbstractConstant)
-    assert meet(ac1, cv1) == cv1
-    assert meet(cv1, ac1) == cv1
+    assert meet(ac1, cv1).eager_concrete
+    assert meet(cv1, ac1).eager_concrete
     assert meet(av1, cv1) == av1
     assert meet(cv1, av1) == av1
     assert meet(ac1, av1) == av1
@@ -271,7 +274,7 @@
         v = hint(v, concrete=True)
         return v
     hs, ha = hannotate(ll1, [int], annotator=True)
-    assert isinstance(hs, SomeLLConcreteValue)
+    assert hs.eager_concrete
     g1 = graphof(ha.translator, ll1)
     hs_n = ha.binding(g1.getargs()[0])
     assert hs_n.origins.keys()[0].fixed
@@ -284,7 +287,7 @@
         v = hint(v, concrete=True)
         return v
     hs, ha = hannotate(ll1, [int], annotator=True)
-    assert isinstance(hs, SomeLLConcreteValue)
+    assert hs.eager_concrete
     g1 = graphof(ha.translator, ll1)
     hs_n = ha.binding(g1.getargs()[0])
     assert hs_n.origins.keys()[0].fixed
@@ -302,7 +305,7 @@
         z = hint(z, concrete=True)
         return z
     hs, ha  = hannotate(ll_function, [bool, int, int, int, int], annotator=True)
-    assert isinstance(hs, SomeLLConcreteValue)
+    assert hs.eager_concrete
     assert hs.concretetype == lltype.Signed
     ll_help_graph = graphof(ha.base_translator, ll_help)
     gdesc = ha.bookkeeper.getdesc(ll_help_graph)
@@ -320,15 +323,16 @@
         z2 = ll_add(x1, y)
         return z2
     hs, ha  = hannotate(ll_function, [int, int], annotator=True)
-    assert isinstance(hs, SomeLLConcreteValue)
+    assert hs.eager_concrete
     assert hs.concretetype == lltype.Signed
     ll_add_graph = graphof(ha.base_translator, ll_add)
     gdesc = ha.bookkeeper.getdesc(ll_add_graph)    
     assert len(gdesc._cache) == 2
-    assert 'Cx' in gdesc._cache
-    v1, v2 = gdesc._cache['Cx'].getargs()
-    assert isinstance(ha.binding(v1), SomeLLConcreteValue)
+    assert 'Ex' in gdesc._cache
+    v1, v2 = gdesc._cache['Ex'].getargs()
+    assert isinstance(ha.binding(v1), SomeLLAbstractConstant)
     assert isinstance(ha.binding(v2), SomeLLAbstractConstant)
+    assert ha.binding(v1).eager_concrete
     assert not ha.binding(v2).is_fixed()
 
 def test_propagate_fixing_across_func_arguments():
@@ -343,7 +347,7 @@
         z = ll_func2(z)
         return z
     hs, ha = hannotate(ll_function, [bool, int, int], annotator=True)
-    assert isinstance(hs, SomeLLConcreteValue)
+    assert hs.eager_concrete
     assert hs.concretetype == lltype.Signed
     ll_function_graph = graphof(ha.base_translator, ll_function)
     gdesc = ha.bookkeeper.getdesc(ll_function_graph)



More information about the Pypy-commit mailing list