Author: Lin Cheng <[email protected]>
Branch: record-exact-value
Changeset: r96407:7264752cbbf9
Date: 2019-04-03 09:25 -0400
http://bitbucket.org/pypy/pypy/changeset/7264752cbbf9/

Log:    ( yodada, cfbolz ) Implemented the function in rlib and add llop

diff --git a/rpython/rlib/jit.py b/rpython/rlib/jit.py
--- a/rpython/rlib/jit.py
+++ b/rpython/rlib/jit.py
@@ -1193,6 +1193,36 @@
         hop.exception_is_here()
         return hop.gendirectcall(ll_record_exact_class, v_inst, v_cls)
 
+def record_exact_value(value, const_value):
+    """
+    Assure the JIT that value is the same as const_value
+    """
+    assert value is const_value
+
+def ll_record_exact_value(ll_value, ll_const_value):
+    from rpython.rlib.debug import ll_assert
+    from rpython.rtyper.lltypesystem.lloperation import llop
+    from rpython.rtyper.lltypesystem import lltype
+    ll_assert(ll_value is ll_const_value, "record_exact_value called with two 
different arguments")
+    llop.jit_record_exact_value(lltype.Void, ll_value, ll_const_value)
+
+class Entry(ExtRegistryEntry):
+    _about_ = record_exact_value
+
+    def compute_result_annotation(self, s_inst, s_const_inst):
+        from rpython.annotator import model as annmodel
+        assert isinstance(s_inst, annmodel.SomeInstance)
+        assert isinstance(s_const_inst, annmodel.SomeInstance)
+
+    def specialize_call(self, hop):
+        from rpython.rtyper.lltypesystem import lltype
+        from rpython.rtyper import rclass
+
+        v_inst = hop.inputarg(hop.args_r[0], arg=0)
+        v_const_inst = hop.inputarg(hop.args_r[1], arg=0)
+        hop.exception_is_here()
+        return hop.gendirectcall(ll_record_exact_value, v_inst, v_const_inst)
+
 def _jit_conditional_call(condition, function, *args):
     pass           # special-cased below
 
diff --git a/rpython/rlib/test/test_jit.py b/rpython/rlib/test/test_jit.py
--- a/rpython/rlib/test/test_jit.py
+++ b/rpython/rlib/test/test_jit.py
@@ -5,7 +5,7 @@
 from rpython.rlib.jit import (hint, we_are_jitted, JitDriver, elidable_promote,
     JitHintError, oopspec, isconstant, conditional_call,
     elidable, unroll_safe, dont_look_inside, conditional_call_elidable,
-    enter_portal_frame, leave_portal_frame)
+    enter_portal_frame, leave_portal_frame, record_exact_value)
 from rpython.rlib.rarithmetic import r_uint
 from rpython.rtyper.test.tool import BaseRtypingTest
 from rpython.rtyper.lltypesystem import lltype
@@ -115,6 +115,15 @@
         def f():
             pass
 
+def test_record_exact_value():
+    class A(object):
+        pass
+    a = A()
+    b = A()
+    record_exact_value(a,a) # assume not crash
+    with pytest.raises(AssertionError):
+        record_exact_value(a, b)
+
 class TestJIT(BaseRtypingTest):
     def test_hint(self):
         def f():
@@ -341,3 +350,12 @@
             leave_portal_frame()
         t = Translation(g, [])
         t.compile_c() # does not crash
+
+    def test_record_exact_value(self):
+        class A(object):
+            pass
+        def g():
+            a = A()
+            b = A()
+            record_exact_value(a,a) # assume not crash
+        self.interpret(g, [])
diff --git a/rpython/rtyper/llinterp.py b/rpython/rtyper/llinterp.py
--- a/rpython/rtyper/llinterp.py
+++ b/rpython/rtyper/llinterp.py
@@ -563,6 +563,9 @@
     def op_jit_record_exact_class(self, *args):
         pass
 
+    def op_jit_record_exact_value(self, *args):
+        pass
+
     def op_jit_conditional_call(self, *args):
         raise NotImplementedError("should not be called while not jitted")
 
diff --git a/rpython/rtyper/lltypesystem/lloperation.py 
b/rpython/rtyper/lltypesystem/lloperation.py
--- a/rpython/rtyper/lltypesystem/lloperation.py
+++ b/rpython/rtyper/lltypesystem/lloperation.py
@@ -456,6 +456,7 @@
     'jit_is_virtual':       LLOp(canrun=True),
     'jit_force_quasi_immutable': LLOp(canrun=True),
     'jit_record_exact_class'  : LLOp(canrun=True),
+    'jit_record_exact_value'  : LLOp(canrun=True),
     'jit_ffi_save_result':  LLOp(canrun=True),
     'jit_conditional_call': LLOp(),
     'jit_conditional_call_value': LLOp(),
diff --git a/rpython/rtyper/lltypesystem/opimpl.py 
b/rpython/rtyper/lltypesystem/opimpl.py
--- a/rpython/rtyper/lltypesystem/opimpl.py
+++ b/rpython/rtyper/lltypesystem/opimpl.py
@@ -636,6 +636,9 @@
 def op_jit_record_exact_class(x, y):
     pass
 
+def op_jit_record_exact_value(x, y):
+    pass
+
 def op_jit_ffi_save_result(*args):
     pass
 
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to