[pypy-commit] pypy stm-thread-2: Support for mangling the calls to ptr_eq.
arigo
noreply at buildbot.pypy.org
Tue Sep 11 16:49:56 CEST 2012
Author: Armin Rigo <arigo at tunes.org>
Branch: stm-thread-2
Changeset: r57293:bc6fba36bb22
Date: 2012-09-11 16:47 +0200
http://bitbucket.org/pypy/pypy/changeset/bc6fba36bb22/
Log: Support for mangling the calls to ptr_eq.
diff --git a/pypy/jit/backend/llsupport/gc.py b/pypy/jit/backend/llsupport/gc.py
--- a/pypy/jit/backend/llsupport/gc.py
+++ b/pypy/jit/backend/llsupport/gc.py
@@ -860,9 +860,14 @@
[lltype.Signed] * 2)
if self.stm:
+ # XXX remove the indirections in the following calls
from pypy.rlib import rstm
self.generate_function('stm_try_inevitable',
rstm.become_inevitable, [])
+ def ptr_eq(x, y): return x == y
+ def ptr_ne(x, y): return x != y
+ self.generate_function('stm_ptr_eq', ptr_eq, [llmemory.GCREF] * 2)
+ self.generate_function('stm_ptr_ne', ptr_ne, [llmemory.GCREF] * 2)
def _bh_malloc(self, sizedescr):
from pypy.rpython.memory.gctypelayout import check_typeid
diff --git a/pypy/jit/backend/llsupport/stmrewrite.py b/pypy/jit/backend/llsupport/stmrewrite.py
--- a/pypy/jit/backend/llsupport/stmrewrite.py
+++ b/pypy/jit/backend/llsupport/stmrewrite.py
@@ -1,6 +1,7 @@
from pypy.jit.backend.llsupport.rewrite import GcRewriterAssembler
from pypy.jit.metainterp.resoperation import ResOperation, rop
from pypy.jit.metainterp.history import BoxPtr, ConstPtr, ConstInt
+from pypy.rlib.objectmodel import specialize
#
# STM Support
@@ -44,6 +45,11 @@
for op in operations:
if op.getopnum() == rop.DEBUG_MERGE_POINT:
continue
+ # ---------- ptr_eq ----------
+ if op.getopnum() in (rop.PTR_EQ, rop.INSTANCE_PTR_EQ,
+ rop.PTR_NE, rop.INSTANCE_PTR_NE):
+ self.handle_ptr_eq(op)
+ continue
# ---------- pure operations, guards ----------
if op.is_always_pure() or op.is_guard() or op.is_ovf():
self.newops.append(op)
@@ -146,12 +152,31 @@
# then a read barrier the source string
self.handle_category_operations(op, 'R')
+ @specialize.arg(1)
+ def _do_stm_call(self, funcname, args, result):
+ addr = self.gc_ll_descr.get_malloc_fn_addr(funcname)
+ descr = getattr(self.gc_ll_descr, funcname + '_descr')
+ op1 = ResOperation(rop.CALL, [ConstInt(addr)] + args,
+ result, descr=descr)
+ self.newops.append(op1)
+
def fallback_inevitable(self, op):
self.known_category.clear()
if not self.always_inevitable:
- addr = self.gc_ll_descr.get_malloc_fn_addr('stm_try_inevitable')
- descr = self.gc_ll_descr.stm_try_inevitable_descr
- op1 = ResOperation(rop.CALL, [ConstInt(addr)], None, descr=descr)
- self.newops.append(op1)
+ self._do_stm_call('stm_try_inevitable', [], None)
self.always_inevitable = True
self.newops.append(op)
+
+ def _is_null(self, box):
+ return isinstance(box, ConstPtr) and not box.value
+
+ def handle_ptr_eq(self, op):
+ if self._is_null(op.getarg(0)) or self._is_null(op.getarg(1)):
+ self.newops.append(op)
+ return
+ args = op.getarglist()
+ result = op.result
+ if op.getopnum() in (rop.PTR_EQ, rop.INSTANCE_PTR_EQ):
+ self._do_stm_call('stm_ptr_eq', args, result)
+ else:
+ self._do_stm_call('stm_ptr_ne', args, result)
diff --git a/pypy/jit/backend/llsupport/test/test_stmrewrite.py b/pypy/jit/backend/llsupport/test/test_stmrewrite.py
--- a/pypy/jit/backend/llsupport/test/test_stmrewrite.py
+++ b/pypy/jit/backend/llsupport/test/test_stmrewrite.py
@@ -136,7 +136,6 @@
"guard_true(i1) [i2]", # all guards
"i3 = int_add(i1, i2)", # all pure operations
"f3 = float_abs(f1)",
- "i3 = ptr_eq(p1, p2)",
"i3 = force_token()",
"i3 = read_timestamp()",
"i3 = mark_opaque_ptr(p1)",
@@ -487,3 +486,58 @@
setfield_gc(p1, 20, descr=tydescr)
jump(p1)
""" % op)
+
+ def test_ptr_eq_null(self):
+ self.check_rewrite("""
+ [p1, p2]
+ i1 = ptr_eq(p1, NULL)
+ jump(i1)
+ """, """
+ [p1, p2]
+ i1 = ptr_eq(p1, NULL)
+ jump(i1)
+ """)
+
+ def test_ptr_eq(self):
+ self.check_rewrite("""
+ [p1, p2]
+ i1 = ptr_eq(p1, p2)
+ jump(i1)
+ """, """
+ [p1, p2]
+ i1 = call(ConstClass(stm_ptr_eq), p1, p2, descr=stm_ptr_eq_descr)
+ jump(i1)
+ """)
+
+ def test_instance_ptr_eq(self):
+ self.check_rewrite("""
+ [p1, p2]
+ i1 = instance_ptr_eq(p1, p2)
+ jump(i1)
+ """, """
+ [p1, p2]
+ i1 = call(ConstClass(stm_ptr_eq), p1, p2, descr=stm_ptr_eq_descr)
+ jump(i1)
+ """)
+
+ def test_ptr_ne(self):
+ self.check_rewrite("""
+ [p1, p2]
+ i1 = ptr_ne(p1, p2)
+ jump(i1)
+ """, """
+ [p1, p2]
+ i1 = call(ConstClass(stm_ptr_ne), p1, p2, descr=stm_ptr_ne_descr)
+ jump(i1)
+ """)
+
+ def test_instance_ptr_ne(self):
+ self.check_rewrite("""
+ [p1, p2]
+ i1 = instance_ptr_ne(p1, p2)
+ jump(i1)
+ """, """
+ [p1, p2]
+ i1 = call(ConstClass(stm_ptr_ne), p1, p2, descr=stm_ptr_ne_descr)
+ jump(i1)
+ """)
More information about the pypy-commit
mailing list