[pypy-svn] r23585 - in pypy/dist/pypy/jit: . test
pedronis at codespeak.net
pedronis at codespeak.net
Wed Feb 22 03:03:36 CET 2006
Author: pedronis
Date: Wed Feb 22 03:03:34 2006
New Revision: 23585
Modified:
pypy/dist/pypy/jit/hintrtyper.py
pypy/dist/pypy/jit/hinttimeshift.py
pypy/dist/pypy/jit/rtimeshift.py
pypy/dist/pypy/jit/test/test_hint_timeshift.py
Log:
do the immutable const getfield case.
Needed some pushing and pulling because creating an AddrRedBox with a working getgenvar really needs a pointer.
Of course there are other solutions to this problem involving putting the right casts around ,
but what exactly a AddrRedBox should contain is a bit unclear (GcAddress, generic Ptr(GcManaged?)?).
Modified: pypy/dist/pypy/jit/hintrtyper.py
==============================================================================
--- pypy/dist/pypy/jit/hintrtyper.py (original)
+++ pypy/dist/pypy/jit/hintrtyper.py Wed Feb 22 03:03:34 2006
@@ -97,21 +97,23 @@
return hop.inputarg(hop.r_result, arg=0)
def translate_op_getfield(self, hop):
- # XXX check 'immutable'
+ ts = self.timeshifter
PTRTYPE = originalconcretetype(hop.args_s[0])
RESTYPE = originalconcretetype(hop.s_result)
v_argbox, c_fieldname = hop.inputargs(self.getredrepr(PTRTYPE),
green_void_repr)
+ fielddesc = rtimeshift.make_fielddesc(PTRTYPE, c_fieldname.value)
+ c_fielddesc = inputconst(lltype.Void, fielddesc)
+ s_fielddesc = ts.rtyper.annotator.bookkeeper.immutablevalue(fielddesc)
gv_fieldname = rgenop.constFieldName(c_fieldname.value)
gv_resulttype = rgenop.constTYPE(RESTYPE)
c_fieldname = hop.inputconst(rgenop.CONSTORVAR, gv_fieldname)
c_resulttype = hop.inputconst(rgenop.CONSTORVAR, gv_resulttype)
- ts = self.timeshifter
v_jitstate = hop.llops.getjitstate()
s_CONSTORVAR = annmodel.SomePtr(rgenop.CONSTORVAR)
return hop.llops.genmixlevelhelpercall(rtimeshift.ll_generate_getfield,
- [ts.s_JITState, ts.s_RedBox, s_CONSTORVAR, s_CONSTORVAR],
- [v_jitstate, v_argbox, c_fieldname, c_resulttype],
+ [ts.s_JITState, s_fielddesc, ts.s_RedBox, s_CONSTORVAR, s_CONSTORVAR],
+ [v_jitstate, c_fielddesc, v_argbox, c_fieldname, c_resulttype],
ts.s_RedBox)
Modified: pypy/dist/pypy/jit/hinttimeshift.py
==============================================================================
--- pypy/dist/pypy/jit/hinttimeshift.py (original)
+++ pypy/dist/pypy/jit/hinttimeshift.py Wed Feb 22 03:03:34 2006
@@ -47,6 +47,10 @@
rtimeshift.ll_signed_box,
[self.s_JITState, annmodel.SomeInteger()],
self.s_RedBox)
+ self.ll_adr_box_graph = self.annhelper.getgraph(
+ rtimeshift.ll_adr_box,
+ [self.s_JITState, annmodel.SomeAddress(), annmodel.SomePtr(rgenop.CONSTORVAR)],
+ self.s_RedBox)
self.ll_var_box_graph = self.annhelper.getgraph(
rtimeshift.ll_var_box,
[self.s_JITState, annmodel.SomePtr(rgenop.CONSTORVAR)],
Modified: pypy/dist/pypy/jit/rtimeshift.py
==============================================================================
--- pypy/dist/pypy/jit/rtimeshift.py (original)
+++ pypy/dist/pypy/jit/rtimeshift.py Wed Feb 22 03:03:34 2006
@@ -48,7 +48,7 @@
def ll_fromvalue(value):
T = lltype.typeOf(value)
if isinstance(T, lltype.Ptr):
- return AddrRedBox(llmemory.cast_ptr_to_adr(value))
+ return AddrRedBox(llmemory.cast_ptr_to_adr(value), rgenop.genconst(value))
elif T is lltype.Float:
return DoubleRedBox(value)
else:
@@ -98,20 +98,24 @@
return rgenop.genconst(self.dblvalue)
def same_constant(self, other):
- return isinstance(other, DoubleRedBox) and self.intvalue == other.dblvalue
+ return isinstance(other, DoubleRedBox) and self.dblvalue == other.dblvalue
class AddrRedBox(ConstRedBox):
"A red box that contains a constant address."
- def __init__(self, adrvalue):
+ # xxx the constant genvar needs to preserve the pointer itself!
+ # for now do it this way, anyway addresses are not the right thing
+ # GC wise
+ def __init__(self, adrvalue, genvar):
self.adrvalue = adrvalue
+ self.genvar = genvar
def getgenvar(self):
- return rgenop.genconst(self.adrvalue)
+ return self.genvar # created eagerly
def same_constant(self, other):
- return isinstance(other, AddrRedBox) and self.intvalue == other.adrvalue
+ return isinstance(other, AddrRedBox) and self.adrvalue == other.adrvalue
# ____________________________________________________________
@@ -193,8 +197,32 @@
rgenop.constTYPE(RESULT))
return VarRedBox(genvar)
-def ll_generate_getfield(jitstate, argbox,
+class FieldDesc(object): # xxx should we use offsets instead
+ def __init__(self, PTRTYPE, fieldname):
+ self.PTRTYPE = PTRTYPE
+ self.immutable = PTRTYPE.TO._hints.get('immutable', False)
+ self.fieldname = fieldname
+
+ def _freeze_(self):
+ return True
+
+ def compact_repr(self): # goes in ll helper names
+ return "Fld_%s_in_%s" % (self.fieldname, self.PTRTYPE._short_name())
+
+_fielddesc_cache = {}
+
+def make_fielddesc(PTRTYPE, fieldname):
+ try:
+ return _fielddesc_cache[PTRTYPE, fieldname]
+ except KeyError:
+ fdesc = _fielddesc_cache[PTRTYPE, fieldname] = FieldDesc(PTRTYPE, fieldname)
+ return fdesc
+
+def ll_generate_getfield(jitstate, fielddesc, argbox,
gv_fieldname, gv_resulttype):
+ 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
@@ -359,6 +387,9 @@
value = lltype.cast_primitive(lltype.Signed, value)
return ConstRedBox.ll_fromvalue(value)
+def ll_adr_box(jitstate, addr, genvar): # xxx
+ return AddrRedBox(addr, genvar)
+
def ll_var_box(jitstate, gv_TYPE):
genvar = rgenop.geninputarg(jitstate.curblock, gv_TYPE)
return VarRedBox(genvar)
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 Wed Feb 22 03:03:34 2006
@@ -6,7 +6,7 @@
from pypy.jit.hinttimeshift import HintTimeshift
from pypy.jit import rtimeshift, hintrtyper
from pypy.jit.test.test_llabstractinterp import annotation, summary
-from pypy.rpython.lltypesystem import lltype
+from pypy.rpython.lltypesystem import lltype, llmemory
from pypy.rpython.objectmodel import hint
from pypy.rpython import rgenop
from pypy.annotation import model as annmodel
@@ -64,7 +64,12 @@
box = llinterp.eval_graph(htshift.ll_var_box_graph, [jitstate,
rgenop.constTYPE(TYPE)])
if i in opt_consts: # XXX what should happen here interface wise is unclear
- box = llinterp.eval_graph(htshift.ll_signed_box_graph, [jitstate, llvalue])
+ if isinstance(lltype.typeOf(llvalue), lltype.Ptr):
+ box = llinterp.eval_graph(htshift.ll_adr_box_graph, [jitstate,
+ llmemory.cast_ptr_to_adr(llvalue),
+ rgenop.genconst(llvalue)]) # xxx
+ else:
+ box = llinterp.eval_graph(htshift.ll_signed_box_graph, [jitstate, llvalue])
graph1args.append(box)
residual_graph_args.append(llvalue)
startblock = llinterp.eval_graph(htshift.ll_end_setup_jitstate_graph, [jitstate])
@@ -259,3 +264,6 @@
assert res == 42
assert insns == {'getfield': 2,
'int_mul': 1}
+ insns, res = timeshift(ll_function, [s1], [0])
+ assert res == 42
+ assert insns == {}
More information about the Pypy-commit
mailing list