[pypy-svn] r24996 - in pypy/dist/pypy/jit: . test
arigo at codespeak.net
arigo at codespeak.net
Sat Mar 25 14:27:56 CET 2006
Author: arigo
Date: Sat Mar 25 14:27:55 2006
New Revision: 24996
Modified:
pypy/dist/pypy/jit/hintrtyper.py
pypy/dist/pypy/jit/rtimeshift.py
pypy/dist/pypy/jit/test/test_hint_timeshift.py
Log:
(arigo, pedronis yesterday evening)
Intermediate check-in: VirtualRedBox.
Started to move some rtimeshift functions to be methods
of the RedBox subclasses.
Modified: pypy/dist/pypy/jit/hintrtyper.py
==============================================================================
--- pypy/dist/pypy/jit/hintrtyper.py (original)
+++ pypy/dist/pypy/jit/hintrtyper.py Sat Mar 25 14:27:55 2006
@@ -55,7 +55,11 @@
try:
return self.red_reprs[lowleveltype]
except KeyError:
- r = RedRepr(lowleveltype, self.timeshifter)
+ redreprcls = RedRepr
+ if isinstance(lowleveltype, lltype.Ptr):
+ if isinstance(lowleveltype.TO, lltype.Struct):
+ redreprcls = RedStructRepr
+ r = redreprcls(lowleveltype, self.timeshifter)
self.red_reprs[lowleveltype] = r
return r
@@ -323,20 +327,17 @@
def residual_values(self, ll_value):
return [ll_value]
+
+class RedStructRepr(RedRepr):
+ ll_factory = None
+
def create(self, hop):
+ if self.ll_factory is None:
+ T = self.original_concretetype.TO
+ self.ll_factory = rtimeshift.make_virtualredbox_factory_for_struct(T)
ts = self.timeshifter
- s_CONSTORVAR = annmodel.SomePtr(rgenop.CONSTORVAR)
- RESTYPE = self.original_concretetype
- gv_type = rgenop.constTYPE(RESTYPE.TO)
- c_type = hop.inputconst(rgenop.CONSTORVAR, gv_type)
- gv_resulttype = rgenop.constTYPE(RESTYPE)
- c_resulttype = hop.inputconst(rgenop.CONSTORVAR, gv_resulttype)
- v_jitstate = hop.llops.getjitstate()
-
- return hop.llops.genmixlevelhelpercall(rtimeshift.ll_generate_malloc,
- [ts.s_JITState, s_CONSTORVAR, s_CONSTORVAR],
- [v_jitstate, c_type, c_resulttype],
- ts.s_RedBox)
+ return hop.llops.genmixlevelhelpercall(self.ll_factory,
+ [], [], ts.s_RedBox)
class BlueRepr(Repr):
Modified: pypy/dist/pypy/jit/rtimeshift.py
==============================================================================
--- pypy/dist/pypy/jit/rtimeshift.py (original)
+++ pypy/dist/pypy/jit/rtimeshift.py Sat Mar 25 14:27:55 2006
@@ -1,3 +1,4 @@
+import operator
from pypy.rpython.lltypesystem import lltype, lloperation, llmemory
from pypy.rpython import rgenop
@@ -31,6 +32,23 @@
def same_constant(self, other):
return False
+ # generic implementation of some operations
+ def op_getfield(self, jitstate, fielddesc, gv_fieldname, gv_resulttype):
+ op_args = lltype.malloc(VARLIST.TO, 2)
+ op_args[0] = self.getgenvar()
+ op_args[1] = gv_fieldname
+ genvar = rgenop.genop(jitstate.curblock, 'getfield', op_args,
+ gv_resulttype)
+ return VarRedBox(genvar)
+
+ def op_setfield(self, jitstate, fielddesc, gv_fieldname, valuebox):
+ op_args = lltype.malloc(VARLIST.TO, 3)
+ op_args[0] = self.getgenvar()
+ op_args[1] = gv_fieldname
+ op_args[2] = valuebox.getgenvar()
+ rgenop.genop(jitstate.curblock, 'setfield', op_args,
+ gv_Void)
+
class VarRedBox(RedBox):
"A red box that contains a run-time variable."
@@ -68,6 +86,33 @@
assert isinstance(box, ContainerRedBox)
return box.content_addr
+
+class VirtualRedBox(RedBox):
+ "A red box that contains (for now) a virtual Struct."
+
+ def __init__(self, content_boxes):
+ self.content_boxes = content_boxes[:]
+
+ def getgenvar(self): # no support at the moment
+ raise RuntimeError("cannot force virtual containers")
+
+ def op_getfield(self, jitstate, fielddesc, gv_fieldname, gv_returntype):
+ return self.content_boxes[fielddesc.fieldindex]
+
+ def op_setfield(self, jitstate, fielddesc, gv_fieldname, valuebox):
+ self.content_boxes[fielddesc.fieldindex] = valuebox
+
+def make_virtualredbox_factory_for_struct(T):
+ defls = []
+ for name in T._names:
+ FIELDTYPE = T._flds[name]
+ defaultvalue = FIELDTYPE._defl()
+ defaultbox = ConstRedBox.ll_fromvalue(defaultvalue)
+ defls.append(defaultbox)
+ def ll_factory():
+ return VirtualRedBox(defls)
+ return ll_factory
+
class ConstRedBox(RedBox):
"A red box that contains a run-time constant."
@@ -206,6 +251,12 @@
self.PTRTYPE = PTRTYPE
self.immutable = PTRTYPE.TO._hints.get('immutable', False)
self.fieldname = fieldname
+ if isinstance(PTRTYPE.TO, lltype.Struct):
+ try:
+ self.fieldindex = operator.indexOf(PTRTYPE.TO._names, fieldname)
+ except ValueError:
+ raise ValueError("field not found: %r in %r" % (fieldname,
+ PTRTYPE.TO))
def _freeze_(self):
return True
@@ -227,24 +278,13 @@
if fielddesc.immutable and isinstance(argbox, ConstRedBox):
res = getattr(argbox.ll_getvalue(fielddesc.PTRTYPE), fielddesc.fieldname)
return ConstRedBox.ll_fromvalue(res)
- op_args = lltype.malloc(VARLIST.TO, 2)
- op_args[0] = argbox.getgenvar()
- op_args[1] = gv_fieldname
- genvar = rgenop.genop(jitstate.curblock, 'getfield', op_args,
- gv_resulttype)
- return VarRedBox(genvar)
+ return argbox.op_getfield(jitstate, fielddesc, gv_fieldname, gv_resulttype)
gv_Void = rgenop.constTYPE(lltype.Void)
def ll_generate_setfield(jitstate, fielddesc, destbox,
gv_fieldname, valuebox):
- op_args = lltype.malloc(VARLIST.TO, 3)
- op_args[0] = destbox.getgenvar()
- op_args[1] = gv_fieldname
- op_args[2] = valuebox.getgenvar()
- rgenop.genop(jitstate.curblock, 'setfield', op_args,
- gv_Void)
-
+ destbox.op_setfield(jitstate, fielddesc, gv_fieldname, valuebox)
def ll_generate_getsubstruct(jitstate, fielddesc, argbox,
@@ -273,12 +313,12 @@
gv_resulttype)
return VarRedBox(genvar)
-def ll_generate_malloc(jitstate, gv_type, gv_resulttype):
- op_args = lltype.malloc(VARLIST.TO, 1)
- op_args[0] = gv_type
- genvar = rgenop.genop(jitstate.curblock, 'malloc', op_args,
- gv_resulttype)
- return VarRedBox(genvar)
+##def ll_generate_malloc(jitstate, gv_type, gv_resulttype):
+## op_args = lltype.malloc(VARLIST.TO, 1)
+## op_args[0] = gv_type
+## genvar = rgenop.genop(jitstate.curblock, 'malloc', op_args,
+## gv_resulttype)
+## return VarRedBox(genvar)
# ____________________________________________________________
# other jitstate/graph level operations
Modified: pypy/dist/pypy/jit/test/test_hint_timeshift.py
==============================================================================
--- pypy/dist/pypy/jit/test/test_hint_timeshift.py (original)
+++ pypy/dist/pypy/jit/test/test_hint_timeshift.py Sat Mar 25 14:27:55 2006
@@ -260,6 +260,7 @@
'int_sub': 1}
def test_simple_struct():
+ py.test.skip("pending rpython.test_rpbc.test_disjoint_pbcs")
S = lltype.GcStruct('helloworld', ('hello', lltype.Signed),
('world', lltype.Signed),
hints={'immutable': True})
@@ -325,6 +326,7 @@
assert insns == {}
def test_degenerated_merge_substructure():
+ py.test.skip("re in-progress")
S = lltype.GcStruct('S', ('n', lltype.Signed))
T = lltype.GcStruct('T', ('s', S), ('n', lltype.Float))
@@ -363,7 +365,6 @@
# this checks that red boxes are able to be virtualized dynamically by
# the compiler (the P_NOVIRTUAL policy prevents the hint-annotator from
# marking variables in blue)
- py.test.skip("in-progress")
S = lltype.GcStruct('S', ('n', lltype.Signed))
def ll_function(n):
s = lltype.malloc(S)
More information about the Pypy-commit
mailing list