[pypy-svn] r22768 - in pypy/dist/pypy: annotation jit jit/test

pedronis at codespeak.net pedronis at codespeak.net
Sat Jan 28 12:24:55 CET 2006


Author: pedronis
Date: Sat Jan 28 12:24:51 2006
New Revision: 22768

Modified:
   pypy/dist/pypy/annotation/annrpython.py
   pypy/dist/pypy/annotation/bookkeeper.py
   pypy/dist/pypy/jit/hintbookkeeper.py
   pypy/dist/pypy/jit/hintmodel.py
   pypy/dist/pypy/jit/test/test_hint_annotation.py
Log:
(arre, arigo, pedronis)

implemented hint support (constant -> concrete).



Modified: pypy/dist/pypy/annotation/annrpython.py
==============================================================================
--- pypy/dist/pypy/annotation/annrpython.py	(original)
+++ pypy/dist/pypy/annotation/annrpython.py	Sat Jan 28 12:24:51 2006
@@ -197,7 +197,7 @@
         elif isinstance(arg, Constant):
             #if arg.value is undefined_value:   # undefined local variables
             #    return annmodel.SomeImpossibleValue()
-            return self.bookkeeper.immutablevalue(arg.value)
+            return self.bookkeeper.immutableconstant(arg)
         else:
             raise TypeError, 'Variable or Constant expected, got %r' % (arg,)
 

Modified: pypy/dist/pypy/annotation/bookkeeper.py
==============================================================================
--- pypy/dist/pypy/annotation/bookkeeper.py	(original)
+++ pypy/dist/pypy/annotation/bookkeeper.py	Sat Jan 28 12:24:51 2006
@@ -292,6 +292,9 @@
             dictdef.generalize_value(s_value)
         return SomeDict(dictdef)
 
+    def immutableconstant(self, const):
+        return self.immutablevalue(const.value)
+
     def immutablevalue(self, x):
         """The most precise SomeValue instance that contains the
         immutable value x."""

Modified: pypy/dist/pypy/jit/hintbookkeeper.py
==============================================================================
--- pypy/dist/pypy/jit/hintbookkeeper.py	(original)
+++ pypy/dist/pypy/jit/hintbookkeeper.py	Sat Jan 28 12:24:51 2006
@@ -31,6 +31,12 @@
     def compute_at_fixpoint(self):
         pass
 
+    def immutableconstant(self, const):
+        from pypy.jit import hintmodel
+        res = hintmodel.SomeLLAbstractConstant(const.concretetype, {})
+        res.const = const.value
+        return res
+
 # get current bookkeeper
 
 def getbookkeeper():

Modified: pypy/dist/pypy/jit/hintmodel.py
==============================================================================
--- pypy/dist/pypy/jit/hintmodel.py	(original)
+++ pypy/dist/pypy/jit/hintmodel.py	Sat Jan 28 12:24:51 2006
@@ -3,12 +3,14 @@
 from pypy.jit.hintbookkeeper import getbookkeeper
 from pypy.rpython.lltypesystem import lltype
 
-UNARY_OPERATIONS = "same_as".split()
+UNARY_OPERATIONS = "same_as hint".split()
 
 BINARY_OPERATIONS = "int_add int_sub".split()
 
 class OriginTreeNode(object):
 
+    fixed = False
+
     def __init__(self, origins=None):
         if origins is None:
             origins = {}
@@ -17,6 +19,16 @@
     def merge(self, nodes):
         self.origins.update(nodes)
 
+    def visit(self, seen=None):
+        if seen is None:
+            seen = {}
+        yield self
+        for o in self.origins:
+            if o not in seen:
+                seen[o] = True
+                for o1 in o.visit(seen):
+                    yield o1
+                    
 class SomeLLAbstractValue(annmodel.SomeObject):
 
     def __init__(self, T):
@@ -31,11 +43,26 @@
         SomeLLAbstractValue.__init__(self, T)
         self.origins = origins
 
+class SomeLLConcreteValue(SomeLLAbstractValue):
+    pass
+
+# ____________________________________________________________
+# operations
+
 class __extend__(SomeLLAbstractValue):
 
     def same_as(hs_v1):
         return hs_v1
 
+class __extend__(SomeLLAbstractConstant):
+
+    def hint(hs_c1, hs_flags):
+        assert hs_flags.const['concrete']
+        for o in hs_c1.origins:
+            for o1 in o.visit():
+                o1.fixed = True
+        return SomeLLConcreteValue(hs_c1.concretetype)
+
 class __extend__(pairtype(SomeLLAbstractConstant, SomeLLAbstractConstant)):
 
     def int_add((hs_c1, hs_c2)):

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	Sat Jan 28 12:24:51 2006
@@ -1,7 +1,8 @@
 from pypy.translator.translator import TranslationContext, graphof
 from pypy.jit.hintannotator import HintAnnotator
-from pypy.jit.hintmodel import SomeLLAbstractConstant, OriginTreeNode
+from pypy.jit.hintmodel import SomeLLAbstractConstant, SomeLLConcreteValue, OriginTreeNode
 from pypy.rpython.lltypesystem import lltype
+from pypy.rpython.objectmodel import hint
 
 def hannotate(func, argtypes):
     # build the normal ll graphs for ll_function
@@ -37,3 +38,36 @@
     assert isinstance(hs, SomeLLAbstractConstant)
     assert len(hs.origins) == 2
     assert hs.concretetype == lltype.Signed
+
+
+def test_simple_hint_result():
+    def ll_function(cond, x,y):
+        if cond:
+            z = x+y
+        else:
+            z = x-y
+        z = hint(z, concrete=True)
+        return z
+    hs = hannotate(ll_function, [bool, int, int])
+    assert isinstance(hs, SomeLLConcreteValue)
+    assert hs.concretetype == lltype.Signed
+  
+def test_simple_hint_origins():
+    def ll_function(cond, x,y):
+        if cond:
+            z = x+y
+        else:
+            z = x-y
+        z1 = hint(z, concrete=True)
+        return z # origin of z1
+    hs = hannotate(ll_function, [bool, int, int])
+    assert isinstance(hs, SomeLLAbstractConstant)
+    assert len(hs.origins) == 2
+    for o in hs.origins:
+        assert o.fixed
+        assert len(o.origins) == 2
+        for o in o.origins:
+            assert o.fixed
+            assert not o.origins
+    assert hs.concretetype == lltype.Signed
+ 



More information about the Pypy-commit mailing list