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

pedronis at codespeak.net pedronis at codespeak.net
Tue Jan 31 14:29:38 CET 2006


Author: pedronis
Date: Tue Jan 31 14:29:25 2006
New Revision: 22891

Modified:
   pypy/dist/pypy/jit/hintmodel.py
   pypy/dist/pypy/jit/test/test_hint_annotation.py
Log:
try at specialisation for functions during hint-annotation separating signatures involving concretes and fixed and the 
rest.



Modified: pypy/dist/pypy/jit/hintmodel.py
==============================================================================
--- pypy/dist/pypy/jit/hintmodel.py	(original)
+++ pypy/dist/pypy/jit/hintmodel.py	Tue Jan 31 14:29:25 2006
@@ -74,14 +74,20 @@
             lst.append(s)
         return '<%s>' % (', '.join(lst),)
 
+    def is_fixed(self):
+        for o in self.origins:
+            if not o.fixed:
+                return False
+        return True
+
     def annotationcolor(self):
         """Compute the color of the variables with this annotation
         for the pygame viewer
         """
-        for o in self.origins:
-            if not o.fixed:
-                return None
-        return (50,140,0)
+        if self.is_fixed():
+            return (50,140,0)
+        else:
+            return None
     annotationcolor = property(annotationcolor)
 
 class SomeLLConcreteValue(SomeLLAbstractValue):
@@ -182,11 +188,49 @@
         desc = bookkeeper.getdesc(fnobj.graph)
         key = None
         alt_name = None
+        to_fix = []
         if bookkeeper.myorigin().read_fixed():
             key = 'fixed'
             alt_name = fnobj.graph.name + '_HFixed'
+        else:
+            key = []
+            specialize = False
+            for i, arg_hs in enumerate(args_hs):
+                if isinstance(arg_hs, SomeLLConcreteValue):
+                    key.append('C')
+                    specialize = True
+                elif isinstance(arg_hs, SomeLLAbstractConstant):
+                    if arg_hs.origins:
+                        fixed = True
+                        for o in arg_hs.origins:
+                            if not o.read_fixed():
+                                fixed = False
+                                break
+                        if fixed:
+                            key.append('f')
+                            # fix the corresponding SomeLLAbstractConstant
+                            # in the input signature of the specialized callee
+                            to_fix.append(i)
+                            specialize = True
+                            continue
+                    
+                    key.append('x')
+                else:
+                    key.append('x')
+            if specialize:
+                key = ''.join(key)
+                alt_name = fnobj.graph.name + '_H'+key
+            else:
+                key = None
+                                    
         input_args_hs = list(args_hs)
         graph = desc.specialize(input_args_hs, key=key, alt_name=alt_name)
+        
+        for i in to_fix:
+            inp_arg_hs = input_args_hs[i]
+            assert len(inp_arg_hs.origins) == 1
+            inp_arg_hs.origins.keys()[0].set_fixed()
+        
         hs_res = bookkeeper.annotator.recursivecall(graph,
                                                     bookkeeper.position_key,
                                                     input_args_hs)
@@ -355,7 +399,7 @@
         #if hasattr(hs_c1, 'const') or hasattr(hs_c2, 'const'):
         return SomeLLConcreteValue(hs_c1.concretetype) # MAYBE
         #else:
-        #    raise annmodel.UnionError("%s %s don't mix, unless the constant is constant" % (hs_c1, hs_c2))
+        #raise annmodel.UnionError("%s %s don't mix, unless the constant is constant" % (hs_c1, hs_c2))
 
 class __extend__(pairtype(SomeLLAbstractContainer, SomeLLAbstractContainer)):
 

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	Tue Jan 31 14:29:25 2006
@@ -76,8 +76,7 @@
     hs = hannotate(ll_function, [bool, int, int])
     assert isinstance(hs, SomeLLAbstractConstant)
     assert len(hs.origins) == 4
-    for o in hs.origins:
-        assert o.fixed
+    assert hs.is_fixed()
     assert hs.concretetype == lltype.Signed
  
 def test_simple_variable():
@@ -292,21 +291,46 @@
         else:
             z = x-y
         return z
-    def ll_function(cond, x,y, y1):
-        z1 = ll_help(cond, x, y1)
+    def ll_function(cond, x,y, x1, y1):
+        z1 = ll_help(cond, x1, y1)
         z = ll_help(cond, x, y)
         z = hint(z, concrete=True)
         return z
-    hs, ha  = hannotate(ll_function, [bool, int, int, int], annotator=True)
+    hs, ha  = hannotate(ll_function, [bool, int, int, int, int], annotator=True)
     assert isinstance(hs, SomeLLConcreteValue)
     assert hs.concretetype == lltype.Signed
     ll_help_graph = graphof(ha.base_translator, ll_help)
     gdesc = ha.bookkeeper.getdesc(ll_help_graph)
-    for o in ha.binding(gdesc._cache[None].getreturnvar()).origins:
-        assert not o.fixed
+    assert not ha.binding(gdesc._cache[None].getreturnvar()).is_fixed()
     assert len(gdesc._cache) == 2
-    for o in ha.binding(gdesc._cache['fixed'].getreturnvar()).origins:
-        assert o.fixed
+    assert ha.binding(gdesc._cache['fixed'].getreturnvar()).is_fixed()    
+
+def test_specialize_calls():
+    def ll_add(x, y):
+        return x+y
+    def ll_function(x,y):
+        z0 = ll_add(y, 2)
+        z1 = ll_add(x, y)
+        x1 = hint(x, concrete=True)
+        z2 = ll_add(x1, y)
+        return z2
+    hs, ha  = hannotate(ll_function, [int, int], annotator=True)
+    assert isinstance(hs, SomeLLConcreteValue)
+    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) == 3
+    assert 'Cx' in gdesc._cache
+    assert 'fx' in gdesc._cache
+    v1, v2 = gdesc._cache['Cx'].getargs()
+    assert isinstance(ha.binding(v1), SomeLLConcreteValue)
+    assert isinstance(ha.binding(v2), SomeLLAbstractConstant)
+    assert not ha.binding(v2).is_fixed()
+    v1, v2 = gdesc._cache['fx'].getargs()
+    assert isinstance(ha.binding(v1), SomeLLAbstractConstant)
+    assert isinstance(ha.binding(v2), SomeLLAbstractConstant)
+    assert ha.binding(v1).is_fixed()
+    assert not ha.binding(v2).is_fixed()    
     
  
 def test_hannotate_tl():



More information about the Pypy-commit mailing list