[pypy-svn] r40586 - in pypy/branch/jit-virtual-world/pypy/jit: hintannotator timeshifter timeshifter/test

pedronis at codespeak.net pedronis at codespeak.net
Fri Mar 16 16:45:32 CET 2007


Author: pedronis
Date: Fri Mar 16 16:45:29 2007
New Revision: 40586

Modified:
   pypy/branch/jit-virtual-world/pypy/jit/hintannotator/model.py
   pypy/branch/jit-virtual-world/pypy/jit/timeshifter/hrtyper.py
   pypy/branch/jit-virtual-world/pypy/jit/timeshifter/test/test_frontend.py
Log:
(arigo, pedronis)

- implement _is_early_constant to timeshifts to a constant-check for red boxes and to true for green variables




Modified: pypy/branch/jit-virtual-world/pypy/jit/hintannotator/model.py
==============================================================================
--- pypy/branch/jit-virtual-world/pypy/jit/hintannotator/model.py	(original)
+++ pypy/branch/jit-virtual-world/pypy/jit/hintannotator/model.py	Fri Mar 16 16:45:29 2007
@@ -17,6 +17,7 @@
                       cast_bool_to_int
                       ptr_nonzero
                       ptr_iszero
+                      is_early_constant
                       """.split()
 
 BINARY_OPERATIONS = """int_add int_sub int_mul int_mod int_and int_rshift
@@ -327,6 +328,8 @@
 
         raise HintError("hint %s makes no sense on %r" % (hs_flags.const,
                                                           hs_v1))
+    def is_early_constant(hs_v1):
+        return SomeLLAbstractConstant(lltype.Bool, {})
 
     def getfield(hs_v1, hs_fieldname):
         S = hs_v1.concretetype.TO

Modified: pypy/branch/jit-virtual-world/pypy/jit/timeshifter/hrtyper.py
==============================================================================
--- pypy/branch/jit-virtual-world/pypy/jit/timeshifter/hrtyper.py	(original)
+++ pypy/branch/jit-virtual-world/pypy/jit/timeshifter/hrtyper.py	Fri Mar 16 16:45:29 2007
@@ -1008,6 +1008,12 @@
                   [v_jitstate     , c_index                          , c_TYPE],
                   s_result)
 
+    def translate_op_is_early_constant(self, hop):
+        hs = hop.args_s[0]
+        if hs.is_green():
+            return hop.inputconst(lltype.Bool, True)
+        return self.translate_op_is_constant(hop)
+
     def translate_op_is_constant(self, hop):
         hs = hop.args_s[0]
         r_arg = self.getredrepr(originalconcretetype(hs))

Modified: pypy/branch/jit-virtual-world/pypy/jit/timeshifter/test/test_frontend.py
==============================================================================
--- pypy/branch/jit-virtual-world/pypy/jit/timeshifter/test/test_frontend.py	(original)
+++ pypy/branch/jit-virtual-world/pypy/jit/timeshifter/test/test_frontend.py	Fri Mar 16 16:45:29 2007
@@ -1,4 +1,4 @@
-from pypy.rlib.objectmodel import we_are_jitted, _is_early_constant
+from pypy.rlib.objectmodel import we_are_jitted, _is_early_constant, hint
 from pypy.rpython.test.test_llinterp import interpret
 from pypy.jit.timeshifter.test.test_timeshift import TimeshiftingTests
 
@@ -17,3 +17,23 @@
         res = self.timeshift(f, [])
         assert res == 42
 
+    def test_is_early_constant(self):
+        def f(x):
+            if _is_early_constant(x):
+                return 42
+            return 0
+
+        res = self.timeshift(f, [5])
+        assert res == 0
+        res = self.timeshift(f, [5], [0])
+        assert res == 42
+
+    def test_is_early_constant_for_green(self):
+        def g(x):
+            if _is_early_constant(x):
+                return 42
+            hint(x, concrete=True)
+            return 0
+        
+        res = self.timeshift(g, [5])
+        assert res == 42        



More information about the Pypy-commit mailing list