[pypy-svn] r23564 - in pypy/dist/pypy/jit: . test
arigo at codespeak.net
arigo at codespeak.net
Tue Feb 21 17:06:21 CET 2006
Author: arigo
Date: Tue Feb 21 17:06:21 2006
New Revision: 23564
Modified:
pypy/dist/pypy/jit/hintrtyper.py
pypy/dist/pypy/jit/rtimeshift.py
pypy/dist/pypy/jit/test/test_hint_timeshift.py
Log:
Basic getfield test passes.
Modified: pypy/dist/pypy/jit/hintrtyper.py
==============================================================================
--- pypy/dist/pypy/jit/hintrtyper.py (original)
+++ pypy/dist/pypy/jit/hintrtyper.py Tue Feb 21 17:06:21 2006
@@ -57,7 +57,9 @@
return r
def generic_translate_operation(self, hop):
- # detect all-green operations
+ # detect constant-foldable all-green operations
+ if hop.spaceop.opname not in rtimeshift.FOLDABLE_OPS:
+ return None
green = True
for r_arg in hop.args_r:
green = green and isinstance(r_arg, GreenRepr)
@@ -73,7 +75,6 @@
# by default, a red operation converts all its arguments to
# genop variables, and emits a call to a helper that will generate
# the same operation at run-time
- # XXX constant propagate if possible
opdesc = rtimeshift.make_opdesc(hop)
if opdesc.nb_args == 1:
ll_generate = rtimeshift.ll_generate_operation1
@@ -91,6 +92,24 @@
[c_opdesc, v_jitstate] + args_v,
ts.s_RedBox)
+ def translate_op_getfield(self, hop):
+ # XXX check 'immutable'
+ PTRTYPE = originalconcretetype(hop.args_s[0])
+ RESTYPE = originalconcretetype(hop.s_result)
+ v_argbox, c_fieldname = hop.inputargs(self.getredrepr(PTRTYPE),
+ green_void_repr)
+ 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_RedBox)
+
class HintLowLevelOpList(LowLevelOpList):
"""Warning: the HintLowLevelOpList's rtyper is the *original*
Modified: pypy/dist/pypy/jit/rtimeshift.py
==============================================================================
--- pypy/dist/pypy/jit/rtimeshift.py (original)
+++ pypy/dist/pypy/jit/rtimeshift.py Tue Feb 21 17:06:21 2006
@@ -1,7 +1,9 @@
-from pypy.rpython.lltypesystem import lltype
+from pypy.rpython.lltypesystem import lltype, lloperation
from pypy.rpython import objectmodel
from pypy.rpython import rgenop
+FOLDABLE_OPS = dict.fromkeys(lloperation.enum_foldable_ops())
+
# ____________________________________________________________
# types and adtmeths
@@ -129,10 +131,11 @@
def __init__(self, opname, ARGS, RESULT):
self.opname = opname
- self.llop = getattr(objectmodel.llop, opname)
+ self.llop = lloperation.LL_OPERATIONS[opname]
self.nb_args = len(ARGS)
self.ARGS = ARGS
self.RESULT = RESULT
+ self.canfold = opname in FOLDABLE_OPS
def __getattr__(self, name): # .ARGx -> .ARGS[x]
if name.startswith('ARG'):
@@ -162,7 +165,7 @@
ARG0 = opdesc.ARG0
RESULT = opdesc.RESULT
opname = opdesc.name
- if isinstance(argbox, ConstRedBox):
+ if opdesc.canfold and isinstance(argbox, ConstRedBox):
arg = argbox.ll_getvalue(ARG0)
res = opdesc.llop(RESULT, arg)
return ConstRedBox.ll_fromvalue(res)
@@ -177,7 +180,8 @@
ARG1 = opdesc.ARG1
RESULT = opdesc.RESULT
opname = opdesc.name
- if isinstance(argbox0, ConstRedBox) and isinstance(argbox1, ConstRedBox):
+ if opdesc.canfold and (isinstance(argbox0, ConstRedBox) and
+ isinstance(argbox1, ConstRedBox)):
# const propagate
arg0 = argbox0.ll_getvalue(ARG0)
arg1 = argbox1.ll_getvalue(ARG1)
@@ -190,6 +194,15 @@
rgenop.constTYPE(RESULT))
return VarRedBox(genvar)
+def ll_generate_getfield(jitstate, argbox,
+ gv_fieldname, gv_resulttype):
+ 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)
+
# ____________________________________________________________
# 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 Tue Feb 21 17:06:21 2006
@@ -246,7 +246,7 @@
assert insns == {'int_add': 2,
'int_sub': 1}
-def INPROGRESS_test_simple_struct():
+def test_simple_struct():
S = lltype.GcStruct('helloworld', ('hello', lltype.Signed),
('world', lltype.Signed),
hints={'immutable': True})
More information about the Pypy-commit
mailing list