[pypy-svn] r69877 - in pypy/branch/virtual-forcing/pypy: rlib rlib/test rpython/lltypesystem
arigo at codespeak.net
arigo at codespeak.net
Thu Dec 3 20:03:42 CET 2009
Author: arigo
Date: Thu Dec 3 20:03:41 2009
New Revision: 69877
Modified:
pypy/branch/virtual-forcing/pypy/rlib/_jit_vref.py
pypy/branch/virtual-forcing/pypy/rlib/jit.py
pypy/branch/virtual-forcing/pypy/rlib/test/test__jit_vref.py
pypy/branch/virtual-forcing/pypy/rpython/lltypesystem/lloperation.py
pypy/branch/virtual-forcing/pypy/rpython/lltypesystem/opimpl.py
Log:
Finish the part in rlib. Missing tests for some cases,
which I think I really need to write in metainterp/test.
Modified: pypy/branch/virtual-forcing/pypy/rlib/_jit_vref.py
==============================================================================
--- pypy/branch/virtual-forcing/pypy/rlib/_jit_vref.py (original)
+++ pypy/branch/virtual-forcing/pypy/rlib/_jit_vref.py Thu Dec 3 20:03:41 2009
@@ -1,6 +1,9 @@
from pypy.annotation import model as annmodel
+from pypy.rpython.extregistry import ExtRegistryEntry
from pypy.rpython.rclass import getinstancerepr
from pypy.rpython.rmodel import Repr
+from pypy.rpython.lltypesystem.lloperation import llop
+from pypy.rpython.lltypesystem.rclass import OBJECTPTR
class SomeVRef(annmodel.SomeObject):
@@ -12,26 +15,39 @@
return self.s_instance
def rtyper_makerepr(self, rtyper):
- return get_vref(rtyper)
+ if not hasattr(rtyper, '_vrefrepr'):
+ rtyper._vrefrepr = VRefRepr(rtyper)
+ return rtyper._vrefrepr
def rtyper_makekey(self):
return self.__class__,
-def specialize_call(hop):
- [v] = hop.inputargs(getinstancerepr(hop.rtyper, None))
- return v
-
-def get_vref(rtyper):
- if not hasattr(rtyper, '_vrefrepr'):
- rtyper._vrefrepr = VRefRepr(rtyper)
- return rtyper._vrefrepr
-
-
class VRefRepr(Repr):
def __init__(self, rtyper):
self.lowleveltype = getinstancerepr(rtyper, None).lowleveltype
+ def specialize_call(self, hop):
+ [v] = hop.inputargs(getinstancerepr(hop.rtyper, None))
+ return v
+
def rtype_simple_call(self, hop):
[v] = hop.inputargs(self)
+ v = hop.genop('jit_virtual_force', [v], resulttype = OBJECTPTR)
return hop.genop('cast_pointer', [v], resulttype = hop.r_result)
+
+# ____________________________________________________________
+
+
+def jit_virtual_ref(x):
+ raise Exception("should not be reached")
+
+class Entry(ExtRegistryEntry):
+ _about_ = jit_virtual_ref
+
+ def compute_result_annotation(self, s_obj):
+ return SomeVRef(s_obj)
+
+ def specialize_call(self, hop):
+ [v] = hop.inputargs(getinstancerepr(hop.rtyper, None))
+ return hop.genop('jit_virtual_ref', [v], resulttype = hop.r_result)
Modified: pypy/branch/virtual-forcing/pypy/rlib/jit.py
==============================================================================
--- pypy/branch/virtual-forcing/pypy/rlib/jit.py (original)
+++ pypy/branch/virtual-forcing/pypy/rlib/jit.py Thu Dec 3 20:03:41 2009
@@ -102,7 +102,11 @@
# VRefs
def virtual_ref(x):
- return DirectVRef(x)
+ if we_are_jitted():
+ from pypy.rlib import _jit_vref
+ return _jit_vref.jit_virtual_ref(x)
+ else:
+ return DirectVRef(x)
class DirectVRef(object):
def __init__(self, x):
@@ -110,18 +114,17 @@
def __call__(self):
return self._x
def _freeze_(self):
- raise Exception("should not see a prebuilt pypy.rlib.jit.virtual_ref")
+ raise Exception("should not see a prebuilt virtual_ref")
class Entry(ExtRegistryEntry):
- _about_ = virtual_ref
+ _about_ = DirectVRef
def compute_result_annotation(self, s_obj):
from pypy.rlib import _jit_vref
return _jit_vref.SomeVRef(s_obj)
def specialize_call(self, hop):
- from pypy.rlib import _jit_vref
- return _jit_vref.specialize_call(hop)
+ return hop.r_result.specialize_call(hop)
# ____________________________________________________________
# User interface for the hotpath JIT policy
Modified: pypy/branch/virtual-forcing/pypy/rlib/test/test__jit_vref.py
==============================================================================
--- pypy/branch/virtual-forcing/pypy/rlib/test/test__jit_vref.py (original)
+++ pypy/branch/virtual-forcing/pypy/rlib/test/test__jit_vref.py Thu Dec 3 20:03:41 2009
@@ -10,6 +10,12 @@
class X(object):
pass
+class Y(X):
+ pass
+
+class Z(X):
+ pass
+
def test_direct():
x1 = X()
@@ -34,6 +40,18 @@
assert isinstance(s, annmodel.SomeInstance)
assert s.classdef == a.bookkeeper.getuniqueclassdef(X)
+def test_annotate_3():
+ def f(n):
+ if n > 0:
+ return virtual_ref(Y())
+ else:
+ return virtual_ref(Z())
+ a = RPythonAnnotator()
+ s = a.build_types(f, [int])
+ assert isinstance(s, SomeVRef)
+ assert isinstance(s.s_instance, annmodel.SomeInstance)
+ assert s.s_instance.classdef == a.bookkeeper.getuniqueclassdef(X)
+
def test_rtype_1():
def f():
return virtual_ref(X())
@@ -46,3 +64,14 @@
return vref()
x = interpret(f, [])
assert lltype.castable(OBJECTPTR, lltype.typeOf(x)) > 0
+
+def test_rtype_3():
+ def f(n):
+ if n > 0:
+ return virtual_ref(Y())
+ else:
+ return virtual_ref(Z())
+ x = interpret(f, [-5])
+ assert lltype.typeOf(x) == OBJECTPTR
+
+# the path "we_are_jitted()" is tested in jit/metainterp/test/test_codewriter.
Modified: pypy/branch/virtual-forcing/pypy/rpython/lltypesystem/lloperation.py
==============================================================================
--- pypy/branch/virtual-forcing/pypy/rpython/lltypesystem/lloperation.py (original)
+++ pypy/branch/virtual-forcing/pypy/rpython/lltypesystem/lloperation.py Thu Dec 3 20:03:41 2009
@@ -434,6 +434,8 @@
'do_malloc_varsize_clear': LLOp(canunwindgc=True),
'get_write_barrier_failing_case': LLOp(sideeffects=False),
'gc_get_type_info_group': LLOp(sideeffects=False),
+ 'jit_virtual_ref': LLOp(),
+ 'jit_virtual_force': LLOp(canfold=True),
# __________ GC operations __________
Modified: pypy/branch/virtual-forcing/pypy/rpython/lltypesystem/opimpl.py
==============================================================================
--- pypy/branch/virtual-forcing/pypy/rpython/lltypesystem/opimpl.py (original)
+++ pypy/branch/virtual-forcing/pypy/rpython/lltypesystem/opimpl.py Thu Dec 3 20:03:41 2009
@@ -489,6 +489,9 @@
def op_gc_assume_young_pointers(addr):
pass
+def op_jit_virtual_force(x):
+ return x
+
# ____________________________________________________________
def get_op_impl(opname):
More information about the Pypy-commit
mailing list