[pypy-svn] r41992 - in pypy/dist/pypy/jit: codegen/llgraph hintannotator hintannotator/test timeshifter/test

arigo at codespeak.net arigo at codespeak.net
Tue Apr 10 20:16:02 CEST 2007


Author: arigo
Date: Tue Apr 10 20:16:02 2007
New Revision: 41992

Modified:
   pypy/dist/pypy/jit/codegen/llgraph/llimpl.py
   pypy/dist/pypy/jit/hintannotator/model.py
   pypy/dist/pypy/jit/hintannotator/test/test_annotator.py
   pypy/dist/pypy/jit/timeshifter/test/test_portal.py
Log:
cast_ptr_to_int support.


Modified: pypy/dist/pypy/jit/codegen/llgraph/llimpl.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/llgraph/llimpl.py	(original)
+++ pypy/dist/pypy/jit/codegen/llgraph/llimpl.py	Tue Apr 10 20:16:02 2007
@@ -167,11 +167,17 @@
     block.operations.append(op)
     return to_opaque_object(erasedvar(v, block))
 
+RESULT_TYPES = {
+    'cast_ptr_to_int': lltype.Signed,
+    }
+
 def guess_result_type(opname, opvars):
     if opname.endswith('_zer'):   # h
         opname = opname[:-4]      # a
     if opname.endswith('_ovf'):   # c
         opname = opname[:-4]      # k
+    if opname in RESULT_TYPES:
+        return RESULT_TYPES[opname]
     op = getattr(llop, opname)
     need_result_type = getattr(op.fold, 'need_result_type', False)
     assert not need_result_type, ("cannot guess the result type of %r"

Modified: pypy/dist/pypy/jit/hintannotator/model.py
==============================================================================
--- pypy/dist/pypy/jit/hintannotator/model.py	(original)
+++ pypy/dist/pypy/jit/hintannotator/model.py	Tue Apr 10 20:16:02 2007
@@ -15,6 +15,7 @@
                       cast_uint_to_int
                       cast_char_to_int
                       cast_bool_to_int
+                      cast_ptr_to_int
                       ptr_nonzero
                       ptr_iszero
                       is_early_constant

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	Tue Apr 10 20:16:02 2007
@@ -909,3 +909,13 @@
     assert hs.is_green()
     for graph in hannotator.translator.graphs:
         assert 'int_mul' not in flowmodel.summary(graph)
+
+
+def test_cast_ptr_to_int():
+    GCS1 = lltype.GcStruct('s1', ('x', lltype.Signed))
+    def f():
+        p = lltype.malloc(GCS1)
+        return lltype.cast_ptr_to_int(p)
+
+    hs = hannotate(f, [], policy=P_NOVIRTUAL)
+    assert not hs.is_green()

Modified: pypy/dist/pypy/jit/timeshifter/test/test_portal.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/test/test_portal.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/test/test_portal.py	Tue Apr 10 20:16:02 2007
@@ -5,6 +5,7 @@
 from pypy.jit.timeshifter.test.test_timeshift import P_NOVIRTUAL, StopAtXPolicy
 from pypy.jit.timeshifter.test.test_vlist import P_OOPSPEC
 from pypy.rpython.llinterp import LLInterpreter
+from pypy.rpython.lltypesystem import lltype
 from pypy.objspace.flow.model import  summary
 from pypy.rlib.objectmodel import hint
 from pypy.jit.codegen.llgraph.rgenop import RGenOp as LLRGenOp
@@ -517,3 +518,14 @@
 
         res = self.timeshift_from_portal(f, f, [15], policy=P_OOPSPEC)
         assert res == 15
+
+    def test_cast_ptr_to_int(self):
+        GCS1 = lltype.GcStruct('s1', ('x', lltype.Signed))
+        def g(p):
+            return lltype.cast_ptr_to_int(p)
+        def f():
+            p = lltype.malloc(GCS1)
+            return g(p) - lltype.cast_ptr_to_int(p)
+
+        res = self.timeshift_from_portal(f, g, [], policy=P_NOVIRTUAL)
+        assert res == 0



More information about the Pypy-commit mailing list