[pypy-svn] r53636 - in pypy/branch/jit-hotpath/pypy/jit: rainbow rainbow/test timeshifter
antocuni at codespeak.net
antocuni at codespeak.net
Thu Apr 10 00:17:56 CEST 2008
Author: antocuni
Date: Thu Apr 10 00:17:55 2008
New Revision: 53636
Modified:
pypy/branch/jit-hotpath/pypy/jit/rainbow/codewriter.py
pypy/branch/jit-hotpath/pypy/jit/rainbow/interpreter.py
pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_interpreter.py
pypy/branch/jit-hotpath/pypy/jit/timeshifter/rcontainer.py
Log:
Implement red_oosend, to make test_simple_meth & co. working for
ootype.
The idea is to store jitcodes for each method we need on the
InstanceTypeDesc of each type.
Modified: pypy/branch/jit-hotpath/pypy/jit/rainbow/codewriter.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/rainbow/codewriter.py (original)
+++ pypy/branch/jit-hotpath/pypy/jit/rainbow/codewriter.py Thu Apr 10 00:17:55 2008
@@ -146,7 +146,6 @@
keys = []
values = []
- common_args_r = None
for graph, tsgraph in graph2tsgraph:
fnptr = codewriter.rtyper.getcallable(graph)
keys.append(llmemory.cast_ptr_to_adr(fnptr))
@@ -163,8 +162,6 @@
self.bytecode_for_address = bytecode_for_address
- self.graphs = [graph for (graph, tsgraph) in graph2tsgraph]
- self.jitcodes = values
self.calldesc = CallDesc(codewriter.RGenOp, codewriter.exceptiondesc,
lltype.typeOf(fnptr), colororder)
@@ -234,6 +231,7 @@
self.calldescs = []
self.indirectcalldescs = []
self.metacalldescs = []
+ self.strings = []
self.is_portal = is_portal
# mapping constant -> index in constants
self.const_positions = {}
@@ -271,6 +269,8 @@
self.metacalldesc_positions = {}
# mapping fnobjs to index
self.indirectcalldesc_positions = {}
+ # mapping string to index
+ self.string_positions = {}
self.graph = graph
self.mergepoint_set = {}
@@ -301,6 +301,7 @@
self.sharelist("calldescs"),
self.sharelist("metacalldescs"),
self.sharelist("indirectcalldescs"),
+ self.sharelist("strings"),
self.is_portal,
owncalldesc,
gv_ownfnptr)
@@ -822,6 +823,14 @@
self.indirectcalldesc_positions[subkey] = result
return result
+ def string_position(self, s):
+ if s in self.string_positions:
+ return self.string_positions[s]
+ result = len(self.strings)
+ self.strings.append(s)
+ self.string_positions[s] = result
+ return result
+
def interiordesc(self, op, PTRTYPE, nb_offsets):
path = []
CONTAINER = PTRTYPE.TO
@@ -1420,6 +1429,12 @@
elif spaceop.opname == 'indirect_call':
graphs = spaceop.args[-1].value
args_v = spaceop.args[1:-1]
+ elif spaceop.opname == 'oosend':
+ meth_name = spaceop.args[0].value
+ v_self = spaceop.args[1]
+ SELF = v_self.concretetype
+ graphs = SELF._lookup_graphs(meth_name)
+ args_v = spaceop.args[1:]
else:
raise AssertionError(spaceop.opname)
return graphs, args_v
@@ -1617,14 +1632,15 @@
self.register_redvar(op.result)
def serialize_op_oosend(self, op):
- if self.hannotator.bookkeeper.is_green_call(op):
+ kind, withexc = self.guess_call_kind(op)
+ if kind == 'green':
assert False, 'TODO'
- withexc = self.can_raise(op)
name = op.args[0].value
opargs = op.args[1:]
SELFTYPE = opargs[0].concretetype
if SELFTYPE.oopspec_name is not None:
+ # we are calling a method like List.ll_getitem or so
hasresult = op.result.concretetype != lltype.Void
_, meth = SELFTYPE._lookup(name)
oopspecdescindex = self.oopspecdesc_position('send', meth, withexc)
@@ -1643,9 +1659,53 @@
self.emit(oopspecdescindex)
self.emit(deepfrozen)
self.emit(*args)
+ return
- else:
- assert False, 'TODO'
+ # normal oosend
+ # XXX: share code with serialize_op_indirect_call
+ has_result = (self.varcolor(op.result) != "gray" and
+ op.result.concretetype != lltype.Void)
+ assert not self.hannotator.policy.hotpath
+ emitted_args = []
+ for v in op.args[1:]:
+ if v.concretetype == lltype.Void:
+ continue
+ emitted_args.append(self.serialize_oparg("red", v))
+
+
+ if has_result:
+ self.register_redvar(op.result)
+
+ graph2tsgraph = dict(self.graphs_from(op))
+ #type2graph = self.collect_graphs_and_types(op, graph2tsgraph)
+ self.fill_methodcodes(SELFTYPE, name, graph2tsgraph)
+ args = graph2tsgraph.values()[0].getargs()
+ emitted_args = self.args_of_call(op.args[1:], args)
+ self.emit("red_oosend")
+ self.emit(*emitted_args)
+ #setdescindex = self.oosenddesc_position(type2graph)
+ #self.emit(setdescindex)
+ methnameindex = self.string_position(name)
+ self.emit(methnameindex)
+ if kind == "yellow":
+ self.emit("yellow_retrieve_result_as_red")
+ self.emit(self.type_position(op.result.concretetype))
+ elif kind in ("gray", "red"):
+ pass
+ else:
+ assert 0, "unknown call kind %s" % (kind, )
+
+ def fill_methodcodes(self, INSTANCE, methname, graph2tsgraph):
+ TYPES = [INSTANCE] + INSTANCE._subclasses
+ for T in TYPES:
+ descindex = self.structtypedesc_position(T)
+ desc = self.structtypedescs[descindex]
+ if methname in desc.methodcodes:
+ break # we already filled the codes for this type
+ _, meth = T._lookup(methname)
+ tsgraph = graph2tsgraph[meth.graph]
+ jitcode = self.get_jitcode(tsgraph)
+ desc.methodcodes[methname] = jitcode
class GraphTransformer(object):
Modified: pypy/branch/jit-hotpath/pypy/jit/rainbow/interpreter.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/rainbow/interpreter.py (original)
+++ pypy/branch/jit-hotpath/pypy/jit/rainbow/interpreter.py Thu Apr 10 00:17:55 2008
@@ -8,6 +8,7 @@
from pypy.jit.rainbow import rhotpath
from pypy.jit.rainbow import typesystem
from pypy.rpython.lltypesystem import lltype, llmemory
+from pypy.rpython.ootypesystem import ootype
import py
from pypy.tool.ansi_print import ansi_log
@@ -37,7 +38,8 @@
interiordescs, exceptioninstances, oopspecdescs,
promotiondescs, called_bytecodes, num_mergepoints,
graph_color, calldescs, metacalldescs,
- indirectcalldescs, is_portal, owncalldesc, gv_ownfnptr):
+ indirectcalldescs, strings, is_portal, owncalldesc,
+ gv_ownfnptr):
# XXX quite a lot of lists of descs here... At least we
# share identical lists between the numberous prebuilt
# JitCode instances.
@@ -60,6 +62,7 @@
self.calldescs = calldescs
self.metacalldescs = metacalldescs
self.indirectcalldescs = indirectcalldescs
+ self.strings = strings
self.is_portal = is_portal
self.owncalldesc = owncalldesc
self.gv_ownfnptr = gv_ownfnptr
@@ -165,6 +168,10 @@
index = self.load_int()
function = self.getjitcode().indirectcalldescs[index]
args += (function, )
+ elif argspec == "string":
+ index = self.load_int()
+ string = self.getjitcode().strings[index]
+ args += (string, )
elif argspec == "oopspec":
oopspecindex = self.load_int()
oopspec = self.getjitcode().oopspecdescs[oopspecindex]
@@ -654,6 +661,15 @@
self.run(self.jitstate, bytecode, greenargs, redargs,
start_bytecode_loop=False)
+ @arguments("green_varargs", "red_varargs", "string")
+ def opimpl_red_oosend(self, greenargs, redargs, methname):
+ selfbox = redargs[0]
+ vstruct = selfbox.content
+ assert isinstance(vstruct, rcontainer.VirtualStruct), 'TODO???'
+ bytecode = vstruct.typedesc.methodcodes[methname]
+ self.run(self.jitstate, bytecode, greenargs, redargs,
+ start_bytecode_loop=False)
+
@arguments(returns="green")
def opimpl_yellow_retrieve_result(self):
# XXX all this jitstate.greens business is a bit messy
Modified: pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_interpreter.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_interpreter.py (original)
+++ pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_interpreter.py Thu Apr 10 00:17:55 2008
@@ -2332,9 +2332,6 @@
test_red_varsized_struct = _skip
test_array_of_voids = _skip
test_compile_time_const_tuple = _skip # needs vdict
- test_simple_meth = _skip
- test_simple_red_meth = _skip
- test_simple_red_meth_vars_around = _skip
test_simple_indirect_call = _skip
test_normalize_indirect_call = _skip
test_normalize_indirect_call_more = _skip
Modified: pypy/branch/jit-hotpath/pypy/jit/timeshifter/rcontainer.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/timeshifter/rcontainer.py (original)
+++ pypy/branch/jit-hotpath/pypy/jit/timeshifter/rcontainer.py Thu Apr 10 00:17:55 2008
@@ -256,6 +256,12 @@
StructFieldDesc = None # patched later with InstanceFieldDesc
PtrRedBox = rvalue.InstanceRedBox
+ _attrs_ = ['methodcodes']
+
+ def __init__(self, RGenOp, TYPE):
+ AbstractStructTypeDesc.__init__(self, RGenOp, TYPE)
+ self.methodcodes = {} # method name --> jitcode
+
def Ptr(self, TYPE):
return TYPE
More information about the Pypy-commit
mailing list