Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r69468:0e5972cfb8d4
Date: 2014-02-26 18:35 +0100
http://bitbucket.org/pypy/pypy/changeset/0e5972cfb8d4/

Log:    Allow @jit.elidable_promote to work also with string arguments. Done
        with a hack of saying hint(arg, promote=True, promote_string=True)
        and letting jtransform.py choose.

diff --git a/rpython/jit/codewriter/jtransform.py 
b/rpython/jit/codewriter/jtransform.py
--- a/rpython/jit/codewriter/jtransform.py
+++ b/rpython/jit/codewriter/jtransform.py
@@ -499,6 +499,16 @@
 
     def rewrite_op_hint(self, op):
         hints = op.args[1].value
+
+        # hack: if there are both 'promote' and 'promote_string', kill
+        # one of them based on the type of the value
+        if hints.get('promote_string') and hints.get('promote'):
+            hints = hints.copy()
+            if op.args[0].concretetype == lltype.Ptr(rstr.STR):
+                del hints['promote']
+            else:
+                del hints['promote_string']
+
         if hints.get('promote') and op.args[0].concretetype is not lltype.Void:
             assert op.args[0].concretetype != lltype.Ptr(rstr.STR)
             kind = getkind(op.args[0].concretetype)
diff --git a/rpython/jit/codewriter/test/test_jtransform.py 
b/rpython/jit/codewriter/test/test_jtransform.py
--- a/rpython/jit/codewriter/test/test_jtransform.py
+++ b/rpython/jit/codewriter/test/test_jtransform.py
@@ -1050,6 +1050,37 @@
     assert op1.result == v2
     assert op0.opname == '-live-'
 
+def test_double_promote_str():
+    PSTR = lltype.Ptr(rstr.STR)
+    v1 = varoftype(PSTR)
+    v2 = varoftype(PSTR)
+    tr = Transformer(FakeCPU(), FakeBuiltinCallControl())
+    op1 = SpaceOperation('hint',
+                         [v1, Constant({'promote_string': True}, lltype.Void)],
+                         v2)
+    op2 = SpaceOperation('hint',
+                         [v1, Constant({'promote_string': True,
+                                        'promote': True}, lltype.Void)],
+                         v2)
+    lst1 = tr.rewrite_operation(op1)
+    lst2 = tr.rewrite_operation(op2)
+    assert lst1 == lst2
+
+def test_double_promote_nonstr():
+    v1 = varoftype(lltype.Signed)
+    v2 = varoftype(lltype.Signed)
+    tr = Transformer(FakeCPU(), FakeBuiltinCallControl())
+    op1 = SpaceOperation('hint',
+                         [v1, Constant({'promote': True}, lltype.Void)],
+                         v2)
+    op2 = SpaceOperation('hint',
+                         [v1, Constant({'promote_string': True,
+                                        'promote': True}, lltype.Void)],
+                         v2)
+    lst1 = tr.rewrite_operation(op1)
+    lst2 = tr.rewrite_operation(op2)
+    assert lst1 == lst2
+
 def test_unicode_concat():
     # test that the oopspec is present and correctly transformed
     PSTR = lltype.Ptr(rstr.UNICODE)
diff --git a/rpython/rlib/jit.py b/rpython/rlib/jit.py
--- a/rpython/rlib/jit.py
+++ b/rpython/rlib/jit.py
@@ -130,7 +130,9 @@
         if promote_args != 'all':
             args = [args[int(i)] for i in promote_args.split(",")]
         for arg in args:
-            code.append("    %s = hint(%s, promote=True)\n" % (arg, arg))
+            code.append( #use both hints, and let jtransform pick the right one
+                "    %s = hint(%s, promote=True, promote_string=True)\n" %
+                (arg, arg))
         code.append("    return _orig_func_unlikely_name(%s)\n" % (argstring, 
))
         d = {"_orig_func_unlikely_name": func, "hint": hint}
         exec py.code.Source("\n".join(code)).compile() in d
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to