[pypy-svn] r64497 - in pypy/branch/pyjitpl5-simplify/pypy/jit: backend backend/llgraph metainterp metainterp/test
antocuni at codespeak.net
antocuni at codespeak.net
Tue Apr 21 12:10:53 CEST 2009
Author: antocuni
Date: Tue Apr 21 12:10:53 2009
New Revision: 64497
Modified:
pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/runner.py
pypy/branch/pyjitpl5-simplify/pypy/jit/backend/model.py
pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/codewriter.py
pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/pyjitpl.py
pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/resoperation.py
pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/test/test_basic.py
Log:
(arigo, antocuni)
- implement the new ootype operation runtimenew
- introduce MethDesc, to be able to fish jitcode for a specific method of a
given class
- a new test passes :-)
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/runner.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/runner.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/runner.py Tue Apr 21 12:10:53 2009
@@ -419,6 +419,13 @@
assert isinstance(typedescr, TypeDescr)
return typedescr.create()
+ def do_runtimenew(self, args, descr):
+ "NOT_RPYTHON"
+ classbox = args[0]
+ classobj = ootype.cast_from_object(ootype.Class, classbox.getobj())
+ res = ootype.runtimenew(classobj)
+ return history.BoxObj(ootype.cast_to_object(res))
+
def do_getfield_gc(self, args, fielddescr):
assert isinstance(fielddescr, FieldDescr)
return fielddescr.getfield(args[0])
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/backend/model.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/backend/model.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/backend/model.py Tue Apr 21 12:10:53 2009
@@ -127,6 +127,9 @@
# ootype specific operations
# --------------------------
+ def do_runtimenew(cpu, args, descr=None):
+ raise NotImplementedError
+
def do_oosend(cpu, args, descr=None):
raise NotImplementedError
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/codewriter.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/codewriter.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/codewriter.py Tue Apr 21 12:10:53 2009
@@ -69,6 +69,22 @@
self.bytecode_for_address = bytecode_for_address
self.dict = None
+class MethDesc(history.AbstractValue):
+
+ def __init__(self, codewriter, INSTANCE, methname):
+ self.jitcodes = {} # runtimeClass -> jitcode for runtimeClass.methname
+ TYPES = INSTANCE._all_subclasses()
+ for T in TYPES:
+ #desc = self.register_typedesc_for_type(T)
+ _, meth = T._lookup(methname)
+ if not getattr(meth, 'abstract', False):
+ assert meth.graph
+ jitcode = codewriter.get_jitcode(meth.graph)
+ oocls = ootype.runtimeClass(T)
+ self.jitcodes[oocls] = jitcode
+
+ def get_jitcode_for_class(self, oocls):
+ return self.jitcodes[oocls]
class SwitchDict(history.AbstractValue):
"Get a 'dict' attribute mapping integer values to bytecode positions."
@@ -83,6 +99,7 @@
self.all_prebuilt_values = {}
self.all_graphs = {}
self.all_indirectcallsets = {}
+ self.all_methdescs = {}
self.all_listdescs = {}
self.unfinished_graphs = []
self.metainterp_sd = metainterp_sd
@@ -152,6 +169,19 @@
IndirectCallset(self, graphs)
return result
+ def get_methdesc(self, INSTANCE, methname):
+ # use the type where the method is actually defined as a key. This way
+ # we can reuse the same desc also for subclasses
+ INSTANCE, _ = INSTANCE._lookup(methname)
+ key = (INSTANCE, methname)
+ try:
+ result = self.all_methdescs[key]
+ except KeyError:
+ result = self.all_methdescs[key] = \
+ MethDesc(self, INSTANCE, methname)
+ return result
+
+
def getcalldescr(self, v_func, args, result):
non_void_args = [x for x in args if x.concretetype is not lltype.Void]
NON_VOID_ARGS = [x.concretetype for x in non_void_args]
@@ -800,6 +830,21 @@
if x.concretetype is not lltype.Void])
self.register_var(op.result)
+ def handle_regular_oosend(self, op):
+ methname = op.args[0].value
+ v_obj = op.args[1]
+ INSTANCE = v_obj.concretetype
+ graphs = v_obj.concretetype._lookup_graphs(methname)
+ if len(graphs) == 1:
+ assert False, 'TODO'
+ self.minimize_variables()
+ methdesc = self.codewriter.get_methdesc(INSTANCE, methname)
+ self.emit('oosend')
+ self.emit(self.get_position(methdesc))
+ self.emit_varargs([x for x in op.args
+ if x.concretetype is not lltype.Void])
+ self.register_var(op.result)
+
def handle_builtin_call(self, op):
oopspec_name, args = support.decode_builtin_call(op)
argtypes = [v.concretetype for v in args]
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/pyjitpl.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/pyjitpl.py Tue Apr 21 12:10:53 2009
@@ -1,5 +1,6 @@
import py
from pypy.rpython.lltypesystem import lltype, llmemory, rclass
+from pypy.rpython.ootypesystem import ootype
from pypy.rpython.llinterp import LLException
from pypy.rpython.annlowlevel import cast_base_ptr_to_instance
from pypy.tool.sourcetools import func_with_new_name
@@ -85,6 +86,11 @@
assert isinstance(indirectcallset,
codewriter.IndirectCallset)
args += (indirectcallset, )
+ elif argspec == "methdesc":
+ methdesc = self.load_const_arg()
+ assert isinstance(methdesc,
+ codewriter.MethDesc)
+ args += (methdesc, )
elif argspec == "virtualizabledesc":
from virtualizable import VirtualizableDesc
virtualizabledesc = self.load_const_arg()
@@ -344,6 +350,10 @@
def opimpl_new_with_vtable(self, size, vtablebox):
self.execute(rop.NEW_WITH_VTABLE, [vtablebox], descr=size)
+ @arguments("box")
+ def opimpl_runtimenew(self, classbox):
+ self.execute(rop.RUNTIMENEW, [classbox])
+
@arguments("descr", "box")
def opimpl_new_array(self, itemsize, countbox):
self.execute(rop.NEW_ARRAY, [countbox], descr=itemsize)
@@ -500,6 +510,18 @@
f.setup_call(varargs)
return True
+ @arguments("orgpc", "methdesc", "varargs")
+ def opimpl_oosend(self, pc, methdesc, varargs):
+ objbox = varargs[0]
+ obj = ootype.cast_from_object(ootype.ROOT, objbox.getobj())
+ oocls = ootype.classof(obj)
+ jitcode = methdesc.get_jitcode_for_class(oocls)
+ # XXX put a guard on the class (in some way)
+ cpu = self.metainterp.cpu
+ f = self.metainterp.newframe(jitcode)
+ f.setup_call(varargs)
+ return True
+
@arguments("box")
def opimpl_strlen(self, str):
self.execute(rop.STRLEN, [str])
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/resoperation.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/resoperation.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/resoperation.py Tue Apr 21 12:10:53 2009
@@ -180,6 +180,7 @@
STRSETITEM = 137
UNICODESETITEM = 138
NEWUNICODE = 139
+ RUNTIMENEW = 140
_CANRAISE_FIRST = 150 # ----- start of can_raise operations -----
CALL = 150
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/test/test_basic.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/test/test_basic.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/test/test_basic.py Tue Apr 21 12:10:53 2009
@@ -519,7 +519,6 @@
test_format = skip
test_oops_on_nongc = skip
- test_instantiate_classes = skip
test_print = skip
test_bridge_from_interpreter_2 = skip
More information about the Pypy-commit
mailing list