[pypy-commit] pypy string-promote-2: a branch to experiment with promoting strings

fijal noreply at buildbot.pypy.org
Sun Oct 9 21:09:55 CEST 2011


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: string-promote-2
Changeset: r47909:8bc71436e96c
Date: 2011-10-09 21:09 +0200
http://bitbucket.org/pypy/pypy/changeset/8bc71436e96c/

Log:	a branch to experiment with promoting strings

diff --git a/pypy/jit/codewriter/jtransform.py b/pypy/jit/codewriter/jtransform.py
--- a/pypy/jit/codewriter/jtransform.py
+++ b/pypy/jit/codewriter/jtransform.py
@@ -455,6 +455,12 @@
             # the special return value None forces op.result to be considered
             # equal to op.args[0]
             return [op0, op1, None]
+        if (hints.get('string_promote') and
+            op.args[0].concretetype is not lltype.Void):
+            assert op.args[0].concretetype == lltype.Ptr(rstr.STR)
+            op0 = SpaceOperation('-live-', [], None)
+            op1 = SpaceOperation('str_guard_value', [op.args[0]], op.result)
+            return [op0, op1, None]
         else:
             log.WARNING('ignoring hint %r at %r' % (hints, self.graph))
 
diff --git a/pypy/jit/codewriter/test/test_jtransform.py b/pypy/jit/codewriter/test/test_jtransform.py
--- a/pypy/jit/codewriter/test/test_jtransform.py
+++ b/pypy/jit/codewriter/test/test_jtransform.py
@@ -844,6 +844,20 @@
     assert op1.args[2] == ListOfKind('ref', [v1, v2])
     assert op1.result == v3
 
+def test_str_promote():
+    PSTR = lltype.Ptr(rstr.STR)
+    v1 = varoftype(PSTR)
+    v2 = varoftype(PSTR)
+    op = SpaceOperation('hint',
+                        [v1, Constant({'string_promote': True}, lltype.Void)],
+                        v2)
+    tr = Transformer(FakeCPU(), FakeBuiltinCallControl())
+    op0, op1, _ = tr.rewrite_operation(op)
+    assert op0.opname == '-live-'
+    assert op1.opname == 'str_guard_value'
+    assert op1.args == [v1]
+    assert op1.result == v2
+
 def test_unicode_concat():
     # test that the oopspec is present and correctly transformed
     PSTR = lltype.Ptr(rstr.UNICODE)
diff --git a/pypy/rlib/jit.py b/pypy/rlib/jit.py
--- a/pypy/rlib/jit.py
+++ b/pypy/rlib/jit.py
@@ -38,6 +38,7 @@
     possible arguments are:
 
     * promote - promote the argument from a variable into a constant
+    * string_promote - same, but promote string by *value*
     * access_directly - directly access a virtualizable, as a structure
                         and don't treat it as a virtualizable
     * fresh_virtualizable - means that virtualizable was just allocated.
@@ -51,6 +52,9 @@
 def promote(x):
     return hint(x, promote=True)
 
+def promote_string(x):
+    return hint(x, promote_string=True)
+
 def dont_look_inside(func):
     """ Make sure the JIT does not trace inside decorated function
     (it becomes a call instead)


More information about the pypy-commit mailing list